[vlc-commits] filter: use constant callback structures

Rémi Denis-Courmont git at videolan.org
Sun Jun 10 14:37:22 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 10 15:37:00 2018 +0300| [537ef170cab4779b28f826caa85464a3e1709b4b] | committer: Rémi Denis-Courmont

filter: use constant callback structures

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

 include/vlc_filter.h                 | 27 +++++++++++++++------------
 modules/stream_out/mosaic_bridge.c   |  9 ++++++---
 modules/stream_out/transcode/video.c |  9 ++++++---
 modules/video_chroma/chain.c         |  9 ++++++---
 modules/video_filter/canvas.c        |  9 ++++++---
 modules/video_filter/edgedetection.c |  9 ++++++---
 src/misc/filter_chain.c              | 11 +++++++----
 src/misc/image.c                     |  7 ++++++-
 src/video_output/display.c           |  8 +++++---
 src/video_output/video_output.c      | 19 ++++++++++++-------
 src/video_output/vout_subpictures.c  | 12 ++++++++++--
 11 files changed, 85 insertions(+), 44 deletions(-)

diff --git a/include/vlc_filter.h b/include/vlc_filter.h
index eb7624aa55..99425e5f73 100644
--- a/include/vlc_filter.h
+++ b/include/vlc_filter.h
@@ -38,21 +38,24 @@
 
 typedef struct filter_owner_sys_t filter_owner_sys_t;
 
-typedef struct filter_owner_t
+struct filter_video_callbacks
 {
-    void *sys;
+    picture_t *(*buffer_new)(filter_t *);
+};
 
+struct filter_subpicture_callbacks
+{
+    subpicture_t *(*buffer_new)(filter_t *);
+};
+
+typedef struct filter_owner_t
+{
     union
     {
-        struct
-        {
-            picture_t * (*buffer_new)( filter_t * );
-        } video;
-        struct
-        {
-            subpicture_t * (*buffer_new)( filter_t * );
-        } sub;
+        const struct filter_video_callbacks *video;
+        const struct filter_subpicture_callbacks *sub;
     };
+    void *sys;
 } filter_owner_t;
 
 struct vlc_mouse_t;
