filter: separate owner structure from the filter itself
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 28 Jul 2014 16:31:22 +0000 (19:31 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 28 Jul 2014 20:14:26 +0000 (23:14 +0300)
include/vlc_filter.h
modules/stream_out/mosaic_bridge.c
modules/stream_out/transcode/video.c
modules/video_chroma/chain.c
modules/video_filter/canvas.c
src/audio_output/filters.c
src/misc/filter_chain.c
src/misc/image.c
src/video_output/display.c
src/video_output/video_output.c
src/video_output/vout_subpictures.c

index 320cbac..96ffb61 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * vlc_filter.h: filter related structures and functions
  *****************************************************************************
- * Copyright (C) 1999-2008 VLC authors and VideoLAN
- * $Id$
+ * Copyright (C) 1999-2014 VLC authors and VideoLAN
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *          Antoine Cellerier <dionoea at videolan dot org>
+ *          Rémi Denis-Courmont
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
 
 typedef struct filter_owner_sys_t filter_owner_sys_t;
 
+typedef struct filter_owner_t
+{
+    void *sys;
+
+    union
+    {
+        struct
+        {
+            picture_t * (*buffer_new)( filter_t * );
+            void        (*buffer_del)( filter_t *, picture_t * );
+        } video;
+        struct
+        {
+            subpicture_t * (*buffer_new)( filter_t * );
+            void           (*buffer_del)( filter_t *, subpicture_t * );
+        } sub;
+    };
+} filter_owner_t;
+
+
 /** Structure describing a filter
  * @warning BIG FAT WARNING : the code relies on the first 4 members of
  * filter_t and decoder_t to be the same, so if you have anything to add,
@@ -66,8 +86,6 @@ struct filter_t
         {
             picture_t * (*pf_filter) ( filter_t *, picture_t * );
             void        (*pf_flush)( filter_t * );
-            picture_t * (*pf_buffer_new) ( filter_t * );
-            void        (*pf_buffer_del) ( filter_t *, picture_t * );
             /* Filter mouse state.
              *
              * If non-NULL, you must convert from output to input formats:
@@ -83,8 +101,6 @@ struct filter_t
 #define pf_video_filter     u.video.pf_filter
 #define pf_video_flush      u.video.pf_flush
 #define pf_video_mouse      u.video.pf_mouse
-#define pf_video_buffer_new u.video.pf_buffer_new
-#define pf_video_buffer_del u.video.pf_buffer_del
 
         struct
         {
@@ -102,16 +118,12 @@ struct filter_t
         struct
         {
             subpicture_t * (*pf_source)    ( filter_t *, mtime_t );
-            subpicture_t * (*pf_buffer_new)( filter_t * );
-            void           (*pf_buffer_del)( filter_t *, subpicture_t * );
             int            (*pf_mouse)     ( filter_t *,
                                              const vlc_mouse_t *p_old,
                                              const vlc_mouse_t *p_new,
                                              const video_format_t * );
         } sub;
 #define pf_sub_source      u.sub.pf_source
-#define pf_sub_buffer_new  u.sub.pf_buffer_new
-#define pf_sub_buffer_del  u.sub.pf_buffer_del
 #define pf_sub_mouse       u.sub.pf_mouse
 
         struct
@@ -139,7 +151,7 @@ struct filter_t
     int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
 
     /* Private structure for the owner of the decoder */
-    filter_owner_sys_t *p_owner;
+    filter_owner_t      owner;
 };
 
 /**
@@ -153,10 +165,10 @@ struct filter_t
  */
 static inline picture_t *filter_NewPicture( filter_t *p_filter )
 {
-    picture_t *p_picture = p_filter->pf_video_buffer_new( p_filter );
-    if( !p_picture )
+    picture_t *pic = p_filter->owner.video.buffer_new( p_filter );
+    if( pic == NULL )
         msg_Warn( p_filter, "can't get output picture" );
-    return p_picture;
+    return pic;
 }
 
 /**
@@ -166,9 +178,9 @@ static inline picture_t *filter_NewPicture( filter_t *p_filter )
  * \param p_filter filter_t object
  * \param p_picture picture to be deleted
  */
