[vlc-devel] [PATCH 3/9] avcodec: vdpau: move the video context resources to a separate structure
Steve Lhomme
robux4 at ycbcr.xyz
Fri Oct 18 17:11:08 CEST 2019
The video context will be alive even when the decoder might be unloaded.
---
modules/hw/vdpau/avcodec.c | 47 +++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index 9f66cd72167..3a6e936052a 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -41,9 +41,15 @@
#include "vlc_vdpau.h"
#include "../../codec/avcodec/va.h"
-struct vlc_va_sys_t
+struct video_context_private
{
vdp_t *vdp;
+ vlc_vdp_video_field_t *pool[];
+};
+
+struct vlc_va_sys_t
+{
+ struct video_context_private vctx_priv;
VdpDevice device;
VdpChromaType type;
void *hwaccel_context;
@@ -52,7 +58,6 @@ struct vlc_va_sys_t
vlc_video_context *vctx;
/* until we can allocate pictures and provide a picture_sys without a VdpOutputSurface */
picture_pool_t *picture_pool;
- vlc_vdp_video_field_t *pool[];
};
static vlc_vdp_video_field_t *CreateSurface(vlc_va_t *va)
@@ -61,18 +66,18 @@ static vlc_vdp_video_field_t *CreateSurface(vlc_va_t *va)
VdpVideoSurface surface;
VdpStatus err;
- err = vdp_video_surface_create(sys->vdp, sys->device, sys->type,
+ err = vdp_video_surface_create(sys->vctx_priv.vdp, sys->device, sys->type,
sys->width, sys->height, &surface);
if (err != VDP_STATUS_OK)
{
msg_Err(va, "%s creation failure: %s", "video surface",
- vdp_get_error_string(sys->vdp, err));
+ vdp_get_error_string(sys->vctx_priv.vdp, err));
return NULL;
}
- vlc_vdp_video_field_t *field = vlc_vdp_video_create(sys->vdp, surface);
+ vlc_vdp_video_field_t *field = vlc_vdp_video_create(sys->vctx_priv.vdp, surface);
if (unlikely(field == NULL))
- vdp_video_surface_destroy(sys->vdp, surface);
+ vdp_video_surface_destroy(sys->vctx_priv.vdp, surface);
return field;
}
@@ -80,7 +85,7 @@ static vlc_vdp_video_field_t *GetSurface(vlc_va_sys_t *sys)
{
vlc_vdp_video_field_t *f;
- for (unsigned i = 0; (f = sys->pool[i]) != NULL; i++)
+ for (unsigned i = 0; (f = sys->vctx_priv.pool[i]) != NULL; i++)
{
uintptr_t expected = 1;
@@ -128,9 +133,9 @@ static void Close(vlc_va_t *va)
vlc_va_sys_t *sys = va->sys;
picture_pool_Release(sys->picture_pool);
- for (unsigned i = 0; sys->pool[i] != NULL; i++)
- vlc_vdp_video_destroy(sys->pool[i]);
- vdp_release_x11(sys->vdp);
+ for (unsigned i = 0; sys->vctx_priv.pool[i] != NULL; i++)
+ vlc_vdp_video_destroy(sys->vctx_priv.pool[i]);
+ vdp_release_x11(sys->vctx_priv.vdp);
vlc_video_context_Release(sys->vctx);
if (sys->hwaccel_context)
av_free(sys->hwaccel_context);
@@ -177,7 +182,7 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
unsigned refs = avctx->refs + 2 * avctx->thread_count + 5;
vlc_va_sys_t *sys = malloc(sizeof (*sys)
- + (refs + 1) * sizeof (sys->pool[0]));
+ + (refs + 1) * sizeof (sys->vctx_priv.pool[0]));
if (unlikely(sys == NULL))
return VLC_ENOMEM;
@@ -185,12 +190,12 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
sys->width = width;
sys->height = height;
sys->hwaccel_context = NULL;
- sys->vdp = dec_device->opaque;
- vdp_hold_x11(sys->vdp, &sys->device);
+ sys->vctx_priv.vdp = dec_device->opaque;
+ vdp_hold_x11(sys->vctx_priv.vdp, &sys->device);
unsigned flags = AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH;
- err = vdp_get_proc_address(sys->vdp, sys->device,
+ err = vdp_get_proc_address(sys->vctx_priv.vdp, sys->device,
VDP_FUNC_ID_GET_PROC_ADDRESS, &func);
if (err != VDP_STATUS_OK)
goto error;
@@ -203,18 +208,18 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
unsigned i = 0;
while (i < refs)
{
- sys->pool[i] = CreateSurface(va);
- if (sys->pool[i] == NULL)
+ sys->vctx_priv.pool[i] = CreateSurface(va);
+ if (sys->vctx_priv.pool[i] == NULL)
break;
i++;
}
- sys->pool[i] = NULL;
+ sys->vctx_priv.pool[i] = NULL;
if (i < avctx->refs + 3u)
{
msg_Err(va, "not enough video RAM");
while (i > 0)
- vlc_vdp_video_destroy(sys->pool[--i]);
+ vlc_vdp_video_destroy(sys->vctx_priv.pool[--i]);
goto error;
}
@@ -227,13 +232,13 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
i, refs);
/* similar to the pool found in converter_vdpau */
- sys->picture_pool = vlc_vdp_output_pool_create(sys->vdp,
+ sys->picture_pool = vlc_vdp_output_pool_create(sys->vctx_priv.vdp,
VDP_RGBA_FORMAT_B8G8R8A8, &fmt->video, i);
if (sys->picture_pool == NULL)
goto error;
const char *infos;
- if (vdp_get_information_string(sys->vdp, &infos) == VDP_STATUS_OK)
+ if (vdp_get_information_string(sys->vctx_priv.vdp, &infos) == VDP_STATUS_OK)
msg_Info(va, "Using %s", infos);
*vtcx_out = sys->vctx;
@@ -245,7 +250,7 @@ error:
picture_pool_Release(sys->picture_pool);
if (sys->hwaccel_context)
av_free(sys->hwaccel_context);
- vdp_release_x11(sys->vdp);
+ vdp_release_x11(sys->vctx_priv.vdp);
free(sys);
return VLC_EGENERIC;
}
--
2.17.1
More information about the vlc-devel
mailing list