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.real.php | |
18
|
|
|
// | Module for analyzing Real Audio/Video files | |
19
|
|
|
// | dependencies: module.audio-video.riff.php | |
20
|
|
|
// +----------------------------------------------------------------------+ |
21
|
|
|
// |
22
|
|
|
// $Id: module.audio-video.real.php,v 1.4 2006/11/02 10:48:00 ah Exp $ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class getid3_real extends getid3_handler |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
public function Analyze() { |
30
|
|
|
|
31
|
|
|
$getid3 = $this->getid3; |
32
|
|
|
|
33
|
|
|
$getid3->include_module('audio-video.riff'); |
34
|
|
|
|
35
|
|
|
$getid3->info['fileformat'] = 'real'; |
36
|
|
|
$getid3->info['bitrate'] = 0; |
37
|
|
|
$getid3->info['playtime_seconds'] = 0; |
38
|
|
|
|
39
|
|
|
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); |
40
|
|
|
$chunk_counter = 0; |
41
|
|
|
|
42
|
|
|
while (ftell($getid3->fp) < $getid3->info['avdataend']) { |
43
|
|
|
|
44
|
|
|
$chunk_data = fread($getid3->fp, 8); |
45
|
|
|
$chunk_name = substr($chunk_data, 0, 4); |
46
|
|
|
$chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4)); |
47
|
|
|
|
48
|
|
|
if ($chunk_name == '.ra'."\xFD") { |
49
|
|
|
$chunk_data .= fread($getid3->fp, $chunk_size - 8); |
50
|
|
|
|
51
|
|
|
if ($this->ParseOldRAheader(substr($chunk_data, 0, 128), $getid3->info['real']['old_ra_header'])) { |
52
|
|
|
|
53
|
|
|
$getid3->info['audio']['dataformat'] = 'real'; |
54
|
|
|
$getid3->info['audio']['lossless'] = false; |
55
|
|
|
$getid3->info['audio']['sample_rate'] = $getid3->info['real']['old_ra_header']['sample_rate']; |
56
|
|
|
$getid3->info['audio']['bits_per_sample'] = $getid3->info['real']['old_ra_header']['bits_per_sample']; |
57
|
|
|
$getid3->info['audio']['channels'] = $getid3->info['real']['old_ra_header']['channels']; |
58
|
|
|
|
59
|
|
|
$getid3->info['playtime_seconds'] = 60 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['real']['old_ra_header']['bytes_per_minute']); |
60
|
|
|
$getid3->info['audio']['bitrate'] = 8 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['playtime_seconds']); |
61
|
|
|
$getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($getid3->info['real']['old_ra_header']['fourcc'], $getid3->info['audio']['bitrate']); |
62
|
|
|
|
63
|
|
|
foreach ($getid3->info['real']['old_ra_header']['comments'] as $key => $value_array) { |
64
|
|
|
|
65
|
|
|
if (strlen(trim($value_array[0])) > 0) { |
66
|
|
|
$getid3->info['real']['comments'][$key][] = trim($value_array[0]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
return true; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
throw new getid3_exception('There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or [email protected]'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$getid3->info['real']['chunks'][$chunk_counter] = array (); |
76
|
|
|
$info_real_chunks_current_chunk = &$getid3->info['real']['chunks'][$chunk_counter]; |
77
|
|
|
|
78
|
|
|
$info_real_chunks_current_chunk['name'] = $chunk_name; |
79
|
|
|
$info_real_chunks_current_chunk['offset'] = ftell($getid3->fp) - 8; |
80
|
|
|
$info_real_chunks_current_chunk['length'] = $chunk_size; |
81
|
|
|
|
82
|
|
|
if (($info_real_chunks_current_chunk['offset'] + $info_real_chunks_current_chunk['length']) > $getid3->info['avdataend']) { |
83
|
|
|
$getid3->warning('Chunk "'.$info_real_chunks_current_chunk['name'].'" at offset '.$info_real_chunks_current_chunk['offset'].' claims to be '.$info_real_chunks_current_chunk['length'].' bytes long, which is beyond end of file'); |
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if ($chunk_size > (getid3::FREAD_BUFFER_SIZE + 8)) { |
88
|
|
|
$chunk_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE - 8); |
89
|
|
|
fseek($getid3->fp, $info_real_chunks_current_chunk['offset'] + $chunk_size, SEEK_SET); |
90
|
|
|
|
91
|
|
|
} elseif(($chunk_size - 8) > 0) { |
92
|
|
|
$chunk_data .= fread($getid3->fp, $chunk_size - 8); |
93
|
|
|
} |
94
|
|
|
$offset = 8; |
95
|
|
|
|
96
|
|
|
switch ($chunk_name) { |
97
|
|
|
|
98
|
|
|
case '.RMF': // RealMedia File Header |
99
|
|
|
|
100
|
|
|
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
101
|
|
|
$offset += 2; |
102
|
|
|
|
103
|
|
|
switch ($info_real_chunks_current_chunk['object_version']) { |
104
|
|
|
|
105
|
|
|
case 0: |
106
|
|
|
$info_real_chunks_current_chunk['file_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
107
|
|
|
$offset += 4; |
108
|
|
|
|
109
|
|
|
$info_real_chunks_current_chunk['headers_count'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
110
|
|
|
$offset += 4; |
111
|
|
|
break; |
112
|
|
|
|
113
|
|
|
default: |
114
|
|
|
//$getid3->warning('Expected .RMF-object_version to be "0", actual value is "'.$info_real_chunks_current_chunk['object_version'].'" (should not be a problem)'; |
115
|
|
|
break; |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
break; |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
case 'PROP': // Properties Header |
122
|
|
|
|
123
|
|
|
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
124
|
|
|
$offset += 2; |
125
|
|
|
|
126
|
|
|
if ($info_real_chunks_current_chunk['object_version'] == 0) { |
127
|
|
|
|
128
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, |
129
|
|
|
array ( |
130
|
|
|
'max_bit_rate' => 4, |
131
|
|
|
'avg_bit_rate' => 4, |
132
|
|
|
'max_packet_size' => 4, |
133
|
|
|
'avg_packet_size' => 4, |
134
|
|
|
'num_packets' => 4, |
135
|
|
|
'duration' => 4, |
136
|
|
|
'preroll' => 4, |
137
|
|
|
'index_offset' => 4, |
138
|
|
|
'data_offset' => 4, |
139
|
|
|
'num_streams' => 2, |
140
|
|
|
'flags_raw' => 2 |
141
|
|
|
) |
142
|
|
|
); |
143
|
|
|
$offset += 40; |
144
|
|
|
|
145
|
|
|
$getid3->info['playtime_seconds'] = $info_real_chunks_current_chunk['duration'] / 1000; |
146
|
|
|
if ($info_real_chunks_current_chunk['duration'] > 0) { |
147
|
|
|
$getid3->info['bitrate'] += $info_real_chunks_current_chunk['avg_bit_rate']; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$info_real_chunks_current_chunk['flags']['save_enabled'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0001); |
151
|
|
|
$info_real_chunks_current_chunk['flags']['perfect_play'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0002); |
152
|
|
|
$info_real_chunks_current_chunk['flags']['live_broadcast'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0004); |
153
|
|
|
} |
154
|
|
|
break; |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
case 'MDPR': // Media Properties Header |
158
|
|
|
|
159
|
|
|
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
160
|
|
|
$offset += 2; |
161
|
|
|
|
162
|
|
|
if ($info_real_chunks_current_chunk['object_version'] == 0) { |
163
|
|
|
|
164
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, |
165
|
|
|
array ( |
166
|
|
|
'stream_number' => 2, |
167
|
|
|
'max_bit_rate' => 4, |
168
|
|
|
'avg_bit_rate' => 4, |
169
|
|
|
'max_packet_size' => 4, |
170
|
|
|
'avg_packet_size' => 4, |
171
|
|
|
'start_time' => 4, |
172
|
|
|
'preroll' => 4, |
173
|
|
|
'duration' => 4, |
174
|
|
|
'stream_name_size' => 1 |
175
|
|
|
) |
176
|
|
|
); |
177
|
|
|
$offset += 31; |
178
|
|
|
|
179
|
|
|
$info_real_chunks_current_chunk['stream_name'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['stream_name_size']); |
180
|
|
|
$offset += $info_real_chunks_current_chunk['stream_name_size']; |
181
|
|
|
|
182
|
|
|
$info_real_chunks_current_chunk['mime_type_size'] = getid3_lib::BigEndian2Int($chunk_data{$offset++}); |
183
|
|
|
|
184
|
|
|
$info_real_chunks_current_chunk['mime_type'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['mime_type_size']); |
185
|
|
|
$offset += $info_real_chunks_current_chunk['mime_type_size']; |
186
|
|
|
|
187
|
|
|
$info_real_chunks_current_chunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
188
|
|
|
$offset += 4; |
189
|
|
|
|
190
|
|
|
$info_real_chunks_current_chunk['type_specific_data'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['type_specific_len']); |
191
|
|
|
$offset += $info_real_chunks_current_chunk['type_specific_len']; |
192
|
|
|
|
193
|
|
|
$info_real_chunks_current_chunk_typespecificdata = &$info_real_chunks_current_chunk['type_specific_data']; |
194
|
|
|
|
195
|
|
|
switch ($info_real_chunks_current_chunk['mime_type']) { |
196
|
|
|
|
197
|
|
|
case 'video/x-pn-realvideo': |
198
|
|
|
case 'video/x-pn-multirate-realvideo': |
199
|
|
|
// http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html |
200
|
|
|
|
201
|
|
|
$info_real_chunks_current_chunk['video_info'] = array (); |
202
|
|
|
$info_real_chunks_current_chunk_video_info = &$info_real_chunks_current_chunk['video_info']; |
203
|
|
|
|
204
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk_video_info, $info_real_chunks_current_chunk_typespecificdata, 0, |
205
|
|
|
array ( |
206
|
|
|
'dwSize' => 4, |
207
|
|
|
'fourcc1' => -4, |
208
|
|
|
'fourcc2' => -4, |
209
|
|
|
'width' => 2, |
210
|
|
|
'height' => 2, |
211
|
|
|
'bits_per_sample' => 2, |
212
|
|
|
'IGNORE-unknown1' => 2, |
213
|
|
|
'IGNORE-unknown2' => 2, |
214
|
|
|
'frames_per_second' => 2, |
215
|
|
|
'IGNORE-unknown3' => 2, |
216
|
|
|
'IGNORE-unknown4' => 2, |
217
|
|
|
'IGNORE-unknown5' => 2, |
218
|
|
|
'IGNORE-unknown6' => 2, |
219
|
|
|
'IGNORE-unknown7' => 2, |
220
|
|
|
'IGNORE-unknown8' => 2, |
221
|
|
|
'IGNORE-unknown9' => 2 |
222
|
|
|
) |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
$info_real_chunks_current_chunk_video_info['codec'] = getid3_riff::RIFFfourccLookup($info_real_chunks_current_chunk_video_info['fourcc2']); |
226
|
|
|
|
227
|
|
|
$getid3->info['video']['resolution_x'] = $info_real_chunks_current_chunk_video_info['width']; |
228
|
|
|
$getid3->info['video']['resolution_y'] = $info_real_chunks_current_chunk_video_info['height']; |
229
|
|
|
$getid3->info['video']['frame_rate'] = (float)$info_real_chunks_current_chunk_video_info['frames_per_second']; |
230
|
|
|
$getid3->info['video']['codec'] = $info_real_chunks_current_chunk_video_info['codec']; |
231
|
|
|
$getid3->info['video']['bits_per_sample'] = $info_real_chunks_current_chunk_video_info['bits_per_sample']; |
232
|
|
|
break; |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
case 'audio/x-pn-realaudio': |
236
|
|
|
case 'audio/x-pn-multirate-realaudio': |
237
|
|
|
|
238
|
|
|
$this->ParseOldRAheader($info_real_chunks_current_chunk_typespecificdata, $info_real_chunks_current_chunk['parsed_audio_data']); |
239
|
|
|
|
240
|
|
|
$getid3->info['audio']['sample_rate'] = $info_real_chunks_current_chunk['parsed_audio_data']['sample_rate']; |
241
|
|
|
$getid3->info['audio']['bits_per_sample'] = $info_real_chunks_current_chunk['parsed_audio_data']['bits_per_sample']; |
242
|
|
|
$getid3->info['audio']['channels'] = $info_real_chunks_current_chunk['parsed_audio_data']['channels']; |
243
|
|
|
|
244
|
|
|
if (!empty($getid3->info['audio']['dataformat'])) { |
245
|
|
|
foreach ($getid3->info['audio'] as $key => $value) { |
246
|
|
|
if ($key != 'streams') { |
247
|
|
|
$getid3->info['audio']['streams'][$info_real_chunks_current_chunk['stream_number']][$key] = $value; |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
break; |
252
|
|
|
|
253
|
|
|
|
254
|
|
|
case 'logical-fileinfo': |
255
|
|
|
|
256
|
|
|
$info_real_chunks_current_chunk['logical_fileinfo']['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 0, 4)); |
257
|
|
|
// $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown1'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 4, 4)); |
258
|
|
|
$info_real_chunks_current_chunk['logical_fileinfo']['num_tags'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 8, 4)); |
259
|
|
|
// $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown2'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 12, 4)); |
260
|
|
|
break; |
261
|
|
|
|
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
if (empty($getid3->info['playtime_seconds'])) { |
266
|
|
|
$getid3->info['playtime_seconds'] = max($getid3->info['playtime_seconds'], ($info_real_chunks_current_chunk['duration'] + $info_real_chunks_current_chunk['start_time']) / 1000); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
if ($info_real_chunks_current_chunk['duration'] > 0) { |
270
|
|
|
|
271
|
|
|
switch ($info_real_chunks_current_chunk['mime_type']) { |
272
|
|
|
|
273
|
|
|
case 'audio/x-pn-realaudio': |
274
|
|
|
case 'audio/x-pn-multirate-realaudio': |
275
|
|
|
|
276
|
|
|
$getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
277
|
|
|
$getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info_real_chunks_current_chunk['parsed_audio_data']['fourcc'], $getid3->info['audio']['bitrate']); |
278
|
|
|
$getid3->info['audio']['dataformat'] = 'real'; |
279
|
|
|
$getid3->info['audio']['lossless'] = false; |
280
|
|
|
break; |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
case 'video/x-pn-realvideo': |
284
|
|
|
case 'video/x-pn-multirate-realvideo': |
285
|
|
|
|
286
|
|
|
$getid3->info['video']['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
287
|
|
|
$getid3->info['video']['bitrate_mode'] = 'cbr'; |
288
|
|
|
$getid3->info['video']['dataformat'] = 'real'; |
289
|
|
|
$getid3->info['video']['lossless'] = false; |
290
|
|
|
$getid3->info['video']['pixel_aspect_ratio'] = (float)1; |
291
|
|
|
break; |
292
|
|
|
|
293
|
|
|
|
294
|
|
|
case 'audio/x-ralf-mpeg4-generic': |
295
|
|
|
|
296
|
|
|
$getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
297
|
|
|
$getid3->info['audio']['codec'] = 'RealAudio Lossless'; |
298
|
|
|
$getid3->info['audio']['dataformat'] = 'real'; |
299
|
|
|
$getid3->info['audio']['lossless'] = true; |
300
|
|
|
break; |
301
|
|
|
|
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
$getid3->info['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0); |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
break; |
308
|
|
|
|
309
|
|
|
|
310
|
|
|
case 'CONT': // Content Description Header (text comments) |
311
|
|
|
|
312
|
|
|
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
313
|
|
|
$offset += 2; |
314
|
|
|
|
315
|
|
|
if ($info_real_chunks_current_chunk['object_version'] == 0) { |
316
|
|
|
|
317
|
|
|
$info_real_chunks_current_chunk['title_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
318
|
|
|
$offset += 2; |
319
|
|
|
|
320
|
|
|
$info_real_chunks_current_chunk['title'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['title_len']); |
321
|
|
|
$offset += $info_real_chunks_current_chunk['title_len']; |
322
|
|
|
|
323
|
|
|
$info_real_chunks_current_chunk['artist_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
324
|
|
|
$offset += 2; |
325
|
|
|
|
326
|
|
|
$info_real_chunks_current_chunk['artist'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['artist_len']); |
327
|
|
|
$offset += $info_real_chunks_current_chunk['artist_len']; |
328
|
|
|
|
329
|
|
|
$info_real_chunks_current_chunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
330
|
|
|
$offset += 2; |
331
|
|
|
|
332
|
|
|
$info_real_chunks_current_chunk['copyright'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['copyright_len']); |
333
|
|
|
$offset += $info_real_chunks_current_chunk['copyright_len']; |
334
|
|
|
|
335
|
|
|
$info_real_chunks_current_chunk['comment_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
336
|
|
|
$offset += 2; |
337
|
|
|
|
338
|
|
|
$info_real_chunks_current_chunk['comment'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['comment_len']); |
339
|
|
|
$offset += $info_real_chunks_current_chunk['comment_len']; |
340
|
|
|
|
341
|
|
|
foreach (array ('title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment') as $key => $val) { |
342
|
|
|
if ($info_real_chunks_current_chunk[$key]) { |
343
|
|
|
$getid3->info['real']['comments'][$val][] = trim($info_real_chunks_current_chunk[$key]); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
break; |
348
|
|
|
|
349
|
|
|
|
350
|
|
|
case 'DATA': // Data Chunk Header |
351
|
|
|
|
352
|
|
|
// do nothing |
353
|
|
|
break; |
354
|
|
|
|
355
|
|
|
|
356
|
|
|
case 'INDX': // Index Section Header |
357
|
|
|
|
358
|
|
|
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
359
|
|
|
$offset += 2; |
360
|
|
|
|
361
|
|
|
if ($info_real_chunks_current_chunk['object_version'] == 0) { |
362
|
|
|
|
363
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, |
364
|
|
|
array ( |
365
|
|
|
'num_indices' => 4, |
366
|
|
|
'stream_number' => 2, |
367
|
|
|
'next_index_header' => 4 |
368
|
|
|
) |
369
|
|
|
); |
370
|
|
|
$offset += 10; |
371
|
|
|
|
372
|
|
|
if ($info_real_chunks_current_chunk['next_index_header'] == 0) { |
373
|
|
|
// last index chunk found, ignore rest of file |
374
|
|
|
break 2; |
375
|
|
|
} else { |
376
|
|
|
// non-last index chunk, seek to next index chunk (skipping actual index data) |
377
|
|
|
fseek($getid3->fp, $info_real_chunks_current_chunk['next_index_header'], SEEK_SET); |
378
|
|
|
} |
379
|
|
|
} |
380
|
|
|
break; |
381
|
|
|
|
382
|
|
|
|
383
|
|
|
default: |
384
|
|
|
$getid3->warning('Unhandled RealMedia chunk "'.$chunk_name.'" at offset '.$info_real_chunks_current_chunk['offset']); |
385
|
|
|
break; |
386
|
|
|
} |
387
|
|
|
$chunk_counter++; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
if (!empty($getid3->info['audio']['streams'])) { |
391
|
|
|
|
392
|
|
|
$getid3->info['audio']['bitrate'] = 0; |
393
|
|
|
|
394
|
|
|
foreach ($getid3->info['audio']['streams'] as $key => $value_array) { |
395
|
|
|
$getid3->info['audio']['bitrate'] += $value_array['bitrate']; |
396
|
|
|
} |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
return true; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
|
403
|
|
|
|
404
|
|
|
public static function ParseOldRAheader($old_ra_header_data, &$parsed_array) { |
405
|
|
|
|
406
|
|
|
// http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html |
407
|
|
|
|
408
|
|
|
$parsed_array = array (); |
409
|
|
|
$parsed_array['magic'] = substr($old_ra_header_data, 0, 4); |
410
|
|
|
|
411
|
|
|
if ($parsed_array['magic'] != '.ra'."\xFD") { |
412
|
|
|
return false; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
$parsed_array['version1'] = getid3_lib::BigEndian2Int(substr($old_ra_header_data, 4, 2)); |
416
|
|
|
|
417
|
|
|
if ($parsed_array['version1'] < 3) { |
418
|
|
|
|
419
|
|
|
return false; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
if ($parsed_array['version1'] == 3) { |
423
|
|
|
|
424
|
|
|
$parsed_array['fourcc1'] = '.ra3'; |
425
|
|
|
$parsed_array['bits_per_sample'] = 16; // hard-coded for old versions? |
426
|
|
|
$parsed_array['sample_rate'] = 8000; // hard-coded for old versions? |
427
|
|
|
|
428
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6, |
429
|
|
|
array ( |
430
|
|
|
'header_size' => 2, |
431
|
|
|
'channels' => 2, // always 1 (?) |
432
|
|
|
'IGNORE-unknown1' => 2, |
433
|
|
|
'IGNORE-unknown2' => 2, |
434
|
|
|
'IGNORE-unknown3' => 2, |
435
|
|
|
'bytes_per_minute' => 2, |
436
|
|
|
'audio_bytes' => 4, |
437
|
|
|
) |
438
|
|
|
); |
439
|
|
|
|
440
|
|
|
$parsed_array['comments_raw'] = substr($old_ra_header_data, 22, $parsed_array['header_size'] - 22 + 1); // not including null terminator |
441
|
|
|
|
442
|
|
|
$comment_offset = 0; |
443
|
|
|
|
444
|
|
|
foreach (array ('title', 'artist', 'copyright') as $name) { |
445
|
|
|
$comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++}); |
446
|
|
|
$parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length); |
447
|
|
|
$comment_offset += $comment_length; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
$comment_offset++; // final null terminator (?) |
451
|
|
|
$comment_offset++; // fourcc length (?) should be 4 |
452
|
|
|
|
453
|
|
|
$parsed_array['fourcc'] = substr($old_ra_header_data, 23 + $comment_offset, 4); |
454
|
|
|
|
455
|
|
|
|
456
|
|
|
} elseif ($parsed_array['version1'] <= 5) { |
457
|
|
|
|
458
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6, |
459
|
|
|
array ( |
460
|
|
|
'IGNORE-unknown1' => 2, |
461
|
|
|
'fourcc1' => -4, |
462
|
|
|
'file_size' => 4, |
463
|
|
|
'version2' => 2, |
464
|
|
|
'header_size' => 4, |
465
|
|
|
'codec_flavor_id' => 2, |
466
|
|
|
'coded_frame_size' => 4, |
467
|
|
|
'audio_bytes' => 4, |
468
|
|
|
'bytes_per_minute' => 4, |
469
|
|
|
'IGNORE-unknown5' => 4, |
470
|
|
|
'sub_packet_h' => 2, |
471
|
|
|
'frame_size' => 2, |
472
|
|
|
'sub_packet_size' => 2, |
473
|
|
|
'IGNORE-unknown6' => 2 |
474
|
|
|
) |
475
|
|
|
); |
476
|
|
|
|
477
|
|
|
switch ($parsed_array['version1']) { |
478
|
|
|
|
479
|
|
|
case 4: |
480
|
|
|
|
481
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48, |
482
|
|
|
array ( |
483
|
|
|
'sample_rate' => 2, |
484
|
|
|
'IGNORE-unknown8' => 2, |
485
|
|
|
'bits_per_sample' => 2, |
486
|
|
|
'channels' => 2, |
487
|
|
|
'length_fourcc2' => 1, |
488
|
|
|
'fourcc2' => -4, |
489
|
|
|
'length_fourcc3' => 1, |
490
|
|
|
'fourcc3' => -4, |
491
|
|
|
'IGNORE-unknown9' => 1, |
492
|
|
|
'IGNORE-unknown10' => 2, |
493
|
|
|
) |
494
|
|
|
); |
495
|
|
|
|
496
|
|
|
$parsed_array['comments_raw'] = substr($old_ra_header_data, 69, $parsed_array['header_size'] - 69 + 16); |
497
|
|
|
|
498
|
|
|
$comment_offset = 0; |
499
|
|
|
|
500
|
|
|
foreach (array ('title', 'artist', 'copyright') as $name) { |
501
|
|
|
$comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++}); |
502
|
|
|
$parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length); |
503
|
|
|
$comment_offset += $comment_length; |
504
|
|
|
} |
505
|
|
|
break; |
506
|
|
|
|
507
|
|
|
|
508
|
|
|
case 5: |
509
|
|
|
|
510
|
|
|
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48, |
511
|
|
|
array ( |
512
|
|
|
'sample_rate' => 4, |
513
|
|
|
'sample_rate2' => 4, |
514
|
|
|
'bits_per_sample' => 4, |
515
|
|
|
'channels' => 2, |
516
|
|
|
'genr' => -4, |
517
|
|
|
'fourcc3' => -4, |
518
|
|
|
) |
519
|
|
|
); |
520
|
|
|
$parsed_array['comments'] = array (); |
521
|
|
|
break; |
522
|
|
|
|
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
$parsed_array['fourcc'] = $parsed_array['fourcc3']; |
526
|
|
|
|
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
foreach ($parsed_array['comments'] as $key => $value) { |
530
|
|
|
|
531
|
|
|
if ($parsed_array['comments'][$key][0] === false) { |
532
|
|
|
$parsed_array['comments'][$key][0] = ''; |
533
|
|
|
} |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
return true; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
|
540
|
|
|
|
541
|
|
|
public static function RealAudioCodecFourCClookup($fourcc, $bitrate) { |
542
|
|
|
|
543
|
|
|
// http://www.its.msstate.edu/net/real/reports/config/tags.stats |
544
|
|
|
// http://www.freelists.org/archives/matroska-devel/06-2003/fullthread18.html |
545
|
|
|
|
546
|
|
|
static $lookup; |
547
|
|
|
|
548
|
|
|
if (empty($lookup)) { |
549
|
|
|
$lookup['14_4'][8000] = 'RealAudio v2 (14.4kbps)'; |
550
|
|
|
$lookup['14.4'][8000] = 'RealAudio v2 (14.4kbps)'; |
551
|
|
|
$lookup['lpcJ'][8000] = 'RealAudio v2 (14.4kbps)'; |
552
|
|
|
$lookup['28_8'][15200] = 'RealAudio v2 (28.8kbps)'; |
553
|
|
|
$lookup['28.8'][15200] = 'RealAudio v2 (28.8kbps)'; |
554
|
|
|
$lookup['sipr'][4933] = 'RealAudio v4 (5kbps Voice)'; |
555
|
|
|
$lookup['sipr'][6444] = 'RealAudio v4 (6.5kbps Voice)'; |
556
|
|
|
$lookup['sipr'][8444] = 'RealAudio v4 (8.5kbps Voice)'; |
557
|
|
|
$lookup['sipr'][16000] = 'RealAudio v4 (16kbps Wideband)'; |
558
|
|
|
$lookup['dnet'][8000] = 'RealAudio v3 (8kbps Music)'; |
559
|
|
|
$lookup['dnet'][16000] = 'RealAudio v3 (16kbps Music Low Response)'; |
560
|
|
|
$lookup['dnet'][15963] = 'RealAudio v3 (16kbps Music Mid/High Response)'; |
561
|
|
|
$lookup['dnet'][20000] = 'RealAudio v3 (20kbps Music Stereo)'; |
562
|
|
|
$lookup['dnet'][32000] = 'RealAudio v3 (32kbps Music Mono)'; |
563
|
|
|
$lookup['dnet'][31951] = 'RealAudio v3 (32kbps Music Stereo)'; |
564
|
|
|
$lookup['dnet'][39965] = 'RealAudio v3 (40kbps Music Mono)'; |
565
|
|
|
$lookup['dnet'][40000] = 'RealAudio v3 (40kbps Music Stereo)'; |
566
|
|
|
$lookup['dnet'][79947] = 'RealAudio v3 (80kbps Music Mono)'; |
567
|
|
|
$lookup['dnet'][80000] = 'RealAudio v3 (80kbps Music Stereo)'; |
568
|
|
|
|
569
|
|
|
$lookup['dnet'][0] = 'RealAudio v3'; |
570
|
|
|
$lookup['sipr'][0] = 'RealAudio v4'; |
571
|
|
|
$lookup['cook'][0] = 'RealAudio G2'; |
572
|
|
|
$lookup['atrc'][0] = 'RealAudio 8'; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
$round_bitrate = intval(round($bitrate)); |
576
|
|
|
|
577
|
|
|
if (isset($lookup[$fourcc][$round_bitrate])) { |
578
|
|
|
return $lookup[$fourcc][$round_bitrate]; |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
if (isset($lookup[$fourcc][0])) { |
582
|
|
|
return $lookup[$fourcc][0]; |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
return $fourcc; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
|
591
|
|
|
?> |
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.