1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 02:59:00 +03:00

short libvpx try

This commit is contained in:
Anton Afanasyeu
2026-05-18 14:25:02 +02:00
parent 9b1afec032
commit 7a07d6de1e
33 changed files with 1400 additions and 58 deletions

View File

@@ -1,32 +1,109 @@
#!/usr/bin/env bash
# Optional: build third-party codecs for Android and point Gradle/CMake at the outputs.
# Build libvpx for Android ABIs and produce libvpx.a for ANDROIDCAST_LIBVPX_LIB.
#
# Prerequisites:
# git submodule update --init --recursive third-party/libvpx third-party/opus third-party/speex
# Android NDK (same as used by the app, see local.properties or ndk.dir)
# git submodule update --init third-party/libvpx
# Android NDK (ndk.dir in local.properties)
#
# Usage:
# ./scripts/build-native-codecs.sh arm64-v8a
# ANDROIDCAST_LIBVPX_LIB=$PWD/build/native/arm64-v8a/libvpx.a ./gradlew assembleDebug
#
# Note: libvpx Makefiles do not support spaces in paths (SRC_PATH_BARE). If the repo
# path contains spaces, this script builds under /tmp and copies libvpx.a back.
#
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ABI="${1:-arm64-v8a}"
OUT="$ROOT/build/native/$ABI"
mkdir -p "$OUT"
VPX_SRC_REAL="$ROOT/third-party/libvpx"
PROJECT_OUT="$ROOT/build/native/$ABI"
OUT="$PROJECT_OUT"
BUILD_DIR="$OUT/libvpx-build"
echo "Native codec build scaffold — ABI=$ABI"
echo "Output directory: $OUT"
echo ""
echo "libvpx Android cross-compile is project-specific. After you produce libvpx.a, rebuild with:"
echo " export ANDROIDCAST_LIBVPX_LIB=$OUT/libvpx.a"
echo " ./gradlew assembleDebug"
echo ""
if [[ ! -d "$ROOT/third-party/libvpx" ]]; then
echo "WARN: third-party/libvpx missing. Run: git submodule update --init third-party/libvpx"
if [[ ! -d "$VPX_SRC_REAL" ]]; then
echo "ERROR: $VPX_SRC_REAL missing. Run:"
echo " git submodule update --init third-party/libvpx"
exit 1
fi
echo "libvpx sources present at third-party/libvpx — add your configure/make steps here."
touch "$OUT/.placeholder"
echo "Done (placeholder). See ndk/README.md for integration notes."
NDK=""
if [[ -f "$ROOT/local.properties" ]]; then
NDK="$(sed -n 's/^ndk\.dir=//p' "$ROOT/local.properties" | tr -d '\r' | head -1)"
fi
if [[ -z "$NDK" && -n "${ANDROID_NDK_HOME:-}" ]]; then
NDK="$ANDROID_NDK_HOME"
fi
if [[ -z "$NDK" && -n "${ANDROID_NDK_ROOT:-}" ]]; then
NDK="$ANDROID_NDK_ROOT"
fi
if [[ -z "$NDK" || ! -d "$NDK" ]]; then
echo "ERROR: Set ndk.dir in local.properties or ANDROID_NDK_HOME"
exit 1
fi
case "$ABI" in
arm64-v8a) VPX_TARGET=arm64-android-gcc ;;
armeabi-v7a) VPX_TARGET=armv7-android-gcc ;;
x86_64) VPX_TARGET=x86_64-android-gcc ;;
x86) VPX_TARGET=x86-android-gcc ;;
*)
echo "Unsupported ABI: $ABI"
exit 1
;;
esac
# libvpx: include $(SRC_PATH_BARE)/foo.mk breaks when SRC_PATH_BARE has spaces.
path_has_space() {
case "$1" in
*" "*) return 0 ;;
*) return 1 ;;
esac
}
VPX_SRC="$VPX_SRC_REAL"
STAGING=""
if path_has_space "$ROOT" || path_has_space "$VPX_SRC_REAL"; then
STAGING="/tmp/androidcast-libvpx-${USER:-build}"
VPX_SRC="$STAGING/src"
BUILD_DIR="$STAGING/build/$ABI"
OUT="$STAGING/out/$ABI"
mkdir -p "$STAGING/build" "$STAGING/out"
ln -sfn "$VPX_SRC_REAL" "$VPX_SRC"
echo "Repo path contains spaces; using space-free staging under $STAGING"
fi
mkdir -p "$BUILD_DIR" "$OUT" "$PROJECT_OUT"
export ANDROID_NDK_ROOT="$NDK"
export PATH="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
echo "Building libvpx for $ABI (target=$VPX_TARGET) ..."
echo " source: $VPX_SRC"
echo " build: $BUILD_DIR"
cd "$BUILD_DIR"
if [[ ! -f Makefile ]]; then
"$VPX_SRC/configure" \
--target="$VPX_TARGET" \
--disable-examples \
--disable-tools \
--disable-unit-tests \
--disable-webm-io \
--enable-vp8 \
--enable-vp9 \
--enable-static \
--disable-shared \
--extra-cflags="-fPIC -O2"
fi
make -j"$(nproc)" libvpx.a
cp -f libvpx.a "$OUT/libvpx.a"
cp -f "$OUT/libvpx.a" "$PROJECT_OUT/libvpx.a"
echo ""
echo "Built: $PROJECT_OUT/libvpx.a"
if [[ -n "$STAGING" ]]; then
echo "(staged under $STAGING because of spaces in repo path)"
fi
echo "Rebuild APK with:"
echo " export ANDROIDCAST_LIBVPX_LIB=$PROJECT_OUT/libvpx.a"
echo " ./gradlew assembleDebug"