Purpose of RTCRtpSender and RTCRtpReceiver in WebRTC
This article explains the specific architectural purposes of the
RTCRtpSender and RTCRtpReceiver objects in the
WebRTC API. It explores how these interfaces transition WebRTC from a
legacy stream-based model to a modern, track-level media control
architecture, enabling granular control over media encoding,
transmission, and reception.
The Shift to Track-Based Architecture
In early versions of the WebRTC specification, media was managed at
the stream level using MediaStream objects. This approach
lacked flexibility because it treated all tracks within a stream as a
single unit. To provide developer control over individual audio and
video tracks, the WebRTC 1.0 specification introduced a track-based
architecture.
At the core of this modern architecture are RTCRtpSender
and RTCRtpReceiver. Instead of managing broad streams,
WebRTC now assigns a dedicated sender and receiver object to each
individual MediaStreamTrack (such as a single microphone
input or a camera feed).
Architectural Purpose of RTCRtpSender
The RTCRtpSender interface is architected to control the
encoding and transmission of a local MediaStreamTrack to a
remote peer over an RTP (Real-time Transport Protocol) connection.
Its primary architectural responsibilities include: * Media
Association: It binds a specific local media track to an active
peer connection. * Encoding and Codec Configuration:
Through the setParameters() method, developers can
configure encoding parameters dynamically without renegotiating the peer
connection. This includes setting maximum bitrates, adjusting scale
resolution down (for simulcast), and prioritizing specific tracks. *
Transmission Control: It allows developers to replace
the media track being sent on the fly using replaceTrack().
This enables seamless transitions (such as switching from a front-facing
camera to a rear-facing camera) without interrupting the underlying
network connection or triggering SDP renegotiation.
Architectural Purpose of RTCRtpReceiver
The RTCRtpReceiver interface is designed to manage the
reception, decoding, and playout of an incoming
MediaStreamTrack sent by a remote peer.
Its primary architectural responsibilities include: *
Decoding Management: It handles the incoming RTP packet
stream, reassembling and decoding the packets back into a playable media
track. * Jitter and Playout Control: The receiver
manages the jitter buffer and handles packet loss concealment to ensure
smooth playback of real-time audio and video. * Contributing
Sources (CSRC): It exposes information about the contributing
sources (getContributingSources()) and synchronization
sources (getSynchronizationSources()), allowing developers
to identify which remote audio/video streams are contributing to the
received media.
The RTCRtpTransceiver Relationship
Architecturally, RTCRtpSender and
RTCRtpReceiver do not exist in isolation. They are paired
together within an RTCRtpTransceiver object. A transceiver
represents a bidirectional media channel (corresponding to a single “m=”
line in the SDP session description).
By separating the sending and receiving mechanisms into distinct
RTCRtpSender and RTCRtpReceiver objects within
a transceiver, WebRTC allows unidirectional controls. For example, a
peer can mute their outgoing video (by stopping or disabling the sender)
while continuing to receive and render the remote peer’s video (via the
receiver) on the same bidirectional channel.