| 1 | /********** |
| 2 | This library is free software; you can redistribute it and/or modify it under |
| 3 | the terms of the GNU Lesser General Public License as published by the |
| 4 | Free Software Foundation; either version 3 of the License, or (at your |
| 5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) |
| 6 | |
| 7 | This library is distributed in the hope that it will be useful, but WITHOUT |
| 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 10 | more details. |
| 11 | |
| 12 | You should have received a copy of the GNU Lesser General Public License |
| 13 | along with this library; if not, write to the Free Software Foundation, Inc., |
| 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | **********/ |
| 16 | // "liveMedia" |
| 17 | // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved. |
| 18 | // A 'ServerMediaSubsession' object that creates new, unicast, "RTPSink"s |
| 19 | // on demand, from a MPEG-2 Transport Stream file. |
| 20 | // C++ header |
| 21 | |
| 22 | #ifndef _MPEG2_TRANSPORT_FILE_SERVER_MEDIA_SUBSESSION_HH |
| 23 | #define _MPEG2_TRANSPORT_FILE_SERVER_MEDIA_SUBSESSION_HH |
| 24 | |
| 25 | #ifndef _FILE_SERVER_MEDIA_SUBSESSION_HH |
| 26 | #include "FileServerMediaSubsession.hh" |
| 27 | #endif |
| 28 | #ifndef _MPEG2_TRANSPORT_STREAM_FRAMER_HH |
| 29 | #include "MPEG2TransportStreamFramer.hh" |
| 30 | #endif |
| 31 | #ifndef _BYTE_STREAM_FILE_SOURCE_HH |
| 32 | #include "ByteStreamFileSource.hh" |
| 33 | #endif |
| 34 | #ifndef _MPEG2_TRANSPORT_STREAM_TRICK_MODE_FILTER_HH |
| 35 | #include "MPEG2TransportStreamTrickModeFilter.hh" |
| 36 | #endif |
| 37 | #ifndef _MPEG2_TRANSPORT_STREAM_FROM_ES_SOURCE_HH |
| 38 | #include "MPEG2TransportStreamFromESSource.hh" |
| 39 | #endif |
| 40 | |
| 41 | class ClientTrickPlayState; // forward |
| 42 | |
| 43 | class MPEG2TransportFileServerMediaSubsession: public FileServerMediaSubsession { |
| 44 | public: |
| 45 | static MPEG2TransportFileServerMediaSubsession* |
| 46 | createNew(UsageEnvironment& env, |
| 47 | char const* dataFileName, char const* indexFileName, |
| 48 | Boolean reuseFirstSource); |
| 49 | |
| 50 | protected: |
| 51 | MPEG2TransportFileServerMediaSubsession(UsageEnvironment& env, |
| 52 | char const* fileName, |
| 53 | MPEG2TransportStreamIndexFile* indexFile, |
| 54 | Boolean reuseFirstSource); |
| 55 | // called only by createNew(); |
| 56 | virtual ~MPEG2TransportFileServerMediaSubsession(); |
| 57 | |
| 58 | virtual ClientTrickPlayState* newClientTrickPlayState(); |
| 59 | |
| 60 | private: // redefined virtual functions |
| 61 | // Note that because - to implement 'trick play' operations - we're operating on |
| 62 | // more than just the input source, we reimplement some functions that are |
| 63 | // already implemented in "OnDemandServerMediaSubsession", rather than |
| 64 | // reimplementing "seekStreamSource()" and "setStreamSourceScale()": |
| 65 | virtual void startStream(unsigned clientSessionId, void* streamToken, |
| 66 | TaskFunc* rtcpRRHandler, |
| 67 | void* rtcpRRHandlerClientData, |
| 68 | unsigned short& rtpSeqNum, |
| 69 | unsigned& rtpTimestamp, |
| 70 | ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler, |
| 71 | void* serverRequestAlternativeByteHandlerClientData); |
| 72 | virtual void pauseStream(unsigned clientSessionId, void* streamToken); |
| 73 | virtual void seekStream(unsigned clientSessionId, void* streamToken, double& seekNPT, double streamDuration, u_int64_t& numBytes); |
| 74 | virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale); |
| 75 | virtual void deleteStream(unsigned clientSessionId, void*& streamToken); |
| 76 | |
| 77 | // The virtual functions that are usually implemented by "ServerMediaSubsession"s: |
| 78 | virtual FramedSource* createNewStreamSource(unsigned clientSessionId, |
| 79 | unsigned& estBitrate); |
| 80 | virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock, |
| 81 | unsigned char rtpPayloadTypeIfDynamic, |
| 82 | FramedSource* inputSource); |
| 83 | |
| 84 | virtual void testScaleFactor(float& scale); |
| 85 | virtual float duration() const; |
| 86 | |
| 87 | private: |
| 88 | ClientTrickPlayState* lookupClient(unsigned clientSessionId); |
| 89 | |
| 90 | private: |
| 91 | MPEG2TransportStreamIndexFile* fIndexFile; |
| 92 | float fDuration; |
| 93 | HashTable* fClientSessionHashTable; // indexed by client session id |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | // This class encapsulates the 'trick play' state for each current client (for |
| 98 | // a given "MPEG2TransportFileServerMediaSubsession" - i.e., Transport Stream file). |
| 99 | // It is used only within the implementation of "MPEG2TransportFileServerMediaSubsession", but is included here, |
| 100 | // in case subclasses of "MPEG2TransportFileServerMediaSubsession" want to use it. |
| 101 | |
| 102 | class ClientTrickPlayState { |
| 103 | public: |
| 104 | ClientTrickPlayState(MPEG2TransportStreamIndexFile* indexFile); |
| 105 | |
| 106 | // Functions to bring "fNPT", "fTSRecordNum" and "fIxRecordNum" in sync: |
| 107 | unsigned long updateStateFromNPT(double npt, double seekDuration); |
| 108 | void updateStateOnScaleChange(); |
| 109 | void updateStateOnPlayChange(Boolean reverseToPreviousVSH); |
| 110 | |
| 111 | void handleStreamDeletion(); |
| 112 | void setSource(MPEG2TransportStreamFramer* framer); |
| 113 | |
| 114 | void setNextScale(float nextScale) { fNextScale = nextScale; } |
| 115 | Boolean areChangingScale() const { return fNextScale != fScale; } |
| 116 | |
| 117 | protected: |
| 118 | void updateTSRecordNum(); |
| 119 | void reseekOriginalTransportStreamSource(); |
| 120 | |
| 121 | protected: |
| 122 | MPEG2TransportStreamIndexFile* fIndexFile; |
| 123 | ByteStreamFileSource* fOriginalTransportStreamSource; |
| 124 | MPEG2TransportStreamTrickModeFilter* fTrickModeFilter; |
| 125 | MPEG2TransportStreamFromESSource* fTrickPlaySource; |
| 126 | MPEG2TransportStreamFramer* fFramer; |
| 127 | float fScale, fNextScale, fNPT; |
| 128 | unsigned long fTSRecordNum, fIxRecordNum; |
| 129 | }; |
| 130 | |
| 131 | #endif |
| 132 | |