概述
metaRTC5.0版本 API进行了重构,本篇文章将介绍webrtc传输调用流程和例子。
metaRTC5.0版本提供了C++和纯C两种接口。
ICE设置
iceCandidateType参数可以在配置文件yang_config.ini中配置,也可以在程序中赋值。
iceCandidateType=0 //0:host 1:stun 2:turn
[rtc]
enableDatachannel=0
iceServerIP=10.42.0.1
iceUsingLocalIp=0
iceLocalIP=192.168.1.102
iceCandidateType=0 //0:hots 1:stun 2:turn
iceStunPort=3478
iceServerIP=10.42.0.171
iceUserName=metartc
icePassword=metartc
int32_t err = Yang_Ok;
char* localSdp=NULL;
char* remoteSdp=NULL;
yangbool enableWhipWhep = yangtrue;
YangRtcDirection direction = YangSendonly;//YangSendrecv,YangSendonly,YangRecvonly
YangPeerConnection *peer = (YangPeerConnection*)yang_calloc(sizeof(YangPeerConnection),1);
yang_create_peerConnection(peer);
peer->addAudioTrack(&peer->peer,Yang_AED_OPUS);
peer->addVideoTrack(&peer->peer,Yang_VED_H264);
peer->addTransceiver(&peer->peer,direction);
//sfu server
if(enableWhipWhep)
err = peer->connectWhipWhepServer(&peer->peer,url);
else
err = peer->connectSfuServer(&peer->peer);
//p2p
peer->createDataChannel(&peer->peer);//add datachannel
if((err=peer->createOffer(&peer->peer, &localSdp))!=Yang_Ok){
yang_error("createOffer fail!");
goto cleanup;
}
if((err=peer->setLocalDescription(&peer->peer, localSdp))!=Yang_Ok){
yang_error("setLocalDescription fail!");
goto cleanup;
}
......
//get remote peer sdp
if((err=peer->setRemoteDescription(&peer->peer,remoteSdp))!=Yang_Ok){
yang_error("setRemoteDescription fail!");
goto cleanup;
}
//deviser
//根据官网的sample写的demo如下,但它是建立在我们本身就有音视频的编码和采集模块,只作传输时使用。
YangContext* m_context=new YangContext();
m_context->init();
int32_t err = Yang_Ok;
yangbool enableWhipWhep = yangtrue;
YangRtcDirection direction = YangSendrecv;//YangSendrecv,YangSendonly,YangRecvonly
YangPeerConnection * peer = NULL;
peer = (YangPeerConnection*)yang_calloc(sizeof(YangPeerConnection),1);
//将参数传入
memcpy(&peer->peer.streamconfig.rtcCallback,&m_context->rtcCallback,sizeof(YangRtcCallback));
peer->peer.avinfo=&m_context->avinfo;
strcpy(peer->peer.avinfo->rtc.iceLocalIP, "192.168.100.240");
strcpy(peer->peer.avinfo->rtc.rtcServerIP, "192.168.100.240");
yang_create_peerConnection(peer);
peer->init(&peer->peer);
peer->addAudioTrack(&peer->peer, Yang_AED_OPUS);
peer->addVideoTrack(&peer->peer, Yang_VED_H264);
peer->addTransceiver(&peer->peer, YangRtcDirection::YangSendonly);
// err = peer->connectSfuServer(&peer->peer);
char *localSdp = (char *)calloc(12 * 1000, 1);
peer->createOffer(&peer->peer, &localSdp);
cout << "localSdp : " << localSdp << endl;
peer->connectWhipWhepServer(&peer->peer,"http://192.168.100.240:1985/rtc/v1/whip/?app=live&stream=livestream");
while (1)
{
sleep(9);
}
return 0;
//以上是伪代码
//deviser
libmetartccore2工程为C版webrtc实现
libmetartc2为C++版采集编解码等实现
纯C接口(pure C API)YangPeerConnection
头文件:include/yangrtc/YangPeerConnection.h
C++接口(C++ API)YangPeerConnection2
头文件:include/yangrtc/YangPeerConnection2.h
MetaRTC5.0 API
Sample
MetaRTC7 API
7的Sample在首页
MetaRTC 连接信息回调函数
瑞芯微IPC
讲解meta rtc push stream开源项目之一
gb2312
瑞芯微3588 V:接口采集 A:alsa
博通 V:v4l2 A:alsa
采集是v4l2,编码调用接口
支持:GB2811
1.浏览metartc官网WIKI,确认是否支持32位
2.配置metartc7/5环境,编译metapush7和metaplay7,并测试推拉流
3.编译demo调用metartc7 api,排查错误
4.看metartcplay7的代码结构,数据传递等
下方是笔者微信,备注webrtc爱好者