1 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  *  Use of this source code is governed by a BSD-style license that can
4  *  be found in the License.html file in the root of the source tree.
5  */
6 
7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 //
9 // Information about MPEG Transport Stream files
10 //
11 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 
13 //---------------------------------------------------------------------------
14 #ifndef MediaInfo_MpegTsH
15 #define MediaInfo_MpegTsH
16 //---------------------------------------------------------------------------
17 
18 //---------------------------------------------------------------------------
19 #include "MediaInfo/File__Duplicate.h"
20 #include "MediaInfo/Multiple/File_Mpeg_Psi.h"
21 //---------------------------------------------------------------------------
22 
23 namespace MediaInfoLib
24 {
25 
26 //***************************************************************************
27 // Class File_MpegTs
28 //***************************************************************************
29 
30 class File_MpegTs :
31 #if MEDIAINFO_DUPLICATE
32     public File__Duplicate
33 #else //MEDIAINFO_DUPLICATE
34     public File__Analyze
35 #endif //MEDIAINFO_DUPLICATE
36 {
37 public :
38     //In
39     #ifdef MEDIAINFO_BDAV_YES
40         size_t BDAV_Size;
41     #endif
42     #ifdef MEDIAINFO_TSP_YES
43         size_t TSP_Size;
44     #endif
45     #ifdef MEDIAINFO_ARIBSTDB24B37_YES
46         bool FromAribStdB24B37;
47     #endif
48     bool NoPatPmt;
49 
50     //Constructor/Destructor
51     File_MpegTs();
52     ~File_MpegTs();
53 
54 private :
55     //Streams management
56     void Streams_Accept();
57     void Streams_Fill();
58     void Streams_Update();
59     void Streams_Finish();
60 
61     //Buffer - File header
62     bool FileHeader_Begin();
63 
64     //Buffer - Synchro
65     bool Synchronize();
66     bool Synched_Test();
67     void Synched_Init();
68 
69     //Options
70     void Option_Manage ();
71 
72     //Buffer - Global
73     void Read_Buffer_Continue();
74     void Read_Buffer_AfterParsing ();
75     #if MEDIAINFO_ADVANCED2
76     void Read_Buffer_SegmentChange();
77     #endif //MEDIAINFO_ADVANCED2
78     void Read_Buffer_Unsynched();
79     #if MEDIAINFO_SEEK
80     size_t Read_Buffer_Seek (size_t Method, int64u Value, int64u ID);
81     #endif //MEDIAINFO_SEEK
82 
83     //Buffer - Per element
84     void Header_Parse();
85     void Header_Parse_AdaptationField();
86     void Data_Parse();
87 
88     int16u                      pid;
89     int8u                       transport_scrambling_control;
90     bool                        payload_unit_start_indicator;
91 
92     //Global infos
93     complete_stream* Complete_Stream;
94 
95     //Elements
96     void PSI();
97     void PES();
98     void PES_Parse_Finish();
99 
100     //Helpers
101     bool Header_Parser_QuickSearch();
102 
103     //Temp
104     #if defined(MEDIAINFO_BDAV_YES) || defined(MEDIAINFO_TSP_YES)
105         size_t TS_Size;
106     #endif
107     int64u MpegTs_JumpTo_Begin;
108     int64u MpegTs_JumpTo_End;
109     int64u MpegTs_ScanUpTo;
110     int64u Begin_MaxDuration; //in 27 MHz
111     bool   ForceStreamDisplay;
112     bool   ForceTextStreamDisplay;
113     bool   Searching_TimeStamp_Start;
114 
115     #if MEDIAINFO_EVENTS
116         void Header_Parse_Events();
117         void Header_Parse_Events_Duration(int64u program_clock_reference);
118     #else //MEDIAINFO_EVENTS
Header_Parse_Events()119         inline void Header_Parse_Events() {}
Header_Parse_Events_Duration(int64u)120         inline void Header_Parse_Events_Duration(int64u) {}
121     #endif //MEDIAINFO_EVENTS
122      void Header_Parse_Events_Duration_Helper(int64u& program_clock_reference, const bool discontinuity_indicator);
123 
124     //Helpers
125     void Streams_Update_Programs();
126     void Streams_Update_Programs_PerStream(size_t StreamID);
127     void Streams_Update_EPG();
128     void Streams_Update_EPG_PerProgram(complete_stream::transport_stream::programs::iterator Program);
129     #ifdef MEDIAINFO_MPEGTS_PCR_YES
130     void Streams_Update_Duration_Update();
131     #if MEDIAINFO_ADVANCED
132         float64 Config_VbrDetection_Delta;
133         int64u  Config_VbrDetection_Occurences;
134         bool    Config_VbrDetection_GiveUp;
135     #endif // MEDIAINFO_ADVANCED
136     #endif //MEDIAINFO_MPEGTS_PCR_YES
137     void Streams_Update_Duration_End();
138     void SetAllToPES();
139     void transport_private_data(int8u transport_private_data_length);
140     void MergeGeneral(complete_stream::stream* Parser, general Parameter);
141 
142     #if MEDIAINFO_DUPLICATE
143         //File__Duplicate
144         void   File__Duplicate_Streams_Finish ();
145         bool   File__Duplicate_Set  (const Ztring &Value); //Fill a new File__Duplicate value
146         void   File__Duplicate_Write ();
147 
148         //Output buffer
149         size_t Output_Buffer_Get (const String &Value);
150         size_t Output_Buffer_Get (size_t Pos);
151         std::vector<int16u> Output_Buffer_Get_Pos;
152     #endif //MEDIAINFO_DUPLICATE
153 
154     //Config
155     bool Config_Trace_TimeSection_OnlyFirstOccurrence;
156     bool TimeSection_FirstOccurrenceParsed;
157 
158     #if MEDIAINFO_SEEK
159         std::map<int16u, int64u>    Unsynch_Frame_Counts;
160         int64u                      Seek_Value;
161         int64u                      Seek_Value_Maximal;
162         int64u                      Seek_ID;
163         size_t                      InfiniteLoop_Detect;
164         bool                        Duration_Detected;
165     #endif //MEDIAINFO_SEEK
166 };
167 
168 } //NameSpace
169 
170 #endif
171