wppaste
WordPress

getid3_mp3::decodeMPEGaudioHeader( int $offset, array $info, bool $recursivesearch = true, bool $ScanAsCBR = false, bool $FastMPEGheaderScan = false ): bool

Source
wp-includes/ID3/module.audio.mp3.php:453

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$offsetint
$infoarray
$recursivesearchbooloptional
Default: true
$ScanAsCBRbooloptional
Default: false
$FastMPEGheaderScanbooloptional
Default: false

Return value

bool

Performance profile

How much work a call to getid3_mp3::decodeMPEGaudioHeader() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
62–265

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 1411.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 5 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost getid3_mp3::decodeMPEGaudioHeader() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!empty($MPEGaudioVersionLookup) && !isset($MPEGaudioHeaderDecodeCache[$head4_key]) && isset($MPEGaudioHeaderValidCache[$head4_key]) && isset($value) && !$MPEGaudioHeaderValidCache62->fseek(), ->fread(), ::getid3_lib(), ::MPEGaudioHeaderDecode(), ::getid3_lib(), ->warning()
!empty($MPEGaudioVersionLookup) && !isset($MPEGaudioHeaderDecodeCache[$head4_key]) && isset($MPEGaudioHeaderValidCache[$head4_key]) && isset($value) && $MPEGaudioHeaderValidCache && empty($thisfile_mpeg_audio) && !$ExpectedNumberOfAudioBytes && !isset($thisfile_mpeg_audio)174–214->fseek(), ->fread(), ::getid3_lib(), ::MPEGaudioHeaderDecode(), ::XingVBRidOffset(), ::getid3_lib()
!empty($MPEGaudioVersionLookup) && !isset($MPEGaudioHeaderDecodeCache[$head4_key]) && isset($MPEGaudioHeaderValidCache[$head4_key]) && isset($value) && $MPEGaudioHeaderValidCache && empty($thisfile_mpeg_audio) && !$ExpectedNumberOfAudioBytes && !isset($thisfile_mpeg_audio)180–238->fseek(), ->fread(), ::getid3_lib(), ::MPEGaudioHeaderDecode(), ::XingVBRidOffset(), ::getid3_lib(), ->RecursiveFrameScanning()
!empty($MPEGaudioVersionLookup) && !isset($MPEGaudioHeaderDecodeCache[$head4_key]) && isset($MPEGaudioHeaderValidCache[$head4_key]) && isset($value) && $MPEGaudioHeaderValidCache && !$ExpectedNumberOfAudioBytes && !isset($thisfile_mpeg_audio) && ->RecursiveFrameScanning() && !empty($value)204–247->fseek(), ->fread(), ::getid3_lib(), ::MPEGaudioHeaderDecode(), ::XingVBRidOffset(), ::getid3_lib(), ->RecursiveFrameScanning(), array_keys()
!empty($MPEGaudioVersionLookup) && !isset($MPEGaudioHeaderDecodeCache[$head4_key]) && isset($MPEGaudioHeaderValidCache[$head4_key]) && isset($value) && $MPEGaudioHeaderValidCache && !$ExpectedNumberOfAudioBytes && !isset($thisfile_mpeg_audio) && ->RecursiveFrameScanning() && !empty($value)220–265->fseek(), ->fread(), ::getid3_lib(), ::MPEGaudioHeaderDecode(), ::XingVBRidOffset(), ::getid3_lib(), ->RecursiveFrameScanning(), array_keys(), array_keys(), abs()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev141162–265103
8.5141162–265103
8.4141162–265103129 fewer instructions than PHP 8.3
8.3154066–283103
8.2154066–2831032 more instructions than PHP 8.1
8.1153866–2831036 fewer instructions than PHP 7.4
7.4154466–284103

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 31

Show all 31

Used by · 2

Source code

	public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) {		static $MPEGaudioVersionLookup;		static $MPEGaudioLayerLookup;		static $MPEGaudioBitrateLookup;		static $MPEGaudioFrequencyLookup;		static $MPEGaudioChannelModeLookup;		static $MPEGaudioModeExtensionLookup;		static $MPEGaudioEmphasisLookup;		if (empty($MPEGaudioVersionLookup)) {			$MPEGaudioVersionLookup       = self::MPEGaudioVersionArray();			$MPEGaudioLayerLookup         = self::MPEGaudioLayerArray();			$MPEGaudioBitrateLookup       = self::MPEGaudioBitrateArray();			$MPEGaudioFrequencyLookup     = self::MPEGaudioFrequencyArray();			$MPEGaudioChannelModeLookup   = self::MPEGaudioChannelModeArray();			$MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();			$MPEGaudioEmphasisLookup      = self::MPEGaudioEmphasisArray();		} 		if ($this->fseek($offset) != 0) {			$this->error('decodeMPEGaudioHeader() failed to seek to next offset at '.$offset);			return false;		}		//$headerstring = $this->fread(1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame		$headerstring = $this->fread(226); // LAME header at offset 36 + 190 bytes of Xing/LAME data 		// MP3 audio frame structure:		// $aa $aa $aa $aa [$bb $bb] $cc...		// where $aa..$aa is the four-byte mpeg-audio header (below)		// $bb $bb is the optional 2-byte CRC		// and $cc... is the audio data 		$head4 = substr($headerstring, 0, 4);		$head4_key = getid3_lib::PrintHexBytes($head4, true, false, false);		static $MPEGaudioHeaderDecodeCache = array();		if (isset($MPEGaudioHeaderDecodeCache[$head4_key])) {			$MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4_key];		} else {			$MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4);			$MPEGaudioHeaderDecodeCache[$head4_key] = $MPEGheaderRawArray;		} 		static $MPEGaudioHeaderValidCache = array();		if (!isset($MPEGaudioHeaderValidCache[$head4_key])) { // Not in cache			//$MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true);  // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)			$MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);		} 		// shortcut		if (!isset($info['mpeg']['audio'])) {			$info['mpeg']['audio'] = array();		}		$thisfile_mpeg_audio = &$info['mpeg']['audio']; 		if ($MPEGaudioHeaderValidCache[$head4_key]) {			$thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray;		} else {			$this->warning('Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset);			return false;		} 		if (!$FastMPEGheaderScan) {			$thisfile_mpeg_audio['version']       = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']];			$thisfile_mpeg_audio['layer']         = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']]; 			$thisfile_mpeg_audio['channelmode']   = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio['raw']['channelmode']];			$thisfile_mpeg_audio['channels']      = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2);			$thisfile_mpeg_audio['sample_rate']   = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']];			$thisfile_mpeg_audio['protection']    = !$thisfile_mpeg_audio['raw']['protection'];			$thisfile_mpeg_audio['private']       = (bool) $thisfile_mpeg_audio['raw']['private'];			$thisfile_mpeg_audio['modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']];			$thisfile_mpeg_audio['copyright']     = (bool) $thisfile_mpeg_audio['raw']['copyright'];			$thisfile_mpeg_audio['original']      = (bool) $thisfile_mpeg_audio['raw']['original'];			$thisfile_mpeg_audio['emphasis']      = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']]; 			$info['audio']['channels']    = $thisfile_mpeg_audio['channels'];			$info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate']; 			if ($thisfile_mpeg_audio['protection']) {				$thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($headerstring, 4, 2));			}

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/ID3/module.audio.mp3.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.