-
Notifications
You must be signed in to change notification settings - Fork 227
metaRTC5.0 API
yangrtc edited this page Aug 31, 2022
·
10 revisions
metaRTC5.0版本 API进行了重构,本篇文章将介绍webrtc传输调用流程和例子。
metaRTC5.0版本提供了C++和纯C两种接口。
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
头文件:include/yangrtc/YangPeerConnection.h
typedef struct{
void* conn;
YangAVInfo* avinfo;
YangStreamConfig streamconfig;
}YangPeer;
typedef struct {
YangPeer peer;
//初始化
void (*init)(YangPeer* peer);
//生成本端sdp
int32_t (*createOffer)(YangPeer* peer, char **psdp);
//交换sdp时,获取对端sdp后,生成本地sdp以回传回对端
int32_t (*createAnswer)(YangPeer* peer,char* answer);
//http侦听信令侦听到请求后,生成http的answer sdp
int32_t (*createHttpAnswer)(YangPeer* peer,char* answer);
//启动metaRTC开始webrtc
int32_t (*setRemoteDescription)(YangPeer* peer,char* sdp);
//封装了srs/zlm的信令交换并启动metaRTC
int32_t (*connectSfuServer)(YangPeer* peer);
//关闭metartc
int32_t (*close)(YangPeer* peer);
//是否活连接
int32_t (*isAlive)(YangPeer* peer);
//是否已经连接
int32_t (*isConnected)(YangPeer* peer);
//推音频流
int32_t (*on_audio)(YangPeer* peer,YangFrame* audioFrame);
//推视频流
int32_t (*on_video)(YangPeer* peer,YangFrame* videoFrame);
//推送datachannel消息
int32_t (*on_message)(YangPeer* peer,YangFrame* msgFrame);
//发送rtc系统消息
int32_t (*sendRtcMessage)(YangPeer* peer, YangRtcMessageType mess);
}YangPeerConnection;
头文件:include/yangrtc/YangPeerConnection2.h
class YangPeerConnection2 {
public:
YangPeerConnection2(YangAVInfo* avinfo,YangStreamConfig* streamConfig);
virtual ~YangPeerConnection2();
YangStreamConfig* streamConfig;
public:
//初始化
void init();
//生成本端sdp
int32_t createOffer( char **psdp);
//交换sdp时,获取对端sdp后,生成本地sdp以回传回对端
int32_t createAnswer(char* answer);
//http侦听信令侦听到请求后,生成http的answer sdp
int32_t createHttpAnswer(char* answer);
//启动metaRTC开始webrtc
int32_t setRemoteDescription(char* sdp);
//封装了srs/zlm的信令交换并启动metaRTC
int32_t connectSfuServer();
//关闭metartc
int32_t close();
//是否活连接
int32_t isAlive();
//是否已经连接
int32_t isConnected();
//推音频流
int32_t on_audio(YangFrame* audioFrame);
//推视频流
int32_t on_video(YangFrame* videoFrame);
//推送datachannel消息
int32_t on_message(YangFrame* msgFrame);
//发送rtc系统消息
int32_t sendRtcMessage( YangRtcMessageType mess);
private:
YangPeerConnection m_conn;
};