pans
2017-08-30 71c92f101b6c8b4a678a8c3cfe2d8edbf488efa4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**********
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
 
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
more details.
 
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
**********/
// "liveMedia"
// Copyright (c) 1996-2017 Live Networks, Inc.  All rights reserved.// A filter that converts a MPEG Transport Stream file - with corresponding index file
// - to a corresponding Video Elementary Stream.  It also uses a "scale" parameter
// to implement 'trick mode' (fast forward or reverse play, using I-frames) on
// the video stream.
// C++ header
 
#ifndef _MPEG2_TRANSPORT_STREAM_TRICK_MODE_FILTER_HH
#define _MPEG2_TRANSPORT_STREAM_TRICK_MODE_FILTER_HH
 
#ifndef _FRAMED_FILTER_HH
#include "FramedFilter.hh"
#endif
 
#ifndef _MPEG2_TRANSPORT_STREAM_INDEX_FILE_HH
#include "MPEG2TransportStreamIndexFile.hh"
#endif
 
#ifndef TRANSPORT_PACKET_SIZE
#define TRANSPORT_PACKET_SIZE 188
#endif
 
class MPEG2TransportStreamTrickModeFilter: public FramedFilter {
public:
  static MPEG2TransportStreamTrickModeFilter*
  createNew(UsageEnvironment& env, FramedSource* inputSource,
        MPEG2TransportStreamIndexFile* indexFile, int scale);
 
  Boolean seekTo(unsigned long tsPacketNumber, unsigned long indexRecordNumber);
 
  unsigned long nextIndexRecordNum() const { return fNextIndexRecordNum; }
 
  void forgetInputSource() { fInputSource = NULL; }
      // this lets us delete this without also deleting the input Transport Stream
 
protected:
  MPEG2TransportStreamTrickModeFilter(UsageEnvironment& env, FramedSource* inputSource,
                      MPEG2TransportStreamIndexFile* indexFile, int scale);
      // called only by createNew()
  virtual ~MPEG2TransportStreamTrickModeFilter();
 
private:
  // Redefined virtual functions:
  virtual void doGetNextFrame();
  virtual void doStopGettingFrames();
 
private:
  void attemptDeliveryToClient();
  void seekToTransportPacket(unsigned long tsPacketNum);
  void readTransportPacket(unsigned long tsPacketNum); // asynchronously
 
  static void afterGettingFrame(void* clientData, unsigned frameSize,
                unsigned numTruncatedBytes,
                struct timeval presentationTime,
                unsigned durationInMicroseconds);
  void afterGettingFrame1(unsigned frameSize);
 
  static void onSourceClosure(void* clientData);
  void onSourceClosure1();
 
private:
  Boolean fHaveStarted;
  MPEG2TransportStreamIndexFile* fIndexFile;
  int fScale; // absolute value
  int fDirection; // 1 => forward; -1 => reverse
  enum {
    SKIPPING_FRAME,
    DELIVERING_SAVED_FRAME,
    SAVING_AND_DELIVERING_FRAME
  } fState;
  unsigned fFrameCount;
  unsigned long fNextIndexRecordNum; // next to be read from the index file
  unsigned long fNextTSPacketNum; // next to be read from the transport stream file
  unsigned char fInputBuffer[TRANSPORT_PACKET_SIZE];
  unsigned long fCurrentTSPacketNum; // corresponding to data currently in the buffer
  unsigned long fDesiredTSPacketNum;
  u_int8_t fDesiredDataOffset, fDesiredDataSize;
  float fDesiredDataPCR, fFirstPCR;
  unsigned long fSavedFrameIndexRecordStart;
  unsigned long fSavedSequentialIndexRecordNum;
  Boolean fUseSavedFrameNextTime;
};
 
#endif