wp/wp-includes/ID3/module.audio.ogg.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     1 <?php
     1 <?php
     2 /////////////////////////////////////////////////////////////////
     2 /////////////////////////////////////////////////////////////////
     3 /// getID3() by James Heinrich <info@getid3.org>               //
     3 /// getID3() by James Heinrich <info@getid3.org>               //
     4 //  available at http://getid3.sourceforge.net                 //
     4 //  available at http://getid3.sourceforge.net                 //
     5 //            or http://www.getid3.org                         //
     5 //            or http://www.getid3.org                         //
       
     6 //          also https://github.com/JamesHeinrich/getID3       //
     6 /////////////////////////////////////////////////////////////////
     7 /////////////////////////////////////////////////////////////////
     7 // See readme.txt for more details                             //
     8 // See readme.txt for more details                             //
     8 /////////////////////////////////////////////////////////////////
     9 /////////////////////////////////////////////////////////////////
     9 //                                                             //
    10 //                                                             //
    10 // module.audio.ogg.php                                        //
    11 // module.audio.ogg.php                                        //
   111 			$info['audio']['sample_rate']   = $info['speex']['sample_rate'];
   112 			$info['audio']['sample_rate']   = $info['speex']['sample_rate'];
   112 			$info['audio']['channels']      = $info['speex']['channels'];
   113 			$info['audio']['channels']      = $info['speex']['channels'];
   113 			if ($info['speex']['vbr']) {
   114 			if ($info['speex']['vbr']) {
   114 				$info['audio']['bitrate_mode'] = 'vbr';
   115 				$info['audio']['bitrate_mode'] = 'vbr';
   115 			}
   116 			}
       
   117 
       
   118 		} elseif (substr($filedata, 0, 7) == "\x80".'theora') {
       
   119 
       
   120 			// http://www.theora.org/doc/Theora.pdf (section 6.2)
       
   121 
       
   122 			$info['ogg']['pageheader']['theora']['theora_magic']             =                           substr($filedata, $filedataoffset,  7); // hard-coded to "\x80.'theora'
       
   123 			$filedataoffset += 7;
       
   124 			$info['ogg']['pageheader']['theora']['version_major']            = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
       
   125 			$filedataoffset += 1;
       
   126 			$info['ogg']['pageheader']['theora']['version_minor']            = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
       
   127 			$filedataoffset += 1;
       
   128 			$info['ogg']['pageheader']['theora']['version_revision']         = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
       
   129 			$filedataoffset += 1;
       
   130 			$info['ogg']['pageheader']['theora']['frame_width_macroblocks']  = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  2));
       
   131 			$filedataoffset += 2;
       
   132 			$info['ogg']['pageheader']['theora']['frame_height_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  2));
       
   133 			$filedataoffset += 2;
       
   134 			$info['ogg']['pageheader']['theora']['resolution_x']             = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
       
   135 			$filedataoffset += 3;
       
   136 			$info['ogg']['pageheader']['theora']['resolution_y']             = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
       
   137 			$filedataoffset += 3;
       
   138 			$info['ogg']['pageheader']['theora']['picture_offset_x']         = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
       
   139 			$filedataoffset += 1;
       
   140 			$info['ogg']['pageheader']['theora']['picture_offset_y']         = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
       
   141 			$filedataoffset += 1;
       
   142 			$info['ogg']['pageheader']['theora']['frame_rate_numerator']     = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  4));
       
   143 			$filedataoffset += 4;
       
   144 			$info['ogg']['pageheader']['theora']['frame_rate_denominator']   = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  4));
       
   145 			$filedataoffset += 4;
       
   146 			$info['ogg']['pageheader']['theora']['pixel_aspect_numerator']   = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
       
   147 			$filedataoffset += 3;
       
   148 			$info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
       
   149 			$filedataoffset += 3;
       
   150 			$info['ogg']['pageheader']['theora']['color_space_id']           = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  1));
       
   151 			$filedataoffset += 1;
       
   152 			$info['ogg']['pageheader']['theora']['nominal_bitrate']          = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  3));
       
   153 			$filedataoffset += 3;
       
   154 			$info['ogg']['pageheader']['theora']['flags']                    = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset,  2));
       
   155 			$filedataoffset += 2;
       
   156 
       
   157 			$info['ogg']['pageheader']['theora']['quality']         = ($info['ogg']['pageheader']['theora']['flags'] & 0xFC00) >> 10;
       
   158 			$info['ogg']['pageheader']['theora']['kfg_shift']       = ($info['ogg']['pageheader']['theora']['flags'] & 0x03E0) >>  5;
       
   159 			$info['ogg']['pageheader']['theora']['pixel_format_id'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0018) >>  3;
       
   160 			$info['ogg']['pageheader']['theora']['reserved']        = ($info['ogg']['pageheader']['theora']['flags'] & 0x0007) >>  0; // should be 0
       
   161 			$info['ogg']['pageheader']['theora']['color_space']     = self::TheoraColorSpace($info['ogg']['pageheader']['theora']['color_space_id']);
       
   162 			$info['ogg']['pageheader']['theora']['pixel_format']    = self::TheoraPixelFormat($info['ogg']['pageheader']['theora']['pixel_format_id']);
       
   163 
       
   164 			$info['video']['dataformat']   = 'theora';
       
   165 			$info['mime_type']             = 'video/ogg';
       
   166 			//$info['audio']['bitrate_mode'] = 'abr';
       
   167 			//$info['audio']['lossless']     = false;
       
   168 			$info['video']['resolution_x'] = $info['ogg']['pageheader']['theora']['resolution_x'];
       
   169 			$info['video']['resolution_y'] = $info['ogg']['pageheader']['theora']['resolution_y'];
       
   170 			if ($info['ogg']['pageheader']['theora']['frame_rate_denominator'] > 0) {
       
   171 				$info['video']['frame_rate'] = (float) $info['ogg']['pageheader']['theora']['frame_rate_numerator'] / $info['ogg']['pageheader']['theora']['frame_rate_denominator'];
       
   172 			}
       
   173 			if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) {
       
   174 				$info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'];
       
   175 			}
       
   176 $info['warning'][] = 'Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable';
   116 
   177 
   117 
   178 
   118 		} elseif (substr($filedata, 0, 8) == "fishead\x00") {
   179 		} elseif (substr($filedata, 0, 8) == "fishead\x00") {
   119 
   180 
   120 			// Ogg Skeleton version 3.0 Format Specification
   181 			// Ogg Skeleton version 3.0 Format Specification
   170 					$info['ogg']['skeleton']['fisbone']['raw']['padding']                 =                              substr($filedata, $filedataoffset,  3);
   231 					$info['ogg']['skeleton']['fisbone']['raw']['padding']                 =                              substr($filedata, $filedataoffset,  3);
   171 					$filedataoffset += 3;
   232 					$filedataoffset += 3;
   172 
   233 
   173 				} elseif (substr($filedata, 1, 6) == 'theora') {
   234 				} elseif (substr($filedata, 1, 6) == 'theora') {
   174 
   235 
   175 					$info['video']['dataformat'] = 'theora';
   236 					$info['video']['dataformat'] = 'theora1';
   176 					$info['error'][] = 'Ogg Theora not correctly handled in this version of getID3 ['.$this->getid3->version().']';
   237 					$info['error'][] = 'Ogg Theora (v1) not correctly handled in this version of getID3 ['.$this->getid3->version().']';
   177 					//break;
   238 					//break;
   178 
   239 
   179 				} elseif (substr($filedata, 1, 6) == 'vorbis') {
   240 				} elseif (substr($filedata, 1, 6) == 'vorbis') {
   180 
   241 
   181 					$this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo);
   242 					$this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo);
   666 		//return $qval; // 5.031324
   727 		//return $qval; // 5.031324
   667 		//return intval($qval); // 5
   728 		//return intval($qval); // 5
   668 		return round($qval, 1); // 5 or 4.9
   729 		return round($qval, 1); // 5 or 4.9
   669 	}
   730 	}
   670 
   731 
       
   732 	public static function TheoraColorSpace($colorspace_id) {
       
   733 		// http://www.theora.org/doc/Theora.pdf (table 6.3)
       
   734 		static $TheoraColorSpaceLookup = array();
       
   735 		if (empty($TheoraColorSpaceLookup)) {
       
   736 			$TheoraColorSpaceLookup[0] = 'Undefined';
       
   737 			$TheoraColorSpaceLookup[1] = 'Rec. 470M';
       
   738 			$TheoraColorSpaceLookup[2] = 'Rec. 470BG';
       
   739 			$TheoraColorSpaceLookup[3] = 'Reserved';
       
   740 		}
       
   741 		return (isset($TheoraColorSpaceLookup[$colorspace_id]) ? $TheoraColorSpaceLookup[$colorspace_id] : null);
       
   742 	}
       
   743 
       
   744 	public static function TheoraPixelFormat($pixelformat_id) {
       
   745 		// http://www.theora.org/doc/Theora.pdf (table 6.4)
       
   746 		static $TheoraPixelFormatLookup = array();
       
   747 		if (empty($TheoraPixelFormatLookup)) {
       
   748 			$TheoraPixelFormatLookup[0] = '4:2:0';
       
   749 			$TheoraPixelFormatLookup[1] = 'Reserved';
       
   750 			$TheoraPixelFormatLookup[2] = '4:2:2';
       
   751 			$TheoraPixelFormatLookup[3] = '4:4:4';
       
   752 		}
       
   753 		return (isset($TheoraPixelFormatLookup[$pixelformat_id]) ? $TheoraPixelFormatLookup[$pixelformat_id] : null);
       
   754 	}
       
   755 
   671 }
   756 }