Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like getid3_matroska often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use getid3_matroska, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 216 | class getid3_matroska extends getid3_handler |
||
| 217 | { |
||
| 218 | // public options |
||
| 219 | public static $hide_clusters = true; // if true, do not return information about CLUSTER chunks, since there's a lot of them and they're not usually useful [default: TRUE] |
||
| 220 | public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE] |
||
| 221 | |||
| 222 | // private parser settings/placeholders |
||
| 223 | private $EBMLbuffer = ''; |
||
| 224 | private $EBMLbuffer_offset = 0; |
||
| 225 | private $EBMLbuffer_length = 0; |
||
| 226 | private $current_offset = 0; |
||
| 227 | private $unuseful_elements = array(EBML_ID_CRC32, EBML_ID_VOID); |
||
| 228 | |||
| 229 | public function Analyze() |
||
| 230 | { |
||
| 231 | $info = &$this->getid3->info; |
||
| 232 | |||
| 233 | // parse container |
||
| 234 | try { |
||
| 235 | $this->parseEBML($info); |
||
| 236 | } catch (Exception $e) { |
||
| 237 | $info['error'][] = 'EBML parser: '.$e->getMessage(); |
||
| 238 | } |
||
| 239 | |||
| 240 | // calculate playtime |
||
| 241 | if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { |
||
| 242 | foreach ($info['matroska']['info'] as $key => $infoarray) { |
||
| 243 | if (isset($infoarray['Duration'])) { |
||
| 244 | // TimecodeScale is how many nanoseconds each Duration unit is |
||
| 245 | $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000); |
||
| 246 | break; |
||
| 247 | } |
||
| 248 | } |
||
| 249 | } |
||
| 250 | |||
| 251 | // extract tags |
||
| 252 | if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) { |
||
| 253 | foreach ($info['matroska']['tags'] as $key => $infoarray) { |
||
| 254 | $this->ExtractCommentsSimpleTag($infoarray); |
||
| 255 | } |
||
| 256 | } |
||
| 257 | |||
| 258 | // process tracks |
||
| 259 | if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { |
||
| 260 | foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) { |
||
| 261 | |||
| 262 | $track_info = array(); |
||
| 263 | $track_info['dataformat'] = self::CodecIDtoCommonName($trackarray['CodecID']); |
||
| 264 | $track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true); |
||
| 265 | if (isset($trackarray['Name'])) { $track_info['name'] = $trackarray['Name']; } |
||
| 266 | |||
| 267 | switch ($trackarray['TrackType']) { |
||
| 268 | |||
| 269 | case 1: // Video |
||
| 270 | $track_info['resolution_x'] = $trackarray['PixelWidth']; |
||
| 271 | $track_info['resolution_y'] = $trackarray['PixelHeight']; |
||
| 272 | $track_info['display_unit'] = self::displayUnit(isset($trackarray['DisplayUnit']) ? $trackarray['DisplayUnit'] : 0); |
||
| 273 | $track_info['display_x'] = (isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth']); |
||
| 274 | $track_info['display_y'] = (isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight']); |
||
| 275 | |||
| 276 | if (isset($trackarray['PixelCropBottom'])) { $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; } |
||
| 277 | if (isset($trackarray['PixelCropTop'])) { $track_info['crop_top'] = $trackarray['PixelCropTop']; } |
||
| 278 | if (isset($trackarray['PixelCropLeft'])) { $track_info['crop_left'] = $trackarray['PixelCropLeft']; } |
||
| 279 | if (isset($trackarray['PixelCropRight'])) { $track_info['crop_right'] = $trackarray['PixelCropRight']; } |
||
| 280 | if (isset($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); } |
||
| 281 | if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } |
||
| 282 | |||
| 283 | switch ($trackarray['CodecID']) { |
||
| 284 | case 'V_MS/VFW/FOURCC': |
||
| 285 | getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); |
||
| 286 | |||
| 287 | $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']); |
||
| 288 | $track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']); |
||
| 289 | $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; |
||
| 290 | break; |
||
| 291 | |||
| 292 | /*case 'V_MPEG4/ISO/AVC': |
||
| 293 | $h264['profile'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 1, 1)); |
||
| 294 | $h264['level'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 3, 1)); |
||
| 295 | $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 4, 1)); |
||
| 296 | $h264['NALUlength'] = ($rn & 3) + 1; |
||
| 297 | $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 5, 1)); |
||
| 298 | $nsps = ($rn & 31); |
||
| 299 | $offset = 6; |
||
| 300 | for ($i = 0; $i < $nsps; $i ++) { |
||
| 301 | $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); |
||
| 302 | $h264['SPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); |
||
| 303 | $offset += 2 + $length; |
||
| 304 | } |
||
| 305 | $npps = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 1)); |
||
| 306 | $offset += 1; |
||
| 307 | for ($i = 0; $i < $npps; $i ++) { |
||
| 308 | $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); |
||
| 309 | $h264['PPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); |
||
| 310 | $offset += 2 + $length; |
||
| 311 | } |
||
| 312 | $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $h264; |
||
| 313 | break;*/ |
||
| 314 | } |
||
| 315 | |||
| 316 | $info['video']['streams'][] = $track_info; |
||
| 317 | break; |
||
| 318 | |||
| 319 | case 2: // Audio |
||
| 320 | $track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0); |
||
| 321 | $track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1); |
||
| 322 | $track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng'); |
||
| 323 | if (isset($trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; } |
||
| 324 | if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } |
||
| 325 | |||
| 326 | switch ($trackarray['CodecID']) { |
||
| 327 | case 'A_PCM/INT/LIT': |
||
| 328 | case 'A_PCM/INT/BIG': |
||
| 329 | $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth']; |
||
| 330 | break; |
||
| 331 | |||
| 332 | case 'A_AC3': |
||
| 333 | case 'A_DTS': |
||
| 334 | case 'A_MPEG/L3': |
||
| 335 | case 'A_MPEG/L2': |
||
| 336 | case 'A_FLAC': |
||
| 337 | getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']).'.php', __FILE__, true); |
||
| 338 | |||
| 339 | if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) { |
||
| 340 | $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set'); |
||
| 341 | break; |
||
| 342 | } |
||
| 343 | |||
| 344 | // create temp instance |
||
| 345 | $getid3_temp = new getID3(); |
||
| 346 | if ($track_info['dataformat'] != 'flac') { |
||
| 347 | $getid3_temp->openfile($this->getid3->filename); |
||
| 348 | } |
||
| 349 | $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset']; |
||
| 350 | if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') { |
||
| 351 | $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length']; |
||
| 352 | } |
||
| 353 | |||
| 354 | // analyze |
||
| 355 | $class = 'getid3_'.($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']); |
||
| 356 | $header_data_key = $track_info['dataformat'][0] == 'm' ? 'mpeg' : $track_info['dataformat']; |
||
| 357 | $getid3_audio = new $class($getid3_temp, __CLASS__); |
||
| 358 | if ($track_info['dataformat'] == 'flac') { |
||
| 359 | $getid3_audio->AnalyzeString($trackarray['CodecPrivate']); |
||
| 360 | } |
||
| 361 | else { |
||
| 362 | $getid3_audio->Analyze(); |
||
| 363 | } |
||
| 364 | if (!empty($getid3_temp->info[$header_data_key])) { |
||
| 365 | $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key]; |
||
| 366 | if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { |
||
| 367 | foreach ($getid3_temp->info['audio'] as $key => $value) { |
||
| 368 | $track_info[$key] = $value; |
||
| 369 | } |
||
| 370 | } |
||
| 371 | } |
||
| 372 | else { |
||
| 373 | $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']); |
||
| 374 | } |
||
| 375 | |||
| 376 | // copy errors and warnings |
||
| 377 | if (!empty($getid3_temp->info['error'])) { |
||
| 378 | foreach ($getid3_temp->info['error'] as $newerror) { |
||
| 379 | $this->warning($class.'() says: ['.$newerror.']'); |
||
| 380 | } |
||
| 381 | } |
||
| 382 | if (!empty($getid3_temp->info['warning'])) { |
||
| 383 | foreach ($getid3_temp->info['warning'] as $newerror) { |
||
| 384 | $this->warning($class.'() says: ['.$newerror.']'); |
||
| 385 | } |
||
| 386 | } |
||
| 387 | unset($getid3_temp, $getid3_audio); |
||
| 388 | break; |
||
| 389 | |||
| 390 | case 'A_AAC': |
||
| 391 | case 'A_AAC/MPEG2/LC': |
||
| 392 | case 'A_AAC/MPEG2/LC/SBR': |
||
| 393 | case 'A_AAC/MPEG4/LC': |
||
| 394 | case 'A_AAC/MPEG4/LC/SBR': |
||
| 395 | $this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated'); |
||
| 396 | break; |
||
| 397 | |||
| 398 | case 'A_VORBIS': |
||
| 399 | if (!isset($trackarray['CodecPrivate'])) { |
||
| 400 | $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set'); |
||
| 401 | break; |
||
| 402 | } |
||
| 403 | $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1); |
||
| 404 | if ($vorbis_offset === false) { |
||
| 405 | $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword'); |
||
| 406 | break; |
||
| 407 | } |
||
| 408 | $vorbis_offset -= 1; |
||
| 409 | |||
| 410 | getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); |
||
| 411 | |||
| 412 | // create temp instance |
||
| 413 | $getid3_temp = new getID3(); |
||
| 414 | |||
| 415 | // analyze |
||
| 416 | $getid3_ogg = new getid3_ogg($getid3_temp); |
||
| 417 | $oggpageinfo['page_seqno'] = 0; |
||
| 418 | $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo); |
||
| 419 | if (!empty($getid3_temp->info['ogg'])) { |
||
| 420 | $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg']; |
||
| 421 | if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { |
||
| 422 | foreach ($getid3_temp->info['audio'] as $key => $value) { |
||
| 423 | $track_info[$key] = $value; |
||
| 424 | } |
||
| 425 | } |
||
| 426 | } |
||
| 427 | |||
| 428 | // copy errors and warnings |
||
| 429 | if (!empty($getid3_temp->info['error'])) { |
||
| 430 | foreach ($getid3_temp->info['error'] as $newerror) { |
||
| 431 | $this->warning('getid3_ogg() says: ['.$newerror.']'); |
||
| 432 | } |
||
| 433 | } |
||
| 434 | if (!empty($getid3_temp->info['warning'])) { |
||
| 435 | foreach ($getid3_temp->info['warning'] as $newerror) { |
||
| 436 | $this->warning('getid3_ogg() says: ['.$newerror.']'); |
||
| 437 | } |
||
| 438 | } |
||
| 439 | |||
| 440 | if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) { |
||
| 441 | $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal']; |
||
| 442 | } |
||
| 443 | unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset); |
||
| 444 | break; |
||
| 445 | |||
| 446 | case 'A_MS/ACM': |
||
| 447 | getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); |
||
| 448 | |||
| 449 | $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']); |
||
| 450 | foreach ($parsed as $key => $value) { |
||
| 451 | if ($key != 'raw') { |
||
| 452 | $track_info[$key] = $value; |
||
| 453 | } |
||
| 454 | } |
||
| 455 | $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; |
||
| 456 | break; |
||
| 457 | |||
| 458 | default: |
||
| 459 | $this->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"'); |
||
| 460 | } |
||
| 461 | |||
| 462 | $info['audio']['streams'][] = $track_info; |
||
| 463 | break; |
||
| 464 | } |
||
| 465 | } |
||
| 466 | |||
| 467 | if (!empty($info['video']['streams'])) { |
||
| 468 | $info['video'] = self::getDefaultStreamInfo($info['video']['streams']); |
||
| 469 | } |
||
| 470 | if (!empty($info['audio']['streams'])) { |
||
| 471 | $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']); |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | // process attachments |
||
| 476 | if (isset($info['matroska']['attachments']) && $this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE) { |
||
| 477 | foreach ($info['matroska']['attachments'] as $i => $entry) { |
||
| 478 | if (strpos($entry['FileMimeType'], 'image/') === 0 && !empty($entry['FileData'])) { |
||
| 479 | $info['matroska']['comments']['picture'][] = array('data' => $entry['FileData'], 'image_mime' => $entry['FileMimeType'], 'filename' => $entry['FileName']); |
||
| 480 | } |
||
| 481 | } |
||
| 482 | } |
||
| 483 | |||
| 484 | // determine mime type |
||
| 485 | if (!empty($info['video']['streams'])) { |
||
| 486 | $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska'); |
||
| 487 | } elseif (!empty($info['audio']['streams'])) { |
||
| 488 | $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska'); |
||
| 489 | } elseif (isset($info['mime_type'])) { |
||
| 490 | unset($info['mime_type']); |
||
| 491 | } |
||
| 492 | |||
| 493 | return true; |
||
| 494 | } |
||
| 495 | |||
| 496 | private function parseEBML(&$info) { |
||
| 497 | // http://www.matroska.org/technical/specs/index.html#EBMLBasics |
||
| 498 | $this->current_offset = $info['avdataoffset']; |
||
| 499 | |||
| 500 | while ($this->getEBMLelement($top_element, $info['avdataend'])) { |
||
| 501 | switch ($top_element['id']) { |
||
| 502 | |||
| 503 | case EBML_ID_EBML: |
||
| 504 | $info['matroska']['header']['offset'] = $top_element['offset']; |
||
| 505 | $info['matroska']['header']['length'] = $top_element['length']; |
||
| 506 | |||
| 507 | while ($this->getEBMLelement($element_data, $top_element['end'], true)) { |
||
| 508 | switch ($element_data['id']) { |
||
| 509 | |||
| 510 | case EBML_ID_EBMLVERSION: |
||
| 511 | case EBML_ID_EBMLREADVERSION: |
||
| 512 | case EBML_ID_EBMLMAXIDLENGTH: |
||
| 513 | case EBML_ID_EBMLMAXSIZELENGTH: |
||
| 514 | case EBML_ID_DOCTYPEVERSION: |
||
| 515 | case EBML_ID_DOCTYPEREADVERSION: |
||
| 516 | $element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']); |
||
| 517 | break; |
||
| 518 | |||
| 519 | case EBML_ID_DOCTYPE: |
||
| 520 | $element_data['data'] = getid3_lib::trimNullByte($element_data['data']); |
||
| 521 | $info['matroska']['doctype'] = $element_data['data']; |
||
| 522 | $info['fileformat'] = $element_data['data']; |
||
| 523 | break; |
||
| 524 | |||
| 525 | default: |
||
| 526 | $this->unhandledElement('header', __LINE__, $element_data); |
||
| 527 | } |
||
| 528 | |||
| 529 | unset($element_data['offset'], $element_data['end']); |
||
| 530 | $info['matroska']['header']['elements'][] = $element_data; |
||
| 531 | } |
||
| 532 | break; |
||
| 533 | |||
| 534 | case EBML_ID_SEGMENT: |
||
| 535 | $info['matroska']['segment'][0]['offset'] = $top_element['offset']; |
||
| 536 | $info['matroska']['segment'][0]['length'] = $top_element['length']; |
||
| 537 | |||
| 538 | while ($this->getEBMLelement($element_data, $top_element['end'])) { |
||
| 539 | if ($element_data['id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required |
||
| 540 | $info['matroska']['segments'][] = $element_data; |
||
| 541 | } |
||
| 542 | switch ($element_data['id']) { |
||
| 543 | |||
| 544 | case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements. |
||
| 545 | |||
| 546 | while ($this->getEBMLelement($seek_entry, $element_data['end'])) { |
||
| 547 | switch ($seek_entry['id']) { |
||
| 548 | |||
| 549 | case EBML_ID_SEEK: // Contains a single seek entry to an EBML element |
||
| 550 | while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) { |
||
| 551 | |||
| 552 | switch ($sub_seek_entry['id']) { |
||
| 553 | |||
| 554 | case EBML_ID_SEEKID: |
||
| 555 | $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']); |
||
| 556 | $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']); |
||
| 557 | break; |
||
| 558 | |||
| 559 | case EBML_ID_SEEKPOSITION: |
||
| 560 | $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']); |
||
| 561 | break; |
||
| 562 | |||
| 563 | default: |
||
| 564 | $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); } |
||
| 565 | } |
||
| 566 | |||
| 567 | if ($seek_entry['target_id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required |
||
| 568 | $info['matroska']['seek'][] = $seek_entry; |
||
| 569 | } |
||
| 570 | break; |
||
| 571 | |||
| 572 | default: |
||
| 573 | $this->unhandledElement('seekhead', __LINE__, $seek_entry); |
||
| 574 | } |
||
| 575 | } |
||
| 576 | break; |
||
| 577 | |||
| 578 | case EBML_ID_TRACKS: // A top-level block of information with many tracks described. |
||
| 579 | $info['matroska']['tracks'] = $element_data; |
||
| 580 | |||
| 581 | while ($this->getEBMLelement($track_entry, $element_data['end'])) { |
||
| 582 | switch ($track_entry['id']) { |
||
| 583 | |||
| 584 | case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements. |
||
| 585 | |||
| 586 | while ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS, EBML_ID_CODECPRIVATE))) { |
||
| 587 | switch ($subelement['id']) { |
||
| 588 | |||
| 589 | case EBML_ID_TRACKNUMBER: |
||
| 590 | case EBML_ID_TRACKUID: |
||
| 591 | case EBML_ID_TRACKTYPE: |
||
| 592 | case EBML_ID_MINCACHE: |
||
| 593 | case EBML_ID_MAXCACHE: |
||
| 594 | case EBML_ID_MAXBLOCKADDITIONID: |
||
| 595 | case EBML_ID_DEFAULTDURATION: // nanoseconds per frame |
||
| 596 | $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); |
||
| 597 | break; |
||
| 598 | |||
| 599 | case EBML_ID_TRACKTIMECODESCALE: |
||
| 600 | $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); |
||
| 601 | break; |
||
| 602 | |||
| 603 | case EBML_ID_CODECID: |
||
| 604 | case EBML_ID_LANGUAGE: |
||
| 605 | case EBML_ID_NAME: |
||
| 606 | case EBML_ID_CODECNAME: |
||
| 607 | $track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); |
||
| 608 | break; |
||
| 609 | |||
| 610 | case EBML_ID_CODECPRIVATE: |
||
| 611 | $track_entry[$subelement['id_name']] = $this->readEBMLelementData($subelement['length'], true); |
||
| 612 | break; |
||
| 613 | |||
| 614 | case EBML_ID_FLAGENABLED: |
||
| 615 | case EBML_ID_FLAGDEFAULT: |
||
| 616 | case EBML_ID_FLAGFORCED: |
||
| 617 | case EBML_ID_FLAGLACING: |
||
| 618 | case EBML_ID_CODECDECODEALL: |
||
| 619 | $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']); |
||
| 620 | break; |
||
| 621 | |||
| 622 | case EBML_ID_VIDEO: |
||
| 623 | |||
| 624 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { |
||
| 625 | switch ($sub_subelement['id']) { |
||
| 626 | |||
| 627 | case EBML_ID_PIXELWIDTH: |
||
| 628 | case EBML_ID_PIXELHEIGHT: |
||
| 629 | case EBML_ID_PIXELCROPBOTTOM: |
||
| 630 | case EBML_ID_PIXELCROPTOP: |
||
| 631 | case EBML_ID_PIXELCROPLEFT: |
||
| 632 | case EBML_ID_PIXELCROPRIGHT: |
||
| 633 | case EBML_ID_DISPLAYWIDTH: |
||
| 634 | case EBML_ID_DISPLAYHEIGHT: |
||
| 635 | case EBML_ID_DISPLAYUNIT: |
||
| 636 | case EBML_ID_ASPECTRATIOTYPE: |
||
| 637 | case EBML_ID_STEREOMODE: |
||
| 638 | case EBML_ID_OLDSTEREOMODE: |
||
| 639 | $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 640 | break; |
||
| 641 | |||
| 642 | case EBML_ID_FLAGINTERLACED: |
||
| 643 | $track_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 644 | break; |
||
| 645 | |||
| 646 | case EBML_ID_GAMMAVALUE: |
||
| 647 | $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); |
||
| 648 | break; |
||
| 649 | |||
| 650 | case EBML_ID_COLOURSPACE: |
||
| 651 | $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); |
||
| 652 | break; |
||
| 653 | |||
| 654 | default: |
||
| 655 | $this->unhandledElement('track.video', __LINE__, $sub_subelement); |
||
| 656 | } |
||
| 657 | } |
||
| 658 | break; |
||
| 659 | |||
| 660 | case EBML_ID_AUDIO: |
||
| 661 | |||
| 662 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { |
||
| 663 | switch ($sub_subelement['id']) { |
||
| 664 | |||
| 665 | case EBML_ID_CHANNELS: |
||
| 666 | case EBML_ID_BITDEPTH: |
||
| 667 | $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 668 | break; |
||
| 669 | |||
| 670 | case EBML_ID_SAMPLINGFREQUENCY: |
||
| 671 | case EBML_ID_OUTPUTSAMPLINGFREQUENCY: |
||
| 672 | $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); |
||
| 673 | break; |
||
| 674 | |||
| 675 | case EBML_ID_CHANNELPOSITIONS: |
||
| 676 | $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); |
||
| 677 | break; |
||
| 678 | |||
| 679 | default: |
||
| 680 | $this->unhandledElement('track.audio', __LINE__, $sub_subelement); |
||
| 681 | } |
||
| 682 | } |
||
| 683 | break; |
||
| 684 | |||
| 685 | case EBML_ID_CONTENTENCODINGS: |
||
| 686 | |||
| 687 | while ($this->getEBMLelement($sub_subelement, $subelement['end'])) { |
||
| 688 | switch ($sub_subelement['id']) { |
||
| 689 | |||
| 690 | case EBML_ID_CONTENTENCODING: |
||
| 691 | |||
| 692 | while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CONTENTCOMPRESSION, EBML_ID_CONTENTENCRYPTION))) { |
||
| 693 | switch ($sub_sub_subelement['id']) { |
||
| 694 | |||
| 695 | case EBML_ID_CONTENTENCODINGORDER: |
||
| 696 | case EBML_ID_CONTENTENCODINGSCOPE: |
||
| 697 | case EBML_ID_CONTENTENCODINGTYPE: |
||
| 698 | $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); |
||
| 699 | break; |
||
| 700 | |||
| 701 | case EBML_ID_CONTENTCOMPRESSION: |
||
| 702 | |||
| 703 | while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { |
||
| 704 | switch ($sub_sub_sub_subelement['id']) { |
||
| 705 | |||
| 706 | case EBML_ID_CONTENTCOMPALGO: |
||
| 707 | $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); |
||
| 708 | break; |
||
| 709 | |||
| 710 | case EBML_ID_CONTENTCOMPSETTINGS: |
||
| 711 | $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; |
||
| 712 | break; |
||
| 713 | |||
| 714 | default: |
||
| 715 | $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); |
||
| 716 | } |
||
| 717 | } |
||
| 718 | break; |
||
| 719 | |||
| 720 | case EBML_ID_CONTENTENCRYPTION: |
||
| 721 | |||
| 722 | while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { |
||
| 723 | switch ($sub_sub_sub_subelement['id']) { |
||
| 724 | |||
| 725 | case EBML_ID_CONTENTENCALGO: |
||
| 726 | case EBML_ID_CONTENTSIGALGO: |
||
| 727 | case EBML_ID_CONTENTSIGHASHALGO: |
||
| 728 | $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); |
||
| 729 | break; |
||
| 730 | |||
| 731 | case EBML_ID_CONTENTENCKEYID: |
||
| 732 | case EBML_ID_CONTENTSIGNATURE: |
||
| 733 | case EBML_ID_CONTENTSIGKEYID: |
||
| 734 | $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; |
||
| 735 | break; |
||
| 736 | |||
| 737 | default: |
||
| 738 | $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); |
||
| 739 | } |
||
| 740 | } |
||
| 741 | break; |
||
| 742 | |||
| 743 | default: |
||
| 744 | $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement); |
||
| 745 | } |
||
| 746 | } |
||
| 747 | break; |
||
| 748 | |||
| 749 | default: |
||
| 750 | $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement); |
||
| 751 | } |
||
| 752 | } |
||
| 753 | break; |
||
| 754 | |||
| 755 | default: |
||
| 756 | $this->unhandledElement('track', __LINE__, $subelement); |
||
| 757 | } |
||
| 758 | } |
||
| 759 | |||
| 760 | $info['matroska']['tracks']['tracks'][] = $track_entry; |
||
| 761 | break; |
||
| 762 | |||
| 763 | default: |
||
| 764 | $this->unhandledElement('tracks', __LINE__, $track_entry); |
||
| 765 | } |
||
| 766 | } |
||
| 767 | break; |
||
| 768 | |||
| 769 | case EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file. |
||
| 770 | $info_entry = array(); |
||
| 771 | |||
| 772 | while ($this->getEBMLelement($subelement, $element_data['end'], true)) { |
||
| 773 | switch ($subelement['id']) { |
||
| 774 | |||
| 775 | case EBML_ID_TIMECODESCALE: |
||
| 776 | $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); |
||
| 777 | break; |
||
| 778 | |||
| 779 | case EBML_ID_DURATION: |
||
| 780 | $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); |
||
| 781 | break; |
||
| 782 | |||
| 783 | case EBML_ID_DATEUTC: |
||
| 784 | $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); |
||
| 785 | $info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]); |
||
| 786 | break; |
||
| 787 | |||
| 788 | case EBML_ID_SEGMENTUID: |
||
| 789 | case EBML_ID_PREVUID: |
||
| 790 | case EBML_ID_NEXTUID: |
||
| 791 | $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); |
||
| 792 | break; |
||
| 793 | |||
| 794 | case EBML_ID_SEGMENTFAMILY: |
||
| 795 | $info_entry[$subelement['id_name']][] = getid3_lib::trimNullByte($subelement['data']); |
||
| 796 | break; |
||
| 797 | |||
| 798 | case EBML_ID_SEGMENTFILENAME: |
||
| 799 | case EBML_ID_PREVFILENAME: |
||
| 800 | case EBML_ID_NEXTFILENAME: |
||
| 801 | case EBML_ID_TITLE: |
||
| 802 | case EBML_ID_MUXINGAPP: |
||
| 803 | case EBML_ID_WRITINGAPP: |
||
| 804 | $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); |
||
| 805 | $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']]; |
||
| 806 | break; |
||
| 807 | |||
| 808 | case EBML_ID_CHAPTERTRANSLATE: |
||
| 809 | $chaptertranslate_entry = array(); |
||
| 810 | |||
| 811 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { |
||
| 812 | switch ($sub_subelement['id']) { |
||
| 813 | |||
| 814 | case EBML_ID_CHAPTERTRANSLATEEDITIONUID: |
||
| 815 | $chaptertranslate_entry[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 816 | break; |
||
| 817 | |||
| 818 | case EBML_ID_CHAPTERTRANSLATECODEC: |
||
| 819 | $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 820 | break; |
||
| 821 | |||
| 822 | case EBML_ID_CHAPTERTRANSLATEID: |
||
| 823 | $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); |
||
| 824 | break; |
||
| 825 | |||
| 826 | default: |
||
| 827 | $this->unhandledElement('info.chaptertranslate', __LINE__, $sub_subelement); |
||
| 828 | } |
||
| 829 | } |
||
| 830 | $info_entry[$subelement['id_name']] = $chaptertranslate_entry; |
||
| 831 | break; |
||
| 832 | |||
| 833 | default: |
||
| 834 | $this->unhandledElement('info', __LINE__, $subelement); |
||
| 835 | } |
||
| 836 | } |
||
| 837 | $info['matroska']['info'][] = $info_entry; |
||
| 838 | break; |
||
| 839 | |||
| 840 | case EBML_ID_CUES: // A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non "live" streams. |
||
| 841 | if (self::$hide_clusters) { // do not parse cues if hide clusters is "ON" till they point to clusters anyway |
||
| 842 | $this->current_offset = $element_data['end']; |
||
| 843 | break; |
||
| 844 | } |
||
| 845 | $cues_entry = array(); |
||
| 846 | |||
| 847 | while ($this->getEBMLelement($subelement, $element_data['end'])) { |
||
| 848 | switch ($subelement['id']) { |
||
| 849 | |||
| 850 | case EBML_ID_CUEPOINT: |
||
| 851 | $cuepoint_entry = array(); |
||
| 852 | |||
| 853 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) { |
||
| 854 | switch ($sub_subelement['id']) { |
||
| 855 | |||
| 856 | case EBML_ID_CUETRACKPOSITIONS: |
||
| 857 | $cuetrackpositions_entry = array(); |
||
| 858 | |||
| 859 | while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { |
||
| 860 | switch ($sub_sub_subelement['id']) { |
||
| 861 | |||
| 862 | case EBML_ID_CUETRACK: |
||
| 863 | case EBML_ID_CUECLUSTERPOSITION: |
||
| 864 | case EBML_ID_CUEBLOCKNUMBER: |
||
| 865 | case EBML_ID_CUECODECSTATE: |
||
| 866 | $cuetrackpositions_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); |
||
| 867 | break; |
||
| 868 | |||
| 869 | default: |
||
| 870 | $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement); |
||
| 871 | } |
||
| 872 | } |
||
| 873 | $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry; |
||
| 874 | break; |
||
| 875 | |||
| 876 | case EBML_ID_CUETIME: |
||
| 877 | $cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 878 | break; |
||
| 879 | |||
| 880 | default: |
||
| 881 | $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement); |
||
| 882 | } |
||
| 883 | } |
||
| 884 | $cues_entry[] = $cuepoint_entry; |
||
| 885 | break; |
||
| 886 | |||
| 887 | default: |
||
| 888 | $this->unhandledElement('cues', __LINE__, $subelement); |
||
| 889 | } |
||
| 890 | } |
||
| 891 | $info['matroska']['cues'] = $cues_entry; |
||
| 892 | break; |
||
| 893 | |||
| 894 | case EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters. |
||
| 895 | $tags_entry = array(); |
||
| 896 | |||
| 897 | while ($this->getEBMLelement($subelement, $element_data['end'], false)) { |
||
| 898 | switch ($subelement['id']) { |
||
| 899 | |||
| 900 | case EBML_ID_TAG: |
||
| 901 | $tag_entry = array(); |
||
| 902 | |||
| 903 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) { |
||
| 904 | switch ($sub_subelement['id']) { |
||
| 905 | |||
| 906 | case EBML_ID_TARGETS: |
||
| 907 | $targets_entry = array(); |
||
| 908 | |||
| 909 | while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { |
||
| 910 | switch ($sub_sub_subelement['id']) { |
||
| 911 | |||
| 912 | case EBML_ID_TARGETTYPEVALUE: |
||
| 913 | $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); |
||
| 914 | $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::TargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]); |
||
| 915 | break; |
||
| 916 | |||
| 917 | case EBML_ID_TARGETTYPE: |
||
| 918 | $targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; |
||
| 919 | break; |
||
| 920 | |||
| 921 | case EBML_ID_TAGTRACKUID: |
||
| 922 | case EBML_ID_TAGEDITIONUID: |
||
| 923 | case EBML_ID_TAGCHAPTERUID: |
||
| 924 | case EBML_ID_TAGATTACHMENTUID: |
||
| 925 | $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); |
||
| 926 | break; |
||
| 927 | |||
| 928 | default: |
||
| 929 | $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement); |
||
| 930 | } |
||
| 931 | } |
||
| 932 | $tag_entry[$sub_subelement['id_name']] = $targets_entry; |
||
| 933 | break; |
||
| 934 | |||
| 935 | case EBML_ID_SIMPLETAG: |
||
| 936 | $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']); |
||
| 937 | break; |
||
| 938 | |||
| 939 | default: |
||
| 940 | $this->unhandledElement('tags.tag', __LINE__, $sub_subelement); |
||
| 941 | } |
||
| 942 | } |
||
| 943 | $tags_entry[] = $tag_entry; |
||
| 944 | break; |
||
| 945 | |||
| 946 | default: |
||
| 947 | $this->unhandledElement('tags', __LINE__, $subelement); |
||
| 948 | } |
||
| 949 | } |
||
| 950 | $info['matroska']['tags'] = $tags_entry; |
||
| 951 | break; |
||
| 952 | |||
| 953 | case EBML_ID_ATTACHMENTS: // Contain attached files. |
||
| 954 | |||
| 955 | while ($this->getEBMLelement($subelement, $element_data['end'])) { |
||
| 956 | switch ($subelement['id']) { |
||
| 957 | |||
| 958 | case EBML_ID_ATTACHEDFILE: |
||
| 959 | $attachedfile_entry = array(); |
||
| 960 | |||
| 961 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_FILEDATA))) { |
||
| 962 | switch ($sub_subelement['id']) { |
||
| 963 | |||
| 964 | case EBML_ID_FILEDESCRIPTION: |
||
| 965 | case EBML_ID_FILENAME: |
||
| 966 | case EBML_ID_FILEMIMETYPE: |
||
| 967 | $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data']; |
||
| 968 | break; |
||
| 969 | |||
| 970 | case EBML_ID_FILEDATA: |
||
| 971 | $attachedfile_entry['data_offset'] = $this->current_offset; |
||
| 972 | $attachedfile_entry['data_length'] = $sub_subelement['length']; |
||
| 973 | |||
| 974 | $attachedfile_entry[$sub_subelement['id_name']] = $this->saveAttachment( |
||
| 975 | $attachedfile_entry['FileName'], |
||
| 976 | $attachedfile_entry['data_offset'], |
||
| 977 | $attachedfile_entry['data_length']); |
||
| 978 | |||
| 979 | $this->current_offset = $sub_subelement['end']; |
||
| 980 | break; |
||
| 981 | |||
| 982 | case EBML_ID_FILEUID: |
||
| 983 | $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 984 | break; |
||
| 985 | |||
| 986 | default: |
||
| 987 | $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement); |
||
| 988 | } |
||
| 989 | } |
||
| 990 | $info['matroska']['attachments'][] = $attachedfile_entry; |
||
| 991 | break; |
||
| 992 | |||
| 993 | default: |
||
| 994 | $this->unhandledElement('attachments', __LINE__, $subelement); |
||
| 995 | } |
||
| 996 | } |
||
| 997 | break; |
||
| 998 | |||
| 999 | case EBML_ID_CHAPTERS: |
||
| 1000 | |||
| 1001 | while ($this->getEBMLelement($subelement, $element_data['end'])) { |
||
| 1002 | switch ($subelement['id']) { |
||
| 1003 | |||
| 1004 | case EBML_ID_EDITIONENTRY: |
||
| 1005 | $editionentry_entry = array(); |
||
| 1006 | |||
| 1007 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CHAPTERATOM))) { |
||
| 1008 | switch ($sub_subelement['id']) { |
||
| 1009 | |||
| 1010 | case EBML_ID_EDITIONUID: |
||
| 1011 | $editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 1012 | break; |
||
| 1013 | |||
| 1014 | case EBML_ID_EDITIONFLAGHIDDEN: |
||
| 1015 | case EBML_ID_EDITIONFLAGDEFAULT: |
||
| 1016 | case EBML_ID_EDITIONFLAGORDERED: |
||
| 1017 | $editionentry_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 1018 | break; |
||
| 1019 | |||
| 1020 | case EBML_ID_CHAPTERATOM: |
||
| 1021 | $chapteratom_entry = array(); |
||
| 1022 | |||
| 1023 | while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CHAPTERTRACK, EBML_ID_CHAPTERDISPLAY))) { |
||
| 1024 | switch ($sub_sub_subelement['id']) { |
||
| 1025 | |||
| 1026 | case EBML_ID_CHAPTERSEGMENTUID: |
||
| 1027 | case EBML_ID_CHAPTERSEGMENTEDITIONUID: |
||
| 1028 | $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; |
||
| 1029 | break; |
||
| 1030 | |||
| 1031 | case EBML_ID_CHAPTERFLAGENABLED: |
||
| 1032 | case EBML_ID_CHAPTERFLAGHIDDEN: |
||
| 1033 | $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_sub_subelement['data']); |
||
| 1034 | break; |
||
| 1035 | |||
| 1036 | case EBML_ID_CHAPTERUID: |
||
| 1037 | case EBML_ID_CHAPTERTIMESTART: |
||
| 1038 | case EBML_ID_CHAPTERTIMEEND: |
||
| 1039 | $chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); |
||
| 1040 | break; |
||
| 1041 | |||
| 1042 | case EBML_ID_CHAPTERTRACK: |
||
| 1043 | $chaptertrack_entry = array(); |
||
| 1044 | |||
| 1045 | while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { |
||
| 1046 | switch ($sub_sub_sub_subelement['id']) { |
||
| 1047 | |||
| 1048 | case EBML_ID_CHAPTERTRACKNUMBER: |
||
| 1049 | $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); |
||
| 1050 | break; |
||
| 1051 | |||
| 1052 | default: |
||
| 1053 | $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement); |
||
| 1054 | } |
||
| 1055 | } |
||
| 1056 | $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry; |
||
| 1057 | break; |
||
| 1058 | |||
| 1059 | case EBML_ID_CHAPTERDISPLAY: |
||
| 1060 | $chapterdisplay_entry = array(); |
||
| 1061 | |||
| 1062 | while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { |
||
| 1063 | switch ($sub_sub_sub_subelement['id']) { |
||
| 1064 | |||
| 1065 | case EBML_ID_CHAPSTRING: |
||
| 1066 | case EBML_ID_CHAPLANGUAGE: |
||
| 1067 | case EBML_ID_CHAPCOUNTRY: |
||
| 1068 | $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; |
||
| 1069 | break; |
||
| 1070 | |||
| 1071 | default: |
||
| 1072 | $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement); |
||
| 1073 | } |
||
| 1074 | } |
||
| 1075 | $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry; |
||
| 1076 | break; |
||
| 1077 | |||
| 1078 | default: |
||
| 1079 | $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement); |
||
| 1080 | } |
||
| 1081 | } |
||
| 1082 | $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry; |
||
| 1083 | break; |
||
| 1084 | |||
| 1085 | default: |
||
| 1086 | $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement); |
||
| 1087 | } |
||
| 1088 | } |
||
| 1089 | $info['matroska']['chapters'][] = $editionentry_entry; |
||
| 1090 | break; |
||
| 1091 | |||
| 1092 | default: |
||
| 1093 | $this->unhandledElement('chapters', __LINE__, $subelement); |
||
| 1094 | } |
||
| 1095 | } |
||
| 1096 | break; |
||
| 1097 | |||
| 1098 | case EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure. |
||
| 1099 | $cluster_entry = array(); |
||
| 1100 | |||
| 1101 | while ($this->getEBMLelement($subelement, $element_data['end'], array(EBML_ID_CLUSTERSILENTTRACKS, EBML_ID_CLUSTERBLOCKGROUP, EBML_ID_CLUSTERSIMPLEBLOCK))) { |
||
| 1102 | switch ($subelement['id']) { |
||
| 1103 | |||
| 1104 | case EBML_ID_CLUSTERTIMECODE: |
||
| 1105 | case EBML_ID_CLUSTERPOSITION: |
||
| 1106 | case EBML_ID_CLUSTERPREVSIZE: |
||
| 1107 | $cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); |
||
| 1108 | break; |
||
| 1109 | |||
| 1110 | case EBML_ID_CLUSTERSILENTTRACKS: |
||
| 1111 | $cluster_silent_tracks = array(); |
||
| 1112 | |||
| 1113 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { |
||
| 1114 | switch ($sub_subelement['id']) { |
||
| 1115 | |||
| 1116 | case EBML_ID_CLUSTERSILENTTRACKNUMBER: |
||
| 1117 | $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 1118 | break; |
||
| 1119 | |||
| 1120 | default: |
||
| 1121 | $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement); |
||
| 1122 | } |
||
| 1123 | } |
||
| 1124 | $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks; |
||
| 1125 | break; |
||
| 1126 | |||
| 1127 | case EBML_ID_CLUSTERBLOCKGROUP: |
||
| 1128 | $cluster_block_group = array('offset' => $this->current_offset); |
||
| 1129 | |||
| 1130 | while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CLUSTERBLOCK))) { |
||
| 1131 | switch ($sub_subelement['id']) { |
||
| 1132 | |||
| 1133 | case EBML_ID_CLUSTERBLOCK: |
||
| 1134 | $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, EBML_ID_CLUSTERBLOCK, $info); |
||
| 1135 | break; |
||
| 1136 | |||
| 1137 | case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int |
||
| 1138 | case EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int |
||
| 1139 | $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); |
||
| 1140 | break; |
||
| 1141 | |||
| 1142 | case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int |
||
| 1143 | $cluster_block_group[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data'], false, true); |
||
| 1144 | break; |
||
| 1145 | |||
| 1146 | case EBML_ID_CLUSTERCODECSTATE: |
||
| 1147 | $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); |
||
| 1148 | break; |
||
| 1149 | |||
| 1150 | default: |
||
| 1151 | $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement); |
||
| 1152 | } |
||
| 1153 | } |
||
| 1154 | $cluster_entry[$subelement['id_name']][] = $cluster_block_group; |
||
| 1155 | break; |
||
| 1156 | |||
| 1157 | case EBML_ID_CLUSTERSIMPLEBLOCK: |
||
| 1158 | $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info); |
||
| 1159 | break; |
||
| 1160 | |||
| 1161 | default: |
||
| 1162 | $this->unhandledElement('cluster', __LINE__, $subelement); |
||
| 1163 | } |
||
| 1164 | $this->current_offset = $subelement['end']; |
||
| 1165 | } |
||
| 1166 | if (!self::$hide_clusters) { |
||
| 1167 | $info['matroska']['cluster'][] = $cluster_entry; |
||
| 1168 | } |
||
| 1169 | |||
| 1170 | // check to see if all the data we need exists already, if so, break out of the loop |
||
| 1171 | if (!self::$parse_whole_file) { |
||
| 1172 | if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { |
||
| 1173 | if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { |
||
| 1174 | if (count($info['matroska']['track_data_offsets']) == count($info['matroska']['tracks']['tracks'])) { |
||
| 1175 | return; |
||
| 1176 | } |
||
| 1177 | } |
||
| 1178 | } |
||
| 1179 | } |
||
| 1180 | break; |
||
| 1181 | |||
| 1182 | default: |
||
| 1183 | $this->unhandledElement('segment', __LINE__, $element_data); |
||
| 1184 | } |
||
| 1185 | } |
||
| 1186 | break; |
||
| 1187 | |||
| 1188 | default: |
||
| 1189 | $this->unhandledElement('root', __LINE__, $top_element); |
||
| 1190 | } |
||
| 1191 | } |
||
| 1192 | } |
||
| 1193 | |||
| 1194 | private function EnsureBufferHasEnoughData($min_data=1024) { |
||
| 1195 | if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) { |
||
| 1196 | $read_bytes = max($min_data, $this->getid3->fread_buffer_size()); |
||
| 1197 | |||
| 1198 | try { |
||
| 1199 | $this->fseek($this->current_offset); |
||
| 1200 | $this->EBMLbuffer_offset = $this->current_offset; |
||
| 1201 | $this->EBMLbuffer = $this->fread($read_bytes); |
||
| 1202 | $this->EBMLbuffer_length = strlen($this->EBMLbuffer); |
||
| 1203 | } catch (getid3_exception $e) { |
||
| 1204 | $this->warning('EBML parser: '.$e->getMessage()); |
||
| 1205 | return false; |
||
| 1206 | } |
||
| 1207 | |||
| 1208 | if ($this->EBMLbuffer_length == 0 && $this->feof()) { |
||
| 1209 | return $this->error('EBML parser: ran out of file at offset '.$this->current_offset); |
||
| 1210 | } |
||
| 1211 | } |
||
| 1212 | return true; |
||
| 1213 | } |
||
| 1214 | |||
| 1215 | private function readEBMLint() { |
||
| 1216 | $actual_offset = $this->current_offset - $this->EBMLbuffer_offset; |
||
| 1217 | |||
| 1218 | // get length of integer |
||
| 1219 | $first_byte_int = ord($this->EBMLbuffer[$actual_offset]); |
||
| 1220 | if (0x80 & $first_byte_int) { |
||
| 1221 | $length = 1; |
||
| 1222 | } elseif (0x40 & $first_byte_int) { |
||
| 1223 | $length = 2; |
||
| 1224 | } elseif (0x20 & $first_byte_int) { |
||
| 1225 | $length = 3; |
||
| 1226 | } elseif (0x10 & $first_byte_int) { |
||
| 1227 | $length = 4; |
||
| 1228 | } elseif (0x08 & $first_byte_int) { |
||
| 1229 | $length = 5; |
||
| 1230 | } elseif (0x04 & $first_byte_int) { |
||
| 1231 | $length = 6; |
||
| 1232 | } elseif (0x02 & $first_byte_int) { |
||
| 1233 | $length = 7; |
||
| 1234 | } elseif (0x01 & $first_byte_int) { |
||
| 1235 | $length = 8; |
||
| 1236 | } else { |
||
| 1237 | throw new Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset); |
||
| 1238 | } |
||
| 1239 | |||
| 1240 | // read |
||
| 1241 | $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length)); |
||
| 1242 | $this->current_offset += $length; |
||
| 1243 | |||
| 1244 | return $int_value; |
||
| 1245 | } |
||
| 1246 | |||
| 1247 | private function readEBMLelementData($length, $check_buffer=false) { |
||
| 1248 | if ($check_buffer && !$this->EnsureBufferHasEnoughData($length)) { |
||
| 1249 | return false; |
||
| 1250 | } |
||
| 1251 | $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length); |
||
| 1252 | $this->current_offset += $length; |
||
| 1253 | return $data; |
||
| 1254 | } |
||
| 1255 | |||
| 1256 | private function getEBMLelement(&$element, $parent_end, $get_data=false) { |
||
| 1257 | if ($this->current_offset >= $parent_end) { |
||
| 1258 | return false; |
||
| 1259 | } |
||
| 1260 | |||
| 1261 | if (!$this->EnsureBufferHasEnoughData()) { |
||
| 1262 | $this->current_offset = PHP_INT_MAX; // do not exit parser right now, allow to finish current loop to gather maximum information |
||
| 1263 | return false; |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | $element = array(); |
||
| 1267 | |||
| 1268 | // set offset |
||
| 1269 | $element['offset'] = $this->current_offset; |
||
| 1270 | |||
| 1271 | // get ID |
||
| 1272 | $element['id'] = $this->readEBMLint(); |
||
| 1273 | |||
| 1274 | // get name |
||
| 1275 | $element['id_name'] = self::EBMLidName($element['id']); |
||
| 1276 | |||
| 1277 | // get length |
||
| 1278 | $element['length'] = $this->readEBMLint(); |
||
| 1279 | |||
| 1280 | // get end offset |
||
| 1281 | $element['end'] = $this->current_offset + $element['length']; |
||
| 1282 | |||
| 1283 | // get raw data |
||
| 1284 | $dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id'])); |
||
| 1285 | if (($get_data === true || (is_array($get_data) && !in_array($element['id'], $get_data))) && !$dont_parse) { |
||
| 1286 | $element['data'] = $this->readEBMLelementData($element['length'], $element); |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | return true; |
||
| 1290 | } |
||
| 1291 | |||
| 1292 | private function unhandledElement($type, $line, $element) { |
||
| 1293 | // warn only about unknown and missed elements, not about unuseful |
||
| 1294 | if (!in_array($element['id'], $this->unuseful_elements)) { |
||
| 1295 | $this->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']); |
||
| 1296 | } |
||
| 1297 | |||
| 1298 | // increase offset for unparsed elements |
||
| 1299 | if (!isset($element['data'])) { |
||
| 1300 | $this->current_offset = $element['end']; |
||
| 1301 | } |
||
| 1302 | } |
||
| 1303 | |||
| 1304 | private function ExtractCommentsSimpleTag($SimpleTagArray) { |
||
| 1305 | if (!empty($SimpleTagArray['SimpleTag'])) { |
||
| 1306 | foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) { |
||
| 1307 | if (!empty($SimpleTagData['TagName']) && !empty($SimpleTagData['TagString'])) { |
||
| 1308 | $this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString']; |
||
| 1309 | } |
||
| 1310 | if (!empty($SimpleTagData['SimpleTag'])) { |
||
| 1311 | $this->ExtractCommentsSimpleTag($SimpleTagData); |
||
| 1312 | } |
||
| 1313 | } |
||
| 1314 | } |
||
| 1315 | |||
| 1316 | return true; |
||
| 1317 | } |
||
| 1318 | |||
| 1319 | private function HandleEMBLSimpleTag($parent_end) { |
||
| 1320 | $simpletag_entry = array(); |
||
| 1321 | |||
| 1322 | while ($this->getEBMLelement($element, $parent_end, array(EBML_ID_SIMPLETAG))) { |
||
| 1323 | switch ($element['id']) { |
||
| 1324 | |||
| 1325 | case EBML_ID_TAGNAME: |
||
| 1326 | case EBML_ID_TAGLANGUAGE: |
||
| 1327 | case EBML_ID_TAGSTRING: |
||
| 1328 | case EBML_ID_TAGBINARY: |
||
| 1329 | $simpletag_entry[$element['id_name']] = $element['data']; |
||
| 1330 | break; |
||
| 1331 | |||
| 1332 | case EBML_ID_SIMPLETAG: |
||
| 1333 | $simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']); |
||
| 1334 | break; |
||
| 1335 | |||
| 1336 | case EBML_ID_TAGDEFAULT: |
||
| 1337 | $simpletag_entry[$element['id_name']] = (bool)getid3_lib::BigEndian2Int($element['data']); |
||
| 1338 | break; |
||
| 1339 | |||
| 1340 | default: |
||
| 1341 | $this->unhandledElement('tag.simpletag', __LINE__, $element); |
||
| 1342 | } |
||
| 1343 | } |
||
| 1344 | |||
| 1345 | return $simpletag_entry; |
||
| 1346 | } |
||
| 1347 | |||
| 1348 | private function HandleEMBLClusterBlock($element, $block_type, &$info) { |
||
| 1349 | // http://www.matroska.org/technical/specs/index.html#block_structure |
||
| 1350 | // http://www.matroska.org/technical/specs/index.html#simpleblock_structure |
||
| 1351 | |||
| 1352 | $block_data = array(); |
||
| 1353 | $block_data['tracknumber'] = $this->readEBMLint(); |
||
| 1354 | $block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2), false, true); |
||
| 1355 | $block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); |
||
| 1356 | |||
| 1357 | if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { |
||
| 1358 | $block_data['flags']['keyframe'] = (($block_data['flags_raw'] & 0x80) >> 7); |
||
| 1359 | //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0x70) >> 4); |
||
| 1360 | } |
||
| 1361 | else { |
||
| 1362 | //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0xF0) >> 4); |
||
| 1363 | } |
||
| 1364 | $block_data['flags']['invisible'] = (bool)(($block_data['flags_raw'] & 0x08) >> 3); |
||
| 1365 | $block_data['flags']['lacing'] = (($block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing |
||
| 1366 | if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { |
||
| 1367 | $block_data['flags']['discardable'] = (($block_data['flags_raw'] & 0x01)); |
||
| 1368 | } |
||
| 1369 | else { |
||
| 1370 | //$block_data['flags']['reserved2'] = (($block_data['flags_raw'] & 0x01) >> 0); |
||
| 1371 | } |
||
| 1372 | $block_data['flags']['lacing_type'] = self::BlockLacingType($block_data['flags']['lacing']); |
||
| 1373 | |||
| 1374 | // Lace (when lacing bit is set) |
||
| 1375 | if ($block_data['flags']['lacing'] > 0) { |
||
| 1376 | $block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8) |
||
| 1377 | if ($block_data['flags']['lacing'] != 0x02) { |
||
| 1378 | for ($i = 1; $i < $block_data['lace_frames']; $i ++) { // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). |
||
| 1379 | if ($block_data['flags']['lacing'] == 0x03) { // EBML lacing |
||
| 1380 | $block_data['lace_frames_size'][$i] = $this->readEBMLint(); // TODO: read size correctly, calc size for the last frame. For now offsets are deteminded OK with readEBMLint() and that's the most important thing. |
||
| 1381 | } |
||
| 1382 | else { // Xiph lacing |
||
| 1383 | $block_data['lace_frames_size'][$i] = 0; |
||
| 1384 | do { |
||
| 1385 | $size = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); |
||
| 1386 | $block_data['lace_frames_size'][$i] += $size; |
||
| 1387 | } |
||
| 1388 | while ($size == 255); |
||
| 1389 | } |
||
| 1390 | } |
||
| 1391 | if ($block_data['flags']['lacing'] == 0x01) { // calc size of the last frame only for Xiph lacing, till EBML sizes are now anyway determined incorrectly |
||
| 1392 | $block_data['lace_frames_size'][] = $element['end'] - $this->current_offset - array_sum($block_data['lace_frames_size']); |
||
| 1393 | } |
||
| 1394 | } |
||
| 1395 | } |
||
| 1396 | |||
| 1397 | if (!isset($info['matroska']['track_data_offsets'][$block_data['tracknumber']])) { |
||
| 1398 | $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['offset'] = $this->current_offset; |
||
| 1399 | $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset; |
||
| 1400 | //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] = 0; |
||
| 1401 | } |
||
| 1402 | //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] += $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length']; |
||
| 1403 | //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['duration'] = $block_data['timecode'] * ((isset($info['matroska']['info'][0]['TimecodeScale']) ? $info['matroska']['info'][0]['TimecodeScale'] : 1000000) / 1000000000); |
||
| 1404 | |||
| 1405 | // set offset manually |
||
| 1406 | $this->current_offset = $element['end']; |
||
| 1407 | |||
| 1408 | return $block_data; |
||
| 1409 | } |
||
| 1410 | |||
| 1411 | private static function EBML2Int($EBMLstring) { |
||
| 1412 | // http://matroska.org/specs/ |
||
| 1413 | |||
| 1414 | // Element ID coded with an UTF-8 like system: |
||
| 1415 | // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X) |
||
| 1416 | // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX) |
||
| 1417 | // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX) |
||
| 1418 | // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX) |
||
| 1419 | // Values with all x at 0 and 1 are reserved (hence the -2). |
||
| 1420 | |||
| 1421 | // Data size, in octets, is also coded with an UTF-8 like system : |
||
| 1422 | // 1xxx xxxx - value 0 to 2^7-2 |
||
| 1423 | // 01xx xxxx xxxx xxxx - value 0 to 2^14-2 |
||
| 1424 | // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2 |
||
| 1425 | // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2 |
||
| 1426 | // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2 |
||
| 1427 | // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2 |
||
| 1428 | // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2 |
||
| 1429 | // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2 |
||
| 1430 | |||
| 1431 | $first_byte_int = ord($EBMLstring[0]); |
||
| 1432 | if (0x80 & $first_byte_int) { |
||
| 1433 | $EBMLstring[0] = chr($first_byte_int & 0x7F); |
||
| 1434 | } elseif (0x40 & $first_byte_int) { |
||
| 1435 | $EBMLstring[0] = chr($first_byte_int & 0x3F); |
||
| 1436 | } elseif (0x20 & $first_byte_int) { |
||
| 1437 | $EBMLstring[0] = chr($first_byte_int & 0x1F); |
||
| 1438 | } elseif (0x10 & $first_byte_int) { |
||
| 1439 | $EBMLstring[0] = chr($first_byte_int & 0x0F); |
||
| 1440 | } elseif (0x08 & $first_byte_int) { |
||
| 1441 | $EBMLstring[0] = chr($first_byte_int & 0x07); |
||
| 1442 | } elseif (0x04 & $first_byte_int) { |
||
| 1443 | $EBMLstring[0] = chr($first_byte_int & 0x03); |
||
| 1444 | } elseif (0x02 & $first_byte_int) { |
||
| 1445 | $EBMLstring[0] = chr($first_byte_int & 0x01); |
||
| 1446 | } elseif (0x01 & $first_byte_int) { |
||
| 1447 | $EBMLstring[0] = chr($first_byte_int & 0x00); |
||
| 1448 | } |
||
| 1449 | |||
| 1450 | return getid3_lib::BigEndian2Int($EBMLstring); |
||
| 1451 | } |
||
| 1452 | |||
| 1453 | private static function EBMLdate2unix($EBMLdatestamp) { |
||
| 1454 | // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC) |
||
| 1455 | // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC |
||
| 1456 | return round(($EBMLdatestamp / 1000000000) + 978307200); |
||
| 1457 | } |
||
| 1458 | |||
| 1459 | public static function TargetTypeValue($target_type) { |
||
| 1460 | // http://www.matroska.org/technical/specs/tagging/index.html |
||
| 1461 | static $TargetTypeValue = array(); |
||
| 1462 | if (empty($TargetTypeValue)) { |
||
| 1463 | $TargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies |
||
| 1464 | $TargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement) |
||
| 1465 | $TargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie |
||
| 1466 | $TargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts |
||
| 1467 | $TargetTypeValue[50] = 'A:album/opera/concert ~ V:movie/episode/concert'; // the most common grouping level of music and video (equals to an episode for TV series) |
||
| 1468 | $TargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together |
||
| 1469 | $TargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items |
||
| 1470 | } |
||
| 1471 | return (isset($TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type); |
||
| 1472 | } |
||
| 1473 | |||
| 1474 | public static function BlockLacingType($lacingtype) { |
||
| 1475 | // http://matroska.org/technical/specs/index.html#block_structure |
||
| 1476 | static $BlockLacingType = array(); |
||
| 1477 | if (empty($BlockLacingType)) { |
||
| 1478 | $BlockLacingType[0x00] = 'no lacing'; |
||
| 1479 | $BlockLacingType[0x01] = 'Xiph lacing'; |
||
| 1480 | $BlockLacingType[0x02] = 'fixed-size lacing'; |
||
| 1481 | $BlockLacingType[0x03] = 'EBML lacing'; |
||
| 1482 | } |
||
| 1483 | return (isset($BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype); |
||
| 1484 | } |
||
| 1485 | |||
| 1486 | public static function CodecIDtoCommonName($codecid) { |
||
| 1487 | // http://www.matroska.org/technical/specs/codecid/index.html |
||
| 1488 | static $CodecIDlist = array(); |
||
| 1489 | if (empty($CodecIDlist)) { |
||
| 1490 | $CodecIDlist['A_AAC'] = 'aac'; |
||
| 1491 | $CodecIDlist['A_AAC/MPEG2/LC'] = 'aac'; |
||
| 1492 | $CodecIDlist['A_AC3'] = 'ac3'; |
||
| 1493 | $CodecIDlist['A_DTS'] = 'dts'; |
||
| 1494 | $CodecIDlist['A_FLAC'] = 'flac'; |
||
| 1495 | $CodecIDlist['A_MPEG/L1'] = 'mp1'; |
||
| 1496 | $CodecIDlist['A_MPEG/L2'] = 'mp2'; |
||
| 1497 | $CodecIDlist['A_MPEG/L3'] = 'mp3'; |
||
| 1498 | $CodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian |
||
| 1499 | $CodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian |
||
| 1500 | $CodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music |
||
| 1501 | $CodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2 |
||
| 1502 | $CodecIDlist['A_VORBIS'] = 'vorbis'; |
||
| 1503 | $CodecIDlist['V_MPEG1'] = 'mpeg'; |
||
| 1504 | $CodecIDlist['V_THEORA'] = 'theora'; |
||
| 1505 | $CodecIDlist['V_REAL/RV40'] = 'real'; |
||
| 1506 | $CodecIDlist['V_REAL/RV10'] = 'real'; |
||
| 1507 | $CodecIDlist['V_REAL/RV20'] = 'real'; |
||
| 1508 | $CodecIDlist['V_REAL/RV30'] = 'real'; |
||
| 1509 | $CodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime |
||
| 1510 | $CodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4'; |
||
| 1511 | $CodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4'; |
||
| 1512 | $CodecIDlist['V_MPEG4/ISO/AVC'] = 'h264'; |
||
| 1513 | $CodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4'; |
||
| 1514 | $CodecIDlist['V_VP8'] = 'vp8'; |
||
| 1515 | $CodecIDlist['V_MS/VFW/FOURCC'] = 'vcm'; // Microsoft (TM) Video Codec Manager (VCM) |
||
| 1516 | $CodecIDlist['A_MS/ACM'] = 'acm'; // Microsoft (TM) Audio Codec Manager (ACM) |
||
| 1517 | } |
||
| 1518 | return (isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid); |
||
| 1519 | } |
||
| 1520 | |||
| 1521 | private static function EBMLidName($value) { |
||
| 1522 | static $EBMLidList = array(); |
||
| 1523 | if (empty($EBMLidList)) { |
||
| 1524 | $EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType'; |
||
| 1525 | $EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile'; |
||
| 1526 | $EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink'; |
||
| 1527 | $EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments'; |
||
| 1528 | $EBMLidList[EBML_ID_AUDIO] = 'Audio'; |
||
| 1529 | $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth'; |
||
| 1530 | $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions'; |
||
| 1531 | $EBMLidList[EBML_ID_CHANNELS] = 'Channels'; |
||
| 1532 | $EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry'; |
||
| 1533 | $EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage'; |
||
| 1534 | $EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess'; |
||
| 1535 | $EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID'; |
||
| 1536 | $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand'; |
||
| 1537 | $EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData'; |
||
| 1538 | $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate'; |
||
| 1539 | $EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime'; |
||
| 1540 | $EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString'; |
||
| 1541 | $EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom'; |
||
| 1542 | $EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay'; |
||
| 1543 | $EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled'; |
||
| 1544 | $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden'; |
||
| 1545 | $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv'; |
||
| 1546 | $EBMLidList[EBML_ID_CHAPTERS] = 'Chapters'; |
||
| 1547 | $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID'; |
||
| 1548 | $EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID'; |
||
| 1549 | $EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd'; |
||
| 1550 | $EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart'; |
||
| 1551 | $EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack'; |
||
| 1552 | $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber'; |
||
| 1553 | $EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate'; |
||
| 1554 | $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec'; |
||
| 1555 | $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID'; |
||
| 1556 | $EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID'; |
||
| 1557 | $EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID'; |
||
| 1558 | $EBMLidList[EBML_ID_CLUSTER] = 'Cluster'; |
||
| 1559 | $EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock'; |
||
| 1560 | $EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID'; |
||
| 1561 | $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional'; |
||
| 1562 | $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID'; |
||
| 1563 | $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions'; |
||
| 1564 | $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration'; |
||
| 1565 | $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup'; |
||
| 1566 | $EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore'; |
||
| 1567 | $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual'; |
||
| 1568 | $EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState'; |
||
| 1569 | $EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay'; |
||
| 1570 | $EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration'; |
||
| 1571 | $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock'; |
||
| 1572 | $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber'; |
||
| 1573 | $EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber'; |
||
| 1574 | $EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition'; |
||
| 1575 | $EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize'; |
||
| 1576 | $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock'; |
||
| 1577 | $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority'; |
||
| 1578 | $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual'; |
||
| 1579 | $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber'; |
||
| 1580 | $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks'; |
||
| 1581 | $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock'; |
||
| 1582 | $EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode'; |
||
| 1583 | $EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice'; |
||
| 1584 | $EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll'; |
||
| 1585 | $EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL'; |
||
| 1586 | $EBMLidList[EBML_ID_CODECID] = 'CodecID'; |
||
| 1587 | $EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL'; |
||
| 1588 | $EBMLidList[EBML_ID_CODECNAME] = 'CodecName'; |
||
| 1589 | $EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate'; |
||
| 1590 | $EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings'; |
||
| 1591 | $EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace'; |
||
| 1592 | $EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo'; |
||
| 1593 | $EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression'; |
||
| 1594 | $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings'; |
||
| 1595 | $EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo'; |
||
| 1596 | $EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID'; |
||
| 1597 | $EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding'; |
||
| 1598 | $EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder'; |
||
| 1599 | $EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings'; |
||
| 1600 | $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope'; |
||
| 1601 | $EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType'; |
||
| 1602 | $EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption'; |
||
| 1603 | $EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo'; |
||
| 1604 | $EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo'; |
||
| 1605 | $EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID'; |
||
| 1606 | $EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature'; |
||
| 1607 | $EBMLidList[EBML_ID_CRC32] = 'CRC32'; |
||
| 1608 | $EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber'; |
||
| 1609 | $EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition'; |
||
| 1610 | $EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState'; |
||
| 1611 | $EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint'; |
||
| 1612 | $EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster'; |
||
| 1613 | $EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState'; |
||
| 1614 | $EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference'; |
||
| 1615 | $EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber'; |
||
| 1616 | $EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime'; |
||
| 1617 | $EBMLidList[EBML_ID_CUES] = 'Cues'; |
||
| 1618 | $EBMLidList[EBML_ID_CUETIME] = 'CueTime'; |
||
| 1619 | $EBMLidList[EBML_ID_CUETRACK] = 'CueTrack'; |
||
| 1620 | $EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions'; |
||
| 1621 | $EBMLidList[EBML_ID_DATEUTC] = 'DateUTC'; |
||
| 1622 | $EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration'; |
||
| 1623 | $EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight'; |
||
| 1624 | $EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit'; |
||
| 1625 | $EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth'; |
||
| 1626 | $EBMLidList[EBML_ID_DOCTYPE] = 'DocType'; |
||
| 1627 | $EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion'; |
||
| 1628 | $EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion'; |
||
| 1629 | $EBMLidList[EBML_ID_DURATION] = 'Duration'; |
||
| 1630 | $EBMLidList[EBML_ID_EBML] = 'EBML'; |
||
| 1631 | $EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength'; |
||
| 1632 | $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength'; |
||
| 1633 | $EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion'; |
||
| 1634 | $EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion'; |
||
| 1635 | $EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry'; |
||
| 1636 | $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault'; |
||
| 1637 | $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden'; |
||
| 1638 | $EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered'; |
||
| 1639 | $EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID'; |
||
| 1640 | $EBMLidList[EBML_ID_FILEDATA] = 'FileData'; |
||
| 1641 | $EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription'; |
||
| 1642 | $EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType'; |
||
| 1643 | $EBMLidList[EBML_ID_FILENAME] = 'FileName'; |
||
| 1644 | $EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral'; |
||
| 1645 | $EBMLidList[EBML_ID_FILEUID] = 'FileUID'; |
||
| 1646 | $EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault'; |
||
| 1647 | $EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled'; |
||
| 1648 | $EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced'; |
||
| 1649 | $EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced'; |
||
| 1650 | $EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing'; |
||
| 1651 | $EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue'; |
||
| 1652 | $EBMLidList[EBML_ID_INFO] = 'Info'; |
||
| 1653 | $EBMLidList[EBML_ID_LANGUAGE] = 'Language'; |
||
| 1654 | $EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID'; |
||
| 1655 | $EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache'; |
||
| 1656 | $EBMLidList[EBML_ID_MINCACHE] = 'MinCache'; |
||
| 1657 | $EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp'; |
||
| 1658 | $EBMLidList[EBML_ID_NAME] = 'Name'; |
||
| 1659 | $EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename'; |
||
| 1660 | $EBMLidList[EBML_ID_NEXTUID] = 'NextUID'; |
||
| 1661 | $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency'; |
||
| 1662 | $EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom'; |
||
| 1663 | $EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft'; |
||
| 1664 | $EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight'; |
||
| 1665 | $EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop'; |
||
| 1666 | $EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight'; |
||
| 1667 | $EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth'; |
||
| 1668 | $EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename'; |
||
| 1669 | $EBMLidList[EBML_ID_PREVUID] = 'PrevUID'; |
||
| 1670 | $EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency'; |
||
| 1671 | $EBMLidList[EBML_ID_SEEK] = 'Seek'; |
||
| 1672 | $EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead'; |
||
| 1673 | $EBMLidList[EBML_ID_SEEKID] = 'SeekID'; |
||
| 1674 | $EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition'; |
||
| 1675 | $EBMLidList[EBML_ID_SEGMENT] = 'Segment'; |
||
| 1676 | $EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily'; |
||
| 1677 | $EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename'; |
||
| 1678 | $EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID'; |
||
| 1679 | $EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag'; |
||
| 1680 | $EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices'; |
||
| 1681 | $EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode'; |
||
| 1682 | $EBMLidList[EBML_ID_OLDSTEREOMODE] = 'OldStereoMode'; |
||
| 1683 | $EBMLidList[EBML_ID_TAG] = 'Tag'; |
||
| 1684 | $EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID'; |
||
| 1685 | $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary'; |
||
| 1686 | $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID'; |
||
| 1687 | $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault'; |
||
| 1688 | $EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID'; |
||
| 1689 | $EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage'; |
||
| 1690 | $EBMLidList[EBML_ID_TAGNAME] = 'TagName'; |
||
| 1691 | $EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID'; |
||
| 1692 | $EBMLidList[EBML_ID_TAGS] = 'Tags'; |
||
| 1693 | $EBMLidList[EBML_ID_TAGSTRING] = 'TagString'; |
||
| 1694 | $EBMLidList[EBML_ID_TARGETS] = 'Targets'; |
||
| 1695 | $EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType'; |
||
| 1696 | $EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue'; |
||
| 1697 | $EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale'; |
||
| 1698 | $EBMLidList[EBML_ID_TITLE] = 'Title'; |
||
| 1699 | $EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry'; |
||
| 1700 | $EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber'; |
||
| 1701 | $EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset'; |
||
| 1702 | $EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay'; |
||
| 1703 | $EBMLidList[EBML_ID_TRACKS] = 'Tracks'; |
||
| 1704 | $EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale'; |
||
| 1705 | $EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate'; |
||
| 1706 | $EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec'; |
||
| 1707 | $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID'; |
||
| 1708 | $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID'; |
||
| 1709 | $EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType'; |
||
| 1710 | $EBMLidList[EBML_ID_TRACKUID] = 'TrackUID'; |
||
| 1711 | $EBMLidList[EBML_ID_VIDEO] = 'Video'; |
||
| 1712 | $EBMLidList[EBML_ID_VOID] = 'Void'; |
||
| 1713 | $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp'; |
||
| 1714 | } |
||
| 1715 | |||
| 1716 | return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value)); |
||
| 1717 | } |
||
| 1718 | |||
| 1719 | public static function displayUnit($value) { |
||
| 1720 | // http://www.matroska.org/technical/specs/index.html#DisplayUnit |
||
| 1721 | static $units = array( |
||
| 1722 | 0 => 'pixels', |
||
| 1723 | 1 => 'centimeters', |
||
| 1724 | 2 => 'inches', |
||
| 1725 | 3 => 'Display Aspect Ratio'); |
||
| 1726 | |||
| 1727 | return (isset($units[$value]) ? $units[$value] : 'unknown'); |
||
| 1728 | } |
||
| 1729 | |||
| 1730 | private static function getDefaultStreamInfo($streams) |
||
| 1731 | { |
||
| 1732 | foreach (array_reverse($streams) as $stream) { |
||
| 1733 | if ($stream['default']) { |
||
| 1734 | break; |
||
| 1735 | } |
||
| 1736 | } |
||
| 1737 | |||
| 1738 | $unset = array('default', 'name'); |
||
| 1739 | foreach ($unset as $u) { |
||
| 1740 | if (isset($stream[$u])) { |
||
| 1741 | unset($stream[$u]); |
||
| 1742 | } |
||
| 1743 | } |
||
| 1744 | |||
| 1745 | $info = $stream; |
||
| 1746 | $info['streams'] = $streams; |
||
| 1747 | |||
| 1748 | return $info; |
||
| 1749 | } |
||
| 1750 | |||
| 1751 | } |
||
| 1752 |