[vlc-devel] [PATCH v2 25/26] audio renderer/resampler/converter: use a typed close callback in the operations structure

Steve Lhomme robux4 at ycbcr.xyz
Fri Oct 9 15:04:21 CEST 2020


---
 .../audio_filter/channel_mixer/spatialaudio.cpp   | 15 ++++-----------
 modules/audio_filter/resampler/bandlimited.c      | 11 +++++------
 modules/audio_filter/resampler/soxr.c             | 10 +++++-----
 modules/audio_filter/resampler/speex.c            | 11 +++++------
 modules/audio_filter/resampler/src.c              | 11 +++++------
 5 files changed, 24 insertions(+), 34 deletions(-)

diff --git a/modules/audio_filter/channel_mixer/spatialaudio.cpp b/modules/audio_filter/channel_mixer/spatialaudio.cpp
index 132adc4a6ed..c8cda9175de 100644
--- a/modules/audio_filter/channel_mixer/spatialaudio.cpp
+++ b/modules/audio_filter/channel_mixer/spatialaudio.cpp
@@ -57,7 +57,7 @@
 
 static int OpenBinauralizer(vlc_object_t *p_this);
 static int Open( vlc_object_t * );
-static void Close( vlc_object_t * );
+static void Close( filter_t * );
 static void Flush( filter_t * );
 
 vlc_module_begin()
@@ -66,7 +66,7 @@ vlc_module_begin()
     set_capability("audio renderer", 1)
     set_category(CAT_AUDIO)
     set_subcategory(SUBCAT_AUDIO_AFILTER)
-    set_callbacks(Open, Close)
+    set_callback(Open)
     add_bool(CFG_PREFIX "headphones", false,
              HEADPHONES_TEXT, HEADPHONES_LONGTEXT, true)
     add_loadfile("hrtf-file", NULL, HRTF_FILE_TEXT, HRTF_FILE_LONGTEXT)
@@ -318,11 +318,6 @@ static int allocateBuffers(filter_spatialaudio *p_sys)
     return VLC_SUCCESS;
 }
 
-static void CloseFilter(filter_t *p_filter)
-{
-    Close( VLC_OBJECT(p_filter) );
-}
-
 static const struct FilterOperationInitializer {
     struct vlc_filter_operations ops {};
     FilterOperationInitializer()
@@ -330,7 +325,7 @@ static const struct FilterOperationInitializer {
         ops.filter_audio = Mix;
         ops.flush = Flush;
         ops.change_viewpoint = ChangeViewpoint;
-        ops.close = CloseFilter;
+        ops.close = Close;
     };
 } filter_ops;
 
@@ -560,10 +555,8 @@ static int Open(vlc_object_t *p_this)
     return VLC_SUCCESS;
 }
 
-static void Close(vlc_object_t *p_this)
+static void Close(filter_t *p_filter)
 {
-    filter_t *p_filter = (filter_t *)p_this;
-
     filter_spatialaudio *p_sys = reinterpret_cast<filter_spatialaudio *>(p_filter->p_sys);
     delete p_sys;
 }
diff --git a/modules/audio_filter/resampler/bandlimited.c b/modules/audio_filter/resampler/bandlimited.c
index 1256f71afd6..97ae8485651 100644
--- a/modules/audio_filter/resampler/bandlimited.c
+++ b/modules/audio_filter/resampler/bandlimited.c
@@ -52,7 +52,7 @@
 
 /* audio filter */
 static int  OpenFilter ( vlc_object_t * );
-static void CloseFilter( vlc_object_t * );
+static void CloseFilter( filter_t * );
 static block_t *Resample( filter_t *, block_t * );
 
 static void ResampleFloat( filter_t *p_filter,
@@ -87,11 +87,11 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_AUDIO_RESAMPLER )
     set_description( N_("Audio filter for band-limited interpolation resampling") )
     set_capability( "audio converter", 20 )
-    set_callbacks( OpenFilter, CloseFilter )
+    set_callback( OpenFilter )
 
     add_submodule()
     set_capability( "audio resampler", 20 )
-    set_callbacks( OpenFilter, CloseFilter )
+    set_callback( OpenFilter )
 vlc_module_end ()
 
 /*****************************************************************************
@@ -280,7 +280,7 @@ static block_t *Resample( filter_t * p_filter, block_t * p_in_buf )
 }
 
 static const struct vlc_filter_operations filter_ops = {
-    .filter_audio = Resample,
+    .filter_audio = Resample, .close = CloseFilter,
 };
 
 /*****************************************************************************
@@ -329,9 +329,8 @@ static int OpenFilter( vlc_object_t *p_this )
 /*****************************************************************************
  * CloseFilter : deallocate data structures
  *****************************************************************************/
-static void CloseFilter( vlc_object_t *p_this )
+static void CloseFilter( filter_t *p_filter )
 {
-    filter_t *p_filter = (filter_t *)p_this;
     free( p_filter->p_sys->p_buf );
     free( p_filter->p_sys );
 }
diff --git a/modules/audio_filter/resampler/soxr.c b/modules/audio_filter/resampler/soxr.c
index b073e3e3a34..2e4f1dbf1c8 100644
--- a/modules/audio_filter/resampler/soxr.c
+++ b/modules/audio_filter/resampler/soxr.c
@@ -61,7 +61,7 @@ static const soxr_datatype_t soxr_resampler_quality_list[] =
 
 static int OpenConverter( vlc_object_t * );
 static int OpenResampler( vlc_object_t * );
