| 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.// A filter that converts a MPEG Transport Stream file - with corresponding index file | 
| 18 | // - to a corresponding Video Elementary Stream.  It also uses a "scale" parameter | 
| 19 | // to implement 'trick mode' (fast forward or reverse play, using I-frames) on | 
| 20 | // the video stream. | 
| 21 | // C++ header | 
| 22 |  | 
| 23 | #ifndef _MPEG2_TRANSPORT_STREAM_TRICK_MODE_FILTER_HH | 
| 24 | #define _MPEG2_TRANSPORT_STREAM_TRICK_MODE_FILTER_HH | 
| 25 |  | 
| 26 | #ifndef _FRAMED_FILTER_HH | 
| 27 | #include "FramedFilter.hh" | 
| 28 | #endif | 
| 29 |  | 
| 30 | #ifndef _MPEG2_TRANSPORT_STREAM_INDEX_FILE_HH | 
| 31 | #include "MPEG2TransportStreamIndexFile.hh" | 
| 32 | #endif | 
| 33 |  | 
| 34 | #ifndef TRANSPORT_PACKET_SIZE | 
| 35 | #define TRANSPORT_PACKET_SIZE 188 | 
| 36 | #endif | 
| 37 |  | 
| 38 | class MPEG2TransportStreamTrickModeFilter: public FramedFilter { | 
| 39 | public: | 
| 40 |   static MPEG2TransportStreamTrickModeFilter* | 
| 41 |   createNew(UsageEnvironment& env, FramedSource* inputSource, | 
| 42 | 	    MPEG2TransportStreamIndexFile* indexFile, int scale); | 
| 43 |  | 
| 44 |   Boolean seekTo(unsigned long tsPacketNumber, unsigned long indexRecordNumber); | 
| 45 |  | 
| 46 |   unsigned long nextIndexRecordNum() const { return fNextIndexRecordNum; } | 
| 47 |  | 
| 48 |   void forgetInputSource() { fInputSource = NULL; } | 
| 49 |       // this lets us delete this without also deleting the input Transport Stream | 
| 50 |  | 
| 51 | protected: | 
| 52 |   MPEG2TransportStreamTrickModeFilter(UsageEnvironment& env, FramedSource* inputSource, | 
| 53 | 				      MPEG2TransportStreamIndexFile* indexFile, int scale); | 
| 54 |       // called only by createNew() | 
| 55 |   virtual ~MPEG2TransportStreamTrickModeFilter(); | 
| 56 |  | 
| 57 | private: | 
| 58 |   // Redefined virtual functions: | 
| 59 |   virtual void doGetNextFrame(); | 
| 60 |   virtual void doStopGettingFrames(); | 
| 61 |  | 
| 62 | private: | 
| 63 |   void attemptDeliveryToClient(); | 
| 64 |   void seekToTransportPacket(unsigned long tsPacketNum); | 
| 65 |   void readTransportPacket(unsigned long tsPacketNum); // asynchronously | 
| 66 |  | 
| 67 |   static void afterGettingFrame(void* clientData, unsigned frameSize, | 
| 68 | 				unsigned numTruncatedBytes, | 
| 69 | 				struct timeval presentationTime, | 
| 70 | 				unsigned durationInMicroseconds); | 
| 71 |   void afterGettingFrame1(unsigned frameSize); | 
| 72 |  | 
| 73 |   static void onSourceClosure(void* clientData); | 
| 74 |   void onSourceClosure1(); | 
| 75 |  | 
| 76 | private: | 
| 77 |   Boolean fHaveStarted; | 
| 78 |   MPEG2TransportStreamIndexFile* fIndexFile; | 
| 79 |   int fScale; // absolute value | 
| 80 |   int fDirection; // 1 => forward; -1 => reverse | 
| 81 |   enum { | 
| 82 |     SKIPPING_FRAME, | 
| 83 |     DELIVERING_SAVED_FRAME, | 
| 84 |     SAVING_AND_DELIVERING_FRAME | 
| 85 |   } fState; | 
| 86 |   unsigned fFrameCount; | 
| 87 |   unsigned long fNextIndexRecordNum; // next to be read from the index file | 
| 88 |   unsigned long fNextTSPacketNum; // next to be read from the transport stream file | 
| 89 |   unsigned char fInputBuffer[TRANSPORT_PACKET_SIZE]; | 
| 90 |   unsigned long fCurrentTSPacketNum; // corresponding to data currently in the buffer | 
| 91 |   unsigned long fDesiredTSPacketNum; | 
| 92 |   u_int8_t fDesiredDataOffset, fDesiredDataSize; | 
| 93 |   float fDesiredDataPCR, fFirstPCR; | 
| 94 |   unsigned long fSavedFrameIndexRecordStart; | 
| 95 |   unsigned long fSavedSequentialIndexRecordNum; | 
| 96 |   Boolean fUseSavedFrameNextTime; | 
| 97 | }; | 
| 98 |  | 
| 99 | #endif | 
| 100 |  |