liveMedia/MPEG4LATMAudioRTPSink.cpp

Go to the documentation of this file.
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 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2012 Live Networks, Inc.  All rights reserved.
00018 // RTP sink for MPEG-4 audio, using LATM multiplexing (RFC 3016)
00019 // Implementation
00020 
00021 #include "MPEG4LATMAudioRTPSink.hh"
00022 
00023 MPEG4LATMAudioRTPSink
00024 ::MPEG4LATMAudioRTPSink(UsageEnvironment& env, Groupsock* RTPgs,
00025                         u_int8_t rtpPayloadFormat,
00026                         u_int32_t rtpTimestampFrequency,
00027                         char const* streamMuxConfigString,
00028                         unsigned numChannels,
00029                         Boolean allowMultipleFramesPerPacket)
00030   : AudioRTPSink(env, RTPgs, rtpPayloadFormat,
00031                  rtpTimestampFrequency, "MP4A-LATM", numChannels),
00032   fStreamMuxConfigString(strDup(streamMuxConfigString)),
00033   fAllowMultipleFramesPerPacket(allowMultipleFramesPerPacket) {
00034   // Set up the "a=fmtp:" SDP line for this stream:
00035   char const* fmtpFmt =
00036     "a=fmtp:%d "
00037     "cpresent=0;config=%s\r\n";
00038   unsigned fmtpFmtSize = strlen(fmtpFmt)
00039     + 3 /* max char len */
00040     + strlen(fStreamMuxConfigString);
00041   char* fmtp = new char[fmtpFmtSize];
00042   sprintf(fmtp, fmtpFmt,
00043           rtpPayloadType(),
00044           fStreamMuxConfigString);
00045   fFmtpSDPLine = strDup(fmtp);
00046   delete[] fmtp;
00047 }
00048 
00049 MPEG4LATMAudioRTPSink::~MPEG4LATMAudioRTPSink() {
00050   delete[] fFmtpSDPLine;
00051   delete[] (char*)fStreamMuxConfigString;
00052 }
00053 
00054 MPEG4LATMAudioRTPSink*
00055 MPEG4LATMAudioRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs,
00056                                  u_int8_t rtpPayloadFormat,
00057                                  u_int32_t rtpTimestampFrequency,
00058                                  char const* streamMuxConfigString,
00059                                  unsigned numChannels,
00060                                  Boolean allowMultipleFramesPerPacket) {
00061   return new MPEG4LATMAudioRTPSink(env, RTPgs, rtpPayloadFormat,
00062                                    rtpTimestampFrequency, streamMuxConfigString,
00063                                    numChannels,
00064                                    allowMultipleFramesPerPacket);
00065 }
00066 
00067 Boolean MPEG4LATMAudioRTPSink
00068 ::frameCanAppearAfterPacketStart(unsigned char const* /*frameStart*/,
00069                                  unsigned /*numBytesInFrame*/) const {
00070   return fAllowMultipleFramesPerPacket;
00071 }
00072 
00073 void MPEG4LATMAudioRTPSink
00074 ::doSpecialFrameHandling(unsigned fragmentationOffset,
00075                          unsigned char* frameStart,
00076                          unsigned numBytesInFrame,
00077                          struct timeval framePresentationTime,
00078                          unsigned numRemainingBytes) {
00079   if (numRemainingBytes == 0) {
00080     // This packet contains the last (or only) fragment of the frame.
00081     // Set the RTP 'M' ('marker') bit:
00082     setMarkerBit();
00083   }
00084 
00085   // Important: Also call our base class's doSpecialFrameHandling(),
00086   // to set the packet's timestamp:
00087   MultiFramedRTPSink::doSpecialFrameHandling(fragmentationOffset,
00088                                              frameStart, numBytesInFrame,
00089                                              framePresentationTime,
00090                                              numRemainingBytes);
00091 }
00092 
00093 char const* MPEG4LATMAudioRTPSink::auxSDPLine() {
00094   return fFmtpSDPLine;
00095 }

Generated on Thu May 17 07:11:47 2012 for live by  doxygen 1.5.2