Artem Titov | a617867 | 2023-01-30 10:51:01 | [diff] [blame] | 1 | <!-- go/cmark --> |
| 2 | <!--* freshness: {owner: 'hta' reviewed: '2021-06-03'} *--> |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 3 | |
| 4 | # RTP in WebRTC |
Artem Titov | a2a073b | 2021-06-16 14:36:48 | [diff] [blame] | 5 | |
| 6 | WebRTC uses the RTP protocol described in |
| 7 | [RFC3550](https://datatracker.ietf.org/doc/html/rfc3550) for transporting audio |
| 8 | and video. Media is encrypted using [SRTP](./srtp.md). |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 9 | |
| 10 | ## Allocation of payload types |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 11 | |
Artem Titov | a2a073b | 2021-06-16 14:36:48 | [diff] [blame] | 12 | RTP packets have a payload type field that describes which media codec can be |
| 13 | used to handle a packet. For some (older) codecs like PCMU the payload type is |
| 14 | assigned statically as described in |
| 15 | [RFC3551](https://datatracker.ietf.org/doc/html/rfc3551). For others, it is |
| 16 | assigned dynamically through the SDP. **Note:** there are no guarantees on the |
| 17 | stability of a payload type assignment. |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 18 | |
Artem Titov | a2a073b | 2021-06-16 14:36:48 | [diff] [blame] | 19 | For this allocation, the range from 96 to 127 is used. When this range is |
| 20 | exhausted, the allocation falls back to the range from 35 to 63 as permitted by |
| 21 | [section 5.1 of RFC3550][1]. Note that older versions of WebRTC failed to |
| 22 | recognize payload types in the lower range. Newer codecs (such as flexfec-03 and |
| 23 | AV1) will by default be allocated in that range. |
| 24 | |
| 25 | Payload types in the range 64 to 95 are not used to avoid confusion with RTCP as |
| 26 | described in [RFC5761](https://datatracker.ietf.org/doc/html/rfc5761). |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 27 | |
| 28 | ## Allocation of audio payload types |
Artem Titov | a2a073b | 2021-06-16 14:36:48 | [diff] [blame] | 29 | |
| 30 | Audio payload types are assigned from a table by the [PayloadTypeMapper][2] |
| 31 | class. New audio codecs should be allocated in the lower dynamic range [35,63], |
| 32 | starting at 63, to reduce collisions with payload types |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 33 | |
| 34 | ## Allocation of video payload types |
Artem Titov | a2a073b | 2021-06-16 14:36:48 | [diff] [blame] | 35 | |
| 36 | Video payload types are allocated by the |
| 37 | [GetPayloadTypesAndDefaultCodecs method][3]. The set of codecs depends on the |
| 38 | platform, in particular for H264 codecs and their different profiles. Payload |
| 39 | numbers are assigned ascending from 96 for video codecs and their |
| 40 | [associated retransmission format](https://datatracker.ietf.org/doc/html/rfc4588). |
| 41 | Some codecs like flexfec-03 and AV1 are assigned to the lower range [35,63] for |
| 42 | reasons explained above. When the upper range [96,127] is exhausted, payload |
| 43 | types are assigned to the lower range [35,63], starting at 35. |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 44 | |
| 45 | ## Handling of payload type collisions |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 46 | |
Artem Titov | a2a073b | 2021-06-16 14:36:48 | [diff] [blame] | 47 | Due to the requirement that payload types must be uniquely identifiable when |
| 48 | using [BUNDLE](https://datatracker.ietf.org/doc/html/rfc8829) collisions between |
| 49 | the assignments of the audio and video payload types may arise. These are |
| 50 | resolved by the [UsedPayloadTypes][4] class which will reassign payload type |
| 51 | numbers descending from 127. |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 52 | |
Philipp Hancke | c7695a5 | 2023-06-05 11:59:02 | [diff] [blame] | 53 | # Bitrate probing |
| 54 | |
| 55 | Bandwidth estimation sometimes requires sending RTP packets to ramp up the |
| 56 | estimate above a certain treshold. WebRTC uses two techniques for that: |
| 57 | |
| 58 | * Packets that only consist of RTP padding |
| 59 | * RTX packets |
| 60 | |
| 61 | At the receiving end, both types of probing packets do not interfere with media processing. |
| 62 | After being taken into account for bandwidth estimation, probing packets only consisting |
| 63 | of padding can be dropped and RTX packets act as redundancy. |
| 64 | |
| 65 | Using RTX for probing is generally preferred as padding probes are limited to 256 bytes |
| 66 | of RTP payload which results in a larger number of packets being used for probing which |
| 67 | is a disadvantage from a congestion control point of view. |
| 68 | |
| 69 | ## Padding probes |
| 70 | |
| 71 | Padding probes consist of RTP packets with header extensions (either abs-send time or |
| 72 | the transport-wide-cc sequence number) and set the RTP "P" bit. The last byte of the |
| 73 | RTP payload which specifies the amount of padding is set to 255 and preceeded by 255 |
| 74 | bytes of all zeroes. See [section 5.1 of RFC3550][1]. |
| 75 | Padding probes use the RTX RTP stream (i.e. payload type, sequence number and timestamp) |
| 76 | when RTX is negotiated or share the same RTP stream as the media packets otherwise. |
| 77 | |
| 78 | Padding probes are used either when |
| 79 | * RTX is not negotiated (such as for audio, less commonly for video) or |
| 80 | * no suitable original packet is found for RTX probing. |
| 81 | |
| 82 | Padding probes should not be interleaved with packets of a video frame. |
| 83 | |
| 84 | ## RTX probes |
| 85 | |
| 86 | RTX probes are resends of previous packets that use RTX retransmissions specified in |
| 87 | [RFC4588](https://www.rfc-editor.org/rfc/rfc4588) as payload format when negotiated with |
| 88 | the peer. These packets will have a different abs-send-time or transport-wide-cc sequence |
| 89 | number and use the RTX RTP stream (i.e. RTX payload type, sequence number and timestamp) |
| 90 | associated with the media RTP stream. |
| 91 | |
| 92 | RTX probing uses recently sent RTP packets that have not yet been acknowledged by |
| 93 | the remote side. Sending these packets again has a small chance of being useful when the |
| 94 | original packet is lost and will not affect RTP processing at the receiver otherwise. |
| 95 | |
Philipp Hancke | d25af8ce | 2021-06-04 04:58:53 | [diff] [blame] | 96 | [1]: https://datatracker.ietf.org/doc/html/rfc3550#section-5.1 |
| 97 | [2]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/media/engine/payload_type_mapper.cc;l=25;drc=4f26a3c7e8e20e0e0ca4ca67a6ebdf3f5543dc3f |
| 98 | [3]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/media/engine/webrtc_video_engine.cc;l=119;drc=b412efdb780c86e6530493afa403783d14985347 |
| 99 | [4]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/pc/used_ids.h;l=94;drc=b412efdb780c86e6530493afa403783d14985347 |