* [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools
@ 2023-09-06 6:00 Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 02/13] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
When AVQSVFramesContext.nb_surfaces is set to 0, a dynamic frame pool is
expected, otherwise a fixed frame pool is expected.
In addition, AVQSVFramesContext.info is added. User should provide
AVQSVFramesContext.info instead of AVQSVFramesContext.surfaces for
dynamic frame pools.
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
doc/APIchanges | 3 +++
libavutil/hwcontext_qsv.c | 4 ++--
libavutil/hwcontext_qsv.h | 22 +++++++++++++++++++++-
libavutil/version.h | 2 +-
4 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index dbaec30aac..5fa9110c21 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-09-xx - xxxxxxxxxx - lavu 58.20.100 - hwcontext_qsv.h
+ Add AVQSVFramesContext.info to support dynamic frame pools
+
2023-09-02 - xxxxxxxxxx - lavu 58.19.100 - executor.h
Add AVExecutor API
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 1bfda9e69b..b76a89d13a 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..317ae5094f 100644
--- a/libavutil/hwcontext_qsv.h
+++ b/libavutil/hwcontext_qsv.h
@@ -51,7 +51,27 @@ typedef struct AVQSVDeviceContext {
* This struct is allocated as AVHWFramesContext.hwctx
*/
typedef struct AVQSVFramesContext {
- mfxFrameSurface1 *surfaces;
+ /**
+ * A pointer to mfxFrameSurface1 or mfxFrameInfo structure.
+ *
+ * When nb_surfaces is 0, it is a pointer to mfxFrameInfo structure,
+ * otherwise it is a pointer to mfxFrameSurface1.
+ */
+ union {
+ mfxFrameSurface1 *surfaces;
+ mfxFrameInfo *info;
+ };
+
+ /**
+ * Number of frames
+ *
+ * A dynamic frame pool is required when nb_surfaces is 0, otherwise
+ * a fixed frame pool is required.
+ *
+ * User should make sure the configuration can support dynamic frame
+ * allocation when dynamic frame pool is required. For example, you cannt
+ * set nb_surfaces to 0 when the child_device_type is AV_HWDEVICE_TYPE_DXVA2.
+ */
int nb_surfaces;
/**
diff --git a/libavutil/version.h b/libavutil/version.h
index 897feff84f..605f85cd41 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 58
-#define LIBAVUTIL_VERSION_MINOR 19
+#define LIBAVUTIL_VERSION_MINOR 20
#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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 02/13] lavu/hwcontext_qsv: create dynamic frame pool if required
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 03/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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 b76a89d13a..21ce4225bd 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)
+ return NULL;
+
+ *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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 03/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 02/13] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 04/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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 21ce4225bd..ceb5087b6b 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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 04/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 02/13] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 03/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 05/13] lavc/qsv: fix qsv_frame_get_hdl callback to support dynamic frame pools Xiang, Haihao
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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 ceb5087b6b..d097f28654 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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 05/13] lavc/qsv: fix qsv_frame_get_hdl callback to support dynamic frame pools
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (2 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 04/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 06/13] lavc/qsv: set right mfxFrameInfo for frames in " Xiang, Haihao
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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/qsv.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 7563625627..3f4b7b8193 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -987,9 +987,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;
--
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 06/13] lavc/qsv: set right mfxFrameInfo for frames in dynamic frame pools
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (3 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 05/13] lavc/qsv: fix qsv_frame_get_hdl callback to support dynamic frame pools Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 07/13] lavc/qsv: needn't QSVMid array " Xiang, Haihao
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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/qsv.c | 4 ++--
libavcodec/qsvenc.c | 10 ++++++----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 3f4b7b8193..4ae697379f 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -839,7 +839,7 @@ 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 = frames_hwctx->nb_surfaces ? &frames_hwctx->surfaces[0].Info : frames_hwctx->info;
if (i->Width > i1->Width || i->Height > i1->Height ||
i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
@@ -954,7 +954,7 @@ static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
if (!qsv_mid->hw_frame->hw_frames_ctx)
goto fail;
- qsv_mid->surf.Info = hw_frames_hwctx->surfaces[0].Info;
+ qsv_mid->surf.Info = hw_frames_hwctx->nb_surfaces ? hw_frames_hwctx->surfaces[0].Info : *hw_frames_hwctx->info;
qsv_mid->surf.Data.MemId = qsv_mid->handle_pair;
/* map the data to the system memory */
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index b3b7475b0f..72dc33c2e4 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -717,8 +717,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) {
@@ -841,8 +842,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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 07/13] lavc/qsv: needn't QSVMid array for frames in dynamic frame pools
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (4 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 06/13] lavc/qsv: set right mfxFrameInfo for frames in " Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 08/13] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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/qsv.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 4ae697379f..f8ef5a4ae5 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -841,6 +841,13 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
mfxFrameInfo *i = &req->Info;
mfxFrameInfo *i1 = frames_hwctx->nb_surfaces ? &frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+ if (!frames_ctx->initial_pool_size) {
+ av_log(ctx->logctx, AV_LOG_DEBUG,
+ "Dynamic frame pools, no frame is pre-allocated\n");
+
+ return MFX_ERR_NONE;
+ }
+
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 "
@@ -912,6 +919,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);
@@ -1112,14 +1122,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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 08/13] lavc/qsvdec: require a dynamic frame pool if possible
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (5 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 07/13] lavc/qsv: needn't QSVMid array " Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 09/13] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools Xiang, Haihao
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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/qsvdec.c | 57 +++++++++++++++++++++++++++++++++++----------
1 file changed, 45 insertions(+), 12 deletions(-)
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index da700f25e9..5549df304a 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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 09/13] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (6 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 08/13] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 10/13] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 10/13] lavfi/qsvvpp: require a dynamic frame pool for output if possible
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (7 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 09/13] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 11/13] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1) Xiang, Haihao
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 11/13] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1)
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (8 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 10/13] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 12/13] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 13/13] lavfi/vaapi_vpp: use dynamic frame pool for output link " Xiang, Haihao
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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 5fa9110c21..9e3184bc9a 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-09-xx - xxxxxxxxxx - lavu 58.21.100 - hwcontext_vaapi.h
+ Modify the documentation to relax the constraint for dynamic
+ frames pool.
+
2023-09-xx - xxxxxxxxxx - lavu 58.20.100 - hwcontext_qsv.h
Add AVQSVFramesContext.info to support dynamic frame pools
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 558fed94c6..5ff24bb3ed 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..7badf38ec4 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() with libva. 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 605f85cd41..f1946b780f 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 58
-#define LIBAVUTIL_VERSION_MINOR 20
+#define LIBAVUTIL_VERSION_MINOR 21
#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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 12/13] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (9 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 11/13] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1) Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 13/13] lavfi/vaapi_vpp: use dynamic frame pool for output link " Xiang, Haihao
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 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 dd55cbd6f1..c0a52c1d41 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -600,22 +600,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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 13/13] lavfi/vaapi_vpp: use dynamic frame pool for output link with libva2
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
` (10 preceding siblings ...)
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 12/13] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
@ 2023-09-06 6:00 ` Xiang, Haihao
11 siblings, 0 replies; 13+ messages in thread
From: Xiang, Haihao @ 2023-09-06 6:00 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
This can avoid out of memory with vaapi filters since commit 5fa00b3.
Example:
$ ffmpeg -init_hw_device vaapi=hw:/dev/dri/renderD128
-hwaccel_output_format vaapi -hwaccel vaapi -i input.mp4 -vf
'scale_vaapi=w=720:h=480' -vframes 1 -f null -
...
[vf#0:0 @ 0x55ffe793ba80] Error while filtering: Cannot allocate memory
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] 13+ messages in thread
end of thread, other threads:[~2023-09-06 6:03 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 02/13] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 03/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 04/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 05/13] lavc/qsv: fix qsv_frame_get_hdl callback to support dynamic frame pools Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 06/13] lavc/qsv: set right mfxFrameInfo for frames in " Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 07/13] lavc/qsv: needn't QSVMid array " Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 08/13] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 09/13] lavfi/qsvvpp: set right mfxFrameInfo for frames in dynamic frame pools Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 10/13] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 11/13] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1) Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 12/13] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
2023-09-06 6:00 ` [FFmpeg-devel] [PATCH 13/13] lavfi/vaapi_vpp: use dynamic frame pool for output link " 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