source: extensions/charlies_content/getid3/getid3/module.audio-video.matroska.php @ 9130

Last change on this file since 9130 was 3544, checked in by vdigital, 15 years ago

Change: getid3 upgraded to -> 1.7.9

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 113.7 KB
Line 
1<?php
2/////////////////////////////////////////////////////////////////
3/// getID3() by James Heinrich <info@getid3.org>               //
4//  available at http://getid3.sourceforge.net                 //
5//            or http://www.getid3.org                         //
6/////////////////////////////////////////////////////////////////
7// See readme.txt for more details                             //
8/////////////////////////////////////////////////////////////////
9//                                                             //
10// module.audio-video.matriska.php                             //
11// module for analyzing Matroska containers                    //
12// dependencies: NONE                                          //
13//                                                            ///
14/////////////////////////////////////////////////////////////////
15
16
17define('EBML_ID_CHAPTERS',                  0x0043A770); // [10][43][A7][70] -- A system to define basic menus and partition data. For more detailed information, look at the Chapters Explanation.
18define('EBML_ID_SEEKHEAD',                  0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements.
19define('EBML_ID_TAGS',                      0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found here.
20define('EBML_ID_INFO',                      0x0549A966); // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file.
21define('EBML_ID_TRACKS',                    0x0654AE6B); // [16][54][AE][6B] -- A top-level block of information with many tracks described.
22define('EBML_ID_SEGMENT',                   0x08538067); // [18][53][80][67] -- This element contains all other top-level (level 1) elements. Typically a Matroska file is composed of 1 segment.
23define('EBML_ID_ATTACHMENTS',               0x0941A469); // [19][41][A4][69] -- Contain attached files.
24define('EBML_ID_EBML',                      0x0A45DFA3); // [1A][45][DF][A3] -- Set the EBML characteristics of the data to follow. Each EBML document has to start with this.
25define('EBML_ID_CUES',                      0x0C53BB6B); // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment.
26define('EBML_ID_CLUSTER',                   0x0F43B675); // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure.
27define('EBML_ID_LANGUAGE',                    0x02B59C); //     [22][B5][9C] -- Specifies the language of the track in the Matroska languages form.
28define('EBML_ID_TRACKTIMECODESCALE',          0x03314F); //     [23][31][4F] -- The scale to apply on this track to work at normal speed in relation with other tracks (mostly used to adjust video speed when the audio length differs).
29define('EBML_ID_DEFAULTDURATION',             0x03E383); //     [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame.
30define('EBML_ID_CODECNAME',                   0x058688); //     [25][86][88] -- A human-readable string specifying the codec.
31define('EBML_ID_CODECDOWNLOADURL',            0x06B240); //     [26][B2][40] -- A URL to download about the codec used.
32define('EBML_ID_TIMECODESCALE',               0x0AD7B1); //     [2A][D7][B1] -- Timecode scale in nanoseconds (1.000.000 means all timecodes in the segment are expressed in milliseconds).
33define('EBML_ID_COLOURSPACE',                 0x0EB524); //     [2E][B5][24] -- Same value as in AVI (32 bits).
34define('EBML_ID_GAMMAVALUE',                  0x0FB523); //     [2F][B5][23] -- Gamma Value.
35define('EBML_ID_CODECSETTINGS',               0x1A9697); //     [3A][96][97] -- A string describing the encoding setting used.
36define('EBML_ID_CODECINFOURL',                0x1B4040); //     [3B][40][40] -- A URL to find information about the codec used.
37define('EBML_ID_PREVFILENAME',                0x1C83AB); //     [3C][83][AB] -- An escaped filename corresponding to the previous segment.
38define('EBML_ID_PREVUID',                     0x1CB923); //     [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits).
39define('EBML_ID_NEXTFILENAME',                0x1E83BB); //     [3E][83][BB] -- An escaped filename corresponding to the next segment.
40define('EBML_ID_NEXTUID',                     0x1EB923); //     [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits).
41define('EBML_ID_CONTENTCOMPALGO',               0x0254); //         [42][54] -- The compression algorithm used. Algorithms that have been specified so far are:
42define('EBML_ID_CONTENTCOMPSETTINGS',           0x0255); //         [42][55] -- Settings that might be needed by the decompressor. For Header Stripping (ContentCompAlgo=3), the bytes that were removed from the beggining of each frames of the track.
43define('EBML_ID_DOCTYPE',                       0x0282); //         [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case).
44define('EBML_ID_DOCTYPEREADVERSION',            0x0285); //         [42][85] -- The minimum DocType version an interpreter has to support to read this file.
45define('EBML_ID_EBMLVERSION',                   0x0286); //         [42][86] -- The version of EBML parser used to create the file.
46define('EBML_ID_DOCTYPEVERSION',                0x0287); //         [42][87] -- The version of DocType interpreter used to create the file.
47define('EBML_ID_EBMLMAXIDLENGTH',               0x02F2); //         [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska).
48define('EBML_ID_EBMLMAXSIZELENGTH',             0x02F3); //         [42][F3] -- The maximum length of the sizes you'll find in this file (8 or less in Matroska). This does not override the element size indicated at the beginning of an element. Elements that have an indicated size which is larger than what is allowed by EBMLMaxSizeLength shall be considered invalid.
49define('EBML_ID_EBMLREADVERSION',               0x02F7); //         [42][F7] -- The minimum EBML version a parser has to support to read this file.
50define('EBML_ID_CHAPLANGUAGE',                  0x037C); //         [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form.
51define('EBML_ID_CHAPCOUNTRY',                   0x037E); //         [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains.
52define('EBML_ID_SEGMENTFAMILY',                 0x0444); //         [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits).
53define('EBML_ID_DATEUTC',                       0x0461); //         [44][61] -- Date of the origin of timecode (value 0), i.e. production date.
54define('EBML_ID_TAGLANGUAGE',                   0x047A); //         [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form.
55define('EBML_ID_TAGDEFAULT',                    0x0484); //         [44][84] -- Indication to know if this is the default/original language to use for the given tag.
56define('EBML_ID_TAGBINARY',                     0x0485); //         [44][85] -- The values of the Tag if it is binary. Note that this cannot be used in the same SimpleTag as TagString.
57define('EBML_ID_TAGSTRING',                     0x0487); //         [44][87] -- The value of the Tag.
58define('EBML_ID_DURATION',                      0x0489); //         [44][89] -- Duration of the segment (based on TimecodeScale).
59define('EBML_ID_CHAPPROCESSPRIVATE',            0x050D); //         [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent.
60define('EBML_ID_CHAPTERFLAGENABLED',            0x0598); //         [45][98] -- Specify wether the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie should skip all the content between the TimeStart and TimeEnd of this chapter.
61define('EBML_ID_TAGNAME',                       0x05A3); //         [45][A3] -- The name of the Tag that is going to be stored.
62define('EBML_ID_EDITIONENTRY',                  0x05B9); //         [45][B9] -- Contains all information about a segment edition.
63define('EBML_ID_EDITIONUID',                    0x05BC); //         [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition.
64define('EBML_ID_EDITIONFLAGHIDDEN',             0x05BD); //         [45][BD] -- If an edition is hidden (1), it should not be available to the user interface (but still to Control Tracks).
65define('EBML_ID_EDITIONFLAGDEFAULT',            0x05DB); //         [45][DB] -- If a flag is set (1) the edition should be used as the default one.
66define('EBML_ID_EDITIONFLAGORDERED',            0x05DD); //         [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced.
67define('EBML_ID_FILEDATA',                      0x065C); //         [46][5C] -- The data of the file.
68define('EBML_ID_FILEMIMETYPE',                  0x0660); //         [46][60] -- MIME type of the file.
69define('EBML_ID_FILENAME',                      0x066E); //         [46][6E] -- Filename of the attached file.
70define('EBML_ID_FILEREFERRAL',                  0x0675); //         [46][75] -- A binary value that a track/codec can refer to when the attachment is needed.
71define('EBML_ID_FILEDESCRIPTION',               0x067E); //         [46][7E] -- A human-friendly name for the attached file.
72define('EBML_ID_FILEUID',                       0x06AE); //         [46][AE] -- Unique ID representing the file, as random as possible.
73define('EBML_ID_CONTENTENCALGO',                0x07E1); //         [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values:
74define('EBML_ID_CONTENTENCKEYID',               0x07E2); //         [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with.
75define('EBML_ID_CONTENTSIGNATURE',              0x07E3); //         [47][E3] -- A cryptographic signature of the contents.
76define('EBML_ID_CONTENTSIGKEYID',               0x07E4); //         [47][E4] -- This is the ID of the private key the data was signed with.
77define('EBML_ID_CONTENTSIGALGO',                0x07E5); //         [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values:
78define('EBML_ID_CONTENTSIGHASHALGO',            0x07E6); //         [47][E6] -- The hash algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values:
79define('EBML_ID_MUXINGAPP',                     0x0D80); //         [4D][80] -- Muxing application or library ("libmatroska-0.4.3").
80define('EBML_ID_SEEK',                          0x0DBB); //         [4D][BB] -- Contains a single seek entry to an EBML element.
81define('EBML_ID_CONTENTENCODINGORDER',          0x1031); //         [50][31] -- Tells when this modification was used during encoding/muxing starting with 0 and counting upwards. The decoder/demuxer has to start with the highest order number it finds and work its way down. This value has to be unique over all ContentEncodingOrder elements in the segment.
82define('EBML_ID_CONTENTENCODINGSCOPE',          0x1032); //         [50][32] -- A bit field that describes which elements have been modified in this way. Values (big endian) can be OR'ed. Possible values:
83define('EBML_ID_CONTENTENCODINGTYPE',           0x1033); //         [50][33] -- A value describing what kind of transformation has been done. Possible values:
84define('EBML_ID_CONTENTCOMPRESSION',            0x1034); //         [50][34] -- Settings describing the compression used. Must be present if the value of ContentEncodingType is 0 and absent otherwise. Each block must be decompressable even if no previous block is available in order not to prevent seeking.
85define('EBML_ID_CONTENTENCRYPTION',             0x1035); //         [50][35] -- Settings describing the encryption used. Must be present if the value of ContentEncodingType is 1 and absent otherwise.
86define('EBML_ID_CUEREFNUMBER',                  0x135F); //         [53][5F] -- Number of the referenced Block of Track X in the specified Cluster.
87define('EBML_ID_NAME',                          0x136E); //         [53][6E] -- A human-readable track name.
88define('EBML_ID_CUEBLOCKNUMBER',                0x1378); //         [53][78] -- Number of the Block in the specified Cluster.
89define('EBML_ID_TRACKOFFSET',                   0x137F); //         [53][7F] -- A value to add to the Block's Timecode. This can be used to adjust the playback offset of a track.
90define('EBML_ID_SEEKID',                        0x13AB); //         [53][AB] -- The binary ID corresponding to the element name.
91define('EBML_ID_SEEKPOSITION',                  0x13AC); //         [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element).
92define('EBML_ID_STEREOMODE',                    0x13B8); //         [53][B8] -- Stereo-3D video mode on 2 bits (0: mono, 1: right eye, 2: left eye, 3: both eyes).
93define('EBML_ID_PIXELCROPBOTTOM',               0x14AA); //         [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content).
94define('EBML_ID_DISPLAYWIDTH',                  0x14B0); //         [54][B0] -- Width of the video frames to display.
95define('EBML_ID_DISPLAYUNIT',                   0x14B2); //         [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches).
96define('EBML_ID_ASPECTRATIOTYPE',               0x14B3); //         [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed).
97define('EBML_ID_DISPLAYHEIGHT',                 0x14BA); //         [54][BA] -- Height of the video frames to display.
98define('EBML_ID_PIXELCROPTOP',                  0x14BB); //         [54][BB] -- The number of video pixels to remove at the top of the image.
99define('EBML_ID_PIXELCROPLEFT',                 0x14CC); //         [54][CC] -- The number of video pixels to remove on the left of the image.
100define('EBML_ID_PIXELCROPRIGHT',                0x14DD); //         [54][DD] -- The number of video pixels to remove on the right of the image.
101define('EBML_ID_FLAGFORCED',                    0x15AA); //         [55][AA] -- Set if that track MUST be used during playback. There can be many forced track for a kind (audio, video or subs), the player should select the one which language matches the user preference or the default + forced track. Overlay MAY happen between a forced and non-forced track of the same kind.
102define('EBML_ID_MAXBLOCKADDITIONID',            0x15EE); //         [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track.
103define('EBML_ID_WRITINGAPP',                    0x1741); //         [57][41] -- Writing application ("mkvmerge-0.3.3").
104define('EBML_ID_CLUSTERSILENTTRACKS',           0x1854); //         [58][54] -- The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking. Then you should decide what track to use.
105define('EBML_ID_CLUSTERSILENTTRACKNUMBER',      0x18D7); //         [58][D7] -- One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster.
106define('EBML_ID_ATTACHEDFILE',                  0x21A7); //         [61][A7] -- An attached file.
107define('EBML_ID_CONTENTENCODING',               0x2240); //         [62][40] -- Settings for one content encoding like compression or encryption.
108define('EBML_ID_BITDEPTH',                      0x2264); //         [62][64] -- Bits per sample, mostly used for PCM.
109define('EBML_ID_CODECPRIVATE',                  0x23A2); //         [63][A2] -- Private data only known to the codec.
110define('EBML_ID_TARGETS',                       0x23C0); //         [63][C0] -- Contain all UIDs where the specified meta data apply. It is void to describe everything in the segment.
111define('EBML_ID_CHAPTERPHYSICALEQUIV',          0x23C3); //         [63][C3] -- Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50), see complete list of values.
112define('EBML_ID_TAGCHAPTERUID',                 0x23C4); //         [63][C4] -- A unique ID to identify the Chapter(s) the tags belong to. If the value is 0 at this level, the tags apply to all chapters in the Segment.
113define('EBML_ID_TAGTRACKUID',                   0x23C5); //         [63][C5] -- A unique ID to identify the Track(s) the tags belong to. If the value is 0 at this level, the tags apply to all tracks in the Segment.
114define('EBML_ID_ATTACHMENTUID',                 0x23C6); //         [63][C6] -- A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment.
115define('EBML_ID_TAGEDITIONUID',                 0x23C9); //         [63][C9] -- A unique ID to identify the EditionEntry(s) the tags belong to. If the value is 0 at this level, the tags apply to all editions in the Segment.
116define('EBML_ID_TARGETTYPE',                    0x23CA); //         [63][CA] -- An informational string that can be used to display the logical level of the target like "ALBUM", "TRACK", "MOVIE", "CHAPTER", etc (see TargetType).
117define('EBML_ID_TRACKTRANSLATE',                0x2624); //         [66][24] -- The track identification for the given Chapter Codec.
118define('EBML_ID_TRACKTRANSLATETRACKID',         0x26A5); //         [66][A5] -- The binary value used to represent this track in the chapter codec data. The format depends on the ChapProcessCodecID used.
119define('EBML_ID_TRACKTRANSLATECODEC',           0x26BF); //         [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
120define('EBML_ID_TRACKTRANSLATEEDITIONUID',      0x26FC); //         [66][FC] -- Specify an edition UID on which this translation applies. When not specified, it means for all editions found in the segment.
121define('EBML_ID_SIMPLETAG',                     0x27C8); //         [67][C8] -- Contains general information about the target.
122define('EBML_ID_TARGETTYPEVALUE',               0x28CA); //         [68][CA] -- A number to indicate the logical level of the target (see TargetType).
123define('EBML_ID_CHAPPROCESSCOMMAND',            0x2911); //         [69][11] -- Contains all the commands associated to the Atom.
124define('EBML_ID_CHAPPROCESSTIME',               0x2922); //         [69][22] -- Defines when the process command should be handled (0: during the whole chapter, 1: before starting playback, 2: after playback of the chapter).
125define('EBML_ID_CHAPTERTRANSLATE',              0x2924); //         [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment.
126define('EBML_ID_CHAPPROCESSDATA',               0x2933); //         [69][33] -- Contains the command information. The data should be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands.
127define('EBML_ID_CHAPPROCESS',                   0x2944); //         [69][44] -- Contains all the commands associated to the Atom.
128define('EBML_ID_CHAPPROCESSCODECID',            0x2955); //         [69][55] -- Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used. More codec IDs can be added later.
129define('EBML_ID_CHAPTERTRANSLATEID',            0x29A5); //         [69][A5] -- The binary value used to represent this segment in the chapter codec data. The format depends on the ChapProcessCodecID used.
130define('EBML_ID_CHAPTERTRANSLATECODEC',         0x29BF); //         [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
131define('EBML_ID_CHAPTERTRANSLATEEDITIONUID',    0x29FC); //         [69][FC] -- Specify an edition UID on which this correspondance applies. When not specified, it means for all editions found in the segment.
132define('EBML_ID_CONTENTENCODINGS',              0x2D80); //         [6D][80] -- Settings for several content encoding mechanisms like compression or encryption.
133define('EBML_ID_MINCACHE',                      0x2DE7); //         [6D][E7] -- The minimum number of frames a player should be able to cache during playback. If set to 0, the reference pseudo-cache system is not used.
134define('EBML_ID_MAXCACHE',                      0x2DF8); //         [6D][F8] -- The maximum cache size required to store referenced frames in and the current frame. 0 means no cache is needed.
135define('EBML_ID_CHAPTERSEGMENTUID',             0x2E67); //         [6E][67] -- A segment to play in place of this chapter. Edition ChapterSegmentEditionUID should be used for this segment, otherwise no edition is used.
136define('EBML_ID_CHAPTERSEGMENTEDITIONUID',      0x2EBC); //         [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID.
137define('EBML_ID_TRACKOVERLAY',                  0x2FAB); //         [6F][AB] -- Specify that this track is an overlay track for the Track specified (in the u-integer). That means when this track has a gap (see SilentTracks) the overlay track should be used instead. The order of multiple TrackOverlay matters, the first one is the one that should be used. If not found it should be the second, etc.
138define('EBML_ID_TAG',                           0x3373); //         [73][73] -- Element containing elements specific to Tracks/Chapters.
139define('EBML_ID_SEGMENTFILENAME',               0x3384); //         [73][84] -- A filename corresponding to this segment.
140define('EBML_ID_SEGMENTUID',                    0x33A4); //         [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits).
141define('EBML_ID_CHAPTERUID',                    0x33C4); //         [73][C4] -- A unique ID to identify the Chapter.
142define('EBML_ID_TRACKUID',                      0x33C5); //         [73][C5] -- A unique ID to identify the Track. This should be kept the same when making a direct stream copy of the Track to another file.
143define('EBML_ID_ATTACHMENTLINK',                0x3446); //         [74][46] -- The UID of an attachment that is used by this codec.
144define('EBML_ID_CLUSTERBLOCKADDITIONS',         0x35A1); //         [75][A1] -- Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data.
145define('EBML_ID_CHANNELPOSITIONS',              0x347B); //         [7D][7B] -- Table of horizontal angles for each successive channel, see appendix.
146define('EBML_ID_OUTPUTSAMPLINGFREQUENCY',       0x38B5); //         [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques).
147define('EBML_ID_TITLE',                         0x3BA9); //         [7B][A9] -- General name of the segment.
148define('EBML_ID_CHAPTERDISPLAY',                  0x00); //             [80] -- Contains all possible strings to use for the chapter display.
149define('EBML_ID_TRACKTYPE',                       0x03); //             [83] -- A set of track types coded on 8 bits (1: video, 2: audio, 3: complex, 0x10: logo, 0x11: subtitle, 0x12: buttons, 0x20: control).
150define('EBML_ID_CHAPSTRING',                      0x05); //             [85] -- Contains the string to use as the chapter atom.
151define('EBML_ID_CODECID',                         0x06); //             [86] -- An ID corresponding to the codec, see the codec page for more info.
152define('EBML_ID_FLAGDEFAULT',                     0x08); //             [88] -- Set if that track (audio, video or subs) SHOULD be used if no language found matches the user preference.
153define('EBML_ID_CHAPTERTRACKNUMBER',              0x09); //             [89] -- UID of the Track to apply this chapter too. In the absense of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absense of this element indicates that the Chapter should be applied to any currently used Tracks.
154define('EBML_ID_CLUSTERSLICES',                   0x0E); //             [8E] -- Contains slices description.
155define('EBML_ID_CHAPTERTRACK',                    0x0F); //             [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply
156define('EBML_ID_CHAPTERTIMESTART',                0x11); //             [91] -- Timecode of the start of Chapter (not scaled).
157define('EBML_ID_CHAPTERTIMEEND',                  0x12); //             [92] -- Timecode of the end of Chapter (timecode excluded, not scaled).
158define('EBML_ID_CUEREFTIME',                      0x16); //             [96] -- Timecode of the referenced Block.
159define('EBML_ID_CUEREFCLUSTER',                   0x17); //             [97] -- Position of the Cluster containing the referenced Block.
160define('EBML_ID_CHAPTERFLAGHIDDEN',               0x18); //             [98] -- If a chapter is hidden (1), it should not be available to the user interface (but still to Control Tracks).
161define('EBML_ID_FLAGINTERLACED',                  0x1A); //             [9A] -- Set if the video is interlaced.
162define('EBML_ID_CLUSTERBLOCKDURATION',            0x1B); //             [9B] -- The duration of the Block (based on TimecodeScale). This element is mandatory when DefaultDuration is set for the track. When not written and with no DefaultDuration, the value is assumed to be the difference between the timecode of this Block and the timecode of the next Block in "display" order (not coding order). This element can be useful at the end of a Track (as there is not other Block available), or when there is a break in a track like for subtitle tracks.
163define('EBML_ID_FLAGLACING',                      0x1C); //             [9C] -- Set if the track may contain blocks using lacing.
164define('EBML_ID_CHANNELS',                        0x1F); //             [9F] -- Numbers of channels in the track.
165define('EBML_ID_CLUSTERBLOCKGROUP',               0x20); //             [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock.
166define('EBML_ID_CLUSTERBLOCK',                    0x21); //             [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode.
167define('EBML_ID_CLUSTERBLOCKVIRTUAL',             0x22); //             [A2] -- A Block with no data. It must be stored in the stream at the place the real Block should be in display order.
168define('EBML_ID_CLUSTERSIMPLEBLOCK',              0x23); //             [A3] -- Similar to Block but without all the extra information, mostly used to reduced overhead when no extra feature is needed.
169define('EBML_ID_CLUSTERCODECSTATE',               0x24); //             [A4] -- The new codec state to use. Data interpretation is private to the codec. This information should always be referenced by a seek entry.
170define('EBML_ID_CLUSTERBLOCKADDITIONAL',          0x25); //             [A5] -- Interpreted by the codec as it wishes (using the BlockAddID).
171define('EBML_ID_CLUSTERBLOCKMORE',                0x26); //             [A6] -- Contain the BlockAdditional and some parameters.
172define('EBML_ID_CLUSTERPOSITION',                 0x27); //             [A7] -- Position of the Cluster in the segment (0 in live broadcast streams). It might help to resynchronise offset on damaged streams.
173define('EBML_ID_CODECDECODEALL',                  0x2A); //             [AA] -- The codec can decode potentially damaged data.
174define('EBML_ID_CLUSTERPREVSIZE',                 0x2B); //             [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing.
175define('EBML_ID_TRACKENTRY',                      0x2E); //             [AE] -- Describes a track with all elements.
176define('EBML_ID_CLUSTERENCRYPTEDBLOCK',           0x2F); //             [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed).
177define('EBML_ID_PIXELWIDTH',                      0x30); //             [B0] -- Width of the encoded video frames in pixels.
178define('EBML_ID_CUETIME',                         0x33); //             [B3] -- Absolute timecode according to the segment time base.
179define('EBML_ID_SAMPLINGFREQUENCY',               0x35); //             [B5] -- Sampling frequency in Hz.
180define('EBML_ID_CHAPTERATOM',                     0x36); //             [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks).
181define('EBML_ID_CUETRACKPOSITIONS',               0x37); //             [B7] -- Contain positions for different tracks corresponding to the timecode.
182define('EBML_ID_FLAGENABLED',                     0x39); //             [B9] -- Set if the track is used.
183define('EBML_ID_PIXELHEIGHT',                     0x3A); //             [BA] -- Height of the encoded video frames in pixels.
184define('EBML_ID_CUEPOINT',                        0x3B); //             [BB] -- Contains all information relative to a seek point in the segment.
185define('EBML_ID_CRC32',                           0x3F); //             [BF] -- The CRC is computed on all the data of the Master element it's in, regardless of its position. It's recommended to put the CRC value at the beggining of the Master element for easier reading. All level 1 elements should include a CRC-32.
186define('EBML_ID_CLUSTERBLOCKADDITIONID',          0x4B); //             [CB] -- The ID of the BlockAdditional element (0 is the main Block).
187define('EBML_ID_CLUSTERLACENUMBER',               0x4C); //             [CC] -- The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback.
188define('EBML_ID_CLUSTERFRAMENUMBER',              0x4D); //             [CD] -- The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame).
189define('EBML_ID_CLUSTERDELAY',                    0x4E); //             [CE] -- The (scaled) delay to apply to the element.
190define('EBML_ID_CLUSTERDURATION',                 0x4F); //             [CF] -- The (scaled) duration to apply to the element.
191define('EBML_ID_TRACKNUMBER',                     0x57); //             [D7] -- The track number as used in the Block Header (using more than 127 tracks is not encouraged, though the design allows an unlimited number).
192define('EBML_ID_CUEREFERENCE',                    0x5B); //             [DB] -- The Clusters containing the required referenced Blocks.
193define('EBML_ID_VIDEO',                           0x60); //             [E0] -- Video settings.
194define('EBML_ID_AUDIO',                           0x61); //             [E1] -- Audio settings.
195define('EBML_ID_CLUSTERTIMESLICE',                0x68); //             [E8] -- Contains extra time information about the data contained in the Block. While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback.
196define('EBML_ID_CUECODECSTATE',                   0x6A); //             [EA] -- The position of the Codec State corresponding to this Cue element. 0 means that the data is taken from the initial Track Entry.
197define('EBML_ID_CUEREFCODECSTATE',                0x6B); //             [EB] -- The position of the Codec State corresponding to this referenced element. 0 means that the data is taken from the initial Track Entry.
198define('EBML_ID_VOID',                            0x6C); //             [EC] -- Used to void damaged data, to avoid unexpected behaviors when using damaged data. The content is discarded. Also used to reserve space in a sub-element for later use.
199define('EBML_ID_CLUSTERTIMECODE',                 0x67); //             [E7] -- Absolute timecode of the cluster (based on TimecodeScale).
200define('EBML_ID_CLUSTERBLOCKADDID',               0x6E); //             [EE] -- An ID to identify the BlockAdditional level.
201define('EBML_ID_CUECLUSTERPOSITION',              0x71); //             [F1] -- The position of the Cluster containing the required Block.
202define('EBML_ID_CUETRACK',                        0x77); //             [F7] -- The track for which a position is given.
203define('EBML_ID_CLUSTERREFERENCEPRIORITY',        0x7A); //             [FA] -- This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced.
204define('EBML_ID_CLUSTERREFERENCEBLOCK',           0x7B); //             [FB] -- Timecode of another frame used as a reference (ie: B or P frame). The timecode is relative to the block it's attached to.
205define('EBML_ID_CLUSTERREFERENCEVIRTUAL',         0x7D); //             [FD] -- Relative position of the data that should be in position of the virtual block.
206
207
208class getid3_matroska
209{
210        var $read_buffer_size = 32768; // size of read buffer, 32kB is default
211        var $hide_clusters    = true;  // if true, do not return information about CLUSTER chunks, since there's a lot of them and they're not usually useful
212        var $warnings         = array();
213
214        function getid3_matroska(&$fd, &$ThisFileInfo) {
215
216                // http://www.matroska.org/technical/specs/index.html#EBMLBasics
217                $offset = $ThisFileInfo['avdataoffset'];
218                $EBMLdata = '';
219                $EBMLdata_offset = $offset;
220
221                if ($ThisFileInfo['avdataend'] > 2147483648) {
222                        $this->warnings[] = 'This version of getID3() may or may not correctly handle Matroska files larger than 2GB';
223                }
224
225                while ($offset < $ThisFileInfo['avdataend']) {
226                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
227
228                        $top_element_offset    = $offset;
229                        $top_element_id        = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
230                        $top_element_length    = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
231                        if ($top_element_length === false) {
232                                $this->warnings[] = 'invalid chunk length at '.$top_element_offset;
233                                $offset = pow(2, 63);
234                                break;
235                        }
236                        $top_element_endoffset = $offset + $top_element_length;
237                        switch ($top_element_id) {
238                                case EBML_ID_EBML:
239                                        $ThisFileInfo['fileformat'] = 'matroska';
240                                        $ThisFileInfo['matroska']['header']['offset'] = $top_element_offset;
241                                        $ThisFileInfo['matroska']['header']['length'] = $top_element_length;
242
243                                        while ($offset < $top_element_endoffset) {
244                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
245                                                $element_data = array();
246                                                $element_data_offset     = $offset;
247                                                $element_data['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
248                                                $element_data['id_name'] = $this->EBMLidName($element_data['id']);
249                                                $element_data['length']     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
250                                                $end_offset              = $offset + $element_data['length'];
251
252                                                switch ($element_data['id']) {
253                                                        case EBML_ID_EBMLVERSION:
254                                                        case EBML_ID_EBMLREADVERSION:
255                                                        case EBML_ID_EBMLMAXIDLENGTH:
256                                                        case EBML_ID_EBMLMAXSIZELENGTH:
257                                                        case EBML_ID_DOCTYPEVERSION:
258                                                        case EBML_ID_DOCTYPEREADVERSION:
259                                                                $element_data['data'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']));
260                                                                break;
261                                                        case EBML_ID_DOCTYPE:
262                                                                $element_data['data'] =                      trim(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']), "\x00");
263                                                                break;
264                                                        default:
265                                                                $this->warnings[] = 'Unhandled track.video element['.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data_offset;
266                                                                break;
267                                                }
268                                                $offset = $end_offset;
269                                                $ThisFileInfo['matroska']['header']['elements'][] = $element_data;
270                                        }
271                                        break;
272
273
274                                case EBML_ID_SEGMENT:
275                                        $ThisFileInfo['matroska']['segment'][0]['offset'] = $top_element_offset;
276                                        $ThisFileInfo['matroska']['segment'][0]['length'] = $top_element_length;
277
278                                        $segment_key = -1;
279                                        while ($offset < $ThisFileInfo['avdataend']) {
280                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
281
282                                                $element_data = array();
283                                                $element_data['offset']  = $offset;
284                                                $element_data['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
285                                                $element_data['id_name'] = $this->EBMLidName($element_data['id']);
286                                                $element_data['length']  = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
287                                                if ($element_data['length'] === false) {
288                                                        $this->warnings[] = 'invalid chunk length at '.$element_data['offset'];
289                                                        //$offset = pow(2, 63);
290                                                        $offset = $ThisFileInfo['avdataend'];
291                                                        break;
292                                                }
293                                                $element_end             = $offset + $element_data['length'];
294                                                switch ($element_data['id']) {
295                                                        //case EBML_ID_CLUSTER:
296                                                        //      // too many cluster entries, probably not useful
297                                                        //      break;
298                                                        case false:
299                                                                $this->warnings[] = 'invalid ID at '.$element_data['offset'];
300                                                                $offset = $element_end;
301                                                                continue 3;
302                                                        default:
303                                                                $ThisFileInfo['matroska']['segments'][] = $element_data;
304                                                                break;
305                                                }
306                                                $segment_key++;
307
308                                                switch ($element_data['id']) {
309                                                        case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements
310                                                                while ($offset < $element_end) {
311                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
312                                                                        $seek_entry = array();
313                                                                        $seek_entry['offset']  = $offset;
314                                                                        $seek_entry['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
315                                                                        $seek_entry['id_name'] = $this->EBMLidName($seek_entry['id']);
316                                                                        $seek_entry['length']  = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
317                                                                        $seek_end_offset       = $offset + $seek_entry['length'];
318                                                                        switch ($seek_entry['id']) {
319                                                                                case EBML_ID_SEEK: // Contains a single seek entry to an EBML element
320                                                                                        while ($offset < $seek_end_offset) {
321                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
322                                                                                                $id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
323                                                                                                $length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
324                                                                                                $value  =             substr($EBMLdata, $offset - $EBMLdata_offset, $length);
325                                                                                                $offset += $length;
326                                                                                                switch ($id) {
327                                                                                                        case EBML_ID_SEEKID:
328                                                                                                                $dummy = 0;
329                                                                                                                $seek_entry['target_id']   = $this->readEBMLint($value, $dummy);
330                                                                                                                $seek_entry['target_name'] = $this->EBMLidName($seek_entry['target_id']);
331                                                                                                                break;
332                                                                                                        case EBML_ID_SEEKPOSITION:
333                                                                                                                $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($value);
334                                                                                                                break;
335                                                                                                        default:
336                                                                                                                $ThisFileInfo['error'][] = 'Unhandled segment['.__LINE__.'] ('.$id.') at '.$offset;
337                                                                                                                break;
338                                                                                                }
339                                                                                        }
340                                                                                        $ThisFileInfo['matroska']['seek'][] = $seek_entry;
341                                                                                        //switch ($seek_entry['target_id']) {
342                                                                                        //      case EBML_ID_CLUSTER:
343                                                                                        //              // too many cluster seek points, probably not useful
344                                                                                        //              break;
345                                                                                        //      default:
346                                                                                        //              $ThisFileInfo['matroska']['seek'][] = $seek_entry;
347                                                                                        //              break;
348                                                                                        //}
349                                                                                        break;
350                                                                                default:
351                                                                                        $this->warnings[] = 'Unhandled seekhead element['.__LINE__.'] ('.$seek_entry['id'].') at '.$offset;
352                                                                                        break;
353                                                                        }
354                                                                        $offset = $seek_end_offset;
355                                                                }
356                                                                break;
357
358                                                        case EBML_ID_TRACKS: // information about all tracks in segment
359                                                                $ThisFileInfo['matroska']['tracks'] = $element_data;
360                                                                while ($offset < $element_end) {
361                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
362                                                                        $track_entry = array();
363                                                                        $track_entry['offset']  = $offset;
364                                                                        $track_entry['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
365                                                                        $track_entry['id_name'] = $this->EBMLidName($track_entry['id']);
366                                                                        $track_entry['length']  = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
367                                                                        $track_entry_endoffset  = $offset + $track_entry['length'];
368                                                                        switch ($track_entry['id']) {
369                                                                                case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements.
370                                                                                        while ($offset < $track_entry_endoffset) {
371                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
372                                                                                                $subelement_offset = $offset;
373                                                                                                $subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
374                                                                                                $subelement_idname = $this->EBMLidName($subelement_id);
375                                                                                                $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
376                                                                                                $subelement_end    = $offset + $subelement_length;
377                                                                                                switch ($subelement_id) {
378                                                                                                        case EBML_ID_TRACKNUMBER:
379                                                                                                        case EBML_ID_TRACKUID:
380                                                                                                        case EBML_ID_TRACKTYPE:
381                                                                                                        case EBML_ID_MINCACHE:
382                                                                                                        case EBML_ID_MAXCACHE:
383                                                                                                        case EBML_ID_MAXBLOCKADDITIONID:
384                                                                                                        case EBML_ID_DEFAULTDURATION: // nanoseconds per frame
385                                                                                                                $track_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
386                                                                                                                break;
387                                                                                                        case EBML_ID_TRACKTIMECODESCALE:
388                                                                                                                $track_entry[$subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
389                                                                                                                break;
390                                                                                                        case EBML_ID_CODECID:
391                                                                                                        case EBML_ID_LANGUAGE:
392                                                                                                        case EBML_ID_NAME:
393                                                                                                        case EBML_ID_CODECPRIVATE:
394                                                                                                                $track_entry[$subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
395                                                                                                                break;
396                                                                                                        case EBML_ID_FLAGENABLED:
397                                                                                                        case EBML_ID_FLAGDEFAULT:
398                                                                                                        case EBML_ID_FLAGFORCED:
399                                                                                                        case EBML_ID_FLAGLACING:
400                                                                                                        case EBML_ID_CODECDECODEALL:
401                                                                                                                $track_entry[$subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
402                                                                                                                break;
403                                                                                                        case EBML_ID_VIDEO:
404                                                                                                                while ($offset < $subelement_end) {
405                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
406                                                                                                                        $sub_subelement_offset = $offset;
407                                                                                                                        $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
408                                                                                                                        $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
409                                                                                                                        $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
410                                                                                                                        $sub_subelement_end    = $offset + $sub_subelement_length;
411                                                                                                                        switch ($sub_subelement_id) {
412                                                                                                                                case EBML_ID_PIXELWIDTH:
413                                                                                                                                case EBML_ID_PIXELHEIGHT:
414                                                                                                                                case EBML_ID_STEREOMODE:
415                                                                                                                                case EBML_ID_PIXELCROPBOTTOM:
416                                                                                                                                case EBML_ID_PIXELCROPTOP:
417                                                                                                                                case EBML_ID_PIXELCROPLEFT:
418                                                                                                                                case EBML_ID_PIXELCROPRIGHT:
419                                                                                                                                case EBML_ID_DISPLAYWIDTH:
420                                                                                                                                case EBML_ID_DISPLAYHEIGHT:
421                                                                                                                                case EBML_ID_DISPLAYUNIT:
422                                                                                                                                case EBML_ID_ASPECTRATIOTYPE:
423                                                                                                                                        $track_entry[$sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
424                                                                                                                                        break;
425                                                                                                                                case EBML_ID_FLAGINTERLACED:
426                                                                                                                                        $track_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
427                                                                                                                                        break;
428                                                                                                                                case EBML_ID_GAMMAVALUE:
429                                                                                                                                        $track_entry[$sub_subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
430                                                                                                                                        break;
431                                                                                                                                case EBML_ID_COLOURSPACE:
432                                                                                                                                        $track_entry[$sub_subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00");
433                                                                                                                                        break;
434                                                                                                                                default:
435                                                                                                                                        $this->warnings[] = 'Unhandled track.video element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
436                                                                                                                                        break;
437                                                                                                                        }
438                                                                                                                        $offset = $sub_subelement_end;
439                                                                                                                }
440
441                                                                                                                if ((@$track_entry[$this->EBMLidName(EBML_ID_CODECID)] == 'V_MS/VFW/FOURCC') && isset($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)])) {
442                                                                                                                        if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
443                                                                                                                                $track_entry['codec_private_parsed'] = getid3_riff::ParseBITMAPINFOHEADER($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)]);
444                                                                                                                        } else {
445                                                                                                                                $this->warnings[] = 'Unable to parse codec private data['.__LINE__.'] because cannot include "module.audio-video.riff.php"';
446                                                                                                                        }
447                                                                                                                }
448                                                                                                                break;
449                                                                                                        case EBML_ID_AUDIO:
450                                                                                                                while ($offset < $subelement_end) {
451                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
452                                                                                                                        $sub_subelement_offset = $offset;
453                                                                                                                        $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
454                                                                                                                        $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
455                                                                                                                        $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
456                                                                                                                        $sub_subelement_end    = $offset + $sub_subelement_length;
457                                                                                                                        switch ($sub_subelement_id) {
458                                                                                                                                case EBML_ID_CHANNELS:
459                                                                                                                                case EBML_ID_BITDEPTH:
460                                                                                                                                        $track_entry[$sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
461                                                                                                                                        break;
462                                                                                                                                case EBML_ID_SAMPLINGFREQUENCY:
463                                                                                                                                case EBML_ID_OUTPUTSAMPLINGFREQUENCY:
464                                                                                                                                        $track_entry[$sub_subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
465                                                                                                                                        break;
466                                                                                                                                case EBML_ID_CHANNELPOSITIONS:
467                                                                                                                                        $track_entry[$sub_subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00");
468                                                                                                                                        break;
469                                                                                                                                default:
470                                                                                                                                        $this->warnings[] = 'Unhandled track.video element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
471                                                                                                                                        break;
472                                                                                                                        }
473                                                                                                                        $offset = $sub_subelement_end;
474                                                                                                                }
475                                                                                                                break;
476
477                                                                                                        case EBML_ID_CONTENTENCODINGS:
478                                                                                                                while ($offset < $subelement_end) {
479                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
480                                                                                                                        $sub_subelement_offset = $offset;
481                                                                                                                        $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
482                                                                                                                        $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
483                                                                                                                        $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
484                                                                                                                        $sub_subelement_end    = $offset + $sub_subelement_length;
485                                                                                                                        switch ($sub_subelement_id) {
486                                                                                                                                case EBML_ID_CONTENTENCODING:
487                                                                                                                                        while ($offset < $sub_subelement_end) {
488                                                                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
489                                                                                                                                                $sub_sub_subelement_offset = $offset;
490                                                                                                                                                $sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
491                                                                                                                                                $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
492                                                                                                                                                $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
493                                                                                                                                                $sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
494                                                                                                                                                switch ($sub_sub_subelement_id) {
495                                                                                                                                                        case EBML_ID_CONTENTENCODINGORDER:
496                                                                                                                                                        case EBML_ID_CONTENTENCODINGSCOPE:
497                                                                                                                                                        case EBML_ID_CONTENTENCODINGTYPE:
498                                                                                                                                                                $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
499                                                                                                                                                                break;
500                                                                                                                                                        case EBML_ID_CONTENTCOMPRESSION:
501                                                                                                                                                                while ($offset < $sub_sub_subelement_end) {
502                                                                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
503                                                                                                                                                                        $sub_sub_sub_subelement_offset = $offset;
504                                                                                                                                                                        $sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
505                                                                                                                                                                        $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
506                                                                                                                                                                        $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
507                                                                                                                                                                        $sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
508                                                                                                                                                                        switch ($sub_sub_sub_subelement_id) {
509                                                                                                                                                                                case EBML_ID_CONTENTCOMPALGO:
510                                                                                                                                                                                        $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
511                                                                                                                                                                                        break;
512                                                                                                                                                                                case EBML_ID_CONTENTCOMPSETTINGS:
513                                                                                                                                                                                        $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
514                                                                                                                                                                                        break;
515                                                                                                                                                                                default:
516                                                                                                                                                                                        $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
517                                                                                                                                                                                        break;
518                                                                                                                                                                        }
519                                                                                                                                                                        $offset = $sub_sub_sub_subelement_end;
520                                                                                                                                                                }
521                                                                                                                                                                break;
522
523                                                                                                                                                        case EBML_ID_CONTENTENCRYPTION:
524                                                                                                                                                                while ($offset < $sub_sub_subelement_end) {
525                                                                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
526                                                                                                                                                                        $sub_sub_sub_subelement_offset = $offset;
527                                                                                                                                                                        $sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
528                                                                                                                                                                        $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
529                                                                                                                                                                        $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
530                                                                                                                                                                        $sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
531                                                                                                                                                                        switch ($sub_sub_sub_subelement_id) {
532                                                                                                                                                                                case EBML_ID_CONTENTENCALGO:
533                                                                                                                                                                                case EBML_ID_CONTENTSIGALGO:
534                                                                                                                                                                                case EBML_ID_CONTENTSIGHASHALGO:
535                                                                                                                                                                                        $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
536                                                                                                                                                                                        break;
537                                                                                                                                                                                case EBML_ID_CONTENTENCKEYID:
538                                                                                                                                                                                case EBML_ID_CONTENTSIGNATURE:
539                                                                                                                                                                                case EBML_ID_CONTENTSIGKEYID:
540                                                                                                                                                                                        $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
541                                                                                                                                                                                        break;
542                                                                                                                                                                                default:
543                                                                                                                                                                                        $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
544                                                                                                                                                                                        break;
545                                                                                                                                                                        }
546                                                                                                                                                                        $offset = $sub_sub_sub_subelement_end;
547                                                                                                                                                                }
548                                                                                                                                                                break;
549
550                                                                                                                                                        default:
551                                                                                                                                                                $this->warnings[] = 'Unhandled track.contentencodings.contentencoding element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
552                                                                                                                                                                break;
553                                                                                                                                                }
554                                                                                                                                                $offset = $sub_sub_subelement_end;
555                                                                                                                                        }
556                                                                                                                                        break;
557                                                                                                                                default:
558                                                                                                                                        $this->warnings[] = 'Unhandled track.contentencodings element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
559                                                                                                                                        break;
560                                                                                                                        }
561                                                                                                                        $offset = $sub_subelement_end;
562                                                                                                                }
563                                                                                                                break;
564
565                                                                                                        default:
566                                                                                                                $this->warnings[] = 'Unhandled track element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
567                                                                                                                break;
568                                                                                                }
569                                                                                                $offset = $subelement_end;
570                                                                                        }
571                                                                                        break;
572                                                                                default:
573                                                                                        $this->warnings[] = 'Unhandled track element['.__LINE__.'] ('.$track_entry['id'].'::'.$track_entry['id_name'].') at '.$track_entry['offset'];
574                                                                                        $offset = $track_entry_endoffset;
575                                                                                        break;
576                                                                        }
577                                                                        $ThisFileInfo['matroska']['tracks']['tracks'][] = $track_entry;
578                                                                }
579                                                                break;
580
581                                                        case EBML_ID_INFO: // Contains the position of other level 1 elements
582                                                                $info_entry = array();
583                                                                while ($offset < $element_end) {
584                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
585                                                                        $subelement_offset = $offset;
586                                                                        $subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
587                                                                        $subelement_idname = $this->EBMLidName($subelement_id);
588                                                                        $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
589                                                                        $subelement_end    = $offset + $subelement_length;
590                                                                        switch ($subelement_id) {
591                                                                                case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
592                                                                                case EBML_ID_CHAPTERTRANSLATECODEC:
593                                                                                case EBML_ID_TIMECODESCALE:
594                                                                                        $info_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
595                                                                                        break;
596                                                                                case EBML_ID_DURATION:
597                                                                                        $info_entry[$subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
598                                                                                        break;
599                                                                                case EBML_ID_DATEUTC:
600                                                                                        $info_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
601                                                                                        $info_entry[$subelement_idname.'_unix'] = $this->EBMLdate2unix($info_entry[$subelement_idname]);
602                                                                                        break;
603                                                                                case EBML_ID_SEGMENTUID:
604                                                                                case EBML_ID_PREVUID:
605                                                                                case EBML_ID_NEXTUID:
606                                                                                case EBML_ID_SEGMENTFAMILY:
607                                                                                case EBML_ID_CHAPTERTRANSLATEID:
608                                                                                        $info_entry[$subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
609                                                                                        break;
610                                                                                case EBML_ID_SEGMENTFILENAME:
611                                                                                case EBML_ID_PREVFILENAME:
612                                                                                case EBML_ID_NEXTFILENAME:
613                                                                                case EBML_ID_TITLE:
614                                                                                case EBML_ID_MUXINGAPP:
615                                                                                case EBML_ID_WRITINGAPP:
616                                                                                        $info_entry[$subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
617                                                                                        break;
618                                                                                default:
619                                                                                        $this->warnings[] = 'Unhandled info element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
620                                                                                        break;
621                                                                        }
622                                                                        $offset = $subelement_end;
623                                                                }
624                                                                $ThisFileInfo['matroska']['info'][] = $info_entry;
625                                                                break;
626
627                                                        case EBML_ID_CUES:
628                                                                $cues_entry = array();
629                                                                while ($offset < $element_end) {
630                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
631                                                                        $subelement_offset = $offset;
632                                                                        $subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
633                                                                        $subelement_idname = $this->EBMLidName($subelement_id);
634                                                                        $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
635                                                                        $subelement_end    = $offset + $subelement_length;
636                                                                        switch ($subelement_id) {
637                                                                                case EBML_ID_CUEPOINT:
638                                                                                        $cuepoint_entry = array();
639                                                                                        while ($offset < $subelement_end) {
640                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
641                                                                                                $sub_subelement_offset = $offset;
642                                                                                                $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
643                                                                                                $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
644                                                                                                $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
645                                                                                                $sub_subelement_end    = $offset + $sub_subelement_length;
646                                                                                                switch ($sub_subelement_id) {
647                                                                                                        case EBML_ID_CUETRACKPOSITIONS:
648                                                                                                                while ($offset < $sub_subelement_end) {
649                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
650                                                                                                                        $sub_sub_subelement_offset = $offset;
651                                                                                                                        $sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
652                                                                                                                        $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
653                                                                                                                        $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
654                                                                                                                        $sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
655                                                                                                                        switch ($sub_sub_subelement_id) {
656                                                                                                                                case EBML_ID_CUETRACK:
657                                                                                                                                        $cuepoint_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
658                                                                                                                                        break;
659                                                                                                                                default:
660                                                                                                                                        $this->warnings[] = 'Unhandled cues.cuepoint.cuetrackpositions element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
661                                                                                                                                        break;
662                                                                                                                        }
663                                                                                                                        $offset = $sub_subelement_end;
664                                                                                                                }
665                                                                                                                break;
666                                                                                                        case EBML_ID_CUETIME:
667                                                                                                                $cuepoint_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
668                                                                                                                break;
669                                                                                                        default:
670                                                                                                                $this->warnings[] = 'Unhandled cues.cuepoint element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
671                                                                                                                break;
672                                                                                                }
673                                                                                                $offset = $sub_subelement_end;
674                                                                                        }
675                                                                                        $cues_entry[] = $cuepoint_entry;
676                                                                                        $offset = $sub_subelement_end;
677                                                                                        break;
678                                                                                default:
679                                                                                        $this->warnings[] = 'Unhandled cues element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
680                                                                                        break;
681                                                                        }
682                                                                        $offset = $subelement_end;
683                                                                }
684                                                                $ThisFileInfo['matroska']['cues'] = $cues_entry;
685                                                                break;
686
687                                                        case EBML_ID_TAGS:
688                                                                $tags_entry = array();
689                                                                while ($offset < $element_end) {
690                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
691                                                                        $subelement_offset = $offset;
692                                                                        $subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
693                                                                        $subelement_idname = $this->EBMLidName($subelement_id);
694                                                                        $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
695                                                                        $subelement_end    = $offset + $subelement_length;
696                                                                        switch ($subelement_id) {
697                                                                                case EBML_ID_WRITINGAPP:
698                                                                                        $tags_entry[$subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length);
699                                                                                        break;
700                                                                                case EBML_ID_TAG:
701                                                                                        $tag_entry = array();
702                                                                                        while ($offset < $subelement_end) {
703                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
704                                                                                                $sub_subelement_offset = $offset;
705                                                                                                $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
706                                                                                                $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
707                                                                                                $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
708                                                                                                $sub_subelement_end    = $offset + $sub_subelement_length;
709                                                                                                switch ($sub_subelement_id) {
710                                                                                                        case EBML_ID_TARGETS:
711                                                                                                                $targets_entry = array();
712                                                                                                                while ($offset < $sub_subelement_end) {
713                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
714                                                                                                                        $sub_sub_subelement_offset = $offset;
715                                                                                                                        $sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
716                                                                                                                        $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
717                                                                                                                        $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
718                                                                                                                        $sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
719                                                                                                                        switch ($sub_sub_subelement_id) {
720                                                                                                                                case EBML_ID_TARGETTYPEVALUE:
721                                                                                                                                case EBML_ID_EDITIONUID:
722                                                                                                                                case EBML_ID_CHAPTERUID:
723                                                                                                                                case EBML_ID_ATTACHMENTUID:
724                                                                                                                                case EBML_ID_TAGTRACKUID:
725                                                                                                                                case EBML_ID_TAGCHAPTERUID:
726                                                                                                                                        $targets_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
727                                                                                                                                        break;
728                                                                                                                                default:
729                                                                                                                                        $this->warnings[] = 'Unhandled tag.targets element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
730                                                                                                                                        break;
731                                                                                                                        }
732                                                                                                                        $offset = $sub_sub_subelement_end;
733                                                                                                                }
734                                                                                                                $tag_entry[$sub_subelement_idname][] = $targets_entry;
735                                                                                                                break;
736                                                                                                        case EBML_ID_SIMPLETAG:
737                                                                                                                $simpletag_entry = array();
738                                                                                                                while ($offset < $sub_subelement_end) {
739                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
740                                                                                                                        $sub_sub_subelement_offset = $offset;
741                                                                                                                        $sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
742                                                                                                                        $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
743                                                                                                                        $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
744                                                                                                                        $sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
745                                                                                                                        switch ($sub_sub_subelement_id) {
746                                                                                                                                case EBML_ID_TAGNAME:
747                                                                                                                                case EBML_ID_TAGLANGUAGE:
748                                                                                                                                case EBML_ID_TAGSTRING:
749                                                                                                                                case EBML_ID_TAGBINARY:
750                                                                                                                                        $simpletag_entry[$sub_sub_subelement_idname] =                                  substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
751                                                                                                                                        break;
752                                                                                                                                case EBML_ID_TAGDEFAULT:
753                                                                                                                                        $simpletag_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
754                                                                                                                                        break;
755                                                                                                                                default:
756                                                                                                                                        $this->warnings[] = 'Unhandled tag.simpletag element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
757                                                                                                                                        break;
758                                                                                                                        }
759                                                                                                                        $offset = $sub_sub_subelement_end;
760                                                                                                                }
761                                                                                                                $tag_entry[$sub_subelement_idname][] = $simpletag_entry;
762                                                                                                                break;
763                                                                                                        case EBML_ID_TARGETTYPE:
764                                                                                                                $tag_entry[$sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
765                                                                                                                break;
766                                                                                                        case EBML_ID_TRACKUID:
767                                                                                                                $tag_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
768                                                                                                                break;
769                                                                                                        default:
770                                                                                                                $this->warnings[] = 'Unhandled tags.tag element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
771                                                                                                                break;
772                                                                                                }
773                                                                                                $offset = $sub_subelement_end;
774                                                                                        }
775                                                                                        $tags_entry['tags'][] = $tag_entry;
776                                                                                        $offset = $sub_subelement_end;
777                                                                                        break;
778                                                                                default:
779                                                                                        $this->warnings[] = 'Unhandled tags element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
780                                                                                        break;
781                                                                        }
782                                                                        $offset = $subelement_end;
783                                                                }
784                                                                $ThisFileInfo['matroska']['tags'] = $tags_entry;
785                                                                break;
786
787
788                                                        case EBML_ID_ATTACHMENTS:
789                                                                while ($offset < $element_end) {
790                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
791                                                                        $subelement_offset = $offset;
792                                                                        $subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
793                                                                        $subelement_idname = $this->EBMLidName($subelement_id);
794                                                                        $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
795                                                                        $subelement_end    = $offset + $subelement_length;
796                                                                        switch ($subelement_id) {
797                                                                                case EBML_ID_ATTACHEDFILE:
798                                                                                        $attachedfile_entry = array();
799                                                                                        while ($offset < $subelement_end) {
800                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
801                                                                                                $sub_subelement_offset = $offset;
802                                                                                                $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
803                                                                                                $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
804                                                                                                $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
805                                                                                                $sub_subelement_end    = $offset + $sub_subelement_length;
806                                                                                                switch ($sub_subelement_id) {
807                                                                                                        case EBML_ID_FILEDESCRIPTION:
808                                                                                                        case EBML_ID_FILENAME:
809                                                                                                        case EBML_ID_FILEMIMETYPE:
810                                                                                                                $attachedfile_entry[$sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
811                                                                                                                break;
812
813                                                                                                        case EBML_ID_FILEDATA:
814                                                                                                                $attachedfile_entry['data_offset'] = $offset;
815                                                                                                                $attachedfile_entry['data_length'] = $sub_subelement_length;
816                                                                                                                if ($sub_subelement_length < 1024) {
817                                                                                                                        $attachedfile_entry[$sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
818                                                                                                                }
819                                                                                                                break;
820
821                                                                                                        case EBML_ID_FILEUID:
822                                                                                                                $attachedfile_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
823                                                                                                                break;
824
825                                                                                                        default:
826                                                                                                                $this->warnings[] = 'Unhandled attachment.attachedfile element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
827                                                                                                                break;
828                                                                                                }
829                                                                                                $offset = $sub_subelement_end;
830                                                                                        }
831                                                                                        $ThisFileInfo['matroska']['attachments'][] = $attachedfile_entry;
832                                                                                        $offset = $sub_subelement_end;
833                                                                                        break;
834                                                                                default:
835                                                                                        $this->warnings[] = 'Unhandled tags element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
836                                                                                        break;
837                                                                        }
838                                                                        $offset = $subelement_end;
839                                                                }
840                                                                break;
841
842
843                                                        case EBML_ID_CHAPTERS: // not important to us, contains mostly actual audio/video data, ignore
844                                                                while ($offset < $element_end) {
845                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
846                                                                        $subelement_offset = $offset;
847                                                                        $subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
848                                                                        $subelement_idname = $this->EBMLidName($subelement_id);
849                                                                        $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
850                                                                        $subelement_end    = $offset + $subelement_length;
851                                                                        switch ($subelement_id) {
852                                                                                case EBML_ID_EDITIONENTRY:
853                                                                                        $editionentry_entry = array();
854                                                                                        while ($offset < $subelement_end) {
855                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
856                                                                                                $sub_subelement_offset = $offset;
857                                                                                                $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
858                                                                                                $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
859                                                                                                $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
860                                                                                                $sub_subelement_end    = $offset + $sub_subelement_length;
861                                                                                                switch ($sub_subelement_id) {
862                                                                                                        case EBML_ID_EDITIONUID:
863                                                                                                                $editionentry_entry[$sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
864                                                                                                                break;
865                                                                                                        case EBML_ID_EDITIONFLAGHIDDEN:
866                                                                                                        case EBML_ID_EDITIONFLAGDEFAULT:
867                                                                                                        case EBML_ID_EDITIONFLAGORDERED:
868                                                                                                                $editionentry_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
869                                                                                                                break;
870                                                                                                        case EBML_ID_CHAPTERATOM:
871                                                                                                                $chapteratom_entry = array();
872                                                                                                                while ($offset < $sub_subelement_end) {
873                                                                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
874                                                                                                                        $sub_sub_subelement_offset = $offset;
875                                                                                                                        $sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
876                                                                                                                        $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
877                                                                                                                        $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
878                                                                                                                        $sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
879                                                                                                                        switch ($sub_sub_subelement_id) {
880                                                                                                                                case EBML_ID_CHAPTERSEGMENTUID:
881                                                                                                                                case EBML_ID_CHAPTERSEGMENTEDITIONUID:
882                                                                                                                                        $chapteratom_entry[$sub_sub_subelement_idname] =                                  substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
883                                                                                                                                        break;
884                                                                                                                                case EBML_ID_CHAPTERFLAGENABLED:
885                                                                                                                                case EBML_ID_CHAPTERFLAGHIDDEN:
886                                                                                                                                        $chapteratom_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
887                                                                                                                                        break;
888                                                                                                                                case EBML_ID_CHAPTERUID:
889                                                                                                                                case EBML_ID_CHAPTERTIMESTART:
890                                                                                                                                case EBML_ID_CHAPTERTIMEEND:
891                                                                                                                                        $chapteratom_entry[$sub_sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
892                                                                                                                                        break;
893                                                                                                                                case EBML_ID_CHAPTERTRACK:
894                                                                                                                                        $chaptertrack_entry = array();
895                                                                                                                                        while ($offset < $sub_sub_subelement_end) {
896                                                                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
897                                                                                                                                                $sub_sub_sub_subelement_offset = $offset;
898                                                                                                                                                $sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
899                                                                                                                                                $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
900                                                                                                                                                $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
901                                                                                                                                                $sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
902                                                                                                                                                switch ($sub_sub_sub_subelement_id) {
903                                                                                                                                                        case EBML_ID_CHAPTERTRACKNUMBER:
904                                                                                                                                                                $chaptertrack_entry[$sub_sub_sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
905                                                                                                                                                                break;
906                                                                                                                                                        default:
907                                                                                                                                                                $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chaptertrack element['.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset;
908                                                                                                                                                                break;
909                                                                                                                                                }
910                                                                                                                                                $offset = $sub_sub_sub_subelement_end;
911                                                                                                                                        }
912                                                                                                                                        $chapteratom_entry[$sub_sub_subelement_idname][] = $chaptertrack_entry;
913                                                                                                                                        break;
914                                                                                                                                case EBML_ID_CHAPTERDISPLAY:
915                                                                                                                                        $chapterdisplay_entry = array();
916                                                                                                                                        while ($offset < $sub_sub_subelement_end) {
917                                                                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
918                                                                                                                                                $sub_sub_sub_subelement_offset = $offset;
919                                                                                                                                                $sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
920                                                                                                                                                $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_sub_subelement_id);
921                                                                                                                                                $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
922                                                                                                                                                $sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
923                                                                                                                                                switch ($sub_sub_sub_subelement_id) {
924                                                                                                                                                        case EBML_ID_CHAPSTRING:
925                                                                                                                                                        case EBML_ID_CHAPLANGUAGE:
926                                                                                                                                                        case EBML_ID_CHAPCOUNTRY:
927                                                                                                                                                                $chapterdisplay_entry[$sub_sub_sub_subelement_idname] =                                  substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
928                                                                                                                                                                break;
929                                                                                                                                                        default:
930                                                                                                                                                                $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chapterdisplay element['.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset;
931                                                                                                                                                                break;
932                                                                                                                                                }
933                                                                                                                                                $offset = $sub_sub_sub_subelement_end;
934                                                                                                                                        }
935                                                                                                                                        $chapteratom_entry[$sub_sub_subelement_idname][] = $chapterdisplay_entry;
936                                                                                                                                        break;
937                                                                                                                                default:
938                                                                                                                                        $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom element['.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
939                                                                                                                                        break;
940                                                                                                                        }
941                                                                                                                        $offset = $sub_sub_subelement_end;
942                                                                                                                }
943                                                                                                                $editionentry_entry[$sub_subelement_idname][] = $chapteratom_entry;
944                                                                                                                break;
945                                                                                                        default:
946                                                                                                                $this->warnings[] = 'Unhandled chapters.editionentry element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
947                                                                                                                break;
948                                                                                                }
949                                                                                                $offset = $sub_subelement_end;
950                                                                                        }
951                                                                                        $ThisFileInfo['matroska']['chapters'][] = $editionentry_entry;
952                                                                                        $offset = $sub_subelement_end;
953                                                                                        break;
954                                                                                default:
955                                                                                        $this->warnings[] = 'Unhandled chapters element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
956                                                                                        break;
957                                                                        }
958                                                                        $offset = $subelement_end;
959                                                                }
960                                                                break;
961
962
963                                                        case EBML_ID_VOID:    // padding, ignore
964                                                                $void_entry = array();
965                                                                $void_entry['offset'] = $offset;
966                                                                $ThisFileInfo['matroska']['void'][] = $void_entry;
967                                                                break;
968
969                                                        case EBML_ID_CLUSTER: // not important to us, contains mostly actual audio/video data, ignore
970                                                                $cluster_entry = array();
971                                                                while ($offset < $element_end) {
972                                                                        $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
973                                                                        $subelement_offset = $offset;
974//var_dump($offset);
975                                                                        $subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
976//var_dump($subelement_id);
977//echo '<br>';
978                                                                        $subelement_idname = $this->EBMLidName($subelement_id);
979                                                                        $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
980//var_dump($subelement_length);
981                                                                        $subelement_end    = $offset + $subelement_length;
982//exit;
983                                                                        switch ($subelement_id) {
984                                                                                case EBML_ID_CLUSTERTIMECODE:
985                                                                                case EBML_ID_CLUSTERPOSITION:
986                                                                                case EBML_ID_CLUSTERPREVSIZE:
987                                                                                        $cluster_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
988                                                                                        break;
989
990                                                                                case EBML_ID_CLUSTERSILENTTRACKS:
991                                                                                        $cluster_silent_tracks = array();
992                                                                                        while ($offset < $subelement_end) {
993                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
994                                                                                                $sub_subelement_offset = $offset;
995                                                                                                $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
996                                                                                                $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
997                                                                                                $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
998                                                                                                $sub_subelement_end    = $offset + $sub_subelement_length;
999                                                                                                switch ($sub_subelement_id) {
1000                                                                                                        case EBML_ID_CLUSTERSILENTTRACKNUMBER:
1001                                                                                                                $cluster_silent_tracks[] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
1002                                                                                                                break;
1003                                                                                                        default:
1004                                                                                                                $this->warnings[] = 'Unhandled clusters.silenttracks element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
1005                                                                                                                break;
1006                                                                                                }
1007                                                                                                $offset = $sub_subelement_end;
1008                                                                                        }
1009                                                                                        $cluster_entry[$subelement_idname][] = $cluster_silent_tracks;
1010                                                                                        $offset = $sub_subelement_end;
1011                                                                                        break;
1012
1013                                                                                case EBML_ID_CLUSTERBLOCKGROUP:
1014                                                                                        $cluster_block_group = array('offset'=>$offset);
1015                                                                                        while ($offset < $subelement_end) {
1016                                                                                                $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
1017                                                                                                $sub_subelement_offset = $offset;
1018                                                                                                $sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
1019                                                                                                $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
1020                                                                                                $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
1021                                                                                                $sub_subelement_end    = $offset + $sub_subelement_length;
1022                                                                                                switch ($sub_subelement_id) {
1023                                                                                                        case EBML_ID_CLUSTERBLOCK:
1024                                                                                                                $cluster_block_data = array();
1025                                                                                                                $cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
1026                                                                                                                $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2));
1027                                                                                                                $offset += 2;
1028                                                                                                                // unsure whether this is 1 octect or 2 octets? (http://matroska.org/technical/specs/index.html#block_structure)
1029                                                                                                                $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
1030                                                                                                                $offset += 1;
1031                                                                                                                //$cluster_block_data['flags']['reserved1'] =      (($cluster_block_data['flags_raw'] & 0xF0) >> 4);
1032                                                                                                                $cluster_block_data['flags']['invisible'] = (bool) (($cluster_block_data['flags_raw'] & 0x08) >> 3);
1033                                                                                                                $cluster_block_data['flags']['lacing']    =        (($cluster_block_data['flags_raw'] & 0x06) >> 1);
1034                                                                                                                //$cluster_block_data['flags']['reserved2'] =      (($cluster_block_data['flags_raw'] & 0x01) >> 0);
1035                                                                                                                $cluster_block_data['flags']['lacing_type'] = $this->MatroskaBlockLacingType($cluster_block_data['flags']['lacing']);
1036                                                                                                                if ($cluster_block_data['flags']['lacing'] != 0) {
1037                                                                                                                        $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // Number of frames in the lace-1 (uint8)
1038                                                                                                                        $offset += 1;
1039                                                                                                                        if ($cluster_block_data['flags']['lacing'] != 2) {
1040                                                                                                                                $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace).
1041                                                                                                                                $offset += 1;
1042                                                                                                                        }
1043                                                                                                                }
1044                                                                                                                if (!isset($ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
1045                                                                                                                        $ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']] = $offset;
1046                                                                                                                }
1047                                                                                                                $cluster_block_group[$sub_subelement_idname] = $cluster_block_data;
1048                                                                                                                break;
1049
1050                                                                                                        case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int
1051                                                                                                        case EBML_ID_CLUSTERBLOCKDURATION:     // unsigned-int
1052                                                                                                                $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
1053                                                                                                                break;
1054
1055                                                                                                        case EBML_ID_CLUSTERREFERENCEBLOCK:    // signed-int
1056                                                                                                                $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), false, true);
1057                                                                                                                break;
1058
1059                                                                                                        default:
1060                                                                                                                $this->warnings[] = 'Unhandled clusters.blockgroup element['.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
1061                                                                                                                break;
1062                                                                                                }
1063                                                                                                $offset = $sub_subelement_end;
1064                                                                                        }
1065                                                                                        $cluster_entry[$subelement_idname][] = $cluster_block_group;
1066                                                                                        $offset = $sub_subelement_end;
1067                                                                                        break;
1068
1069                                                                                default:
1070                                                                                        $this->warnings[] = 'Unhandled cluster element['.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
1071                                                                                        break;
1072                                                                        }
1073                                                                        $offset = $subelement_end;
1074                                                                }
1075                                                                $ThisFileInfo['matroska']['cluster'][] = $cluster_entry;
1076
1077                                                                // check to see if all the data we need exists already, if so, break out of the loop
1078                                                                if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) {
1079                                                                        if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) {
1080                                                                                break 2;
1081                                                                        }
1082                                                                }
1083                                                                break;
1084
1085                                                        default:
1086                                                                if ($element_data['id_name'] == dechex($element_data['id'])) {
1087                                                                        $ThisFileInfo['error'][] = 'Unhandled segment['.__LINE__.'] ('.$element_data['id'].') at '.$element_data_offset;
1088                                                                } else {
1089                                                                        $this->warnings[] = 'Unhandled segment['.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data['offset'];
1090                                                                }
1091                                                                break;
1092                                                }
1093                                                $offset = $element_end;
1094                                        }
1095                                        break;
1096
1097
1098                                default:
1099                                        $ThisFileInfo['error'][] = 'Unhandled chunk['.__LINE__.'] ('.$top_element_id.') at '.$offset;
1100                                        break;
1101                        }
1102                        $offset = $top_element_endoffset;
1103                }
1104
1105
1106
1107                if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) {
1108                        foreach ($ThisFileInfo['matroska']['info'] as $key => $infoarray) {
1109                                if (isset($infoarray['Duration'])) {
1110                                        // TimecodeScale is how many nanoseconds each Duration unit is
1111                                        $ThisFileInfo['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
1112                                        break;
1113                                }
1114                        }
1115                }
1116                if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) {
1117                        foreach ($ThisFileInfo['matroska']['tracks']['tracks'] as $key => $trackarray) {
1118                                $track_info = array();
1119                                switch (@$trackarray['TrackType']) {
1120                                        case 1: // Video
1121                                                if (@$trackarray['PixelWidth'])      { $track_info['resolution_x']  =                                    $trackarray['PixelWidth'];          }
1122                                                if (@$trackarray['PixelHeight'])     { $track_info['resolution_y']  =                                    $trackarray['PixelHeight'];         }
1123                                                if (@$trackarray['DisplayWidth'])    { $track_info['display_x']     =                                    $trackarray['DisplayWidth'];        }
1124                                                if (@$trackarray['DisplayHeight'])   { $track_info['display_y']     =                                    $trackarray['DisplayHeight'];       }
1125                                                if (@$trackarray['DefaultDuration']) { $track_info['frame_rate']    =                 round(1000000000 / $trackarray['DefaultDuration'], 3); }
1126                                                if (@$trackarray['CodecID'])         { $track_info['dataformat']    = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);            }
1127                                                if (!empty($trackarray['codec_private_parsed']['fourcc'])) {
1128                                                        $track_info['fourcc'] = $trackarray['codec_private_parsed']['fourcc'];
1129                                                }
1130                                                $ThisFileInfo['video']['streams'][] = $track_info;
1131                                                if (isset($track_info['resolution_x']) && empty($ThisFileInfo['video']['resolution_x'])) {
1132                                                        foreach ($track_info as $key => $value) {
1133                                                                $ThisFileInfo['video'][$key] = $value;
1134                                                        }
1135                                                }
1136                                                break;
1137                                        case 2: // Audio
1138                                                if (@$trackarray['CodecID'])           { $track_info['dataformat']      = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);          }
1139                                                if (@$trackarray['SamplingFrequency']) { $track_info['sample_rate']     =                                    $trackarray['SamplingFrequency']; }
1140                                                if (@$trackarray['Channels'])          { $track_info['channels']        =                                    $trackarray['Channels'];          }
1141                                                if (@$trackarray['BitDepth'])          { $track_info['bits_per_sample'] =                                    $trackarray['BitDepth'];          }
1142                                                switch (@$trackarray[$this->EBMLidName(EBML_ID_CODECID)]) {
1143                                                        case 'A_PCM/INT/LIT':
1144                                                        case 'A_PCM/INT/BIG':
1145                                                                $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
1146                                                                break;
1147
1148                                                        case 'A_AC3':
1149                                                                if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
1150                                                                        $ac3_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]);
1151                                                                        $getid3_ac3 = new getid3_ac3($fd, $ac3_thisfileinfo);
1152                                                                        $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $ac3_thisfileinfo;
1153                                                                        if (!empty($ac3_thisfileinfo['error'])) {
1154                                                                                foreach ($ac3_thisfileinfo['error'] as $newerror) {
1155                                                                                        $this->warnings[] = 'getid3_ac3() says: ['.$newerror.']';
1156                                                                                }
1157                                                                        }
1158                                                                        if (!empty($ac3_thisfileinfo['warning'])) {
1159                                                                                foreach ($ac3_thisfileinfo['warning'] as $newerror) {
1160                                                                                        $this->warnings[] = 'getid3_ac3() says: ['.$newerror.']';
1161                                                                                }
1162                                                                        }
1163                                                                        if (isset($ac3_thisfileinfo['audio']) && is_array($ac3_thisfileinfo['audio'])) {
1164                                                                                foreach ($ac3_thisfileinfo['audio'] as $key => $value) {
1165                                                                                        $track_info[$key] = $value;
1166                                                                                }
1167                                                                        }
1168                                                                        unset($ac3_thisfileinfo);
1169                                                                        unset($getid3_ac3);
1170                                                                } else {
1171                                                                        $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.ac3.php"';
1172                                                                }
1173                                                                break;
1174
1175                                                        case 'A_DTS':
1176                                                                $dts_offset = $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']];
1177                                                                // this is a NASTY hack, but sometimes audio data is off by a byte or two and not sure why, email info@getid3.org if you can explain better
1178                                                                fseek($fd, $dts_offset, SEEK_SET);
1179                                                                $magic_test = fread($fd, 8);
1180                                                                for ($i = 0; $i < 4; $i++) {
1181                                                                        // look to see if DTS "magic" is here, if so adjust offset by that many bytes
1182                                                                        if (substr($magic_test, $i, 4) == "\x7F\xFE\x80\x01") {
1183                                                                                $dts_offset += $i;
1184                                                                                break;
1185                                                                        }
1186                                                                }
1187                                                                if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, false)) {
1188                                                                        $dts_thisfileinfo = array('avdataoffset'=>$dts_offset);
1189                                                                        $getid3_dts = new getid3_dts($fd, $dts_thisfileinfo);
1190                                                                        $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $dts_thisfileinfo;
1191                                                                        if (!empty($dts_thisfileinfo['error'])) {
1192                                                                                foreach ($dts_thisfileinfo['error'] as $newerror) {
1193                                                                                        $this->warnings[] = 'getid3_dts() says: ['.$newerror.']';
1194                                                                                }
1195                                                                        }
1196                                                                        if (!empty($dts_thisfileinfo['warning'])) {
1197                                                                                foreach ($dts_thisfileinfo['warning'] as $newerror) {
1198                                                                                        $this->warnings[] = 'getid3_dts() says: ['.$newerror.']';
1199                                                                                }
1200                                                                        }
1201                                                                        if (isset($dts_thisfileinfo['audio']) && is_array($dts_thisfileinfo['audio'])) {
1202                                                                                foreach ($dts_thisfileinfo['audio'] as $key => $value) {
1203                                                                                        $track_info[$key] = $value;
1204                                                                                }
1205                                                                        }
1206                                                                        unset($dts_thisfileinfo);
1207                                                                        unset($getid3_dts);
1208                                                                } else {
1209                                                                        $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.dts.php"';
1210                                                                }
1211                                                                break;
1212
1213                                                        //case 'A_AAC':
1214                                                        //      if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.aac.php', __FILE__, false)) {
1215                                                        //              $aac_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]);
1216                                                        //              $getid3_aac = new getid3_aac($fd, $aac_thisfileinfo);
1217                                                        //              $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $aac_thisfileinfo;
1218                                                        //              if (isset($aac_thisfileinfo['audio']) && is_array($aac_thisfileinfo['audio'])) {
1219                                                        //                      foreach ($aac_thisfileinfo['audio'] as $key => $value) {
1220                                                        //                              $track_info[$key] = $value;
1221                                                        //                      }
1222                                                        //              }
1223                                                        //              unset($aac_thisfileinfo);
1224                                                        //              unset($getid3_aac);
1225                                                        //      } else {
1226                                                        //              $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.aac.php"';
1227                                                        //      }
1228                                                        //      break;
1229
1230                                                        case 'A_MPEG/L3':
1231                                                                if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, false)) {
1232                                                                        $mp3_thisfileinfo = array(
1233                                                                                'avdataoffset' => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']],
1234                                                                                'avdataend'    => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']] + 1024,
1235                                                                        );
1236                                                                        $getid3_mp3 = new getid3_mp3($fd, $mp3_thisfileinfo);
1237                                                                        $getid3_mp3->allow_bruteforce = true;
1238                                                                        //getid3_mp3::getOnlyMPEGaudioInfo($fd, $mp3_thisfileinfo, $offset, false);
1239                                                                        $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $mp3_thisfileinfo;
1240                                                                        if (!empty($mp3_thisfileinfo['error'])) {
1241                                                                                foreach ($mp3_thisfileinfo['error'] as $newerror) {
1242                                                                                        $this->warnings[] = 'getid3_mp3() says: ['.$newerror.']';
1243                                                                                }
1244                                                                        }
1245                                                                        if (!empty($mp3_thisfileinfo['warning'])) {
1246                                                                                foreach ($mp3_thisfileinfo['warning'] as $newerror) {
1247                                                                                        $this->warnings[] = 'getid3_mp3() says: ['.$newerror.']';
1248                                                                                }
1249                                                                        }
1250                                                                        if (isset($mp3_thisfileinfo['audio']) && is_array($mp3_thisfileinfo['audio'])) {
1251                                                                                foreach ($mp3_thisfileinfo['audio'] as $key => $value) {
1252                                                                                        $track_info[$key] = $value;
1253                                                                                }
1254                                                                        }
1255                                                                        unset($mp3_thisfileinfo);
1256                                                                        unset($getid3_mp3);
1257                                                                } else {
1258                                                                        $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.mp3.php"';
1259                                                                }
1260                                                                break;
1261
1262                                                        case 'A_VORBIS':
1263                                                                if (isset($trackarray['CodecPrivate'])) {
1264                                                                        // this is a NASTY hack, email info@getid3.org if you have a better idea how to get this info out
1265                                                                        $found_vorbis = false;
1266                                                                        for ($vorbis_offset = 1; $vorbis_offset < 16; $vorbis_offset++) {
1267                                                                                if (substr($trackarray['CodecPrivate'], $vorbis_offset, 6) == 'vorbis') {
1268                                                                                        $vorbis_offset--;
1269                                                                                        $found_vorbis = true;
1270                                                                                        break;
1271                                                                                }
1272                                                                        }
1273                                                                        if ($found_vorbis) {
1274                                                                                if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, false)) {
1275                                                                                        $vorbis_fileinfo = array();
1276                                                                                        $oggpageinfo['page_seqno'] = 0;
1277                                                                                        getid3_ogg::ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $vorbis_fileinfo, $oggpageinfo);
1278                                                                                        $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $vorbis_fileinfo;
1279                                                                                        if (!empty($vorbis_fileinfo['error'])) {
1280                                                                                                foreach ($vorbis_fileinfo['error'] as $newerror) {
1281                                                                                                        $this->warnings[] = 'getid3_ogg() says: ['.$newerror.']';
1282                                                                                                }
1283                                                                                        }
1284                                                                                        if (!empty($vorbis_fileinfo['warning'])) {
1285                                                                                                foreach ($vorbis_fileinfo['warning'] as $newerror) {
1286                                                                                                        $this->warnings[] = 'getid3_ogg() says: ['.$newerror.']';
1287                                                                                                }
1288                                                                                        }
1289                                                                                        if (isset($vorbis_fileinfo['audio']) && is_array($vorbis_fileinfo['audio'])) {
1290                                                                                                foreach ($vorbis_fileinfo['audio'] as $key => $value) {
1291                                                                                                        $track_info[$key] = $value;
1292                                                                                                }
1293                                                                                        }
1294                                                                                        if (@$vorbis_fileinfo['ogg']['bitrate_average']) {
1295                                                                                                $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_average'];
1296                                                                                        } elseif (@$vorbis_fileinfo['ogg']['bitrate_nominal']) {
1297                                                                                                $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_nominal'];
1298                                                                                        }
1299                                                                                        unset($vorbis_fileinfo);
1300                                                                                        unset($oggpageinfo);
1301                                                                                } else {
1302                                                                                        $this->warnings[] = 'Unable to parse audio data['.__LINE__.'] because cannot include "module.audio.ogg.php"';
1303                                                                                }
1304                                                                        } else {
1305                                                                        }
1306                                                                } else {
1307                                                                }
1308                                                                break;
1309
1310                                                        default:
1311                                                                $this->warnings[] = 'Unhandled audio type "'.@$trackarray[$this->EBMLidName(EBML_ID_CODECID)].'"';
1312                                                                break;
1313                                                }
1314
1315
1316                                                $ThisFileInfo['audio']['streams'][] = $track_info;
1317                                                if (isset($track_info['dataformat']) && empty($ThisFileInfo['audio']['dataformat'])) {
1318                                                        foreach ($track_info as $key => $value) {
1319                                                                $ThisFileInfo['audio'][$key] = $value;
1320                                                        }
1321                                                }
1322                                                break;
1323                                        default:
1324                                                // ignore, do nothing
1325                                                break;
1326                                }
1327                        }
1328                }
1329
1330                if ($this->hide_clusters) {
1331                        // too much data returned that is usually not useful
1332                        if (isset($ThisFileInfo['matroska']['segments']) && is_array($ThisFileInfo['matroska']['segments'])) {
1333                                foreach ($ThisFileInfo['matroska']['segments'] as $key => $segmentsarray) {
1334                                        if ($segmentsarray['id'] == EBML_ID_CLUSTER) {
1335                                                unset($ThisFileInfo['matroska']['segments'][$key]);
1336                                        }
1337                                }
1338                        }
1339                        if (isset($ThisFileInfo['matroska']['seek']) && is_array($ThisFileInfo['matroska']['seek'])) {
1340                                foreach ($ThisFileInfo['matroska']['seek'] as $key => $seekarray) {
1341                                        if ($seekarray['target_id'] == EBML_ID_CLUSTER) {
1342                                                unset($ThisFileInfo['matroska']['seek'][$key]);
1343                                        }
1344                                }
1345                        }
1346                        //unset($ThisFileInfo['matroska']['cluster']);
1347                        //unset($ThisFileInfo['matroska']['track_data_offsets']);
1348                }
1349
1350                if (!empty($ThisFileInfo['video']['streams'])) {
1351                        $ThisFileInfo['mime_type'] = 'video/x-matroska';
1352                } elseif (!empty($ThisFileInfo['video']['streams'])) {
1353                        $ThisFileInfo['mime_type'] = 'audio/x-matroska';
1354                } elseif (isset($ThisFileInfo['mime_type'])) {
1355                        unset($ThisFileInfo['mime_type']);
1356                }
1357
1358                foreach ($this->warnings as $key => $value) {
1359                        $ThisFileInfo['warning'][] = $value;
1360                }
1361
1362                return true;
1363        }
1364
1365
1366///////////////////////////////////////
1367
1368
1369        function EnsureBufferHasEnoughData(&$fd, &$EBMLdata, &$offset, &$EBMLdata_offset) {
1370                $min_data = 1024;
1371                if ($offset > 2147450880) { // 2^31 - 2^15 (2G-32k)
1372                        $offset = pow(2,63);
1373                        return false;
1374                } elseif (($offset - $EBMLdata_offset) >= (strlen($EBMLdata) - $min_data)) {
1375                        fseek($fd, $offset, SEEK_SET);
1376                        $EBMLdata_offset = ftell($fd);
1377                        $EBMLdata = fread($fd, $this->read_buffer_size);
1378                }
1379                return true;
1380        }
1381
1382        function readEBMLint(&$string, &$offset, $dataoffset=0) {
1383                $actual_offset = $offset - $dataoffset;
1384                if ($offset > 2147450880) { // 2^31 - 2^15 (2G-32k)
1385                        $this->warnings[] = 'aborting readEBMLint() because $offset larger than 2GB';
1386                        return false;
1387                } elseif ($actual_offset >= strlen($string)) {
1388                        $this->warnings[] = '$actual_offset > $string in readEBMLint($string['.strlen($string).'], '.$offset.', '.$dataoffset.')';
1389                        return false;
1390                } elseif ($actual_offset < 0) {
1391                        $this->warnings[] = '$actual_offset < 0 in readEBMLint($string['.strlen($string).'], '.$offset.', '.$dataoffset.')';
1392                        return false;
1393                }
1394                $first_byte_int = ord($string{$actual_offset});
1395                if (0x80 & $first_byte_int) {
1396                        $length = 1;
1397                } elseif (0x40 & $first_byte_int) {
1398                        $length = 2;
1399                } elseif (0x20 & $first_byte_int) {
1400                        $length = 3;
1401                } elseif (0x10 & $first_byte_int) {
1402                        $length = 4;
1403                } elseif (0x08 & $first_byte_int) {
1404                        $length = 5;
1405                } elseif (0x04 & $first_byte_int) {
1406                        $length = 6;
1407                } elseif (0x02 & $first_byte_int) {
1408                        $length = 7;
1409                } elseif (0x01 & $first_byte_int) {
1410                        $length = 8;
1411                } else {
1412                        $offset = pow(2,63); // abort processing, skip to end of file
1413                        $this->warnings[] = 'invalid EBML integer (leading 0x00) at '.$offset;
1414                        return false;
1415                }
1416                $int_value = $this->EBML2Int(substr($string, $actual_offset, $length));
1417                $offset += $length;
1418                return $int_value;
1419        }
1420
1421        function EBML2Int($EBMLstring) {
1422                // http://matroska.org/specs/
1423
1424                // Element ID coded with an UTF-8 like system:
1425                // 1xxx xxxx                                  - Class A IDs (2^7 -2 possible values) (base 0x8X)
1426                // 01xx xxxx  xxxx xxxx                       - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX)
1427                // 001x xxxx  xxxx xxxx  xxxx xxxx            - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX)
1428                // 0001 xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX)
1429                // Values with all x at 0 and 1 are reserved (hence the -2).
1430
1431                // Data size, in octets, is also coded with an UTF-8 like system :
1432                // 1xxx xxxx                                                                              - value 0 to  2^7-2
1433                // 01xx xxxx  xxxx xxxx                                                                   - value 0 to 2^14-2
1434                // 001x xxxx  xxxx xxxx  xxxx xxxx                                                        - value 0 to 2^21-2
1435                // 0001 xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx                                             - value 0 to 2^28-2
1436                // 0000 1xxx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx                                  - value 0 to 2^35-2
1437                // 0000 01xx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx                       - value 0 to 2^42-2
1438                // 0000 001x  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx            - value 0 to 2^49-2
1439                // 0000 0001  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx - value 0 to 2^56-2
1440
1441                $first_byte_int = ord($EBMLstring{0});
1442                if (0x80 & $first_byte_int) {
1443                        $EBMLstring{0} = chr($first_byte_int & 0x7F);
1444                } elseif (0x40 & $first_byte_int) {
1445                        $EBMLstring{0} = chr($first_byte_int & 0x3F);
1446                } elseif (0x20 & $first_byte_int) {
1447                        $EBMLstring{0} = chr($first_byte_int & 0x1F);
1448                } elseif (0x10 & $first_byte_int) {
1449                        $EBMLstring{0} = chr($first_byte_int & 0x0F);
1450                } elseif (0x08 & $first_byte_int) {
1451                        $EBMLstring{0} = chr($first_byte_int & 0x07);
1452                } elseif (0x04 & $first_byte_int) {
1453                        $EBMLstring{0} = chr($first_byte_int & 0x03);
1454                } elseif (0x02 & $first_byte_int) {
1455                        $EBMLstring{0} = chr($first_byte_int & 0x01);
1456                } elseif (0x01 & $first_byte_int) {
1457                        $EBMLstring{0} = chr($first_byte_int & 0x00);
1458                } else {
1459                        return false;
1460                }
1461                return getid3_lib::BigEndian2Int($EBMLstring);
1462        }
1463
1464
1465        function EBMLdate2unix($EBMLdatestamp) {
1466                // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
1467                // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC
1468                return round(($EBMLdatestamp / 1000000000) + 978307200);
1469        }
1470
1471
1472        function MatroskaBlockLacingType($lacingtype) {
1473                // http://matroska.org/technical/specs/index.html#block_structure
1474                static $MatroskaBlockLacingType = array();
1475                if (empty($MatroskaBlockLacingType)) {
1476                        $MatroskaBlockLacingType[0x00] = 'no lacing';
1477                        $MatroskaBlockLacingType[0x01] = 'Xiph lacing';
1478                        $MatroskaBlockLacingType[0x02] = 'fixed-size lacing';
1479                        $MatroskaBlockLacingType[0x03] = 'EBML lacing';
1480                }
1481                return (isset($MatroskaBlockLacingType[$lacingtype]) ? $MatroskaBlockLacingType[$lacingtype] : $lacingtype);
1482        }
1483
1484        function MatroskaCodecIDtoCommonName($codecid) {
1485                // http://www.matroska.org/technical/specs/codecid/index.html
1486                static $MatroskaCodecIDlist = array();
1487                if (empty($MatroskaCodecIDlist)) {
1488                        $MatroskaCodecIDlist['A_AAC']            = 'aac';
1489                        $MatroskaCodecIDlist['A_AAC/MPEG2/LC']   = 'aac';
1490                        $MatroskaCodecIDlist['A_AC3']            = 'ac3';
1491                        $MatroskaCodecIDlist['A_DTS']            = 'dts';
1492                        $MatroskaCodecIDlist['A_FLAC']           = 'flac';
1493                        $MatroskaCodecIDlist['A_MPEG/L1']        = 'mp1';
1494                        $MatroskaCodecIDlist['A_MPEG/L2']        = 'mp2';
1495                        $MatroskaCodecIDlist['A_MPEG/L3']        = 'mp3';
1496                        $MatroskaCodecIDlist['A_PCM/INT/LIT']    = 'pcm';       // PCM Integer Little Endian
1497                        $MatroskaCodecIDlist['A_PCM/INT/BIG']    = 'pcm';       // PCM Integer Big Endian
1498                        $MatroskaCodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music
1499                        $MatroskaCodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2
1500                        $MatroskaCodecIDlist['A_VORBIS']         = 'vorbis';
1501                        $MatroskaCodecIDlist['V_MPEG1']          = 'mpeg';
1502                        $MatroskaCodecIDlist['V_THEORA']         = 'theora';
1503                        $MatroskaCodecIDlist['V_REAL/RV40']      = 'real';
1504                        $MatroskaCodecIDlist['V_REAL/RV10']      = 'real';
1505                        $MatroskaCodecIDlist['V_REAL/RV20']      = 'real';
1506                        $MatroskaCodecIDlist['V_REAL/RV30']      = 'real';
1507                        $MatroskaCodecIDlist['V_QUICKTIME']      = 'quicktime'; // Quicktime
1508                        $MatroskaCodecIDlist['V_MPEG4/ISO/AP']   = 'mpeg4';
1509                        $MatroskaCodecIDlist['V_MPEG4/ISO/ASP']  = 'mpeg4';
1510                        $MatroskaCodecIDlist['V_MPEG4/ISO/AVC']  = 'h264';
1511                        $MatroskaCodecIDlist['V_MPEG4/ISO/SP']   = 'mpeg4';
1512                }
1513                return (isset($MatroskaCodecIDlist[$codecid]) ? $MatroskaCodecIDlist[$codecid] : $codecid);
1514        }
1515
1516        function EBMLidName($value) {
1517                static $EBMLidList = array();
1518                if (empty($EBMLidList)) {
1519                        $EBMLidList[EBML_ID_ASPECTRATIOTYPE]            = 'AspectRatioType';
1520                        $EBMLidList[EBML_ID_ATTACHEDFILE]               = 'AttachedFile';
1521                        $EBMLidList[EBML_ID_ATTACHMENTLINK]             = 'AttachmentLink';
1522                        $EBMLidList[EBML_ID_ATTACHMENTS]                = 'Attachments';
1523                        $EBMLidList[EBML_ID_ATTACHMENTUID]              = 'AttachmentUID';
1524                        $EBMLidList[EBML_ID_AUDIO]                      = 'Audio';
1525                        $EBMLidList[EBML_ID_BITDEPTH]                   = 'BitDepth';
1526                        $EBMLidList[EBML_ID_CHANNELPOSITIONS]           = 'ChannelPositions';
1527                        $EBMLidList[EBML_ID_CHANNELS]                   = 'Channels';
1528                        $EBMLidList[EBML_ID_CHAPCOUNTRY]                = 'ChapCountry';
1529                        $EBMLidList[EBML_ID_CHAPLANGUAGE]               = 'ChapLanguage';
1530                        $EBMLidList[EBML_ID_CHAPPROCESS]                = 'ChapProcess';
1531                        $EBMLidList[EBML_ID_CHAPPROCESSCODECID]         = 'ChapProcessCodecID';
1532                        $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND]         = 'ChapProcessCommand';
1533                        $EBMLidList[EBML_ID_CHAPPROCESSDATA]            = 'ChapProcessData';
1534                        $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE]         = 'ChapProcessPrivate';
1535                        $EBMLidList[EBML_ID_CHAPPROCESSTIME]            = 'ChapProcessTime';
1536                        $EBMLidList[EBML_ID_CHAPSTRING]                 = 'ChapString';
1537                        $EBMLidList[EBML_ID_CHAPTERATOM]                = 'ChapterAtom';
1538                        $EBMLidList[EBML_ID_CHAPTERDISPLAY]             = 'ChapterDisplay';
1539                        $EBMLidList[EBML_ID_CHAPTERFLAGENABLED]         = 'ChapterFlagEnabled';
1540                        $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN]          = 'ChapterFlagHidden';
1541                        $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV]       = 'ChapterPhysicalEquiv';
1542                        $EBMLidList[EBML_ID_CHAPTERS]                   = 'Chapters';
1543                        $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID]   = 'ChapterSegmentEditionUID';
1544                        $EBMLidList[EBML_ID_CHAPTERSEGMENTUID]          = 'ChapterSegmentUID';
1545                        $EBMLidList[EBML_ID_CHAPTERTIMEEND]             = 'ChapterTimeEnd';
1546                        $EBMLidList[EBML_ID_CHAPTERTIMESTART]           = 'ChapterTimeStart';
1547                        $EBMLidList[EBML_ID_CHAPTERTRACK]               = 'ChapterTrack';
1548                        $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER]         = 'ChapterTrackNumber';
1549                        $EBMLidList[EBML_ID_CHAPTERTRANSLATE]           = 'ChapterTranslate';
1550                        $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC]      = 'ChapterTranslateCodec';
1551                        $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID';
1552                        $EBMLidList[EBML_ID_CHAPTERTRANSLATEID]         = 'ChapterTranslateID';
1553                        $EBMLidList[EBML_ID_CHAPTERUID]                 = 'ChapterUID';
1554                        $EBMLidList[EBML_ID_CLUSTER]                    = 'Cluster';
1555                        $EBMLidList[EBML_ID_CLUSTERBLOCK]               = 'ClusterBlock';
1556                        $EBMLidList[EBML_ID_CLUSTERBLOCKADDID]          = 'ClusterBlockAddID';
1557                        $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL]     = 'ClusterBlockAdditional';
1558                        $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID]     = 'ClusterBlockAdditionID';
1559                        $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS]      = 'ClusterBlockAdditions';
1560                        $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION]       = 'ClusterBlockDuration';
1561                        $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP]          = 'ClusterBlockGroup';
1562                        $EBMLidList[EBML_ID_CLUSTERBLOCKMORE]           = 'ClusterBlockMore';
1563                        $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL]        = 'ClusterBlockVirtual';
1564                        $EBMLidList[EBML_ID_CLUSTERCODECSTATE]          = 'ClusterCodecState';
1565                        $EBMLidList[EBML_ID_CLUSTERDELAY]               = 'ClusterDelay';
1566                        $EBMLidList[EBML_ID_CLUSTERDURATION]            = 'ClusterDuration';
1567                        $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK]      = 'ClusterEncryptedBlock';
1568                        $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER]         = 'ClusterFrameNumber';
1569                        $EBMLidList[EBML_ID_CLUSTERLACENUMBER]          = 'ClusterLaceNumber';
1570                        $EBMLidList[EBML_ID_CLUSTERPOSITION]            = 'ClusterPosition';
1571                        $EBMLidList[EBML_ID_CLUSTERPREVSIZE]            = 'ClusterPrevSize';
1572                        $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK]      = 'ClusterReferenceBlock';
1573                        $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY]   = 'ClusterReferencePriority';
1574                        $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL]    = 'ClusterReferenceVirtual';
1575                        $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER]   = 'ClusterSilentTrackNumber';
1576                        $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS]        = 'ClusterSilentTracks';
1577                        $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK]         = 'ClusterSimpleBlock';
1578                        $EBMLidList[EBML_ID_CLUSTERTIMECODE]            = 'ClusterTimecode';
1579                        $EBMLidList[EBML_ID_CLUSTERTIMESLICE]           = 'ClusterTimeSlice';
1580                        $EBMLidList[EBML_ID_CODECDECODEALL]             = 'CodecDecodeAll';
1581                        $EBMLidList[EBML_ID_CODECDOWNLOADURL]           = 'CodecDownloadURL';
1582                        $EBMLidList[EBML_ID_CODECID]                    = 'CodecID';
1583                        $EBMLidList[EBML_ID_CODECINFOURL]               = 'CodecInfoURL';
1584                        $EBMLidList[EBML_ID_CODECNAME]                  = 'CodecName';
1585                        $EBMLidList[EBML_ID_CODECPRIVATE]               = 'CodecPrivate';
1586                        $EBMLidList[EBML_ID_CODECSETTINGS]              = 'CodecSettings';
1587                        $EBMLidList[EBML_ID_COLOURSPACE]                = 'ColourSpace';
1588                        $EBMLidList[EBML_ID_CONTENTCOMPALGO]            = 'ContentCompAlgo';
1589                        $EBMLidList[EBML_ID_CONTENTCOMPRESSION]         = 'ContentCompression';
1590                        $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS]        = 'ContentCompSettings';
1591                        $EBMLidList[EBML_ID_CONTENTENCALGO]             = 'ContentEncAlgo';
1592                        $EBMLidList[EBML_ID_CONTENTENCKEYID]            = 'ContentEncKeyID';
1593                        $EBMLidList[EBML_ID_CONTENTENCODING]            = 'ContentEncoding';
1594                        $EBMLidList[EBML_ID_CONTENTENCODINGORDER]       = 'ContentEncodingOrder';
1595                        $EBMLidList[EBML_ID_CONTENTENCODINGS]           = 'ContentEncodings';
1596                        $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE]       = 'ContentEncodingScope';
1597                        $EBMLidList[EBML_ID_CONTENTENCODINGTYPE]        = 'ContentEncodingType';
1598                        $EBMLidList[EBML_ID_CONTENTENCRYPTION]          = 'ContentEncryption';
1599                        $EBMLidList[EBML_ID_CONTENTSIGALGO]             = 'ContentSigAlgo';
1600                        $EBMLidList[EBML_ID_CONTENTSIGHASHALGO]         = 'ContentSigHashAlgo';
1601                        $EBMLidList[EBML_ID_CONTENTSIGKEYID]            = 'ContentSigKeyID';
1602                        $EBMLidList[EBML_ID_CONTENTSIGNATURE]           = 'ContentSignature';
1603                        $EBMLidList[EBML_ID_CRC32]                      = 'CRC32';
1604                        $EBMLidList[EBML_ID_CUEBLOCKNUMBER]             = 'CueBlockNumber';
1605                        $EBMLidList[EBML_ID_CUECLUSTERPOSITION]         = 'CueClusterPosition';
1606                        $EBMLidList[EBML_ID_CUECODECSTATE]              = 'CueCodecState';
1607                        $EBMLidList[EBML_ID_CUEPOINT]                   = 'CuePoint';
1608                        $EBMLidList[EBML_ID_CUEREFCLUSTER]              = 'CueRefCluster';
1609                        $EBMLidList[EBML_ID_CUEREFCODECSTATE]           = 'CueRefCodecState';
1610                        $EBMLidList[EBML_ID_CUEREFERENCE]               = 'CueReference';
1611                        $EBMLidList[EBML_ID_CUEREFNUMBER]               = 'CueRefNumber';
1612                        $EBMLidList[EBML_ID_CUEREFTIME]                 = 'CueRefTime';
1613                        $EBMLidList[EBML_ID_CUES]                       = 'Cues';
1614                        $EBMLidList[EBML_ID_CUETIME]                    = 'CueTime';
1615                        $EBMLidList[EBML_ID_CUETRACK]                   = 'CueTrack';
1616                        $EBMLidList[EBML_ID_CUETRACKPOSITIONS]          = 'CueTrackPositions';
1617                        $EBMLidList[EBML_ID_DATEUTC]                    = 'DateUTC';
1618                        $EBMLidList[EBML_ID_DEFAULTDURATION]            = 'DefaultDuration';
1619                        $EBMLidList[EBML_ID_DISPLAYHEIGHT]              = 'DisplayHeight';
1620                        $EBMLidList[EBML_ID_DISPLAYUNIT]                = 'DisplayUnit';
1621                        $EBMLidList[EBML_ID_DISPLAYWIDTH]               = 'DisplayWidth';
1622                        $EBMLidList[EBML_ID_DOCTYPE]                    = 'DocType';
1623                        $EBMLidList[EBML_ID_DOCTYPEREADVERSION]         = 'DocTypeReadVersion';
1624                        $EBMLidList[EBML_ID_DOCTYPEVERSION]             = 'DocTypeVersion';
1625                        $EBMLidList[EBML_ID_DURATION]                   = 'Duration';
1626                        $EBMLidList[EBML_ID_EBMLMAXIDLENGTH]            = 'EBMLMaxIDLength';
1627                        $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH]          = 'EBMLMaxSizeLength';
1628                        $EBMLidList[EBML_ID_EBMLREADVERSION]            = 'EBMLReadVersion';
1629                        $EBMLidList[EBML_ID_EBMLVERSION]                = 'EBMLVersion';
1630                        $EBMLidList[EBML_ID_EDITIONENTRY]               = 'EditionEntry';
1631                        $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT]         = 'EditionFlagDefault';
1632                        $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN]          = 'EditionFlagHidden';
1633                        $EBMLidList[EBML_ID_EDITIONFLAGORDERED]         = 'EditionFlagOrdered';
1634                        $EBMLidList[EBML_ID_EDITIONUID]                 = 'EditionUID';
1635                        $EBMLidList[EBML_ID_FILEDATA]                   = 'FileData';
1636                        $EBMLidList[EBML_ID_FILEDESCRIPTION]            = 'FileDescription';
1637                        $EBMLidList[EBML_ID_FILEMIMETYPE]               = 'FileMimeType';
1638                        $EBMLidList[EBML_ID_FILENAME]                   = 'FileName';
1639                        $EBMLidList[EBML_ID_FILEREFERRAL]               = 'FileReferral';
1640                        $EBMLidList[EBML_ID_FILEUID]                    = 'FileUID';
1641                        $EBMLidList[EBML_ID_FLAGDEFAULT]                = 'FlagDefault';
1642                        $EBMLidList[EBML_ID_FLAGENABLED]                = 'FlagEnabled';
1643                        $EBMLidList[EBML_ID_FLAGFORCED]                 = 'FlagForced';
1644                        $EBMLidList[EBML_ID_FLAGINTERLACED]             = 'FlagInterlaced';
1645                        $EBMLidList[EBML_ID_FLAGLACING]                 = 'FlagLacing';
1646                        $EBMLidList[EBML_ID_GAMMAVALUE]                 = 'GammaValue';
1647                        $EBMLidList[EBML_ID_INFO]                       = 'Info';
1648                        $EBMLidList[EBML_ID_LANGUAGE]                   = 'Language';
1649                        $EBMLidList[EBML_ID_MAXBLOCKADDITIONID]         = 'MaxBlockAdditionID';
1650                        $EBMLidList[EBML_ID_MAXCACHE]                   = 'MaxCache';
1651                        $EBMLidList[EBML_ID_MINCACHE]                   = 'MinCache';
1652                        $EBMLidList[EBML_ID_MUXINGAPP]                  = 'MuxingApp';
1653                        $EBMLidList[EBML_ID_NAME]                       = 'Name';
1654                        $EBMLidList[EBML_ID_NEXTFILENAME]               = 'NextFilename';
1655                        $EBMLidList[EBML_ID_NEXTUID]                    = 'NextUID';
1656                        $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY]    = 'OutputSamplingFrequency';
1657                        $EBMLidList[EBML_ID_PIXELCROPBOTTOM]            = 'PixelCropBottom';
1658                        $EBMLidList[EBML_ID_PIXELCROPLEFT]              = 'PixelCropLeft';
1659                        $EBMLidList[EBML_ID_PIXELCROPRIGHT]             = 'PixelCropRight';
1660                        $EBMLidList[EBML_ID_PIXELCROPTOP]               = 'PixelCropTop';
1661                        $EBMLidList[EBML_ID_PIXELHEIGHT]                = 'PixelHeight';
1662                        $EBMLidList[EBML_ID_PIXELWIDTH]                 = 'PixelWidth';
1663                        $EBMLidList[EBML_ID_PREVFILENAME]               = 'PrevFilename';
1664                        $EBMLidList[EBML_ID_PREVUID]                    = 'PrevUID';
1665                        $EBMLidList[EBML_ID_SAMPLINGFREQUENCY]          = 'SamplingFrequency';
1666                        $EBMLidList[EBML_ID_SEEK]                       = 'Seek';
1667                        $EBMLidList[EBML_ID_SEEKHEAD]                   = 'SeekHead';
1668                        $EBMLidList[EBML_ID_SEEKID]                     = 'SeekID';
1669                        $EBMLidList[EBML_ID_SEEKPOSITION]               = 'SeekPosition';
1670                        $EBMLidList[EBML_ID_SEGMENTFAMILY]              = 'SegmentFamily';
1671                        $EBMLidList[EBML_ID_SEGMENTFILENAME]            = 'SegmentFilename';
1672                        $EBMLidList[EBML_ID_SEGMENTUID]                 = 'SegmentUID';
1673                        $EBMLidList[EBML_ID_SIMPLETAG]                  = 'SimpleTag';
1674                        $EBMLidList[EBML_ID_CLUSTERSLICES]              = 'ClusterSlices';
1675                        $EBMLidList[EBML_ID_STEREOMODE]                 = 'StereoMode';
1676                        $EBMLidList[EBML_ID_TAG]                        = 'Tag';
1677                        $EBMLidList[EBML_ID_TAGBINARY]                  = 'TagBinary';
1678                        $EBMLidList[EBML_ID_TAGCHAPTERUID]              = 'TagChapterUID';
1679                        $EBMLidList[EBML_ID_TAGDEFAULT]                 = 'TagDefault';
1680                        $EBMLidList[EBML_ID_TAGEDITIONUID]              = 'TagEditionUID';
1681                        $EBMLidList[EBML_ID_TAGLANGUAGE]                = 'TagLanguage';
1682                        $EBMLidList[EBML_ID_TAGNAME]                    = 'TagName';
1683                        $EBMLidList[EBML_ID_TAGTRACKUID]                = 'TagTrackUID';
1684                        $EBMLidList[EBML_ID_TAGS]                       = 'Tags';
1685                        $EBMLidList[EBML_ID_TAGSTRING]                  = 'TagString';
1686                        $EBMLidList[EBML_ID_TARGETS]                    = 'Targets';
1687                        $EBMLidList[EBML_ID_TARGETTYPE]                 = 'TargetType';
1688                        $EBMLidList[EBML_ID_TARGETTYPEVALUE]            = 'TargetTypeValue';
1689                        $EBMLidList[EBML_ID_TIMECODESCALE]              = 'TimecodeScale';
1690                        $EBMLidList[EBML_ID_TITLE]                      = 'Title';
1691                        $EBMLidList[EBML_ID_TRACKENTRY]                 = 'TrackEntry';
1692                        $EBMLidList[EBML_ID_TRACKNUMBER]                = 'TrackNumber';
1693                        $EBMLidList[EBML_ID_TRACKOFFSET]                = 'TrackOffset';
1694                        $EBMLidList[EBML_ID_TRACKOVERLAY]               = 'TrackOverlay';
1695                        $EBMLidList[EBML_ID_TRACKS]                     = 'Tracks';
1696                        $EBMLidList[EBML_ID_TRACKTIMECODESCALE]         = 'TrackTimecodeScale';
1697                        $EBMLidList[EBML_ID_TRACKTRANSLATE]             = 'TrackTranslate';
1698                        $EBMLidList[EBML_ID_TRACKTRANSLATECODEC]        = 'TrackTranslateCodec';
1699                        $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID]   = 'TrackTranslateEditionUID';
1700                        $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID]      = 'TrackTranslateTrackID';
1701                        $EBMLidList[EBML_ID_TRACKTYPE]                  = 'TrackType';
1702                        $EBMLidList[EBML_ID_TRACKUID]                   = 'TrackUID';
1703                        $EBMLidList[EBML_ID_VIDEO]                      = 'Video';
1704                        $EBMLidList[EBML_ID_VOID]                       = 'Void';
1705                        $EBMLidList[EBML_ID_WRITINGAPP]                 = 'WritingApp';
1706                }
1707                return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
1708        }
1709
1710}
1711
1712?>
Note: See TracBrowser for help on using the repository browser.