1*d9f75844SAndroid Build Coastguard Worker<?% config.freshness.reviewed = '2021-05-07' %?> 2*d9f75844SAndroid Build Coastguard Worker<?% config.freshness.owner = 'hta' %?> 3*d9f75844SAndroid Build Coastguard Worker 4*d9f75844SAndroid Build Coastguard Worker# PeerConnection and friends 5*d9f75844SAndroid Build Coastguard Worker 6*d9f75844SAndroid Build Coastguard WorkerThe PeerConnection is the C++-level implementation of the Javascript 7*d9f75844SAndroid Build Coastguard Workerobject "RTCPeerConnection" from the 8*d9f75844SAndroid Build Coastguard Worker[WEBRTC specification](https://w3c.github.io/webrtc-pc/). 9*d9f75844SAndroid Build Coastguard Worker 10*d9f75844SAndroid Build Coastguard WorkerLike many objects in WebRTC, the PeerConnection is used via a factory and an 11*d9f75844SAndroid Build Coastguard Workerobserver: 12*d9f75844SAndroid Build Coastguard Worker 13*d9f75844SAndroid Build Coastguard Worker * PeerConnectionFactory, which is created via a static Create method and takes 14*d9f75844SAndroid Build Coastguard Worker a PeerConnectionFactoryDependencies structure listing such things as 15*d9f75844SAndroid Build Coastguard Worker non-default threads and factories for use by all PeerConnections using 16*d9f75844SAndroid Build Coastguard Worker the same factory. (Using more than one factory should be avoided, since 17*d9f75844SAndroid Build Coastguard Worker it takes more resources.) 18*d9f75844SAndroid Build Coastguard Worker * PeerConnection itself, which is created by the method called 19*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactory::CreatePeerConnectionOrError, and takes a 20*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration argument, as well as 21*d9f75844SAndroid Build Coastguard Worker a PeerConnectionDependencies (even more factories, plus other stuff). 22*d9f75844SAndroid Build Coastguard Worker * PeerConnectionObserver (a member of PeerConnectionDependencies), which 23*d9f75844SAndroid Build Coastguard Worker contains the functions that will be called on events in the PeerConnection 24*d9f75844SAndroid Build Coastguard Worker 25*d9f75844SAndroid Build Coastguard WorkerThese types are visible in the API. 26*d9f75844SAndroid Build Coastguard Worker 27*d9f75844SAndroid Build Coastguard Worker## Internal structure of PeerConnection and friends 28*d9f75844SAndroid Build Coastguard Worker 29*d9f75844SAndroid Build Coastguard WorkerThe PeerConnection is, to a large extent, a "God object" - most things 30*d9f75844SAndroid Build Coastguard Workerthat are done in WebRTC require a PeerConnection. 31*d9f75844SAndroid Build Coastguard Worker 32*d9f75844SAndroid Build Coastguard WorkerInternally, it is divided into several objects, each with its own 33*d9f75844SAndroid Build Coastguard Workerresponsibilities, all of which are owned by the PeerConnection and live 34*d9f75844SAndroid Build Coastguard Workeras long as the PeerConnection: 35*d9f75844SAndroid Build Coastguard Worker 36*d9f75844SAndroid Build Coastguard Worker * SdpOfferAnswerHandler takes care of negotiating configurations with 37*d9f75844SAndroid Build Coastguard Worker a remote peer, using SDP-formatted descriptions. 38*d9f75844SAndroid Build Coastguard Worker * RtpTransmissionManager takes care of the lists of RtpSenders, 39*d9f75844SAndroid Build Coastguard Worker RtpReceivers and RtpTransceivers that form the heart of the transmission 40*d9f75844SAndroid Build Coastguard Worker service. 41*d9f75844SAndroid Build Coastguard Worker * DataChannelController takes care of managing the PeerConnection's 42*d9f75844SAndroid Build Coastguard Worker DataChannels and its SctpTransport. 43*d9f75844SAndroid Build Coastguard Worker * JsepTransportController takes care of configuring the details of senders 44*d9f75844SAndroid Build Coastguard Worker and receivers. 45*d9f75844SAndroid Build Coastguard Worker * Call does management of overall call state. 46*d9f75844SAndroid Build Coastguard Worker * RtcStatsCollector (and its obsolete sibling, StatsCollector) collects 47*d9f75844SAndroid Build Coastguard Worker statistics from all the objects comprising the PeerConnection when 48*d9f75844SAndroid Build Coastguard Worker requested. 49*d9f75844SAndroid Build Coastguard Worker 50*d9f75844SAndroid Build Coastguard WorkerThere are a number of other smaller objects that are also owned by 51*d9f75844SAndroid Build Coastguard Workerthe PeerConnection, but it would take too much space to describe them 52*d9f75844SAndroid Build Coastguard Workerall here; please consult the .h files. 53*d9f75844SAndroid Build Coastguard Worker 54*d9f75844SAndroid Build Coastguard WorkerPeerConnectionFactory owns an object called ConnectionContext, and a 55*d9f75844SAndroid Build Coastguard Workerreference to this is passed to each PeerConnection. It is referenced 56*d9f75844SAndroid Build Coastguard Workervia an rtc::scoped_refptr, which means that it is guaranteed to be 57*d9f75844SAndroid Build Coastguard Workeralive as long as either the factory or one of the PeerConnections 58*d9f75844SAndroid Build Coastguard Workeris using it. 59*d9f75844SAndroid Build Coastguard Worker 60