[vlc-devel] [PATCH 13/19] picture: pass the opaque pointer to the destroy callback rather than the picture

Steve Lhomme robux4 at ycbcr.xyz
Thu Jul 30 14:16:54 CEST 2020


The resource desctrutor shouldn't have to know much about the picture nor if
it's still allocated or not.

This avoids some container_of in the picture_pool.
---
 include/vlc_picture.h                    |  2 +-
 modules/hw/vaapi/vlc_vaapi.c             |  4 ++--
 modules/hw/vdpau/picture.c               |  4 ++--
 modules/video_chroma/copy.c              |  4 ++--
 modules/video_output/android/display.c   |  4 ++--
 modules/video_output/opengl/interop_sw.c |  4 ++--
 modules/video_output/win32/direct3d11.c  |  4 ++--
 src/misc/picture.c                       | 10 +++++-----
 src/misc/picture_pool.c                  |  5 ++---
 9 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 11c2fc70ac9..178118633d0 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -206,7 +206,7 @@ typedef struct
  */
 typedef struct
 {
-    void (*destroy)(picture_t *);
+    void (*destroy)(void *opaque);
     void *opaque;
 } picture_gc_t;
 
diff --git a/modules/hw/vaapi/vlc_vaapi.c b/modules/hw/vaapi/vlc_vaapi.c
index 1d77a04297a..7d9b545928d 100644
--- a/modules/hw/vaapi/vlc_vaapi.c
+++ b/modules/hw/vaapi/vlc_vaapi.c
@@ -421,9 +421,9 @@ typedef struct
 } picture_sys_t;
 
 static void
-pool_pic_destroy_cb(picture_t *pic)
+pool_pic_destroy_cb(void *opaque)
 {
-    picture_sys_t *p_sys = pic->p_sys;
+    picture_sys_t *p_sys = opaque;
     struct pic_sys_vaapi_instance *instance = p_sys->instance;
 
     if (atomic_fetch_sub(&instance->pic_refcount, 1) == 1)
diff --git a/modules/hw/vdpau/picture.c b/modules/hw/vdpau/picture.c
index 0cc7cbba5c6..fdebcaa9ffb 100644
--- a/modules/hw/vdpau/picture.c
+++ b/modules/hw/vdpau/picture.c
@@ -137,9 +137,9 @@ VdpStatus vlc_vdp_video_attach(vdp_t *vdp, VdpVideoSurface surface,
     return VDP_STATUS_OK;
 }
 
-static void vlc_vdp_output_surface_destroy(picture_t *pic)
+static void vlc_vdp_output_surface_destroy(void *opaque)
 {
-    vlc_vdp_output_surface_t *sys = pic->p_sys;
+    vlc_vdp_output_surface_t *sys = opaque;
 
     vdp_output_surface_destroy(sys->vdp, sys->surface);
     vdp_release_x11(sys->vdp);
diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c
index 9c10d52ecc1..c457730b7fa 100644
--- a/modules/video_chroma/copy.c
+++ b/modules/video_chroma/copy.c
@@ -1095,9 +1095,9 @@ static void piccheck(picture_t *pic, const vlc_chroma_description_t *dsc,
     }
 }
 
-static void pic_rsc_destroy(picture_t *pic)
+static void pic_rsc_destroy(void *opaque)
 {
-    pic_resource_t *rsc = pic->p_sys;
+    pic_resource_t *rsc = opaque;
     for (unsigned i = 0; i < rsc->i_planes; i++)
         free(rsc->p[i].p_pixels);
     free(rsc);
diff --git a/modules/video_output/android/display.c b/modules/video_output/android/display.c
index 3c657324ce5..a257ba1a7f0 100644
--- a/modules/video_output/android/display.c
+++ b/modules/video_output/android/display.c
@@ -172,9 +172,9 @@ static int UpdateVideoSize(vout_display_sys_t *sys, video_format_t *p_fmt)
     return 0;
 }
 
-static void AndroidPicture_Destroy(picture_t *pic)
+static void AndroidPicture_Destroy(void *opaque)
 {
-    free(pic->p_sys);
+    free(opaque);
 }
 
 static picture_t *PictureAlloc(video_format_t *fmt)
diff --git a/modules/video_output/opengl/interop_sw.c b/modules/video_output/opengl/interop_sw.c
index d65345b723a..630d1fbb2b3 100644
--- a/modules/video_output/opengl/interop_sw.c
+++ b/modules/video_output/opengl/interop_sw.c
@@ -51,9 +51,9 @@ struct priv
 };
 
 static void
-pbo_picture_destroy(picture_t *pic)
+pbo_picture_destroy(void *opaque)
 {
-    picture_sys_t *picsys = pic->p_sys;
+    picture_sys_t *picsys = opaque;
 
     picsys->DeleteBuffers(picsys->i_planes, picsys->buffers);
 
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 25576cf43b8..0c5a487ec29 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1243,9 +1243,9 @@ static void Direct3D11DeleteRegions(int count, picture_t **region)
     free(region);
 }
 
-static void DestroyPictureQuad(picture_t *p_picture)
+static void DestroyPictureQuad(void *opaque)
 {
-    D3D11_ReleaseQuad( (d3d_quad_t *) p_picture->p_sys );
+    D3D11_ReleaseQuad( opaque );
 }
 
 static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_count,
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 87f71f6b8cd..149111d74aa 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -54,9 +54,9 @@ static void PictureDestroyContext( picture_t *p_picture )
 /**
  * Destroys a picture allocated with picture_NewFromFormat().
  */
-static void picture_DestroyFromFormat(picture_t *pic)
+static void picture_DestroyFromFormat(void *opaque)
 {
-    picture_buffer_t *res = pic->p_sys;
+    picture_buffer_t *res = opaque;
 
     picture_Deallocate(res->fd, res->base, res->size);
 }
@@ -338,7 +338,7 @@ void picture_Destroy(picture_t *picture)
 
     picture_priv_t *priv = container_of(picture, picture_priv_t, picture);
     if (priv->gc.destroy != NULL)
-        priv->gc.destroy(picture);
+        priv->gc.destroy(priv->gc.opaque);
     free(priv);
 }
 
@@ -409,9 +409,9 @@ void picture_Copy( picture_t *p_dst, const picture_t *p_src )
     picture_CopyProperties( p_dst, p_src );
 }
 
-static void picture_DestroyClone(picture_t *clone)
+static void picture_DestroyClone(void *opaque)
 {
-    picture_t *picture = ((picture_priv_t *)clone)->gc.opaque;
+    picture_t *picture = opaque;
 
     picture_Release(picture);
 }
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 0a2e4eaa433..cf0fe6f76fe 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -65,10 +65,9 @@ void picture_pool_Release(picture_pool_t *pool)
     picture_pool_Destroy(pool);
 }
 
-static void picture_pool_ReleaseClone(picture_t *clone)
+static void picture_pool_ReleaseClone(void *opaque)
 {
-    picture_priv_t *priv = (picture_priv_t *)clone;
-    uintptr_t sys = (uintptr_t)priv->gc.opaque;
+    uintptr_t sys = (uintptr_t)opaque;
     picture_pool_t *pool = (void *)(sys & ~(POOL_MAX - 1));
     unsigned offset = sys & (POOL_MAX - 1);
     picture_t *picture = pool->picture[offset];
-- 
2.26.2



More information about the vlc-devel mailing list