当前位置:网站首页>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);
边栏推荐
- Light collector, Yunnan Baiyao!
- Idle interrupt cannot be cleared
- Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
- LeetCode 88:合并两个有序数组
- 2022 safety officer-b certificate examination question bank and answers
- 摄像头基础知识
- [csp-j2020] excellent splitting
- PCR/qPCR研究:Lumiprobe丨dsGreen 用于实时 PCR
- Flexible IP network test tool -- x-launch
- wordpress zibll子比主题6.4.1开心版 免授权
猜你喜欢

Feign通过自定义注解实现路径的转义

Leetcode 88: merge two ordered arrays

The latest examination questions and answers for the eight members (standard members) of Liaoning architecture in 2022

Distributed transaction - Final consistency scheme based on message compensation (local message table, message queue)

Performance optimization and implementation of video codec
![[csp-j2020] excellent splitting](/img/05/90f9cf71791b3cdc37073eaf5db989.png)
[csp-j2020] excellent splitting

店铺进销存管理系统源码

Multi thread implementation rewrites run (), how to inject and use mapper file to operate database

Analysis of distributed transaction solution Seata golang

Sword finger offer 47 Maximum gift value (DP)
随机推荐
Hundreds of lines of code to implement a script interpreter
Operation of simulated examination platform of G3 boiler water treatment recurrent training question bank in 2022
What to do when MySQL changes the password and reports an error
Distributed transaction - Final consistency scheme based on message compensation (local message table, message queue)
控制器的功能和工作原理
Necessary skills for test and development: actual combat of security test vulnerability shooting range
Audio and video technology development weekly
mysql----where 1=1是什么意思
metaRTC5.0编程之p2p网络穿透(stun)指南
2022年最新辽宁建筑八大员(标准员)考试试题及答案
店铺进销存管理系统源码
[NOIP2002 普及组] 过河卒
BioVendor sRAGE Elisa试剂盒化学性质和技术研究
Role of native keyword
通过例子学习Rust
二级造价工程师证书含金量到底有多高?看这些就知道了
UI automation test framework construction - write an app automation
2022年低压电工考题及答案
深度强化学习笔记
Generate QR code in wechat applet