* [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools
@ 2023-12-20 7:10 Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 02/12] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
` (11 more replies)
0 siblings, 12 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Add AVQSVFramesContext.info and update the description
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
Rebased https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=9639
against the latest master with a few changes.
doc/APIchanges | 3 +++
libavutil/hwcontext_qsv.c | 4 ++--
libavutil/hwcontext_qsv.h | 31 +++++++++++++++++++++++++++----
libavutil/version.h | 2 +-
4 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index a3e4ebbccd..b68156ee94 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
API changes, most recent first:
+2023-12-xx - xxxxxxxxxx - lavu 58.36.100 - hwcontext_qsv.h
+ Add AVQSVFramesContext.info
+
2023-12-18 - 74279227dd2 - lavc 60.36.100 - packet.h
Add AV_PKT_DATA_IAMF_MIX_GAIN_PARAM, AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
and AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM.
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index a67552b5ac..071489f070 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -613,7 +613,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
QSVFramesContext *s = ctx->internal->priv;
AVQSVFramesContext *hwctx = ctx->hwctx;
mfxFrameInfo *i = &req->Info;
- mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
+ mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info : hwctx->info;
if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
!(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
@@ -1173,7 +1173,7 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
par.AsyncDepth = 1;
- par.vpp.In = frames_hwctx->surfaces[0].Info;
+ par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info : *frames_hwctx->info;
/* Apparently VPP requires the frame rate to be set to some value, otherwise
* init will fail (probably for the framerate conversion filter). Since we
diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
index e2dba8ad83..5950e38500 100644
--- a/libavutil/hwcontext_qsv.h
+++ b/libavutil/hwcontext_qsv.h
@@ -25,8 +25,8 @@
* @file
* An API-specific header for AV_HWDEVICE_TYPE_QSV.
*
- * This API does not support dynamic frame pools. AVHWFramesContext.pool must
- * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 struct.
+ * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer points
+ * to a mfxFrameSurface1 struct.
*/
/**
@@ -51,11 +51,34 @@ typedef struct AVQSVDeviceContext {
* This struct is allocated as AVHWFramesContext.hwctx
*/
typedef struct AVQSVFramesContext {
- mfxFrameSurface1 *surfaces;
+ /**
+ * A pointer to a mfxFrameSurface1 or mfxFrameInfo struct
+ *
+ * When nb_surfaces is non-zero, it is a pointer to a mfxFrameSurface1
+ * struct.
+ *
+ * When nb_surfaces is 0, it is a pointer to a mfxFrameInfo struct, all
+ * buffers allocated from the pool have the same mfxFrameInfo.
+ */
+ union {
+ mfxFrameSurface1 *surfaces;
+ mfxFrameInfo *info;
+ };
+
+ /**
+ * Number of frames in the pool
+ *
+ * It is 0 for dynamic frame pools or AVHWFramesContext.initial_pool_size
+ * for fixed frame pools.
+ *
+ * Note only oneVPL GPU runtime 2.9+ can support dynamic frame pools
+ * on d3d11va or vaapi
+ */
int nb_surfaces;
/**
- * A combination of MFX_MEMTYPE_* describing the frame pool.
+ * Set by user. It is a combination of MFX_MEMTYPE_* describing the frame
+ * pool.
*/
int frame_type;
} AVQSVFramesContext;
diff --git a/libavutil/version.h b/libavutil/version.h
index 7664cd97bd..3b4c50e9a9 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 58
-#define LIBAVUTIL_VERSION_MINOR 35
+#define LIBAVUTIL_VERSION_MINOR 36
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 02/12] lavu/hwcontext_qsv: create dynamic frame pool if required
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 03/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
` (10 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
When AVHWFramesContext.initial_pool_size is 0, a dynamic frame pool is
required. We may support this under certain conditions, e.g. oneVPL 2.9+
support dynamic frame allocation, we needn't provide a fixed frame pool
in the mfxFrameAllocator.Alloc callback.
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavutil/hwcontext_qsv.c | 157 +++++++++++++++++++++++++++++++++++++-
1 file changed, 154 insertions(+), 3 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 071489f070..3922ba3ec0 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -104,8 +104,15 @@ typedef struct QSVFramesContext {
#endif
AVFrame realigned_upload_frame;
AVFrame realigned_download_frame;
+
+ mfxFrameInfo frame_info;
} QSVFramesContext;
+typedef struct QSVSurface {
+ mfxFrameSurface1 mfx_surface;
+ AVFrame *child_frame;
+} QSVSurface;
+
static const struct {
enum AVPixelFormat pix_fmt;
uint32_t fourcc;
@@ -151,6 +158,8 @@ extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
enum AVHWDeviceType base_dev_type,
void **base_handle);
+static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf);
+
/**
* Caller needs to allocate enough space for base_handle pointer.
**/
@@ -359,7 +368,32 @@ static void qsv_pool_release_dummy(void *opaque, uint8_t *data)
{
}
-static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
+static void qsv_pool_release(void *opaque, uint8_t *data)
+{
+ AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
+ QSVFramesContext *s = ctx->internal->priv;
+ QSVSurface *qsv_surface = (QSVSurface *)data;
+ mfxHDLPair *hdl_pair = (mfxHDLPair *)qsv_surface->mfx_surface.Data.MemId;
+ AVHWFramesContext *child_frames_ctx;
+
+ if (!s->child_frames_ref)
+ return;
+
+ child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+ if (!child_frames_ctx->device_ctx)
+ return;
+
+#if CONFIG_VAAPI
+ if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI)
+ av_freep(&hdl_pair->first);
+#endif
+
+ av_freep(&hdl_pair);
+ av_frame_free(&qsv_surface->child_frame);
+ av_freep(&qsv_surface);
+}
+
+static AVBufferRef *qsv_fixed_pool_alloc(void *opaque, size_t size)
{
AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
QSVFramesContext *s = ctx->internal->priv;
@@ -374,6 +408,104 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
return NULL;
}
+static AVBufferRef *qsv_dynamic_pool_alloc(void *opaque, size_t size)
+{
+ AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
+ QSVFramesContext *s = ctx->internal->priv;
+ AVHWFramesContext *child_frames_ctx;
+ QSVSurface *qsv_surface = NULL;
+ mfxHDLPair *handle_pairs_internal = NULL;
+ int ret;
+
+ if (!s->child_frames_ref)
+ goto fail;
+
+ child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+ if (!child_frames_ctx->device_ctx)
+ goto fail;
+
+#if CONFIG_DXVA2
+ if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) {
+ av_log(ctx, AV_LOG_ERROR,
+ "QSV on dxva2 requires a fixed frame pool size\n");
+ goto fail;
+ }
+#endif
+
+ qsv_surface = av_calloc(1, sizeof(*qsv_surface));
+ if (!qsv_surface)
+ goto fail;
+
+ qsv_surface->child_frame = av_frame_alloc();
+ if (!qsv_surface->child_frame)
+ goto fail;
+
+ ret = av_hwframe_get_buffer(s->child_frames_ref, qsv_surface->child_frame, 0);
+ if (ret < 0)
+ goto fail;
+
+ handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+ if (!handle_pairs_internal)
+ goto fail;
+
+ ret = qsv_init_surface(ctx, &qsv_surface->mfx_surface);
+ if (ret < 0)
+ goto fail;
+
+#if CONFIG_VAAPI
+ if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI) {
+ VASurfaceID *surface_id_internal;
+
+ surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+ if (!surface_id_internal)
+ goto fail;
+
+ *surface_id_internal = (VASurfaceID)(uintptr_t)qsv_surface->child_frame->data[3];
+ handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+ handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+ }
+#endif
+
+#if CONFIG_D3D11VA
+ if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
+ AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx;
+ handle_pairs_internal->first = (mfxMemId)qsv_surface->child_frame->data[0];
+
+ if (child_frames_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET)
+ handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+ else
+ handle_pairs_internal->second = (mfxMemId)qsv_surface->child_frame->data[1];
+
+ }
+#endif
+
+ qsv_surface->mfx_surface.Data.MemId = (mfxMemId)handle_pairs_internal;
+ return av_buffer_create((uint8_t *)qsv_surface, sizeof(*qsv_surface),
+ qsv_pool_release, ctx, 0);
+
+fail:
+ if (qsv_surface) {
+ av_frame_free(&qsv_surface->child_frame);
+ }
+
+ av_freep(&qsv_surface);
+ av_freep(&handle_pairs_internal);
+
+ return NULL;
+}
+
+static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
+{
+ AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
+ AVQSVFramesContext *hwctx = ctx->hwctx;
+
+ if (hwctx->nb_surfaces == 0) {
+ return qsv_dynamic_pool_alloc(opaque, size);
+ } else {
+ return qsv_fixed_pool_alloc(opaque, size);
+ }
+}
+
static int qsv_init_child_ctx(AVHWFramesContext *ctx)
{
AVQSVFramesContext *hwctx = ctx->hwctx;
@@ -562,9 +694,28 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc)
int i, ret = 0;
- if (ctx->initial_pool_size <= 0) {
- av_log(ctx, AV_LOG_ERROR, "QSV requires a fixed frame pool size\n");
+ if (ctx->initial_pool_size < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame pool size\n");
return AVERROR(EINVAL);
+ } else if (ctx->initial_pool_size == 0) {
+ mfxFrameSurface1 mfx_surf1;
+
+ ret = qsv_init_child_ctx(ctx);
+ if (ret < 0)
+ return ret;
+
+ ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1),
+ ctx, qsv_pool_alloc, NULL);
+ if (!ctx->internal->pool_internal)
+ return AVERROR(ENOMEM);
+
+ memset(&mfx_surf1, 0, sizeof(mfx_surf1));
+ qsv_init_surface(ctx, &mfx_surf1);
+ s->frame_info = mfx_surf1.Info;
+ frames_hwctx->info = &s->frame_info;
+ frames_hwctx->nb_surfaces = 0;
+
+ return 0;
}
s->handle_pairs_internal = av_calloc(ctx->initial_pool_size,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 03/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 02/12] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 04/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
` (9 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Allow the source is a dynamic frame pool
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavutil/hwcontext_qsv.c | 61 ++++++++++++++++++++++++++++++++++-----
1 file changed, 54 insertions(+), 7 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 3922ba3ec0..3259cd38ba 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1938,18 +1938,52 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
return 0;
}
-static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
- AVHWFramesContext *src_ctx, int flags)
+static int qsv_dynamic_frames_derive_to(AVHWFramesContext *dst_ctx,
+ AVHWFramesContext *src_ctx, int flags)
{
QSVFramesContext *s = dst_ctx->internal->priv;
AVQSVFramesContext *dst_hwctx = dst_ctx->hwctx;
- int i;
+ mfxFrameSurface1 mfx_surf1;
- if (src_ctx->initial_pool_size == 0) {
- av_log(dst_ctx, AV_LOG_ERROR, "Only fixed-size pools can be "
- "mapped to QSV frames.\n");
- return AVERROR(EINVAL);
+ switch (src_ctx->device_ctx->type) {
+#if CONFIG_VAAPI
+ case AV_HWDEVICE_TYPE_VAAPI:
+ dst_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+ break;
+#endif
+
+#if CONFIG_D3D11VA
+ case AV_HWDEVICE_TYPE_D3D11VA:
+ {
+ AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+ if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+ dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
+ } else {
+ dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+ }
}
+ break;
+#endif
+
+ default:
+ return AVERROR(ENOSYS);
+ }
+
+ memset(&mfx_surf1, 0, sizeof(mfx_surf1));
+ qsv_init_surface(dst_ctx, &mfx_surf1);
+ s->frame_info = mfx_surf1.Info;
+ dst_hwctx->info = &s->frame_info;
+ dst_hwctx->nb_surfaces = 0;
+ return 0;
+}
+
+static int qsv_fixed_frames_derive_to(AVHWFramesContext *dst_ctx,
+ AVHWFramesContext *src_ctx, int flags)
+{
+ QSVFramesContext *s = dst_ctx->internal->priv;
+ AVQSVFramesContext *dst_hwctx = dst_ctx->hwctx;
+ int i;
switch (src_ctx->device_ctx->type) {
#if CONFIG_VAAPI
@@ -2041,6 +2075,19 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
return 0;
}
+static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
+ AVHWFramesContext *src_ctx, int flags)
+{
+ if (src_ctx->initial_pool_size < 0) {
+ av_log(dst_ctx, AV_LOG_ERROR, "Invalid src frame pool. \n");
+ return AVERROR(EINVAL);
+ } else if (src_ctx->initial_pool_size == 0) {
+ return qsv_dynamic_frames_derive_to(dst_ctx, src_ctx, flags);
+ } else {
+ return qsv_fixed_frames_derive_to(dst_ctx, src_ctx, flags);
+ }
+}
+
static int qsv_map_to(AVHWFramesContext *dst_ctx,
AVFrame *dst, const AVFrame *src, int flags)
{
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 04/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 02/12] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 03/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 05/12] lavc/qsv: fix the mfx allocator to support dynamic frame pools Xiang, Haihao
` (8 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavutil/hwcontext_qsv.c | 131 +++++++++++++++++++++++++++++++++++++-
1 file changed, 129 insertions(+), 2 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 3259cd38ba..2e75f5ca0b 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -2088,8 +2088,8 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
}
}
-static int qsv_map_to(AVHWFramesContext *dst_ctx,
- AVFrame *dst, const AVFrame *src, int flags)
+static int qsv_fixed_pool_map_to(AVHWFramesContext *dst_ctx,
+ AVFrame *dst, const AVFrame *src, int flags)
{
AVQSVFramesContext *hwctx = dst_ctx->hwctx;
int i, err, index = -1;
@@ -2148,6 +2148,133 @@ static int qsv_map_to(AVHWFramesContext *dst_ctx,
return 0;
}
+static void qsv_dynamic_pool_unmap(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
+{
+ mfxFrameSurface1 *surfaces_internal = (mfxFrameSurface1 *)hwmap->priv;
+ mfxHDLPair *handle_pairs_internal = (mfxHDLPair *)surfaces_internal->Data.MemId;
+ AVHWFramesContext *src_ctx = (AVHWFramesContext *)ctx->internal->source_frames->data;
+
+ switch (src_ctx->format) {
+#if CONFIG_VAAPI
+ case AV_PIX_FMT_VAAPI:
+ {
+ av_freep(&handle_pairs_internal->first);
+
+ break;
+ }
+#endif
+
+#if CONFIG_D3D11VA
+ case AV_PIX_FMT_D3D11:
+ {
+ /* Do nothing */
+ break;
+ }
+#endif
+ default:
+ av_log(ctx, AV_LOG_ERROR, "Should not reach here. \n");
+ break;
+ }
+
+ av_freep(&handle_pairs_internal);
+ av_freep(&surfaces_internal);
+}
+
+static int qsv_dynamic_pool_map_to(AVHWFramesContext *dst_ctx,
+ AVFrame *dst, const AVFrame *src, int flags)
+{
+ mfxFrameSurface1 *surfaces_internal = NULL;
+ mfxHDLPair *handle_pairs_internal = NULL;
+ int ret = 0;
+
+ surfaces_internal = av_calloc(1, sizeof(*surfaces_internal));
+ if (!surfaces_internal) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+ if (!handle_pairs_internal) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ ret = qsv_init_surface(dst_ctx, surfaces_internal);
+ if (ret < 0)
+ goto fail;
+
+ switch (src->format) {
+#if CONFIG_VAAPI
+ case AV_PIX_FMT_VAAPI:
+ {
+ VASurfaceID *surface_id_internal;
+
+ surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+ if (!surface_id_internal) {
+ ret =AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ *surface_id_internal = (VASurfaceID)(uintptr_t)src->data[3];
+ handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+ handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+
+ break;
+ }
+#endif
+
+#if CONFIG_D3D11VA
+ case AV_PIX_FMT_D3D11:
+ {
+ AVHWFramesContext *src_ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;
+ AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+ handle_pairs_internal->first = (mfxMemId)src->data[0];
+
+ if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+ handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+ } else {
+ handle_pairs_internal->second = (mfxMemId)src->data[1];
+ }
+
+ break;
+ }
+#endif
+ default:
+ ret = AVERROR(ENOSYS);
+ goto fail;
+ }
+
+ surfaces_internal->Data.MemId = (mfxMemId)handle_pairs_internal;
+
+ ret = ff_hwframe_map_create(dst->hw_frames_ctx,
+ dst, src, qsv_dynamic_pool_unmap, surfaces_internal);
+ if (ret)
+ goto fail;
+
+ dst->width = src->width;
+ dst->height = src->height;
+ dst->data[3] = (uint8_t*)surfaces_internal;
+
+ return 0;
+
+fail:
+ av_freep(&handle_pairs_internal);
+ av_freep(&surfaces_internal);
+ return ret;
+}
+
+static int qsv_map_to(AVHWFramesContext *dst_ctx,
+ AVFrame *dst, const AVFrame *src, int flags)
+{
+ AVQSVFramesContext *hwctx = dst_ctx->hwctx;
+
+ if (hwctx->nb_surfaces)
+ return qsv_fixed_pool_map_to(dst_ctx, dst, src, flags);
+ else
+ return qsv_dynamic_pool_map_to(dst_ctx, dst, src, flags);
+}
+
static int qsv_frames_get_constraints(AVHWDeviceContext *ctx,
const void *hwconfig,
AVHWFramesConstraints *constraints)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 05/12] lavc/qsv: fix the mfx allocator to support dynamic frame pools
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (2 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 04/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 06/12] lavc/qsvenc: use the right info to config encoding parameters Xiang, Haihao
` (7 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Lock()/Unlock() aren't called to map/unmap data to system memory, so the
array of QSVMid is not needed.
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavcodec/qsv.c | 70 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 57 insertions(+), 13 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 7563625627..e9410d417e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -839,8 +839,16 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)ctx->hw_frames_ctx->data;
AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
mfxFrameInfo *i = &req->Info;
- mfxFrameInfo *i1 = &frames_hwctx->surfaces[0].Info;
+ mfxFrameInfo *i1;
+ if (!frames_hwctx->nb_surfaces) {
+ av_log(ctx->logctx, AV_LOG_DEBUG,
+ "Dynamic frame pools, no frame is pre-allocated\n");
+
+ return MFX_ERR_NONE;
+ }
+
+ i1 = &frames_hwctx->surfaces[0].Info;
if (i->Width > i1->Width || i->Height > i1->Height ||
i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
av_log(ctx->logctx, AV_LOG_ERROR, "Mismatching surface properties in an "
@@ -859,12 +867,16 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
} else if (req->Type & MFX_MEMTYPE_INTERNAL_FRAME) {
/* internal frames -- allocate a new hw frames context */
AVHWFramesContext *ext_frames_ctx = (AVHWFramesContext*)ctx->hw_frames_ctx->data;
+ AVQSVFramesContext *ext_frames_hwctx = ext_frames_ctx->hwctx;
mfxFrameInfo *i = &req->Info;
AVBufferRef *frames_ref, *mids_buf;
AVHWFramesContext *frames_ctx;
AVQSVFramesContext *frames_hwctx;
+ if (!ext_frames_hwctx->nb_surfaces)
+ return MFX_ERR_UNSUPPORTED;
+
frames_ref = av_hwframe_ctx_alloc(ext_frames_ctx->device_ref);
if (!frames_ref)
return MFX_ERR_MEMORY_ALLOC;
@@ -912,6 +924,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
{
+ if (!resp->mids)
+ return MFX_ERR_NONE;
+
av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]);
av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual + 1]);
av_freep(&resp->mids);
@@ -920,11 +935,20 @@ static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
{
- QSVMid *qsv_mid = mid;
- AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
- AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
+ QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+ AVHWFramesContext *frames_ctx = (AVHWFramesContext*)ctx->hw_frames_ctx->data;
+ AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+ QSVMid *qsv_mid;
+ AVHWFramesContext *hw_frames_ctx;
+ AVQSVFramesContext *hw_frames_hwctx;
int ret;
+ if (!frames_hwctx->nb_surfaces)
+ return MFX_ERR_UNSUPPORTED;
+
+ qsv_mid = mid;
+ hw_frames_ctx = (AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
+ hw_frames_hwctx = hw_frames_ctx->hwctx;
if (qsv_mid->locked_frame)
return MFX_ERR_UNDEFINED_BEHAVIOR;
@@ -977,8 +1001,15 @@ fail:
static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
{
- QSVMid *qsv_mid = mid;
+ QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+ AVHWFramesContext *frames_ctx = (AVHWFramesContext*)ctx->hw_frames_ctx->data;
+ AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+ QSVMid *qsv_mid;
+ if (!frames_hwctx->nb_surfaces)
+ return MFX_ERR_UNSUPPORTED;
+
+ qsv_mid = mid;
av_frame_free(&qsv_mid->locked_frame);
av_frame_free(&qsv_mid->hw_frame);
@@ -987,9 +1018,18 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
{
- QSVMid *qsv_mid = (QSVMid*)mid;
+ QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+ AVHWFramesContext *frames_ctx = (AVHWFramesContext*)ctx->hw_frames_ctx->data;
+ AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
- mfxHDLPair *pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+ mfxHDLPair *pair_src;
+
+ if (frames_hwctx->nb_surfaces) {
+ QSVMid *qsv_mid = (QSVMid*)mid;
+ pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+ } else {
+ pair_src = (mfxHDLPair*)mid;
+ }
pair_dst->first = pair_src->first;
@@ -1103,14 +1143,18 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession,
if (!opaque) {
qsv_frames_ctx->logctx = avctx;
+ av_buffer_unref(&qsv_frames_ctx->mids_buf);
+ qsv_frames_ctx->mids = NULL;
+ qsv_frames_ctx->nb_mids = 0;
/* allocate the memory ids for the external frames */
- av_buffer_unref(&qsv_frames_ctx->mids_buf);
- qsv_frames_ctx->mids_buf = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx);
- if (!qsv_frames_ctx->mids_buf)
- return AVERROR(ENOMEM);
- qsv_frames_ctx->mids = (QSVMid*)qsv_frames_ctx->mids_buf->data;
- qsv_frames_ctx->nb_mids = frames_hwctx->nb_surfaces;
+ if (frames_hwctx->nb_surfaces) {
+ qsv_frames_ctx->mids_buf = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx);
+ if (!qsv_frames_ctx->mids_buf)
+ return AVERROR(ENOMEM);
+ qsv_frames_ctx->mids = (QSVMid*)qsv_frames_ctx->mids_buf->data;
+ qsv_frames_ctx->nb_mids = frames_hwctx->nb_surfaces;
+ }
err = MFXVideoCORE_SetFrameAllocator(session, &frame_allocator);
if (err != MFX_ERR_NONE)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 06/12] lavc/qsvenc: use the right info to config encoding parameters
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (3 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 05/12] lavc/qsv: fix the mfx allocator to support dynamic frame pools Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 07/12] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
` (6 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavcodec/qsvenc.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index a0144b0760..0f7e7eb85a 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -718,8 +718,9 @@ static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q)
if (avctx->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
- q->param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
- q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+ mfxFrameInfo *info = frames_hwctx->nb_surfaces ? &frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+ q->param.mfx.FrameInfo.Width = info->Width;
+ q->param.mfx.FrameInfo.Height = info->Height;
}
if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
@@ -842,8 +843,9 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
if (avctx->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
- q->param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
- q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+ mfxFrameInfo *info = frames_hwctx->nb_surfaces ? &frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+ q->param.mfx.FrameInfo.Width = info->Width;
+ q->param.mfx.FrameInfo.Height = info->Height;
}
if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 07/12] lavc/qsvdec: require a dynamic frame pool if possible
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (4 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 06/12] lavc/qsvenc: use the right info to config encoding parameters Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 08/12] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools Xiang, Haihao
` (5 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
This allows a downstream element stores more frames from qsv decoders
and fixes error in get_buffer()
$ ffmpeg -hwaccel qsv -hwaccel_output_format qsv -i input.mp4 -vf
reverse -f null -
[vist#0:0/h264 @ 0x562248f12c50] Decoding error: Cannot allocate memory
[h264_qsv @ 0x562248f66b10] get_buffer() failed
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavcodec/qsvdec.c | 57 +++++++++++++++++++++++++++++++++++----------
1 file changed, 45 insertions(+), 12 deletions(-)
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 559f63698a..3895b3a168 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -42,6 +42,7 @@
#include "libavutil/imgutils.h"
#include "libavutil/film_grain_params.h"
#include "libavutil/mastering_display_metadata.h"
+#include "libavutil/avassert.h"
#include "avcodec.h"
#include "codec_internal.h"
@@ -67,6 +68,8 @@ static const AVRational mfx_tb = { 1, 90000 };
AV_NOPTS_VALUE : pts_tb.num ? \
av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
typedef struct QSVAsyncFrame {
mfxSyncPoint *sync;
QSVFrame *frame;
@@ -76,6 +79,7 @@ typedef struct QSVContext {
// the session used for decoding
mfxSession session;
mfxVersion ver;
+ mfxHandleType handle_type;
// the session we allocated internally, in case the caller did not provide
// one
@@ -182,6 +186,7 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses
AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
{
int ret;
+ mfxIMPL impl;
if (q->gpu_copy == MFX_GPUCOPY_ON &&
!(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
@@ -239,27 +244,52 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses
q->session = q->internal_qs.session;
}
- if (MFXQueryVersion(q->session, &q->ver) != MFX_ERR_NONE) {
- av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
- q->session = NULL;
+ if (MFXQueryIMPL(q->session, &impl) == MFX_ERR_NONE) {
+ switch (MFX_IMPL_VIA_MASK(impl)) {
+ case MFX_IMPL_VIA_VAAPI:
+ q->handle_type = MFX_HANDLE_VA_DISPLAY;
+ break;
- if (q->internal_qs.session) {
- MFXClose(q->internal_qs.session);
- q->internal_qs.session = NULL;
- }
+ case MFX_IMPL_VIA_D3D11:
+ q->handle_type = MFX_HANDLE_D3D11_DEVICE;
+ break;
+
+ case MFX_IMPL_VIA_D3D9:
+ q->handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+ break;
- if (q->internal_qs.loader) {
- MFXUnload(q->internal_qs.loader);
- q->internal_qs.loader = NULL;
+ default:
+ av_assert0(!"should not reach here");
}
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Error querying the implementation. \n");
+ goto fail;
+ }
- return AVERROR_EXTERNAL;
+ if (MFXQueryVersion(q->session, &q->ver) != MFX_ERR_NONE) {
+ av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
+ goto fail;
}
/* make sure the decoder is uninitialized */
MFXVideoDECODE_Close(q->session);
return 0;
+
+fail:
+ q->session = NULL;
+
+ if (q->internal_qs.session) {
+ MFXClose(q->internal_qs.session);
+ q->internal_qs.session = NULL;
+ }
+
+ if (q->internal_qs.loader) {
+ MFXUnload(q->internal_qs.loader);
+ q->internal_qs.loader = NULL;
+ }
+
+ return AVERROR_EXTERNAL;
}
static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
@@ -309,7 +339,10 @@ static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel
hwframes_ctx->height = FFALIGN(avctx->coded_height, 32);
hwframes_ctx->format = AV_PIX_FMT_QSV;
hwframes_ctx->sw_format = avctx->sw_pix_fmt;
- hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + avctx->extra_hw_frames;
+ if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && q->handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER)
+ hwframes_ctx->initial_pool_size = 0;
+ else
+ hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + avctx->extra_hw_frames;
frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 08/12] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (5 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 07/12] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 09/12] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
` (4 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavfilter/qsvvpp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 5cdba7d54a..d09140d89b 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -307,7 +307,7 @@ static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, AVFilterLink *link)
frames_ctx = (AVHWFramesContext *)link->hw_frames_ctx->data;
frames_hwctx = frames_ctx->hwctx;
- *frameinfo = frames_hwctx->surfaces[0].Info;
+ *frameinfo = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info : *frames_hwctx->info;
} else {
pix_fmt = link->format;
desc = av_pix_fmt_desc_get(pix_fmt);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 09/12] lavfi/qsvvpp: require a dynamic frame pool for output if possible
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (6 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 08/12] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 10/12] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1) Xiang, Haihao
` (3 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavfilter/qsvvpp.c | 52 ++++++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 23 deletions(-)
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index d09140d89b..2c8e73e87d 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -603,6 +603,26 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
device_ctx = (AVHWDeviceContext *)device_ref->data;
device_hwctx = device_ctx->hwctx;
+ /* extract the properties of the "master" session given to us */
+ ret = MFXQueryIMPL(device_hwctx->session, &impl);
+ if (ret == MFX_ERR_NONE)
+ ret = MFXQueryVersion(device_hwctx->session, &ver);
+ if (ret != MFX_ERR_NONE) {
+ av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
+ return AVERROR_UNKNOWN;
+ }
+
+ if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+ handle_type = MFX_HANDLE_VA_DISPLAY;
+ } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+ handle_type = MFX_HANDLE_D3D11_DEVICE;
+ } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+ handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+ return AVERROR_UNKNOWN;
+ }
+
if (outlink->format == AV_PIX_FMT_QSV) {
AVHWFramesContext *out_frames_ctx;
AVBufferRef *out_frames_ref = av_hwframe_ctx_alloc(device_ref);
@@ -624,9 +644,15 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
out_frames_ctx->width = FFALIGN(outlink->w, 32);
out_frames_ctx->height = FFALIGN(outlink->h, 32);
out_frames_ctx->sw_format = s->out_sw_format;
- out_frames_ctx->initial_pool_size = 64;
- if (avctx->extra_hw_frames > 0)
- out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+
+ if (QSV_RUNTIME_VERSION_ATLEAST(ver, 2, 9) && handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER)
+ out_frames_ctx->initial_pool_size = 0;
+ else {
+ out_frames_ctx->initial_pool_size = 64;
+ if (avctx->extra_hw_frames > 0)
+ out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+ }
+
out_frames_hwctx->frame_type = s->out_mem_mode;
ret = av_hwframe_ctx_init(out_frames_ref);
@@ -652,26 +678,6 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
} else
s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
- /* extract the properties of the "master" session given to us */
- ret = MFXQueryIMPL(device_hwctx->session, &impl);
- if (ret == MFX_ERR_NONE)
- ret = MFXQueryVersion(device_hwctx->session, &ver);
- if (ret != MFX_ERR_NONE) {
- av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
- return AVERROR_UNKNOWN;
- }
-
- if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
- handle_type = MFX_HANDLE_VA_DISPLAY;
- } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
- handle_type = MFX_HANDLE_D3D11_DEVICE;
- } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
- handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
- } else {
- av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
- return AVERROR_UNKNOWN;
- }
-
ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
if (ret < 0)
return ff_qsvvpp_print_error(avctx, ret, "Error getting the session handle");
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 10/12] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1)
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (7 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 09/12] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
` (2 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
With libva2, the argument for render target list to vaCreateContext() is
a hint, so we may use a dynamic frame pool.
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
doc/APIchanges | 4 ++++
libavutil/hwcontext_vaapi.c | 2 +-
libavutil/hwcontext_vaapi.h | 5 +++--
libavutil/version.h | 2 +-
4 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index b68156ee94..0e36f43a91 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,10 @@ The last version increases of all libraries were on 2023-02-09
API changes, most recent first:
+2023-12-xx - xxxxxxxxxx - lavu 58.37.100 - hwcontext_vaapi.h
+ Modify the documentation to relax the constraint for dynamic
+ frames pool
+
2023-12-xx - xxxxxxxxxx - lavu 58.36.100 - hwcontext_qsv.h
Add AVQSVFramesContext.info
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 29fc8bd648..628232e2b8 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -618,7 +618,7 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc)
}
} else {
// This pool allows dynamic sizing, and will not be usable as a
- // render target.
+ // render target with libva. It can be used with libva2
avfc->nb_surfaces = 0;
avfc->surface_ids = NULL;
}
diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 0b2e071cb3..cff88ad237 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -25,9 +25,10 @@
* @file
* API-specific header for AV_HWDEVICE_TYPE_VAAPI.
*
- * Dynamic frame pools are supported, but note that any pool used as a render
+ * Dynamic frame pools are supported. Note that any pool used as a render
* target is required to be of fixed size in order to be be usable as an
- * argument to vaCreateContext().
+ * argument to vaCreateContext() when libva is used. When libva2 (VAAPI 1)
+ * is used, a pool used as a render target can be dynamic.
*
* For user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs
* with the data pointer set to a VASurfaceID.
diff --git a/libavutil/version.h b/libavutil/version.h
index 3b4c50e9a9..3b38f8f5da 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 58
-#define LIBAVUTIL_VERSION_MINOR 36
+#define LIBAVUTIL_VERSION_MINOR 37
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (8 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 10/12] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1) Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2024-01-26 7:25 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 12/12] lavfi/vaapi_vpp: use dynamic frame pool for output link " Xiang, Haihao
2024-01-02 5:33 ` [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
11 siblings, 1 reply; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
This allows a downstream element stores more frames from VAAPI
decoders and fixes error in get_buffer()
$ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i input_100frames.mp4 \
-vf reverse -an -f null -
...
[h264 @ 0x557a075a1400] get_buffer() failed
[h264 @ 0x557a075a1400] thread_get_buffer() failed
[h264 @ 0x557a075a1400] decode_slice_header error
[h264 @ 0x557a075a1400] no frame!
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavcodec/vaapi_decode.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index ceac769c52..8cc29e96f9 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -601,22 +601,26 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
if (err < 0)
goto fail;
- frames->initial_pool_size = 1;
- // Add per-codec number of surfaces used for storing reference frames.
- switch (avctx->codec_id) {
- case AV_CODEC_ID_H264:
- case AV_CODEC_ID_HEVC:
- case AV_CODEC_ID_AV1:
- frames->initial_pool_size += 16;
- break;
- case AV_CODEC_ID_VP9:
- frames->initial_pool_size += 8;
- break;
- case AV_CODEC_ID_VP8:
- frames->initial_pool_size += 3;
- break;
- default:
- frames->initial_pool_size += 2;
+ if (CONFIG_VAAPI_1)
+ frames->initial_pool_size = 0;
+ else {
+ frames->initial_pool_size = 1;
+ // Add per-codec number of surfaces used for storing reference frames.
+ switch (avctx->codec_id) {
+ case AV_CODEC_ID_H264:
+ case AV_CODEC_ID_HEVC:
+ case AV_CODEC_ID_AV1:
+ frames->initial_pool_size += 16;
+ break;
+ case AV_CODEC_ID_VP9:
+ frames->initial_pool_size += 8;
+ break;
+ case AV_CODEC_ID_VP8:
+ frames->initial_pool_size += 3;
+ break;
+ default:
+ frames->initial_pool_size += 2;
+ }
}
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* [FFmpeg-devel] [PATCH v2 12/12] lavfi/vaapi_vpp: use dynamic frame pool for output link with libva2
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (9 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
@ 2023-12-20 7:10 ` Xiang, Haihao
2024-01-02 5:33 ` [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2023-12-20 7:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavfilter/vaapi_vpp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index cf2592e068..818bc7d58a 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -199,7 +199,10 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
output_frames->width = ctx->output_width;
output_frames->height = ctx->output_height;
- output_frames->initial_pool_size = 4;
+ if (CONFIG_VAAPI_1)
+ output_frames->initial_pool_size = 0;
+ else
+ output_frames->initial_pool_size = 4;
err = ff_filter_init_hw_frames(avctx, outlink, 10);
if (err < 0)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (10 preceding siblings ...)
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 12/12] lavfi/vaapi_vpp: use dynamic frame pool for output link " Xiang, Haihao
@ 2024-01-02 5:33 ` Xiang, Haihao
11 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2024-01-02 5:33 UTC (permalink / raw)
To: ffmpeg-devel
On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang <haihao.xiang@intel.com>
>
> Add AVQSVFramesContext.info and update the description
>
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
> Rebased https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=9639
> against the latest master with a few changes.
>
> doc/APIchanges | 3 +++
> libavutil/hwcontext_qsv.c | 4 ++--
> libavutil/hwcontext_qsv.h | 31 +++++++++++++++++++++++++++----
> libavutil/version.h | 2 +-
> 4 files changed, 33 insertions(+), 7 deletions(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index a3e4ebbccd..b68156ee94 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>
> API changes, most recent first:
>
> +2023-12-xx - xxxxxxxxxx - lavu 58.36.100 - hwcontext_qsv.h
> + Add AVQSVFramesContext.info
> +
> 2023-12-18 - 74279227dd2 - lavc 60.36.100 - packet.h
> Add AV_PKT_DATA_IAMF_MIX_GAIN_PARAM, AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
> and AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM.
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index a67552b5ac..071489f070 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -613,7 +613,7 @@ static mfxStatus frame_alloc(mfxHDL pthis,
> mfxFrameAllocRequest *req,
> QSVFramesContext *s = ctx->internal->priv;
> AVQSVFramesContext *hwctx = ctx->hwctx;
> mfxFrameInfo *i = &req->Info;
> - mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
> + mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info : hwctx-
> >info;
>
> if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
> !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
> @@ -1173,7 +1173,7 @@ static int qsv_init_internal_session(AVHWFramesContext
> *ctx,
> MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
> par.AsyncDepth = 1;
>
> - par.vpp.In = frames_hwctx->surfaces[0].Info;
> + par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info :
> *frames_hwctx->info;
>
> /* Apparently VPP requires the frame rate to be set to some value,
> otherwise
> * init will fail (probably for the framerate conversion filter). Since
> we
> diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
> index e2dba8ad83..5950e38500 100644
> --- a/libavutil/hwcontext_qsv.h
> +++ b/libavutil/hwcontext_qsv.h
> @@ -25,8 +25,8 @@
> * @file
> * An API-specific header for AV_HWDEVICE_TYPE_QSV.
> *
> - * This API does not support dynamic frame pools. AVHWFramesContext.pool must
> - * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1
> struct.
> + * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer points
> + * to a mfxFrameSurface1 struct.
> */
>
> /**
> @@ -51,11 +51,34 @@ typedef struct AVQSVDeviceContext {
> * This struct is allocated as AVHWFramesContext.hwctx
> */
> typedef struct AVQSVFramesContext {
> - mfxFrameSurface1 *surfaces;
> + /**
> + * A pointer to a mfxFrameSurface1 or mfxFrameInfo struct
> + *
> + * When nb_surfaces is non-zero, it is a pointer to a mfxFrameSurface1
> + * struct.
> + *
> + * When nb_surfaces is 0, it is a pointer to a mfxFrameInfo struct, all
> + * buffers allocated from the pool have the same mfxFrameInfo.
> + */
> + union {
> + mfxFrameSurface1 *surfaces;
> + mfxFrameInfo *info;
> + };
> +
> + /**
> + * Number of frames in the pool
> + *
> + * It is 0 for dynamic frame pools or AVHWFramesContext.initial_pool_size
> + * for fixed frame pools.
> + *
> + * Note only oneVPL GPU runtime 2.9+ can support dynamic frame pools
> + * on d3d11va or vaapi
> + */
> int nb_surfaces;
>
> /**
> - * A combination of MFX_MEMTYPE_* describing the frame pool.
> + * Set by user. It is a combination of MFX_MEMTYPE_* describing the frame
> + * pool.
> */
> int frame_type;
> } AVQSVFramesContext;
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 7664cd97bd..3b4c50e9a9 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
> */
>
> #define LIBAVUTIL_VERSION_MAJOR 58
> -#define LIBAVUTIL_VERSION_MINOR 35
> +#define LIBAVUTIL_VERSION_MINOR 36
> #define LIBAVUTIL_VERSION_MICRO 100
>
> #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Hi,
Any comment for this patchset ?
Thanks
Haihao
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
@ 2024-01-26 7:25 ` Xiang, Haihao
2024-01-29 21:58 ` Mark Thompson
0 siblings, 1 reply; 19+ messages in thread
From: Xiang, Haihao @ 2024-01-26 7:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: sw
On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang <haihao.xiang@intel.com>
>
> This allows a downstream element stores more frames from VAAPI
> decoders and fixes error in get_buffer()
>
> $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i input_100frames.mp4 \
> -vf reverse -an -f null -
> ...
> [h264 @ 0x557a075a1400] get_buffer() failed
> [h264 @ 0x557a075a1400] thread_get_buffer() failed
> [h264 @ 0x557a075a1400] decode_slice_header error
> [h264 @ 0x557a075a1400] no frame!
>
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
> libavcodec/vaapi_decode.c | 36 ++++++++++++++++++++----------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index ceac769c52..8cc29e96f9 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -601,22 +601,26 @@ static int vaapi_decode_make_config(AVCodecContext
> *avctx,
> if (err < 0)
> goto fail;
>
> - frames->initial_pool_size = 1;
> - // Add per-codec number of surfaces used for storing reference
> frames.
> - switch (avctx->codec_id) {
> - case AV_CODEC_ID_H264:
> - case AV_CODEC_ID_HEVC:
> - case AV_CODEC_ID_AV1:
> - frames->initial_pool_size += 16;
> - break;
> - case AV_CODEC_ID_VP9:
> - frames->initial_pool_size += 8;
> - break;
> - case AV_CODEC_ID_VP8:
> - frames->initial_pool_size += 3;
> - break;
> - default:
> - frames->initial_pool_size += 2;
> + if (CONFIG_VAAPI_1)
> + frames->initial_pool_size = 0;
> + else {
> + frames->initial_pool_size = 1;
> + // Add per-codec number of surfaces used for storing reference
> frames.
> + switch (avctx->codec_id) {
> + case AV_CODEC_ID_H264:
> + case AV_CODEC_ID_HEVC:
> + case AV_CODEC_ID_AV1:
> + frames->initial_pool_size += 16;
> + break;
> + case AV_CODEC_ID_VP9:
> + frames->initial_pool_size += 8;
> + break;
> + case AV_CODEC_ID_VP8:
> + frames->initial_pool_size += 3;
> + break;
> + default:
> + frames->initial_pool_size += 2;
> + }
> }
> }
>
Hi Mark,
Do you have any comment about dynamic frame pool used in vaapi ?
Thanks
Haihao
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2024-01-26 7:25 ` Xiang, Haihao
@ 2024-01-29 21:58 ` Mark Thompson
2024-01-30 6:30 ` Xiang, Haihao
0 siblings, 1 reply; 19+ messages in thread
From: Mark Thompson @ 2024-01-29 21:58 UTC (permalink / raw)
To: ffmpeg-devel
On 26/01/2024 07:25, Xiang, Haihao wrote:
> On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
>> From: Haihao Xiang <haihao.xiang@intel.com>
>>
>> This allows a downstream element stores more frames from VAAPI
>> decoders and fixes error in get_buffer()
>>
>> $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i input_100frames.mp4 \
>> -vf reverse -an -f null -
>> ...
>> [h264 @ 0x557a075a1400] get_buffer() failed
>> [h264 @ 0x557a075a1400] thread_get_buffer() failed
>> [h264 @ 0x557a075a1400] decode_slice_header error
>> [h264 @ 0x557a075a1400] no frame!
>>
>> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
>> ---
>> libavcodec/vaapi_decode.c | 36 ++++++++++++++++++++----------------
>> 1 file changed, 20 insertions(+), 16 deletions(-)
>>
>> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
>> index ceac769c52..8cc29e96f9 100644
>> --- a/libavcodec/vaapi_decode.c
>> +++ b/libavcodec/vaapi_decode.c
>> @@ -601,22 +601,26 @@ static int vaapi_decode_make_config(AVCodecContext
>> *avctx,
>> if (err < 0)
>> goto fail;
>>
>> - frames->initial_pool_size = 1;
>> - // Add per-codec number of surfaces used for storing reference
>> frames.
>> - switch (avctx->codec_id) {
>> - case AV_CODEC_ID_H264:
>> - case AV_CODEC_ID_HEVC:
>> - case AV_CODEC_ID_AV1:
>> - frames->initial_pool_size += 16;
>> - break;
>> - case AV_CODEC_ID_VP9:
>> - frames->initial_pool_size += 8;
>> - break;
>> - case AV_CODEC_ID_VP8:
>> - frames->initial_pool_size += 3;
>> - break;
>> - default:
>> - frames->initial_pool_size += 2;
>> + if (CONFIG_VAAPI_1)
>> + frames->initial_pool_size = 0;
>> + else {
>> + frames->initial_pool_size = 1;
>> + // Add per-codec number of surfaces used for storing reference
>> frames.
>> + switch (avctx->codec_id) {
>> + case AV_CODEC_ID_H264:
>> + case AV_CODEC_ID_HEVC:
>> + case AV_CODEC_ID_AV1:
>> + frames->initial_pool_size += 16;
>> + break;
>> + case AV_CODEC_ID_VP9:
>> + frames->initial_pool_size += 8;
>> + break;
>> + case AV_CODEC_ID_VP8:
>> + frames->initial_pool_size += 3;
>> + break;
>> + default:
>> + frames->initial_pool_size += 2;
>> + }
>> }
>> }
>>
>
> Hi Mark,
>
> Do you have any comment about dynamic frame pool used in vaapi ?
Are we completely sure that there are no driver/hardware combinations which rely on this still used?
I note that the D3D12 implementation in ffmpeg is currently incomplete and does not work on some hardware because it only supports dynamic pools (non-array textures), which makes me wonder whether changing this would cause the same problem for VAAPI.
Thanks,
- Mark
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2024-01-29 21:58 ` Mark Thompson
@ 2024-01-30 6:30 ` Xiang, Haihao
2024-01-30 19:07 ` Mark Thompson
0 siblings, 1 reply; 19+ messages in thread
From: Xiang, Haihao @ 2024-01-30 6:30 UTC (permalink / raw)
To: ffmpeg-devel
On Ma, 2024-01-29 at 21:58 +0000, Mark Thompson wrote:
> On 26/01/2024 07:25, Xiang, Haihao wrote:
> > On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
> > > From: Haihao Xiang <haihao.xiang@intel.com>
> > >
> > > This allows a downstream element stores more frames from VAAPI
> > > decoders and fixes error in get_buffer()
> > >
> > > $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i
> > > input_100frames.mp4 \
> > > -vf reverse -an -f null -
> > > ...
> > > [h264 @ 0x557a075a1400] get_buffer() failed
> > > [h264 @ 0x557a075a1400] thread_get_buffer() failed
> > > [h264 @ 0x557a075a1400] decode_slice_header error
> > > [h264 @ 0x557a075a1400] no frame!
> > >
> > > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> > > ---
> > > libavcodec/vaapi_decode.c | 36 ++++++++++++++++++++----------------
> > > 1 file changed, 20 insertions(+), 16 deletions(-)
> > >
> > > diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> > > index ceac769c52..8cc29e96f9 100644
> > > --- a/libavcodec/vaapi_decode.c
> > > +++ b/libavcodec/vaapi_decode.c
> > > @@ -601,22 +601,26 @@ static int vaapi_decode_make_config(AVCodecContext
> > > *avctx,
> > > if (err < 0)
> > > goto fail;
> > >
> > > - frames->initial_pool_size = 1;
> > > - // Add per-codec number of surfaces used for storing reference
> > > frames.
> > > - switch (avctx->codec_id) {
> > > - case AV_CODEC_ID_H264:
> > > - case AV_CODEC_ID_HEVC:
> > > - case AV_CODEC_ID_AV1:
> > > - frames->initial_pool_size += 16;
> > > - break;
> > > - case AV_CODEC_ID_VP9:
> > > - frames->initial_pool_size += 8;
> > > - break;
> > > - case AV_CODEC_ID_VP8:
> > > - frames->initial_pool_size += 3;
> > > - break;
> > > - default:
> > > - frames->initial_pool_size += 2;
> > > + if (CONFIG_VAAPI_1)
> > > + frames->initial_pool_size = 0;
> > > + else {
> > > + frames->initial_pool_size = 1;
> > > + // Add per-codec number of surfaces used for storing
> > > reference
> > > frames.
> > > + switch (avctx->codec_id) {
> > > + case AV_CODEC_ID_H264:
> > > + case AV_CODEC_ID_HEVC:
> > > + case AV_CODEC_ID_AV1:
> > > + frames->initial_pool_size += 16;
> > > + break;
> > > + case AV_CODEC_ID_VP9:
> > > + frames->initial_pool_size += 8;
> > > + break;
> > > + case AV_CODEC_ID_VP8:
> > > + frames->initial_pool_size += 3;
> > > + break;
> > > + default:
> > > + frames->initial_pool_size += 2;
> > > + }
> > > }
> > > }
> > >
> >
> > Hi Mark,
> >
> > Do you have any comment about dynamic frame pool used in vaapi ?
>
> Are we completely sure that there are no driver/hardware combinations which
> rely on this still used?
I tested this patch with i965, iHD and radeonsi drivers on Linux and vaon12
driver on Windows. But honestly I am not sure whether there is a driver which
works with fixed frame pool only.
How about add a driver_quirk for workable drivers ? Or add a driver quirk in the
future if there is a driver which supports fixed frame pool only ?
Thanks
Haihao
>
> I note that the D3D12 implementation in ffmpeg is currently incomplete and
> does not work on some hardware because it only supports dynamic pools (non-
> array textures), which makes me wonder whether changing this would cause the
> same problem for VAAPI.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2024-01-30 6:30 ` Xiang, Haihao
@ 2024-01-30 19:07 ` Mark Thompson
2024-01-31 2:26 ` Xiang, Haihao
0 siblings, 1 reply; 19+ messages in thread
From: Mark Thompson @ 2024-01-30 19:07 UTC (permalink / raw)
To: ffmpeg-devel
On 30/01/2024 06:30, Xiang, Haihao wrote:
> On Ma, 2024-01-29 at 21:58 +0000, Mark Thompson wrote:
>> On 26/01/2024 07:25, Xiang, Haihao wrote:
>>> On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
>>>> From: Haihao Xiang <haihao.xiang@intel.com>
>>>>
>>>> This allows a downstream element stores more frames from VAAPI
>>>> decoders and fixes error in get_buffer()
>>>>
>>>> $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i
>>>> input_100frames.mp4 \
>>>> -vf reverse -an -f null -
>>>> ...
>>>> [h264 @ 0x557a075a1400] get_buffer() failed
>>>> [h264 @ 0x557a075a1400] thread_get_buffer() failed
>>>> [h264 @ 0x557a075a1400] decode_slice_header error
>>>> [h264 @ 0x557a075a1400] no frame!
>>>>
>>>> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
>>>> ---
>>>> libavcodec/vaapi_decode.c | 36 ++++++++++++++++++++----------------
>>>> 1 file changed, 20 insertions(+), 16 deletions(-)
>>>>
>>>> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
>>>> index ceac769c52..8cc29e96f9 100644
>>>> --- a/libavcodec/vaapi_decode.c
>>>> +++ b/libavcodec/vaapi_decode.c
>>>> @@ -601,22 +601,26 @@ static int vaapi_decode_make_config(AVCodecContext
>>>> *avctx,
>>>> if (err < 0)
>>>> goto fail;
>>>>
>>>> - frames->initial_pool_size = 1;
>>>> - // Add per-codec number of surfaces used for storing reference
>>>> frames.
>>>> - switch (avctx->codec_id) {
>>>> - case AV_CODEC_ID_H264:
>>>> - case AV_CODEC_ID_HEVC:
>>>> - case AV_CODEC_ID_AV1:
>>>> - frames->initial_pool_size += 16;
>>>> - break;
>>>> - case AV_CODEC_ID_VP9:
>>>> - frames->initial_pool_size += 8;
>>>> - break;
>>>> - case AV_CODEC_ID_VP8:
>>>> - frames->initial_pool_size += 3;
>>>> - break;
>>>> - default:
>>>> - frames->initial_pool_size += 2;
>>>> + if (CONFIG_VAAPI_1)
>>>> + frames->initial_pool_size = 0;
>>>> + else {
>>>> + frames->initial_pool_size = 1;
>>>> + // Add per-codec number of surfaces used for storing
>>>> reference
>>>> frames.
>>>> + switch (avctx->codec_id) {
>>>> + case AV_CODEC_ID_H264:
>>>> + case AV_CODEC_ID_HEVC:
>>>> + case AV_CODEC_ID_AV1:
>>>> + frames->initial_pool_size += 16;
>>>> + break;
>>>> + case AV_CODEC_ID_VP9:
>>>> + frames->initial_pool_size += 8;
>>>> + break;
>>>> + case AV_CODEC_ID_VP8:
>>>> + frames->initial_pool_size += 3;
>>>> + break;
>>>> + default:
>>>> + frames->initial_pool_size += 2;
>>>> + }
>>>> }
>>>> }
>>>>
>>>
>>> Hi Mark,
>>>
>>> Do you have any comment about dynamic frame pool used in vaapi ?
>>
>> Are we completely sure that there are no driver/hardware combinations which
>> rely on this still used?
>
> I tested this patch with i965, iHD and radeonsi drivers on Linux and vaon12
> driver on Windows. But honestly I am not sure whether there is a driver which
> works with fixed frame pool only.
How does the vaon12 driver work with this given that some D3D12 devices require a fixed array texture?
Note that the interesting test here is not the most recent version of any of these things. Rather, it is the older versions which exist in a distribution configuration which we still want to support, for example Ubuntu 20.04.
I'm also unclear to what degree this might depend on the hardware being used. Certainly in D3D12 whether the fixed array texture is required depends on the actual hardware support.
Thanks,
- Mark
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2024-01-30 19:07 ` Mark Thompson
@ 2024-01-31 2:26 ` Xiang, Haihao
2024-02-08 4:15 ` Xiang, Haihao
0 siblings, 1 reply; 19+ messages in thread
From: Xiang, Haihao @ 2024-01-31 2:26 UTC (permalink / raw)
To: ffmpeg-devel
On Di, 2024-01-30 at 19:07 +0000, Mark Thompson wrote:
> On 30/01/2024 06:30, Xiang, Haihao wrote:
> > On Ma, 2024-01-29 at 21:58 +0000, Mark Thompson wrote:
> > > On 26/01/2024 07:25, Xiang, Haihao wrote:
> > > > On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
> > > > > From: Haihao Xiang <haihao.xiang@intel.com>
> > > > >
> > > > > This allows a downstream element stores more frames from VAAPI
> > > > > decoders and fixes error in get_buffer()
> > > > >
> > > > > $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i
> > > > > input_100frames.mp4 \
> > > > > -vf reverse -an -f null -
> > > > > ...
> > > > > [h264 @ 0x557a075a1400] get_buffer() failed
> > > > > [h264 @ 0x557a075a1400] thread_get_buffer() failed
> > > > > [h264 @ 0x557a075a1400] decode_slice_header error
> > > > > [h264 @ 0x557a075a1400] no frame!
> > > > >
> > > > > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> > > > > ---
> > > > > libavcodec/vaapi_decode.c | 36 ++++++++++++++++++++----------------
> > > > > 1 file changed, 20 insertions(+), 16 deletions(-)
> > > > >
> > > > > diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> > > > > index ceac769c52..8cc29e96f9 100644
> > > > > --- a/libavcodec/vaapi_decode.c
> > > > > +++ b/libavcodec/vaapi_decode.c
> > > > > @@ -601,22 +601,26 @@ static int
> > > > > vaapi_decode_make_config(AVCodecContext
> > > > > *avctx,
> > > > > if (err < 0)
> > > > > goto fail;
> > > > >
> > > > > - frames->initial_pool_size = 1;
> > > > > - // Add per-codec number of surfaces used for storing
> > > > > reference
> > > > > frames.
> > > > > - switch (avctx->codec_id) {
> > > > > - case AV_CODEC_ID_H264:
> > > > > - case AV_CODEC_ID_HEVC:
> > > > > - case AV_CODEC_ID_AV1:
> > > > > - frames->initial_pool_size += 16;
> > > > > - break;
> > > > > - case AV_CODEC_ID_VP9:
> > > > > - frames->initial_pool_size += 8;
> > > > > - break;
> > > > > - case AV_CODEC_ID_VP8:
> > > > > - frames->initial_pool_size += 3;
> > > > > - break;
> > > > > - default:
> > > > > - frames->initial_pool_size += 2;
> > > > > + if (CONFIG_VAAPI_1)
> > > > > + frames->initial_pool_size = 0;
> > > > > + else {
> > > > > + frames->initial_pool_size = 1;
> > > > > + // Add per-codec number of surfaces used for storing
> > > > > reference
> > > > > frames.
> > > > > + switch (avctx->codec_id) {
> > > > > + case AV_CODEC_ID_H264:
> > > > > + case AV_CODEC_ID_HEVC:
> > > > > + case AV_CODEC_ID_AV1:
> > > > > + frames->initial_pool_size += 16;
> > > > > + break;
> > > > > + case AV_CODEC_ID_VP9:
> > > > > + frames->initial_pool_size += 8;
> > > > > + break;
> > > > > + case AV_CODEC_ID_VP8:
> > > > > + frames->initial_pool_size += 3;
> > > > > + break;
> > > > > + default:
> > > > > + frames->initial_pool_size += 2;
> > > > > + }
> > > > > }
> > > > > }
> > > > >
> > > >
> > > > Hi Mark,
> > > >
> > > > Do you have any comment about dynamic frame pool used in vaapi ?
> > >
> > > Are we completely sure that there are no driver/hardware combinations
> > > which
> > > rely on this still used?
> >
> > I tested this patch with i965, iHD and radeonsi drivers on Linux and vaon12
> > driver on Windows. But honestly I am not sure whether there is a driver
> > which
> > works with fixed frame pool only.
>
> How does the vaon12 driver work with this given that some D3D12 devices
> require a fixed array texture?
Honestly I don't know. I don't have such HWs for testing.
>
> Note that the interesting test here is not the most recent version of any of
> these things. Rather, it is the older versions which exist in a distribution
> configuration which we still want to support, for example Ubuntu 20.04.
This patch is based on libva2, FFmpeg still works with libva. For older versions
, user may use libva.
>
> I'm also unclear to what degree this might depend on the hardware being used.
> Certainly in D3D12 whether the fixed array texture is required depends on the
> actual hardware support.
How about add a quirk for workable driver(s) only ? We won't be concerned by
other drivers.
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index e6f45f8fde..aecdd55728 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -374,7 +374,7 @@ static const struct {
{
"Intel iHD",
"ubit",
- AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE,
+ AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE | AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL,
},
{
"VDPAU wrapper",
diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 259c6f5dbd..c4d2709224 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -60,6 +60,12 @@ enum {
* and the results of the vaQuerySurfaceAttributes() call will be faked.
*/
AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
+
+ /**
+ * The driver (and the underlying HW) supports dynamic surface pool.
+ * The vaCreateContext() call doesn't require a fixed array surfaces.
+ */
+ AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL = (1 << 4),
};
/**
Thanks
Haihao
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2024-01-31 2:26 ` Xiang, Haihao
@ 2024-02-08 4:15 ` Xiang, Haihao
0 siblings, 0 replies; 19+ messages in thread
From: Xiang, Haihao @ 2024-02-08 4:15 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: sw
On Wo, 2024-01-31 at 02:26 +0000, Xiang, Haihao wrote:
> On Di, 2024-01-30 at 19:07 +0000, Mark Thompson wrote:
> > On 30/01/2024 06:30, Xiang, Haihao wrote:
> > > On Ma, 2024-01-29 at 21:58 +0000, Mark Thompson wrote:
> > > > On 26/01/2024 07:25, Xiang, Haihao wrote:
> > > > > On Wo, 2023-12-20 at 15:10 +0800, Xiang, Haihao wrote:
> > > > > > From: Haihao Xiang <haihao.xiang@intel.com>
> > > > > >
> > > > > > This allows a downstream element stores more frames from VAAPI
> > > > > > decoders and fixes error in get_buffer()
> > > > > >
> > > > > > $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i
> > > > > > input_100frames.mp4 \
> > > > > > -vf reverse -an -f null -
> > > > > > ...
> > > > > > [h264 @ 0x557a075a1400] get_buffer() failed
> > > > > > [h264 @ 0x557a075a1400] thread_get_buffer() failed
> > > > > > [h264 @ 0x557a075a1400] decode_slice_header error
> > > > > > [h264 @ 0x557a075a1400] no frame!
> > > > > >
> > > > > > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> > > > > > ---
> > > > > > libavcodec/vaapi_decode.c | 36 ++++++++++++++++++++--------------
> > > > > > --
> > > > > > 1 file changed, 20 insertions(+), 16 deletions(-)
> > > > > >
> > > > > > diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> > > > > > index ceac769c52..8cc29e96f9 100644
> > > > > > --- a/libavcodec/vaapi_decode.c
> > > > > > +++ b/libavcodec/vaapi_decode.c
> > > > > > @@ -601,22 +601,26 @@ static int
> > > > > > vaapi_decode_make_config(AVCodecContext
> > > > > > *avctx,
> > > > > > if (err < 0)
> > > > > > goto fail;
> > > > > >
> > > > > > - frames->initial_pool_size = 1;
> > > > > > - // Add per-codec number of surfaces used for storing
> > > > > > reference
> > > > > > frames.
> > > > > > - switch (avctx->codec_id) {
> > > > > > - case AV_CODEC_ID_H264:
> > > > > > - case AV_CODEC_ID_HEVC:
> > > > > > - case AV_CODEC_ID_AV1:
> > > > > > - frames->initial_pool_size += 16;
> > > > > > - break;
> > > > > > - case AV_CODEC_ID_VP9:
> > > > > > - frames->initial_pool_size += 8;
> > > > > > - break;
> > > > > > - case AV_CODEC_ID_VP8:
> > > > > > - frames->initial_pool_size += 3;
> > > > > > - break;
> > > > > > - default:
> > > > > > - frames->initial_pool_size += 2;
> > > > > > + if (CONFIG_VAAPI_1)
> > > > > > + frames->initial_pool_size = 0;
> > > > > > + else {
> > > > > > + frames->initial_pool_size = 1;
> > > > > > + // Add per-codec number of surfaces used for storing
> > > > > > reference
> > > > > > frames.
> > > > > > + switch (avctx->codec_id) {
> > > > > > + case AV_CODEC_ID_H264:
> > > > > > + case AV_CODEC_ID_HEVC:
> > > > > > + case AV_CODEC_ID_AV1:
> > > > > > + frames->initial_pool_size += 16;
> > > > > > + break;
> > > > > > + case AV_CODEC_ID_VP9:
> > > > > > + frames->initial_pool_size += 8;
> > > > > > + break;
> > > > > > + case AV_CODEC_ID_VP8:
> > > > > > + frames->initial_pool_size += 3;
> > > > > > + break;
> > > > > > + default:
> > > > > > + frames->initial_pool_size += 2;
> > > > > > + }
> > > > > > }
> > > > > > }
> > > > > >
> > > > >
> > > > > Hi Mark,
> > > > >
> > > > > Do you have any comment about dynamic frame pool used in vaapi ?
> > > >
> > > > Are we completely sure that there are no driver/hardware combinations
> > > > which
> > > > rely on this still used?
> > >
> > > I tested this patch with i965, iHD and radeonsi drivers on Linux and
> > > vaon12
> > > driver on Windows. But honestly I am not sure whether there is a driver
> > > which
> > > works with fixed frame pool only.
> >
> > How does the vaon12 driver work with this given that some D3D12 devices
> > require a fixed array texture?
>
> Honestly I don't know. I don't have such HWs for testing.
>
> >
> > Note that the interesting test here is not the most recent version of any of
> > these things. Rather, it is the older versions which exist in a
> > distribution
> > configuration which we still want to support, for example Ubuntu 20.04.
>
> This patch is based on libva2, FFmpeg still works with libva. For older
> versions
> , user may use libva.
>
> >
> > I'm also unclear to what degree this might depend on the hardware being
> > used.
> > Certainly in D3D12 whether the fixed array texture is required depends on
> > the
> > actual hardware support.
>
> How about add a quirk for workable driver(s) only ? We won't be concerned by
> other drivers.
>
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index e6f45f8fde..aecdd55728 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -374,7 +374,7 @@ static const struct {
> {
> "Intel iHD",
> "ubit",
> - AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE,
> + AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE |
> AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL,
> },
> {
> "VDPAU wrapper",
> diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
> index 259c6f5dbd..c4d2709224 100644
> --- a/libavutil/hwcontext_vaapi.h
> +++ b/libavutil/hwcontext_vaapi.h
> @@ -60,6 +60,12 @@ enum {
> * and the results of the vaQuerySurfaceAttributes() call will be faked.
> */
> AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
> +
> + /**
> + * The driver (and the underlying HW) supports dynamic surface pool.
> + * The vaCreateContext() call doesn't require a fixed array surfaces.
> + */
> + AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL = (1 << 4),
> };
>
> /**
Hi Mark,
Is there any comment or concern about adding a quirk for workable drivers ? We
may use a dynamic frame pool in vaapi decoders and filters for workable drivers
only.
Note since commit e0da916b, a command below doesn't work with the current fixed
frame pool used in vaapi filters.
$ ffmpeg -hwaccel_output_format vaapi -hwaccel vaapi -i input.mp4 -vf
'scale_vaapi=w=720:h=480' -c:v hevc_vaapi -f null -
[...]
[vf#0:0 @ 0x562847b01050] Error while filtering: Cannot allocate memory
[vf#0:0 @ 0x562847b01050] Task finished with error code: -12 (Cannot allocate
memory)
[vf#0:0 @ 0x562847b01050] Terminating thread with return code -12 (Cannot
allocate memory)
[...]
Thanks
Haihao
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2024-02-08 4:15 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-20 7:10 [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 02/12] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 03/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 04/12] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 05/12] lavc/qsv: fix the mfx allocator to support dynamic frame pools Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 06/12] lavc/qsvenc: use the right info to config encoding parameters Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 07/12] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 08/12] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 09/12] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 10/12] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1) Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 11/12] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
2024-01-26 7:25 ` Xiang, Haihao
2024-01-29 21:58 ` Mark Thompson
2024-01-30 6:30 ` Xiang, Haihao
2024-01-30 19:07 ` Mark Thompson
2024-01-31 2:26 ` Xiang, Haihao
2024-02-08 4:15 ` Xiang, Haihao
2023-12-20 7:10 ` [FFmpeg-devel] [PATCH v2 12/12] lavfi/vaapi_vpp: use dynamic frame pool for output link " Xiang, Haihao
2024-01-02 5:33 ` [FFmpeg-devel] [PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git