[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / medias / lib / getid3 / module.audio-video.matroska.php
index 825a22e..b2b187b 100644 (file)
@@ -1,11 +1,11 @@
 <?php
+
 /////////////////////////////////////////////////////////////////
 /// getID3() by James Heinrich <info@getid3.org>               //
-//  available at http://getid3.sourceforge.net                 //
-//            or http://www.getid3.org                         //
-//          also https://github.com/JamesHeinrich/getID3       //
-/////////////////////////////////////////////////////////////////
-// See readme.txt for more details                             //
+//  available at https://github.com/JamesHeinrich/getID3       //
+//            or https://www.getid3.org                        //
+//            or http://getid3.sourceforge.net                 //
+//  see readme.txt for more details                            //
 /////////////////////////////////////////////////////////////////
 //                                                             //
 // module.audio-video.matriska.php                             //
@@ -72,7 +72,7 @@ define('EBML_ID_FILEREFERRAL',                  0x0675); //         [46][75] --
 define('EBML_ID_FILEDESCRIPTION',               0x067E); //         [46][7E] -- A human-friendly name for the attached file.
 define('EBML_ID_FILEUID',                       0x06AE); //         [46][AE] -- Unique ID representing the file, as random as possible.
 define('EBML_ID_CONTENTENCALGO',                0x07E1); //         [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values:
-define('EBML_ID_CONTENTENCKEYID',               0x07E2); //         [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with.
+define('EBML_ID_CONTENTENCKEYID',               0x07E2); //         [47][E2] -- For public key algorithms this is the ID of the public key the data was encrypted with.
 define('EBML_ID_CONTENTSIGNATURE',              0x07E3); //         [47][E3] -- A cryptographic signature of the contents.
 define('EBML_ID_CONTENTSIGKEYID',               0x07E4); //         [47][E4] -- This is the ID of the private key the data was signed with.
 define('EBML_ID_CONTENTSIGALGO',                0x07E5); //         [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values:
@@ -215,17 +215,33 @@ define('EBML_ID_CLUSTERREFERENCEVIRTUAL',         0x7D); //             [FD] --
 */
 class getid3_matroska extends getid3_handler
 {
-       // public options
-       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]
-       public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE]
-
-       // private parser settings/placeholders
+       /**
+        * If true, do not return information about CLUSTER chunks, since there's a lot of them
+        * and they're not usually useful [default: TRUE].
+        *
+        * @var bool
+        */
+       public static $hide_clusters    = true;
+
+       /**
+        * True to parse the whole file, not only header [default: FALSE].
+        *
+        * @var bool
+        */
+       public static $parse_whole_file = false;
+
+       /*
+        * Private parser settings/placeholders.
+        */
        private $EBMLbuffer        = '';
        private $EBMLbuffer_offset = 0;
        private $EBMLbuffer_length = 0;
        private $current_offset    = 0;
        private $unuseful_elements = array(EBML_ID_CRC32, EBML_ID_VOID);
 
+       /**
+        * @return bool
+        */
        public function Analyze()
        {
                $info = &$this->getid3->info;
@@ -366,8 +382,8 @@ class getid3_matroska extends getid3_handler
                                                                if (!empty($getid3_temp->info[$header_data_key])) {
                                                                        $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key];
                                                                        if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
-                                                                               foreach ($getid3_temp->info['audio'] as $key => $value) {
-                                                                                       $track_info[$key] = $value;
+                                                                               foreach ($getid3_temp->info['audio'] as $sub_key => $value) {
+                                                                                       $track_info[$sub_key] = $value;
                                                                                }
                                                                        }
                                                                }
@@ -421,8 +437,8 @@ class getid3_matroska extends getid3_handler
                                                                if (!empty($getid3_temp->info['ogg'])) {
                                                                        $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg'];
                                                                        if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
-                                                                               foreach ($getid3_temp->info['audio'] as $key => $value) {
-                                                                                       $track_info[$key] = $value;
+                                                                               foreach ($getid3_temp->info['audio'] as $sub_key => $value) {
+                                                                                       $track_info[$sub_key] = $value;
                                                                                }
                                                                        }
                                                                }
@@ -449,9 +465,9 @@ class getid3_matroska extends getid3_handler
                                                                getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
 
                                                                $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']);
-                                                               foreach ($parsed as $key => $value) {
-                                                                       if ($key != 'raw') {
-                                                                               $track_info[$key] = $value;
+                                                               foreach ($parsed as $sub_key => $value) {
+                                                                       if ($sub_key != 'raw') {
+                                                                               $track_info[$sub_key] = $value;
                                                                        }
                                                                }
                                                                $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
@@ -496,6 +512,9 @@ class getid3_matroska extends getid3_handler
                return true;
        }
 
+       /**
+        * @param array $info
+        */
        private function parseEBML(&$info) {
                // http://www.matroska.org/technical/specs/index.html#EBMLBasics
                $this->current_offset = $info['avdataoffset'];
@@ -1228,6 +1247,11 @@ class getid3_matroska extends getid3_handler
                }
        }
 
+       /**
+        * @param int $min_data
+        *
+        * @return bool
+        */
        private function EnsureBufferHasEnoughData($min_data=1024) {
                if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) {
                        $read_bytes = max($min_data, $this->getid3->fread_buffer_size());
@@ -1249,6 +1273,9 @@ class getid3_matroska extends getid3_handler
                return true;
        }
 
