* [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool
@ 2024-05-08 6:03 Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 2/9] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
` (7 more replies)
0 siblings, 8 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 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>
---
doc/APIchanges | 3 +++
libavutil/hwcontext_qsv.c | 4 ++--
libavutil/hwcontext_qsv.h | 27 +++++++++++++++++++++++++--
libavutil/version.h | 2 +-
4 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 824beec9d3..fa281cec5c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
API changes, most recent first:
+2024-05-xx - xxxxxxxxxx - lavu 59.18.100 - hwcontext_qsv.h
+ Add AVQSVFramesContext.info
+
2024-05-04 - xxxxxxxxxx - lavu 59.17.100 - opt.h
Add AV_OPT_TYPE_UINT and av_opt_eval_uint().
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index c7c7878644..f552811346 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -627,7 +627,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
QSVFramesContext *s = ctx->hwctx;
AVQSVFramesContext *hwctx = &s->p;
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)) ||
@@ -1207,7 +1207,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..35530e4e93 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,13 +51,36 @@ typedef struct AVQSVDeviceContext {
* This struct is allocated as AVHWFramesContext.hwctx
*/
typedef struct AVQSVFramesContext {
+ /**
+ * A pointer to a mfxFrameSurface1 struct
+ *
+ * It is available when nb_surfaces is non-zero.
+ */
mfxFrameSurface1 *surfaces;
+
+ /**
+ * 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.
*/
int frame_type;
+
+ /**
+ * A pointer to a mfxFrameInfo struct
+ *
+ * It is available when nb_surfaces is 0, all buffers allocated from the
+ * pool have the same mfxFrameInfo.
+ */
+ mfxFrameInfo *info;
} AVQSVFramesContext;
#endif /* AVUTIL_HWCONTEXT_QSV_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 3b5a2e7aaa..b9b9baf98c 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 59
-#define LIBAVUTIL_VERSION_MINOR 17
+#define LIBAVUTIL_VERSION_MINOR 18
#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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/9] lavu/hwcontext_qsv: create dynamic frame pool if required
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 3/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 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 f552811346..01bd273a08 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -118,8 +118,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;
@@ -165,6 +172,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.
**/
@@ -373,7 +382,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->hwctx;
+ 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->hwctx;
@@ -388,6 +422,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->hwctx;
+ 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)
{
QSVDeviceContext *device_priv = ctx->device_ctx->hwctx;
@@ -576,9 +708,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;
+
+ ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1),
+ ctx, qsv_pool_alloc, NULL);
+ if (!ffhwframesctx(ctx)->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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 2/9] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 4/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Make it work with the source which has 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 01bd273a08..1d3091e6f8 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1972,18 +1972,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->hwctx;
AVQSVFramesContext *dst_hwctx = &s->p;
- 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->hwctx;
+ AVQSVFramesContext *dst_hwctx = &s->p;
+ int i;
switch (src_ctx->device_ctx->type) {
#if CONFIG_VAAPI
@@ -2075,6 +2109,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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 4/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 2/9] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 3/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 5/9] lavc/qsv: fix the mfx allocator to support dynamic frame pool Xiang, Haihao
` (4 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Make it work with the source which has a dynamic frame pool.
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 1d3091e6f8..8b7b4dc501 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -2122,8 +2122,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;
@@ -2182,6 +2182,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 *)ffhwframesctx(ctx)->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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 5/9] lavc/qsv: fix the mfx allocator to support dynamic frame pool
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
` (2 preceding siblings ...)
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 4/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 6/9] lavc/qsvenc: use the right info for encoding Xiang, Haihao
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
When the external allocator is used for dynamic frame allocation, only
video memory is supported, the SDK doesn't lock/unlock the memory block
via Lock()/Unlock() calls.
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
libavcodec/qsv.c | 68 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 12 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b07302cdf6..6bbfe2a5a9 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -825,8 +825,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 "
@@ -845,6 +853,7 @@ 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;
@@ -852,6 +861,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
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;
@@ -899,6 +911,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]);
ff_refstruct_unref(&resp->mids[resp->NumFrameActual + 1]);
av_freep(&resp->mids);
@@ -907,11 +922,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;
@@ -964,8 +988,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);
@@ -974,9 +1005,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;
@@ -1090,13 +1130,17 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession,
if (!opaque) {
qsv_frames_ctx->logctx = avctx;
+ qsv_frames_ctx->mids = NULL;
+ qsv_frames_ctx->nb_mids = 0;
/* allocate the memory ids for the external frames */
- ff_refstruct_unref(&qsv_frames_ctx->mids);
- qsv_frames_ctx->mids = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx);
- if (!qsv_frames_ctx->mids)
- return AVERROR(ENOMEM);
- qsv_frames_ctx->nb_mids = frames_hwctx->nb_surfaces;
+ if (frames_hwctx->nb_surfaces) {
+ ff_refstruct_unref(&qsv_frames_ctx->mids);
+ qsv_frames_ctx->mids = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx);
+ if (!qsv_frames_ctx->mids)
+ return AVERROR(ENOMEM);
+ 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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 6/9] lavc/qsvenc: use the right info for encoding
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
` (3 preceding siblings ...)
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 5/9] lavc/qsv: fix the mfx allocator to support dynamic frame pool Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 7/9] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 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 d881c11160..3df355ce78 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -745,8 +745,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) {
@@ -869,8 +870,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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 7/9] lavc/qsvdec: require a dynamic frame pool if possible
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
` (4 preceding siblings ...)
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 6/9] lavc/qsvenc: use the right info for encoding Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
7 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 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 ed0bfe4c8b..4ecc7f5adb 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"
@@ -68,6 +69,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;
@@ -77,6 +80,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
@@ -183,6 +187,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)) {
@@ -240,27 +245,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)
@@ -310,7 +340,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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
` (5 preceding siblings ...)
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 7/9] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
7 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 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 10d970652e..c4c338b36b 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -308,7 +308,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] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
` (6 preceding siblings ...)
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used Xiang, Haihao
@ 2024-05-08 6:03 ` Xiang, Haihao
2024-05-13 6:29 ` Xiang, Haihao
7 siblings, 1 reply; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-08 6:03 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 c4c338b36b..1c9773df09 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -587,6 +587,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);
@@ -608,9 +628,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);
@@ -636,26 +662,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] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
@ 2024-05-13 6:29 ` Xiang, Haihao
0 siblings, 0 replies; 10+ messages in thread
From: Xiang, Haihao @ 2024-05-13 6:29 UTC (permalink / raw)
To: ffmpeg-devel
On Wo, 2024-05-08 at 14:03 +0800, Xiang, Haihao wrote:
> 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 c4c338b36b..1c9773df09 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -587,6 +587,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);
> @@ -608,9 +628,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);
> @@ -636,26 +662,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");
Will apply the patchset
- 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] 10+ messages in thread
end of thread, other threads:[~2024-05-13 6:30 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08 6:03 [FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 2/9] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 3/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 4/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 5/9] lavc/qsv: fix the mfx allocator to support dynamic frame pool Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 6/9] lavc/qsvenc: use the right info for encoding Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 7/9] lavc/qsvdec: require a dynamic frame pool if possible Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used Xiang, Haihao
2024-05-08 6:03 ` [FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
2024-05-13 6:29 ` 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