[vlc-commits] vdpau: add proper structure type for picture context

Rémi Denis-Courmont git at videolan.org
Mon Jun 5 18:32:33 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 27 22:33:17 2016 +0200| [7080c3bb8a9b80844c5e30c2b22f85548e0d87c7] | committer: Rémi Denis-Courmont

vdpau: add proper structure type for picture context

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

 include/vlc_picture.h          |  8 ++++++--
 modules/hw/vdpau/adjust.c      |  2 +-
 modules/hw/vdpau/avcodec.c     |  4 ++--
 modules/hw/vdpau/chroma.c      | 13 +++++++------
 modules/hw/vdpau/deinterlace.c |  4 ++--
 modules/hw/vdpau/picture.c     | 13 ++++++++-----
 modules/hw/vdpau/sharpen.c     |  2 +-
 modules/hw/vdpau/vlc_vdpau.h   |  3 ++-
 src/misc/picture.c             |  7 +++----
 9 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index b8d4a5a223..a48a053ac6 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -56,6 +56,11 @@ typedef struct plane_t
  */
 #define PICTURE_PLANE_MAX (VOUT_MAX_PLANES)
 
+typedef struct picture_context_t
+{
+    void (*destroy)(struct picture_context_t *);
+} picture_context_t;
+
 /**
  * Video picture
  */
@@ -84,8 +89,7 @@ struct picture_t
     bool            b_progressive;          /**< is it a progressive frame ? */
     bool            b_top_field_first;             /**< which field is first */
     unsigned int    i_nb_fields;                  /**< # of displayed fields */
-    void          * context;          /**< video format-specific data pointer,
-             * must point to a (void (*)(void*)) pointer to free the context */
+    picture_context_t *context;      /**< video format-specific data pointer */
     /**@}*/
 
     /** Private data - the video output plugin might want to put stuff here to
diff --git a/modules/hw/vdpau/adjust.c b/modules/hw/vdpau/adjust.c
index 0c11345fad..f7905d65d6 100644
--- a/modules/hw/vdpau/adjust.c
+++ b/modules/hw/vdpau/adjust.c
@@ -108,7 +108,7 @@ static int HueCallback(vlc_object_t *obj, const char *varname,
 static picture_t *Adjust(filter_t *filter, picture_t *pic)
 {
     filter_sys_t *sys = filter->p_sys;
-    vlc_vdp_video_field_t *f = pic->context;
+    vlc_vdp_video_field_t *f = (vlc_vdp_video_field_t *)pic->context;
 
     if (unlikely(f == NULL))
         return pic;
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index 53ed6d92d2..a73ba53033 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -73,7 +73,7 @@ static vlc_vdp_video_field_t *CreateSurface(vlc_va_t *va)
 static void DestroySurface(vlc_vdp_video_field_t *field)
 {
     assert(field != NULL);
-    field->destroy(field);
+    field->context.destroy(&field->context);
 }
 
 static vlc_vdp_video_field_t *GetSurface(vlc_va_t *va)
@@ -109,7 +109,7 @@ static int Lock(vlc_va_t *va, picture_t *pic, uint8_t **data)
         msleep(VOUT_OUTMEM_SLEEP);
     }
 
-    pic->context = field;
+    pic->context = &field->context;
     *data = (void *)(uintptr_t)field->frame->surface;
     return VLC_SUCCESS;
 }
diff --git a/modules/hw/vdpau/chroma.c b/modules/hw/vdpau/chroma.c
index ae0d3eb7e4..115d07fcba 100644
--- a/modules/hw/vdpau/chroma.c
+++ b/modules/hw/vdpau/chroma.c
@@ -290,7 +290,8 @@ static void Flush(filter_t *filter)
     for (unsigned i = 0; i < MAX_PAST + MAX_FUTURE; i++)
         if (sys->history[i].field != NULL)
         {
-            sys->history[i].field->destroy(sys->history[i].field);
+            sys->history[i].field->context.destroy(
+                &sys->history[i].field->context);
             sys->history[i].field = NULL;
         }
 }
@@ -299,7 +300,7 @@ static void Flush(filter_t *filter)
 static picture_t *VideoExport(filter_t *filter, picture_t *src, picture_t *dst)
 {
     filter_sys_t *sys = filter->p_sys;
-    vlc_vdp_video_field_t *field = src->context;
+    vlc_vdp_video_field_t *field = (vlc_vdp_video_field_t *)src->context;
     vlc_vdp_video_frame_t *psys = field->frame;
     VdpStatus err;
     VdpVideoSurface surface = psys->surface;
@@ -446,7 +447,7 @@ static picture_t *Render(filter_t *filter, picture_t *src, bool import)
     }
 
     /* Corner case: different VDPAU instances decoding and rendering */
