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 // Pre-compilation
9 #include "MediaInfo/PreComp.h"
10 #ifdef __BORLANDC__
11     #pragma hdrstop
12 #endif
13 //---------------------------------------------------------------------------
14 
15 //---------------------------------------------------------------------------
16 #include "MediaInfo/Setup.h"
17 //---------------------------------------------------------------------------
18 
19 //---------------------------------------------------------------------------
20 #if defined(MEDIAINFO_MK_YES)
21 //---------------------------------------------------------------------------
22 
23 //---------------------------------------------------------------------------
24 #include "MediaInfo/Multiple/File_Mk.h"
25 #if defined(MEDIAINFO_OGG_YES)
26     #include "MediaInfo/Multiple/File_Ogg.h"
27 #endif
28 #if defined(MEDIAINFO_RM_YES)
29     #include "MediaInfo/Multiple/File_Rm.h"
30 #endif
31 #if defined(MEDIAINFO_MPEG4V_YES)
32     #include "MediaInfo/Video/File_Mpeg4v.h"
33 #endif
34 #if defined(MEDIAINFO_AV1_YES)
35     #include "MediaInfo/Video/File_Av1.h"
36 #endif
37 #if defined(MEDIAINFO_AVC_YES)
38     #include "MediaInfo/Video/File_Avc.h"
39 #endif
40 #if defined(MEDIAINFO_DVDIF_YES)
41     #include "MediaInfo/Multiple/File_DvDif.h"
42 #endif
43 #if defined(MEDIAINFO_HEVC_YES)
44     #include "MediaInfo/Video/File_Hevc.h"
45 #endif
46 #if defined(MEDIAINFO_FFV1_YES)
47     #include "MediaInfo/Video/File_Ffv1.h"
48 #endif
49 #if defined(MEDIAINFO_HUFFYUV_YES)
50     #include "MediaInfo/Video/File_HuffYuv.h"
51 #endif
52 #if defined(MEDIAINFO_VC1_YES)
53     #include "MediaInfo/Video/File_Vc1.h"
54 #endif
55 #if defined(MEDIAINFO_DIRAC_YES)
56     #include "MediaInfo/Video/File_Dirac.h"
57 #endif
58 #if defined(MEDIAINFO_MPEGV_YES)
59     #include "MediaInfo/Video/File_Mpegv.h"
60 #endif
61 #if defined(MEDIAINFO_PRORES_YES)
62     #include "MediaInfo/Video/File_ProRes.h"
63 #endif
64 #if defined(MEDIAINFO_VP8_YES)
65     #include "MediaInfo/Video/File_Vp8.h"
66 #endif
67 #if defined(MEDIAINFO_AAC_YES)
68     #include "MediaInfo/Audio/File_Aac.h"
69 #endif
70 #if defined(MEDIAINFO_AC3_YES)
71     #include "MediaInfo/Audio/File_Ac3.h"
72 #endif
73 #if defined(MEDIAINFO_DTS_YES)
74     #include "MediaInfo/Audio/File_Dts.h"
75 #endif
76 #if defined(MEDIAINFO_MPEGA_YES)
77     #include "MediaInfo/Audio/File_Mpega.h"
78 #endif
79 #if defined(MEDIAINFO_FLAC_YES)
80     #include "MediaInfo/Audio/File_Flac.h"
81 #endif
82 #if defined(MEDIAINFO_OPUS_YES)
83     #include "MediaInfo/Audio/File_Opus.h"
84 #endif
85 #if defined(MEDIAINFO_WVPK_YES)
86     #include "MediaInfo/Audio/File_Wvpk.h"
87 #endif
88 #if defined(MEDIAINFO_TTA_YES)
89     #include "MediaInfo/Audio/File_Tta.h"
90 #endif
91 #if defined(MEDIAINFO_PCM_YES)
92     #include "MediaInfo/Audio/File_Pcm.h"
93 #endif
94 #if MEDIAINFO_EVENTS
95     #include "MediaInfo/MediaInfo_Events.h"
96 #endif //MEDIAINFO_EVENTS
97 #include "MediaInfo/MediaInfo_Config_MediaInfo.h"
98 #include <cstring>
99 #include <cmath>
100 #include <algorithm>
101 #include <zlib.h>
102 #include "ThirdParty/base64/base64.h"
103 #if MEDIAINFO_EVENTS
104     #include "MediaInfo/MediaInfo_Events_Internal.h"
105 #endif //MEDIAINFO_EVENTS
106 //---------------------------------------------------------------------------
107 
108 namespace MediaInfoLib
109 {
110 
111 //***************************************************************************
112 // Constants
113 //***************************************************************************
114 
115 //---------------------------------------------------------------------------
116 #if MEDIAINFO_TRACE
117     static const size_t MaxCountSameElementInTrace=10;
118 #endif // MEDIAINFO_TRACE
119 
120 //---------------------------------------------------------------------------
121 namespace Elements
122 {
123     //Common
124     const int64u Zero=(int32u)-1; //Should be (int64u)-1 but Borland C++ does not like this
125     const int64u CRC32=0x3F;
126     const int64u Void=0x6C;
127 
128     //EBML
129     const int64u Ebml=0xA45DFA3;
130     const int64u Ebml_Version=0x286;
131     const int64u Ebml_ReadVersion=0x2F7;
132     const int64u Ebml_MaxIDLength=0x2F2;
133     const int64u Ebml_MaxSizeLength=0x2F3;
134     const int64u Ebml_DocType=0x282;
135     const int64u Ebml_DocTypeVersion=0x287;
136     const int64u Ebml_DocTypeReadVersion=0x285;
137 
138     //RAWcooked
139     const int64u RawcookedBlock=0x7262;
140     const int64u RawcookedBlock_AfterData=0x02;
141     const int64u RawcookedBlock_BeforeData=0x01;
142     const int64u RawcookedBlock_FileName=0x10;
143     const int64u RawcookedBlock_FileHash=0x20;
144     const int64u RawcookedBlock_MaskAdditionAfterData=0x04;
145     const int64u RawcookedBlock_MaskAdditionBeforeData=0x03;
146     const int64u RawcookedBlock_MaskAdditionFileName=0x11;
147     const int64u RawcookedSegment=0x7273;
148     const int64u RawcookedSegment_LibraryName=0x70;
149     const int64u RawcookedSegment_LibraryVersion=0x71;
150     const int64u RawcookedTrack=0x7274;
151     const int64u RawcookedTrack_AfterData=0x02;
152     const int64u RawcookedTrack_BeforeData=0x01;
153     const int64u RawcookedTrack_FileName=0x10;
154     const int64u RawcookedTrack_FileHash=0x20;
155     const int64u RawcookedTrack_MaskBaseAfterData=0x04;
156     const int64u RawcookedTrack_MaskBaseBeforeData=0x03;
157     const int64u RawcookedTrack_MaskBaseFileName=0x11;
158 
159     //Segment
160     const int64u Segment=0x8538067;
161     const int64u Segment_SeekHead=0x14D9B74;
162     const int64u Segment_SeekHead_Seek=0xDBB;
163     const int64u Segment_SeekHead_Seek_SeekID=0x13AB;
164     const int64u Segment_SeekHead_Seek_SeekPosition=0x13AC;
165     const int64u Segment_Info=0x549A966;
166     const int64u Segment_Info_SegmentUID=0x33A4;
167     const int64u Segment_Info_SegmentFilename=0x3384;
168     const int64u Segment_Info_PrevUID=0x1CB923;
169     const int64u Segment_Info_PrevFilename=0x1C83AB;
170     const int64u Segment_Info_NextUID=0x1EB923;
171     const int64u Segment_Info_NextFilename=0x1E83BB;
172     const int64u Segment_Info_SegmentFamily=0x444;
173     const int64u Segment_Info_ChapterTranslate=0x2924;
174     const int64u Segment_Info_ChapterTranslate_ChapterTranslateEditionUID=0x29FC;
175     const int64u Segment_Info_ChapterTranslate_ChapterTranslateCodec=0x29BF;
176     const int64u Segment_Info_ChapterTranslate_ChapterTranslateID=0x29A5;
177     const int64u Segment_Info_TimecodeScale=0xAD7B1;
178     const int64u Segment_Info_Duration=0x489;
179     const int64u Segment_Info_DateUTC=0x461;
180     const int64u Segment_Info_Title=0x3BA9;
181     const int64u Segment_Info_MuxingApp=0xD80;
182     const int64u Segment_Info_WritingApp=0x1741;
183     const int64u Segment_Cluster=0xF43B675;
184     const int64u Segment_Cluster_Timecode=0x67;
185     const int64u Segment_Cluster_SilentTracks=0x1854;
186     const int64u Segment_Cluster_SilentTracks_SilentTrackNumber=0x18D7;
187     const int64u Segment_Cluster_Position=0x27;
188     const int64u Segment_Cluster_PrevSize=0x2B;
189     const int64u Segment_Cluster_SimpleBlock=0x23;
190     const int64u Segment_Cluster_BlockGroup=0x20;
191     const int64u Segment_Cluster_BlockGroup_Block=0x21;
192     const int64u Segment_Cluster_BlockGroup_Block_Lace=0xFFFFFFFFFFFFFFFELL; //Fake one
193     const int64u Segment_Cluster_BlockGroup_BlockVirtual=0x22;
194     const int64u Segment_Cluster_BlockGroup_BlockAdditions=0x35A1;
195     const int64u Segment_Cluster_BlockGroup_BlockAdditions_BlockMore=0x26;
196     const int64u Segment_Cluster_BlockGroup_BlockAdditions_BlockMore_BlockAddID=0x6E;
197     const int64u Segment_Cluster_BlockGroup_BlockAdditions_BlockMore_BlockAdditional=0x25;
198     const int64u Segment_Cluster_BlockGroup_BlockDuration=0x1B;
199     const int64u Segment_Cluster_BlockGroup_ReferencePriority=0x7A;
200     const int64u Segment_Cluster_BlockGroup_ReferenceBlock=0x7B;
201     const int64u Segment_Cluster_BlockGroup_ReferenceVirtual=0x7D;
202     const int64u Segment_Cluster_BlockGroup_CodecState=0x24;
203     const int64u Segment_Cluster_BlockGroup_DiscardPadding=0x35A2;
204     const int64u Segment_Cluster_BlockGroup_Slices=0xE;
205     const int64u Segment_Cluster_BlockGroup_Slices_TimeSlice=0x68;
206     const int64u Segment_Cluster_BlockGroup_Slices_TimeSlice_LaceNumber=0x4C;
207     const int64u Segment_Cluster_BlockGroup_Slices_TimeSlice_FrameNumber=0x4D;
208     const int64u Segment_Cluster_BlockGroup_Slices_TimeSlice_BlockAdditionID=0x4B;
209     const int64u Segment_Cluster_BlockGroup_Slices_TimeSlice_Delay=0x4E;
210     const int64u Segment_Cluster_BlockGroup_Slices_TimeSlice_SliceDuration=0x4F;
211     const int64u Segment_Cluster_BlockGroup_ReferenceFrame=0x48;
212     const int64u Segment_Cluster_BlockGroup_ReferenceFrame_ReferenceOffset=0x49;
213     const int64u Segment_Cluster_BlockGroup_ReferenceFrame_ReferenceTimeCode=0x4A;
214     const int64u Segment_Cluster_EncryptedBlock=0x2F;
215     const int64u Segment_Tracks=0x654AE6B;
216     const int64u Segment_Tracks_TrackEntry=0x2E;
217     const int64u Segment_Tracks_TrackEntry_TrackNumber=0x57;
218     const int64u Segment_Tracks_TrackEntry_TrackUID=0x33C5;
219     const int64u Segment_Tracks_TrackEntry_TrackType=0x3;
220     const int64u Segment_Tracks_TrackEntry_FlagEnabled=0x39;
221     const int64u Segment_Tracks_TrackEntry_FlagDefault=0x8;
222     const int64u Segment_Tracks_TrackEntry_FlagForced=0x15AA;
223     const int64u Segment_Tracks_TrackEntry_FlagLacing=0x1C;
224     const int64u Segment_Tracks_TrackEntry_MinCache=0x2DE7;
225     const int64u Segment_Tracks_TrackEntry_MaxCache=0x2DF8;
226     const int64u Segment_Tracks_TrackEntry_DefaultDuration=0x3E383;
227     const int64u Segment_Tracks_TrackEntry_DefaultDecodedFieldDuration=0x34E7A;
228     const int64u Segment_Tracks_TrackEntry_TrackTimecodeScale=0x3314F;
229     const int64u Segment_Tracks_TrackEntry_TrackOffset=0x137F;
230     const int64u Segment_Tracks_TrackEntry_MaxBlockAdditionID=0x15EE;
231     const int64u Segment_Tracks_TrackEntry_Name=0x136E;
232     const int64u Segment_Tracks_TrackEntry_Language=0x2B59C;
233     const int64u Segment_Tracks_TrackEntry_LanguageIETF=0x2B59D;
234     const int64u Segment_Tracks_TrackEntry_CodecID=0x6;
235     const int64u Segment_Tracks_TrackEntry_CodecPrivate=0x23A2;
236     const int64u Segment_Tracks_TrackEntry_CodecName=0x58688;
237     const int64u Segment_Tracks_TrackEntry_AttachmentLink=0x3446;
238     const int64u Segment_Tracks_TrackEntry_CodecSettings=0x1A9697;
239     const int64u Segment_Tracks_TrackEntry_CodecInfoURL=0x1B4040;
240     const int64u Segment_Tracks_TrackEntry_CodecDownloadURL=0x6B240;
241     const int64u Segment_Tracks_TrackEntry_CodecDecodeAll=0x2A;
242     const int64u Segment_Tracks_TrackEntry_TrackOverlay=0x2FAB;
243     const int64u Segment_Tracks_TrackEntry_CodecDelay=0x16AA;
244     const int64u Segment_Tracks_TrackEntry_SeekPreRoll=0x16BB;
245     const int64u Segment_Tracks_TrackEntry_TrackTranslate=0x2624;
246     const int64u Segment_Tracks_TrackEntry_TrackTranslate_TrackTranslateEditionUID=0x26FC;
247     const int64u Segment_Tracks_TrackEntry_TrackTranslate_TrackTranslateCodec=0x26BF;
248     const int64u Segment_Tracks_TrackEntry_TrackTranslate_TrackTranslateTrackID=0x26A5;
249     const int64u Segment_Tracks_TrackEntry_Video=0x60;
250     const int64u Segment_Tracks_TrackEntry_Video_FlagInterlaced=0x1A;
251     const int64u Segment_Tracks_TrackEntry_Video_FieldOrder=0x1D;
252     const int64u Segment_Tracks_TrackEntry_Video_StereoMode=0x13B8;
253     const int64u Segment_Tracks_TrackEntry_Video_AlphaMode=0x13C0;
254     const int64u Segment_Tracks_TrackEntry_Video_OldStereoMode=0x13B9;
255     const int64u Segment_Tracks_TrackEntry_Video_PixelWidth=0x30;
256     const int64u Segment_Tracks_TrackEntry_Video_PixelHeight=0x3A;
257     const int64u Segment_Tracks_TrackEntry_Video_PixelCropBottom=0x14AA;
258     const int64u Segment_Tracks_TrackEntry_Video_PixelCropTop=0x14BB;
259     const int64u Segment_Tracks_TrackEntry_Video_PixelCropLeft=0x14CC;
260     const int64u Segment_Tracks_TrackEntry_Video_PixelCropRight=0x14DD;
261     const int64u Segment_Tracks_TrackEntry_Video_DisplayWidth=0x14B0;
262     const int64u Segment_Tracks_TrackEntry_Video_DisplayHeight=0x14BA;
263     const int64u Segment_Tracks_TrackEntry_Video_DisplayUnit=0x14B2;
264     const int64u Segment_Tracks_TrackEntry_Video_AspectRatioType=0x14B3;
265     const int64u Segment_Tracks_TrackEntry_Video_ColourSpace=0xEB524;
266     const int64u Segment_Tracks_TrackEntry_Video_GammaValue=0xFB523;
267     const int64u Segment_Tracks_TrackEntry_Video_FrameRate=0x383E3;
268     const int64u Segment_Tracks_TrackEntry_Video_Colour=0x15B0;
269     const int64u Segment_Tracks_TrackEntry_Video_Colour_MatrixCoefficients=0x15B1;
270     const int64u Segment_Tracks_TrackEntry_Video_Colour_BitsPerChannel=0x15B2;
271     const int64u Segment_Tracks_TrackEntry_Video_Colour_ChromaSubsamplingHorz=0x15B3;
272     const int64u Segment_Tracks_TrackEntry_Video_Colour_ChromaSubsamplingVert=0x15B4;
273     const int64u Segment_Tracks_TrackEntry_Video_Colour_CbSubsamplingHorz=0x15B5;
274     const int64u Segment_Tracks_TrackEntry_Video_Colour_CbSubsamplingVert=0x15B6;
275     const int64u Segment_Tracks_TrackEntry_Video_Colour_ChromaSitingHorz=0x15B7;
276     const int64u Segment_Tracks_TrackEntry_Video_Colour_ChromaSitingVert=0x15B8;
277     const int64u Segment_Tracks_TrackEntry_Video_Colour_Range=0x15B9;
278     const int64u Segment_Tracks_TrackEntry_Video_Colour_TransferCharacteristics=0x15BA;
279     const int64u Segment_Tracks_TrackEntry_Video_Colour_Primaries=0x15BB;
280     const int64u Segment_Tracks_TrackEntry_Video_Colour_MaxCLL=0x15BC;
281     const int64u Segment_Tracks_TrackEntry_Video_Colour_MaxFALL=0x15BD;
282     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata=0x15D0;
283     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryRChromaticityX=0x15D1;
284     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryRChromaticityY=0x15D2;
285     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryGChromaticityX=0x15D3;
286     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryGChromaticityY=0x15D4;
287     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryBChromaticityX=0x15D5;
288     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryBChromaticityY=0x15D6;
289     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_WhitePointChromaticityX=0x15D7;
290     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_WhitePointChromaticityY=0x15D8;
291     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_LuminanceMax=0x15D9;
292     const int64u Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_LuminanceMin=0x15DA;
293     const int64u Segment_Tracks_TrackEntry_Video_Projection=0x3670;
294     const int64u Segment_Tracks_TrackEntry_Video_Projection_ProjectionType=0x3671;
295     const int64u Segment_Tracks_TrackEntry_Video_Projection_ProjectionPrivate=0x3672;
296     const int64u Segment_Tracks_TrackEntry_Video_Projection_ProjectionPoseYaw=0x3673;
297     const int64u Segment_Tracks_TrackEntry_Video_Projection_ProjectionPosePitch=0x3674;
298     const int64u Segment_Tracks_TrackEntry_Video_Projection_ProjectionPoseRoll=0x3675;
299     const int64u Segment_Tracks_TrackEntry_Audio=0x61;
300     const int64u Segment_Tracks_TrackEntry_Audio_SamplingFrequency=0x35;
301     const int64u Segment_Tracks_TrackEntry_Audio_OutputSamplingFrequency=0x38B5;
302     const int64u Segment_Tracks_TrackEntry_Audio_Channels=0x1F;
303     const int64u Segment_Tracks_TrackEntry_Audio_ChannelPositions=0x3D7B;
304     const int64u Segment_Tracks_TrackEntry_Audio_BitDepth=0x2264;
305     const int64u Segment_Tracks_TrackEntry_TrackOperation=0x62;
306     const int64u Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes=0x63;
307     const int64u Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes_TrackPlane=0x64;
308     const int64u Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes_TrackPlane_TrackPlaneUID=0x65;
309     const int64u Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes_TrackPlane_TrackPlaneType=0x66;
310     const int64u Segment_Tracks_TrackEntry_TrackOperation_TrackJoinBlocks=0x69;
311     const int64u Segment_Tracks_TrackEntry_TrackOperation_TrackJoinBlocks_TrackJoinUID=0x6D;
312     const int64u Segment_Tracks_TrackEntry_TrickTrackUID=0x40;
313     const int64u Segment_Tracks_TrackEntry_TrickTrackSegmentUID=0x41;
314     const int64u Segment_Tracks_TrackEntry_TrickTrackFlag=0x46;
315     const int64u Segment_Tracks_TrackEntry_TrickMasterTrackUID=0x47;
316     const int64u Segment_Tracks_TrackEntry_TrickMasterTrackSegmentUID=0x44;
317     const int64u Segment_Tracks_TrackEntry_BlockAdditionMapping=0x1E4;
318     const int64u Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDName=0x1A4;
319     const int64u Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDType=0x1E7;
320     const int64u Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDExtraData=0x1ED;
321     const int64u Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDValue=0x1F0;
322     const int64u Segment_Tracks_TrackEntry_ContentEncodings=0x2D80;
323     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding=0x2240;
324     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncodingOrder=0x1031;
325     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncodingScope=0x1032;
326     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncodingType=0x1033;
327     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression=0x1034;
328     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompAlgo=0x254;
329     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompSettings=0x255;
330     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption=0x1035;
331     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentEncAlgo=0x7E1;
332     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentEncKeyID=0x7E2;
333     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSignature=0x7E3;
334     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSigKeyID=0x7E4;
335     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSigAlgo=0x7E5;
336     const int64u Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSigHashAlgo=0x7E6;
337     const int64u Segment_Cues=0xC53BB6B;
338     const int64u Segment_Cues_CuePoint=0x3B;
339     const int64u Segment_Cues_CuePoint_CueTime=0x33;
340     const int64u Segment_Cues_CuePoint_CueTrackPositions=0x37;
341     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueTrack=0x77;
342     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueClusterPosition=0x71;
343     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueRelativePosition=0x70;
344     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueDuration=0x32;
345     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueBlockNumber=0x1378;
346     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueCodecState=0x6A;
347     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueReference=0x5B;
348     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefTime=0x16;
349     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefCluster=0x17;
350     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefNumber=0x135F;
351     const int64u Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefCodecState=0x6B;
352     const int64u Segment_Attachments=0x941A469;
353     const int64u Segment_Attachments_AttachedFile=0x21A7;
354     const int64u Segment_Attachments_AttachedFile_FileDescription=0x67E;
355     const int64u Segment_Attachments_AttachedFile_FileName=0x66E;
356     const int64u Segment_Attachments_AttachedFile_FileMimeType=0x660;
357     const int64u Segment_Attachments_AttachedFile_FileData=0x65C;
358     const int64u Segment_Attachments_AttachedFile_FileUID=0x6AE;
359     const int64u Segment_Attachments_AttachedFile_FileReferral=0x675;
360     const int64u Segment_Attachments_AttachedFile_FileUsedStartTime=0x661;
361     const int64u Segment_Attachments_AttachedFile_FileUsedEndTime=0x662;
362     const int64u Segment_Chapters=0x43A770;
363     const int64u Segment_Chapters_EditionEntry=0x5B9;
364     const int64u Segment_Chapters_EditionEntry_EditionUID=0x5BC;
365     const int64u Segment_Chapters_EditionEntry_EditionFlagHidden=0x5BD;
366     const int64u Segment_Chapters_EditionEntry_EditionFlagDefault=0x5DB;
367     const int64u Segment_Chapters_EditionEntry_EditionFlagOrdered=0x5DD;
368     const int64u Segment_Chapters_EditionEntry_ChapterAtom=0x36;
369     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterUID=0x33C4;
370     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterStringUID=0x1654;
371     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeStart=0x11;
372     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeEnd=0x12;
373     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterFlagHidden=0x18;
374     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterFlagEnabled=0x598;
375     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterSegmentUID=0x2E67;
376     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterSegmentEditionUID=0x2EBC;
377     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterPhysicalEquiv=0x23C3;
378     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterTrack=0xF;
379     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterTrack_ChapterTrackNumber=0x9;
380     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay=0x0;
381     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapString=0x5;
382     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguage=0x37C;
383     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguageIETF=0x37D;
384     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapCountry=0x37E;
385     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess=0x2944;
386     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCodecID=0x2955;
387     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessPrivate=0x50D;
388     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand=0x2911;
389     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand_ChapProcessTime=0x2922;
390     const int64u Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand_ChapProcessData=0x2933;
391     const int64u Segment_Tags=0x254C367;
392     const int64u Segment_Tags_Tag=0x3373;
393     const int64u Segment_Tags_Tag_Targets=0x23C0;
394     const int64u Segment_Tags_Tag_Targets_TargetTypeValue=0x28CA;
395     const int64u Segment_Tags_Tag_Targets_TargetType=0x23CA;
396     const int64u Segment_Tags_Tag_Targets_TagTrackUID=0x23C5;
397     const int64u Segment_Tags_Tag_Targets_TagEditionUID=0x23C9;
398     const int64u Segment_Tags_Tag_Targets_TagChapterUID=0x23C4;
399     const int64u Segment_Tags_Tag_Targets_TagAttachmentUID=0x23C6;
400     const int64u Segment_Tags_Tag_SimpleTag=0x27C8;
401     const int64u Segment_Tags_Tag_SimpleTag_TagName=0x5A3;
402     const int64u Segment_Tags_Tag_SimpleTag_TagLanguage=0x47A;
403     const int64u Segment_Tags_Tag_SimpleTag_TagLanguageIETF=0x47B;
404     const int64u Segment_Tags_Tag_SimpleTag_TagDefault=0x484;
405     const int64u Segment_Tags_Tag_SimpleTag_TagString=0x487;
406     const int64u Segment_Tags_Tag_SimpleTag_TagBinary=0x485;
407 }
408 
409 //---------------------------------------------------------------------------
410 // CRC_32_Table (Little Endian bitstream, )
411 // The CRC in use is the IEEE-CRC-32 algorithm as used in the ISO 3309 standard and in section 8.1.1.6.2 of ITU-T recommendation V.42, with initial value of 0xFFFFFFFF. The CRC value MUST be computed on a little endian bitstream and MUST use little endian storage.
412 // A CRC is computed like this:
413 // Init: int32u CRC32 ^= 0;
414 // for each data byte do
415 //     CRC32=(CRC32>>8) ^ Mk_CRC32_Table[(CRC32&0xFF)^*Buffer_Current++];
416 // End: CRC32 ^= 0;
417 static const int32u Mk_CRC32_Table[256] =
418 {
419     0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
420     0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
421     0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
422     0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
423     0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
424     0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
425     0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
426     0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
427     0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
428     0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
429     0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
430     0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
431     0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
432     0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
433     0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
434     0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
435     0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
436     0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
437     0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
438     0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
439     0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
440     0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
441     0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
442     0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
443     0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
444     0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
445     0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
446     0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
447     0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
448     0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
449     0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
450     0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
451     0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
452     0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
453     0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
454     0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
455     0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
456     0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
457     0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
458     0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
459     0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
460     0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
461     0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
462     0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
463     0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
464     0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
465     0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
466     0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
467     0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
468     0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
469     0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
470     0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
471     0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
472     0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
473     0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
474     0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
475     0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
476     0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
477     0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
478     0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
479     0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
480     0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
481     0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
482     0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02Ef8D,
483 };
484 
485 //---------------------------------------------------------------------------
Matroska_CRC32_Compute(int32u & CRC32,const int8u * Buffer_Current,const int8u * Buffer_End)486 static void Matroska_CRC32_Compute(int32u &CRC32, const int8u* Buffer_Current, const int8u* Buffer_End)
487 {
488     while (Buffer_Current<Buffer_End)
489         CRC32 = (CRC32 >> 8) ^ Mk_CRC32_Table[(CRC32 & 0xFF) ^ *Buffer_Current++];
490 }
491 
492 //---------------------------------------------------------------------------
493 #if MEDIAINFO_FIXITY
Matroska_TryToFixCRC(int8u * Buffer,size_t Buffer_Size,int32u CRCExpected,int8u & Modified)494 static size_t Matroska_TryToFixCRC(int8u* Buffer, size_t Buffer_Size, int32u CRCExpected, int8u& Modified)
495 {
496     //looking for a bit flip
497     vector<size_t> BitPositions;
498     size_t BitPosition_Max=Buffer_Size*8;
499     for (size_t BitPosition=0; BitPosition<BitPosition_Max; BitPosition++)
500     {
501         size_t BytePosition=BitPosition>>3;
502         size_t BitInBytePosition=BitPosition&0x7;
503         Buffer[BytePosition]^=1<<BitInBytePosition;
504         int32u CRC32Computed=0xFFFFFFFF;
505         Matroska_CRC32_Compute(CRC32Computed, Buffer, Buffer+Buffer_Size);
506         CRC32Computed ^= 0xFFFFFFFF;
507         if (CRC32Computed==CRCExpected)
508         {
509             BitPositions.push_back(BitPosition);
510         }
511         Buffer[BytePosition]^=1<<BitInBytePosition;
512     }
513 
514     if (BitPositions.size()!=1)
515         return (size_t)-1;
516 
517     Modified=Buffer[BitPositions[0]>>3]; //Save the byte here as we already have the content
518     return BitPositions[0];
519 }
520 #endif //MEDIAINFO_FIXITY
521 
522 //---------------------------------------------------------------------------
Mk_ContentCompAlgo(int64u Algo)523 static const char* Mk_ContentCompAlgo(int64u Algo)
524 {
525     switch (Algo)
526     {
527         case 0x00 : return "zlib";
528         case 0x01 : return "bzlib";
529         case 0x02 : return "lzo1x";
530         case 0x03 : return "Header stripping";
531         default   : return "";
532     }
533 }
534 
535 //---------------------------------------------------------------------------
Mk_StereoMode(int64u StereoMode)536 static const char* Mk_StereoMode(int64u StereoMode)
537 {
538     switch (StereoMode)
539     {
540         case 0x00 : return ""; //Mono (default)
541         case 0x01 : return "Side by Side (left eye first)";
542         case 0x02 : return "Top-Bottom (right eye first)";
543         case 0x03 : return "Top-Bottom (left eye first)";
544         case 0x04 : return "Checkboard (right eye first)";
545         case 0x05 : return "Checkboard (left eye first)";
546         case 0x06 : return "Row Interleaved (right eye first)";
547         case 0x07 : return "Row Interleaved (left eye first)";
548         case 0x08 : return "Column Interleaved (right eye first)";
549         case 0x09 : return "Column Interleaved (left eye first)";
550         case 0x0A : return "Anaglyph (cyan/red)";
551         case 0x0B : return "Side by Side (right eye first)";
552         case 0x0C : return "Anaglyph (green/magenta)";
553         case 0x0D : return "Both Eyes laced in one block (left eye first)";
554         case 0x0E : return "Both Eyes laced in one block (right eye first)";
555         default   : return "";
556     }
557 }
558 
559 //---------------------------------------------------------------------------
Mk_OriginalSourceMedium_From_Source_ID(const Ztring & Value)560 static const char* Mk_OriginalSourceMedium_From_Source_ID (const Ztring &Value)
561 {
562     if (Value.size()==6 && Value[0] == __T('0') && Value[1] == __T('0'))
563         return "Blu-ray";
564     if (Value.size()==6 && Value[0] == __T('0') && Value[1] == __T('1'))
565         return "DVD-Video";
566     return "";
567 }
568 
569 //---------------------------------------------------------------------------
Mk_ID_From_Source_ID(const Ztring & Value)570 static Ztring Mk_ID_From_Source_ID (const Ztring &Value)
571 {
572     if (Value.size()==6 && Value[0] == __T('0') && Value[1] == __T('0'))
573     {
574         // Blu-ray
575         int16u ValueI=0;
576         for (size_t Pos=2; Pos<Value.size(); Pos++)
577         {
578             ValueI*=16;
579             if (Value[Pos]>=__T('0') && Value[Pos]<=__T('9'))
580                 ValueI+=Value[Pos]-__T('0');
581             else if (Value[Pos]>=__T('A') && Value[Pos]<=__T('F'))
582                 ValueI+=10+Value[Pos]-__T('A');
583             else if (Value[Pos]>=__T('a') && Value[Pos]<=__T('f'))
584                 ValueI+=10+Value[Pos]-__T('a');
585             else
586                 return Value;
587         }
588         return Ztring::ToZtring(ValueI);
589     }
590 
591     if (Value.size()==6 && Value[0] == __T('0') && Value[1] == __T('1'))
592     {
593         // DVD-Video
594         int16u ValueI=0;
595         for (size_t Pos=2; Pos<Value.size(); Pos++)
596         {
597             ValueI*=16;
598             if (Value[Pos]>=__T('0') && Value[Pos]<=__T('9'))
599                 ValueI+=Value[Pos]-__T('0');
600             else if (Value[Pos]>=__T('A') && Value[Pos]<=__T('F'))
601                 ValueI+=10+Value[Pos]-__T('A');
602             else if (Value[Pos]>=__T('a') && Value[Pos]<=__T('f'))
603                 ValueI+=10+Value[Pos]-__T('a');
604             else
605                 return Value;
606         }
607         int8u ID1 = ValueI&0xFF;
608         int8u ID2 = 0;
609         ValueI-=ID1;
610         if (ValueI)
611             ID2=ValueI>>8;
612 
613         return Ztring::ToZtring(ID1) + (ID2?(__T('-') + Ztring::ToZtring(ID2)):Ztring());
614     }
615 
616     return Value;
617 }
618 
619 //---------------------------------------------------------------------------
Mk_ID_String_From_Source_ID(const Ztring & Value)620 static Ztring Mk_ID_String_From_Source_ID (const Ztring &Value)
621 {
622     if (Value.size()==6 && Value[0] == __T('0') && Value[1] == __T('0'))
623     {
624         // Blu-ray
625         int16u ValueI=0;
626         for (size_t Pos=2; Pos<Value.size(); Pos++)
627         {
628             ValueI*=16;
629             if (Value[Pos]>=__T('0') && Value[Pos]<=__T('9'))
630                 ValueI+=Value[Pos]-__T('0');
631             else if (Value[Pos]>=__T('A') && Value[Pos]<=__T('F'))
632                 ValueI+=10+Value[Pos]-__T('A');
633             else if (Value[Pos]>=__T('a') && Value[Pos]<=__T('f'))
634                 ValueI+=10+Value[Pos]-__T('a');
635             else
636                 return Value;
637         }
638 
639         return Get_Hex_ID(ValueI);
640     }
641 
642     if (Value.size()==6 && Value[0] == __T('0') && Value[1] == __T('1'))
643     {
644         // DVD-Video
645         int16u ValueI=0;
646         for (size_t Pos=2; Pos<Value.size(); Pos++)
647         {
648             ValueI*=16;
649             if (Value[Pos]>=__T('0') && Value[Pos]<=__T('9'))
650                 ValueI+=Value[Pos]-__T('0');
651             else if (Value[Pos]>=__T('A') && Value[Pos]<=__T('F'))
652                 ValueI+=10+Value[Pos]-__T('A');
653             else if (Value[Pos]>=__T('a') && Value[Pos]<=__T('f'))
654                 ValueI+=10+Value[Pos]-__T('a');
655             else
656                 return Value;
657         }
658         int8u ID1 = ValueI&0xFF;
659         int8u ID2 = 0;
660         ValueI-=ID1;
661         if (ValueI)
662             ID2=ValueI>>8;
663 
664         return Get_Hex_ID(ID1) + (ID2? Get_Hex_ID(ID2):Ztring());
665     }
666 
667     return Value;
668 }
669 
670 //***************************************************************************
671 // Infos
672 //***************************************************************************
673 
674 //---------------------------------------------------------------------------
675 extern std::string ExtensibleWave_ChannelMask (int32u ChannelMask);
676 extern std::string ExtensibleWave_ChannelMask2 (int32u ChannelMask);
677 extern std::string ExtensibleWave_ChannelMask_ChannelLayout(int32u ChannelMask);
678 
679 //---------------------------------------------------------------------------
680 const char* Mpegv_colour_primaries(int8u colour_primaries);
681 const char* Mpegv_transfer_characteristics(int8u transfer_characteristics);
682 const char* Mpegv_matrix_coefficients(int8u matrix_coefficients);
683 const char* Mpegv_matrix_coefficients_ColorSpace(int8u matrix_coefficients);
684 
Mk_Video_Colour_Range(int8u range)685 const char* Mk_Video_Colour_Range(int8u range)
686 {
687     switch (range)
688     {
689         case 1: return "Limited";
690         case 2: return "Full";
691         default: return "";
692     }
693 }
694 
695 //***************************************************************************
696 // Constructor/Destructor
697 //***************************************************************************
698 
699 //---------------------------------------------------------------------------
File_Mk()700 File_Mk::File_Mk()
701 :File__Analyze()
702 {
703     //Configuration
704     #if MEDIAINFO_EVENTS
705         ParserIDs[0]=MediaInfo_Parser_Matroska;
706         StreamIDs_Width[0]=16;
707     #endif //MEDIAINFO_EVENTS
708     #if MEDIAINFO_DEMUX
709         Demux_Level=2; //Container
710     #endif //MEDIAINFO_DEMUX
711     #if MEDIAINFO_TRACE
712         Trace_Layers_Update(0); //Container1
713     #endif //MEDIAINFO_TRACE
714     DataMustAlwaysBeComplete=false;
715     MustSynchronize=true;
716 
717     //Temp
718     InvalidByteMax=0; //Default is max size of 8 bytes
719     Format_Version=0;
720     TimecodeScale=1000000; //Default value
721     Duration=0;
722     Segment_Info_Count=0;
723     Segment_Tracks_Count=0;
724     Segment_Cluster_Count=0;
725     CurrentAttachmentIsCover=false;
726     CoverIsSetFromAttachment=false;
727     BlockAddIDType=0;
728     Laces_Pos=0;
729     IsParsingSegmentTrack_SeekBackTo=0;
730     SegmentTrack_Offset_End=0;
731     #if MEDIAINFO_DEMUX
732         Demux_EventWasSent=(int64u)-1;
733     #endif //MEDIAINFO_DEMUX
734     CRC32Compute_SkipUpTo=0;
735     Stream_Count=0;
736     #if MEDIAINFO_TRACE
737         Trace_Activated_Save=false;
738     #endif //MEDIAINFO_TRACE
739 
740     //Hints
741     File_Buffer_Size_Hint_Pointer=NULL;
742 
743     //Helpers
744     CodecPrivate=NULL;
745 }
746 
747 //---------------------------------------------------------------------------
~File_Mk()748 File_Mk::~File_Mk()
749 {
750     delete[] CodecPrivate; //CodecPrivate=NULL;
751 }
752 
753 //***************************************************************************
754 // Streams management
755 //***************************************************************************
756 
757 //---------------------------------------------------------------------------
Streams_Finish()758 void File_Mk::Streams_Finish()
759 {
760     if (Duration!=0 && TimecodeScale!=0)
761         Fill(Stream_General, 0, General_Duration, Duration*int64u_float64(TimecodeScale)/1000000.0, 0);
762 
763     if (Retrieve(Stream_General, 0, General_IsStreamable).empty())
764         Fill(Stream_General, 0, General_IsStreamable, "Yes");
765 
766     //Tags (General)
767     for (tags::iterator Item=Segment_Tags_Tag_Items.begin(); Item!=Segment_Tags_Tag_Items.end(); ++Item)
768         if (!Item->first || Item->first == (int64u)-1)
769         {
770             for (tagspertrack::iterator Tag=Item->second.begin(); Tag!=Item->second.end(); ++Tag)
771                 if ((Tag->first!=__T("Encoded_Library") || Retrieve(Stream_General, 0, "Encoded_Library")!=Tag->second) // Avoid repetition if Info block is same as tags
772                  && (Tag->first!=__T("Encoded_Date") || Retrieve(StreamKind_Last, StreamPos_Last, "Encoded_Date")!=Tag->second)
773                  && (Tag->first!=__T("Title") || Retrieve(StreamKind_Last, StreamPos_Last, "Title")!=Tag->second))
774                     Fill(Stream_General, 0, Tag->first.To_UTF8().c_str(), Tag->second);
775         }
776 
777     for (std::map<int64u, stream>::iterator Temp=Stream.begin(); Temp!=Stream.end(); ++Temp)
778     {
779         StreamKind_Last=Temp->second.StreamKind;
780         StreamPos_Last=Temp->second.StreamPos;
781         float64 FrameRate_FromTags = 0.0;
782         bool HasStats=false;
783 
784         //Tags (per track)
785         if (Temp->second.TrackUID && Temp->second.TrackUID!=(int64u)-1)
786         {
787             //Technical info
788             for (std::map<std::string, Ztring>::iterator Info=Temp->second.Infos.begin(); Info!=Temp->second.Infos.end(); ++Info)
789                 Fill(StreamKind_Last, StreamPos_Last, Info->first.c_str(), Info->second);
790 
791             tags::iterator Item=Segment_Tags_Tag_Items.find(Temp->second.TrackUID);
792             if (Item != Segment_Tags_Tag_Items.end())
793             {
794                 //Statistic Tags
795                 tagspertrack::iterator Item2=Item->second.find(__T("_STATISTICS_TAGS"));
796                 HasStats=Item2!=Item->second.end();
797                 if (HasStats)
798                 {
799                     Ztring TagsList=Item2->second;
800                     Item->second.erase(Item2);
801                     bool Tags_Verified=false;
802                     {
803                         Ztring Hutc = Retrieve(Stream_General, 0, "Encoded_Date");
804                         Hutc.FindAndReplace(__T("UTC "), Ztring());
805                         Hutc = Hutc.substr(0, Hutc.find(__T(" / "), 0)); // leave only the first date in a "UTC date1 / UTC date2" field
806                         Ztring App, Utc;
807                         Item2=Item->second.find(__T("_STATISTICS_WRITING_APP"));
808                         if (Item2!=Item->second.end())
809                         {
810                             App=Item2->second;
811                             Item->second.erase(Item2);
812                         }
813                         Item2=Item->second.find(__T("_STATISTICS_WRITING_DATE_UTC"));
814                         if (Item2!=Item->second.end())
815                         {
816                             Utc=Item2->second;
817                             Item->second.erase(Item2);
818                         }
819                         if (Utc>=Hutc)
820                             Tags_Verified=true;
821                         else
822                             Fill(StreamKind_Last, StreamPos_Last, "Statistics Tags Issue", App + __T(' ') + Utc + __T(" / ") + Retrieve(Stream_General, 0, "Encoded_Application") + __T(' ') + Hutc);
823                     }
824                     Ztring TempTag;
825 
826                     float64 Statistics_Duration=0;
827                     float64 Statistics_FrameCount=0;
828                     for (Ztring::iterator Back = TagsList.begin();;++Back)
829                     {
830                         if ((Back == TagsList.end()) || (*Back == ' ') || (*Back == '\0'))
831                         {
832                             if (!TempTag.empty())
833                             {
834                                 Item2=Item->second.find(TempTag);
835                                 if (Item2!=Item->second.end())
836                                 {
837                                     TempTag=Item2->first;
838                                     const Ztring& TagValue=Item2->second;
839                                     bool Set=false;
840                                     if (TempTag==__T("BPS"))
841                                     {
842                                         if (Tags_Verified)
843                                         { Item->second["BitRate"]=TagValue; Set=true; }
844                                         else
845                                             TempTag="BitRate";
846                                     }
847                                     else if (TempTag==__T("DURATION"))
848                                     {
849                                         if (Tags_Verified)
850                                         {
851                                             ZtringList Parts;
852                                             Parts.Separator_Set(0, ":");
853                                             Parts.Write(TagValue);
854                                             Statistics_Duration=0;
855                                             if (Parts.size()>=1)
856                                                 Statistics_Duration += Parts[0].To_float64()*60*60;
857                                             if (Parts.size()>=2)
858                                                 Statistics_Duration += Parts[1].To_float64()*60;
859                                             int8u Rounding=0; //Default is rounding to milliseconds, TODO: rounding to less than millisecond when "Duration" field is changed to seconds.
860                                             if (Parts.size()>=3)
861                                             {
862                                                 Statistics_Duration += Parts[2].To_float64();
863                                                 if (Parts[2].size()>6) //More than milliseconds
864                                                     Rounding=Parts[2].size()-6;
865                                             }
866                                             Item->second["Duration"].From_Number(Statistics_Duration*1000, Rounding);
867                                             Set=true;
868                                         }
869                                         if (!Set) TempTag="Duration";
870                                     }
871                                     else if (TempTag==__T("NUMBER_OF_FRAMES"))
872                                     {
873                                         if (Tags_Verified)
874                                         {
875                                             Statistics_FrameCount=TagValue.To_float64();
876                                             Item->second["FrameCount"]=TagValue;
877                                             if (StreamKind_Last==Stream_Text)
878                                             {
879                                                 const Ztring &Format=Retrieve(Stream_Text, StreamPos_Last, "Format");
880                                                 if (Format.find(__T("608"))==string::npos && Format.find(__T("708"))==string::npos)
881                                                     Item->second["ElementCount"]=TagValue; // if not 608 or 708, this is used to be also the count of elements
882                                             }
883                                             Set=true;
884                                         }
885                                         else
886                                             TempTag="FrameCount";
887                                     }
888                                     else if (TempTag==__T("NUMBER_OF_BYTES"))
889                                     {
890                                         if (Tags_Verified)
891                                         {
892                                             Item->second["StreamSize"]=TagValue;
893                                             Set=true;
894                                         }
895                                         else
896                                             TempTag="StreamSize";
897                                     }
898                                     else if (TempTag==__T("NUMBER_OF_BYTES_UNCOMPRESSED"))
899                                     {
900                                         if (Tags_Verified)
901                                         {
902                                             Item->second["StreamSize_Demuxed"]=TagValue;
903                                             Set=true;
904                                         }
905                                         else
906                                             TempTag="Stream Size (Uncompressed)";
907                                     }
908                                     else if (TempTag==__T("SOURCE_ID"))
909                                     {
910                                         if (Tags_Verified)
911                                         {
912                                             Item->second["OriginalSourceMedium_ID"]=Mk_ID_From_Source_ID(TagValue);
913                                             Item->second["OriginalSourceMedium_ID/String"]=Mk_ID_String_From_Source_ID(TagValue);
914                                             Item->second["OriginalSourceMedium"]=Mk_OriginalSourceMedium_From_Source_ID(TagValue);
915                                             Set=true;
916                                         }
917                                         else
918                                             TempTag="OriginalSourceMedium_ID";
919                                     }
920                                     if (!Set)
921                                     {
922                                         TempTag.insert(0, __T("FromStats_"));
923                                         Item->second[TempTag]=TagValue;
924                                     }
925 
926                                     Item->second.erase(Item2);
927                                 }
928                                 if (Back == TagsList.end())
929                                     break;
930                                 TempTag.clear();
931                             }
932                         }
933                         else
934                             TempTag+=*Back;
935                     }
936                     if (Statistics_Duration && Statistics_FrameCount)
937                     {
938                         FrameRate_FromTags = Statistics_FrameCount/Statistics_Duration;
939                         if (float64_int64s(FrameRate_FromTags) - FrameRate_FromTags*1.001 > -0.0001
940                          && float64_int64s(FrameRate_FromTags) - FrameRate_FromTags*1.001 < +0.0001)
941                         {
942                             // Checking 1.001 frame rates, Statistics_Duration is has often only a 1 ms precision so we test between -1ms and +1ms
943                             float64 Duration_1001 = Statistics_FrameCount / float64_int64s(FrameRate_FromTags) * 1.001000;
944                             float64 Duration_1000 = Statistics_FrameCount / float64_int64s(FrameRate_FromTags) * 1.001001;
945                             bool CanBe1001 = false;
946                             bool CanBe1000 = false;
947                             if (std::fabs((Duration_1000 - Duration_1001) * 10000) >= 15)
948                             {
949                                 Ztring DurationS; DurationS.From_Number(Statistics_Duration, 3);
950                                 Ztring DurationS_1001; DurationS_1001.From_Number(Duration_1001, 3);
951                                 Ztring DurationS_1000; DurationS_1000.From_Number(Duration_1000, 3);
952 
953                                 CanBe1001=DurationS==DurationS_1001?true:false;
954                                 CanBe1000=DurationS==DurationS_1000?true:false;
955                                 if (CanBe1001 && !CanBe1000)
956                                     FrameRate_FromTags = float64_int64s(FrameRate_FromTags) / 1.001;
957                                 if (CanBe1000 && !CanBe1001)
958                                     FrameRate_FromTags = float64_int64s(FrameRate_FromTags) / 1.001001;
959                             }
960 
961                             // Duration from tags not reliable, checking TrackDefaultDuration
962                             if (CanBe1000 == CanBe1001 && Temp->second.TrackDefaultDuration)
963                             {
964                                 const float64 Duration_Default=((float64)1000000000)/Temp->second.TrackDefaultDuration;
965                                 if (float64_int64s(Duration_Default) - Duration_Default*1.001000 > -0.000002
966                                  && float64_int64s(Duration_Default) - Duration_Default*1.001000 < +0.000002) // Detection of precise 1.001 (e.g. 24000/1001) taking into account precision of 32-bit float
967                                 {
968                                     FrameRate_FromTags = float64_int64s(FrameRate_FromTags) / 1.001;
969                                 }
970                                 if (float64_int64s(Duration_Default) - Duration_Default*1.001001 > -0.000002
971                                  && float64_int64s(Duration_Default) - Duration_Default*1.001001 < +0.000002) // Detection of rounded 1.001 (e.g. 23976/1000) taking into account precision of 32-bit float
972                                 {
973                                     FrameRate_FromTags = float64_int64s(FrameRate_FromTags) / 1.001001;
974                                 }
975                             }
976                         }
977 
978                         Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_FrameRate), FrameRate_FromTags, 3, true);
979                     }
980                 }
981 
982                 //Filling
983                 for (tagspertrack::iterator Tag=Item->second.begin(); Tag!=Item->second.end(); ++Tag)
984                 {
985                     if (!HasStats && Tag->first==__T("DURATION"))
986                     {
987                         //If this field is present but there is no stats tag, let's hope that the field was not copied as is after an edit of the file...
988                         const string& s=Tag->second.To_UTF8();
989                         if ( s.size()>=12
990                          &&  s[ 0]>='0' && s[ 0]<='9'
991                          &&  s[ 1]>='0' && s[ 1]<='9'
992                          &&  s[ 2]==':'
993                          &&  s[ 3]>='0' && s[ 3]<='9'
994                          &&  s[ 4]>='0' && s[ 4]<='9'
995                          &&  s[ 5]==':'
996                          &&  s[ 6]>='0' && s[ 6]<='9'
997                          &&  s[ 7]>='0' && s[ 7]<='9'
998                          &&  s[ 8]=='.')
999                         {
1000                             bool IsNok=false;
1001                             size_t s_size=s.size();
1002                             for (size_t i=9; i<s_size; i++)
1003                                 if (s[i]<'0' || s[i]>'9')
1004                                     IsNok=true;
1005                             if (!IsNok)
1006                             {
1007                                 float64 d=(s[ 0]-'0')*10*60*60
1008                                         + (s[ 1]-'0')   *60*60
1009                                         + (s[ 3]-'0')   *10*60
1010                                         + (s[ 4]-'0')      *60
1011                                         + (s[ 6]-'0')      *10
1012                                         + (s[ 7]-'0')         ;
1013                                 for (size_t i=9; i<s_size; i++)
1014                                     d+=(s[i]-'0')/std::pow(10.0, double(i)-8);
1015                                 Fill(StreamKind_Last, StreamPos_Last, "Duration", d*1000, s.size()-12);
1016                                 continue;
1017                             }
1018                         }
1019                     }
1020                     if ((Tag->first!=__T("Language") || Retrieve(StreamKind_Last, StreamPos_Last, "Language").empty())) // Prioritize Tracks block over tags
1021                         Fill(StreamKind_Last, StreamPos_Last, Tag->first.To_UTF8().c_str(), Tag->second);
1022                 }
1023             }
1024         }
1025 
1026         if (Temp->second.DisplayAspectRatio!=0)
1027         {
1028             //Corrections
1029             if (Temp->second.DisplayAspectRatio>=1.777 && Temp->second.DisplayAspectRatio<=1.778)
1030                 Temp->second.DisplayAspectRatio=((float32)16)/9;
1031             if (Temp->second.DisplayAspectRatio>=1.333 && Temp->second.DisplayAspectRatio<=1.334)
1032                 Temp->second.DisplayAspectRatio=((float32)4)/3;
1033             Fill(Stream_Video, StreamPos_Last, Video_DisplayAspectRatio, Temp->second.DisplayAspectRatio, 3, true);
1034             int64u Width=Retrieve(Stream_Video, StreamPos_Last, Video_Width).To_int64u();
1035             int64u Height=Retrieve(Stream_Video, StreamPos_Last, Video_Height).To_int64u();
1036             if (Width)
1037                 Fill(Stream_Video, StreamPos_Last, Video_PixelAspectRatio, Temp->second.DisplayAspectRatio*Height/Width, 3, true);
1038         }
1039 
1040         if (Temp->second.Parser)
1041         {
1042             Fill(Temp->second.Parser);
1043             if (Config->ParseSpeed<=1.0)
1044                 Temp->second.Parser->Open_Buffer_Unsynch();
1045         }
1046 
1047         //Video specific
1048         if (StreamKind_Last==Stream_Video)
1049         {
1050             //FrameRate
1051             bool IsVfr=false;
1052             bool RelyOnParser=false;
1053             if (Temp->second.Segment_Cluster_BlockGroup_BlockDuration_Counts.size()>2)
1054                 IsVfr=true;
1055             else if (Temp->second.TimeCodes.size()>1)
1056             {
1057                 //Trying to detect VFR
1058                 std::vector<int64s> FrameRate_Between;
1059                 std::sort(Temp->second.TimeCodes.begin(), Temp->second.TimeCodes.end()); //This is PTS, no DTS --> Some frames are out of order
1060                 size_t FramesToAdd=0;
1061                 for (size_t Pos=1; Pos<Temp->second.TimeCodes.size(); Pos++)
1062                 {
1063                     int64u Duration=Temp->second.TimeCodes[Pos]-Temp->second.TimeCodes[Pos-1];
1064                     if (Duration)
1065                         FrameRate_Between.push_back(Duration);
1066                     else
1067                         FramesToAdd++;
1068                 }
1069                 if (FrameRate_Between.size()>=60+32) //Minimal 1 seconds (@60 fps)
1070                     FrameRate_Between.resize(FrameRate_Between.size()-16); //We remove the last ones, because this is PTS, no DTS --> Some frames are out of order
1071                 std::sort(FrameRate_Between.begin(), FrameRate_Between.end());
1072                 if (FrameRate_Between.size()>2)
1073                 {
1074                     //Looking for 3 consecutive same values, in order to remove some missing frames from stats
1075                     size_t i=FrameRate_Between.size()-1;
1076                     int64s Previous = FrameRate_Between[i];
1077                     do
1078                     {
1079                         i--;
1080                         if (FrameRate_Between[i]==Previous && FrameRate_Between[i-1]==Previous)
1081                             break;
1082                         Previous=FrameRate_Between[i];
1083                     }
1084                     while (i>2);
1085                     if (i>FrameRate_Between.size()/2)
1086                         FrameRate_Between.resize(i+2);
1087                 }
1088 
1089                 if (FrameRate_Between.size()>=40)
1090                     FrameRate_Between.resize(FrameRate_Between.size()-FrameRate_Between.size()/10); //We remove the last ones, in order to ignore skipped frames (bug of the muxer?)
1091                 else if (FrameRate_Between.size()>=7)
1092                     FrameRate_Between.resize(FrameRate_Between.size()-4); //We remove the last ones, in order to ignore skipped frames (bug of the muxer?)
1093                 if (FrameRate_Between.size()>2
1094                  && FrameRate_Between[0]*0.9<FrameRate_Between[FrameRate_Between.size()-1]
1095                  && FrameRate_Between[0]*1.1>FrameRate_Between[FrameRate_Between.size()-1]
1096                  && TimecodeScale)
1097                 {
1098                     float Time=0;
1099                     for (size_t i=0; i<FrameRate_Between.size(); i++)
1100                         Time += FrameRate_Between[i];
1101                     Time /= FrameRate_Between.size();
1102 
1103                     if (Temp->second.TrackDefaultDuration && Time>=Temp->second.TrackDefaultDuration/TimecodeScale*0.95 && Time<=Temp->second.TrackDefaultDuration/TimecodeScale*1.05)
1104                         Time=(float)Temp->second.TrackDefaultDuration/TimecodeScale; //TrackDefaultDuration is maybe more precise than the time code
1105 
1106                     if (Time)
1107                     {
1108                         float32 FrameRate_FromCluster=1000000000/Time/TimecodeScale;
1109                         if (Temp->second.Parser)
1110                         {
1111                             float32 FrameRate_FromParser=Temp->second.Parser->Retrieve(Stream_Video, StreamPos_Last, Video_FrameRate).To_float32();
1112                             if (FrameRate_FromParser
1113                              && FrameRate_FromParser*2>FrameRate_FromCluster*0.9
1114                              && FrameRate_FromParser*2<FrameRate_FromCluster*1.1) //TODO: awfull method to detect interlaced content with one field per block
1115                                 FrameRate_FromCluster/=2;
1116                             if (FrameRate_FromParser
1117                              && FrameRate_FromParser>FrameRate_FromCluster*0.99
1118                              && FrameRate_FromParser<FrameRate_FromCluster*1.01)
1119                                 RelyOnParser=true; //Disabling frame rate guess, relying on parser precision
1120                         }
1121                         if (FrameRate_FromTags)
1122                         {
1123                                 if (FrameRate_FromCluster < FrameRate_FromTags - (FrameRate_FromTags*(TimecodeScale*0.0000000010021)) || FrameRate_FromCluster > FrameRate_FromTags + (FrameRate_FromTags*(TimecodeScale*0.0000000010021)))
1124                                     IsVfr=true;
1125                         }
1126                         else if (!RelyOnParser)
1127                             Fill(Stream_Video, StreamPos_Last, Video_FrameRate, FrameRate_FromCluster);
1128                     }
1129                 }
1130                 else if (FrameRate_Between.size()>2)
1131                     IsVfr=true;
1132             }
1133 
1134             // In case there are not enough frames for computing frame rate, trying to rely on TrackDefaultDuration as a fallback
1135             if (!IsVfr && !RelyOnParser && Retrieve(Stream_Video, StreamPos_Last, Video_FrameRate).empty() && Temp->second.TrackDefaultDuration
1136              && Temp->second.TrackDefaultDuration!=32999999 // Seen in some 30 fps stream, not the one for all frames
1137              && Temp->second.TrackDefaultDuration!=41999998 // Seen in some 24 fps stream, not the one for all frames
1138              && Temp->second.TrackDefaultDuration!=41999999 // Seen in some 24 fps stream, not the one for all frames
1139                 )
1140             {
1141                 float32 FrameRate_FromCluster=1000000000/(float32)Temp->second.TrackDefaultDuration;
1142                 if (Retrieve(Stream_Video, StreamPos_Last, Video_FrameRate).empty())
1143                     Fill(Stream_Video, StreamPos_Last, Video_FrameRate, FrameRate_FromCluster);
1144             }
1145 
1146             Fill(Stream_Video, StreamPos_Last, Video_FrameRate_Mode, IsVfr?"VFR":"CFR");
1147 
1148             //MasteringDisplay
1149             Ztring MasteringDisplay_ColorPrimaries, MasteringDisplay_Luminance;
1150             Get_MasteringDisplayColorVolume(MasteringDisplay_ColorPrimaries, MasteringDisplay_Luminance, Temp->second.MasteringMetadata);
1151             if (!MasteringDisplay_ColorPrimaries.empty() || !MasteringDisplay_Luminance.empty())
1152             {
1153                 Fill(StreamKind_Last, StreamPos_Last, "HDR_Format", "SMPTE ST 2086");
1154                 Fill(StreamKind_Last, StreamPos_Last, "HDR_Format_Compatibility", "HDR10");
1155                 Fill(StreamKind_Last, StreamPos_Last, "MasteringDisplay_ColorPrimaries", MasteringDisplay_ColorPrimaries);
1156                 Fill(StreamKind_Last, StreamPos_Last, "MasteringDisplay_Luminance", MasteringDisplay_Luminance);
1157             }
1158         }
1159 
1160         if (Temp->second.Parser)
1161         {
1162             //Delay
1163             if (Temp->second.TimeCode_Start!=(int64u)-1 && TimecodeScale)
1164             {
1165                 //From TimeCode
1166                 float64 Delay=Temp->second.TimeCode_Start*int64u_float64(TimecodeScale)/1000000.0;
1167 
1168                 //From stream format
1169                 if (StreamKind_Last==Stream_Audio && Count_Get(Stream_Video)==1 && Temp->second.Parser->Count_Get(Stream_General)>0)
1170                 {
1171                          if (Temp->second.Parser->Buffer_TotalBytes_FirstSynched==0)
1172                         ;
1173                     else if (Temp->second.AvgBytesPerSec!=0)
1174                         Delay+=((float64)Temp->second.Parser->Buffer_TotalBytes_FirstSynched)*1000/Temp->second.AvgBytesPerSec;
1175                     else
1176                     {
1177                         int64u BitRate = Temp->second.Parser->Retrieve(Stream_Audio, 0, Audio_BitRate).To_int64u();
1178                         if (BitRate == 0)
1179                             BitRate = Temp->second.Parser->Retrieve(Stream_Audio, 0, Audio_BitRate_Nominal).To_int64u();
1180                         if (BitRate)
1181                             Delay += ((float64)Temp->second.Parser->Buffer_TotalBytes_FirstSynched) * 1000 / BitRate;
1182                     }
1183                 }
1184 
1185                 //Filling
1186                 Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Delay), Delay, 0, true);
1187                 Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Delay_Source), "Container");
1188 
1189                 const Ztring &DurationS=Retrieve(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Duration));
1190                 float64 Duration=DurationS.To_float64();
1191                 if (!HasStats && Duration && Duration>=Delay) //Not sure about when tats are present, so for the moment we remove delay from duration only if there is no stats, Duration looks like more lie timestamp of the end of the last frame with the example we got
1192                 {
1193                     Duration-=Delay;
1194                     size_t DotPos=DurationS.find(__T('.'));
1195                     if (DotPos == (size_t)-1)
1196                         DotPos = DurationS.size();
1197                     else
1198                         DotPos++;
1199                     Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Duration), Duration, DurationS.size()-DotPos, true);
1200                 }
1201             }
1202 
1203             Ztring Codec_Temp=Retrieve(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Codec)); //We want to keep the 4CC;
1204             //if (Duration_Temp.empty()) Duration_Temp=Retrieve(StreamKind_Last, Temp->second.StreamPos, Fill_Parameter(StreamKind_Last, Generic_Duration)); //Duration from stream is sometimes false
1205             //else Duration_Temp.clear();
1206 
1207             #ifdef MEDIAINFO_PCM_YES
1208                 if (Temp->second.Parser && Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("PCM"))
1209                 {
1210                     Temp->second.Parser->Accept();
1211                     Temp->second.Parser->Fill(); // No need of any content for filling, so filling it even if very quick pass
1212                 }
1213             #endif //MEDIAINFO_PCM_YES
1214             Finish(Temp->second.Parser);
1215             Merge(*Temp->second.Parser, StreamKind_Last, 0, StreamPos_Last);
1216             //if (!Duration_Temp.empty()) Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Duration), Duration_Temp, true);
1217             if (Temp->second.StreamKind==Stream_Video && !Codec_Temp.empty())
1218                 Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Codec), Codec_Temp, true);
1219 
1220 
1221             //Format specific
1222             #if defined(MEDIAINFO_DVDIF_YES)
1223                 if (StreamKind_Last==Stream_Video && Retrieve(Stream_Video, StreamPos_Last, Video_Format)==__T("DV"))
1224                 {
1225                     if (Retrieve(Stream_General, 0, General_Recorded_Date).empty())
1226                         Fill(Stream_General, 0, General_Recorded_Date, Temp->second.Parser->Retrieve(Stream_General, 0, General_Recorded_Date));
1227 
1228                     //Video and Audio are together
1229                     size_t Audio_Count=Temp->second.Parser->Count_Get(Stream_Audio);
1230                     for (size_t Audio_Pos=0; Audio_Pos<Audio_Count; Audio_Pos++)
1231                     {
1232                         Fill_Flush();
1233                         Stream_Prepare(Stream_Audio); // TODO: merge code with the one from RIFF/AVI parser and put this audio streams in the ID order instead of after pure Matroska audio streams
1234                         size_t Pos=Count_Get(Stream_Audio)-1;
1235                         Merge(*Temp->second.Parser, Stream_Audio, Audio_Pos, StreamPos_Last);
1236                         Fill(Stream_Audio, Pos, Audio_MuxingMode, "DV");
1237                         Fill(Stream_Audio, Pos, Audio_Duration, Retrieve(Stream_Video, Temp->second.StreamPos, Video_Duration));
1238                         Fill(Stream_Audio, Pos, "MuxingMode_MoreInfo", __T("Muxed in Video #")+Ztring().From_Number(Temp->second.StreamPos+1));
1239                         Fill(Stream_Audio, Pos, Audio_StreamSize_Encoded, 0); //Included in the DV stream size
1240                         Ztring ID=Retrieve(Stream_Audio, Pos, Audio_ID);
1241                         Fill(Stream_Audio, Pos, Audio_ID, Retrieve(Stream_Video, Temp->second.StreamPos, Video_ID)+__T("-")+ID, true);
1242                     }
1243 
1244                     StreamKind_Last=Stream_Video;
1245                     StreamPos_Last=Temp->second.StreamPos;
1246                 }
1247             #endif
1248 
1249             //Special case: AAC
1250             if (StreamKind_Last==Stream_Audio
1251              && (Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("AAC")
1252               || Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("MPEG Audio")
1253               || Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("Vorbis")))
1254                 Clear(Stream_Audio, StreamPos_Last, Audio_BitDepth); //Resolution is not valid for AAC / MPEG Audio / Vorbis
1255 
1256             //Special case: 5.1
1257             if (StreamKind_Last==Stream_Audio
1258              && (Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("AC-3")
1259               || Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("E-AC-3")
1260               || Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("DTS"))
1261              && Retrieve(Stream_Audio, StreamPos_Last, Audio_Channel_s__Original)==__T("6")
1262              && Retrieve(Stream_Audio, StreamPos_Last, Audio_Channel_s_)==__T("5"))
1263             {
1264                 Clear(Stream_Audio, StreamPos_Last, Audio_Channel_s__Original);
1265                 Fill(Stream_Audio, StreamPos_Last, Audio_Channel_s_, 6, 10, true); //Some muxers do not count LFE in the channel count, let's say it is normal
1266             }
1267 
1268             //VFR
1269             if (Retrieve(Stream_Video, StreamPos_Last, Video_FrameRate_Mode)==__T("VFR") && Retrieve(Stream_Video, StreamPos_Last, Video_FrameRate_Original).empty())
1270             {
1271                 Fill(Stream_Video, StreamPos_Last, Video_FrameRate_Original, Retrieve(Stream_Video, StreamPos_Last, Video_FrameRate));
1272                 Clear(Stream_Video, StreamPos_Last, Video_FrameRate);
1273             }
1274 
1275             //Crop
1276             if (Temp->second.PixelCropLeft || Temp->second.PixelCropRight)
1277             {
1278                 Fill(Stream_Video, StreamPos_Last, Video_Width_Original, Retrieve(Stream_Video, StreamPos_Last, Video_Width), true);
1279                 Fill(Stream_Video, StreamPos_Last, Video_Width, Retrieve(Stream_Video, StreamPos_Last, Video_Width).To_int64u()-Temp->second.PixelCropLeft-Temp->second.PixelCropRight, 10, true);
1280                 Fill(Stream_Video, StreamPos_Last, Video_Width_Offset, Temp->second.PixelCropLeft, 10, true);
1281             }
1282             if (Temp->second.PixelCropTop || Temp->second.PixelCropBottom)
1283             {
1284                 Fill(Stream_Video, StreamPos_Last, Video_Height_Original, Retrieve(Stream_Video, StreamPos_Last, Video_Height), true);
1285                 Fill(Stream_Video, StreamPos_Last, Video_Height, Retrieve(Stream_Video, StreamPos_Last, Video_Height).To_int64u()-Temp->second.PixelCropTop-Temp->second.PixelCropBottom, 10, true);
1286                 Fill(Stream_Video, StreamPos_Last, Video_Height_Offset, Temp->second.PixelCropTop, 10, true);
1287             }
1288         }
1289 
1290         if (Temp->second.FrameRate!=0 && Retrieve(Stream_Video, StreamPos_Last, Video_FrameRate).empty())
1291             Fill(Stream_Video, StreamPos_Last, Video_FrameRate, Temp->second.FrameRate, 3);
1292 
1293         //Flags
1294         Fill(StreamKind_Last, StreamPos_Last, "Default", Temp->second.Default?"Yes":"No");
1295         Fill(StreamKind_Last, StreamPos_Last, "Forced", Temp->second.Forced?"Yes":"No");
1296     }
1297 
1298     //Chapters
1299     if (TimecodeScale)
1300     {
1301         for (EditionEntries_Pos=0; EditionEntries_Pos<EditionEntries.size(); EditionEntries_Pos++)
1302         {
1303             Stream_Prepare(Stream_Menu);
1304             Fill(Stream_Menu, StreamPos_Last, Menu_Chapters_Pos_Begin, Count_Get(Stream_Menu, StreamPos_Last), 10, true);
1305             for (ChapterAtoms_Pos=0; ChapterAtoms_Pos<EditionEntries[EditionEntries_Pos].ChapterAtoms.size(); ChapterAtoms_Pos++)
1306             {
1307                 if (EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterTimeStart!=(int64u)-1)
1308                 {
1309                     Ztring Text;
1310                     for (ChapterDisplays_Pos=0; ChapterDisplays_Pos<EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays.size(); ChapterDisplays_Pos++)
1311                     {
1312                         Ztring PerLanguage;
1313                         if (!EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays[ChapterDisplays_Pos].ChapLanguage.empty())
1314                             PerLanguage=MediaInfoLib::Config.Iso639_1_Get(EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays[ChapterDisplays_Pos].ChapLanguage)+__T(':');
1315                         PerLanguage+=EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays[ChapterDisplays_Pos].ChapString;
1316                         Text+=PerLanguage+__T(" - ");
1317                     }
1318                     Ztring Time=Ztring().Duration_From_Milliseconds(EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterTimeStart/1000000).To_UTF8().c_str();
1319                     if (Text.size())
1320                         Text.resize(Text.size()-3);
1321                     else
1322                         Text = Time;
1323                     Fill(Stream_Menu, StreamPos_Last, Time.To_UTF8().c_str(), Text);
1324                 }
1325             }
1326             Fill(Stream_Menu, StreamPos_Last, Menu_Chapters_Pos_End, Count_Get(Stream_Menu, StreamPos_Last), 10, true);
1327         }
1328     }
1329 
1330     //Purge what is not needed anymore
1331     if (!File_Name.empty()) //Only if this is not a buffer, with buffer we can have more data
1332         Stream.clear();
1333 }
1334 
1335 //***************************************************************************
1336 // Buffer - Global
1337 //***************************************************************************
1338 
1339 //---------------------------------------------------------------------------
Read_Buffer_Unsynched()1340 void File_Mk::Read_Buffer_Unsynched()
1341 {
1342     Laces_Pos=0;
1343     Laces.clear();
1344     if (!File_GoTo)
1345         Element_Level=0;
1346 
1347     for (std::map<int64u, stream>::iterator streamItem=Stream.begin(); streamItem!=Stream.end(); streamItem++)
1348     {
1349         if (!File_GoTo)
1350             streamItem->second.PacketCount=0;
1351         if (streamItem->second.Parser)
1352             streamItem->second.Parser->Open_Buffer_Unsynch();
1353     }
1354 }
1355 
1356 //---------------------------------------------------------------------------
1357 #if MEDIAINFO_SEEK
Read_Buffer_Seek(size_t Method,int64u Value,int64u ID)1358 size_t File_Mk::Read_Buffer_Seek(size_t Method, int64u Value, int64u ID)
1359 {
1360     //Currently stupidely go back to 0 //TODO:
1361     GoTo(Buffer_TotalBytes_FirstSynched);
1362     Open_Buffer_Unsynch();
1363     return 1;
1364 }
1365 #endif //MEDIAINFO_SEEK
1366 
1367 //***************************************************************************
1368 // Buffer - Synchro
1369 //***************************************************************************
1370 
1371 //---------------------------------------------------------------------------
Synchronize()1372 bool File_Mk::Synchronize()
1373 {
1374     //Synchronizing
1375     while (Buffer_Offset+4<=Buffer_Size && (Buffer[Buffer_Offset  ]!=0x1A
1376                                          || Buffer[Buffer_Offset+1]!=0x45
1377                                          || Buffer[Buffer_Offset+2]!=0xDF
1378                                          || Buffer[Buffer_Offset+3]!=0xA3))
1379     {
1380         Buffer_Offset++;
1381         while (Buffer_Offset<Buffer_Size && Buffer[Buffer_Offset]!=0x1A)
1382             Buffer_Offset++;
1383     }
1384 
1385     //Parsing last bytes if needed
1386     if (Buffer_Offset+4>Buffer_Size)
1387     {
1388         if (Buffer_Offset+3==Buffer_Size && CC3(Buffer+Buffer_Offset)!=0x1A45DF)
1389             Buffer_Offset++;
1390         if (Buffer_Offset+2==Buffer_Size && CC2(Buffer+Buffer_Offset)!=0x1A45)
1391             Buffer_Offset++;
1392         if (Buffer_Offset+1==Buffer_Size && CC1(Buffer+Buffer_Offset)!=0x1A)
1393             Buffer_Offset++;
1394         return false;
1395     }
1396 
1397     //Synched is OK
1398     MustSynchronize=false; //We need synchro only once (at the beginning, in case of junk bytes before EBML)
1399     return true;
1400 }
1401 
1402 //***************************************************************************
1403 // Buffer - Global
1404 //***************************************************************************
1405 
1406 //---------------------------------------------------------------------------
Read_Buffer_Continue()1407 void File_Mk::Read_Buffer_Continue()
1408 {
1409     //Handling CRC32 computing when there is no need of the data (data not parsed, only needed for CRC32)
1410     if (CRC32Compute_SkipUpTo>File_Offset)
1411     {
1412         int64u Size=CRC32Compute_SkipUpTo-File_Offset;
1413         if (Element_Size>Size)
1414             Element_Size=Size;
1415         Element_Offset=Element_Size;
1416         CRC32_Check();
1417     }
1418 }
1419 
1420 //***************************************************************************
1421 // Buffer
1422 //***************************************************************************
1423 
1424 //---------------------------------------------------------------------------
Header_Begin()1425 bool File_Mk::Header_Begin()
1426 {
1427     #if MEDIAINFO_DEMUX
1428         //Handling of multiple frames in one block
1429         if (Config->Demux_Unpacketize_Get() && Demux_EventWasSent!=(int64u)-1)
1430         {
1431             stream &Stream_Temp=Stream[Demux_EventWasSent];
1432             Frame_Count_NotParsedIncluded=Stream_Temp.Parser->Frame_Count_NotParsedIncluded;
1433             FrameInfo.PTS=Stream_Temp.Parser->FrameInfo.PTS;
1434             Open_Buffer_Continue(Stream_Temp.Parser, Buffer + Buffer_Offset, 0);
1435             if (Config->Demux_EventWasSent)
1436                 return false;
1437             Demux_EventWasSent=(int64u)-1;
1438         }
1439     #endif //MEDIAINFO_DEMUX
1440 
1441     #if MEDIAINFO_TRACE
1442         if (Trace_Activated_Save && Element_Level==0)
1443         {
1444             Trace_Activated=true;
1445             Trace_Activated_Save=false;
1446         }
1447     #endif //MEDIAINFO_TRACE
1448 
1449     return true;
1450 }
1451 
1452 //---------------------------------------------------------------------------
Header_Parse()1453 void File_Mk::Header_Parse()
1454 {
1455     //Handling of laces
1456     if (!Laces.empty())
1457     {
1458         Header_Fill_Code(Elements::Segment_Cluster_BlockGroup_Block_Lace, "Data");
1459         Header_Fill_Size(Laces[Laces_Pos]);
1460         return;
1461     }
1462 
1463     //Test of zero padding
1464     int8u Null;
1465     Peek_B1(Null);
1466     if (Null<=InvalidByteMax)
1467     {
1468         if (Buffer_Offset_Temp==0)
1469             Buffer_Offset_Temp=Buffer_Offset+1;
1470 
1471         while (Buffer_Offset_Temp<Buffer_Size)
1472         {
1473             if (Buffer[Buffer_Offset_Temp]>InvalidByteMax)
1474                 break;
1475             Buffer_Offset_Temp++;
1476         }
1477         if (Buffer_Offset_Temp>=Buffer_Size)
1478         {
1479             Element_WaitForMoreData();
1480             return;
1481         }
1482 
1483         Header_Fill_Code((int32u)-1); //Should be (int64u)-1 but Borland C++ does not like this
1484         Header_Fill_Size(Buffer_Offset_Temp-Buffer_Offset);
1485         Buffer_Offset_Temp=0;
1486 
1487         return;
1488     }
1489 
1490     //Parsing
1491     int64u Name = 0, Size = 0;
1492     bool NameIsValid=true;
1493     if (Element_Offset+1<Element_Size)
1494     {
1495         int8u NamePeek;
1496         Peek_B1(NamePeek);
1497         if (NamePeek<0x10)
1498         {
1499             Skip_B1(                                            "Invalid");
1500             #if MEDIAINFO_TRACE
1501             Element_Level--;
1502             Element_Info("NOK");
1503             Element_Level++;
1504             #endif //MEDIAINFO_TRACE
1505             NameIsValid=false;
1506 
1507             Header_Fill_Code(0, "Junk");
1508             Header_Fill_Size(1);
1509         }
1510     }
1511     if (NameIsValid)
1512     {
1513     Get_EB (Name,                                               "Name");
1514     Get_EB (Size,                                               "Size");
1515 
1516     //Detection of 0-sized Segment expected to be -1-sized (unlimited)
1517     if (Name==Elements::Segment && Size==0)
1518     {
1519         Param_Info1("Incoherent, changed to unlimited");
1520         Size=0xFFFFFFFFFFFFFFLL; //Unlimited
1521         Fill(Stream_General, 0, "SegmentSizeIsZero", "Yes");
1522 
1523         #if MEDIAINFO_FIXITY
1524             if (Config->TryToFix_Get())
1525             {
1526                 size_t Pos=(size_t)(Element_Offset-1);
1527                 while (!Buffer[Buffer_Offset+Pos])
1528                     Pos--;
1529                 size_t ToWrite_Size=Element_Offset-Pos;
1530                 if (ToWrite_Size<=8)
1531                 {
1532                     int8u ToWrite[8];
1533                     int64u2BigEndian(ToWrite, ((int64u)-1)>>(ToWrite_Size-1));
1534                     FixFile(File_Offset+Buffer_Offset+Pos, ToWrite, ToWrite_Size)?Param_Info1("Fixed"):Param_Info1("Not fixed");
1535                 }
1536             }
1537         #endif //MEDIAINFO_FIXITY
1538     }
1539 
1540     //Filling
1541     Header_Fill_Code(Name, Ztring().From_Number(Name, 16));
1542     Header_Fill_Size(Element_Offset+Size);
1543     }
1544 
1545     if ((Name==Elements::Segment_Cluster_BlockGroup_Block || Name==Elements::Segment_Cluster_SimpleBlock) && Buffer_Offset+Element_Offset+Size>Buffer_Size && File_Buffer_Size_Hint_Pointer)
1546     {
1547         int64u Buffer_Size_Target = (size_t)(Buffer_Offset + Element_Offset + Size - Buffer_Size + Element_Offset); //+Element_Offset for next packet header
1548 
1549         if (Buffer_Size_Target<128 * 1024)
1550             Buffer_Size_Target = 128 * 1024;
1551         (*File_Buffer_Size_Hint_Pointer) = (size_t)Buffer_Size_Target;
1552 
1553         Element_WaitForMoreData();
1554         return;
1555     }
1556 
1557     //Incoherencies
1558     if (Element_Offset+Size>Element_TotalSize_Get())
1559     {
1560         Param_Error("TRUNCATED-ELEMENT:1");
1561         if (Element_Level<=2)
1562             Fill(Stream_General, 0, "IsTruncated", "Yes");
1563     }
1564 
1565     //Should we parse Cluster?
1566     if (Element_Level==3 && Name==Elements::Segment_Cluster && !Segment_Tracks_Count)
1567     {
1568         //Jumping
1569         for (size_t Pos=0; Pos<Segment_Seeks.size(); Pos++)
1570             if (Segment_Seeks[Pos].SeekID==Elements::Segment_Tracks)
1571             {
1572                 Fill(Stream_General, 0, General_IsStreamable, "No");
1573                 Element_DoNotShow();
1574                 IsParsingSegmentTrack_SeekBackTo=File_Offset+Buffer_Offset;
1575 
1576                 JumpTo(Segment_Seeks[Pos].SeekPosition);
1577                 break;
1578             }
1579         if (File_GoTo==(int64u)-1)
1580             JumpTo(Segment_Offset_End);
1581         return;
1582     }
1583 
1584     //Is Tracks already parsed?
1585     if (Element_Level==3 && Name==Elements::Segment_Tracks && SegmentTrack_Offset_End==File_Offset+Buffer_Offset+Element_Offset+Size)
1586     {
1587         //This element was already parsed, skipping it
1588         JumpTo(SegmentTrack_Offset_End);
1589         Element_DoNotShow();
1590         SegmentTrack_Offset_End=0;
1591         return;
1592     }
1593 }
1594 
1595 //---------------------------------------------------------------------------
Data_Parse()1596 void File_Mk::Data_Parse()
1597 {
1598     #define LIS2(_ATOM, _NAME) \
1599         case Elements::_ATOM : \
1600                 if (Level==Element_Level) \
1601                 { \
1602                     Element_Name(_NAME); \
1603                     _ATOM(); \
1604                     Element_ThisIsAList(); \
1605                 } \
1606 
1607     #define ATO2(_ATOM, _NAME) \
1608                 case Elements::_ATOM : \
1609                         if (Level==Element_Level) \
1610                         { \
1611                             if (Element_IsComplete_Get()) \
1612                             { \
1613                                 Element_Name(_NAME); \
1614                                 _ATOM(); \
1615                             } \
1616                             else \
1617                             { \
1618                                 Element_WaitForMoreData(); \
1619                                 return; \
1620                             } \
1621                         } \
1622                         break; \
1623 
1624     #define ATOM_END_MK \
1625         ATOM(Zero) \
1626         ATOM(CRC32) \
1627         ATOM(Void) \
1628         ATOM_END
1629 
1630     //Parsing
1631     DATA_BEGIN
1632     LIS2(Ebml, "EBML")
1633         ATOM_BEGIN
1634         ATO2(Ebml_Version, "EBMLVersion")
1635         ATO2(Ebml_ReadVersion, "EBMLReadVersion")
1636         ATO2(Ebml_MaxIDLength, "EBMLMaxIDLength")
1637         ATO2(Ebml_MaxSizeLength, "EBMLMaxSizeLength")
1638         ATO2(Ebml_DocType, "DocType")
1639         ATO2(Ebml_DocTypeVersion, "DocTypeVersion")
1640         ATO2(Ebml_DocTypeReadVersion, "DocTypeReadVersion")
1641         ATOM_END_MK
1642 #if MEDIAINFO_TRACE
1643     LIS2(RawcookedBlock, "RawcookedBlock")
1644         ATOM_BEGIN
1645         ATO2(RawcookedBlock_AfterData, "AfterData")
1646         ATO2(RawcookedBlock_BeforeData, "BeforeData")
1647         ATO2(RawcookedBlock_FileName, "FileName")
1648         ATO2(RawcookedBlock_FileHash, "FileHash")
1649         ATO2(RawcookedBlock_MaskAdditionBeforeData, "MaskAdditionBeforeData")
1650         ATO2(RawcookedBlock_MaskAdditionAfterData, "MaskAdditionAfterData")
1651         ATO2(RawcookedBlock_MaskAdditionFileName, "MaskAdditionFileName")
1652         ATOM_END_MK
1653     LIS2(RawcookedSegment, "RawcookedSegment")
1654         ATOM_BEGIN
1655         ATO2(RawcookedSegment_LibraryName, "LibraryName")
1656         ATO2(RawcookedSegment_LibraryVersion, "LibraryVersion")
1657         ATOM_END_MK
1658     LIS2(RawcookedTrack, "RawcookedTrack")
1659         ATOM_BEGIN
1660         ATO2(RawcookedTrack_BeforeData, "BeforeData")
1661         ATO2(RawcookedTrack_AfterData, "AfterData")
1662         ATO2(RawcookedTrack_FileName, "FileName")
1663         ATO2(RawcookedTrack_FileHash, "FileHash")
1664         ATO2(RawcookedTrack_MaskBaseAfterData, "MaskBaseAfterData")
1665         ATO2(RawcookedTrack_MaskBaseBeforeData, "MaskBaseBeforeData")
1666         ATO2(RawcookedTrack_MaskBaseFileName, "MaskBaseFileName")
1667         ATOM_END_MK
1668 #endif //MEDIAINFO_TRACE
1669     LIS2(Segment, "Segment")
1670         ATOM_BEGIN
1671         LIS2(Segment_SeekHead, "SeekHead")
1672             ATOM_BEGIN
1673             LIS2(Segment_SeekHead_Seek, "Seek")
1674                 ATOM_BEGIN
1675                 ATO2(Segment_SeekHead_Seek_SeekID, "SeekID")
1676                 ATO2(Segment_SeekHead_Seek_SeekPosition, "SeekPosition")
1677                 ATOM_END_MK
1678             ATOM_END_MK
1679         LIS2(Segment_Info, "Info")
1680             ATOM_BEGIN
1681             ATO2(Segment_Info_SegmentUID, "SegmentUID")
1682             ATO2(Segment_Info_SegmentFilename, "SegmentFilename")
1683             ATO2(Segment_Info_PrevUID, "PrevUID")
1684             ATO2(Segment_Info_PrevFilename, "PrevFilename")
1685             ATO2(Segment_Info_NextUID, "NextUID")
1686             ATO2(Segment_Info_NextFilename, "NextFilename")
1687             ATO2(Segment_Info_SegmentFamily, "SegmentFamily")
1688             LIS2(Segment_Info_ChapterTranslate, "ChapterTranslate")
1689                 ATOM_BEGIN
1690                 ATO2(Segment_Info_ChapterTranslate_ChapterTranslateEditionUID, "ChapterTranslateEditionUID")
1691                 ATO2(Segment_Info_ChapterTranslate_ChapterTranslateCodec, "ChapterTranslateCodec")
1692                 ATO2(Segment_Info_ChapterTranslate_ChapterTranslateID, "ChapterTranslateID")
1693                 ATOM_END_MK
1694             ATO2(Segment_Info_TimecodeScale, "TimecodeScale")
1695             ATO2(Segment_Info_Duration, "Duration")
1696             ATO2(Segment_Info_DateUTC, "DateUTC")
1697             ATO2(Segment_Info_Title, "Title")
1698             ATO2(Segment_Info_MuxingApp, "MuxingApp")
1699             ATO2(Segment_Info_WritingApp, "WritingApp")
1700             ATOM_END_MK
1701         LIS2(Segment_Cluster, "Cluster")
1702             ATOM_BEGIN
1703             ATO2(Segment_Cluster_Timecode, "Timecode")
1704             LIS2(Segment_Cluster_SilentTracks, "SilentTracks")
1705                 ATOM_BEGIN
1706                 ATO2(Segment_Cluster_SilentTracks_SilentTrackNumber, "SilentTrackNumber")
1707                 ATOM_END_MK
1708             ATO2(Segment_Cluster_Position, "Position")
1709             ATO2(Segment_Cluster_PrevSize, "PrevSize")
1710             LIS2(Segment_Cluster_SimpleBlock, "SimpleBlock")
1711                 ATOM_BEGIN
1712                 ATO2(Segment_Cluster_BlockGroup_Block_Lace, "Lace")
1713                 ATOM_END_MK
1714             LIS2(Segment_Cluster_BlockGroup, "BlockGroup")
1715                 ATOM_BEGIN
1716                 LIS2(Segment_Cluster_BlockGroup_Block, "Block")
1717                     ATOM_BEGIN
1718                     ATO2(Segment_Cluster_BlockGroup_Block_Lace, "Lace")
1719                     ATOM_END_MK
1720                 ATO2(Segment_Cluster_BlockGroup_BlockVirtual, "BlockVirtual")
1721                 LIS2(Segment_Cluster_BlockGroup_BlockAdditions, "BlockAdditions")
1722                     ATOM_BEGIN
1723                     LIS2(Segment_Cluster_BlockGroup_BlockAdditions_BlockMore, "BlockMore")
1724                         ATOM_BEGIN
1725                         ATO2(Segment_Cluster_BlockGroup_BlockAdditions_BlockMore_BlockAddID, "BlockAddID")
1726                         ATO2(Segment_Cluster_BlockGroup_BlockAdditions_BlockMore_BlockAdditional, "BlockAdditional")
1727                         ATOM_END_MK
1728                     ATOM_END_MK
1729                 ATO2(Segment_Cluster_BlockGroup_BlockDuration, "BlockDuration")
1730                 ATO2(Segment_Cluster_BlockGroup_ReferencePriority, "ReferencePriority")
1731                 ATO2(Segment_Cluster_BlockGroup_ReferenceBlock, "ReferenceBlock")
1732                 ATO2(Segment_Cluster_BlockGroup_ReferenceVirtual, "ReferenceVirtual")
1733                 ATO2(Segment_Cluster_BlockGroup_CodecState, "CodecState")
1734                 ATO2(Segment_Cluster_BlockGroup_DiscardPadding, "DiscardPadding")
1735                 LIS2(Segment_Cluster_BlockGroup_Slices, "Slices")
1736                     ATOM_BEGIN
1737                     LIS2(Segment_Cluster_BlockGroup_Slices_TimeSlice, "TimeSlice")
1738                         ATOM_BEGIN
1739                         ATO2(Segment_Cluster_BlockGroup_Slices_TimeSlice_LaceNumber, "LaceNumber")
1740                         ATO2(Segment_Cluster_BlockGroup_Slices_TimeSlice_FrameNumber, "FrameNumber")
1741                         ATO2(Segment_Cluster_BlockGroup_Slices_TimeSlice_BlockAdditionID, "BlockAdditionID")
1742                         ATO2(Segment_Cluster_BlockGroup_Slices_TimeSlice_Delay, "Delay")
1743                         ATO2(Segment_Cluster_BlockGroup_Slices_TimeSlice_SliceDuration, "SliceDuration")
1744                         ATOM_END_MK
1745                     ATOM_END_MK
1746                 LIS2(Segment_Cluster_BlockGroup_ReferenceFrame, "ReferenceFrame")
1747                     ATOM_BEGIN
1748                     ATO2(Segment_Cluster_BlockGroup_ReferenceFrame_ReferenceOffset, "ReferenceOffset")
1749                     ATO2(Segment_Cluster_BlockGroup_ReferenceFrame_ReferenceTimeCode, "ReferenceTimeCode")
1750                     ATOM_END_MK
1751                 ATOM_END_MK
1752             ATO2(Segment_Cluster_EncryptedBlock, "EncryptedBlock")
1753             ATOM_END_MK
1754         LIS2(Segment_Tracks, "Tracks")
1755             ATOM_BEGIN
1756             LIS2(Segment_Tracks_TrackEntry, "TrackEntry")
1757                 ATOM_BEGIN
1758                 ATO2(Segment_Tracks_TrackEntry_TrackNumber, "TrackNumber")
1759                 ATO2(Segment_Tracks_TrackEntry_TrackUID, "TrackUID")
1760                 ATO2(Segment_Tracks_TrackEntry_TrackType, "TrackType")
1761                 ATO2(Segment_Tracks_TrackEntry_FlagEnabled, "FlagEnabled")
1762                 ATO2(Segment_Tracks_TrackEntry_FlagDefault, "FlagDefault")
1763                 ATO2(Segment_Tracks_TrackEntry_FlagForced, "FlagForced")
1764                 ATO2(Segment_Tracks_TrackEntry_FlagLacing, "FlagLacing")
1765                 ATO2(Segment_Tracks_TrackEntry_MinCache, "MinCache")
1766                 ATO2(Segment_Tracks_TrackEntry_MaxCache, "MaxCache")
1767                 ATO2(Segment_Tracks_TrackEntry_DefaultDuration, "DefaultDuration")
1768                 ATO2(Segment_Tracks_TrackEntry_DefaultDecodedFieldDuration, "DefaultDecodedFieldDuration")
1769                 ATO2(Segment_Tracks_TrackEntry_TrackTimecodeScale, "TrackTimecodeScale")
1770                 ATO2(Segment_Tracks_TrackEntry_TrackOffset, "TrackOffset")
1771                 ATO2(Segment_Tracks_TrackEntry_MaxBlockAdditionID, "MaxBlockAdditionID")
1772                 ATO2(Segment_Tracks_TrackEntry_Name, "Name")
1773                 ATO2(Segment_Tracks_TrackEntry_Language, "Language")
1774                 ATO2(Segment_Tracks_TrackEntry_LanguageIETF, "LanguageIETF")
1775                 ATO2(Segment_Tracks_TrackEntry_CodecID, "CodecID")
1776                 ATO2(Segment_Tracks_TrackEntry_CodecPrivate, "CodecPrivate")
1777                 ATO2(Segment_Tracks_TrackEntry_CodecName, "CodecName")
1778                 ATO2(Segment_Tracks_TrackEntry_AttachmentLink, "AttachmentLink")
1779                 ATO2(Segment_Tracks_TrackEntry_CodecSettings, "CodecSettings")
1780                 ATO2(Segment_Tracks_TrackEntry_CodecInfoURL, "CodecInfoURL")
1781                 ATO2(Segment_Tracks_TrackEntry_CodecDownloadURL, "CodecDownloadURL")
1782                 ATO2(Segment_Tracks_TrackEntry_CodecDecodeAll, "CodecDecodeAll")
1783                 ATO2(Segment_Tracks_TrackEntry_TrackOverlay, "TrackOverlay")
1784                 ATO2(Segment_Tracks_TrackEntry_CodecDelay, "CodecDelay")
1785                 ATO2(Segment_Tracks_TrackEntry_SeekPreRoll, "SeekPreRoll")
1786                 LIS2(Segment_Tracks_TrackEntry_TrackTranslate, "TrackTranslate")
1787                     ATOM_BEGIN
1788                     ATO2(Segment_Tracks_TrackEntry_TrackTranslate_TrackTranslateEditionUID, "TrackTranslateEditionUID")
1789                     ATO2(Segment_Tracks_TrackEntry_TrackTranslate_TrackTranslateCodec, "TrackTranslateCodec")
1790                     ATO2(Segment_Tracks_TrackEntry_TrackTranslate_TrackTranslateTrackID, "TrackTranslateTrackID")
1791                     ATOM_END_MK
1792                 LIS2(Segment_Tracks_TrackEntry_Video, "Video")
1793                     ATOM_BEGIN
1794                     ATO2(Segment_Tracks_TrackEntry_Video_FlagInterlaced, "FlagInterlaced")
1795                     ATO2(Segment_Tracks_TrackEntry_Video_FieldOrder, "FieldOrder")
1796                     ATO2(Segment_Tracks_TrackEntry_Video_StereoMode, "StereoMode")
1797                     ATO2(Segment_Tracks_TrackEntry_Video_AlphaMode, "AlphaMode")
1798                     ATO2(Segment_Tracks_TrackEntry_Video_OldStereoMode, "OldStereoMode")
1799                     ATO2(Segment_Tracks_TrackEntry_Video_PixelWidth, "PixelWidth")
1800                     ATO2(Segment_Tracks_TrackEntry_Video_PixelHeight, "PixelHeight")
1801                     ATO2(Segment_Tracks_TrackEntry_Video_PixelCropBottom, "PixelCropBottom")
1802                     ATO2(Segment_Tracks_TrackEntry_Video_PixelCropTop, "PixelCropTop")
1803                     ATO2(Segment_Tracks_TrackEntry_Video_PixelCropLeft, "PixelCropLeft")
1804                     ATO2(Segment_Tracks_TrackEntry_Video_PixelCropRight, "PixelCropRight")
1805                     ATO2(Segment_Tracks_TrackEntry_Video_DisplayWidth, "DisplayWidth")
1806                     ATO2(Segment_Tracks_TrackEntry_Video_DisplayHeight, "DisplayHeight")
1807                     ATO2(Segment_Tracks_TrackEntry_Video_DisplayUnit, "DisplayUnit")
1808                     ATO2(Segment_Tracks_TrackEntry_Video_AspectRatioType, "AspectRatioType")
1809                     ATO2(Segment_Tracks_TrackEntry_Video_ColourSpace, "ColourSpace")
1810                     ATO2(Segment_Tracks_TrackEntry_Video_GammaValue, "GammaValue")
1811                     ATO2(Segment_Tracks_TrackEntry_Video_FrameRate, "FrameRate")
1812                     LIS2(Segment_Tracks_TrackEntry_Video_Colour, "Colour")
1813                         ATOM_BEGIN
1814                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_MatrixCoefficients, "MatrixCoefficients")
1815                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_BitsPerChannel, "BitsPerChannel")
1816                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_ChromaSubsamplingHorz, "ChromaSubsamplingHorz")
1817                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_ChromaSubsamplingVert, "ChromaSubsamplingVert")
1818                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_CbSubsamplingHorz, "CbSubsamplingHorz")
1819                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_CbSubsamplingVert, "CbSubsamplingVert")
1820                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_ChromaSitingHorz, "ChromaSitingHorz")
1821                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_ChromaSitingVert, "ChromaSitingVert")
1822                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_Range, "Range")
1823                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_TransferCharacteristics, "TransferCharacteristics")
1824                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_Primaries, "Primaries")
1825                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_MaxCLL, "MaxCLL")
1826                         ATO2(Segment_Tracks_TrackEntry_Video_Colour_MaxFALL, "MaxFALL")
1827                         LIS2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata, "MasteringMetadata")
1828                             ATOM_BEGIN
1829                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryRChromaticityX, "PrimaryRChromaticityX")
1830                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryRChromaticityY, "PrimaryRChromaticityY")
1831                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryGChromaticityX, "PrimaryGChromaticityX")
1832                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryGChromaticityY, "PrimaryGChromaticityY")
1833                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryBChromaticityX, "PrimaryBChromaticityX")
1834                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_PrimaryBChromaticityY, "PrimaryBChromaticityY")
1835                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_WhitePointChromaticityX, "WhitePointChromaticityX")
1836                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_WhitePointChromaticityY, "WhitePointChromaticityY")
1837                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_LuminanceMax, "LuminanceMax")
1838                             ATO2(Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_LuminanceMin, "LuminanceMin")
1839                             ATOM_END_MK
1840                         ATOM_END_MK
1841                     LIS2(Segment_Tracks_TrackEntry_Video_Projection, "Projection")
1842                         ATOM_BEGIN
1843                         ATO2(Segment_Tracks_TrackEntry_Video_Projection_ProjectionType, "ProjectionType")
1844                         ATO2(Segment_Tracks_TrackEntry_Video_Projection_ProjectionPrivate, "ProjectionPrivate")
1845                         ATO2(Segment_Tracks_TrackEntry_Video_Projection_ProjectionPoseYaw, "ProjectionPoseYaw")
1846                         ATO2(Segment_Tracks_TrackEntry_Video_Projection_ProjectionPosePitch, "ProjectionPosePitch")
1847                         ATO2(Segment_Tracks_TrackEntry_Video_Projection_ProjectionPoseRoll, "ProjectionPoseRoll")
1848                         ATOM_END_MK
1849                     ATOM_END_MK
1850                 LIS2(Segment_Tracks_TrackEntry_Audio, "Audio")
1851                     ATOM_BEGIN
1852                     ATO2(Segment_Tracks_TrackEntry_Audio_SamplingFrequency, "SamplingFrequency")
1853                     ATO2(Segment_Tracks_TrackEntry_Audio_OutputSamplingFrequency, "OutputSamplingFrequency")
1854                     ATO2(Segment_Tracks_TrackEntry_Audio_Channels, "Channels")
1855                     ATO2(Segment_Tracks_TrackEntry_Audio_ChannelPositions, "ChannelPositions")
1856                     ATO2(Segment_Tracks_TrackEntry_Audio_BitDepth, "BitDepth")
1857                     ATOM_END_MK
1858                 LIS2(Segment_Tracks_TrackEntry_TrackOperation, "TrackOperation")
1859                     ATOM_BEGIN
1860                     LIS2(Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes, "TrackCombinePlanes")
1861                         ATOM_BEGIN
1862                         LIS2(Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes_TrackPlane, "TrackPlane")
1863                             ATOM_BEGIN
1864                             ATO2(Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes_TrackPlane_TrackPlaneUID, "TrackPlaneUID")
1865                             ATO2(Segment_Tracks_TrackEntry_TrackOperation_TrackCombinePlanes_TrackPlane_TrackPlaneType, "TrackPlaneType")
1866                             ATOM_END_MK
1867                         ATOM_END_MK
1868                     LIS2(Segment_Tracks_TrackEntry_TrackOperation_TrackJoinBlocks, "TrackJoinBlocks")
1869                         ATOM_BEGIN
1870                         ATO2(Segment_Tracks_TrackEntry_TrackOperation_TrackJoinBlocks_TrackJoinUID, "TrackJoinUID")
1871                         ATOM_END_MK
1872                     ATOM_END_MK
1873                 ATO2(Segment_Tracks_TrackEntry_TrickTrackUID, "TrickTrackUID")
1874                 ATO2(Segment_Tracks_TrackEntry_TrickTrackSegmentUID, "TrickTrackSegmentUID")
1875                 ATO2(Segment_Tracks_TrackEntry_TrickTrackFlag, "TrickTrackFlag")
1876                 ATO2(Segment_Tracks_TrackEntry_TrickMasterTrackUID, "TrickMasterTrackUID")
1877                 ATO2(Segment_Tracks_TrackEntry_TrickMasterTrackSegmentUID, "TrickMasterTrackSegmentUID")
1878                 LIS2(Segment_Tracks_TrackEntry_BlockAdditionMapping, "BlockAdditionMapping")
1879                     ATOM_BEGIN
1880                     ATO2(Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDName, "BlockAddIDName")
1881                     ATO2(Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDType, "BlockAddIDType")
1882                     ATO2(Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDExtraData, "BlockAddIDExtraData")
1883                     ATO2(Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDValue, "BlockAddIDValue")
1884                     ATOM_END_MK
1885                 LIS2(Segment_Tracks_TrackEntry_ContentEncodings, "ContentEncodings")
1886                     ATOM_BEGIN
1887                     LIS2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding, "ContentEncoding")
1888                         ATOM_BEGIN
1889                         ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncodingOrder, "ContentEncodingOrder")
1890                         ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncodingScope, "ContentEncodingScope")
1891                         ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncodingType, "ContentEncodingType")
1892                         LIS2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression, "ContentCompression")
1893                             ATOM_BEGIN
1894                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompAlgo, "ContentCompAlgo")
1895                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompSettings, "ContentCompSettings")
1896                             ATOM_END_MK
1897                         LIS2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption, "ContentEncryption")
1898                             ATOM_BEGIN
1899                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentEncAlgo, "ContentEncAlgo")
1900                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentEncKeyID, "ContentEncKeyID")
1901                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSignature, "ContentSignature")
1902                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSigKeyID, "ContentSigKeyID")
1903                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSigAlgo, "ContentSigAlgo")
1904                             ATO2(Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentEncryption_ContentSigHashAlgo, "ContentSigHashAlgo")
1905                             ATOM_END_MK
1906                         ATOM_END_MK
1907                     ATOM_END_MK
1908                 ATOM_END_MK
1909             ATOM_END_MK
1910         LIS2(Segment_Cues, "Cues")
1911             ATOM_BEGIN
1912             LIS2(Segment_Cues_CuePoint, "CuePoint")
1913                 ATOM_BEGIN
1914                 ATO2(Segment_Cues_CuePoint_CueTime, "CueTime")
1915                 LIS2(Segment_Cues_CuePoint_CueTrackPositions, "CueTrackPositions")
1916                     ATOM_BEGIN
1917                     ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueTrack, "CueTrack")
1918                     ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueClusterPosition, "CueClusterPosition")
1919                     ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueRelativePosition, "CueRelativePosition")
1920                     ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueDuration, "CueDuration")
1921                     ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueBlockNumber, "CueBlockNumber")
1922                     ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueCodecState, "CueCodecState")
1923                     LIS2(Segment_Cues_CuePoint_CueTrackPositions_CueReference, "CueReference")
1924                         ATOM_BEGIN
1925                         ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefTime, "CueRefTime")
1926                         ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefCluster, "CueRefCluster")
1927                         ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefNumber, "CueRefNumber")
1928                         ATO2(Segment_Cues_CuePoint_CueTrackPositions_CueReference_CueRefCodecState, "CueRefCodecState")
1929                         ATOM_END_MK
1930                     ATOM_END_MK
1931                 ATOM_END_MK
1932             ATOM_END_MK
1933         LIS2(Segment_Attachments, "Attachments")
1934             ATOM_BEGIN
1935             LIS2(Segment_Attachments_AttachedFile, "AttachedFile")
1936                 ATOM_BEGIN
1937                 ATO2(Segment_Attachments_AttachedFile_FileDescription, "FileDescription")
1938                 ATO2(Segment_Attachments_AttachedFile_FileName, "FileName")
1939                 ATO2(Segment_Attachments_AttachedFile_FileMimeType, "FileMimeType")
1940                 LIS2(Segment_Attachments_AttachedFile_FileData, "FileData") //This is ATOM, but some ATOMs are too big
1941                     ATOM_BEGIN
1942                     ATOM_END_MK
1943                 ATO2(Segment_Attachments_AttachedFile_FileUID, "FileUID")
1944                 ATO2(Segment_Attachments_AttachedFile_FileReferral, "FileReferral")
1945                 ATO2(Segment_Attachments_AttachedFile_FileUsedStartTime, "FileUsedStartTime")
1946                 ATO2(Segment_Attachments_AttachedFile_FileUsedEndTime, "FileUsedEndTime")
1947                 ATOM_END_MK
1948             ATOM_END_MK
1949         LIS2(Segment_Chapters, "Chapters")
1950             ATOM_BEGIN
1951             LIS2(Segment_Chapters_EditionEntry, "EditionEntry")
1952                 ATOM_BEGIN
1953                 ATO2(Segment_Chapters_EditionEntry_EditionUID, "EditionUID")
1954                 ATO2(Segment_Chapters_EditionEntry_EditionFlagHidden, "EditionFlagHidden")
1955                 ATO2(Segment_Chapters_EditionEntry_EditionFlagDefault, "EditionFlagDefault")
1956                 ATO2(Segment_Chapters_EditionEntry_EditionFlagOrdered, "EditionFlagOrdered")
1957                 LIS2(Segment_Chapters_EditionEntry_ChapterAtom, "ChapterAtom")
1958                     ATOM_BEGIN
1959                     LIS2(Segment_Chapters_EditionEntry_ChapterAtom, "ChapterAtom")
1960                         ATOM_BEGIN
1961                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterUID, "ChapterUID")
1962                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterStringUID, "ChapterStringUID")
1963                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeStart, "ChapterTimeStart")
1964                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeEnd, "ChapterTimeEnd")
1965                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterFlagHidden, "ChapterFlagHidden")
1966                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterFlagEnabled, "ChapterFlagEnabled")
1967                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterSegmentUID, "ChapterSegmentUID")
1968                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterSegmentEditionUID, "ChapterSegmentEditionUID")
1969                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterPhysicalEquiv, "ChapterPhysicalEquiv")
1970                         LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTrack, "ChapterTrack")
1971                             ATOM_BEGIN
1972                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTrack_ChapterTrackNumber, "ChapterTrackNumber")
1973                             ATOM_END_MK
1974                         LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay, "ChapterDisplay")
1975                             ATOM_BEGIN
1976                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapString, "ChapString")
1977                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguage, "ChapLanguage")
1978                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguageIETF, "ChapLanguageIETF")
1979                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapCountry, "ChapCountry")
1980                             ATOM_END_MK
1981                         LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess, "ChapProcess")
1982                             ATOM_BEGIN
1983                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCodecID, "ChapProcessCodecID")
1984                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessPrivate, "ChapProcessPrivate")
1985                             LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand, "ChapProcessCommand")
1986                                 ATOM_BEGIN
1987                                 ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand_ChapProcessTime, "ChapProcessTime")
1988                                 ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand_ChapProcessData, "ChapProcessData")
1989                                 ATOM_END_MK
1990                             ATOM_END_MK
1991                         ATOM_END_MK
1992                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterUID, "ChapterUID")
1993                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterStringUID, "ChapterStringUID")
1994                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeStart, "ChapterTimeStart")
1995                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeEnd, "ChapterTimeEnd")
1996                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterFlagHidden, "ChapterFlagHidden")
1997                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterFlagEnabled, "ChapterFlagEnabled")
1998                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterSegmentUID, "ChapterSegmentUID")
1999                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterSegmentEditionUID, "ChapterSegmentEditionUID")
2000                     ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterPhysicalEquiv, "ChapterPhysicalEquiv")
2001                     LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTrack, "ChapterTrack")
2002                         ATOM_BEGIN
2003                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterTrack_ChapterTrackNumber, "ChapterTrackNumber")
2004                         ATOM_END_MK
2005                     LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay, "ChapterDisplay")
2006                         ATOM_BEGIN
2007                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapString, "ChapString")
2008                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguage, "ChapLanguage")
2009                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguageIETF, "ChapLanguageIETF")
2010                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapCountry, "ChapCountry")
2011                         ATOM_END_MK
2012                     LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess, "ChapProcess")
2013                         ATOM_BEGIN
2014                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCodecID, "ChapProcessCodecID")
2015                         ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessPrivate, "ChapProcessPrivate")
2016                         LIS2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand, "ChapProcessCommand")
2017                             ATOM_BEGIN
2018                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand_ChapProcessTime, "ChapProcessTime")
2019                             ATO2(Segment_Chapters_EditionEntry_ChapterAtom_ChapProcess_ChapProcessCommand_ChapProcessData, "ChapProcessData")
2020                             ATOM_END_MK
2021                         ATOM_END_MK
2022                     ATOM_END_MK
2023                 ATOM_END_MK
2024             ATOM_END_MK
2025         LIS2(Segment_Tags, "Tags")
2026             ATOM_BEGIN
2027             LIS2(Segment_Tags_Tag, "Tag")
2028                 ATOM_BEGIN
2029                 LIS2(Segment_Tags_Tag_Targets, "Targets")
2030                     ATOM_BEGIN
2031                     ATO2(Segment_Tags_Tag_Targets_TargetTypeValue, "TargetTypeValue")
2032                     ATO2(Segment_Tags_Tag_Targets_TargetType, "TargetType")
2033                     ATO2(Segment_Tags_Tag_Targets_TagTrackUID, "TagTrackUID")
2034                     ATO2(Segment_Tags_Tag_Targets_TagEditionUID, "TagEditionUID")
2035                     ATO2(Segment_Tags_Tag_Targets_TagChapterUID, "TagChapterUID")
2036                     ATO2(Segment_Tags_Tag_Targets_TagAttachmentUID, "TagAttachmentUID")
2037                     ATOM_END_MK
2038                 LIS2(Segment_Tags_Tag_SimpleTag, "SimpleTag")
2039                     ATOM_BEGIN
2040                     LIS2(Segment_Tags_Tag_SimpleTag, "SimpleTag")
2041                         ATOM_BEGIN
2042                         ATO2(Segment_Tags_Tag_SimpleTag_TagName, "TagName")
2043                         ATO2(Segment_Tags_Tag_SimpleTag_TagLanguage, "TagLanguage")
2044                         ATO2(Segment_Tags_Tag_SimpleTag_TagLanguageIETF, "TagLanguageIETF")
2045                         ATO2(Segment_Tags_Tag_SimpleTag_TagDefault, "TagDefault")
2046                         ATO2(Segment_Tags_Tag_SimpleTag_TagString, "TagString")
2047                         ATO2(Segment_Tags_Tag_SimpleTag_TagBinary, "TagBinary")
2048                         ATOM_END_MK
2049                     ATO2(Segment_Tags_Tag_SimpleTag_TagName, "TagName")
2050                     ATO2(Segment_Tags_Tag_SimpleTag_TagLanguage, "TagLanguage")
2051                     ATO2(Segment_Tags_Tag_SimpleTag_TagLanguageIETF, "TagLanguageIETF")
2052                     ATO2(Segment_Tags_Tag_SimpleTag_TagDefault, "TagDefault")
2053                     ATO2(Segment_Tags_Tag_SimpleTag_TagString, "TagString")
2054                     ATO2(Segment_Tags_Tag_SimpleTag_TagBinary, "TagBinary")
2055                     ATOM_END_MK
2056                 ATOM_END_MK
2057             ATOM_END_MK
2058         ATOM_END_MK
2059     DATA_END
2060 
2061     if (!Element_IsWaitingForMoreData() && !CRC32Compute.empty())
2062         CRC32_Check();
2063 
2064     if (IsParsingSegmentTrack_SeekBackTo && File_Offset+Buffer_Offset+Element_Offset==SegmentTrack_Offset_End) //TODO: implement check at end of an element
2065     {
2066         while (Element_Level>(Element_Offset==Element_Size?2:1))
2067             Element_End0();
2068         GoTo(IsParsingSegmentTrack_SeekBackTo);
2069         IsParsingSegmentTrack_SeekBackTo=0;
2070     }
2071 }
2072 
2073 //***************************************************************************
2074 // Elements
2075 //***************************************************************************
2076 
2077 //---------------------------------------------------------------------------
Zero()2078 void File_Mk::Zero()
2079 {
2080     Element_Name("Junk");
2081 
2082     Skip_XX(Element_Size,                                       "Junk");
2083 }
2084 
2085 //---------------------------------------------------------------------------
CRC32()2086 void File_Mk::CRC32()
2087 {
2088     Element_Name("CRC-32");
2089 
2090     //Parsing
2091     if (Element_Size!=4)
2092         UInteger_Info(); //Something is wrong, 4-byte integer is expected
2093     else
2094     {
2095         if (CRC32Compute.empty())
2096             Fill(Stream_General, 0, "ErrorDetectionType", Element_Level==3?"Per level 1":"Custom", Unlimited, true, true);
2097 
2098         if (CRC32Compute.size()<Element_Level)
2099             CRC32Compute.resize(Element_Level);
2100 
2101         Get_L4(CRC32Compute[Element_Level-1].Expected,          "Value");
2102 
2103         {
2104             Param_Info1(__T("Not tested ")+Ztring::ToZtring(Element_Level-1)+__T(' ')+Ztring::ToZtring(CRC32Compute[Element_Level-1].Expected));
2105             CRC32Compute[Element_Level-1].Computed=0xFFFFFFFF;
2106             CRC32Compute[Element_Level-1].Pos = File_Offset + Buffer_Offset;
2107             CRC32Compute[Element_Level-1].From = File_Offset + Buffer_Offset + Element_Size;
2108             CRC32Compute[Element_Level-1].UpTo = File_Offset + Buffer_Offset + Element_TotalSize_Get(1);
2109         }
2110     }
2111 }
2112 
2113 //---------------------------------------------------------------------------
Void()2114 void File_Mk::Void()
2115 {
2116     Element_Name("Void");
2117 
2118     //Parsing
2119     UInteger_Info();
2120 }
2121 
2122 //---------------------------------------------------------------------------
Ebml_ReadVersion()2123 void File_Mk::Ebml_ReadVersion()
2124 {
2125     //Parsing
2126     UInteger_Info();
2127 }
2128 
2129 //---------------------------------------------------------------------------
Ebml_MaxSizeLength()2130 void File_Mk::Ebml_MaxSizeLength()
2131 {
2132     //Parsing
2133     int64u Value = UInteger_Get();
2134 
2135     //Filling
2136     FILLING_BEGIN();
2137         if (Value > 8)
2138             Value = 8; //Not expected, considerating it as if it is 8 for the moment
2139         InvalidByteMax = (int8u)((1 << (8-Value))-1);
2140     FILLING_END();
2141 }
2142 
2143 //---------------------------------------------------------------------------
Ebml_DocType()2144 void File_Mk::Ebml_DocType()
2145 {
2146     //Parsing
2147     Ztring Data=String_Get();
2148 
2149     //Filling
2150     FILLING_BEGIN();
2151         if (Data==__T("matroska"))
2152         {
2153             Accept("Matroska");
2154             Fill(Stream_General, 0, General_Format, "Matroska");
2155             Buffer_MaximumSize = 64 * 1024 * 1024; //Testing with huge lossless 4K frames
2156             File_Buffer_Size_Hint_Pointer = Config->File_Buffer_Size_Hint_Pointer_Get();
2157         }
2158         else if (Data==__T("webm"))
2159         {
2160             Accept("Matroska");
2161             Fill(Stream_General, 0, General_Format, "WebM");
2162         }
2163         else if (Data==__T("rawcooked"))
2164         {
2165             Accept("RAWcooked");
2166             Fill(Stream_General, 0, General_Format, "RAWcooked");
2167         }
2168         else
2169         {
2170             Reject("Matroska");
2171             return;
2172         }
2173     FILLING_END();
2174 }
2175 
2176 //---------------------------------------------------------------------------
Ebml_DocTypeVersion()2177 void File_Mk::Ebml_DocTypeVersion()
2178 {
2179     //Parsing
2180     Format_Version=UInteger_Get();
2181 
2182     //Filling
2183     FILLING_BEGIN();
2184         Fill(Stream_General, 0, General_Format_Version, __T("Version ")+Ztring::ToZtring(Format_Version));
2185     FILLING_END();
2186 }
2187 
2188 //---------------------------------------------------------------------------
Ebml_DocTypeReadVersion()2189 void File_Mk::Ebml_DocTypeReadVersion()
2190 {
2191     //Parsing
2192     int64u UInteger=UInteger_Get();
2193 
2194     //Filling
2195     FILLING_BEGIN();
2196         if (UInteger!=Format_Version && MediaInfoLib::Config.LegacyStreamDisplay_Get())
2197             Fill(Stream_General, 0, General_Format_Version, __T("Version ")+Ztring::ToZtring(UInteger)); //Adding compatible version for info about legacy decoders
2198     FILLING_END();
2199 }
2200 
2201 //---------------------------------------------------------------------------
2202 #if MEDIAINFO_TRACE
Rawcooked_Compressed_Start(rawcookedtrack::mask * Mask,bool UseMask)2203 bool File_Mk::Rawcooked_Compressed_Start(rawcookedtrack::mask* Mask, bool UseMask)
2204 {
2205     if (!Trace_Activated) // Currently used only for trace
2206     {
2207         int64u Size;
2208         Get_EB(Size,                                            "Size");
2209         Skip_XX(Element_Size-Element_Offset,                    "Data");
2210         return false;
2211     }
2212 
2213     Get_EB(Rawcooked_Compressed_Save_Element_Size,               "Size");
2214     if (Rawcooked_Compressed_Save_Element_Size && Element_Offset!=Element_Size)
2215     {
2216         int64u Element_Offset_Save=Element_Offset;
2217         Skip_XX(Element_Size-Element_Offset,                    "Compressed data");
2218         Element_Offset=Element_Offset_Save;
2219 
2220         //Sizes
2221         unsigned long Source_Size=(unsigned long)(Element_Size-Element_Offset);
2222         unsigned long Dest_Size=(unsigned long)Rawcooked_Compressed_Save_Element_Size;
2223 
2224         //Uncompressing
2225         int8u* Dest=new int8u[(Mask && UseMask && Mask->Size>Dest_Size)?Mask->Size:Dest_Size];
2226         if (uncompress((Bytef*)Dest, &Dest_Size, (const Bytef*)Buffer+Buffer_Offset+(size_t)Element_Offset, Source_Size)<0)
2227         {
2228             delete[] Dest; //Dest=NULL;
2229             Param_Info("Problem during the decompression");
2230             return false;
2231         }
2232 
2233         //Store or apply mask
2234         if (Mask)
2235         {
2236             if (UseMask && Mask->Buffer)
2237             {
2238                 size_t i=0;
2239                 for (; i<Dest_Size && i<Mask->Size; i++)
2240                     Dest[i]+=Mask->Buffer[i];
2241                 for (; i<Mask->Size; i++)
2242                     Dest[i]=Mask->Buffer[i];
2243             }
2244             if (!UseMask)
2245             {
2246                 Mask->Buffer=Dest;
2247                 Mask->Size=Dest_Size;
2248             }
2249         }
2250 
2251         File_Offset+=Buffer_Offset+Element_Offset;
2252         Rawcooked_Compressed_Save_Buffer_Offset=Buffer_Offset;
2253         Buffer_Offset=0;
2254         Rawcooked_Compressed_Save_Buffer=Buffer;
2255         Buffer=Dest;
2256         Rawcooked_Compressed_Save_Element_Size=Element_Size;
2257         Element_Size=Dest_Size;
2258         Rawcooked_Compressed_Save_Element_Offset=Element_Offset;
2259         Element_Offset=0;
2260     }
2261     else
2262     {
2263         Rawcooked_Compressed_Save_Buffer=Buffer;
2264     }
2265 
2266     return true;
2267 }
2268 
2269 //---------------------------------------------------------------------------
Rawcooked_Compressed_End(rawcookedtrack::mask * Mask,bool UseMask)2270 void File_Mk::Rawcooked_Compressed_End(rawcookedtrack::mask* Mask, bool UseMask)
2271 {
2272     if (Buffer==Rawcooked_Compressed_Save_Buffer)
2273         return; // No buffer created, nothing to do
2274 
2275     if (!Mask || !Mask->Buffer || UseMask)
2276         delete[] Buffer; //Buffer=NULL;
2277     Buffer=Rawcooked_Compressed_Save_Buffer;
2278     Buffer_Offset=Rawcooked_Compressed_Save_Buffer_Offset;
2279     Element_Size=Rawcooked_Compressed_Save_Element_Size;
2280     Element_Offset=Element_Size;
2281     File_Offset-=Buffer_Offset+Rawcooked_Compressed_Save_Element_Offset;
2282 }
2283 
2284 //---------------------------------------------------------------------------
Rawcooked_BeforeData()2285 void File_Mk::Rawcooked_BeforeData()
2286 {
2287     //Parsing
2288     MediaInfo_Internal MI;
2289     MI.Option(__T("File_IsReferenced"), __T("1"));
2290     MI.Option(__T("File_KeepInfo"), __T("1"));
2291     MI.Open_Buffer_Init(Element_Size-Element_Offset);
2292     MI.Open_Buffer_Continue(Buffer+Buffer_Offset+(size_t)Element_Offset, (size_t)(Element_Size-Element_Offset));
2293     MI.Open_Buffer_Finalize();
2294     Element[Element_Level].TraceNode.TakeChilrenFrom(MI.Info->Element[0].TraceNode);
2295 }
2296 
2297 //---------------------------------------------------------------------------
Rawcooked_BeforeData(bool HasMask,bool UseMask)2298 void File_Mk::Rawcooked_BeforeData(bool HasMask, bool UseMask)
2299 {
2300     if (!Rawcooked_Compressed_Start(HasMask?&RawcookedTrack_Data.MaskBaseBeforeData:NULL, UseMask))
2301         return;
2302 
2303     Rawcooked_BeforeData();
2304 
2305     Rawcooked_Compressed_End(HasMask?&RawcookedTrack_Data.MaskBaseBeforeData:NULL, UseMask);
2306 }
2307 
2308 //---------------------------------------------------------------------------
Rawcooked_AfterData()2309 void File_Mk::Rawcooked_AfterData()
2310 {
2311     //Parsing
2312     Skip_XX(Element_Size-Element_Offset,                        "Data");
2313 }
2314 
2315 //---------------------------------------------------------------------------
Rawcooked_AfterData(bool,bool UseMask)2316 void File_Mk::Rawcooked_AfterData(bool, bool UseMask)
2317 {
2318     if (!Rawcooked_Compressed_Start(NULL, UseMask))
2319         return;
2320 
2321     Rawcooked_AfterData();
2322 
2323     Rawcooked_Compressed_End(NULL, UseMask);
2324 }
2325 
2326 //---------------------------------------------------------------------------
Rawcooked_FileName()2327 void File_Mk::Rawcooked_FileName()
2328 {
2329     //Parsing
2330     Skip_String(Element_Size-Element_Offset,                    "Data");
2331 }
2332 
2333 //---------------------------------------------------------------------------
Rawcooked_FileName(bool HasMask,bool UseMask)2334 void File_Mk::Rawcooked_FileName(bool HasMask, bool UseMask)
2335 {
2336     if (!Rawcooked_Compressed_Start(HasMask?&RawcookedTrack_Data.MaskBaseFileName:NULL, UseMask))
2337         return;
2338 
2339     Rawcooked_FileName();
2340 
2341     Rawcooked_Compressed_End(HasMask?&RawcookedTrack_Data.MaskBaseFileName:NULL, UseMask);
2342 }
2343 //---------------------------------------------------------------------------
RawcookedBlock()2344 void File_Mk::RawcookedBlock()
2345 {
2346     if (Trace_Activated)
2347     {
2348         Element_Info1(Ztring().From_Number(RawcookedTrack_Data.FramePos));
2349         RawcookedTrack_Data.FramePos++;
2350         if (RawcookedTrack_Data.FramePos>10)
2351         {
2352             Trace_Activated_Save=true;
2353             Trace_Activated=false;
2354             Skip_XX(Element_Size,                               "");
2355         }
2356     }
2357 }
2358 
2359 //---------------------------------------------------------------------------
RawcookedBlock_FileHash()2360 void File_Mk::RawcookedBlock_FileHash()
2361 {
2362     //Parsing
2363     int64u Type;
2364     Get_EB(Type,                                                "Type");
2365     switch (Type)
2366     {
2367         case 0 : Param_Info("MD5");  Skip_Hexa(16,              "Data"); break;
2368         default: Skip_XX(Element_Size-Element_Offset,           "Data");
2369     }
2370 }
2371 
2372 //---------------------------------------------------------------------------
RawcookedSegment()2373 void File_Mk::RawcookedSegment()
2374 {
2375 }
2376 
2377 //---------------------------------------------------------------------------
RawcookedSegment_LibraryName()2378 void File_Mk::RawcookedSegment_LibraryName()
2379 {
2380     Skip_Local(Element_Size,                                    "LibraryName");
2381 }
2382 
2383 //---------------------------------------------------------------------------
RawcookedSegment_LibraryVersion()2384 void File_Mk::RawcookedSegment_LibraryVersion()
2385 {
2386     Skip_Local(Element_Size,                                    "LibraryVersion");
2387 }
2388 
2389 //---------------------------------------------------------------------------
RawcookedTrack()2390 void File_Mk::RawcookedTrack()
2391 {
2392     if (RawcookedTrack_Data.FramePos>10)
2393     {
2394         Element_Level--;
2395         Param("RawcookedBlock", Ztring::ToZtring(RawcookedTrack_Data.FramePos-10)+__T(" other blocks"));
2396         Element_Level++;
2397     }
2398     RawcookedTrack_Data=rawcookedtrack();
2399 }
2400 #endif //MEDIAINFO_TRACE
2401 
2402 //---------------------------------------------------------------------------
Segment()2403 void File_Mk::Segment()
2404 {
2405     if (!Status[IsAccepted])
2406     {
2407         Accept("Matroska");
2408         Fill(Stream_General, 0, General_Format, "Matroska"); //Default is Matroska
2409     }
2410 
2411     Segment_Offset_Begin=File_Offset+Buffer_Offset;
2412     Segment_Offset_End=File_Offset+Buffer_Offset+Element_TotalSize_Get();
2413 
2414     #if MEDIAINFO_TRACE
2415         Trace_Segment_Cluster_Count=0;
2416     #endif // MEDIAINFO_TRACE
2417 }
2418 
2419 //---------------------------------------------------------------------------
Segment_Attachments_AttachedFile()2420 void File_Mk::Segment_Attachments_AttachedFile()
2421 {
2422     AttachedFile_FileName.clear();
2423     AttachedFile_FileMimeType.clear();
2424     AttachedFile_FileDescription.clear();
2425 }
2426 
2427 //---------------------------------------------------------------------------
Segment_Attachments_AttachedFile_FileDescription()2428 void File_Mk::Segment_Attachments_AttachedFile_FileDescription()
2429 {
2430     //Parsing
2431     Ztring Data=UTF8_Get();
2432 
2433     AttachedFile_FileDescription=Data.To_UTF8();
2434 }
2435 
2436 //---------------------------------------------------------------------------
Segment_Attachments_AttachedFile_FileName()2437 void File_Mk::Segment_Attachments_AttachedFile_FileName()
2438 {
2439     //Parsing
2440     Ztring Data=UTF8_Get();
2441 
2442     Fill(Stream_General, 0, "Attachments", Data);
2443 
2444     //Cover is in the first file which name contains "cover"
2445     if (!CoverIsSetFromAttachment && Data.MakeLowerCase().find(__T("cover")) != string::npos)
2446         CurrentAttachmentIsCover=true;
2447 
2448     AttachedFile_FileName=Data.To_UTF8();
2449 }
2450 
2451 //---------------------------------------------------------------------------
Segment_Attachments_AttachedFile_FileMimeType()2452 void File_Mk::Segment_Attachments_AttachedFile_FileMimeType()
2453 {
2454     //Parsing
2455     Ztring Data=String_Get();
2456 
2457     AttachedFile_FileMimeType=Data.To_UTF8();
2458 }
2459 
2460 //---------------------------------------------------------------------------
Segment_Attachments_AttachedFile_FileData()2461 void File_Mk::Segment_Attachments_AttachedFile_FileData()
2462 {
2463     Element_Name("FileData");
2464 
2465     bool Attachments_Demux=true;
2466 
2467     //Parsing
2468     if ((Attachments_Demux || !CoverIsSetFromAttachment && CurrentAttachmentIsCover) && Element_Size<=16*1024*1024) //TODO: option for setting the acceptable maximum size of the attachment
2469     {
2470         if (!Element_IsComplete_Get())
2471         {
2472             Element_WaitForMoreData();
2473             return;
2474         }
2475 
2476         #if MEDIAINFO_TRACE
2477             if (Trace_Activated)
2478             {
2479                 //Parsing
2480                 MediaInfo_Internal MI;
2481                 MI.Option(__T("File_IsReferenced"), __T("1"));
2482                 MI.Option(__T("File_KeepInfo"), __T("1"));
2483                 MI.Open_Buffer_Init(Element_Size-Element_Offset);
2484                 MI.Open_Buffer_Continue(Buffer+Buffer_Offset+(size_t)Element_Offset, (size_t)(Element_Size-Element_Offset));
2485                 MI.Open_Buffer_Finalize();
2486                 Element[Element_Level].TraceNode.TakeChilrenFrom(MI.Info->Element[0].TraceNode);
2487             }
2488         #endif //MEDIAINFO_TRACE
2489 
2490         std::string Data_Raw;
2491         Peek_String(Element_TotalSize_Get(), Data_Raw);
2492 
2493         if (!CoverIsSetFromAttachment && CurrentAttachmentIsCover)
2494         {
2495             //Filling
2496             #if MEDIAINFO_ADVANCED
2497                 if (MediaInfoLib::Config.Flags1_Get(Flags_Cover_Data_base64))
2498                 {
2499                     std::string Data_Base64(Base64::encode(Data_Raw));
2500                     Fill(Stream_General, 0, General_Cover_Data, Data_Base64);
2501                 }
2502             #endif //MEDIAINFO_ADVANCED
2503             Fill(Stream_General, 0, General_Cover, "Yes");
2504             CoverIsSetFromAttachment=true;
2505         }
2506 
2507         #if MEDIAINFO_EVENTS
2508             if (Attachments_Demux)
2509             {
2510                 EVENT_BEGIN(Global, AttachedFile, 0)
2511                     Event.Content_Size=Data_Raw.size();
2512                     Event.Content=(const int8u*)Data_Raw.c_str();
2513                     Event.Flags=0;
2514                     Event.Name=AttachedFile_FileName.c_str();
2515                     Event.MimeType=AttachedFile_FileMimeType.c_str();
2516                     Event.Description=AttachedFile_FileDescription.c_str();
2517                 EVENT_END()
2518             }
2519         #endif //MEDIAINFO_EVENTS
2520     }
2521 
2522     Element_Offset=Element_Size;
2523 
2524     Element_ThisIsAList();
2525 }
2526 
2527 //---------------------------------------------------------------------------
Segment_Chapters_EditionEntry()2528 void File_Mk::Segment_Chapters_EditionEntry()
2529 {
2530     //Filling
2531     EditionEntries_Pos=EditionEntries.size();
2532     EditionEntries.resize(EditionEntries_Pos+1);
2533 }
2534 
2535 //---------------------------------------------------------------------------
Segment_Chapters_EditionEntry_ChapterAtom()2536 void File_Mk::Segment_Chapters_EditionEntry_ChapterAtom()
2537 {
2538     //Filling
2539     ChapterAtoms_Pos=EditionEntries[EditionEntries_Pos].ChapterAtoms.size();
2540     EditionEntries[EditionEntries_Pos].ChapterAtoms.resize(ChapterAtoms_Pos+1);
2541 }
2542 
2543 //---------------------------------------------------------------------------
Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay()2544 void File_Mk::Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay()
2545 {
2546     //Filling
2547     ChapterDisplays_Pos=EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays.size();
2548     EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays.resize(ChapterDisplays_Pos+1);
2549 }
2550 
2551 //---------------------------------------------------------------------------
Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguage()2552 void File_Mk::Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapLanguage()
2553 {
2554     //Parsing
2555     Ztring Data=String_Get();
2556 
2557     FILLING_BEGIN();
2558         EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays[ChapterDisplays_Pos].ChapLanguage=Data;
2559     FILLING_END();
2560 }
2561 
2562 //---------------------------------------------------------------------------
Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapString()2563 void File_Mk::Segment_Chapters_EditionEntry_ChapterAtom_ChapterDisplay_ChapString()
2564 {
2565     //Parsing
2566     Ztring Data=UTF8_Get();
2567 
2568     FILLING_BEGIN();
2569         EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterDisplays[ChapterDisplays_Pos].ChapString=Data;
2570         //if (TimecodeScale!=0 && ChapterTimeStart!=(int64u)-1)
2571         //    Fill(StreamKind_Last, StreamPos_Last, Ztring::ToZtring(Chapter_Pos).To_Local().c_str(), Ztring().Duration_From_Milliseconds(ChapterTimeStart/TimecodeScale)+__T(" - ")+ChapterString, true);
2572     FILLING_END();
2573 }
2574 
2575 //---------------------------------------------------------------------------
Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeStart()2576 void File_Mk::Segment_Chapters_EditionEntry_ChapterAtom_ChapterTimeStart()
2577 {
2578     //Parsing
2579     int64u Data=UInteger_Get();
2580 
2581     FILLING_BEGIN();
2582         EditionEntries[EditionEntries_Pos].ChapterAtoms[ChapterAtoms_Pos].ChapterTimeStart=Data;
2583     FILLING_END();
2584 }
2585 
2586 //---------------------------------------------------------------------------
Segment_Cluster()2587 void File_Mk::Segment_Cluster()
2588 {
2589     #if MEDIAINFO_TRACE
2590         if (Trace_Activated)
2591         {
2592             if (Trace_Segment_Cluster_Count<MaxCountSameElementInTrace)
2593                 Trace_Segment_Cluster_Count++;
2594             else
2595                 Element_Set_Remove_Children_IfNoErrors();
2596         }
2597     #endif // MEDIAINFO_TRACE
2598 
2599     //For each stream
2600     if (!Segment_Cluster_Count)
2601     {
2602 
2603         for (std::map<int64u, stream>::iterator Temp=Stream.begin(); Temp!=Stream.end(); ++Temp)
2604         {
2605             if (!Temp->second.Parser)
2606                 Temp->second.Searching_Payload=false;
2607             if (Temp->second.StreamKind==Stream_Video || Temp->second.StreamKind==Stream_Audio)
2608                 Temp->second.Searching_TimeStamp_Start=true;
2609             if (Temp->second.StreamKind==Stream_Video)
2610                 Temp->second.Searching_TimeStamps=true;
2611             if (Temp->second.Searching_Payload
2612              || Temp->second.Searching_TimeStamp_Start
2613              || Temp->second.Searching_TimeStamps)
2614                 Stream_Count++;
2615 
2616             //Specific cases
2617             #ifdef MEDIAINFO_AAC_YES
2618                 if (Retrieve(Temp->second.StreamKind, Temp->second.StreamPos, Audio_CodecID).find(__T("A_AAC/"))==0)
2619                     ((File_Aac*)Stream[Temp->first].Parser)->Mode=File_Aac::Mode_raw_data_block; //In case AudioSpecificConfig is not present
2620             #endif //MEDIAINFO_AAC_YES
2621         }
2622     }
2623     Segment_Cluster_Count++;
2624     Segment_Cluster_TimeCode_Value=0; //Default
2625 }
2626 
2627 //---------------------------------------------------------------------------
Segment_Cluster_BlockGroup()2628 void File_Mk::Segment_Cluster_BlockGroup()
2629 {
2630     Segment_Cluster_BlockGroup_BlockDuration_Value=(int64u)-1;
2631     Segment_Cluster_BlockGroup_BlockDuration_TrackNumber=(int64u)-1;
2632 }
2633 
2634 //---------------------------------------------------------------------------
Segment_Cluster_BlockGroup_Block()2635 void File_Mk::Segment_Cluster_BlockGroup_Block()
2636 {
2637     if (!Element_IsComplete_Get())
2638     {
2639         Element_WaitForMoreData();
2640         return;
2641     }
2642 
2643     //Parsing
2644     Get_EB (TrackNumber,                                        "TrackNumber"); Element_Info1(TrackNumber);
2645 
2646     //Finished?
2647     stream& streamItem = Stream[TrackNumber];
2648     #if MEDIAINFO_TRACE
2649         if (Trace_Activated)
2650         {
2651             if (streamItem.Trace_Segment_Cluster_Block_Count<=MaxCountSameElementInTrace)
2652                 streamItem.Trace_Segment_Cluster_Block_Count++;
2653             //else
2654             //    Element_Set_Remove_Children_IfNoErrors();
2655         }
2656     #endif // MEDIAINFO_TRACE
2657     streamItem.PacketCount++;
2658     if (streamItem.Searching_Payload || streamItem.Searching_TimeStamps || streamItem.Searching_TimeStamp_Start)
2659     {
2660         //Parsing
2661         int16u TimeCodeU;
2662         Get_B2 (TimeCodeU,                                      "TimeCode"); // Should be signed, but we don't have signed integer reader
2663         int16s TimeCode = (int16s)TimeCodeU;
2664         Element_Info1(TimeCodeU);
2665         #if MEDIAINFO_DEMUX
2666         FrameInfo.PTS=(Segment_Cluster_TimeCode_Value+TimeCode)*1000000;
2667         #endif //MEDIAINFO_DEMUX
2668 
2669         FILLING_BEGIN();
2670             if (Segment_Cluster_TimeCode_Value+TimeCode<streamItem.TimeCode_Start) //Does not work well: streamItem.Searching_TimeStamp_Start)
2671             {
2672                 FILLING_BEGIN();
2673                       streamItem.TimeCode_Start=Segment_Cluster_TimeCode_Value+TimeCode;
2674                     //streamItem.Searching_TimeStamp_Start=false;
2675                 FILLING_END();
2676             }
2677             if (streamItem.Searching_TimeStamps)
2678             {
2679                 streamItem.TimeCodes.push_back(Segment_Cluster_TimeCode_Value+TimeCode);
2680                 if (streamItem.TimeCodes.size()>128)
2681                     streamItem.Searching_TimeStamps=false;
2682             }
2683 
2684             if (Segment_Cluster_BlockGroup_BlockDuration_Value!=(int64u)-1)
2685             {
2686                 streamItem.Segment_Cluster_BlockGroup_BlockDuration_Counts[Segment_Cluster_BlockGroup_BlockDuration_Value]++;
2687                 Segment_Cluster_BlockGroup_BlockDuration_Value=(int64u)-1;
2688             }
2689         FILLING_END();
2690 
2691         if (streamItem.Searching_Payload)
2692         {
2693             int32u Lacing;
2694             Element_Begin1("Flags");
2695                 BS_Begin();
2696                 Skip_BS(1,                                      "KeyFrame");
2697                 Skip_BS(3,                                      "Reserved");
2698                 Skip_BS(1,                                      "Invisible");
2699                 Get_BS (2, Lacing,                              "Lacing");
2700                 Skip_BS(1,                                      "Discardable");
2701                 BS_End();
2702             Element_End0();
2703             if (Lacing>0)
2704             {
2705                 Element_Begin1("Lacing");
2706                     int8u FrameCountMinus1;
2707                     Get_B1(FrameCountMinus1,                    "Frame count minus 1");
2708                     switch (Lacing)
2709                     {
2710                         case 1 : //Xiph lacing
2711                                 {
2712                                     int64u Element_Offset_Virtual=0;
2713                                     for (int8u Pos=0; Pos<FrameCountMinus1; Pos++)
2714                                     {
2715                                         int32u Size=0;
2716                                         int8u Size8;
2717                                         do
2718                                         {
2719                                             Get_B1 (Size8,      "Size");
2720                                             Size+=Size8;
2721                                         }
2722                                         while (Size8==0xFF);
2723                                         Param_Info1(Size);
2724                                         Element_Offset_Virtual+=Size;
2725                                         Laces.push_back(Size);
2726                                     }
2727                                     if (Element_Offset+Element_Offset_Virtual>Element_Size)
2728                                     {
2729                                         //Problem
2730                                         Laces.clear();
2731                                         Laces.push_back(Element_Size - Element_Offset);
2732                                     }
2733                                     else
2734                                         Laces.push_back(Element_Size-Element_Offset-Element_Offset_Virtual); //last lace
2735                                 }
2736                                 break;
2737                         case 2 : //Fixed-size lacing - No more data
2738                                 {
2739                                     int64u Size=(Element_Size-Element_Offset)/(FrameCountMinus1+1);
2740                                     Laces.resize(FrameCountMinus1+1, Size);
2741                                 }
2742                                 break;
2743                         case 3 : //EBML lacing
2744                                 {
2745                                     int64u Element_Offset_Virtual=0, Size;
2746                                     Get_EB (Size,                "Size");
2747                                     Laces.push_back(Size);
2748                                     Element_Offset_Virtual+=Size;
2749                                     for (int8u Pos=1; Pos<FrameCountMinus1; Pos++)
2750                                     {
2751                                         int64s Diff;
2752                                         Get_ES (Diff,           "Difference");
2753                                         Size+=Diff; Param_Info1(Size);
2754                                         Element_Offset_Virtual+=Size;
2755                                         Laces.push_back(Size);
2756                                     }
2757                                     if (Element_Offset+Element_Offset_Virtual>Element_Size)
2758                                     {
2759                                         //Problem
2760                                         Laces.clear();
2761                                         Laces.push_back(Element_Size - Element_Offset);
2762                                     }
2763                                     else
2764                                         Laces.push_back(Element_Size-Element_Offset-Element_Offset_Virtual); Param_Info1(Size); //last lace
2765                                 }
2766                                 break;
2767                         default : ; //Should never be here
2768                     }
2769                 Element_End0();
2770             }
2771             else
2772                 Laces.push_back(Element_Size-Element_Offset);
2773         }
2774         else
2775         {
2776             Laces.push_back(Element_Size-Element_Offset);
2777         }
2778     }
2779     else
2780     {
2781         Laces.push_back(Element_Size-Element_Offset);
2782     }
2783 
2784     if (Laces.size()==1)
2785     {
2786         Element_Begin1("Data");
2787         Segment_Cluster_BlockGroup_Block_Lace();
2788         Element_End0();
2789     }
2790 
2791     #if MEDIAINFO_TRACE
2792         if (Trace_Activated && (Trace_Segment_Cluster_Count>MaxCountSameElementInTrace || streamItem.Trace_Segment_Cluster_Block_Count>MaxCountSameElementInTrace))
2793             Element_Children_IfNoErrors();
2794     #endif // MEDIAINFO_TRACE
2795 }
2796 
2797 //---------------------------------------------------------------------------
Segment_Cluster_BlockGroup_Block_Lace()2798 void File_Mk::Segment_Cluster_BlockGroup_Block_Lace()
2799 {
2800     stream& streamItem=Stream[TrackNumber];
2801 
2802     //Content compression
2803     if (streamItem.ContentCompAlgo!=(int32u)-1 && streamItem.ContentCompAlgo!=3)
2804         streamItem.Searching_Payload=false; //Unsupported
2805 
2806     if (streamItem.Searching_Payload && streamItem.Parser)
2807     {
2808         Element_Parser(streamItem.Parser->ParserName.c_str());
2809 
2810         Element_Code=TrackNumber;
2811 
2812         //Content compression
2813         /* Old method, does not support all needs e.g. 1 complete frame per demux packet
2814         if (streamItem.ContentCompAlgo==3) //Header Stripping
2815         {
2816             Element_Offset-=(size_t)streamItem.ContentCompSettings_Buffer_Size; //This is an extra array, not in the stream
2817             Open_Buffer_Continue(streamItem.Parser, streamItem.ContentCompSettings_Buffer, (size_t)streamItem.ContentCompSettings_Buffer_Size);
2818             Element_Offset+=(size_t)streamItem.ContentCompSettings_Buffer_Size;
2819             Demux(streamItem.ContentCompSettings_Buffer, (size_t)streamItem.ContentCompSettings_Buffer_Size, ContentType_MainStream);
2820         }
2821         */
2822         int8u* Buffer_Stripping=NULL;
2823         const int8u* Save_Buffer=Buffer;
2824         int64u Save_File_Offset=File_Offset;
2825         size_t Save_Buffer_Offset=Buffer_Offset;
2826         int64u Save_Element_Size=Element_Size;
2827         size_t Save_Element_Offset=(size_t)Element_Offset;
2828         if (streamItem.ContentCompAlgo==3) //Header Stripping
2829         {
2830             Element_Size=streamItem.ContentCompSettings_Buffer_Size+Save_Element_Size-Save_Element_Offset;
2831             File_Offset+=Buffer_Offset+Element_Offset-streamItem.ContentCompSettings_Buffer_Size;
2832             Buffer_Offset=0;
2833             Element_Offset=0;
2834             Buffer_Stripping=new int8u[(size_t)Element_Size];
2835             std::memcpy(Buffer_Stripping, streamItem.ContentCompSettings_Buffer, streamItem.ContentCompSettings_Buffer_Size);
2836             std::memcpy(Buffer_Stripping+streamItem.ContentCompSettings_Buffer_Size, Save_Buffer+Save_Buffer_Offset+Save_Element_Offset, Save_Element_Size-Save_Element_Offset);
2837             Buffer=Buffer_Stripping;
2838         }
2839 
2840         //Parsing
2841         if(Laces_Pos)
2842             FrameInfo.PTS=streamItem.Parser->FrameInfo.PTS;
2843         else
2844             streamItem.Parser->FrameInfo.PTS=FrameInfo.PTS;
2845         Frame_Count_NotParsedIncluded=(streamItem.PacketCount==1 && !Laces_Pos)?0:streamItem.Parser->Frame_Count_NotParsedIncluded;
2846         #if MEDIAINFO_DEMUX
2847             int8u Demux_Level_old=Demux_Level;
2848             if (streamItem.Parser && streamItem.Parser->Demux_Level==2)
2849                 Demux_Level=4;
2850             Demux(Buffer+Buffer_Offset+(size_t)Element_Offset, (size_t)(Element_Size-Element_Offset), ContentType_MainStream);
2851             Demux_Level=Demux_Level_old;
2852             streamItem.Parser->FrameInfo.PTS=FrameInfo.PTS;
2853         #endif //MEDIAINFO_DEMUX
2854             Open_Buffer_Continue(streamItem.Parser, (size_t)(Element_Size-Element_Offset));
2855         if (streamItem.Parser->Status[IsFinished]
2856             || (streamItem.PacketCount>=300 && Config->ParseSpeed<1.0)
2857             || (streamItem.PacketCount>=3 && Config->ParseSpeed==0)
2858             )
2859         {
2860             streamItem.Searching_Payload=false;
2861             if (!streamItem.Searching_TimeStamps && !streamItem.Searching_TimeStamp_Start)
2862                 Stream_Count--;
2863         }
2864         FrameInfo.PTS=(int64u)-1;
2865         Frame_Count_NotParsedIncluded=(int64u)-1;
2866 
2867         #if MEDIAINFO_DEMUX
2868             if (Config->Demux_EventWasSent && Config->Demux_Unpacketize_Get())
2869                 Demux_EventWasSent=Element_Code;
2870         #endif //MEDIAINFO_DEMUX
2871 
2872         if (Save_Buffer!=Buffer)
2873         {
2874             //We must change the buffer for keeping out
2875             Element_Offset=Save_Element_Size;
2876             Element_Size=Save_Element_Size;
2877             File_Offset=Save_File_Offset;
2878             Buffer_Offset=Save_Buffer_Offset;
2879             delete[] Buffer; Buffer=Save_Buffer;
2880         }
2881     }
2882     else
2883         Skip_XX(Element_Size-Element_Offset,                    "Data");
2884 
2885     //Filling
2886     Frame_Count++;
2887     if (!Status[IsFilled] && (Stream_Count==0 || Frame_Count>(Config->ParseSpeed?512:3)*Stream.size()))
2888     {
2889         Fill();
2890         if (Config->ParseSpeed<1.0)
2891         {
2892             //Jumping
2893             std::sort(Segment_Seeks.begin(), Segment_Seeks.end());
2894             for (size_t Pos=0; Pos<Segment_Seeks.size(); Pos++)
2895                 if (Segment_Seeks[Pos].SeekPosition>File_Offset+Buffer_Offset+Element_Size)
2896                 {
2897                     JumpTo(Segment_Seeks[Pos].SeekPosition);
2898                     break;
2899                 }
2900             if (File_GoTo==(int64u)-1)
2901             {
2902                 JumpTo(Segment_Offset_End);
2903             }
2904         }
2905 
2906         Laces.clear();
2907     }
2908 
2909     Laces_Pos++;
2910     if (Laces_Pos>=Laces.size())
2911     {
2912         Laces.clear();
2913         Laces_Pos=0;
2914     }
2915 
2916     Element_Show();
2917 
2918     #if MEDIAINFO_TRACE
2919         if (Trace_Activated && (Trace_Segment_Cluster_Count>MaxCountSameElementInTrace || streamItem.Trace_Segment_Cluster_Block_Count>MaxCountSameElementInTrace))
2920             Element_Children_IfNoErrors();
2921     #endif // MEDIAINFO_TRACE
2922 }
2923 
2924 //---------------------------------------------------------------------------
Segment_Cluster_BlockGroup_BlockDuration()2925 void File_Mk::Segment_Cluster_BlockGroup_BlockDuration()
2926 {
2927     //Parsing
2928     int64u Segment_Cluster_TimeCode_Value=UInteger_Get();
2929 
2930     FILLING_BEGIN();
2931         if (Segment_Cluster_BlockGroup_BlockDuration_TrackNumber!=(int64u)-1)
2932         {
2933             Stream[Segment_Cluster_BlockGroup_BlockDuration_TrackNumber].Segment_Cluster_BlockGroup_BlockDuration_Counts[Segment_Cluster_TimeCode_Value]++;
2934             Segment_Cluster_BlockGroup_BlockDuration_TrackNumber=(int64u)-1;
2935         }
2936         else
2937             Segment_Cluster_BlockGroup_BlockDuration_Value=Segment_Cluster_TimeCode_Value;
2938     FILLING_END();
2939 }
2940 
2941 //---------------------------------------------------------------------------
Segment_Cluster_SimpleBlock()2942 void File_Mk::Segment_Cluster_SimpleBlock()
2943 {
2944     Segment_Cluster_BlockGroup_BlockDuration_Value=(int64u)-1;
2945     Segment_Cluster_BlockGroup_BlockDuration_TrackNumber=(int64u)-1;
2946 
2947     Segment_Cluster_BlockGroup_Block();
2948 }
2949 
2950 //---------------------------------------------------------------------------
Segment_Cluster_Timecode()2951 void File_Mk::Segment_Cluster_Timecode()
2952 {
2953     //Parsing
2954     Segment_Cluster_TimeCode_Value=UInteger_Get();
2955 }
2956 
2957 //---------------------------------------------------------------------------
Segment_Cues()2958 void File_Mk::Segment_Cues()
2959 {
2960     //Skipping Cues, we don't need of them
2961     TestMultipleInstances();
2962 
2963     #if MEDIAINFO_TRACE
2964         Trace_Segment_Cues_CuePoint_Count=0;
2965     #endif // MEDIAINFO_TRACE
2966 }
2967 
2968 //---------------------------------------------------------------------------
Segment_Cues_CuePoint()2969 void File_Mk::Segment_Cues_CuePoint()
2970 {
2971     #if MEDIAINFO_TRACE
2972         if (Trace_Activated)
2973         {
2974             if (Trace_Segment_Cues_CuePoint_Count<MaxCountSameElementInTrace)
2975                 Trace_Segment_Cues_CuePoint_Count++;
2976             else
2977                 Element_Set_Remove_Children_IfNoErrors();
2978         }
2979     #endif // MEDIAINFO_TRACE
2980 }
2981 
2982 //---------------------------------------------------------------------------
Segment_Info()2983 void File_Mk::Segment_Info()
2984 {
2985     TestMultipleInstances(&Segment_Info_Count);
2986 }
2987 
2988 //---------------------------------------------------------------------------
Segment_Info_DateUTC()2989 void File_Mk::Segment_Info_DateUTC()
2990 {
2991     //Parsing
2992     int64u Data;
2993     Get_B8(Data,                                                "Data"); Element_Info1(Data/1000000000+978307200); //From Beginning of the millenium, in nanoseconds
2994 
2995     FILLING_BEGIN();
2996         if (Segment_Info_Count>1)
2997             return; //First element has the priority
2998         Fill(Stream_General, 0, "Encoded_Date", Ztring().Date_From_Seconds_1970((int32u)(Data/1000000000+978307200))); //978307200s between beginning of the millenium and 1970
2999     FILLING_END();
3000 }
3001 
3002 //---------------------------------------------------------------------------
Segment_Info_Duration()3003 void File_Mk::Segment_Info_Duration()
3004 {
3005     //Parsing
3006     float64 Float=Float_Get();
3007 
3008     FILLING_BEGIN();
3009         if (Segment_Info_Count>1)
3010             return; //First element has the priority
3011         Duration=Float;
3012     FILLING_END();
3013 }
3014 
3015 //---------------------------------------------------------------------------
Segment_Info_MuxingApp()3016 void File_Mk::Segment_Info_MuxingApp()
3017 {
3018     //Parsing
3019     Ztring Data=UTF8_Get();
3020 
3021     FILLING_BEGIN();
3022         if (Segment_Info_Count>1)
3023             return; //First element has the priority
3024         Fill(Stream_General, 0, "Encoded_Library", Data);
3025     FILLING_END();
3026 }
3027 
3028 //---------------------------------------------------------------------------
Segment_Info_SegmentUID()3029 void File_Mk::Segment_Info_SegmentUID()
3030 {
3031     //Parsing
3032     int128u Data;
3033     Data=UInteger16_Get();
3034 
3035     FILLING_BEGIN();
3036         if (Segment_Info_Count>1)
3037             return; //First element has the priority
3038         string DataString=uint128toString(Data, 10);
3039         Fill(Stream_General, 0, General_UniqueID, DataString);
3040         Fill(Stream_General, 0, General_UniqueID_String, DataString+" (0x"+uint128toString(Data, 16)+')');
3041     FILLING_END();
3042 }
3043 
3044 //---------------------------------------------------------------------------
Segment_Info_TimecodeScale()3045 void File_Mk::Segment_Info_TimecodeScale()
3046 {
3047     //Parsing
3048     int64u UInteger=UInteger_Get();
3049 
3050     FILLING_BEGIN();
3051         if (Segment_Info_Count>1)
3052             return; //First element has the priority
3053         TimecodeScale=UInteger;
3054     FILLING_END();
3055 }
3056 
3057 //---------------------------------------------------------------------------
Segment_Info_Title()3058 void File_Mk::Segment_Info_Title()
3059 {
3060     //Parsing
3061     Ztring Data=UTF8_Get();
3062 
3063     FILLING_BEGIN();
3064         if (Segment_Info_Count>1)
3065             return; //First element has the priority
3066         Fill(Stream_General, 0, "Title", Data);
3067     FILLING_END();
3068 }
3069 
3070 //---------------------------------------------------------------------------
Segment_Info_WritingApp()3071 void File_Mk::Segment_Info_WritingApp()
3072 {
3073     //Parsing
3074     Ztring Data=UTF8_Get();
3075 
3076     FILLING_BEGIN();
3077         if (Segment_Info_Count>1)
3078             return; //First element has the priority
3079         Fill(Stream_General, 0, "Encoded_Application", Data);
3080     FILLING_END();
3081 }
3082 
3083 //---------------------------------------------------------------------------
Segment_SeekHead()3084 void File_Mk::Segment_SeekHead()
3085 {
3086     Segment_Seeks.clear();
3087 
3088     #if MEDIAINFO_TRACE
3089         Trace_Segment_SeekHead_Seek_Count=0;
3090     #endif // MEDIAINFO_TRACE
3091 }
3092 
3093 //---------------------------------------------------------------------------
Segment_SeekHead_Seek()3094 void File_Mk::Segment_SeekHead_Seek()
3095 {
3096     #if MEDIAINFO_TRACE
3097         if (Trace_Activated)
3098         {
3099             if (Trace_Segment_SeekHead_Seek_Count<MaxCountSameElementInTrace)
3100                 Trace_Segment_SeekHead_Seek_Count++;
3101             else
3102                 Element_Set_Remove_Children_IfNoErrors();
3103         }
3104     #endif // MEDIAINFO_TRACE
3105 
3106     Segment_Seeks.resize(Segment_Seeks.size()+1);
3107 }
3108 
3109 //---------------------------------------------------------------------------
Segment_SeekHead_Seek_SeekID()3110 void File_Mk::Segment_SeekHead_Seek_SeekID()
3111 {
3112     //Parsing
3113     int64u Data;
3114     Get_EB (Data,                                               "Data");
3115 
3116     FILLING_BEGIN();
3117         Segment_Seeks.back().SeekID=Data;
3118     FILLING_END();
3119 }
3120 
3121 //---------------------------------------------------------------------------
Segment_SeekHead_Seek_SeekPosition()3122 void File_Mk::Segment_SeekHead_Seek_SeekPosition()
3123 {
3124     //Parsing
3125     int64u Data=UInteger_Get();
3126 
3127     FILLING_BEGIN();
3128         Segment_Seeks.back().SeekPosition=Segment_Offset_Begin+Data;
3129     FILLING_END();
3130     Element_Info1(Ztring::ToZtring(Segment_Offset_Begin+Data, 16));
3131 }
3132 
3133 //---------------------------------------------------------------------------
Segment_Tags()3134 void File_Mk::Segment_Tags()
3135 {
3136     Segment_Tag_SimpleTag_TagNames.clear();
3137 }
3138 
3139 //---------------------------------------------------------------------------
Segment_Tags_Tag()3140 void File_Mk::Segment_Tags_Tag()
3141 {
3142     //Previous tags
3143     tags::iterator Items0 = Segment_Tags_Tag_Items.find((int64u)-1);
3144     if (Items0 != Segment_Tags_Tag_Items.end())
3145     {
3146         tagspertrack &Items = Segment_Tags_Tag_Items[0]; // Creates it if not yet present, else take the previous one
3147 
3148         //Change the key of the current tag
3149         for (tagspertrack::iterator Item=Items0->second.begin(); Item!=Items0->second.end(); ++Item)
3150             Items[Item->first] = Item->second;
3151         Segment_Tags_Tag_Items.erase(Items0);
3152     }
3153 
3154     //Init
3155     Segment_Tags_Tag_Targets_TagTrackUID_Value=0; // Default is all tracks
3156 }
3157 
3158 //---------------------------------------------------------------------------
Segment_Tags_Tag_SimpleTag_TagLanguage()3159 void File_Mk::Segment_Tags_Tag_SimpleTag_TagLanguage()
3160 {
3161     //Parsing
3162     Ztring Data=String_Get();
3163 
3164     FILLING_BEGIN();
3165         //Fill(StreamKind_Last, StreamPos_Last, "Language", Data);
3166     FILLING_END();
3167 }
3168 
3169 //---------------------------------------------------------------------------
Segment_Tags_Tag_SimpleTag_TagName()3170 void File_Mk::Segment_Tags_Tag_SimpleTag_TagName()
3171 {
3172     //Parsing
3173     Ztring TagName=UTF8_Get();
3174 
3175     Segment_Tag_SimpleTag_TagNames.resize(Element_Level-5); //5 is the first level of a tag
3176     Segment_Tag_SimpleTag_TagNames.push_back(TagName);
3177 }
3178 
3179 //---------------------------------------------------------------------------
Segment_Tags_Tag_SimpleTag_TagString()3180 void File_Mk::Segment_Tags_Tag_SimpleTag_TagString()
3181 {
3182     //Parsing
3183     Ztring TagString;
3184     TagString=UTF8_Get();
3185 
3186     if (Segment_Tag_SimpleTag_TagNames.empty())
3187         return;
3188     if (Segment_Tag_SimpleTag_TagNames[0]==__T("AERMS_OF_USE")) Segment_Tag_SimpleTag_TagNames[0]=__T("TermsOfUse"); //Typo in the source file
3189     if (Segment_Tag_SimpleTag_TagNames[0]==__T("BITSPS")) return; //Useless
3190     if (Segment_Tag_SimpleTag_TagNames[0]==__T("COMPATIBLE_BRANDS")) return; //QuickTime techinical info, useless
3191     if (Segment_Tag_SimpleTag_TagNames[0]==__T("CONTENT_TYPE")) Segment_Tag_SimpleTag_TagNames[0]=__T("ContentType");
3192     if (Segment_Tag_SimpleTag_TagNames[0]==__T("COPYRIGHT")) Segment_Tag_SimpleTag_TagNames[0]=__T("Copyright");
3193     if (Segment_Tag_SimpleTag_TagNames[0]==__T("CREATION_TIME")) {Segment_Tag_SimpleTag_TagNames[0]=__T("Encoded_Date"); TagString.insert(0, __T("UTC "));}
3194     if (Segment_Tag_SimpleTag_TagNames[0]==__T("DATE_DIGITIZED")) {Segment_Tag_SimpleTag_TagNames[0]=__T("Mastered_Date"); TagString.insert(0, __T("UTC "));}
3195     if (Segment_Tag_SimpleTag_TagNames[0]==__T("DATE_RELEASE")) Segment_Tag_SimpleTag_TagNames[0]=__T("Released_Date");
3196     if (Segment_Tag_SimpleTag_TagNames[0]==__T("DATE_RELEASED")) Segment_Tag_SimpleTag_TagNames[0]=__T("Released_Date");
3197     if (Segment_Tag_SimpleTag_TagNames[0]==__T("DESCRIPTION")) Segment_Tag_SimpleTag_TagNames[0]=__T("Description");
3198     if (Segment_Tag_SimpleTag_TagNames[0]==__T("ENCODED_BY")) Segment_Tag_SimpleTag_TagNames[0]=__T("EncodedBy");
3199     if (Segment_Tag_SimpleTag_TagNames[0]==__T("ENCODER")) Segment_Tag_SimpleTag_TagNames[0]=__T("Encoded_Library");
3200     if (Segment_Tag_SimpleTag_TagNames[0]==__T("FPS")) return; //Useless
3201     if (Segment_Tag_SimpleTag_TagNames[0]==__T("HANDLER_NAME"))
3202     {
3203         if (TagString.find(__T("Handler"))!=std::string::npos || TagString.find(__T("handler"))!=std::string::npos || TagString.find(__T("vide"))!=std::string::npos || TagString.find(__T("soun"))!=std::string::npos)
3204             return; //This is not a Title
3205         Segment_Tag_SimpleTag_TagNames[0]=__T("Title");
3206     }
3207     if (Segment_Tag_SimpleTag_TagNames[0]==__T("LANGUAGE")) Segment_Tag_SimpleTag_TagNames[0]=__T("Language");
3208     if (Segment_Tag_SimpleTag_TagNames[0]==__T("MAJOR_BRAND")) return; //QuickTime techinical info, useless
3209     if (Segment_Tag_SimpleTag_TagNames[0]==__T("MINOR_VERSION")) return; //QuickTime techinical info, useless
3210     if (Segment_Tag_SimpleTag_TagNames[0]==__T("PART_NUMBER")) Segment_Tag_SimpleTag_TagNames[0]=__T("Track/Position");
3211     if (Segment_Tag_SimpleTag_TagNames[0]==__T("ORIGINAL_MEDIA_TYPE")) Segment_Tag_SimpleTag_TagNames[0]=__T("OriginalSourceForm");
3212     if (Segment_Tag_SimpleTag_TagNames[0]==__T("SAMPLE") && Segment_Tag_SimpleTag_TagNames.size()==2 && Segment_Tag_SimpleTag_TagNames[1]==__T("PART_NUMBER")) return; //Useless
3213     if (Segment_Tag_SimpleTag_TagNames[0]==__T("SAMPLE") && Segment_Tag_SimpleTag_TagNames.size()==2 && Segment_Tag_SimpleTag_TagNames[1]==__T("TITLE")) {Segment_Tag_SimpleTag_TagNames.resize(1); Segment_Tag_SimpleTag_TagNames[0]=__T("Title_More");}
3214     if (Segment_Tag_SimpleTag_TagNames[0]==__T("STEREO_MODE")) return; //Useless
3215     if (Segment_Tag_SimpleTag_TagNames[0]==__T("TERMS_OF_USE")) Segment_Tag_SimpleTag_TagNames[0]=__T("TermsOfUse");
3216     if (Segment_Tag_SimpleTag_TagNames[0]==__T("TIMECODE"))
3217     {
3218         if (TagString.find(__T("Handler"))!=std::string::npos || TagString.find(__T("handler"))!=std::string::npos || TagString.find(__T("vide"))!=std::string::npos || TagString.find(__T("soun"))!=std::string::npos)
3219             return; //This is not a Title
3220         Segment_Tag_SimpleTag_TagNames[0]=__T("TimeCode_FirstFrame");
3221         Segment_Tags_Tag_Items[Segment_Tags_Tag_Targets_TagTrackUID_Value]["TimeCode_Source"]="Matroska tags";
3222     }
3223     if (Segment_Tag_SimpleTag_TagNames[0]==__T("TITLE")) Segment_Tag_SimpleTag_TagNames[0]=__T("Title");
3224     if (Segment_Tag_SimpleTag_TagNames[0]==__T("TOTAL_PARTS")) Segment_Tag_SimpleTag_TagNames[0]=__T("Track/Position_Total");
3225     for (size_t Pos=0; Pos<Segment_Tag_SimpleTag_TagNames.size(); Pos++)
3226     {
3227         if (Segment_Tag_SimpleTag_TagNames[Pos]==__T("BARCODE")) Segment_Tag_SimpleTag_TagNames[Pos]=__T("BarCode");
3228         if (Segment_Tag_SimpleTag_TagNames[Pos]==__T("COMMENT")) Segment_Tag_SimpleTag_TagNames[Pos]=__T("Comment");
3229         if (Segment_Tag_SimpleTag_TagNames[Pos]==__T("ORIGINAL")) Segment_Tag_SimpleTag_TagNames[Pos]=__T("Original");
3230         if (Segment_Tag_SimpleTag_TagNames[Pos]==__T("URL")) Segment_Tag_SimpleTag_TagNames[Pos]=__T("Url");
3231     }
3232 
3233     Ztring TagName;
3234     for (size_t Pos=0; Pos<Segment_Tag_SimpleTag_TagNames.size(); Pos++)
3235     {
3236         TagName+=Segment_Tag_SimpleTag_TagNames[Pos];
3237         if (Pos+1<Segment_Tag_SimpleTag_TagNames.size())
3238             TagName+=__T('/');
3239     }
3240 
3241     Segment_Tags_Tag_Items[Segment_Tags_Tag_Targets_TagTrackUID_Value][TagName]=TagString;
3242 }
3243 
3244 //---------------------------------------------------------------------------
Segment_Tags_Tag_Targets_TagTrackUID()3245 void File_Mk::Segment_Tags_Tag_Targets_TagTrackUID()
3246 {
3247     //Parsing
3248     Segment_Tags_Tag_Targets_TagTrackUID_Value=UInteger_Get();
3249 
3250     FILLING_BEGIN();
3251         tags::iterator Items0 = Segment_Tags_Tag_Items.find((int64u)-1);
3252         if (Items0 != Segment_Tags_Tag_Items.end())
3253         {
3254             tagspertrack &Items = Segment_Tags_Tag_Items[Segment_Tags_Tag_Targets_TagTrackUID_Value]; // Creates it if not yet present, else take the previous one
3255 
3256             //Change the key of the current tag
3257             for (tagspertrack::iterator Item=Items0->second.begin(); Item!=Items0->second.end(); ++Item)
3258                 Items[Item->first] = Item->second;
3259             Segment_Tags_Tag_Items.erase(Items0);
3260         }
3261     FILLING_END();
3262 }
3263 
3264 //---------------------------------------------------------------------------
Segment_Tracks()3265 void File_Mk::Segment_Tracks()
3266 {
3267     TestMultipleInstances(&Segment_Tracks_Count);
3268 
3269     SegmentTrack_Offset_End=File_Offset+Buffer_Offset+Element_TotalSize_Get();
3270 }
3271 
3272 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry()3273 void File_Mk::Segment_Tracks_TrackEntry()
3274 {
3275     if (Segment_Info_Count>1)
3276         return; //First element has the priority
3277 
3278     //Clearing
3279     CodecID.clear();
3280     InfoCodecID_Format_Type=InfoCodecID_Format_Matroska;
3281     TrackType=(int64u)-1;
3282     TrackNumber=(int64u)-1;
3283     AudioBitDepth=(int64u)-1;
3284     TrackVideoDisplayWidth=0;
3285     TrackVideoDisplayHeight=0;
3286     AvgBytesPerSec=0;
3287 
3288     //Preparing
3289     Stream_Prepare(Stream_Max);
3290 
3291     //Default values
3292     Fill_Flush();
3293     Fill(StreamKind_Last, StreamPos_Last, "Language", "eng");
3294     Fill(StreamKind_Last, StreamPos_Last, General_StreamOrder, Stream.size());
3295 }
3296 
3297 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Audio()3298 void File_Mk::Segment_Tracks_TrackEntry_Audio()
3299 {
3300     //Default values
3301     if (StreamKind_Last==Stream_Max)
3302         Stream_Prepare(Stream_Audio);
3303     Fill(Stream_Audio, StreamPos_Last, Audio_Channel_s_, 1);
3304     if (Retrieve_Const(Stream_Audio, StreamPos_Last, Audio_SamplingRate).empty())
3305         Fill(Stream_Audio, StreamPos_Last, Audio_SamplingRate, 8000);
3306     Audio_Manage();
3307 }
3308 
3309 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Audio_BitDepth()3310 void File_Mk::Segment_Tracks_TrackEntry_Audio_BitDepth()
3311 {
3312     //Parsing
3313     int64u UInteger=UInteger_Get();
3314 
3315     FILLING_BEGIN();
3316         if (Segment_Info_Count>1)
3317             return; //First element has the priority
3318         if (UInteger)
3319         {
3320             Fill(StreamKind_Last, StreamPos_Last, "BitDepth", UInteger, 10, true);
3321             Audio_Manage();
3322         }
3323     FILLING_END();
3324 }
3325 
3326 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Audio_Channels()3327 void File_Mk::Segment_Tracks_TrackEntry_Audio_Channels()
3328 {
3329     //Parsing
3330     int64u UInteger=UInteger_Get();
3331 
3332     FILLING_BEGIN();
3333         if (Segment_Info_Count>1)
3334             return; //First element has the priority
3335         if (UInteger)
3336         {
3337             Fill(Stream_Audio, StreamPos_Last, Audio_Channel_s_, UInteger, 10, true);
3338             Audio_Manage();
3339         }
3340     FILLING_END();
3341 }
3342 
3343 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Audio_OutputSamplingFrequency()3344 void File_Mk::Segment_Tracks_TrackEntry_Audio_OutputSamplingFrequency()
3345 {
3346     //Parsing
3347     float64 Float=Float_Get();
3348 
3349     FILLING_BEGIN();
3350         if (Segment_Info_Count>1)
3351             return; //First element has the priority
3352         if (Float)
3353         {
3354             Fill(Stream_Audio, StreamPos_Last, Audio_SamplingRate, Float, 0, true);
3355         }
3356     FILLING_END();
3357 }
3358 
3359 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Audio_SamplingFrequency()3360 void File_Mk::Segment_Tracks_TrackEntry_Audio_SamplingFrequency()
3361 {
3362     //Parsing
3363     float64 Float=Float_Get();
3364 
3365     FILLING_BEGIN();
3366         if (Segment_Info_Count>1)
3367             return; //First element has the priority
3368         if (Float)
3369         {
3370             if (Retrieve(Stream_Audio, StreamPos_Last, Audio_SamplingRate)==__T("8000"))
3371                 Fill(Stream_Audio, StreamPos_Last, Audio_SamplingRate, Float, 0, true);
3372             #ifdef MEDIAINFO_AAC_YES
3373                 if (Retrieve(Stream_Audio, StreamPos_Last, Audio_CodecID).find(__T("A_AAC/"))==0)
3374                     ((File_Aac*)Stream[TrackNumber].Parser)->AudioSpecificConfig_OutOfBand(float64_int64s(Float));
3375             #endif //MEDIAINFO_AAC_YES
3376             Audio_Manage();
3377         }
3378     FILLING_END();
3379 }
3380 
3381 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_CodecID()3382 void File_Mk::Segment_Tracks_TrackEntry_CodecID()
3383 {
3384     //Parsing
3385     Ztring Data=String_Get();
3386 
3387     FILLING_BEGIN();
3388         if (Segment_Info_Count>1)
3389             return; //First element has the priority
3390         CodecID=Data;
3391         CodecID_Manage();
3392         CodecPrivate_Manage();
3393     FILLING_END();
3394 }
3395 
3396 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDType()3397 void File_Mk::Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDType()
3398 {
3399     //Parsing
3400     int32u Value;
3401     Get_C4(Value,                                               "Value");
3402 
3403     FILLING_BEGIN();
3404         BlockAddIDType=Value;
3405     FILLING_END();
3406 }
3407 
3408 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDExtraData()3409 void File_Mk::Segment_Tracks_TrackEntry_BlockAdditionMapping_BlockAddIDExtraData()
3410 {
3411     //Parsing
3412     switch (BlockAddIDType)
3413     {
3414         case 0x64766343: // dvcC
3415         case 0x64767643: // dvvC
3416                 Element_Name("Dolby Vision Configuration");
3417                 dvcC();
3418                 break;
3419         case 0x68766345:
3420                 Element_Name("Dolby Vision EL HEVC");
3421                 #if MEDIAINFO_TRACE
3422                     if (Trace_Activated)
3423                     {
3424                         File_Hevc* Parser=new File_Hevc();
3425                         Parser->FrameIsAlwaysComplete=true;
3426                         Parser->MustSynchronize=false;
3427                         Parser->MustParse_VPS_SPS_PPS=true;
3428                         Parser->SizedBlocks=true;
3429                         Open_Buffer_Init(Parser);
3430                         Open_Buffer_Continue(Parser);
3431                         delete Parser;
3432                     }
3433                 #else
3434                     Skip_XX(Element_Size,                       "HEVCDecoderConfigurationRecord"); //enhancement-layer configuration information required to initialize the Dolby Vision decoder for the enhancement - layer substream
3435                 #endif
3436                 break;
3437         case 0x6D766343:
3438                 Element_Name("MVC configuration");
3439                 #if MEDIAINFO_TRACE
3440                     if (Trace_Activated)
3441                     {
3442                         File_Avc* Parser=new File_Avc();
3443                         Parser->FrameIsAlwaysComplete=true;
3444                         Parser->MustSynchronize=false;
3445                         Parser->MustParse_SPS_PPS=true;
3446                         Parser->SizedBlocks=true;
3447                         Open_Buffer_Init(Parser);
3448                         Open_Buffer_Continue(Parser);
3449                         delete Parser;
3450                     }
3451                 #else
3452                     Skip_XX(Element_Size,                       "MVCDecoderConfigurationRecord");
3453                 #endif
3454                 break;
3455         default:;
3456     }
3457 }
3458 
3459 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression()3460 void File_Mk::Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression()
3461 {
3462     FILLING_BEGIN();
3463         if (Segment_Info_Count>1)
3464             return; //First element has the priority
3465         Stream[TrackNumber].ContentCompAlgo=0; //0 is default
3466         Fill(StreamKind_Last, StreamPos_Last, "MuxingMode", Mk_ContentCompAlgo(0), Unlimited, true, true);
3467     FILLING_END();
3468 }
3469 
3470 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompAlgo()3471 void File_Mk::Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompAlgo()
3472 {
3473     //Parsing
3474     int64u Algo=UInteger_Get(); Param_Info1(Mk_ContentCompAlgo(Algo));
3475 
3476     FILLING_BEGIN();
3477         if (Segment_Info_Count>1)
3478             return; //First element has the priority
3479         Stream[TrackNumber].ContentCompAlgo=Algo;
3480         Fill(StreamKind_Last, StreamPos_Last, "MuxingMode", Mk_ContentCompAlgo(Algo), Unlimited, true, true);
3481     FILLING_END();
3482 }
3483 
3484 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompSettings()3485 void File_Mk::Segment_Tracks_TrackEntry_ContentEncodings_ContentEncoding_ContentCompression_ContentCompSettings()
3486 {
3487     //Parsing
3488     Skip_XX(Element_Size,                                       "Data");
3489 
3490     FILLING_BEGIN();
3491         if (Segment_Info_Count>1)
3492             return; //First element has the priority
3493         stream& streamItem = Stream[TrackNumber];
3494         streamItem.ContentCompSettings_Buffer=new int8u[(size_t)Element_Size];
3495         std::memcpy(streamItem.ContentCompSettings_Buffer, Buffer+Buffer_Offset, (size_t)Element_Size);
3496         streamItem.ContentCompSettings_Buffer_Size=(size_t)Element_Size;
3497     FILLING_END();
3498 }
3499 
3500 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_CodecPrivate()3501 void File_Mk::Segment_Tracks_TrackEntry_CodecPrivate()
3502 {
3503     if (Segment_Info_Count>1)
3504     {
3505         Skip_XX(Element_Size,                                   "Data (not parsed)");
3506         return; //First element has the priority
3507     }
3508     if (TrackNumber==(int64u)-1 || TrackType==(int64u)-1 || Retrieve(Stream[TrackNumber].StreamKind, Stream[TrackNumber].StreamPos, "CodecID").empty())
3509     {
3510         //Codec not already known, saving CodecPrivate
3511         if (CodecPrivate)
3512             delete[] CodecPrivate; //CodecPrivate=NULL.
3513         CodecPrivate_Size=(size_t)Element_Size;
3514         CodecPrivate=new int8u[CodecPrivate_Size];
3515         std::memcpy(CodecPrivate, Buffer+Buffer_Offset, CodecPrivate_Size);
3516         return;
3517     }
3518 
3519     Segment_Tracks_TrackEntry_CodecPrivate__Parse();
3520 }
3521 
3522 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_CodecPrivate__Parse()3523 void File_Mk::Segment_Tracks_TrackEntry_CodecPrivate__Parse()
3524 {
3525     //Creating the parser
3526     stream& streamItem = Stream[TrackNumber];
3527     if (streamItem.Parser==NULL)
3528     {
3529         if (streamItem.StreamKind==Stream_Audio && Retrieve(Stream_Audio, streamItem.StreamPos, Audio_CodecID)==__T("A_MS/ACM"))
3530             Segment_Tracks_TrackEntry_CodecPrivate_auds();
3531         else if (streamItem.StreamKind==Stream_Video && Retrieve(Stream_Video, streamItem.StreamPos, Video_CodecID)==__T("V_MS/VFW/FOURCC"))
3532             Segment_Tracks_TrackEntry_CodecPrivate_vids();
3533         else if (Element_Size>0)
3534             Skip_XX(Element_Size,                 "Unknown");
3535         return;
3536     }
3537 
3538     #if MEDIAINFO_DEMUX
3539         switch (Config->Demux_InitData_Get())
3540         {
3541             case 0 :    //In demux event
3542                         {
3543                         Demux_Level=2; //Container
3544                         int64u Element_Code_Old=Element_Code;
3545                         Element_Code=TrackNumber;
3546                         Demux(Buffer+Buffer_Offset, (size_t)Element_Size, ContentType_Header);
3547                         Element_Code=Element_Code_Old;
3548                         }
3549                         break;
3550             case 1 :    //In field
3551                         {
3552                         std::string Data_Raw((const char*)(Buffer+Buffer_Offset), (size_t)Element_Size);
3553                         std::string Data_Base64(Base64::encode(Data_Raw));
3554                         Fill(StreamKind_Last, StreamPos_Last, "Demux_InitBytes", Data_Base64);
3555                         Fill_SetOptions(StreamKind_Last, StreamPos_Last, "Demux_InitBytes", "N NT");
3556                         }
3557                         break;
3558             default :   ;
3559         }
3560     #endif // MEDIAINFO_DEMUX
3561 
3562     //Parsing
3563     Open_Buffer_OutOfBand(streamItem.Parser);
3564 
3565     //Filling
3566     if (!streamItem.Parser->Status[IsFinished]) //Can be finnished here...
3567         streamItem.Searching_Payload=true;
3568 
3569     //In case of problem
3570     Element_Show();
3571 }
3572 
3573 //--------------------------------------------------------------------------
Segment_Tracks_TrackEntry_CodecPrivate_auds()3574 void File_Mk::Segment_Tracks_TrackEntry_CodecPrivate_auds()
3575 {
3576     Element_Info1("Copy of auds");
3577 
3578     //Parsing
3579     int32u SamplesPerSec;
3580     int16u FormatTag, Channels, BitsPerSample;
3581     Get_L2 (FormatTag,                                          "FormatTag");
3582     Get_L2 (Channels,                                           "Channels");
3583     Get_L4 (SamplesPerSec,                                      "SamplesPerSec");
3584     Get_L4 (AvgBytesPerSec,                                     "AvgBytesPerSec");
3585     Skip_L2(                                                    "BlockAlign");
3586     Get_L2 (BitsPerSample,                                      "BitsPerSample");
3587 
3588     //Filling
3589     FILLING_BEGIN();
3590         InfoCodecID_Format_Type=InfoCodecID_Format_Riff;
3591         CodecID.From_Number(FormatTag, 16);
3592         CodecID_Fill(CodecID, Stream_Audio, StreamPos_Last, InfoCodecID_Format_Riff);
3593         Fill(Stream_Audio, StreamPos_Last, Audio_Codec, CodecID, true); //May be replaced by codec parser
3594         Fill(Stream_Audio, StreamPos_Last, Audio_Codec_CC, CodecID);
3595         Fill(Stream_Audio, StreamPos_Last, Audio_Channel_s_, Channels!=5?Channels:6, 10, true);
3596         Fill(Stream_Audio, StreamPos_Last, Audio_SamplingRate, SamplesPerSec, 10, true);
3597         Fill(Stream_Audio, StreamPos_Last, Audio_BitRate, AvgBytesPerSec*8, 10, true);
3598         if (BitsPerSample)
3599             Fill(Stream_Audio, StreamPos_Last, Audio_BitDepth, BitsPerSample);
3600 
3601         CodecID_Manage();
3602         if (TrackNumber!=(int64u)-1)
3603             Stream[TrackNumber].AvgBytesPerSec=AvgBytesPerSec;
3604     FILLING_END();
3605 
3606     //Options
3607     if (Element_Offset+2>Element_Size)
3608         return; //No options
3609 
3610     //Parsing
3611     int16u Option_Size;
3612     Get_L2 (Option_Size,                                        "cbSize");
3613 
3614     //Filling
3615     if (Option_Size>0)
3616     {
3617              if (FormatTag==0xFFFE) //Extensible Wave
3618             Segment_Tracks_TrackEntry_CodecPrivate_auds_ExtensibleWave(BitsPerSample);
3619         else Skip_XX(Option_Size,                               "Unknown");
3620     }
3621 }
3622 
3623 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_CodecPrivate_auds_ExtensibleWave(int16u BitsPerSample)3624 void File_Mk::Segment_Tracks_TrackEntry_CodecPrivate_auds_ExtensibleWave(int16u BitsPerSample)
3625 {
3626     //Parsing
3627     int128u SubFormat;
3628     int32u ChannelMask;
3629     int16u ValidBitsPerSample;
3630     Get_L2 (ValidBitsPerSample,                                 "ValidBitsPerSample / SamplesPerBlock");
3631     Get_L4 (ChannelMask,                                        "ChannelMask");
3632     Get_GUID(SubFormat,                                         "SubFormat");
3633 
3634     FILLING_BEGIN();
3635         if ((SubFormat.hi&0x0000FFFFFFFFFFFFLL)==0x0000000000001000LL && SubFormat.lo==0x800000AA00389B71LL)
3636         {
3637             int16u LegacyCodecID=(int16u)((((SubFormat.hi>>48)&0xFF)<<8) | (SubFormat.hi>>56)); // It is Little Endian
3638             CodecID_Fill(Ztring().From_Number(LegacyCodecID, 16), Stream_Audio, StreamPos_Last, InfoCodecID_Format_Riff);
3639             Ztring CodecID_New=Retrieve(Stream_Audio, StreamPos_Last, Audio_CodecID);
3640             Fill(Stream_Audio, StreamPos_Last, Audio_CodecID, __T("A_MS/ACM / ")+Ztring().From_GUID(SubFormat), true);
3641             Fill(Stream_Audio, StreamPos_Last, Audio_Codec, MediaInfoLib::Config.Codec_Get(Ztring().From_Number(LegacyCodecID, 16)), true);
3642 
3643             //Creating the parser
3644             #if defined(MEDIAINFO_PCM_YES)
3645             if (MediaInfoLib::Config.CodecID_Get(Stream_Audio, InfoCodecID_Format_Riff, Ztring().From_Number(LegacyCodecID, 16))==__T("PCM"))
3646             {
3647                 //Creating the parser
3648                 File_Pcm MI;
3649                 MI.Frame_Count_Valid=0;
3650                 MI.Codec=Ztring().From_GUID(SubFormat);
3651                 MI.BitDepth=(int8u)BitsPerSample;
3652                 if (ValidBitsPerSample!=BitsPerSample)
3653                     MI.BitDepth_Significant=(int8u)ValidBitsPerSample;
3654 
3655                 //Parsing
3656                 Open_Buffer_Init(&MI);
3657                 Open_Buffer_Continue(&MI, 0);
3658 
3659                 //Filling
3660                 Finish(&MI);
3661                 Merge(MI, StreamKind_Last, 0, StreamPos_Last);
3662             }
3663             #endif
3664         }
3665         else
3666         {
3667             CodecID_Fill(Ztring().From_GUID(SubFormat), Stream_Audio, StreamPos_Last, InfoCodecID_Format_Riff);
3668         }
3669         Fill(Stream_Audio, StreamPos_Last, Audio_ChannelPositions, ExtensibleWave_ChannelMask(ChannelMask));
3670         Fill(Stream_Audio, StreamPos_Last, Audio_ChannelPositions_String2, ExtensibleWave_ChannelMask2(ChannelMask));
3671         Fill(Stream_Audio, StreamPos_Last, Audio_ChannelLayout, ExtensibleWave_ChannelMask_ChannelLayout(ChannelMask));
3672     FILLING_END();
3673 }
3674 
3675 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_CodecPrivate_vids()3676 void File_Mk::Segment_Tracks_TrackEntry_CodecPrivate_vids()
3677 {
3678     Element_Info1("Copy of vids");
3679 
3680     //Parsing
3681     int32u Size, Width, Height, Compression;
3682     int16u Resolution;
3683     Get_L4 (Size,                                               "Size");
3684     Get_L4 (Width,                                              "Width");
3685     Get_L4 (Height,                                             "Height");
3686     Skip_L2(                                                    "Planes");
3687     Get_L2 (Resolution,                                         "BitCount");
3688     Get_C4 (Compression,                                        "Compression");
3689     Skip_L4(                                                    "SizeImage");
3690     Skip_L4(                                                    "XPelsPerMeter");
3691     Skip_L4(                                                    "YPelsPerMeter");
3692     Skip_L4(                                                    "ClrUsed");
3693     Skip_L4(                                                    "ClrImportant");
3694 
3695     FILLING_BEGIN();
3696         Ztring Codec;
3697         if (((Compression&0x000000FF)>=0x00000020 && (Compression&0x000000FF)<=0x0000007E
3698           && (Compression&0x0000FF00)>=0x00002000 && (Compression&0x0000FF00)<=0x00007E00
3699           && (Compression&0x00FF0000)>=0x00200000 && (Compression&0x00FF0000)<=0x007E0000
3700           && (Compression&0xFF000000)>=0x20000000 && (Compression&0xFF000000)<=0x7E000000)
3701          ||   Compression==0x00000000
3702            ) //Sometimes this value is wrong, we have to test this
3703         {
3704             //Filling
3705             InfoCodecID_Format_Type=InfoCodecID_Format_Riff;
3706             CodecID.From_CC4(Compression);
3707             if (Compression==0x00000000)
3708             {
3709                 Fill(Stream_Video, StreamPos_Last, Video_Format, "RGB", Unlimited, true, true);
3710                 Fill(Stream_Video, StreamPos_Last, Video_Codec, "RGB", Unlimited, true, true); //Raw RGB, not handled by automatic codec mapping
3711             }
3712             else
3713             {
3714                 CodecID_Fill(CodecID, Stream_Video, StreamPos_Last, InfoCodecID_Format_Riff);
3715                 Fill(Stream_Video, StreamPos_Last, Video_Codec, CodecID, true); //FormatTag, may be replaced by codec parser
3716                 Fill(Stream_Video, StreamPos_Last, Video_Codec_CC, CodecID); //FormatTag
3717             }
3718             Fill(Stream_Video, StreamPos_Last, Video_Width, Width, 10, true);
3719             Fill(Stream_Video, StreamPos_Last, Video_Height, Height, 10, true);
3720             if (Resolution==32 && Compression==0x74736363) //tscc
3721                 Fill(StreamKind_Last, StreamPos_Last, "BitDepth", 8);
3722             else if (Compression==0x44495633) //DIV3
3723                 Fill(StreamKind_Last, StreamPos_Last, "BitDepth", 8);
3724             else if (Compression==0x44585342) //DXSB
3725                 Fill(StreamKind_Last, StreamPos_Last, "BitDepth", Resolution);
3726             else if (Resolution>16 && MediaInfoLib::Config.CodecID_Get(StreamKind_Last, InfoCodecID_Format_Riff, Ztring().From_CC4(Compression), InfoCodecID_ColorSpace).find(__T("RGBA"))!=std::string::npos) //RGB codecs
3727                 Fill(StreamKind_Last, StreamPos_Last, "BitDepth", Resolution/4);
3728             else if (Compression==0x00000000 //RGB
3729                   || MediaInfoLib::Config.CodecID_Get(StreamKind_Last, InfoCodecID_Format_Riff, Ztring().From_CC4(Compression), InfoCodecID_ColorSpace).find(__T("RGB"))!=std::string::npos) //RGB codecs
3730             {
3731                 if (Resolution==32)
3732                 {
3733                     Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Format), "RGBA", Unlimited, true, true);
3734                     Fill(StreamKind_Last, StreamPos_Last, "BitDepth", Resolution/4); //With Alpha
3735                 }
3736                 else
3737                     Fill(StreamKind_Last, StreamPos_Last, "BitDepth", Resolution<=16?8:(Resolution/3)); //indexed or normal
3738             }
3739             else if (Compression==0x56503632 //VP62
3740                   || MediaInfoLib::Config.CodecID_Get(StreamKind_Last, InfoCodecID_Format_Riff, Ztring().From_CC4(Compression), InfoCodecID_Format)==__T("H.263") //H.263
3741                   || MediaInfoLib::Config.CodecID_Get(StreamKind_Last, InfoCodecID_Format_Riff, Ztring().From_CC4(Compression), InfoCodecID_Format)==__T("VC-1")) //VC-1
3742                 Fill(StreamKind_Last, StreamPos_Last, "BitDepth", Resolution/3);
3743         }
3744 
3745         //Creating the parser
3746         CodecID_Manage();
3747 
3748     FILLING_END();
3749 
3750     if (Data_Remain())
3751     {
3752         Element_Begin1("Private data");
3753         if (Size>Element_Size)
3754             Size=Element_Size;
3755         Open_Buffer_OutOfBand(Stream[TrackNumber].Parser, Size-Element_Offset);
3756         Element_End0();
3757 
3758         if (Element_Offset<Element_Size)
3759             Skip_XX(Element_Size-Element_Offset,                "Padding");
3760     }
3761 }
3762 
3763 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_DefaultDuration()3764 void File_Mk::Segment_Tracks_TrackEntry_DefaultDuration()
3765 {
3766     //Parsing
3767     int64u UInteger=UInteger_Get();
3768 
3769     FILLING_BEGIN();
3770         if (Segment_Info_Count>1)
3771             return; //First element has the priority
3772         Stream[TrackNumber].TrackDefaultDuration=UInteger;
3773     FILLING_END();
3774 }
3775 
3776 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_FlagDefault()3777 void File_Mk::Segment_Tracks_TrackEntry_FlagDefault()
3778 {
3779     //Parsing
3780     int64u UInteger=UInteger_Get();
3781 
3782     FILLING_BEGIN();
3783         if (Segment_Info_Count>1)
3784             return; //First element has the priority
3785         Stream[TrackNumber].Default=UInteger?true:false;
3786     FILLING_END();
3787 }
3788 
3789 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_FlagForced()3790 void File_Mk::Segment_Tracks_TrackEntry_FlagForced()
3791 {
3792     //Parsing
3793     int64u UInteger=UInteger_Get();
3794 
3795     FILLING_BEGIN();
3796         if (Segment_Info_Count>1)
3797             return; //First element has the priority
3798         Stream[TrackNumber].Forced=UInteger?true:false;
3799     FILLING_END();
3800 }
3801 
3802 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Language()3803 void File_Mk::Segment_Tracks_TrackEntry_Language()
3804 {
3805     //Parsing
3806     Ztring Data=String_Get();
3807 
3808     FILLING_BEGIN();
3809         if (Segment_Info_Count>1)
3810             return; //First element has the priority
3811         Fill(StreamKind_Last, StreamPos_Last, "Language", Data, true);
3812     FILLING_END();
3813 }
3814 
3815 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Name()3816 void File_Mk::Segment_Tracks_TrackEntry_Name()
3817 {
3818     //Parsing
3819     Ztring Data;
3820     Get_UTF8(Element_Size, Data,                               "Data"); Element_Info1(Data);
3821 
3822     FILLING_BEGIN();
3823         if (Segment_Info_Count>1)
3824             return; //First element has the priority
3825         Fill(StreamKind_Last, StreamPos_Last, "Title", Data);
3826     FILLING_END();
3827 }
3828 
3829 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_TrackNumber()3830 void File_Mk::Segment_Tracks_TrackEntry_TrackNumber()
3831 {
3832     //Parsing
3833     TrackNumber=UInteger_Get();
3834 
3835     FILLING_BEGIN();
3836         if (Segment_Info_Count>1)
3837             return; //First element has the priority
3838         Fill(StreamKind_Last, StreamPos_Last, General_ID, TrackNumber);
3839         stream& streamItem = Stream[TrackNumber];
3840         if (StreamKind_Last!=Stream_Max)
3841         {
3842             streamItem.StreamKind=StreamKind_Last;
3843             streamItem.StreamPos=StreamPos_Last;
3844         }
3845         if (TrackVideoDisplayWidth && TrackVideoDisplayHeight)
3846             streamItem.DisplayAspectRatio=((float)TrackVideoDisplayWidth)/(float)TrackVideoDisplayHeight;
3847         if (AvgBytesPerSec)
3848             streamItem.AvgBytesPerSec=AvgBytesPerSec;
3849 
3850         CodecID_Manage();
3851         CodecPrivate_Manage();
3852     FILLING_END();
3853 }
3854 
3855 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_TrackType()3856 void File_Mk::Segment_Tracks_TrackEntry_TrackType()
3857 {
3858     //Parsing
3859     int64u UInteger=UInteger_Get();
3860 
3861     //Filling
3862     FILLING_BEGIN();
3863         if (Segment_Info_Count>1)
3864             return; //First element has the priority
3865         TrackType=UInteger;
3866         if (StreamKind_Last==Stream_Max)
3867         {
3868             switch(UInteger)
3869             {
3870                 case 0x01 :
3871                             Stream_Prepare(Stream_Video);
3872                             break;
3873                 case 0x02 :
3874                             Stream_Prepare(Stream_Audio);
3875                             break;
3876                 case 0x11 :
3877                             Stream_Prepare(Stream_Text);
3878                             break;
3879                 default   : ;
3880             }
3881         }
3882 
3883         if (TrackNumber!=(int64u)-1 && StreamKind_Last!=Stream_Max)
3884         {
3885             stream& streamItem = Stream[TrackNumber];
3886             streamItem.StreamKind=StreamKind_Last;
3887             streamItem.StreamPos=StreamPos_Last;
3888         }
3889 
3890         CodecID_Manage();
3891         CodecPrivate_Manage();
3892     FILLING_END();
3893 }
3894 
3895 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_TrackUID()3896 void File_Mk::Segment_Tracks_TrackEntry_TrackUID()
3897 {
3898     //Parsing
3899     int64u UInteger=UInteger_Get();
3900 
3901     //Filling
3902     FILLING_BEGIN();
3903         if (Segment_Info_Count>1)
3904             return; //First element has the priority
3905         Stream[TrackNumber].TrackUID=UInteger;
3906         Fill(StreamKind_Last, StreamPos_Last, General_UniqueID, UInteger);
3907     FILLING_END();
3908 }
3909 
3910 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video()3911 void File_Mk::Segment_Tracks_TrackEntry_Video()
3912 {
3913     //Preparing
3914     if (Segment_Info_Count>1)
3915         return; //First element has the priority
3916     if (StreamKind_Last==Stream_Max)
3917         Stream_Prepare(Stream_Video);
3918     TrackVideoDisplayWidth=0;
3919     TrackVideoDisplayHeight=0;
3920 }
3921 
3922 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_DisplayHeight()3923 void File_Mk::Segment_Tracks_TrackEntry_Video_DisplayHeight()
3924 {
3925     //Parsing
3926     int64u UInteger=UInteger_Get();
3927 
3928     //Filling
3929     FILLING_BEGIN();
3930         if (Segment_Info_Count>1)
3931             return; //First element has the priority
3932         TrackVideoDisplayHeight=UInteger;
3933         if (TrackNumber!=(int64u)-1 && TrackVideoDisplayWidth && TrackVideoDisplayHeight)
3934             Stream[TrackNumber].DisplayAspectRatio=((float)TrackVideoDisplayWidth)/(float)TrackVideoDisplayHeight;
3935     FILLING_END();
3936 }
3937 
3938 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_DisplayWidth()3939 void File_Mk::Segment_Tracks_TrackEntry_Video_DisplayWidth()
3940 {
3941     //Parsing
3942     int64u UInteger=UInteger_Get();
3943 
3944     //Filling
3945     FILLING_BEGIN();
3946         if (Segment_Info_Count>1)
3947             return; //First element has the priority
3948         TrackVideoDisplayWidth=UInteger;
3949         if (TrackNumber!=(int64u)-1 && TrackVideoDisplayWidth && TrackVideoDisplayHeight)
3950             Stream[TrackNumber].DisplayAspectRatio=((float)TrackVideoDisplayWidth)/(float)TrackVideoDisplayHeight;
3951     FILLING_END();
3952 }
3953 
3954 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_FrameRate()3955 void File_Mk::Segment_Tracks_TrackEntry_Video_FrameRate()
3956 {
3957     //Parsing
3958    float64 Value=Float_Get();
3959 
3960     //Filling
3961     FILLING_BEGIN();
3962         if (Segment_Info_Count>1)
3963             return; //First element has the priority
3964         Stream[TrackNumber].FrameRate=Value;
3965     FILLING_END();
3966 }
3967 
3968 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_MatrixCoefficients()3969 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_MatrixCoefficients()
3970 {
3971     //Parsing
3972     int64u UInteger=UInteger_Get(); Element_Info1(Mpegv_matrix_coefficients(UInteger));
3973 
3974     //Filling
3975     FILLING_BEGIN();
3976         if (Segment_Info_Count>1)
3977             return; //First element has the priority
3978         Stream[TrackNumber].Infos["colour_description_present"]="Yes";
3979         Stream[TrackNumber].Infos["matrix_coefficients"]=Mpegv_matrix_coefficients(UInteger);
3980         Stream[TrackNumber].Infos["ColorSpace"]=Mpegv_matrix_coefficients_ColorSpace(UInteger);
3981     FILLING_END();
3982 }
3983 
3984 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_BitsPerChannel()3985 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_BitsPerChannel()
3986 {
3987     //Parsing
3988     UInteger_Info();
3989 }
3990 
3991 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_Range()3992 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_Range()
3993 {
3994     //Parsing
3995     int64u UInteger=UInteger_Get(); Element_Info1(Mk_Video_Colour_Range(UInteger));
3996 
3997     //Filling
3998     FILLING_BEGIN();
3999         if (Segment_Info_Count>1)
4000             return; //First element has the priority
4001         Stream[TrackNumber].Infos["colour_description_present"]="Yes";
4002         Stream[TrackNumber].Infos["colour_range"]=Mk_Video_Colour_Range(UInteger);
4003     FILLING_END();
4004 }
4005 
4006 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_TransferCharacteristics()4007 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_TransferCharacteristics()
4008 {
4009     //Parsing
4010     int64u UInteger=UInteger_Get(); Element_Info1(Mpegv_transfer_characteristics(UInteger));
4011 
4012     //Filling
4013     FILLING_BEGIN();
4014         if (Segment_Info_Count>1)
4015             return; //First element has the priority
4016         Stream[TrackNumber].Infos["colour_description_present"]="Yes";
4017         Stream[TrackNumber].Infos["transfer_characteristics"]=Mpegv_transfer_characteristics(UInteger);
4018     FILLING_END();
4019 }
4020 
4021 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_Primaries()4022 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_Primaries()
4023 {
4024     //Parsing
4025     int64u UInteger=UInteger_Get(); Element_Info1(Mpegv_colour_primaries(UInteger));
4026 
4027     //Filling
4028     FILLING_BEGIN();
4029         if (Segment_Info_Count>1)
4030             return; //First element has the priority
4031         Stream[TrackNumber].Infos["colour_description_present"]="Yes";
4032         Stream[TrackNumber].Infos["colour_primaries"]=Mpegv_colour_primaries(UInteger);
4033     FILLING_END();
4034 }
4035 
4036 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_MaxCLL()4037 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_MaxCLL()
4038 {
4039     //Parsing
4040     int64u UInteger=UInteger_Get();
4041 
4042     //Filling
4043     FILLING_BEGIN();
4044         if (Segment_Info_Count>1)
4045             return; //First element has the priority
4046         Stream[TrackNumber].Infos["MaxCLL"].From_Number(UInteger);
4047     FILLING_END();
4048 }
4049 
4050 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_MaxFALL()4051 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_MaxFALL()
4052 {
4053     //Parsing
4054     int64u UInteger=UInteger_Get();
4055 
4056     //Filling
4057     FILLING_BEGIN();
4058         if (Segment_Info_Count>1)
4059             return; //First element has the priority
4060         Stream[TrackNumber].Infos["MaxFALL"].From_Number(UInteger);
4061     FILLING_END();
4062 }
4063 
4064 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_PixelCropBottom()4065 void File_Mk::Segment_Tracks_TrackEntry_Video_PixelCropBottom()
4066 {
4067     //Parsing
4068     int64u UInteger=UInteger_Get();
4069 
4070     //Filling
4071     FILLING_BEGIN();
4072         if (Segment_Info_Count>1)
4073             return; //First element has the priority
4074         Stream[TrackNumber].PixelCropBottom=UInteger;
4075     FILLING_END();
4076 }
4077 
4078 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_PixelCropLeft()4079 void File_Mk::Segment_Tracks_TrackEntry_Video_PixelCropLeft()
4080 {
4081     //Parsing
4082     int64u UInteger=UInteger_Get();
4083 
4084     //Filling
4085     FILLING_BEGIN();
4086         if (Segment_Info_Count>1)
4087             return; //First element has the priority
4088         Stream[TrackNumber].PixelCropLeft=UInteger;
4089     FILLING_END();
4090 }
4091 
4092 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_PixelCropRight()4093 void File_Mk::Segment_Tracks_TrackEntry_Video_PixelCropRight()
4094 {
4095     //Parsing
4096     int64u UInteger=UInteger_Get();
4097 
4098     //Filling
4099     FILLING_BEGIN();
4100         if (Segment_Info_Count>1)
4101             return; //First element has the priority
4102         Stream[TrackNumber].PixelCropRight=UInteger;
4103     FILLING_END();
4104 }
4105 
4106 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_PixelCropTop()4107 void File_Mk::Segment_Tracks_TrackEntry_Video_PixelCropTop()
4108 {
4109     //Parsing
4110     int64u UInteger=UInteger_Get();
4111 
4112     //Filling
4113     FILLING_BEGIN();
4114         if (Segment_Info_Count>1)
4115             return; //First element has the priority
4116         Stream[TrackNumber].PixelCropTop=UInteger;
4117     FILLING_END();
4118 }
4119 
4120 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_PixelHeight()4121 void File_Mk::Segment_Tracks_TrackEntry_Video_PixelHeight()
4122 {
4123     //Parsing
4124     int64u UInteger=UInteger_Get();
4125 
4126     //Filling
4127     FILLING_BEGIN();
4128         if (Segment_Info_Count>1)
4129             return; //First element has the priority
4130         Fill(Stream_Video, StreamPos_Last, Video_Height, UInteger, 10, true);
4131         if (!TrackVideoDisplayHeight)
4132             TrackVideoDisplayHeight=UInteger; //Default value of DisplayHeight is PixelHeight
4133 
4134         //In case CodecID was defined before this item, some decoders are not initialized with the correct values, filling it now
4135         #if defined(MEDIAINFO_FFV1_YES)
4136             const Ztring &Format=Retrieve(Stream_Video, StreamPos_Last, Video_Format);
4137             stream& streamItem = Stream[TrackNumber];
4138             if (0);
4139         #endif
4140         #if defined(MEDIAINFO_FFV1_YES)
4141         else if (Format==__T("FFV1"))
4142         {
4143             File_Ffv1* parser = (File_Ffv1*)streamItem.Parser;
4144             parser->Height=UInteger;
4145         }
4146         #endif
4147     FILLING_END();
4148 }
4149 
4150 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_PixelWidth()4151 void File_Mk::Segment_Tracks_TrackEntry_Video_PixelWidth()
4152 {
4153     //Parsing
4154     int64u UInteger=UInteger_Get();
4155 
4156     //Filling
4157     FILLING_BEGIN();
4158         if (Segment_Info_Count>1)
4159             return; //First element has the priority
4160         Fill(Stream_Video, StreamPos_Last, Video_Width, UInteger, 10, true);
4161         if (!TrackVideoDisplayWidth)
4162             TrackVideoDisplayWidth=UInteger; //Default value of DisplayWidth is PixelWidth
4163 
4164         //In case CodecID was defined before this item, some decoders are not initialized with the correct values, filling it now
4165         #if defined(MEDIAINFO_FFV1_YES)
4166             const Ztring &Format=Retrieve(Stream_Video, StreamPos_Last, Video_Format);
4167             stream& streamItem = Stream[TrackNumber];
4168             if (0);
4169         #endif
4170         #if defined(MEDIAINFO_FFV1_YES)
4171         else if (Format==__T("FFV1"))
4172         {
4173             File_Ffv1* parser = (File_Ffv1*)streamItem.Parser;
4174             parser->Width=UInteger;
4175         }
4176         #endif
4177     FILLING_END();
4178 }
4179 
4180 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_FieldOrder()4181 void File_Mk::Segment_Tracks_TrackEntry_Video_FieldOrder()
4182 {
4183     //Parsing
4184     int64u UInteger=UInteger_Get();
4185 
4186     //Filling
4187     FILLING_BEGIN();
4188         // Same as MOV
4189         switch(UInteger)
4190         {
4191             case  1 :
4192             case  9 :
4193             case  6 :
4194             case 14 :
4195                         Fill(Stream_Video, StreamPos_Last, Video_ScanType, "Interlaced", Unlimited, true, true);
4196                         break;
4197             default  :  ;
4198         }
4199         switch(UInteger)
4200         {
4201             case  1 :   // T is displayed earliest, T is stored first in the file.
4202             case  9 :   // B is displayed earliest, T is stored first in the file.
4203                         Fill(Stream_Video, StreamPos_Last, Video_ScanOrder, "TFF", Unlimited, true, true);
4204                         break;
4205             case  6 :   // B is displayed earliest, B is stored first in the file.
4206             case 14 :   // T is displayed earliest, B is stored first in the file.
4207                         Fill(Stream_Video, StreamPos_Last, Video_ScanOrder, "BFF", Unlimited, true, true);
4208                         break;
4209             default  :  ;
4210         }
4211         switch (UInteger)
4212         {
4213             case  1 :   // Separated fields, TFF
4214             case  6 :   // Separated fields, BFF
4215                         Fill(Stream_Video, StreamPos_Last, Video_ScanType_StoreMethod_FieldsPerBlock, 2, 10, true);
4216                         Fill(Stream_Video, StreamPos_Last, Video_ScanType_StoreMethod, "SeparatedFields", Unlimited, true, true);
4217                         break;
4218             case  9 :   // Interleaved fields, TFF
4219             case 14 :   // Interleaved fields, BFF
4220                         Fill(Stream_Video, StreamPos_Last, Video_ScanType_StoreMethod, "InterleavedFields", Unlimited, true, true);
4221                         break;
4222             default  :  ;
4223         }
4224     FILLING_END();
4225 }
4226 
4227 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_StereoMode()4228 void File_Mk::Segment_Tracks_TrackEntry_Video_StereoMode()
4229 {
4230     //Parsing
4231     int64u UInteger=UInteger_Get(); Element_Info1(Mk_StereoMode(UInteger));
4232 
4233     //Filling
4234     FILLING_BEGIN();
4235         if (Segment_Info_Count>1)
4236             return; //First element has the priority
4237         Fill(Stream_Video, StreamPos_Last, Video_MultiView_Count, 2); //Matroska seems to be limited to 2 views
4238         Fill(Stream_Video, StreamPos_Last, Video_MultiView_Layout, Mk_StereoMode(UInteger));
4239     FILLING_END();
4240 }
4241 
4242 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_OldStereoMode()4243 void File_Mk::Segment_Tracks_TrackEntry_Video_OldStereoMode()
4244 {
4245     //Parsing
4246     int64u UInteger=UInteger_Get(); Element_Info1(Mk_StereoMode(UInteger));
4247 
4248     //Filling
4249     FILLING_BEGIN();
4250         if (Segment_Info_Count>1)
4251             return; //First element has the priority
4252         Fill(Stream_Video, StreamPos_Last, Video_MultiView_Count, 2); //Matroska seems to be limited to 2 views
4253         Fill(Stream_Video, StreamPos_Last, Video_MultiView_Layout, Mk_StereoMode(UInteger));
4254     FILLING_END();
4255 }
4256 
4257 //***************************************************************************
4258 // Data
4259 //***************************************************************************
4260 
4261 //---------------------------------------------------------------------------
UInteger_Info()4262 void File_Mk::UInteger_Info()
4263 {
4264     switch (Element_Size)
4265     {
4266         case 1 :
4267                 {
4268                     Info_B1(Data,                               "Data"); Element_Info1(Data);
4269                     return;
4270                 }
4271         case 2 :
4272                 {
4273                     Info_B2(Data,                               "Data"); Element_Info1(Data);
4274                     return;
4275                 }
4276         case 3 :
4277                 {
4278                     Info_B3(Data,                               "Data"); Element_Info1(Data);
4279                     return;
4280                 }
4281         case 4 :
4282                 {
4283                     Info_B4(Data,                               "Data"); Element_Info1(Data);
4284                     return;
4285                 }
4286         case 5 :
4287                 {
4288                     Info_B5(Data,                               "Data"); Element_Info1(Data);
4289                     return;
4290                 }
4291         case 6 :
4292                 {
4293                     Info_B6(Data,                               "Data"); Element_Info1(Data);
4294                     return;
4295                 }
4296         case 7 :
4297                 {
4298                     Info_B7(Data,                               "Data"); Element_Info1(Data);
4299                     return;
4300                 }
4301         case 8 :
4302                 {
4303                     Info_B8(Data,                               "Data"); Element_Info1(Data);
4304                     return;
4305                 }
4306         case 16:
4307                 {
4308                     Info_B16(Data,                              "Data"); Element_Info1(Data);
4309                     return;
4310                 }
4311         default : Skip_XX(Element_Size,                         "Data");
4312     }
4313 }
4314 
4315 //---------------------------------------------------------------------------
UInteger_Get()4316 int64u File_Mk::UInteger_Get()
4317 {
4318     switch (Element_Size)
4319     {
4320         case 1 :
4321                 {
4322                     int8u Data;
4323                     Get_B1 (Data,                               "Data"); Element_Info1(Data);
4324                     return Data;
4325                 }
4326         case 2 :
4327                 {
4328                     int16u Data;
4329                     Get_B2 (Data,                               "Data"); Element_Info1(Data);
4330                     return Data;
4331                 }
4332         case 3 :
4333                 {
4334                     int32u Data;
4335                     Get_B3 (Data,                               "Data"); Element_Info1(Data);
4336                     return Data;
4337                 }
4338         case 4 :
4339                 {
4340                     int32u Data;
4341                     Get_B4 (Data,                               "Data"); Element_Info1(Data);
4342                     return Data;
4343                 }
4344         case 5 :
4345                 {
4346                     int64u Data;
4347                     Get_B5 (Data,                               "Data"); Element_Info1(Data);
4348                     return Data;
4349                 }
4350         case 6 :
4351                 {
4352                     int64u Data;
4353                     Get_B6 (Data,                               "Data"); Element_Info1(Data);
4354                     return Data;
4355                 }
4356         case 7 :
4357                 {
4358                     int64u Data;
4359                     Get_B7 (Data,                               "Data"); Element_Info1(Data);
4360                     return Data;
4361                 }
4362         case 8 :
4363                 {
4364                     int64u Data;
4365                     Get_B8 (Data,                               "Data"); Element_Info1(Data);
4366                     return Data;
4367                 }
4368         default :   Skip_XX(Element_Size,                       "Data");
4369                     return 0;
4370     }
4371 }
4372 
4373 //---------------------------------------------------------------------------
UInteger16_Get()4374 int128u File_Mk::UInteger16_Get()
4375 {
4376     switch (Element_Size)
4377     {
4378         case 1 :
4379                 {
4380                     int8u Data;
4381                     Get_B1 (Data,                               "Data"); Element_Info1(Data);
4382                     return Data;
4383                 }
4384         case 2 :
4385                 {
4386                     int16u Data;
4387                     Get_B2 (Data,                               "Data"); Element_Info1(Data);
4388                     return Data;
4389                 }
4390         case 3 :
4391                 {
4392                     int32u Data;
4393                     Get_B3 (Data,                               "Data"); Element_Info1(Data);
4394                     return Data;
4395                 }
4396         case 4 :
4397                 {
4398                     int32u Data;
4399                     Get_B4 (Data,                               "Data"); Element_Info1(Data);
4400                     return Data;
4401                 }
4402         case 5 :
4403                 {
4404                     int64u Data;
4405                     Get_B5 (Data,                               "Data"); Element_Info1(Data);
4406                     return Data;
4407                 }
4408         case 6 :
4409                 {
4410                     int64u Data;
4411                     Get_B6 (Data,                               "Data"); Element_Info1(Data);
4412                     return Data;
4413                 }
4414         case 7 :
4415                 {
4416                     int64u Data;
4417                     Get_B7 (Data,                               "Data"); Element_Info1(Data);
4418                     return Data;
4419                 }
4420         case 8 :
4421                 {
4422                     int64u Data;
4423                     Get_B8 (Data,                               "Data"); Element_Info1(Data);
4424                     return Data;
4425                 }
4426         case 16:
4427                 {
4428                     int128u Data;
4429                     Get_B16(Data,                               "Data"); Element_Info1(Data);
4430                     return Data;
4431                 }
4432         default :   Skip_XX(Element_Size,                       "Data");
4433                     return 0;
4434     }
4435 }
4436 
4437 //---------------------------------------------------------------------------
Float_Get()4438 float64 File_Mk::Float_Get()
4439 {
4440     switch (Element_Size)
4441     {
4442         case 4 :
4443                 {
4444                     float32 Data;
4445                     Get_BF4(Data,                               "Data"); Element_Info1(Data);
4446                     return Data;
4447                 }
4448         case 8 :
4449                 {
4450                     float64 Data;
4451                     Get_BF8(Data,                               "Data"); Element_Info1(Data);
4452                     return Data;
4453                 }
4454         default :   Skip_XX(Element_Size,                       "Data");
4455                     return 0.0;
4456     }
4457 }
4458 
4459 //---------------------------------------------------------------------------
Float_Info()4460 void File_Mk::Float_Info()
4461 {
4462     switch (Element_Size)
4463     {
4464         case 4 :
4465                 {
4466                     Info_BF4(Data,                              "Data"); Element_Info1(Data);
4467                     return;
4468                 }
4469         case 8 :
4470                 {
4471                     Info_BF8(Data,                              "Data"); Element_Info1(Data);
4472                     return;
4473                 }
4474         default :   Skip_XX(Element_Size,                       "Data");
4475                     return;
4476     }
4477 }
4478 
4479 //---------------------------------------------------------------------------
UTF8_Get()4480 Ztring File_Mk::UTF8_Get()
4481 {
4482     Ztring Data;
4483     Get_UTF8(Element_Size, Data,                                "Data"); Element_Info1(Data);
4484     return Data;
4485 }
4486 
4487 //---------------------------------------------------------------------------
UTF8_Info()4488 void File_Mk::UTF8_Info()
4489 {
4490     Info_UTF8(Element_Size, Data,                               "Data"); Element_Info1(Data);
4491 }
4492 
4493 //---------------------------------------------------------------------------
String_Get()4494 Ztring File_Mk::String_Get()
4495 {
4496     Ztring Data;
4497     Get_UTF8(Element_Size, Data,                                "Data"); Element_Info1(Data);
4498     #if MEDIAINFO_TRACE
4499         if (Trace_Activated)
4500         {
4501             //Check that this is printable ASCII (0x20-0x7F) content only, accepting trailing NULL bytes
4502             size_t s=Data.size();
4503             while (s && !Data[s-1])
4504                 s--;
4505             for (size_t i=0; i<s; i++)
4506                 if (Data[i]<0x20 || Data[i]>=0x80)
4507                 {
4508                     Param_Error("EBML-ASCII-ONLY-IN-STRING:1");
4509                     break;
4510                 }
4511         }
4512     #endif //MEDIAINFO_TRACE
4513     return Data;
4514 }
4515 
4516 //---------------------------------------------------------------------------
String_Info()4517 void File_Mk::String_Info()
4518 {
4519     #if MEDIAINFO_TRACE
4520         String_Get(); //TODO: optimize by removal useless string copies
4521     #else //MEDIAINFO_TRACE
4522         Info_UTF8(Element_Size, Data,                               "Data"); Element_Info1(Data);
4523     #endif //MEDIAINFO_TRACE
4524 }
4525 
4526 //***************************************************************************
4527 // Helpers
4528 //***************************************************************************
4529 
4530 //---------------------------------------------------------------------------
CodecID_Manage()4531 void File_Mk::CodecID_Manage()
4532 {
4533     if (TrackType==(int64u)-1 || TrackNumber==(int64u)-1 || CodecID.empty() || Stream[TrackNumber].Parser)
4534         return; //Not ready (or not needed)
4535 
4536     if (Retrieve(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_CodecID)).empty())
4537     {
4538         CodecID_Fill(CodecID, StreamKind_Last, StreamPos_Last, InfoCodecID_Format_Matroska);
4539         Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Codec), CodecID);
4540     }
4541     stream& streamItem = Stream[TrackNumber];
4542 
4543     //Creating the parser
4544     #if defined(MEDIAINFO_MPEG4V_YES) || defined(MEDIAINFO_AV1_YES) || defined(MEDIAINFO_AVC_YES) || defined(MEDIAINFO_HEVC_YES) || defined(MEDIAINFO_VC1_YES) || defined(MEDIAINFO_DIRAC_YES) || defined(MEDIAINFO_MPEGV_YES) || defined(MEDIAINFO_VP8_YES) || defined(MEDIAINFO_VP9_YES) || defined(MEDIAINFO_OGG_YES) || defined(MEDIAINFO_DTS_YES)
4545         const Ztring &Format=MediaInfoLib::Config.CodecID_Get(StreamKind_Last, InfoCodecID_Format_Type, CodecID, InfoCodecID_Format);
4546     #endif
4547         if (0);
4548     #if defined(MEDIAINFO_MPEG4V_YES)
4549     else if (Format==__T("MPEG-4 Visual"))
4550     {
4551         streamItem.Parser=new File_Mpeg4v;
4552         ((File_Mpeg4v*)streamItem.Parser)->FrameIsAlwaysComplete=true;
4553     }
4554     #endif
4555     #if defined(MEDIAINFO_AV1_YES)
4556     else if (Format==__T("AV1"))
4557     {
4558         File_Av1* Parser=new File_Av1;
4559         Parser->FrameIsAlwaysComplete=true;
4560         streamItem.Parser=Parser;
4561     }
4562     #endif
4563     #if defined(MEDIAINFO_AVC_YES)
4564     else if (Format==__T("AVC"))
4565     {
4566         File_Avc* parser = new File_Avc;
4567         streamItem.Parser= parser;
4568         ((File_Avc*)streamItem.Parser)->FrameIsAlwaysComplete=true;
4569         if (InfoCodecID_Format_Type==InfoCodecID_Format_Matroska)
4570         {
4571             parser->MustSynchronize=false;
4572             parser->MustParse_SPS_PPS=true;
4573             parser->SizedBlocks=true;
4574             #if MEDIAINFO_DEMUX
4575                 if (Config->Demux_Avc_Transcode_Iso14496_15_to_Iso14496_10_Get())
4576                 {
4577                     streamItem.Parser->Demux_Level=2; //Container
4578                     streamItem.Parser->Demux_UnpacketizeContainer=true;
4579                 }
4580             #endif //MEDIAINFO_DEMUX
4581         }
4582     }
4583     #endif
4584     #if defined(MEDIAINFO_HUFFYUV_YES)
4585     else if (Format==__T("DV"))
4586     {
4587         streamItem.Parser=new File_DvDif;
4588     }
4589     #endif
4590     #if defined(MEDIAINFO_HEVC_YES)
4591     else if (Format==__T("HEVC"))
4592     {
4593         File_Hevc* parser = new File_Hevc;
4594         streamItem.Parser = parser;
4595         parser->FrameIsAlwaysComplete=true;
4596         if (InfoCodecID_Format_Type==InfoCodecID_Format_Matroska)
4597         {
4598             parser->MustSynchronize=false;
4599             parser->MustParse_VPS_SPS_PPS=true;
4600             parser->MustParse_VPS_SPS_PPS_FromMatroska=true;
4601             parser->SizedBlocks=true;
4602             #if MEDIAINFO_DEMUX
4603                 if (Config->Demux_Hevc_Transcode_Iso14496_15_to_AnnexB_Get())
4604                 {
4605                     streamItem.Parser->Demux_Level=2; //Container
4606                     streamItem.Parser->Demux_UnpacketizeContainer=true;
4607                 }
4608             #endif //MEDIAINFO_DEMUX
4609         }
4610     }
4611     #endif
4612     #if defined(MEDIAINFO_FFV1_YES)
4613     else if (Format==__T("FFV1"))
4614     {
4615         File_Ffv1* parser = new File_Ffv1;
4616         streamItem.Parser = parser;
4617         parser->Width=Retrieve(Stream_Video, StreamPos_Last, Video_Width).To_int32u();
4618         parser->Height=Retrieve(Stream_Video, StreamPos_Last, Video_Height).To_int32u();
4619     }
4620     #endif
4621     #if defined(MEDIAINFO_HUFFYUV_YES)
4622     else if (Format==__T("HuffYUV"))
4623     {
4624         streamItem.Parser=new File_HuffYuv;
4625     }
4626     #endif
4627     #if defined(MEDIAINFO_VC1_YES)
4628     else if (Format==__T("VC-1"))
4629     {
4630         File_Vc1* parser = new File_Vc1;
4631         streamItem.Parser= parser;
4632         parser->FrameIsAlwaysComplete=true;
4633     }
4634     #endif
4635     #if defined(MEDIAINFO_DIRAC_YES)
4636     else if (Format==__T("Dirac"))
4637     {
4638         streamItem.Parser=new File_Dirac;
4639     }
4640     #endif
4641     #if defined(MEDIAINFO_MPEGV_YES)
4642     else if (Format==__T("MPEG Video"))
4643     {
4644         File_Mpegv* parser = new File_Mpegv;
4645         streamItem.Parser = parser;
4646         parser->FrameIsAlwaysComplete=true;
4647     }
4648     #endif
4649     #if defined(MEDIAINFO_PRORES_YES)
4650     else if (Format==__T("ProRes"))
4651     {
4652         streamItem.Parser=new File_ProRes;
4653     }
4654     #endif
4655     #if defined(MEDIAINFO_VP8_YES)
4656     else if (Format==__T("VP8"))
4657     {
4658         streamItem.Parser=new File_Vp8;
4659     }
4660     #endif
4661     #if defined(MEDIAINFO_OGG_YES)
4662     else if (Format==__T("Theora")  || Format==__T("Vorbis"))
4663     {
4664         File_Ogg* parser = new File_Ogg;
4665         streamItem.Parser = parser;
4666         streamItem.Parser->MustSynchronize=false;
4667         parser->XiphLacing=true;
4668     }
4669     #endif
4670     #if defined(MEDIAINFO_RM_YES)
4671     else if (CodecID.find(__T("V_REAL/"))==0)
4672     {
4673         File_Rm* parser = new File_Rm;
4674         streamItem.Parser = parser;
4675         parser->FromMKV_StreamType=Stream_Video;
4676     }
4677     #endif
4678     #if defined(MEDIAINFO_AC3_YES)
4679     else if (Format==__T("AC-3") || Format==__T("E-AC-3") || Format==__T("TrueHD"))
4680     {
4681         streamItem.Parser=new File_Ac3;
4682     }
4683     #endif
4684     #if defined(MEDIAINFO_DTS_YES)
4685     else if (Format==__T("DTS"))
4686     {
4687         streamItem.Parser=new File_Dts;
4688     }
4689     #endif
4690     #if defined(MEDIAINFO_AAC_YES)
4691     else if (CodecID==(__T("A_AAC")))
4692     {
4693         File_Aac* parser = new File_Aac;
4694         streamItem.Parser = parser;
4695         parser->Mode=File_Aac::Mode_AudioSpecificConfig;
4696     }
4697     #endif
4698     #if defined(MEDIAINFO_AAC_YES)
4699     else if (CodecID.find(__T("A_AAC/"))==0)
4700     {
4701         Ztring Profile;
4702         int8u audioObjectType=0, Version=0, SBR=2, PS=2;
4703              if (CodecID==__T("A_AAC/MPEG2/MAIN"))     {Version=2; Profile=__T("Main");                   audioObjectType=1;}
4704         else if (CodecID==__T("A_AAC/MPEG2/LC"))       {Version=2; Profile=__T("LC");                     audioObjectType=2; SBR=0;}
4705         else if (CodecID==__T("A_AAC/MPEG2/LC/SBR"))   {Version=2; Profile=__T("HE-AAC / LC");            audioObjectType=2; SBR=1;}
4706         else if (CodecID==__T("A_AAC/MPEG2/SSR"))      {Version=2; Profile=__T("SSR");                    audioObjectType=3;}
4707         else if (CodecID==__T("A_AAC/MPEG4/MAIN"))     {Version=4; Profile=__T("Main");                   audioObjectType=1;}
4708         else if (CodecID==__T("A_AAC/MPEG4/LC"))       {Version=4; Profile=__T("LC");                     audioObjectType=2; SBR=0;}
4709         else if (CodecID==__T("A_AAC/MPEG4/LC/SBR"))   {Version=4; Profile=__T("HE-AAC / LC");            audioObjectType=2; SBR=1; PS=0;}
4710         else if (CodecID==__T("A_AAC/MPEG4/LC/SBR/PS")){Version=4; Profile=__T("HE-AACv2 / HE-AAC / LC"); audioObjectType=2; SBR=1; PS=1;}
4711         else if (CodecID==__T("A_AAC/MPEG4/SSR"))      {Version=4; Profile=__T("SSR");                    audioObjectType=3;}
4712         else if (CodecID==__T("A_AAC/MPEG4/LTP"))      {Version=4; Profile=__T("LTP");                    audioObjectType=4;}
4713         else if (CodecID==__T("raac"))                 {           Profile=__T("LC");                     audioObjectType=2;}
4714         else if (CodecID==__T("racp"))                 {           Profile=__T("HE-AAC / LC");            audioObjectType=2; SBR=1; PS=0;}
4715 
4716         if (Version>0)
4717             Fill(Stream_Audio, StreamPos_Last, Audio_Format_Version, Version==2?"Version 2":"Version 4");
4718         Fill(Stream_Audio, StreamPos_Last, Audio_Format_Profile, Profile);
4719         if (SBR!=2)
4720             Fill(Stream_Audio, StreamPos_Last, Audio_Format_Settings_SBR, SBR?"Yes":"No");
4721         if (PS!=2)
4722             Fill(Stream_Audio, StreamPos_Last, Audio_Format_Settings_PS, PS?"Yes":"No");
4723         int64s sampling_frequency=Retrieve(Stream_Audio, StreamPos_Last, Audio_SamplingRate).To_int64s();
4724 
4725         File_Aac* parser = new File_Aac;
4726         streamItem.Parser = parser;
4727         parser->Mode=File_Aac::Mode_AudioSpecificConfig;
4728         parser->AudioSpecificConfig_OutOfBand(sampling_frequency, audioObjectType, SBR==1?true:false, PS==1?true:false, SBR==1?true:false, PS==1?true:false);
4729     }
4730     #endif
4731     #if defined(MEDIAINFO_AAC_YES)
4732     else if (Format==(__T("AAC")))
4733     {
4734         File_Aac* parser = new File_Aac;
4735         streamItem.Parser = parser;
4736         parser->Mode=File_Aac::Mode_ADTS;
4737     }
4738     #endif
4739     #if defined(MEDIAINFO_MPEGA_YES)
4740     else if (Format==__T("MPEG Audio"))
4741     {
4742         streamItem.Parser=new File_Mpega;
4743     }
4744     #endif
4745     #if defined(MEDIAINFO_FLAC_YES)
4746     else if (Format==__T("Flac"))
4747     {
4748         streamItem.Parser=new File_Flac;
4749     }
4750     #endif
4751     #if defined(MEDIAINFO_OPUS_YES)
4752     else if (CodecID.find(__T("A_OPUS"))==0) //http://wiki.xiph.org/MatroskaOpus
4753     {
4754         streamItem.Parser=new File_Opus;
4755     }
4756     #endif
4757     #if defined(MEDIAINFO_WVPK_YES)
4758     else if (Format==__T("WavPack"))
4759     {
4760         File_Wvpk* parser = new File_Wvpk;
4761         streamItem.Parser = parser;
4762         parser->FromMKV=true;
4763     }
4764     #endif
4765     #if defined(MEDIAINFO_TTA_YES)
4766     else if (Format==__T("TTA"))
4767     {
4768         //streamItem.Parser=new File_Tta; //Parser is not needed, because header is useless and dropped (the parser analyses only the header)
4769     }
4770     #endif
4771     #if defined(MEDIAINFO_PCM_YES)
4772     else if (Format==__T("PCM"))
4773     {
4774         File_Pcm* parser = new File_Pcm;
4775         if (AudioBitDepth!=(int64u)-1)
4776             parser->BitDepth=AudioBitDepth;
4777         streamItem.Parser = parser;
4778         parser->Codec=CodecID;
4779     }
4780     #endif
4781     #if defined(MEDIAINFO_RM_YES)
4782     else if (CodecID.find(__T("A_REAL/"))==0)
4783     {
4784         File_Rm* parser = new File_Rm;
4785         streamItem.Parser = parser;
4786         parser->FromMKV_StreamType=Stream_Audio;
4787     }
4788     #endif
4789     Element_Code=TrackNumber;
4790     Open_Buffer_Init(streamItem.Parser);
4791     Audio_Manage();
4792 
4793     CodecID.clear();
4794 }
4795 
4796 //---------------------------------------------------------------------------
CodecPrivate_Manage()4797 void File_Mk::CodecPrivate_Manage()
4798 {
4799     if (CodecPrivate==NULL || TrackNumber==(int64u)-1 || TrackType==(int64u)-1 || Retrieve(Stream[TrackNumber].StreamKind, Stream[TrackNumber].StreamPos, "CodecID").empty())
4800         return; //Not ready (or not needed)
4801 
4802     //Codec Private is already here, so we can parse it now
4803     const int8u* Buffer_Save=Buffer;
4804     size_t Buffer_Offset_Save=Buffer_Offset;
4805     size_t Buffer_Size_Save=Buffer_Size;
4806     int64u Element_Size_Save=Element_Size;
4807     Buffer=CodecPrivate;
4808     Buffer_Offset=0;
4809     Buffer_Size=CodecPrivate_Size;
4810     Element_Offset=0;
4811     Element_Size=Buffer_Size;
4812     Segment_Tracks_TrackEntry_CodecPrivate__Parse();
4813     Buffer=Buffer_Save;
4814     Buffer_Offset=Buffer_Offset_Save;
4815     Buffer_Size=Buffer_Size_Save;
4816     Element_Size=Element_Size_Save;
4817     Element_Offset=Element_Size_Save;
4818     delete[] CodecPrivate; CodecPrivate=NULL;
4819     CodecPrivate_Size=0;
4820 }
4821 
4822 
4823 //---------------------------------------------------------------------------
Audio_Manage()4824 void File_Mk::Audio_Manage()
4825 {
4826     if (!Stream[TrackNumber].Parser)
4827         return; //Not ready (or not needed)
4828 
4829     const stream& streamItem=Stream[TrackNumber];
4830 
4831     #ifdef MEDIAINFO_PCM_YES
4832         if (streamItem.StreamKind==Stream_Audio && Retrieve(Stream_Audio, streamItem.StreamPos, Audio_Format)==__T("PCM"))
4833         {
4834             File_Pcm* Parser=(File_Pcm*)streamItem.Parser;
4835             int8u Channels=Retrieve(Stream_Audio, StreamPos_Last, Audio_Channel_s_).To_int8u();
4836             if (Channels)
4837                 Parser->Channels=Channels;
4838             int32u SamplingFrequency=Retrieve(Stream_Audio, StreamPos_Last, Audio_SamplingRate).To_int32u();
4839             if (SamplingFrequency)
4840                 Parser->SamplingRate=SamplingFrequency;
4841             int8u BitDepth=Retrieve(Stream_Audio, StreamPos_Last, Audio_BitDepth).To_int8u();
4842             if (BitDepth)
4843             {
4844                 Parser->BitDepth=BitDepth;
4845                 Parser->Sign=(BitDepth==8?'U':'S');
4846             }
4847         }
4848     #endif //MEDIAINFO_PCM_YES
4849 }
4850 
4851 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_Primary(int8u i)4852 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_Primary(int8u i)
4853 {
4854     //Parsing
4855     float Float=Float_Get();
4856 
4857     //Filling
4858     FILLING_BEGIN();
4859         if (Segment_Info_Count>1)
4860             return; //First element has the priority
4861         mastering_metadata_2086& MasteringMetadata=Stream[TrackNumber].MasteringMetadata;
4862         int16u& Value= MasteringMetadata.Primaries[i];
4863         if (Value==(int16u)-1 && Float>=0 && Float<=1)
4864             Value=((int16u)float32_int32s(Float*50000));
4865     FILLING_END();
4866 }
4867 
4868 //---------------------------------------------------------------------------
Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_Luminance(int8u i)4869 void File_Mk::Segment_Tracks_TrackEntry_Video_Colour_MasteringMetadata_Luminance(int8u i)
4870 {
4871     //Parsing
4872     float Float=Float_Get();
4873 
4874     //Filling
4875     FILLING_BEGIN();
4876         if (Segment_Info_Count>1)
4877             return; //First element has the priority
4878         mastering_metadata_2086& MasteringMetadata=Stream[TrackNumber].MasteringMetadata;
4879         int32u& Value= MasteringMetadata.Luminance[i];
4880         if (Value==(int32u)-1 && Float<0x8FFFFFFF/10000)
4881             Value=float32_int32s(Float*10000);
4882     FILLING_END();
4883 }
4884 
4885 //***************************************************************************
4886 // Helpers
4887 //***************************************************************************
4888 
4889 //---------------------------------------------------------------------------
JumpTo(int64u GoToValue)4890 void File_Mk::JumpTo (int64u GoToValue)
4891 {
4892     //Clearing CRC data
4893     for (size_t i = 0; i<CRC32Compute.size(); i++)
4894         if (CRC32Compute[i].UpTo)
4895         {
4896             //Searching and replacing CRC-32 information
4897             //TODO: better implementation without this ugly hack
4898             #if MEDIAINFO_TRACE
4899             element_details::Element_Node *node = Get_Trace_Node(i);
4900             if (node)
4901             {
4902                 std::string ToSearchInInfo=std::string("Not tested ")+Ztring::ToZtring(i).To_UTF8()+' '+Ztring::ToZtring(CRC32Compute[i].Expected).To_UTF8();
4903                 CRC32_Check_In_Node(ToSearchInInfo, "Not tested", node);
4904             }
4905             #endif //MEDIAINFO_TRACE
4906 
4907             CRC32Compute[i].UpTo=0;
4908         }
4909     CRC32Compute.clear();
4910 
4911     //GoTo
4912     Open_Buffer_Unsynch();
4913     GoTo(GoToValue);
4914 }
4915 
4916 //---------------------------------------------------------------------------
4917 //We want to parse more than the 1st element only if one of the following:
4918 //-trace is activated
4919 //-request for parsing all and CRC-32 is present
4920 //TODO: if trace is not activated and CRC-32 is present, we don't need to parse all elements, we only need to do the CRC-32 check
TestMultipleInstances(size_t * Instances)4921 void File_Mk::TestMultipleInstances (size_t* Instances)
4922 {
4923     #if MEDIAINFO_TRACE
4924     bool ParseAll=false;
4925     if (Trace_Activated)
4926         ParseAll=true;
4927     #else //MEDIAINFO_TRACE
4928     static bool ParseAll = false;
4929     #endif //MEDIAINFO_TRACE
4930     if (!ParseAll && Config->ParseSpeed >= 1.0)
4931     {
4932         //Probing, checking if CRC-32 is present
4933         if (Element_Size < 1)
4934         {
4935             Element_WaitForMoreData();
4936             return;
4937         }
4938         #if MEDIAINFO_TRACE
4939         if (Buffer[Buffer_Offset] == 0xBF) //CRC-32 element
4940             ParseAll=true;
4941         #endif //MEDIAINFO_TRACE
4942     }
4943 
4944     if ((!Instances || *Instances) && !ParseAll)
4945         Skip_XX(Element_TotalSize_Get(),                    "No need, skipping");
4946 
4947     if (Instances)
4948         (*Instances)++;
4949 }
4950 
4951 //---------------------------------------------------------------------------
4952 #if MEDIAINFO_TRACE
CRC32_Check_In_Node(const std::string & ToSearchInInfo,const std::string & info,element_details::Element_Node * node)4953 bool File_Mk::CRC32_Check_In_Node(const std::string& ToSearchInInfo, const std::string& info, element_details::Element_Node *node)
4954 {
4955     //Check in the current node
4956     for (size_t i = 0; i < node->Infos.size(); ++i)
4957     {
4958         if (node->Infos[i]->data == ToSearchInInfo)
4959         {
4960             node->Infos[i]->data = info;
4961             return true;
4962         }
4963     }
4964 
4965     //Check in the children of the current node
4966     for (size_t i = 0; i < node->Children.size(); ++i)
4967     {
4968         if (CRC32_Check_In_Node(ToSearchInInfo, info, node->Children[i]))
4969             return true;
4970     }
4971 
4972     return false;
4973 }
4974 #endif // MEDIAINFO_TRACE
4975 
4976 //---------------------------------------------------------------------------
CRC32_Check()4977 void File_Mk::CRC32_Check ()
4978 {
4979     for (size_t i = 0; i<CRC32Compute.size(); i++)
4980         if (CRC32Compute[i].UpTo && File_Offset + Buffer_Offset - (size_t)Header_Size >= CRC32Compute[i].From)
4981         {
4982             //Handling of case when data is not completetely loaded because it is not needed by the parser
4983             const size_t Offset = Buffer_Offset + (size_t)((Element_WantNextLevel && Element_Offset <= Element_Size) ? Element_Offset : Element_Size);
4984             if (Element_Offset > Element_Size)
4985             {
4986                 CRC32Compute_SkipUpTo = File_Offset + Element_Offset;
4987                 Element_Offset = Element_Size;
4988             }
4989 
4990             Matroska_CRC32_Compute(CRC32Compute[i].Computed, Buffer + Buffer_Offset - (size_t)Header_Size, Buffer + Offset);
4991             if (File_Offset + Offset >= CRC32Compute[i].UpTo)
4992             {
4993                 CRC32Compute[i].Computed ^= 0xFFFFFFFF;
4994 
4995                 #if MEDIAINFO_TRACE
4996                     if (Trace_Activated)
4997                     {
4998                         //Searching and replacing CRC-32 information
4999                         //TODO: better implementation without this ugly hack
5000 
5001                         element_details::Element_Node *node = Get_Trace_Node(i);
5002                         if (node)
5003                         {
5004                             std::string ToSearchInInfo=std::string("Not tested ")+Ztring::ToZtring(i).To_UTF8()+' '+Ztring::ToZtring(CRC32Compute[i].Expected).To_UTF8();
5005                             CRC32_Check_In_Node(ToSearchInInfo, CRC32Compute[i].Computed == CRC32Compute[i].Expected?"OK":"NOK", node);
5006 
5007                             #if MEDIAINFO_FIXITY
5008                                 if (Config->TryToFix_Get() && CRC32Compute[i].Computed!=CRC32Compute[i].Expected)
5009                                 {
5010                                     size_t NewBuffer_Size=(size_t)(CRC32Compute[i].UpTo-CRC32Compute[i].From);
5011                                     File F;
5012                                     if (F.Open(File_Name))
5013                                     {
5014                                         int8u* NewBuffer = new int8u[NewBuffer_Size];
5015                                         F.GoTo(CRC32Compute[i].From);
5016                                         F.Read(NewBuffer, NewBuffer_Size);
5017                                         int8u Modified=0;
5018                                         size_t BitPosition=Matroska_TryToFixCRC(NewBuffer, NewBuffer_Size, CRC32Compute[i].Expected, Modified);
5019                                         if (BitPosition!=(size_t)-1)
5020                                         {
5021                                             size_t BytePosition=BitPosition>>3;
5022                                             size_t BitInBytePosition=BitPosition&0x7;
5023                                             Modified^=1<<BitInBytePosition;
5024                                             FixFile(CRC32Compute[i].From+BytePosition, &Modified, 1)?Param_Info1("Fixed"):Param_Info1("Not fixed");
5025                                         }
5026                                         delete[] NewBuffer; //NewBuffer=NULL;
5027                                     }
5028                                 }
5029                             #endif //MEDIAINFO_FIXITY
5030 
5031                         }
5032 
5033                         //Debug
5034                         //size_t Element_Level_Save=Element_Level;
5035                         //Element_Level=i;
5036                         //Element_Info(CRC32Compute[i].Computed == CRC32Compute[i].Expected ? __T("CRC32 check OK"):__T("CRC32 check NOK"));
5037                         //Element_Level=Element_Level_Save;
5038                     }
5039                 #endif //MEDIAINFO_TRACE
5040 
5041                 if (CRC32Compute[i].Computed != CRC32Compute[i].Expected)
5042                 {
5043                     Fill(Stream_General, 0, "CRC_Error_Pos", CRC32Compute[i].Pos);
5044                 }
5045 
5046                 CRC32Compute[i].UpTo=0;
5047             }
5048         }
5049 }
5050 
5051 } //NameSpace
5052 
5053 #endif //MEDIAINFO_MK_YES
5054