WebRTC 音视频开发之路
? ? 早在2014年就通過WebRTC實(shí)現(xiàn)了PC客戶端的實(shí)時(shí)視頻語音,那時(shí)P2P連接的建立使用的WebRTC自帶的libjingle庫,使用peerconnection的API實(shí)現(xiàn)的。后來在做遠(yuǎn)程桌面,文件傳輸需要點(diǎn)對點(diǎn)建立連接,對libjingle庫研究了一段時(shí)間,發(fā)現(xiàn)了幾個(gè)問題:
1.libjingle庫底層使用xmpp協(xié)議實(shí)現(xiàn)進(jìn)行通道的建立,但是我們的客戶端不支持xmpp協(xié)議;
2.libjingle庫龐大,使得改寫困難。
3.穩(wěn)定性問題。
? ? 之后基于UDT庫實(shí)現(xiàn)了一套p2p傳輸庫,使用也非常方便只要雙方約定好名字同時(shí)連接服務(wù)器就可以打洞成功,后來使用這套庫替換了WebRTC的libjingle庫進(jìn)行傳輸。
實(shí)現(xiàn)細(xì)節(jié)如下:
? ? 直接使用WebRTC的voice_engine和video_engine實(shí)現(xiàn)視頻語音(因?yàn)関oice_engine和video_engine API簡單易于維護(hù)),對接部分如下:
1 class WEBRTC_DLLEXPORT VoENetwork 2 { 3 public: 4 // Factory for the VoENetwork sub-API. Increases an internal 5 // reference counter if successful. Returns NULL if the API is not 6 // supported or if construction fails. 7 static VoENetwork* GetInterface(VoiceEngine* voiceEngine); 8 9 // Releases the VoENetwork sub-API and decreases an internal 10 // reference counter. Returns the new reference count. This value should 11 // be zero for all sub-API:s before the VoiceEngine object can be safely 12 // deleted. 13 virtual int Release() = 0; 14 15 // Installs and enables a user-defined external transport protocol for a 16 // specified |channel|. 17 virtual int RegisterExternalTransport( 18 int channel, Transport& transport) = 0; 19 20 // Removes and disables a user-defined external transport protocol for a 21 // specified |channel|. 22 virtual int DeRegisterExternalTransport(int channel) = 0; 23 24 // The packets received from the network should be passed to this 25 // function when external transport is enabled. Note that the data 26 // including the RTP-header must also be given to the VoiceEngine. 27 virtual int ReceivedRTPPacket( 28 int channel, const void* data, unsigned int length) = 0; 29 30 // The packets received from the network should be passed to this 31 // function when external transport is enabled. Note that the data 32 // including the RTCP-header must also be given to the VoiceEngine. 33 virtual int ReceivedRTCPPacket( 34 int channel, const void* data, unsigned int length) = 0; 35 36 protected: 37 VoENetwork() {} 38 virtual ~VoENetwork() {} 39 };實(shí)現(xiàn)Transport類SendPacket,SendRTCPPacket的接口來發(fā)送RTP和RTCP數(shù)據(jù)包,調(diào)用VoENetwork::RegisterExternalTransport()注冊給voice_engine,再將收到的數(shù)據(jù)包交由VoENetwork::ReceivedRTPPacket和VoENetwork::ReceivedRTCPPacket來處理,視頻也類似處理。
?
轉(zhuǎn)載于:https://www.cnblogs.com/zentel/p/4957414.html
總結(jié)
以上是生活随笔為你收集整理的WebRTC 音视频开发之路的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 夺命雷公狗---PHP开发APP接口--
- 下一篇: 职场@之旅