RFC 2658
RTP Payload Format for PureVoice(tm) Audio
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 Notice ๐
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
9 Full Copyright Statement ยฉ๏ธ
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
- ietf: rfc2658 1999-08
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms