Changeset 46112 for trunk/src/wp-includes/ID3/module.audio.ogg.php
- Timestamp:
- 09/14/2019 07:06:09 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ID3/module.audio.ogg.php
r41196 r46112 1 1 <?php 2 2 3 ///////////////////////////////////////////////////////////////// 3 4 /// getID3() by James Heinrich <info@getid3.org> // 4 // available at http://getid3.sourceforge.net // 5 // or http://www.getid3.org // 6 // also https://github.com/JamesHeinrich/getID3 // 7 ///////////////////////////////////////////////////////////////// 8 // See readme.txt for more details // 5 // available at https://github.com/JamesHeinrich/getID3 // 6 // or https://www.getid3.org // 7 // or http://getid3.sourceforge.net // 8 // see readme.txt for more details // 9 9 ///////////////////////////////////////////////////////////////// 10 10 // // … … 19 19 class getid3_ogg extends getid3_handler 20 20 { 21 // http://xiph.org/vorbis/doc/Vorbis_I_spec.html 21 /** 22 * @link http://xiph.org/vorbis/doc/Vorbis_I_spec.html 23 * 24 * @return bool 25 */ 22 26 public function Analyze() { 23 27 $info = &$this->getid3->info; … … 66 70 } elseif (substr($filedata, 0, 8) == 'OpusHead') { 67 71 68 if ( $this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) == false) {72 if ($this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) === false) { 69 73 return false; 70 74 } … … 180 184 $info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator']; 181 185 } 182 $this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable');186 $this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable'); 183 187 184 188 … … 260 264 //return false; 261 265 266 } elseif (substr($filedata, 0, 5) == "\x7F".'FLAC') { 267 // https://xiph.org/flac/ogg_mapping.html 268 269 $info['audio']['dataformat'] = 'flac'; 270 $info['audio']['bitrate_mode'] = 'vbr'; 271 $info['audio']['lossless'] = true; 272 273 $info['ogg']['flac']['header']['version_major'] = ord(substr($filedata, 5, 1)); 274 $info['ogg']['flac']['header']['version_minor'] = ord(substr($filedata, 6, 1)); 275 $info['ogg']['flac']['header']['header_packets'] = getid3_lib::BigEndian2Int(substr($filedata, 7, 2)) + 1; // "A two-byte, big-endian binary number signifying the number of header (non-audio) packets, not including this one. This number may be zero (0x0000) to signify 'unknown' but be aware that some decoders may not be able to handle such streams." 276 $info['ogg']['flac']['header']['magic'] = substr($filedata, 9, 4); 277 if ($info['ogg']['flac']['header']['magic'] != 'fLaC') { 278 $this->error('Ogg-FLAC expecting "fLaC", found "'.$info['ogg']['flac']['header']['magic'].'" ('.trim(getid3_lib::PrintHexBytes($info['ogg']['flac']['header']['magic'])).')'); 279 return false; 280 } 281 $info['ogg']['flac']['header']['STREAMINFO_bytes'] = getid3_lib::BigEndian2Int(substr($filedata, 13, 4)); 282 $info['flac']['STREAMINFO'] = getid3_flac::parseSTREAMINFOdata(substr($filedata, 17, 34)); 283 if (!empty($info['flac']['STREAMINFO']['sample_rate'])) { 284 $info['audio']['bitrate_mode'] = 'vbr'; 285 $info['audio']['sample_rate'] = $info['flac']['STREAMINFO']['sample_rate']; 286 $info['audio']['channels'] = $info['flac']['STREAMINFO']['channels']; 287 $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample']; 288 $info['playtime_seconds'] = $info['flac']['STREAMINFO']['samples_stream'] / $info['flac']['STREAMINFO']['sample_rate']; 289 } 290 262 291 } else { 263 292 264 $this->error('Expecting either "Speex ", "OpusHead" or "vorbis" identifier strings, found "'.substr($filedata, 0, 8).'"');293 $this->error('Expecting one of "vorbis", "Speex", "OpusHead", "vorbis", "fishhead", "theora", "fLaC" identifier strings, found "'.substr($filedata, 0, 8).'"'); 265 294 unset($info['ogg']); 266 295 unset($info['mime_type']); … … 379 408 } 380 409 410 /** 411 * @param string $filedata 412 * @param int $filedataoffset 413 * @param array $oggpageinfo 414 * 415 * @return bool 416 */ 381 417 public function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) { 382 418 $info = &$this->getid3->info; … … 427 463 } 428 464 429 // http://tools.ietf.org/html/draft-ietf-codec-oggopus-03 465 /** 466 * @link http://tools.ietf.org/html/draft-ietf-codec-oggopus-03 467 * 468 * @param string $filedata 469 * @param int $filedataoffset 470 * @param array $oggpageinfo 471 * 472 * @return bool 473 */ 430 474 public function ParseOpusPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) { 431 475 $info = &$this->getid3->info; … … 459 503 $filedataoffset += 2; 460 504 461 $info['ogg']['pageheader']['opus'][' sample_rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4));505 $info['ogg']['pageheader']['opus']['input_sample_rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); 462 506 $filedataoffset += 4; 463 507 … … 468 512 //$filedataoffset += 1; 469 513 470 $info['opus']['opus_version'] = $info['ogg']['pageheader']['opus']['version']; 471 $info['opus']['sample_rate'] = $info['ogg']['pageheader']['opus']['sample_rate']; 472 $info['opus']['out_channel_count'] = $info['ogg']['pageheader']['opus']['out_channel_count']; 473 474 $info['audio']['channels'] = $info['opus']['out_channel_count']; 475 $info['audio']['sample_rate'] = $info['opus']['sample_rate']; 514 $info['opus']['opus_version'] = $info['ogg']['pageheader']['opus']['version']; 515 $info['opus']['sample_rate_input'] = $info['ogg']['pageheader']['opus']['input_sample_rate']; 516 $info['opus']['out_channel_count'] = $info['ogg']['pageheader']['opus']['out_channel_count']; 517 518 $info['audio']['channels'] = $info['opus']['out_channel_count']; 519 $info['audio']['sample_rate_input'] = $info['opus']['sample_rate_input']; 520 $info['audio']['sample_rate'] = 48000; // "All Opus audio is coded at 48 kHz, and should also be decoded at 48 kHz for playback (unless the target hardware does not support this sampling rate). However, this field may be used to resample the audio back to the original sampling rate, for example, when saving the output to a file." -- https://mf4.xiph.org/jenkins/view/opus/job/opusfile-unix/ws/doc/html/structOpusHead.html 476 521 return true; 477 522 } 478 523 479 524 /** 525 * @return array|false 526 */ 480 527 public function ParseOggPageHeader() { 481 528 // http://xiph.org/ogg/vorbis/doc/framing.html … … 490 537 } 491 538 if ((($filedataoffset + 28) > strlen($filedata)) || (strlen($filedata) < 28)) { 492 if ($this->feof() || (($filedata .= $this->fread($this->getid3->fread_buffer_size())) === false)) {539 if ($this->feof() || (($filedata .= $this->fread($this->getid3->fread_buffer_size())) === '')) { 493 540 // get some more data, unless eof, in which case fail 494 541 return false; … … 529 576 } 530 577 531 // http://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810005 578 /** 579 * @link http://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810005 580 * 581 * @return bool 582 */ 532 583 public function ParseVorbisComments() { 533 584 $info = &$this->getid3->info; 534 585 535 586 $OriginalOffset = $this->ftell(); 587 $commentdata = null; 536 588 $commentdataoffset = 0; 537 589 $VorbisCommentPage = 1; 590 $CommentStartOffset = 0; 538 591 539 592 switch ($info['audio']['dataformat']) { … … 766 819 } 767 820 821 /** 822 * @param int $mode 823 * 824 * @return string|null 825 */ 768 826 public static function SpeexBandModeLookup($mode) { 769 827 static $SpeexBandModeLookup = array(); … … 776 834 } 777 835 778 836 /** 837 * @param array $OggInfoArray 838 * @param int $SegmentNumber 839 * 840 * @return int 841 */ 779 842 public static function OggPageSegmentLength($OggInfoArray, $SegmentNumber=1) { 843 $segmentlength = 0; 780 844 for ($i = 0; $i < $SegmentNumber; $i++) { 781 845 $segmentlength = 0; … … 790 854 } 791 855 792 856 /** 857 * @param int $nominal_bitrate 858 * 859 * @return float 860 */ 793 861 public static function get_quality_from_nominal_bitrate($nominal_bitrate) { 794 862 … … 814 882 } 815 883 884 /** 885 * @param int $colorspace_id 886 * 887 * @return string|null 888 */ 816 889 public static function TheoraColorSpace($colorspace_id) { 817 890 // http://www.theora.org/doc/Theora.pdf (table 6.3) … … 826 899 } 827 900 901 /** 902 * @param int $pixelformat_id 903 * 904 * @return string|null 905 */ 828 906 public static function TheoraPixelFormat($pixelformat_id) { 829 907 // http://www.theora.org/doc/Theora.pdf (table 6.4)
Note: See TracChangeset
for help on using the changeset viewer.