[vlc-commits] va_surface: pass an opaque pointer to use with callbacks
Steve Lhomme
git at videolan.org
Fri Oct 18 11:02:15 CEST 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Oct 18 10:02:23 2019 +0200| [00aaa32d67d90bde8792dc03148bb2be99e7c33b] | committer: Steve Lhomme
va_surface: pass an opaque pointer to use with callbacks
We need to keep a local copy of the pool configuration now.
+ rename DestroyVideoDecoder to ReleasePoolSurfaces
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=00aaa32d67d90bde8792dc03148bb2be99e7c33b
---
modules/codec/avcodec/d3d11va.c | 11 +++++++----
modules/codec/avcodec/dxva2.c | 11 +++++++----
modules/codec/avcodec/va_surface.c | 23 ++++++++++-------------
modules/codec/avcodec/va_surface_internal.h | 6 ++++--
4 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 5a87aa1e51..ba2c6931b0 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -128,10 +128,11 @@ static int DxSetupOutput(vlc_va_t *, const directx_va_mode_t *, const video_form
static int DxCreateDecoderSurfaces(vlc_va_t *, int codec_id,
const video_format_t *fmt, unsigned surface_count);
-static void DxDestroySurfaces(vlc_va_sys_t *);
+static void DxDestroySurfaces(void *);
-static void SetupAVCodecContext(vlc_va_sys_t *sys)
+static void SetupAVCodecContext(void *opaque)
{
+ vlc_va_sys_t *sys = opaque;
sys->hw.cfg = &sys->cfg;
sys->hw.surface = sys->hw_surface;
sys->hw.context_mutex = sys->d3d_dev.context_mutex;
@@ -339,13 +340,14 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
goto error;
}
- static const struct va_pool_cfg pool_cfg = {
+ struct va_pool_cfg pool_cfg = {
D3dCreateDevice,
D3dDestroyDevice,
DxCreateDecoderSurfaces,
DxDestroySurfaces,
SetupAVCodecContext,
NewSurfacePicContext,
+ sys,
};
sys->va_pool = va_pool_Create(va, &pool_cfg);
@@ -782,8 +784,9 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
return VLC_SUCCESS;
}
-static void DxDestroySurfaces(vlc_va_sys_t *sys)
+static void DxDestroySurfaces(void *opaque)
{
+ vlc_va_sys_t *sys = opaque;
if (sys->hw_surface[0]) {
ID3D11Resource *p_texture;
ID3D11VideoDecoderOutputView_GetResource( sys->hw_surface[0], &p_texture );
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index d06f739799..eed65180e3 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -151,10 +151,11 @@ static int DxSetupOutput(vlc_va_t *, const directx_va_mode_t *, const video_form
static int DxCreateVideoDecoder(vlc_va_t *, int codec_id,
const video_format_t *, unsigned surface_count);
-static void DxDestroyVideoDecoder(vlc_va_sys_t *);
+static void DxDestroyVideoDecoder(void *);
-static void SetupAVCodecContext(vlc_va_sys_t *sys)
+static void SetupAVCodecContext(void *opaque)
{
+ vlc_va_sys_t *sys = opaque;
sys->hw.cfg = &sys->cfg;
sys->hw.surface = sys->hw_surface;
sys->hw.workaround = sys->selected_decoder->workaround;
@@ -324,13 +325,14 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
return VLC_EGENERIC;
}
- static const struct va_pool_cfg pool_cfg = {
+ struct va_pool_cfg pool_cfg = {
D3dCreateDevice,
D3dDestroyDevice,
DxCreateVideoDecoder,
DxDestroyVideoDecoder,
SetupAVCodecContext,
NewSurfacePicContext,
+ sys,
};
sys->va_pool = va_pool_Create(va, &pool_cfg);
@@ -684,8 +686,9 @@ error:
return VLC_EGENERIC;
}
-static void DxDestroyVideoDecoder(vlc_va_sys_t *sys)
+static void DxDestroyVideoDecoder(void *opaque)
{
+ vlc_va_sys_t *sys = opaque;
/* releases a reference on each decoder surface */
if (sys->hw.decoder)
IDirectXVideoDecoder_Release(sys->hw.decoder);
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index aac1634445..9f9c957836 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -49,7 +49,7 @@ struct va_pool_t
vlc_va_surface_t *surface[MAX_SURFACE_COUNT];
- const struct va_pool_cfg *callbacks;
+ struct va_pool_cfg callbacks;
};
struct vlc_va_surface_t {
@@ -57,11 +57,11 @@ struct vlc_va_surface_t {
picture_context_t *pic_va_ctx;
};
-static void DestroyVideoDecoder(vlc_va_sys_t *sys, va_pool_t *va_pool)
+static void ReleasePoolSurfaces(va_pool_t *va_pool)
{
for (unsigned i = 0; i < va_pool->surface_count; i++)
va_surface_Release(va_pool->surface[i]);
- va_pool->callbacks->pf_destroy_surfaces(sys);
+ va_pool->callbacks.pf_destroy_surfaces(va_pool->callbacks.opaque);
va_pool->surface_count = 0;
}
@@ -83,7 +83,7 @@ int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext
}
/* */
- DestroyVideoDecoder(va->sys, va_pool);
+ ReleasePoolSurfaces(va_pool);
/* */
msg_Dbg(va, "va_pool_SetupDecoder id %d %dx%d count: %d", avctx->codec_id, avctx->coded_width, avctx->coded_height, count);
@@ -91,7 +91,7 @@ int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext
if (count > MAX_SURFACE_COUNT)
return VLC_EGENERIC;
- err = va_pool->callbacks->pf_create_decoder_surfaces(va, avctx->codec_id, fmt, count);
+ err = va_pool->callbacks.pf_create_decoder_surfaces(va, avctx->codec_id, fmt, count);
if (err == VLC_SUCCESS)
{
va_pool->surface_width = fmt->i_width;
@@ -114,7 +114,7 @@ static int SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool)
vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface));
if (unlikely(p_surface==NULL))
goto done;
- p_surface->pic_va_ctx = va_pool->callbacks->pf_new_surface_context(va, i, p_surface);
+ 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);
@@ -127,7 +127,7 @@ static int SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool)
done:
if (err == VLC_SUCCESS)
- va_pool->callbacks->pf_setup_avcodec_ctx(va->sys);
+ va_pool->callbacks.pf_setup_avcodec_ctx(va_pool->callbacks.opaque);
return err;
}
@@ -187,11 +187,8 @@ void va_surface_Release(vlc_va_surface_t *surface)
void va_pool_Close(vlc_va_t *va, va_pool_t *va_pool)
{
- if (va_pool->callbacks)
- {
- DestroyVideoDecoder(va->sys, va_pool);
- va_pool->callbacks->pf_destroy_device(va);
- }
+ ReleasePoolSurfaces(va_pool);
+ va_pool->callbacks.pf_destroy_device(va);
}
va_pool_t * va_pool_Create(vlc_va_t *va, const struct va_pool_cfg *cbs)
@@ -200,7 +197,7 @@ va_pool_t * va_pool_Create(vlc_va_t *va, const struct va_pool_cfg *cbs)
if (unlikely(va_pool == NULL))
return NULL;
- va_pool->callbacks = cbs;
+ va_pool->callbacks = *cbs;
/* */
if (cbs->pf_create_device(va)) {
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index e4d974e599..e9bb532503 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -49,16 +49,18 @@ struct va_pool_cfg {
/**
* Destroy resources allocated with the surfaces and the associated decoder
*/
- void (*pf_destroy_surfaces)(vlc_va_sys_t *);
+ void (*pf_destroy_surfaces)(void *opaque);
/**
* Set the avcodec hw context after the decoder is created
*/
- void (*pf_setup_avcodec_ctx)(vlc_va_sys_t *);
+ void (*pf_setup_avcodec_ctx)(void *opaque);
/**
* Create a new context for the surface being acquired
*/
picture_context_t* (*pf_new_surface_context)(vlc_va_t *, int surface_index, vlc_va_surface_t *);
+
+ void *opaque;
};
va_pool_t * va_pool_Create(vlc_va_t *, const struct va_pool_cfg *);
More information about the vlc-commits
mailing list