liveMedia/include/MPEG2TransportFileServerMediaSubsession.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 // A 'ServerMediaSubsession' object that creates new, unicast, "RTPSink"s
00019 // on demand, from a MPEG-2 Transport Stream file.
00020 // C++ header
00021 
00022 #ifndef _MPEG2_TRANSPORT_FILE_SERVER_MEDIA_SUBSESSION_HH
00023 #define _MPEG2_TRANSPORT_FILE_SERVER_MEDIA_SUBSESSION_HH
00024 
00025 #ifndef _FILE_SERVER_MEDIA_SUBSESSION_HH
00026 #include "FileServerMediaSubsession.hh"
00027 #endif
00028 #ifndef _MPEG2_TRANSPORT_STREAM_FRAMER_HH
00029 #include "MPEG2TransportStreamFramer.hh"
00030 #endif
00031 #ifndef _BYTE_STREAM_FILE_SOURCE_HH
00032 #include "ByteStreamFileSource.hh"
00033 #endif
00034 #ifndef _MPEG2_TRANSPORT_STREAM_TRICK_MODE_FILTER_HH
00035 #include "MPEG2TransportStreamTrickModeFilter.hh"
00036 #endif
00037 #ifndef _MPEG2_TRANSPORT_STREAM_FROM_ES_SOURCE_HH
00038 #include "MPEG2TransportStreamFromESSource.hh"
00039 #endif
00040 
00041 class ClientTrickPlayState; // forward
00042 
00043 class MPEG2TransportFileServerMediaSubsession: public FileServerMediaSubsession{
00044 public:
00045   static MPEG2TransportFileServerMediaSubsession*
00046   createNew(UsageEnvironment& env,
00047             char const* dataFileName, char const* indexFileName,
00048             Boolean reuseFirstSource);
00049 
00050 protected:
00051   MPEG2TransportFileServerMediaSubsession(UsageEnvironment& env,
00052                                           char const* fileName,
00053                                           MPEG2TransportStreamIndexFile* indexFile,
00054                                           Boolean reuseFirstSource);
00055       // called only by createNew();
00056   virtual ~MPEG2TransportFileServerMediaSubsession();
00057 
00058   virtual ClientTrickPlayState* newClientTrickPlayState();
00059 
00060 private: // redefined virtual functions
00061   // Note that because - to implement 'trick play' operations - we're operating on
00062   // more than just the input source, we reimplement some functions that are
00063   // already implemented in "OnDemandServerMediaSubsession", rather than
00064   // reimplementing "seekStreamSource()" and "setStreamSourceScale()":
00065   virtual void startStream(unsigned clientSessionId, void* streamToken,
00066                            TaskFunc* rtcpRRHandler,
00067                            void* rtcpRRHandlerClientData,
00068                            unsigned short& rtpSeqNum,
00069                            unsigned& rtpTimestamp,
00070                            ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
00071                            void* serverRequestAlternativeByteHandlerClientData);
00072   virtual void pauseStream(unsigned clientSessionId, void* streamToken);
00073   virtual void seekStream(unsigned clientSessionId, void* streamToken, double& seekNPT, double streamDuration, u_int64_t& numBytes);
00074   virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale);
00075   virtual void deleteStream(unsigned clientSessionId, void*& streamToken);
00076 
00077   // The virtual functions thare are usually implemented by "ServerMediaSubsession"s:
00078   virtual FramedSource* createNewStreamSource(unsigned clientSessionId,
00079                                               unsigned& estBitrate);
00080   virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock,
00081                                     unsigned char rtpPayloadTypeIfDynamic,
00082                                     FramedSource* inputSource);
00083 
00084   virtual void testScaleFactor(float& scale);
00085   virtual float duration() const;
00086 
00087 private:
00088   ClientTrickPlayState* lookupClient(unsigned clientSessionId);
00089 
00090 private:
00091   MPEG2TransportStreamIndexFile* fIndexFile;
00092   float fDuration;
00093   HashTable* fClientSessionHashTable; // indexed by client session id
00094 };
00095 
00096 
00097 // This class encapsulates the 'trick play' state for each current client (for
00098 // a given "MPEG2TransportFileServerMediaSubsession" - i.e., Transport Stream file).
00099 // It is used only within the implementation of "MPEG2TransportFileServerMediaSubsession", but is included here,
00100 // in case subclasses of "MPEG2TransportFileServerMediaSubsession" want to use it.
00101 
00102 class ClientTrickPlayState {
00103 public:
00104   ClientTrickPlayState(MPEG2TransportStreamIndexFile* indexFile);
00105 
00106   // Functions to bring "fNPT", "fTSRecordNum" and "fIxRecordNum" in sync:
00107   unsigned long updateStateFromNPT(double npt, double seekDuration);
00108   void updateStateOnScaleChange();
00109   void updateStateOnPlayChange(Boolean reverseToPreviousVSH);
00110 
00111   void handleStreamDeletion();
00112   void setSource(MPEG2TransportStreamFramer* framer);
00113 
00114   void setNextScale(float nextScale) { fNextScale = nextScale; }
00115   Boolean areChangingScale() const { return fNextScale != fScale; }
00116 
00117 protected:
00118   void updateTSRecordNum();
00119   void reseekOriginalTransportStreamSource();
00120 
00121 protected:
00122   MPEG2TransportStreamIndexFile* fIndexFile;
00123   ByteStreamFileSource* fOriginalTransportStreamSource;
00124   MPEG2TransportStreamTrickModeFilter* fTrickModeFilter;
00125   MPEG2TransportStreamFromESSource* fTrickPlaySource;
00126   MPEG2TransportStreamFramer* fFramer;
00127   float fScale, fNextScale, fNPT;
00128   unsigned long fTSRecordNum, fIxRecordNum;
00129 };
00130 
00131 #endif

Generated on Thu May 30 08:12:57 2013 for live by  doxygen 1.5.2