diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7010deb..5edec2c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,15 +1,18 @@ name: Build libmpv-android -on: +on: push: branches: - main pull_request: +permissions: + contents: write + jobs: build: name: Build - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout repository uses: actions/checkout@v4 @@ -20,21 +23,39 @@ jobs: java-version: 17 - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 + - name: Setup Flutter SDK + uses: subosito/flutter-action@v1 + with: + channel: "stable" - name: Symlink SDK working-directory: ./buildscripts run: | mkdir sdk ln -s ${ANDROID_HOME} ./sdk/android-sdk-linux - - name: Download dependencies + - name: Bundle (default) working-directory: ./buildscripts - run: ./download.sh - - name: Apply patches + run: | + sudo chmod +x bundle_default.sh + ./bundle_default.sh + - name: Bundle (full) working-directory: ./buildscripts - run: ./patch.sh - - name: Build + run: | + sudo chmod +x bundle_full.sh + ./bundle_full.sh + - name: Bundle (encoders-gpl) working-directory: ./buildscripts - run: ./build.sh + run: | + sudo chmod +x bundle_encoders-gpl.sh + ./bundle_encoders-gpl.sh - uses: actions/upload-artifact@v4 with: - name: libmpv-release.aar - path: ./libmpv/build/outputs/aar/libmpv-release.aar + name: artifact + path: ./buildscripts/*.jar + - uses: softprops/action-gh-release@v1 + if: github.ref == 'refs/heads/main' + with: + draft: true + prerelease: false + tag_name: "vnext" + files: | + buildscripts/*.jar diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml deleted file mode 100644 index dd458a5..0000000 --- a/.github/workflows/publish.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: Publish - -on: - push: - tags: - - v* - -jobs: - publish: - name: Publish - runs-on: ubuntu-latest - environment: release - if: ${{ contains(github.repository_owner, 'jarnedemeulemeester') || startsWith(github.ref, 'refs/tags/v') }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup Java JDK - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 17 - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - name: Symlink SDK - working-directory: ./buildscripts - run: | - mkdir sdk - ln -s ${ANDROID_HOME} ./sdk/android-sdk-linux - - name: Download dependencies - working-directory: ./buildscripts - run: ./download.sh - - name: Apply patches - working-directory: ./buildscripts - run: ./patch.sh - - name: Build - working-directory: ./buildscripts - run: ./build.sh - - name: Publish to MavenCentral - run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository - env: - OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} - OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} - SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} - SIGNING_KEY: ${{ secrets.SIGNING_KEY }} - SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} - - name: Create release - uses: softprops/action-gh-release@v2 - with: - draft: true - files: | - ./libmpv/build/outputs/aar/libmpv-release.aar diff --git a/LICENSE b/LICENSE index 81d2ff3..cfaa955 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +For the "default" and "full" flavors, the following license applies: + Copyright (c) 2016 Ilya Zhuravlev Copyright (c) 2016 sfan5 @@ -6,3 +8,20 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the "encoders-gpl" flavor, the following license applies: + +Copyright (C) 2023 Callum Moffat + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . diff --git a/README.md b/README.md deleted file mode 100644 index 7d27336..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# libmpv for Android - -Based on [mpv-android](https://github.com/mpv-android/mpv-android) - -## Building from source - -Take a look at [README.md](buildscripts/README.md) inside the `buildscripts` directory. diff --git a/build.gradle.kts b/build.gradle.kts index 99629b3..ed1e353 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +@Suppress("DSL_SCOPE_VIOLATION") // False positive plugins { alias(libs.plugins.android.library) apply false alias(libs.plugins.publish.plugin) apply true @@ -10,44 +11,11 @@ allprojects { } } -// Create variables with empty default values -ext["signing.keyId"] = null -ext["signing.password"] = null -ext["signing.key"] = null -ext["ossrhUsername"] = null -ext["ossrhPassword"] = null -ext["sonatypeStagingProfileId"] = null - -val secretPropsFile: File = project.rootProject.file("local.properties") -if (secretPropsFile.exists()) { - // Read local.properties file first if it exists - secretPropsFile.reader().use { - java.util.Properties().apply { - load(it) - } - }.onEach { (name, value) -> - ext[name.toString()] = value - } -} else { - // Use system environment variables - ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME") - ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") - ext["sonatypeStagingProfileId"] = System.getenv("SONATYPE_STAGING_PROFILE_ID") - ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID") - ext["signing.password"] = System.getenv("SIGNING_PASSWORD") - ext["signing.key"] = System.getenv("SIGNING_KEY") +tasks.wrapper { + gradleVersion = "7.6" + distributionType = Wrapper.DistributionType.ALL } -fun getExtraString(name: String) = ext[name]?.toString() - -nexusPublishing { - this.repositories { - sonatype { - stagingProfileId = getExtraString("sonatypeStagingProfileId") - username = getExtraString("ossrhUsername") - password = getExtraString("ossrhPassword") - nexusUrl = uri("https://s01.oss.sonatype.org/service/local/") - snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") - } - } +apply { + from("$rootDir/scripts/publish-root.gradle") } \ No newline at end of file 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..76bffb7 --- /dev/null +++ b/buildscripts/bundle_default.sh @@ -0,0 +1,45 @@ +# -------------------------------------------------- + +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 + +cp app/build/outputs/apk/release/lib/arm64-v8a/libmediakitandroidhelper.so ../../prefix/arm64-v8a/usr/local/lib +cp app/build/outputs/apk/release/lib/armeabi-v7a/libmediakitandroidhelper.so ../../prefix/armeabi-v7a/usr/local/lib +cp app/build/outputs/apk/release/lib/x86/libmediakitandroidhelper.so ../../prefix/x86/usr/local/lib +cp app/build/outputs/apk/release/lib/x86_64/libmediakitandroidhelper.so ../../prefix/x86_64/usr/local/lib + +cd ../.. + +zip -r default-arm64-v8a.jar prefix/arm64-v8a/usr/local/lib/*.so +zip -r default-armeabi-v7a.jar prefix/armeabi-v7a/usr/local/lib/*.so +zip -r default-x86.jar prefix/x86/usr/local/lib/*.so +zip -r default-x86_64.jar prefix/x86_64/usr/local/lib/*.so + +md5sum *.jar diff --git a/buildscripts/bundle_encoders-gpl.sh b/buildscripts/bundle_encoders-gpl.sh new file mode 100755 index 0000000..9e79d57 --- /dev/null +++ b/buildscripts/bundle_encoders-gpl.sh @@ -0,0 +1,46 @@ +# -------------------------------------------------- +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 + +cp app/build/outputs/apk/release/lib/arm64-v8a/libmediakitandroidhelper.so ../../prefix/arm64-v8a/usr/local/lib +cp app/build/outputs/apk/release/lib/armeabi-v7a/libmediakitandroidhelper.so ../../prefix/armeabi-v7a/usr/local/lib +cp app/build/outputs/apk/release/lib/x86/libmediakitandroidhelper.so ../../prefix/x86/usr/local/lib +cp app/build/outputs/apk/release/lib/x86_64/libmediakitandroidhelper.so ../../prefix/x86_64/usr/local/lib + +cd ../.. + +zip -r encoders-gpl-arm64-v8a.jar prefix/arm64-v8a/usr/local/lib/*.so +zip -r encoders-gpl-armeabi-v7a.jar prefix/armeabi-v7a/usr/local/lib/*.so +zip -r encoders-gpl-x86.jar prefix/x86/usr/local/lib/*.so +zip -r encoders-gpl-x86_64.jar prefix/x86_64/usr/local/lib/*.so + +md5sum *.jar diff --git a/buildscripts/bundle_full.sh b/buildscripts/bundle_full.sh new file mode 100755 index 0000000..ed34fcf --- /dev/null +++ b/buildscripts/bundle_full.sh @@ -0,0 +1,45 @@ +# -------------------------------------------------- + +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 + +cp app/build/outputs/apk/release/lib/arm64-v8a/libmediakitandroidhelper.so ../../prefix/arm64-v8a/usr/local/lib +cp app/build/outputs/apk/release/lib/armeabi-v7a/libmediakitandroidhelper.so ../../prefix/armeabi-v7a/usr/local/lib +cp app/build/outputs/apk/release/lib/x86/libmediakitandroidhelper.so ../../prefix/x86/usr/local/lib +cp app/build/outputs/apk/release/lib/x86_64/libmediakitandroidhelper.so ../../prefix/x86_64/usr/local/lib + +cd ../.. + +zip -r full-arm64-v8a.jar prefix/arm64-v8a/usr/local/lib/*.so +zip -r full-armeabi-v7a.jar prefix/armeabi-v7a/usr/local/lib/*.so +zip -r full-x86.jar prefix/x86/usr/local/lib/*.so +zip -r full-x86_64.jar prefix/x86_64/usr/local/lib/*.so + +md5sum *.jar 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 100755 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..0b50cb1 --- /dev/null +++ b/buildscripts/patches-encoders-gpl/mpv/depend_on_fftools_ffi.patch @@ -0,0 +1,36 @@ +diff --git a/meson.build b/meson.build +index 7e816d8b29..0ac66d3e98 100644 +--- a/meson.build ++++ b/meson.build +@@ -26,6 +26,9 @@ libavutil = dependency('libavutil', version: '>= 58.29.100') + libswresample = dependency('libswresample', version: '>= 4.12.100') + libswscale = dependency('libswscale', version: '>= 7.5.100') + ++# fftools-ffi ++libfftools_ffi = dependency('fftools-ffi') ++ + libplacebo = dependency('libplacebo', version: '>=6.338.2', + default_options: ['default_library=static', 'demos=false']) + +@@ -40,7 +43,8 @@ dependencies = [libass, + libavutil, + libplacebo, + libswresample, +- libswscale] ++ libswscale, ++ libfftools_ffi] + + # Keeps track of all enabled/disabled features + features = { +@@ -257,7 +261,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/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/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..548353f --- /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 8eb5e05a04..51e490d9e7 100644 +--- a/libmpv/client.h ++++ b/libmpv/client.h +@@ -1730,6 +1730,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/player/client.c b/player/client.c +index b5112d1490..b9e1ea8e3c 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" +@@ -964,6 +966,10 @@ void mpv_wakeup(mpv_handle *ctx) + mp_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 old mode 100755 new mode 100644 index affccce..7e09c87 --- a/buildscripts/scripts/ffmpeg.sh +++ b/buildscripts/scripts/ffmpeg.sh @@ -24,14 +24,247 @@ cpuflags= [[ "$ndk_triple" == "arm"* ]] && cpuflags="$cpuflags -mfpu=neon -mcpu=cortex-a8" ../configure \ - --target-os=android --enable-cross-compile --cross-prefix=$ndk_triple- --cc=$CC \ + --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" \ - --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 + \ + --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 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 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index a4b76b9..943f0cb 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradlew b/gradlew index f5feea6..65dcd68 100755 --- a/gradlew +++ b/gradlew @@ -15,8 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# SPDX-License-Identifier: Apache-2.0 -# ############################################################################## # @@ -57,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -85,9 +83,10 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -134,13 +133,10 @@ location of your Java installation." fi else JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi fi # Increase the maximum file descriptors if we can. @@ -148,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -156,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -201,15 +197,11 @@ if "$cygwin" || "$msys" ; then done fi - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/libmpv/build.gradle.kts b/libmpv/build.gradle.kts deleted file mode 100755 index ba35b22..0000000 --- a/libmpv/build.gradle.kts +++ /dev/null @@ -1,94 +0,0 @@ -plugins { - alias(libs.plugins.android.library) - `maven-publish` - signing -} - -android { - namespace = "dev.jdtech.mpv" - compileSdk = 35 - buildToolsVersion = "35.0.0" - ndkVersion = "27.1.12297006" - - defaultConfig { - minSdk = 26 - consumerProguardFiles("proguard-rules.pro") - externalNativeBuild { - cmake { - arguments += listOf( - "-DANDROID_STL=c++_shared", - "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON", - ) - cFlags += "-Werror" - cppFlags += "-std=c++11" - } - } - } - - externalNativeBuild { - cmake { - path = file("src/main/cpp/CMakeLists.txt") - version = "3.30.3" - } - } - - publishing { - singleVariant("release") { - withSourcesJar() - } - } -} - -dependencies { - implementation(libs.androidx.annotation) -} - -publishing { - publications { - create("release") { - groupId = "dev.jdtech.mpv" - artifactId = "libmpv" - version = "0.4.1" - - afterEvaluate { - from(components["release"]) - } - - pom { - name = "dev.jdtech.mpv" - description = "libmpv for Android" - url = "https://github.com/jarnedemeulemeester/libmpv-android" - licenses { - license { - name = "MIT license" - url = "https://github.com/jarnedemeulemeester/libmpv-android/blob/main/LICENSE" - } - } - developers { - developer { - id = "jarnedemeulemeester" - name = "Jarne Demeulemeester" - email = "jarnedemeulemeester@gmail.com" - } - } - scm { - url = "https://github.com/jarnedemeulemeester/libmpv-android.git" - connection = "scm:git@github.com:jarnedemeulemeester/libmpv-android.git" - developerConnection = "scm:git@github.com:jarnedemeulemeester/libmpv-android.git" - } - issueManagement { - url = "https://github.com/jarnedemeulemeester/libmpv-android/issues" - } - } - } - } -} - -signing { - useInMemoryPgpKeys( - rootProject.ext["signing.keyId"]?.toString(), - rootProject.ext["signing.key"]?.toString(), - rootProject.ext["signing.password"]?.toString(), - ) - sign(publishing.publications) -} diff --git a/libmpv/proguard-rules.pro b/libmpv/proguard-rules.pro deleted file mode 100644 index cf1ca81..0000000 --- a/libmpv/proguard-rules.pro +++ /dev/null @@ -1 +0,0 @@ --keep class dev.jdtech.mpv.MPVLib { *; } diff --git a/libmpv/src/main/cpp/CMakeLists.txt b/libmpv/src/main/cpp/CMakeLists.txt deleted file mode 100644 index a1b8f62..0000000 --- a/libmpv/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 3.22.1) - -project("libmpv") - -add_library( - player - SHARED - main.cpp render.cpp log.cpp jni_utils.cpp property.cpp event.cpp -) - -add_library( - mpv - SHARED - IMPORTED -) - -set_target_properties( - mpv - PROPERTIES IMPORTED_LOCATION - ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libmpv.so -) - -add_library( - avcodec - SHARED - IMPORTED -) - -set_target_properties( - avcodec - PROPERTIES IMPORTED_LOCATION - ${CMAKE_CURRENT_SOURCE_DIR}/../../../../buildscripts/prefix/${ANDROID_ABI}/lib/libavcodec.so -) - -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../../../buildscripts/prefix/${ANDROID_ABI}/include ) - -target_link_libraries( player mpv avcodec log ) \ No newline at end of file diff --git a/libmpv/src/main/cpp/event.cpp b/libmpv/src/main/cpp/event.cpp deleted file mode 100644 index 549f3e3..0000000 --- a/libmpv/src/main/cpp/event.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include - -#include - -#include "globals.h" -#include "jni_utils.h" -#include "log.h" - -static void sendPropertyUpdateToJava(JNIEnv *env, mpv_event_property *prop) { - jstring jprop = env->NewStringUTF(prop->name); - jstring jvalue = nullptr; - switch (prop->format) { - case MPV_FORMAT_NONE: - env->CallStaticVoidMethod(mpv_MPVLib, mpv_MPVLib_eventProperty_S, jprop); - break; - case MPV_FORMAT_FLAG: - env->CallStaticVoidMethod(mpv_MPVLib, mpv_MPVLib_eventProperty_Sb, jprop, *(int*)prop->data); - break; - case MPV_FORMAT_INT64: - env->CallStaticVoidMethod(mpv_MPVLib, mpv_MPVLib_eventProperty_Sl, jprop, *(int64_t*)prop->data); - break; - case MPV_FORMAT_DOUBLE: - env->CallStaticVoidMethod(mpv_MPVLib, mpv_MPVLib_eventProperty_Sd, jprop, *(double*)prop->data); - break; - case MPV_FORMAT_STRING: - jvalue = env->NewStringUTF(*(const char**)prop->data); - env->CallStaticVoidMethod(mpv_MPVLib, mpv_MPVLib_eventProperty_SS, jprop, jvalue); - break; - default: - ALOGV("sendPropertyUpdateToJava: Unknown property update format received in callback: %d!", prop->format); - break; - } - if (jprop) - env->DeleteLocalRef(jprop); - if (jvalue) - env->DeleteLocalRef(jvalue); -} - -static void sendEventToJava(JNIEnv *env, int event) { - env->CallStaticVoidMethod(mpv_MPVLib, mpv_MPVLib_event, event); -} - -static inline bool invalid_utf8(unsigned char c) { - return c == 0xc0 || c == 0xc1 || c >= 0xf5; -} - -static void sendLogMessageToJava(JNIEnv *env, mpv_event_log_message *msg) { - // filter the most obvious cases of invalid utf-8 - int invalid = 0; - for (int i = 0; msg->text[i]; i++) - invalid |= invalid_utf8((unsigned char) msg->text[i]); - if (invalid) - return; - - jstring jprefix = env->NewStringUTF(msg->prefix); - jstring jtext = env->NewStringUTF(msg->text); - - env->CallStaticVoidMethod(mpv_MPVLib, mpv_MPVLib_logMessage_SiS, - jprefix, (jint) msg->log_level, jtext); - - if (jprefix) - env->DeleteLocalRef(jprefix); - if (jtext) - env->DeleteLocalRef(jtext); -} - -void *event_thread(void *arg) { - JNIEnv *env = nullptr; - acquire_jni_env(g_vm, &env); - if (!env) - die("failed to acquire java env"); - - while (true) { - mpv_event *mp_event; - mpv_event_property *mp_property; - mpv_event_log_message *msg; - - mp_event = mpv_wait_event(g_mpv, -1.0); - - if (g_event_thread_request_exit) - break; - - if (mp_event->event_id == MPV_EVENT_NONE) - continue; - - switch (mp_event->event_id) { - case MPV_EVENT_LOG_MESSAGE: - msg = (mpv_event_log_message*)mp_event->data; - ALOGV("[%s:%s] %s", msg->prefix, msg->level, msg->text); - sendLogMessageToJava(env, msg); - break; - case MPV_EVENT_PROPERTY_CHANGE: - mp_property = (mpv_event_property*)mp_event->data; - sendPropertyUpdateToJava(env, mp_property); - break; - default: - ALOGV("event: %s\n", mpv_event_name(mp_event->event_id)); - sendEventToJava(env, mp_event->event_id); - break; - } - } - - g_vm->DetachCurrentThread(); - - return nullptr; -} diff --git a/libmpv/src/main/cpp/event.h b/libmpv/src/main/cpp/event.h deleted file mode 100644 index ebb20d2..0000000 --- a/libmpv/src/main/cpp/event.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void *event_thread(void *arg); diff --git a/libmpv/src/main/cpp/globals.h b/libmpv/src/main/cpp/globals.h deleted file mode 100644 index e2427b8..0000000 --- a/libmpv/src/main/cpp/globals.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -extern JavaVM *g_vm; -extern mpv_handle *g_mpv; -extern std::atomic g_event_thread_request_exit; diff --git a/libmpv/src/main/cpp/jni_utils.cpp b/libmpv/src/main/cpp/jni_utils.cpp deleted file mode 100644 index ebd519b..0000000 --- a/libmpv/src/main/cpp/jni_utils.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "jni_utils.h" - -#include -#include - -bool acquire_jni_env(JavaVM *vm, JNIEnv **env) -{ - int ret = vm->GetEnv((void**) env, JNI_VERSION_1_6); - if (ret == JNI_EDETACHED) - return vm->AttachCurrentThread(env, nullptr) == 0; - else - return ret == JNI_OK; -} - -// Apparently it's considered slow to FindClass and GetMethodID every time we need them, -// so let's have a nice cache here -jclass java_Integer, java_Double, java_Boolean; -jmethodID java_Integer_init, java_Integer_intValue, java_Double_init, java_Double_doubleValue, java_Boolean_init, java_Boolean_booleanValue; -jmethodID java_GLSurfaceView_requestRender; - -jclass mpv_MPVLib; -jmethodID mpv_MPVLib_eventProperty_S, mpv_MPVLib_eventProperty_Sb, mpv_MPVLib_eventProperty_Sl, mpv_MPVLib_eventProperty_Sd, mpv_MPVLib_eventProperty_SS, mpv_MPVLib_event, mpv_MPVLib_logMessage_SiS; - -void init_methods_cache(JNIEnv *env) { - static bool methods_initialized = false; - if (methods_initialized) - return; - - #define FIND_CLASS(name) reinterpret_cast(env->NewGlobalRef(env->FindClass(name))) - java_Integer = FIND_CLASS("java/lang/Integer"); - java_Integer_init = env->GetMethodID(java_Integer, "", "(I)V"); - java_Integer_intValue = env->GetMethodID(java_Integer, "intValue", "()I"); - java_Double = FIND_CLASS("java/lang/Double"); - java_Double_init = env->GetMethodID(java_Double, "", "(D)V"); - java_Double_doubleValue = env->GetMethodID(java_Double, "doubleValue", "()D"); - java_Boolean = FIND_CLASS("java/lang/Boolean"); - java_Boolean_init = env->GetMethodID(java_Boolean, "", "(Z)V"); - java_Boolean_booleanValue = env->GetMethodID(java_Boolean, "booleanValue", "()Z"); - - mpv_MPVLib = FIND_CLASS("dev/jdtech/mpv/MPVLib"); - mpv_MPVLib_eventProperty_S = env->GetStaticMethodID(mpv_MPVLib, "eventProperty", "(Ljava/lang/String;)V"); // eventProperty(String) - mpv_MPVLib_eventProperty_Sb = env->GetStaticMethodID(mpv_MPVLib, "eventProperty", "(Ljava/lang/String;Z)V"); // eventProperty(String, boolean) - mpv_MPVLib_eventProperty_Sl = env->GetStaticMethodID(mpv_MPVLib, "eventProperty", "(Ljava/lang/String;J)V"); // eventProperty(String, long) - mpv_MPVLib_eventProperty_Sd = env->GetStaticMethodID(mpv_MPVLib, "eventProperty", "(Ljava/lang/String;D)V"); // eventProperty(String, double) - mpv_MPVLib_eventProperty_SS = env->GetStaticMethodID(mpv_MPVLib, "eventProperty", "(Ljava/lang/String;Ljava/lang/String;)V"); // eventProperty(String, String) - mpv_MPVLib_event = env->GetStaticMethodID(mpv_MPVLib, "event", "(I)V"); // event(int) - mpv_MPVLib_logMessage_SiS = env->GetStaticMethodID(mpv_MPVLib, "logMessage", "(Ljava/lang/String;ILjava/lang/String;)V"); // logMessage(String, int, String) - #undef FIND_CLASS - - methods_initialized = true; -} diff --git a/libmpv/src/main/cpp/jni_utils.h b/libmpv/src/main/cpp/jni_utils.h deleted file mode 100644 index af0b08f..0000000 --- a/libmpv/src/main/cpp/jni_utils.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -#define jni_func_name(name) Java_dev_jdtech_mpv_MPVLib_##name -#define jni_func(return_type, name, ...) JNIEXPORT return_type JNICALL jni_func_name(name) (JNIEnv *env, jobject obj, ##__VA_ARGS__) - -bool acquire_jni_env(JavaVM *vm, JNIEnv **env); -void init_methods_cache(JNIEnv *env); - -extern jclass java_Integer, java_Double, java_Boolean; -extern jmethodID java_Integer_init, java_Integer_intValue, java_Double_init, java_Double_doubleValue, java_Boolean_init, java_Boolean_booleanValue; -extern jmethodID java_GLSurfaceView_requestRender; - -extern jclass mpv_MPVLib; -extern jmethodID mpv_MPVLib_eventProperty_S, mpv_MPVLib_eventProperty_Sb, mpv_MPVLib_eventProperty_Sl, mpv_MPVLib_eventProperty_Sd, mpv_MPVLib_eventProperty_SS, mpv_MPVLib_event, mpv_MPVLib_logMessage_SiS; diff --git a/libmpv/src/main/cpp/log.cpp b/libmpv/src/main/cpp/log.cpp deleted file mode 100644 index 98a4642..0000000 --- a/libmpv/src/main/cpp/log.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "log.h" - -#include - -void die(const char *msg) -{ - ALOGE("%s", msg); - exit(1); -} diff --git a/libmpv/src/main/cpp/log.h b/libmpv/src/main/cpp/log.h deleted file mode 100644 index f7003f9..0000000 --- a/libmpv/src/main/cpp/log.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -#define DEBUG 1 - -#define LOG_TAG "mpv" -#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -#if DEBUG -#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) -#else -#define ALOGV(...) -#endif - -void die(const char *msg); diff --git a/libmpv/src/main/cpp/main.cpp b/libmpv/src/main/cpp/main.cpp deleted file mode 100644 index a61df51..0000000 --- a/libmpv/src/main/cpp/main.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern "C" { - #include -} - -#include "log.h" -#include "jni_utils.h" -#include "event.h" - -#define ARRAYLEN(a) (sizeof(a)/sizeof(a[0])) - -extern "C" { - jni_func(void, create, jobject appctx); - jni_func(void, init); - jni_func(void, destroy); - - jni_func(void, command, jobjectArray jarray); -}; - -JavaVM *g_vm; -mpv_handle *g_mpv; -std::atomic g_event_thread_request_exit(false); - -static pthread_t event_thread_id; - -static void prepare_environment(JNIEnv *env, jobject appctx) { - setlocale(LC_NUMERIC, "C"); - - if (!env->GetJavaVM(&g_vm) && g_vm) - av_jni_set_java_vm(g_vm, nullptr); - init_methods_cache(env); -} - -jni_func(void, create, jobject appctx) { - prepare_environment(env, appctx); - - if (g_mpv) - die("mpv is already initialized"); - - g_mpv = mpv_create(); - if (!g_mpv) - die("context init failed"); - - mpv_request_log_messages(g_mpv, "v"); -} - -jni_func(void, init) { - if (!g_mpv) - die("mpv is not created"); - - if (mpv_initialize(g_mpv) < 0) - die("mpv init failed"); - - g_event_thread_request_exit = false; - pthread_create(&event_thread_id, nullptr, event_thread, nullptr); -} - -jni_func(void, destroy) { - if (!g_mpv) - die("mpv destroy called but it's already destroyed"); - - // poke event thread and wait for it to exit - g_event_thread_request_exit = true; - mpv_wakeup(g_mpv); - pthread_join(event_thread_id, nullptr); - - mpv_terminate_destroy(g_mpv); - g_mpv = nullptr; -} - -jni_func(void, command, jobjectArray jarray) { - const char *arguments[128] = { 0 }; - int len = env->GetArrayLength(jarray); - if (!g_mpv) - die("Cannot run command: mpv is not initialized"); - if (len >= ARRAYLEN(arguments)) - die("Cannot run command: too many arguments"); - - for (int i = 0; i < len; ++i) - arguments[i] = env->GetStringUTFChars((jstring)env->GetObjectArrayElement(jarray, i), nullptr); - - mpv_command(g_mpv, arguments); - - for (int i = 0; i < len; ++i) - env->ReleaseStringUTFChars((jstring)env->GetObjectArrayElement(jarray, i), arguments[i]); -} diff --git a/libmpv/src/main/cpp/property.cpp b/libmpv/src/main/cpp/property.cpp deleted file mode 100644 index 5d52c04..0000000 --- a/libmpv/src/main/cpp/property.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include - -#include - -#include "jni_utils.h" -#include "log.h" -#include "globals.h" - -extern "C" { - jni_func(jint, setOptionString, jstring option, jstring value); - - jni_func(jobject, getPropertyInt, jstring property); - jni_func(void, setPropertyInt, jstring property, jobject value); - jni_func(jobject, getPropertyDouble, jstring property); - jni_func(void, setPropertyDouble, jstring property, jobject value); - jni_func(jobject, getPropertyBoolean, jstring property); - jni_func(void, setPropertyBoolean, jstring property, jobject value); - jni_func(jstring, getPropertyString, jstring jproperty); - jni_func(void, setPropertyString, jstring jproperty, jstring jvalue); - - jni_func(void, observeProperty, jstring property, jint format); -} - -jni_func(jint, setOptionString, jstring joption, jstring jvalue) { - if (!g_mpv) - die("mpv is not initialized"); - - const char *option = env->GetStringUTFChars(joption, nullptr); - const char *value = env->GetStringUTFChars(jvalue, nullptr); - - int result = mpv_set_option_string(g_mpv, option, value); - - env->ReleaseStringUTFChars(joption, option); - env->ReleaseStringUTFChars(jvalue, value); - - return result; -} - -static int common_get_property(JNIEnv *env, jstring jproperty, mpv_format format, void *output) { - if (!g_mpv) - die("get_property called but mpv is not initialized"); - - const char *prop = env->GetStringUTFChars(jproperty, nullptr); - int result = mpv_get_property(g_mpv, prop, format, output); - if (result < 0) - ALOGE("mpv_get_property(%s) format %d returned error %s", prop, format, mpv_error_string(result)); - env->ReleaseStringUTFChars(jproperty, prop); - - return result; -} - -static int common_set_property(JNIEnv *env, jstring jproperty, mpv_format format, void *value) { - if (!g_mpv) - die("set_property called but mpv is not initialized"); - - const char *prop = env->GetStringUTFChars(jproperty, nullptr); - int result = mpv_set_property(g_mpv, prop, format, value); - if (result < 0) - ALOGE("mpv_set_property(%s, %p) format %d returned error %s", prop, value, format, mpv_error_string(result)); - env->ReleaseStringUTFChars(jproperty, prop); - - return result; -} - -jni_func(jobject, getPropertyInt, jstring jproperty) { - int64_t value = 0; - if (common_get_property(env, jproperty, MPV_FORMAT_INT64, &value) < 0) - return nullptr; - return env->NewObject(java_Integer, java_Integer_init, (jint)value); -} - -jni_func(jobject, getPropertyDouble, jstring jproperty) { - double value = 0; - if (common_get_property(env, jproperty, MPV_FORMAT_DOUBLE, &value) < 0) - return nullptr; - return env->NewObject(java_Double, java_Double_init, (jdouble)value); -} - -jni_func(jobject, getPropertyBoolean, jstring jproperty) { - int value = 0; - if (common_get_property(env, jproperty, MPV_FORMAT_FLAG, &value) < 0) - return nullptr; - return env->NewObject(java_Boolean, java_Boolean_init, (jboolean)value); -} - -jni_func(jstring, getPropertyString, jstring jproperty) { - char *value; - if (common_get_property(env, jproperty, MPV_FORMAT_STRING, &value) < 0) - return nullptr; - jstring jvalue = env->NewStringUTF(value); - mpv_free(value); - return jvalue; -} - -jni_func(void, setPropertyInt, jstring jproperty, jobject jvalue) { - int64_t value = env->CallIntMethod(jvalue, java_Integer_intValue); - common_set_property(env, jproperty, MPV_FORMAT_INT64, &value); -} - -jni_func(void, setPropertyDouble, jstring jproperty, jobject jvalue) { - double value = env->CallDoubleMethod(jvalue, java_Double_doubleValue); - common_set_property(env, jproperty, MPV_FORMAT_DOUBLE, &value); -} - -jni_func(void, setPropertyBoolean, jstring jproperty, jobject jvalue) { - int value = env->CallBooleanMethod(jvalue, java_Boolean_booleanValue); - common_set_property(env, jproperty, MPV_FORMAT_FLAG, &value); -} - -jni_func(void, setPropertyString, jstring jproperty, jstring jvalue) { - const char *value = env->GetStringUTFChars(jvalue, nullptr); - common_set_property(env, jproperty, MPV_FORMAT_STRING, &value); - env->ReleaseStringUTFChars(jvalue, value); -} - -jni_func(void, observeProperty, jstring property, jint format) { - if (!g_mpv) - die("mpv is not initialized"); - const char *prop = env->GetStringUTFChars(property, nullptr); - mpv_observe_property(g_mpv, 0, prop, (mpv_format)format); - env->ReleaseStringUTFChars(property, prop); -} diff --git a/libmpv/src/main/cpp/render.cpp b/libmpv/src/main/cpp/render.cpp deleted file mode 100644 index 061df84..0000000 --- a/libmpv/src/main/cpp/render.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#include - -#include "jni_utils.h" -#include "globals.h" - -extern "C" { - jni_func(void, attachSurface, jobject surface_); - jni_func(void, detachSurface); -}; - -static jobject surface; - -jni_func(void, attachSurface, jobject surface_) { - surface = env->NewGlobalRef(surface_); - int64_t wid = (int64_t)(intptr_t) surface; - mpv_set_option(g_mpv, "wid", MPV_FORMAT_INT64, (void*) &wid); -} - -jni_func(void, detachSurface) { - int64_t wid = 0; - mpv_set_option(g_mpv, "wid", MPV_FORMAT_INT64, (void*) &wid); - - env->DeleteGlobalRef(surface); - surface = nullptr; -} diff --git a/libmpv/src/main/java/dev/jdtech/mpv/MPVLib.java b/libmpv/src/main/java/dev/jdtech/mpv/MPVLib.java deleted file mode 100644 index fb91913..0000000 --- a/libmpv/src/main/java/dev/jdtech/mpv/MPVLib.java +++ /dev/null @@ -1,241 +0,0 @@ -package dev.jdtech.mpv; - -// Wrapper for native library - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.ArrayList; -import java.util.List; - -import android.content.Context; -import android.view.Surface; - -import androidx.annotation.IntDef; -import androidx.annotation.NonNull; - -@SuppressWarnings("unused") -public class MPVLib { - - static { - String[] libs = {"mpv", "player"}; - for (String lib : libs) { - System.loadLibrary(lib); - } - } - - public static native void create(Context appctx); - - public static native void init(); - - public static native void destroy(); - - public static native void attachSurface(Surface surface); - - public static native void detachSurface(); - - public static native void command(@NonNull String[] cmd); - - public static native int setOptionString(@NonNull String name, @NonNull String value); - - public static native Integer getPropertyInt(@NonNull String property); - - public static native void setPropertyInt(@NonNull String property, @NonNull Integer value); - - public static native Double getPropertyDouble(@NonNull String property); - - public static native void setPropertyDouble(@NonNull String property, @NonNull Double value); - - public static native Boolean getPropertyBoolean(@NonNull String property); - - public static native void setPropertyBoolean(@NonNull String property, @NonNull Boolean value); - - public static native String getPropertyString(@NonNull String property); - - public static native void setPropertyString(@NonNull String property, @NonNull String value); - - public static native void observeProperty(@NonNull String property, @Format int format); - - private static final List observers = new ArrayList<>(); - - public static void addObserver(EventObserver o) { - synchronized (observers) { - observers.add(o); - } - } - - public static void removeObserver(EventObserver o) { - synchronized (observers) { - observers.remove(o); - } - } - - public static void eventProperty(String property, long value) { - synchronized (observers) { - for (EventObserver o : observers) - o.eventProperty(property, value); - } - } - - public static void eventProperty(String property, double value) { - synchronized (observers) { - for (EventObserver o : observers) - o.eventProperty(property, value); - } - } - - public static void eventProperty(String property, boolean value) { - synchronized (observers) { - for (EventObserver o : observers) - o.eventProperty(property, value); - } - } - - public static void eventProperty(String property, String value) { - synchronized (observers) { - for (EventObserver o : observers) - o.eventProperty(property, value); - } - } - - public static void eventProperty(String property) { - synchronized (observers) { - for (EventObserver o : observers) - o.eventProperty(property); - } - } - - public static void event(@Event int eventId) { - synchronized (observers) { - for (EventObserver o : observers) - o.event(eventId); - } - } - - private static final List log_observers = new ArrayList<>(); - - public static void addLogObserver(LogObserver o) { - synchronized (log_observers) { - log_observers.add(o); - } - } - - public static void removeLogObserver(LogObserver o) { - synchronized (log_observers) { - log_observers.remove(o); - } - } - - public static void logMessage(String prefix, @LogLevel int level, String text) { - synchronized (log_observers) { - for (LogObserver o : log_observers) - o.logMessage(prefix, level, text); - } - } - - public interface EventObserver { - void eventProperty(@NonNull String property); - - void eventProperty(@NonNull String property, long value); - - void eventProperty(@NonNull String property, double value); - - void eventProperty(@NonNull String property, boolean value); - - void eventProperty(@NonNull String property, @NonNull String value); - - void event(@Event int eventId); - } - - public interface LogObserver { - void logMessage(@NonNull String prefix, @LogLevel int level, @NonNull String text); - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - MPV_FORMAT_NONE, - MPV_FORMAT_STRING, - MPV_FORMAT_OSD_STRING, - MPV_FORMAT_FLAG, - MPV_FORMAT_INT64, - MPV_FORMAT_DOUBLE, - MPV_FORMAT_NODE, - MPV_FORMAT_NODE_ARRAY, - MPV_FORMAT_NODE_MAP, - MPV_FORMAT_BYTE_ARRAY - }) - public @interface Format {} - - public static final int MPV_FORMAT_NONE = 0; - public static final int MPV_FORMAT_STRING = 1; - public static final int MPV_FORMAT_OSD_STRING = 2; - public static final int MPV_FORMAT_FLAG = 3; - public static final int MPV_FORMAT_INT64 = 4; - public static final int MPV_FORMAT_DOUBLE = 5; - public static final int MPV_FORMAT_NODE = 6; - public static final int MPV_FORMAT_NODE_ARRAY = 7; - public static final int MPV_FORMAT_NODE_MAP = 8; - public static final int MPV_FORMAT_BYTE_ARRAY = 9; - - - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - MPV_EVENT_NONE, - MPV_EVENT_SHUTDOWN, - MPV_EVENT_LOG_MESSAGE, - MPV_EVENT_GET_PROPERTY_REPLY, - MPV_EVENT_SET_PROPERTY_REPLY, - MPV_EVENT_COMMAND_REPLY, - MPV_EVENT_START_FILE, - MPV_EVENT_END_FILE, - MPV_EVENT_FILE_LOADED, - MPV_EVENT_CLIENT_MESSAGE, - MPV_EVENT_VIDEO_RECONFIG, - MPV_EVENT_AUDIO_RECONFIG, - MPV_EVENT_SEEK, - MPV_EVENT_PLAYBACK_RESTART, - MPV_EVENT_PROPERTY_CHANGE, - MPV_EVENT_QUEUE_OVERFLOW, - MPV_EVENT_HOOK - }) - public @interface Event {} - - public static final int MPV_EVENT_NONE = 0; - public static final int MPV_EVENT_SHUTDOWN = 1; - public static final int MPV_EVENT_LOG_MESSAGE = 2; - public static final int MPV_EVENT_GET_PROPERTY_REPLY = 3; - public static final int MPV_EVENT_SET_PROPERTY_REPLY = 4; - public static final int MPV_EVENT_COMMAND_REPLY = 5; - public static final int MPV_EVENT_START_FILE = 6; - public static final int MPV_EVENT_END_FILE = 7; - public static final int MPV_EVENT_FILE_LOADED = 8; - public static final int MPV_EVENT_CLIENT_MESSAGE = 16; - public static final int MPV_EVENT_VIDEO_RECONFIG = 17; - public static final int MPV_EVENT_AUDIO_RECONFIG = 18; - public static final int MPV_EVENT_SEEK = 20; - public static final int MPV_EVENT_PLAYBACK_RESTART = 21; - public static final int MPV_EVENT_PROPERTY_CHANGE = 22; - public static final int MPV_EVENT_QUEUE_OVERFLOW = 24; - public static final int MPV_EVENT_HOOK = 25; - - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - MPV_LOG_LEVEL_NONE, - MPV_LOG_LEVEL_FATAL, - MPV_LOG_LEVEL_ERROR, - MPV_LOG_LEVEL_WARN, - MPV_LOG_LEVEL_INFO, - MPV_LOG_LEVEL_V, - MPV_LOG_LEVEL_DEBUG, - MPV_LOG_LEVEL_TRACE - }) - public @interface LogLevel {} - - public static final int MPV_LOG_LEVEL_NONE = 0; - public static final int MPV_LOG_LEVEL_FATAL = 10; - public static final int MPV_LOG_LEVEL_ERROR = 20; - public static final int MPV_LOG_LEVEL_WARN = 30; - public static final int MPV_LOG_LEVEL_INFO = 40; - public static final int MPV_LOG_LEVEL_V = 50; - public static final int MPV_LOG_LEVEL_DEBUG = 60; - public static final int MPV_LOG_LEVEL_TRACE = 70; -}