getid3_riff::ParseRIFF() –

You appear to be a bot. Output may be restricted

Description

Usage

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

Parameters

$startoffset
( int ) required
$maxoffset
( int ) required

Returns

array|false

Source

File name: wordpress/wp-includes/ID3/module.audio-video.riff.php


Lines:

1 to 100 of 361
  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->getid3_riff::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->getid3_riff::Analyze();
                    if (empty($getid3_temp->info['error'])) {
                      $info['audio']   = $getid3_temp->info['audio'];
                      $info['ac3']     = $getid3_temp->info['ac3'];
                      if (!empty($getid3_temp->info['warning'])) {
                        foreach ($getid3_temp->info['warning'] as $key => $value) {
                          $this->warning($value);
                        }
                      }
                    }
                    unset($getid3_temp, $getid3_ac3);
                  }
                }
                $FoundAllChunksWeNeed = true;
                $this->fseek($WhereWeWere);
              }
              $this->fseek($chunksize - 4, SEEK_CUR);

            } else {

              if (!isset($RIFFchunk[$listname])) {
                $RIFFchunk[$listname] = array();
              }
              $LISTchunkParent    = $listname;

 View on GitHub View on Trac