当前位置:网站首页>Metartc5.0 API programming guide (I)
Metartc5.0 API programming guide (I)
2022-06-28 05:01:00 【metaRTC】
summary
metaRTC5.0 edition API Refactored , This article will introduce webrtc Transfer call process and examples .
metaRTC5.0 Version provides C++ And pure C Two interfaces .
pure C Interface YangPeerConnection
The header file :include/yangrtc/YangPeerConnection.h
typedef struct{
void* conn;
YangAVInfo* avinfo;
YangStreamConfig streamconfig;
}YangPeer;
typedef struct {
YangPeer peer;
// initialization
void (*init)(YangPeer* peer);
// from stun The server obtains the Internet ip And port
int32_t (*requestStunServer)(YangPeer *peer);
// Generate local end sdp
int32_t (*createOffer)(YangPeer* peer, char **psdp);
// In exchange for sdp when , Get peer sdp after , Generate local sdp Back to the opposite end
int32_t (*createAnswer)(YangPeer* peer,char* answer);
//http Listening signaling after listening to the request , Generate http Of answer sdp
int32_t (*createHttpAnswer)(YangPeer* peer,char* answer);
// start-up metaRTC Start webrtc
int32_t (*setRemoteDescription)(YangPeer* peer,char* sdp);
// Encapsulates the srs/zlm Signaling exchange and start metaRTC
int32_t (*connectSfuServer)(YangPeer* peer);
// close metartc
int32_t (*close)(YangPeer* peer);
// Live connection
int32_t (*isAlive)(YangPeer* peer);
// Whether it is connected
int32_t (*isConnected)(YangPeer* peer);
// Push audio stream
int32_t (*on_audio)(YangPeer* peer,YangFrame* audioFrame);
// Push video stream
int32_t (*on_video)(YangPeer* peer,YangFrame* videoFrame);
// push datachannel news
int32_t (*on_message)(YangPeer* peer,YangFrame* msgFrame);
// send out rtc System message
int32_t (*sendRtcMessage)(YangPeer* peer, YangRtcMessageType mess);
}YangPeerConnection;
C++ Interface YangPeerConnection2
The header file :include/yangrtc/YangPeerConnection2.h
class YangPeerConnection2 {
public:
YangPeerConnection2(YangAVInfo* avinfo,YangStreamConfig* streamConfig);
virtual ~YangPeerConnection2();
YangStreamConfig* streamConfig;
public:
// initialization
void init();
// from stun The server obtains the Internet ip And port
int32_t requestStunServer();
// Generate local end sdp
int32_t createOffer( char **psdp);
// In exchange for sdp when , Get peer sdp after , Generate local sdp Back to the opposite end
int32_t createAnswer(char* answer);
//http Listening signaling after listening to the request , Generate http Of answer sdp
int32_t createHttpAnswer(char* answer);
// start-up metaRTC Start webrtc
int32_t setRemoteDescription(char* sdp);
// Encapsulates the srs/zlm Signaling exchange and start metaRTC
int32_t connectSfuServer();
// close metartc
int32_t close();
// Live connection
int32_t isAlive();
// Whether it is connected
int32_t isConnected();
// Push audio stream
int32_t on_audio(YangFrame* audioFrame);
// Push video stream
int32_t on_video(YangFrame* videoFrame);
// push datachannel news
int32_t on_message(YangFrame* msgFrame);
// send out rtc System message
int32_t sendRtcMessage( YangRtcMessageType mess);
private:
YangPeerConnection m_conn;
};Interface call process and examples
Configuration parameters
Parameter in YangStreamConfig and YangAVInfo Two struct in
libmetartc5/src/yangp2p/YangP2pRtc.cpp Code sample in
void g_p2p_rtcrecv_sendData(void* context,YangFrame* frame){
YangP2pRtc* rtcHandle=(YangP2pRtc*)context;
rtcHandle->publishMsg(frame);
}
void g_p2p_rtcrecv_sslAlert(void* context,int32_t uid,char* type,char* desc){
if(context==NULL||type==NULL||desc==NULL) return;
YangP2pRtc* rtc=(YangP2pRtc*)context;
if(strcmp(type,"warning")==0&&strcmp(desc,"CN")==0){
rtc->removePeer(uid);
}
}
void g_p2p_rtcrecv_receiveAudio(void* user,YangFrame *audioFrame){
if(user==NULL || audioFrame==NULL) return;
YangP2pRtc* rtcHandle=(YangP2pRtc*)user;
rtcHandle->receiveAudio(audioFrame);
}
void g_p2p_rtcrecv_receiveVideo(void* user,YangFrame *videoFrame){
if(user==NULL || videoFrame==NULL) return;
YangP2pRtc* rtcHandle=(YangP2pRtc*)user;
rtcHandle->receiveVideo(videoFrame);
}
void g_p2p_rtcrecv_receiveMsg(void* user,YangFrame *msgFrame){
if(user==NULL) return;
YangP2pRtc* rtcHandle=(YangP2pRtc*)user;
rtcHandle->receiveMsg(msgFrame);
}
int32_t YangP2pRtc::connectPeer(int32_t nettype, string server,int32_t localPort,int32_t pport,string app,string stream) {
int32_t ret = 0;
YangPeerConnection* sh=(YangPeerConnection*)calloc(sizeof(YangPeerConnection),1);
strcpy(sh->peer.streamconfig.app,app.c_str());
sh->peer.streamconfig.streamOptType=Yang_Stream_Both;
strcpy(sh->peer.streamconfig.remoteIp,server.c_str());
sh->peer.streamconfig.remotePort=pport;
m_clientUid=m_uidSeq++;
strcpy(sh->peer.streamconfig.stream,stream.c_str());
sh->peer.streamconfig.uid=m_clientUid;
sh->peer.streamconfig.isServer=0;
sh->peer.streamconfig.localPort=localPort;
sh->peer.streamconfig.recvCallback.context=this;
sh->peer.streamconfig.recvCallback.receiveAudio=g_p2p_rtcrecv_receiveAudio;
sh->peer.streamconfig.recvCallback.receiveVideo=g_p2p_rtcrecv_receiveVideo;
sh->peer.streamconfig.recvCallback.receiveMsg=g_p2p_rtcrecv_receiveMsg;
}pure C Interface call example
YangPeerConnection* sh=(YangPeerConnection*)calloc(sizeof(YangPeerConnection),1);
.... Configuration parameters ..
// Pass in parameters to YangPeerConnection memcpy(&sh->peer.streamconfig.rtcCallback,&m_context->rtcCallback,sizeof(YangRtcCallback));
sh->peer.avinfo=&m_context->avinfo;
//1. initialization
yang_create_peerConnection(sh);
sh->init(&sh->peer);
//2. Generate local end sdp,srs and zlm This step is not required for the call ,p2p need
char* localSdp;
char* remoteSdp=(char*)calloc(12*1000,1);
//stun request , Connect srs and zlm Unwanted
if(m_context->avinfo.rtc.hasIceServer){
if(sh->requestStunServer(&sh->peer)!=Yang_Ok) yang_error("request stun server fail!");
}
sh->createOffer(&sh->peer, &localSdp);
//3. Get the opposite end or sfu Server's sdp after , start-up metartc
// Point to point call
ret=sh->setRemoteDescription(&sh->peer,remoteSdp);
//srs/zlm call , It's sealed inside sdp Exchange and metartc start-up
ret=sh->connectSfuServer(&sh->peer)
//4. After executing the program , Destroy object
sh->close(&sh->peer);
yang_destroy_peerConnection(sh);
yang_free(sh);
C++ Interface call example
.... Parameter configuration ..
//1. initialization
YangPeerConnection2* sh=new YangPeerConnection2(&m_context->avinfo,&streamconfig);
sh->init();
//2. Generate local end sdp, Be careful :srs and zlm This step is not required for the call
char* localSdp;
char* remoteSdp=(char*)calloc(12*1000,1);
//stun request , Connect srs and zlm Unwanted
if(m_context->avinfo.rtc.hasIceServer){
if(sh->requestStunServer()!=Yang_Ok) yang_error("request stun server fail!");
}
sh->createOffer(&localSdp);
//3. Get the opposite end or sfu Server's sdp after , start-up metartc
//srs/zlm call
ret = sh->connectSfuServer();
//p2p call
ret=sh->setRemoteDescription(remoteSdp);
//4. After executing the program , Destroy object
sh->close();
yang_delete(sh);
边栏推荐
- It is the latest weapon to cross the blockade. It is one of the fastest ladders.
- 判断对象中是否存在某一个属性
- Assembly common instructions
- 氨基染料研究:Lumiprobe FAM 胺,6-异构体
- Feign通过自定义注解实现路径的转义
- Google Earth Engine(GEE)——全球洪水数据库 v1 (2000-2018年)
- JS 文本框失去焦点修改全半角文字和符号
- 羧酸研究:Lumiprobe 磺基花青7二羧酸
- Role of native keyword
- Feign remote call fallback callback failed, no effect
猜你喜欢
随机推荐
Performance optimization and implementation of video codec
2022年G3锅炉水处理复训题库模拟考试平台操作
The number of small stores in Suning has dropped sharply by 428 in one year. Zhangkangyang, the son of Zhang Jindong, is the actual controller
基于微信小程序的婚纱影楼门户小程序
Light collector, Yunnan Baiyao!
Opencv实现颜色检测
Meta universe standard forum established
Cgo+gsoap+onvif learning summary: 8. Summary of arm platform cross compilation operation and common problems
穿越封锁的最新利器,速度最快梯没有之一。
Understanding the source of innovation II
It is the latest weapon to cross the blockade. It is one of the fastest ladders.
Standard particle swarm optimization C language program
通过例子学习Rust
基于订单流工具,我们能看到什么?
项目经理考完PMP就够了?不是的!
机器人学DH参数及利用matlab符号运算推导
Operation of simulated examination platform of G3 boiler water treatment recurrent training question bank in 2022
Differences between pragma and ifndef
2022 low voltage electrician examination questions and answers
JS 文本框失去焦点修改全半角文字和符号









