Skip to content

Commit

Permalink
Merge pull request #463 from nyanmisaka/qsv-msdk-init
Browse files Browse the repository at this point in the history
Allow VPL QSV to init with the legacy MSDK path
  • Loading branch information
nyanmisaka authored Sep 25, 2024
2 parents 3d25b92 + 50f1db8 commit 0ae3f9d
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# We just wrap `build` so this is really it
name: "jellyfin-ffmpeg"
version: "7.0.2-2"
version: "7.0.2-3"
packages:
- bullseye-amd64
- bullseye-armhf
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
jellyfin-ffmpeg (7.0.2-3) unstable; urgency=medium

* Allow VPL QSV to init with the legacy MSDK path

-- nyanmisaka <[email protected]> Tue, 24 Sep 2024 20:03:23 +0800

jellyfin-ffmpeg (7.0.2-2) unstable; urgency=medium

* Add bwdif_videotoolbox filter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
Index: FFmpeg/configure
===================================================================
--- FFmpeg.orig/configure
+++ FFmpeg/configure
@@ -2528,6 +2528,7 @@ HAVE_LIST="
xmllint
zlib_gzip
openvino2
+ libvpl_legacy_mfxinit
"

# options emitted with CONFIG_ prefix but not available on the command line
@@ -6947,6 +6948,9 @@ elif enabled libvpl; then
die "ERROR: libvpl >= 2.6 not found"
add_cflags -DMFX_DEPRECATED_OFF
check_type "vpl/mfxdefs.h vpl/mfxvideo.h" "struct mfxConfigInterface"
+# Ancient Intel driver on Windows still require the legacy init functions.
+# No compiler option is changed if the test fails, just needs to add back the disabled libmfx.
+ { test_pkg_config libmfx "vpl >= 2.6" "mfxvideo.h mfxdispatcher.h" "MFXInit MFXInitEx" && enable libvpl_legacy_mfxinit; } || enable libmfx
fi

if enabled libmfx; then
Index: FFmpeg/libavcodec/qsv.c
===================================================================
--- FFmpeg.orig/libavcodec/qsv.c
+++ FFmpeg/libavcodec/qsv.c
@@ -496,6 +496,17 @@ static int ff_qsv_set_display_handle(AVC
}
#endif //AVCODEC_QSV_LINUX_SESSION_HANDLE

