当前位置:网站首页>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);
边栏推荐
- PMP考试成绩多久出来?这些你务必知道!
- lotus v1.16.0 calibnet
- 基于订单流工具,我们能看到什么?
- 如何学习可编程逻辑控制器(PLC)?
- Opencv实现目标检测
- Precautions for using C language global variables (global variables in C and H files, static global variables)
- Interview: what are the similarities and differences between abstract classes and interfaces?
- 2022电力电缆判断题模拟考试平台操作
- 羧酸研究:Lumiprobe 磺基花青7二羧酸
- 改性三磷酸盐研究:Lumiprobe氨基-11-ddUTP
猜你喜欢

Meta universe standard forum established

Feign remote call fallback callback failed, no effect

native关键字的作用

Dart学习——函数、类

?位置怎么写才能输出true

灵活的IP网络测试工具——— X-Launch

metaRTC5.0编程之p2p网络穿透(stun)指南

CUPTI error: CUPTI could not be loaded or symbol could not be found.

DH parameters of robotics and derivation using MATLAB symbolic operation

恭喜我自己,公众号粉丝破万
随机推荐
Hundreds of lines of code to implement a script interpreter
Audio and video technology development weekly
摄像头基础知识
It is the latest weapon to cross the blockade. It is one of the fastest ladders.
汇编常用指令
公司为什么选择云数据库?它的魅力到底是什么!
Feign implements path escape through custom annotations
Generate QR code in wechat applet
Extjs图书管理系统源码 智能化图书管理系统源码
BioVendor sRAGE蛋白解决方案
机器人学DH参数及利用matlab符号运算推导
IP数据报的发送和转发过程
Project practice! Teach you JMeter performance test hand in hand
BioVendor sRAGE Elisa试剂盒化学性质和技术研究
mysql----where 1=1是什么意思
109. simple chat room 12: realize client-side one-to-one chat
2022年低压电工考题及答案
Differences between pragma and ifndef
Analysis of distributed transaction TCC
控制器的功能和工作原理