liveMedia/include/H264VideoRTPSink.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-2012 Live Networks, Inc.  All rights reserved.
00018 // RTP sink for H.264 video (RFC 3984)
00019 // C++ header
00020 
00021 #ifndef _H264_VIDEO_RTP_SINK_HH
00022 #define _H264_VIDEO_RTP_SINK_HH
00023 
00024 #ifndef _VIDEO_RTP_SINK_HH
00025 #include "VideoRTPSink.hh"
00026 #endif
00027 #ifndef _FRAMED_FILTER_HH
00028 #include "FramedFilter.hh"
00029 #endif
00030 
00031 class H264FUAFragmenter;
00032 
00033 class H264VideoRTPSink: public VideoRTPSink {
00034 public:
00035   static H264VideoRTPSink* createNew(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat);
00036   static H264VideoRTPSink* createNew(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat,
00037                                      u_int8_t const* sps, unsigned spsSize, u_int8_t const* pps, unsigned ppsSize);
00038     // an optional variant of "createNew()", useful if we know, in advance, the stream's SPS and PPL NAL units.
00039   static H264VideoRTPSink* createNew(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat,
00040                                      char const* sPropParameterSetsStr);
00041     // an optional variant of "createNew()", useful if we know, in advance, the stream's SPS and PPL NAL units.
00042 
00043 protected:
00044   H264VideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat,
00045                    u_int8_t const* sps = NULL, unsigned spsSize = 0, u_int8_t const* pps = NULL, unsigned ppsSize = 0);
00046         // called only by createNew()
00047 
00048   virtual ~H264VideoRTPSink();
00049 
00050 protected: // redefined virtual functions:
00051   virtual char const* auxSDPLine();
00052 
00053 private: // redefined virtual functions:
00054   virtual Boolean sourceIsCompatibleWithUs(MediaSource& source);
00055   virtual Boolean continuePlaying();
00056   virtual void doSpecialFrameHandling(unsigned fragmentationOffset,
00057                                       unsigned char* frameStart,
00058                                       unsigned numBytesInFrame,
00059                                       struct timeval framePresentationTime,
00060                                       unsigned numRemainingBytes);
00061   virtual Boolean frameCanAppearAfterPacketStart(unsigned char const* frameStart,
00062                                                  unsigned numBytesInFrame) const;
00063 
00064 protected:
00065   H264FUAFragmenter* fOurFragmenter;
00066 
00067 private:
00068   char* fFmtpSDPLine;
00069   u_int8_t* fSPS; unsigned fSPSSize; u_int8_t* fPPS; unsigned fPPSSize;
00070 };
00071 
00072 
00074 
00075 // Because of the ideosyncracies of the H.264 RTP payload format, we implement
00076 // "H264VideoRTPSink" using a separate "H264FUAFragmenter" class that delivers,
00077 // to the "H264VideoRTPSink", only fragments that will fit within an outgoing
00078 // RTP packet.  I.e., we implement fragmentation in this separate "H264FUAFragmenter"
00079 // class, rather than in "H264VideoRTPSink".
00080 // (Note: This class should be used only by "H264VideoRTPSink", or a subclass.)
00081 
00082 class H264FUAFragmenter: public FramedFilter {
00083 public:
00084   H264FUAFragmenter(UsageEnvironment& env, FramedSource* inputSource,
00085                     unsigned inputBufferMax, unsigned maxOutputPacketSize);
00086   virtual ~H264FUAFragmenter();
00087 
00088   Boolean lastFragmentCompletedNALUnit() const { return fLastFragmentCompletedNALUnit; }
00089 
00090 private: // redefined virtual functions:
00091   virtual void doGetNextFrame();
00092 
00093 private:
00094   static void afterGettingFrame(void* clientData, unsigned frameSize,
00095                                 unsigned numTruncatedBytes,
00096                                 struct timeval presentationTime,
00097                                 unsigned durationInMicroseconds);
00098   void afterGettingFrame1(unsigned frameSize,
00099                           unsigned numTruncatedBytes,
00100                           struct timeval presentationTime,
00101                           unsigned durationInMicroseconds);
00102 
00103 private:
00104   unsigned fInputBufferSize;
00105   unsigned fMaxOutputPacketSize;
00106   unsigned char* fInputBuffer;
00107   unsigned fNumValidDataBytes;
00108   unsigned fCurDataOffset;
00109   unsigned fSaveNumTruncatedBytes;
00110   Boolean fLastFragmentCompletedNALUnit;
00111 };
00112 
00113 
00114 #endif

Generated on Thu May 10 20:25:11 2012 for live by  doxygen 1.5.2