liveMedia/DVVideoRTPSink.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-2013 Live Networks, Inc.  All rights reserved.
00018 // RTP sink for DV video (RFC 3189)
00019 // (Thanks to Ben Hutchings for prototyping this.)
00020 // Implementation
00021 
00022 #include "DVVideoRTPSink.hh"
00023 
00025 
00026 DVVideoRTPSink
00027 ::DVVideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat)
00028   : VideoRTPSink(env, RTPgs, rtpPayloadFormat, 90000, "DV"),
00029     fFmtpSDPLine(NULL) {
00030 }
00031 
00032 DVVideoRTPSink::~DVVideoRTPSink() {
00033   delete[] fFmtpSDPLine;
00034 }
00035 
00036 DVVideoRTPSink*
00037 DVVideoRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat) {
00038   return new DVVideoRTPSink(env, RTPgs, rtpPayloadFormat);
00039 }
00040 
00041 Boolean DVVideoRTPSink::sourceIsCompatibleWithUs(MediaSource& source) {
00042   // Our source must be an appropriate framer:
00043   return source.isDVVideoStreamFramer();
00044 }
00045 
00046 void DVVideoRTPSink::doSpecialFrameHandling(unsigned fragmentationOffset,
00047                                               unsigned char* /*frameStart*/,
00048                                               unsigned /*numBytesInFrame*/,
00049                                               struct timeval framePresentationTime,
00050                                               unsigned numRemainingBytes) {
00051   if (numRemainingBytes == 0) {
00052     // This packet contains the last (or only) fragment of the frame.
00053     // Set the RTP 'M' ('marker') bit:
00054     setMarkerBit();
00055   }
00056 
00057   // Also set the RTP timestamp:
00058   setTimestamp(framePresentationTime);
00059 }
00060 
00061 unsigned DVVideoRTPSink::computeOverflowForNewFrame(unsigned newFrameSize) const {
00062   unsigned initialOverflow = MultiFramedRTPSink::computeOverflowForNewFrame(newFrameSize);
00063 
00064   // Adjust (increase) this overflow, if necessary, so that the amount of frame data that we use is an integral number
00065   // of DIF blocks:
00066   unsigned numFrameBytesUsed = newFrameSize - initialOverflow;
00067   initialOverflow += numFrameBytesUsed%DV_DIF_BLOCK_SIZE;
00068 
00069   return initialOverflow;
00070 }
00071 
00072 char const* DVVideoRTPSink::auxSDPLine() {
00073   // Generate a new "a=fmtp:" line each time, using parameters from
00074   // our framer source (in case they've changed since the last time that
00075   // we were called):
00076   DVVideoStreamFramer* framerSource = (DVVideoStreamFramer*)fSource;
00077   if (framerSource == NULL) return NULL; // we don't yet have a source
00078 
00079   return auxSDPLineFromFramer(framerSource);
00080 }
00081 
00082 char const* DVVideoRTPSink::auxSDPLineFromFramer(DVVideoStreamFramer* framerSource) {
00083   char const* const profileName = framerSource->profileName();
00084   if (profileName == NULL) return NULL;
00085 
00086   char const* const fmtpSDPFmt = "a=fmtp:%d encode=%s;audio=bundled\r\n";
00087   unsigned fmtpSDPFmtSize = strlen(fmtpSDPFmt)
00088     + 3 // max payload format code length
00089     + strlen(profileName);
00090   delete[] fFmtpSDPLine; // if it already exists
00091   fFmtpSDPLine = new char[fmtpSDPFmtSize];  
00092   sprintf(fFmtpSDPLine, fmtpSDPFmt, rtpPayloadType(), profileName);
00093 
00094   return fFmtpSDPLine;
00095 }

Generated on Tue Jun 18 13:16:50 2013 for live by  doxygen 1.5.2