RFC 2658

RTP Payload Format for PureVoice(tm) Audio

๐Ÿ“… published August 1999, from ietf

RFC 2658: RTP Payload Format for PureVoice(tm) Audio ๐ŸŽ€

Okay bestie, this one's from the Network Working Group ๐ŸŒธ It's a Standards Track doc by K. McKay of QUALCOMM Incorporated, dated August 1999. The header doesn't mention obsoleting or updating anything, so it's a standalone spec ๐Ÿ’…


Status of this Memo โœจ

This document is an Internet standards track protocol for the Internet community, and it's asking for discussion and suggestions for improvements. For the current standardization state and status of this protocol, check the current edition of the "Internet Official Protocol Standards" (STD 1). Distribution of this memo is unlimited ๐Ÿฆ‹

Copyright (C) The Internet Society (1999). All Rights Reserved.

ABSTRACT ๐Ÿ’œ

This doc describes the RTP payload format for PureVoice(tm) Audio. The packet format supports variable interleaving, which helps soften the blow of packet loss on audio quality ๐Ÿ”ฅ

1 Introduction ๐Ÿงš

Here's the vibe: this doc explains how compressed PureVoice audio, made by the Qualcomm PureVoice CODEC [1], can be formatted to be used as an RTP payload type. There's a method for interleaving the compressor's output, so lost packets hurt the sound less ๐Ÿ˜ญ The sender also gets to pick interleave settings depending on whether low end-to-end delay matters more to them, or greater tolerance for lost packets does ๐Ÿ’–

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [3]. (Yes, those are the official key words, and yes, we're keeping them exactly as written ๐Ÿซถ)

2 Background ๐Ÿ“

So the Electronic Industries Association (EIA) & Telecommunications Industry Association (TIA) standard IS-733 [1] defines an audio compression algorithm for use in CDMA applications. It's not just any codec either. It's the standard CODEC for all wireless CDMA terminals ๐Ÿ“ฑ The Qualcomm PureVoice CODEC (a.k.a. Qcelp) also shows up in several Internet applications, most notably JFax(tm), Apple(r) QuickTime(tm), and Eudora(r) โœจ

The Qcelp CODEC [1] compresses each 20 milliseconds of 8000 Hz, 16-bit sampled input speech into one of four output frame sizes: Rate 1 (266 bits), Rate 1/2 (124 bits), Rate 1/4 (54 bits), or Rate 1/8 (20 bits). The CODEC picks the output frame rate by analyzing the input speech and the current operating mode (either normal or reduced rate). For typical speech patterns, that works out to an average output of 6.8 k bits/sec in normal mode and 4.7 k bits/sec in reduced rate mode ๐ŸŽง

3 RTP/Qcelp Packet Format ๐Ÿ’…

The RTP timestamp is in 1/8000 of a second units. The RTP payload data for the Qcelp CODEC has this format ๐Ÿฆ‹

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      RTP Header [2]                           |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|RR | LLL | NNN |                                               |
+-+-+-+-+-+-+-+-+       one or more codec data frames           |
|                             ....                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The RTP header has the expected values described in [2]. The extension bit is not set, and this payload type never sets the marker bit. The codec data frames are aligned on octet boundaries. When interleaving is in use and/or multiple codec data frames are in a single RTP packet, the timestamp is, as always, that of the oldest data represented in the RTP packet โฐ Here's what the other fields mean:

Reserved (RR): 2 bits MUST be set to zero by sender, SHOULD be ignored by receiver.

Interleave (LLL): 3 bits MUST have a value between 0 and 5 inclusive. The remaining two values (6 and 7) MUST not be used by senders. If this field is non-zero, interleaving is enabled. All receivers MUST support interleaving. Senders MAY support interleaving. Senders that do not support interleaving MUST set field LLL and NNN to zero. ๐ŸŒธ

Interleave Index (NNN): 3 bits MUST have a value less than or equal to the value of LLL. Values of NNN greater than the value of LLL are invalid ๐Ÿ™ˆ

3.1 Receiving Invalid Values ๐Ÿšซ

When a receiver gets an RTP packet with an invalid value in the LLL or NNN field, that RTP packet MUST be treated as lost by the receiver for the purpose of generating erasure frames, as described in section 4. Basically, it gets treated like it never arrived ๐Ÿ’€

3.2 CODEC data frame format ๐Ÿง

The output of the Qcelp CODEC must be converted into CODEC data frames for inclusion in the RTP payload, like this:

a. Octet 0 of the CODEC data frame indicates the rate and total size of the CODEC data frame, as shown in this table:

OCTET 0   RATE      TOTAL CODEC data frame size (in octets)
-----------------------------------------------------------
  0       Blank     1
  1       1/8       4
  2       1/4       8
  3       1/2       17
  4       1         35
  5       reserved  8 (SHOULD be treated as a reserved value)
 14       Erasure   1 (SHOULD NOT be transmitted by sender)
 other    n/a       reserved

Receipt of a CODEC data frame with a reserved value in octet 0 MUST be considered invalid data, as described in 3.1. Oof, so no sneaky reserved values allowed ๐Ÿ™…โ€โ™€๏ธ

b. The bits, numbered in the standard [1] from highest to lowest, get packed into octets. The highest numbered bit (265 for Rate 1, 123 for Rate 1/2, 53 for Rate 1/4, and 19 for Rate 1/8) goes in the most significant bit (Internet bit 0) of octet 1 of the CODEC data frame. The second highest numbered bit (264 for Rate 1, etc.) goes in the second most significant bit (Internet bit 1) of octet 1 of the data frame. This keeps going so that bit 258 from the standard Rate 1 frame lands in the least significant bit of octet 1. Bit 257 from the standard goes in the most significant bit of octet 2, and so on, until bit 0 from the standard Rate 1 frame lands in Internet bit 1 of octet 34 of the CODEC data frame. The remaining unused bits of the last octet of the CODEC data frame MUST be set to zero. Bit-packing brain-teaser unlocked ๐Ÿงฉ

Here's a detail of how a Rate 1/8 frame gets converted into a CODEC data frame:

                        CODEC data frame

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |1|1|1|1|1|1|1|1|1|1| | | | | | | | | | | | | | |
| 1 (Rate 1/8)  |9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|Z|Z|Z|Z|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Octet 0 of the data frame has the value 1 (see the table above), which means the total data frame length, including octet 0, is 4 octets. Bits 19 through 0 from the standard Rate 1/8 frame are placed as shown, with the bits marked "Z" set to zero. The Rate 1, 1/4, and 1/2 standard frames get converted similarly ๐Ÿซง

3.3 Bundling CODEC data frames ๐ŸŽ

As noted in section 3, a sender MAY include more than one CODEC data frame in a single RTP packet. Receivers MUST handle bundles of up to 10 CODEC data frames in a single RTP packet ๐Ÿ’œ

Senders also have these extra restrictions:

  • MUST not bundle more CODEC data frames in a single RTP packet than will fit in the MTU of the RTP transport protocol. For the purpose of computing the maximum bundling value, all CODEC data frames should be assumed to have the Rate 1 size.
  • MUST never bundle more than 10 CODEC data frames in a single RTP packet.
  • Once beginning transmission with a given SSRC and given bundling value, MUST NOT increase the bundling value. If the bundling value needs to be increased, a new SSRC number MUST be used.
  • MAY decrease the bundling value only between interleave groups (see section 3.4). If the bundling value is decreased, it MUST NOT be increased (even to the original value), although it may be decreased again at a later time.

3.3.1 Determining the number of bundled CODEC data frames ๐Ÿ”

No count is sent as part of the RTP payload, and the CODEC data frames have different lengths. So the only way to figure out how many CODEC data frames are in the RTP packet is to look at octet 0 of each CODEC data frame, in sequence, until you hit the end of the RTP packet ๐Ÿ•ต๏ธโ€โ™€๏ธ

3.4 Interleaving CODEC data frames ๐ŸŒ€

Interleaving only means something when more than one CODEC data frame is bundled into a single RTP packet ๐Ÿ’…

All receivers MUST support interleaving. Senders MAY support interleaving.

Say you have a time-ordered sequence of output frames from the Qcelp CODEC, numbered 0..n, a bundling value B, and an interleave value L, where n = B * (L+1) - 1. The output frames get placed into RTP packets like this (the values of the fields LLL and NNN are listed for each RTP packet):

First RTP Packet in Interleave group: LLL=L, NNN=0 Frame 0, Frame L+1, Frame 2(L+1), Frame 3(L+1), ... for a total of B frames

Second RTP Packet in Interleave group: LLL=L, NNN=1 Frame 1, Frame 1+L+1, Frame 1+2(L+1), Frame 1+3(L+1), ... for a total of B frames

This keeps going to the last RTP packet in the interleave group:

L+1 RTP Packet in Interleave group: LLL=L, NNN=L Frame L, Frame L+L+1, Frame L+2(L+1), Frame L+3(L+1), ... for a total of B frames

Senders MUST transmit in timestamp-increasing order. Within each interleave group, the RTP packets making up that group MUST be transmitted in value-increasing order of the NNN field. This doesn't guarantee reduced end-to-end delay on the receiving end, but when packets are delivered in order by the underlying transport, delay gets reduced to the minimum possible โšก

Senders also have these restrictions:

  • Once beginning transmission with a given SSRC and given interleave value, MUST NOT increase the interleave value. If the interleave value needs to be increased, a new SSRC number MUST be used.
  • MAY decrease the interleave value only between interleave groups. If the interleave value is decreased, it MUST NOT be increased (even to the original value), although it may be decreased again at a later time.

3.5 Finding Interleave Group Boundaries ๐Ÿ”โœจ

Okay so, say you've got an RTP packet with sequence number S, an interleave value (field LLL) of L, and an interleave index value (field NNN) of N. Its interleave group is every RTP packet with sequence numbers from S-N to S-N+L inclusive. Basically the group is always L+1 packets with sequential sequence numbers ๐Ÿ’…. And every packet in that group MUST have the same bundling value ๐ŸŽ€.

The receiver figures out what the bundling value should be for the whole group by looking at how many CODEC data frames were bundled in the first packet of the group it actually gets. That might not be the first packet the sender actually sent, though, if the transport delivers things out of order ๐Ÿ™ˆ.

If a packet in the group shows up with a bundling value that isn't the expected one, the receiver MAY chop CODEC data frames off the end, or tack erasure CODEC data frames onto the end, so it can make a stand-in packet with the expected bundling value ๐Ÿงš. The receiver MAY also just throw out the whole interleave group and play silence instead ๐Ÿคซ.


3.6 Reconstructing Interleaved Audio ๐Ÿฆ‹

Say you have a set of RTP packets in an interleave group, numbered 0 to L (L being the interleave value), and B is the bundling value. Each packet has CODEC data frames numbered 1 to B, in order from first to last. You can rebuild the original time-ordered output frames from the CODEC like this:

First L+1 frames:
   Frame 0 from packet 0 of interleave group
   Frame 0 from packet 1 of interleave group
   And so on up to...
   Frame 0 from packet L of interleave group

Second L+1 frames:
   Frame 1 from packet 0 of interleave group
   Frame 1 from packet 1 of interleave group
   And so on up to...
   Frame 1 from packet L of interleave group

And so on up to...

Bth L+1 frames:
   Frame B from packet 0 of interleave group
   Frame B from packet 1 of interleave group
   And so on up to...
   Frame B from packet L of interleave group

3.6.1 Additional Receiver Responsibility ๐Ÿซถ

Let's say the receiver has already started playing frames from an interleave group. Now it's time to play frame x from packet n of that group, but packet n never showed up ๐Ÿ˜ญ. As covered in section 4, an erasure frame gets sent to the Qcelp CODEC in that case.

Now here's the plot twist ๐ŸŒˆ. Suppose packet n finally arrives before frame x+1 from it is needed. Receivers SHOULD use frame x+1 from the newly arrived packet n instead of an erasure frame. The vibe is: just because packet n was missing the first time, that doesn't mean it's gone for good. The receiver SHOULD NOT assume it's unavailable when it's needed later for reconstructing the interleaved audio ๐Ÿ’–.


4 Handling lost RTP packets ๐Ÿ’”

The Qcelp CODEC has this concept called erasure frames. These are frames that, for whatever reason, aren't available. When you're rebuilding interleaved audio or playing back non-interleaved audio, erasure frames MUST be fed to the Qcelp CODEC for every missing packet ๐Ÿ™…โ€โ™€๏ธ.

Receivers MUST use the timestamp clock to figure out how many CODEC data frames are missing ๐Ÿ•ฐ๏ธ. Each CODEC data frame advances the timestamp clock EXACTLY 160 counts, so that's your math ๐Ÿงฎ.

Why is the timestamp clock the only reliable way? Because the bundling value can change (it can only go down), so you can't just count on it staying the same. When a packet gets dropped, the timestamp clock is what tells you exactly how many CODEC data frames went missing ๐ŸŽฏ.

When you're specifically rebuilding interleaved audio, a missing RTP packet in the interleave group should be treated as holding B erasure CODEC data frames, where B is the bundling value for that group ๐Ÿ’œ.


5 Discussion ๐Ÿ’ญ

The Qcelp CODEC fills in missing audio when it gets an erasure frame. The catch is that listeners hear the best quality when erasure frames aren't back to back ๐Ÿ‘€. That's why interleaving is so good: it boosts audio quality exactly when packets are more likely to get dropped ๐ŸŽง.

But here's the tea โ˜•. Interleaving can really bump up end-to-end delay. So for an interactive session, an interleave (field LLL) value of 0 or 1 and a bundling factor of 4 or less is recommended ๐Ÿ“ž.

When end-to-end delay isn't a big deal, a bundling value of at least 4 and an interleave (field LLL) value of 4 or 5 is recommended, subject to MTU limitations ๐Ÿ“ฆ.

Now the sender rules from sections 3.3 and 3.4 are what make this whole thing work ๐Ÿง . After the receiver gets the first payload packet from the sender, it can set aside a well-known amount of buffer space that will be enough for every future reception from that same SSRC value โœจ. In the future it might need less buffer space if the sender lowers the bundling value or interleave, but never more ๐Ÿ™Œ. That way the receiver never has to scramble for extra buffer space (possibly with none available!) just because the sender bumped up the bundling value or interleave value ๐Ÿ˜ฑ. And if the interleave or bundling value did go up, the receiver could be forced to pause playback while it waits for the extra packets needed for the higher values โธ๏ธ.


6 Security Considerations ๐Ÿ”

RTP packets using the payload format defined in this spec are subject to the security considerations in the RTP specification [2], plus any appropriate profile (for example [4]). What that means is that confidentiality of the media streams comes from encryption ๐Ÿ”’. The data compression here is applied end-to-end, so encryption can happen after compression with no clash between the two ๐Ÿค.

Now for the scary part ๐Ÿ‘ป. A potential denial-of-service threat exists for data encodings that use compression techniques with non-uniform receiver-end computational load. An attacker can inject pathological datagrams into the stream that are complicated to decode and overload the receiver ๐Ÿšจ. Good news, though: this encoding doesn't have any significant non-uniformity, so that threat doesn't really apply here ๐Ÿ™Œ.

As with any IP-based protocol, a receiver can sometimes get overloaded just from receiving too many packets, wanted or unwanted ๐Ÿ“ฌ. Network-layer authentication can be used to discard packets from unwanted sources, but the processing cost of that authentication itself might be too high ๐Ÿ˜ฉ. In a multicast environment, pruning specific sources might be added in future versions of IGMP [5] and in multicast routing protocols, so a receiver can pick which sources are allowed to reach it ๐Ÿ›ก๏ธ.


7 References ๐Ÿ“š

[1] TIA/EIA/IS-733. TR45: High Rate Speech Service Option for Wideband Spread Spectrum Communications Systems. Available from Global Engineering +1 800 854 7179 or +1 303 792 2181. May also be ordered online at http://www.eia.org/eng/.

[2] Schulzrinne, H., Casner, S., Frederick, R. and V. Jacobson, "RTP: A Transport Protocol for Real-Time Applications", RFC 1889, January 1996.

[3] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.

[4] Schulzrinne, H., "RTP Profile for Audio and Video Conferences with Minimal Control", RFC 1890, January 1996.

[5] Deering, S., "Host Extensions for IP Multicasting", STD 5, RFC 1112, August 1989.


8 Author's Address ๐Ÿ–‹๏ธ

Kyle J. McKay QUALCOMM Incorporated 5775 Morehouse Drive San Diego, CA 92121-1714 USA

Phone: +1 858 587 1121 EMail: kylem@qualcomm.com


Copyright (C) The Internet Society (1999). All Rights Reserved.

This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations, except as needed for the purpose of developing Internet standards in which case the procedures for copyrights defined in the Internet Standards process must be followed, or as required to translate it into languages other than English.

The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns.

This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.


Acknowledgement ๐ŸŒธ

Funding for the RFC Editor function is currently provided by the Internet Society ๐Ÿ’•.

๐Ÿ“ฆ where this page comes from