-static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
+static inline void filter_DeletePicture( filter_t *p_filter, picture_t *pic )
 {
-    p_filter->pf_video_buffer_del( p_filter, p_picture );
+    p_filter->owner.video.buffer_del( p_filter, pic );
 }
 
 /**
@@ -191,10 +203,10 @@ static inline void filter_FlushPictures( filter_t *p_filter )
  */
 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
 {
-    subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
-    if( !p_subpicture )
+    subpicture_t *subpic = p_filter->owner.sub.buffer_new( p_filter );
+    if( subpic == NULL )
         msg_Warn( p_filter, "can't get output subpicture" );
-    return p_subpicture;
+    return subpic;
 }
 
 /**
@@ -204,9 +216,10 @@ static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
  * \param p_filter filter_t object
  * \param p_subpicture to be released
  */
-static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
+static inline void filter_DeleteSubpicture( filter_t *p_filter,
+                                            subpicture_t *subpic )
 {
-    p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
+    p_filter->owner.sub.buffer_del( p_filter, subpic );
 }
 
 /**
index d06430a..734e9f6 100644 (file)
@@ -276,9 +276,9 @@ static void Close( vlc_object_t * p_this )
 
 static int video_filter_buffer_allocation_init( filter_t *p_filter, void *p_data )
 {
-    p_filter->pf_video_buffer_new = video_new_buffer_filter;
-    p_filter->pf_video_buffer_del = video_del_buffer_filter;
-    p_filter->p_owner = p_data;
+    p_filter->owner.sys = p_data;
+    p_filter->owner.video.buffer_new = video_new_buffer_filter;
+    p_filter->owner.video.buffer_del = video_del_buffer_filter;
     return VLC_SUCCESS;
 }
 
@@ -614,7 +614,7 @@ inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
 {
     return video_new_buffer( VLC_OBJECT( p_filter ),
-                             (decoder_owner_sys_t *)p_filter->p_owner,
+                             (decoder_owner_sys_t *)p_filter->owner.sys,
                              &p_filter->fmt_out );
 }
 
index 05d9252..d14f482 100644 (file)
@@ -87,8 +87,8 @@ static int transcode_video_filter_allocation_init( filter_t *p_filter,
                                                    void *p_data )
 {
     VLC_UNUSED(p_data);
-    p_filter->pf_video_buffer_new = transcode_video_filter_buffer_new;
-    p_filter->pf_video_buffer_del = transcode_video_filter_buffer_del;
+    p_filter->owner.video.buffer_new = transcode_video_filter_buffer_new;
+    p_filter->owner.video.buffer_del = transcode_video_filter_buffer_del;
     return VLC_SUCCESS;
 }
 
index 57436b2..8bea647 100644 (file)
@@ -266,21 +266,23 @@ exit:
  *****************************************************************************/
 static picture_t *BufferNew( filter_t *p_filter )
 {
-    filter_t *p_parent = (filter_t*)p_filter->p_owner;
+    filter_t *p_parent = p_filter->owner.sys;
 
     return filter_NewPicture( p_parent );
 }
+
 static void BufferDel( filter_t *p_filter, picture_t *p_pic )
 {
-    filter_t *p_parent = (filter_t*)p_filter->p_owner;
+    filter_t *p_parent = p_filter->owner.sys;
 
     filter_DeletePicture( p_parent, p_pic );
 }
+
 static int BufferAllocationInit ( filter_t *p_filter, void *p_data )
 {
-    p_filter->pf_video_buffer_new = BufferNew;
-    p_filter->pf_video_buffer_del = BufferDel;
-    p_filter->p_owner = p_data;
+    p_filter->owner.sys = p_data;
+    p_filter->owner.video.buffer_new = BufferNew;
+    p_filter->owner.video.buffer_del = BufferDel;
     return VLC_SUCCESS;
 }
 
index 6c6ea8a..0abbd58 100644 (file)
@@ -370,18 +370,18 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
  *****************************************************************************/
 static picture_t *video_new( filter_t *p_filter )
 {
-    return filter_NewPicture( (filter_t*)p_filter->p_owner );
+    return filter_NewPicture( p_filter->owner.sys );
 }
 
 static void video_del( filter_t *p_filter, picture_t *p_pic )
 {
-    return filter_DeletePicture( (filter_t*)p_filter->p_owner, p_pic );
+    return filter_DeletePicture( p_filter->owner.sys, p_pic );
 }
 
 static int alloc_init( filter_t *p_filter, void *p_data )
 {
-    p_filter->p_owner = p_data;
-    p_filter->pf_video_buffer_new = video_new;
-    p_filter->pf_video_buffer_del = video_del;
+    p_filter->owner.sys = p_data;
+    p_filter->owner.video.buffer_new = video_new;
+    p_filter->owner.video.buffer_del = video_del;
     return VLC_SUCCESS;
 }