+#if !QSV_ONEVPL || HAVE_LIBVPL_LEGACY_MFXINIT
+
+static int qsv_create_mfx_session_legacy(AVCodecContext *avctx,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ int gpu_copy,
+ mfxSession *psession,
+ void **ploader);
+
+#endif
+
#if QSV_ONEVPL
static int qsv_new_mfx_loader(AVCodecContext *avctx,
mfxIMPL implementation,
@@ -636,6 +647,16 @@ static int qsv_create_mfx_session(AVCode
return 0;

fail:
+#if HAVE_LIBVPL_LEGACY_MFXINIT
+ av_log(avctx, AV_LOG_VERBOSE, "Error creating a MFX session using oneVPL, "
+ "falling back to retry with the legacy Media SDK path\n");
+ if (!qsv_create_mfx_session_legacy(avctx, implementation, pver, gpu_copy, psession, ploader)) {
+ if (!*ploader)
+ *ploader = loader;
+ return 0;
+ }
+#endif
+
if (!*ploader && loader)
MFXUnload(loader);

@@ -651,6 +672,20 @@ static int qsv_create_mfx_session(AVCode
mfxSession *psession,
void **ploader)
{
+ return qsv_create_mfx_session_legacy(avctx, implementation, pver, gpu_copy, psession, ploader);
+}
+
+#endif
+
+#if !QSV_ONEVPL || HAVE_LIBVPL_LEGACY_MFXINIT
+
+static int qsv_create_mfx_session_legacy(AVCodecContext *avctx,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ int gpu_copy,
+ mfxSession *psession,
+ void **ploader)
+{
mfxInitParam init_par = { MFX_IMPL_AUTO_ANY };
mfxSession session = NULL;
mfxStatus sts;
Index: FFmpeg/libavcodec/qsvenc.c
===================================================================
--- FFmpeg.orig/libavcodec/qsvenc.c
+++ FFmpeg/libavcodec/qsvenc.c
@@ -1192,7 +1192,7 @@ static int init_video_param(AVCodecConte

#if QSV_HAVE_EXT_AV1_PARAM
if (avctx->codec_id == AV_CODEC_ID_AV1) {
- if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 5)) {
+ if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 255)) { // (2, 5)
q->extav1tileparam.Header.BufferId = MFX_EXTBUFF_AV1_TILE_PARAM;
q->extav1tileparam.Header.BufferSz = sizeof(q->extav1tileparam);
q->extav1tileparam.NumTileColumns = q->tile_cols;
@@ -1416,7 +1416,7 @@ static int qsv_retrieve_enc_av1_params(A
(mfxExtBuffer*)&co3,
};

- if (!QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 5)) {
+ if (!QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 255)) { // (2, 5)
av_log(avctx, AV_LOG_ERROR,
"This version of runtime doesn't support AV1 encoding\n");
return AVERROR_UNKNOWN;
Index: FFmpeg/libavfilter/qsvvpp.c
===================================================================
--- FFmpeg.orig/libavfilter/qsvvpp.c
+++ FFmpeg/libavfilter/qsvvpp.c
@@ -1067,6 +1067,16 @@ int ff_qsvvpp_filter_frame(QSVVPPContext
return 0;
}

+#if !QSV_ONEVPL || HAVE_LIBVPL_LEGACY_MFXINIT
+
+static int qsvvpp_create_mfx_session_legacy(void *ctx,
+ void *loader,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ mfxSession *psession);
+
+#endif
+
#if QSV_ONEVPL

int ff_qsvvpp_create_mfx_session(void *ctx,
@@ -1110,6 +1120,15 @@ int ff_qsvvpp_create_mfx_session(void *c
impl_idx++;
}

+#if HAVE_LIBVPL_LEGACY_MFXINIT
+ if (sts < 0) {
+ av_log(ctx, AV_LOG_VERBOSE, "Error creating a MFX session using oneVPL, "
+ "falling back to retry with the legacy Media SDK path\n");
+ if (!qsvvpp_create_mfx_session_legacy(ctx, loader, implementation, pver, psession))
+ return 0;
+ }
+#endif
+
if (sts < 0)
return ff_qsvvpp_print_error(ctx, sts,
"Error creating a MFX session");
@@ -1127,6 +1146,19 @@ int ff_qsvvpp_create_mfx_session(void *c
mfxVersion *pver,
mfxSession *psession)
{
+ return qsvvpp_create_mfx_session_legacy(ctx, loader, implementation, pver, psession);
+}
+
+#endif
+
+#if !QSV_ONEVPL || HAVE_LIBVPL_LEGACY_MFXINIT
+
+static int qsvvpp_create_mfx_session_legacy(void *ctx,
+ void *loader,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ mfxSession *psession)
+{
mfxSession session = NULL;
mfxStatus sts;

Index: FFmpeg/libavfilter/vf_vpp_qsv.c
===================================================================
--- FFmpeg.orig/libavfilter/vf_vpp_qsv.c
+++ FFmpeg/libavfilter/vf_vpp_qsv.c
@@ -426,7 +426,7 @@ static int vpp_set_frame_ext_params(AVFi
fp->num_ext_buf = 0;

if (!in || !out ||
- !QSV_RUNTIME_VERSION_ATLEAST(qsvvpp->ver, 2, 0))
+ !QSV_RUNTIME_VERSION_ATLEAST(qsvvpp->ver, 1, 255)) // (2, 0)
return 0;

memset(&invsi_conf, 0, sizeof(mfxExtVideoSignalInfo));
Index: FFmpeg/libavutil/hwcontext_qsv.c
===================================================================
--- FFmpeg.orig/libavutil/hwcontext_qsv.c
+++ FFmpeg/libavutil/hwcontext_qsv.c
@@ -827,6 +827,18 @@ static mfxStatus frame_get_hdl(mfxHDL pt
return MFX_ERR_NONE;
}

+#if !QSV_ONEVPL || HAVE_LIBVPL_LEGACY_MFXINIT
+
+static int qsv_create_mfx_session_legacy(void *ctx,
+ mfxHDL handle,
+ mfxHandleType handle_type,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ mfxSession *psession,
+ void **ploader);
+
+#endif
+
#if QSV_ONEVPL

static int qsv_d3d11_update_config(void *ctx, mfxHDL handle, mfxConfig cfg)
@@ -1218,6 +1230,16 @@ static int qsv_create_mfx_session(void *
return 0;

fail:
+#if HAVE_LIBVPL_LEGACY_MFXINIT
+ av_log(ctx, AV_LOG_VERBOSE, "Error creating a MFX session using oneVPL, "
+ "falling back to retry with the legacy Media SDK path\n");
+ if (!qsv_create_mfx_session_legacy(ctx, handle, handle_type, implementation, pver, psession, ploader)) {
+ if (!*ploader)
+ *ploader = loader;
+ return 0;
+ }
+#endif
+
if (!*ploader && loader)
MFXUnload(loader);

@@ -1234,6 +1256,21 @@ static int qsv_create_mfx_session(void *
mfxSession *psession,
void **ploader)
{
+ return qsv_create_mfx_session_legacy(ctx, handle, handle_type, implementation, pver, psession, ploader);
+}
+
+#endif
+
+#if !QSV_ONEVPL || HAVE_LIBVPL_LEGACY_MFXINIT
+
+static int qsv_create_mfx_session_legacy(void *ctx,
+ mfxHDL handle,
+ mfxHandleType handle_type,
+ mfxIMPL implementation,
+ mfxVersion *pver,
+ mfxSession *psession,
+ void **ploader)
+{
mfxVersion ver;
mfxStatus sts;
mfxSession session = NULL;
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@
0072-add-bwdif-videotoolbox-filter.patch
0073-add-12bit-decoding-on-videotoolbox.patch
0074-fix-the-sub2video-perf-regressions.patch
0075-allow-vpl-qsv-to-init-with-the-legacy-msdk-path.patch

0 comments on commit 0ae3f9d

Please sign in to comment.