-
Notifications
You must be signed in to change notification settings - Fork 265
metaRTC 8.0 API Programming Guide
yangrtc edited this page Jan 5, 2026
·
3 revisions
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 yangwhip8 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/YangPeerConnectio8.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);
YangPeerConnection8* conn=new YangPeerConnection8(&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 (00,00,00,01)+sps+(00,00,00,01)+pps+(00,00,00,01)+I-frame e.g.,
00,00,00,01,67,42,c0,1f,8c,8d,40,50,1e,d0,0f,08,84,6a,00,00,00,01,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
YangPushData* pushData;
YangPacer* pacer=(YangPacer*)yang_calloc(sizeof(YangPacer),1);
yang_create_pacer(pacer);
pacer->initAudio(pacer->session,audioCodec,m_context->avinfo.audio.sample,m_context->avinfo.audio.channel);
pacer->initVideo(pacer->session,videoCodec,1024);
pushData=pacer->getVideoData(&videoFrame);
conn->on_video(&rtc->peer, videoFrame)://Push video
conn->on_audio(&rtc->peer, audioFrame);//Push audio
......
yang_destroy_pacer(pacer);
yang_free(pacer);
//C++
YangPushData* pushData;
YangRtcPacer* pacer=new YangRtcPacer();
pacer->initAudio(audioCodec,m_context->avinfo.audio.sample,m_context->avinfo.audio.channel);
pacer->initVideo(videoCodec,1024);
pushData=pacer->getVideoData(&videoFrame);
conn->on_video(pushData)://Push video
pushData=pacer->getAudioData(&audioFrame);
conn->on_audio(pushData);//Push audio