码迷,mamicode.com
首页 > Web开发 > 详细

WebRTC 音视频开发之路

时间:2015-11-11 22:06:09      阅读:595      评论:0      收藏:0      [点我收藏+]

标签:

    早在2014年就通过WebRTC实现了PC客户端的实时视频语音,那时P2P连接的建立使用的WebRTC自带的libjingle库,使用peerconnection的API实现的。后来在做远程桌面,文件传输需要点对点建立连接,对libjingle库研究了一段时间,发现了几个问题:

1.libjingle库底层使用xmpp协议实现进行通道的建立,但是我们的客户端不支持xmpp协议;

2.libjingle库庞大,使得改写困难。

3.稳定性问题。

    之后基于UDT库实现了一套p2p传输库,使用也非常方便只要双方约定好名字同时连接服务器就可以打洞成功,后来使用这套库替换了WebRTC的libjingle库进行传输。

实现细节如下:

    直接使用WebRTC的voice_engine和video_engine实现视频语音(因为voice_engine和video_engine API简单易于维护),对接部分如下:

 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 };

实现Transport类SendPacket,SendRTCPPacket的接口来发送RTP和RTCP数据包,调用VoENetwork::RegisterExternalTransport()注册给voice_engine,再将收到的数据包交由VoENetwork::ReceivedRTPPacket和VoENetwork::ReceivedRTCPPacket来处理,视频也类似处理。

 

WebRTC 音视频开发之路

标签:

原文地址:http://www.cnblogs.com/zentel/p/4957414.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!