liveMedia/SimpleRTPSink.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 // A simple RTP sink that packs frames into each outgoing
00019 //     packet, without any fragmentation or special headers.
00020 // Implementation
00021 
00022 #include "SimpleRTPSink.hh"
00023 
00024 SimpleRTPSink::SimpleRTPSink(UsageEnvironment& env, Groupsock* RTPgs,
00025                              unsigned char rtpPayloadFormat,
00026                              unsigned rtpTimestampFrequency,
00027                              char const* sdpMediaTypeString,
00028                              char const* rtpPayloadFormatName,
00029                              unsigned numChannels,
00030                              Boolean allowMultipleFramesPerPacket,
00031                              Boolean doNormalMBitRule)
00032   : MultiFramedRTPSink(env, RTPgs, rtpPayloadFormat,
00033                        rtpTimestampFrequency, rtpPayloadFormatName,
00034                        numChannels),
00035     fAllowMultipleFramesPerPacket(allowMultipleFramesPerPacket) {
00036   fSDPMediaTypeString
00037     = strDup(sdpMediaTypeString == NULL ? "unknown" : sdpMediaTypeString);
00038   fSetMBitOnLastFrames
00039     = strcmp(fSDPMediaTypeString, "video") == 0 && doNormalMBitRule;
00040 }
00041 
00042 SimpleRTPSink::~SimpleRTPSink() {
00043   delete[] (char*)fSDPMediaTypeString;
00044 }
00045 
00046 SimpleRTPSink*
00047 SimpleRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs,
00048                          unsigned char rtpPayloadFormat,
00049                          unsigned rtpTimestampFrequency,
00050                          char const* sdpMediaTypeString,
00051                          char const* rtpPayloadFormatName,
00052                          unsigned numChannels,
00053                          Boolean allowMultipleFramesPerPacket,
00054                          Boolean doNormalMBitRule) {
00055   return new SimpleRTPSink(env, RTPgs,
00056                            rtpPayloadFormat, rtpTimestampFrequency,
00057                            sdpMediaTypeString, rtpPayloadFormatName,
00058                            numChannels,
00059                            allowMultipleFramesPerPacket,
00060                            doNormalMBitRule);
00061 }
00062 
00063 void SimpleRTPSink::doSpecialFrameHandling(unsigned fragmentationOffset,
00064                                            unsigned char* frameStart,
00065                                            unsigned numBytesInFrame,
00066                                            struct timeval framePresentationTime,
00067                                            unsigned numRemainingBytes) {
00068   if (numRemainingBytes == 0) {
00069     // This packet contains the last (or only) fragment of the frame.
00070     // Set the RTP 'M' ('marker') bit, if appropriate:
00071     if (fSetMBitOnLastFrames) setMarkerBit();
00072   }
00073 
00074   // Important: Also call our base class's doSpecialFrameHandling(),
00075   // to set the packet's timestamp:
00076   MultiFramedRTPSink::doSpecialFrameHandling(fragmentationOffset,
00077                                              frameStart, numBytesInFrame,
00078                                              framePresentationTime,
00079                                              numRemainingBytes);
00080 }
00081 
00082 Boolean SimpleRTPSink::
00083 frameCanAppearAfterPacketStart(unsigned char const* /*frameStart*/,
00084                                unsigned /*numBytesInFrame*/) const {
00085   return fAllowMultipleFramesPerPacket;
00086 }
00087 
00088 char const* SimpleRTPSink::sdpMediaType() const {
00089   return fSDPMediaTypeString;
00090 }

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