+       /**
+        * @return int|float|false
+        */
        private function readEBMLint() {
                $actual_offset = $this->current_offset - $this->EBMLbuffer_offset;
 
@@ -1281,6 +1308,12 @@ class getid3_matroska extends getid3_handler
                return $int_value;
        }
 
+       /**
+        * @param int  $length
+        * @param bool $check_buffer
+        *
+        * @return string|false
+        */
        private function readEBMLelementData($length, $check_buffer=false) {
                if ($check_buffer && !$this->EnsureBufferHasEnoughData($length)) {
                        return false;
@@ -1290,6 +1323,13 @@ class getid3_matroska extends getid3_handler
                return $data;
        }
 
+       /**
+        * @param array      $element
+        * @param int        $parent_end
+        * @param array|bool $get_data
+        *
+        * @return bool
+        */
        private function getEBMLelement(&$element, $parent_end, $get_data=false) {
                if ($this->current_offset >= $parent_end) {
                        return false;
@@ -1326,6 +1366,11 @@ class getid3_matroska extends getid3_handler
                return true;
        }
 
+       /**
+        * @param string $type
+        * @param int    $line
+        * @param array  $element
+        */
        private function unhandledElement($type, $line, $element) {
                // warn only about unknown and missed elements, not about unuseful
                if (!in_array($element['id'], $this->unuseful_elements)) {
@@ -1338,6 +1383,11 @@ class getid3_matroska extends getid3_handler
                }
        }
 
+       /**
+        * @param array $SimpleTagArray
+        *
+        * @return bool
+        */
        private function ExtractCommentsSimpleTag($SimpleTagArray) {
                if (!empty($SimpleTagArray['SimpleTag'])) {
                        foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) {
@@ -1353,6 +1403,11 @@ class getid3_matroska extends getid3_handler
                return true;
        }
 
+       /**
+        * @param int $parent_end
+        *
+        * @return array
+        */
        private function HandleEMBLSimpleTag($parent_end) {
                $simpletag_entry = array();
 
@@ -1383,6 +1438,13 @@ class getid3_matroska extends getid3_handler
                return $simpletag_entry;
        }
 
+       /**
+        * @param array $element
+        * @param int   $block_type
+        * @param array $info
+        *
+        * @return array
+        */
        private function HandleEMBLClusterBlock($element, $block_type, &$info) {
                // http://www.matroska.org/technical/specs/index.html#block_structure
                // http://www.matroska.org/technical/specs/index.html#simpleblock_structure
@@ -1446,6 +1508,11 @@ class getid3_matroska extends getid3_handler
                return $block_data;
        }
 
+       /**
+        * @param string $EBMLstring
+        *
+        * @return int|float|false
+        */
        private static function EBML2Int($EBMLstring) {
                // http://matroska.org/specs/
 
@@ -1488,12 +1555,22 @@ class getid3_matroska extends getid3_handler
                return getid3_lib::BigEndian2Int($EBMLstring);
        }
 
+       /**
+        * @param int $EBMLdatestamp
+        *
+        * @return float
+        */
        private static function EBMLdate2unix($EBMLdatestamp) {
                // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
                // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC
                return round(($EBMLdatestamp / 1000000000) + 978307200);
        }
 
+       /**
+        * @param int $target_type
+        *
+        * @return string|int
+        */
        public static function TargetTypeValue($target_type) {
                // http://www.matroska.org/technical/specs/tagging/index.html
                static $TargetTypeValue = array();
@@ -1509,6 +1586,11 @@ class getid3_matroska extends getid3_handler
                return (isset($TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type);
        }
 
+       /**
+        * @param int $lacingtype
+        *
+        * @return string|int
+        */
        public static function BlockLacingType($lacingtype) {
                // http://matroska.org/technical/specs/index.html#block_structure
                static $BlockLacingType = array();
@@ -1521,6 +1603,11 @@ class getid3_matroska extends getid3_handler
                return (isset($BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype);
        }
 
+       /**
+        * @param string $codecid
+        *
+        * @return string
+        */
        public static function CodecIDtoCommonName($codecid) {
                // http://www.matroska.org/technical/specs/codecid/index.html
                static $CodecIDlist = array();
@@ -1557,6 +1644,11 @@ class getid3_matroska extends getid3_handler
                return (isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid);
        }
 
+       /**
+        * @param int $value
+        *
+        * @return string
+        */
        private static function EBMLidName($value) {
                static $EBMLidList = array();
                if (empty($EBMLidList)) {
@@ -1755,6 +1847,11 @@ class getid3_matroska extends getid3_handler
                return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
        }
 
+       /**
+        * @param int $value
+        *
+        * @return string
+        */
        public static function displayUnit($value) {
                // http://www.matroska.org/technical/specs/index.html#DisplayUnit
                static $units = array(
@@ -1766,8 +1863,14 @@ class getid3_matroska extends getid3_handler
                return (isset($units[$value]) ? $units[$value] : 'unknown');
        }
 
+       /**
+        * @param array $streams
+        *
+        * @return array
+        */
        private static function getDefaultStreamInfo($streams)
        {
+               $stream = array();
                foreach (array_reverse($streams) as $stream) {
                        if ($stream['default']) {
                                break;