Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install ninja-build meson nasm

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v3

Expand Down
114 changes: 113 additions & 1 deletion ffmpeg/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Versions
VPX_VERSION=1.13.0
MBEDTLS_VERSION=3.4.1
DAV1D_VERSION=1.4.1
FFMPEG_VERSION=6.0

# Directories
Expand All @@ -13,11 +14,12 @@ SOURCES_DIR=$BASE_DIR/sources
FFMPEG_DIR=$SOURCES_DIR/ffmpeg-$FFMPEG_VERSION
VPX_DIR=$SOURCES_DIR/libvpx-$VPX_VERSION
MBEDTLS_DIR=$SOURCES_DIR/mbedtls-$MBEDTLS_VERSION
DAV1D_DIR=$SOURCES_DIR/dav1d-$DAV1D_VERSION

# Configuration
ANDROID_ABIS="x86 x86_64 armeabi-v7a arm64-v8a"
ANDROID_PLATFORM=21
ENABLED_DECODERS="vorbis opus flac alac pcm_mulaw pcm_alaw mp3 amrnb amrwb aac ac3 eac3 dca mlp truehd h264 hevc mpeg2video mpegvideo libvpx_vp8 libvpx_vp9"
ENABLED_DECODERS="vorbis opus flac alac pcm_mulaw pcm_alaw mp3 amrnb amrwb aac ac3 eac3 dca mlp truehd h264 hevc mpeg2video mpegvideo libvpx_vp8 libvpx_vp9 libdav1d"
JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || sysctl -n hw.pysicalcpu || echo 4)

# Set up host platform variables
Expand All @@ -36,6 +38,18 @@ esac
# Build tools
TOOLCHAIN_PREFIX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${HOST_PLATFORM}"
CMAKE_EXECUTABLE=${ANDROID_SDK_HOME}/cmake/3.22.1/bin/cmake
# Using Build machine's Ninja. It is used for libdav1d building. Needs to be installed
NINJA_EXECUTABLE=$(which ninja)
# Meson is used for libdav1d building. Needs to be installed
MESON_EXECUTABLE=$(which meson)
# Nasm is used for libdav1d building. Needs to be installed
NASM_EXECUTABLE=$(which nasm)

export FAM_CC=${TOOLCHAIN_PREFIX}/bin/${TARGET}-clang
export FAM_CXX=${FAM_CC}++
export FAM_LD=${FAM_CC}# Forcing FFmpeg and its dependencies to look for dependencies
# in a specific directory when pkg-config is used
export PKG_CONFIG_LIBDIR=$BUILD_DIR/external/lib/pkgconfig

mkdir -p $SOURCES_DIR

Expand All @@ -61,6 +75,17 @@ function downloadMbedTLS() {
popd
}

function downloadDav1d() {
pushd $SOURCES_DIR
echo "Downloading Dav1d source code of version $DAV1D_VERSION..."
DAV1D_FILE=dav1d-$DAV1D_VERSION.tar.gz
curl -L "https://code.videolan.org/videolan/dav1d/-/archive/${DAV1D_VERSION}/dav1d-${DAV1D_VERSION}.tar.gz" -o $DAV1D_FILE
[ -e $DAV1D_FILE ] || { echo "$DAV1D_FILE does not exist. Exiting..."; exit 1; }
tar -zxf $DAV1D_FILE
rm $DAV1D_FILE
popd
}

function downloadFfmpeg() {
pushd $SOURCES_DIR
echo "Downloading FFmpeg source code of version $FFMPEG_VERSION..."
Expand Down Expand Up @@ -159,6 +184,82 @@ function buildMbedTLS() {
popd
}

function buildDav1d() {
pushd $DAV1D_DIR

for ABI in $ANDROID_ABIS; do
CPU_FAMILY=
case $ABI in
armeabi-v7a)
TARGET_TRIPLE_MACHINE_ARCH=arm
TOOLCHAIN=armv7a-linux-androideabi21-
;;
arm64-v8a)
TARGET_TRIPLE_MACHINE_ARCH=aarch64
TOOLCHAIN=aarch64-linux-android21-
;;
x86)
TARGET_TRIPLE_MACHINE_ARCH=i686
TOOLCHAIN=i686-linux-android21-
CPU_FAMILY=x86
;;
x86_64)
TARGET_TRIPLE_MACHINE_ARCH=x86_64
TOOLCHAIN=x86_64-linux-android21-
;;
esac

