Android metaRTC6.0 编译指南

概述

metaRTC新版本优化了安卓系统支持,demo将C和C++生成lib库,在lib库上提供了纯Java的webRTC推拉流demo。

demo支持软硬编解码,软编码为openh264,软解码为yangh264decoder,gpu编解码为mediacodec。

metaRTC android版本音视频的采集/编码/解码/opengl渲染/AEC等均在C++中实现,即使低配硬件也可以实现高效的webRTC推拉流和互动。

下载源码

Release Release v6.0-b2 · 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/v6.0-b2https://gitee.com/metartc/metaRTC/releases/tag/v6.0-b2https://gitee.com/metartc/metaRTC/releases/tag/v6.0-b2

Android metaRTC6.0 编译指南_第1张图片

推拉流demo编译

android studio打开工程demo/metapushstream6_android和demo/metaplayer6_android

库文件放置于app/libs下libmetapush.aar/libmetaplayer.aar

build.grade配置

Android metaRTC6.0 编译指南_第2张图片

调用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 metaRTC6.0 编译指南_第3张图片

android studio打开工程demo/libmetapush_android和demo/libyangplayer_android

编译可选择ssl库

编译生成 libmetapush.aar/libmetaplayer.aar

第三方库

在metartc6_b0.7z压缩文件中,已经编译的第三方库二进制文件存放目录为thirdparty/lib/android

Android metaRTC6.0 编译指南_第4张图片

第三方库编译

 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编译

#cmake_android.sh
rm -rf build
mkdir build
cd build
#ndk目录
export NDK_ROOT=/ndkpath/ndk
#arm64-v8a armeabi x86_64
ARCH=arm64-v8a
API= 29
/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

libspeexdsp编译

cd metaspeexdsp
./cmake_android.sh

openh264编译

#cmake_android.sh
#!/bin/sh
export ANDROID_NDK=/ndkpath/ndk
API=29

#aarch64 armv7a x86_64
PARCH=aarch64

PLATFORM_PREFIX="x86_64-linux-android-"

OPENH264_ARCH=x86_64
HOST=x86_64-linux-android

if [ "$PARCH" = "aarch64" ] ;then
    PLATFORM_PREFIX="aarch64-linux-android-"
    HOST=aarch64-linux-android
    OPENH264_ARCH=arm64
fi
if [ "$PARCH" = "armv7a" ];then
    PLATFORM_PREFIX="armv7a-linux-androideabi-" 
    HOST=arm-linux-androideabi 
    OPENH264_ARCH=arm
fi

SYSROOT=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64

export CC=$TOOLCHAIN/bin/${PARCH}-linux-android${API}-clang
export CXX=$TOOLCHAIN/bin/${PARCH}-linux-android${API}-clang++
export PATH=/home/yang/pro/android/android-sdk-linux/tools:$PATH
CROSS_PREFIX=$TOOLCHAIN/bin/${PLATFORM_PREFIX}


make OS=android NDKROOT=${ANDROID_NDK} TARGET=android-$API ARCH=$OPENH264_ARCH NDKLEVEL=$API CC=$TOOLCHAIN/bin/${PARCH}-linux-android${API}-clang CXX=$TOOLCHAIN/bin/${PARCH}-linux-android${API}-clang++ 

usrsctp编译

#cmake_android.sh
NDK_ROOT=/ndkpath/ndk
rm -rf build
mkdir build
cd build
#arm64-v8a armeabi x86_64
ARCH=arm64-v8a
API=29
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_NATIVE_API_LEVEL=${API} ..
make

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=29
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

Android metaRTC6.0 编译指南_第5张图片

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=29
/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

你可能感兴趣的:(metaRTC,android,webrtc)