liveMedia/include/MultiFramedRTPSink.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-2008 Live Networks, Inc.  All rights reserved.
00018 // RTP sink 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_SINK_HH
00023 #define _MULTI_FRAMED_RTP_SINK_HH
00024 
00025 #ifndef _RTP_SINK_HH
00026 #include "RTPSink.hh"
00027 #endif
00028 
00029 class MultiFramedRTPSink: public RTPSink {
00030 public:
00031   void setPacketSizes(unsigned preferredPacketSize, unsigned maxPacketSize);
00032 
00033 protected:
00034   MultiFramedRTPSink(UsageEnvironment& env,
00035                      Groupsock* rtpgs, unsigned char rtpPayloadType,
00036                      unsigned rtpTimestampFrequency,
00037                      char const* rtpPayloadFormatName,
00038                      unsigned numChannels = 1);
00039         // we're a virtual base class
00040 
00041   virtual ~MultiFramedRTPSink();
00042 
00043   virtual void doSpecialFrameHandling(unsigned fragmentationOffset,
00044                                       unsigned char* frameStart,
00045                                       unsigned numBytesInFrame,
00046                                       struct timeval frameTimestamp,
00047                                       unsigned numRemainingBytes);
00048       // perform any processing specific to the particular payload format
00049   virtual Boolean allowFragmentationAfterStart() const;
00050       // whether a frame can be fragmented if other frame(s) appear earlier
00051       // in the packet (by default: False)
00052   virtual Boolean allowOtherFramesAfterLastFragment() const;
00053       // whether other frames can be packed into a packet following the
00054       // final fragment of a previous, fragmented frame (by default: False)
00055   virtual Boolean frameCanAppearAfterPacketStart(unsigned char const* frameStart,
00056                                          unsigned numBytesInFrame) const;
00057       // whether this frame can appear in position >1 in a pkt (default: True)
00058   virtual unsigned specialHeaderSize() const;
00059       // returns the size of any special header used (following the RTP header)
00060   virtual unsigned frameSpecificHeaderSize() const;
00061       // returns the size of any frame-specific header used (before each frame
00062       // within the packet)
00063 
00064   // Functions that might be called by doSpecialFrameHandling():
00065   Boolean isFirstPacket() const { return fIsFirstPacket; }
00066   Boolean isFirstFrameInPacket() const { return fNumFramesUsedSoFar == 0; }
00067   Boolean curFragmentationOffset() const { return fCurFragmentationOffset; }
00068   void setMarkerBit();
00069   void setTimestamp(struct timeval timestamp);
00070   void setSpecialHeaderWord(unsigned word, /* 32 bits, in host order */
00071                             unsigned wordPosition = 0);
00072   void setSpecialHeaderBytes(unsigned char const* bytes, unsigned numBytes,
00073                              unsigned bytePosition = 0);
00074   void setFrameSpecificHeaderWord(unsigned word, /* 32 bits, in host order */
00075                                   unsigned wordPosition = 0);
00076   void setFrameSpecificHeaderBytes(unsigned char const* bytes, unsigned numBytes,
00077                                    unsigned bytePosition = 0);
00078   void setFramePadding(unsigned numPaddingBytes);
00079   unsigned numFramesUsedSoFar() const { return fNumFramesUsedSoFar; }
00080 
00081   unsigned ourMaxPacketSize() const { return fOurMaxPacketSize; }
00082 
00083 protected: // redefined virtual functions:
00084   virtual Boolean continuePlaying();
00085   virtual void stopPlaying();
00086 
00087 private:
00088   void buildAndSendPacket(Boolean isFirstPacket);
00089   void packFrame();
00090   void sendPacketIfNecessary();
00091   static void sendNext(void* firstArg);
00092   friend void sendNext(void*);
00093 
00094   static void afterGettingFrame(void* clientData,
00095                                 unsigned numBytesRead, unsigned numTruncatedBytes,
00096                                 struct timeval presentationTime,
00097                                 unsigned durationInMicroseconds);
00098   void afterGettingFrame1(unsigned numBytesRead, unsigned numTruncatedBytes,
00099                           struct timeval presentationTime,
00100                           unsigned durationInMicroseconds);
00101   Boolean isTooBigForAPacket(unsigned numBytes) const;
00102 
00103   static void ourHandleClosure(void* clientData);
00104 
00105 private:
00106   OutPacketBuffer* fOutBuf;
00107 
00108   Boolean fNoFramesLeft;
00109   unsigned fNumFramesUsedSoFar;
00110   unsigned fCurFragmentationOffset;
00111   Boolean fPreviousFrameEndedFragmentation;
00112 
00113   Boolean fIsFirstPacket;
00114   struct timeval fNextSendTime;
00115   unsigned fTimestampPosition;
00116   unsigned fSpecialHeaderPosition;
00117   unsigned fSpecialHeaderSize; // size in bytes of any special header used
00118   unsigned fCurFrameSpecificHeaderPosition;
00119   unsigned fCurFrameSpecificHeaderSize; // size in bytes of cur frame-specific header
00120   unsigned fTotalFrameSpecificHeaderSizes; // size of all frame-specific hdrs in pkt
00121   unsigned fOurMaxPacketSize;
00122 };
00123 
00124 #endif

Generated on Tue Oct 7 15:38:09 2008 for live by  doxygen 1.5.2