CROSS_PREFIX_WITH_PATH=${TOOLCHAIN_PREFIX}/bin/llvm-

[ -z "${CPU_FAMILY}" ] && CPU_FAMILY=${TARGET_TRIPLE_MACHINE_ARCH}

CROSS_FILE_NAME=crossfile-${ABI}.meson

echo "
[binaries]
c = '${TOOLCHAIN_PREFIX}/bin/${TOOLCHAIN}clang'
ar = '${CROSS_PREFIX_WITH_PATH}ar'
strip = '${CROSS_PREFIX_WITH_PATH}strip'
nasm = '${NASM_EXECUTABLE}'
pkg-config = '$(which pkg-config)'

[properties]
needs_exe_wrapper = true
sys_root = '${TOOLCHAIN_PREFIX}/sysroot'

[host_machine]
system = 'linux'
cpu_family = '${CPU_FAMILY}'
cpu = '${TARGET_TRIPLE_MACHINE_ARCH}'
endian = 'little'

[built-in options]
prefix = '$BUILD_DIR/external/$ABI'" > "${CROSS_FILE_NAME}"

BUILD_DIRECTORY=build/${ABI}

rm -rf ${BUILD_DIRECTORY}

${MESON_EXECUTABLE} setup . ${BUILD_DIRECTORY} \
--cross-file ${CROSS_FILE_NAME} \
--default-library=static \
-Denable_asm=true \
-Denable_tools=false \
-Denable_tests=false \
-Denable_examples=false \
-Dtestdata_tests=false

pushd ${BUILD_DIRECTORY}

${NINJA_EXECUTABLE} -j$JOBS
${NINJA_EXECUTABLE} install

popd

done
popd
}

function buildFfmpeg() {
pushd $FFMPEG_DIR
EXTRA_BUILD_CONFIGURATION_FLAGS=""
Expand Down Expand Up @@ -201,6 +302,10 @@ function buildFfmpeg() {
;;
esac

# Forcing FFmpeg and its dependencies to look for dependencies
# in a specific directory when pkg-config is used
export PKG_CONFIG_LIBDIR=$BUILD_DIR/external/$ABI/lib/pkgconfig

# Referencing dependencies without pkgconfig
DEP_CFLAGS="-I$BUILD_DIR/external/$ABI/include"
DEP_LD_FLAGS="-L$BUILD_DIR/external/$ABI/lib"
Expand Down Expand Up @@ -236,6 +341,7 @@ function buildFfmpeg() {
--enable-swresample \
--enable-avformat \
--enable-libvpx \
--enable-libdav1d \
--enable-protocol=file,http,https,mmsh,mmst,pipe,rtmp,rtmps,rtmpt,rtmpts,rtp,tls \
--enable-version3 \
--enable-mbedtls \
Expand Down Expand Up @@ -273,6 +379,11 @@ if [[ ! -d "$OUTPUT_DIR" && ! -d "$BUILD_DIR" ]]; then
downloadLibVpx
fi

# Download Dav1d source code if it doesn't exist
if [[ ! -d "$DAV1D_DIR" ]]; then
downloadDav1d
fi

# Download Ffmpeg source code if it doesn't exist
if [[ ! -d "$FFMPEG_DIR" ]]; then
downloadFfmpeg
Expand All @@ -281,5 +392,6 @@ if [[ ! -d "$OUTPUT_DIR" && ! -d "$BUILD_DIR" ]]; then
# Building library
buildMbedTLS
buildLibVpx
buildDav1d
buildFfmpeg
fi
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public static boolean supportsFormat(String mimeType) {
case MimeTypes.VIDEO_MPEG2 -> "mpeg2video";
case MimeTypes.VIDEO_VP8 -> "libvpx";
case MimeTypes.VIDEO_VP9 -> "libvpx-vp9";
case MimeTypes.VIDEO_AV1 -> "libdav1d";
default -> null;
};
}
Expand Down