index e6a6955..74c5a6a 100644 (file)
@@ -51,7 +51,7 @@ static filter_t *CreateFilter (vlc_object_t *obj, const char *type,
     if (unlikely(filter == NULL))
         return NULL;
 
-    filter->p_owner = owner;
+    filter->owner.sys = owner;
     filter->fmt_in.audio = *infmt;
     filter->fmt_in.i_codec = infmt->i_format;
     filter->fmt_out.audio = *outfmt;
@@ -317,7 +317,7 @@ vout_thread_t *aout_filter_RequestVout (filter_t *filter, vout_thread_t *vout,
      * If you want to use visualization filters from another place, you will
      * need to add a new pf_aout_request_vout callback or store a pointer
      * to aout_request_vout_t inside filter_t (i.e. a level of indirection). */
-    const aout_request_vout_t *req = (void *)filter->p_owner;
+    const aout_request_vout_t *req = filter->owner.sys;
     char *visual = var_InheritString (filter->p_parent, "audio-visual");
     /* NOTE: Disable recycling to always close the filter vout because OpenGL
      * visualizations do not use this function to ask for a context. */
index 963537c..460c5ff 100644 (file)
@@ -605,15 +605,15 @@ static int InternalVideoInit( filter_t *p_filter, void *p_data )
 {
     VLC_UNUSED(p_data);
 
-    p_filter->pf_video_buffer_new = VideoBufferNew;
-    p_filter->pf_video_buffer_del = VideoBufferDelete;
+    p_filter->owner.video.buffer_new = VideoBufferNew;
+    p_filter->owner.video.buffer_del = VideoBufferDelete;
 
     return VLC_SUCCESS;
 }
 
 static bool IsInternalVideoAllocator( chained_filter_t *p_filter )
 {
-    return p_filter->filter.pf_video_buffer_new == VideoBufferNew;
+    return p_filter->filter.owner.video.buffer_new == VideoBufferNew;
 }
 
 /* */
index c7f67a1..25fccc9 100644 (file)
@@ -784,9 +784,9 @@ static filter_t *CreateFilter( vlc_object_t *p_this, es_format_t *p_fmt_in,
     filter_t *p_filter;
 
     p_filter = vlc_custom_create( p_this, sizeof(filter_t), "filter" );
-    p_filter->pf_video_buffer_new =
+    p_filter->owner.video.buffer_new =
         (picture_t *(*)(filter_t *))video_new_buffer;
-    p_filter->pf_video_buffer_del =
+    p_filter->owner.video.buffer_del =
         (void (*)(filter_t *, picture_t *))video_del_buffer;
 
     p_filter->fmt_in = *p_fmt_in;
index 3b197b8..871b15b 100644 (file)
@@ -53,7 +53,7 @@ static void SplitterClose(vout_display_t *vd);
  *****************************************************************************/
 static picture_t *VideoBufferNew(filter_t *filter)
 {
-    vout_display_t *vd = (vout_display_t*)filter->p_owner;
+    vout_display_t *vd = filter->owner.sys;
     const video_format_t *fmt = &filter->fmt_out.video;
 
     assert(vd->fmt.i_chroma == fmt->i_chroma &&
@@ -73,10 +73,9 @@ static void VideoBufferDelete(filter_t *filter, picture_t *picture)
 
 static int  FilterAllocationInit(filter_t *filter, void *vd)
 {
-    filter->pf_video_buffer_new = VideoBufferNew;
-    filter->pf_video_buffer_del = VideoBufferDelete;
-    filter->p_owner             = vd;
-
+    filter->owner.sys              = vd;
+    filter->owner.video.buffer_new = VideoBufferNew;
+    filter->owner.video.buffer_del = VideoBufferDelete;
     return VLC_SUCCESS;
 }
 
index 18f22ce..f214a8d 100644 (file)
@@ -669,7 +669,7 @@ void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_display_t *vd,
 /* */
 static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
 {
-    vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
+    vout_thread_t *vout = filter->owner.sys;
 
     picture_t *picture = picture_pool_Get(vout->p->private_pool);
     if (picture) {
@@ -678,9 +678,10 @@ static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
     }
     return picture;
 }
+
 static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
 {
-    vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
+    vout_thread_t *vout = filter->owner.sys;
 
     vlc_assert_locked(&vout->p->filter.lock);
     if (filter_chain_GetLength(vout->p->filter.chain_interactive) == 0)
@@ -688,25 +689,29 @@ static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
 
     return picture_NewFromFormat(&filter->fmt_out.video);
 }
+
 static void VoutVideoFilterDelPicture(filter_t *filter, picture_t *picture)
 {
     VLC_UNUSED(filter);
     picture_Release(picture);
 }
+
 static int VoutVideoFilterStaticAllocationSetup(filter_t *filter, void *data)
 {
-    filter->pf_video_buffer_new = VoutVideoFilterStaticNewPicture;
-    filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
-    filter->p_owner             = data; /* vout */
+    filter->owner.sys              = data; /* vout */
+    filter->owner.video.buffer_new = VoutVideoFilterStaticNewPicture;
+    filter->owner.video.buffer_del = VoutVideoFilterDelPicture;
     return VLC_SUCCESS;
 }
+
 static int VoutVideoFilterInteractiveAllocationSetup(filter_t *filter, void *data)
 {
-    filter->pf_video_buffer_new = VoutVideoFilterInteractiveNewPicture;
-    filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
-    filter->p_owner             = data; /* vout */
+    filter->owner.sys              = data; /* vout */
+    filter->owner.video.buffer_new = VoutVideoFilterInteractiveNewPicture;
+    filter->owner.video.buffer_del = VoutVideoFilterDelPicture;
     return VLC_SUCCESS;
 }
+
 static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
 {
     if (vout->p->displayed.current)
index 632c1b0..f8705f5 100644 (file)
@@ -165,9 +165,7 @@ static void FilterRelease(filter_t *filter)
 {
     if (filter->p_module)
         module_unneed(filter, filter->p_module);
-    if (filter->p_owner)
-        free(filter->p_owner);
-
+    free(filter->owner.sys);
     vlc_object_release(filter);
 }
 
@@ -188,7 +186,8 @@ static int spu_get_attachments(filter_t *filter,
                                input_attachment_t ***attachment_ptr,
                                int *attachment_count)
 {
-    spu_t *spu = filter->p_owner->spu;
+    filter_owner_sys_t *sys = filter->owner.sys;
+    spu_t *spu = sys->spu;
 
     int ret = VLC_EGENERIC;
     if (spu->p->input)
@@ -204,8 +203,9 @@ static filter_t *SpuRenderCreateAndLoadText(spu_t *spu)
     if (!text)
         return NULL;
 
-    text->p_owner = xmalloc(sizeof(*text->p_owner));
-    text->p_owner->spu = spu;
+    filter_owner_sys_t *sys = xmalloc(sizeof(*sys));
+    sys->spu = spu;
+    text->owner.sys = sys;
 
     es_format_Init(&text->fmt_in, VIDEO_ES, 0);
 
@@ -249,8 +249,8 @@ 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->pf_video_buffer_new = spu_new_video_buffer;
-    scale->pf_video_buffer_del = spu_del_video_buffer;
+    scale->owner.video.buffer_new = spu_new_video_buffer;
+    scale->owner.video.buffer_del = spu_del_video_buffer;
 
     scale->p_module = module_need(scale, "video filter2", NULL, false);
 
@@ -1163,13 +1163,14 @@ static int CropCallback(vlc_object_t *object, char const *var,
 
 static subpicture_t *sub_new_buffer(filter_t *filter)
 {
-    filter_owner_sys_t *sys = filter->p_owner;
+    filter_owner_sys_t *sys = filter->owner.sys;
 
     subpicture_t *subpicture = subpicture_New(NULL);
     if (subpicture)
         subpicture->i_channel = sys->channel;
     return subpicture;
 }
+
 static void sub_del_buffer(filter_t *filter, subpicture_t *subpic)
 {
     VLC_UNUSED(filter);
@@ -1184,10 +1185,10 @@ static int SubSourceAllocationInit(filter_t *filter, void *data)
     if (!sys)
         return VLC_EGENERIC;
 
-    filter->pf_sub_buffer_new = sub_new_buffer;
-    filter->pf_sub_buffer_del = sub_del_buffer;
+    filter->owner.sub.buffer_new = sub_new_buffer;
+    filter->owner.sub.buffer_del = sub_del_buffer;
 
-    filter->p_owner = sys;
+    filter->owner.sys = sys;
     sys->channel = spu_RegisterChannel(spu);
     sys->spu     = spu;
 
@@ -1196,10 +1197,10 @@ static int SubSourceAllocationInit(filter_t *filter, void *data)
 
 static void SubSourceAllocationClean(filter_t *filter)
 {
-    filter_owner_sys_t *sys = filter->p_owner;
+    filter_owner_sys_t *sys = filter->owner.sys;
 
     spu_ClearChannel(sys->spu, sys->channel);
-    free(filter->p_owner);
+    free(sys);
 }
 
 /*****************************************************************************