Changeset 41196 for trunk/src/wp-includes/ID3/module.audio.mp3.php
- Timestamp:
- 07/31/2017 07:49:31 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ID3/module.audio.mp3.php
r32979 r41196 35 35 if (!$this->getOnlyMPEGaudioInfo($info['avdataoffset'])) { 36 36 if ($this->allow_bruteforce) { 37 $ info['error'][] = 'Rescanning file in BruteForce mode';37 $this->error('Rescanning file in BruteForce mode'); 38 38 $this->getOnlyMPEGaudioInfoBruteForce($this->getid3->fp, $info); 39 39 } … … 73 73 74 74 } 75 $ info['warning'][] = $synchoffsetwarning;75 $this->warning($synchoffsetwarning); 76 76 77 77 } … … 135 135 136 136 default: 137 $ info['warning'][] = 'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"';137 $this->warning('Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"'); 138 138 break; 139 139 } … … 425 425 426 426 if ($this->fseek($offset) != 0) { 427 $ info['error'][] = 'decodeMPEGaudioHeader() failed to seek to next offset at '.$offset;427 $this->error('decodeMPEGaudioHeader() failed to seek to next offset at '.$offset); 428 428 return false; 429 429 } … … 438 438 439 439 $head4 = substr($headerstring, 0, 4); 440 440 $head4_key = getid3_lib::PrintHexBytes($head4, true, false, false); 441 441 static $MPEGaudioHeaderDecodeCache = array(); 442 if (isset($MPEGaudioHeaderDecodeCache[$head4 ])) {443 $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4 ];442 if (isset($MPEGaudioHeaderDecodeCache[$head4_key])) { 443 $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4_key]; 444 444 } else { 445 445 $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4); 446 $MPEGaudioHeaderDecodeCache[$head4 ] = $MPEGheaderRawArray;446 $MPEGaudioHeaderDecodeCache[$head4_key] = $MPEGheaderRawArray; 447 447 } 448 448 449 449 static $MPEGaudioHeaderValidCache = array(); 450 if (!isset($MPEGaudioHeaderValidCache[$head4 ])) { // Not in cache451 //$MPEGaudioHeaderValidCache[$head4 ] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)452 $MPEGaudioHeaderValidCache[$head4 ] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);450 if (!isset($MPEGaudioHeaderValidCache[$head4_key])) { // Not in cache 451 //$MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1) 452 $MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false); 453 453 } 454 454 … … 460 460 461 461 462 if ($MPEGaudioHeaderValidCache[$head4 ]) {462 if ($MPEGaudioHeaderValidCache[$head4_key]) { 463 463 $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray; 464 464 } else { 465 $ info['error'][] = 'Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset;465 $this->error('Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset); 466 466 return false; 467 467 } … … 491 491 if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) { 492 492 // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 493 $ info['warning'][] = 'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';493 $this->warning('Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'); 494 494 $thisfile_mpeg_audio['raw']['bitrate'] = 0; 495 495 } … … 513 513 // these are ok 514 514 } else { 515 $ info['error'][] = $thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';515 $this->error($thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); 516 516 return false; 517 517 } … … 524 524 // these are ok 525 525 } else { 526 $ info['error'][] = intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';526 $this->error(intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); 527 527 return false; 528 528 } … … 546 546 $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength']; 547 547 } else { 548 $ info['error'][] = 'Frame at offset('.$offset.') is has an invalid frame length.';548 $this->error('Frame at offset('.$offset.') is has an invalid frame length.'); 549 549 return false; 550 550 } … … 649 649 650 650 //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { 651 if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { 652 653 $framelengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']; 651 //if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { 652 if (!empty($thisfile_mpeg_audio['VBR_frames'])) { 653 $used_filesize = 0; 654 if (!empty($thisfile_mpeg_audio['VBR_bytes'])) { 655 $used_filesize = $thisfile_mpeg_audio['VBR_bytes']; 656 } elseif (!empty($info['filesize'])) { 657 $used_filesize = $info['filesize']; 658 $used_filesize -= intval(@$info['id3v2']['headerlength']); 659 $used_filesize -= (isset($info['id3v1']) ? 128 : 0); 660 $used_filesize -= (isset($info['tag_offset_end']) ? $info['tag_offset_end'] - $info['tag_offset_start'] : 0); 661 $this->warning('MP3.Xing header missing VBR_bytes, assuming MPEG audio portion of file is '.number_format($used_filesize).' bytes'); 662 } 663 664 $framelengthfloat = $used_filesize / $thisfile_mpeg_audio['VBR_frames']; 654 665 655 666 if ($thisfile_mpeg_audio['layer'] == '1') { … … 838 849 $thisfile_mpeg_audio_lame['preset_used'] = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame); 839 850 if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) { 840 $ info['warning'][] = 'Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org';851 $this->warning('Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org'); 841 852 } 842 853 if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) { … … 882 893 } 883 894 if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') { 884 $ info['warning'][] = 'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.';895 $this->warning('VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'); 885 896 } 886 897 } … … 909 920 // if ($PossibleNullByte === "\x00") { 910 921 $info['avdataend']--; 911 // $ info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';922 // $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); 912 923 // } else { 913 // $ info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';924 // $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); 914 925 // } 915 926 } else { 916 $ info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';927 $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); 917 928 } 918 929 } … … 932 943 } 933 944 } else { 934 $ info['error'][] = 'Error calculating frame length of free-format MP3 without Xing/LAME header';945 $this->error('Error calculating frame length of free-format MP3 without Xing/LAME header'); 935 946 } 936 947 } … … 949 960 $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / $bytes_per_frame) : 0); 950 961 if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) { 951 $info['audio']['bitrate'] 962 $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; 952 963 $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion 953 964 } … … 1075 1086 public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR) { 1076 1087 $info = &$this->getid3->info; 1077 $firstframetestarray = array('error' =>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);1088 $firstframetestarray = array('error' => array(), 'warning'=> array(), 'avdataend' => $info['avdataend'], 'avdataoffset' => $info['avdataoffset']); 1078 1089 $this->decodeMPEGaudioHeader($offset, $firstframetestarray, false); 1079 1090 … … 1085 1096 } 1086 1097 1087 $nextframetestarray = array('error' =>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);1098 $nextframetestarray = array('error' => array(), 'warning' => array(), 'avdataend' => $info['avdataend'], 'avdataoffset'=>$info['avdataoffset']); 1088 1099 if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) { 1089 1100 if ($ScanAsCBR) { … … 1099 1110 $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength']; 1100 1111 } else { 1101 $ info['error'][] = 'Frame at offset ('.$offset.') is has an invalid frame length.';1112 $this->error('Frame at offset ('.$offset.') is has an invalid frame length.'); 1102 1113 return false; 1103 1114 } … … 1111 1122 1112 1123 // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence 1113 $ info['warning'][] = 'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.';1124 $this->warning('Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'); 1114 1125 1115 1126 return false; … … 1154 1165 } 1155 1166 if (!$framelength) { 1156 $ info['error'][] = 'Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset;1167 $this->error('Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset); 1157 1168 return false; 1158 1169 } else { 1159 $ info['warning'][] = 'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)';1170 $this->warning('ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'); 1160 1171 $info['audio']['codec'] = 'LAME'; 1161 1172 $info['audio']['encoder'] = 'LAME3.88'; … … 1184 1195 $nextoffset++; 1185 1196 } else { 1186 $ info['error'][] = 'Did not find expected free-format sync pattern at offset '.$nextoffset;1197 $this->error('Did not find expected free-format sync pattern at offset '.$nextoffset); 1187 1198 return false; 1188 1199 } … … 1282 1293 if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) { 1283 1294 $pct_data_scanned = ($this->ftell() - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']); 1284 $ info['warning'][] = 'too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';1295 $this->warning('too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); 1285 1296 foreach ($Distribution as $key1 => $value1) { 1286 1297 foreach ($value1 as $key2 => $value2) { … … 1309 1320 $info['mpeg']['audio']['padding_distribution'] = $Distribution['padding']; 1310 1321 if (count($Distribution['version']) > 1) { 1311 $ info['error'][] = 'Corrupt file - more than one MPEG version detected';1322 $this->error('Corrupt file - more than one MPEG version detected'); 1312 1323 } 1313 1324 if (count($Distribution['layer']) > 1) { 1314 $ info['error'][] = 'Corrupt file - more than one MPEG layer detected';1325 $this->error('Corrupt file - more than one MPEG layer detected'); 1315 1326 } 1316 1327 if (count($Distribution['frequency']) > 1) { 1317 $ info['error'][] = 'Corrupt file - more than one MPEG sample rate detected';1328 $this->error('Corrupt file - more than one MPEG sample rate detected'); 1318 1329 } 1319 1330 … … 1327 1338 $info['mpeg']['audio']['frame_count'] = array_sum($Distribution['bitrate']); 1328 1339 if ($info['mpeg']['audio']['frame_count'] == 0) { 1329 $ info['error'][] = 'no MPEG audio frames found';1340 $this->error('no MPEG audio frames found'); 1330 1341 return false; 1331 1342 } … … 1362 1373 $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset); 1363 1374 if ($sync_seek_buffer_size <= 0) { 1364 $ info['error'][] = 'Invalid $sync_seek_buffer_size at offset '.$avdataoffset;1375 $this->error('Invalid $sync_seek_buffer_size at offset '.$avdataoffset); 1365 1376 return false; 1366 1377 } … … 1373 1384 if ($SynchSeekOffset > $sync_seek_buffer_size) { 1374 1385 // if a synch's not found within the first 128k bytes, then give up 1375 $ info['error'][] = 'Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB';1386 $this->error('Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB'); 1376 1387 if (isset($info['audio']['bitrate'])) { 1377 1388 unset($info['audio']['bitrate']); … … 1387 1398 } elseif (feof($this->getid3->fp)) { 1388 1399 1389 $ info['error'][] = 'Could not find valid MPEG audio synch before end of file';1400 $this->error('Could not find valid MPEG audio synch before end of file'); 1390 1401 if (isset($info['audio']['bitrate'])) { 1391 1402 unset($info['audio']['bitrate']); … … 1402 1413 1403 1414 if (($SynchSeekOffset + 1) >= strlen($header)) { 1404 $ info['error'][] = 'Could not find valid MPEG synch before end of file';1415 $this->error('Could not find valid MPEG synch before end of file'); 1405 1416 return false; 1406 1417 } … … 1445 1456 $info = $dummy; 1446 1457 $info['avdataoffset'] = $GarbageOffsetEnd; 1447 $ info['warning'][] = 'apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd;1458 $this->warning('apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd); 1448 1459 } else { 1449 $ info['warning'][] = 'using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')';1460 $this->warning('using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'); 1450 1461 } 1451 1462 } … … 1540 1551 } 1541 1552 if ($pct_data_scanned > 0) { 1542 $ info['warning'][] = 'too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';1553 $this->warning('too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); 1543 1554 foreach ($info['mpeg']['audio'] as $key1 => $value1) { 1544 1555 if (!preg_match('#_distribution$#i', $key1)) { … … 1552 1563 1553 1564 if ($SynchErrorsFound > 0) { 1554 $ info['warning'][] = 'Found '.$SynchErrorsFound.' synch errors in histogram analysis';1565 $this->warning('Found '.$SynchErrorsFound.' synch errors in histogram analysis'); 1555 1566 //return false; 1556 1567 } … … 1565 1576 } 1566 1577 if ($framecounter == 0) { 1567 $ info['error'][] = 'Corrupt MP3 file: framecounter == zero';1578 $this->error('Corrupt MP3 file: framecounter == zero'); 1568 1579 return false; 1569 1580 } … … 1600 1611 if (empty($info['mpeg']['audio'])) { 1601 1612 1602 $ info['error'][] = 'could not find valid MPEG synch before end of file';1613 $this->error('could not find valid MPEG synch before end of file'); 1603 1614 if (isset($info['audio']['bitrate'])) { 1604 1615 unset($info['audio']['bitrate']);
Note: See TracChangeset
for help on using the changeset viewer.