Skip to content

Commit

Permalink
support android ndk 26.x, fixes #850 #909 #937
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed Apr 17, 2024
1 parent c6e08c0 commit 154ef20
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android-build-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/periodic-builds-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
2 changes: 2 additions & 0 deletions apple/src/fftools_ffmpeg_demux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
6 changes: 3 additions & 3 deletions apple/src/fftools_ffmpeg_mux_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
2 changes: 2 additions & 0 deletions linux/src/fftools_ffmpeg_demux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
6 changes: 3 additions & 3 deletions linux/src/fftools_ffmpeg_mux_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
4 changes: 0 additions & 4 deletions scripts/android/ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
31 changes: 23 additions & 8 deletions scripts/function-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
;;
Expand All @@ -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"
;;
Expand All @@ -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}"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 154ef20

Please sign in to comment.