Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add mbedtls to support http,tcp,rtmp etc #25

Merged
merged 7 commits into from
Sep 24, 2023
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
59 changes: 55 additions & 4 deletions ffmpeg/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Versions
VPX_VERSION=1.13.0
MBEDTLS_VERSION=3.4.1
FFMPEG_VERSION=6.0

# Directories
Expand All @@ -11,9 +12,11 @@ OUTPUT_DIR=$BASE_DIR/output
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

# 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"
JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || sysctl -n hw.pysicalcpu || echo 4)

Expand All @@ -30,24 +33,40 @@ msys)
;;
esac

# Build tools
TOOLCHAIN_PREFIX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${HOST_PLATFORM}"
CMAKE_EXECUTABLE=${ANDROID_SDK_HOME}/cmake/3.22.1/bin/cmake

mkdir -p $SOURCES_DIR

function downloadLibVpx() {
pushd $SOURCES_DIR
echo "Downloading Vpx source code of version $VPX_VERSION..."
VPX_FILE=libvpx-$VPX_VERSION.tar.gz
curl -L https://github.com/webmproject/libvpx/archive/refs/tags/v$VPX_VERSION.tar.gz -o $VPX_FILE
curl -L "https://github.com/webmproject/libvpx/archive/refs/tags/v${VPX_VERSION}.tar.gz" -o $VPX_FILE
[ -e $VPX_FILE ] || { echo "$VPX_FILE does not exist. Exiting..."; exit 1; }
tar -zxf $VPX_FILE
rm $VPX_FILE
popd
}

function downloadMbedTLS() {
pushd $SOURCES_DIR
echo "Downloading mbedtls source code of version $MBEDTLS_VERSION..."
MBEDTLS_FILE=mbedtls-$MBEDTLS_VERSION.tar.gz
curl -L "https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v${MBEDTLS_VERSION}.tar.gz" -o $MBEDTLS_FILE
[ -e $MBEDTLS_FILE ] || { echo "$MBEDTLS_FILE does not exist. Exiting..."; exit 1; }
tar -zxf $MBEDTLS_FILE
rm $MBEDTLS_FILE
popd
}

function downloadFfmpeg() {
pushd $SOURCES_DIR
echo "Downloading FFmpeg source code of version $FFMPEG_VERSION..."
FFMPEG_FILE=ffmpeg-$FFMPEG_VERSION.tar.gz
curl -L https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.gz -o $FFMPEG_FILE
curl -L "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz" -o $FFMPEG_FILE
[ -e $FFMPEG_FILE ] || { echo "$FFMPEG_FILE does not exist. Exiting..."; exit 1; }
tar -zxf $FFMPEG_FILE
rm $FFMPEG_FILE
popd
Expand Down Expand Up @@ -110,12 +129,36 @@ function buildLibVpx() {
${EXTRA_BUILD_FLAGS}

make clean
make -j"$JOBS"
make -j$JOBS
make install
done
popd
}

function buildMbedTLS() {
pushd $MBEDTLS_DIR

for ABI in $ANDROID_ABIS; do

CMAKE_BUILD_DIR=$MBEDTLS_DIR/mbedtls_build_${ABI}
rm -rf ${CMAKE_BUILD_DIR}
mkdir -p ${CMAKE_BUILD_DIR}
cd ${CMAKE_BUILD_DIR}

${CMAKE_EXECUTABLE} .. \
-DANDROID_PLATFORM=${ANDROID_PLATFORM} \
-DANDROID_ABI=$ABI \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=$BUILD_DIR/external/$ABI \
-DENABLE_TESTING=0

make -j$JOBS
make install

done
popd
}

function buildFfmpeg() {
pushd $FFMPEG_DIR
EXTRA_BUILD_CONFIGURATION_FLAGS=""
Expand Down Expand Up @@ -194,6 +237,8 @@ function buildFfmpeg() {
--enable-avformat \
--enable-libvpx \
--enable-protocol=file,http,https,mmsh,mmst,pipe,rtmp,rtmps,rtmpt,rtmpts,rtp,tls \
--enable-version3 \
--enable-mbedtls \
--extra-ldexeflags=-pie \
--disable-debug \
${EXTRA_BUILD_CONFIGURATION_FLAGS} \
Expand All @@ -202,7 +247,7 @@ function buildFfmpeg() {
# Build FFmpeg
echo "Building FFmpeg for $ARCH..."
make clean
make -j"$JOBS"
make -j$JOBS
make install

OUTPUT_LIB=${OUTPUT_DIR}/lib/${ABI}
Expand All @@ -218,6 +263,11 @@ function buildFfmpeg() {
}

if [[ ! -d "$OUTPUT_DIR" && ! -d "$BUILD_DIR" ]]; then
# Download MbedTLS source code if it doesn't exist
if [[ ! -d "$MBEDTLS_DIR" ]]; then
downloadMbedTLS
fi

# Download Vpx source code if it doesn't exist
if [[ ! -d "$VPX_DIR" ]]; then
downloadLibVpx
Expand All @@ -229,6 +279,7 @@ if [[ ! -d "$OUTPUT_DIR" && ! -d "$BUILD_DIR" ]]; then
fi

# Building library
buildMbedTLS
buildLibVpx
buildFfmpeg
fi
6 changes: 5 additions & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
jdk:
- openjdk17
- openjdk8
before_install:
- yes | sdkmanager "cmake;3.22.1"
- sdk install java 17.0.8-tem
- sdk use java 17.0.8-tem
1 change: 1 addition & 0 deletions media3ext/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ android {
val ffmpegSetup by tasks.registering(Exec::class) {
workingDir = file("../ffmpeg")
// export ndk path and run bash script
environment("ANDROID_SDK_HOME", android.sdkDirectory.absolutePath)
environment("ANDROID_NDK_HOME", android.ndkDirectory.absolutePath)
commandLine("bash", "setup.sh")
}
Expand Down
1 change: 1 addition & 0 deletions mediainfo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ android {
val ffmpegSetup by tasks.registering(Exec::class) {
workingDir = file("../ffmpeg")
// export ndk path and run bash script
environment("ANDROID_SDK_HOME", android.sdkDirectory.absolutePath)
environment("ANDROID_NDK_HOME", android.ndkDirectory.absolutePath)
commandLine("bash", "setup.sh")
}
Expand Down
Loading