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