当前位置:网站首页>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);
边栏推荐
- 2022年低压电工考题及答案
- Unity delegate
- Google Earth engine (GEE) - global flood database V1 (2000-2018)
- 玩转双指针
- Where does the storm go? Whose pot is the weather forecast wrong?
- 二级造价工程师证书含金量到底有多高?看这些就知道了
- Sword finger offer 49 Ugly number (three finger needling technique)
- 乔布斯在斯坦福大学的演讲稿——Follow your heart
- Analysis of distributed transaction TCC
- Code understanding: implementing volume models for hangwriten text recognition
猜你喜欢
活性染料研究:Lumiprobe AF594 NHS 酯,5-异构体
native关键字的作用
2022新版nft源码中国元宇宙数字藏品艺术品交易平台源码
Mask's miserable and inspirational childhood, who is introverted by campus violence
LeetCode 88:合并两个有序数组
如何学习可编程逻辑控制器(PLC)?
Necessary skills for test and development: actual combat of security test vulnerability shooting range
机器人学DH参数及利用matlab符号运算推导
Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
浅析搭建视频监控汇聚平台的必要性及场景应用
随机推荐
2022烟花爆竹经营单位安全管理人员特种作业证考试题库及模拟考试
机器人学DH参数及利用matlab符号运算推导
2022西式面点师(高级)考试试题模拟考试平台操作
109. 简易聊天室12:实现客户端一对一聊天
项目经理考完PMP就够了?不是的!
C语言全局变量(c文件和h文件中的全局变量、静态全局变量)使用注意事项
店铺进销存管理系统源码
2022新版nft源码中国元宇宙数字藏品艺术品交易平台源码
Redis 的 最新windows 版本 5.0.14
Organize the online cake mall project
Learn Taiji Maker - mqtt Chapter 2 (IV) esp8266 reserved message application
2022高处安装、维护、拆除考试题及答案
JS 文本框失去焦点修改全半角文字和符号
It is the latest weapon to cross the blockade. It is one of the fastest ladders.
乔布斯在斯坦福大学的演讲稿——Follow your heart
Blocking, non blocking, IO multiplexing select\poll\epoll
短视频本地生活版块成为热门,如何把握新的风口机遇?
gsap的简单用法
大促场景下,如何做好网关高可用防护
高通平台 Camera 之 MCLK 配置