[vlc-commits] video_filters: use a p_sys allocated with the object

Steve Lhomme git at videolan.org
Fri Oct 9 13:41:14 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Oct  8 11:49:28 2020 +0200| [4d79988692ef342fdaef2a66c370f3bae6270352] | committer: Steve Lhomme

video_filters: use a p_sys allocated with the object

No need to release it manually.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4d79988692ef342fdaef2a66c370f3bae6270352
---

 modules/audio_filter/channel_mixer/dolby.c   | 16 +++-------------
 modules/audio_filter/channel_mixer/trivial.c | 13 +++----------
 modules/video_filter/anaglyph.c              | 14 +++-----------
 modules/video_filter/croppadd.c              | 16 +++-------------
 modules/video_filter/ripple.c                | 18 +++---------------
 modules/video_filter/transform.c             | 17 ++++-------------
 6 files changed, 19 insertions(+), 75 deletions(-)

diff --git a/modules/audio_filter/channel_mixer/dolby.c b/modules/audio_filter/channel_mixer/dolby.c
index de05e3eb7f..4810eec6c2 100644
--- a/modules/audio_filter/channel_mixer/dolby.c
+++ b/modules/audio_filter/channel_mixer/dolby.c
@@ -37,7 +37,6 @@
  * Local prototypes
  *****************************************************************************/
 static int  Create    ( vlc_object_t * );
-static void Destroy   ( vlc_object_t * );
 
 static block_t *DoWork( filter_t *, block_t * );
 
@@ -50,7 +49,7 @@ vlc_module_begin ()
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_ACODEC )
     set_capability( "audio converter", 5 )
-    set_callbacks( Create, Destroy )
+    set_callback( Create )
 vlc_module_end ()
 
 /*****************************************************************************
@@ -98,8 +97,8 @@ static int Create( vlc_object_t *p_this )
     }
 
     /* Allocate the memory needed to store the module's structure */
-    p_sys = p_filter->p_sys = malloc( sizeof(*p_sys) );
-    if( p_sys == NULL )
+    p_sys = p_filter->p_sys = vlc_obj_malloc( VLC_OBJECT(p_filter), sizeof(*p_sys) );
+    if( unlikely(p_sys == NULL) )
         return VLC_ENOMEM;
     p_sys->i_left = -1;
     p_sys->i_center = -1;
@@ -147,15 +146,6 @@ static int Create( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
-/*****************************************************************************
- * Destroy: deallocate resources associated with headphone downmixer
- *****************************************************************************/
-static void Destroy( vlc_object_t *p_this )
-{
-    filter_t * p_filter = (filter_t *)p_this;
-    free( p_filter->p_sys );
-}
-
 /*****************************************************************************
  * DoWork: convert a buffer
  *****************************************************************************/
diff --git a/modules/audio_filter/channel_mixer/trivial.c b/modules/audio_filter/channel_mixer/trivial.c
index faa142e648..f4d9d00f56 100644
--- a/modules/audio_filter/channel_mixer/trivial.c
+++ b/modules/audio_filter/channel_mixer/trivial.c
@@ -36,14 +36,13 @@
 #include <vlc_filter.h>
 
 static int Create( vlc_object_t * );
-static void Destroy( vlc_object_t * );
 
 vlc_module_begin ()
     set_description( N_("Audio filter for trivial channel mixing") )
     set_capability( "audio converter", 1 )
     set_category( CAT_AUDIO )
     set_subcategory( SUBCAT_AUDIO_AFILTER )
-    set_callbacks( Create, Destroy )
+    set_callback( Create )
 vlc_module_end ()
 
 typedef struct
@@ -310,8 +309,8 @@ static int Create( vlc_object_t *p_this )
         }
     }
 
