Conditions | 180 |
Paths | 14 |
Total Lines | 1118 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | } |
||
2319 | ?> |
||