From 154ef204432b772f09d7e738e903d0a837a78edc Mon Sep 17 00:00:00 2001 From: Taner Sener Date: Sun, 14 Apr 2024 19:20:20 +0100 Subject: [PATCH] support android ndk 26.x, fixes #850 #909 #937 --- .github/workflows/android-build-scripts.yml | 4 +-- .github/workflows/periodic-builds-android.yml | 2 +- .../src/main/cpp/ffmpegkit.c | 2 ++ .../src/main/cpp/fftools_ffmpeg_demux.c | 2 ++ .../src/main/cpp/fftools_ffmpeg_mux_init.c | 6 ++-- apple/src/fftools_ffmpeg_demux.c | 2 ++ apple/src/fftools_ffmpeg_mux_init.c | 6 ++-- linux/src/fftools_ffmpeg_demux.c | 2 ++ linux/src/fftools_ffmpeg_mux_init.c | 6 ++-- scripts/android/ffmpeg.sh | 4 --- scripts/function-android.sh | 31 ++++++++++++++----- 11 files changed, 43 insertions(+), 24 deletions(-) diff --git a/.github/workflows/android-build-scripts.yml b/.github/workflows/android-build-scripts.yml index e2dac25..17ceb44 100644 --- a/.github/workflows/android-build-scripts.yml +++ b/.github/workflows/android-build-scripts.yml @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - ndk-version: [ 'r22b-linux-x86_64', 'r23b-linux', 'r24-linux', 'r25b-linux' ] + ndk-version: [ 'r22b-linux-x86_64', 'r23b-linux', 'r24-linux', 'r25c-linux', 'r26d-linux' ] defaults: run: shell: bash @@ -92,7 +92,7 @@ jobs: runs-on: macos-12 strategy: matrix: - ndk-version: [ 'r22b-darwin-x86_64', 'r23b-darwin', 'r24-darwin', 'r25b-darwin' ] + ndk-version: [ 'r22b-darwin-x86_64', 'r23b-darwin', 'r24-darwin', 'r25c-darwin', 'r26d-darwin' ] defaults: run: shell: bash diff --git a/.github/workflows/periodic-builds-android.yml b/.github/workflows/periodic-builds-android.yml index b45dca2..1ccf4bb 100644 --- a/.github/workflows/periodic-builds-android.yml +++ b/.github/workflows/periodic-builds-android.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - ndk-version: [ 'r22b-linux-x86_64', 'r23b-linux', 'r24-linux', 'r25b-linux' ] + ndk-version: [ 'r22b-linux-x86_64', 'r23b-linux', 'r24-linux', 'r25c-linux', 'r26d-linux' ] branches: [ 'main', 'development' ] defaults: run: diff --git a/android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.c b/android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.c index d7e7023..5adbd7c 100644 --- a/android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.c +++ b/android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.c @@ -723,8 +723,10 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { redirectionEnabled = 0; +#ifdef _USES_FFMPEG_KIT_PROTOCOLS av_set_saf_open(saf_open); av_set_saf_close(saf_close); +#endif enableNativeRedirection(); diff --git a/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_demux.c b/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_demux.c index de246da..88c360e 100644 --- a/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_demux.c +++ b/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_demux.c @@ -987,7 +987,9 @@ int ifile_open(const OptionsContext *o, const char *filename) if (scan_all_pmts_set) av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); remove_avoptions(&o->g->format_opts, o->g->codec_opts); +#ifndef _USES_FFMPEG_KIT_PROTOCOLS assert_avoptions(o->g->format_opts); +#endif /* apply forced codec ids */ for (i = 0; i < ic->nb_streams; i++) diff --git a/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_mux_init.c b/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_mux_init.c index 522f8b8..33e764a 100644 --- a/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_mux_init.c +++ b/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_mux_init.c @@ -284,9 +284,9 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre, static const struct { enum EncStatsType type; const char *str; - int pre_only:1; - int post_only:1; - int need_input_data:1; + unsigned pre_only:1; + unsigned post_only:1; + unsigned need_input_data:1; } fmt_specs[] = { { ENC_STATS_FILE_IDX, "fidx" }, { ENC_STATS_STREAM_IDX, "sidx" }, diff --git a/apple/src/fftools_ffmpeg_demux.c b/apple/src/fftools_ffmpeg_demux.c index de246da..88c360e 100644 --- a/apple/src/fftools_ffmpeg_demux.c +++ b/apple/src/fftools_ffmpeg_demux.c @@ -987,7 +987,9 @@ int ifile_open(const OptionsContext *o, const char *filename) if (scan_all_pmts_set) av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); remove_avoptions(&o->g->format_opts, o->g->codec_opts); +#ifndef _USES_FFMPEG_KIT_PROTOCOLS assert_avoptions(o->g->format_opts); +#endif /* apply forced codec ids */ for (i = 0; i < ic->nb_streams; i++) diff --git a/apple/src/fftools_ffmpeg_mux_init.c b/apple/src/fftools_ffmpeg_mux_init.c index 522f8b8..33e764a 100644 --- a/apple/src/fftools_ffmpeg_mux_init.c +++ b/apple/src/fftools_ffmpeg_mux_init.c @@ -284,9 +284,9 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre, static const struct { enum EncStatsType type; const char *str; - int pre_only:1; - int post_only:1; - int need_input_data:1; + unsigned pre_only:1; + unsigned post_only:1; + unsigned need_input_data:1; } fmt_specs[] = { { ENC_STATS_FILE_IDX, "fidx" }, { ENC_STATS_STREAM_IDX, "sidx" }, diff --git a/linux/src/fftools_ffmpeg_demux.c b/linux/src/fftools_ffmpeg_demux.c index de246da..88c360e 100644 --- a/linux/src/fftools_ffmpeg_demux.c +++ b/linux/src/fftools_ffmpeg_demux.c @@ -987,7 +987,9 @@ int ifile_open(const OptionsContext *o, const char *filename) if (scan_all_pmts_set) av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); remove_avoptions(&o->g->format_opts, o->g->codec_opts); +#ifndef _USES_FFMPEG_KIT_PROTOCOLS assert_avoptions(o->g->format_opts); +#endif /* apply forced codec ids */ for (i = 0; i < ic->nb_streams; i++) diff --git a/linux/src/fftools_ffmpeg_mux_init.c b/linux/src/fftools_ffmpeg_mux_init.c index 522f8b8..33e764a 100644 --- a/linux/src/fftools_ffmpeg_mux_init.c +++ b/linux/src/fftools_ffmpeg_mux_init.c @@ -284,9 +284,9 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre, static const struct { enum EncStatsType type; const char *str; - int pre_only:1; - int post_only:1; - int need_input_data:1; + unsigned pre_only:1; + unsigned post_only:1; + unsigned need_input_data:1; } fmt_specs[] = { { ENC_STATS_FILE_IDX, "fidx" }, { ENC_STATS_STREAM_IDX, "sidx" }, diff --git a/scripts/android/ffmpeg.sh b/scripts/android/ffmpeg.sh index ead711d..5138bca 100755 --- a/scripts/android/ffmpeg.sh +++ b/scripts/android/ffmpeg.sh @@ -390,8 +390,6 @@ ulimit -n 2048 1>>"${BASEDIR}"/build.log 2>&1 ########################### CUSTOMIZATIONS ####################### cd "${BASEDIR}" 1>>"${BASEDIR}"/build.log 2>&1 || return 1 -git checkout android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_demux.c 1>>"${BASEDIR}"/build.log 2>&1 -git checkout android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.c 1>>"${BASEDIR}"/build.log 2>&1 cd "${BASEDIR}"/src/"${LIB_NAME}" 1>>"${BASEDIR}"/build.log 2>&1 || return 1 git checkout libavformat/file.c 1>>"${BASEDIR}"/build.log 2>&1 git checkout libavformat/hls.c 1>>"${BASEDIR}"/build.log 2>&1 @@ -403,7 +401,6 @@ ${SED_INLINE} 's/static int av_log_level/__thread int av_log_level/g' "${BASEDIR # 2. Enable ffmpeg-kit protocols if [[ ${NO_FFMPEG_KIT_PROTOCOLS} == "1" ]]; then - ${SED_INLINE} "s| av_set_saf|//av_set_saf|g" "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.c 1>>"${BASEDIR}"/build.log 2>&1 echo -e "\nINFO: Disabled custom ffmpeg-kit protocols\n" 1>>"${BASEDIR}"/build.log 2>&1 else cat ../../tools/protocols/libavformat_file.c >> libavformat/file.c @@ -412,7 +409,6 @@ else awk '{gsub(/ff_file_protocol;/,"ff_file_protocol;\nextern const URLProtocol ff_saf_protocol;")}1' libavformat/protocols.c > libavformat/protocols.c.tmp cat libavformat/protocols.c.tmp > libavformat/protocols.c ${SED_INLINE} "s|av_strstart(proto_name, \"file\", NULL))|av_strstart(proto_name, \"file\", NULL) \|\| av_strstart(proto_name, \"saf\", NULL))|g" libavformat/hls.c 1>>"${BASEDIR}"/build.log 2>&1 - ${SED_INLINE} "s| assert_avoptions|//assert_avoptions|g" "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_demux.c 1>>"${BASEDIR}"/build.log 2>&1 echo -e "\nINFO: Enabled custom ffmpeg-kit protocols\n" 1>>"${BASEDIR}"/build.log 2>&1 fi diff --git a/scripts/function-android.sh b/scripts/function-android.sh index 0e4b78a..4ea29f2 100755 --- a/scripts/function-android.sh +++ b/scripts/function-android.sh @@ -77,6 +77,9 @@ build_application_mk() { fi local BUILD_DATE="-DFFMPEG_KIT_BUILD_DATE=$(date +%Y%m%d 2>>"${BASEDIR}"/build.log)" + if [[ -z ${NO_FFMPEG_KIT_PROTOCOLS} ]]; then + local USES_FFMPEG_KIT_PROTOCOLS="-D_USES_FFMPEG_KIT_PROTOCOLS" + fi rm -f "${BASEDIR}/android/jni/Application.mk" @@ -87,9 +90,11 @@ APP_ABI := ${ANDROID_ARCHITECTURES} APP_STL := ${APP_STL} +APP_ALLOW_MISSING_DEPS := true + APP_PLATFORM := android-${API} -APP_CFLAGS := -O3 -DANDROID ${LTS_BUILD_FLAG}${BUILD_DATE} -Wall -Wno-deprecated-declarations -Wno-pointer-sign -Wno-switch -Wno-unused-result -Wno-unused-variable +APP_CFLAGS := -O3 -DANDROID ${LTS_BUILD_FLAG}${BUILD_DATE} -Wall -Wno-deprecated-declarations -Wno-pointer-sign -Wno-switch -Wno-unused-result -Wno-unused-variable ${USES_FFMPEG_KIT_PROTOCOLS} APP_LDFLAGS := -Wl,--hash-style=both EOF @@ -219,7 +224,7 @@ get_android_arch() { } get_common_includes() { - echo "" + echo "-I${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/sysroot/usr/include" } get_common_cflags() { @@ -311,9 +316,6 @@ get_size_optimization_cflags() { get_app_specific_cflags() { local APP_FLAGS="" case $1 in - xvidcore) - APP_FLAGS="" - ;; ffmpeg) APP_FLAGS="-Wno-unused-function -DBIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD" ;; @@ -323,18 +325,30 @@ get_app_specific_cflags() { kvazaar) APP_FLAGS="-std=gnu99 -Wno-unused-function" ;; + libaom) + APP_FLAGS="-std=gnu99 -Wno-unused-function -Wno-implicit-function-declaration" + ;; + libuuid) + APP_FLAGS="-std=gnu99 -Wno-unused-function -DHAVE_SYS_FILE_H=1" + ;; + libvpx | openssl | shine | srt) + APP_FLAGS="-Wno-unused-function" + ;; openh264) APP_FLAGS="-std=gnu99 -Wno-unused-function -fstack-protector-all" ;; rubberband) APP_FLAGS="-std=c99 -Wno-unused-function" ;; - libvpx | openssl | shine | srt) - APP_FLAGS="-Wno-unused-function" + sdl) + APP_FLAGS="-std=c99 -Wno-unused-function -Wno-incompatible-function-pointer-types" ;; soxr | snappy | libwebp) APP_FLAGS="-std=gnu99 -Wno-unused-function -DPIC" ;; + xvidcore) + APP_FLAGS="" + ;; *) APP_FLAGS="-std=c99 -Wno-unused-function" ;; @@ -352,6 +366,7 @@ get_cflags() { else local OPTIMIZATION_FLAGS="${FFMPEG_KIT_DEBUG}" fi + local COMMON_INCLUDES=$(get_common_includes) echo "${ARCH_FLAGS} ${APP_FLAGS} ${COMMON_FLAGS} ${OPTIMIZATION_FLAGS} ${COMMON_INCLUDES}" @@ -397,7 +412,7 @@ get_cxxflags() { } get_common_linked_libraries() { - local COMMON_LIBRARY_PATHS="-L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/${HOST}/lib -L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/sysroot/usr/lib/${HOST}/${API} -L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/lib" + local COMMON_LIBRARY_PATHS="-L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/${HOST}/lib -L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/sysroot/usr/lib/${HOST}/${API}" case $1 in ffmpeg)