Make WordPress Core


Ignore:
Timestamp:
09/14/2019 07:06:09 PM (7 years ago)
Author:
jorbin
Message:

Update getID3 library to fix issues with PHP7.4

Updates to trunk version that includes fixes for PHP7.4

Changelog:
​https://github.com/JamesHeinrich/getID3/compare/v1.9.14...00f3fbfd77e583099ca70a3cf0bc092e113d2b20

See: #47751,#47783.
Fixes: #48040.

File:
1 edited

Legend:

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

    r41196 r46112  
    11<?php
     2
    23/////////////////////////////////////////////////////////////////
    34/// 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                            //
    99/////////////////////////////////////////////////////////////////
    1010//                                                             //
    … …  
    1919class getid3_ogg extends getid3_handler
    2020{
    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         */
    2226        public function Analyze() {
    2327                $info = &$this->getid3->info;
    … …  
    6670                } elseif (substr($filedata, 0, 8) == 'OpusHead') {
    6771
    68                         if( $this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) == false ) {
     72                        if ($this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) === false) {
    6973                                return false;
    7074                        }
    … …  
    180184                                $info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'];
    181185                        }
    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');
    183187
    184188
    … …  
    260264                        //return false;
    261265
     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
    262291                } else {
    263292
    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).'"');
    265294                        unset($info['ogg']);
    266295                        unset($info['mime_type']);
    … …  
    379408        }
    380409
     410        /**
     411         * @param string $filedata
     412         * @param int    $filedataoffset
     413         * @param array  $oggpageinfo
     414         *
     415         * @return bool
     416         */
    381417        public function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) {
    382418                $info = &$this->getid3->info;
    … …  
    427463        }
    428464
    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         */
    430474        public function ParseOpusPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) {
    431475                $info = &$this->getid3->info;
    … …  
    459503                $filedataoffset += 2;
    460504
    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));
    462506                $filedataoffset += 4;
    463507
    … …  
    468512                //$filedataoffset += 1;
    469513
    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
    476521                return true;
    477522        }
    478523
    479 
     524        /**
     525         * @return array|false
     526         */
    480527        public function ParseOggPageHeader() {
    481528                // http://xiph.org/ogg/vorbis/doc/framing.html
    … …  
    490537                        }
    491538                        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())) === '')) {
    493540                                        // get some more data, unless eof, in which case fail
    494541                                        return false;
    … …  
    529576        }
    530577
    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         */
    532583        public function ParseVorbisComments() {
    533584                $info = &$this->getid3->info;
    534585
    535586                $OriginalOffset = $this->ftell();
     587                $commentdata = null;
    536588                $commentdataoffset = 0;
    537589                $VorbisCommentPage = 1;
     590                $CommentStartOffset = 0;
    538591
    539592                switch ($info['audio']['dataformat']) {
    … …  
    766819        }
    767820
     821        /**
     822         * @param int $mode
     823         *
     824         * @return string|null
     825         */
    768826        public static function SpeexBandModeLookup($mode) {
    769827                static $SpeexBandModeLookup = array();
    … …  
    776834        }
    777835
    778 
     836        /**
     837         * @param array $OggInfoArray
     838         * @param int   $SegmentNumber
     839         *
     840         * @return int
     841         */
    779842        public static function OggPageSegmentLength($OggInfoArray, $SegmentNumber=1) {
     843                $segmentlength = 0;
    780844                for ($i = 0; $i < $SegmentNumber; $i++) {
    781845                        $segmentlength = 0;
    … …  
    790854        }
    791855
    792 
     856        /**
     857         * @param int $nominal_bitrate
     858         *
     859         * @return float
     860         */
    793861        public static function get_quality_from_nominal_bitrate($nominal_bitrate) {
    794862
    … …  
    814882        }
    815883
     884        /**
     885         * @param int $colorspace_id
     886         *
     887         * @return string|null
     888         */
    816889        public static function TheoraColorSpace($colorspace_id) {
    817890                // http://www.theora.org/doc/Theora.pdf (table 6.3)
    … …  
    826899        }
    827900
     901        /**
     902         * @param int $pixelformat_id
     903         *
     904         * @return string|null
     905         */
    828906        public static function TheoraPixelFormat($pixelformat_id) {
    829907                // http://www.theora.org/doc/Theora.pdf (table 6.4)
Note: See TracChangeset for help on using the changeset viewer.