liveMedia/include/MediaSink.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 // Media Sinks
00019 // C++ header
00020 
00021 #ifndef _MEDIA_SINK_HH
00022 #define _MEDIA_SINK_HH
00023 
00024 #ifndef _FRAMED_SOURCE_HH
00025 #include "FramedSource.hh"
00026 #endif
00027 
00028 class MediaSink: public Medium {
00029 public:
00030   static Boolean lookupByName(UsageEnvironment& env, char const* sinkName,
00031                               MediaSink*& resultSink);
00032 
00033   typedef void (afterPlayingFunc)(void* clientData);
00034   Boolean startPlaying(MediaSource& source,
00035                        afterPlayingFunc* afterFunc,
00036                        void* afterClientData);
00037   virtual void stopPlaying();
00038 
00039   // Test for specific types of sink:
00040   virtual Boolean isRTPSink() const;
00041 
00042   FramedSource* source() const {return fSource;}
00043 
00044 protected:
00045   MediaSink(UsageEnvironment& env); // abstract base class
00046   virtual ~MediaSink();
00047 
00048   virtual Boolean sourceIsCompatibleWithUs(MediaSource& source);
00049       // called by startPlaying()
00050   virtual Boolean continuePlaying() = 0;
00051       // called by startPlaying()
00052 
00053   static void onSourceClosure(void* clientData);
00054       // should be called (on ourselves) by continuePlaying() when it
00055       // discovers that the source we're playing from has closed.
00056 
00057   FramedSource* fSource;
00058 
00059 private:
00060   // redefined virtual functions:
00061   virtual Boolean isSink() const;
00062 
00063 private:
00064   // The following fields are used when we're being played:
00065   afterPlayingFunc* fAfterFunc;
00066   void* fAfterClientData;
00067 };
00068 
00069 // A data structure that a sink may use for an output packet:
00070 class OutPacketBuffer {
00071 public:
00072   OutPacketBuffer(unsigned preferredPacketSize, unsigned maxPacketSize);
00073   ~OutPacketBuffer();
00074 
00075   static unsigned maxSize;
00076 
00077   unsigned char* curPtr() const {return &fBuf[fPacketStart + fCurOffset];}
00078   unsigned totalBytesAvailable() const {
00079     return fLimit - (fPacketStart + fCurOffset);
00080   }
00081   unsigned totalBufferSize() const { return fLimit; }
00082   unsigned char* packet() const {return &fBuf[fPacketStart];}
00083   unsigned curPacketSize() const {return fCurOffset;}
00084 
00085   void increment(unsigned numBytes) {fCurOffset += numBytes;}
00086 
00087   void enqueue(unsigned char const* from, unsigned numBytes);
00088   void enqueueWord(u_int32_t word);
00089   void insert(unsigned char const* from, unsigned numBytes, unsigned toPosition);
00090   void insertWord(u_int32_t word, unsigned toPosition);
00091   void extract(unsigned char* to, unsigned numBytes, unsigned fromPosition);
00092   u_int32_t extractWord(unsigned fromPosition);
00093 
00094   void skipBytes(unsigned numBytes);
00095 
00096   Boolean isPreferredSize() const {return fCurOffset >= fPreferred;}
00097   Boolean wouldOverflow(unsigned numBytes) const {
00098     return (fCurOffset+numBytes) > fMax;
00099   }
00100   unsigned numOverflowBytes(unsigned numBytes) const {
00101     return (fCurOffset+numBytes) - fMax;
00102   }
00103   Boolean isTooBigForAPacket(unsigned numBytes) const {
00104     return numBytes > fMax;
00105   }
00106 
00107   void setOverflowData(unsigned overflowDataOffset,
00108                        unsigned overflowDataSize,
00109                        struct timeval const& presentationTime,
00110                        unsigned durationInMicroseconds);
00111   unsigned overflowDataSize() const {return fOverflowDataSize;}
00112   struct timeval overflowPresentationTime() const {return fOverflowPresentationTime;}
00113   unsigned overflowDurationInMicroseconds() const {return fOverflowDurationInMicroseconds;}
00114   Boolean haveOverflowData() const {return fOverflowDataSize > 0;}
00115   void useOverflowData();
00116 
00117   void adjustPacketStart(unsigned numBytes);
00118   void resetPacketStart();
00119   void resetOffset() { fCurOffset = 0; }
00120   void resetOverflowData() { fOverflowDataOffset = fOverflowDataSize = 0; }
00121 
00122 private:
00123   unsigned fPacketStart, fCurOffset, fPreferred, fMax, fLimit;
00124   unsigned char* fBuf;
00125 
00126   unsigned fOverflowDataOffset, fOverflowDataSize;
00127   struct timeval fOverflowPresentationTime;
00128   unsigned fOverflowDurationInMicroseconds;
00129 };
00130 
00131 #endif

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