-static void Close( vlc_object_t * );
+static void Close( filter_t * );
 
 vlc_module_begin ()
     set_shortname( N_("SoX Resampler") )
@@ -72,11 +72,11 @@ vlc_module_begin ()
         change_integer_list( soxr_resampler_quality_vlclist,
                              soxr_resampler_quality_vlctext )
     set_capability ( "audio converter", 51 )
-    set_callbacks( OpenConverter, Close )
+    set_callback( OpenConverter )
 
     add_submodule()
     set_capability( "audio resampler", 51 )
-    set_callbacks( OpenResampler, Close )
+    set_callback( OpenResampler )
     add_shortcut( "soxr" )
 vlc_module_end ()
 
@@ -193,6 +193,7 @@ Open( vlc_object_t *p_obj, bool b_change_ratio )
         .filter_audio = Resample,
         .drain_audio = Drain,
         .flush = Flush,
+        .close = Close,
     };
     p_filter->ops = &filter_ops;
     p_filter->p_sys = p_sys;
@@ -223,9 +224,8 @@ OpenConverter( vlc_object_t *p_obj )
 }
 
 static void
-Close( vlc_object_t *p_obj )
+Close( filter_t *p_filter )
 {
-    filter_t *p_filter = (filter_t *)p_obj;
     filter_sys_t *p_sys = p_filter->p_sys;
 
     soxr_delete( p_sys->soxr );
diff --git a/modules/audio_filter/resampler/speex.c b/modules/audio_filter/resampler/speex.c
index 6c339489c2a..37f92e1596d 100644
--- a/modules/audio_filter/resampler/speex.c
+++ b/modules/audio_filter/resampler/speex.c
@@ -36,7 +36,7 @@
 
 static int Open (vlc_object_t *);
 static int OpenResampler (vlc_object_t *);
-static void Close (vlc_object_t *);
+static void Close (filter_t *);
 
 vlc_module_begin ()
     set_shortname (N_("Speex resampler"))
@@ -47,11 +47,11 @@ vlc_module_begin ()
                  QUALITY_TEXT, QUALITY_LONGTEXT, true)
         change_integer_range (0, 10)
     set_capability ("audio converter", 0)
-    set_callbacks (Open, Close)
+    set_callback (Open)
 
     add_submodule ()
     set_capability ("audio resampler", 0)
-    set_callbacks (OpenResampler, Close)
+    set_callback (OpenResampler)
     add_shortcut ("speex")
 vlc_module_end ()
 
@@ -93,7 +93,7 @@ static int OpenResampler (vlc_object_t *obj)
     }
 
     static const struct vlc_filter_operations filter_ops =
-        { .filter_audio = Resample };
+        { .filter_audio = Resample, .close = Close };
 
     filter->p_sys = st;
     filter->ops = &filter_ops;
@@ -111,9 +111,8 @@ static int Open (vlc_object_t *obj)
     return OpenResampler (obj);
 }
 
-static void Close (vlc_object_t *obj)
+static void Close (filter_t *filter)
 {
-    filter_t *filter = (filter_t *)obj;
     SpeexResamplerState *st = (SpeexResamplerState *)filter->p_sys;
 
     speex_resampler_destroy (st);
diff --git a/modules/audio_filter/resampler/src.c b/modules/audio_filter/resampler/src.c
index 5e069e76bc6..51b955f408a 100644
--- a/modules/audio_filter/resampler/src.c
+++ b/modules/audio_filter/resampler/src.c
@@ -52,7 +52,7 @@ static const char *const conv_type_texts[] = {
 
 static int Open (vlc_object_t *);
 static int OpenResampler (vlc_object_t *);
-static void Close (vlc_object_t *);
+static void Close (filter_t *);
 
 vlc_module_begin ()
     set_shortname (N_("SRC resampler"))
@@ -63,11 +63,11 @@ vlc_module_begin ()
                  SRC_CONV_TYPE_TEXT, SRC_CONV_TYPE_LONGTEXT, true)
         change_integer_list (conv_type_values, conv_type_texts)
     set_capability ("audio converter", 50)
-    set_callbacks (Open, Close)
+    set_callback (Open)
 
     add_submodule ()
     set_capability ("audio resampler", 50)
-    set_callbacks (OpenResampler, Close)
+    set_callback (OpenResampler)
 vlc_module_end ()
 
 static block_t *Resample (filter_t *, block_t *);
@@ -105,7 +105,7 @@ static int OpenResampler (vlc_object_t *obj)
 
     static const struct vlc_filter_operations filter_ops =
     {
-        .filter_audio = Resample,
+        .filter_audio = Resample, .close = Close,
     };
     filter->ops = &filter_ops;
     filter->p_sys = s;
@@ -113,9 +113,8 @@ static int OpenResampler (vlc_object_t *obj)
     return VLC_SUCCESS;
 }
 
-static void Close (vlc_object_t *obj)
+static void Close (filter_t *filter)
 {
-    filter_t *filter = (filter_t *)obj;
     SRC_STATE *s = (SRC_STATE *)filter->p_sys;
 
     src_delete (s);
-- 
2.26.2



More information about the vlc-devel mailing list