[vlc-devel] [PATCH 2/2] vdpau: use a macro to use the picture context

Steve Lhomme robux4 at ycbcr.xyz
Fri Nov 29 13:11:25 CET 2019


Rather than a dirty cast.
---
 modules/hw/vdpau/adjust.c      |  2 +-
 modules/hw/vdpau/chroma.c      | 10 +++++-----
 modules/hw/vdpau/deinterlace.c |  2 +-
 modules/hw/vdpau/sharpen.c     |  2 +-
 modules/hw/vdpau/vlc_vdpau.h   |  5 ++++-
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/modules/hw/vdpau/adjust.c b/modules/hw/vdpau/adjust.c
index d522279c49d..5db0379c285 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 = (vlc_vdp_video_field_t *)pic->context;
+    vlc_vdp_video_field_t *f = VDPAU_FIELD_FROM_PICCTX(pic->context);
 
     if (unlikely(f == NULL))
         return pic;
diff --git a/modules/hw/vdpau/chroma.c b/modules/hw/vdpau/chroma.c
index cae8d96db58..a67ee4e3410 100644
--- a/modules/hw/vdpau/chroma.c
+++ b/modules/hw/vdpau/chroma.c
@@ -296,7 +296,7 @@ static void Flush(filter_t *filter)
 static picture_t *VideoExport(filter_t *filter, picture_t *src, picture_t *dst,
                               VdpYCbCrFormat format)
 {
-    vlc_vdp_video_field_t *field = (vlc_vdp_video_field_t *)src->context;
+    vlc_vdp_video_field_t *field = VDPAU_FIELD_FROM_PICCTX(src->context);
     vlc_vdp_video_frame_t *psys = field->frame;
     VdpStatus err;
     VdpVideoSurface surface = psys->surface;
@@ -443,7 +443,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 = (vlc_vdp_video_field_t *)src->context;
+    vlc_vdp_video_field_t *field = VDPAU_FIELD_FROM_PICCTX(src->context);
     if (field->frame->vdp != sys->vdp)
     {
         video_format_t fmt = src->format;
@@ -508,7 +508,7 @@ static picture_t *Render(filter_t *filter, picture_t *src, bool import)
     dst->b_force = pic_f->b_force;
 
     /* Enable/Disable features */
-    vlc_vdp_video_field_t *f = (vlc_vdp_video_field_t *)(pic_f->context);
+    vlc_vdp_video_field_t *f = VDPAU_FIELD_FROM_PICCTX(pic_f->context);
     const VdpVideoMixerFeature features[] = {
         VDP_VIDEO_MIXER_FEATURE_SHARPNESS,
     };
@@ -635,12 +635,12 @@ static picture_t *Render(filter_t *filter, picture_t *src, bool import)
     for (unsigned i = 0; i < MAX_PAST; i++)
     {
         pic_f = sys->history[(MAX_PAST - 1) - i];
-        past[i] = (pic_f != NULL) ? ((vlc_vdp_video_field_t *)(pic_f->context))->frame->surface : VDP_INVALID_HANDLE;
+        past[i] = (pic_f != NULL) ? VDPAU_FIELD_FROM_PICCTX(pic_f->context)->frame->surface : VDP_INVALID_HANDLE;
     }
     for (unsigned i = 0; i < MAX_FUTURE; i++)
     {
         pic_f = sys->history[(MAX_PAST + 1) + i];
-        future[i] = (pic_f != NULL) ? ((vlc_vdp_video_field_t *)(pic_f->context))->frame->surface : VDP_INVALID_HANDLE;
+        future[i] = (pic_f != NULL) ? VDPAU_FIELD_FROM_PICCTX(pic_f->context)->frame->surface : VDP_INVALID_HANDLE;
     }
 
     err = vdp_video_mixer_render(sys->vdp, sys->mixer, VDP_INVALID_HANDLE,
diff --git a/modules/hw/vdpau/deinterlace.c b/modules/hw/vdpau/deinterlace.c
index c57dcd509da..619c75346c4 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 = (vlc_vdp_video_field_t *)src->context;
+    vlc_vdp_video_field_t *f1 = VDPAU_FIELD_FROM_PICCTX(src->context);
     if (unlikely(f1 == NULL))
         return src;
     if (f1->structure != VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME)
diff --git a/modules/hw/vdpau/sharpen.c b/modules/hw/vdpau/sharpen.c
index 72ccbcedf0c..5e93fc7568c 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 = (vlc_vdp_video_field_t *)pic->context;
+    vlc_vdp_video_field_t *f = VDPAU_FIELD_FROM_PICCTX(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 f467c0d33f0..c7f57b97fa0 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -275,6 +275,9 @@ typedef struct vlc_vdp_video_field
     float sharpen;
 } vlc_vdp_video_field_t;
 
+#define VDPAU_FIELD_FROM_PICCTX(pic_ctx)  \
+    container_of((pic_ctx), vlc_vdp_video_field_t, context)
+
 typedef struct {
     vdp_t              *vdp;
     VdpDevice          device;
@@ -324,7 +327,7 @@ static inline void vlc_vdp_video_destroy(vlc_vdp_video_field_t *f)
 static inline vlc_vdp_video_field_t *vlc_vdp_video_copy(
     vlc_vdp_video_field_t *fold)
 {
-    return (vlc_vdp_video_field_t *)fold->context.copy(&fold->context);
+    return VDPAU_FIELD_FROM_PICCTX(fold->context.copy(&fold->context));
 }
 
 typedef struct vlc_vdp_output_surface
-- 
2.17.1



More information about the vlc-devel mailing list