getid3_riff::ParseRIFF( int $startoffset, int $maxoffset ): array|false
- Source
wp-includes/ID3/module.audio-video.riff.php:1592
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
$startoffsetint$maxoffsetint
Return value
array|false
Performance profile
How much work a call to getid3_riff::ParseRIFF() 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
- 64
- Plugin surface
- None
- Called by
- 2
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. The body compiles to 1481.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost getid3_riff::ParseRIFF() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$maxoffset && $chunksize == 0 && $chunkname != "JUNK" && $chunkname != "data" | 64 | pack(), ->fseek(), ->ftell(), ->fread(), ->EitherEndian2Int(), ->ftell(), ->warning() |
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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 1481 | 64 | 78 | |
| 8.5 | 1481 | 64 | 78 | |
| 8.4 | 1481 | 64 | 78 | 241 fewer instructions than PHP 8.3 |
| 8.3 | 1722 | 76 | 78 | |
| 8.2 | 1722 | 76 | 78 | 2 more instructions than PHP 8.1 |
| 8.1 | 1720 | 32–76 | 78 | |
| 7.4 | 1720 | 32–76 | 78 |
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 · 14
- getid3_riff::fseek()
- getid3_riff::ftell()
- getid3_riff::fread()
- getid3_riff::EitherEndian2Int()
- getid3_riff::error()
- getid3_riff::warning()
- getid3_lib::LittleEndian2Int()
- getid3_mp3::MPEGaudioHeaderBytesValid()
- getID3::__construct()
- getid3_mp3::__construct()
- getid3_ac3::__construct()
- getid3_riff::ParseRIFF()
Show all 14
- getid3_dts::__construct()
- getid3_riff::parseWavPackHeader()
Used by · 2
Source code
public function ParseRIFF($startoffset, $maxoffset) { $info = &$this->getid3->info; $RIFFchunk = array(); $FoundAllChunksWeNeed = false; $LISTchunkParent = null; $LISTchunkMaxOffset = null; $AC3syncwordBytes = pack('n', getid3_ac3::syncword); // 0x0B77 -> "\x0B\x77" try { $this->fseek($startoffset); $maxoffset = min($maxoffset, $info['avdataend']); while ($this->ftell() < $maxoffset) { $chunknamesize = $this->fread(8); //$chunkname = substr($chunknamesize, 0, 4); $chunkname = str_replace("\x00", '_', substr($chunknamesize, 0, 4)); // note: chunk names of 4 null bytes do appear to be legal (has been observed inside INFO and PRMI chunks, for example), but makes traversing array keys more difficult $chunksize = $this->EitherEndian2Int(substr($chunknamesize, 4, 4)); //if (strlen(trim($chunkname, "\x00")) < 4) { if (strlen($chunkname) < 4) { $this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.'); break; } if ($chunksize == 0) { if ($chunkname == 'JUNK') { // this is allowed } elseif ($chunkname == 'data') { // https://github.com/JamesHeinrich/getID3/issues/468 // may occur in streaming files where the data size is unknown $chunksize = $info['avdataend'] - $this->ftell(); $this->warning('RIFF.data size field is empty, assuming the correct value is filesize-offset ('.$chunksize.')'); } else { $this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.'); break; } } if (($chunksize % 2) != 0) { // all structures are packed on word boundaries $chunksize++; } switch ($chunkname) { case 'LIST': $listname = $this->fread(4); if (preg_match('#^(movi|rec )$#i', $listname)) { $RIFFchunk[$listname]['offset'] = $this->ftell() - 4; $RIFFchunk[$listname]['size'] = $chunksize; if (!$FoundAllChunksWeNeed) { $WhereWeWere = $this->ftell(); $AudioChunkHeader = $this->fread(12); $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2); $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2); $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4)); if ($AudioChunkStreamType == 'wb') { $FirstFourBytes = substr($AudioChunkHeader, 8, 4); if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) { // MP3 if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) { $getid3_temp = new getID3(); $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__); $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); if (isset($getid3_temp->info['mpeg']['audio'])) { $info['mpeg']['audio'] = $getid3_temp->info['mpeg']['audio']; $info['audio'] = $getid3_temp->info['audio']; $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; $info['audio']['channels'] = $info['mpeg']['audio']['channels']; $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); //$info['bitrate'] = $info['audio']['bitrate']; } unset($getid3_temp, $getid3_mp3); } } elseif (strpos($FirstFourBytes, $AC3syncwordBytes) === 0) { // AC3Changelog
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-video.riff.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.