From 0ac403aff7086ad6de722e397462dbc292fa5394 Mon Sep 17 00:00:00 2001 From: gnattu Date: Wed, 8 May 2024 12:23:43 +0800 Subject: [PATCH] lavc/videotoolbox: Add low_priority key_frame_only decoding --- ...076-vt-enable-keyframe-only-decoding.patch | 19 ----- ...76-vt-low-priority-keyframe-decoding.patch | 72 +++++++++++++++++++ debian/patches/series | 3 +- 3 files changed, 73 insertions(+), 21 deletions(-) delete mode 100644 debian/patches/0076-vt-enable-keyframe-only-decoding.patch create mode 100644 debian/patches/0076-vt-low-priority-keyframe-decoding.patch diff --git a/debian/patches/0076-vt-enable-keyframe-only-decoding.patch b/debian/patches/0076-vt-enable-keyframe-only-decoding.patch deleted file mode 100644 index 6580665088e..00000000000 --- a/debian/patches/0076-vt-enable-keyframe-only-decoding.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c -index c234b18f59..72e8137b35 100644 ---- a/libavcodec/videotoolbox.c -+++ b/libavcodec/videotoolbox.c -@@ -983,6 +983,14 @@ static int videotoolbox_start(AVCodecContext *avctx) - av_log(avctx, AV_LOG_ERROR, "VideoToolbox reported invalid data.\n"); - return AVERROR_INVALIDDATA; - case 0: -+ if (avctx->skip_frame >= AVDISCARD_NONKEY) { -+ status = VTSessionSetProperty(videotoolbox->session, -+ kVTDecompressionPropertyKey_OnlyTheseFrames, -+ kVTDecompressionProperty_OnlyTheseFrames_KeyFrames); -+ if (status) { -+ av_log(avctx, AV_LOG_WARNING, "kVTDecompressionProperty_OnlyTheseFrames_KeyFrames is not supported on this device. Ignoring.\n"); -+ } -+ } - return 0; - default: - av_log(avctx, AV_LOG_ERROR, "Unknown VideoToolbox session creation error %d\n", (int)status); diff --git a/debian/patches/0076-vt-low-priority-keyframe-decoding.patch b/debian/patches/0076-vt-low-priority-keyframe-decoding.patch new file mode 100644 index 00000000000..5fd998125d5 --- /dev/null +++ b/debian/patches/0076-vt-low-priority-keyframe-decoding.patch @@ -0,0 +1,72 @@ +Subject: [PATCH] lavcvideotoolbox: Add low_priority key_frame_only decoding +--- +Index: libavcodec/avcodec.h +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h +--- a/libavcodec/avcodec.h (revision 019c5b13ace26af67613d27f333104e90bde8b31) ++++ b/libavcodec/avcodec.h (revision c58e99fd3e45d898d4726456f6bddb0453592bac) +@@ -2275,6 +2275,13 @@ + */ + #define AV_HWACCEL_FLAG_UNSAFE_OUTPUT (1 << 3) + ++/** ++ * Some hardware decoders (like VideoToolbox) supports decode session priority ++ * that run decode pipeline at a lower priority than is used for realtime decoding. ++ * This will be useful for background processing without interrupting normal playback. ++ */ ++#define AV_HWACCEL_FLAG_LOW_PRIORITY (1 << 4) ++ + /** + * @} + */ +Index: libavcodec/options_table.h +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h +--- a/libavcodec/options_table.h (revision 019c5b13ace26af67613d27f333104e90bde8b31) ++++ b/libavcodec/options_table.h (revision c58e99fd3e45d898d4726456f6bddb0453592bac) +@@ -397,6 +397,7 @@ + {"unsafe_output", "allow potentially unsafe hwaccel frame output that might require special care to process successfully", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_UNSAFE_OUTPUT }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"}, + {"extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, V|D }, + {"discard_damaged_percentage", "Percentage of damaged samples to discard a frame", OFFSET(discard_damaged_percentage), AV_OPT_TYPE_INT, {.i64 = 95 }, 0, 100, V|D }, ++{"low_priority", "attempt to run decode pipeline at a lower priority than is used for realtime decoding", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_LOW_PRIORITY }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"}, + {NULL}, + }; + +Index: libavcodec/videotoolbox.c +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c +--- a/libavcodec/videotoolbox.c (revision 019c5b13ace26af67613d27f333104e90bde8b31) ++++ b/libavcodec/videotoolbox.c (revision c58e99fd3e45d898d4726456f6bddb0453592bac) +@@ -983,6 +983,23 @@ + av_log(avctx, AV_LOG_ERROR, "VideoToolbox reported invalid data.\n"); + return AVERROR_INVALIDDATA; + case 0: ++ if (avctx->skip_frame >= AVDISCARD_NONKEY) { ++ status = VTSessionSetProperty(videotoolbox->session, ++ kVTDecompressionPropertyKey_OnlyTheseFrames, ++ kVTDecompressionProperty_OnlyTheseFrames_KeyFrames); ++ if (status) { ++ av_log(avctx, AV_LOG_WARNING, "kVTDecompressionProperty_OnlyTheseFrames_KeyFrames is not supported on this device. Ignoring.\n"); ++ } ++ } ++ if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_LOW_PRIORITY) { ++ status = VTSessionSetProperty(videotoolbox->session, ++ kVTDecompressionPropertyKey_RealTime, ++ kCFBooleanFalse); ++ av_log(avctx, AV_LOG_INFO, "Decoder running at lower priority.\n"); ++ if (status) { ++ av_log(avctx, AV_LOG_WARNING, "kVTDecompressionPropertyKey_RealTime is not supported on this device. Ignoring.\n"); ++ } ++ } + return 0; + default: + av_log(avctx, AV_LOG_ERROR, "Unknown VideoToolbox session creation error %d\n", (int)status); diff --git a/debian/patches/series b/debian/patches/series index 83194f612c6..34479e1ae8e 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -73,5 +73,4 @@ 0073-opus-allow-5point1-side-inputs.patch 0074-add-dovi-descriptor-support-in-mpegtsenc.patch 0075-fix-gcc-14-warnings-in-qsv-hwcontext.patch -0076-vt-enable-keyframe-only-decoding.patch - +0076-vt-low-priority-keyframe-decoding.patch