-    vlc_vdp_video_field_t *field = src->context;
+    vlc_vdp_video_field_t *field = (vlc_vdp_video_field_t *)src->context;
     if (field->frame->vdp != sys->vdp)
     {
         video_format_t fmt = src->format;
@@ -478,7 +479,7 @@ static picture_t *Render(filter_t *filter, picture_t *src, bool import)
     if (likely(src != NULL))
     {
         sys->history[MAX_PAST + MAX_FUTURE].field =
-                                              vlc_vdp_video_copy(src->context);
+            vlc_vdp_video_copy((vlc_vdp_video_field_t *)src->context);
         sys->history[MAX_PAST + MAX_FUTURE].date = src->date;
         sys->history[MAX_PAST + MAX_FUTURE].force = src->b_force;
         picture_Release(src);
@@ -502,7 +503,7 @@ static picture_t *Render(filter_t *filter, picture_t *src, bool import)
         {
             f = sys->history[0].field;
             if (f != NULL)
-                f->destroy(f);
+                f->context.destroy(&f->context);
 
             memmove(sys->history, sys->history + 1,
                     sizeof (sys->history[0]) * (MAX_PAST + MAX_FUTURE));
@@ -679,7 +680,7 @@ static picture_t *Render(filter_t *filter, picture_t *src, bool import)
 skip:
     f = sys->history[0].field;
     if (f != NULL)
-        f->destroy(f); /* Release oldest field */
+        f->context.destroy(&f->context); /* Release oldest field */
     memmove(sys->history, sys->history + 1, /* Advance history */
             sizeof (sys->history[0]) * (MAX_PAST + MAX_FUTURE));
 
diff --git a/modules/hw/vdpau/deinterlace.c b/modules/hw/vdpau/deinterlace.c
index a1370a7560..2cc8b371d2 100644
--- a/modules/hw/vdpau/deinterlace.c
+++ b/modules/hw/vdpau/deinterlace.c
@@ -43,7 +43,7 @@ static picture_t *Deinterlace(filter_t *filter, picture_t *src)
 
     sys->last_pts = src->date;
 
-    vlc_vdp_video_field_t *f1 = src->context;
+    vlc_vdp_video_field_t *f1 = (vlc_vdp_video_field_t *)src->context;
     if (unlikely(f1 == NULL))
         return src;
     if (f1->structure != VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME)
@@ -65,7 +65,7 @@ static picture_t *Deinterlace(filter_t *filter, picture_t *src)
     }
 
     picture_CopyProperties(dst, src);
-    dst->context = f2;
+    dst->context = &f2->context;
 
     if (last_pts != VLC_TS_INVALID)
         dst->date = (3 * src->date - last_pts) / 2;
diff --git a/modules/hw/vdpau/picture.c b/modules/hw/vdpau/picture.c
index 05e711658c..29e6be9c4a 100644
--- a/modules/hw/vdpau/picture.c
+++ b/modules/hw/vdpau/picture.c
@@ -32,9 +32,12 @@
 
 #pragma GCC visibility push(default)
 
-static void SurfaceDestroy(void *opaque)
+static_assert(offsetof (vlc_vdp_video_field_t, context) == 0,
+              "Cast assumption failure");
+
+static void SurfaceDestroy(struct picture_context_t *ctx)
 {
-    vlc_vdp_video_field_t *field = opaque;
+    vlc_vdp_video_field_t *field = (vlc_vdp_video_field_t *)ctx;
     vlc_vdp_video_frame_t *frame = field->frame;
     VdpStatus err;
 
@@ -75,7 +78,7 @@ vlc_vdp_video_field_t *vlc_vdp_video_create(vdp_t *vdp,
         return NULL;
     }
 
-    field->destroy = SurfaceDestroy;
+    field->context.destroy = SurfaceDestroy;
     field->frame = frame;
     field->structure = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
     field->procamp = procamp_default;
@@ -99,7 +102,7 @@ VdpStatus vlc_vdp_video_attach(vdp_t *vdp, VdpVideoSurface surface,
         || pic->format.i_chroma == VLC_CODEC_VDPAU_VIDEO_444);
     assert(!picture_IsReferenced(pic));
     assert(pic->context == NULL);
-    pic->context = field;
+    pic->context = &field->context;
     return VDP_STATUS_OK;
 }
 
@@ -110,7 +113,7 @@ vlc_vdp_video_field_t *vlc_vdp_video_copy(vlc_vdp_video_field_t *fold)
     if (unlikely(fnew == NULL))
         return NULL;
 
-    fnew->destroy = SurfaceDestroy;
+    fnew->context.destroy = SurfaceDestroy;
     fnew->frame = frame;
     fnew->structure = fold->structure;
     fnew->procamp = fold->procamp;
diff --git a/modules/hw/vdpau/sharpen.c b/modules/hw/vdpau/sharpen.c
index df7232b0ee..2f89c2b8ba 100644
--- a/modules/hw/vdpau/sharpen.c
+++ b/modules/hw/vdpau/sharpen.c
@@ -61,7 +61,7 @@ static int SharpenCallback(vlc_object_t *obj, const char *varname,
 static picture_t *Sharpen(filter_t *filter, picture_t *pic)
 {
     filter_sys_t *sys = filter->p_sys;
-    vlc_vdp_video_field_t *f = pic->context;
+    vlc_vdp_video_field_t *f = (vlc_vdp_video_field_t *)pic->context;
     union { uint32_t u; float f; } u;
 
     if (unlikely(f == NULL))
diff --git a/modules/hw/vdpau/vlc_vdpau.h b/modules/hw/vdpau/vlc_vdpau.h
index 031124dd0e..16e776d92c 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -208,6 +208,7 @@ void vdp_release_x11(vdp_t *);
 # include <vlc_common.h>
 # include <vlc_fourcc.h>
 # include <vlc_atomic.h>
+# include <vlc_picture.h>
 
 /** Converts VLC YUV format to VDPAU chroma type and YCbCr format */
 static inline
@@ -272,7 +273,7 @@ typedef struct vlc_vdp_video_frame
 
 typedef struct vlc_vdp_video_field
 {
-    void (*destroy)(void *); /* must be first @ref picture_Release() */
+    picture_context_t context;
     vlc_vdp_video_frame_t *frame;
     VdpVideoMixerPictureStructure structure;
     VdpProcamp procamp;
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 0a2dc8f69a..3f37648985 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -86,11 +86,10 @@ static int AllocatePicture( picture_t *p_pic )
 
 static void PictureDestroyContext( picture_t *p_picture )
 {
-    void (**context)( void * ) = p_picture->context;
-    if( context != NULL )
+    picture_context_t *ctx = p_picture->context;
+    if (ctx != NULL)
     {
-        void (*context_destroy)( void * ) = *context;
-        context_destroy( context );
+        ctx->destroy(ctx);
         p_picture->context = NULL;
     }
 }



More information about the vlc-commits mailing list