概述
metaRTC新版本优化了安卓系统支持,demo将C和C++生成lib库,在lib库上提供了纯Java的webRTC推拉流demo。
demo支持软硬编解码,软编码为openh264,软解码为yangh264decoder,gpu编解码为mediacodec。
metaRTC android版本音视频的采集/编码/解码/opengl渲染/AEC等均在C++中实现,即使低配硬件也可以实现高效的webRTC推拉流和互动。
下载源码
Release metartc6.086 with 3rdparty and runtime · metartc/metaRTC · GitHubA cross-platform WebRTC SDK. Contribute to metartc/metaRTC development by creating an account on GitHub.https://github.com/metartc/metaRTC/releases/tag/6.0.086
https://gitee.com/metartc/metaRTC/releases/tag/6.0.086https://gitee.com/metartc/metaRTC/releases/tag/6.0.086
推拉流demo编译
android studio打开工程demo/metapushstream6_android和demo/metaplayer6_android
库文件放置于app/libs下libmetapush.aar/libmetaplayer.aar
build.grade配置
调用lib api代码
//推流
if(m_push==null) m_push=new YangPush(YangPush.Camera_Front,YangPush.Encoder_cpu,YangPush.MediaServer_srs);
//拉流
if(m_player==null) m_player=new YangPlayer(YangPlayer.Decoder_cpu,YangPlayer.MediaServer_srs);
//api参数
public static final int Decoder_cpu=1;
public static final int Decoder_gpu=0;
public static final int Encoder_cpu=1;
public static final int Encoder_gpu=0;
public static final int Camera_Back=1;
public static final int Camera_Front=0;
public static final int MediaServer_srs=0;
public static final int MediaServer_zlm=1;
lib库编译
运行脚本cmake_lib_android.sh
#cmake_lib_android.sh 脚本
cd libmetartccore6
./cmake_android.sh
cd ../libmetartc6
./cmake_android.sh
cd ../demo/libmetaApp
./cmake_android.sh
生成libmetartccore6.a/libmetartc6.a/libmetaApp.a于目录bin/lib_android
android studio打开工程demo/libmetapush_android和demo/libyangplayer_android
编译可选择ssl库
编译生成 libmetapush.aar/libmetaplayer.aar
第三方库
在metartc6.086.7z压缩文件中,已经编译的第三方库二进制文件存放目录为thirdparty/lib/android
第三方库编译
openssl编译
export ANDROID_NDK=/ndkpath/ndk
export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
#android-arm64 android-armeabi android-x86_64
./Configure android-arm64 -D__ANDROID_API__=29
make
opus/libyuv/srtp编译
mkdir build
cd build
#ndk目录
export NDK_ROOT=/ndkpath/ndk
#arm64-v8a armeabi x86_64
cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_NDK=$NDK_ROOT -DCMAKE_SYSTEM_NAME=Android -DANDROID_PLATFORM=android-29 -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=arm64-v8a -DAndroid=ON -DANDROID_STL=c++_static -DCMAKE_CXX_STANDARD=11 -DANDROID_NATIVE_API_LEVEL=29 ..
make
libspeexdsp编译
cd metaspeexdsp
./cmake_android.sh
mbedtls编译
修改mbedtls/mbedtls_config.h(mbedtls3.0)和mbedtls/config.h(mbedtls2.0)参数
去掉#define MBEDTLS_SSL_DTLS_SRTP注释使其生效
#cmake_android.sh
NDK_ROOT=/ndkpath/ndk
rm -rf build
mkdir build
cd build
#arm64-v8a armeabi x86_64
ARCH=x86_64
API=25
cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_NDK=$NDK_ROOT -DCMAKE_SYSTEM_NAME=Android -DANDROID_PLATFORM=android-${API} -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=${ARCH} -DAndroid=ON -DANDROID_STL=c++_static -DCMAKE_CXX_STANDARD=11 -DANDROID_NATIVE_API_LEVEL=${API} ..
make
支持mbedtls的srtp编译
cmake文件CMakeLists.txt中修改为ON或者编译加参数使其支持mbedtls
set(MBEDTLS_INCLUDE_DIRS "/metartcpath/thirdparty/user_include/mbedtls3/")
set(Yang_3RD_DIR "/metartcpath/thirdparty/lib/android/arm64-v8a")
set(MBEDTLS_LIBRARY ${Yang_3RD_DIR}/libmbedtls.a)
set(MBEDX509_LIBRARY ${Yang_3RD_DIR}/libmbedx509.a)
set(MBEDCRYPTO_LIBRARY ${Yang_3RD_DIR}/libmbedcrypto.a)
运行cmake_android.sh脚本编译
NDK_ROOT=/ndkpath/ndk
rm -rf build
mkdir build
cd build
#arm64-v8a armeabi x86_64
ARCH=arm64-v8a
API=25
/usr/bin/cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_NDK=$NDK_ROOT -DCMAKE_SYSTEM_NAME=Android -DANDROID_PLATFORM=android-${API} -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=${ARCH} -DAndroid=ON -DANDROID_STL=c++_static -DCMAKE_CXX_STANDARD=11 -DANDROID_NATIVE_API_LEVEL=${API} ..
make