-
Notifications
You must be signed in to change notification settings - Fork 271
metaRTC 7.0 API Programming Guide
yangrtc edited this page Dec 16, 2025
·
2 revisions
Starting with the new version released on June 16, 2025, metaRTC 7.0 features a completely new API. All versions of metaRTC 7.0 have unified the API and added libyangwhip7 to connect to signaling modules such as SFU/MCU.
The new API version separates signaling and integrates SFU/MCU connection code implementations such as whip/srs/zlm. Developers can extend the SFU/MCU connection code in the yangwhip7 module.
#include <yangrtc/YangWhip.h>
//url http://ip:port/whipurl
int32_t yang_whip_connectWhipWhepServer(YangPeer* peer,char* url);
//url webrtc://ip:port/app/stream
//mediaServer:Yang_Server_Srs/Yang_Server_Zlm
int32_t yang_whip_connectSfuServer(YangPeer* peer,char* url,int32_t mediaServer);`
#include <yangrtc/YangWhip.h>
#include <yangrtc/YangPeerInfo.h>
#include <yangrtc/YangPeerConnection.h>
int32_t localPort=16000;
YangAVInfo* avinfo;
YangPeerConnection* conn=(YangPeerConnection*)calloc(sizeof(YangPeerConnection),1);
//yang_init_peerInfo(&conn->peer.peerInfo);
yang_avinfo_initPeerInfo(&conn->peer.peerInfo,avinfo);
conn->peer.peerInfo.rtc.rtcLocalPort = localPort;
conn->peer.peerInfo.direction = YangRecvonly;
conn->peer.peerInfo.uid = puid;
conn->peer.peerCallback.recvCallback.context=this;
conn->peer.peerCallback.recvCallback.receiveAudio=g_rtcrecv_receiveAudio;
conn->peer.peerCallback.recvCallback.receiveVideo=g_rtcrecv_receiveVideo;
conn->peer.peerCallback.recvCallback.receiveMsg=g_rtcrecv_receiveMsg;
yang_create_peerConnection(conn);
conn->addAudioTrack(&conn->peer,Yang_AED_OPUS);
conn->addVideoTrack(&conn->peer,Yang_VED_H264);
conn->addTransceiver(&conn->peer,YangMediaAudio,YangRecvonly);
conn->addTransceiver(&conn->peer,YangMediaVideo,YangRecvonly);
//sfu
if(isWhip)
yang_whip_connectWhipWhepServer(&conn->peer,url);
else
yang_whip_connectSfuServer(&conn->peer,url,mediaServer);
//p2p
conn->createDataChannel(&conn->peer);
if((err=conn->createOffer(&conn->peer, &localSdp))!=Yang_Ok){
yang_error("createOffer fail",);
goto cleanup;
}
if((err=conn->setLocalDescription(&conn->peer, localSdp))!=Yang_Ok){
yang_error("setLocalDescription fail");
goto cleanup;
}
......
//get remote peer sdp
if((err=conn->setRemoteDescription(&conn->peer,remoteSdp))!=Yang_Ok){
yang_error("setRemoteDescription fail!");
goto cleanup;
}
#include <yangrtc/YangWhip.h>
#include <yangrtc/YangPeerInfo.h>
#include <yangrtc/YangPeerConnection7.h>
int32_t localPort=16000;
YangAVInfo* avinfo;
YangPeerInfo peerInfo;
//yang_init_peerInfo(&peerInfo);
yang_avinfo_initPeerInfo(&peerInfo,avinfo);
peerInfo.uid=0;
peerInfo.direction=YangSendonly;
peerInfo.rtc.rtcLocalPort = localPort;
//YangCallbackReceive* receive
//YangCallbackIce* ice
//YangCallbackRtc* rtc
//YangCallbackSslAlert* sslAlert);
YangPeerConnection7* conn=new YangPeerConnection7(&peerInfo,receive,ice, rtc,sslAlert);
conn->addAudioTrack(Yang_AED_OPUS);
conn->addVideoTrack(Yang_VED_H264);
conn->addTransceiver(YangMediaAudio,peerInfo.direction);
conn->addTransceiver(YangMediaVideo,peerInfo.direction);
//sfu
if(isWhip)
yang_whip_connectWhipWhepServer(&conn->m_peer,url);
else
yang_whip_connectSfuServer(&conn->m_peer,url,mediaServer);
//p2p
conn->createDataChannel();
if((err=conn->createOffer(&localSdp))!=Yang_Ok){
yang_error("createOffer fail",);
goto cleanup;
}
if((err=conn->setLocalDescription(localSdp))!=Yang_Ok){
yang_error("setLocalDescription fail");
goto cleanup;
}
......
//get remote peer sdp
if((err=conn->setRemoteDescription(remoteSdp))!=Yang_Ok){
yang_error("setRemoteDescription fail!");
goto cleanup;
}
return 0;
}
//YangFrame payload data nb: data length
//frametype: YANG_Frametype_I (I-frame) YANG_Frametype_P (P-frame or B-frame)
//I-frame: 4-byte SPS length + SPS + 4-byte PPS length + PPS + (00,00,00,01) + I-frame
//00,00,00,0e,67,42,c0,1f,8c,8d,40,50,1e,d0,0f,08,84,6a,00,00,00,04,68,ce,3c,80,00,00,00,01,65,b8,00,04,00,00,13,88,c5
//P-frame or B-frame For example: 00,00,00,01,61,e0,00,40,00,be,41,38,22,93,df
//Remove start code 00,00,00,01, get 61,e0,00,40,00,be,41,38,22,93,df
//pure C
conn->on_video(&rtc->peer, videoFrame)://Push video
conn->on_audio(&rtc->peer, audioFrame);//Push audio
//C++
conn->on_video(videoFrame)://Push video
conn->on_audio(audioFrame);//Push audio