Skip to content

Commit

Permalink
Use dynamic pool for VPL QSV hwupload
Browse files Browse the repository at this point in the history
Signed-off-by: nyanmisaka <nst799610810@gmail.com>
  • Loading branch information
nyanmisaka committed Oct 30, 2024
1 parent a856e91 commit 83852c8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
79 changes: 79 additions & 0 deletions debian/patches/0080-use-dynamic-pool-for-vpl-qsv-hwupload.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Index: FFmpeg/libavfilter/vf_hwupload.c
===================================================================
--- FFmpeg.orig/libavfilter/vf_hwupload.c
+++ FFmpeg/libavfilter/vf_hwupload.c
@@ -32,6 +32,10 @@
#include "internal.h"
#include "video.h"

+#if CONFIG_LIBMFX
+extern int ff_qsv_check_dynamic_pool_supported(AVHWDeviceContext *device_ctx);
+#endif
+
typedef struct HWUploadContext {
const AVClass *class;

@@ -163,6 +167,15 @@ static int hwupload_config_output(AVFilt
ctx->hwframes->user_opaque = &texDesc;
#endif

+#if CONFIG_LIBMFX
+ if (ctx->hwframes->format == AV_PIX_FMT_QSV) {
+ AVHWDeviceContext *qsv_ctx = (AVHWDeviceContext *)ctx->hwdevice_ref->data;
+ if (!ff_qsv_check_dynamic_pool_supported(qsv_ctx)) {
+ ctx->hwframes->initial_pool_size = 0;
+ }
+ }
+#endif
+
err = av_hwframe_ctx_init(ctx->hwframes_ref);
if (err < 0)
goto fail;
Index: FFmpeg/libavutil/hwcontext_qsv.c
===================================================================
--- FFmpeg.orig/libavutil/hwcontext_qsv.c
+++ FFmpeg/libavutil/hwcontext_qsv.c
@@ -173,6 +173,8 @@ extern int ff_qsv_get_surface_base_handl
enum AVHWDeviceType base_dev_type,
void **base_handle);

+extern int ff_qsv_check_dynamic_pool_supported(AVHWDeviceContext *device_ctx);
+
static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf);

/**
@@ -205,6 +207,34 @@ int ff_qsv_get_surface_base_handle(mfxFr
return AVERROR(EINVAL);
}

+int ff_qsv_check_dynamic_pool_supported(AVHWDeviceContext *device_ctx)
+{
+ AVQSVDeviceContext *device_hwctx;
+ mfxIMPL impl;
+ mfxVersion ver;
+ int ret;
+
+ if (!device_ctx || device_ctx->type != AV_HWDEVICE_TYPE_QSV)
+ return AVERROR(EINVAL);
+
+ device_hwctx = device_ctx->hwctx;
+
+ ret = MFXQueryIMPL(device_hwctx->session, &impl);
+ if (ret == MFX_ERR_NONE)
+ ret = MFXQueryVersion(device_hwctx->session, &ver);
+ if (ret != MFX_ERR_NONE)
+ return AVERROR_UNKNOWN;
+
+ if (!QSV_RUNTIME_VERSION_ATLEAST(ver, 2, 9))
+ return AVERROR(ENOSYS);
+
+ if (!(MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl) ||
+ MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)))
+ return AVERROR(ENOSYS);
+
+ return 0;
+}
+
static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt)
{
int i;
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@
0077-add-remove-dovi-hdr10plus-bsf.patch
0078-fix-atenc-layout-samplerate.patch
0079-videotoolbox-remove-opengl-compatability.patch
0080-use-dynamic-pool-for-vpl-qsv-hwupload.patch

0 comments on commit 83852c8

Please sign in to comment.