Skip to content

Commit

Permalink
add 6.0 patches, fix patch set selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Feb 17, 2024
1 parent 94f117b commit a8ab6cb
Show file tree
Hide file tree
Showing 50 changed files with 2,497 additions and 228 deletions.
19 changes: 10 additions & 9 deletions avbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ VER_SH=version.sh
[ -f $VER_SH ] || VER_SH=ffbuild/version.sh
[ -f $VER_SH ] || VER_SH=avbuild/version.sh
FFVERSION_FULL=`./$VER_SH`
echo $FFVERSION_FULL |grep '\.' || FFVERSION_FULL=`head -n 1 RELEASE`
FFMAJOR_GEN=`echo $FFVERSION_FULL |sed 's,[a-zA-Z]*\([0-9]*\)\..*,\1,'`
#echo $FFVERSION_FULL |grep '\.' || FFVERSION_FULL=`head -n 1 RELEASE` # stop updating in 6.x
echo $FFVERSION_FULL |grep '\.' || FFVERSION_FULL=`grep -m 1 'cut here' doc/APIchanges |sed 's,.* \([0-9]*\.[0-9]*\) .*,\1,'`
FFMAJOR=`echo $FFVERSION_FULL |sed 's,[a-zA-Z]*\([0-9]*\)\..*,\1,'`
FFMINOR=`echo $FFVERSION_FULL |sed 's,[a-zA-Z]*[0-9]*\.\([0-9]*\).*,\1,'`
MAJOR_GUESS=`cat libavutil/version.h |grep LIBAVUTIL_VERSION_MAJOR |head -n 1`
MAJOR_GUESS=${MAJOR_GUESS##* }
MAJOR_GUESS=$((MAJOR_GUESS-52))
FFGIT=false
echo $FFMAJOR |grep '\-' &>/dev/null && {
echo $FFMAJOR_GEN |grep '\-' &>/dev/null && {
FFGIT=true
FFMAJOR=$MAJOR_GUESS
}
Expand All @@ -94,21 +96,19 @@ echo $FFMAJOR |grep '\-' &>/dev/null && {
FFMAJOR=$MAJOR_GUESS
FFMINOR=0
}
! $FFGIT && [ ${FFMAJOR} -gt 3 ] && FFGIT=true
PATCH_BRANCH=master
[ $FFMAJOR -lt 5 ] && PATCH_BRANCH=4.4
[ $FFMAJOR -eq 5 ] && PATCH_BRANCH=5.1
[ $FFMAJOR -eq 6 -a $FFMINOR -lt 1 ] && PATCH_BRANCH=6.0
echo "FFmpeg/Libav version: $FFMAJOR.$FFMINOR git: $FFGIT. patch set version: $PATCH_BRANCH"
USE_VK=false
if $FFGIT; then
USE_VK=true
for p in $(find "$THIS_DIR/patches-$PATCH_BRANCH" -name "*.patch"); do
USE_VK=$FFGIT
if $FFGIT || [ ${FFMAJOR} -gt 3 ]; then
for p in $(find -s "$THIS_DIR/patches-$PATCH_BRANCH" -name "*.patch"); do
echo $p
patch -p1 -N < $p
done
fi
[ $FFMAJOR -ge 6 -a $FFMAJOR -ge 1 ] && USE_VK=true
$USE_VK || disable_opt vulkan
cd -

toupper(){
Expand Down Expand Up @@ -218,6 +218,7 @@ enable_libmfx(){
}

enable_opt hwaccels
$USE_VK || disable_opt vulkan

add_elf_flags() {
# -Wl,-z,noexecstack -Wl,--as-needed is added by configure
Expand Down Expand Up @@ -311,7 +312,7 @@ use_llvm_binutils() {
local clang_dir=${USE_TOOLCHAIN%clang*}
local clang_name=${USE_TOOLCHAIN##*/}
local clang=$clang_dir${clang_name/-cl/}
local CLANG_FALLBACK=clang-${LLVM_VER:-17}
local CLANG_FALLBACK=clang-${LLVM_VER:-18}
$IS_APPLE_CLANG && CLANG_FALLBACK=/usr/local/opt/llvm/bin/clang
echo "clang: `$clang --version`"
# -print-prog-name= prints native dir format(on windows) and `which` fails
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 93069bf6d85c7173b657367ac2c6b0b55d9d8989 Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Sat, 28 Oct 2017 20:26:50 +0800
Subject: [PATCH 01/30] use CreateMutexEx instead of CreateMutex to fix win8
store app link error

---
libavutil/hwcontext_d3d11va.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 363ec6a47d..fc7519c783 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -41,6 +41,10 @@
#include "thread.h"
#include "compat/w32dlfcn.h"

+#ifndef CreateMutexEx
+#define CreateMutexEx(lpMutexAttributes, lpName, dwFlags, dwDesiredAccess) CreateMutex(lpMutexAttributes, lpName, dwFlags)
+#endif
+
typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);

static AVOnce functions_loaded = AV_ONCE_INIT;
@@ -482,7 +486,7 @@ static int d3d11va_device_init(AVHWDeviceContext *hwdev)
HRESULT hr;

if (!device_hwctx->lock) {
- device_hwctx->lock_ctx = CreateMutex(NULL, 0, NULL);
+ device_hwctx->lock_ctx = CreateMutexEx(NULL, NULL, 0, 0);
if (device_hwctx->lock_ctx == INVALID_HANDLE_VALUE) {
av_log(NULL, AV_LOG_ERROR, "Failed to create a mutex\n");
return AVERROR(EINVAL);
--
2.39.3 (Apple Git-145)

35 changes: 35 additions & 0 deletions patches-6.0/0002-mmal-enable-0-copy-for-egl-interop.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From eb2dfdeef151d24f6fb2cd857b32d23e51f5d105 Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Sun, 29 Oct 2017 23:19:07 +0800
Subject: [PATCH 02/30] mmal: enable 0-copy for egl interop

---
libavcodec/mmaldec.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
index 3092f58510..f5f569ab0a 100644
--- a/libavcodec/mmaldec.c
+++ b/libavcodec/mmaldec.c
@@ -300,6 +300,8 @@ static int ffmal_update_format(AVCodecContext *avctx)
goto fail;

if (avctx->pix_fmt == AV_PIX_FMT_MMAL) {
+ if ((status = mmal_port_parameter_set_boolean(decoder->output[0], MMAL_PARAMETER_ZERO_COPY, 1)))
+ goto fail;
format_out->encoding = MMAL_ENCODING_OPAQUE;
} else {
format_out->encoding_variant = format_out->encoding = MMAL_ENCODING_I420;
@@ -337,7 +339,8 @@ static int ffmal_update_format(AVCodecContext *avctx)
FFMAX(decoder->output[0]->buffer_size_min, decoder->output[0]->buffer_size_recommended);
decoder->output[0]->buffer_num =
FFMAX(decoder->output[0]->buffer_num_min, decoder->output[0]->buffer_num_recommended) + ctx->extra_buffers;
- ctx->pool_out->pool = mmal_pool_create(decoder->output[0]->buffer_num,
+ ctx->pool_out->pool = mmal_port_pool_create(decoder->output[0],
+ decoder->output[0]->buffer_num,
decoder->output[0]->buffer_size);
if (!ctx->pool_out->pool) {
ret = AVERROR(ENOMEM);
--
2.39.3 (Apple Git-145)

30 changes: 30 additions & 0 deletions patches-6.0/0003-configure-fix-mmal-probing-in-cross-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From af9e79a6347d574819b1fd0ca2232bc730251eb5 Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Sun, 29 Oct 2017 23:22:25 +0800
Subject: [PATCH 03/30] configure: fix mmal probing in cross build

---
configure | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 3cd3bdfb44..eafc204e58 100755
--- a/configure
+++ b/configure
@@ -6745,11 +6745,11 @@ enabled mbedtls && { check_pkg_config mbedtls mbedtls mbedtls/x509_crt
check_lib mbedtls mbedtls/ssl.h mbedtls_ssl_init -lmbedtls -lmbedx509 -lmbedcrypto ||
die "ERROR: mbedTLS not found"; }
enabled mediacodec && { enabled jni || die "ERROR: mediacodec requires --enable-jni"; }
-enabled mmal && { check_lib mmal interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host ||
+enabled mmal && { check_lib mmal interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host -lvcos -lpthread ||
{ ! enabled cross_compile &&
add_cflags -isystem/opt/vc/include/ -isystem/opt/vc/include/interface/vmcs_host/linux -isystem/opt/vc/include/interface/vcos/pthreads -fgnu89-inline &&
add_ldflags -L/opt/vc/lib/ &&
- check_lib mmal interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host; } ||
+ check_lib mmal interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host -lvcos -lpthread; } ||
die "ERROR: mmal not found" &&
check_func_headers interface/mmal/mmal.h "MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS"; }
enabled openal && { check_pkg_config openal "openal >= 1.1" "AL/al.h" alGetError ||
--
2.39.3 (Apple Git-145)

76 changes: 76 additions & 0 deletions patches-6.0/0004-videotoolbox-check-runtime-availability.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
From e19a2f2dede270dae888337cb8478f799477be6b Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Sun, 29 Oct 2017 23:35:28 +0800
Subject: [PATCH 04/30] videotoolbox: check runtime availability

fix warnings/errors for new compiler (since xcode9) if targeting
macOS<10.8
---
libavcodec/videotoolbox.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index e42fea6f32..ab05404fd9 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -39,6 +39,10 @@
#include <AvailabilityMacros.h>
#include <TargetConditionals.h>

+#if !__has_builtin(__builtin_available)
+#define __builtin_available(...) (true)
+#endif
+
#ifndef kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder
# define kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder CFSTR("RequireHardwareAcceleratedVideoDecoder")
#endif
@@ -708,7 +712,7 @@ static void videotoolbox_decoder_callback(void *opaque,

static OSStatus videotoolbox_session_decode_frame(AVCodecContext *avctx)
{
- OSStatus status;
+ OSStatus status = kVTInvalidSessionErr;
CMSampleBufferRef sample_buf;
AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
VTContext *vtctx = avctx->internal->hwaccel_priv_data;
@@ -720,13 +724,15 @@ static OSStatus videotoolbox_session_decode_frame(AVCodecContext *avctx)
if (!sample_buf)
return -1;

- status = VTDecompressionSessionDecodeFrame(videotoolbox->session,
+ if (__builtin_available(macOS 10.8, iOS 8.0, tvOS 10.2, *)) {
+ status = VTDecompressionSessionDecodeFrame(videotoolbox->session,
sample_buf,
0, // decodeFlags
NULL, // sourceFrameRefCon
0); // infoFlagsOut
- if (status == noErr)
- status = VTDecompressionSessionWaitForAsynchronousFrames(videotoolbox->session);
+ if (status == noErr)
+ status = VTDecompressionSessionWaitForAsynchronousFrames(videotoolbox->session);
+ }

CFRelease(sample_buf);

@@ -860,7 +866,7 @@ static CFDictionaryRef videotoolbox_decoder_config_create(CMVideoCodecType codec
static int videotoolbox_start(AVCodecContext *avctx)
{
AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
- OSStatus status;
+ OSStatus status = kVTInvalidSessionErr;
VTDecompressionOutputCallbackRecord decoder_cb;
CFDictionaryRef decoder_spec;
CFDictionaryRef buf_attr;
@@ -951,7 +957,8 @@ static int videotoolbox_start(AVCodecContext *avctx)
decoder_cb.decompressionOutputCallback = videotoolbox_decoder_callback;
decoder_cb.decompressionOutputRefCon = avctx->internal->hwaccel_priv_data;

- status = VTDecompressionSessionCreate(NULL, // allocator
+ if (__builtin_available(macOS 10.8, iOS 8.0, tvOS 10.2, *))
+ status = VTDecompressionSessionCreate(NULL, // allocator
videotoolbox->cm_fmt_desc, // videoFormatDescription
decoder_spec, // videoDecoderSpecification
buf_attr, // destinationImageBufferAttributes
--
2.39.3 (Apple Git-145)

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From 7036120bd563c471b8d7d6b65b7839f0132d782e Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Sun, 29 Oct 2017 23:52:35 +0800
Subject: [PATCH 05/30] mediacodec: check whether cropping is set before use

---
libavcodec/mediacodecdec_common.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
index 03bee11918..94e7668bf3 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -481,10 +481,15 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte
}

/* Optional fields */
- AMEDIAFORMAT_GET_INT32(s->crop_top, "crop-top", 0);
- AMEDIAFORMAT_GET_INT32(s->crop_bottom, "crop-bottom", 0);
- AMEDIAFORMAT_GET_INT32(s->crop_left, "crop-left", 0);
- AMEDIAFORMAT_GET_INT32(s->crop_right, "crop-right", 0);
+ if (ff_AMediaFormat_getInt32(s->format, "crop-top", &s->crop_top) && ff_AMediaFormat_getInt32(s->format, "crop-bottom", &s->crop_bottom))
+ height = s->crop_bottom + 1 - s->crop_top;
+ else
+ height = s->height;
+
+ if (ff_AMediaFormat_getInt32(s->format, "crop-left", &s->crop_left) && ff_AMediaFormat_getInt32(s->format, "crop-right", &s->crop_right))
+ width = s->crop_right + 1 - s->crop_left;
+ else
+ width = s->width;

// Try "crop" for NDK
if (!(s->crop_right && s->crop_bottom) && s->use_ndk_codec)
--
2.39.3 (Apple Git-145)

42 changes: 42 additions & 0 deletions patches-6.0/0006-avcodec-add-AV_HWACCEL_FLAG_ALLOW_SOFTWARE.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 24d50aa38bd0fe1641069e953f47bbe290fc84a5 Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Thu, 9 Nov 2017 14:56:53 +0800
Subject: [PATCH 06/30] avcodec: add AV_HWACCEL_FLAG_ALLOW_SOFTWARE

a hw decoder may have software or hybrid implementation, for example videotoolbox hevc.
the performance may be better than ffmpeg sw decoder.
---
libavcodec/avcodec.h | 4 ++++
libavcodec/options_table.h | 1 +
2 files changed, 5 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 39881a1d2b..4d186bdf57 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2275,6 +2275,10 @@ typedef struct AVHWAccel {
*/
#define AV_HWACCEL_FLAG_UNSAFE_OUTPUT (1 << 3)

+/**
+ * Hardware acceleration can use it's software implementation.
+ */
+#define AV_HWACCEL_FLAG_ALLOW_SOFTWARE (1 << 8)
/**
* @}
*/
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 4fea57673a..1e0dd7d0fd 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -395,6 +395,7 @@ static const AVOption avcodec_options[] = {
{"allow_high_depth", "allow to output YUV pixel formats with a different chroma sampling than 4:2:0 and/or other than 8 bits per component", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"},
{"allow_profile_mismatch", "attempt to decode anyway if HW accelerated decoder's supported profiles do not exactly match the stream", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"},
{"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"},
+{"allow_software", "allow to use software implementation in HW accelerated decoder", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_SOFTWARE}, 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 },
{NULL},
--
2.39.3 (Apple Git-145)

34 changes: 34 additions & 0 deletions patches-6.0/0007-videotoolbox-allow-software-implementation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 6878517651664f752ce3cc5a90f1d4f442f3500a Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Thu, 9 Nov 2017 15:05:26 +0800
Subject: [PATCH 07/30] videotoolbox: allow software implementation

hevc is supported on macOS 10.12+ and iOS11+. sw implementaion is
provided for old devices. vt sw decoder is more energy effecient than
ffmpeg sw decoder. the sum of program and vt service cpu usage is about
50% lower than ffmpeg. decoding speed is faster sometimes(if opengl
compatiblility attribute is disabled)
---
libavcodec/videotoolbox.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index ab05404fd9..d6688ce053 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -811,9 +811,9 @@ static CFDictionaryRef videotoolbox_decoder_config_create(CMVideoCodecType codec
&kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(config_info,
- codec_type == kCMVideoCodecType_HEVC ?
- kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder :
- kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
+ (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_SOFTWARE)
+ ? kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder
+ : kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
kCFBooleanTrue);

CFMutableDictionaryRef avc_info;
--
2.39.3 (Apple Git-145)

27 changes: 27 additions & 0 deletions patches-6.0/0008-h264-increase-MAX_SLICES-to-64.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From defe4c2acc0e06196281441d29d8be3d02724144 Mon Sep 17 00:00:00 2001
From: wang-bin <[email protected]>
Date: Mon, 13 Nov 2017 12:23:10 +0800
Subject: [PATCH 08/30] h264: increase MAX_SLICES to 64

lavfilters is 256. 64 can fix corrupt decoded frames
https://github.com/wang-bin/QtAV/issues/923
---
libavcodec/h264dec.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 9a1ec1bace..cb8a320ba1 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -59,7 +59,7 @@
* The maximum number of slices supported by the decoder.
* must be a power of 2
*/
-#define MAX_SLICES 32
+#define MAX_SLICES 64

#ifdef ALLOW_INTERLACE
#define MB_MBAFF(h) (h)->mb_mbaff
--
2.39.3 (Apple Git-145)

Loading

0 comments on commit a8ab6cb

Please sign in to comment.