[vlc-devel] [PATCH 3/5] visual: use a local picture pool to output pictures

Steve Lhomme robux4 at ycbcr.xyz
Fri Aug 14 10:25:37 CEST 2020


Also fix potential NULL usage.
---
 modules/visualization/visual/visual.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/modules/visualization/visual/visual.c b/modules/visualization/visual/visual.c
index db693dfbcd9..500046a9595 100644
--- a/modules/visualization/visual/visual.c
+++ b/modules/visualization/visual/visual.c
@@ -36,6 +36,7 @@
 #include <vlc_aout.h>
 #include <vlc_filter.h>
 #include <vlc_queue.h>
+#include <vlc_picture_pool.h>
 
 #include "visual.h"
 
@@ -182,6 +183,7 @@ typedef struct
 {
     vlc_queue_t     queue;
     vout_thread_t   *p_vout;
+    picture_pool_t  *pool;
     visual_effect_t **effect;
     int             i_effect;
     bool            dead;
@@ -198,7 +200,7 @@ static int Open( vlc_object_t *p_this )
 
     char *psz_effects, *psz_parser;
 
-    p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
+    p_sys = p_filter->p_sys = calloc( 1, sizeof( filter_sys_t ) );
     if( unlikely (p_sys == NULL ) )
         return VLC_EGENERIC;
 
@@ -304,6 +306,13 @@ static int Open( vlc_object_t *p_this )
         .primaries = COLOR_PRIMARIES_SRGB,
         .space = COLOR_SPACE_SRGB,
     };
+    p_sys->pool = picture_pool_NewFromFormat( &fmt, 3 );
+    if( p_sys->pool == NULL )
+    {
+        msg_Err( p_filter, "cannot allocate output pictures" );
+        goto error;
+    }
+
     p_sys->p_vout = aout_filter_GetVout( p_filter, &fmt );
     if( p_sys->p_vout == NULL )
     {
@@ -328,6 +337,8 @@ static int Open( vlc_object_t *p_this )
     return VLC_SUCCESS;
 
 error:
+    if ( p_sys->pool )
+        picture_pool_Release( p_sys->pool );
     for( int i = 0; i < p_sys->i_effect; i++ )
         free( p_sys->effect[i] );
     free( p_sys->effect );
@@ -340,10 +351,10 @@ static block_t *DoRealWork( filter_t *p_filter, block_t *p_in_buf )
     filter_sys_t *p_sys = p_filter->p_sys;
 
     /* First, get a new picture */
-    picture_t *p_outpic = vout_GetPicture( p_sys->p_vout );
-    p_outpic->b_progressive = true;
+    picture_t *p_outpic = picture_pool_Wait( p_sys->pool );
     if( unlikely(p_outpic == NULL) )
         return p_in_buf;
+    p_outpic->b_progressive = true;
 
     /* Blank the picture */
     for( int i = 0 ; i < p_outpic->i_planes ; i++ )
@@ -416,6 +427,7 @@ static void Close( vlc_object_t *p_this )
         free( p_effect );
 #undef p_effect
     }
+    picture_pool_Release( p_sys->pool );
 
     free( p_sys->effect );
     free( p_sys );
-- 
2.26.2



More information about the vlc-devel mailing list