-    filter_sys_t *p_sys = malloc( sizeof(*p_sys) );
-    if( !p_sys )
+    filter_sys_t *p_sys = vlc_obj_malloc( VLC_OBJECT(p_filter), sizeof(*p_sys) );
+    if( unlikely(!p_sys) )
         return VLC_ENOMEM;
     p_filter->p_sys = p_sys;
     memcpy( p_sys->channel_map, channel_map, sizeof(channel_map) );
@@ -323,9 +322,3 @@ static int Create( vlc_object_t *p_this )
 
     return VLC_SUCCESS;
 }
-
-static void Destroy( vlc_object_t *p_this )
-{
-    filter_t *p_filter = (filter_t *)p_this;
-    free( p_filter->p_sys );
-}
diff --git a/modules/video_filter/anaglyph.c b/modules/video_filter/anaglyph.c
index 0f1b16689f..fcb9993ac8 100644
--- a/modules/video_filter/anaglyph.c
+++ b/modules/video_filter/anaglyph.c
@@ -31,7 +31,6 @@
 #include "filter_picture.h"
 
 static int Create(vlc_object_t *);
-static void Destroy(vlc_object_t *);
 static picture_t *Filter(filter_t *, picture_t *);
 static void combine_side_by_side_yuv420(picture_t *, picture_t *, int, int);
 
@@ -74,7 +73,7 @@ vlc_module_begin()
     set_capability("video filter", 0)
     add_string(FILTER_PREFIX "scheme", "red-cyan", SCHEME_TEXT, SCHEME_LONGTEXT, false)
         change_string_list(ppsz_scheme_values, ppsz_scheme_descriptions)
-    set_callbacks(Create, Destroy)
+    set_callback(Create)
 vlc_module_end()
 
 static const char *const ppsz_filter_options[] = {
@@ -109,8 +108,8 @@ static int Create(vlc_object_t *p_this)
             return VLC_EGENERIC;
     }
 
-    p_filter->p_sys = malloc(sizeof(filter_sys_t));
-    if (!p_filter->p_sys)
+    p_filter->p_sys = vlc_obj_malloc(VLC_OBJECT(p_filter), sizeof(filter_sys_t));
+    if (unlikely(!p_filter->p_sys))
         return VLC_ENOMEM;
     filter_sys_t *p_sys = p_filter->p_sys;
 
@@ -165,13 +164,6 @@ static int Create(vlc_object_t *p_this)
     return VLC_SUCCESS;
 }
 
-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;
-    free(p_sys);
-}
-
 static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
 {
     filter_sys_t *p_sys = p_filter->p_sys;
diff --git a/modules/video_filter/croppadd.c b/modules/video_filter/croppadd.c
index 4471e859a7..07e14f6c56 100644
--- a/modules/video_filter/croppadd.c
+++ b/modules/video_filter/croppadd.c
@@ -39,7 +39,6 @@
  * Local prototypes
  ****************************************************************************/
 static int  OpenFilter ( vlc_object_t * );
-static void CloseFilter( vlc_object_t * );
 
 static picture_t *Filter( filter_t *, picture_t * );
 
@@ -78,7 +77,7 @@ vlc_module_begin ()
     set_shortname( N_("Croppadd") )
     set_description( N_("Video cropping filter") )
     set_capability( "video filter", 0 )
-    set_callbacks( OpenFilter, CloseFilter )
+    set_callback( OpenFilter )
 
     set_category( CAT_VIDEO )
     set_subcategory( SUBCAT_VIDEO_VFILTER );
@@ -158,8 +157,8 @@ static int OpenFilter( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    p_filter->p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) );
-    if( !p_filter->p_sys ) return VLC_ENOMEM;
+    p_filter->p_sys = (filter_sys_t *)vlc_obj_malloc( VLC_OBJECT(p_filter), sizeof( filter_sys_t ) );
+    if( unlikely(!p_filter->p_sys) ) return VLC_ENOMEM;
 
     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
                        p_filter->p_cfg );
