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__AnalyzeMinimizeSizeH
9 #define MediaInfo_File__AnalyzeMinimizeSizeH
10 //---------------------------------------------------------------------------
11 
12 //***************************************************************************
13 // Class File__Analyze
14 //***************************************************************************
15 
16 class File__Analyze : public File__Base
17 {
18 public :
19     //***************************************************************************
20     // Constructor/Destructor
21     //***************************************************************************
22 
23     File__Analyze();
24     virtual ~File__Analyze();
25 
26     //***************************************************************************
27     // Open
28     //***************************************************************************
29 
30     void    Open_Buffer_Init        (                    int64u File_Size);
31     void    Open_Buffer_Init        (File__Analyze* Sub);
32     void    Open_Buffer_Init        (File__Analyze* Sub, int64u File_Size);
Open_Buffer_OutOfBand(const int8u * Buffer,size_t Buffer_Size)33     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;}
34     void    Open_Buffer_OutOfBand   (File__Analyze* Sub                     , size_t Buffer_Size);
Open_Buffer_OutOfBand(File__Analyze * Sub)35     void    Open_Buffer_OutOfBand   (File__Analyze* Sub) {Open_Buffer_OutOfBand(Sub, Element_Size-Element_Offset);};
36     void    Open_Buffer_Continue    (                    const int8u* Buffer, size_t Buffer_Size);
37     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)38     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)39     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;}
40     void    Open_Buffer_Position_Set(int64u File_Offset);
41     void    Open_Buffer_CheckFileModifications();
42     #if MEDIAINFO_SEEK
43     size_t  Open_Buffer_Seek        (size_t Method, int64u Value, int64u ID);
44     #endif //MEDIAINFO_SEEK
45     #if MEDIAINFO_ADVANCED2
46     void    Open_Buffer_SegmentChange();
47     #endif //MEDIAINFO_ADVANCED2
48     void    Open_Buffer_Unsynch     ();
49     void    Open_Buffer_Update      ();
50     void    Open_Buffer_Update      (File__Analyze* Sub);
51     void    Open_Buffer_Finalize    (bool NoBufferModification=false);
52     void    Open_Buffer_Finalize    (File__Analyze* Sub);
53 
54     //***************************************************************************
55     // In/Out (for parsers)
56     //***************************************************************************
57 
58     //In
59     std::string ParserName;
60     #if MEDIAINFO_EVENTS
61         size_t  StreamIDs_Size;
62         int64u  StreamIDs[16];
63         int8u   StreamIDs_Width[16];
64         int8u   ParserIDs[16];
65         void    Event_Prepare (struct MediaInfo_Event_Generic* Event, int32u Event_Code, size_t Event_Size);
66     #endif //MEDIAINFO_EVENTS
67     #if MEDIAINFO_DEMUX
68         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
69         bool    Demux_random_access;
70         bool    Demux_UnpacketizeContainer;
71         bool    Demux_IntermediateItemFound;
72         size_t  Demux_Offset;
73         int64u  Demux_TotalBytes;
74         File__Analyze* Demux_CurrentParser;
75     #endif //MEDIAINFO_DEMUX
76     Ztring  File_Name_WithoutDemux;
77     bool   PTS_DTS_Needed;
78     enum ts_type
79     {
80         TS_NONE=0,
81         TS_PTS=1,
82         TS_DTS=2,
83         TS_ALL=TS_PTS|TS_DTS,
84     };
85     void   TS_Clear(ts_type Type=TS_ALL);
86     void   TS_Set(int64s Ticks, ts_type Type=TS_ALL);
87     void   TS_Set(File__Analyze* Parser, ts_type Type=TS_ALL);
88     void   TS_Add(int64s Ticks, ts_type Type=TS_ALL);
89     void   TS_Ajust(int64s Ticks);
90     int64s Frequency_c; //Frequency of the timestamp of the container (e.g. 90000 for MPEG-PS)
91     int64s Frequency_b; //Frequency of the timestamp of the bitstream (e.g. 48000 for AC-3)
92     #if MEDIAINFO_ADVANCED2
93     static const int64s NoTs=0x8000000000000000LL;
94     int64s PTSb; //In 1/Frequency_b if sub, in 1/(Frequency_c*Frequency_b) if in a container
95     int64s DTSb; //In 1/Frequency_b if sub, in 1/(Frequency_c*Frequency_b) if in a container
96     #endif //MEDIAINFO_ADVANCED2
97     struct frame_info
98     {
99         int64u Buffer_Offset_End;
100         int64u PCR; //In nanoseconds
101         int64u PTS; //In nanoseconds
102         int64u DTS; //In nanoseconds
103         int64u DUR; //In nanoseconds
104         #if MEDIAINFO_ADVANCED2
105         int64s PTSc; //In 1/Frequency_c
106         int64s DTSc; //In 1/Frequency_c
107         int64u Frame_Count_AfterLastTimeStamp;
108         #endif //MEDIAINFO_ADVANCED2
109 
frame_infoframe_info110         frame_info()
111         {
112             Buffer_Offset_End=(int64u)-1;
113             PCR=(int64u)-1;
114             PTS=(int64u)-1;
115             DTS=(int64u)-1;
116             DUR=(int64u)-1;
117             #if MEDIAINFO_ADVANCED2
118             PTSc=NoTs;
119             DTSc=NoTs;
120             Frame_Count_AfterLastTimeStamp=0;
121             #endif //MEDIAINFO_ADVANCED2
122         }
123     };
124     frame_info FrameInfo;
125     frame_info FrameInfo_Previous;
126     frame_info FrameInfo_Next;
127     std::vector<int64u> Offsets_Stream;
128     std::vector<int64u> Offsets_Buffer;
129     size_t              Offsets_Pos;
130     int8u*              OriginalBuffer;
131     size_t              OriginalBuffer_Size;
132     size_t              OriginalBuffer_Capacity;
133     #if defined(MEDIAINFO_EIA608_YES) || defined(MEDIAINFO_EIA708_YES)
134         struct servicedescriptor
135         {
136             string language;
137         };
138         typedef std::map<int8u, servicedescriptor> servicedescriptors608;
139         typedef std::map<int8u, servicedescriptor> servicedescriptors708;
140         struct servicedescriptors
141         {
142             #if defined(MEDIAINFO_EIA608_YES)
143                 std::map<int8u, servicedescriptor> ServiceDescriptors608;
144             #endif
145             #if defined(MEDIAINFO_EIA708_YES)
146                 std::map<int8u, servicedescriptor> ServiceDescriptors708;
147             #endif
148         };
149         servicedescriptors* ServiceDescriptors;
150     #endif
151     #if defined(MEDIAINFO_TELETEXT_YES)
152         struct teletext
153         {
154             std::map<std::string, Ztring>           Infos;
155             stream_t                                StreamKind;
156             size_t                                  StreamPos;
157 
teletextteletext158             teletext()
159                 : StreamKind(Stream_Max)
160                 , StreamPos((size_t)-1)
161             {}
162         };
163         std::map<int16u, teletext>*                 Teletexts; //Key is teletext_magazine_number
164     #endif
165 
166     //Out
167     int64u PTS_Begin;                  //In nanoseconds
168     #if MEDIAINFO_ADVANCED2
169     int64u PTS_Begin_Segment;          //In nanoseconds
170     #endif //MEDIAINFO_ADVANCED2
171     int64u PTS_End;                    //In nanoseconds
172     int64u DTS_Begin;                  //In nanoseconds
173     int64u DTS_End;                    //In nanoseconds
174     int64u Frame_Count;
175     int64u Frame_Count_Previous;
176     int64u Frame_Count_InThisBlock;
177     int64u Field_Count;
178     int64u Field_Count_Previous;
179     int64u Field_Count_InThisBlock;
180     int64u Frame_Count_NotParsedIncluded;
181     int64u FrameNumber_PresentationOrder;
182     bool   Synched;                    //Data is synched
183     bool   UnSynched_IsNotJunk;        //Data is actually synched
184     bool   MustExtendParsingDuration;  //Data has some substreams difficult to detect (e.g. captions), must wait a bit before final filling
185 
186 protected :
187     //***************************************************************************
188     // Streams management
189     //***************************************************************************
190 
Streams_Accept()191     virtual void Streams_Accept()                                               {};
Streams_Fill()192     virtual void Streams_Fill()                                                 {};
Streams_Update()193     virtual void Streams_Update()                                               {};
Streams_Finish()194     virtual void Streams_Finish()                                               {};
195 
196     //***************************************************************************
197     // Synchro
198     //***************************************************************************
199 
Synchronize()200     virtual bool Synchronize()    {Synched=true; return true;}; //Look for the synchro
Synched_Test()201     virtual bool Synched_Test()   {return true;}; //Test is synchro is OK
Synched_Init()202     virtual void Synched_Init()   {}; //When synched, we can Init data
203     bool Synchro_Manage();
204     bool Synchro_Manage_Test();
205 
206     //***************************************************************************
207     // Buffer
208     //***************************************************************************
209 
210     //Buffer
Read_Buffer_Init()211     virtual void Read_Buffer_Init ()          {}; //Temp, should be in File__Base caller
Read_Buffer_OutOfBand()212     virtual void Read_Buffer_OutOfBand ()     {Open_Buffer_Continue(Buffer, Buffer_Size);} //Temp, should be in File__Base caller
Read_Buffer_Continue()213     virtual void Read_Buffer_Continue ()      {}; //Temp, should be in File__Base caller
Read_Buffer_CheckFileModifications()214     virtual void Read_Buffer_CheckFileModifications() {} //Temp, should be in File__Base caller
Read_Buffer_AfterParsing()215     virtual void Read_Buffer_AfterParsing ()  {}; //Temp, should be in File__Base caller
216     #if MEDIAINFO_SEEK
217     virtual size_t Read_Buffer_Seek (size_t, int64u, int64u); //Temp, should be in File__Base caller
218     size_t Read_Buffer_Seek_OneFramePerFile (size_t, int64u, int64u);
219     #endif //MEDIAINFO_SEEK
220     #if MEDIAINFO_ADVANCED2
Read_Buffer_SegmentChange()221     virtual void Read_Buffer_SegmentChange () {}; //Temp, should be in File__Base caller
222     #endif //MEDIAINFO_ADVANCED2
Read_Buffer_Unsynched()223     virtual void Read_Buffer_Unsynched ()     {}; //Temp, should be in File__Base caller
224     void Read_Buffer_Unsynched_OneFramePerFile ();
Read_Buffer_Finalize()225     virtual void Read_Buffer_Finalize ()      {}; //Temp, should be in File__Base caller
226     bool Buffer_Parse();
227 
228     //***************************************************************************
229     // BitStream init
230     //***************************************************************************
231 
232     void BS_Begin();
233     void BS_Begin_LE(); //Little Endian version
234     void BS_End();
235     void BS_End_LE(); //Little Endian version
236 
237     //***************************************************************************
238     // File Header
239     //***************************************************************************
240 
241     //File Header - Management
242     bool FileHeader_Manage ();
243 
244     //File Header - Begin
FileHeader_Begin()245     virtual bool FileHeader_Begin ()                                            {return true;};
246 
247     //File Header - Parse
FileHeader_Parse()248     virtual void FileHeader_Parse ()                                            {Element_DoNotShow();};
249 
250     //***************************************************************************
251     // Header
252     //***************************************************************************
253 
254     //Header - Management
255     bool Header_Manage ();
256 
257     //Header - Begin
Header_Begin()258     virtual bool Header_Begin ()                                                {return true;};
259 
260     //Header - Parse
261     virtual void Header_Parse ();
262 
263     //Header - Info
264     void Header_Fill_Code (int64u Code);
Header_Fill_Code(int64u Code,const Ztring &)265     inline void Header_Fill_Code (int64u Code, const Ztring &) {Header_Fill_Code(Code);};
266     #define Header_Fill_Code2(A,B) Header_Fill_Code(A)
267     void Header_Fill_Size (int64u Size);
268 
269     //***************************************************************************
270     // Data
271     //***************************************************************************
272 
273     //Header - Management
274     bool Data_Manage ();
275 
276     //Data - Parse
Data_Parse()277     virtual void Data_Parse ()                                                  {};
278 
279     //Data - Info
Data_Info(const Ztring &)280     inline void Data_Info (const Ztring &)                                      {};
Data_Info_From_Milliseconds(int64u)281     inline void Data_Info_From_Milliseconds (int64u)                            {}
282 
283     //Data - Get info
Data_Remain()284     size_t Data_Remain ()                                                       {return (size_t)(Element_Size-(Element_Offset+BS->Offset_Get()));};
Data_BS_Remain()285     size_t Data_BS_Remain ()                                                    {return (size_t)BS->Remain();};
286 
287     //Data - Detect EOF
Detect_EOF()288     virtual void Detect_EOF ()                                                  {};
289     bool EOF_AlreadyDetected;
290 
291     //Data - Helpers
Data_Accept(const char *)292     void Data_Accept        (const char*)                                       {Accept();}
Data_Accept()293     void Data_Accept        ()                                                  {Accept();}
Data_Reject(const char *)294     void Data_Reject        (const char*)                                       {Reject();}
Data_Reject()295     void Data_Reject        ()                                                  {Reject();}
Data_Finish(const char *)296     void Data_Finish        (const char*)                                       {ForceFinish();}
Data_Finish()297     void Data_Finish        ()                                                  {ForceFinish();}
Data_GoTo(int64u GoTo_,const char *)298     void Data_GoTo          (int64u GoTo_, const char*)                         {GoTo(GoTo_);}
Data_GoTo(int64u GoTo_)299     void Data_GoTo          (int64u GoTo_)                                      {GoTo(GoTo_);}
Data_GoToFromEnd(int64u GoToFromEnd_,const char *)300     void Data_GoToFromEnd   (int64u GoToFromEnd_, const char*)                  {GoToFromEnd(GoToFromEnd_);}
Data_GoToFromEnd(int64u GoToFromEnd_)301     void Data_GoToFromEnd   (int64u GoToFromEnd_)                               {GoToFromEnd(GoToFromEnd_);}
302 
303     //***************************************************************************
304     // Elements
305     //***************************************************************************
306 
307     //Elements - Begin
308     void Element_Begin ();
309     #define Element_Begin0() Element_Begin()
310     #define Element_Begin1(_NAME) Element_Begin()
311     #define Element_Trace_Begin0()
312     #define Element_Trace_Begin1(_NAME)
313 
314     //Elements - Name
315     #define Element_Name(_A)
316 
317     //Elements - Info
318     #define Element_Info1(_A)
319     #define Element_Info2(_A,_B)
320     #define Element_Info3(_A,_B,_C)
321     #define Element_Info1C(_CONDITION,_A)
322     #define Element_Info_From_Milliseconds(_A)
323     #define Element_Parser(_A) {}
324     #define Element_Error(_A) {}
325     #define Param_Error(_A) {}
326 
327     //Elements - End
Element_End()328     inline void Element_End () {Element_End_Common_Flush();}
329     #define Element_End0() Element_End()
330     #define Element_End1(_NAME) Element_End()
331     #define Element_Trace_End0()
332     #define Element_Trace_End1(_NAME)
333 
334     //Elements - Preparation of element from external app
335     void Element_Prepare (int64u Size);
336 
337 protected :
338     //Element - Common
339     void   Element_End_Common_Flush();
340 public :
341 
342     //***************************************************************************
343     // Param
344     //***************************************************************************
345 
346     //Param - Main
noop()347     inline void noop() {}
348     #define Param1(_A) noop()
349     #define Param2(_A,_B) noop()
350     #define Param3(_A,_B,_C) noop()
351 
352     //Param - Info
353     #define Param_Info1(_A) noop()
354     #define Param_Info2(_A,_B) noop()
355     #define Param_Info3(_A,_B,_C) noop()
356     #define Param_Info1C(_CONDITION,_A) noop()
357     #define Param_Info2C(_CONDITION,_A,_B) noop()
358     #define Param_Info3C(_CONDITION,_A,_B,_C) noop()
359     #define Param_Info_From_Milliseconds(A) noop()
360 
361     //***************************************************************************
362     // Information
363     //***************************************************************************
364 
365     inline void Info (const std::string&, size_t =0) {}
366 
367     //***************************************************************************
368     // Big Endian (Integer, Float, Fixed-Point)
369     //***************************************************************************
370 
371     void Get_B1_   (int8u   &Info);
372     void Get_B2_   (int16u  &Info);
373     void Get_B3_   (int32u  &Info);
374     void Get_B4_   (int32u  &Info);
375     void Get_B5_   (int64u  &Info);
376     void Get_B6_   (int64u  &Info);
377     void Get_B7_   (int64u  &Info);
378     void Get_B8_   (int64u  &Info);
379     void Get_B16_  (int128u &Info);
380     void Get_BF2_  (float32 &Info);
381     void Get_BF4_  (float32 &Info);
382     void Get_BF8_  (float64 &Info);
383     void Get_BF10_ (float80 &Info);
384     void Get_BFP4_ (int8u  Bits, float32 &Info);
385     #define Get_B1(Info, Name) Get_B1_(Info)
386     #define Get_B2(Info, Name) Get_B2_(Info)
387     #define Get_B3(Info, Name) Get_B3_(Info)
388     #define Get_B4(Info, Name) Get_B4_(Info)
389     #define Get_B5(Info, Name) Get_B5_(Info)
390     #define Get_B6(Info, Name) Get_B6_(Info)
391     #define Get_B7(Info, Name) Get_B7_(Info)
392     #define Get_B8(Info, Name) Get_B8_(Info)
393     #define Get_B16(Info, Name) Get_B16_(Info)
394     #define Get_BF2(Info, Name) Get_BF2_(Info)
395     #define Get_BF4(Info, Name) Get_BF4_(Info)
396     #define Get_BF8(Info, Name) Get_BF8_(Info)
397     #define Get_BF10(Info, Name) Get_BF10_(Info)
398     #define Get_BFP4(Bits, Info, Name) Get_BFP4_(Bits, Info)
399     void Peek_B1  (int8u   &Info);
400     void Peek_B2  (int16u  &Info);
401     void Peek_B3  (int32u  &Info);
402     void Peek_B4  (int32u  &Info);
403     void Peek_B5  (int64u  &Info);
404     void Peek_B6  (int64u  &Info);
405     void Peek_B7  (int64u  &Info);
406     void Peek_B8  (int64u  &Info);
407     void Peek_B16 (int128u &Info);
408     void Peek_BF4 (float32 &Info);
409     void Peek_BF8 (float64 &Info);
410     void Peek_BF10(float64 &Info);
411     void Peek_BFP4(int8u  Bits, float64 &Info);
412     #define Skip_B1(Name) Element_Offset++
413     #define Skip_B2(Name) Element_Offset+=2
414     #define Skip_B3(Name) Element_Offset+=3
415     #define Skip_B4(Name) Element_Offset+=4
416     #define Skip_B5(Name) Element_Offset+=5
417     #define Skip_B6(Name) Element_Offset+=6
418     #define Skip_B7(Name) Element_Offset+=7
419     #define Skip_B8(Name) Element_Offset+=8
420     #define Skip_BF4(Name) Element_Offset+=4
421     #define Skip_BF8(Name) Element_Offset+=8
422     #define Skip_B16(Name) Element_Offset+=16
423     #define Skip_BFP4(Size, Name) Element_Offset+=4
424     #define Skip_Hexa(Bytes, Name) Element_Offset+=Bytes
425     #define Info_B1(_INFO, _NAME)   Element_Offset++
426     #define Info_B2(_INFO, _NAME)   Element_Offset+=2
427     #define Info_B3(_INFO, _NAME)   Element_Offset+=3
428     #define Info_B4(_INFO, _NAME)   Element_Offset+=4
429     #define Info_B5(_INFO, _NAME)   Element_Offset+=5
430     #define Info_B6(_INFO, _NAME)   Element_Offset+=6
431     #define Info_B7(_INFO, _NAME)   Element_Offset+=7
432     #define Info_B8(_INFO, _NAME)   Element_Offset+=8
433     #define Info_B16(_INFO, _NAME)  Element_Offset+=16
434     #define Info_BF4(_INFO, _NAME)  Element_Offset+=4
435     #define Info_BF8(_INFO, _NAME)  Element_Offset+=8
436     #define Info_BF10(_INFO, _NAME) Element_Offset+=10
437     #define Info_BFP4(_BITS, _INFO, _NAME) Element_Offset+=4
438 
439     //***************************************************************************
440     // Little Endian
441     //***************************************************************************
442 
443     void Get_L1_   (int8u   &Info);
444     void Get_L2_   (int16u  &Info);
445     void Get_L3_   (int32u  &Info);
446     void Get_L4_   (int32u  &Info);
447     void Get_L5_   (int64u  &Info);
448     void Get_L6_   (int64u  &Info);
449     void Get_L7_   (int64u  &Info);
450     void Get_L8_   (int64u  &Info);
451     void Get_L16_  (int128u &Info);
452     void Get_LF4_  (float32 &Info);
453     void Get_LF8_  (float64 &Info);
454     void Get_LF10_ (float80 &Info);
455     void Get_LFP4_ (int8u  Bits, float32 &Info);
456     #define Get_L1(Info, Name) Get_L1_(Info)
457     #define Get_L2(Info, Name) Get_L2_(Info)
458     #define Get_L3(Info, Name) Get_L3_(Info)
459     #define Get_L4(Info, Name) Get_L4_(Info)
460     #define Get_L5(Info, Name) Get_L5_(Info)
461     #define Get_L6(Info, Name) Get_L6_(Info)
462     #define Get_L7(Info, Name) Get_L7_(Info)
463     #define Get_L8(Info, Name) Get_L8_(Info)
464     #define Get_L16(Info, Name) Get_L16_(Info)
465     #define Get_LF4(Info, Name) Get_LF4_(Info)
466     #define Get_LF8(Info, Name) Get_LF8_(Info)
467     #define Get_LF10(Info, Name) Get_LF10_(Info)
468     #define Get_LFP4(Bits, Info, Name) Get_LFP4_(Bits, Info)
469     void Peek_L1  (int8u   &Info);
470     void Peek_L2  (int16u  &Info);
471     void Peek_L3  (int32u  &Info);
472     void Peek_L4  (int32u  &Info);
473     void Peek_L5  (int64u  &Info);
474     void Peek_L6  (int64u  &Info);
475     void Peek_L7  (int64u  &Info);
476     void Peek_L8  (int64u  &Info);
477     void Peek_L16 (int128u &Info);
478     void Peek_LF4 (float32 &Info);
479     void Peek_LF8 (float64 &Info);
480     void Peek_LF10(float64 &Info);
481     void Peek_LFP4(int8u  Bits, float64 &Info);
482     #define Skip_L1(Name) Element_Offset++
483     #define Skip_L2(Name) Element_Offset+=2
484     #define Skip_L3(Name) Element_Offset+=3
485     #define Skip_L4(Name) Element_Offset+=4
486     #define Skip_L5(Name) Element_Offset+=5
487     #define Skip_L6(Name) Element_Offset+=6
488     #define Skip_L7(Name) Element_Offset+=7
489     #define Skip_L8(Name) Element_Offset+=8
490     #define Skip_LF4(Name) Element_Offset+=4
491     #define Skip_LF8(Name) Element_Offset+=8
492     #define Skip_L16(Name) Element_Offset+=16
493     #define Skip_LFP4(Size, Name) Element_Offset+=4
494     #define Info_L1(_INFO, _NAME)   Element_Offset++
495     #define Info_L2(_INFO, _NAME)   Element_Offset+=2
496     #define Info_L3(_INFO, _NAME)   Element_Offset+=3
497     #define Info_L4(_INFO, _NAME)   Element_Offset+=4
498     #define Info_L5(_INFO, _NAME)   Element_Offset+=5
499     #define Info_L6(_INFO, _NAME)   Element_Offset+=6
500     #define Info_L7(_INFO, _NAME)   Element_Offset+=7
501     #define Info_L8(_INFO, _NAME)   Element_Offset+=8
502     #define Info_L16(_INFO, _NAME)  Element_Offset+=16
503     #define Info_LF4(_INFO, _NAME)  Element_Offset+=4
504     #define Info_LF8(_INFO, _NAME)  Element_Offset+=8
505     #define Info_LF10(_INFO, _NAME) Element_Offset+=10
506     #define Info_LFP4(_LITS, _INFO, _NAME) Element_Offset+=4
507 
508     //***************************************************************************
509     // Little and Big Endian together
510     //***************************************************************************
511 
512     void Get_D1_   (int8u   &Info);
513     void Get_D2_   (int16u  &Info);
514     void Get_D3_   (int32u  &Info);
515     void Get_D4_   (int32u  &Info);
516     void Get_D5_   (int64u  &Info);
517     void Get_D6_   (int64u  &Info);
518     void Get_D7_   (int64u  &Info);
519     void Get_D8_   (int64u  &Info);
520     void Get_D16_  (int128u &Info);
521     void Get_DF4_  (float32 &Info);
522     void Get_DF8_  (float64 &Info);
523     void Get_DF10_ (float80 &Info);
524     void Get_DFP4_ (int8u  Bits, float32 &Info);
525     #define Get_D1(Info, Name) Get_D1_(Info)
526     #define Get_D2(Info, Name) Get_D2_(Info)
527     #define Get_D3(Info, Name) Get_D3_(Info)
528     #define Get_D4(Info, Name) Get_D4_(Info)
529     #define Get_D5(Info, Name) Get_D5_(Info)
530     #define Get_D6(Info, Name) Get_D6_(Info)
531     #define Get_D7(Info, Name) Get_D7_(Info)
532     #define Get_D8(Info, Name) Get_D8_(Info)
533     #define Get_D16(Info, Name) Get_D16_(Info)
534     #define Get_DF4(Info, Name) Get_DF4_(Info)
535     #define Get_DF8(Info, Name) Get_DF8_(Info)
536     #define Get_DF10(Info, Name) Get_DF10_(Info)
537     #define Get_DFP4(Bits, Info, Name) Get_DFP4_(Bits, Info)
538     void Peek_D1  (int8u   &Info);
539     void Peek_D2  (int16u  &Info);
540     void Peek_D3  (int32u  &Info);
541     void Peek_D4  (int32u  &Info);
542     void Peek_D5  (int64u  &Info);
543     void Peek_D6  (int64u  &Info);
544     void Peek_D7  (int64u  &Info);
545     void Peek_D8  (int64u  &Info);
546     void Peek_D16 (int128u &Info);
547     void Peek_DF4 (float32 &Info);
548     void Peek_DF8 (float64 &Info);
549     void Peek_DF10(float64 &Info);
550     void Peek_DFP4(int8u  Bits, float64 &Info);
551     #define Skip_D1(Name) Element_Offset++
552     #define Skip_D2(Name) Element_Offset+=2
553     #define Skip_D3(Name) Element_Offset+=3
554     #define Skip_D4(Name) Element_Offset+=4
555     #define Skip_D5(Name) Element_Offset+=5
556     #define Skip_D6(Name) Element_Offset+=6
557     #define Skip_D7(Name) Element_Offset+=7
558     #define Skip_D8(Name) Element_Offset+=8
559     #define Skip_DF4(Name) Element_Offset+=4
560     #define Skip_DF8(Name) Element_Offset+=8
561     #define Skip_D16(Name) Element_Offset+=16
562     #define Skip_DFP4(Size, Name) Element_Offset+=4
563     #define Info_D1(_INFO, _NAME)   Element_Offset++
564     #define Info_D2(_INFO, _NAME)   Element_Offset+=2
565     #define Info_D3(_INFO, _NAME)   Element_Offset+=3
566     #define Info_D4(_INFO, _NAME)   Element_Offset+=4
567     #define Info_D5(_INFO, _NAME)   Element_Offset+=5
568     #define Info_D6(_INFO, _NAME)   Element_Offset+=6
569     #define Info_D7(_INFO, _NAME)   Element_Offset+=7
570     #define Info_D8(_INFO, _NAME)   Element_Offset+=8
571     #define Info_D16(_INFO, _NAME)  Element_Offset+=16
572     #define Info_DF4(_INFO, _NAME)  Element_Offset+=4
573     #define Info_DF8(_INFO, _NAME)  Element_Offset+=8
574     #define Info_DF10(_INFO, _NAME) Element_Offset+=10
575     #define Info_DFP4(_DITS, _INFO, _NAME) Element_Offset+=4
576 
577     //***************************************************************************
578     // GUID
579     //***************************************************************************
580 
581     void Get_GUID (int128u &Info);
Get_GUID(int128u & Info,const char *)582     inline void Get_GUID (int128u &Info, const char*) {Get_GUID(Info);}
583     void Peek_GUID(int128u &Info);
Skip_GUID(const char *)584     inline void Skip_GUID(               const char*) {if (Element_Offset+16>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=16;}
585     #define Info_GUID(_INFO, _NAME) int128u _INFO; Get_GUID(_INFO, _NAME)
586 
587     //***************************************************************************
588     // UUID
589     //***************************************************************************
590 
Get_UUID(int128u & Info)591     inline void Get_UUID (int128u &Info) {Get_B16_(Info);}
Get_UUID(int128u & Info,const char *)592     inline void Get_UUID (int128u &Info, const char*) {Get_B16_(Info);}
Peek_UUID(int128u & Info)593     inline void Peek_UUID(int128u &Info) {Peek_B16(Info);}
Skip_UUID(const char *)594     inline void Skip_UUID(               const char*) {if (Element_Offset+16>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=16;}
595     #define Info_UUID(_INFO, _NAME) int128u _INFO; Get_UUID(_INFO, _NAME)
596 
597     //***************************************************************************
598     // EBML
599     //***************************************************************************
600 
601     void Get_EB (int64u &Info);
602     void Get_ES (int64s &Info);
Get_EB(int64u & Info,const char *)603     inline void Get_EB (int64u &Info, const char*) {Get_EB(Info);}
Get_ES(int64s & Info,const char *)604     inline void Get_ES (int64s &Info, const char*) {Get_ES(Info);}
605     void Skip_EB();
606     void Skip_ES();
Skip_EB(const char *)607     inline void Skip_EB(              const char*) {Skip_EB();}
Skip_ES(const char *)608     inline void Skip_ES(              const char*) {Skip_ES();}
609     #define Info_EB(_INFO, _NAME) int64u _INFO; Get_EB(_INFO, _NAME)
610     #define Info_ES(_INFO, _NAME) int64s _INFO; Get_ES(_INFO, _NAME)
611 
612     //***************************************************************************
613     // Variable Size Value
614     //***************************************************************************
615 
616     void Get_VS (int64u &Info);
Get_VS(int64u & Info,const char *)617     inline void Get_VS (int64u &Info, const char*) {Get_VS(Info);}
618     void Skip_VS();
Skip_VS(const char *)619     inline void Skip_VS(              const char*) {Skip_VS();}
620     #define Info_VS(_INFO, _NAME) int64u _INFO; Get_VS(_INFO, _NAME)
621 
622     //***************************************************************************
623     // Exp-Golomb
624     //***************************************************************************
625 
626     void Get_UE (int32u &Info);
627     void Get_SE (int32s &Info);
Get_UE(int32u & Info,const char *)628     inline void Get_UE (int32u &Info, const char*) {Get_UE(Info);}
Get_SE(int32s & Info,const char *)629     inline void Get_SE (int32s &Info, const char*) {Get_SE(Info);}
630     void Skip_UE();
Skip_SE()631     inline void Skip_SE() {Skip_UE();}
Skip_UE(const char *)632     inline void Skip_UE(              const char*) {Skip_UE();}
Skip_SE(const char *)633     inline void Skip_SE(              const char*) {Skip_SE();}
634     #define Info_UE(_INFO, _NAME) int32u _INFO; Get_UE(_INFO, _NAME)
635     #define Info_SE(_INFO, _NAME) int32s _INFO; Get_SE(_INFO, _NAME)
636 
637     //***************************************************************************
638     // Interleaved Exp-Golomb
639     //***************************************************************************
640 
641     void Get_UI (int32u &Info);
642     void Get_SI (int32s &Info);
Get_UI(int32u & Info,const char *)643     inline void Get_UI (int32u &Info, const char*) {Get_UI(Info);}
Get_SI(int32s & Info,const char *)644     inline void Get_SI (int32s &Info, const char*) {Get_SI(Info);}
645     void Skip_UI();
646     void Skip_SI();
Skip_UI(const char *)647     inline void Skip_UI(              const char*) {Skip_UI();}
Skip_SI(const char *)648     inline void Skip_SI(              const char*) {Skip_SI();}
649     #define Info_UI(_INFO, _NAME) int32u _INFO; Get_UI(_INFO, _NAME)
650     #define Info_SI(_INFO, _NAME) int32s _INFO; Get_SI(_INFO, _NAME)
651 
652     //***************************************************************************
653     // Variable Length Code
654     //***************************************************************************
655 
656     struct vlc
657     {
658         int32u  value;
659         int8u   bit_increment;
660         int8s   mapped_to1;
661         int8s   mapped_to2;
662         int8s   mapped_to3;
663     };
664     struct vlc_fast
665     {
666         int8u*      Array;
667         int8u*      BitsToSkip;
668         const vlc*  Vlc;
669         int8u       Size;
670     };
671     #define VLC_END \
672         {(int32u)-1, (int8u)-1, 0, 0, 0}
673     static void Get_VL_Prepare(vlc_fast &Vlc);
674     void Get_VL_ (const vlc Vlc[], size_t &Info);
675     void Get_VL_ (const vlc_fast &Vlc, size_t &Info);
676     #define Get_VL(Vlc, Info, Name) Get_VL_(Vlc, Info);
677     void Skip_VL_(const vlc Vlc[]);
678     void Skip_VL_(const vlc_fast &Vlc);
679     #define Skip_VL(Vlc, Name) Skip_VL_(Vlc);
680     #define Info_VL(Vlc, Info, Name) Skip_VL_(Vlc)
681 
682     //***************************************************************************
683     // Characters
684     //***************************************************************************
685 
686     void Get_C1 (int8u  &Info);
687     void Get_C2 (int16u &Info);
688     void Get_C3 (int32u &Info);
689     void Get_C4 (int32u &Info);
690     void Get_C5 (int64u &Info);
691     void Get_C6 (int64u &Info);
692     void Get_C7 (int64u &Info);
693     void Get_C8 (int64u &Info);
Get_C1(int8u & Info,const char *)694     inline void Get_C1 (int8u  &Info, const char*) {Get_C1(Info);}
Get_C2(int16u & Info,const char *)695     inline void Get_C2 (int16u &Info, const char*) {Get_C2(Info);}
Get_C3(int32u & Info,const char *)696     inline void Get_C3 (int32u &Info, const char*) {Get_C3(Info);}
Get_C4(int32u & Info,const char *)697     inline void Get_C4 (int32u &Info, const char*) {Get_C4(Info);}
Get_C5(int64u & Info,const char *)698     inline void Get_C5 (int64u &Info, const char*) {Get_C5(Info);}
Get_C6(int64u & Info,const char *)699     inline void Get_C6 (int64u &Info, const char*) {Get_C6(Info);}
Get_C7(int64u & Info,const char *)700     inline void Get_C7 (int64u &Info, const char*) {Get_C7(Info);}
Get_C8(int64u & Info,const char *)701     inline void Get_C8 (int64u &Info, const char*) {Get_C8(Info);}
Skip_C1(const char *)702     inline void Skip_C1(              const char*) {if (Element_Offset+1>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=1;}
Skip_C2(const char *)703     inline void Skip_C2(              const char*) {if (Element_Offset+2>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=2;}
Skip_C3(const char *)704     inline void Skip_C3(              const char*) {if (Element_Offset+3>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=3;}
Skip_C4(const char *)705     inline void Skip_C4(              const char*) {if (Element_Offset+4>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=4;}
Skip_C5(const char *)706     inline void Skip_C5(              const char*) {if (Element_Offset+5>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=5;}
Skip_C6(const char *)707     inline void Skip_C6(              const char*) {if (Element_Offset+6>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=6;}
Skip_C7(const char *)708     inline void Skip_C7(              const char*) {if (Element_Offset+7>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=7;}
Skip_C8(const char *)709     inline void Skip_C8(              const char*) {if (Element_Offset+8>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=8;}
710     #define Info_C1(_INFO, _NAME) int8u  _INFO; Get_C1(_INFO, _NAME)
711     #define Info_C2(_INFO, _NAME) int16u _INFO; Get_C2(_INFO, _NAME)
712     #define Info_C3(_INFO, _NAME) int32u _INFO; Get_C3(_INFO, _NAME)
713     #define Info_C4(_INFO, _NAME) int32u _INFO; Get_C4(_INFO, _NAME)
714     #define Info_C5(_INFO, _NAME) int64u _INFO; Get_C5(_INFO, _NAME)
715     #define Info_C6(_INFO, _NAME) int64u _INFO; Get_C6(_INFO, _NAME)
716     #define Info_C7(_INFO, _NAME) int64u _INFO; Get_C7(_INFO, _NAME)
717     #define Info_C8(_INFO, _NAME) int64u _INFO; Get_C8(_INFO, _NAME)
718 
719     //***************************************************************************
720     // Text
721     //***************************************************************************
722 
723     void Get_Local  (int64u Bytes, Ztring      &Info);
724     void Get_ISO_6937_2 (int64u Bytes, Ztring  &Info);
725     void Get_ISO_8859_1 (int64u Bytes, Ztring  &Info);
726     void Get_ISO_8859_2 (int64u Bytes, Ztring  &Info);
727     void Get_ISO_8859_5 (int64u Bytes, Ztring  &Info);
728     void Get_MacRoman   (int64u Bytes, Ztring  &Info);
729     void Get_String (int64u Bytes, std::string &Info);
730     void Get_UTF8   (int64u Bytes, Ztring      &Info);
731     void Get_UTF16  (int64u Bytes, Ztring      &Info);
732     void Get_UTF16B (int64u Bytes, Ztring      &Info);
733     void Get_UTF16L (int64u Bytes, Ztring      &Info);
Get_Local(int64u Bytes,Ztring & Info,const char *)734     inline void Get_Local  (int64u Bytes, Ztring      &Info, const char*) {Get_Local(Bytes, Info);}
Get_ISO_6937_2(int64u Bytes,Ztring & Info,const char *)735     inline void Get_ISO_6937_2 (int64u Bytes, Ztring  &Info, const char*) {Get_ISO_6937_2(Bytes, Info);}
Get_ISO_8859_1(int64u Bytes,Ztring & Info,const char *)736     inline void Get_ISO_8859_1 (int64u Bytes, Ztring  &Info, const char*) {Get_ISO_8859_1(Bytes, Info);}
Get_ISO_8859_2(int64u Bytes,Ztring & Info,const char *)737     inline void Get_ISO_8859_2 (int64u Bytes, Ztring  &Info, const char*) {Get_ISO_8859_2(Bytes, Info);}
Get_ISO_8859_5(int64u Bytes,Ztring & Info,const char *)738     inline void Get_ISO_8859_5 (int64u Bytes, Ztring  &Info, const char*) {Get_ISO_8859_5(Bytes, Info);}
Get_MacRoman(int64u Bytes,Ztring & Info,const char *)739     inline void Get_MacRoman   (int64u Bytes, Ztring  &Info, const char*) {Get_MacRoman(Bytes, Info);}
Get_String(int64u Bytes,std::string & Info,const char *)740     inline void Get_String (int64u Bytes, std::string &Info, const char*) {Get_String(Bytes, Info);}
Get_UTF8(int64u Bytes,Ztring & Info,const char *)741     inline void Get_UTF8   (int64u Bytes, Ztring      &Info, const char*) {Get_UTF8(Bytes, Info);}
Get_UTF16(int64u Bytes,Ztring & Info,const char *)742     inline void Get_UTF16  (int64u Bytes, Ztring      &Info, const char*) {Get_UTF16(Bytes, Info);}
Get_UTF16B(int64u Bytes,Ztring & Info,const char *)743     inline void Get_UTF16B (int64u Bytes, Ztring      &Info, const char*) {Get_UTF16B(Bytes, Info);}
Get_UTF16L(int64u Bytes,Ztring & Info,const char *)744     inline void Get_UTF16L (int64u Bytes, Ztring      &Info, const char*) {Get_UTF16L(Bytes, Info);}
745     void Peek_Local (int64u Bytes, Ztring      &Info);
746     void Peek_String(int64u Bytes, std::string &Info);
Skip_Local(int64u Bytes,const char *)747     void Skip_Local (int64u Bytes,                    const char*) {if (Element_Offset+Bytes>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=(size_t)Bytes;}
Skip_ISO_6937_2(int64u Bytes,const char *)748     void Skip_ISO_6937_2(int64u Bytes,                const char*) {if (Element_Offset+Bytes>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=(size_t)Bytes;}
Skip_String(int64u Bytes,const char *)749     void Skip_String(int64u Bytes,                    const char*) {if (Element_Offset+Bytes>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=(size_t)Bytes;}
Skip_UTF8(int64u Bytes,const char *)750     void Skip_UTF8  (int64u Bytes,                    const char*) {if (Element_Offset+Bytes>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=(size_t)Bytes;}
Skip_UTF16B(int64u Bytes,const char *)751     void Skip_UTF16B(int64u Bytes,                    const char*) {if (Element_Offset+Bytes>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=(size_t)Bytes;}
Skip_UTF16L(int64u Bytes,const char *)752     void Skip_UTF16L(int64u Bytes,                    const char*) {if (Element_Offset+Bytes>Element_Size) {Trusted_IsNot(); return;} Element_Offset+=(size_t)Bytes;}
753     #define Info_Local(_BYTES, _INFO, _NAME)  Ztring _INFO; Get_Local (_BYTES, _INFO, _NAME)
754     #define Info_ISO_6937_2(_BYTES, _INFO, _NAME)  Ztring _INFO; Info_ISO_6937_2(_BYTES, _INFO, _NAME)
755     #define Info_UTF8(_BYTES, _INFO, _NAME)   Ztring _INFO; Get_UTF8  (_BYTES, _INFO, _NAME)
756     #define Info_UTF16B(_BYTES, _INFO, _NAME) Ztring _INFO; Get_UTF16B(_BYTES, _INFO, _NAME)
757     #define Info_UTF16L(_BYTES, _INFO, _NAME) Ztring _INFO; Get_UTF16L(_BYTES, _INFO, _NAME)
758 
759     //***************************************************************************
760     // Pascal strings
761     //***************************************************************************
762 
763     void Get_PA (std::string &Info);
Get_PA(std::string & Info,const char *)764     inline void Get_PA (std::string &Info, const char*) {Get_PA(Info);}
765     void Peek_PA(std::string &Info);
766     void Skip_PA();
Skip_PA(const char *)767     inline void Skip_PA(                   const char*) {Skip_PA();}
768     #define Info_PA(_INFO, _NAME) Ztring _INFO; Get_PA (_INFO, _NAME)
769 
770     //***************************************************************************
771     // Others, specialized
772     //***************************************************************************
773 
774     #if defined(MEDIAINFO_HEVC_YES) || defined(MEDIAINFO_MPEG4_YES)
775     void Get_MasteringDisplayColorVolume(Ztring &MasteringDisplay_ColorPrimaries, Ztring &MasteringDisplay_Luminance);
776     #endif
777     #if defined(MEDIAINFO_HEVC_YES) || defined(MEDIAINFO_MPEG4_YES) || defined(MEDIAINFO_MATROSKA_YES) || defined(MEDIAINFO_MXF_YES)
778     struct mastering_metadata_2086
779     {
780         int16u Primaries[8];
781         int32u Luminance[2];
782     };
783     void Get_MasteringDisplayColorVolume(Ztring &MasteringDisplay_ColorPrimaries, Ztring &MasteringDisplay_Luminance, mastering_metadata_2086 &Meta);
784     #endif
785     #if defined(MEDIAINFO_MPEGPS_YES) || defined(MEDIAINFO_MPEGTS_YES) || defined(MEDIAINFO_MPEG4_YES) || defined(MEDIAINFO_MK_YES)
786     void dvcC(bool has_dependency_pid=false, std::map<std::string, Ztring>* Infos=NULL);
787     #endif
788 
789     //***************************************************************************
790     // Unknown
791     //***************************************************************************
792 
793     void Skip_XX(int64u Bytes);
Skip_XX(int64u Bytes,const char *)794     inline void Skip_XX(int64u Bytes, const char*) {Skip_XX(Bytes);}
795 
796     //***************************************************************************
797     // Flags
798     //***************************************************************************
799 
800     void Get_Flags_ (int64u Flags, size_t Order, bool  &Info);
801     void Get_FlagsM_ (int64u ValueToPut, int8u &Info); //Multiple
802     #define Get_Flags(_FLAGS, _ORDER, _INFO, _NAME) Get_Flags_(_FLAGS, _ORDER, _INFO)
803     #define Get_FlagsM(_VALUE, _INFO, _NAME) Get_FlagsM_(_VALUE, _INFO)
804     #define Skip_Flags(_FLAGS, _ORDER, _NAME)
805     #define Skip_FlagsM(_VALUE, _NAME)
806     #define Info_Flags(_FLAGS, _ORDER, _INFO, _NAME)
807 
808     //***************************************************************************
809     // BitStream
810     //***************************************************************************
811 
812     void Get_BS_ (int8u  Bits, int32u  &Info);
813     void Get_SB_ (             bool    &Info);
Get_SB_()814     bool Get_SB_ ()                                              {return BS->GetB();}
815     void Get_S1_ (int8u  Bits, int8u   &Info);
816     void Get_S2_ (int8u  Bits, int16u  &Info);
817     void Get_S3_ (int8u  Bits, int32u  &Info);
818     void Get_S4_ (int8u  Bits, int32u  &Info);
819     void Get_S5_ (int8u  Bits, int64u  &Info);
820     void Get_S6_ (int8u  Bits, int64u  &Info);
821     void Get_S7_ (int8u  Bits, int64u  &Info);
822     void Get_S8_ (int8u  Bits, int64u  &Info);
823     #define Get_BS(Bits, Info, Name) Get_BS_(Bits, Info)
824     #define Get_SB(      Info, Name) Get_SB_(      Info)
825     #define Get_S1(Bits, Info, Name) Get_S1_(Bits, Info)
826     #define Get_S2(Bits, Info, Name) Get_S2_(Bits, Info)
827     #define Get_S3(Bits, Info, Name) Get_S3_(Bits, Info)
828     #define Get_S4(Bits, Info, Name) Get_S4_(Bits, Info)
829     #define Get_S5(Bits, Info, Name) Get_S5_(Bits, Info)
830     #define Get_S6(Bits, Info, Name) Get_S6_(Bits, Info)
831     #define Get_S7(Bits, Info, Name) Get_S7_(Bits, Info)
832     #define Get_S8(Bits, Info, Name) Get_S8_(Bits, Info)
833     void Peek_BS(int8u  Bits, int32u  &Info);
834     void Peek_SB(              bool    &Info);
Peek_SB()835     bool Peek_SB()                                              {return BS->PeekB();}
836     void Peek_S1(int8u  Bits, int8u   &Info);
837     void Peek_S2(int8u  Bits, int16u  &Info);
838     void Peek_S3(int8u  Bits, int32u  &Info);
839     void Peek_S4(int8u  Bits, int32u  &Info);
840     void Peek_S5(int8u  Bits, int64u  &Info);
841     void Peek_S6(int8u  Bits, int64u  &Info);
842     void Peek_S7(int8u  Bits, int64u  &Info);
843     void Peek_S8(int8u  Bits, int64u  &Info);
Skip_BS_(size_t Bits)844     inline void Skip_BS_(size_t Bits) {BS->Skip(Bits);}
Skip_SB_()845     inline void Skip_SB_(           ) {BS->Skip(1);}
Skip_S1_(int8u Bits)846     inline void Skip_S1_(int8u  Bits) {BS->Skip(Bits);}
Skip_S2_(int8u Bits)847     inline void Skip_S2_(int8u  Bits) {BS->Skip(Bits);}
Skip_S3_(int8u Bits)848     inline void Skip_S3_(int8u  Bits) {BS->Skip(Bits);}
Skip_S4_(int8u Bits)849     inline void Skip_S4_(int8u  Bits) {BS->Skip(Bits);}
Skip_S5_(int8u Bits)850     inline void Skip_S5_(int8u  Bits) {BS->Skip(Bits);}
Skip_S6_(int8u Bits)851     inline void Skip_S6_(int8u  Bits) {BS->Skip(Bits);}
Skip_S7_(int8u Bits)852     inline void Skip_S7_(int8u  Bits) {BS->Skip(Bits);}
Skip_S8_(int8u Bits)853     inline void Skip_S8_(int8u  Bits) {BS->Skip(Bits);}
854     #define Skip_BS(Bits, Name) Skip_BS_(Bits)
855     #define Skip_SB(      Name) Skip_SB_()
856     #define Skip_S1(Bits, Name) Skip_S1_(Bits)
857     #define Skip_S2(Bits, Name) Skip_S2_(Bits)
858     #define Skip_S3(Bits, Name) Skip_S3_(Bits)
859     #define Skip_S4(Bits, Name) Skip_S4_(Bits)
860     #define Skip_S5(Bits, Name) Skip_S5_(Bits)
861     #define Skip_S6(Bits, Name) Skip_S6_(Bits)
862     #define Skip_S7(Bits, Name) Skip_S7_(Bits)
863     #define Skip_S8(Bits, Name) Skip_S8_(Bits)
864     void Mark_0 ();
865     #define Mark_0_NoTrustError() Skip_SB_() //Use it for providing a warning instead of a non-trusting error
866     void Mark_1 ();
867     #define Mark_1_NoTrustError() Skip_SB_() //Use it for providing a warning instead of a non-trusting error
868     #define Info_BS(_BITS, _INFO, _NAME) Skip_BS_(_BITS)
869     #define Info_SB(_INFO, _NAME)        Skip_SB_(     )
870     #define Info_S1(_BITS, _INFO, _NAME) Skip_S1_(_BITS)
871     #define Info_S2(_BITS, _INFO, _NAME) Skip_S2_(_BITS)
872     #define Info_S3(_BITS, _INFO, _NAME) Skip_S3_(_BITS)
873     #define Info_S4(_BITS, _INFO, _NAME) Skip_S4_(_BITS)
874     #define Info_S5(_BITS, _INFO, _NAME) Skip_S5_(_BITS)
875     #define Info_S6(_BITS, _INFO, _NAME) Skip_S6_(_BITS)
876     #define Info_S7(_BITS, _INFO, _NAME) Skip_S7_(_BITS)
877     #define Info_S8(_BITS, _INFO, _NAME) Skip_S8_(_BITS)
878 
879     #define TEST_SB_GET(_CODE, _NAME) \
880         { \
881             Peek_SB(_CODE); \
882             if (!_CODE) \
883                 Skip_SB_(); \
884             else \
885             { \
886                 Element_Begin0(); \
887                 Skip_SB_(); \
888 
889     #define TEST_SB_SKIP(_NAME) \
890         { \
891             if (!Peek_SB()) \
892                 Skip_SB_(); \
893             else \
894             { \
895                 Element_Begin0(); \
896                 Skip_SB_(); \
897 
898     #define TESTELSE_SB_GET(_CODE, _NAME) \
899         { \
900             Peek_SB(_CODE); \
901             if (_CODE) \
902             { \
903                 Element_Begin0(); \
904                 Skip_SB_(); \
905 
906     #define TESTELSE_SB_SKIP(_NAME) \
907         { \
908             if (Peek_SB()) \
909             { \
910                 Element_Begin0(); \
911                 Skip_SB_(); \
912 
913     #define TESTELSE_SB_ELSE(_NAME) \
914                 Element_End0(); \
915             } \
916             else \
917             { \
918                 Skip_SB_(); \
919 
920     #define TESTELSE_SB_END() \
921             } \
922         } \
923 
924     #define TEST_SB_END() \
925                 Element_End0(); \
926             } \
927         } \
928 
929     //***************************************************************************
930     // BitStream (Little Endian)
931     //***************************************************************************
932 
933     void Get_BT_ (int8u  Bits, int32u  &Info);
934     void Get_TB_ (             bool    &Info);
Get_TB_()935     bool Get_TB_ ()                                              {bool Temp; Get_TB_(Temp); return Temp;}
936     void Get_T1_ (int8u  Bits, int8u   &Info);
937     void Get_T2_ (int8u  Bits, int16u  &Info);
938     void Get_T4_ (int8u  Bits, int32u  &Info);
939     void Get_T8_ (int8u  Bits, int64u  &Info);
940     #define Get_BT(Bits, Info, Name) Get_BT_(Bits, Info)
941     #define Get_TB(      Info, Name) Get_TB_(      Info)
942     #define Get_T1(Bits, Info, Name) Get_T1_(Bits, Info)
943     #define Get_T2(Bits, Info, Name) Get_T2_(Bits, Info)
944     #define Get_T4(Bits, Info, Name) Get_T4_(Bits, Info)
945     #define Get_T8(Bits, Info, Name) Get_T8_(Bits, Info)
946     void Peek_BT(int8u  Bits, int32u  &Info);
947     void Peek_TB(              bool    &Info);
Peek_TB()948     bool Peek_TB()                                              {bool Temp; Peek_TB(Temp); return Temp;}
949     void Peek_T1(int8u  Bits, int8u   &Info);
950     void Peek_T2(int8u  Bits, int16u  &Info);
951     void Peek_T4(int8u  Bits, int32u  &Info);
952     void Peek_T8(int8u  Bits, int64u  &Info);
Skip_BT_(size_t Bits)953     inline void Skip_BT_(size_t Bits) {BT->Skip(Bits);}
Skip_TB_()954     inline void Skip_TB_(           ) {BT->SkipB();}
Skip_T1_(int8u Bits)955     inline void Skip_T1_(int8u  Bits) {BT->Skip1(Bits);}
Skip_T2_(int8u Bits)956     inline void Skip_T2_(int8u  Bits) {BT->Skip2(Bits);}
Skip_T4_(int8u Bits)957     inline void Skip_T4_(int8u  Bits) {BT->Skip4(Bits);}
Skip_T8_(int8u Bits)958     inline void Skip_T8_(int8u  Bits) {BT->Skip8(Bits);}
959     #define Skip_BT(Bits, Name) Skip_BT_(Bits)
960     #define Skip_TB(      Name) Skip_TB_()
961     #define Skip_T1(Bits, Name) Skip_T1_(Bits)
962     #define Skip_T2(Bits, Name) Skip_T2_(Bits)
963     #define Skip_T4(Bits, Name) Skip_T4_(Bits)
964     #define Skip_T8(Bits, Name) Skip_T8_(Bits)
965     #define Info_BT(_BITS, _INFO, _NAME) Skip_BT_(_BITS)
966     #define Info_TB(_INFO, _NAME)        Skip_TB_(     )
967     #define Info_T1(_BITS, _INFO, _NAME) Skip_T1_(_BITS)
968     #define Info_T2(_BITS, _INFO, _NAME) Skip_T2_(_BITS)
969     #define Info_T4(_BITS, _INFO, _NAME) Skip_T4_(_BITS)
970     #define Info_T8(_BITS, _INFO, _NAME) Skip_T8_(_BITS)
971 
972     #define TEST_TB_GET(_CODE, _NAME) \
973         { \
974             Peek_TB(_CODE); \
975             if (!_CODE) \
976                 Skip_TB_(); \
977             else \
978             { \
979                 Element_Begin0(); \
980                 Skip_TB_(); \
981 
982     #define TEST_TB_TKIP(_NAME) \
983         { \
984             if (!Peek_TB()) \
985                 Skip_TB_(); \
986             else \
987             { \
988                 Element_Begin0(); \
989                 Skip_TB_(); \
990 
991     #define TESTELSE_TB_GET(_CODE, _NAME) \
992         { \
993             Peek_TB(_CODE); \
994             if (_CODE) \
995             { \
996                 Element_Begin0(); \
997                 Skip_TB_(); \
998 
999     #define TESTELSE_TB_TKIP(_NAME) \
1000         { \
1001             if (Peek_TB()) \
1002             { \
1003                 Element_Begin0(); \
1004                 Skip_TB_(); \
1005 
1006     #define TESTELSE_TB_ELSE(_NAME) \
1007                 Element_End0(); \
1008             } \
1009             else \
1010             { \
1011                 Skip_TB_(); \
1012 
1013     #define TESTELSE_TB_END() \
1014             } \
1015         } \
1016 
1017     #define TEST_TB_END() \
1018                 Element_End0(); \
1019             } \
1020         } \
1021 
1022     //***************************************************************************
1023     // Next code planning
1024     //***************************************************************************
1025 
1026     void NextCode_Add(int64u Code);
1027     void NextCode_Clear();
1028     bool NextCode_Test();
1029 
1030     //***************************************************************************
1031     // Element trusting
1032     //***************************************************************************
1033 
Trusted_IsNot(const char *)1034     void Trusted_IsNot (const char*)                                            {Trusted_IsNot();}
1035     void Trusted_IsNot ();
Trusted_Get()1036     bool Trusted_Get   () {return !Element[Element_Level].UnTrusted;}
1037 
1038     //***************************************************************************
1039     // Stream filling
1040     //***************************************************************************
1041 
1042     //Elements - Preparation of element from external app
1043     size_t Stream_Prepare   (stream_t KindOfStream, size_t StreamPos=(size_t)-1);
1044     size_t Stream_Erase     (stream_t KindOfStream, size_t StreamPos);
1045 
1046     //Fill with datas (with parameter as a size_t)
1047     void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, const Ztring  &Value, bool Replace=false);
1048     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);}
1049     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);}
1050     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);}
1051     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);}
1052     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);}
1053     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);}
1054     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);}
1055     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);}
1056     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);}
1057     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);}
1058     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);}
1059            void Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, float64        Value, int8u AfterComma=3, bool Replace=false);
1060     #ifdef SIZE_T_IS_LONG
1061     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);}
1062     #endif //SIZE_T_IS_LONG
1063     //Fill with datas
1064     void Fill_Dup (stream_t StreamKind, size_t StreamPos, const char* Parameter, const Ztring  &Value, bool Replace=false);
1065     void Fill_Measure (stream_t StreamKind, size_t StreamPos, const char* Parameter, const Ztring  &Value, const Ztring& Measure, bool Replace=false);
1066     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);}
1067     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);}
1068     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);}
1069     void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, const Ztring  &Value, bool Replace=false);
1070     void Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, ZtringList &Value, ZtringList& Id, bool Replace=false);
1071     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);}
1072     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);}
1073     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);}
1074     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);}
1075     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);}
1076     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);}
1077     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);}
1078     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);}
1079     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);}
1080     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);}
1081     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);}
1082     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);}
1083     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);}
1084     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);}
1085     #ifdef SIZE_T_IS_LONG
1086     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);}
1087     #endif //SIZE_T_IS_LONG
1088     struct fill_temp_item
1089     {
1090         Ztring Parameter;
1091         Ztring Value;
1092     };
1093     void Fill_SetOptions(stream_t StreamKind, size_t StreamPos, const char* Parameter, const char* Options);
1094     vector<fill_temp_item> Fill_Temp[Stream_Max+1]; // +1 because Fill_Temp[Stream_Max] is used when StreamKind is unknown
1095     map<string, string> Fill_Temp_Options[Stream_Max+1]; // +1 because Fill_Temp[Stream_Max] is used when StreamKind is unknown
1096     void Fill_Flush ();
1097     static size_t Fill_Parameter(stream_t StreamKind, generic StreamPos);
1098 
1099     const Ztring &Retrieve_Const (stream_t StreamKind, size_t StreamPos, size_t Parameter, info_t KindOfInfo=Info_Text);
1100     Ztring Retrieve (stream_t StreamKind, size_t StreamPos, size_t Parameter, info_t KindOfInfo=Info_Text);
1101     const Ztring &Retrieve_Const (stream_t StreamKind, size_t StreamPos, const char* Parameter, info_t KindOfInfo=Info_Text);
1102     Ztring Retrieve (stream_t StreamKind, size_t StreamPos, const char* Parameter, info_t KindOfInfo=Info_Text);
1103 
1104     void Clear (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1105     void Clear (stream_t StreamKind, size_t StreamPos, const char* Parameter);
1106     void Clear (stream_t StreamKind, size_t StreamPos);
1107     void Clear (stream_t StreamKind);
Clear()1108     inline void Clear () {File__Base::Clear();}
1109 
1110     //***************************************************************************
1111     // Filling
1112     //***************************************************************************
1113 
1114     //Actions
Accept(const char *)1115     void Accept        (const char*)                                            {Accept();}
1116     void Accept        ();
1117     void Accept        (File__Analyze* Parser);
Reject(const char *)1118     void Reject        (const char*)                                            {Reject();}
1119     void Reject        ();
1120     void Reject        (File__Analyze* Parser);
Fill(const char *)1121     void Fill          (const char*)                                            {Fill();}
1122     void Fill          ();
1123     void Fill          (File__Analyze* Parser);
Update(const char *)1124     void Update        (const char*)                                            {Fill();}
1125     void Update        ();
1126     void Update        (File__Analyze* Parser);
Finish(const char *)1127     void Finish        (const char*)                                            {Finish();}
1128     void Finish        ();
1129     void Finish        (File__Analyze* Parser);
ForceFinish(const char *)1130     void ForceFinish   (const char*)                                            {ForceFinish();}
1131     void ForceFinish   ();
1132     void ForceFinish   (File__Analyze* Parser);
GoTo(int64u GoTo_,const char *)1133     void GoTo          (int64u GoTo_, const char*)                              {GoTo(GoTo_);}
1134     void GoTo          (int64u GoTo);
GoToFromEnd(int64u GoToFromEnd_,const char *)1135     void GoToFromEnd   (int64u GoToFromEnd_, const char*)                       {GoToFromEnd(GoToFromEnd_);}
1136     void GoToFromEnd   (int64u GoToFromEnd);
1137     int64u Element_Code_Get (size_t Level);
1138     int64u Element_TotalSize_Get (size_t LevelLess=0);
1139     bool Element_IsComplete_Get ();
1140     void Element_ThisIsAList ();
1141     void Element_WaitForMoreData ();
Element_DoNotTrust(const char *)1142     void Element_DoNotTrust (const char*)                                       {Element_DoNotTrust();}
1143     void Element_DoNotTrust ();
Element_DoNotShow()1144     inline void Element_DoNotShow () {}
Element_Show()1145     inline void Element_Show () {}
Element_Show_Get()1146     inline bool Element_Show_Get () {return false;}
Element_Show_Add(const Ztring &)1147     inline void Element_Show_Add (const Ztring &) {}
1148 
1149     //Status
1150     bool Element_IsOK ();
1151     bool Element_IsNotFinished ();
1152     bool Element_IsWaitingForMoreData ();
1153 
1154     //***************************************************************************
1155     // Merging
1156     //***************************************************************************
1157 
1158     //Utils
1159 public :
1160     size_t Merge(MediaInfo_Internal &ToAdd, bool Erase=true); //Merge 2 File_Base
1161     size_t Merge(MediaInfo_Internal &ToAdd, stream_t StreamKind, size_t StreamPos_From, size_t StreamPos_To, bool Erase=true); //Merge 2 streams
1162     size_t Merge(File__Analyze &ToAdd, bool Erase=true); //Merge 2 File_Base
1163     size_t Merge(File__Analyze &ToAdd, stream_t StreamKind, size_t StreamPos_From, size_t StreamPos_To, bool Erase=true); //Merge 2 streams
1164 
1165     void CodecID_Fill           (const Ztring &Value, stream_t StreamKind, size_t StreamPos, infocodecid_format_t Format, stream_t StreamKind_CodecID=Stream_Max);
1166     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);
1167     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);
1168     #if MEDIAINFO_EVENTS
Streamkind_Get(int8u * ParserIDs,size_t StreamIDs_Size)1169     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()1170     stream_t Streamkind_Get() {return Streamkind_Get(ParserIDs, StreamIDs_Size);}
1171     #endif //MEDIAINFO_EVENTS
1172 
1173     //***************************************************************************
1174     // Finalize
1175     //***************************************************************************
1176 
1177     //End
1178     void Streams_Finish_Global();
1179 
1180 protected :
1181     void Streams_Finish_StreamOnly();
1182     void Streams_Finish_StreamOnly(stream_t StreamKid, size_t StreamPos);
1183     void Streams_Finish_StreamOnly_General(size_t StreamPos);
1184     void Streams_Finish_StreamOnly_Video(size_t StreamPos);
1185     void Streams_Finish_StreamOnly_Audio(size_t StreamPos);
1186     void Streams_Finish_StreamOnly_Text(size_t StreamPos);
1187     void Streams_Finish_StreamOnly_Other(size_t StreamPos);
1188     void Streams_Finish_StreamOnly_Image(size_t StreamPos);
1189     void Streams_Finish_StreamOnly_Menu(size_t StreamPos);
1190     void Streams_Finish_InterStreams();
1191     void Streams_Finish_Cosmetic();
1192     void Streams_Finish_Cosmetic(stream_t StreamKid, size_t StreamPos);
1193     void Streams_Finish_Cosmetic_General(size_t StreamPos);
1194     void Streams_Finish_Cosmetic_Video(size_t StreamPos);
1195     void Streams_Finish_Cosmetic_Audio(size_t StreamPos);
1196     void Streams_Finish_Cosmetic_Text(size_t StreamPos);
1197     void Streams_Finish_Cosmetic_Chapters(size_t StreamPos);
1198     void Streams_Finish_Cosmetic_Image(size_t StreamPos);
1199     void Streams_Finish_Cosmetic_Menu(size_t StreamPos);
1200     void Streams_Finish_HumanReadable();
1201     void Streams_Finish_HumanReadable_PerStream(stream_t StreamKind, size_t StreamPos, size_t Parameter);
1202 
1203     void Tags ();
1204     void Video_FrameRate_Rounding (size_t Pos, video Parameter);
1205     void Video_BitRate_Rounding (size_t Pos, video Parameter);
1206     void Audio_BitRate_Rounding (size_t Pos, audio Parameter);
1207 
1208     //Utils - Finalize
1209     void Duration_Duration123   (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1210     void FileSize_FileSize123   (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1211     void Kilo_Kilo123           (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1212     void Value_Value123         (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1213     void YesNo_YesNo            (stream_t StreamKind, size_t StreamPos, size_t Parameter);
1214 
1215     //***************************************************************************
1216     //
1217     //***************************************************************************
1218 
1219 protected :
1220     //Save for speed improvement
1221     int8u           Config_Demux;
1222     Ztring          Config_LineSeparator;
1223     bool            IsSub;
1224     enum stream_source
1225     {
1226         IsContainer,
1227         IsStream,
1228         IsContainerExtra,
1229         StreamSource_Max,
1230     };
1231     stream_source   StreamSource;
1232 
1233     //Configuration
1234     bool DataMustAlwaysBeComplete;  //Data must always be complete, else wait for more data
1235     bool MustUseAlternativeParser;  //Must use the second parser (example: for Data part)
1236 
1237     //Synchro
1238     bool MustParseTheHeaderFile;    //There is an header part, must parse it
1239     size_t Trusted;
1240     size_t Trusted_Multiplier;
1241 
1242     //Elements
1243     size_t Element_Level;           //Current level
1244     bool   Element_WantNextLevel;   //Want to go to the next leavel instead of the same level
1245 
1246     //Element
1247     int64u Element_Code;            //Code filled in the file, copy of Element[Element_Level].Code
1248     int64u Element_Offset;          //Position in the Element (without header)
1249     int64u Element_Size;            //Size of the Element (without header)
1250 
1251 private :
1252     //***************************************************************************
1253     // Buffer
1254     //***************************************************************************
1255 
1256     void Buffer_Clear(); //Clear the buffer
1257 protected :
1258     //Buffer
1259     bool Open_Buffer_Continue_Loop();
1260     const int8u* Buffer;
1261 public : //TO CHANGE
1262     size_t Buffer_Size;
1263     int64u Buffer_TotalBytes;
1264     int64u Buffer_TotalBytes_FirstSynched;
1265     int64u Buffer_TotalBytes_LastSynched;
1266     int64u Buffer_PaddingBytes;
1267     int64u Buffer_JunkBytes;
1268     float64 Stream_BitRateFromContainer;
1269 protected :
1270     int8u* Buffer_Temp;
1271     size_t Buffer_Temp_Size;
1272     size_t Buffer_Temp_Size_Max;
1273     size_t Buffer_Offset; //Temporary usage in this parser
1274     size_t Buffer_Offset_Temp; //Temporary usage in this parser
1275     size_t Buffer_MinimumSize;
1276     size_t Buffer_MaximumSize;
1277     int64u Buffer_TotalBytes_FirstSynched_Max;
1278     int64u Buffer_TotalBytes_Fill_Max;
1279     friend class File__Tags_Helper;
1280     friend class File_Usac;
1281     friend class File_Mk;
1282     friend class File_Mpeg4;
1283     friend class File_Hevc;
1284 
1285     //***************************************************************************
1286     // Helpers
1287     //***************************************************************************
1288 
1289     bool FileHeader_Begin_0x000001();
1290     bool FileHeader_Begin_XML(tinyxml2::XMLDocument &Document);
1291     bool Synchronize_0x000001();
1292 public:
1293     #if defined(MEDIAINFO_FILE_YES)
1294     void TestContinuousFileNames(size_t CountOfFiles=24, Ztring FileExtension=Ztring(), bool SkipComputeDelay=false);
1295     void TestDirectory();
1296     #else //defined(MEDIAINFO_FILE_YES)
1297     void TestContinuousFileNames(size_t =24, Ztring =Ztring(), bool =false) {}
1298     void TestDirectory() {}
1299     #endif //defined(MEDIAINFO_FILE_YES)
1300     #if MEDIAINFO_FIXITY
1301     bool FixFile(int64u FileOffsetForWriting, const int8u* ToWrite, const size_t ToWrite_Size);
1302     #endif// MEDIAINFO_FIXITY
1303 
1304 private :
1305 
1306     //***************************************************************************
1307     // Elements
1308     //***************************************************************************
1309 
1310     //Element
1311 public: //TO CHANGE
1312     BitStream_Fast* BS;             //For conversion from bytes to bitstream
1313     BitStream*      BT;             //For conversion from bytes to bitstream (Little Endian)
1314     int64u Header_Size;             //Size of the header of the current element
1315 private :
1316 
1317     //Elements
1318     size_t Element_Level_Base;      //From other parsers
1319 
1320 public : //For very quick access, to not use except if you know what you do
1321     struct element_details
1322     {
1323         int64u  Code;               //Code filled in the file
1324         int64u  Next;               //
1325         bool    WaitForMoreData;    //This element is not complete, we need more data
1326         bool    UnTrusted;          //This element has a problem
1327         bool    IsComplete;         //This element is fully buffered, no need of more
1328     };
1329     std::vector<element_details> Element;
1330 
1331 private :
1332 
1333     //NextCode
1334     std::map<int64u, bool> NextCode;
1335 
1336     //BookMarks
1337     size_t              BookMark_Element_Level;
1338     int64u              BookMark_GoTo;
1339     std::vector<int64u> BookMark_Code;
1340     std::vector<int64u> BookMark_Next;
1341 
1342 public :
1343     void BookMark_Set(size_t Element_Level_ToGet=(size_t)-1);
1344     void BookMark_Get();
BookMark_Needed()1345     virtual bool BookMark_Needed()                                              {return false;};
1346 
1347     //Temp
1348     std::bitset<32> Status;
1349     enum status
1350     {
1351         IsAccepted,
1352         IsFilled,
1353         IsUpdated,
1354         IsFinished,
1355         Reserved_04,
1356         Reserved_05,
1357         Reserved_06,
1358         Reserved_07,
1359         Reserved_08,
1360         Reserved_09,
1361         Reserved_10,
1362         Reserved_11,
1363         Reserved_12,
1364         Reserved_13,
1365         Reserved_14,
1366         Reserved_15,
1367         User_16,
1368         User_17,
1369         User_18,
1370         User_19,
1371         User_20,
1372         User_21,
1373         User_22,
1374         User_23,
1375         User_24,
1376         User_25,
1377         User_26,
1378         User_27,
1379         User_28,
1380         User_29,
1381         User_30,
1382         User_31,
1383     };
1384     bool ShouldContinueParsing;
1385 
1386     //Configuration
1387     bool MustSynchronize;
1388     bool CA_system_ID_MustSkipSlices;
1389     bool FillAllMergedStreams;
1390     class streamidentity
1391     {
1392     public:
1393         stream_t StreamKind;
1394         size_t   StreamPos;
1395 
streamidentity(stream_t StreamKind_,size_t StreamPos_)1396         streamidentity(stream_t StreamKind_, size_t StreamPos_)
1397             : StreamKind(StreamKind_)
1398             , StreamPos(StreamPos_)
1399         {}
1400     };
1401     std::vector<streamidentity> MergedStreams_Last;
1402 
1403     //Demux
1404     enum contenttype
1405     {
1406         ContentType_MainStream,
1407         ContentType_SubStream,
1408         ContentType_Header,
1409         ContentType_Synchro
1410     };
1411     #if MEDIAINFO_DEMUX
1412         void Demux (const int8u* Buffer, size_t Buffer_Size, contenttype ContentType, const int8u* OriginalBuffer=NULL, size_t OriginalBuffer_Size=0);
Demux_UnpacketizeContainer_Test()1413         virtual bool Demux_UnpacketizeContainer_Test() {return true;}
1414         bool Demux_UnpacketizeContainer_Test_OneFramePerFile();
1415         void Demux_UnpacketizeContainer_Demux(bool random_access=true);
1416         void Demux_UnpacketizeContainer_Demux_Clear();
1417         bool Demux_EventWasSent_Accept_Specific;
1418     #else //MEDIAINFO_DEMUX
1419         #define Demux(_A, _B, _C)
1420     #endif //MEDIAINFO_DEMUX
1421     #if MEDIAINFO_DECODE
1422         void Decoded(const int8u* Buffer, size_t Buffer_Size);
1423     #endif //MEDIAINFO_DECODE
1424 
1425     //Events data
1426     bool    PES_FirstByte_IsAvailable;
1427     bool    PES_FirstByte_Value;
1428 
1429     int64u  Unsynch_Frame_Count;
1430 
1431     //AES
1432     #if MEDIAINFO_AES
1433         AESdecrypt* AES;
1434         int8u*      AES_IV;
1435         int8u*      AES_Decrypted;
1436         size_t      AES_Decrypted_Size;
1437     #endif //MEDIAINFO_AES
1438 
1439     //Hash
1440     #if MEDIAINFO_HASH
1441         HashWrapper*        Hash;
1442         int64u              Hash_Offset;
1443         int64u              Hash_ParseUpTo;
1444     #endif //MEDIAINFO_HASH
1445 
1446     #if MEDIAINFO_SEEK
1447     private:
1448         bool Seek_Duration_Detected;
1449     #endif //MEDIAINFO_SEEK
1450 
1451     #if MEDIAINFO_IBIUSAGE
1452     public:
1453         bool    Config_Ibi_Create;
1454         int64u  Ibi_SynchronizationOffset_Current;
1455         int64u  Ibi_SynchronizationOffset_BeginOfFrame;
1456         ibi     Ibi; //If Main only
1457         ibi::stream* IbiStream; //If sub only
1458         size_t  Ibi_Read_Buffer_Seek        (size_t Method, int64u Value, int64u ID);
1459         void    Ibi_Read_Buffer_Unsynched   ();
1460         void    Ibi_Stream_Finish           ();
1461         void    Ibi_Stream_Finish           (int64u Numerator, int64u Denominator); //Partial
1462         void    Ibi_Add                     ();
1463     #else //MEDIAINFO_IBIUSAGE
Ibi_Read_Buffer_Seek(size_t,int64u,int64u)1464         size_t  Ibi_Read_Buffer_Seek        (size_t, int64u, int64u)            {return (size_t)-1;}
Ibi_Read_Buffer_Unsynched()1465         void    Ibi_Read_Buffer_Unsynched   ()                                  {}
Ibi_Stream_Finish()1466         void    Ibi_Stream_Finish           ()                                  {}
Ibi_Stream_Finish(int64u,int64u)1467         void    Ibi_Stream_Finish           (int64u, int64u)                    {}
Ibi_Add()1468         void    Ibi_Add                     ()                                  {}
1469     #endif //MEDIAINFO_IBIUSAGE
1470 };
1471 
1472 //Helpers
1473 #define DETAILS_INFO(_DATA)
1474 
1475 #endif
1476