diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d0d0c0..f2dc859 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,7 +72,7 @@ jobs: id: native-prefix-cache uses: actions/cache/restore@v4 with: - path: gh-cache/ + path: buildscripts/prefix/ key: native-prefix-${{ runner.os }}-${{ env.CACHE_IDENTIFIER }} restore-keys: | native-prefix-${{ runner.os }}- @@ -95,9 +95,11 @@ jobs: automake \ build-essential \ ccache \ + dos2unix \ gcc g++ \ cmake \ gettext \ + glslang-tools \ gperf \ libtool \ nasm \ @@ -105,6 +107,7 @@ jobs: pkg-config \ python3 \ python3-pip \ + spirv-tools \ unzip \ wget @@ -118,6 +121,15 @@ jobs: set -euxo pipefail cd buildscripts ./download.sh + + echo "Downloading latest Vulkan-Headers..." + if [ ! -d "deps/Vulkan-Headers" ]; then + git clone https://github.com/KhronosGroup/Vulkan-Headers.git deps/Vulkan-Headers + fi + + echo "Normalizing line endings for all scripts..." + cd .. + find . -type f \( -name '*.sh' -o -name 'gradlew' \) -exec dos2unix {} + - name: Save Android SDK cache if: steps.android-sdk-cache.outputs.cache-hit != 'true' @@ -130,7 +142,7 @@ jobs: if: steps.native-prefix-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 with: - path: gh-cache/ + path: buildscripts/prefix/ key: native-prefix-${{ runner.os }}-${{ env.CACHE_IDENTIFIER }} - name: Show ccache stats before build @@ -151,6 +163,10 @@ jobs: [ "$ENABLE_ARM_V9A" = "true" ] && arches+=(arm64-v9a) [ "$ENABLE_X86_ARCH" = "true" ] && arches+=(x86 x86_64) for arch in "${arches[@]}"; do + echo "Injecting Vulkan headers into prefix/$arch/include..." + mkdir -p "prefix/$arch/include" + cp -r deps/Vulkan-Headers/include/vulkan "prefix/$arch/include/" + cp -r deps/Vulkan-Headers/include/vk_video "prefix/$arch/include/" ./buildall.sh --arch "$arch" mpv done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dc4e608..87c0431 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -123,7 +123,7 @@ jobs: id: native-prefix-cache uses: actions/cache/restore@v4 with: - path: gh-cache/ + path: buildscripts/prefix/ key: native-prefix-${{ runner.os }}-${{ env.CACHE_IDENTIFIER }} restore-keys: | native-prefix-${{ runner.os }}- @@ -147,8 +147,10 @@ jobs: build-essential \ ccache \ cmake \ + dos2unix \ gcc g++ \ gettext \ + glslang-tools \ gperf \ libtool \ nasm \ @@ -156,6 +158,7 @@ jobs: pkg-config \ python3 \ python3-pip \ + spirv-tools \ unzip \ wget @@ -169,6 +172,15 @@ jobs: set -euxo pipefail cd buildscripts ./download.sh + + echo "Downloading latest Vulkan-Headers..." + if [ ! -d "deps/Vulkan-Headers" ]; then + git clone https://github.com/KhronosGroup/Vulkan-Headers.git deps/Vulkan-Headers + fi + + echo "Normalizing line endings for all scripts..." + cd .. + find . -type f \( -name '*.sh' -o -name 'gradlew' \) -exec dos2unix {} + - name: Save Android SDK cache if: steps.android-sdk-cache.outputs.cache-hit != 'true' @@ -181,7 +193,7 @@ jobs: if: steps.native-prefix-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 with: - path: gh-cache/ + path: buildscripts/prefix/ key: native-prefix-${{ runner.os }}-${{ env.CACHE_IDENTIFIER }} - name: Show ccache stats before build @@ -202,6 +214,10 @@ jobs: [ "$ENABLE_ARM_V9A" = "true" ] && arches+=(arm64-v9a) [ "$ENABLE_X86_ARCH" = "true" ] && arches+=(x86 x86_64) for arch in "${arches[@]}"; do + echo "Injecting Vulkan headers into prefix/$arch/include..." + mkdir -p "prefix/$arch/include" + cp -r deps/Vulkan-Headers/include/vulkan "prefix/$arch/include/" + cp -r deps/Vulkan-Headers/include/vk_video "prefix/$arch/include/" ./buildall.sh --arch "$arch" mpv done diff --git a/app/build.gradle b/app/build.gradle index 9c2f1fb..620de13 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { compileSdk 36 defaultConfig { - minSdkVersion 24 + minSdkVersion 33 targetSdkVersion 36 versionCode 38 @@ -22,6 +22,12 @@ android { buildConfig = true } + sourceSets { + main { + jniLibs.srcDirs = ['src/main/libs'] + } + } + // https://youtrack.jetbrains.com/issue/KT-55947 compileOptions { sourceCompatibility JavaVersion.VERSION_17 diff --git a/app/src/main/java/is/xyz/mpv/BaseMPVView.kt b/app/src/main/java/is/xyz/mpv/BaseMPVView.kt index 5eeb8be..7d7e088 100644 --- a/app/src/main/java/is/xyz/mpv/BaseMPVView.kt +++ b/app/src/main/java/is/xyz/mpv/BaseMPVView.kt @@ -36,6 +36,14 @@ abstract class BaseMPVView(context: Context, attrs: AttributeSet) : SurfaceView( } catch (e: Exception) { Log.e(TAG, "Failed to set SSL_CERT_FILE", e) } + + // Adreno-optimized Vulkan defaults for vo=gpu-next + MPVLib.setOptionString("gpu-api", "vulkan") + MPVLib.setOptionString("vulkan-async-compute", "no") + MPVLib.setOptionString("vulkan-async-transfer", "no") + MPVLib.setOptionString("vulkan-queue-count", "1") + MPVLib.setOptionString("vd-lavc-film-grain", "gpu") + initOptions() MPVLib.init() @@ -74,7 +82,7 @@ abstract class BaseMPVView(context: Context, attrs: AttributeSet) : SurfaceView( this.filePath = filePath } - private var voInUse: String = "gpu" + private var voInUse: String = "gpu-next" /** * Sets the VO to use. diff --git a/buildscripts/buildall.sh b/buildscripts/buildall.sh index c3c8ea0..cdc9abc 100755 --- a/buildscripts/buildall.sh +++ b/buildscripts/buildall.sh @@ -89,10 +89,15 @@ loadarch () { } setup_prefix () { - if [ ! -d "$prefix_dir" ]; then - mkdir -p "$prefix_dir" - # enforce flat structure (/usr/local -> /) + mkdir -p "$prefix_dir" + # enforce flat structure (/usr/local -> /) + # Always re-create: cache restore may replace symlinks with real directories + if [ ! -L "$prefix_dir/usr" ]; then + rm -rf "$prefix_dir/usr" ln -s . "$prefix_dir/usr" + fi + if [ ! -L "$prefix_dir/local" ]; then + rm -rf "$prefix_dir/local" ln -s . "$prefix_dir/local" fi diff --git a/buildscripts/include/depinfo.sh b/buildscripts/include/depinfo.sh index b749759..7e60fb7 100755 --- a/buildscripts/include/depinfo.sh +++ b/buildscripts/include/depinfo.sh @@ -26,6 +26,7 @@ v_vvdec=2.3.0 v_mpeghdec=1.0.2 v_libiamf=1.0.0 v_liblcevc=0.4.1 +v_dav1d=1.5.3 ## Dependency tree @@ -37,7 +38,7 @@ dep_vvdec=() dep_mpeghdec=() dep_libiamf=() dep_liblcevc=() -dep_ffmpeg=(mbedtls dav1d vvdec mpeghdec libiamf liblcevc) +dep_ffmpeg=(mbedtls dav1d vvdec mpeghdec libiamf liblcevc shaderc) dep_freetype2=() dep_fribidi=() dep_harfbuzz=() @@ -60,4 +61,4 @@ dep_mpv_android=(mpv python) v_ci_ffmpeg=n8.1.1 # filename used to uniquely identify a build prefix -ci_tarball="prefix-all-ndk-${v_ndk}-lua-${v_lua}-mujs-${v_mujs}-unibreak-${v_unibreak}-harfbuzz-${v_harfbuzz}-fribidi-${v_fribidi}-freetype-${v_freetype}-mbedtls-${v_mbedtls}-openssl-${v_openssl}-python-${v_python}-curl-${v_curl}-vvdec-${v_vvdec}-mpeghdec-${v_mpeghdec}-libiamf-${v_libiamf}-liblcevc-${v_liblcevc}-ffmpeg-${v_ci_ffmpeg}.tgz" +ci_tarball="prefix-all-ndk-${v_ndk}-lua-${v_lua}-mujs-${v_mujs}-unibreak-${v_unibreak}-harfbuzz-${v_harfbuzz}-fribidi-${v_fribidi}-freetype-${v_freetype}-mbedtls-${v_mbedtls}-openssl-${v_openssl}-python-${v_python}-curl-${v_curl}-vvdec-${v_vvdec}-mpeghdec-${v_mpeghdec}-libiamf-${v_libiamf}-liblcevc-${v_liblcevc}-dav1d-${v_dav1d}-ffmpeg-${v_ci_ffmpeg}.tgz" diff --git a/buildscripts/include/download-deps.sh b/buildscripts/include/download-deps.sh index aecfd31..cbf33d0 100755 --- a/buildscripts/include/download-deps.sh +++ b/buildscripts/include/download-deps.sh @@ -16,7 +16,7 @@ if [ ! -d mbedtls ]; then fi # dav1d (canonical repo, GitHub is read-only mirror) -[ ! -d dav1d ] && git clone https://github.com/videolan/dav1d +[ ! -d dav1d ] && git clone --depth 1 --branch $v_dav1d https://github.com/videolan/dav1d # vvdec — Fraunhofer VVC (H.266) decoder if [ ! -d vvdec ]; then diff --git a/buildscripts/scripts/dav1d.sh b/buildscripts/scripts/dav1d.sh index 8bf6584..f7eca7d 100755 --- a/buildscripts/scripts/dav1d.sh +++ b/buildscripts/scripts/dav1d.sh @@ -16,7 +16,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 -Dstack_alignment=16 \ -Denable_asm=true ninja -C $build -j$cores diff --git a/buildscripts/scripts/ffmpeg.sh b/buildscripts/scripts/ffmpeg.sh index 0342c36..e8bb0e9 100755 --- a/buildscripts/scripts/ffmpeg.sh +++ b/buildscripts/scripts/ffmpeg.sh @@ -36,10 +36,17 @@ args=( --target-os=android --enable-cross-compile --cross-prefix=$ndk_triple- --cc=$CC --pkg-config=pkg-config --nm=llvm-nm --arch=${ndk_triple%%-*} --cpu=$cpu - --extra-cflags="-I$prefix_dir/include $cpuflags" --extra-ldflags="-L$prefix_dir/lib" + --extra-cflags="-I$prefix_dir/include $cpuflags" --extra-ldflags="-L$prefix_dir/lib -lvulkan" --enable-{jni,mediacodec,mbedtls,libdav1d} + # === VULKAN SUPPORT & OPTIMIZATIONS === + --enable-vulkan + --enable-libshaderc + --enable-decoder=prores_vulkan,ffv1_vulkan,dpx_vulkan + --enable-encoder=ffv1_vulkan,prores_vulkan + --enable-filter=bwdif_vulkan,xfade_vulkan,hflip_vulkan,vflip_vulkan,scale_vulkan,overlay_vulkan,avgblur_vulkan,blend_vulkan,flip_vulkan,transpose_vulkan + # === NEW CODECS (FFmpeg n8.1.1) === # VVC (H.266) — Versatile Video Coding diff --git a/buildscripts/scripts/shaderc.sh b/buildscripts/scripts/shaderc.sh index d943f45..a128a41 100755 --- a/buildscripts/scripts/shaderc.sh +++ b/buildscripts/scripts/shaderc.sh @@ -39,11 +39,19 @@ cat >"$prefix_dir"/lib/pkgconfig/shaderc_combined.pc <<"END" Name: shaderc_combined Description: Version: 2022.3-unknown -Libs: -L/usr/local/lib -lshaderc_combined +Libs: -L/usr/local/lib -lshaderc_combined -lc++ -lm Cflags: -I/usr/local/include END -if [ -z "$(pkg-config --cflags shaderc_combined)" ]; then +cat >"$prefix_dir"/lib/pkgconfig/shaderc.pc <<"END" +Name: shaderc +Description: +Version: 2022.3-unknown +Libs: -L/usr/local/lib -lshaderc_combined -lc++ -lm +Cflags: -I/usr/local/include +END + +if [ -z "$(pkg-config --cflags shaderc_combined)" ] || [ -z "$(pkg-config --cflags shaderc)" ]; then echo >&2 "shaderc pkg-config sanity check failed" exit 1 fi diff --git a/wsl-compile.sh b/wsl-compile.sh new file mode 100644 index 0000000..372c179 --- /dev/null +++ b/wsl-compile.sh @@ -0,0 +1,59 @@ +#!/bin/bash +set -e + +# WSL Compilation Script for MPV Android AAR +# This script compiles the optimized Vulkan/Adreno AAR library from WSL Ubuntu. + +echo "==========================================================" +echo " Vulkan-Optimized MPV Android AAR Compiler for WSL" +echo "==========================================================" + +# 1. Sanity Checks +if ! grep -qis "microsoft" /proc/version && ! grep -qis "wsl" /proc/version; then + echo "Warning: This script is designed to run inside WSL (Windows Subsystem for Linux)." + echo "It seems you are running this elsewhere. Let's proceed, but make sure you are on Ubuntu/Debian." + read -p "Press Enter to continue..." +fi + +echo "Step 1: Installing Ubuntu dependencies (requires sudo)..." +sudo apt-get update +sudo apt-get install -y \ + autoconf \ + pkg-config \ + libtool \ + ninja-build \ + unzip \ + wget \ + meson \ + python3 \ + nasm \ + git \ + openjdk-17-jdk \ + clang \ + build-essential + +# 2. Check Java Version +if ! javac -version &>/dev/null; then + echo "Error: JDK 17 is required but could not be found. Please ensure openjdk-17-jdk is installed and configured." + exit 1 +fi + +echo "Step 2: Checking out/downloading Android SDK and NDK dependencies..." +cd buildscripts +./download.sh + +echo "Step 3: Compiling dependencies for standard arm64-v8a..." +./buildall.sh --arch arm64 + +echo "Step 4: Compiling dependencies for optimized arm64-v9a (Snapdragon 8s Gen 3 / Adreno 735)..." +./buildall.sh --arch arm64-v9a + +echo "Step 5: Building final JNI wrappers and packaging AAR..." +./buildall.sh mpv-android + +echo "==========================================================" +echo " Build Completed Successfully!" +echo "==========================================================" +echo "Your optimized AAR file is located at:" +ls -lh ../app/build/outputs/aar/*.aar +echo "==========================================================" diff --git a/wsl-source.tar b/wsl-source.tar new file mode 100644 index 0000000..ae8bc8f Binary files /dev/null and b/wsl-source.tar differ diff --git a/wsl_build.sh b/wsl_build.sh new file mode 100644 index 0000000..cbcbc01 --- /dev/null +++ b/wsl_build.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +# Fast rsync to avoid 9p filesystem overhead for excluded heavy folders +echo "Step 1: Synchronizing source code to WSL home directory..." +mkdir -p /home/sagnik/mpvlibAndroid +rsync -a --delete \ + --exclude='.git' \ + --exclude='build' \ + --exclude='.gradle' \ + --exclude='app/build' \ + --exclude='buildscripts/prefix' \ + --exclude='buildscripts/deps' \ + --exclude='buildscripts/sdk' \ + --exclude='buildscripts/_build*' \ + --exclude='wsl-source.tar' \ + /mnt/c/Users/sagni/StudioProjects/mpvlibAndroid/ /home/sagnik/mpvlibAndroid/ + +cd /home/sagnik/mpvlibAndroid + +echo "Step 2: Cleaning any leftover build files just in case..." +rm -rf buildscripts/prefix buildscripts/deps buildscripts/sdk buildscripts/_build* app/build + +echo "Step 3: Downloading SDK, NDK, and dependencies..." +cd buildscripts +echo 2007 | sudo -S ./download.sh +echo 2007 | sudo -S chown -R $USER:$USER /home/sagnik/mpvlibAndroid + +echo "Step 4: Building arm64-v8a (base) - CLEAN BUILD..." +./buildall.sh --clean --arch arm64 + +echo "Step 5: Building arm64-v9a (SVE2 optimized) - CLEAN BUILD..." +./buildall.sh --clean --arch arm64-v9a + +echo "Step 6: Packaging final mpv-android AAR..." +./buildall.sh mpv-android +cd .. + +echo "Step 7: Copying generated AARs back to Windows host..." +mkdir -p /mnt/c/Users/sagni/StudioProjects/mpvlibAndroid/app/build/outputs/aar/ +cp -r app/build/outputs/aar/* /mnt/c/Users/sagni/StudioProjects/mpvlibAndroid/app/build/outputs/aar/ + +echo "ALL DONE!" diff --git a/wsl_continue.sh b/wsl_continue.sh new file mode 100644 index 0000000..c5f02a5 --- /dev/null +++ b/wsl_continue.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +echo "Fixing permissions for downloaded deps..." +echo 2007 | sudo -S chown -R $USER:$USER /home/sagnik/mpvlibAndroid + +cd /home/sagnik/mpvlibAndroid/buildscripts + +echo "Step 4: Building arm64-v8a (base) - CLEAN BUILD..." +./buildall.sh --clean --arch arm64 + +echo "Step 5: Building arm64-v9a (SVE2 optimized) - CLEAN BUILD..." +./buildall.sh --clean --arch arm64-v9a + +echo "Step 6: Packaging final mpv-android AAR..." +./buildall.sh mpv-android +cd .. + +echo "Step 7: Copying generated AARs back to Windows host..." +mkdir -p /mnt/c/Users/sagni/StudioProjects/mpvlibAndroid/app/build/outputs/aar/ +cp -r app/build/outputs/aar/* /mnt/c/Users/sagni/StudioProjects/mpvlibAndroid/app/build/outputs/aar/ + +echo "ALL DONE!" diff --git a/wsl_final.sh b/wsl_final.sh new file mode 100644 index 0000000..492f625 --- /dev/null +++ b/wsl_final.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +cd /home/sagnik/mpvlibAndroid/buildscripts + +echo "Step 5: Building arm64-v9a (SVE2 optimized) - CLEAN BUILD..." +./buildall.sh --clean --arch arm64-v9a + +echo "Step 6: Packaging final mpv-android AAR..." +./buildall.sh mpv-android +cd .. + +echo "Step 7: Copying generated AARs back to Windows host..." +mkdir -p /mnt/c/Users/sagni/StudioProjects/mpvlibAndroid/app/build/outputs/aar/ +cp -r app/build/outputs/aar/* /mnt/c/Users/sagni/StudioProjects/mpvlibAndroid/app/build/outputs/aar/ + +echo "ALL DONE!" diff --git a/wsl_vulkan_headers.sh b/wsl_vulkan_headers.sh new file mode 100644 index 0000000..4301a58 --- /dev/null +++ b/wsl_vulkan_headers.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +echo "Downloading latest Vulkan-Headers..." +cd /home/sagnik/mpvlibAndroid/buildscripts/deps +if [ ! -d "Vulkan-Headers" ]; then + git clone https://github.com/KhronosGroup/Vulkan-Headers.git +else + cd Vulkan-Headers + git pull + cd .. +fi + +echo "Installing Vulkan headers to prefix directories..." +for arch in arm64 arm64-v9a; do + mkdir -p /home/sagnik/mpvlibAndroid/buildscripts/prefix/$arch/include/ + cp -r Vulkan-Headers/include/vulkan /home/sagnik/mpvlibAndroid/buildscripts/prefix/$arch/include/ + cp -r Vulkan-Headers/include/vk_video /home/sagnik/mpvlibAndroid/buildscripts/prefix/$arch/include/ +done + +echo "Headers installed successfully! Resuming build..." +cd /home/sagnik/mpvlibAndroid +bash wsl_continue.sh