]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/blendbench.c
Fix memleak
[vlc] / modules / video_filter / blendbench.c
index f21d6f412ad2c041d03d5f57f2362213c9f9aac1..e0302a269703b0c01c25e1c6bf270b331493068f 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_sout.h>
 #include <vlc_vout.h>
 
@@ -70,34 +71,34 @@ static picture_t *Filter( filter_t *, picture_t * );
 #define CFG_PREFIX "blendbench-"
 
 vlc_module_begin();
-    set_description( _("Blending benchmark filter") );
-    set_shortname( _("blendbench" ));
+    set_description( N_("Blending benchmark filter") );
+    set_shortname( N_("blendbench" ));
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_VFILTER );
     set_capability( "video filter2", 0 );
 
     set_section( N_("Benchmarking"), NULL );
     add_integer( CFG_PREFIX "loops", 1000, NULL, LOOPS_TEXT,
-              LOOPS_LONGTEXT, VLC_FALSE );
+              LOOPS_LONGTEXT, false );
     add_integer_with_range( CFG_PREFIX "alpha", 128, 0, 255, NULL, ALPHA_TEXT,
-              ALPHA_LONGTEXT, VLC_FALSE );
+              ALPHA_LONGTEXT, false );
 
     set_section( N_("Base image"), NULL );
     add_file( CFG_PREFIX "base-image", NULL, NULL, BASE_IMAGE_TEXT,
-              BASE_IMAGE_LONGTEXT, VLC_FALSE );
+              BASE_IMAGE_LONGTEXT, false );
     add_string( CFG_PREFIX "base-chroma", "I420", NULL, BASE_CHROMA_TEXT,
-              BASE_CHROMA_LONGTEXT, VLC_FALSE );
+              BASE_CHROMA_LONGTEXT, false );
 
     set_section( N_("Blend image"), NULL );
     add_file( CFG_PREFIX "blend-image", NULL, NULL, BLEND_IMAGE_TEXT,
-              BLEND_IMAGE_LONGTEXT, VLC_FALSE );
+              BLEND_IMAGE_LONGTEXT, false );
     add_string( CFG_PREFIX "blend-chroma", "YUVA", NULL, BLEND_CHROMA_TEXT,
-              BLEND_CHROMA_LONGTEXT, VLC_FALSE );
+              BLEND_CHROMA_LONGTEXT, false );
 
     set_callbacks( Create, Destroy );
 vlc_module_end();
 
-static const char *ppsz_filter_options[] = {
+static const char *const ppsz_filter_options[] = {
     "loops", "alpha", "base-image", "base-chroma", "blend-image",
     "blend-chroma", NULL
 };
@@ -107,7 +108,7 @@ static const char *ppsz_filter_options[] = {
  *****************************************************************************/
 struct filter_sys_t
 {
-    vlc_bool_t b_done;
+    bool b_done;
     int i_loops, i_alpha;
 
     picture_t *p_base_image;
@@ -117,8 +118,8 @@ struct filter_sys_t
     vlc_fourcc_t i_blend_chroma;
 };
 
-static int LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
-                       vlc_fourcc_t i_chroma, char *psz_file, const char *psz_name )
+static int blendbench_LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
+                                 vlc_fourcc_t i_chroma, char *psz_file, const char *psz_name )
 {
     image_handler_t *p_image;
     video_format_t fmt_in, fmt_out;
@@ -131,7 +132,8 @@ static int LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
     *pp_pic = image_ReadUrl( p_image, psz_file, &fmt_in, &fmt_out );
     image_HandlerDelete( p_image );
 
-    if( *pp_pic == NULL ) {
+    if( *pp_pic == NULL )
+    {
         msg_Err( p_this, "Unable to load %s image", psz_name );
         return VLC_EGENERIC;
     }
@@ -155,12 +157,10 @@ static int Create( vlc_object_t *p_this )
     /* Allocate structure */
     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
     if( p_filter->p_sys == NULL )
-    {
-        msg_Err( p_filter, "out of memory" );
         return VLC_ENOMEM;
-    }
+
     p_sys = p_filter->p_sys;
-    p_sys->b_done = VLC_FALSE;
+    p_sys->b_done = false;
 
     p_filter->pf_video_filter = Filter;
 
@@ -177,7 +177,8 @@ static int Create( vlc_object_t *p_this )
     psz_temp = var_CreateGetStringCommand( p_filter, CFG_PREFIX "base-chroma" );
     p_sys->i_base_chroma = VLC_FOURCC( psz_temp[0], psz_temp[1],
                                        psz_temp[2], psz_temp[3] );
-    LoadImage( p_this, &p_sys->p_base_image, p_sys->i_base_chroma,
+    free( psz_temp );
+    blendbench_LoadImage( p_this, &p_sys->p_base_image, p_sys->i_base_chroma,
                var_CreateGetStringCommand( p_filter, CFG_PREFIX "base-image" ),
                "Base" );
 
@@ -185,7 +186,8 @@ static int Create( vlc_object_t *p_this )
                                            CFG_PREFIX "blend-chroma" );
     p_sys->i_blend_chroma = VLC_FOURCC( psz_temp[0], psz_temp[1],
                                         psz_temp[2], psz_temp[3] );
-    LoadImage( p_this, &p_sys->p_blend_image, p_sys->i_blend_chroma,
+    free( psz_temp );
+    blendbench_LoadImage( p_this, &p_sys->p_blend_image, p_sys->i_blend_chroma,
                var_CreateGetStringCommand( p_filter, CFG_PREFIX "blend-image" ),
                "Blend" );
 
@@ -200,8 +202,8 @@ static void Destroy( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    p_sys->p_base_image->pf_release( p_sys->p_base_image );
-    p_sys->p_blend_image->pf_release( p_sys->p_blend_image );
+    picture_Release( p_sys->p_base_image );
+    picture_Release( p_sys->p_blend_image );
 }
 
 /*****************************************************************************
@@ -210,26 +212,35 @@ static void Destroy( vlc_object_t *p_this )
 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
+    filter_t *p_blend;
 
     if( p_sys->b_done )
-    {
         return p_pic;
-    }
 
-    filter_t *p_blend;
-
-    p_blend = vlc_object_create( p_filter, VLC_OBJECT_FILTER );
+    p_blend = vlc_object_create( p_filter, sizeof(filter_t) );
+    if( !p_blend )
+    {
+        picture_Release( p_pic );
+        return NULL;
+    }
     vlc_object_attach( p_blend, p_filter );
     p_blend->fmt_out.video = p_sys->p_base_image->format;
     p_blend->fmt_in.video = p_sys->p_blend_image->format;
     p_blend->p_module = module_Need( p_blend, "video blending", 0, 0 );
+    if( !p_blend->p_module )
+    {
+        picture_Release( p_pic );
+        vlc_object_detach( p_blend );
+        vlc_object_release( p_blend );
+        return NULL;
+    }
 
     mtime_t time = mdate();
     for( int i_iter = 0; i_iter < p_sys->i_loops; ++i_iter )
     {
         p_blend->pf_video_blend( p_blend, p_sys->p_base_image,
-                                 p_sys->p_base_image, p_sys->p_blend_image, 0,
-                                 0, p_sys->i_alpha );
+                                 p_sys->p_base_image, p_sys->p_blend_image,
+                                 0, 0, p_sys->i_alpha );
     }
     time = mdate() - time;
 
@@ -246,6 +257,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
     vlc_object_detach( p_blend );
     vlc_object_release( p_blend );
 
-    p_sys->b_done = VLC_TRUE;
+    p_sys->b_done = true;
     return p_pic;
 }