liveMedia/include/MultiFramedRTPSource.hh

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 source for a common kind of payload format: Those which pack multiple,
00019 // complete codec frames (as many as possible) into each RTP packet.
00020 // C++ header
00021 
00022 #ifndef _MULTI_FRAMED_RTP_SOURCE_HH
00023 #define _MULTI_FRAMED_RTP_SOURCE_HH
00024 
00025 #ifndef _RTP_SOURCE_HH
00026 #include "RTPSource.hh"
00027 #endif
00028 
00029 class BufferedPacket; // forward
00030 class BufferedPacketFactory; // forward
00031 
00032 class MultiFramedRTPSource: public RTPSource {
00033 protected:
00034   MultiFramedRTPSource(UsageEnvironment& env, Groupsock* RTPgs,
00035                        unsigned char rtpPayloadFormat,
00036                        unsigned rtpTimestampFrequency,
00037                        BufferedPacketFactory* packetFactory = NULL);
00038       // virtual base class
00039   virtual ~MultiFramedRTPSource();
00040 
00041   virtual Boolean processSpecialHeader(BufferedPacket* packet,
00042                                        unsigned& resultSpecialHeaderSize);
00043       // Subclasses redefine this to handle any special, payload format
00044       // specific header that follows the RTP header.
00045 
00046   virtual Boolean packetIsUsableInJitterCalculation(unsigned char* packet,
00047                                                     unsigned packetSize);
00048       // The default implementation returns True, but this can be redefined
00049 
00050 protected:
00051   Boolean fCurrentPacketBeginsFrame;
00052   Boolean fCurrentPacketCompletesFrame;
00053 
00054 protected:
00055   // redefined virtual functions:
00056   virtual void doStopGettingFrames();
00057 
00058 private:
00059   // redefined virtual functions:
00060   virtual void doGetNextFrame();
00061   virtual void setPacketReorderingThresholdTime(unsigned uSeconds);
00062 
00063 private:
00064   void reset();
00065   void doGetNextFrame1();
00066 
00067   static void networkReadHandler(MultiFramedRTPSource* source, int /*mask*/);
00068   void networkReadHandler1();
00069 
00070   Boolean fAreDoingNetworkReads;
00071   BufferedPacket* fPacketReadInProgress;
00072   Boolean fNeedDelivery;
00073   Boolean fPacketLossInFragmentedFrame;
00074   unsigned char* fSavedTo;
00075   unsigned fSavedMaxSize;
00076 
00077   // A buffer to (optionally) hold incoming pkts that have been reorderered
00078   class ReorderingPacketBuffer* fReorderingBuffer;
00079 };
00080 
00081 
00082 // A 'packet data' class that's used to implement the above.
00083 // Note that this can be subclassed - if desired - to redefine
00084 // "nextEnclosedFrameSize()".
00085 
00086 class BufferedPacket {
00087 public:
00088   BufferedPacket();
00089   virtual ~BufferedPacket();
00090 
00091   Boolean hasUsableData() const { return fTail > fHead; }
00092   unsigned useCount() const { return fUseCount; }
00093 
00094   Boolean fillInData(RTPInterface& rtpInterface, Boolean& packetReadWasIncomplete);
00095   void assignMiscParams(unsigned short rtpSeqNo, unsigned rtpTimestamp,
00096                         struct timeval presentationTime,
00097                         Boolean hasBeenSyncedUsingRTCP,
00098                         Boolean rtpMarkerBit, struct timeval timeReceived);
00099   void skip(unsigned numBytes); // used to skip over an initial header
00100   void removePadding(unsigned numBytes); // used to remove trailing bytes
00101   void appendData(unsigned char* newData, unsigned numBytes);
00102   void use(unsigned char* to, unsigned toSize,
00103            unsigned& bytesUsed, unsigned& bytesTruncated,
00104            unsigned short& rtpSeqNo, unsigned& rtpTimestamp,
00105            struct timeval& presentationTime,
00106            Boolean& hasBeenSyncedUsingRTCP, Boolean& rtpMarkerBit);
00107 
00108   BufferedPacket*& nextPacket() { return fNextPacket; }
00109 
00110   unsigned short rtpSeqNo() const { return fRTPSeqNo; }
00111   struct timeval const& timeReceived() const { return fTimeReceived; }
00112 
00113   unsigned char* data() const { return &fBuf[fHead]; }
00114   unsigned dataSize() const { return fTail-fHead; }
00115   Boolean rtpMarkerBit() const { return fRTPMarkerBit; }
00116   Boolean& isFirstPacket() { return fIsFirstPacket; }
00117   unsigned bytesAvailable() const { return fPacketSize - fTail; }
00118 
00119 protected:
00120   virtual void reset();
00121   virtual unsigned nextEnclosedFrameSize(unsigned char*& framePtr,
00122                                          unsigned dataSize);
00123       // The above function has been deprecated.  Instead, new subclasses should use:
00124   virtual void getNextEnclosedFrameParameters(unsigned char*& framePtr,
00125                                               unsigned dataSize,
00126                                               unsigned& frameSize,
00127                                               unsigned& frameDurationInMicroseconds);
00128 
00129   unsigned fPacketSize;
00130   unsigned char* fBuf;
00131   unsigned fHead;
00132   unsigned fTail;
00133 
00134 private:
00135   BufferedPacket* fNextPacket; // used to link together packets
00136 
00137   unsigned fUseCount;
00138   unsigned short fRTPSeqNo;
00139   unsigned fRTPTimestamp;
00140   struct timeval fPresentationTime; // corresponding to "fRTPTimestamp"
00141   Boolean fHasBeenSyncedUsingRTCP;
00142   Boolean fRTPMarkerBit;
00143   Boolean fIsFirstPacket;
00144   struct timeval fTimeReceived;
00145 };
00146 
00147 // A 'factory' class for creating "BufferedPacket" objects.
00148 // If you want to subclass "BufferedPacket", then you'll also
00149 // want to subclass this, to redefine createNewPacket()
00150 
00151 class BufferedPacketFactory {
00152 public:
00153   BufferedPacketFactory();
00154   virtual ~BufferedPacketFactory();
00155 
00156   virtual BufferedPacket* createNewPacket(MultiFramedRTPSource* ourSource);
00157 };
00158 
00159 #endif

Generated on Mon Apr 29 13:28:01 2013 for live by  doxygen 1.5.2