@@ -207,15 +206,6 @@ static int OpenFilter( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
-/*****************************************************************************
- * CloseFilter: clean up the filter
- *****************************************************************************/
-static void CloseFilter( vlc_object_t *p_this )
-{
-    filter_t *p_filter = (filter_t *)p_this;
-    free( p_filter->p_sys );
-}
-
 /****************************************************************************
  * Filter: the whole thing
  ****************************************************************************/
diff --git a/modules/video_filter/ripple.c b/modules/video_filter/ripple.c
index c6748995bb..9355f60ca2 100644
--- a/modules/video_filter/ripple.c
+++ b/modules/video_filter/ripple.c
@@ -41,7 +41,6 @@
  * Local prototypes
  *****************************************************************************/
 static int  Create    ( vlc_object_t * );
-static void Destroy   ( vlc_object_t * );
 
 static picture_t *Filter( filter_t *, picture_t * );
 
@@ -56,7 +55,7 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_VIDEO_VFILTER )
 
     add_shortcut( "ripple" )
-    set_callbacks( Create, Destroy )
+    set_callback( Create )
 vlc_module_end ()
 
 /*****************************************************************************
@@ -86,8 +85,8 @@ static int Create( vlc_object_t *p_this )
         return VLC_EGENERIC;
 
     /* Allocate structure */
-    filter_sys_t *p_sys = malloc( sizeof( filter_sys_t ) );
-    if( p_sys == NULL )
+    filter_sys_t *p_sys = vlc_obj_malloc( VLC_OBJECT(p_filter), sizeof( filter_sys_t ) );
+    if( unlikely(p_sys == NULL) )
         return VLC_ENOMEM;
     p_filter->p_sys = p_sys;
 
@@ -103,17 +102,6 @@ static int Create( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
-/*****************************************************************************
- * Destroy: destroy Distort video thread output method
- *****************************************************************************
- * Terminate an output method created by DistortCreateOutputMethod
- *****************************************************************************/
-static void Destroy( vlc_object_t *p_this )
-{
-    filter_t *p_filter = (filter_t *)p_this;
-    free( p_filter->p_sys );
-}
-
 /*****************************************************************************
  * Render: displays previously rendered output
  *****************************************************************************
diff --git a/modules/video_filter/transform.c b/modules/video_filter/transform.c
index ab48f748b4..481ac5b401 100644
--- a/modules/video_filter/transform.c
+++ b/modules/video_filter/transform.c
@@ -42,7 +42,6 @@
  * Module descriptor
  *****************************************************************************/
 static int  Open (vlc_object_t *);
-static void Close(vlc_object_t *);
 
 #define CFG_PREFIX "transform-"
 
@@ -67,7 +66,7 @@ vlc_module_begin()
         change_safe()
 
     add_shortcut("transform")
-    set_callbacks(Open, Close)
+    set_callback(Open)
 vlc_module_end()
 
 /*****************************************************************************
@@ -313,8 +312,8 @@ static int Open(vlc_object_t *object)
     if (chroma == NULL)
         return VLC_EGENERIC;
 
-    filter_sys_t *sys = malloc(sizeof(*sys));
-    if (!sys)
+    filter_sys_t *sys = vlc_obj_malloc(VLC_OBJECT(filter), sizeof(*sys));
+    if (unlikely(!sys))
         return VLC_ENOMEM;
 
     sys->chroma = chroma;
@@ -441,14 +440,6 @@ static int Open(vlc_object_t *object)
     filter->p_sys           = sys;
     return VLC_SUCCESS;
 error:
-    free(sys);
+    vlc_obj_free(VLC_OBJECT(filter), sys);
     return VLC_EGENERIC;
 }
-
-static void Close(vlc_object_t *object)
-{
-    filter_t     *filter = (filter_t *)object;
-    filter_sys_t *sys    = filter->p_sys;
-
-    free(sys);
-}



More information about the vlc-commits mailing list