|
MythTV
0.25-pre
|
00001 /********** 00002 This library is free software; you can redistribute it and/or modify it under 00003 the terms of the GNU Lesser General Public License as published by the 00004 Free Software Foundation; either version 2.1 of the License, or (at your 00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) 00006 00007 This library is distributed in the hope that it will be useful, but WITHOUT 00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00009 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00010 more details. 00011 00012 You should have received a copy of the GNU Lesser General Public License 00013 along with this library; if not, write to the Free Software Foundation, Inc., 00014 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00015 **********/ 00016 // "liveMedia" 00017 // Copyright (c) 1996-2005 Live Networks, Inc. All rights reserved. 00018 // RTP sink for AC3 audio 00019 // Implementation 00020 00021 #include "AC3AudioRTPSink.hh" 00022 00023 AC3AudioRTPSink::AC3AudioRTPSink(UsageEnvironment& env, Groupsock* RTPgs, 00024 u_int8_t rtpPayloadFormat, 00025 u_int32_t rtpTimestampFrequency) 00026 : AudioRTPSink(env, RTPgs, rtpPayloadFormat, 00027 rtpTimestampFrequency, "AC3") { 00028 } 00029 00030 AC3AudioRTPSink::~AC3AudioRTPSink() { 00031 } 00032 00033 AC3AudioRTPSink* 00034 AC3AudioRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs, 00035 u_int8_t rtpPayloadFormat, 00036 u_int32_t rtpTimestampFrequency) { 00037 return new AC3AudioRTPSink(env, RTPgs, 00038 rtpPayloadFormat, rtpTimestampFrequency); 00039 } 00040 00041 Boolean AC3AudioRTPSink 00042 ::frameCanAppearAfterPacketStart(unsigned char const* /*frameStart*/, 00043 unsigned /*numBytesInFrame*/) const { 00044 // (For now) allow at most 1 frame in a single packet: 00045 return False; 00046 } 00047 00048 void AC3AudioRTPSink 00049 ::doSpecialFrameHandling(unsigned fragmentationOffset, 00050 unsigned char* frameStart, 00051 unsigned numBytesInFrame, 00052 struct timeval frameTimestamp, 00053 unsigned numRemainingBytes) { 00054 // Update the "NDU" header. 00055 // Also set the "Data Unit Header" for the frame, because we 00056 // have already allotted space for this, by virtue of the fact that 00057 // (for now) we pack only one frame in each RTP packet: 00058 unsigned char headers[2]; 00059 headers[0] = numFramesUsedSoFar() + 1; 00060 00061 Boolean isFragment = numRemainingBytes > 0 || fragmentationOffset > 0; 00062 unsigned const totalFrameSize 00063 = fragmentationOffset + numBytesInFrame + numRemainingBytes; 00064 unsigned const fiveEighthsPoint = totalFrameSize/2 + totalFrameSize/8; 00065 Boolean haveFiveEighths 00066 = fragmentationOffset == 0 && numBytesInFrame >= fiveEighthsPoint; 00067 headers[1] = (isFragment<<5)|(haveFiveEighths<<4); // F|B 00068 // Note: TYP==0, RDT==0 ???, T==0 ??? 00069 00070 setSpecialHeaderBytes(headers, sizeof headers); 00071 00072 if (numRemainingBytes == 0) { 00073 // This packet contains the last (or only) fragment of the frame. 00074 // Set the RTP 'M' ('marker') bit: 00075 setMarkerBit(); 00076 } 00077 00078 // Important: Also call our base class's doSpecialFrameHandling(), 00079 // to set the packet's timestamp: 00080 MultiFramedRTPSink::doSpecialFrameHandling(fragmentationOffset, 00081 frameStart, numBytesInFrame, 00082 frameTimestamp, 00083 numRemainingBytes); 00084 } 00085 00086 unsigned AC3AudioRTPSink::specialHeaderSize() const { 00087 // There's a 1 byte "NDU" header. 00088 // There's also a 1-byte "Data Unit Header" preceding each frame in 00089 // the RTP packet, but since we (for now) pack only one frame in 00090 // each RTP packet, we also count this here: 00091 return 1 + 1; 00092 }
1.7.6.1