Make WordPress Core


Ignore:
Timestamp:
06/28/2015 12:16:17 AM (11 years ago)
Author:
wonderboymusic
Message:

Update getID3 to 1.9.9

Changelog:

Fixes #32806.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ID3/module.audio.ogg.php

    r29734 r32979  
    6363
    6464                        $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo);
     65
     66                } elseif (substr($filedata, 0, 8) == 'OpusHead') {
     67
     68                        if( $this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) == false ) {
     69                                return false;
     70                        }
    6571
    6672                } elseif (substr($filedata, 0, 8) == 'Speex   ') {
    … …  
    256262                } else {
    257263
    258                         $info['error'][] = 'Expecting either "Speex   " or "vorbis" identifier strings, found "'.substr($filedata, 0, 8).'"';
     264                        $info['error'][] = 'Expecting either "Speex   ", "OpusHead" or "vorbis" identifier strings, found "'.substr($filedata, 0, 8).'"';
    259265                        unset($info['ogg']);
    260266                        unset($info['mime_type']);
    … …  
    289295                                $this->ParseVorbisComments();
    290296                                break;
    291                 }
    292 
     297
     298                        case 'opus':
     299                                $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
     300                                $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 0, 8); // hard-coded to 'OpusTags'
     301                                if(substr($filedata, 0, 8)  != 'OpusTags') {
     302                                        $info['error'][] = 'Expected "OpusTags" as header but got "'.substr($filedata, 0, 8).'"';
     303                                        return false;
     304                                }
     305
     306                                $this->ParseVorbisComments();
     307                                break;
     308
     309                }
    293310
    294311                // Last Page - Number of Samples
    … …  
    409426                return true;
    410427        }
     428
     429        // http://tools.ietf.org/html/draft-ietf-codec-oggopus-03
     430        public function ParseOpusPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) {
     431                $info = &$this->getid3->info;
     432                $info['audio']['dataformat']   = 'opus';
     433                $info['mime_type']             = 'audio/ogg; codecs=opus';
     434
     435                /** @todo find a usable way to detect abr (vbr that is padded to be abr) */
     436                $info['audio']['bitrate_mode'] = 'vbr';
     437
     438                $info['audio']['lossless']     = false;
     439
     440                $info['ogg']['pageheader']['opus']['opus_magic'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'OpusHead'
     441                $filedataoffset += 8;
     442                $info['ogg']['pageheader']['opus']['version']    = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset,  1));
     443                $filedataoffset += 1;
     444
     445                if ($info['ogg']['pageheader']['opus']['version'] < 1 || $info['ogg']['pageheader']['opus']['version'] > 15) {
     446                        $info['error'][] = 'Unknown opus version number (only accepting 1-15)';
     447                        return false;
     448                }
     449
     450                $info['ogg']['pageheader']['opus']['out_channel_count'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset,  1));
     451                $filedataoffset += 1;
     452
     453                if ($info['ogg']['pageheader']['opus']['out_channel_count'] == 0) {
     454                        $info['error'][] = 'Invalid channel count in opus header (must not be zero)';
     455                        return false;
     456                }
     457
     458                $info['ogg']['pageheader']['opus']['pre_skip'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset,  2));
     459                $filedataoffset += 2;
     460
     461                $info['ogg']['pageheader']['opus']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset,  4));
     462                $filedataoffset += 4;
     463
     464                //$info['ogg']['pageheader']['opus']['output_gain'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset,  2));
     465                //$filedataoffset += 2;
     466
     467                //$info['ogg']['pageheader']['opus']['channel_mapping_family'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset,  1));
     468                //$filedataoffset += 1;
     469
     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'];
     476                return true;
     477        }
     478
    411479
    412480        public function ParseOggPageHeader() {
    … …  
    472540                        case 'vorbis':
    473541                        case 'speex':
     542                        case 'opus':
    474543                                $CommentStartOffset = $info['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset'];  // Second Ogg page, after header block
    475544                                $this->fseek($CommentStartOffset);
    … …  
    480549                                        $commentdataoffset += (strlen('vorbis') + 1);
    481550                                }
     551                                else if ($info['audio']['dataformat'] == 'opus') {
     552                                        $commentdataoffset += strlen('OpusTags');
     553                                }
     554
    482555                                break;
    483556
    … …  
    505578                $ThisFileInfo_ogg_comments_raw = &$info['ogg']['comments_raw'];
    506579                for ($i = 0; $i < $CommentsCount; $i++) {
     580
     581                        if ($i >= 10000) {
     582                                // https://github.com/owncloud/music/issues/212#issuecomment-43082336
     583                                $info['warning'][] = 'Unexpectedly large number ('.$CommentsCount.') of Ogg comments - breaking after reading '.$i.' comments';
     584                                break;
     585                        }
    507586
    508587                        $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset;
    … …  
    616695                                        $ogg->setStringMode($data);
    617696                                        $info['ogg']['comments']['picture'][] = array(
    618                                                 'image_mime' => $imageinfo['mime'],
    619                                                 'data'       => $ogg->saveAttachment('coverart', 0, strlen($data), $imageinfo['mime']),
     697                                                'image_mime'   => $imageinfo['mime'],
     698                                                'datalength'   => strlen($data),
     699                                                'picturetype'  => 'cover art',
     700                                                'image_height' => $imageinfo['height'],
     701                                                'image_width'  => $imageinfo['width'],
     702                                                'data'         => $ogg->saveAttachment('coverart', 0, strlen($data), $imageinfo['mime']),
    620703                                        );
    621704                                        unset($ogg);
Note: See TracChangeset for help on using the changeset viewer.