From b12405fee8521811cfd80eb35406bfbe5c87a7a7 Mon Sep 17 00:00:00 2001 From: Hitesh Kumar Saini Date: Sun, 13 Oct 2024 18:28:41 +0530 Subject: [PATCH] build --- buildscripts/README.md | 125 -------- buildscripts/build.sh | 39 +-- buildscripts/bundle_default.sh | 56 ++++ buildscripts/bundle_encoders-gpl.sh | 57 ++++ buildscripts/bundle_full.sh | 56 ++++ buildscripts/flavors/default.sh | 279 ++++++++++++++++++ buildscripts/flavors/encoders-gpl.sh | 127 ++++++++ buildscripts/flavors/full.sh | 132 +++++++++ buildscripts/include/depinfo.sh | 21 +- buildscripts/include/download-deps.sh | 39 ++- buildscripts/include/download-sdk.sh | 4 +- buildscripts/patch-encoders-gpl.sh | 21 ++ buildscripts/patches-encoders-gpl/ffmpeg | 1 + .../libx264/fix_x86_asm.patch | 13 + .../mpv/depend_on_fftools_ffi.patch | 48 +++ .../mpv/mpv_lavc_set_java_vm.patch | 1 + .../patches/ffmpeg/av1_mediacodec.patch | 81 +++++ .../patches/ffmpeg/dash_base_url_escape.patch | 26 ++ .../patches/mpv/mpv_lavc_set_java_vm.patch | 44 +++ buildscripts/scripts/dav1d.sh | 4 +- buildscripts/scripts/ffmpeg.sh | 46 --- buildscripts/scripts/fftools_ffi.sh | 22 ++ buildscripts/scripts/libass.sh | 8 +- buildscripts/scripts/libogg.build | 17 ++ buildscripts/scripts/libogg.sh | 24 ++ buildscripts/scripts/libvorbis.build | 17 ++ buildscripts/scripts/libvorbis.sh | 26 ++ buildscripts/scripts/libvpx.sh | 22 ++ buildscripts/scripts/libx264.build | 26 ++ buildscripts/scripts/libx264.sh | 26 ++ buildscripts/scripts/libxml2.sh | 31 ++ buildscripts/scripts/lua.sh | 36 --- buildscripts/scripts/mbedtls.sh | 4 +- buildscripts/scripts/mpv-android.sh | 27 -- buildscripts/scripts/mpv.sh | 11 +- buildscripts/scripts/shaderc.sh | 43 +++ 36 files changed, 1277 insertions(+), 283 deletions(-) delete mode 100644 buildscripts/README.md create mode 100755 buildscripts/bundle_default.sh create mode 100644 buildscripts/bundle_encoders-gpl.sh create mode 100644 buildscripts/bundle_full.sh create mode 100644 buildscripts/flavors/default.sh create mode 100644 buildscripts/flavors/encoders-gpl.sh create mode 100644 buildscripts/flavors/full.sh create mode 100644 buildscripts/patch-encoders-gpl.sh create mode 120000 buildscripts/patches-encoders-gpl/ffmpeg create mode 100644 buildscripts/patches-encoders-gpl/libx264/fix_x86_asm.patch create mode 100644 buildscripts/patches-encoders-gpl/mpv/depend_on_fftools_ffi.patch create mode 120000 buildscripts/patches-encoders-gpl/mpv/mpv_lavc_set_java_vm.patch create mode 100644 buildscripts/patches/ffmpeg/av1_mediacodec.patch create mode 100644 buildscripts/patches/ffmpeg/dash_base_url_escape.patch create mode 100644 buildscripts/patches/mpv/mpv_lavc_set_java_vm.patch delete mode 100755 buildscripts/scripts/ffmpeg.sh create mode 100644 buildscripts/scripts/fftools_ffi.sh create mode 100644 buildscripts/scripts/libogg.build create mode 100644 buildscripts/scripts/libogg.sh create mode 100644 buildscripts/scripts/libvorbis.build create mode 100644 buildscripts/scripts/libvorbis.sh create mode 100644 buildscripts/scripts/libvpx.sh create mode 100644 buildscripts/scripts/libx264.build create mode 100644 buildscripts/scripts/libx264.sh create mode 100644 buildscripts/scripts/libxml2.sh delete mode 100755 buildscripts/scripts/lua.sh delete mode 100755 buildscripts/scripts/mpv-android.sh create mode 100644 buildscripts/scripts/shaderc.sh diff --git a/buildscripts/README.md b/buildscripts/README.md deleted file mode 100644 index 28c8566..0000000 --- a/buildscripts/README.md +++ /dev/null @@ -1,125 +0,0 @@ -# Building - -## Download dependencies - -`download.sh` will take care of installing the Android SDK, NDK and downloading the sources. - -If you're running on Debian/Ubuntu or RHEL/Fedora it will also install the necessary dependencies for you. - -```shell -./download.sh -``` - -If you already have the Android SDK installed you can symlink `android-sdk-linux` to your SDK root -before running the script, it will still install the necessary SDK packages. - -A matching NDK version inside the SDK will be picked up automatically or downloaded/installed otherwise. - -## Patching - -```shell -./patch.sh -``` - -Run `patch.sh` to apply the custom patches to the dependencies. These patches are located in the `patches` folder. - -**Note** running `patch.sh` resets the dependencies to a clean state. - -## Build - -```shell -./build.sh -``` - -Run `build.sh` with `--clean` to clean the build directories before building. - -This builds for all architectures (`armeabi-v7a` `arm64-v8a` `x86` `x86_64`) by default. - -If you want to build only for a specific arch, build the native part like this: -```shell -./build.sh --arch arm64 mpv -./build.sh --arch x86_64 mpv -``` - -You also need to tell gradle to only build said architectures. See [Specify ABIs](https://developer.android.com/studio/projects/gradle-external-native-builds#specify-abi) for more information -```kotlin -android { - ... - defaultConfig { - ... - ndk { - abiFilters += listOf("x86_64", "arm64-v8a") - } - } -} -``` - -Finally you can build the AAR: -```shell -./build.sh -n -``` - -# Developing - -## Getting logs - -```shell -adb logcat # get all logs, useful when drivers/vendor libs output to logcat -adb logcat -s "mpv" # get only mpv logs -``` - -## Rebuilding a single component - -If you've made changes to a single component (e.g. ffmpeg or mpv) and want a new build you can of course just run ./build.sh but it's also possible to just build a single component like this: - -```shell -./build.sh -n ffmpeg -# optional: add --clean to build from a clean state -``` - -Note this will build the component for all architectures, specify `--arch` to build for a single arch. - -Afterwards, build mpv-android: - -```shell -./build.sh -n -``` - -## Using Android Studio - -You can use Android Studio to develop the Java part of the codebase. Before using it, make sure to build the project at least once by following the steps in the **Build** section. - -You should point Android Studio to existing SDK installation at `mpv-android/buildscripts/sdk/android-sdk-linux`. Then click "Open an existing Android Studio project" and select `mpv-android`. - -If Android Studio complains about project sync failing (`Error:Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#createNativeBuildModel`), go to "File -> Project Structure -> SDK Location" and set "Android NDK Location" to `mpv-android/buildscripts/sdk/android-ndk-rVERSION`. - -Note that if you build from Android Studio only the Java part will be built. If you make any changes to libraries (ffmpeg, mpv, ...) or mpv-android native code (`app/src/main/jni/*`), first rebuild native code with: - -```shell -./build.sh -n -``` - -then build the project from Android Studio. - -Also, debugging native code does not work from within the studio at the moment, you will have to use gdb for that. - -## Debugging native code with gdb - -You first need to rebuild mpv-android with gdbserver support: - -```shell -NDK_DEBUG=1 ./build.sh -n -adb install -r ../app/build/outputs/apk/debug/app-debug.apk -``` - -After that, ndk-gdb can be used to debug the app: - -```shell -cd mpv-android/app/src/main/ -../../../buildscripts/sdk/android-ndk-r*/ndk-gdb --launch -``` - -# Credits, notes, etc - -These build scripts were created by @sfan5 and modified by @jarnedemeulemeester. - diff --git a/buildscripts/build.sh b/buildscripts/build.sh index 2659eeb..32b9828 100755 --- a/buildscripts/build.sh +++ b/buildscripts/build.sh @@ -5,7 +5,7 @@ cd "$( dirname "${BASH_SOURCE[0]}" )" cleanbuild=0 nodeps=0 -target=mpv-android +target=mpv archs=(armv7l arm64 x86 x86_64) getdeps () { @@ -15,9 +15,8 @@ getdeps () { loadarch () { unset CC CXX CPATH LIBRARY_PATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH - unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS - local apilvl=26 + local apilvl=21 # ndk_triple: what the toolchain actually is # cc_triple: what Google pretends the toolchain is if [ "$1" == "armv7l" ]; then @@ -47,6 +46,11 @@ loadarch () { export prefix_dir="$PWD/prefix/$prefix_name" export native_dir="$PWD/../libmpv/src/main/jniLibs/$prefix_name" export CC=$cc_triple-clang + if [[ "$1" == arm* ]]; then + export AS="$CC" + else + export AS="nasm" + fi export CXX=$cc_triple-clang++ export LDFLAGS="-Wl,-O1,--icf=safe -Wl,-z,max-page-size=16384" export AR=llvm-ar @@ -91,7 +95,7 @@ CROSSFILE } build () { - if [ $1 != "mpv-android" ] && [ ! -d deps/$1 ]; then + if [ ! -d deps/$1 ]; then printf >&2 '\e[1;31m%s\e[m\n' "Target $1 not found" return 1 fi @@ -103,23 +107,14 @@ build () { build $dep done fi - if [ "$1" != "mpv-android" ]; then - printf >&2 '\e[1;34m%s\e[m\n' "Building $1..." - pushd deps/$1 - BUILDSCRIPT=../../scripts/$1.sh - [ $cleanbuild -eq 1 ] && $BUILDSCRIPT clean + + printf >&2 '\e[1;34m%s\e[m\n' "Building $1..." + pushd deps/$1 + BUILDSCRIPT=../../scripts/$1.sh + sudo chmod +x $BUILDSCRIPT + [ $cleanbuild -eq 1 ] && $BUILDSCRIPT clean $BUILDSCRIPT build popd - fi -} - -assemble () { - printf >&2 '\e[1;34m%s\e[m\n' "Assembling $1..." - pushd .. - BUILDSCRIPT=buildscripts/scripts/mpv-android.sh - [ $cleanbuild -eq 1 ] && $BUILDSCRIPT clean - $BUILDSCRIPT build - popd } usage () { @@ -166,10 +161,4 @@ else build $target fi -if [ "$target" == "mpv-android" ]; then - assemble - [ -d ../libmpv/build/outputs/aar ] && ls -lh ../libmpv/build/outputs/aar/*.aar - [ -d ../libmpv/build/libs ] && ls -lh ../libmpv/build/libs/*.jar -fi - exit 0 diff --git a/buildscripts/bundle_default.sh b/buildscripts/bundle_default.sh new file mode 100755 index 0000000..67c7bd5 --- /dev/null +++ b/buildscripts/bundle_default.sh @@ -0,0 +1,56 @@ +# -------------------------------------------------- + +if [ ! -f "deps" ]; then + sudo rm -r deps +fi +if [ ! -f "prefix" ]; then + sudo rm -r prefix +fi + +./download.sh +./patch.sh + +# -------------------------------------------------- + +if [ ! -f "scripts/ffmpeg" ]; then + rm scripts/ffmpeg.sh +fi +cp flavors/default.sh scripts/ffmpeg.sh + +# -------------------------------------------------- + +./build.sh + +# -------------------------------------------------- + +cd deps/media-kit-android-helper + +sudo chmod +x gradlew +./gradlew assembleRelease + +unzip -o app/build/outputs/apk/release/app-release.apk -d app/build/outputs/apk/release + +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/arm64-v8a/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/arm64-v8a" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/armeabi-v7a/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/armeabi-v7a" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/x86/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/x86" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/x86_64/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/x86_64" + +cd ../.. + +zip -r "default-arm64-v8a.jar" lib/arm64-v8a +zip -r "default-armeabi-v7a.jar" lib/armeabi-v7a +zip -r "default-x86.jar" lib/x86 +zip -r "default-x86_64.jar" lib/x86_64 + +mkdir -p ../../../../../../../../../../output + +cp *.jar ../../../../../../../../../../output + +md5sum *.jar + +cd ../../../../../../../../.. + +# -------------------------------------------------- + +zip -r debug-symbols-default.zip prefix/*/lib +cp debug-symbols-default.zip ../output diff --git a/buildscripts/bundle_encoders-gpl.sh b/buildscripts/bundle_encoders-gpl.sh new file mode 100644 index 0000000..4769213 --- /dev/null +++ b/buildscripts/bundle_encoders-gpl.sh @@ -0,0 +1,57 @@ +# -------------------------------------------------- +set -euxo pipefail + +export ENCODERS_GPL=1 + +if [ -d deps ]; then + sudo rm -r deps +fi +if [ -d prefix ]; then + sudo rm -r prefix +fi + +./download.sh +./patch-encoders-gpl.sh + +# -------------------------------------------------- + +rm scripts/ffmpeg.sh +cp flavors/encoders-gpl.sh scripts/ffmpeg.sh + +# -------------------------------------------------- + +./build.sh + +# -------------------------------------------------- + +cd deps/media-kit-android-helper + +sudo chmod +x gradlew +./gradlew assembleRelease + +unzip -o app/build/outputs/apk/release/app-release.apk -d app/build/outputs/apk/release + +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/arm64-v8a/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/arm64-v8a" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/armeabi-v7a/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/armeabi-v7a" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/x86/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/x86" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/x86_64/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/x86_64" + +cd ../.. + +zip -r "encoders-gpl-arm64-v8a.jar" lib/arm64-v8a +zip -r "encoders-gpl-armeabi-v7a.jar" lib/armeabi-v7a +zip -r "encoders-gpl-x86.jar" lib/x86 +zip -r "encoders-gpl-x86_64.jar" lib/x86_64 + +mkdir -p ../../../../../../../../../../output + +cp *.jar ../../../../../../../../../../output + +md5sum *.jar + +cd ../../../../../../../../.. + +# -------------------------------------------------- + +zip -r debug-symbols-encoders-gpl.zip prefix/*/lib +cp debug-symbols-encoders-gpl.zip ../output diff --git a/buildscripts/bundle_full.sh b/buildscripts/bundle_full.sh new file mode 100644 index 0000000..8c1222d --- /dev/null +++ b/buildscripts/bundle_full.sh @@ -0,0 +1,56 @@ +# -------------------------------------------------- + +if [ ! -f "deps" ]; then + sudo rm -r deps +fi +if [ ! -f "prefix" ]; then + sudo rm -r prefix +fi + +./download.sh +./patch.sh + +# -------------------------------------------------- + +if [ ! -f "scripts/ffmpeg" ]; then + rm scripts/ffmpeg.sh +fi +cp flavors/full.sh scripts/ffmpeg.sh + +# -------------------------------------------------- + +./build.sh + +# -------------------------------------------------- + +cd deps/media-kit-android-helper + +sudo chmod +x gradlew +./gradlew assembleRelease + +unzip -o app/build/outputs/apk/release/app-release.apk -d app/build/outputs/apk/release + +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/arm64-v8a/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/arm64-v8a" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/armeabi-v7a/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/armeabi-v7a" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/x86/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/x86" +ln -sf "$(pwd)/app/build/outputs/apk/release/lib/x86_64/libmediakitandroidhelper.so" "../../../libmpv/src/main/jniLibs/x86_64" + +cd ../.. + +zip -r "full-arm64-v8a.jar" lib/arm64-v8a +zip -r "full-armeabi-v7a.jar" lib/armeabi-v7a +zip -r "full-x86.jar" lib/x86 +zip -r "full-x86_64.jar" lib/x86_64 + +mkdir -p ../../../../../../../../../../output + +cp *.jar ../../../../../../../../../../output + +md5sum *.jar + +cd ../../../../../../../../.. + +# -------------------------------------------------- + +zip -r debug-symbols-full.zip prefix/*/lib +cp debug-symbols-full.zip ../output diff --git a/buildscripts/flavors/default.sh b/buildscripts/flavors/default.sh new file mode 100644 index 0000000..7e09c87 --- /dev/null +++ b/buildscripts/flavors/default.sh @@ -0,0 +1,279 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf _build$ndk_suffix + exit 0 +else + exit 255 +fi + +mkdir -p _build$ndk_suffix +cd _build$ndk_suffix + +cpu=armv7-a +[[ "$ndk_triple" == "aarch64"* ]] && cpu=armv8-a +[[ "$ndk_triple" == "x86_64"* ]] && cpu=generic +[[ "$ndk_triple" == "i686"* ]] && cpu="i686 --disable-asm" + +cpuflags= +[[ "$ndk_triple" == "arm"* ]] && cpuflags="$cpuflags -mfpu=neon -mcpu=cortex-a8" + +../configure \ + --target-os=android --enable-cross-compile --cross-prefix=$ndk_triple- --ar=$AR --cc=$CC --ranlib=$RANLIB \ + --arch=${ndk_triple%%-*} --cpu=$cpu --pkg-config=pkg-config --nm=llvm-nm \ + --extra-cflags="-I$prefix_dir/include $cpuflags" --extra-ldflags="-L$prefix_dir/lib" \ + \ + --disable-gpl \ + --disable-nonfree \ + --enable-version3 \ + --enable-static \ + --disable-shared \ + --disable-vulkan \ + --disable-iconv \ + --disable-stripping \ + --pkg-config-flags=--static \ + \ + --disable-muxers \ + --disable-decoders \ + --disable-encoders \ + --disable-demuxers \ + --disable-parsers \ + --disable-protocols \ + --disable-devices \ + --disable-filters \ + --disable-doc \ + --disable-avdevice \ + --disable-postproc \ + --disable-programs \ + --disable-gray \ + --disable-swscale-alpha \ + \ + --enable-jni \ + --enable-bsfs \ + --enable-mediacodec \ + \ + --disable-dxva2 \ + --disable-vaapi \ + --disable-vdpau \ + --disable-bzlib \ + --disable-linux-perf \ + --disable-videotoolbox \ + --disable-audiotoolbox \ + \ + --enable-small \ + --enable-hwaccels \ + --enable-optimizations \ + --enable-runtime-cpudetect \ + \ + --enable-mbedtls \ + \ + --enable-libdav1d \ + \ + --enable-libxml2 \ + \ + --enable-avutil \ + --enable-avcodec \ + --enable-avfilter \ + --enable-avformat \ + --enable-swscale \ + --enable-swresample \ + \ + --enable-decoder=flv \ + --enable-decoder=h263 \ + --enable-decoder=h263i \ + --enable-decoder=h263p \ + --enable-decoder=h264* \ + --enable-decoder=mpeg1video \ + --enable-decoder=mpeg2* \ + --enable-decoder=mpeg4* \ + --enable-decoder=vp6 \ + --enable-decoder=vp6a \ + --enable-decoder=vp6f \ + --enable-decoder=vp8* \ + --enable-decoder=vp9* \ + --enable-decoder=hevc* \ + --enable-decoder=av1* \ + --enable-decoder=libdav1d \ + --enable-decoder=theora \ + --enable-decoder=msmpeg* \ + --enable-decoder=mjpeg* \ + --enable-decoder=wmv* \ + \ + --enable-decoder=aac* \ + --enable-decoder=ac3 \ + --enable-decoder=alac \ + --enable-decoder=als \ + --enable-decoder=ape \ + --enable-decoder=atrac* \ + --enable-decoder=eac3 \ + --enable-decoder=flac \ + --enable-decoder=gsm* \ + --enable-decoder=mp1* \ + --enable-decoder=mp2* \ + --enable-decoder=mp3* \ + --enable-decoder=mpc* \ + --enable-decoder=opus \ + --enable-decoder=ra* \ + --enable-decoder=ralf \ + --enable-decoder=shorten \ + --enable-decoder=tak \ + --enable-decoder=tta \ + --enable-decoder=vorbis \ + --enable-decoder=wavpack \ + --enable-decoder=wma* \ + --enable-decoder=pcm* \ + --enable-decoder=dsd* \ + --enable-decoder=dca \ + \ + --enable-decoder=ssa \ + --enable-decoder=ass \ + --enable-decoder=dvbsub \ + --enable-decoder=dvdsub \ + --enable-decoder=srt \ + --enable-decoder=stl \ + --enable-decoder=subrip \ + --enable-decoder=subviewer \ + --enable-decoder=subviewer1 \ + --enable-decoder=text \ + --enable-decoder=vplayer \ + --enable-decoder=webvtt \ + --enable-decoder=movtext \ + \ + --enable-decoder=mjpeg \ + --enable-decoder=ljpeg \ + --enable-decoder=jpegls \ + --enable-decoder=jpeg2000 \ + --enable-decoder=png \ + --enable-decoder=gif \ + --enable-decoder=bmp \ + --enable-decoder=tiff \ + --enable-decoder=webp \ + --enable-decoder=jpegls \ + \ + --enable-demuxer=concat \ + --enable-demuxer=data \ + --enable-demuxer=flv \ + --enable-demuxer=hls \ + --enable-demuxer=latm \ + --enable-demuxer=live_flv \ + --enable-demuxer=loas \ + --enable-demuxer=m4v \ + --enable-demuxer=mov \ + --enable-demuxer=mpegps \ + --enable-demuxer=mpegts \ + --enable-demuxer=mpegvideo \ + --enable-demuxer=hevc \ + --enable-demuxer=rtsp \ + --enable-demuxer=mpeg4 \ + --enable-demuxer=mjpeg* \ + --enable-demuxer=avi \ + --enable-demuxer=av1 \ + --enable-demuxer=matroska \ + --enable-demuxer=dash \ + --enable-demuxer=webm_dash_manifest \ + \ + --enable-demuxer=aac \ + --enable-demuxer=ac3 \ + --enable-demuxer=aiff \ + --enable-demuxer=ape \ + --enable-demuxer=asf \ + --enable-demuxer=au \ + --enable-demuxer=avi \ + --enable-demuxer=flac \ + --enable-demuxer=flv \ + --enable-demuxer=matroska \ + --enable-demuxer=mov \ + --enable-demuxer=m4v \ + --enable-demuxer=mp3 \ + --enable-demuxer=mpc* \ + --enable-demuxer=ogg \ + --enable-demuxer=pcm* \ + --enable-demuxer=rm \ + --enable-demuxer=shorten \ + --enable-demuxer=tak \ + --enable-demuxer=tta \ + --enable-demuxer=wav \ + --enable-demuxer=wv \ + --enable-demuxer=xwma \ + --enable-demuxer=dsf \ + --enable-demuxer=truehd \ + --enable-demuxer=dts \ + --enable-demuxer=dtshd \ + \ + --enable-demuxer=ass \ + --enable-demuxer=srt \ + --enable-demuxer=stl \ + --enable-demuxer=webvtt \ + --enable-demuxer=subviewer \ + --enable-demuxer=subviewer1 \ + --enable-demuxer=vplayer \ + \ + --enable-parser=h263 \ + --enable-parser=h264 \ + --enable-parser=hevc \ + --enable-parser=mpeg4 \ + --enable-parser=mpeg4video \ + --enable-parser=mpegvideo \ + \ + --enable-parser=aac* \ + --enable-parser=ac3 \ + --enable-parser=cook \ + --enable-parser=dca \ + --enable-parser=flac \ + --enable-parser=gsm \ + --enable-parser=mpegaudio \ + --enable-parser=tak \ + --enable-parser=vorbis \ + --enable-parser=dca \ + \ + --enable-filter=overlay \ + --enable-filter=equalizer \ + \ + --enable-protocol=async \ + --enable-protocol=cache \ + --enable-protocol=crypto \ + --enable-protocol=data \ + --enable-protocol=ffrtmphttp \ + --enable-protocol=file \ + --enable-protocol=ftp \ + --enable-protocol=hls \ + --enable-protocol=http \ + --enable-protocol=httpproxy \ + --enable-protocol=https \ + --enable-protocol=pipe \ + --enable-protocol=rtmp \ + --enable-protocol=rtmps \ + --enable-protocol=rtmpt \ + --enable-protocol=rtmpts \ + --enable-protocol=rtp \ + --enable-protocol=subfile \ + --enable-protocol=tcp \ + --enable-protocol=tls \ + --enable-protocol=srt \ + --enable-protocol=udp \ + \ + --enable-encoder=mjpeg \ + --enable-encoder=ljpeg \ + --enable-encoder=jpegls \ + --enable-encoder=jpeg2000 \ + --enable-encoder=png \ + --enable-encoder=jpegls \ + \ + --enable-network \ + +make -j$cores +make DESTDIR="$prefix_dir" install + +ln -sf "$prefix_dir"/lib/libswresample.so "$native_dir" +ln -sf "$prefix_dir"/lib/libpostproc.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavutil.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavcodec.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavformat.so "$native_dir" +ln -sf "$prefix_dir"/lib/libswscale.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavfilter.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavdevice.so "$native_dir" diff --git a/buildscripts/flavors/encoders-gpl.sh b/buildscripts/flavors/encoders-gpl.sh new file mode 100644 index 0000000..6e626b7 --- /dev/null +++ b/buildscripts/flavors/encoders-gpl.sh @@ -0,0 +1,127 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf _build$ndk_suffix + exit 0 +else + exit 255 +fi + +mkdir -p _build$ndk_suffix +cd _build$ndk_suffix + +cpu=armv7-a +[[ "$ndk_triple" == "aarch64"* ]] && cpu=armv8-a +[[ "$ndk_triple" == "x86_64"* ]] && cpu=generic +[[ "$ndk_triple" == "i686"* ]] && cpu="i686 --disable-asm" + +cpuflags= +[[ "$ndk_triple" == "arm"* ]] && cpuflags="$cpuflags -mfpu=neon -mcpu=cortex-a8" + +../configure \ + --target-os=android --enable-cross-compile --cross-prefix=$ndk_triple- --ar=$AR --cc=$CC --ranlib=$RANLIB \ + --arch=${ndk_triple%%-*} --cpu=$cpu --pkg-config=pkg-config --nm=llvm-nm \ + --extra-cflags="-I$prefix_dir/include $cpuflags" --extra-ldflags="-L$prefix_dir/lib" \ + --pkg-config-flags="--static" \ + \ + --disable-nonfree \ + --enable-version3 \ + --enable-static \ + --disable-shared \ + --disable-vulkan \ + --disable-iconv \ + --disable-stripping \ + --pkg-config-flags=--static \ + \ + --enable-decoders \ + --enable-encoders \ + --enable-libvorbis \ + --enable-libvpx \ + --enable-gpl \ + --enable-libx264 \ + --enable-muxers \ + --enable-demuxers \ + --enable-parsers \ + \ + --disable-protocols \ + --disable-devices \ + --disable-doc \ + --disable-avdevice \ + --disable-postproc \ + --disable-programs \ + --disable-gray \ + --disable-swscale-alpha \ + \ + --enable-jni \ + --enable-bsfs \ + --enable-mediacodec \ + \ + --disable-dxva2 \ + --disable-vaapi \ + --disable-vdpau \ + --disable-bzlib \ + --disable-linux-perf \ + --disable-videotoolbox \ + --disable-audiotoolbox \ + \ + --enable-small \ + --enable-hwaccels \ + --enable-optimizations \ + --enable-runtime-cpudetect \ + \ + --enable-mbedtls \ + \ + --enable-libdav1d \ + \ + --enable-libxml2 \ + \ + --enable-avutil \ + --enable-avcodec \ + --enable-avfilter \ + --enable-avformat \ + --enable-swscale \ + --enable-swresample \ + \ + --enable-filters \ + \ + --enable-protocol=async \ + --enable-protocol=cache \ + --enable-protocol=crypto \ + --enable-protocol=data \ + --enable-protocol=ffrtmphttp \ + --enable-protocol=file \ + --enable-protocol=ftp \ + --enable-protocol=hls \ + --enable-protocol=http \ + --enable-protocol=httpproxy \ + --enable-protocol=https \ + --enable-protocol=pipe \ + --enable-protocol=rtmp \ + --enable-protocol=rtmps \ + --enable-protocol=rtmpt \ + --enable-protocol=rtmpts \ + --enable-protocol=rtp \ + --enable-protocol=subfile \ + --enable-protocol=tcp \ + --enable-protocol=tls \ + --enable-protocol=srt \ + --enable-protocol=udp \ + \ + --enable-network \ + +make -j$cores +make DESTDIR="$prefix_dir" install + +ln -sf "$prefix_dir"/lib/libswresample.so "$native_dir" +ln -sf "$prefix_dir"/lib/libpostproc.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavutil.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavcodec.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavformat.so "$native_dir" +ln -sf "$prefix_dir"/lib/libswscale.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavfilter.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavdevice.so "$native_dir" diff --git a/buildscripts/flavors/full.sh b/buildscripts/flavors/full.sh new file mode 100644 index 0000000..4cfb1a5 --- /dev/null +++ b/buildscripts/flavors/full.sh @@ -0,0 +1,132 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf _build$ndk_suffix + exit 0 +else + exit 255 +fi + +mkdir -p _build$ndk_suffix +cd _build$ndk_suffix + +cpu=armv7-a +[[ "$ndk_triple" == "aarch64"* ]] && cpu=armv8-a +[[ "$ndk_triple" == "x86_64"* ]] && cpu=generic +[[ "$ndk_triple" == "i686"* ]] && cpu="i686 --disable-asm" + +cpuflags= +[[ "$ndk_triple" == "arm"* ]] && cpuflags="$cpuflags -mfpu=neon -mcpu=cortex-a8" + +../configure \ + --target-os=android --enable-cross-compile --cross-prefix=$ndk_triple- --ar=$AR --cc=$CC --ranlib=$RANLIB \ + --arch=${ndk_triple%%-*} --cpu=$cpu --pkg-config=pkg-config --nm=llvm-nm \ + --extra-cflags="-I$prefix_dir/include $cpuflags" --extra-ldflags="-L$prefix_dir/lib" \ + \ + --disable-gpl \ + --disable-nonfree \ + --enable-version3 \ + --enable-static \ + --disable-shared \ + --disable-vulkan \ + --disable-iconv \ + --disable-stripping \ + --pkg-config-flags=--static \ + \ + --enable-decoders \ + --enable-demuxers \ + --enable-parsers \ + \ + --disable-muxers \ + --disable-encoders \ + --disable-protocols \ + --disable-devices \ + --disable-filters \ + --disable-doc \ + --disable-avdevice \ + --disable-postproc \ + --disable-programs \ + --disable-gray \ + --disable-swscale-alpha \ + \ + --enable-jni \ + --enable-bsfs \ + --enable-mediacodec \ + \ + --disable-dxva2 \ + --disable-vaapi \ + --disable-vdpau \ + --disable-bzlib \ + --disable-linux-perf \ + --disable-videotoolbox \ + --disable-audiotoolbox \ + \ + --enable-small \ + --enable-hwaccels \ + --enable-optimizations \ + --enable-runtime-cpudetect \ + \ + --enable-mbedtls \ + \ + --enable-libdav1d \ + \ + --enable-libxml2 \ + \ + --enable-avutil \ + --enable-avcodec \ + --enable-avfilter \ + --enable-avformat \ + --enable-swscale \ + --enable-swresample \ + \ + --enable-filter=overlay \ + --enable-filter=equalizer \ + \ + --enable-protocol=async \ + --enable-protocol=cache \ + --enable-protocol=crypto \ + --enable-protocol=data \ + --enable-protocol=ffrtmphttp \ + --enable-protocol=file \ + --enable-protocol=ftp \ + --enable-protocol=hls \ + --enable-protocol=http \ + --enable-protocol=httpproxy \ + --enable-protocol=https \ + --enable-protocol=pipe \ + --enable-protocol=rtmp \ + --enable-protocol=rtmps \ + --enable-protocol=rtmpt \ + --enable-protocol=rtmpts \ + --enable-protocol=rtp \ + --enable-protocol=subfile \ + --enable-protocol=tcp \ + --enable-protocol=tls \ + --enable-protocol=srt \ + --enable-protocol=udp \ + \ + --enable-encoder=mjpeg \ + --enable-encoder=ljpeg \ + --enable-encoder=jpegls \ + --enable-encoder=jpeg2000 \ + --enable-encoder=png \ + --enable-encoder=jpegls \ + \ + --enable-network \ + +make -j$cores +make DESTDIR="$prefix_dir" install + +ln -sf "$prefix_dir"/lib/libswresample.so "$native_dir" +ln -sf "$prefix_dir"/lib/libpostproc.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavutil.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavcodec.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavformat.so "$native_dir" +ln -sf "$prefix_dir"/lib/libswscale.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavfilter.so "$native_dir" +ln -sf "$prefix_dir"/lib/libavdevice.so "$native_dir" diff --git a/buildscripts/include/depinfo.sh b/buildscripts/include/depinfo.sh index 68804c8..46b3351 100755 --- a/buildscripts/include/depinfo.sh +++ b/buildscripts/include/depinfo.sh @@ -6,7 +6,6 @@ v_sdk=11076708_latest v_ndk=27.1.12297006 v_sdk_build_tools=35.0.0 -v_lua=5.2.4 v_libass=0.17.3 v_harfbuzz=10.0.1 v_fribidi=1.0.16 @@ -14,8 +13,12 @@ v_freetype=2-13-3 v_mbedtls=3.6.1 v_libplacebo=7.349.0 v_dav1d=1.4.3 +v_libxml2=2.10.3 v_ffmpeg=7.1 v_mpv=0.39.0 +v_libogg=1.3.5 +v_libvorbis=1.3.7 +v_libvpx=1.13 ## Dependency tree @@ -23,13 +26,21 @@ v_mpv=0.39.0 dep_mbedtls=() dep_dav1d=() -dep_ffmpeg=(mbedtls dav1d) +dep_libvorbis=(libogg) +if [ -n "$ENCODERS_GPL" ]; then + dep_ffmpeg=(mbedtls dav1d libxml2 libvorbis libvpx libx264) +else + dep_ffmpeg=(mbedtls dav1d libxml2) +fi dep_freetype2=() dep_fribidi=() dep_harfbuzz=() dep_libass=(freetype fribidi harfbuzz) dep_lua=() +dep_shaderc=() dep_libplacebo=() -dep_mpv=(ffmpeg libass lua libplacebo) -dep_mpv_android=(mpv) - +if [ -n "$ENCODERS_GPL" ]; then + dep_mpv=(ffmpeg libass libplacebo fftools_ffi) +else + dep_mpv=(ffmpeg libass libplacebo) +fi diff --git a/buildscripts/include/download-deps.sh b/buildscripts/include/download-deps.sh index 365f53e..49fae40 100755 --- a/buildscripts/include/download-deps.sh +++ b/buildscripts/include/download-deps.sh @@ -12,6 +12,21 @@ mkdir -p deps && cd deps # dav1d [ ! -d dav1d ] && git clone --depth 1 --branch $v_dav1d https://code.videolan.org/videolan/dav1d.git dav1d +# libxml2 +[ ! -d libxml2 ] && git clone --depth 1 --branch v$v_libxml2 --recursive https://gitlab.gnome.org/GNOME/libxml2.git libxml2 + +# libogg +[ ! -d libogg ] && $WGET https://github.com/xiph/ogg/releases/download/v${v_libogg}/libogg-${v_libogg}.tar.gz && tar -xf libogg-${v_libogg}.tar.gz && mv libogg-${v_libogg} libogg && rm libogg-${v_libogg}.tar.gz + +# libvorbis +[ ! -d libvorbis ] && $WGET https://github.com/xiph/vorbis/releases/download/v${v_libvorbis}/libvorbis-${v_libvorbis}.tar.gz && tar -xf libvorbis-${v_libvorbis}.tar.gz && mv libvorbis-${v_libvorbis} libvorbis && rm libvorbis-${v_libvorbis}.tar.gz + +# libvpx +[ ! -d libvpx ] && git clone --depth 1 --branch meson-$v_libvpx https://gitlab.freedesktop.org/gstreamer/meson-ports/libvpx.git + +# libx264 +[ ! -d libx264 ] && git clone --depth 1 https://code.videolan.org/videolan/x264.git --branch master libx264 + # ffmpeg [ ! -d ffmpeg ] && git clone --depth 1 --branch n$v_ffmpeg https://github.com/FFmpeg/FFmpeg.git ffmpeg @@ -27,16 +42,26 @@ mkdir -p deps && cd deps # libass [ ! -d libass ] && git clone --depth 1 --branch $v_libass https://github.com/libass/libass.git libass -# lua -if [ ! -d lua ]; then - mkdir lua - $WGET http://www.lua.org/ftp/lua-$v_lua.tar.gz -O - | \ - tar -xz -C lua --strip-components=1 -fi +# shaderc +mkdir -p shaderc +cat >shaderc/README <<'HEREDOC' +Shaderc sources are provided by the NDK. +see /sources/third_party/shaderc +HEREDOC +# libplacebo [ ! -d libplacebo ] && git clone --depth 1 --branch v$v_libplacebo --recurse-submodules https://code.videolan.org/videolan/libplacebo.git libplacebo # mpv -[ ! -d mpv ] && git clone --depth 1 --branch v$v_mpv https://github.com/mpv-player/mpv.git mpv +[ ! -d mpv ] && git clone --depth 1 --branch v$v_mpv https://github.com/mpv-player/mpv.git mpv + +# fftools_ffi +[ ! -d fftools_ffi ] && git clone --depth 1 --branch main https://github.com/moffatman/fftools-ffi.git fftools_ffi + +# media-kit-android-helper +[ ! -d media-kit-android-helper ] && git clone --depth 1 --branch main https://github.com/media-kit/media-kit-android-helper.git + +# media_kit +[ ! -d media_kit ] && git clone --depth 1 --single-branch --branch main https://github.com/alexmercerind/media_kit.git cd .. diff --git a/buildscripts/include/download-sdk.sh b/buildscripts/include/download-sdk.sh index ef317dc..5bc1670 100755 --- a/buildscripts/include/download-sdk.sh +++ b/buildscripts/include/download-sdk.sh @@ -10,12 +10,12 @@ if [ "$os" == "linux" ]; then if [ $TRAVIS -eq 0 ]; then hash yum &>/dev/null && { - sudo yum install autoconf pkgconfig libtool ninja-build \ + sudo yum install autoconf pkgconfig libtool ninja-build unzip \ python3-pip python3-setuptools unzip wget; python3 -m pip install meson jsonschema jinja2; } apt-get -v &>/dev/null && { sudo apt-get update; - sudo apt-get install -y autoconf pkg-config libtool ninja-build nasm \ + sudo apt-get install -y autoconf pkg-config libtool ninja-build nasm unzip \ python3-pip python3-setuptools unzip; python3 -m pip install meson jsonschema jinja2; } fi diff --git a/buildscripts/patch-encoders-gpl.sh b/buildscripts/patch-encoders-gpl.sh new file mode 100644 index 0000000..2352eba --- /dev/null +++ b/buildscripts/patch-encoders-gpl.sh @@ -0,0 +1,21 @@ +#!/bin/bash -e + +PATCHES=(patches-encoders-gpl/*) +ROOT=$(pwd) + +for dep_path in "${PATCHES[@]}"; do + if [ -d "$dep_path" ]; then + patches=($dep_path/*) + dep=$(echo $dep_path |cut -d/ -f 2) + cd deps/$dep + echo Patching $dep + git reset --hard + for patch in "${patches[@]}"; do + echo Applying $patch + git apply "$ROOT/$patch" + done + cd $ROOT + fi +done + +exit 0 diff --git a/buildscripts/patches-encoders-gpl/ffmpeg b/buildscripts/patches-encoders-gpl/ffmpeg new file mode 120000 index 0000000..e2bf6e7 --- /dev/null +++ b/buildscripts/patches-encoders-gpl/ffmpeg @@ -0,0 +1 @@ +../patches/ffmpeg \ No newline at end of file diff --git a/buildscripts/patches-encoders-gpl/libx264/fix_x86_asm.patch b/buildscripts/patches-encoders-gpl/libx264/fix_x86_asm.patch new file mode 100644 index 0000000..b5630b2 --- /dev/null +++ b/buildscripts/patches-encoders-gpl/libx264/fix_x86_asm.patch @@ -0,0 +1,13 @@ +diff --git a/configure b/configure +index e242e73c..219381ab 100755 +--- a/configure ++++ b/configure +@@ -738,7 +739,7 @@ LDFLAGS="$LDFLAGS $libm" + + stack_alignment=4 + case $host_cpu in +- i*86) ++ *86) + ARCH="X86" + AS="${AS-nasm}" + AS_EXT=".asm" diff --git a/buildscripts/patches-encoders-gpl/mpv/depend_on_fftools_ffi.patch b/buildscripts/patches-encoders-gpl/mpv/depend_on_fftools_ffi.patch new file mode 100644 index 0000000..cb69350 --- /dev/null +++ b/buildscripts/patches-encoders-gpl/mpv/depend_on_fftools_ffi.patch @@ -0,0 +1,48 @@ +diff --git a/meson.build b/meson.build +index a56bb1f37c..7cd3b195f9 100644 +--- a/meson.build ++++ b/meson.build +@@ -23,6 +23,9 @@ libavutil = dependency('libavutil', version: '>= 56.70.100') + libswresample = dependency('libswresample', version: '>= 3.9.100') + libswscale = dependency('libswscale', version: '>= 5.9.100') + ++# fftools-ffi ++libfftools_ffi = dependency('fftools-ffi') ++ + libass = dependency('libass', version: '>= 0.12.2') + + # the dependency order of libass -> ffmpeg is necessary due to +@@ -33,7 +36,8 @@ dependencies = [libass, + libavformat, + libavutil, + libswresample, +- libswscale] ++ libswscale, ++ libfftools_ffi] + + # Keeps track of all enabled/disabled features + features = { +@@ -244,7 +248,10 @@ sources = files( + ## tree_allocator + 'ta/ta.c', + 'ta/ta_talloc.c', +- 'ta/ta_utils.c' ++ 'ta/ta_utils.c', ++ ++ ## fftools-ffi hack ++ 'fftools-ffi.c' + ) + + +diff --git a/fftools-ffi.c b/fftools-ffi.c +new file mode 100644 +index 0000000..6cd4258 +--- /dev/null ++++ b/fftools-ffi.c +@@ -0,0 +1,6 @@ ++#include "fftools-ffi/dart_api.h" ++ ++void* a = FFToolsFFIInitialize; ++void* b = FFToolsFFIExecuteFFmpeg; ++void* c = FFToolsFFIExecuteFFprobe; ++void* d = FFToolsCancel; diff --git a/buildscripts/patches-encoders-gpl/mpv/mpv_lavc_set_java_vm.patch b/buildscripts/patches-encoders-gpl/mpv/mpv_lavc_set_java_vm.patch new file mode 120000 index 0000000..1b46060 --- /dev/null +++ b/buildscripts/patches-encoders-gpl/mpv/mpv_lavc_set_java_vm.patch @@ -0,0 +1 @@ +../../patches/mpv/mpv_lavc_set_java_vm.patch \ No newline at end of file diff --git a/buildscripts/patches/ffmpeg/av1_mediacodec.patch b/buildscripts/patches/ffmpeg/av1_mediacodec.patch new file mode 100644 index 0000000..e87d137 --- /dev/null +++ b/buildscripts/patches/ffmpeg/av1_mediacodec.patch @@ -0,0 +1,81 @@ +diff --git a/configure b/configure +index ba5793b..b73af74 100755 +--- a/configure ++++ b/configure +@@ -3163,6 +3163,7 @@ nvenc_deps_any="libdl LoadLibrary" + aac_mf_encoder_deps="mediafoundation" + ac3_mf_encoder_deps="mediafoundation" + av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS" ++av1_mediacodec_decoder_deps="mediacodec" + h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m" + h263_v4l2m2m_encoder_deps="v4l2_m2m h263_v4l2_m2m" + h264_amf_encoder_deps="amf" +diff --git a/libavcodec/Makefile b/libavcodec/Makefile +index 457ec58..0b95b65 100644 +--- a/libavcodec/Makefile ++++ b/libavcodec/Makefile +@@ -241,6 +241,7 @@ OBJS-$(CONFIG_AURA_DECODER) += cyuv.o + OBJS-$(CONFIG_AURA2_DECODER) += aura.o + OBJS-$(CONFIG_AV1_DECODER) += av1dec.o + OBJS-$(CONFIG_AV1_CUVID_DECODER) += cuviddec.o ++OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER) += mediacodecdec.o + OBJS-$(CONFIG_AVRN_DECODER) += avrndec.o + OBJS-$(CONFIG_AVRP_DECODER) += r210dec.o + OBJS-$(CONFIG_AVRP_ENCODER) += r210enc.o +diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c +index bdfc2f6..5c35444 100644 +--- a/libavcodec/allcodecs.c ++++ b/libavcodec/allcodecs.c +@@ -815,6 +815,7 @@ extern const FFCodec ff_libaom_av1_decoder; + /* hwaccel hooks only, so prefer external decoders */ + extern const FFCodec ff_av1_decoder; + extern const FFCodec ff_av1_cuvid_decoder; ++extern const FFCodec ff_av1_mediacodec_decoder; + extern const FFCodec ff_av1_qsv_decoder; + extern const FFCodec ff_libopenh264_encoder; + extern const FFCodec ff_libopenh264_decoder; +diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c +index 6b4c39b..49f118e 100644 +--- a/libavcodec/mediacodecdec.c ++++ b/libavcodec/mediacodecdec.c +@@ -1,5 +1,5 @@ + /* +- * Android MediaCodec MPEG-2 / H.264 / H.265 / MPEG-4 / VP8 / VP9 decoders ++ * Android MediaCodec MPEG-2 / H.264 / H.265 / MPEG-4 / VP8 / VP9 / AV1 decoders + * + * Copyright (c) 2015-2016 Matthieu Bouron + * +@@ -287,7 +287,8 @@ done: + #if CONFIG_MPEG2_MEDIACODEC_DECODER || \ + CONFIG_MPEG4_MEDIACODEC_DECODER || \ + CONFIG_VP8_MEDIACODEC_DECODER || \ +- CONFIG_VP9_MEDIACODEC_DECODER ++ CONFIG_VP9_MEDIACODEC_DECODER || \ ++ CONFIG_AV1_MEDIACODEC_DECODER + static int common_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format) + { + int ret = 0; +@@ -372,6 +373,15 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) + goto done; + break; + #endif ++#if CONFIG_AV1_MEDIACODEC_DECODER ++ case AV_CODEC_ID_AV1: ++ codec_mime = "video/av01"; ++ ++ ret = common_set_extradata(avctx, format); ++ if (ret < 0) ++ goto done; ++ break; ++#endif + default: + av_assert0(0); + } +@@ -573,3 +583,7 @@ DECLARE_MEDIACODEC_VDEC(vp8, "VP8", AV_CODEC_ID_VP8, NULL) + #if CONFIG_VP9_MEDIACODEC_DECODER + DECLARE_MEDIACODEC_VDEC(vp9, "VP9", AV_CODEC_ID_VP9, NULL) + #endif ++ ++#if CONFIG_AV1_MEDIACODEC_DECODER ++DECLARE_MEDIACODEC_VDEC(av1, "AV1", AV_CODEC_ID_AV1, NULL) ++#endif diff --git a/buildscripts/patches/ffmpeg/dash_base_url_escape.patch b/buildscripts/patches/ffmpeg/dash_base_url_escape.patch new file mode 100644 index 0000000..36ed6d5 --- /dev/null +++ b/buildscripts/patches/ffmpeg/dash_base_url_escape.patch @@ -0,0 +1,26 @@ +diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c +index 29d4680..c50afaf 100644 +--- a/libavformat/dashdec.c ++++ b/libavformat/dashdec.c +@@ -768,7 +768,9 @@ static int resolve_content_path(AVFormatContext *s, const char *url, int *max_ur + baseurl = xmlNodeGetContent(node); + root_url = (av_strcasecmp(baseurl, "")) ? baseurl : path; + if (node) { +- xmlNodeSetContent(node, root_url); ++ char* root_url_content = xmlEncodeSpecialChars(NULL, root_url); ++ xmlNodeSetContent(node, root_url_content); ++ xmlFree(root_url_content); + updated = 1; + } + +@@ -802,7 +804,9 @@ static int resolve_content_path(AVFormatContext *s, const char *url, int *max_ur + memset(p + 1, 0, strlen(p)); + } + av_strlcat(tmp_str, text + start, tmp_max_url_size); +- xmlNodeSetContent(baseurl_nodes[i], tmp_str); ++ char* tmp_str_content = xmlEncodeSpecialChars(NULL, tmp_str); ++ xmlNodeSetContent(baseurl_nodes[i], tmp_str_content); ++ xmlFree(tmp_str_content); + updated = 1; + xmlFree(text); + } diff --git a/buildscripts/patches/mpv/mpv_lavc_set_java_vm.patch b/buildscripts/patches/mpv/mpv_lavc_set_java_vm.patch new file mode 100644 index 0000000..a5a5e92 --- /dev/null +++ b/buildscripts/patches/mpv/mpv_lavc_set_java_vm.patch @@ -0,0 +1,44 @@ +diff --git a/libmpv/client.h b/libmpv/client.h +index fb10e5e..afbc952 100644 +--- a/libmpv/client.h ++++ b/libmpv/client.h +@@ -1707,6 +1707,15 @@ MPV_EXPORT mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout); + */ + MPV_EXPORT void mpv_wakeup(mpv_handle *ctx); + ++/** ++ * Calls av_jni_set_java_vm() with the given JavaVM*. ++ * https://github.com/FFmpeg/FFmpeg/blob/0ba719f726632d73592311615087a0d64aa2fb60/libavcodec/jni.h#L26-L36 ++ * ++ * The av_jni_set_java_vm() symbol is not visible when statically linking with libavcodec. ++ * It is important to call this method so that libavcodec can access JNI environment & thus, mediacodec APIs. ++ */ ++MPV_EXPORT int mpv_lavc_set_java_vm(void *vm); ++ + /** + * Set a custom function that should be called when there are new events. Use + * this if blocking in mpv_wait_event() to wait for new events is not feasible. +diff --git a/libmpv/mpv.def b/libmpv/mpv.def +index 232490d..d7a2842 100644 +--- a/player/client.c ++++ b/player/client.c +@@ -22,6 +22,8 @@ + #include + #include + ++#include ++ + #include "common/common.h" + #include "common/global.h" + #include "common/msg.h" +@@ -967,6 +969,10 @@ void mpv_wakeup(mpv_handle *ctx) + pthread_mutex_unlock(&ctx->lock); + } + ++int mpv_lavc_set_java_vm(void *vm) { ++ return av_jni_set_java_vm(vm, NULL); ++} ++ + // map client API types to internal types + static const struct m_option type_conv[] = { + [MPV_FORMAT_STRING] = { .type = CONF_TYPE_STRING }, diff --git a/buildscripts/scripts/dav1d.sh b/buildscripts/scripts/dav1d.sh index 7df636d..87a7198 100755 --- a/buildscripts/scripts/dav1d.sh +++ b/buildscripts/scripts/dav1d.sh @@ -17,9 +17,7 @@ fi unset CC CXX # meson wants these unset meson setup $build --cross-file "$prefix_dir"/crossfile.txt \ - -Denable_tests=false \ - -Db_lto=true \ - -Dstack_alignment=16 + -Denable_tests=false -Db_lto=true -Dstack_alignment=16 ninja -C $build -j$cores DESTDIR="$prefix_dir" ninja -C $build install diff --git a/buildscripts/scripts/ffmpeg.sh b/buildscripts/scripts/ffmpeg.sh deleted file mode 100755 index affccce..0000000 --- a/buildscripts/scripts/ffmpeg.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -e - -. ../../include/depinfo.sh -. ../../include/path.sh - -if [ "$1" == "build" ]; then - true -elif [ "$1" == "clean" ]; then - rm -rf _build$ndk_suffix - exit 0 -else - exit 255 -fi - -mkdir -p _build$ndk_suffix -cd _build$ndk_suffix - -cpu=armv7-a -[[ "$ndk_triple" == "aarch64"* ]] && cpu=armv8-a -[[ "$ndk_triple" == "x86_64"* ]] && cpu=generic -[[ "$ndk_triple" == "i686"* ]] && cpu="i686 --disable-asm" - -cpuflags= -[[ "$ndk_triple" == "arm"* ]] && cpuflags="$cpuflags -mfpu=neon -mcpu=cortex-a8" - -../configure \ - --target-os=android --enable-cross-compile --cross-prefix=$ndk_triple- --cc=$CC \ - --arch=${ndk_triple%%-*} --cpu=$cpu --pkg-config=pkg-config --nm=llvm-nm \ - --extra-cflags="-I$prefix_dir/include $cpuflags" --extra-ldflags="-L$prefix_dir/lib" \ - --enable-{jni,mediacodec,mbedtls,libdav1d} --disable-vulkan \ - --disable-static --enable-shared --enable-{gpl,version3} \ - --disable-{stripping,doc,programs} \ - --disable-{muxers,encoders,devices,filters} \ - --disable-v4l2-m2m - -make -j$cores -make DESTDIR="$prefix_dir" install - -ln -sf "$prefix_dir"/lib/libswresample.so "$native_dir" -ln -sf "$prefix_dir"/lib/libpostproc.so "$native_dir" -ln -sf "$prefix_dir"/lib/libavutil.so "$native_dir" -ln -sf "$prefix_dir"/lib/libavcodec.so "$native_dir" -ln -sf "$prefix_dir"/lib/libavformat.so "$native_dir" -ln -sf "$prefix_dir"/lib/libswscale.so "$native_dir" -ln -sf "$prefix_dir"/lib/libavfilter.so "$native_dir" -ln -sf "$prefix_dir"/lib/libavdevice.so "$native_dir" diff --git a/buildscripts/scripts/fftools_ffi.sh b/buildscripts/scripts/fftools_ffi.sh new file mode 100644 index 0000000..a8e6b19 --- /dev/null +++ b/buildscripts/scripts/fftools_ffi.sh @@ -0,0 +1,22 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +build=_build$ndk_suffix + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf $build + exit 0 +else + exit 255 +fi + +unset CC CXX # meson wants these unset + +CFLAGS=-fPIC CXXFLAGS=-fPIC meson setup $build --cross-file "$prefix_dir"/crossfile.txt + +ninja -C $build -j$cores +DESTDIR="$prefix_dir" ninja -C $build install diff --git a/buildscripts/scripts/libass.sh b/buildscripts/scripts/libass.sh index 2a9a44e..fd95d94 100755 --- a/buildscripts/scripts/libass.sh +++ b/buildscripts/scripts/libass.sh @@ -18,8 +18,12 @@ mkdir -p _build$ndk_suffix cd _build$ndk_suffix ../configure \ - --host=$ndk_triple --with-pic \ - --enable-static --disable-shared \ + CFLAGS=-fPIC CXXFLAGS=-fPIC \ + --host=$ndk_triple \ + --with-pic \ + --disable-asm \ + --enable-static\ + --disable-shared \ --disable-require-system-font-provider make -j$cores diff --git a/buildscripts/scripts/libogg.build b/buildscripts/scripts/libogg.build new file mode 100644 index 0000000..16cfd10 --- /dev/null +++ b/buildscripts/scripts/libogg.build @@ -0,0 +1,17 @@ +# https://mesonbuild.com/External-Project-module.html + +project('libogg', 'c') + +mod = import('unstable-external_project') + +p = mod.add_project('configure', + configure_options : [ + '--prefix=@PREFIX@', + '--disable-shared', + '--enable-static', + ], + verbose: true, +) + +libogg_dep = p.dependency('libogg') +meson.override_dependency('libogg', libogg_dep) diff --git a/buildscripts/scripts/libogg.sh b/buildscripts/scripts/libogg.sh new file mode 100644 index 0000000..c100114 --- /dev/null +++ b/buildscripts/scripts/libogg.sh @@ -0,0 +1,24 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +build=_build$ndk_suffix + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf $build + exit 0 +else + exit 255 +fi + +cp ../../scripts/libogg.build meson.build + +unset CC CXX # meson wants these unset + +CFLAGS=-fPIC CXXFLAGS=-fPIC meson setup $build --cross-file "$prefix_dir"/crossfile.txt -Ddefault_library=static + +meson compile -C $build libogg +DESTDIR="$prefix_dir" ninja -C $build install diff --git a/buildscripts/scripts/libvorbis.build b/buildscripts/scripts/libvorbis.build new file mode 100644 index 0000000..4755ea7 --- /dev/null +++ b/buildscripts/scripts/libvorbis.build @@ -0,0 +1,17 @@ +# https://mesonbuild.com/External-Project-module.html + +project('libvorbis', 'c') + +mod = import('unstable-external_project') + +p = mod.add_project('configure', + configure_options : [ + '--prefix=@PREFIX@', + '--enable-static', + '--disable-shared', + ], + verbose: true, +) + +libvorbis_dep = p.dependency('libvorbis') +meson.override_dependency('libvorbis', libvorbis_dep) diff --git a/buildscripts/scripts/libvorbis.sh b/buildscripts/scripts/libvorbis.sh new file mode 100644 index 0000000..5933f27 --- /dev/null +++ b/buildscripts/scripts/libvorbis.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +build=_build$ndk_suffix + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf $build + exit 0 +else + exit 255 +fi + +cp ../../scripts/libvorbis.build meson.build +# -mno-ieee-fp is not supported by clang +sed s/\-mno\-ieee\-fp// -i {configure,configure.ac} + +unset CC CXX # meson wants these unset + +CFLAGS=-fPIC CXXFLAGS=-fPIC meson setup $build --cross-file "$prefix_dir"/crossfile.txt -Ddefault_library=static + +meson compile -C $build libvorbis +DESTDIR="$prefix_dir" ninja -C $build install diff --git a/buildscripts/scripts/libvpx.sh b/buildscripts/scripts/libvpx.sh new file mode 100644 index 0000000..c3d0449 --- /dev/null +++ b/buildscripts/scripts/libvpx.sh @@ -0,0 +1,22 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +build=_build$ndk_suffix + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf $build + exit 0 +else + exit 255 +fi + +unset CC CXX # meson wants these unset + +meson setup $build --cross-file "$prefix_dir"/crossfile.txt -Ddefault_library=static -Dcpu_features_path="$ANDROID_HOME/ndk/$v_ndk/sources/android/cpufeatures" + +ninja -C $build -j$cores +DESTDIR="$prefix_dir" ninja -C $build install diff --git a/buildscripts/scripts/libx264.build b/buildscripts/scripts/libx264.build new file mode 100644 index 0000000..776ac2f --- /dev/null +++ b/buildscripts/scripts/libx264.build @@ -0,0 +1,26 @@ +# https://mesonbuild.com/External-Project-module.html + +project('libx264', 'c') + +mod = import('unstable-external_project') + +configure_options = [ + '--prefix=@PREFIX@', + '--disable-shared', + '--enable-static', + '--disable-cli', + '--enable-pic' +] + +if host_machine.cpu() == 'i686' + # See https://github.com/android/ndk/issues/693 + configure_options += '--disable-asm' +endif + +p = mod.add_project('configure', + configure_options : configure_options, + verbose: true +) + +libx264_dep = p.dependency('libx264') +meson.override_dependency('libx264', libx264_dep) diff --git a/buildscripts/scripts/libx264.sh b/buildscripts/scripts/libx264.sh new file mode 100644 index 0000000..eb597a2 --- /dev/null +++ b/buildscripts/scripts/libx264.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +build=_build$ndk_suffix + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf $build + exit 0 +else + exit 255 +fi + +cp ../../scripts/libx264.build meson.build + +unset CC CXX # meson wants these unset + +mkdir $build + +meson setup $build --cross-file "$prefix_dir"/crossfile.txt --prefix="$prefix_dir" + +meson compile -C $build libx264 +meson install -C $build diff --git a/buildscripts/scripts/libxml2.sh b/buildscripts/scripts/libxml2.sh new file mode 100644 index 0000000..4418462 --- /dev/null +++ b/buildscripts/scripts/libxml2.sh @@ -0,0 +1,31 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf _build$ndk_suffix + exit 0 +else + exit 255 +fi + +[ -f configure ] || ./autogen.sh + +mkdir -p _build$ndk_suffix +cd _build$ndk_suffix + +../configure \ + CFLAGS=-fPIC CXXFLAGS=-fPIC \ + --host=$ndk_triple \ + --disable-shared \ + --enable-static \ + --with-minimum \ + --with-threads \ + --with-tree \ + --without-lzma \ + +make -j$cores +make DESTDIR="$prefix_dir" install diff --git a/buildscripts/scripts/lua.sh b/buildscripts/scripts/lua.sh deleted file mode 100755 index 38a0f24..0000000 --- a/buildscripts/scripts/lua.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -e - -. ../../include/depinfo.sh -. ../../include/path.sh - -if [ "$1" == "build" ]; then - true -elif [ "$1" == "clean" ]; then - make clean - exit 0 -else - exit 255 -fi - -# Building seperately from source tree is not supported, this means we are forced to always clean -$0 clean - -# LUA_T= and LUAC_T= to disable building lua & luac -# -Dgetlocaledecpoint()=('.') fixes bionic missing decimal_point in localeconv -make CC="$CC" AR="$AR rc" RANLIB="$RANLIB" \ - MYCFLAGS="-fPIC -Dgetlocaledecpoint\(\)=\(\'.\'\)" \ - PLAT=linux LUA_T= LUAC_T= -j$cores - -# TO_BIN=/dev/null disables installing lua & luac -make INSTALL=${INSTALL:-install} INSTALL_TOP="$prefix_dir" TO_BIN=/dev/null install - -# make pc only generates a partial pkg-config file because ???? -mkdir -p $prefix_dir/lib/pkgconfig -make pc >$prefix_dir/lib/pkgconfig/lua.pc -cat >>$prefix_dir/lib/pkgconfig/lua.pc <<'EOF' -Name: Lua -Description: -Version: ${version} -Libs: -L${libdir} -llua -Cflags: -I${includedir} -EOF diff --git a/buildscripts/scripts/mbedtls.sh b/buildscripts/scripts/mbedtls.sh index f2aec46..220a812 100755 --- a/buildscripts/scripts/mbedtls.sh +++ b/buildscripts/scripts/mbedtls.sh @@ -14,5 +14,5 @@ fi $0 clean # separate building not supported, always clean -make -j$cores no_test -make DESTDIR="$prefix_dir" install +make CFLAGS=-fPIC CXXFLAGS=-fPIC -j$cores no_test +make CFLAGS=-fPIC CXXFLAGS=-fPIC DESTDIR="$prefix_dir" install diff --git a/buildscripts/scripts/mpv-android.sh b/buildscripts/scripts/mpv-android.sh deleted file mode 100755 index 98ee640..0000000 --- a/buildscripts/scripts/mpv-android.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -BUILD="$DIR/.." -MPV_ANDROID="$DIR/../.." - -. $BUILD/include/path.sh -. $BUILD/include/depinfo.sh - -if [ "$1" == "build" ]; then - true -elif [ "$1" == "clean" ]; then - rm -rf $MPV_ANDROID/{libmpv,.}/build $MPV_ANDROID/libmpv/src/main/{libs,obj} - exit 0 -else - exit 255 -fi - -nativeprefix () { - if [ -f $BUILD/prefix/$1/lib/libmpv.so ]; then - echo $BUILD/prefix/$1 - else - echo >&2 "Warning: libmpv.so not found in native prefix for $1, support will be omitted" - fi -} - -./gradlew assembleRelease diff --git a/buildscripts/scripts/mpv.sh b/buildscripts/scripts/mpv.sh index 92f16a3..cd7ec65 100755 --- a/buildscripts/scripts/mpv.sh +++ b/buildscripts/scripts/mpv.sh @@ -17,10 +17,15 @@ fi unset CC CXX # meson wants these unset meson setup $build --cross-file "$prefix_dir"/crossfile.txt \ + --prefer-static \ --default-library shared \ - -Diconv=disabled -Dlua=enabled \ - -Dlibmpv=true -Dcplayer=false \ - -Dmanpage-build=disabled + -Dgpl=false \ + -Dlibmpv=true \ + -Dcplayer=false \ + -Dlua=disabled \ + -Diconv=disabled \ + -Djavascript=disabled \ + -Dmanpage-build=disabled ninja -C $build -j$cores DESTDIR="$prefix_dir" ninja -C $build install diff --git a/buildscripts/scripts/shaderc.sh b/buildscripts/scripts/shaderc.sh new file mode 100644 index 0000000..3da0902 --- /dev/null +++ b/buildscripts/scripts/shaderc.sh @@ -0,0 +1,43 @@ +#!/bin/bash -e + +. ../../include/depinfo.sh +. ../../include/path.sh + +if [ "$1" == "build" ]; then + true +elif [ "$1" == "clean" ]; then + rm -rf local include libs + exit 0 +else + exit 255 +fi + +builddir=$PWD + +abi=armeabi-v7a +[[ "$ndk_triple" == "aarch64"* ]] && abi=arm64-v8a +[[ "$ndk_triple" == "x86_64"* ]] && abi=x86_64 +[[ "$ndk_triple" == "i686"* ]] && abi=x86 + +# build using the NDK's scripts, but keep object files in our build dir +cd "$(dirname "$(which ndk-build)")/sources/third_party/shaderc" +ndk-build -j$cores \ + NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk \ + APP_PLATFORM=android-26 APP_STL=c++_shared APP_ABI=$abi \ + NDK_APP_OUT="$builddir" NDK_APP_LIBS_OUT="$builddir/libs" \ + libshaderc_combined + +cd "$builddir" +cp -r include/* "$prefix_dir/include" +cp libs/*/$abi/libshaderc.a "$prefix_dir/lib/libshaderc_combined.a" + +# create a pkgconfig file +# 'libc++' instead of 'libstdc++': workaround for meson linking bug +mkdir -p "$prefix_dir"/lib/pkgconfig +cat >"$prefix_dir"/lib/pkgconfig/shaderc_combined.pc <<"END" +Name: shaderc_combined +Description: +Version: 2022.1-unknown +Libs: -L/usr/lib -lshaderc_combined -llibc++ +Cflags: -I${includedir} +END