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 #ifndef MediaInfo_File__AnalyzeH
9 #define MediaInfo_File__AnalyzeH
10 //---------------------------------------------------------------------------
11 
12 //---------------------------------------------------------------------------
13 #include "MediaInfo/File__Base.h"
14 #include "MediaInfo/File__Analyse_Automatic.h"
15 #include "MediaInfo/File__Analyze_Element.h"
16 #include "ZenLib/BitStream_Fast.h"
17 #include "ZenLib/BitStream_LE.h"
18 #if MEDIAINFO_IBIUSAGE
19     #include "MediaInfo/Multiple/File_Ibi_Creation.h"
20 #endif //MEDIAINFO_IBIUSAGE
21 #include "tinyxml2.h"
22 #if MEDIAINFO_AES
23     #include <aescpp.h>
24 #endif //MEDIAINFO_AES
25 #include "MediaInfo/HashWrapper.h"
26 //---------------------------------------------------------------------------
27 
28 namespace MediaInfoLib
29 {
30 
31 class MediaInfo_Internal;
32 
Get_Hex_ID(const T & Value)33 template <class T> inline Ztring Get_Hex_ID(const T& Value)
34 {
35     Ztring ID_String;
36     ID_String.From_Number(Value);
37     ID_String += __T(" (0x");
38     ID_String += Ztring::ToZtring(Value, 16);
39     ID_String += __T(")");
40     return ID_String;
41 }
42 
43 struct buffer_data
44 {
45     size_t Size;
46     int8u* Data;
47 
buffer_databuffer_data48     buffer_data()
49     {
50         Size = 0;
51         Data = NULL;
52     }
buffer_databuffer_data53     buffer_data(const int8u* aData, size_t aSize)
54     {
55         Size = aSize;
56         Data = new int8u[aSize];
57         std::memcpy(Data, aData, aSize);
58     }
59 
~buffer_databuffer_data60     ~buffer_data()
61     {
62         delete[] Data; //Data=NULL;
63     }
64 };
65 
ReverseBits(int8u c)66 static inline int8u ReverseBits(int8u c)
67 {
68     // Input: bit order is 76543210
69     //Output: bit order is 01234567
70     c = (c & 0x0F) << 4 | (c & 0xF0) >> 4;
71     c = (c & 0x33) << 2 | (c & 0xCC) >> 2;
72     c = (c & 0x55) << 1 | (c & 0xAA) >> 1;
73     return c;
74 }
75 
76 string uint128toString(uint128 Value, int radix);
77 
78 #if !MEDIAINFO_TRACE
79     #include "MediaInfo/File__Analyze_MinimizeSize.h"
80 #else
81 
82 //***************************************************************************
83 // Class File__Base
84 //***************************************************************************
85 
86 class File__Analyze : public File__Base
87 {
88 public :
89     //***************************************************************************
90     // Constructor/Destructor
91     //***************************************************************************
92 
93     File__Analyze();
94     virtual ~File__Analyze();
95 
96     //***************************************************************************
97     // Open
98     //***************************************************************************
99 
100     void    Open_Buffer_Init        (                    int64u File_Size);
101     void    Open_Buffer_Init        (File__Analyze* Sub);
102     void    Open_Buffer_Init        (File__Analyze* Sub, int64u File_Size);
Open_Buffer_OutOfBand(const int8u * Buffer,size_t Buffer_Size)103     void    Open_Buffer_OutOfBand   (                    const int8u* Buffer, size_t Buffer_Size) {File__Analyze::Buffer=Buffer; File__Analyze::Buffer_Size=Buffer_Size; Element_Offset=0; Element_Size=Buffer_Size; Read_Buffer_OutOfBand(); File__Analyze::Buffer=NULL; File__Analyze::Buffer_Size=0; Element_Offset=0; Element_Size=0;}
104     void    Open_Buffer_OutOfBand   (File__Analyze* Sub                     , size_t Buffer_Size);
Open_Buffer_OutOfBand(File__Analyze * Sub)105     void    Open_Buffer_OutOfBand   (File__Analyze* Sub) {Open_Buffer_OutOfBand(Sub, Element_Size-Element_Offset);};
106     void    Open_Buffer_Continue    (                    const int8u* Buffer, size_t Buffer_Size);
107     void    Open_Buffer_Continue    (File__Analyze* Sub, const int8u* Buffer, size_t Buffer_Size, bool IsNewPacket=true, float64 Ratio=1.0);
Open_Buffer_Continue(File__Analyze * Sub,size_t Buffer_Size)108     void    Open_Buffer_Continue    (File__Analyze* Sub, size_t Buffer_Size) {if (Element_Offset+Buffer_Size<=Element_Size) Open_Buffer_Continue(Sub, Buffer+Buffer_Offset+(size_t)Element_Offset, Buffer_Size); Element_Offset+=Buffer_Size;}
Open_Buffer_Continue(File__Analyze * Sub)109     void    Open_Buffer_Continue    (File__Analyze* Sub) {if (Element_Offset<=Element_Size) Open_Buffer_Continue(Sub, Buffer+Buffer_Offset+(size_t)Element_Offset, (size_t)(Element_Size-Element_Offset)); Element_Offset=Element_Size;}
110     void    Open_Buffer_Position_Set(int64u File_Offset);
111     void    Open_Buffer_CheckFileModifications();
112     #if MEDIAINFO_SEEK
113     size_t  Open_Buffer_Seek        (size_t Method, int64u Value, int64u ID);
114     #endif //MEDIAINFO_SEEK
115     #if MEDIAINFO_ADVANCED2
116     void    Open_Buffer_SegmentChange();
117     #endif //MEDIAINFO_ADVANCED2
118     void    Open_Buffer_Update      ();
119     void    Open_Buffer_Update      (File__Analyze* Sub);
120     void    Open_Buffer_Unsynch     ();
121     void    Open_Buffer_Finalize    (bool NoBufferModification=false);
122     void    Open_Buffer_Finalize    (File__Analyze* Sub);
123 
124     //***************************************************************************
125     // In/Out (for parsers)
126     //***************************************************************************
127 
128     //In
129     std::string ParserName;
130     #if MEDIAINFO_EVENTS
131         size_t  StreamIDs_Size;
132         int64u  StreamIDs[16];
133         int8u   StreamIDs_Width[16];
134         int8u   ParserIDs[16];
135         void    Event_Prepare (struct MediaInfo_Event_Generic* Event, int32u Event_Code, size_t Event_Size);
136     #endif //MEDIAINFO_EVENTS
137     #if MEDIAINFO_DEMUX
138         int8u   Demux_Level; //bit 0=frame, bit 1=container, bit 2=elementary (eg MPEG-TS), bit 3=ancillary (e.g. DTVCC), default with frame set
139         bool    Demux_random_access;
140         bool    Demux_UnpacketizeContainer;
141         bool    Demux_IntermediateItemFound;
142         size_t  Demux_Offset;
143         int64u  Demux_TotalBytes;
144         File__Analyze* Demux_CurrentParser;
145     #endif //MEDIAINFO_DEMUX
146     Ztring  File_Name_WithoutDemux;
147     bool   PTS_DTS_Needed;
148     enum ts_type
149     {
150         TS_NONE=0,
151         TS_PTS=1,
152         TS_DTS=2,
153         TS_ALL=TS_PTS|TS_DTS,
154     };
155     void   TS_Clear(ts_type Type=TS_ALL);
156     void   TS_Set(int64s Ticks, ts_type Type=TS_ALL);
157     void   TS_Set(File__Analyze* Parser, ts_type Type=TS_ALL);
158     void   TS_Add(int64s Ticks, ts_type Type=TS_ALL);
159     void   TS_Ajust(int64s Ticks);
160     int64s Frequency_c; //Frequency of the timestamp of the container (e.g. 90000 for MPEG-PS)
161     int64s Frequency_b; //Frequency of the timestamp of the bitstream (e.g. 48000 for AC-3)
162     #if MEDIAINFO_ADVANCED2
163     static const int64s NoTs=0x8000000000000000LL;
164     int64s PTSb; //In 1/Frequency_b if sub, in 1/(Frequency_c*Frequency_b) if in a container
165     int64s DTSb; //In 1/Frequency_b if sub, in 1/(Frequency_c*Frequency_b) if in a container
166     #endif //MEDIAINFO_ADVANCED2
167     struct frame_info
168     {
169         int64u Buffer_Offset_End;
170         int64u PCR; //In nanoseconds
171         int64u PTS; //In nanoseconds
172         int64u DTS; //In nanoseconds
173         int64u DUR; //In nanoseconds
174         #if MEDIAINFO_ADVANCED2
175         int64s PTSc; //In 1/Frequency_c
176         int64s DTSc; //In 1/Frequency_c
177         int64u Frame_Count_AfterLastTimeStamp;
178         #endif //MEDIAINFO_ADVANCED2
179 
frame_infoframe_info180         frame_info()
181         {
182             Buffer_Offset_End=(int64u)-1;
183             PCR=(int64u)-1;
184             PTS=(int64u)-1;
185             DTS=(int64u)-1;
186             DUR=(int64u)-1;
187             #if MEDIAINFO_ADVANCED2
188             PTSc=NoTs;
189             DTSc=NoTs;
190             Frame_Count_AfterLastTimeStamp=0;
191             #endif //MEDIAINFO_ADVANCED2
192         }
193     };
194     frame_info FrameInfo;
195     frame_info FrameInfo_Previous;
196     frame_info FrameInfo_Next;
197     std::vector<int64u> Offsets_Stream;
198     std::vector<int64u> Offsets_Buffer;
199     size_t              Offsets_Pos;
200     int8u*              OriginalBuffer;
201     size_t              OriginalBuffer_Size;
202     size_t              OriginalBuffer_Capacity;
203     #if defined(MEDIAINFO_EIA608_YES) || defined(MEDIAINFO_EIA708_YES)
204         struct servicedescriptor
205         {
206             string language;
207         };
208         typedef std::map<int8u, servicedescriptor> servicedescriptors608;
209         typedef std::map<int8u, servicedescriptor> servicedescriptors708;
210         struct servicedescriptors
211         {
212             #if defined(MEDIAINFO_EIA608_YES)
213                 std::map<int8u, servicedescriptor> ServiceDescriptors608;
214             #endif
215             #if defined(MEDIAINFO_EIA708_YES)
216                 std::map<int8u, servicedescriptor> ServiceDescriptors708;
217             #endif
218         };
219         servicedescriptors* ServiceDescriptors;
220     #endif
221     #if defined(MEDIAINFO_TELETEXT_YES)
222         struct teletext
223         {
224             std::map<std::string, Ztring>           Infos;
225             stream_t                                StreamKind;
226             size_t                                  StreamPos;
227 
teletextteletext228             teletext()
229                 : StreamKind(Stream_Max)
230                 , StreamPos((size_t)-1)
231             {}
232         };
233         std::map<int16u, teletext>*                 Teletexts; //Key is teletext_magazine_number
234     #endif
235 
236     //Out
237     int64u PTS_Begin;                  //In nanoseconds
238     #if MEDIAINFO_ADVANCED2
239     int64u PTS_Begin_Segment;          //In nanoseconds
240     #endif //MEDIAINFO_ADVANCED2
241     int64u PTS_End;                    //In nanoseconds
242     int64u DTS_Begin;                  //In nanoseconds
243     int64u DTS_End;                    //In nanoseconds
244     int64u Frame_Count;
245     int64u Frame_Count_Previous;
246     int64u Frame_Count_InThisBlock;
247     int64u Field_Count;
248     int64u Field_Count_Previous;
249     int64u Field_Count_InThisBlock;
250     int64u Frame_Count_NotParsedIncluded;
251     int64u FrameNumber_PresentationOrder;
252     bool   Synched;                    //Data is synched
253     bool   UnSynched_IsNotJunk;        //Data is actually synched
254     bool   MustExtendParsingDuration;  //Data has some substreams difficult to detect (e.g. captions), must wait a bit before final filling
255 
256 protected :
257     //***************************************************************************
258     // Streams management
259     //***************************************************************************
260 
Streams_Accept()261     virtual void Streams_Accept()                                               {};
Streams_Fill()262     virtual void Streams_Fill()                                                 {};
Streams_Update()263     virtual void Streams_Update()                                               {};
Streams_Finish()264     virtual void Streams_Finish()                                               {};
265 
266     //***************************************************************************
267     // Synchro
268     //***************************************************************************
269 
Synchronize()270     virtual bool Synchronize()    {Synched=true; return true;}; //Look for the synchro
Synched_Test()271     virtual bool Synched_Test()   {return true;}; //Test is synchro is OK
Synched_Init()272     virtual void Synched_Init()   {}; //When synched, we can Init data
273     bool Synchro_Manage();
274     bool Synchro_Manage_Test();
275 
276     //***************************************************************************
277     // Buffer
278     //***************************************************************************
279 
280     //Buffer
Read_Buffer_Init()281     virtual void Read_Buffer_Init ()          {}; //Temp, should be in File__Base caller
Read_Buffer_OutOfBand()282     virtual void Read_Buffer_OutOfBand ()     {Open_Buffer_Continue(Buffer, Buffer_Size);} //Temp, should be in File__Base caller
Read_Buffer_Continue()283     virtual void Read_Buffer_Continue ()      {}; //Temp, should be in File__Base caller
Read_Buffer_CheckFileModifications()284     virtual void Read_Buffer_CheckFileModifications() {} //Temp, should be in File__Base caller
Read_Buffer_AfterParsing()285     virtual void Read_Buffer_AfterParsing ()  {}; //Temp, should be in File__Base caller
286     #if MEDIAINFO_SEEK
287     virtual size_t Read_Buffer_Seek (size_t, int64u, int64u); //Temp, should be in File__Base caller
288     size_t Read_Buffer_Seek_OneFramePerFile (size_t, int64u, int64u);
289     #endif //MEDIAINFO_SEEK
290     #if MEDIAINFO_ADVANCED2
Read_Buffer_SegmentChange()291     virtual void Read_Buffer_SegmentChange () {}; //Temp, should be in File__Base caller
292     #endif //MEDIAINFO_ADVANCED2
Read_Buffer_Unsynched()293     virtual void Read_Buffer_Unsynched ()     {}; //Temp, should be in File__Base caller
294     void Read_Buffer_Unsynched_OneFramePerFile ();
Read_Buffer_Finalize()295     virtual void Read_Buffer_Finalize ()      {}; //Temp, should be in File__Base caller
296     bool Buffer_Parse();
297 
298     //***************************************************************************
299     // BitStream init
300     //***************************************************************************
301 
302     void BS_Begin();
303     void BS_Begin_LE(); //Little Endian version
304     void BS_End();
305     void BS_End_LE(); //Little Endian version
306 
307     //***************************************************************************
308     // File Header
309     //***************************************************************************
310 
311     //File Header - Management
312     bool FileHeader_Manage ();
313 
314     //File Header - Begin
FileHeader_Begin()315     virtual bool FileHeader_Begin ()                                            {return true;};
316 
317     //File Header - Parse
FileHeader_Parse()318     virtual void FileHeader_Parse ()                                            {Element_DoNotShow();};
319 
320     //***************************************************************************
321     // Header
322     //***************************************************************************
323 
324     //Header - Management
325     bool Header_Manage ();
326 
327     //Header - Begin
Header_Begin()328     virtual bool Header_Begin ()                                                {return true;};
329 
330     //Header - Parse
331     virtual void Header_Parse ();
332 
333     //Header - Info
334     void Header_Fill_Code (int64u Code);
335     void Header_Fill_Code (int64u Code, const Ztring &Name);
336     #define Header_Fill_Code2(A,B) Header_Fill_Code(A,B)
337     void Header_Fill_Size (int64u Size);
338 
339     //***************************************************************************
340     // Data
341     //***************************************************************************
342 
343     //Header - Management
344     bool Data_Manage ();
345 
346     //Data - Parse
Data_Parse()347     virtual void Data_Parse ()                                                  {};
348 
349     //Data - Info
350     void Data_Info (const Ztring &Parameter);
Data_Info_From_Milliseconds(int64u Parameter)351     inline void Data_Info_From_Milliseconds (int64u Parameter)                  {Data_Info(Ztring().Duration_From_Milliseconds(Parameter));}
352 
353     //Data - Get info
Data_Remain()354     size_t Data_Remain ()                                                       {return (size_t)(Element_Size-(Element_Offset+BS->Offset_Get()));};
Data_BS_Remain()355     size_t Data_BS_Remain ()                                                    {return (size_t)BS->Remain();};
356 
357     //Data - Detect EOF
Detect_EOF()358     virtual void Detect_EOF ()                                                  {};
359     bool EOF_AlreadyDetected;
360 
361     //Data - Helpers
362     void Data_Accept        (const char* ParserName);
363     void Data_Reject        (const char* ParserName);
364     void Data_Finish        (const char* ParserName);
365     void Data_GoTo          (int64u GoTo, const char* ParserName);
366     void Data_GoToFromEnd   (int64u GoToFromEnd, const char* ParserName);
367 
368     //***************************************************************************
369     // Elements
370     //***************************************************************************
371 
372     //Elements - Begin
373     void Element_Begin ();
374     void Element_Begin (const Ztring &Name);
375     void Element_Begin (const char *Name);
376     #define Element_Begin0() Element_Begin()
377     #define Element_Begin1(_NAME) Element_Begin(_NAME)
378     #define Element_Trace_Begin0() Element_Begin()
379     #define Element_Trace_Begin1(_NAME) Element_Begin(_NAME)
380 
381     //Elements - Name
382     void Element_Name (const Ztring &Name);
Element_Name(const char * Name)383     inline void Element_Name (const char*   Name) {Element_Name(Ztring().From_UTF8(Name));}
384 
385     //Elements - Info
386 #if MEDIAINFO_TRACE
387     template<typename T>
388     void Element_Info (T Parameter, const char* Measure=NULL, int8u AfterComma=3)
389     {
390         if (Config_Trace_Level<1)
391             return;
392 
393         //Needed?
394         if (Config_Trace_Level<=0.7)
395             return;
396 
397         Element[Element_Level].TraceNode.Infos.push_back(new element_details::Element_Node_Info(Parameter, Measure, AfterComma));
398     }
399 
400     void Element_Info (const char* Parameter, const char* Measure=NULL, int8u AfterComma=3)
401     {
402         if (Config_Trace_Level<1)
403             return;
404 
405         //Needed?
406         if (Config_Trace_Level<=0.7)
407             return;
408 
409         if ((Parameter && std::string(Parameter) == "NOK") || (Measure && std::string(Measure) == "Error"))
410             Element[Element_Level].TraceNode.HasError = true;
411 
412         Element[Element_Level].TraceNode.Infos.push_back(new element_details::Element_Node_Info(Parameter, Measure, AfterComma));
413     }
414 #endif //MEDIAINFO_TRACE
415 
416     #ifdef SIZE_T_IS_LONG
417     inline void Element_Info (size_t        Parameter, const char*   Measure=NULL) {Element_Info(Ztring::ToZtring(Parameter), Measure);}
418     #endif //SIZE_T_IS_LONG
419     #define Element_Info1(_A) Element_Info(_A)
420     #define Element_Info2(_A,_B) Element_Info(_A, _B)
421     #define Element_Info3(_A,_B,_C) Element_Info(_A, _B, _C)
422     #define Element_Info1C(_CONDITION,_A) if (_CONDITION) Element_Info(_A)
Element_Info_From_Milliseconds(int64u Parameter)423     inline void Element_Info_From_Milliseconds (int64u Parameter)                  {if (Config_Trace_Level<1) return; Element_Info(Ztring().Duration_From_Milliseconds(Parameter));}
424 
425     void Element_Parser (const char* Name);
426     void Element_Error (const char* Name);
427     void Param_Error (const char* Name);
428 
429     //Elements - End
Element_End()430     inline void Element_End () {Element_End_Common_Flush();}
431     void Element_End (const Ztring &Name);
Element_End(const char * Name)432     inline void Element_End (const char *Name) {Element_End(Ztring().From_UTF8(Name));}
433     #define Element_End0() Element_End()
434     #define Element_End1(_NAME) Element_End(_NAME)
435     #define Element_Trace_End0() Element_End()
436     #define Element_Trace_End1(_NAME) Element_End(_NAME)
437 
438     //Elements - Preparation of element from external app
439     void Element_Prepare (int64u Size);
440 
441 protected :
442     //Element - Common
443     void   Element_End_Common_Flush();
444     void   Element_End_Common_Flush_Details();
445 public :
446 
447     //***************************************************************************
448     // Param
449     //***************************************************************************
450 
451     //TODO: put this in Ztring()
452     Ztring ToZtring(const char* Value, size_t Value_Size=Unlimited, bool Utf8=true)
453     {
454         if (Utf8)
455             return Ztring().From_UTF8(Value, Value_Size);
456         else
457             return Ztring().From_Local(Value, Value_Size);
458     }
459 
460     //Param - Main
461     template<typename T>
462     inline void Param(const std::string &Parameter, T Value, int8u GenericOption=(int8u)-1)
463     {
464         if (!Trace_Activated)
465             return;
466 
467         if (Config_Trace_Level==0 || !(Trace_Layers.to_ulong()&Config_Trace_Layers.to_ulong()))
468             return ;
469 
470         //Coherancy
471         if (Element[Element_Level].UnTrusted)
472             return ;
473 
474         element_details::Element_Node *node = new element_details::Element_Node;
475         node->Set_Name(Parameter);
476         node->Pos = File_Offset+Buffer_Offset+Element_Offset;
477         if (BS_Size)
478         {
479             int64u BS_BitOffset = BS_Size-BS->Remain();
480             if (GenericOption != (int8u)-1)
481                 BS_BitOffset -= GenericOption;
482             node->Pos += BS_BitOffset>>3; //Including Bits to Bytes
483         }
484         node->Value.set_Option(GenericOption);
485         node->Value = Value;
486         Element[Element_Level].TraceNode.Current_Child = Element[Element_Level].TraceNode.Children.size();
487         Element[Element_Level].TraceNode.Children.push_back(node);
488     }
489 
490     inline void Param      (const char*   Parameter, const char*   Value, size_t Value_Size, bool Utf8=true) {Param(Parameter, ToZtring(Value, Value_Size, Utf8));}
491     inline void Param      (const char*   Parameter, const int8u*  Value, size_t Value_Size, bool Utf8=true) {Param(Parameter, (const char*)Value, Value_Size, Utf8);}
Param_GUID(const char * Parameter,int128u Value)492     inline void Param_GUID (const char*   Parameter, int128u Value){Param(Parameter, Ztring().From_GUID(Value));}
Param_UUID(const char * Parameter,int128u Value)493     inline void Param_UUID (const char*   Parameter, int128u Value){Param(Parameter, Ztring().From_UUID(Value));}
Param_CC(const char * Parameter,const int8u * Value,int8u Value_Size)494     inline void Param_CC   (const char*   Parameter, const int8u*  Value, int8u Value_Size){Ztring Name2; for (int8s i=0; i<Value_Size; i++) Name2.append(1, (ZenLib::Char)(Value[i])); Param(Parameter, Name2);}
495     /* #ifdef SIZE_T_IS_LONG */
496     /* inline void Param      (const char*   Parameter, size_t Value, intu Radix) {if (Trace_Activated) Param(Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase()+__T(" (")+Ztring::ToZtring(Value, 10).MakeUpperCase()+__T(")"));} */
497     /* #endif //SIZE_T_IS_LONG */
Param(const int32u Parameter,const Ztring & Value)498     inline void Param      (const int32u  Parameter, const Ztring& Value) {if (Trace_Activated) Param(Ztring().From_CC4(Parameter).To_UTF8(), Value.To_UTF8());};
Param(const int16u Parameter,const Ztring & Value)499     inline void Param      (const int16u  Parameter, const Ztring& Value) {if (Trace_Activated) Param(Ztring().From_CC2(Parameter).To_UTF8(), Value.To_UTF8());};
500     #define Param1(_A) Param_(_A)
501     #define Param2(_A,_B) Param(_A, _B)
502     #define Param3(_A,_B,_C) Param(_A, _B, _C)
503 
504     //Param - Info
505 #if MEDIAINFO_TRACE
506     template<typename T>
507     void Param_Info(T Parameter, const char* Measure=NULL, int8u AfterComma=3)
508     {
509         //Coherancy
510         if (!Trace_Activated)
511             return;
512         if (Element[Element_Level].UnTrusted)
513             return;
514         if (Config_Trace_Level<=0.7)
515             return;
516 
517         // if (!(Trace_Layers.to_ulong()&Config_Trace_Layers.to_ulong()) || Element[Element_Level].TraceNode.Details.size()>64*1024*1024)
518         //     return;
519         int32s child = Element[Element_Level].TraceNode.Current_Child;
520         if (child >= 0 && Element[Element_Level].TraceNode.Children[child])
521             Element[Element_Level].TraceNode.Children[child]->Infos.push_back(new element_details::Element_Node_Info(Parameter, Measure, AfterComma));
522         else
523             Element[Element_Level].TraceNode.Infos.push_back(new element_details::Element_Node_Info(Parameter, Measure, AfterComma));
524     }
525 
526     void Param_Info(const char* Parameter, const char* Measure=NULL, int8u AfterComma=3)
527     {
528         //Coherancy
529         if (!Trace_Activated)
530             return;
531         if (Element[Element_Level].UnTrusted)
532             return;
533         if (Config_Trace_Level<=0.7)
534             return;
535 
536         if ((Parameter && std::string(Parameter) == "NOK") || (Measure && std::string(Measure) == "Error"))
537             Element[Element_Level].TraceNode.HasError = true;
538 
539         int32s child = Element[Element_Level].TraceNode.Current_Child;
540         if (child >= 0 && Element[Element_Level].TraceNode.Children[child])
541             Element[Element_Level].TraceNode.Children[child]->Infos.push_back(new element_details::Element_Node_Info(Parameter, Measure, AfterComma));
542         else
543             Element[Element_Level].TraceNode.Infos.push_back(new element_details::Element_Node_Info(Parameter, Measure, AfterComma));
544     }
545 #endif //MEDIAINFO_TRACE
546 
547     #ifdef SIZE_T_IS_LONG
548     inline void Param_Info (size_t        Parameter, const char*   Measure=NULL) {if (Trace_Activated) Param_Info(Ztring::ToZtring(Parameter)+Ztring().From_UTF8(Measure));}
549     #endif //SIZE_T_IS_LONG
550     #define Param_Info1(_A) Param_Info(_A)
551     #define Param_Info2(_A,_B) Param_Info(_A, _B)
552     #define Param_Info3(_A,_B,_C) Param_Info(_A, _B, _C)
553     #define Param_Info1C(_CONDITION,_A) if (_CONDITION) Param_Info(_A)
554     #define Param_Info2C(_CONDITION,_A,_B) if (_CONDITION) Param_Info(_A, _B)
555     #define Param_Info3C(_CONDITION,_A,_B,_C) if (_CONDITION) Param_Info(_A, _B, _C)
Param_Info_From_Milliseconds(int64u Parameter)556     inline void Param_Info_From_Milliseconds (int64u Parameter)                  {if (Trace_Activated) Param_Info(Ztring().Duration_From_Milliseconds(Parameter));}
557 
558     //***************************************************************************
559     // Element Node
560     //***************************************************************************
561     element_details::Element_Node *Get_Trace_Node(size_t level = 0);
562 
563     //***************************************************************************
564     // Information
565     //***************************************************************************
566 
567     void Info (const std::string& Value, size_t Element_Level_Minus=0);
568 
569     //***************************************************************************
570     // Big Endian (Integer, Float, Fixed-Point)
571     //***************************************************************************
572 
573     void Get_B1   (int8u   &Info, const char* Name);
574     void Get_B2   (int16u  &Info, const char* Name);
575     void Get_B3   (int32u  &Info, const char* Name);
576     void Get_B4   (int32u  &Info, const char* Name);
577     void Get_B5   (int64u  &Info, const char* Name);
578     void Get_B6   (int64u  &Info, const char* Name);
579     void Get_B7   (int64u  &Info, const char* Name);
580     void Get_B8   (int64u  &Info, const char* Name);
581     void Get_B16  (int128u &Info, const char* Name);
582     void Get_BF2  (float32 &Info, const char* Name);
583     void Get_BF4  (float32 &Info, const char* Name);
584     void Get_BF8  (float64 &Info, const char* Name);
585     void Get_BF10 (float80 &Info, const char* Name);
586     void Get_BFP4 (int8u Bits, float32 &Info, const char* Name);
587     void Peek_B1  (int8u   &Info);
588     void Peek_B2  (int16u  &Info);
589     void Peek_B3  (int32u  &Info);
590     void Peek_B4  (int32u  &Info);
591     void Peek_B5  (int64u  &Info);
592     void Peek_B6  (int64u  &Info);
593     void Peek_B7  (int64u  &Info);
594     void Peek_B8  (int64u  &Info);
595     void Peek_B16 (int128u &Info);
596     void Peek_BF4 (float32 &Info);
597     void Peek_BF8 (float64 &Info);
598     void Peek_BF10(float64 &Info);
599     void Peek_BFP4(size_t Bits, float64 &Info);
600     void Skip_B1  (               const char* Name);
601     void Skip_B2  (               const char* Name);
602     void Skip_B3  (               const char* Name);
603     void Skip_B4  (               const char* Name);
604     void Skip_B5  (               const char* Name);
605     void Skip_B6  (               const char* Name);
606     void Skip_B7  (               const char* Name);
607     void Skip_B8  (               const char* Name);
608     void Skip_B16 (               const char* Name);
609     void Skip_BF4 (               const char* Name);
610     void Skip_BF8 (               const char* Name);
611     void Skip_BF10(               const char* Name);
612     void Skip_BFP4(int8u Bits,                const char* Name);
613     void Skip_Hexa(int8u Bytes,   const char* Name);
614     #define Info_B1(_INFO, _NAME)   int8u   _INFO; Get_B1  (_INFO, _NAME)
615     #define Info_B2(_INFO, _NAME)   int16u  _INFO; Get_B2  (_INFO, _NAME)
616     #define Info_B3(_INFO, _NAME)   int32u  _INFO; Get_B3  (_INFO, _NAME)
617     #define Info_B4(_INFO, _NAME)   int32u  _INFO; Get_B4  (_INFO, _NAME)
618     #define Info_B5(_INFO, _NAME)   int64u  _INFO; Get_B5  (_INFO, _NAME)
619     #define Info_B6(_INFO, _NAME)   int64u  _INFO; Get_B6  (_INFO, _NAME)
620     #define Info_B7(_INFO, _NAME)   int64u  _INFO; Get_B7  (_INFO, _NAME)
621     #define Info_B8(_INFO, _NAME)   int64u  _INFO; Get_B8  (_INFO, _NAME)
622     #define Info_B16(_INFO, _NAME)  int128u _INFO; Get_B16 (_INFO, _NAME)
623     #define Info_BF2(_INFO, _NAME)  float32 _INFO; Get_BF2 (_INFO, _NAME)
624     #define Info_BF4(_INFO, _NAME)  float32 _INFO; Get_BF4 (_INFO, _NAME)
625     #define Info_BF8(_INFO, _NAME)  float64 _INFO; Get_BF8 (_INFO, _NAME)
626     #define Info_BF10(_INFO, _NAME) float80 _INFO; Get_BF10(_INFO, _NAME)
627     #define Info_BFP4(_BITS, _INFO, _NAME) float32 _INFO; Get_BFP4(_BITS, _INFO, _NAME)
628 
629     //***************************************************************************
630     // Little Endian
631     //***************************************************************************
632 
633     void Get_L1  (int8u   &Info, const char* Name);
634     void Get_L2  (int16u  &Info, const char* Name);
635     void Get_L3  (int32u  &Info, const char* Name);
636     void Get_L4  (int32u  &Info, const char* Name);
637     void Get_L5  (int64u  &Info, const char* Name);
638     void Get_L6  (int64u  &Info, const char* Name);
639     void Get_L7  (int64u  &Info, const char* Name);
640     void Get_L8  (int64u  &Info, const char* Name);
641     void Get_L16 (int128u &Info, const char* Name);
642     void Get_LF4 (float32 &Info, const char* Name);
643     void Get_LF8 (float64 &Info, const char* Name);
644     void Peek_L1 (int8u   &Info);
645     void Peek_L2 (int16u  &Info);
646     void Peek_L3 (int32u  &Info);
647     void Peek_L4 (int32u  &Info);
648     void Peek_L5 (int64u  &Info);
649     void Peek_L6 (int64u  &Info);
650     void Peek_L7 (int64u  &Info);
651     void Peek_L8 (int64u  &Info);
652     void Peek_L16(int128u &Info);
653     void Peek_LF4(float32 &Info);
654     void Peek_LF8(float64 &Info);
655     void Skip_L1 (               const char* Name);
656     void Skip_L2 (               const char* Name);
657     void Skip_L3 (               const char* Name);
658     void Skip_L4 (               const char* Name);
659     void Skip_L5 (               const char* Name);
660     void Skip_L6 (               const char* Name);
661     void Skip_L7 (               const char* Name);
662     void Skip_L8 (               const char* Name);
663     void Skip_LF4(               const char* Name);
664     void Skip_LF8(               const char* Name);
665     void Skip_L16(               const char* Name);
666     #define Info_L1(_INFO, _NAME)  int8u   _INFO; Get_L1 (_INFO, _NAME)
667     #define Info_L2(_INFO, _NAME)  int16u  _INFO; Get_L2 (_INFO, _NAME)
668     #define Info_L3(_INFO, _NAME)  int32u  _INFO; Get_L3 (_INFO, _NAME)
669     #define Info_L4(_INFO, _NAME)  int32u  _INFO; Get_L4 (_INFO, _NAME)
670     #define Info_L5(_INFO, _NAME)  int64u  _INFO; Get_L5 (_INFO, _NAME)
671     #define Info_L6(_INFO, _NAME)  int64u  _INFO; Get_L6 (_INFO, _NAME)
672     #define Info_L7(_INFO, _NAME)  int64u  _INFO; Get_L7 (_INFO, _NAME)
673     #define Info_L8(_INFO, _NAME)  int64u  _INFO; Get_L8 (_INFO, _NAME)
674     #define Info_L16(_INFO, _NAME) int128u _INFO; Get_L16(_INFO, _NAME)
675     #define Info_LF4(_INFO, _NAME) float32 _INFO; Get_LF4(_INFO, _NAME)
676     #define Info_LF8(_INFO, _NAME) float64 _INFO; Get_LF8(_INFO, _NAME)
677 
678     //***************************************************************************
679     // Little and Big Endian together
680     //***************************************************************************
681 
682     void Get_D1  (int8u   &Info, const char* Name);
683     void Get_D2  (int16u  &Info, const char* Name);
684     void Get_D3  (int32u  &Info, const char* Name);
685     void Get_D4  (int32u  &Info, const char* Name);
686     void Get_D5  (int64u  &Info, const char* Name);
687     void Get_D6  (int64u  &Info, const char* Name);
688     void Get_D7  (int64u  &Info, const char* Name);
689     void Get_D8  (int64u  &Info, const char* Name);
690     void Get_D16 (int128u &Info, const char* Name);
691     void Get_DF4 (float32 &Info, const char* Name);
692     void Get_DF8 (float64 &Info, const char* Name);
693     void Peek_D1 (int8u   &Info);
694     void Peek_D2 (int16u  &Info);
695     void Peek_D3 (int32u  &Info);
696     void Peek_D4 (int32u  &Info);
697     void Peek_D5 (int64u  &Info);
698     void Peek_D6 (int64u  &Info);
699     void Peek_D7 (int64u  &Info);
700     void Peek_D8 (int64u  &Info);
701     void Peek_D16(int128u &Info);
702     void Peek_DF4(float32 &Info);
703     void Peek_DF8(float64 &Info);
704     void Skip_D1 (               const char* Name);
705     void Skip_D2 (               const char* Name);
706     void Skip_D3 (               const char* Name);
707     void Skip_D4 (               const char* Name);
708     void Skip_D5 (               const char* Name);
709     void Skip_D6 (               const char* Name);
710     void Skip_D7 (               const char* Name);
711     void Skip_D8 (               const char* Name);
712     void Skip_DF4(               const char* Name);
713     void Skip_DF8(               const char* Name);
714     void Skip_D16(               const char* Name);
715     #define Info_D1(_INFO, _NAME)  int8u   _INFO; Get_D1 (_INFO, _NAME)
716     #define Info_D2(_INFO, _NAME)  int16u  _INFO; Get_D2 (_INFO, _NAME)
717     #define Info_D3(_INFO, _NAME)  int32u  _INFO; Get_D3 (_INFO, _NAME)
718     #define Info_D4(_INFO, _NAME)  int32u  _INFO; Get_D4 (_INFO, _NAME)
719     #define Info_D5(_INFO, _NAME)  int64u  _INFO; Get_D5 (_INFO, _NAME)
720     #define Info_D6(_INFO, _NAME)  int64u  _INFO; Get_D6 (_INFO, _NAME)
721     #define Info_D7(_INFO, _NAME)  int64u  _INFO; Get_D7 (_INFO, _NAME)
722     #define Info_D8(_INFO, _NAME)  int64u  _INFO; Get_D8 (_INFO, _NAME)
723     #define Info_D16(_INFO, _NAME) int128u _INFO; Get_D16(_INFO, _NAME)
724     #define Info_DF4(_INFO, _NAME) float32 _INFO; Get_DF4(_INFO, _NAME)
725     #define Info_DF8(_INFO, _NAME) float64 _INFO; Get_DF8(_INFO, _NAME)
726 
727     //***************************************************************************
728     // GUID
729     //***************************************************************************
730 
731     void Get_GUID (int128u &Info, const char* Name);
732     void Peek_GUID(int128u &Info);
733     void Skip_GUID(               const char* Name);
734     #define Info_GUID(_INFO, _NAME) int128u _INFO; Get_GUID(_INFO, _NAME)
735 
736     //***************************************************************************
737     // UUID
738     //***************************************************************************
739 
740     void Get_UUID (int128u &Info, const char* Name);
741     void Peek_UUID(int128u &Info);
742     void Skip_UUID(               const char* Name);
743     #define Info_UUID(_INFO, _NAME) int128u _INFO; Get_UUID(_INFO, _NAME)
744 
745     //***************************************************************************
746     // EBML
747     //***************************************************************************
748 
749     void Get_EB (int64u &Info, const char* Name);
750     void Get_ES (int64s &Info, const char* Name);
751     void Skip_EB(              const char* Name);
752     void Skip_ES(              const char* Name);
753     #define Info_EB(_INFO, _NAME) int64u _INFO; Get_EB(_INFO, _NAME)
754     #define Info_ES(_INFO, _NAME) int64s _INFO; Get_ES(_INFO, _NAME)
755 
756     //***************************************************************************
757     // Variable Size Value
758     //***************************************************************************
759 
760     void Get_VS (int64u &Info, const char* Name);
761     void Skip_VS(              const char* Name);
762     #define Info_VS(_INFO, _NAME) int64u _INFO; Get_VS(_INFO, _NAME)
763 
764     //***************************************************************************
765     // Exp-Golomb
766     //***************************************************************************
767 
768     void Get_UE (int32u &Info, const char* Name);
769     void Get_SE (int32s &Info, const char* Name);
770     void Skip_UE(              const char* Name);
771     void Skip_SE(              const char* Name);
772     #define Info_UE(_INFO, _NAME) int32u _INFO; Get_UE(_INFO, _NAME)
773     #define Info_SE(_INFO, _NAME) int32s _INFO; Get_SE(_INFO, _NAME)
774 
775     //***************************************************************************
776     // Interleaved Exp-Golomb
777     //***************************************************************************
778 
779     void Get_UI (int32u &Info, const char* Name);
780     void Get_SI (int32s &Info, const char* Name);
781     void Skip_UI(              const char* Name);
782     void Skip_SI(              const char* Name);
783     #define Info_UI(_INFO, _NAME) int32u _INFO; Get_UI(_INFO, _NAME)
784     #define Info_SI(_INFO, _NAME) int32s _INFO; Get_SI(_INFO, _NAME)
785 
786     //***************************************************************************
787     // Variable Length Code
788     //***************************************************************************
789 
790     struct vlc
791     {
792         int32u  value;
793         int8u   bit_increment;
794         int8s   mapped_to1;
795         int8s   mapped_to2;
796         int8s   mapped_to3;
797     };
798     struct vlc_fast
799     {
800         int8u*      Array;
801         int8u*      BitsToSkip;
802         const vlc*  Vlc;
803         int8u       Size;
804     };
805     #define VLC_END \
806         {(int32u)-1, (int8u)-1, 0, 0, 0}
807     static void Get_VL_Prepare(vlc_fast &Vlc);
808     void Get_VL (const vlc Vlc[], size_t &Info, const char* Name);
809     void Get_VL (vlc_fast &Vlc, size_t &Info, const char* Name);
810     void Skip_VL(const vlc Vlc[], const char* Name);
811     void Skip_VL(vlc_fast &Vlc, const char* Name);
812     #define Info_VL(Vlc, Info, Name) size_t Info; Get_VL(Vlc, Info, Name)
813 
814     //***************************************************************************
815     // Characters
816     //***************************************************************************
817 
818     void Get_C1 (int8u  &Info, const char* Name);
819     void Get_C2 (int16u &Info, const char* Name);
820     void Get_C3 (int32u &Info, const char* Name);
821     void Get_C4 (int32u &Info, const char* Name);
822     void Get_C5 (int64u &Info, const char* Name);
823     void Get_C6 (int64u &Info, const char* Name);
824     void Get_C7 (int64u &Info, const char* Name);
825     void Get_C8 (int64u &Info, const char* Name);
826     void Skip_C1(              const char* Name);
827     void Skip_C2(              const char* Name);
828     void Skip_C3(              const char* Name);
829     void Skip_C4(              const char* Name);
830     void Skip_C5(              const char* Name);
831     void Skip_C6(              const char* Name);
832     void Skip_C7(              const char* Name);
833     void Skip_C8(              const char* Name);
834     #define Info_C1(_INFO, _NAME) int8u  _INFO; Get_C1(_INFO, _NAME)
835     #define Info_C2(_INFO, _NAME) int16u _INFO; Get_C2(_INFO, _NAME)
836     #define Info_C3(_INFO, _NAME) int32u _INFO; Get_C3(_INFO, _NAME)
837     #define Info_C4(_INFO, _NAME) int32u _INFO; Get_C4(_INFO, _NAME)
838     #define Info_C5(_INFO, _NAME) int64u _INFO; Get_C5(_INFO, _NAME)
839     #define Info_C6(_INFO, _NAME) int64u _INFO; Get_C6(_INFO, _NAME)
840     #define Info_C7(_INFO, _NAME) int64u _INFO; Get_C7(_INFO, _NAME)
841     #define Info_C8(_INFO, _NAME) int64u _INFO; Get_C8(_INFO, _NAME)
842 
843     //***************************************************************************
844     // Text
845     //***************************************************************************
846 
847     void Get_Local  (int64u Bytes, Ztring      &Info, const char* Name);
848     void Get_ISO_6937_2(int64u Bytes, Ztring   &Info, const char* Name);
849     void Get_ISO_8859_1(int64u Bytes, Ztring   &Info, const char* Name);
850     void Get_ISO_8859_2(int64u Bytes, Ztring   &Info, const char* Name);
851     void Get_ISO_8859_5(int64u Bytes, Ztring   &Info, const char* Name);
852     void Get_MacRoman(int64u Bytes, Ztring& Info, const char* Name);
853     void Get_String (int64u Bytes, std::string &Info, const char* Name);
854     void Get_UTF8   (int64u Bytes, Ztring      &Info, const char* Name);
855     void Get_UTF16  (int64u Bytes, Ztring      &Info, const char* Name);
856     void Get_UTF16B (int64u Bytes, Ztring      &Info, const char* Name);
857     void Get_UTF16L (int64u Bytes, Ztring      &Info, const char* Name);
858     void Peek_Local (int64u Bytes, Ztring      &Info);
859     void Peek_String(int64u Bytes, std::string &Info);
860     void Skip_Local (int64u Bytes,                    const char* Name);
861     void Skip_ISO_6937_2(int64u Bytes,                const char* Name);
862     void Skip_String(int64u Bytes,                    const char* Name);
863     void Skip_UTF8  (int64u Bytes,                    const char* Name);
864     void Skip_UTF16B(int64u Bytes,                    const char* Name);
865     void Skip_UTF16L(int64u Bytes,                    const char* Name);
866     #define Info_Local(_BYTES, _INFO, _NAME)  Ztring _INFO; Get_Local (_BYTES, _INFO, _NAME)
867     #define Info_ISO_6937_2(_BYTES, _INFO, _NAME)  Ztring _INFO; Get_ISO_6937_2 (_BYTES, _INFO, _NAME)
868     #define Info_UTF8(_BYTES, _INFO, _NAME)   Ztring _INFO; Get_UTF8  (_BYTES, _INFO, _NAME)
869     #define Info_UTF16B(_BYTES, _INFO, _NAME) Ztring _INFO; Get_UTF16B(_BYTES, _INFO, _NAME)
870     #define Info_UTF16L(_BYTES, _INFO, _NAME) Ztring _INFO; Get_UTF16L(_BYTES, _INFO, _NAME)
871 
872     //***************************************************************************
873     // PAscal strings
874     //***************************************************************************
875 
876     void Get_PA (std::string &Info, const char* Name);
877     void Peek_PA(std::string &Info);
878     void Skip_PA(                   const char* Name);
879     #define Info_PA(_INFO, _NAME) Ztring _INFO; Get_PA (_INFO, _NAME)
880 
881     //***************************************************************************
882     // Others, specialized
883     //***************************************************************************
884 
885     #if defined(MEDIAINFO_HEVC_YES) || defined(MEDIAINFO_MPEG4_YES)
886     void Get_MasteringDisplayColorVolume(Ztring &MasteringDisplay_ColorPrimaries, Ztring &MasteringDisplay_Luminance);
887     #endif
888     #if defined(MEDIAINFO_HEVC_YES) || defined(MEDIAINFO_MPEG4_YES) || defined(MEDIAINFO_MATROSKA_YES) || defined(MEDIAINFO_MXF_YES)
889     struct mastering_metadata_2086
890     {
891         int16u Primaries[8];
892         int32u Luminance[2];
893     };
894     void Get_MasteringDisplayColorVolume(Ztring &MasteringDisplay_ColorPrimaries, Ztring &MasteringDisplay_Luminance, mastering_metadata_2086 &Meta);
895     #endif
896     #if defined(MEDIAINFO_MPEGPS_YES) || defined(MEDIAINFO_MPEGTS_YES) || defined(MEDIAINFO_MPEG4_YES) || defined(MEDIAINFO_MK_YES)
897     void dvcC(bool has_dependency_pid=false, std::map<std::string, Ztring>* Infos=NULL);
898     #endif
899 
900     //***************************************************************************
901     // Unknown
902     //***************************************************************************
903 
904     void Skip_XX(int64u Bytes, const char* Name);
905 
906     //***************************************************************************
907     // Flags
908     //***************************************************************************
909 
910     void Get_Flags (int64u Flags, size_t Order, bool  &Info, const char* Name);
911     void Get_Flags (int64u ValueToPut,          int8u &Info, const char* Name);
912     void Skip_Flags(int64u Flags, size_t Order,              const char* Name);
913     void Skip_Flags(int64u ValueToPut,                       const char* Name);
914     #define Get_FlagsM(_VALUE, _INFO, _NAME) Get_Flags(_VALUE, _INFO, _NAME)
915     #define Skip_FlagsM(_VALUE, _NAME) Skip_Flags(_VALUE, _NAME)
916     #define Info_Flags(_FLAGS, _ORDER, _INFO, _NAME) bool _INFO; Get_Flags (_FLAGS, _ORDER, _INFO, _NAME)
917 
918     //***************************************************************************
919     // BitStream
920     //***************************************************************************
921 
922     void Get_BS (int8u  Bits, int32u  &Info, const char* Name);
923     void Get_SB (             bool    &Info, const char* Name);
Get_SB(const char * Name)924     bool Get_SB(                             const char* Name)  {bool Temp; Get_SB(Temp, Name); return Temp;}
925     void Get_S1 (int8u  Bits, int8u   &Info, const char* Name);
926     void Get_S2 (int8u  Bits, int16u  &Info, const char* Name);
927     void Get_S3 (int8u  Bits, int32u  &Info, const char* Name);
928     void Get_S4 (int8u  Bits, int32u  &Info, const char* Name);
929     void Get_S5 (int8u  Bits, int64u  &Info, const char* Name);
930     void Get_S6 (int8u  Bits, int64u  &Info, const char* Name);
931     void Get_S7 (int8u  Bits, int64u  &Info, const char* Name);
932     void Get_S8 (int8u  Bits, int64u  &Info, const char* Name);
933     void Peek_BS(int8u  Bits, int32u  &Info);
934     void Peek_SB(             bool    &Info);
Peek_SB()935     bool Peek_SB()                                              {bool Temp; Peek_SB(Temp); return Temp;}
936     void Peek_S1(int8u  Bits, int8u   &Info);
937     void Peek_S2(int8u  Bits, int16u  &Info);
938     void Peek_S3(int8u  Bits, int32u  &Info);
939     void Peek_S4(int8u  Bits, int32u  &Info);
940     void Peek_S5(int8u  Bits, int64u  &Info);
941     void Peek_S6(int8u  Bits, int64u  &Info);
942     void Peek_S7(int8u  Bits, int64u  &Info);
943     void Peek_S8(int8u  Bits, int64u  &Info);
944     void Skip_BS(size_t Bits,                const char* Name);
945     void Skip_SB(                            const char* Name);
946     void Skip_S1(int8u  Bits,                const char* Name);
947     void Skip_S2(int8u  Bits,                const char* Name);
948     void Skip_S3(int8u  Bits,                const char* Name);
949     void Skip_S4(int8u  Bits,                const char* Name);
950     void Skip_S5(int8u  Bits,                const char* Name);
951     void Skip_S6(int8u  Bits,                const char* Name);
952     void Skip_S7(int8u  Bits,                const char* Name);
953     void Skip_S8(int8u  Bits,                const char* Name);
954     void Mark_0 ();
955     void Mark_0_NoTrustError (); //Use it for providing a warning instead of a non-trusting error
956     void Mark_1 ();
957     void Mark_1_NoTrustError (); //Use it for providing a warning instead of a non-trusting error
958     #define Info_BS(_BITS, _INFO, _NAME) int32u  _INFO; Get_BS(_BITS, _INFO, _NAME)
959     #define Info_SB(_INFO, _NAME)        bool    _INFO; Get_SB(       _INFO, _NAME)
960     #define Info_S1(_BITS, _INFO, _NAME) int8u   _INFO; Get_S1(_BITS, _INFO, _NAME)
961     #define Info_S2(_BITS, _INFO, _NAME) int16u  _INFO; Get_S2(_BITS, _INFO, _NAME)
962     #define Info_S3(_BITS, _INFO, _NAME) int32u  _INFO; Get_S4(_BITS, _INFO, _NAME)
963     #define Info_S4(_BITS, _INFO, _NAME) int32u  _INFO; Get_S4(_BITS, _INFO, _NAME)
964     #define Info_S5(_BITS, _INFO, _NAME) int64u  _INFO; Get_S5(_BITS, _INFO, _NAME)
965     #define Info_S6(_BITS, _INFO, _NAME) int64u  _INFO; Get_S6(_BITS, _INFO, _NAME)
966     #define Info_S7(_BITS, _INFO, _NAME) int64u  _INFO; Get_S7(_BITS, _INFO, _NAME)
967     #define Info_S8(_BITS, _INFO, _NAME) int64u  _INFO; Get_S8(_BITS, _INFO, _NAME)
968 
969     #define TEST_SB_GET(_CODE, _NAME) \
970         { \
971             Peek_SB(_CODE); \
972             if (!_CODE) \
973                 Skip_SB(                                        _NAME); \
974             else \
975             { \
976                 Element_Begin1(_NAME); \
977                 Skip_SB(                                        _NAME); \
978 
979     #define TEST_SB_SKIP(_NAME) \
980         { \
981             if (!Peek_SB()) \
982                 Skip_SB(                                        _NAME); \
983             else \
984             { \
985                 Element_Begin1(_NAME); \
986                 Skip_SB(                                        _NAME); \
987 
988     #define TESTELSE_SB_GET(_CODE, _NAME) \
989         { \
990             Peek_SB(_CODE); \
991             if (_CODE) \
992             { \
993                 Element_Begin1(_NAME); \
994                 Skip_SB(                                        _NAME); \
995 
996     #define TESTELSE_SB_SKIP(_NAME) \
997         { \
998             if (Peek_SB()) \
999             { \
1000                 Element_Begin1(_NAME); \
1001                 Skip_SB(                                        _NAME); \
1002 
1003     #define TESTELSE_SB_ELSE(_NAME) \
1004                 Element_End0(); \
1005             } \
1006             else \
1007             { \
1008                 Skip_SB(                                        _NAME); \
1009 
1010     #define TESTELSE_SB_END() \
1011             } \
1012         } \
1013 
1014     #define TEST_SB_END() \
1015                 Element_End0(); \
1016             } \
1017         } \
1018 
1019     //***************************************************************************
1020     // BitStream (Little Endian)
1021     //***************************************************************************
1022 
1023     void Get_BT (size_t Bits, int32u  &Info, const char* Name);
1024     void Get_TB (             bool    &Info, const char* Name);
Get_TB(const char * Name)1025     bool Get_TB(                             const char* Name)  {bool Temp; Get_TB(Temp, Name); return Temp;}
1026     void Get_T1 (size_t Bits, int8u   &Info, const char* Name);
1027     void Get_T2 (size_t Bits, int16u  &Info, const char* Name);
1028     void Get_T4 (size_t Bits, int32u  &Info, const char* Name);
1029     void Get_T8 (size_t Bits, int64u  &Info, const char* Name);
1030     void Peek_BT(size_t Bits, int32u  &Info);
1031     void Peek_TB(              bool    &Info);
Peek_TB()1032     bool Peek_TB()                                              {bool Temp; Peek_TB(Temp); return Temp;}
1033     void Peek_T1(size_t Bits, int8u   &Info);
1034     void Peek_T2(size_t Bits, int16u  &Info);
1035     void Peek_T4(size_t Bits, int32u  &Info);
1036     void Peek_T8(size_t Bits, int64u  &Info);
1037     void Skip_BT(size_t Bits,                const char* Name);
1038     void Skip_TB(                            const char* Name);
1039     void Skip_T1(size_t Bits,                const char* Name);
1040     void Skip_T2(size_t Bits,                const char* Name);
1041     void Skip_T4(size_t Bits,                const char* Name);
1042     void Skip_T8(size_t Bits,                const char* Name);
1043     #define Info_BT(_BITS, _INFO, _NAME) int32u  _INFO; Get_BT(_BITS, _INFO, _NAME)
1044     #define Info_TB(_INFO, _NAME)        bool    _INFO; Get_TB(       _INFO, _NAME)
1045     #define Info_T1(_BITS, _INFO, _NAME) int8u   _INFO; Get_T1(_BITS, _INFO, _NAME)
1046     #define Info_T2(_BITS, _INFO, _NAME) int16u  _INFO; Get_T2(_BITS, _INFO, _NAME)
1047     #define Info_T4(_BITS, _INFO, _NAME) int32u  _INFO; Get_T4(_BITS, _INFO, _NAME)
1048     #define Info_T8(_BITS, _INFO, _NAME) int64u  _INFO; Get_T8(_BITS, _INFO, _NAME)
1049 
1050     #define TEST_TB_GET(_CODE, _NAME) \
1051         { \
1052             Peek_TB(_CODE); \
1053             if (!_CODE) \
1054                 Skip_TB(                                        _NAME); \
1055             else \
1056             { \
1057                 Element_Begin1(_NAME); \
1058                 Skip_TB(                                        _NAME); \
1059 
1060     #define TEST_TB_SKIP(_NAME) \
1061         { \
1062             if (!Peek_TB()) \
1063                 Skip_TB(                                        _NAME); \
1064             else \
1065             { \
1066                 Element_Begin1(_NAME); \
1067                 Skip_TB(                                        _NAME); \
1068 
1069     #define TESTELSE_TB_GET(_CODE, _NAME) \
1070         { \
1071             Peek_TB(_CODE); \
1072             if (_CODE) \
1073             { \
1074                 Element_Begin1(_NAME); \
1075                 Skip_TB(                                        _NAME); \
1076 
1077     #define TESTELSE_TB_SKIP(_NAME) \
1078         { \
1079             if (Peek_TB()) \
1080             { \
1081                 Element_Begin1(_NAME); \
1082                 Skip_TB(                                        _NAME); \
1083 
1084     #define TESTELSE_TB_ELSE(_NAME) \
1085                 Element_End0(); \
1086             } \
1087             else \
1088             { \
1089                 Skip_TB(                                        _NAME); \
1090 
1091     #define TESTELSE_TB_END() \
1092             } \
1093         } \
1094 
1095     #define TEST_TB_END() \
1096                 Element_End0(); \
1097             } \
1098         } \
1099 
1100     //***************************************************************************
1101     // Next code planning
1102     //***************************************************************************
1103 
1104     void NextCode_Add(int64u Code);
1105     void NextCode_Clear();
1106     bool NextCode_Test();
1107 
1108     //***************************************************************************
1109     // Element trusting
1110     //***************************************************************************
1111 
1112     void Trusted_IsNot (const char* Reason);
Trusted_Get()1113     bool Trusted_Get   () {return !Element[Element_Level].UnTrusted;}
1114 
1115     //***************************************************************************
1116     // Stream filling
1117     //***************************************************************************
1118 
1119     //Elements - Preparation of element from external app
1120     size_t Stream_Prepare   (stream_t KindOfStream, size_t StreamPos=(size_t)-1);
1121     size_t Stream_Erase     (stream_t KindOfStream, size_t StreamPos);
1122 
1123     //Fill with datas (with parameter as a size_t)
1124     void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, const Ztring  &Value, bool Replace=false);
1125     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, const std::string &Value, bool Utf8=true, bool Replace=false) {if (Utf8) Fill(StreamKind, StreamPos, Parameter, Ztring().From_UTF8(Value.c_str(), Value.size()), Replace); else Fill(StreamKind, StreamPos, Parameter, Ztring().From_Local(Value.c_str(), Value.size()), Replace);}
1126     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, const char*    Value, size_t Value_Size=Unlimited, bool Utf8=true, bool Replace=false) {if (Utf8) Fill(StreamKind, StreamPos, Parameter, Ztring().From_UTF8(Value, Value_Size), Replace); else Fill(StreamKind, StreamPos, Parameter, Ztring().From_Local(Value, Value_Size), Replace);}
1127     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, const wchar_t* Value, size_t Value_Size=Unlimited, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring().From_Unicode(Value, Value_Size), Replace);}
1128     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int8u          Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1129     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int8s          Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1130     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int16u         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1131     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int16s         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1132     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int32u         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1133     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int32s         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1134     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int64u         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1135     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, int64s         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1136            void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, float64        Value, int8u AfterComma=3, bool Replace=false);
1137     #ifdef SIZE_T_IS_LONG
1138     inline void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, size_t         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1139     #endif //SIZE_T_IS_LONG
1140     //Fill with datas
1141     void Fill_Dup (stream_t StreamKind, size_t StreamPos, const char* Parameter, const Ztring  &Value, bool Replace=false);
1142     void Fill_Measure (stream_t StreamKind, size_t StreamPos, const char* Parameter, const Ztring  &Value, const Ztring& Measure, bool Replace=false);
1143     inline void Fill_Measure(stream_t StreamKind, size_t StreamPos, const char* Parameter, const string&  Value, const Ztring& Measure, bool Utf8=true, bool Replace=false) {Fill_Measure(StreamKind, StreamPos, Parameter, Ztring().From_UTF8(Value.c_str(), Value.size()), Measure, Replace);}
1144     inline void Fill_Measure(stream_t StreamKind, size_t StreamPos, const char* Parameter, int            Value, const Ztring& Measure, int8u Radix=10, bool Replace=false) {Fill_Measure(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Measure, Replace);}
1145     inline void Fill_Measure(stream_t StreamKind, size_t StreamPos, const char* Parameter, float64        Value, const Ztring& Measure, int8u AfterComma=3, bool Replace=false) {Fill_Measure(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, AfterComma), Measure, Replace);}
1146     void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, const Ztring  &Value, bool Replace=false);
1147     void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, ZtringList &Value, ZtringList& Id, bool Replace=false);
1148     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, const std::string &Value, bool Utf8=true, bool Replace=false) {if (Utf8) Fill(StreamKind, StreamPos, Parameter, Ztring().From_UTF8(Value.c_str(), Value.size()), Replace); else Fill(StreamKind, StreamPos, Parameter, Ztring().From_Local(Value.c_str(), Value.size()), Replace);}
1149     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, const char*    Value, size_t Value_Size=Unlimited, bool Utf8=true, bool Replace=false) {if (Utf8) Fill(StreamKind, StreamPos, Parameter, Ztring().From_UTF8(Value, Value_Size), Replace); else Fill(StreamKind, StreamPos, Parameter, Ztring().From_Local(Value, Value_Size), Replace);}
1150     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, const wchar_t* Value, size_t Value_Size=Unlimited, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring().From_Unicode(Value, Value_Size), Replace);}
1151     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int8u          Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1152     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int8s          Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1153     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int16u         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1154     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int16s         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1155     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int32u         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1156     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int32s         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1157     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int64u         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1158     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, int64s         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1159     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, float32        Value, int8u AfterComma=3, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, AfterComma), Replace);}
1160     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, float64        Value, int8u AfterComma=3, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, AfterComma), Replace);}
1161     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, float80        Value, int8u AfterComma=3, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, AfterComma), Replace);}
1162     #ifdef SIZE_T_IS_LONG
1163     inline void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, size_t         Value, int8u Radix=10, bool Replace=false) {Fill(StreamKind, StreamPos, Parameter, Ztring::ToZtring(Value, Radix).MakeUpperCase(), Replace);}
1164     #endif //SIZE_T_IS_LONG
1165     struct fill_temp_item
1166     {
1167         Ztring Parameter;
1168         Ztring Value;
1169     };
1170     void Fill_SetOptions(stream_t StreamKind, size_t StreamPos, const char* Parameter, const char* Options);
1171     vector<fill_temp_item> Fill_Temp[Stream_Max+1]; // +1 because Fill_Temp[Stream_Max] is used when StreamKind is unknown
1172     map<string, string> Fill_Temp_Options[Stream_Max+1]; // +1 because Fill_Temp[Stream_Max] is used when StreamKind is unknown
1173     void Fill_Flush ();
1174     static size_t Fill_Parameter(stream_t StreamKind, generic StreamPos);
1175 
1176     const Ztring &Retrieve_Const (stream_t StreamKind, size_t StreamPos, size_t Parameter, info_t KindOfInfo=Info_Text);
1177     Ztring Retrieve (stream_t StreamKind, size_t StreamPos, size_t Parameter, info_t KindOfInfo=Info_Text);
1178     const Ztring &Retrieve_Const (stream_t StreamKind, size_t StreamPos, const char* Parameter, info_t KindOfInfo=Info_Text);
1179     Ztring Retrieve (stream_t StreamKind, size_t StreamPos, const char* Parameter, info_t KindOfInfo=Info_Text);
1180 
1181     void Clear (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1182     void Clear (stream_t StreamKind, size_t StreamPos, const char* Parameter);
1183     void Clear (stream_t StreamKind, size_t StreamPos);
1184     void Clear (stream_t StreamKind);
Clear()1185     inline void Clear () {File__Base::Clear();}
1186 
1187     //***************************************************************************
1188     // Filling
1189     //***************************************************************************
1190 
1191     //Actions
1192     void Accept        (const char* ParserName=NULL);
1193     void Accept        (File__Analyze* Parser);
1194     void Reject        (const char* ParserName=NULL);
1195     void Reject        (File__Analyze* Parser);
1196     void Update        (const char* ParserName=NULL);
1197     void Update        (File__Analyze* Parser);
1198     void Fill          (const char* ParserName=NULL);
1199     void Fill          (File__Analyze* Parser);
1200     void Finish        (const char* ParserName=NULL);
1201     void Finish        (File__Analyze* Parser);
1202     void ForceFinish   (const char* ParserName=NULL);
1203     void ForceFinish   (File__Analyze* Parser);
1204     void GoTo          (int64u GoTo, const char* ParserName=NULL);
1205     void GoToFromEnd   (int64u GoToFromEnd, const char* ParserName=NULL);
1206     int64u Element_Code_Get (size_t Level);
1207     int64u Element_TotalSize_Get (size_t LevelLess=0);
1208     bool Element_IsComplete_Get ();
1209     void Element_ThisIsAList ();
1210     void Element_WaitForMoreData ();
1211     void Element_DoNotTrust (const char* Reason);
1212     void Element_DoNotShow ();
1213     void Element_Show ();
1214     void Element_Set_Remove_Children_IfNoErrors ();
1215     void Element_Remove_Children_IfNoErrors ();
1216     void Element_Children_IfNoErrors ();
1217     void Element_DoNotShow_Children ();
1218     void Element_Show_Children ();
1219     bool Element_Show_Get ();
1220     void Element_Show_Add (File__Analyze* node);
1221 
1222     //Status
1223     bool Element_IsOK ();
1224     bool Element_IsNotFinished ();
1225     bool Element_IsWaitingForMoreData ();
1226 
1227     //***************************************************************************
1228     // Merging
1229     //***************************************************************************
1230 
1231     //Utils
1232 public :
1233     size_t Merge(MediaInfo_Internal &ToAdd, bool Erase=true); //Merge 2 File_Base
1234     size_t Merge(MediaInfo_Internal &ToAdd, stream_t StreamKind, size_t StreamPos_From, size_t StreamPos_To, bool Erase=true); //Merge 2 streams
1235     size_t Merge(File__Analyze &ToAdd, bool Erase=true); //Merge 2 File_Base
1236     size_t Merge(File__Analyze &ToAdd, stream_t StreamKind, size_t StreamPos_From, size_t StreamPos_To, bool Erase=true); //Merge 2 streams
1237 
1238     void CodecID_Fill           (const Ztring &Value, stream_t StreamKind, size_t StreamPos, infocodecid_format_t Format, stream_t StreamKind_CodecID=Stream_Max);
1239     void PixelAspectRatio_Fill  (const Ztring &Value, stream_t StreamKind, size_t StreamPos, size_t Parameter_Width, size_t Parameter_Height, size_t Parameter_PixelAspectRatio, size_t Parameter_DisplayAspectRatio);
1240     void DisplayAspectRatio_Fill(const Ztring &Value, stream_t StreamKind, size_t StreamPos, size_t Parameter_Width, size_t Parameter_Height, size_t Parameter_PixelAspectRatio, size_t Parameter_DisplayAspectRatio);
1241     #if MEDIAINFO_EVENTS
Streamkind_Get(int8u * ParserIDs,size_t StreamIDs_Size)1242     static stream_t Streamkind_Get(int8u* ParserIDs, size_t StreamIDs_Size) {if ((ParserIDs[StreamIDs_Size-1]&0xF0)==0x80) return Stream_Video; if ((ParserIDs[StreamIDs_Size-1]&0xF0)==0xA0) return Stream_Audio; return Stream_Max;}
Streamkind_Get()1243     stream_t Streamkind_Get() {return Streamkind_Get(ParserIDs, StreamIDs_Size);}
1244     #endif //MEDIAINFO_EVENTS
1245 
1246     //***************************************************************************
1247     // Finalize
1248     //***************************************************************************
1249 
1250     //End
1251     void Streams_Finish_Global();
1252 
1253 protected :
1254     void Streams_Finish_StreamOnly();
1255     void Streams_Finish_StreamOnly(stream_t StreamKid, size_t StreamPos);
1256     void Streams_Finish_StreamOnly_General(size_t StreamPos);
1257     void Streams_Finish_StreamOnly_Video(size_t StreamPos);
1258     void Streams_Finish_StreamOnly_Audio(size_t StreamPos);
1259     void Streams_Finish_StreamOnly_Text(size_t StreamPos);
1260     void Streams_Finish_StreamOnly_Other(size_t StreamPos);
1261     void Streams_Finish_StreamOnly_Image(size_t StreamPos);
1262     void Streams_Finish_StreamOnly_Menu(size_t StreamPos);
1263     void Streams_Finish_InterStreams();
1264     void Streams_Finish_Cosmetic();
1265     void Streams_Finish_Cosmetic(stream_t StreamKid, size_t StreamPos);
1266     void Streams_Finish_Cosmetic_General(size_t StreamPos);
1267     void Streams_Finish_Cosmetic_Video(size_t StreamPos);
1268     void Streams_Finish_Cosmetic_Audio(size_t StreamPos);
1269     void Streams_Finish_Cosmetic_Text(size_t StreamPos);
1270     void Streams_Finish_Cosmetic_Chapters(size_t StreamPos);
1271     void Streams_Finish_Cosmetic_Image(size_t StreamPos);
1272     void Streams_Finish_Cosmetic_Menu(size_t StreamPos);
1273     void Streams_Finish_HumanReadable();
1274     void Streams_Finish_HumanReadable_PerStream(stream_t StreamKind, size_t StreamPos, size_t Parameter);
1275 
1276     void Tags ();
1277     void Video_FrameRate_Rounding (size_t Pos, video Parameter);
1278     void Video_BitRate_Rounding (size_t Pos, video Parameter);
1279     void Audio_BitRate_Rounding (size_t Pos, audio Parameter);
1280 
1281     //Utils - Finalize
1282     void Duration_Duration123   (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1283     void FileSize_FileSize123   (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1284     void Kilo_Kilo123           (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1285     void Value_Value123         (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1286     void YesNo_YesNo            (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1287 
1288     //***************************************************************************
1289     //
1290     //***************************************************************************
1291 
1292 protected :
1293     //Save for speed improvement
1294     float                           Config_Trace_Level;
1295     std::bitset<32>                 Config_Trace_Layers;
1296     MediaInfo_Config::trace_Format  Config_Trace_Format;
1297     int8u                           Config_Demux;
1298     Ztring                          Config_LineSeparator;
1299     bool                            IsSub;
1300     enum stream_source
1301     {
1302         IsContainer,
1303         IsStream,
1304         IsContainerExtra,
1305         StreamSource_Max,
1306     };
1307     stream_source                   StreamSource;
1308 
1309     //Configuration
1310     bool DataMustAlwaysBeComplete;  //Data must always be complete, else wait for more data
1311     bool MustUseAlternativeParser;  //Must use the second parser (example: for Data part)
1312 
1313     //Synchro
1314     bool MustParseTheHeaderFile;    //There is an header part, must parse it
1315     size_t Trusted;
1316     size_t Trusted_Multiplier;
1317 
1318     //Elements
1319     size_t Element_Level;           //Current level
1320     bool   Element_WantNextLevel;   //Want to go to the next leavel instead of the same level
1321 
1322     //Element
1323     int64u Element_Code;            //Code filled in the file, copy of Element[Element_Level].Code
1324     int64u Element_Offset;          //Position in the Element (without header)
1325     int64u Element_Size;            //Size of the Element (without header)
1326 
1327 private :
1328     //***************************************************************************
1329     // Buffer
1330     //***************************************************************************
1331 
1332     void Buffer_Clear(); //Clear the buffer
1333 protected :
1334     //Buffer
1335     bool Open_Buffer_Continue_Loop();
1336     const int8u* Buffer;
1337 public : //TO CHANGE
1338     size_t Buffer_Size;
1339     int64u Buffer_TotalBytes;
1340     int64u Buffer_TotalBytes_FirstSynched;
1341     int64u Buffer_TotalBytes_LastSynched;
1342     int64u Buffer_PaddingBytes;
1343     int64u Buffer_JunkBytes;
1344     float64 Stream_BitRateFromContainer;
1345 protected :
1346     int8u* Buffer_Temp;
1347     size_t Buffer_Temp_Size;
1348     size_t Buffer_Temp_Size_Max;
1349     size_t Buffer_Offset; //Temporary usage in this parser
1350     size_t Buffer_Offset_Temp; //Temporary usage in this parser
1351     size_t Buffer_MinimumSize;
1352     size_t Buffer_MaximumSize;
1353     int64u Buffer_TotalBytes_FirstSynched_Max;
1354     int64u Buffer_TotalBytes_Fill_Max;
1355     friend class File__Tags_Helper;
1356     friend class File_Usac;
1357     friend class File_Mk;
1358     friend class File_Mpeg4;
1359     friend class File_Hevc;
1360 
1361     //***************************************************************************
1362     // Helpers
1363     //***************************************************************************
1364 
1365     bool FileHeader_Begin_0x000001();
1366     bool FileHeader_Begin_XML(tinyxml2::XMLDocument &Document);
1367     bool Synchronize_0x000001();
1368 public:
1369     #if defined(MEDIAINFO_FILE_YES)
1370     void TestContinuousFileNames(size_t CountOfFiles=24, Ztring FileExtension=Ztring(), bool SkipComputeDelay=false);
1371     void TestDirectory();
1372     #else //defined(MEDIAINFO_FILE_YES)
1373     void TestContinuousFileNames(size_t =24, Ztring =Ztring(), bool =false) {}
1374     void TestDirectory() {}
1375     #endif //defined(MEDIAINFO_FILE_YES)
1376     #if MEDIAINFO_FIXITY
1377     bool FixFile(int64u FileOffsetForWriting, const int8u* ToWrite, const size_t ToWrite_Size);
1378     #endif// MEDIAINFO_FIXITY
1379 
1380 private :
1381 
1382     //***************************************************************************
1383     // Elements
1384     //***************************************************************************
1385 
1386     //Data
1387     size_t Data_Level;              //Current level for Data ("Top level")
1388 
1389     //Element
1390 public: //TO CHANGE
1391     BitStream_Fast* BS;             //For conversion from bytes to bitstream
1392     BitStream*      BT;             //For conversion from bytes to bitstream
1393     int64u          BS_Size;
1394 public : //TO CHANGE
1395     int64u Header_Size;             //Size of the header of the current element
1396     Ztring Details_Get(size_t Level=0) { std::string str; if (Element[Level].TraceNode.Print(Config_Trace_Format, str, Config_LineSeparator.To_UTF8(), File_Size) < 0) return Ztring(); return Ztring().From_UTF8(str);}
1397     void   Details_Clear();
1398 protected :
1399     bool Trace_DoNotSave;
1400     bool Trace_Activated;
1401     std::bitset<32> Trace_Layers;
1402     void Trace_Layers_Update (size_t Layer=(size_t)-1);
1403 private :
1404 #if MEDIAINFO_TRACE
1405     void Trace_Details_Handling(File__Analyze* Sub);
1406 #endif // MEDIAINFO_TRACE
1407     //Elements
1408     size_t Element_Level_Base;      //From other parsers
1409     std::vector<element_details> Element;
1410 
1411     //NextCode
1412     std::map<int64u, bool> NextCode;
1413 
1414     //BookMarks
1415     size_t              BookMark_Element_Level;
1416     int64u              BookMark_GoTo;
1417     std::vector<int64u> BookMark_Code;
1418     std::vector<int64u> BookMark_Next;
1419 
1420 public :
1421     void BookMark_Set(size_t Element_Level_ToGet=(size_t)-1);
1422     void BookMark_Get();
BookMark_Needed()1423     virtual bool BookMark_Needed()                                              {return false;};
1424 
1425     //Temp
1426     std::bitset<32> Status;
1427     enum status
1428     {
1429         IsAccepted,
1430         IsFilled,
1431         IsUpdated,
1432         IsFinished,
1433         Reserved_04,
1434         Reserved_05,
1435         Reserved_06,
1436         Reserved_07,
1437         Reserved_08,
1438         Reserved_09,
1439         Reserved_10,
1440         Reserved_11,
1441         Reserved_12,
1442         Reserved_13,
1443         Reserved_14,
1444         Reserved_15,
1445         User_16,
1446         User_17,
1447         User_18,
1448         User_19,
1449         User_20,
1450         User_21,
1451         User_22,
1452         User_23,
1453         User_24,
1454         User_25,
1455         User_26,
1456         User_27,
1457         User_28,
1458         User_29,
1459         User_30,
1460         User_31,
1461     };
1462     bool ShouldContinueParsing;
1463 
1464     //Configuration
1465     bool MustSynchronize;
1466     bool CA_system_ID_MustSkipSlices;
1467     bool FillAllMergedStreams;
1468     class streamidentity
1469     {
1470     public:
1471         stream_t StreamKind;
1472         size_t   StreamPos;
1473 
streamidentity(stream_t StreamKind_,size_t StreamPos_)1474         streamidentity(stream_t StreamKind_, size_t StreamPos_)
1475             : StreamKind(StreamKind_)
1476             , StreamPos(StreamPos_)
1477         {}
1478     };
1479     std::vector<streamidentity> MergedStreams_Last;
1480 
1481     //Demux
1482     enum contenttype
1483     {
1484         ContentType_MainStream,
1485         ContentType_SubStream,
1486         ContentType_Header,
1487         ContentType_Synchro
1488     };
1489     #if MEDIAINFO_DEMUX
1490         void Demux (const int8u* Buffer, size_t Buffer_Size, contenttype ContentType, const int8u* OriginalBuffer=NULL, size_t OriginalBuffer_Size=0);
Demux_UnpacketizeContainer_Test()1491         virtual bool Demux_UnpacketizeContainer_Test() {return true;}
1492         bool Demux_UnpacketizeContainer_Test_OneFramePerFile();
1493         void Demux_UnpacketizeContainer_Demux(bool random_access=true);
1494         void Demux_UnpacketizeContainer_Demux_Clear();
1495         bool Demux_EventWasSent_Accept_Specific;
1496     #else //MEDIAINFO_DEMUX
1497         #define Demux(_A, _B, _C)
1498     #endif //MEDIAINFO_DEMUX
1499     #if MEDIAINFO_DECODE
1500         void Decoded(const int8u* Buffer, size_t Buffer_Size);
1501     #endif //MEDIAINFO_DECODE
1502 
1503     //Events data
1504     bool    PES_FirstByte_IsAvailable;
1505     bool    PES_FirstByte_Value;
1506 
1507     int64u  Unsynch_Frame_Count;
1508 
1509     //AES
1510     #if MEDIAINFO_AES
1511         AESdecrypt* AES;
1512         int8u*      AES_IV;
1513         int8u*      AES_Decrypted;
1514         size_t      AES_Decrypted_Size;
1515     #endif //MEDIAINFO_AES
1516 
1517     //Hash
1518     #if MEDIAINFO_HASH
1519         HashWrapper*        Hash;
1520         int64u              Hash_Offset;
1521         int64u              Hash_ParseUpTo;
1522     #endif //MEDIAINFO_HASH
1523 
1524     #if MEDIAINFO_SEEK
1525     private:
1526         bool Seek_Duration_Detected;
1527     #endif //MEDIAINFO_SEEK
1528 
1529     #if MEDIAINFO_IBIUSAGE
1530     public:
1531         int64u  Ibi_SynchronizationOffset_Current;
1532         int64u  Ibi_SynchronizationOffset_BeginOfFrame;
1533     #endif //MEDIAINFO_IBIUSAGE
1534     #if MEDIAINFO_IBIUSAGE
1535     public:
1536         bool    Config_Ibi_Create;
1537         ibi     Ibi; //If Main only
1538         ibi::stream* IbiStream; //If sub only
1539         size_t  Ibi_Read_Buffer_Seek        (size_t Method, int64u Value, int64u ID);
1540         void    Ibi_Read_Buffer_Unsynched   ();
1541         void    Ibi_Stream_Finish           ();
1542         void    Ibi_Stream_Finish           (int64u Numerator, int64u Denominator); //Partial
1543         void    Ibi_Add                     ();
1544     #else //MEDIAINFO_IBIUSAGE
Ibi_Read_Buffer_Seek(size_t,int64u,int64u)1545         size_t  Ibi_Read_Buffer_Seek        (size_t, int64u, int64u)            {return (size_t)-1;}
Ibi_Read_Buffer_Unsynched()1546         void    Ibi_Read_Buffer_Unsynched   ()                                  {}
Ibi_Stream_Finish()1547         void    Ibi_Stream_Finish           ()                                  {}
Ibi_Stream_Finish(int64u,int64u)1548         void    Ibi_Stream_Finish           (int64u, int64u)                    {}
Ibi_Add()1549         void    Ibi_Add                     ()                                  {}
1550     #endif //MEDIAINFO_IBIUSAGE
1551 };
1552 
1553 //Helpers
1554 #define DETAILS_INFO(_DATA) _DATA
1555 
1556 #endif //MEDIAINFO_TRACE
1557 
1558 } //NameSpace
1559 
1560 
1561 
1562 /*
1563 #define BS_END() \
1564     { \
1565         BS.Byte_Align(); \
1566         int32u BS_Value=0x00; \
1567         while(BS.Remain()>0 && BS_Value==0x00) \
1568             BS_Value=BS.Get(8); \
1569         if (BS_Value!=0x00) \
1570             INTEGRITY_SIZE(BS.Offset_Get()-1, BS.Offset_Get()) \
1571         else \
1572             INTEGRITY_SIZE(BS.Offset_Get(), BS.Offset_Get()) \
1573     } \
1574 
1575 #define BS_END_FF() \
1576     { \
1577         BS.Byte_Align(); \
1578         int32u BS_Value=0xFF; \
1579         while(BS.Remain()>0 && BS_Value==0x00) \
1580             BS_Value=BS.Get(8); \
1581         if (BS_Value!=0xFF) \
1582             INTEGRITY_SIZE(BS.Offset_Get()-1, BS.Offset_Get()) \
1583         else \
1584             INTEGRITY_SIZE(BS.Offset_Get(), BS.Offset_Get()) \
1585     } \
1586 
1587 #define BS_END_CANBEMORE() \
1588     { \
1589     } \
1590 */
1591 
1592 
1593     //Begin
1594     #define FILLING_BEGIN() \
1595         if (Element_IsOK()) \
1596         {
1597 
1598     #define FILLING_BEGIN_PRECISE() \
1599         if (Element_Offset!=Element_Size) \
1600         { \
1601             Trusted_IsNot("Size is wrong"); \
1602         } \
1603         if (Element_IsOK()) \
1604         {
1605 
1606     //Else
1607     #define FILLING_ELSE() \
1608         } \
1609         else \
1610         { \
1611 
1612     //End
1613     #define FILLING_END() \
1614         }
1615 
1616 #define ATOM_BEGIN \
1617     if (Level!=Element_Level) \
1618     { \
1619         Level++; \
1620         switch (Element_Code_Get(Level)) \
1621         { \
1622 
1623 #define ATOM(_ATOM) \
1624             case Elements::_ATOM : \
1625                     if (Level==Element_Level) \
1626                     { \
1627                         if (Element_IsComplete_Get()) \
1628                             _ATOM(); \
1629                         else \
1630                         { \
1631                             Element_WaitForMoreData(); \
1632                             return; \
1633                         } \
1634                     } \
1635                     break; \
1636 
1637 #define ATOM_PARTIAL(_ATOM) \
1638             case Elements::_ATOM : \
1639                     if (Level==Element_Level) \
1640                         _ATOM(); \
1641                     break; \
1642 
1643 #define ATOM_DEFAULT(_ATOM) \
1644             default : \
1645                     if (Level==Element_Level) \
1646                     { \
1647                         if (Element_IsComplete_Get()) \
1648                             _ATOM(); \
1649                         else \
1650                         { \
1651                             Element_WaitForMoreData(); \
1652                             return; \
1653                         } \
1654                     } \
1655                     break; \
1656 
1657 #define ATOM_END \
1658             default : \
1659             Skip_XX(Element_TotalSize_Get(), "Unknown"); \
1660         } \
1661     } \
1662     break; \
1663 
1664 #define LIST(_ATOM) \
1665     case Elements::_ATOM : \
1666             if (Level==Element_Level) \
1667             { \
1668                 Element_ThisIsAList(); \
1669                 _ATOM(); \
1670             } \
1671 
1672 #define LIST_COMPLETE(_ATOM) \
1673     case Elements::_ATOM : \
1674             if (Level==Element_Level) \
1675             { \
1676                 if (Element_IsComplete_Get()) \
1677                 { \
1678                     Element_ThisIsAList(); \
1679                     _ATOM(); \
1680                 } \
1681                 else \
1682                 { \
1683                     Element_WaitForMoreData(); \
1684                     return; \
1685                 } \
1686             } \
1687 
1688 #define LIST_DEFAULT(_ATOM) \
1689             default : \
1690             if (Level==Element_Level) \
1691             { \
1692                 Element_ThisIsAList(); \
1693                 _ATOM(); \
1694             } \
1695 
1696 #define LIST_DEFAULT_COMPLETE(_ATOM) \
1697             default : \
1698             if (Level==Element_Level) \
1699             { \
1700                 if (Element_IsComplete_Get()) \
1701                 { \
1702                     Element_ThisIsAList(); \
1703                     _ATOM(); \
1704                 } \
1705                 else \
1706                 { \
1707                     Element_WaitForMoreData(); \
1708                     return; \
1709                 } \
1710             } \
1711 
1712 #define ATOM_END_DEFAULT \
1713         } \
1714     } \
1715     break; \
1716 
1717 #define ATOM_DEFAULT_ALONE(_ATOM) \
1718     if (Level!=Element_Level) \
1719     { \
1720         Level++; \
1721         if (Level==Element_Level) \
1722         { \
1723             if (Element_IsComplete_Get()) \
1724                 _ATOM(); \
1725             else \
1726             { \
1727                 Element_WaitForMoreData(); \
1728                 return; \
1729             } \
1730         } \
1731     } \
1732     break; \
1733 
1734 #define LIST_DEFAULT_ALONE_BEGIN(_ATOM) \
1735     if (Level!=Element_Level) \
1736     { \
1737         Level++; \
1738         if (Level==Element_Level) \
1739         { \
1740             Element_ThisIsAList(); \
1741             _ATOM(); \
1742         } \
1743 
1744 #define LIST_DEFAULT_ALONE_END \
1745     } \
1746     break; \
1747 
1748 #define LIST_SKIP(_ATOM) \
1749     case Elements::_ATOM : \
1750             if (Level==Element_Level) \
1751             { \
1752                 Element_ThisIsAList(); \
1753                 _ATOM(); \
1754             } \
1755             break; \
1756 
1757 
1758 #define DATA_BEGIN \
1759     size_t Level=0; \
1760     ATOM_BEGIN \
1761 
1762 #define DATA_END \
1763             default : ; \
1764                 Skip_XX(Element_TotalSize_Get(), "Unknown"); \
1765         } \
1766     } \
1767 
1768 #define DATA_DEFAULT \
1769         default : \
1770 
1771 #define DATA_END_DEFAULT \
1772         } \
1773     } \
1774 
1775 #endif
1776