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 filter that produces a sequence of I-frame indices from a MPEG-2 Transport Stream |
19 | // C++ header |
20 | |
21 | #ifndef _MPEG2_IFRAME_INDEX_FROM_TRANSPORT_STREAM_HH |
22 | #define _MPEG2_IFRAME_INDEX_FROM_TRANSPORT_STREAM_HH |
23 | |
24 | #ifndef _FRAMED_FILTER_HH |
25 | #include "FramedFilter.hh" |
26 | #endif |
27 | |
28 | #ifndef TRANSPORT_PACKET_SIZE |
29 | #define TRANSPORT_PACKET_SIZE 188 |
30 | #endif |
31 | |
32 | #ifndef MAX_PES_PACKET_SIZE |
33 | #define MAX_PES_PACKET_SIZE 65536 |
34 | #endif |
35 | |
36 | class IndexRecord; // forward |
37 | |
38 | class MPEG2IFrameIndexFromTransportStream: public FramedFilter { |
39 | public: |
40 | static MPEG2IFrameIndexFromTransportStream* |
41 | createNew(UsageEnvironment& env, FramedSource* inputSource); |
42 | |
43 | protected: |
44 | MPEG2IFrameIndexFromTransportStream(UsageEnvironment& env, |
45 | FramedSource* inputSource); |
46 | // called only by createNew() |
47 | virtual ~MPEG2IFrameIndexFromTransportStream(); |
48 | |
49 | private: |
50 | // Redefined virtual functions: |
51 | virtual void doGetNextFrame(); |
52 | |
53 | private: |
54 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
55 | unsigned numTruncatedBytes, |
56 | struct timeval presentationTime, |
57 | unsigned durationInMicroseconds); |
58 | void afterGettingFrame1(unsigned frameSize, |
59 | unsigned numTruncatedBytes, |
60 | struct timeval presentationTime, |
61 | unsigned durationInMicroseconds); |
62 | |
63 | static void handleInputClosure(void* clientData); |
64 | void handleInputClosure1(); |
65 | |
66 | void analyzePAT(unsigned char* pkt, unsigned size); |
67 | void analyzePMT(unsigned char* pkt, unsigned size); |
68 | |
69 | Boolean deliverIndexRecord(); |
70 | Boolean parseFrame(); |
71 | Boolean parseToNextCode(unsigned char& nextCode); |
72 | void compactParseBuffer(); |
73 | void addToTail(IndexRecord* newIndexRecord); |
74 | |
75 | private: |
76 | Boolean fIsH264; // True iff the video is H.264 (encapsulated in a Transport Stream) |
77 | Boolean fIsH265; // True iff the video is H.265 (encapsulated in a Transport Stream) |
78 | unsigned long fInputTransportPacketCounter; |
79 | unsigned fClosureNumber; |
80 | u_int8_t fLastContinuityCounter; |
81 | float fFirstPCR, fLastPCR; |
82 | Boolean fHaveSeenFirstPCR; |
83 | u_int16_t fPMT_PID, fVideo_PID; |
84 | // Note: We assume: 1 program per Transport Stream; 1 video stream per program |
85 | unsigned char fInputBuffer[TRANSPORT_PACKET_SIZE]; |
86 | unsigned char* fParseBuffer; |
87 | unsigned fParseBufferSize; |
88 | unsigned fParseBufferFrameStart; |
89 | unsigned fParseBufferParseEnd; |
90 | unsigned fParseBufferDataEnd; |
91 | IndexRecord* fHeadIndexRecord; |
92 | IndexRecord* fTailIndexRecord; |
93 | }; |
94 | |
95 | #endif |
96 | |