comparison e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.riff.php @ 3:3f6b44aa6b35 judyates

[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author rlm
date Mon, 22 Feb 2010 08:02:39 -0500
parents
children
comparison
equal deleted inserted replaced
2:670229c4eb4b 3:3f6b44aa6b35
1 <?php
2 // +----------------------------------------------------------------------+
3 // | PHP version 5 |
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
6 // +----------------------------------------------------------------------+
7 // | This source file is subject to version 2 of the GPL license, |
8 // | that is bundled with this package in the file license.txt and is |
9 // | available through the world-wide-web at the following url: |
10 // | http://www.gnu.org/copyleft/gpl.html |
11 // +----------------------------------------------------------------------+
12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
13 // +----------------------------------------------------------------------+
14 // | Authors: James Heinrich <infoØgetid3*org> |
15 // | Allan Hansen <ahØartemis*dk> |
16 // +----------------------------------------------------------------------+
17 // | module.audio-video.riff.php |
18 // | module for analyzing RIFF files: |
19 // | Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack3, 8SVX |
20 // | dependencies: module.audio.mp3.php (optional) |
21 // | module.audio.ac3.php (optional) |
22 // | module.audio.dts.php (optional) |
23 // | module.audio-video.mpeg.php (optional) |
24 // +----------------------------------------------------------------------+
25 //
26 // $Id: module.audio-video.riff.php,v 1.10 2006/12/03 20:13:17 ah Exp $
27
28
29
30 class getid3_riff extends getid3_handler
31 {
32
33 private $endian_function = 'LittleEndian2Int';
34
35
36 public function Analyze() {
37
38 $getid3 = $this->getid3;
39
40 $getid3->info['riff']['raw'] = array ();
41 $info_riff = &$getid3->info['riff'];
42 $info_riff_raw = &$info_riff['raw'];
43 $info_audio = &$getid3->info['audio'];
44 $info_video = &$getid3->info['video'];
45 $info_avdataoffset = &$getid3->info['avdataoffset'];
46 $info_avdataend = &$getid3->info['avdataend'];
47 $info_audio_dataformat = &$info_audio['dataformat'];
48 $info_riff_audio = &$info_riff['audio'];
49 $info_riff_video = &$info_riff['video'];
50
51 $original['avdataend'] = $info_avdataend;
52
53 $this->fseek($info_avdataoffset, SEEK_SET);
54 $riff_header = $this->fread(12);
55
56 $riff_sub_type = substr($riff_header, 8, 4);
57
58 switch (substr($riff_header, 0, 4)) {
59
60 case 'FORM':
61 $getid3->info['fileformat'] = 'aiff';
62 $this->endian_function = 'BigEndian2Int';
63 $riff_header_size = getid3_lib::BigEndian2Int(substr($riff_header, 4, 4));
64 $info_riff[$riff_sub_type] = $this->ParseRIFF($info_avdataoffset + 12, $info_avdataoffset + $riff_header_size);
65 $info_riff['header_size'] = $riff_header_size;
66 break;
67
68
69 case 'RIFF':
70 case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
71 case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
72
73 if ($riff_sub_type == 'RMP3') {
74 $riff_sub_type = 'WAVE';
75 }
76
77 $getid3->info['fileformat'] = 'riff';
78 $this->endian_function = 'LittleEndian2Int';
79 $riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_header, 4, 4));
80 $info_riff[$riff_sub_type] = $this->ParseRIFF($info_avdataoffset + 12, $info_avdataoffset + $riff_header_size);
81 $info_riff['header_size'] = $riff_header_size;
82 if ($riff_sub_type == 'WAVE') {
83 $info_riff_wave = &$info_riff['WAVE'];
84 }
85 break;
86
87
88 default:
89 throw new getid3_exception('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$riff_sub_type.'" instead');
90 }
91
92 $endian_function = $this->endian_function;
93
94 $stream_index = 0;
95 switch ($riff_sub_type) {
96
97 case 'WAVE':
98
99 if (empty($info_audio['bitrate_mode'])) {
100 $info_audio['bitrate_mode'] = 'cbr';
101 }
102
103 if (empty($info_audio_dataformat)) {
104 $info_audio_dataformat = 'wav';
105 }
106
107 if (isset($info_riff_wave['data'][0]['offset'])) {
108 $info_avdataoffset = $info_riff_wave['data'][0]['offset'] + 8;
109 $info_avdataend = $info_avdataoffset + $info_riff_wave['data'][0]['size'];
110 }
111
112 if (isset($info_riff_wave['fmt '][0]['data'])) {
113
114 $info_riff_audio[$stream_index] = getid3_riff::RIFFparseWAVEFORMATex($info_riff_wave['fmt '][0]['data']);
115 $info_audio['wformattag'] = $info_riff_audio[$stream_index]['raw']['wFormatTag'];
116 $info_riff_raw['fmt '] = $info_riff_audio[$stream_index]['raw'];
117 unset($info_riff_audio[$stream_index]['raw']);
118 $info_audio['streams'][$stream_index] = $info_riff_audio[$stream_index];
119
120 $info_audio = getid3_riff::array_merge_noclobber($info_audio, $info_riff_audio[$stream_index]);
121 if (substr($info_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
122 $getid3->warning('Audio codec = '.$info_audio['codec']);
123 }
124 $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate'];
125
126 $getid3->info['playtime_seconds'] = (float)((($info_avdataend - $info_avdataoffset) * 8) / $info_audio['bitrate']);
127
128 $info_audio['lossless'] = false;
129
130 if (isset($info_riff_wave['data'][0]['offset']) && isset($info_riff_raw['fmt ']['wFormatTag'])) {
131
132 switch ($info_riff_raw['fmt ']['wFormatTag']) {
133
134 case 0x0001: // PCM
135 $info_audio['lossless'] = true;
136 break;
137
138 case 0x2000: // AC-3
139 $info_audio_dataformat = 'ac3';
140 break;
141
142 default:
143 // do nothing
144 break;
145
146 }
147 }
148
149 $info_audio['streams'][$stream_index]['wformattag'] = $info_audio['wformattag'];
150 $info_audio['streams'][$stream_index]['bitrate_mode'] = $info_audio['bitrate_mode'];
151 $info_audio['streams'][$stream_index]['lossless'] = $info_audio['lossless'];
152 $info_audio['streams'][$stream_index]['dataformat'] = $info_audio_dataformat;
153 }
154
155
156 if (isset($info_riff_wave['rgad'][0]['data'])) {
157
158 // shortcuts
159 $rgadData = &$info_riff_wave['rgad'][0]['data'];
160 $info_riff_raw['rgad'] = array ('track'=>array(), 'album'=>array());
161 $info_riff_raw_rgad = &$info_riff_raw['rgad'];
162 $info_riff_raw_rgad_track = &$info_riff_raw_rgad['track'];
163 $info_riff_raw_rgad_album = &$info_riff_raw_rgad['album'];
164
165 $info_riff_raw_rgad['fPeakAmplitude'] = getid3_riff::BigEndian2Float(strrev(substr($rgadData, 0, 4))); // LittleEndian2Float()
166 $info_riff_raw_rgad['nRadioRgAdjust'] = getid3_lib::$endian_function(substr($rgadData, 4, 2));
167 $info_riff_raw_rgad['nAudiophileRgAdjust'] = getid3_lib::$endian_function(substr($rgadData, 6, 2));
168
169 $n_track_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
170 $n_album_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
171
172 $info_riff_raw_rgad_track['name'] = bindec(substr($n_track_rg_adjust_bit_string, 0, 3));
173 $info_riff_raw_rgad_track['originator'] = bindec(substr($n_track_rg_adjust_bit_string, 3, 3));
174 $info_riff_raw_rgad_track['signbit'] = bindec($n_track_rg_adjust_bit_string[6]);
175 $info_riff_raw_rgad_track['adjustment'] = bindec(substr($n_track_rg_adjust_bit_string, 7, 9));
176 $info_riff_raw_rgad_album['name'] = bindec(substr($n_album_rg_adjust_bit_string, 0, 3));
177 $info_riff_raw_rgad_album['originator'] = bindec(substr($n_album_rg_adjust_bit_string, 3, 3));
178 $info_riff_raw_rgad_album['signbit'] = bindec($n_album_rg_adjust_bit_string[6]);
179 $info_riff_raw_rgad_album['adjustment'] = bindec(substr($n_album_rg_adjust_bit_string, 7, 9));
180
181 $info_riff['rgad']['peakamplitude'] = $info_riff_raw_rgad['fPeakAmplitude'];
182 if (($info_riff_raw_rgad_track['name'] != 0) && ($info_riff_raw_rgad_track['originator'] != 0)) {
183 $info_riff['rgad']['track']['name'] = getid3_lib_replaygain::NameLookup($info_riff_raw_rgad_track['name']);
184 $info_riff['rgad']['track']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_track['originator']);
185 $info_riff['rgad']['track']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($info_riff_raw_rgad_track['adjustment'], $info_riff_raw_rgad_track['signbit']);
186 }
187
188 if (($info_riff_raw_rgad_album['name'] != 0) && ($info_riff_raw_rgad_album['originator'] != 0)) {
189 $info_riff['rgad']['album']['name'] = getid3_lib_replaygain::NameLookup($info_riff_raw_rgad_album['name']);
190 $info_riff['rgad']['album']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_album['originator']);
191 $info_riff['rgad']['album']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($info_riff_raw_rgad_album['adjustment'], $info_riff_raw_rgad_album['signbit']);
192 }
193 }
194
195 if (isset($info_riff_wave['fact'][0]['data'])) {
196
197 $info_riff_raw['fact']['NumberOfSamples'] = getid3_lib::$endian_function(substr($info_riff_wave['fact'][0]['data'], 0, 4));
198
199 // This should be a good way of calculating exact playtime, but some sample files have had incorrect number of samples, so cannot use this method
200 // if (!empty($info_riff_raw['fmt ']['nSamplesPerSec'])) {
201 // $getid3->info['playtime_seconds'] = (float)$info_riff_raw['fact']['NumberOfSamples'] / $info_riff_raw['fmt ']['nSamplesPerSec'];
202 // }
203 }
204
205
206 if (!empty($info_riff_raw['fmt ']['nAvgBytesPerSec'])) {
207 $info_audio['bitrate'] = (int)$info_riff_raw['fmt ']['nAvgBytesPerSec'] * 8;
208 }
209
210 if (isset($info_riff_wave['bext'][0]['data'])) {
211
212 $info_riff_wave_bext_0 = &$info_riff_wave['bext'][0];
213
214 getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_bext_0, $info_riff_wave_bext_0['data'], 0,
215 array (
216 'title' => -256,
217 'author' => -32,
218 'reference' => -32,
219 'origin_date' => -10,
220 'origin_time' => -8,
221 'time_reference' => 8,
222 'bwf_version' => 1,
223 'reserved' => 254
224 )
225 );
226
227 foreach (array ('title', 'author', 'reference') as $key) {
228 $info_riff_wave_bext_0[$key] = trim($info_riff_wave_bext_0[$key]);
229 }
230
231 $info_riff_wave_bext_0['coding_history'] = explode("\r\n", trim(substr($info_riff_wave_bext_0['data'], 601)));
232
233 $info_riff_wave_bext_0['origin_date_unix'] = gmmktime(substr($info_riff_wave_bext_0['origin_time'], 0, 2),
234 substr($info_riff_wave_bext_0['origin_time'], 3, 2),
235 substr($info_riff_wave_bext_0['origin_time'], 6, 2),
236 substr($info_riff_wave_bext_0['origin_date'], 5, 2),
237 substr($info_riff_wave_bext_0['origin_date'], 8, 2),
238 substr($info_riff_wave_bext_0['origin_date'], 0, 4));
239
240 $info_riff['comments']['author'][] = $info_riff_wave_bext_0['author'];
241 $info_riff['comments']['title'][] = $info_riff_wave_bext_0['title'];
242 }
243
244 if (isset($info_riff_wave['MEXT'][0]['data'])) {
245
246 $info_riff_wave_mext_0 = &$info_riff_wave['MEXT'][0];
247
248 $info_riff_wave_mext_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 0, 2));
249 $info_riff_wave_mext_0['flags']['homogenous'] = (bool)($info_riff_wave_mext_0['raw']['sound_information'] & 0x0001);
250 if ($info_riff_wave_mext_0['flags']['homogenous']) {
251 $info_riff_wave_mext_0['flags']['padding'] = ($info_riff_wave_mext_0['raw']['sound_information'] & 0x0002) ? false : true;
252 $info_riff_wave_mext_0['flags']['22_or_44'] = (bool)($info_riff_wave_mext_0['raw']['sound_information'] & 0x0004);
253 $info_riff_wave_mext_0['flags']['free_format'] = (bool)($info_riff_wave_mext_0['raw']['sound_information'] & 0x0008);
254
255 $info_riff_wave_mext_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 2, 2));
256 }
257 $info_riff_wave_mext_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 6, 2));
258 $info_riff_wave_mext_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 8, 2));
259 $info_riff_wave_mext_0['flags']['anciliary_data_left'] = (bool)($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x0001);
260 $info_riff_wave_mext_0['flags']['anciliary_data_free'] = (bool)($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x0002);
261 $info_riff_wave_mext_0['flags']['anciliary_data_right'] = (bool)($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x0004);
262 }
263
264 if (isset($info_riff_wave['cart'][0]['data'])) {
265
266 $info_riff_wave_cart_0 = &$info_riff_wave['cart'][0];
267
268 getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_cart_0, $info_riff_wave_cart_0['data'], 0,
269 array (
270 'version' => -4,
271 'title' => -64,
272 'artist' => -64,
273 'cut_id' => -64,
274 'client_id' => -64,
275 'category' => -64,
276 'classification' => -64,
277 'out_cue' => -64,
278 'start_date' => -10,
279 'start_time' => -8,
280 'end_date' => -10,
281 'end_time' => -8,
282 'producer_app_id' => -64,
283 'producer_app_version' => -64,
284 'user_defined_text' => -64,
285 )
286 );
287
288 foreach (array ('artist', 'cut_id', 'client_id', 'category', 'classification', 'out_cue', 'start_date', 'start_time', 'end_date', 'end_time', 'producer_app_id', 'producer_app_version', 'user_defined_text') as $key) {
289 $info_riff_wave_cart_0[$key] = trim($info_riff_wave_cart_0[$key]);
290 }
291
292 $info_riff_wave_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_cart_0['data'], 680, 4), true);
293
294 for ($i = 0; $i < 8; $i++) {
295 $info_riff_wave_cart_0['post_time'][$i]['usage_fourcc'] = substr($info_riff_wave_cart_0['data'], 684 + ($i * 8), 4);
296 $info_riff_wave_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_cart_0['data'], 684 + ($i * 8) + 4, 4));
297 }
298 $info_riff_wave_cart_0['url'] = trim(substr($info_riff_wave_cart_0['data'], 748, 1024));
299 $info_riff_wave_cart_0['tag_text'] = explode("\r\n", trim(substr($info_riff_wave_cart_0['data'], 1772)));
300
301 $info_riff['comments']['artist'][] = $info_riff_wave_cart_0['artist'];
302 $info_riff['comments']['title'][] = $info_riff_wave_cart_0['title'];
303 }
304
305 if (!isset($info_audio['bitrate']) && isset($info_riff_audio[$stream_index]['bitrate'])) {
306 $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate'];
307 $getid3->info['playtime_seconds'] = (float)((($info_avdataend - $info_avdataoffset) * 8) / $info_audio['bitrate']);
308 }
309
310 if (@$getid3->info['wavpack']) {
311
312 if (!$this->data_string_flag) {
313
314 $info_audio_dataformat = 'wavpack';
315 $info_audio['bitrate_mode'] = 'vbr';
316 $info_audio['encoder'] = 'WavPack v'.$getid3->info['wavpack']['version'];
317
318 // Reset to the way it was - RIFF parsing will have messed this up
319 $info_avdataend = $original['avdataend'];
320 $info_audio['bitrate'] = (($info_avdataend - $info_avdataoffset) * 8) / $getid3->info['playtime_seconds'];
321
322 $this->fseek($info_avdataoffset - 44, SEEK_SET);
323 $riff_data = $this->fread(44);
324 $orignal_riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_data, 4, 4)) + 8;
325 $orignal_riff_data_size = getid3_lib::LittleEndian2Int(substr($riff_data, 40, 4)) + 44;
326
327 if ($orignal_riff_header_size > $orignal_riff_data_size) {
328 $info_avdataend -= ($orignal_riff_header_size - $orignal_riff_data_size);
329 $this->fseek($info_avdataend, SEEK_SET);
330 $riff_data .= $this->fread($orignal_riff_header_size - $orignal_riff_data_size);
331 }
332
333 // move the data chunk after all other chunks (if any)
334 // so that the RIFF parser doesn't see EOF when trying
335 // to skip over the data chunk
336 $riff_data = substr($riff_data, 0, 36).substr($riff_data, 44).substr($riff_data, 36, 8);
337
338 // Save audio info key
339 $saved_info_audio = $info_audio;
340
341 // Analyze riff_data
342 $this->AnalyzeString($riff_data);
343
344 // Restore info key
345 $info_audio = $saved_info_audio;
346 }
347 }
348
349 if (isset($info_riff_raw['fmt ']['wFormatTag'])) {
350
351 switch ($info_riff_raw['fmt ']['wFormatTag']) {
352
353 case 0x08AE: // ClearJump LiteWave
354 $info_audio['bitrate_mode'] = 'vbr';
355 $info_audio_dataformat = 'litewave';
356
357 //typedef struct tagSLwFormat {
358 // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags
359 // DWORD m_dwScale; // scale factor for lossy compression
360 // DWORD m_dwBlockSize; // number of samples in encoded blocks
361 // WORD m_wQuality; // alias for the scale factor
362 // WORD m_wMarkDistance; // distance between marks in bytes
363 // WORD m_wReserved;
364 //
365 // //following paramters are ignored if CF_FILESRC is not set
366 // DWORD m_dwOrgSize; // original file size in bytes
367 // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file
368 // DWORD m_dwRiffChunkSize; // riff chunk size in the original file
369 //
370 // PCMWAVEFORMAT m_OrgWf; // original wave format
371 // }SLwFormat, *PSLwFormat;
372
373 $info_riff['litewave']['raw'] = array ();
374 $info_riff_litewave = &$info_riff['litewave'];
375 $info_riff_litewave_raw = &$info_riff_litewave['raw'];
376
377 getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_litewave_raw, $info_riff_wave['fmt '][0]['data'], 18,
378 array (
379 'compression_method' => 1,
380 'compression_flags' => 1,
381 'm_dwScale' => 4,
382 'm_dwBlockSize' => 4,
383 'm_wQuality' => 2,
384 'm_wMarkDistance' => 2,
385 'm_wReserved' => 2,
386 'm_dwOrgSize' => 4,
387 'm_bFactExists' => 2,
388 'm_dwRiffChunkSize' => 4
389 )
390 );
391
392 //$info_riff_litewave['quality_factor'] = intval(round((2000 - $info_riff_litewave_raw['m_dwScale']) / 20));
393 $info_riff_litewave['quality_factor'] = $info_riff_litewave_raw['m_wQuality'];
394
395 $info_riff_litewave['flags']['raw_source'] = ($info_riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
396 $info_riff_litewave['flags']['vbr_blocksize'] = ($info_riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
397 $info_riff_litewave['flags']['seekpoints'] = (bool)($info_riff_litewave_raw['compression_flags'] & 0x04);
398
399 $info_audio['lossless'] = (($info_riff_litewave_raw['m_wQuality'] == 100) ? true : false);
400 $info_audio['encoder_options'] = '-q'.$info_riff_litewave['quality_factor'];
401 break;
402 }
403 }
404
405 if ($info_avdataend > $getid3->info['filesize']) {
406
407 switch (@$info_audio_dataformat) {
408
409 case 'wavpack': // WavPack
410 case 'lpac': // LPAC
411 case 'ofr': // OptimFROG
412 case 'ofs': // OptimFROG DualStream
413 // lossless compressed audio formats that keep original RIFF headers - skip warning
414 break;
415
416
417 case 'litewave':
418
419 if (($info_avdataend - $getid3->info['filesize']) == 1) {
420 // LiteWave appears to incorrectly *not* pad actual output file
421 // to nearest WORD boundary so may appear to be short by one
422 // byte, in which case - skip warning
423 } else {
424 // Short by more than one byte, throw warning
425 $getid3->warning('Probably truncated file - expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' (short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
426 }
427 break;
428
429
430 default:
431
432 if ((($info_avdataend - $getid3->info['filesize']) == 1) && (($info_riff[$riff_sub_type]['data'][0]['size'] % 2) == 0) && ((($getid3->info['filesize'] - $info_avdataoffset) % 2) == 1)) {
433 // output file appears to be incorrectly *not* padded to nearest WORD boundary
434 // Output less severe warning
435 $getid3->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' therefore short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
436 $info_avdataend = $getid3->info['filesize'];
437 break;
438
439 }
440 // Short by more than one byte, throw warning
441 $getid3->warning('Probably truncated file - expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' (short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
442 $info_avdataend = $getid3->info['filesize'];
443 break;
444 }
445 }
446
447 if (!empty($getid3->info['mpeg']['audio']['LAME']['audio_bytes'])) {
448 if ((($info_avdataend - $info_avdataoffset) - $getid3->info['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
449 $info_avdataend--;
450 $getid3->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored');
451 }
452 }
453
454 if (@$info_audio_dataformat == 'ac3') {
455 unset($info_audio['bits_per_sample']);
456 if (!empty($getid3->info['ac3']['bitrate']) && ($getid3->info['ac3']['bitrate'] != $info_audio['bitrate'])) {
457 $info_audio['bitrate'] = $getid3->info['ac3']['bitrate'];
458 }
459 }
460 break;
461
462
463 case 'AVI ':
464 $info_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
465 $info_video['dataformat'] = 'avi';
466 $getid3->info['mime_type'] = 'video/avi';
467
468 if (isset($info_riff[$riff_sub_type]['movi']['offset'])) {
469 $info_avdataoffset = $info_riff[$riff_sub_type]['movi']['offset'] + 8;
470 $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['movi']['size'];
471 if ($info_avdataend > $getid3->info['filesize']) {
472 $getid3->warning('Probably truncated file - expecting '.$info_riff[$riff_sub_type]['movi']['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' (short by '.($info_riff[$riff_sub_type]['movi']['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
473 $info_avdataend = $getid3->info['filesize'];
474 }
475 }
476
477 if (isset($info_riff['AVI ']['hdrl']['avih'][$stream_index]['data'])) {
478 $avihData = $info_riff['AVI ']['hdrl']['avih'][$stream_index]['data'];
479
480 $info_riff_raw['avih'] = array ();
481 $info_riff_raw_avih = &$info_riff_raw['avih'];
482
483 getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_avih, $avihData, 0,
484 array (
485 'dwMicroSecPerFrame' => 4, // frame display rate (or 0L)
486 'dwMaxBytesPerSec' => 4, // max. transfer rate
487 'dwPaddingGranularity' => 4, // pad to multiples of this size; normally 2K.
488 'dwFlags' => 4, // the ever-present flags
489 'dwTotalFrames' => 4, // # frames in file
490 'dwInitialFrames' => 4,
491 'dwStreams' => 4,
492 'dwSuggestedBufferSize' => 4,
493 'dwWidth' => 4,
494 'dwHeight' => 4,
495 'dwScale' => 4,
496 'dwRate' => 4,
497 'dwStart' => 4,
498 'dwLength' => 4
499 )
500 );
501
502 $info_riff_raw_avih['flags']['hasindex'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000010);
503 $info_riff_raw_avih['flags']['mustuseindex'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000020);
504 $info_riff_raw_avih['flags']['interleaved'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000100);
505 $info_riff_raw_avih['flags']['trustcktype'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000800);
506 $info_riff_raw_avih['flags']['capturedfile'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00010000);
507 $info_riff_raw_avih['flags']['copyrighted'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00020010);
508
509 $info_riff_video[$stream_index] = array ();
510 $info_riff_video_current = &$info_riff_video[$stream_index];
511
512 if ($info_riff_raw_avih['dwWidth'] > 0) {
513 $info_riff_video_current['frame_width'] = $info_riff_raw_avih['dwWidth'];
514 $info_video['resolution_x'] = $info_riff_video_current['frame_width'];
515 }
516
517 if ($info_riff_raw_avih['dwHeight'] > 0) {
518 $info_riff_video_current['frame_height'] = $info_riff_raw_avih['dwHeight'];
519 $info_video['resolution_y'] = $info_riff_video_current['frame_height'];
520 }
521
522 if ($info_riff_raw_avih['dwTotalFrames'] > 0) {
523 $info_riff_video_current['total_frames'] = $info_riff_raw_avih['dwTotalFrames'];
524 $info_video['total_frames'] = $info_riff_video_current['total_frames'];
525 }
526
527 $info_riff_video_current['frame_rate'] = round(1000000 / $info_riff_raw_avih['dwMicroSecPerFrame'], 3);
528 $info_video['frame_rate'] = $info_riff_video_current['frame_rate'];
529 }
530
531 if (isset($info_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
532 if (is_array($info_riff['AVI ']['hdrl']['strl']['strh'])) {
533 for ($i = 0; $i < count($info_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
534 if (isset($info_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
535 $strh_data = $info_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
536 $strh_fcc_type = substr($strh_data, 0, 4);
537
538 if (isset($info_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
539 $strf_data = $info_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
540
541 // shortcut
542 $info_riff_raw_strf_strh_fcc_type_stream_index = &$info_riff_raw['strf'][$strh_fcc_type][$stream_index];
543
544 switch ($strh_fcc_type) {
545 case 'auds':
546 $info_audio['bitrate_mode'] = 'cbr';
547 $info_audio_dataformat = 'wav';
548 if (isset($info_riff_audio) && is_array($info_riff_audio)) {
549 $stream_index = count($info_riff_audio);
550 }
551
552 $info_riff_audio[$stream_index] = getid3_riff::RIFFparseWAVEFORMATex($strf_data);
553 $info_audio['wformattag'] = $info_riff_audio[$stream_index]['raw']['wFormatTag'];
554
555 // shortcut
556 $info_audio['streams'][$stream_index] = $info_riff_audio[$stream_index];
557 $info_audio_streams_currentstream = &$info_audio['streams'][$stream_index];
558
559 if (@$info_audio_streams_currentstream['bits_per_sample'] === 0) {
560 unset($info_audio_streams_currentstream['bits_per_sample']);
561 }
562 $info_audio_streams_currentstream['wformattag'] = $info_audio_streams_currentstream['raw']['wFormatTag'];
563 unset($info_audio_streams_currentstream['raw']);
564
565 // shortcut
566 $info_riff_raw['strf'][$strh_fcc_type][$stream_index] = $info_riff_audio[$stream_index]['raw'];
567
568 unset($info_riff_audio[$stream_index]['raw']);
569 $info_audio = getid3_riff::array_merge_noclobber($info_audio, $info_riff_audio[$stream_index]);
570
571 $info_audio['lossless'] = false;
572 switch ($info_riff_raw_strf_strh_fcc_type_stream_index['wFormatTag']) {
573
574 case 0x0001: // PCM
575 $info_audio_dataformat = 'wav';
576 $info_audio['lossless'] = true;
577 break;
578
579 case 0x0050: // MPEG Layer 2 or Layer 1
580 $info_audio_dataformat = 'mp2'; // Assume Layer-2
581 break;
582
583 case 0x0055: // MPEG Layer 3
584 $info_audio_dataformat = 'mp3';
585 break;
586
587 case 0x00FF: // AAC
588 $info_audio_dataformat = 'aac';
589 break;
590
591 case 0x0161: // Windows Media v7 / v8 / v9
592 case 0x0162: // Windows Media Professional v9
593 case 0x0163: // Windows Media Lossess v9
594 $info_audio_dataformat = 'wma';
595 break;
596
597 case 0x2000: // AC-3
598 $info_audio_dataformat = 'ac3';
599 break;
600
601 case 0x2001: // DTS
602 $info_audio_dataformat = 'dts';
603 break;
604
605 default:
606 $info_audio_dataformat = 'wav';
607 break;
608 }
609 $info_audio_streams_currentstream['dataformat'] = $info_audio_dataformat;
610 $info_audio_streams_currentstream['lossless'] = $info_audio['lossless'];
611 $info_audio_streams_currentstream['bitrate_mode'] = $info_audio['bitrate_mode'];
612 break;
613
614
615 case 'iavs':
616 case 'vids':
617 // shortcut
618 $info_riff_raw['strh'][$i] = array ();
619 $info_riff_raw_strh_current = &$info_riff_raw['strh'][$i];
620
621 getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strh_current, $strh_data, 0,
622 array (
623 'fccType' => -4, // same as $strh_fcc_type;
624 'fccHandler' => -4,
625 'dwFlags' => 4, // Contains AVITF_* flags
626 'wPriority' => 2,
627 'wLanguage' => 2,
628 'dwInitialFrames' => 4,
629 'dwScale' => 4,
630 'dwRate' => 4,
631 'dwStart' => 4,
632 'dwLength' => 4,
633 'dwSuggestedBufferSize' => 4,
634 'dwQuality' => 4,
635 'dwSampleSize' => 4,
636 'rcFrame' => 4
637 )
638 );
639
640 $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strh_current['fccHandler']);
641 $info_video['fourcc'] = $info_riff_raw_strh_current['fccHandler'];
642
643 if (!$info_riff_video_current['codec'] && isset($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) && getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'])) {
644 $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']);
645 $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'];
646 }
647
648 $info_video['codec'] = $info_riff_video_current['codec'];
649 $info_video['pixel_aspect_ratio'] = (float)1;
650
651 switch ($info_riff_raw_strh_current['fccHandler']) {
652
653 case 'HFYU': // Huffman Lossless Codec
654 case 'IRAW': // Intel YUV Uncompressed
655 case 'YUY2': // Uncompressed YUV 4:2:2
656 $info_video['lossless'] = true;
657 break;
658
659 default:
660 $info_video['lossless'] = false;
661 break;
662 }
663
664 switch ($strh_fcc_type) {
665
666 case 'vids':
667 getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strf_strh_fcc_type_stream_index, $strf_data, 0,
668 array (
669 'biSize' => 4, // number of bytes required by the BITMAPINFOHEADER structure
670 'biWidth' => 4, // width of the bitmap in pixels
671 'biHeight' => 4, // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
672 'biPlanes' => 2, // number of color planes on the target device. In most cases this value must be set to 1
673 'biBitCount' => 2, // Specifies the number of bits per pixels
674 'fourcc' => -4, //
675 'biSizeImage' => 4, // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
676 'biXPelsPerMeter' => 4, // horizontal resolution, in pixels per metre, of the target device
677 'biYPelsPerMeter' => 4, // vertical resolution, in pixels per metre, of the target device
678 'biClrUsed' => 4, // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
679 'biClrImportant' => 4 // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
680 )
681 );
682
683 $info_video['bits_per_sample'] = $info_riff_raw_strf_strh_fcc_type_stream_index['biBitCount'];
684
685 if ($info_riff_video_current['codec'] == 'DV') {
686 $info_riff_video_current['dv_type'] = 2;
687 }
688 break;
689
690 case 'iavs':
691 $info_riff_video_current['dv_type'] = 1;
692 break;
693 }
694 break;
695
696 default:
697 $getid3->warning('Unhandled fccType for stream ('.$i.'): "'.$strh_fcc_type.'"');
698 break;
699
700 }
701 }
702 }
703
704 if (isset($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) && getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'])) {
705
706 $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']);
707 $info_video['codec'] = $info_riff_video_current['codec'];
708 $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'];
709
710 switch ($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) {
711
712 case 'HFYU': // Huffman Lossless Codec
713 case 'IRAW': // Intel YUV Uncompressed
714 case 'YUY2': // Uncompressed YUV 4:2:2
715 $info_video['lossless'] = true;
716 $info_video['bits_per_sample'] = 24;
717 break;
718
719 default:
720 $info_video['lossless'] = false;
721 $info_video['bits_per_sample'] = 24;
722 break;
723 }
724
725 }
726 }
727 }
728 }
729 break;
730
731
732 case 'CDDA':
733 $info_audio['bitrate_mode'] = 'cbr';
734 $info_audio_dataformat = 'cda';
735 $info_audio['lossless'] = true;
736 unset($getid3->info['mime_type']);
737
738 $info_avdataoffset = 44;
739
740 if (isset($info_riff['CDDA']['fmt '][0]['data'])) {
741
742 $info_riff_cdda_fmt_0 = &$info_riff['CDDA']['fmt '][0];
743
744 getid3_lib::ReadSequence($this->endian_function, $info_riff_cdda_fmt_0, $info_riff_cdda_fmt_0['data'], 0,
745 array (
746 'unknown1' => 2,
747 'track_num' => 2,
748 'disc_id' => 4,
749 'start_offset_frame' => 4,
750 'playtime_frames' => 4,
751 'unknown6' => 4,
752 'unknown7' => 4
753 )
754 );
755
756 $info_riff_cdda_fmt_0['start_offset_seconds'] = (float)$info_riff_cdda_fmt_0['start_offset_frame'] / 75;
757 $info_riff_cdda_fmt_0['playtime_seconds'] = (float)$info_riff_cdda_fmt_0['playtime_frames'] / 75;
758 $getid3->info['comments']['track'] = $info_riff_cdda_fmt_0['track_num'];
759 $getid3->info['playtime_seconds'] = $info_riff_cdda_fmt_0['playtime_seconds'];
760
761 // hardcoded data for CD-audio
762 $info_audio['sample_rate'] = 44100;
763 $info_audio['channels'] = 2;
764 $info_audio['bits_per_sample'] = 16;
765 $info_audio['bitrate'] = $info_audio['sample_rate'] * $info_audio['channels'] * $info_audio['bits_per_sample'];
766 $info_audio['bitrate_mode'] = 'cbr';
767 }
768 break;
769
770
771 case 'AIFF':
772 case 'AIFC':
773 $info_audio['bitrate_mode'] = 'cbr';
774 $info_audio_dataformat = 'aiff';
775 $info_audio['lossless'] = true;
776 $getid3->info['mime_type'] = 'audio/x-aiff';
777
778 if (isset($info_riff[$riff_sub_type]['SSND'][0]['offset'])) {
779 $info_avdataoffset = $info_riff[$riff_sub_type]['SSND'][0]['offset'] + 8;
780 $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['SSND'][0]['size'];
781 if ($info_avdataend > $getid3->info['filesize']) {
782 if (($info_avdataend == ($getid3->info['filesize'] + 1)) && (($getid3->info['filesize'] % 2) == 1)) {
783 // structures rounded to 2-byte boundary, but dumb encoders
784 // forget to pad end of file to make this actually work
785 } else {
786 $getid3->warning('Probable truncated AIFF file: expecting '.$info_riff[$riff_sub_type]['SSND'][0]['size'].' bytes of audio data, only '.($getid3->info['filesize'] - $info_avdataoffset).' bytes found');
787 }
788 $info_avdataend = $getid3->info['filesize'];
789 }
790 }
791
792 if (isset($info_riff[$riff_sub_type]['COMM'][0]['data'])) {
793
794 // shortcut
795 $info_riff_RIFFsubtype_COMM_0_data = &$info_riff[$riff_sub_type]['COMM'][0]['data'];
796
797 $info_riff_audio['channels'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 0, 2));
798 $info_riff_audio['total_samples'] = getid3_lib::BigEndian2Int( substr($info_riff_RIFFsubtype_COMM_0_data, 2, 4));
799 $info_riff_audio['bits_per_sample'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 6, 2));
800 $info_riff_audio['sample_rate'] = (int)getid3_riff::BigEndian2Float(substr($info_riff_RIFFsubtype_COMM_0_data, 8, 10));
801
802 if ($info_riff[$riff_sub_type]['COMM'][0]['size'] > 18) {
803 $info_riff_audio['codec_fourcc'] = substr($info_riff_RIFFsubtype_COMM_0_data, 18, 4);
804 $codec_name_size = getid3_lib::BigEndian2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 22, 1));
805 $info_riff_audio['codec_name'] = substr($info_riff_RIFFsubtype_COMM_0_data, 23, $codec_name_size);
806
807 switch ($info_riff_audio['codec_name']) {
808
809 case 'NONE':
810 $info_audio['codec'] = 'Pulse Code Modulation (PCM)';
811 $info_audio['lossless'] = true;
812 break;
813
814 case '':
815 switch ($info_riff_audio['codec_fourcc']) {
816
817 // http://developer.apple.com/qa/snd/snd07.html
818 case 'sowt':
819 $info_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
820 $info_audio['lossless'] = true;
821 break;
822
823 case 'twos':
824 $info_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
825 $info_audio['lossless'] = true;
826 break;
827
828 default:
829 break;
830 }
831 break;
832
833 default:
834 $info_audio['codec'] = $info_riff_audio['codec_name'];
835 $info_audio['lossless'] = false;
836 break;
837 }
838 }
839
840 $info_audio['channels'] = $info_riff_audio['channels'];
841
842 if ($info_riff_audio['bits_per_sample'] > 0) {
843 $info_audio['bits_per_sample'] = $info_riff_audio['bits_per_sample'];
844 }
845
846 $info_audio['sample_rate'] = $info_riff_audio['sample_rate'];
847 $getid3->info['playtime_seconds'] = $info_riff_audio['total_samples'] / $info_audio['sample_rate'];
848 }
849
850 if (isset($info_riff[$riff_sub_type]['COMT'])) {
851
852 $comment_count = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], 0, 2));
853 $offset = 2;
854
855 for ($i = 0; $i < $comment_count; $i++) {
856
857 $getid3->info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int( substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 4));
858 $offset += 4;
859
860 $getid3->info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2));
861 $offset += 2;
862
863 $comment_length = getid3_lib::BigEndian2Int( substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2));
864 $offset += 2;
865
866 $getid3->info['comments_raw'][$i]['comment'] = substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, $comment_length);
867 $offset += $comment_length;
868
869 $getid3->info['comments_raw'][$i]['timestamp_unix'] = getid3_riff::DateMac2Unix($getid3->info['comments_raw'][$i]['timestamp']);
870 $info_riff['comments']['comment'][] = $getid3->info['comments_raw'][$i]['comment'];
871 }
872 }
873
874 foreach (array ('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment') as $key => $value) {
875 if (isset($info_riff[$riff_sub_type][$key][0]['data'])) {
876 $info_riff['comments'][$value][] = $info_riff[$riff_sub_type][$key][0]['data'];
877 }
878 }
879 break;
880
881
882 case '8SVX':
883 $info_audio['bitrate_mode'] = 'cbr';
884 $info_audio_dataformat = '8svx';
885 $info_audio['bits_per_sample'] = 8;
886 $info_audio['channels'] = 1; // overridden below, if need be
887 $getid3->info['mime_type'] = 'audio/x-aiff';
888
889 if (isset($info_riff[$riff_sub_type]['BODY'][0]['offset'])) {
890 $info_avdataoffset = $info_riff[$riff_sub_type]['BODY'][0]['offset'] + 8;
891 $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['BODY'][0]['size'];
892 if ($info_avdataend > $getid3->info['filesize']) {
893 $getid3->warning('Probable truncated AIFF file: expecting '.$info_riff[$riff_sub_type]['BODY'][0]['size'].' bytes of audio data, only '.($getid3->info['filesize'] - $info_avdataoffset).' bytes found');
894 }
895 }
896
897 if (isset($info_riff[$riff_sub_type]['VHDR'][0]['offset'])) {
898 // shortcut
899 $info_riff_riff_sub_type_vhdr_0 = &$info_riff[$riff_sub_type]['VHDR'][0];
900
901 getid3_lib::ReadSequence('BigEndian2Int', $info_riff_riff_sub_type_vhdr_0, $info_riff_riff_sub_type_vhdr_0['data'], 0,
902 array (
903 'oneShotHiSamples' => 4,
904 'repeatHiSamples' => 4,
905 'samplesPerHiCycle' => 4,
906 'samplesPerSec' => 2,
907 'ctOctave' => 1,
908 'sCompression' => 1,
909 'Volume' => -4
910 )
911 );
912
913 $info_riff_riff_sub_type_vhdr_0['Volume'] = getid3_riff::FixedPoint16_16($info_riff_riff_sub_type_vhdr_0['Volume']);
914
915 $info_audio['sample_rate'] = $info_riff_riff_sub_type_vhdr_0['samplesPerSec'];
916
917 switch ($info_riff_riff_sub_type_vhdr_0['sCompression']) {
918 case 0:
919 $info_audio['codec'] = 'Pulse Code Modulation (PCM)';
920 $info_audio['lossless'] = true;
921 $actual_bits_per_sample = 8;
922 break;
923
924 case 1:
925 $info_audio['codec'] = 'Fibonacci-delta encoding';
926 $info_audio['lossless'] = false;
927 $actual_bits_per_sample = 4;
928 break;
929
930 default:
931 $getid3->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"');
932 break;
933 }
934 }
935
936 if (isset($info_riff[$riff_sub_type]['CHAN'][0]['data'])) {
937 $ChannelsIndex = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['CHAN'][0]['data'], 0, 4));
938 switch ($ChannelsIndex) {
939 case 6: // Stereo
940 $info_audio['channels'] = 2;
941 break;
942
943 case 2: // Left channel only
944 case 4: // Right channel only
945 $info_audio['channels'] = 1;
946 break;
947
948 default:
949 $getid3->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"');
950 break;
951 }
952
953 }
954
955 foreach (array ('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment') as $key => $value) {
956 if (isset($info_riff[$riff_sub_type][$key][0]['data'])) {
957 $info_riff['comments'][$value][] = $info_riff[$riff_sub_type][$key][0]['data'];
958 }
959 }
960
961 $info_audio['bitrate'] = $info_audio['sample_rate'] * $actual_bits_per_sample * $info_audio['channels'];
962 if (!empty($info_audio['bitrate'])) {
963 $getid3->info['playtime_seconds'] = ($info_avdataend - $info_avdataoffset) / ($info_audio['bitrate'] / 8);
964 }
965 break;
966
967
968 case 'CDXA':
969
970 $getid3->info['mime_type'] = 'video/mpeg';
971 if (!empty($info_riff['CDXA']['data'][0]['size'])) {
972 $GETID3_ERRORARRAY = &$getid3->info['warning'];
973
974 if (!$getid3->include_module_optional('audio-video.mpeg')) {
975 $getid3->warning('MPEG skipped because mpeg module is missing.');
976 }
977
978 else {
979
980 // Clone getid3 - messing with offsets - better safe than sorry
981 $clone = clone $getid3;
982
983 // Analyse
984 $mpeg = new getid3_mpeg($clone);
985 $mpeg->Analyze();
986
987 // Import from clone and destroy
988 $getid3->info['audio'] = $clone->info['audio'];
989 $getid3->info['video'] = $clone->info['video'];
990 $getid3->info['mpeg'] = $clone->info['mpeg'];
991 $getid3->info['warning'] = $clone->info['warning'];
992
993 unset($clone);
994 }
995 }
996
997 break;
998
999
1000 default:
1001 throw new getid3_exception('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$riff_sub_type.'" instead');
1002 }
1003
1004
1005 if (@$info_riff_raw['fmt ']['wFormatTag'] == 1) {
1006
1007 // http://www.mega-nerd.com/erikd/Blog/Windiots/dts.html
1008 $this->fseek($getid3->info['avdataoffset'], SEEK_SET);
1009 $bytes4 = $this->fread(4);
1010
1011 // DTSWAV
1012 if (preg_match('/^\xFF\x1F\x00\xE8/s', $bytes4)) {
1013 $info_audio_dataformat = 'dts';
1014 }
1015
1016 // DTS, but this probably shouldn't happen
1017 elseif (preg_match('/^\x7F\xFF\x80\x01/s', $bytes4)) {
1018 $info_audio_dataformat = 'dts';
1019 }
1020 }
1021
1022 if (@is_array($info_riff_wave['DISP'])) {
1023 $info_riff['comments']['title'][] = trim(substr($info_riff_wave['DISP'][count($info_riff_wave['DISP']) - 1]['data'], 4));
1024 }
1025
1026 if (@is_array($info_riff_wave['INFO'])) {
1027 getid3_riff::RIFFCommentsParse($info_riff_wave['INFO'], $info_riff['comments']);
1028 }
1029
1030 if (isset($info_riff_wave['INFO']) && is_array($info_riff_wave['INFO'])) {
1031
1032 foreach (array ('IARL' => 'archivallocation', 'IART' => 'artist', 'ICDS' => 'costumedesigner', 'ICMS' => 'commissionedby', 'ICMT' => 'comment', 'ICNT' => 'country', 'ICOP' => 'copyright', 'ICRD' => 'creationdate', 'IDIM' => 'dimensions', 'IDIT' => 'digitizationdate', 'IDPI' => 'resolution', 'IDST' => 'distributor', 'IEDT' => 'editor', 'IENG' => 'engineers', 'IFRM' => 'accountofparts', 'IGNR' => 'genre', 'IKEY' => 'keywords', 'ILGT' => 'lightness', 'ILNG' => 'language', 'IMED' => 'orignalmedium', 'IMUS' => 'composer', 'INAM' => 'title', 'IPDS' => 'productiondesigner', 'IPLT' => 'palette', 'IPRD' => 'product', 'IPRO' => 'producer', 'IPRT' => 'part', 'IRTD' => 'rating', 'ISBJ' => 'subject', 'ISFT' => 'software', 'ISGN' => 'secondarygenre', 'ISHP' => 'sharpness', 'ISRC' => 'sourcesupplier', 'ISRF' => 'digitizationsource', 'ISTD' => 'productionstudio', 'ISTR' => 'starring', 'ITCH' => 'encoded_by', 'IWEB' => 'url', 'IWRI' => 'writer') as $key => $value) {
1033 if (isset($info_riff_wave['INFO'][$key])) {
1034 foreach ($info_riff_wave['INFO'][$key] as $comment_id => $comment_data) {
1035 if (trim($comment_data['data']) != '') {
1036 $info_riff['comments'][$value][] = trim($comment_data['data']);
1037 }
1038 }
1039 }
1040 }
1041 }
1042
1043 if (empty($info_audio['encoder']) && !empty($getid3->info['mpeg']['audio']['LAME']['short_version'])) {
1044 $info_audio['encoder'] = $getid3->info['mpeg']['audio']['LAME']['short_version'];
1045 }
1046
1047 if (!isset($getid3->info['playtime_seconds'])) {
1048 $getid3->info['playtime_seconds'] = 0;
1049 }
1050
1051 if (isset($info_riff_raw['avih']['dwTotalFrames']) && isset($info_riff_raw['avih']['dwMicroSecPerFrame'])) {
1052 $getid3->info['playtime_seconds'] = $info_riff_raw['avih']['dwTotalFrames'] * ($info_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
1053 }
1054
1055 if ($getid3->info['playtime_seconds'] > 0) {
1056 if (isset($info_riff_audio) && isset($info_riff_video)) {
1057
1058 if (!isset($getid3->info['bitrate'])) {
1059 $getid3->info['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
1060 }
1061
1062 } elseif (isset($info_riff_audio) && !isset($info_riff_video)) {
1063
1064 if (!isset($info_audio['bitrate'])) {
1065 $info_audio['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
1066 }
1067
1068 } elseif (!isset($info_riff_audio) && isset($info_riff_video)) {
1069
1070 if (!isset($info_video['bitrate'])) {
1071 $info_video['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
1072 }
1073
1074 }
1075 }
1076
1077
1078 if (isset($info_riff_video) && isset($info_audio['bitrate']) && ($info_audio['bitrate'] > 0) && ($getid3->info['playtime_seconds'] > 0)) {
1079
1080 $getid3->info['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
1081 $info_audio['bitrate'] = 0;
1082 $info_video['bitrate'] = $getid3->info['bitrate'];
1083 foreach ($info_riff_audio as $channelnumber => $audioinfoarray) {
1084 $info_video['bitrate'] -= $audioinfoarray['bitrate'];
1085 $info_audio['bitrate'] += $audioinfoarray['bitrate'];
1086 }
1087 if ($info_video['bitrate'] <= 0) {
1088 unset($info_video['bitrate']);
1089 }
1090 if ($info_audio['bitrate'] <= 0) {
1091 unset($info_audio['bitrate']);
1092 }
1093 }
1094
1095 if (isset($getid3->info['mpeg']['audio'])) {
1096 $info_audio_dataformat = 'mp'.$getid3->info['mpeg']['audio']['layer'];
1097 $info_audio['sample_rate'] = $getid3->info['mpeg']['audio']['sample_rate'];
1098 $info_audio['channels'] = $getid3->info['mpeg']['audio']['channels'];
1099 $info_audio['bitrate'] = $getid3->info['mpeg']['audio']['bitrate'];
1100 $info_audio['bitrate_mode'] = strtolower($getid3->info['mpeg']['audio']['bitrate_mode']);
1101
1102 if (!empty($getid3->info['mpeg']['audio']['codec'])) {
1103 $info_audio['codec'] = $getid3->info['mpeg']['audio']['codec'].' '.$info_audio['codec'];
1104 }
1105
1106 if (!empty($info_audio['streams'])) {
1107 foreach ($info_audio['streams'] as $streamnumber => $streamdata) {
1108 if ($streamdata['dataformat'] == $info_audio_dataformat) {
1109 $info_audio['streams'][$streamnumber]['sample_rate'] = $info_audio['sample_rate'];
1110 $info_audio['streams'][$streamnumber]['channels'] = $info_audio['channels'];
1111 $info_audio['streams'][$streamnumber]['bitrate'] = $info_audio['bitrate'];
1112 $info_audio['streams'][$streamnumber]['bitrate_mode'] = $info_audio['bitrate_mode'];
1113 $info_audio['streams'][$streamnumber]['codec'] = $info_audio['codec'];
1114 }
1115 }
1116 }
1117 $info_audio['encoder_options'] = getid3_mp3::GuessEncoderOptions($getid3->info);
1118 }
1119
1120
1121 if (!empty($info_riff_raw['fmt ']['wBitsPerSample']) && ($info_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
1122 switch ($info_audio_dataformat) {
1123 case 'ac3':
1124 // ignore bits_per_sample
1125 break;
1126
1127 default:
1128 $info_audio['bits_per_sample'] = $info_riff_raw['fmt ']['wBitsPerSample'];
1129 break;
1130 }
1131 }
1132
1133
1134 if (empty($info_riff_raw)) {
1135 unset($info_riff['raw']);
1136 }
1137 if (empty($info_riff_audio)) {
1138 unset($info_riff['audio']);
1139 }
1140 if (empty($info_riff_video)) {
1141 unset($info_riff['video']);
1142 }
1143 if (empty($info_audio_dataformat)) {
1144 unset($info_audio['dataformat']);
1145 }
1146 if (empty($getid3->info['audio'])) {
1147 unset($getid3->info['audio']);
1148 }
1149 if (empty($info_video)) {
1150 unset($getid3->info['video']);
1151 }
1152
1153 return true;
1154 }
1155
1156
1157
1158 public function ParseRIFF($start_offset, $max_offset) {
1159
1160 $getid3 = $this->getid3;
1161
1162 $info = &$getid3->info;
1163
1164 $endian_function = $this->endian_function;
1165
1166 $max_offset = min($max_offset, $info['avdataend']);
1167
1168 $riff_chunk = false;
1169
1170 $this->fseek($start_offset, SEEK_SET);
1171
1172 while ($this->ftell() < $max_offset) {
1173
1174 $chunk_name = $this->fread(4);
1175
1176 if (strlen($chunk_name) < 4) {
1177 throw new getid3_exception('Expecting chunk name at offset '.($this->ftell() - 4).' but found nothing. Aborting RIFF parsing.');
1178 }
1179
1180 $chunk_size = getid3_lib::$endian_function($this->fread(4));
1181
1182 if ($chunk_size == 0) {
1183 continue;
1184 throw new getid3_exception('Chunk size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.');
1185 }
1186
1187 if (($chunk_size % 2) != 0) {
1188 // all structures are packed on word boundaries
1189 $chunk_size++;
1190 }
1191
1192 switch ($chunk_name) {
1193
1194 case 'LIST':
1195 $list_name = $this->fread(4);
1196
1197 switch ($list_name) {
1198
1199 case 'movi':
1200 case 'rec ':
1201 $riff_chunk[$list_name]['offset'] = $this->ftell() - 4;
1202 $riff_chunk[$list_name]['size'] = $chunk_size;
1203
1204 static $parsed_audio_stream = false;
1205
1206 if (!$parsed_audio_stream) {
1207 $where_we_were = $this->ftell();
1208 $audio_chunk_header = $this->fread(12);
1209 $audio_chunk_stream_num = substr($audio_chunk_header, 0, 2);
1210 $audio_chunk_stream_type = substr($audio_chunk_header, 2, 2);
1211 $audio_chunk_size = getid3_lib::LittleEndian2Int(substr($audio_chunk_header, 4, 4));
1212
1213 if ($audio_chunk_stream_type == 'wb') {
1214 $first_four_bytes = substr($audio_chunk_header, 8, 4);
1215
1216
1217 //// MPEG
1218
1219 if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $first_four_bytes)) {
1220
1221 if (!$getid3->include_module_optional('audio.mp3')) {
1222 $getid3->warning('MP3 skipped because mp3 module is missing.');
1223 }
1224
1225 elseif (getid3_mp3::MPEGaudioHeaderBytesValid($first_four_bytes)) {
1226
1227 // Clone getid3 - messing with offsets - better safe than sorry
1228 $clone = clone $getid3;
1229 $clone->info['avdataoffset'] = $this->ftell() - 4;
1230 $clone->info['avdataend'] = $this->ftell() + $audio_chunk_size;
1231
1232 $mp3 = new getid3_mp3($clone);
1233 $mp3->AnalyzeMPEGaudioInfo();
1234
1235 // Import from clone and destroy
1236 if (isset($clone->info['mpeg']['audio'])) {
1237
1238 $info['mpeg']['audio'] = $clone->info['mpeg']['audio'];
1239
1240 $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
1241 $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1242 $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
1243 $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1244 $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
1245 $info['bitrate'] = $info['audio']['bitrate'];
1246
1247 $getid3->warning($clone->warnings());
1248 unset($clone);
1249 }
1250 }
1251 }
1252
1253 //// AC3-WAVE
1254
1255 elseif (preg_match('/^\x0B\x77/s', $first_four_bytes)) {
1256
1257 if (!$getid3->include_module_optional('audio.ac3')) {
1258 $getid3->warning('AC3 skipped because ac3 module is missing.');
1259 }
1260
1261 else {
1262
1263 // Clone getid3 - messing with offsets - better safe than sorry
1264 $clone = clone $getid3;
1265 $clone->info['avdataoffset'] = $this->ftell() - 4;
1266 $clone->info['avdataend'] = $this->ftell() + $audio_chunk_size;
1267
1268 // Analyze clone by fp
1269 $ac3 = new getid3_ac3($clone);
1270 $ac3->Analyze();
1271
1272 // Import from clone and destroy
1273 $info['audio'] = $clone->info['audio'];
1274 $info['ac3'] = $clone->info['ac3'];
1275 $getid3->warning($clone->warnings());
1276 unset($clone);
1277 }
1278 }
1279 }
1280
1281 $parsed_audio_stream = true;
1282 $this->fseek($where_we_were, SEEK_SET);
1283
1284 }
1285 $this->fseek($chunk_size - 4, SEEK_CUR);
1286 break;
1287
1288 default:
1289 if (!isset($riff_chunk[$list_name])) {
1290 $riff_chunk[$list_name] = array ();
1291 }
1292 $list_chunk_parent = $list_name;
1293 $list_chunk_max_offset = $this->ftell() - 4 + $chunk_size;
1294 if ($parsed_chunk = $this->ParseRIFF($this->ftell(), $this->ftell() + $chunk_size - 4)) {
1295 $riff_chunk[$list_name] = array_merge_recursive($riff_chunk[$list_name], $parsed_chunk);
1296 }
1297 break;
1298 }
1299 break;
1300
1301
1302 default:
1303
1304 $this_index = 0;
1305 if (isset($riff_chunk[$chunk_name]) && is_array($riff_chunk[$chunk_name])) {
1306 $this_index = count($riff_chunk[$chunk_name]);
1307 }
1308 $riff_chunk[$chunk_name][$this_index]['offset'] = $this->ftell() - 8;
1309 $riff_chunk[$chunk_name][$this_index]['size'] = $chunk_size;
1310 switch ($chunk_name) {
1311 case 'data':
1312 $info['avdataoffset'] = $this->ftell();
1313 $info['avdataend'] = $info['avdataoffset'] + $chunk_size;
1314
1315 $riff_data_chunk_contents_test = $this->fread(36);
1316
1317
1318 //// This is probably MP3 data
1319
1320 if ((strlen($riff_data_chunk_contents_test) > 0) && preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($riff_data_chunk_contents_test, 0, 4))) {
1321
1322 try {
1323
1324 if (!$getid3->include_module_optional('audio.mp3')) {
1325 $getid3->warning('MP3 skipped because mp3 module is missing.');
1326 }
1327
1328
1329 // Clone getid3 - messing with offsets - better safe than sorry
1330 $clone = clone $getid3;
1331
1332 if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($riff_data_chunk_contents_test, 0, 4))) {
1333
1334 $mp3 = new getid3_mp3($clone);
1335 $mp3->AnalyzeMPEGaudioInfo();
1336
1337 // Import from clone and destroy
1338 if (isset($clone->info['mpeg']['audio'])) {
1339
1340 $info['mpeg']['audio'] = $clone->info['mpeg']['audio'];
1341
1342 $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
1343 $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
1344 $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
1345 $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
1346 $info['bitrate'] = $info['audio']['bitrate'];
1347
1348 $getid3->warning($clone->warnings());
1349 unset($clone);
1350 }
1351 }
1352 }
1353 catch (Exception $e) {
1354 // do nothing - not MP3 data
1355 }
1356 }
1357
1358
1359 //// This is probably AC-3 data
1360
1361 elseif ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 0, 2) == "\x0B\x77")) {
1362
1363 if (!$getid3->include_module_optional('audio.ac3')) {
1364 $getid3->warning('AC3 skipped because ac3 module is missing.');
1365 }
1366
1367 else {
1368
1369 // Clone getid3 - messing with offsets - better safe than sorry
1370 $clone = clone $getid3;
1371 $clone->info['avdataoffset'] = $riff_chunk[$chunk_name][$this_index]['offset'];
1372 $clone->info['avdataend'] = $clone->info['avdataoffset'] + $riff_chunk[$chunk_name][$this_index]['size'];
1373
1374 // Analyze clone by fp
1375 $ac3 = new getid3_ac3($clone);
1376 $ac3->Analyze();
1377
1378 // Import from clone and destroy
1379 $info['audio'] = $clone->info['audio'];
1380 $info['ac3'] = $clone->info['ac3'];
1381 $getid3->warning($clone->warnings());
1382 unset($clone);
1383 }
1384 }
1385
1386
1387 // Dolby Digital WAV
1388 // AC-3 content, but not encoded in same format as normal AC-3 file
1389 // For one thing, byte order is swapped
1390
1391 elseif ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 8, 2) == "\x77\x0B")) {
1392
1393 if (!$getid3->include_module_optional('audio.ac3')) {
1394 $getid3->warning('AC3 skipped because ac3 module is missing.');
1395 }
1396
1397 else {
1398
1399 // Extract ac3 data to string
1400 $ac3_data = '';
1401 for ($i = 0; $i < 28; $i += 2) {
1402 // swap byte order
1403 $ac3_data .= substr($riff_data_chunk_contents_test, 8 + $i + 1, 1);
1404 $ac3_data .= substr($riff_data_chunk_contents_test, 8 + $i + 0, 1);
1405 }
1406
1407 // Clone getid3 - messing with offsets - better safe than sorry
1408 $clone = clone $getid3;
1409 $clone->info['avdataoffset'] = 0;
1410 $clone->info['avdataend'] = 20;
1411
1412 // Analyse clone by string
1413 $ac3 = new getid3_ac3($clone);
1414 $ac3->AnalyzeString($ac3_data);
1415
1416 // Import from clone and destroy
1417 $info['audio'] = $clone->info['audio'];
1418 $info['ac3'] = $clone->info['ac3'];
1419 $getid3->warning($clone->warnings());
1420 unset($clone);
1421 }
1422 }
1423
1424
1425 if ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 0, 4) == 'wvpk')) {
1426
1427 // This is WavPack data
1428 $info['wavpack']['offset'] = $riff_chunk[$chunk_name][$this_index]['offset'];
1429 $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($riff_data_chunk_contents_test, 4, 4));
1430 $this->RIFFparseWavPackHeader(substr($riff_data_chunk_contents_test, 8, 28));
1431
1432 } else {
1433
1434 // This is some other kind of data (quite possibly just PCM)
1435 // do nothing special, just skip it
1436
1437 }
1438 $this->fseek($riff_chunk[$chunk_name][$this_index]['offset'] + 8 + $chunk_size, SEEK_SET);
1439 break;
1440
1441 case 'bext':
1442 case 'cart':
1443 case 'fmt ':
1444 case 'MEXT':
1445 case 'DISP':
1446 // always read data in
1447 $riff_chunk[$chunk_name][$this_index]['data'] = $this->fread($chunk_size);
1448 break;
1449
1450 default:
1451 if (!empty($list_chunk_parent) && (($riff_chunk[$chunk_name][$this_index]['offset'] + $riff_chunk[$chunk_name][$this_index]['size']) <= $list_chunk_max_offset)) {
1452 $riff_chunk[$list_chunk_parent][$chunk_name][$this_index]['offset'] = $riff_chunk[$chunk_name][$this_index]['offset'];
1453 $riff_chunk[$list_chunk_parent][$chunk_name][$this_index]['size'] = $riff_chunk[$chunk_name][$this_index]['size'];
1454 unset($riff_chunk[$chunk_name][$this_index]['offset']);
1455 unset($riff_chunk[$chunk_name][$this_index]['size']);
1456 if (isset($riff_chunk[$chunk_name][$this_index]) && empty($riff_chunk[$chunk_name][$this_index])) {
1457 unset($riff_chunk[$chunk_name][$this_index]);
1458 }
1459 if (isset($riff_chunk[$chunk_name]) && empty($riff_chunk[$chunk_name])) {
1460 unset($riff_chunk[$chunk_name]);
1461 }
1462 $riff_chunk[$list_chunk_parent][$chunk_name][$this_index]['data'] = $this->fread($chunk_size);
1463 } elseif ($chunk_size < 2048) {
1464 // only read data in if smaller than 2kB
1465 $riff_chunk[$chunk_name][$this_index]['data'] = $this->fread($chunk_size);
1466 } else {
1467 $this->fseek($chunk_size, SEEK_CUR);
1468 }
1469 break;
1470 }
1471 break;
1472
1473 }
1474
1475 }
1476
1477 return $riff_chunk;
1478 }
1479
1480
1481
1482 private function RIFFparseWavPackHeader($wavpack3_chunk_data) {
1483
1484 // typedef struct {
1485 // char ckID [4];
1486 // long ckSize;
1487 // short version;
1488 // short bits; // added for version 2.00
1489 // short flags, shift; // added for version 3.00
1490 // long total_samples, crc, crc2;
1491 // char extension [4], extra_bc, extras [3];
1492 // } WavpackHeader;
1493
1494 $this->getid3->info['wavpack'] = array ();
1495 $info_wavpack = &$this->getid3->info['wavpack'];
1496
1497 $info_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($wavpack3_chunk_data, 0, 2));
1498
1499 if ($info_wavpack['version'] >= 2) {
1500 $info_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($wavpack3_chunk_data, 2, 2));
1501 }
1502
1503 if ($info_wavpack['version'] >= 3) {
1504
1505 getid3_lib::ReadSequence('LittleEndian2Int', $info_wavpack, $wavpack3_chunk_data, 4,
1506 array (
1507 'flags_raw' => 2,
1508 'shift' => 2,
1509 'total_samples' => 4,
1510 'crc1' => 4,
1511 'crc2' => 4,
1512 'extension' => -4,
1513 'extra_bc' => 1
1514 )
1515 );
1516
1517 for ($i = 0; $i < 3; $i++) {
1518 $info_wavpack['extras'][] = getid3_lib::LittleEndian2Int($wavpack3_chunk_data{25 + $i});
1519 }
1520
1521 $info_wavpack['flags'] = array ();
1522 $info_wavpack_flags = &$info_wavpack['flags'];
1523
1524 $info_wavpack_flags['mono'] = (bool)($info_wavpack['flags_raw'] & 0x000001);
1525 $info_wavpack_flags['fast_mode'] = (bool)($info_wavpack['flags_raw'] & 0x000002);
1526 $info_wavpack_flags['raw_mode'] = (bool)($info_wavpack['flags_raw'] & 0x000004);
1527 $info_wavpack_flags['calc_noise'] = (bool)($info_wavpack['flags_raw'] & 0x000008);
1528 $info_wavpack_flags['high_quality'] = (bool)($info_wavpack['flags_raw'] & 0x000010);
1529 $info_wavpack_flags['3_byte_samples'] = (bool)($info_wavpack['flags_raw'] & 0x000020);
1530 $info_wavpack_flags['over_20_bits'] = (bool)($info_wavpack['flags_raw'] & 0x000040);
1531 $info_wavpack_flags['use_wvc'] = (bool)($info_wavpack['flags_raw'] & 0x000080);
1532 $info_wavpack_flags['noiseshaping'] = (bool)($info_wavpack['flags_raw'] & 0x000100);
1533 $info_wavpack_flags['very_fast_mode'] = (bool)($info_wavpack['flags_raw'] & 0x000200);
1534 $info_wavpack_flags['new_high_quality'] = (bool)($info_wavpack['flags_raw'] & 0x000400);
1535 $info_wavpack_flags['cancel_extreme'] = (bool)($info_wavpack['flags_raw'] & 0x000800);
1536 $info_wavpack_flags['cross_decorrelation'] = (bool)($info_wavpack['flags_raw'] & 0x001000);
1537 $info_wavpack_flags['new_decorrelation'] = (bool)($info_wavpack['flags_raw'] & 0x002000);
1538 $info_wavpack_flags['joint_stereo'] = (bool)($info_wavpack['flags_raw'] & 0x004000);
1539 $info_wavpack_flags['extra_decorrelation'] = (bool)($info_wavpack['flags_raw'] & 0x008000);
1540 $info_wavpack_flags['override_noiseshape'] = (bool)($info_wavpack['flags_raw'] & 0x010000);
1541 $info_wavpack_flags['override_jointstereo'] = (bool)($info_wavpack['flags_raw'] & 0x020000);
1542 $info_wavpack_flags['copy_source_filetime'] = (bool)($info_wavpack['flags_raw'] & 0x040000);
1543 $info_wavpack_flags['create_exe'] = (bool)($info_wavpack['flags_raw'] & 0x080000);
1544 }
1545
1546 return true;
1547 }
1548
1549
1550
1551 public function AnalyzeString(&$string) {
1552
1553 // Rewrite header_size in header
1554 $new_header_size = getid3_lib::LittleEndian2String(strlen($string), 4);
1555 for ($i = 0; $i < 4; $i++) {
1556 $string{$i + 4} = $new_header_size{$i};
1557 }
1558
1559 return parent::AnalyzeString($string);
1560 }
1561
1562
1563
1564 public static function RIFFparseWAVEFORMATex($wave_format_ex_data) {
1565
1566 $wave_format_ex['raw'] = array ();
1567 $wave_format_ex_raw = &$wave_format_ex['raw'];
1568
1569 getid3_lib::ReadSequence('LittleEndian2Int', $wave_format_ex_raw, $wave_format_ex_data, 0,
1570 array (
1571 'wFormatTag' => 2,
1572 'nChannels' => 2,
1573 'nSamplesPerSec' => 4,
1574 'nAvgBytesPerSec' => 4,
1575 'nBlockAlign' => 2,
1576 'wBitsPerSample' => 2
1577 )
1578 );
1579
1580 if (strlen($wave_format_ex_data) > 16) {
1581 $wave_format_ex_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($wave_format_ex_data, 16, 2));
1582 }
1583
1584 $wave_format_ex['codec'] = getid3_riff::RIFFwFormatTagLookup($wave_format_ex_raw['wFormatTag']);
1585 $wave_format_ex['channels'] = $wave_format_ex_raw['nChannels'];
1586 $wave_format_ex['sample_rate'] = $wave_format_ex_raw['nSamplesPerSec'];
1587 $wave_format_ex['bitrate'] = $wave_format_ex_raw['nAvgBytesPerSec'] * 8;
1588 if (@$wave_format_ex_raw['wBitsPerSample']) {
1589 $wave_format_ex['bits_per_sample'] = $wave_format_ex_raw['wBitsPerSample'];
1590 }
1591
1592 return $wave_format_ex;
1593 }
1594
1595
1596
1597 public static function RIFFwFormatTagLookup($w_format_tag) {
1598
1599 static $lookup = array (
1600 0x0000 => 'Microsoft Unknown Wave Format',
1601 0x0001 => 'Pulse Code Modulation (PCM)',
1602 0x0002 => 'Microsoft ADPCM',
1603 0x0003 => 'IEEE Float',
1604 0x0004 => 'Compaq Computer VSELP',
1605 0x0005 => 'IBM CVSD',
1606 0x0006 => 'Microsoft A-Law',
1607 0x0007 => 'Microsoft mu-Law',
1608 0x0008 => 'Microsoft DTS',
1609 0x0010 => 'OKI ADPCM',
1610 0x0011 => 'Intel DVI/IMA ADPCM',
1611 0x0012 => 'Videologic MediaSpace ADPCM',
1612 0x0013 => 'Sierra Semiconductor ADPCM',
1613 0x0014 => 'Antex Electronics G.723 ADPCM',
1614 0x0015 => 'DSP Solutions DigiSTD',
1615 0x0016 => 'DSP Solutions DigiFIX',
1616 0x0017 => 'Dialogic OKI ADPCM',
1617 0x0018 => 'MediaVision ADPCM',
1618 0x0019 => 'Hewlett-Packard CU',
1619 0x0020 => 'Yamaha ADPCM',
1620 0x0021 => 'Speech Compression Sonarc',
1621 0x0022 => 'DSP Group TrueSpeech',
1622 0x0023 => 'Echo Speech EchoSC1',
1623 0x0024 => 'Audiofile AF36',
1624 0x0025 => 'Audio Processing Technology APTX',
1625 0x0026 => 'AudioFile AF10',
1626 0x0027 => 'Prosody 1612',
1627 0x0028 => 'LRC',
1628 0x0030 => 'Dolby AC2',
1629 0x0031 => 'Microsoft GSM 6.10',
1630 0x0032 => 'MSNAudio',
1631 0x0033 => 'Antex Electronics ADPCME',
1632 0x0034 => 'Control Resources VQLPC',
1633 0x0035 => 'DSP Solutions DigiREAL',
1634 0x0036 => 'DSP Solutions DigiADPCM',
1635 0x0037 => 'Control Resources CR10',
1636 0x0038 => 'Natural MicroSystems VBXADPCM',
1637 0x0039 => 'Crystal Semiconductor IMA ADPCM',
1638 0x003A => 'EchoSC3',
1639 0x003B => 'Rockwell ADPCM',
1640 0x003C => 'Rockwell Digit LK',
1641 0x003D => 'Xebec',
1642 0x0040 => 'Antex Electronics G.721 ADPCM',
1643 0x0041 => 'G.728 CELP',
1644 0x0042 => 'MSG723',
1645 0x0050 => 'MPEG Layer-2 or Layer-1',
1646 0x0052 => 'RT24',
1647 0x0053 => 'PAC',
1648 0x0055 => 'MPEG Layer-3',
1649 0x0059 => 'Lucent G.723',
1650 0x0060 => 'Cirrus',
1651 0x0061 => 'ESPCM',
1652 0x0062 => 'Voxware',
1653 0x0063 => 'Canopus Atrac',
1654 0x0064 => 'G.726 ADPCM',
1655 0x0065 => 'G.722 ADPCM',
1656 0x0066 => 'DSAT',
1657 0x0067 => 'DSAT Display',
1658 0x0069 => 'Voxware Byte Aligned',
1659 0x0070 => 'Voxware AC8',
1660 0x0071 => 'Voxware AC10',
1661 0x0072 => 'Voxware AC16',
1662 0x0073 => 'Voxware AC20',
1663 0x0074 => 'Voxware MetaVoice',
1664 0x0075 => 'Voxware MetaSound',
1665 0x0076 => 'Voxware RT29HW',
1666 0x0077 => 'Voxware VR12',
1667 0x0078 => 'Voxware VR18',
1668 0x0079 => 'Voxware TQ40',
1669 0x0080 => 'Softsound',
1670 0x0081 => 'Voxware TQ60',
1671 0x0082 => 'MSRT24',
1672 0x0083 => 'G.729A',
1673 0x0084 => 'MVI MV12',
1674 0x0085 => 'DF G.726',
1675 0x0086 => 'DF GSM610',
1676 0x0088 => 'ISIAudio',
1677 0x0089 => 'Onlive',
1678 0x0091 => 'SBC24',
1679 0x0092 => 'Dolby AC3 SPDIF',
1680 0x0093 => 'MediaSonic G.723',
1681 0x0094 => 'Aculab PLC Prosody 8kbps',
1682 0x0097 => 'ZyXEL ADPCM',
1683 0x0098 => 'Philips LPCBB',
1684 0x0099 => 'Packed',
1685 0x00FF => 'AAC',
1686 0x0100 => 'Rhetorex ADPCM',
1687 0x0101 => 'IBM mu-law',
1688 0x0102 => 'IBM A-law',
1689 0x0103 => 'IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM)',
1690 0x0111 => 'Vivo G.723',
1691 0x0112 => 'Vivo Siren',
1692 0x0123 => 'Digital G.723',
1693 0x0125 => 'Sanyo LD ADPCM',
1694 0x0130 => 'Sipro Lab Telecom ACELP NET',
1695 0x0131 => 'Sipro Lab Telecom ACELP 4800',
1696 0x0132 => 'Sipro Lab Telecom ACELP 8V3',
1697 0x0133 => 'Sipro Lab Telecom G.729',
1698 0x0134 => 'Sipro Lab Telecom G.729A',
1699 0x0135 => 'Sipro Lab Telecom Kelvin',
1700 0x0140 => 'Windows Media Video V8',
1701 0x0150 => 'Qualcomm PureVoice',
1702 0x0151 => 'Qualcomm HalfRate',
1703 0x0155 => 'Ring Zero Systems TUB GSM',
1704 0x0160 => 'Microsoft Audio 1',
1705 0x0161 => 'Windows Media Audio V7 / V8 / V9',
1706 0x0162 => 'Windows Media Audio Professional V9',
1707 0x0163 => 'Windows Media Audio Lossless V9',
1708 0x0200 => 'Creative Labs ADPCM',
1709 0x0202 => 'Creative Labs Fastspeech8',
1710 0x0203 => 'Creative Labs Fastspeech10',
1711 0x0210 => 'UHER Informatic GmbH ADPCM',
1712 0x0220 => 'Quarterdeck',
1713 0x0230 => 'I-link Worldwide VC',
1714 0x0240 => 'Aureal RAW Sport',
1715 0x0250 => 'Interactive Products HSX',
1716 0x0251 => 'Interactive Products RPELP',
1717 0x0260 => 'Consistent Software CS2',
1718 0x0270 => 'Sony SCX',
1719 0x0300 => 'Fujitsu FM Towns Snd',
1720 0x0400 => 'BTV Digital',
1721 0x0401 => 'Intel Music Coder',
1722 0x0450 => 'QDesign Music',
1723 0x0680 => 'VME VMPCM',
1724 0x0681 => 'AT&T Labs TPC',
1725 0x08AE => 'ClearJump LiteWave',
1726 0x1000 => 'Olivetti GSM',
1727 0x1001 => 'Olivetti ADPCM',
1728 0x1002 => 'Olivetti CELP',
1729 0x1003 => 'Olivetti SBC',
1730 0x1004 => 'Olivetti OPR',
1731 0x1100 => 'Lernout & Hauspie Codec (0x1100)',
1732 0x1101 => 'Lernout & Hauspie CELP Codec (0x1101)',
1733 0x1102 => 'Lernout & Hauspie SBC Codec (0x1102)',
1734 0x1103 => 'Lernout & Hauspie SBC Codec (0x1103)',
1735 0x1104 => 'Lernout & Hauspie SBC Codec (0x1104)',
1736 0x1400 => 'Norris',
1737 0x1401 => 'AT&T ISIAudio',
1738 0x1500 => 'Soundspace Music Compression',
1739 0x181C => 'VoxWare RT24 Speech',
1740 0x1FC4 => 'NCT Soft ALF2CD (www.nctsoft.com)',
1741 0x2000 => 'Dolby AC3',
1742 0x2001 => 'Dolby DTS',
1743 0x2002 => 'WAVE_FORMAT_14_4',
1744 0x2003 => 'WAVE_FORMAT_28_8',
1745 0x2004 => 'WAVE_FORMAT_COOK',
1746 0x2005 => 'WAVE_FORMAT_DNET',
1747 0x674F => 'Ogg Vorbis 1',
1748 0x6750 => 'Ogg Vorbis 2',
1749 0x6751 => 'Ogg Vorbis 3',
1750 0x676F => 'Ogg Vorbis 1+',
1751 0x6770 => 'Ogg Vorbis 2+',
1752 0x6771 => 'Ogg Vorbis 3+',
1753 0x7A21 => 'GSM-AMR (CBR, no SID)',
1754 0x7A22 => 'GSM-AMR (VBR, including SID)',
1755 0xFFFE => 'WAVE_FORMAT_EXTENSIBLE',
1756 0xFFFF => 'WAVE_FORMAT_DEVELOPMENT'
1757 );
1758
1759 return @$lookup[$w_format_tag];
1760 }
1761
1762
1763
1764 public static function RIFFfourccLookup($four_cc) {
1765
1766 static $lookup = array (
1767 'swot' => 'http://developer.apple.com/qa/snd/snd07.html',
1768 '____' => 'No Codec (____)',
1769 '_BIT' => 'BI_BITFIELDS (Raw RGB)',
1770 '_JPG' => 'JPEG compressed',
1771 '_PNG' => 'PNG compressed W3C/ISO/IEC (RFC-2083)',
1772 '_RAW' => 'Full Frames (Uncompressed)',
1773 '_RGB' => 'Raw RGB Bitmap',
1774 '_RL4' => 'RLE 4bpp RGB',
1775 '_RL8' => 'RLE 8bpp RGB',
1776 '3IV1' => '3ivx MPEG-4 v1',
1777 '3IV2' => '3ivx MPEG-4 v2',
1778 '3IVX' => '3ivx MPEG-4',
1779 'AASC' => 'Autodesk Animator',
1780 'ABYR' => 'Kensington ?ABYR?',
1781 'AEMI' => 'Array Microsystems VideoONE MPEG1-I Capture',
1782 'AFLC' => 'Autodesk Animator FLC',
1783 'AFLI' => 'Autodesk Animator FLI',
1784 'AMPG' => 'Array Microsystems VideoONE MPEG',
1785 'ANIM' => 'Intel RDX (ANIM)',
1786 'AP41' => 'AngelPotion Definitive',
1787 'ASV1' => 'Asus Video v1',
1788 'ASV2' => 'Asus Video v2',
1789 'ASVX' => 'Asus Video 2.0 (audio)',
1790 'AUR2' => 'AuraVision Aura 2 Codec - YUV 4:2:2',
1791 'AURA' => 'AuraVision Aura 1 Codec - YUV 4:1:1',
1792 'AVDJ' => 'Independent JPEG Group\'s codec (AVDJ)',
1793 'AVRN' => 'Independent JPEG Group\'s codec (AVRN)',
1794 'AYUV' => '4:4:4 YUV (AYUV)',
1795 'AZPR' => 'Quicktime Apple Video (AZPR)',
1796 'BGR ' => 'Raw RGB32',
1797 'BLZ0' => 'FFmpeg MPEG-4',
1798 'BTVC' => 'Conexant Composite Video',
1799 'BINK' => 'RAD Game Tools Bink Video',
1800 'BT20' => 'Conexant Prosumer Video',
1801 'BTCV' => 'Conexant Composite Video Codec',
1802 'BW10' => 'Data Translation Broadway MPEG Capture',
1803 'CC12' => 'Intel YUV12',
1804 'CDVC' => 'Canopus DV',
1805 'CFCC' => 'Digital Processing Systems DPS Perception',
1806 'CGDI' => 'Microsoft Office 97 Camcorder Video',
1807 'CHAM' => 'Winnov Caviara Champagne',
1808 'CJPG' => 'Creative WebCam JPEG',
1809 'CLJR' => 'Cirrus Logic YUV 4:1:1',
1810 'CMYK' => 'Common Data Format in Printing (Colorgraph)',
1811 'CPLA' => 'Weitek 4:2:0 YUV Planar',
1812 'CRAM' => 'Microsoft Video 1 (CRAM)',
1813 'cvid' => 'Radius Cinepak',
1814 'CVID' => 'Radius Cinepak',
1815 'CWLT' => 'Microsoft Color WLT DIB',
1816 'CYUV' => 'Creative Labs YUV',
1817 'CYUY' => 'ATI YUV',
1818 'D261' => 'H.261',
1819 'D263' => 'H.263',
1820 'DIB ' => 'Device Independent Bitmap',
1821 'DIV1' => 'FFmpeg OpenDivX',
1822 'DIV2' => 'Microsoft MPEG-4 v1/v2',
1823 'DIV3' => 'DivX ;-) MPEG-4 v3.x Low-Motion',
1824 'DIV4' => 'DivX ;-) MPEG-4 v3.x Fast-Motion',
1825 'DIV5' => 'DivX MPEG-4 v5.x',
1826 'DIV6' => 'DivX ;-) (MS MPEG-4 v3.x)',
1827 'DIVX' => 'DivX MPEG-4 v4 (OpenDivX / Project Mayo)',
1828 'divx' => 'DivX MPEG-4',
1829 'DMB1' => 'Matrox Rainbow Runner hardware MJPEG',
1830 'DMB2' => 'Paradigm MJPEG',
1831 'DSVD' => '?DSVD?',
1832 'DUCK' => 'Duck TrueMotion 1.0',
1833 'DPS0' => 'DPS/Leitch Reality Motion JPEG',
1834 'DPSC' => 'DPS/Leitch PAR Motion JPEG',
1835 'DV25' => 'Matrox DVCPRO codec',
1836 'DV50' => 'Matrox DVCPRO50 codec',
1837 'DVC ' => 'IEC 61834 and SMPTE 314M (DVC/DV Video)',
1838 'DVCP' => 'IEC 61834 and SMPTE 314M (DVC/DV Video)',
1839 'DVHD' => 'IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps',
1840 'DVMA' => 'Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com)',
1841 'DVSL' => 'IEC Standard DV compressed in SD (SDL)',
1842 'DVAN' => '?DVAN?',
1843 'DVE2' => 'InSoft DVE-2 Videoconferencing',
1844 'dvsd' => 'IEC 61834 and SMPTE 314M DVC/DV Video',
1845 'DVSD' => 'IEC 61834 and SMPTE 314M DVC/DV Video',
1846 'DVX1' => 'Lucent DVX1000SP Video Decoder',
1847 'DVX2' => 'Lucent DVX2000S Video Decoder',
1848 'DVX3' => 'Lucent DVX3000S Video Decoder',
1849 'DX50' => 'DivX v5',
1850 'DXT1' => 'Microsoft DirectX Compressed Texture (DXT1)',
1851 'DXT2' => 'Microsoft DirectX Compressed Texture (DXT2)',
1852 'DXT3' => 'Microsoft DirectX Compressed Texture (DXT3)',
1853 'DXT4' => 'Microsoft DirectX Compressed Texture (DXT4)',
1854 'DXT5' => 'Microsoft DirectX Compressed Texture (DXT5)',
1855 'DXTC' => 'Microsoft DirectX Compressed Texture (DXTC)',
1856 'DXTn' => 'Microsoft DirectX Compressed Texture (DXTn)',
1857 'EM2V' => 'Etymonix MPEG-2 I-frame (www.etymonix.com)',
1858 'EKQ0' => 'Elsa ?EKQ0?',
1859 'ELK0' => 'Elsa ?ELK0?',
1860 'ESCP' => 'Eidos Escape',
1861 'ETV1' => 'eTreppid Video ETV1',
1862 'ETV2' => 'eTreppid Video ETV2',
1863 'ETVC' => 'eTreppid Video ETVC',
1864 'FLIC' => 'Autodesk FLI/FLC Animation',
1865 'FRWT' => 'Darim Vision Forward Motion JPEG (www.darvision.com)',
1866 'FRWU' => 'Darim Vision Forward Uncompressed (www.darvision.com)',
1867 'FLJP' => 'D-Vision Field Encoded Motion JPEG',
1868 'FRWA' => 'SoftLab-Nsk Forward Motion JPEG w/ alpha channel',
1869 'FRWD' => 'SoftLab-Nsk Forward Motion JPEG',
1870 'FVF1' => 'Iterated Systems Fractal Video Frame',
1871 'GLZW' => 'Motion LZW (gabest@freemail.hu)',
1872 'GPEG' => 'Motion JPEG (gabest@freemail.hu)',
1873 'GWLT' => 'Microsoft Greyscale WLT DIB',
1874 'H260' => 'Intel ITU H.260 Videoconferencing',
1875 'H261' => 'Intel ITU H.261 Videoconferencing',
1876 'H262' => 'Intel ITU H.262 Videoconferencing',
1877 'H263' => 'Intel ITU H.263 Videoconferencing',
1878 'H264' => 'Intel ITU H.264 Videoconferencing',
1879 'H265' => 'Intel ITU H.265 Videoconferencing',
1880 'H266' => 'Intel ITU H.266 Videoconferencing',
1881 'H267' => 'Intel ITU H.267 Videoconferencing',
1882 'H268' => 'Intel ITU H.268 Videoconferencing',
1883 'H269' => 'Intel ITU H.269 Videoconferencing',
1884 'HFYU' => 'Huffman Lossless Codec',
1885 'HMCR' => 'Rendition Motion Compensation Format (HMCR)',
1886 'HMRR' => 'Rendition Motion Compensation Format (HMRR)',
1887 'I263' => 'FFmpeg I263 decoder',
1888 'IF09' => 'Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane")',
1889 'IUYV' => 'Interlaced version of UYVY (www.leadtools.com)',
1890 'IY41' => 'Interlaced version of Y41P (www.leadtools.com)',
1891 'IYU1' => '12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard',
1892 'IYU2' => '24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard',
1893 'IYUV' => 'Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes)',
1894 'i263' => 'Intel ITU H.263 Videoconferencing (i263)',
1895 'I420' => 'Intel Indeo 4',
1896 'IAN ' => 'Intel Indeo 4 (RDX)',
1897 'ICLB' => 'InSoft CellB Videoconferencing',
1898 'IGOR' => 'Power DVD',
1899 'IJPG' => 'Intergraph JPEG',
1900 'ILVC' => 'Intel Layered Video',
1901 'ILVR' => 'ITU-T H.263+',
1902 'IPDV' => 'I-O Data Device Giga AVI DV Codec',
1903 'IR21' => 'Intel Indeo 2.1',
1904 'IRAW' => 'Intel YUV Uncompressed',
1905 'IV30' => 'Intel Indeo 3.0',
1906 'IV31' => 'Intel Indeo 3.1',
1907 'IV32' => 'Ligos Indeo 3.2',
1908 'IV33' => 'Ligos Indeo 3.3',
1909 'IV34' => 'Ligos Indeo 3.4',
1910 'IV35' => 'Ligos Indeo 3.5',
1911 'IV36' => 'Ligos Indeo 3.6',
1912 'IV37' => 'Ligos Indeo 3.7',
1913 'IV38' => 'Ligos Indeo 3.8',
1914 'IV39' => 'Ligos Indeo 3.9',
1915 'IV40' => 'Ligos Indeo Interactive 4.0',
1916 'IV41' => 'Ligos Indeo Interactive 4.1',
1917 'IV42' => 'Ligos Indeo Interactive 4.2',
1918 'IV43' => 'Ligos Indeo Interactive 4.3',
1919 'IV44' => 'Ligos Indeo Interactive 4.4',
1920 'IV45' => 'Ligos Indeo Interactive 4.5',
1921 'IV46' => 'Ligos Indeo Interactive 4.6',
1922 'IV47' => 'Ligos Indeo Interactive 4.7',
1923 'IV48' => 'Ligos Indeo Interactive 4.8',
1924 'IV49' => 'Ligos Indeo Interactive 4.9',
1925 'IV50' => 'Ligos Indeo Interactive 5.0',
1926 'JBYR' => 'Kensington ?JBYR?',
1927 'JPEG' => 'Still Image JPEG DIB',
1928 'JPGL' => 'Pegasus Lossless Motion JPEG',
1929 'KMVC' => 'Team17 Software Karl Morton\'s Video Codec',
1930 'LSVM' => 'Vianet Lighting Strike Vmail (Streaming) (www.vianet.com)',
1931 'LEAD' => 'LEAD Video Codec',
1932 'Ljpg' => 'LEAD MJPEG Codec',
1933 'MDVD' => 'Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de)',
1934 'MJPA' => 'Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com)',
1935 'MJPB' => 'Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com)',
1936 'MMES' => 'Matrox MPEG-2 I-frame',
1937 'MP2v' => 'Microsoft S-Mpeg 4 version 1 (MP2v)',
1938 'MP42' => 'Microsoft S-Mpeg 4 version 2 (MP42)',
1939 'MP43' => 'Microsoft S-Mpeg 4 version 3 (MP43)',
1940 'MP4S' => 'Microsoft S-Mpeg 4 version 3 (MP4S)',
1941 'MP4V' => 'FFmpeg MPEG-4',
1942 'MPG1' => 'FFmpeg MPEG 1/2',
1943 'MPG2' => 'FFmpeg MPEG 1/2',
1944 'MPG3' => 'FFmpeg DivX ;-) (MS MPEG-4 v3)',
1945 'MPG4' => 'Microsoft MPEG-4',
1946 'MPGI' => 'Sigma Designs MPEG',
1947 'MPNG' => 'PNG images decoder',
1948 'MSS1' => 'Microsoft Windows Screen Video',
1949 'MSZH' => 'LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)',
1950 'M261' => 'Microsoft H.261',
1951 'M263' => 'Microsoft H.263',
1952 'M4S2' => 'Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2)',
1953 'm4s2' => 'Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2)',
1954 'MC12' => 'ATI Motion Compensation Format (MC12)',
1955 'MCAM' => 'ATI Motion Compensation Format (MCAM)',
1956 'MJ2C' => 'Morgan Multimedia Motion JPEG2000',
1957 'mJPG' => 'IBM Motion JPEG w/ Huffman Tables',
1958 'MJPG' => 'Microsoft Motion JPEG DIB',
1959 'MP42' => 'Microsoft MPEG-4 (low-motion)',
1960 'MP43' => 'Microsoft MPEG-4 (fast-motion)',
1961 'MP4S' => 'Microsoft MPEG-4 (MP4S)',
1962 'mp4s' => 'Microsoft MPEG-4 (mp4s)',
1963 'MPEG' => 'Chromatic Research MPEG-1 Video I-Frame',
1964 'MPG4' => 'Microsoft MPEG-4 Video High Speed Compressor',
1965 'MPGI' => 'Sigma Designs MPEG',
1966 'MRCA' => 'FAST Multimedia Martin Regen Codec',
1967 'MRLE' => 'Microsoft Run Length Encoding',
1968 'MSVC' => 'Microsoft Video 1',
1969 'MTX1' => 'Matrox ?MTX1?',
1970 'MTX2' => 'Matrox ?MTX2?',
1971 'MTX3' => 'Matrox ?MTX3?',
1972 'MTX4' => 'Matrox ?MTX4?',
1973 'MTX5' => 'Matrox ?MTX5?',
1974 'MTX6' => 'Matrox ?MTX6?',
1975 'MTX7' => 'Matrox ?MTX7?',
1976 'MTX8' => 'Matrox ?MTX8?',
1977 'MTX9' => 'Matrox ?MTX9?',
1978 'MV12' => 'Motion Pixels Codec (old)',
1979 'MWV1' => 'Aware Motion Wavelets',
1980 'nAVI' => 'SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm)',
1981 'NT00' => 'NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com)',
1982 'NUV1' => 'NuppelVideo',
1983 'NTN1' => 'Nogatech Video Compression 1',
1984 'NVS0' => 'nVidia GeForce Texture (NVS0)',
1985 'NVS1' => 'nVidia GeForce Texture (NVS1)',
1986 'NVS2' => 'nVidia GeForce Texture (NVS2)',
1987 'NVS3' => 'nVidia GeForce Texture (NVS3)',
1988 'NVS4' => 'nVidia GeForce Texture (NVS4)',
1989 'NVS5' => 'nVidia GeForce Texture (NVS5)',
1990 'NVT0' => 'nVidia GeForce Texture (NVT0)',
1991 'NVT1' => 'nVidia GeForce Texture (NVT1)',
1992 'NVT2' => 'nVidia GeForce Texture (NVT2)',
1993 'NVT3' => 'nVidia GeForce Texture (NVT3)',
1994 'NVT4' => 'nVidia GeForce Texture (NVT4)',
1995 'NVT5' => 'nVidia GeForce Texture (NVT5)',
1996 'PIXL' => 'MiroXL, Pinnacle PCTV',
1997 'PDVC' => 'I-O Data Device Digital Video Capture DV codec',
1998 'PGVV' => 'Radius Video Vision',
1999 'PHMO' => 'IBM Photomotion',
2000 'PIM1' => 'MPEG Realtime (Pinnacle Cards)',
2001 'PIM2' => 'Pegasus Imaging ?PIM2?',
2002 'PIMJ' => 'Pegasus Imaging Lossless JPEG',
2003 'PVEZ' => 'Horizons Technology PowerEZ',
2004 'PVMM' => 'PacketVideo Corporation MPEG-4',
2005 'PVW2' => 'Pegasus Imaging Wavelet Compression',
2006 'Q1.0' => 'Q-Team\'s QPEG 1.0 (www.q-team.de)',
2007 'Q1.1' => 'Q-Team\'s QPEG 1.1 (www.q-team.de)',
2008 'QPEG' => 'Q-Team QPEG 1.0',
2009 'qpeq' => 'Q-Team QPEG 1.1',
2010 'RGB ' => 'Raw BGR32',
2011 'RGBA' => 'Raw RGB w/ Alpha',
2012 'RMP4' => 'REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com)',
2013 'ROQV' => 'Id RoQ File Video Decoder',
2014 'RPZA' => 'Quicktime Apple Video (RPZA)',
2015 'RUD0' => 'Rududu video codec (http://rududu.ifrance.com/rududu/)',
2016 'RV10' => 'RealVideo 1.0 (aka RealVideo 5.0)',
2017 'RV13' => 'RealVideo 1.0 (RV13)',
2018 'RV20' => 'RealVideo G2',
2019 'RV30' => 'RealVideo 8',
2020 'RV40' => 'RealVideo 9',
2021 'RGBT' => 'Raw RGB w/ Transparency',
2022 'RLE ' => 'Microsoft Run Length Encoder',
2023 'RLE4' => 'Run Length Encoded (4bpp, 16-color)',
2024 'RLE8' => 'Run Length Encoded (8bpp, 256-color)',
2025 'RT21' => 'Intel Indeo RealTime Video 2.1',
2026 'rv20' => 'RealVideo G2',
2027 'rv30' => 'RealVideo 8',
2028 'RVX ' => 'Intel RDX (RVX )',
2029 'SMC ' => 'Apple Graphics (SMC )',
2030 'SP54' => 'Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2',
2031 'SPIG' => 'Radius Spigot',
2032 'SVQ3' => 'Sorenson Video 3 (Apple Quicktime 5)',
2033 's422' => 'Tekram VideoCap C210 YUV 4:2:2',
2034 'SDCC' => 'Sun Communication Digital Camera Codec',
2035 'SFMC' => 'CrystalNet Surface Fitting Method',
2036 'SMSC' => 'Radius SMSC',
2037 'SMSD' => 'Radius SMSD',
2038 'smsv' => 'WorldConnect Wavelet Video',
2039 'SPIG' => 'Radius Spigot',
2040 'SPLC' => 'Splash Studios ACM Audio Codec (www.splashstudios.net)',
2041 'SQZ2' => 'Microsoft VXTreme Video Codec V2',
2042 'STVA' => 'ST Microelectronics CMOS Imager Data (Bayer)',
2043 'STVB' => 'ST Microelectronics CMOS Imager Data (Nudged Bayer)',
2044 'STVC' => 'ST Microelectronics CMOS Imager Data (Bunched)',
2045 'STVX' => 'ST Microelectronics CMOS Imager Data (Extended CODEC Data Format)',
2046 'STVY' => 'ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data)',
2047 'SV10' => 'Sorenson Video R1',
2048 'SVQ1' => 'Sorenson Video',
2049 'T420' => 'Toshiba YUV 4:2:0',
2050 'TM2A' => 'Duck TrueMotion Archiver 2.0 (www.duck.com)',
2051 'TVJP' => 'Pinnacle/Truevision Targa 2000 board (TVJP)',
2052 'TVMJ' => 'Pinnacle/Truevision Targa 2000 board (TVMJ)',
2053 'TY0N' => 'Tecomac Low-Bit Rate Codec (www.tecomac.com)',
2054 'TY2C' => 'Trident Decompression Driver',
2055 'TLMS' => 'TeraLogic Motion Intraframe Codec (TLMS)',
2056 'TLST' => 'TeraLogic Motion Intraframe Codec (TLST)',
2057 'TM20' => 'Duck TrueMotion 2.0',
2058 'TM2X' => 'Duck TrueMotion 2X',
2059 'TMIC' => 'TeraLogic Motion Intraframe Codec (TMIC)',
2060 'TMOT' => 'Horizons Technology TrueMotion S',
2061 'tmot' => 'Horizons TrueMotion Video Compression',
2062 'TR20' => 'Duck TrueMotion RealTime 2.0',
2063 'TSCC' => 'TechSmith Screen Capture Codec',
2064 'TV10' => 'Tecomac Low-Bit Rate Codec',
2065 'TY2N' => 'Trident ?TY2N?',
2066 'U263' => 'UB Video H.263/H.263+/H.263++ Decoder',
2067 'UMP4' => 'UB Video MPEG 4 (www.ubvideo.com)',
2068 'UYNV' => 'Nvidia UYVY packed 4:2:2',
2069 'UYVP' => 'Evans & Sutherland YCbCr 4:2:2 extended precision',
2070 'UCOD' => 'eMajix.com ClearVideo',
2071 'ULTI' => 'IBM Ultimotion',
2072 'UYVY' => 'UYVY packed 4:2:2',
2073 'V261' => 'Lucent VX2000S',
2074 'VIFP' => 'VFAPI Reader Codec (www.yks.ne.jp/~hori/)',
2075 'VIV1' => 'FFmpeg H263+ decoder',
2076 'VIV2' => 'Vivo H.263',
2077 'VQC2' => 'Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf)',
2078 'VTLP' => 'Alaris VideoGramPiX',
2079 'VYU9' => 'ATI YUV (VYU9)',
2080 'VYUY' => 'ATI YUV (VYUY)',
2081 'V261' => 'Lucent VX2000S',
2082 'V422' => 'Vitec Multimedia 24-bit YUV 4:2:2 Format',
2083 'V655' => 'Vitec Multimedia 16-bit YUV 4:2:2 Format',
2084 'VCR1' => 'ATI Video Codec 1',
2085 'VCR2' => 'ATI Video Codec 2',
2086 'VCR3' => 'ATI VCR 3.0',
2087 'VCR4' => 'ATI VCR 4.0',
2088 'VCR5' => 'ATI VCR 5.0',
2089 'VCR6' => 'ATI VCR 6.0',
2090 'VCR7' => 'ATI VCR 7.0',
2091 'VCR8' => 'ATI VCR 8.0',
2092 'VCR9' => 'ATI VCR 9.0',
2093 'VDCT' => 'Vitec Multimedia Video Maker Pro DIB',
2094 'VDOM' => 'VDOnet VDOWave',
2095 'VDOW' => 'VDOnet VDOLive (H.263)',
2096 'VDTZ' => 'Darim Vison VideoTizer YUV',
2097 'VGPX' => 'Alaris VideoGramPiX',
2098 'VIDS' => 'Vitec Multimedia YUV 4:2:2 CCIR 601 for V422',
2099 'VIVO' => 'Vivo H.263 v2.00',
2100 'vivo' => 'Vivo H.263',
2101 'VIXL' => 'Miro/Pinnacle Video XL',
2102 'VLV1' => 'VideoLogic/PURE Digital Videologic Capture',
2103 'VP30' => 'On2 VP3.0',
2104 'VP31' => 'On2 VP3.1',
2105 'VX1K' => 'Lucent VX1000S Video Codec',
2106 'VX2K' => 'Lucent VX2000S Video Codec',
2107 'VXSP' => 'Lucent VX1000SP Video Codec',
2108 'WBVC' => 'Winbond W9960',
2109 'WHAM' => 'Microsoft Video 1 (WHAM)',
2110 'WINX' => 'Winnov Software Compression',
2111 'WJPG' => 'AverMedia Winbond JPEG',
2112 'WMV1' => 'Windows Media Video V7',
2113 'WMV2' => 'Windows Media Video V8',
2114 'WMV3' => 'Windows Media Video V9',
2115 'WNV1' => 'Winnov Hardware Compression',
2116 'XYZP' => 'Extended PAL format XYZ palette (www.riff.org)',
2117 'x263' => 'Xirlink H.263',
2118 'XLV0' => 'NetXL Video Decoder',
2119 'XMPG' => 'Xing MPEG (I-Frame only)',
2120 'XVID' => 'XviD MPEG-4 (www.xvid.org)',
2121 'XXAN' => '?XXAN?',
2122 'YU92' => 'Intel YUV (YU92)',
2123 'YUNV' => 'Nvidia Uncompressed YUV 4:2:2',
2124 'YUVP' => 'Extended PAL format YUV palette (www.riff.org)',
2125 'Y211' => 'YUV 2:1:1 Packed',
2126 'Y411' => 'YUV 4:1:1 Packed',
2127 'Y41B' => 'Weitek YUV 4:1:1 Planar',
2128 'Y41P' => 'Brooktree PC1 YUV 4:1:1 Packed',
2129 'Y41T' => 'Brooktree PC1 YUV 4:1:1 with transparency',
2130 'Y42B' => 'Weitek YUV 4:2:2 Planar',
2131 'Y42T' => 'Brooktree UYUV 4:2:2 with transparency',
2132 'Y422' => 'ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera',
2133 'Y800' => 'Simple, single Y plane for monochrome images',
2134 'Y8 ' => 'Grayscale video',
2135 'YC12' => 'Intel YUV 12 codec',
2136 'YUV8' => 'Winnov Caviar YUV8',
2137 'YUV9' => 'Intel YUV9',
2138 'YUY2' => 'Uncompressed YUV 4:2:2',
2139 'YUYV' => 'Canopus YUV',
2140 'YV12' => 'YVU12 Planar',
2141 'YVU9' => 'Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes)',
2142 'YVYU' => 'YVYU 4:2:2 Packed',
2143 'ZLIB' => 'Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)',
2144 'ZPEG' => 'Metheus Video Zipper'
2145 );
2146
2147 return @$lookup[$four_cc];
2148 }
2149
2150
2151
2152 public static function RIFFcommentsParse(&$riff_info_aray, &$comments_target_array) {
2153
2154 static $lookup = array(
2155 'IARL' => 'archivallocation',
2156 'IART' => 'artist',
2157 'ICDS' => 'costumedesigner',
2158 'ICMS' => 'commissionedby',
2159 'ICMT' => 'comment',
2160 'ICNT' => 'country',
2161 'ICOP' => 'copyright',
2162 'ICRD' => 'creationdate',
2163 'IDIM' => 'dimensions',
2164 'IDIT' => 'digitizationdate',
2165 'IDPI' => 'resolution',
2166 'IDST' => 'distributor',
2167 'IEDT' => 'editor',
2168 'IENG' => 'engineers',
2169 'IFRM' => 'accountofparts',
2170 'IGNR' => 'genre',
2171 'IKEY' => 'keywords',
2172 'ILGT' => 'lightness',
2173 'ILNG' => 'language',
2174 'IMED' => 'orignalmedium',
2175 'IMUS' => 'composer',
2176 'INAM' => 'title',
2177 'IPDS' => 'productiondesigner',
2178 'IPLT' => 'palette',
2179 'IPRD' => 'product',
2180 'IPRO' => 'producer',
2181 'IPRT' => 'part',
2182 'IRTD' => 'rating',
2183 'ISBJ' => 'subject',
2184 'ISFT' => 'software',
2185 'ISGN' => 'secondarygenre',
2186 'ISHP' => 'sharpness',
2187 'ISRC' => 'sourcesupplier',
2188 'ISRF' => 'digitizationsource',
2189 'ISTD' => 'productionstudio',
2190 'ISTR' => 'starring',
2191 'ITCH' => 'encoded_by',
2192 'IWEB' => 'url',
2193 'IWRI' => 'writer'
2194 );
2195
2196 foreach ($lookup as $key => $value) {
2197 if (isset($riff_info_aray[$key])) {
2198 foreach ($riff_info_aray[$key] as $comment_id => $comment_data) {
2199 if (trim($comment_data['data']) != '') {
2200 @$comments_target_array[$value][] = trim($comment_data['data']);
2201 }
2202 }
2203 }
2204 }
2205 return true;
2206 }
2207
2208
2209
2210 public static function array_merge_noclobber($array1, $array2) {
2211 if (!is_array($array1) || !is_array($array2)) {
2212 return false;
2213 }
2214 $new_array = $array1;
2215 foreach ($array2 as $key => $val) {
2216 if (is_array($val) && isset($new_array[$key]) && is_array($new_array[$key])) {
2217 $new_array[$key] = getid3_riff::array_merge_noclobber($new_array[$key], $val);
2218 } elseif (!isset($new_array[$key])) {
2219 $new_array[$key] = $val;
2220 }
2221 }
2222 return $new_array;
2223 }
2224
2225
2226
2227 public static function DateMac2Unix($mac_date) {
2228
2229 // Macintosh timestamp: seconds since 00:00h January 1, 1904
2230 // UNIX timestamp: seconds since 00:00h January 1, 1970
2231 return (int)($mac_date - 2082844800);
2232 }
2233
2234
2235
2236 public static function FixedPoint16_16($raw_data) {
2237
2238 return getid3_lib::BigEndian2Int(substr($raw_data, 0, 2)) + (float)(getid3_lib::BigEndian2Int(substr($raw_data, 2, 2)) / 65536); // pow(2, 16) = 65536
2239 }
2240
2241
2242
2243 function BigEndian2Float($byte_word) {
2244
2245 // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
2246 // http://www.psc.edu/general/software/packages/ieee/ieee.html
2247 // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
2248
2249 $bit_word = getid3_lib::BigEndian2Bin($byte_word);
2250 $sign_bit = $bit_word{0};
2251
2252 switch (strlen($byte_word) * 8) {
2253 case 32:
2254 $exponent_bits = 8;
2255 $fraction_bits = 23;
2256 break;
2257
2258 case 64:
2259 $exponent_bits = 11;
2260 $fraction_bits = 52;
2261 break;
2262
2263 case 80:
2264 // 80-bit Apple SANE format
2265 // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
2266 $exponent_string = substr($bit_word, 1, 15);
2267 $is_normalized = intval($bit_word{16});
2268 $fraction_string = substr($bit_word, 17, 63);
2269 $exponent = pow(2, bindec($exponent_string) - 16383);
2270 $fraction = $is_normalized + bindec($fraction_string) / bindec('1'.str_repeat('0', strlen($fraction_string)));
2271 $float_value = $exponent * $fraction;
2272 if ($sign_bit == '1') {
2273 $float_value *= -1;
2274 }
2275 return $float_value;
2276 break;
2277
2278 default:
2279 return false;
2280 break;
2281 }
2282 $exponent_string = substr($bit_word, 1, $exponent_bits);
2283 $fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits);
2284 $exponent = bindec($exponent_string);
2285 $fraction = bindec($fraction_string);
2286
2287 if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) {
2288 // Not a Number
2289 $float_value = false;
2290 } elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) {
2291 if ($sign_bit == '1') {
2292 $float_value = '-infinity';
2293 } else {
2294 $float_value = '+infinity';
2295 }
2296 } elseif (($exponent == 0) && ($fraction == 0)) {
2297 if ($sign_bit == '1') {
2298 $float_value = -0;
2299 } else {
2300 $float_value = 0;
2301 }
2302 $float_value = ($sign_bit ? 0 : -0);
2303 } elseif (($exponent == 0) && ($fraction != 0)) {
2304 // These are 'unnormalized' values
2305 $float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * bindec($fraction_string) / bindec('1'.str_repeat('0', strlen($fraction_string)));
2306 if ($sign_bit == '1') {
2307 $float_value *= -1;
2308 }
2309 } elseif ($exponent != 0) {
2310 $float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + bindec($fraction_string) / bindec('1'.str_repeat('0', strlen($fraction_string))));
2311 if ($sign_bit == '1') {
2312 $float_value *= -1;
2313 }
2314 }
2315 return (float) $float_value;
2316 }
2317 }
2318
2319 ?>