picture: add the video context in the picture context
authorSteve Lhomme <robux4@ycbcr.xyz>
Wed, 13 Nov 2019 07:45:49 +0000 (08:45 +0100)
committerSteve Lhomme <robux4@ycbcr.xyz>
Mon, 2 Dec 2019 12:42:12 +0000 (13:42 +0100)
The creator of the picture_context_t must set the video context if needed.
If set, the picture context must hold a reference to the video context.

When "copying" a picture (using the same surface in another picture context) a
new reference has to be acquired.

Add an inline function to get the video context from a picture.

13 files changed:
include/vlc_picture.h
modules/codec/avcodec/d3d11va.c
modules/codec/avcodec/dxva2.c
modules/codec/avcodec/vaapi.c
modules/codec/vt_utils.c
modules/hw/d3d11/d3d11_deinterlace.c
modules/hw/d3d11/d3d11_surface.c
modules/hw/d3d9/dxa9.c
modules/hw/d3d9/dxva2_deinterlace.c
modules/hw/nvdec/nvdec.c
modules/hw/vaapi/vlc_vaapi.c
modules/hw/vdpau/picture.c
src/misc/picture.c

index 3298630..75a87c8 100644 (file)
@@ -69,6 +69,7 @@ typedef struct picture_context_t
 {
     void (*destroy)(struct picture_context_t *);
     struct picture_context_t *(*copy)(struct picture_context_t *);
+    struct vlc_video_context *vctx;
 } picture_context_t;
 
 typedef struct picture_buffer_t
@@ -161,6 +162,11 @@ struct picture_t
     atomic_uintptr_t refs;
 };
 
+static inline vlc_video_context* picture_GetVideoContext(picture_t *pic)
+{
+    return pic->context ? pic->context->vctx : NULL;
+}
+
 /**
  * This function will create a new picture.
  * The picture created will implement a default release management compatible
index d4319df..7f2c8e8 100644 (file)
@@ -177,6 +177,7 @@ static struct d3d11va_pic_context *CreatePicContext(
         return NULL;
     pic_ctx->ctx.s = (picture_context_t) {
         d3d11va_pic_context_destroy, d3d11va_pic_context_copy,
+        NULL /*TODO*/
     };
 
     D3D11_TEXTURE2D_DESC txDesc;
index 7b42d6a..a3c708e 100644 (file)
@@ -187,6 +187,7 @@ static struct dxva2_pic_context *CreatePicContext(IDirect3DSurface9 *surface)
         return NULL;
     pic_ctx->ctx.s = (picture_context_t) {
         dxva2_pic_context_destroy, dxva2_pic_context_copy,
+        NULL /*TODO*/
     };
     pic_ctx->ctx.picsys.surface = surface;
     AcquireD3D9PictureSys(&pic_ctx->ctx.picsys);
index 36cb5a1..5a5c86c 100644 (file)
@@ -163,6 +163,7 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
     }
     vaapi_ctx->ctx.s = (picture_context_t) {
         vaapi_dec_pic_context_destroy, vaapi_dec_pic_context_copy,
+        NULL /*TODO*/
     };
     vaapi_ctx->ctx.surface = sys->render_targets[va_surface_GetIndex(va_surface)];
     vaapi_ctx->ctx.va_dpy = sys->hw_ctx.display;
index cb71dae..cac1389 100644 (file)
@@ -89,6 +89,7 @@ cvpxpic_attach_common(picture_t *p_pic, CVPixelBufferRef cvpx,
     }
     ctx->s = (picture_context_t) {
         pf_destroy, cvpxpic_copy_cb,
+        NULL // no video context for now
     };
     ctx->cvpx = CVPixelBufferRetain(cvpx);
     ctx->nb_fields = p_pic->i_nb_fields;
index 90215ef..5c58632 100644 (file)
@@ -266,6 +266,7 @@ picture_t *AllocPicture( filter_t *p_filter )
         {
             pic_ctx->s = (picture_context_t) {
                 d3d11_pic_context_destroy, d3d11_pic_context_copy,
+                NULL /*TODO*/
             };
             pic_ctx->picsys = *pic_sys;
             AcquireD3D11PictureSys( &pic_ctx->picsys );
index 9f0a71e..8b24f34 100644 (file)
@@ -585,6 +585,7 @@ static void NV12_D3D11(filter_t *p_filter, picture_t *src, picture_t *dst)
         {
             pic_ctx->s = (picture_context_t) {
                 d3d11_pic_context_destroy, d3d11_pic_context_copy,
+                NULL /*TODO*/
             };
             pic_ctx->picsys = *p_sys;
             AcquireD3D11PictureSys(&pic_ctx->picsys);
index cd1619b..2ff0027 100644 (file)
@@ -272,6 +272,7 @@ static void YV12_D3D9(filter_t *p_filter, picture_t *src, picture_t *dst)
         {
             pic_ctx->s = (picture_context_t) {
                 d3d9_pic_context_destroy, d3d9_pic_context_copy,
+                NULL /*TODO*/
             };
             pic_ctx->picsys = *p_sys;
             AcquireD3D9PictureSys(&pic_ctx->picsys);
index 2564752..48b59a2 100644 (file)
@@ -326,6 +326,7 @@ picture_t *AllocPicture( filter_t *p_filter )
         {
             pic_ctx->s = (picture_context_t) {
                 d3d9_pic_context_destroy, d3d9_pic_context_copy,
+                NULL /*TODO*/
             };
             pic_ctx->picsys = *pic_sys;
             AcquireD3D9PictureSys( &pic_ctx->picsys );
index e82338d..3b22088 100644 (file)
@@ -372,6 +372,7 @@ static int CUDAAPI HandlePictureDisplay(void *p_opaque, CUVIDPARSERDISPINFO *p_d
             goto error;
         picctx->ctx = (picture_context_t) {
             NVDecCtxDestroy, NVDecCtxClone,
+            NULL /*TODO*/
         };
         uintptr_t pool_idx = (uintptr_t)p_pic->p_sys;
         picctx->devidePtr = p_sys->outputDevicePtr[pool_idx];
index 4c4a30d..a871085 100644 (file)
@@ -509,6 +509,7 @@ vlc_vaapi_PoolNew(vlc_object_t *o, vlc_decoder_device *dec_device,
         p_sys->instance = instance;
         p_sys->ctx.ctx.s = (picture_context_t) {
             pic_sys_ctx_destroy_cb, pic_ctx_copy_cb,
+            NULL /*TODO*/
         };
         p_sys->ctx.ctx.surface = instance->render_targets[i];
         p_sys->ctx.ctx.va_dpy = dpy;
index d834d03..e50a3f3 100644 (file)
@@ -96,6 +96,7 @@ vlc_vdp_video_field_t *vlc_vdp_video_create(vdp_t *vdp,
 
     field->context = (picture_context_t) {
         VideoSurfaceDestroy, VideoSurfaceCopy,
+        NULL /*TODO*/
     };
     field->frame = frame;
     field->structure = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
index 3288aa6..990277e 100644 (file)
@@ -43,7 +43,10 @@ static void PictureDestroyContext( picture_t *p_picture )
     picture_context_t *ctx = p_picture->context;
     if (ctx != NULL)
     {
+        vlc_video_context *vctx = ctx->vctx;
         ctx->destroy(ctx);
+        if (vctx)
+            vlc_video_context_Release(vctx);
         p_picture->context = NULL;
     }
 }