📄 rfc3119.txt
字号:
Segment curADU = pendingADUFrames.head(); int endOfHeadFrame = curADU.mp3FrameSize - curADU.headerSize - curADU.sideInfoSize; int frameOffset = 0; while (1) { int endOfData = frameOffset - curADU.backpointer + curADU.aduDataSize; if (endOfData >= endOfHeadFrame) { // We have enough data to generate a // frame.Finlayson Standards Track [Page 13]RFC 3119 Loss-Tolerant RTP Payload Format for MP3 Audio June 2001 needToEnqueue = False; break; } frameOffset += curADU.mp3FrameSize - curADU.headerSize - curADU.sideInfoSize; if (curADU == pendingADUFrames.tail()) break; curADU = pendingADUFrames.next(curADU); } } return needToEnqueue;}void generateFrameFromHeadADU() { Segment curADU = pendingADUFrames.head(); // Output the header and side info: output(curADU.header); output(curADU.sideInfo); // Begin by zeroing out the rest of the frame, in case the ADU // data doesn't fill it in completely: int endOfHeadFrame = curADU.mp3FrameSize - curADU.headerSize - curADU.sideInfoSize; output("endOfHeadFrame" zero bytes); // Fill in the frame with appropriate ADU data from this and // subsequent ADUs: int frameOffset = 0; int toOffset = 0; while (toOffset < endOfHeadFrame) { int startOfData = frameOffset - curADU.backpointer; if (startOfData > endOfHeadFrame) { break; // no more ADUs are needed } int endOfData = startOfData + curADU.aduDataSize; if (endOfData > endOfHeadFrame) { endOfData = endOfHeadFrame; } int fromOffset; if (startOfData <= toOffset) { fromOffset = toOffset - startOfData; startOfData = toOffset; if (endOfData < startOfData) {Finlayson Standards Track [Page 14]RFC 3119 Loss-Tolerant RTP Payload Format for MP3 Audio June 2001 endOfData = startOfData; } } else { fromOffset = 0; // leave some zero bytes beforehand: toOffset = startOfData; } int bytesUsedHere = endOfData - startOfData; output(starting at offset "toOffset, "bytesUsedHere" bytes from "&curADU.frameData[fromOffset]"); toOffset += bytesUsedHere; frameOffset += curADU.mp3FrameSize - curADU.headerSize - curADU.sideInfoSize; curADU = pendingADUFrames.next(curADU); } pendingADUFrames.dequeue();}void insertDummyADUsIfNecessary() { // The tail segment (ADU) is assumed to have been recently // enqueued. If its backpointer would overlap the data // of the previous ADU, then we need to insert one or more // empty, 'dummy' ADUs ahead of it. (This situation should // occur only if an intermediate ADU was missing - e.g., due // to packet loss.) while (1) { Segment tailADU = pendingADUFrames.tail(); int prevADUend; // relative to the start of the tail ADU if (pendingADUFrames.head() != tailADU) { // there is a previous ADU Segment prevADU = pendingADUFrames.previous(tailADU); prevADUend = prevADU.mp3FrameSize + prevADU.backpointer - prevADU.headerSize - curADU.sideInfoSize; if (prevADU.aduDataSize > prevADUend) { // this shouldn't happen if the previous // ADU was well-formed prevADUend = 0; } else { prevADUend -= prevADU.aduDataSize;Finlayson Standards Track [Page 15]RFC 3119 Loss-Tolerant RTP Payload Format for MP3 Audio June 2001 } } else { prevADUend = 0; } if (tailADU.backpointer > prevADUend) { // Insert a 'dummy' ADU in front of the tail. // This ADU can have the same "header" (and thus // "mp3FrameSize") as the tail ADU, but should // have an "aduDataSize" of zero. The simplest // way to do this is to copy the "sideInfo" from // the tail ADU, and zero out the // "main_data_begin" and all of the // "part2_3_length" fields. } else { break; // no more dummy ADUs need to be inserted } }}Appendix B: Interleaving and Deinterleaving The following 'pseudo code' describes how a sender can reorder a sequence of "ADU Frames" according to an interleaving pattern (step 2), and how a receiver can perform the reverse reordering (step 6).B.1 Interleaving a sequence of "ADU Frames": We first define the following abstract data structures: - "interleaveCycleSize": an integer in the range [1,256] - "interleaveCycle": an array, of size "interleaveCycleSize", containing some permutation of the integers from the set [0 .. interleaveCycleSize-1] e.g., if "interleaveCycleSize" == 8, "interleaveCycle" might contain: 1,3,5,7,0,2,4,6 - "inverseInterleaveCycle": an array containing the inverse of the permutation in "interleaveCycle" - i.e., such that interleaveCycle[inverseInterleaveCycle[i]] == i - "ii": the current Interleave Index (initially 0) - "icc": the current Interleave Cycle Count (initially 0) - "aduFrameBuffer": an array, of size "interleaveCycleSize", of ADU Frames that are awaiting packetizationwhile (1) { int positionOfNextFrame = inverseInterleaveCycle[ii]; aduFrameBuffer[positionOfNextFrame] = the next ADU frame; replace the high-order 11 bits of this frame's MPEG headerFinlayson Standards Track [Page 16]RFC 3119 Loss-Tolerant RTP Payload Format for MP3 Audio June 2001 with (ii,icc); // Note: Be sure to leave the remaining 21 bits as is if (++ii == interleaveCycleSize) { // We've finished this cycle, so pass all // pending frames to the packetizing step for (int i = 0; i < interleaveCycleSize; ++i) { pass aduFrameBuffer[i] to the packetizing step; } ii = 0; icc = (icc+1)%8; }}B.2 Deinterleaving a sequence of (interleaved) "ADU Frames": We first define the following abstract data structures: - "ii": the Interleave Index from the current incoming ADU frame - "icc": the Interleave Cycle Count from the current incoming ADU frame - "iiLastSeen": the most recently seen Interleave Index (initially, some integer *not* in the range [0,255]) - "iccLastSeen": the most recently seen Interleave Cycle Count (initially, some integer *not* in the range [0,7]) - "aduFrameBuffer": an array, of size 32, of (pointers to) ADU Frames that have just been depacketized (initially, all entries are NULL)while (1) { aduFrame = the next ADU frame from the depacketizing step; (ii,icc) = "the high-order 11 bits of aduFrame's MPEG header"; "the high-order 11 bits of aduFrame's MPEG header" = 0xFFE; // Note: Be sure to leave the remaining 21 bits as is if (icc != iccLastSeen || ii == iiLastSeen) { // We've started a new interleave cycle // (or interleaving was not used). Release all // pending ADU frames to the ADU->MP3 conversion step: for (int i = 0; i < 32; ++i) { if (aduFrameBuffer[i] != NULL) { release aduFrameBuffer[i]; aduFrameBuffer[i] = NULL; } } } iiLastSeen = ii;Finlayson Standards Track [Page 17]RFC 3119 Loss-Tolerant RTP Payload Format for MP3 Audio June 2001 iccLastSeen = icc; aduFrameBuffer[ii] = aduFrame;}Finlayson Standards Track [Page 18]RFC 3119 Loss-Tolerant RTP Payload Format for MP3 Audio June 2001Full Copyright Statement Copyright (C) The Internet Society (2001). 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.Finlayson Standards Track [Page 19]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -