[vlc-commits] filters: add a typed Close callback to the operations structure

Steve Lhomme git at videolan.org
Mon Oct 12 15:55:47 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Oct  5 17:00:57 2020 +0200| [3730be78519ad674f10a5445f8cb6a277dec972c] | committer: Steve Lhomme

filters: add a typed Close callback to the operations structure

The close callback is now typed instead of a vlc_object_t.

Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>

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

 include/vlc_filter.h                  | 8 ++++++++
 modules/access/screen/screen.c        | 1 +
 modules/audio_filter/scaletempo.c     | 1 +
 modules/hw/d3d11/d3d11_surface.c      | 3 +++
 modules/hw/d3d9/dxa9.c                | 3 +++
 modules/video_filter/blendbench.c     | 1 +
 modules/video_filter/ci_filters.m     | 2 ++
 modules/video_filter/opencv_wrapper.c | 1 +
 src/audio_output/filters.c            | 2 ++
 src/audio_output/meter.c              | 2 ++
 src/misc/filter.c                     | 4 ++++
 src/misc/filter_chain.c               | 1 +
 src/misc/image.c                      | 6 +++++-
 src/video_output/vout_subpictures.c   | 3 +++
 14 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/include/vlc_filter.h b/include/vlc_filter.h
index 772f58dee9..fa1caf770b 100644
--- a/include/vlc_filter.h
+++ b/include/vlc_filter.h
@@ -136,6 +136,8 @@ struct vlc_filter_operations
     int (*video_mouse)(filter_t *, struct vlc_mouse_t *,
                        const struct vlc_mouse_t *p_old);
 
+    /** Close the filter and release its resources. */
+    void (*close)(filter_t *);
 };
 
 /** Structure describing a filter
@@ -172,6 +174,12 @@ struct filter_t
     filter_owner_t      owner;
 };
 
+static inline void filter_Close( filter_t *p_filter )
+{
+    if ( p_filter->ops->close )
+        p_filter->ops->close( p_filter );
+}
+
 /**
  * This function will return a new picture usable by p_filter as an output
  * buffer. You have to release it using picture_Release or by returning
diff --git a/modules/access/screen/screen.c b/modules/access/screen/screen.c
index 518697f700..06ef075f62 100644
--- a/modules/access/screen/screen.c
+++ b/modules/access/screen/screen.c
@@ -263,6 +263,7 @@ static void Close( vlc_object_t *p_this )
         picture_Release( p_sys->p_mouse );
     if( p_sys->p_blend )
     {
+        filter_Close( p_sys->p_blend );
         module_unneed( p_sys->p_blend, p_sys->p_blend->p_module );
         vlc_object_delete(p_sys->p_blend);
     }
diff --git a/modules/audio_filter/scaletempo.c b/modules/audio_filter/scaletempo.c
index 1616ce59d3..59e2fc05fe 100644
--- a/modules/audio_filter/scaletempo.c
+++ b/modules/audio_filter/scaletempo.c
@@ -545,6 +545,7 @@ static void ClosePitch( vlc_object_t *p_this )
     vlc_object_t *p_aout = vlc_object_parent(p_filter);
     var_DelCallback( p_aout, "pitch-shift", PitchCallback, p_sys );
     var_Destroy( p_aout, "pitch-shift" );
+    filter_Close( p_sys->resampler );
     module_unneed( p_sys->resampler, p_sys->resampler->p_module );
     vlc_object_delete(p_sys->resampler);
     Close( p_this );
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 07d3b71522..44a3c87ac6 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -462,7 +462,10 @@ static void D3D11_RGBA(filter_t *p_filter, picture_t *src, picture_t *dst)
 static void DeleteFilter( filter_t * p_filter )
 {
     if( p_filter->p_module )
+    {
+        filter_Close( p_filter );
         module_unneed( p_filter, p_filter->p_module );
+    }
 
     es_format_Clean( &p_filter->fmt_in );
     es_format_Clean( &p_filter->fmt_out );
diff --git a/modules/hw/d3d9/dxa9.c b/modules/hw/d3d9/dxa9.c
index 621d4af670..66f617e404 100644
--- a/modules/hw/d3d9/dxa9.c
+++ b/modules/hw/d3d9/dxa9.c
@@ -170,7 +170,10 @@ static void DXA9_NV12(filter_t *p_filter, picture_t *src, picture_t *dst)
 static void DeleteFilter( filter_t * p_filter )
 {
     if( p_filter->p_module )
+    {
+        filter_Close( p_filter );
         module_unneed( p_filter, p_filter->p_module );
+    }
 
     es_format_Clean( &p_filter->fmt_in );
     es_format_Clean( &p_filter->fmt_out );
diff --git a/modules/video_filter/blendbench.c b/modules/video_filter/blendbench.c
index 105d0c035c..1787620447 100644
--- a/modules/video_filter/blendbench.c
+++ b/modules/video_filter/blendbench.c
@@ -271,6 +271,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
                   p_sys->p_blend_image->p[Y_PLANE].i_visible_pitch *
                   p_sys->p_blend_image->p[Y_PLANE].i_visible_lines );
 
+    filter_Close( p_blend );
     module_unneed( p_blend, p_blend->p_module );
 
     vlc_object_delete(p_blend);
diff --git a/modules/video_filter/ci_filters.m b/modules/video_filter/ci_filters.m
index 7374393c25..1b0d0f41b3 100644
--- a/modules/video_filter/ci_filters.m
+++ b/modules/video_filter/ci_filters.m
@@ -525,11 +525,13 @@ cvpx_video_context_Destroy(void *priv)
 
     if (ctx->src_converter)
     {
+        filter_Close( ctx->src_converter );
         module_unneed(ctx->src_converter, ctx->src_converter->p_module);
         vlc_object_delete(ctx->src_converter);
     }
     if (ctx->dst_converter)
     {
+        filter_Close( ctx->dst_converter );
         module_unneed(ctx->dst_converter, ctx->dst_converter->p_module);
         vlc_object_delete(ctx->dst_converter);
     }
diff --git a/modules/video_filter/opencv_wrapper.c b/modules/video_filter/opencv_wrapper.c
index 6e92e8b143..f4c8d770dd 100644
--- a/modules/video_filter/opencv_wrapper.c
+++ b/modules/video_filter/opencv_wrapper.c
@@ -271,6 +271,7 @@ static void Destroy( vlc_object_t *p_this )
     ReleaseImages( p_filter );
 
     // Release the internal OpenCV filter.
+    filter_Close( p_sys->p_opencv );
     module_unneed( p_sys->p_opencv, p_sys->p_opencv->p_module );
     vlc_object_delete(p_sys->p_opencv);
 
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index d2d2b3225a..4578051a41 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -118,6 +118,7 @@ static void aout_FiltersPipelineDestroy(filter_t *const *filters, unsigned n)
     {
         filter_t *p_filter = filters[i];
 
+        filter_Close( p_filter );
         module_unneed( p_filter, p_filter->p_module );
         vlc_object_delete(p_filter);
     }
@@ -432,6 +433,7 @@ static int AppendFilter(vlc_object_t *obj, const char *type, const char *name,
                                     max - 1, infmt, &filter->fmt_in.audio, false))
     {
         msg_Err (filter, "cannot add user %s \"%s\" (skipped)", type, name);
+        filter_Close( filter );
         module_unneed (filter, filter->p_module);
         vlc_object_delete(filter);
         return -1;
diff --git a/src/audio_output/meter.c b/src/audio_output/meter.c
index 8fd570d0b1..9c8f736512 100644
--- a/src/audio_output/meter.c
+++ b/src/audio_output/meter.c
@@ -133,6 +133,7 @@ vlc_audio_meter_RemovePlugin(struct vlc_audio_meter *meter, vlc_audio_meter_plug
 
     if (plugin->filter != NULL)
     {
+        filter_Close(plugin->filter);
         module_unneed(plugin->filter, plugin->filter->p_module);
         vlc_object_delete(plugin->filter);
     }
@@ -162,6 +163,7 @@ vlc_audio_meter_Reset(struct vlc_audio_meter *meter, const audio_sample_format_t
     {
         if (plugin->filter != NULL)
         {
+            filter_Close(plugin->filter);
             module_unneed(plugin->filter, plugin->filter->p_module);
             vlc_object_delete(plugin->filter);
             plugin->filter = NULL;
diff --git a/src/misc/filter.c b/src/misc/filter.c
index ace08e2329..131fc63787 100644
--- a/src/misc/filter.c
+++ b/src/misc/filter.c
@@ -134,6 +134,7 @@ int filter_ConfigureBlend( vlc_blender_t *p_blend,
         p_blend->fmt_in.video.i_chroma != p_src->i_chroma )
     {
         /* The chroma is not the same, we need to reload the blend module */
+        filter_Close( p_blend );
         module_unneed( p_blend, p_blend->p_module );
         p_blend->p_module = NULL;
     }
@@ -172,7 +173,10 @@ int filter_Blend( vlc_blender_t *p_blend,
 void filter_DeleteBlend( vlc_blender_t *p_blend )
 {
     if( p_blend->p_module )
+    {
+        filter_Close( p_blend );
         module_unneed( p_blend, p_blend->p_module );
+    }
 
     vlc_object_delete(p_blend);
 }
diff --git a/src/misc/filter_chain.c b/src/misc/filter_chain.c
index a71b6a3c9a..4eafffd4d8 100644
--- a/src/misc/filter_chain.c
+++ b/src/misc/filter_chain.c
@@ -331,6 +331,7 @@ void filter_chain_DeleteFilter( filter_chain_t *chain, filter_t *filter )
         chain->last = chained->prev;
     }
 
+    filter_Close( filter );
     module_unneed( filter, filter->p_module );
 
     msg_Dbg( chain->obj, "Filter %p removed from chain", (void *)filter );
diff --git a/src/misc/image.c b/src/misc/image.c
index c340d0d9aa..5ba958fd40 100644
--- a/src/misc/image.c
+++ b/src/misc/image.c
@@ -815,7 +815,11 @@ static filter_t *CreateConverter( vlc_object_t *p_this,
 
 static void DeleteConverter( filter_t * p_filter )
 {
-    if( p_filter->p_module ) module_unneed( p_filter, p_filter->p_module );
+    if( p_filter->p_module )
+    {
+        filter_Close( p_filter );
+        module_unneed( p_filter, p_filter->p_module );
+    }
 
     es_format_Clean( &p_filter->fmt_in );
     es_format_Clean( &p_filter->fmt_out );
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 8c7af5e387..1afa7bd093 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -225,7 +225,10 @@ static ssize_t spu_GetFreeChannelId(spu_t *spu, enum vlc_vout_order *order)
 static void FilterRelease(filter_t *filter)
 {
     if (filter->p_module)
+    {
+        filter_Close(filter);
         module_unneed(filter, filter->p_module);
+    }
     vlc_object_delete(filter);
 }
 



More information about the vlc-commits mailing list