getid3_mp3::FreeFormatFrameLength( int $offset, bool $deepscan = false ): int|false
- Source
wp-includes/ID3/module.audio.mp3.php:1220
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$deepscanbooloptional- Default:
false
Return value
int|false
Performance profile
How much work a call to getid3_mp3::FreeFormatFrameLength() 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
- Light
- Scaling
- Scales with input
- Instructions
- 42–142
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 184.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 14 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost getid3_mp3::FreeFormatFrameLength() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$SyncPattern2 !== false && $framelength2 | 42–56 | ->fseek(), ->fread(), ord(), chr() |
$SyncPattern2 === false && $framelength2 | 57–71 | ->fseek(), ->fread(), ord(), chr(), ord(), chr() |
$SyncPattern2 !== false && $framelength2 && !$nextoffset | 61–65 | ->fseek(), ->fread(), ord(), chr(), array_sum(), round() |
$SyncPattern2 !== false && !$framelength2 | 68–76 | ->fseek(), ->fread(), ord(), chr(), ::getid3_lib(), ::getid3_lib(), ->error() |
$SyncPattern2 !== false | 70–88 | ->fseek(), ->fread(), ord(), chr(), ->warning() |
$SyncPattern2 === false && $framelength2 && !$nextoffset | 76–80 | ->fseek(), ->fread(), ord(), chr(), ord(), chr(), array_sum(), round() |
$SyncPattern2 === false && !$framelength2 | 83–91 | ->fseek(), ->fread(), ord(), chr(), ord(), chr(), ::getid3_lib(), ::getid3_lib(), ->error() |
$SyncPattern2 === false | 85–103 | ->fseek(), ->fread(), ord(), chr(), ord(), chr(), ->warning() |
$SyncPattern2 !== false && !$nextoffset | 89–97 | ->fseek(), ->fread(), ord(), chr(), ->warning(), array_sum(), round() |
$SyncPattern2 !== false && $framelength2 && $nextoffset && $SyncPattern1 != false && $SyncPattern2 != false | 91–95 | ->fseek(), ->fread(), ord(), chr(), ->fseek(), ->fread(), ->error() |
$SyncPattern2 === false && !$nextoffset | 104–112 | ->fseek(), ->fread(), ord(), chr(), ord(), chr(), ->warning(), array_sum(), round() |
$SyncPattern2 === false && $framelength2 && $nextoffset && $SyncPattern1 != false && $SyncPattern2 != false | 106–110 | ->fseek(), ->fread(), ord(), chr(), ord(), chr(), ->fseek(), ->fread(), ->error() |
2 further outcomes, up to 142 instructions
$SyncPattern2 !== false && $nextoffset && $SyncPattern1 != false && $SyncPattern2 != false | 119–127 | ->fseek(), ->fread(), ord(), chr(), ->warning(), ->fseek(), ->fread(), ->error() |
$SyncPattern2 === false && $nextoffset && $SyncPattern1 != false && $SyncPattern2 != false | 134–142 | ->fseek(), ->fread(), ord(), chr(), ord(), chr(), ->warning(), ->fseek(), ->fread(), ->error() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 184 | 42–142 | 18 | |
| 8.5 | 184 | 42–142 | 18 | |
| 8.4 | 184 | 42–142 | 18 | 46 fewer instructions than PHP 8.3 |
| 8.3 | 230 | 52–188 | 18 | |
| 8.2 | 230 | 52–188 | 18 | |
| 8.1 | 230 | 52–188 | 18 | |
| 7.4 | 230 | 52–188 | 18 |
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 · 5
- getid3_mp3::fseek()
- getid3_mp3::fread()
- getid3_mp3::error()
- getid3_lib::PrintHexBytes()
- getid3_mp3::warning()
Used by · 1
Source code
public function FreeFormatFrameLength($offset, $deepscan=false) { $info = &$this->getid3->info; $this->fseek($offset); $MPEGaudioData = $this->fread(32768); $SyncPattern1 = substr($MPEGaudioData, 0, 4); // may be different pattern due to padding $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) | 0x02).$SyncPattern1[3]; if ($SyncPattern2 === $SyncPattern1) { $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) & 0xFD).$SyncPattern1[3]; } $framelength = false; $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4); $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4); if ($framelength1 > 4) { $framelength = $framelength1; } if (($framelength2 > 4) && ($framelength2 < $framelength1)) { $framelength = $framelength2; } if (!$framelength) { // LAME 3.88 has a different value for modeextension on the first frame vs the rest $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4); $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4); if ($framelength1 > 4) { $framelength = $framelength1; } if (($framelength2 > 4) && ($framelength2 < $framelength1)) { $framelength = $framelength2; } if (!$framelength) { $this->error('Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset); return false; } else { $this->warning('ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'); $info['audio']['codec'] = 'LAME'; $info['audio']['encoder'] = 'LAME3.88'; $SyncPattern1 = substr($SyncPattern1, 0, 3); $SyncPattern2 = substr($SyncPattern2, 0, 3); } } if ($deepscan) { $ActualFrameLengthValues = array(); $nextoffset = $offset + $framelength; while ($nextoffset < ($info['avdataend'] - 6)) { $this->fseek($nextoffset - 1); $NextSyncPattern = $this->fread(6); if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) { // good - found where expected $ActualFrameLengthValues[] = $framelength; } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) { // ok - found one byte earlier than expected (last frame wasn't padded, first frame was) $ActualFrameLengthValues[] = ($framelength - 1); $nextoffset--; } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) { // ok - found one byte later than expected (last frame was padded, first frame wasn't) $ActualFrameLengthValues[] = ($framelength + 1); $nextoffset++; } else { $this->error('Did not find expected free-format sync pattern at offset '.$nextoffset); return false; } $nextoffset += $framelength; } if (count($ActualFrameLengthValues) > 0) { $framelength = intval(round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues))); } } return $framelength; }Changelog
Unchanged from 6.7.7 through 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.