@@ -162,7 +165,7 @@ struct filter_t
  */
 static inline picture_t *filter_NewPicture( filter_t *p_filter )
 {
-    picture_t *pic = p_filter->owner.video.buffer_new( p_filter );
+    picture_t *pic = p_filter->owner.video->buffer_new( p_filter );
     if( pic == NULL )
         msg_Warn( p_filter, "can't get output picture" );
     return pic;
@@ -208,7 +211,7 @@ static inline block_t *filter_DrainAudio( filter_t *p_filter )
  */
 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
 {
-    subpicture_t *subpic = p_filter->owner.sub.buffer_new( p_filter );
+    subpicture_t *subpic = p_filter->owner.sub->buffer_new( p_filter );
     if( subpic == NULL )
         msg_Warn( p_filter, "can't get output subpicture" );
     return subpic;
diff --git a/modules/stream_out/mosaic_bridge.c b/modules/stream_out/mosaic_bridge.c
index e3d75a6a44..c2ea4224c7 100644
--- a/modules/stream_out/mosaic_bridge.c
+++ b/modules/stream_out/mosaic_bridge.c
@@ -383,15 +383,18 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
     msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
 
     /* Create user specified video filters */
+    static const struct filter_video_callbacks cbs =
+    {
+        .buffer_new = video_new_buffer_filter,
+    };
+
     psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
     msg_Dbg( p_stream, "psz_chain: %s", psz_chain );
     if( psz_chain )
     {
         filter_owner_t owner = {
+            .video = &cbs,
             .sys = p_owner,
-            .video = {
-                .buffer_new = video_new_buffer_filter,
-            },
         };
 
         p_sys->p_vf2 = filter_chain_NewVideo( p_stream, false, &owner );
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 05da35115f..f612ddd53a 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -302,15 +302,18 @@ static int transcode_video_new( sout_stream_t *p_stream, sout_stream_id_sys_t *i
     return VLC_SUCCESS;
 }
 
+static const struct filter_video_callbacks transcode_filter_video_cbs =
+{
+    .buffer_new = transcode_video_filter_buffer_new,
+};
+
 static void transcode_video_filter_init( sout_stream_t *p_stream,
                                          sout_stream_id_sys_t *id )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     filter_owner_t owner = {
+        .video = &transcode_filter_video_cbs,
         .sys = p_sys,
-        .video = {
-            .buffer_new = transcode_video_filter_buffer_new,
-        },
     };
     const es_format_t *p_fmt_out = &id->p_decoder->fmt_out;
 
diff --git a/modules/video_chroma/chain.c b/modules/video_chroma/chain.c
index 4edde8abb1..242034bda0 100644
--- a/modules/video_chroma/chain.c
+++ b/modules/video_chroma/chain.c
@@ -140,6 +140,11 @@ static picture_t *BufferNew( filter_t *p_filter )
 
 #define CHAIN_LEVEL_MAX 2
 
+static const struct filter_video_callbacks filter_video_chain_cbs =
+{
+    .buffer_new = BufferNew,
+};
+
 /*****************************************************************************
  * Activate: allocate a chroma function
  *****************************************************************************
@@ -155,10 +160,8 @@ static int Activate( filter_t *p_filter, int (*pf_build)(filter_t *) )
         return VLC_ENOMEM;
 
     filter_owner_t owner = {
+        .video = &filter_video_chain_cbs,
         .sys = p_filter,
-        .video = {
-            .buffer_new = BufferNew,
-        },
     };
 
     p_sys->p_chain = filter_chain_NewVideo( p_filter, p_filter->b_allow_fmt_out_change, &owner );
diff --git a/modules/video_filter/canvas.c b/modules/video_filter/canvas.c
index b9fbe508b2..4e53376a38 100644
--- a/modules/video_filter/canvas.c
+++ b/modules/video_filter/canvas.c
@@ -137,6 +137,11 @@ static picture_t *video_new( filter_t *p_filter )
     return filter_NewPicture( p_filter->owner.sys );
 }
 
+static const struct filter_video_callbacks canvas_cbs =
+{
+    .buffer_new = video_new,
+};
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -232,10 +237,8 @@ static int Activate( vlc_object_t *p_this )
     p_filter->p_sys = p_sys;
 
     filter_owner_t owner = {
+        .video = &canvas_cbs,
         .sys = p_filter,
-        .video = {
-            .buffer_new = video_new,
-        },
     };
 
     p_sys->p_chain = filter_chain_NewVideo( p_filter, true, &owner );
diff --git a/modules/video_filter/edgedetection.c b/modules/video_filter/edgedetection.c
index b2d74f7b7e..371b61504b 100644
--- a/modules/video_filter/edgedetection.c
+++ b/modules/video_filter/edgedetection.c
@@ -84,6 +84,11 @@ typedef struct
     filter_chain_t *p_chain;
 } filter_sys_t;
 
+static const struct filter_video_callbacks filter_video_edge_cbs =
+{
+    .buffer_new = new_frame,
+};
+
 /*****************************************************************************
  * Opens the filter.
  * Allocates and initializes data needed by the filter. The image needs to
@@ -96,10 +101,8 @@ static int Open( vlc_object_t *p_this )
     int i_ret;
     filter_t *p_filter = (filter_t *)p_this;
     filter_owner_t owner = {
+        .video = &filter_video_edge_cbs,
         .sys = p_filter,
-        .video = {
-            .buffer_new = new_frame,
-        },
     };
     /* Store the filter chain in p_sys */
     p_filter->p_sys = (filter_sys_t *)filter_chain_NewVideo( p_filter, true, &owner );
diff --git a/src/misc/filter_chain.c b/src/misc/filter_chain.c
index 552ed9e587..61af86961e 100644
--- a/src/misc/filter_chain.c
+++ b/src/misc/filter_chain.c
@@ -122,21 +122,24 @@ static picture_t *filter_chain_VideoBufferNew( filter_t *filter )
 
         /* XXX ugly */
         filter->owner.sys = chain->owner.sys;
-        picture_t *pic = chain->owner.video.buffer_new( filter );
+        picture_t *pic = chain->owner.video->buffer_new( filter );
         filter->owner.sys = chain;
         return pic;
     }
 }
 
+static const struct filter_video_callbacks filter_chain_video_cbs =
+{
+    .buffer_new = filter_chain_VideoBufferNew,
+};
+
 #undef filter_chain_NewVideo
 filter_chain_t *filter_chain_NewVideo( vlc_object_t *obj, bool allow_change,
                                        const filter_owner_t *restrict owner )
 {
     filter_owner_t callbacks = {
+        .video = &filter_chain_video_cbs,
         .sys = obj,
-        .video = {
-            .buffer_new = filter_chain_VideoBufferNew,
-        },
     };
 
     return filter_chain_NewInner( &callbacks, "video filter",
diff --git a/src/misc/image.c b/src/misc/image.c
index 2d55ec51d1..3b0fec711a 100644
--- a/src/misc/image.c
+++ b/src/misc/image.c
@@ -810,13 +810,18 @@ static picture_t *filter_new_picture( filter_t *p_filter )
     return picture_NewFromFormat( &p_filter->fmt_out.video );
 }
 
+static const struct filter_video_callbacks image_filter_cbs =
+{
+    .buffer_new = filter_new_picture,
+};
+
 static filter_t *CreateFilter( vlc_object_t *p_this, const es_format_t *p_fmt_in,
                                const video_format_t *p_fmt_out )
 {
     filter_t *p_filter;
 
     p_filter = vlc_custom_create( p_this, sizeof(filter_t), "filter" );
-    p_filter->owner.video.buffer_new = filter_new_picture;
+    p_filter->owner.video = &image_filter_cbs;
 
     es_format_Copy( &p_filter->fmt_in, p_fmt_in );
     es_format_Copy( &p_filter->fmt_out, p_fmt_in );
diff --git a/src/video_output/display.c b/src/video_output/display.c
index e965426647..e06ad2ebe3 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -370,14 +370,16 @@ typedef struct {
     atomic_bool reset_pictures;
 } vout_display_owner_sys_t;
 
+static const struct filter_video_callbacks vout_display_filter_cbs = {
+    .buffer_new = VideoBufferNew,
+};
+
 static int VoutDisplayCreateRender(vout_display_t *vd)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
     filter_owner_t owner = {
+        .video = &vout_display_filter_cbs,
         .sys = vd,
-        .video = {
-            .buffer_new = VideoBufferNew,
-        },
     };
 
     osys->filters = filter_chain_NewVideo(vd, false, &owner);
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 5581f50541..8de1b6fcf3 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -909,10 +909,11 @@ static picture_t *ConvertRGB32AndBlend(vout_thread_t *vout, picture_t *pic,
 
     assert(vout->p->spu_blend);
 
+    static const struct filter_video_callbacks cbs = {
+        .buffer_new = ConvertRGB32AndBlendBufferNew,
+    };
     filter_owner_t owner = {
-        .video = {
-            .buffer_new = ConvertRGB32AndBlendBufferNew,
-        },
+        .video = &cbs,
     };
     filter_chain_t *filterc = filter_chain_NewVideo(vout, false, &owner);
     if (!filterc)
@@ -1470,16 +1471,20 @@ static int ThreadStart(vout_thread_t *vout, vout_display_state_t *state)
     vout->p->filter.configuration = NULL;
     video_format_Copy(&vout->p->filter.format, &vout->p->original);
 
+    static const struct filter_video_callbacks static_cbs = {
+        .buffer_new = VoutVideoFilterStaticNewPicture,
+    };
+    static const struct filter_video_callbacks interactive_cbs = {
+        .buffer_new = VoutVideoFilterInteractiveNewPicture,
+    };
     filter_owner_t owner = {
+        .video = &static_cbs,
         .sys = vout,
-        .video = {
-            .buffer_new = VoutVideoFilterStaticNewPicture,
-        },
     };
     vout->p->filter.chain_static =
         filter_chain_NewVideo( vout, true, &owner );
 
-    owner.video.buffer_new = VoutVideoFilterInteractiveNewPicture;
+    owner.video = &interactive_cbs;
     vout->p->filter.chain_interactive =
         filter_chain_NewVideo( vout, true, &owner );
 
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 1bd4a7d9ea..779982bde7 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -214,6 +214,10 @@ static filter_t *SpuRenderCreateAndLoadText(spu_t *spu)
     return text;
 }
 
+static const struct filter_video_callbacks spu_scaler_cbs = {
+    .buffer_new = spu_new_video_buffer,
+};
+
 static filter_t *SpuRenderCreateAndLoadScale(vlc_object_t *object,
                                              vlc_fourcc_t src_chroma,
                                              vlc_fourcc_t dst_chroma,
@@ -237,7 +241,7 @@ static filter_t *SpuRenderCreateAndLoadScale(vlc_object_t *object,
     scale->fmt_out.video.i_height =
     scale->fmt_out.video.i_visible_height = require_resize ? 16 : 32;
 
-    scale->owner.video.buffer_new = spu_new_video_buffer;
+    scale->owner.video = &spu_scaler_cbs;
 
     scale->p_module = module_need(scale, "video converter", NULL, false);
 
@@ -1202,13 +1206,17 @@ static subpicture_t *sub_new_buffer(filter_t *filter)
     return subpicture;
 }
 
+static const struct filter_subpicture_callbacks sub_cbs = {
+    .buffer_new = sub_new_buffer,
+};
+
 static int SubSourceInit(filter_t *filter, void *data)
 {
     spu_t *spu = data;
     int channel = spu_RegisterChannel(spu);
 
     filter->owner.sys = (void *)(intptr_t)channel;
-    filter->owner.sub.buffer_new = sub_new_buffer;
+    filter->owner.sub = &sub_cbs;
     return VLC_SUCCESS;
 }
 



More information about the vlc-commits mailing list