[vlc-devel] [PATCH 2/8] avcodec: va: provide the needed picture pool size to the decoder owner
Steve Lhomme
robux4 at ycbcr.xyz
Tue Jul 28 11:08:35 CEST 2020
---
modules/codec/avcodec/d3d11va.c | 7 +++++--
modules/codec/avcodec/dxva2.c | 6 ++++--
modules/codec/avcodec/va.c | 8 +++++---
modules/codec/avcodec/va.h | 6 ++++--
modules/codec/avcodec/vaapi.c | 3 ++-
modules/codec/avcodec/video.c | 7 +++++--
modules/hw/vdpau/avcodec.c | 3 ++-
7 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index c9793a55d1b..ef142cce4ab 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -62,7 +62,8 @@ struct d3d11va_pic_context
#include "directx_va.h"
static int Open(vlc_va_t *, AVCodecContext *, enum PixelFormat hwfmt, const AVPixFmtDescriptor *,
- const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **);
+ const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **,
+ size_t *out_pool_size);
vlc_module_begin()
set_description(N_("Direct3D11 Video Acceleration"))
@@ -246,7 +247,8 @@ static const struct vlc_va_operations ops = { Get, Close, };
static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const AVPixFmtDescriptor *desc,
const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+ video_format_t *fmt_out, vlc_video_context **vtcx_out,
+ size_t *out_pool_size)
{
int err = VLC_EGENERIC;
@@ -316,6 +318,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
va->ops = &ops;
*fmt_out = final_fmt;
*vtcx_out = sys->vctx;
+ *out_pool_size = sys->hw.surface_count;
return VLC_SUCCESS;
error:
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 4a7b62814f9..3fc42f0d716 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -50,7 +50,8 @@ struct dxva2_pic_context
#include "directx_va.h"
static int Open(vlc_va_t *, AVCodecContext *, enum PixelFormat hwfmt, const AVPixFmtDescriptor *,
- const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **);
+ const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **,
+ size_t *out_pool_size);
vlc_module_begin()
set_description(N_("DirectX Video Acceleration (DXVA) 2.0"))
@@ -257,7 +258,7 @@ static const struct vlc_va_operations ops = { Get, Close, };
static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const AVPixFmtDescriptor *desc,
const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+ video_format_t *fmt_out, vlc_video_context **vtcx_out, size_t *out_pool_size)
{
int err = VLC_EGENERIC;
@@ -342,6 +343,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
va->ops = &ops;
*fmt_out = final_fmt;
*vtcx_out = sys->vctx;
+ *out_pool_size = sys->hw.surface_count;
return VLC_SUCCESS;
error:
diff --git a/modules/codec/avcodec/va.c b/modules/codec/avcodec/va.c
index 855d5a67bfb..0e4dac7775f 100644
--- a/modules/codec/avcodec/va.c
+++ b/modules/codec/avcodec/va.c
@@ -109,16 +109,18 @@ static int vlc_va_Start(void *func, bool forced, va_list ap)
vlc_decoder_device *device = va_arg(ap, vlc_decoder_device *);
video_format_t *fmt_out = va_arg(ap, video_format_t *);
vlc_video_context **vtcx_out = va_arg(ap, vlc_video_context **);
+ size_t *out_pool_size = va_arg(ap, size_t *);
vlc_va_open open = func;
(void) forced;
- return open(va, ctx, hwfmt, src_desc, fmt_in, device, fmt_out, vtcx_out);
+ return open(va, ctx, hwfmt, src_desc, fmt_in, device, fmt_out, vtcx_out, out_pool_size);
}
vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
enum PixelFormat hwfmt, const AVPixFmtDescriptor *src_desc,
const es_format_t *fmt_in, vlc_decoder_device *device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+ video_format_t *fmt_out, vlc_video_context **vtcx_out,
+ size_t *out_pool_size)
{
struct vlc_va_t *va = vlc_object_create(obj, sizeof (*va));
if (unlikely(va == NULL))
@@ -127,7 +129,7 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
if (vlc_module_load(va, "hw decoder", NULL, true,
vlc_va_Start, va, avctx, hwfmt, src_desc, fmt_in, device,
- fmt_out, vtcx_out) == NULL)
+ fmt_out, vtcx_out, out_pool_size) == NULL)
{
vlc_object_delete(va);
va = NULL;
diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h
index 564e5edd66b..9ea649c66a3 100644
--- a/modules/codec/avcodec/va.h
+++ b/modules/codec/avcodec/va.h
@@ -46,7 +46,8 @@ struct vlc_va_t {
typedef int (*vlc_va_open)(vlc_va_t *, AVCodecContext *,
enum PixelFormat hwfmt, const AVPixFmtDescriptor *,
const es_format_t *, vlc_decoder_device *,
- video_format_t *, vlc_video_context **);
+ video_format_t *, vlc_video_context **,
+ size_t *out_pool_size);
#define set_va_callback(activate, priority) \
{ \
@@ -74,7 +75,8 @@ bool vlc_va_MightDecode(enum PixelFormat hwfmt, enum PixelFormat swfmt);
vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *,
enum PixelFormat hwfmt, const AVPixFmtDescriptor *,
const es_format_t *fmt, vlc_decoder_device *device,
- video_format_t *, vlc_video_context **vtcx_out);
+ video_format_t *, vlc_video_context **vtcx_out,
+ size_t *out_pool_size);
/**
* Get a hardware video surface for a libavcodec frame.
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index 01d2b350f1a..0e6deb253cd 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -239,7 +239,7 @@ static void VAAPISetupAVCodecContext(void *opaque, AVCodecContext *avctx)
static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const AVPixFmtDescriptor *desc,
const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+ video_format_t *fmt_out, vlc_video_context **vtcx_out, size_t *out_pool_size)
{
VLC_UNUSED(desc);
if ( hwfmt != AV_PIX_FMT_VAAPI_VLD || dec_device == NULL ||
@@ -309,6 +309,7 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, con
va->ops = &ops;
*vtcx_out = sys->vctx;
+ *out_pool_size = count;
return VLC_SUCCESS;
error:
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 688b7587777..3f06982cc7f 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -1744,11 +1744,14 @@ no_reuse:
p_dec->fmt_out.video.i_chroma = 0; // make sure the va sets its output chroma
vlc_video_context *vctx_out;
+ size_t pool_size = 0;
vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, hwfmt, src_desc,
&p_dec->fmt_in, init_device,
- &p_dec->fmt_out.video, &vctx_out);
+ &p_dec->fmt_out.video, &vctx_out, &pool_size);
if (init_device)
vlc_decoder_device_Release(init_device);
+ //va pools have a fixed size and attach to existing pictures so the pool sizes must match
+ assert(pool_size != 0);
vlc_mutex_lock(&p_sys->lock);
if (va == NULL)
continue; /* Unsupported codec profile or such */
@@ -1756,7 +1759,7 @@ no_reuse:
assert(vctx_out != NULL);
p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma;
- if (decoder_UpdateVideoOutput(p_dec, vctx_out, 0))
+ if (decoder_UpdateVideoOutput(p_dec, vctx_out, pool_size))
{
vlc_va_Delete(va);
p_context->hwaccel_context = NULL;
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index c4120039454..6e2a36413ce 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -149,7 +149,7 @@ const struct vlc_video_context_operations vdpau_vctx_ops = {
static int Open(vlc_va_t *va, AVCodecContext *avctx, enum PixelFormat hwfmt, const AVPixFmtDescriptor *desc,
const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+ video_format_t *fmt_out, vlc_video_context **vtcx_out, size_t *out_pool_size)
{
if ( hwfmt != AV_PIX_FMT_VDPAU || GetVDPAUOpaqueDevice(dec_device) == NULL)
return VLC_EGENERIC;
@@ -255,6 +255,7 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, enum PixelFormat hwfmt, con
msg_Info(va, "Using %s", infos);
*vtcx_out = sys->vctx;
+ *out_pool_size = refs;
va->ops = &ops;
return VLC_SUCCESS;
--
2.26.2
More information about the vlc-devel
mailing list