wppaste
WordPress

getid3_riff::ParseRIFF( int $startoffset, int $maxoffset ): array|false

Source
wp-includes/ID3/module.audio-video.riff.php:1582

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3), 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
Moderate

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
1460

Executed per call on PHP 8.5. The body compiles to 1460.

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.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1460146076
8.51460146076
8.41460146076241 fewer instructions than PHP 8.3
8.31701170176
8.217011701762 more instructions than PHP 8.1
8.116993276
7.416993276

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

Show all 14

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) && ($chunkname != 'JUNK')) {					$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) {										// AC3										$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_ac3 = new getid3_ac3($getid3_temp);										$getid3_ac3->Analyze();										if (empty($getid3_temp->info['error'])) {											$info['audio']   = $getid3_temp->info['audio'];											$info['ac3']     = $getid3_temp->info['ac3'];

Changelog

Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

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

About this page

Parsed data
Generated from the wordpress-develop 6.8.11 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.