From 45aad39f09dee801f2b8fee3d688aead65a5c46c Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Sun, 11 Feb 2024 20:04:03 +0800 Subject: [PATCH 1/4] Fix libplacebo v6 required hostQueryReset capability Signed-off-by: nyanmisaka --- ...055-fix-libplacebo-filter-build-with-v6-api.patch | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/debian/patches/0055-fix-libplacebo-filter-build-with-v6-api.patch b/debian/patches/0055-fix-libplacebo-filter-build-with-v6-api.patch index 57621875c19..93e78364eba 100644 --- a/debian/patches/0055-fix-libplacebo-filter-build-with-v6-api.patch +++ b/debian/patches/0055-fix-libplacebo-filter-build-with-v6-api.patch @@ -35,3 +35,15 @@ Index: jellyfin-ffmpeg/libavfilter/vf_libplacebo.c { "force_dither", "Force dithering", OFFSET(force_dither), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { "disable_fbos", "Force-disable FBOs", OFFSET(disable_fbos), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { NULL }, +Index: jellyfin-ffmpeg/libavutil/hwcontext_vulkan.c +=================================================================== +--- jellyfin-ffmpeg.orig/libavutil/hwcontext_vulkan.c ++++ jellyfin-ffmpeg/libavutil/hwcontext_vulkan.c +@@ -1394,6 +1394,7 @@ static int vulkan_device_create_internal + goto end; + } + p->device_features_1_2.timelineSemaphore = 1; ++ p->device_features_1_2.hostQueryReset = dev_features_1_2.hostQueryReset; + + /* Setup queue family */ + if ((err = setup_queue_families(ctx, &dev_info))) From 37f65e28920a63b4bd8f56cc499e204636b92d53 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Sun, 11 Feb 2024 20:04:20 +0800 Subject: [PATCH 2/4] Sync RKMPP fixes from ffmpeg-rockchip Signed-off-by: nyanmisaka --- ...ipeline-for-rockchip-rk3588-platform.patch | 67 +++++++++---------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/debian/patches/0058-add-full-hwa-pipeline-for-rockchip-rk3588-platform.patch b/debian/patches/0058-add-full-hwa-pipeline-for-rockchip-rk3588-platform.patch index 418fe01c6ff..16b6eaabcf0 100644 --- a/debian/patches/0058-add-full-hwa-pipeline-for-rockchip-rk3588-platform.patch +++ b/debian/patches/0058-add-full-hwa-pipeline-for-rockchip-rk3588-platform.patch @@ -273,7 +273,7 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c * * This file is part of FFmpeg. * -@@ -19,569 +20,931 @@ +@@ -19,569 +20,933 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -924,11 +924,11 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c + light = av_content_light_metadata_create_side_data(frame); + if (!light) + return AVERROR(ENOMEM); -+ -+ light->MaxCLL = mpp_light.MaxCLL; -+ light->MaxFALL = mpp_light.MaxFALL; - av_free(desc); ++ light->MaxCLL = mpp_light.MaxCLL; ++ light->MaxFALL = mpp_light.MaxFALL; ++ + return 0; } @@ -1239,17 +1239,11 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c - } else { - av_log(avctx, AV_LOG_ERROR, "Failed to retrieve the frame buffer, frame is dropped (code = %d)\n", ret); - mpp_frame_deinit(&mppframe); -- } -- } else if (decoder->eos_reached) { -- return AVERROR_EOF; -- } else if (ret == MPP_ERR_TIMEOUT) { -- av_log(avctx, AV_LOG_DEBUG, "Timeout when trying to get a frame from MPP\n"); + if ((ret = r->mapi->control(r->mctx, MPP_SET_OUTPUT_TIMEOUT, (MppParam)&timeout)) != MPP_OK) { + av_log(avctx, AV_LOG_ERROR, "Failed to set output timeout: %d\n", ret); + return AVERROR_EXTERNAL; - } - -- return AVERROR(EAGAIN); ++ } ++ + ret = r->mapi->decode_get_frame(r->mctx, &mpp_frame); + if (ret != MPP_OK && ret != MPP_ERR_TIMEOUT) { + av_log(avctx, AV_LOG_ERROR, "Failed to get frame: %d\n", ret); @@ -1261,10 +1255,17 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c + } + if (mpp_frame_get_eos(mpp_frame)) { + av_log(avctx, AV_LOG_DEBUG, "Received a 'EOS' frame\n"); -+ r->eof = 1; -+ ret = AVERROR_EOF; -+ goto exit; -+ } ++ /* EOS frame may contain valid data */ ++ if (!mpp_frame_get_buffer(mpp_frame)) { ++ r->eof = 1; ++ ret = AVERROR_EOF; ++ goto exit; + } +- } else if (decoder->eos_reached) { +- return AVERROR_EOF; +- } else if (ret == MPP_ERR_TIMEOUT) { +- av_log(avctx, AV_LOG_DEBUG, "Timeout when trying to get a frame from MPP\n"); + } + if (mpp_frame_get_discard(mpp_frame)) { + av_log(avctx, AV_LOG_DEBUG, "Received a 'discard' frame\n"); + ret = AVERROR(EAGAIN); @@ -1299,9 +1300,7 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c + avctx->pix_fmt = ret; + } --fail: -- if (mppframe) -- mpp_frame_deinit(&mppframe); +- return AVERROR(EAGAIN); + avctx->width = mpp_frame_get_width(mpp_frame); + avctx->height = mpp_frame_get_height(mpp_frame); + avctx->coded_width = FFALIGN(avctx->width, 64); @@ -1328,8 +1327,9 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c + goto exit; + } -- if (framecontext) -- av_buffer_unref(&framecontext->decoder_ref); +-fail: +- if (mppframe) +- mpp_frame_deinit(&mppframe); + if ((ret = r->mapi->control(r->mctx, MPP_DEC_SET_INFO_CHANGE_READY, NULL)) != MPP_OK) { + av_log(avctx, AV_LOG_ERROR, "Failed to set info change ready: %d\n", ret); + ret = AVERROR_EXTERNAL; @@ -1389,29 +1389,31 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c + } + } -- if (framecontextref) -- av_buffer_unref(&framecontextref); +- if (framecontext) +- av_buffer_unref(&framecontext->decoder_ref); +exit: + if (mpp_frame) + mpp_frame_deinit(&mpp_frame); + return ret; +} -- if (desc) -- av_free(desc); +- if (framecontextref) +- av_buffer_unref(&framecontextref); +static int rkmpp_send_eos(AVCodecContext *avctx) +{ + RKMPPDecContext *r = avctx->priv_data; + MppPacket mpp_pkt = NULL; + int ret; -- return ret; +- if (desc) +- av_free(desc); + if ((ret = mpp_packet_init(&mpp_pkt, NULL, 0)) != MPP_OK) { + av_log(avctx, AV_LOG_ERROR, "Failed to init 'EOS' packet: %d\n", ret); + return AVERROR_EXTERNAL; + } + mpp_packet_set_eos(mpp_pkt); -+ + +- return ret; + do { + ret = r->mapi->decode_put_packet(r->mctx, mpp_pkt); + } while (ret != MPP_OK); @@ -1567,7 +1569,6 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.c - if (ret == MPP_OK) { - decoder->first_packet = 1; + av_packet_unref(&r->last_pkt); -+ av_frame_unref(&r->last_frame); } else - av_log(avctx, AV_LOG_ERROR, "Failed to reset MPI (code = %d)\n", ret); + av_log(avctx, AV_LOG_ERROR, "Failed to reset MPP context: %d\n", ret); @@ -1641,7 +1642,7 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.h =================================================================== --- /dev/null +++ jellyfin-ffmpeg/libavcodec/rkmppdec.h -@@ -0,0 +1,157 @@ +@@ -0,0 +1,155 @@ +/* + * Copyright (c) 2017 Lionel CHAZALLON + * Copyright (c) 2023 Huseyin BIYIK @@ -1698,8 +1699,6 @@ Index: jellyfin-ffmpeg/libavcodec/rkmppdec.h + AVBufferRef *hwframe; + + AVPacket last_pkt; -+ AVFrame last_frame; -+ + int eof; + int info_change; + int errinfo_cnt; @@ -5543,7 +5542,7 @@ Index: jellyfin-ffmpeg/libavutil/hwcontext_opencl.c { OpenCLDeviceSelector selector = { .platform_index = -1, -@@ -3193,6 +3208,7 @@ static int opencl_map_from_drm_arm(AVHWF +@@ -3198,6 +3213,7 @@ static int opencl_map_from_drm_arm(AVHWF AVHWFramesContext *src_fc = (AVHWFramesContext*)src->hw_frames_ctx->data; AVOpenCLDeviceContext *dst_dev = dst_fc->device_ctx->hwctx; @@ -5551,7 +5550,7 @@ Index: jellyfin-ffmpeg/libavutil/hwcontext_opencl.c const AVDRMFrameDescriptor *desc; DRMARMtoOpenCLMapping *mapping = NULL; cl_mem_flags cl_flags; -@@ -3226,8 +3242,8 @@ static int opencl_map_from_drm_arm(AVHWF +@@ -3231,8 +3247,8 @@ static int opencl_map_from_drm_arm(AVHWF } mapping->object_buffers[i] = @@ -5562,7 +5561,7 @@ Index: jellyfin-ffmpeg/libavutil/hwcontext_opencl.c if (!mapping->object_buffers[i]) { av_log(dst_fc, AV_LOG_ERROR, "Failed to create CL buffer " "from object %d (fd %d, size %"SIZE_SPECIFIER") of DRM frame: %d.\n", -@@ -3258,6 +3274,8 @@ static int opencl_map_from_drm_arm(AVHWF +@@ -3263,6 +3279,8 @@ static int opencl_map_from_drm_arm(AVHWF goto fail; } From e1357f95b723650c67e2aa2ba815758b2ec40363 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Mon, 12 Feb 2024 02:09:42 +0800 Subject: [PATCH 3/4] Update build scripts and dependencies Signed-off-by: nyanmisaka --- ...djusts-bit_shift-for-drm-p010-frames.patch | 41 +++++++++++++++++++ builder/scripts.d/50-ffnvcodec.sh | 2 +- builder/scripts.d/50-vulkan/60-libplacebo.sh | 13 +++++- docker-build-win64.sh | 2 +- docker-build.sh | 18 ++++++-- 5 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 builder/patches/libplacebo/0000-utils-libav-only-adjusts-bit_shift-for-drm-p010-frames.patch diff --git a/builder/patches/libplacebo/0000-utils-libav-only-adjusts-bit_shift-for-drm-p010-frames.patch b/builder/patches/libplacebo/0000-utils-libav-only-adjusts-bit_shift-for-drm-p010-frames.patch new file mode 100644 index 00000000000..9fc0255740f --- /dev/null +++ b/builder/patches/libplacebo/0000-utils-libav-only-adjusts-bit_shift-for-drm-p010-frames.patch @@ -0,0 +1,41 @@ +From a5e701025dce2036930b9e049862e5355b07a45f Mon Sep 17 00:00:00 2001 +From: David Rosca +Date: Tue, 9 Jan 2024 13:38:08 +0100 +Subject: [PATCH] utils/libav: Only adjust bit_shift for DRM P010 frames + +Fixes mapping Vulkan P010 frames. + +Closes #237 +--- + src/include/libplacebo/utils/libav_internal.h | 11 ++++++----- + 1 file changed, 6 insertions(+), 5 deletions(-) + +diff --git a/src/include/libplacebo/utils/libav_internal.h b/src/include/libplacebo/utils/libav_internal.h +index 4c269e5d..992e5ca6 100644 +--- a/src/include/libplacebo/utils/libav_internal.h ++++ b/src/include/libplacebo/utils/libav_internal.h +@@ -967,11 +967,6 @@ static void pl_fix_hwframe_sample_depth(struct pl_frame *out, const AVFrame *fra + struct pl_bit_encoding *bits = &out->repr.bits; + + bits->sample_depth = fmt->component_depth[0]; +- +- switch (hwfc->sw_format) { +- case AV_PIX_FMT_P010: bits->bit_shift = 6; break; +- default: break; +- } + } + + static bool pl_map_avframe_drm(pl_gpu gpu, struct pl_frame *out, +@@ -1016,6 +1011,12 @@ static bool pl_map_avframe_drm(pl_gpu gpu, struct pl_frame *out, + } + + pl_fix_hwframe_sample_depth(out, frame); ++ ++ switch (hwfc->sw_format) { ++ case AV_PIX_FMT_P010: out->repr.bits.bit_shift = 6; break; ++ default: break; ++ } ++ + return true; + } + diff --git a/builder/scripts.d/50-ffnvcodec.sh b/builder/scripts.d/50-ffnvcodec.sh index 7827780aeca..fac18e14085 100755 --- a/builder/scripts.d/50-ffnvcodec.sh +++ b/builder/scripts.d/50-ffnvcodec.sh @@ -1,7 +1,7 @@ #!/bin/bash SCRIPT_REPO="https://github.com/FFmpeg/nv-codec-headers.git" -SCRIPT_COMMIT="c5e4af74850a616c42d39ed45b9b8568b71bf8bf" +SCRIPT_COMMIT="451da99614412a7f9526ef301a5ee0c7a6f9ad76" ffbuild_enabled() { [[ $TARGET == *arm64 ]] && return -1 diff --git a/builder/scripts.d/50-vulkan/60-libplacebo.sh b/builder/scripts.d/50-vulkan/60-libplacebo.sh index a7c85d17ea7..889dfea755c 100755 --- a/builder/scripts.d/50-vulkan/60-libplacebo.sh +++ b/builder/scripts.d/50-vulkan/60-libplacebo.sh @@ -1,17 +1,28 @@ #!/bin/bash SCRIPT_REPO="https://code.videolan.org/videolan/libplacebo.git" -SCRIPT_COMMIT="ed29e541a55acf28022738440b2a925386292551" +SCRIPT_COMMIT="64c1954570f1cd57f8570a57e51fb0249b57bb90" ffbuild_enabled() { return 0 } +ffbuild_dockerstage() { + to_df "RUN --mount=src=${SELF},dst=/stage.sh --mount=src=patches/libplacebo,dst=/patches run_stage /stage.sh" +} + ffbuild_dockerbuild() { git-mini-clone "$SCRIPT_REPO" "$SCRIPT_COMMIT" placebo cd placebo git submodule update --init --recursive + for patch in /patches/*.patch; do + echo "Applying $patch" + patch -p1 < "$patch" + done + + sed -i 's/DPL_EXPORT/DPL_STATIC/' src/meson.build + mkdir build && cd build local myconf=( diff --git a/docker-build-win64.sh b/docker-build-win64.sh index 5ab3677ab06..71b33f968e4 100755 --- a/docker-build-win64.sh +++ b/docker-build-win64.sh @@ -544,7 +544,7 @@ EOF popd # FFNVCODEC -git clone -b n12.0.16.0 --depth=1 https://github.com/FFmpeg/nv-codec-headers.git +git clone -b n12.0.16.1 --depth=1 https://github.com/FFmpeg/nv-codec-headers.git pushd nv-codec-headers make PREFIX=${FF_DEPS_PREFIX} install popd diff --git a/docker-build.sh b/docker-build.sh index 642c5738557..f3fc97a3472 100755 --- a/docker-build.sh +++ b/docker-build.sh @@ -162,7 +162,7 @@ prepare_extra_common() { prepare_extra_amd64() { # FFNVCODEC pushd ${SOURCE_DIR} - git clone -b n12.0.16.0 --depth=1 https://github.com/FFmpeg/nv-codec-headers.git + git clone -b n12.0.16.1 --depth=1 https://github.com/FFmpeg/nv-codec-headers.git pushd nv-codec-headers make && make install popd @@ -300,7 +300,7 @@ prepare_extra_amd64() { # ONEVPL-INTEL-GPU (RT only) # Provides VPL runtime (libmfx-gen.so.1.2) for 11th Gen Tiger Lake and newer pushd ${SOURCE_DIR} - git clone -b intel-onevpl-24.1.1 --depth=1 https://github.com/oneapi-src/oneVPL-intel-gpu.git + git clone -b intel-onevpl-24.1.3 --depth=1 https://github.com/oneapi-src/oneVPL-intel-gpu.git pushd oneVPL-intel-gpu mkdir build && pushd build cmake -DCMAKE_INSTALL_PREFIX=${TARGET_DIR} \ @@ -320,7 +320,7 @@ prepare_extra_amd64() { # Full Feature Build: ENABLE_KERNELS=ON(Default) ENABLE_NONFREE_KERNELS=ON(Default) # Free Kernel Build: ENABLE_KERNELS=ON ENABLE_NONFREE_KERNELS=OFF pushd ${SOURCE_DIR} - git clone -b intel-media-24.1.1 --depth=1 https://github.com/intel/media-driver.git + git clone -b intel-media-24.1.3 --depth=1 https://github.com/intel/media-driver.git pushd media-driver mkdir build && pushd build cmake -DCMAKE_INSTALL_PREFIX=${TARGET_DIR} \ @@ -450,8 +450,18 @@ prepare_extra_amd64() { fi # LIBPLACEBO + pl_ver="v6.338.2" + if [[ $( lsb_release -c -s ) == "buster" ]]; then + pl_ver="v5.264.1" + fi pushd ${SOURCE_DIR} - git clone -b v5.264.1 --recursive --depth=1 https://github.com/haasn/libplacebo.git + git clone -b ${pl_ver} --recursive --depth=1 https://github.com/haasn/libplacebo.git + if [[ $( lsb_release -c -s ) != "buster" ]]; then + pushd libplacebo + # fix p010 green screen in v6.338.2 + wget -q -O - https://github.com/haasn/libplacebo/commit/a5e7010.patch | git apply + popd + fi sed -i 's|env: python_env,||g' libplacebo/src/vulkan/meson.build meson setup libplacebo placebo_build \ --prefix=${TARGET_DIR} \ From 47769dfbe9e3ecd195c6cd58a5a1a20ea67b4a77 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Sun, 11 Feb 2024 20:07:24 +0800 Subject: [PATCH 4/4] Bump version to 6.0.1-3 Signed-off-by: nyanmisaka --- build.yaml | 2 +- debian/changelog | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/build.yaml b/build.yaml index e37393073b4..0eef467d7bf 100644 --- a/build.yaml +++ b/build.yaml @@ -1,7 +1,7 @@ --- # We just wrap `build` so this is really it name: "jellyfin-ffmpeg" -version: "6.0.1-2" +version: "6.0.1-3" packages: - buster-amd64 - buster-armhf diff --git a/debian/changelog b/debian/changelog index 31855894dbb..bc7907ea029 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +jellyfin-ffmpeg (6.0.1-3) unstable; urgency=medium + + * Fix libplacebo v6 required hostQueryReset capability + * Sync RKMPP fixes from ffmpeg-rockchip + * Update build scripts and dependencies + jellyfin-ffmpeg (6.0.1-2) unstable; urgency=medium * Add full HWA pipeline for Rockchip RK3588 platform