peerconnection是webrtc面向外面的音视频交互的统一接口,可以理解为一个功能特别强大的socket接口,里面保存了实时交互的所有信息,同时音视频的转发与接收也是通过peerconnection来完成
1 peerconnection 概述
peerconnection继承自PeerConnectionInterface 接口,所以作为对外暴露的统一接口为PeerConnectionInterface,通过工厂方法来通过统一创建PeerConnectionInterface 来创建peerconnection,在peerConnection.h中,// It uses WebRtcSession to implement the PeerConnection functionality. 说明了,webRtcSession类的重要
2 peerconnection类简要分析
rtc::scoped_refptr<PeerConnectionFactory> factory_; //创建工厂
PeerConnectionObserver* observer_; //回调观察者,一般在外部类创建成功时,传入this指针,在示例中是Conductor,方便时间回调
UMAObserver* uma_observer_; //暂时不清楚
SignalingState signaling_state_; // signal slot相关
// TODO(bemasc): Remove ice_state_.
IceState ice_state_; //ice状态
IceConnectionState ice_connection_state_;//ice链接状态(相当于ice_state_的子状态的一个状态)
IceGatheringState ice_gathering_state_;//ice 收集状态(相当于ice_state_的子状态的一个状态)
std::unique_ptr<cricket::PortAllocator> port_allocator_;//sdp相关?
std::unique_ptr<MediaControllerInterface> media_controller_;//媒体控制相关
// One PeerConnection has only one RTCP CNAME.
// https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9
std::string rtcp_cname_;
// Streams added via AddStream.
rtc::scoped_refptr<StreamCollection> local_streams_;//本地stream管理
// Streams created as a result of SetRemoteDescription.
rtc::scoped_refptr<StreamCollection> remote_streams_;//远端stream管理
std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_;
// These lists store track info seen in local/remote descriptions.
TrackInfos remote_audio_tracks_;
TrackInfos remote_video_tracks_;
TrackInfos local_audio_tracks_;
TrackInfos local_video_tracks_;
SctpSidAllocator sid_allocator_;//暂不清楚
// label -> DataChannel
std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;//数据通道
std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
bool remote_peer_supports_msid_ = false;
std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>>
senders_;
std::vector<
rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>>
receivers_;
std::unique_ptr<WebRtcSession> session_; //session管理类
std::unique_ptr<StatsCollector> stats_;