当前位置:网站首页>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);
边栏推荐
猜你喜欢

Severe tire damage: the first rock band in the world to broadcast live on the Internet

交流电和直流电的区别是什么?

?位置怎么写才能输出true

Learning Tai Chi Maker - mqtt Chapter II (VI) mqtt wills

PCR/qPCR研究:Lumiprobe丨dsGreen 用于实时 PCR

Play with double pointer

控制器的功能和工作原理

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

Cgo+gsoap+onvif learning summary: 8. Summary of arm platform cross compilation operation and common problems

基于微信小程序的婚纱影楼门户小程序
随机推荐
如何从零设计一款牛逼的高并发架构(建议收藏)
信息学奥赛一本通 1360:奇怪的电梯(lift)
Understanding the source of innovation II
Audio and video technology development weekly
Learning Tai Chi Maker - mqtt Chapter 2 (V) heartbeat mechanism
2022电力电缆判断题模拟考试平台操作
2022 low voltage electrician examination questions and answers
PCR/qPCR研究:Lumiprobe丨dsGreen 用于实时 PCR
QCOM LCD调试
Flexible IP network test tool -- x-launch
Sword finger offer 49 Ugly number (three finger needling technique)
BioVendor sRAGE蛋白解决方案
通过例子学习Rust
Sorting out some topics of modern exchange principle MOOC
Excel将一行的内容进行复制时,列与列之间是用制表符“\t”进行分隔的
Lumiprobe细胞成像分析:PKH26 细胞膜标记试剂盒
Opencv实现目标检测
LeetCode 88:合并两个有序数组
Light collector, Yunnan Baiyao!
2022 safety officer-b certificate examination question bank and answers