-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement skeleton of native litr-muxers module (#239)
- Loading branch information
Showing
23 changed files
with
287 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/build | ||
|
||
# FFmpeg symlink | ||
src/main/cpp/ffmpeg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Litr Muxers module | ||
|
||
The Litr Muxers module provides `NativeMediaMuxerMediaTarget`, which uses FFmpeg for muxing | ||
individual streams into a target file container. | ||
|
||
## Build instructions (Linux, macOS) | ||
|
||
It is necessary to manually build the FFmpeg library, so that gradle can bundle the FFmpeg binaries | ||
in the APK: | ||
|
||
* Set the following shell variable: | ||
|
||
``` | ||
cd "<path to project checkout>" | ||
FFMPEG_MODULE_PATH="$(pwd)/litr-muxers/src/main" | ||
``` | ||
|
||
* Download the [Android NDK][] and set its location in a shell variable. | ||
This build configuration has been tested on NDK r22b. | ||
|
||
``` | ||
NDK_PATH="<path to Android NDK>" | ||
``` | ||
|
||
* Set the host platform (use "darwin-x86_64" for Mac OS X): | ||
|
||
``` | ||
HOST_PLATFORM="linux-x86_64" | ||
``` | ||
|
||
* Fetch FFmpeg and checkout an appropriate branch. We cannot guarantee | ||
compatibility with all versions of FFmpeg. We currently recommend version 4.2: | ||
|
||
``` | ||
cd "<preferred location for ffmpeg>" && \ | ||
git clone git://source.ffmpeg.org/ffmpeg && \ | ||
cd ffmpeg && \ | ||
git checkout release/4.2 && \ | ||
FFMPEG_PATH="$(pwd)" | ||
``` | ||
|
||
* Add a link to the FFmpeg source code in the FFmpeg module `cpp` directory. | ||
|
||
``` | ||
cd "${FFMPEG_MODULE_PATH}/cpp" && \ | ||
ln -s "$FFMPEG_PATH" ffmpeg | ||
``` | ||
|
||
* Execute `build_ffmpeg.sh` to build FFmpeg for `armeabi-v7a`, `arm64-v8a`, | ||
`x86` and `x86_64`. The script can be edited if you need to build for | ||
different architectures: | ||
|
||
``` | ||
cd "${FFMPEG_MODULE_PATH}/cpp" && \ | ||
chmod +x build_ffmpeg.sh && \ | ||
./build_ffmpeg.sh \ | ||
"${FFMPEG_MODULE_PATH}" "${NDK_PATH}" "${HOST_PLATFORM}" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.linkedin.android.litr.muxers' | ||
|
||
compileSdkVersion rootProject.ext.compileSdkVersion | ||
buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion rootProject.ext.minSdkVersion | ||
targetSdkVersion rootProject.ext.targetSdkVersion | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" | ||
} | ||
|
||
externalNativeBuild { | ||
cmake { | ||
path file('src/main/cpp/CMakeLists.txt') | ||
version '3.10.2' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':litr') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
# Enable C++11 features. | ||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
project(LiTrMuxers C CXX) | ||
|
||
# Additional flags needed for "arm64-v8a" from NDK 23.1.7779620 and above. | ||
if(${ANDROID_ABI} MATCHES "arm64-v8a") | ||
set(CMAKE_CXX_FLAGS "-Wl,-Bsymbolic") | ||
endif() | ||
|
||
# If locally built ffmpeg binaries are available, we will prioritise these. This is preferable as | ||
# ensures they are built to match exactly what the consumer requires. However, we will allow the | ||
# build to fallback to those bundled with the repository. | ||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg") | ||
set(ffmpeg_location "${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg") | ||
set(ffmpeg_binaries "${ffmpeg_location}/android-libs/${ANDROID_ABI}") | ||
else() | ||
set(ffmpeg_location "${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg_bundled") | ||
set(ffmpeg_binaries "${ffmpeg_location}/${ANDROID_ABI}") | ||
endif() | ||
|
||
foreach(ffmpeg_lib avutil avcodec avformat) | ||
set(ffmpeg_lib_filename lib${ffmpeg_lib}.so) | ||
set(ffmpeg_lib_file_path ${ffmpeg_binaries}/${ffmpeg_lib_filename}) | ||
add_library( | ||
${ffmpeg_lib} | ||
SHARED | ||
IMPORTED) | ||
set_target_properties( | ||
${ffmpeg_lib} PROPERTIES | ||
IMPORTED_LOCATION | ||
${ffmpeg_lib_file_path}) | ||
endforeach() | ||
|
||
include_directories(${ffmpeg_location}) | ||
find_library(log-lib log) | ||
|
||
add_library(litr-muxers SHARED | ||
FFmpeg.h | ||
Logging.h | ||
) | ||
|
||
target_link_libraries(litr-muxers | ||
PRIVATE android | ||
PRIVATE avcodec | ||
PRIVATE avutil | ||
PRIVATE avformat | ||
PRIVATE ${log-lib}) | ||
|
||
set_property(TARGET litr-muxers PROPERTY LINKER_LANGUAGE CXX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2022 LinkedIn Corporation | ||
* All Rights Reserved. | ||
* | ||
* Licensed under the BSD 2-Clause License (the "License"). See License in the project root for | ||
* license information. | ||
* | ||
* Author: Ian Bird | ||
*/ | ||
|
||
#ifndef LITR_FFMPEG_H | ||
#define LITR_FFMPEG_H | ||
|
||
extern "C" { | ||
#include "libavutil/log.h" | ||
#include "libavformat/avformat.h" | ||
} | ||
|
||
#endif //LITR_FFMPEG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2022 LinkedIn Corporation | ||
* All Rights Reserved. | ||
* | ||
* Licensed under the BSD 2-Clause License (the "License"). See License in the project root for | ||
* license information. | ||
* | ||
* Author: Ian Bird | ||
*/ | ||
|
||
#ifndef LITR_LOGGING_H | ||
#define LITR_LOGGING_H | ||
|
||
#include <android/log.h> | ||
|
||
#define LOG_TAG "LiTrMuxers_JNI" | ||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) | ||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) | ||
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) | ||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) | ||
|
||
#endif //LITR_LOGGING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/bash | ||
|
||
FFMPEG_MODULE_PATH=$1 | ||
NDK_PATH=$2 | ||
HOST_PLATFORM=$3 | ||
ENABLED_DECODERS=("${@:4}") | ||
JOBS=$(nproc 2> /dev/null || sysctl -n hw.ncpu 2> /dev/null || echo 4) | ||
echo "Using $JOBS jobs for make" | ||
COMMON_OPTIONS=" | ||
--target-os=android | ||
--enable-shared | ||
--disable-static | ||
--disable-doc | ||
--disable-all | ||
--enable-avcodec | ||
--enable-avformat | ||
--enable-protocol=file | ||
--enable-protocol=hls | ||
--enable-muxer=mp4 | ||
--enable-muxer=matroska | ||
--enable-muxer=hls | ||
--enable-muxer=stream_segment | ||
--enable-parser=aac | ||
--enable-parser=aac_latm | ||
--enable-parser=h264 | ||
--enable-parser=hevc | ||
--extra-ldexeflags=-pie | ||
" | ||
TOOLCHAIN_PREFIX="${NDK_PATH}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin" | ||
cd "${FFMPEG_MODULE_PATH}/cpp/ffmpeg" | ||
./configure \ | ||
--libdir=android-libs/armeabi-v7a \ | ||
--arch=arm \ | ||
--cpu=armv7-a \ | ||
--cross-prefix="${TOOLCHAIN_PREFIX}/armv7a-linux-androideabi16-" \ | ||
--nm="${TOOLCHAIN_PREFIX}/llvm-nm" \ | ||
--ar="${TOOLCHAIN_PREFIX}/llvm-ar" \ | ||
--ranlib="${TOOLCHAIN_PREFIX}/llvm-ranlib" \ | ||
--strip="${TOOLCHAIN_PREFIX}/llvm-strip" \ | ||
--extra-cflags="-march=armv7-a -mfloat-abi=softfp" \ | ||
--extra-ldflags="-Wl,--fix-cortex-a8" \ | ||
${COMMON_OPTIONS} | ||
make -j$JOBS | ||
make install-libs | ||
make clean | ||
./configure \ | ||
--libdir=android-libs/arm64-v8a \ | ||
--arch=aarch64 \ | ||
--cpu=armv8-a \ | ||
--cross-prefix="${TOOLCHAIN_PREFIX}/aarch64-linux-android21-" \ | ||
--nm="${TOOLCHAIN_PREFIX}/llvm-nm" \ | ||
--ar="${TOOLCHAIN_PREFIX}/llvm-ar" \ | ||
--ranlib="${TOOLCHAIN_PREFIX}/llvm-ranlib" \ | ||
--strip="${TOOLCHAIN_PREFIX}/llvm-strip" \ | ||
${COMMON_OPTIONS} | ||
make -j$JOBS | ||
make install-libs | ||
make clean | ||
./configure \ | ||
--libdir=android-libs/x86 \ | ||
--arch=x86 \ | ||
--cpu=i686 \ | ||
--cross-prefix="${TOOLCHAIN_PREFIX}/i686-linux-android16-" \ | ||
--nm="${TOOLCHAIN_PREFIX}/llvm-nm" \ | ||
--ar="${TOOLCHAIN_PREFIX}/llvm-ar" \ | ||
--ranlib="${TOOLCHAIN_PREFIX}/llvm-ranlib" \ | ||
--strip="${TOOLCHAIN_PREFIX}/llvm-strip" \ | ||
--disable-asm \ | ||
${COMMON_OPTIONS} | ||
make -j$JOBS | ||
make install-libs | ||
make clean | ||
./configure \ | ||
--libdir=android-libs/x86_64 \ | ||
--arch=x86_64 \ | ||
--cpu=x86_64 \ | ||
--cross-prefix="${TOOLCHAIN_PREFIX}/x86_64-linux-android21-" \ | ||
--nm="${TOOLCHAIN_PREFIX}/llvm-nm" \ | ||
--ar="${TOOLCHAIN_PREFIX}/llvm-ar" \ | ||
--ranlib="${TOOLCHAIN_PREFIX}/llvm-ranlib" \ | ||
--strip="${TOOLCHAIN_PREFIX}/llvm-strip" \ | ||
--disable-asm \ | ||
${COMMON_OPTIONS} | ||
make -j$JOBS | ||
make install-libs | ||
make clean |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':litr-demo', ':litr', ':litr-filters' | ||
include ':litr-demo', ':litr', ':litr-filters', ':litr-muxers' |