From 8a796c76c81f8bffd0b7ce94342d771d5f5cc4e4 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 17 Nov 2023 15:07:12 +0100 Subject: [PATCH] ffmpeg: add patch to workaround vlc crash with dxva2 hwaccel --- .../0015-guard-null-hw-frames-ctx.patch | 69 +++++++++++++++++++ mingw-w64-ffmpeg/PKGBUILD | 9 ++- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 mingw-w64-ffmpeg/0015-guard-null-hw-frames-ctx.patch diff --git a/mingw-w64-ffmpeg/0015-guard-null-hw-frames-ctx.patch b/mingw-w64-ffmpeg/0015-guard-null-hw-frames-ctx.patch new file mode 100644 index 0000000000..57545acdeb --- /dev/null +++ b/mingw-w64-ffmpeg/0015-guard-null-hw-frames-ctx.patch @@ -0,0 +1,69 @@ +Guard against segfault running VLC decoding under msys2 [1]: + +Thread 33 received signal SIGSEGV, Segmentation fault. +[Switching to Thread 37728.0xadd0] +ff_hwaccel_frame_priv_alloc (avctx=0x6447b00, hwaccel_picture_private=0x65dfd00) + at libavcodec/decode.c:1848 +1848 frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; +(gdb) bt + at libavcodec/decode.c:1848 + at libavcodec/h264_slice.c:208 + first_slice=1) at libavcodec/h264_slice.c:1599 + at libavcodec/h264_slice.c:2130 + at libavcodec/h264dec.c:652 + got_frame=0x646e4b0, avpkt=0x64522c0) at libavcodec/h264dec.c:1048 + +(gdb) p avctx +$1 = (AVCodecContext *) 0x6447b00 +(gdb) p avctx->hw_frames_ctx +$2 = (AVBufferRef *) 0x0 + +v2: check for free_frame_priv (Hendrik) +v3: return EINVAL (Christoph Reiter) + +See[1]: https://github.com/msys2/MINGW-packages/pull/19050 +Fixes: be07145109 ("avcodec: add AVHWAccel.free_frame_priv callback") +CC: Lynne +CC: Christoph Reiter +Signed-off-by: Dmitry Rogozhkin +--- + libavcodec/decode.c | 18 +++++++++++++----- + 1 file changed, 13 insertions(+), 5 deletions(-) + +diff --git a/libavcodec/decode.c b/libavcodec/decode.c +index ad39021..50c3995 100644 +--- a/libavcodec/decode.c ++++ b/libavcodec/decode.c +@@ -1838,17 +1838,25 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) + int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private) + { + const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel); +- AVHWFramesContext *frames_ctx; + + if (!hwaccel || !hwaccel->frame_priv_data_size) + return 0; + + av_assert0(!*hwaccel_picture_private); + +- frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; +- *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, +- frames_ctx->device_ctx, +- hwaccel->free_frame_priv); ++ if (hwaccel->free_frame_priv) { ++ AVHWFramesContext *frames_ctx; ++ ++ if (!avctx->hw_frames_ctx) ++ return AVERROR(EINVAL); ++ ++ *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, ++ frames_ctx->device_ctx, ++ hwaccel->free_frame_priv); ++ } else { ++ *hwaccel_picture_private = ff_refstruct_allocz(hwaccel->frame_priv_data_size); ++ } ++ + if (!*hwaccel_picture_private) + return AVERROR(ENOMEM); + +-- +1.8.3.1 \ No newline at end of file diff --git a/mingw-w64-ffmpeg/PKGBUILD b/mingw-w64-ffmpeg/PKGBUILD index c5bb455c87..7af00eec7d 100644 --- a/mingw-w64-ffmpeg/PKGBUILD +++ b/mingw-w64-ffmpeg/PKGBUILD @@ -69,14 +69,16 @@ source=(https://ffmpeg.org/releases/${_realname}-${pkgver}.tar.xz{,.asc} "pathtools.c" "pathtools.h" "0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch" - "0009-wrong-null-type.patch") + "0009-wrong-null-type.patch" + "0015-guard-null-hw-frames-ctx.patch") validpgpkeys=('FCF986EA15E6E293A5644F10B4322F04D67658D8') sha256sums=('488c76e57dd9b3bee901f71d5c95eaf1db4a5a31fe46a28654e837144207c270' 'SKIP' 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' '1585ef1b61cf53a2ca27049c11d49e0834683dfda798f03547761375df482a90' '8c74e9b5800dbb41c33a60114712726ec768ad6de8f147c2eb30656fd4c899cc' - 'f76048e6e1944e15f646a52b75e75bc8906ca80f2a3124fba6a2050722750447') + 'f76048e6e1944e15f646a52b75e75bc8906ca80f2a3124fba6a2050722750447' + 'ddad247ff44287b5d0089b5b910b4ba0272404c71b2ffb127e3cf833e8b1cb74') # Helper macros to help make tasks easier # apply_patch_with_msg() { @@ -100,6 +102,9 @@ prepare() { 0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch apply_patch_with_msg 0009-wrong-null-type.patch + + # https://github.com/msys2/MINGW-packages/pull/19050#issuecomment-1810884473 + apply_patch_with_msg 0015-guard-null-hw-frames-ctx.patch } build() {