[vlc-commits] direct_va: store the va_surface in the picture context
Steve Lhomme
git at videolan.org
Mon Sep 2 15:43:23 CEST 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Sep 2 12:41:25 2019 +0200| [377d00bb98538d04447467f47454f3b432a5bada] | committer: Steve Lhomme
direct_va: store the va_surface in the picture context
So that every clone can get/release a reference to the original surface.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=377d00bb98538d04447467f47454f3b432a5bada
---
modules/codec/avcodec/d3d11va.c | 3 ++-
modules/codec/avcodec/dxva2.c | 3 ++-
modules/codec/avcodec/va_surface.c | 21 +++++++++++----------
modules/codec/avcodec/va_surface_internal.h | 4 ++--
4 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 7b3900ea7b..b39f5e19f3 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -208,7 +208,7 @@ done:
return pic_ctx;
}
-static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_index)
+static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_index, vlc_va_surface_t *va_surface)
{
vlc_va_sys_t *sys = va->sys;
ID3D11VideoDecoderOutputView *surface = sys->hw_surface[surface_index];
@@ -235,6 +235,7 @@ static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_ind
* CreatePicContext(), undo one of them otherwise we need an extra release
* when the pool is emptied */
ReleaseD3D11PictureSys(&pic_ctx->picsys);
+ pic_ctx->va_surface = va_surface;
return pic_ctx;
}
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 695b3f63ae..8ac094ecb4 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -193,7 +193,7 @@ static struct va_pic_context *CreatePicContext(IDirect3DSurface9 *surface, IDire
return pic_ctx;
}
-static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_index)
+static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_index, vlc_va_surface_t *va_surface)
{
vlc_va_sys_t *sys = va->sys;
struct va_pic_context *pic_ctx = CreatePicContext(sys->hw_surface[surface_index], sys->hw.decoder);
@@ -203,6 +203,7 @@ static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_ind
* CreatePicContext(), undo one of them otherwise we need an extra release
* when the pool is emptied */
ReleaseD3D9PictureSys(&pic_ctx->picsys);
+ pic_ctx->va_surface = va_surface;
return pic_ctx;
}
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index c3ea01efaa..4d0032d068 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -42,12 +42,13 @@ typedef int VA_PICSYS;
struct vlc_va_surface_t {
atomic_uintptr_t refcount;
+ struct va_pic_context *pic_va_ctx;
};
static void DestroyVideoDecoder(vlc_va_sys_t *sys, va_pool_t *va_pool)
{
for (unsigned i = 0; i < va_pool->surface_count; i++)
- va_surface_Release(va_pool->surface[i]->va_surface);
+ va_surface_Release(va_pool->surface[i]);
va_pool->callbacks->pf_destroy_surfaces(sys);
va_pool->surface_count = 0;
}
@@ -119,17 +120,17 @@ static int SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool, unsigned count)
int err = VLC_ENOMEM;
for (unsigned i = 0; i < va_pool->surface_count; i++) {
- struct vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface));
+ vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface));
if (unlikely(p_surface==NULL))
goto done;
- va_pool->surface[i] = va_pool->callbacks->pf_new_surface_context(va, i);
- if (unlikely(va_pool->surface[i]==NULL))
+ p_surface->pic_va_ctx = va_pool->callbacks->pf_new_surface_context(va, i, p_surface);
+ if (unlikely(p_surface->pic_va_ctx==NULL))
{
free(p_surface);
goto done;
}
- va_pool->surface[i]->va_surface = p_surface;
- atomic_init(&va_pool->surface[i]->va_surface->refcount, 1);
+ va_pool->surface[i] = p_surface;
+ atomic_init(&p_surface->refcount, 1);
}
err = VLC_SUCCESS;
@@ -143,14 +144,14 @@ done:
static picture_context_t *GetSurface(va_pool_t *va_pool)
{
for (unsigned i = 0; i < va_pool->surface_count; i++) {
- struct va_pic_context *surface = va_pool->surface[i];
+ vlc_va_surface_t *surface = va_pool->surface[i];
uintptr_t expected = 1;
- if (atomic_compare_exchange_strong(&surface->va_surface->refcount, &expected, 2))
+ if (atomic_compare_exchange_strong(&surface->refcount, &expected, 2))
{
- picture_context_t *field = surface->s.copy(&surface->s);
+ picture_context_t *field = surface->pic_va_ctx->s.copy(&surface->pic_va_ctx->s);
/* the copy should have added an extra reference */
- atomic_fetch_sub(&surface->va_surface->refcount, 1);
+ atomic_fetch_sub(&surface->refcount, 1);
return field;
}
}
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index f875862258..2f8d6e81e2 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -41,7 +41,7 @@ typedef struct
int surface_width;
int surface_height;
- struct va_pic_context *surface[MAX_SURFACE_COUNT];
+ vlc_va_surface_t *surface[MAX_SURFACE_COUNT];
const struct va_pool_cfg *callbacks;
@@ -71,7 +71,7 @@ struct va_pool_cfg {
/**
* Create a new context for the surface being acquired
*/
- struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, int surface_index);
+ struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, int surface_index, vlc_va_surface_t *);
};
int va_pool_Open(vlc_va_t *, const struct va_pool_cfg *, va_pool_t *);
More information about the vlc-commits
mailing list