home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-includes / ID3 / module.audio-video.riff.php < prev    next >
Encoding:
PHP Script  |  2017-07-31  |  119.8 KB  |  2,639 lines

  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org>               //
  4. //  available at http://getid3.sourceforge.net                 //
  5. //            or http://www.getid3.org                         //
  6. //          also https://github.com/JamesHeinrich/getID3       //
  7. /////////////////////////////////////////////////////////////////
  8. // See readme.txt for more details                             //
  9. /////////////////////////////////////////////////////////////////
  10. //                                                             //
  11. // module.audio-video.riff.php                                 //
  12. // module for analyzing RIFF files                             //
  13. // multiple formats supported by this module:                  //
  14. //    Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX   //
  15. // dependencies: module.audio.mp3.php                          //
  16. //               module.audio.ac3.php                          //
  17. //               module.audio.dts.php                          //
  18. //                                                            ///
  19. /////////////////////////////////////////////////////////////////
  20.  
  21. /**
  22. * @todo Parse AC-3/DTS audio inside WAVE correctly
  23. * @todo Rewrite RIFF parser totally
  24. */
  25.  
  26. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
  27. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true);
  28. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, true);
  29.  
  30. class getid3_riff extends getid3_handler {
  31.  
  32.     protected $container = 'riff'; // default
  33.  
  34.     public function Analyze() {
  35.         $info = &$this->getid3->info;
  36.  
  37.         // initialize these values to an empty array, otherwise they default to NULL
  38.         // and you can't append array values to a NULL value
  39.         $info['riff'] = array('raw'=>array());
  40.  
  41.         // Shortcuts
  42.         $thisfile_riff             = &$info['riff'];
  43.         $thisfile_riff_raw         = &$thisfile_riff['raw'];
  44.         $thisfile_audio            = &$info['audio'];
  45.         $thisfile_video            = &$info['video'];
  46.         $thisfile_audio_dataformat = &$thisfile_audio['dataformat'];
  47.         $thisfile_riff_audio       = &$thisfile_riff['audio'];
  48.         $thisfile_riff_video       = &$thisfile_riff['video'];
  49.  
  50.         $Original['avdataoffset'] = $info['avdataoffset'];
  51.         $Original['avdataend']    = $info['avdataend'];
  52.  
  53.         $this->fseek($info['avdataoffset']);
  54.         $RIFFheader = $this->fread(12);
  55.         $offset = $this->ftell();
  56.         $RIFFtype    = substr($RIFFheader, 0, 4);
  57.         $RIFFsize    = substr($RIFFheader, 4, 4);
  58.         $RIFFsubtype = substr($RIFFheader, 8, 4);
  59.  
  60.         switch ($RIFFtype) {
  61.  
  62.             case 'FORM':  // AIFF, AIFC
  63.                 //$info['fileformat']   = 'aiff';
  64.                 $this->container = 'aiff';
  65.                 $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
  66.                 $thisfile_riff[$RIFFsubtype]  = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
  67.                 break;
  68.  
  69.             case 'RIFF':  // AVI, WAV, etc
  70.             case 'SDSS':  // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
  71.             case 'RMP3':  // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
  72.                 //$info['fileformat']   = 'riff';
  73.                 $this->container = 'riff';
  74.                 $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
  75.                 if ($RIFFsubtype == 'RMP3') {
  76.                     // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
  77.                     $RIFFsubtype = 'WAVE';
  78.                 }
  79.                 if ($RIFFsubtype != 'AMV ') {
  80.                     // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
  81.                     // Handled separately in ParseRIFFAMV()
  82.                     $thisfile_riff[$RIFFsubtype]  = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
  83.                 }
  84.                 if (($info['avdataend'] - $info['filesize']) == 1) {
  85.                     // LiteWave appears to incorrectly *not* pad actual output file
  86.                     // to nearest WORD boundary so may appear to be short by one
  87.                     // byte, in which case - skip warning
  88.                     $info['avdataend'] = $info['filesize'];
  89.                 }
  90.  
  91.                 $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset
  92.                 while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) {
  93.                     try {
  94.                         $this->fseek($nextRIFFoffset);
  95.                     } catch (getid3_exception $e) {
  96.                         if ($e->getCode() == 10) {
  97.                             //$this->warning('RIFF parser: '.$e->getMessage());
  98.                             $this->error('AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime may be wrong');
  99.                             $this->warning('[avdataend] value may be incorrect, multiple AVIX chunks may be present');
  100.                             break;
  101.                         } else {
  102.                             throw $e;
  103.                         }
  104.                     }
  105.                     $nextRIFFheader = $this->fread(12);
  106.                     if ($nextRIFFoffset == ($info['avdataend'] - 1)) {
  107.                         if (substr($nextRIFFheader, 0, 1) == "\x00") {
  108.                             // RIFF padded to WORD boundary, we're actually already at the end
  109.                             break;
  110.                         }
  111.                     }
  112.                     $nextRIFFheaderID =                         substr($nextRIFFheader, 0, 4);
  113.                     $nextRIFFsize     = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4));
  114.                     $nextRIFFtype     =                         substr($nextRIFFheader, 8, 4);
  115.                     $chunkdata = array();
  116.                     $chunkdata['offset'] = $nextRIFFoffset + 8;
  117.                     $chunkdata['size']   = $nextRIFFsize;
  118.                     $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size'];
  119.  
  120.                     switch ($nextRIFFheaderID) {
  121.                         case 'RIFF':
  122.                             $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset);
  123.                             if (!isset($thisfile_riff[$nextRIFFtype])) {
  124.                                 $thisfile_riff[$nextRIFFtype] = array();
  125.                             }
  126.                             $thisfile_riff[$nextRIFFtype][] = $chunkdata;
  127.                             break;
  128.  
  129.                         case 'AMV ':
  130.                             unset($info['riff']);
  131.                             $info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset);
  132.                             break;
  133.  
  134.                         case 'JUNK':
  135.                             // ignore
  136.                             $thisfile_riff[$nextRIFFheaderID][] = $chunkdata;
  137.                             break;
  138.  
  139.                         case 'IDVX':
  140.                             $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunkdata['size']));
  141.                             break;
  142.  
  143.                         default:
  144.                             if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) {
  145.                                 $DIVXTAG = $nextRIFFheader.$this->fread(128 - 12);
  146.                                 if (substr($DIVXTAG, -7) == 'DIVXTAG') {
  147.                                     // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file
  148.                                     $this->warning('Found wrongly-structured DIVXTAG at offset '.($this->ftell() - 128).', parsing anyway');
  149.                                     $info['divxtag']['comments'] = self::ParseDIVXTAG($DIVXTAG);
  150.                                     break 2;
  151.                                 }
  152.                             }
  153.                             $this->warning('Expecting "RIFF|JUNK|IDVX" at '.$nextRIFFoffset.', found "'.$nextRIFFheaderID.'" ('.getid3_lib::PrintHexBytes($nextRIFFheaderID).') - skipping rest of file');
  154.                             break 2;
  155.  
  156.                     }
  157.  
  158.                 }
  159.                 if ($RIFFsubtype == 'WAVE') {
  160.                     $thisfile_riff_WAVE = &$thisfile_riff['WAVE'];
  161.                 }
  162.                 break;
  163.  
  164.             default:
  165.                 $this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead');
  166.                 //unset($info['fileformat']);
  167.                 return false;
  168.         }
  169.  
  170.         $streamindex = 0;
  171.         switch ($RIFFsubtype) {
  172.  
  173.             // http://en.wikipedia.org/wiki/Wav
  174.             case 'WAVE':
  175.                 $info['fileformat'] = 'wav';
  176.  
  177.                 if (empty($thisfile_audio['bitrate_mode'])) {
  178.                     $thisfile_audio['bitrate_mode'] = 'cbr';
  179.                 }
  180.                 if (empty($thisfile_audio_dataformat)) {
  181.                     $thisfile_audio_dataformat = 'wav';
  182.                 }
  183.  
  184.                 if (isset($thisfile_riff_WAVE['data'][0]['offset'])) {
  185.                     $info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8;
  186.                     $info['avdataend']    = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size'];
  187.                 }
  188.                 if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) {
  189.  
  190.                     $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']);
  191.                     $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
  192.                     if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) {
  193.                         $this->error('Corrupt RIFF file: bitrate_audio == zero');
  194.                         return false;
  195.                     }
  196.                     $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw'];
  197.                     unset($thisfile_riff_audio[$streamindex]['raw']);
  198.                     $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
  199.  
  200.                     $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
  201.                     if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
  202.                         $this->warning('Audio codec = '.$thisfile_audio['codec']);
  203.                     }
  204.                     $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
  205.  
  206.                     if (empty($info['playtime_seconds'])) { // may already be set (e.g. DTS-WAV)
  207.                         $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
  208.                     }
  209.  
  210.                     $thisfile_audio['lossless'] = false;
  211.                     if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
  212.                         switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
  213.  
  214.                             case 0x0001:  // PCM
  215.                                 $thisfile_audio['lossless'] = true;
  216.                                 break;
  217.  
  218.                             case 0x2000:  // AC-3
  219.                                 $thisfile_audio_dataformat = 'ac3';
  220.                                 break;
  221.  
  222.                             default:
  223.                                 // do nothing
  224.                                 break;
  225.  
  226.                         }
  227.                     }
  228.                     $thisfile_audio['streams'][$streamindex]['wformattag']   = $thisfile_audio['wformattag'];
  229.                     $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
  230.                     $thisfile_audio['streams'][$streamindex]['lossless']     = $thisfile_audio['lossless'];
  231.                     $thisfile_audio['streams'][$streamindex]['dataformat']   = $thisfile_audio_dataformat;
  232.                 }
  233.  
  234.                 if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) {
  235.  
  236.                     // shortcuts
  237.                     $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data'];
  238.                     $thisfile_riff_raw['rgad']    = array('track'=>array(), 'album'=>array());
  239.                     $thisfile_riff_raw_rgad       = &$thisfile_riff_raw['rgad'];
  240.                     $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track'];
  241.                     $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album'];
  242.  
  243.                     $thisfile_riff_raw_rgad['fPeakAmplitude']      = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4));
  244.                     $thisfile_riff_raw_rgad['nRadioRgAdjust']      =        $this->EitherEndian2Int(substr($rgadData, 4, 2));
  245.                     $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] =        $this->EitherEndian2Int(substr($rgadData, 6, 2));
  246.  
  247.                     $nRadioRgAdjustBitstring      = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
  248.                     $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
  249.                     $thisfile_riff_raw_rgad_track['name']       = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
  250.                     $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
  251.                     $thisfile_riff_raw_rgad_track['signbit']    = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
  252.                     $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
  253.                     $thisfile_riff_raw_rgad_album['name']       = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
  254.                     $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
  255.                     $thisfile_riff_raw_rgad_album['signbit']    = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
  256.                     $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
  257.  
  258.                     $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude'];
  259.                     if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) {
  260.                         $thisfile_riff['rgad']['track']['name']            = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']);
  261.                         $thisfile_riff['rgad']['track']['originator']      = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']);
  262.                         $thisfile_riff['rgad']['track']['adjustment']      = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']);
  263.                     }
  264.                     if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) {
  265.                         $thisfile_riff['rgad']['album']['name']       = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']);
  266.                         $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']);
  267.                         $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']);
  268.                     }
  269.                 }
  270.  
  271.                 if (isset($thisfile_riff_WAVE['fact'][0]['data'])) {
  272.                     $thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4));
  273.  
  274.                     // This should be a good way of calculating exact playtime,
  275.                     // but some sample files have had incorrect number of samples,
  276.                     // so cannot use this method
  277.  
  278.                     // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) {
  279.                     //     $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec'];
  280.                     // }
  281.                 }
  282.                 if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
  283.                     $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8);
  284.                 }
  285.  
  286.                 if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
  287.                     // shortcut
  288.                     $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
  289.  
  290.                     $thisfile_riff_WAVE_bext_0['title']          =                         trim(substr($thisfile_riff_WAVE_bext_0['data'],   0, 256));
  291.                     $thisfile_riff_WAVE_bext_0['author']         =                         trim(substr($thisfile_riff_WAVE_bext_0['data'], 256,  32));
  292.                     $thisfile_riff_WAVE_bext_0['reference']      =                         trim(substr($thisfile_riff_WAVE_bext_0['data'], 288,  32));
  293.                     $thisfile_riff_WAVE_bext_0['origin_date']    =                              substr($thisfile_riff_WAVE_bext_0['data'], 320,  10);
  294.                     $thisfile_riff_WAVE_bext_0['origin_time']    =                              substr($thisfile_riff_WAVE_bext_0['data'], 330,   8);
  295.                     $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338,   8));
  296.                     $thisfile_riff_WAVE_bext_0['bwf_version']    = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346,   1));
  297.                     $thisfile_riff_WAVE_bext_0['reserved']       =                              substr($thisfile_riff_WAVE_bext_0['data'], 347, 254);
  298.                     $thisfile_riff_WAVE_bext_0['coding_history'] =         explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601)));
  299.                     if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) {
  300.                         if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) {
  301.                             list($dummy, $bext_timestamp['year'], $bext_timestamp['month'],  $bext_timestamp['day'])    = $matches_bext_date;
  302.                             list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time;
  303.                             $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']);
  304.                         } else {
  305.                             $this->warning('RIFF.WAVE.BEXT.origin_time is invalid');
  306.                         }
  307.                     } else {
  308.                         $this->warning('RIFF.WAVE.BEXT.origin_date is invalid');
  309.                     }
  310.                     $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
  311.                     $thisfile_riff['comments']['title'][]  = $thisfile_riff_WAVE_bext_0['title'];
  312.                 }
  313.  
  314.                 if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) {
  315.                     // shortcut
  316.                     $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0];
  317.  
  318.                     $thisfile_riff_WAVE_MEXT_0['raw']['sound_information']      = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2));
  319.                     $thisfile_riff_WAVE_MEXT_0['flags']['homogenous']           = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001);
  320.                     if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) {
  321.                         $thisfile_riff_WAVE_MEXT_0['flags']['padding']          = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true;
  322.                         $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44']         =        (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004);
  323.                         $thisfile_riff_WAVE_MEXT_0['flags']['free_format']      =        (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008);
  324.  
  325.                         $thisfile_riff_WAVE_MEXT_0['nominal_frame_size']        = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2));
  326.                     }
  327.                     $thisfile_riff_WAVE_MEXT_0['anciliary_data_length']         = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2));
  328.                     $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def']     = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2));
  329.                     $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left']  = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001);
  330.                     $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free']  = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002);
  331.                     $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004);
  332.                 }
  333.  
  334.                 if (isset($thisfile_riff_WAVE['cart'][0]['data'])) {
  335.                     // shortcut
  336.                     $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0];
  337.  
  338.                     $thisfile_riff_WAVE_cart_0['version']              =                              substr($thisfile_riff_WAVE_cart_0['data'],   0,  4);
  339.                     $thisfile_riff_WAVE_cart_0['title']                =                         trim(substr($thisfile_riff_WAVE_cart_0['data'],   4, 64));
  340.                     $thisfile_riff_WAVE_cart_0['artist']               =                         trim(substr($thisfile_riff_WAVE_cart_0['data'],  68, 64));
  341.                     $thisfile_riff_WAVE_cart_0['cut_id']               =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64));
  342.                     $thisfile_riff_WAVE_cart_0['client_id']            =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64));
  343.                     $thisfile_riff_WAVE_cart_0['category']             =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64));
  344.                     $thisfile_riff_WAVE_cart_0['classification']       =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64));
  345.                     $thisfile_riff_WAVE_cart_0['out_cue']              =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64));
  346.                     $thisfile_riff_WAVE_cart_0['start_date']           =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10));
  347.                     $thisfile_riff_WAVE_cart_0['start_time']           =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 462,  8));
  348.                     $thisfile_riff_WAVE_cart_0['end_date']             =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10));
  349.                     $thisfile_riff_WAVE_cart_0['end_time']             =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 480,  8));
  350.                     $thisfile_riff_WAVE_cart_0['producer_app_id']      =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64));
  351.                     $thisfile_riff_WAVE_cart_0['producer_app_version'] =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64));
  352.                     $thisfile_riff_WAVE_cart_0['user_defined_text']    =                         trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64));
  353.                     $thisfile_riff_WAVE_cart_0['zero_db_reference']    = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680,  4), true);
  354.                     for ($i = 0; $i < 8; $i++) {
  355.                         $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] =                  substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4);
  356.                         $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value']  = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4));
  357.                     }
  358.                     $thisfile_riff_WAVE_cart_0['url']              =                 trim(substr($thisfile_riff_WAVE_cart_0['data'],  748, 1024));
  359.                     $thisfile_riff_WAVE_cart_0['tag_text']         = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772)));
  360.  
  361.                     $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist'];
  362.                     $thisfile_riff['comments']['title'][]  = $thisfile_riff_WAVE_cart_0['title'];
  363.                 }
  364.  
  365.                 if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) {
  366.                     // SoundMiner metadata
  367.  
  368.                     // shortcuts
  369.                     $thisfile_riff_WAVE_SNDM_0      = &$thisfile_riff_WAVE['SNDM'][0];
  370.                     $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data'];
  371.                     $SNDM_startoffset = 0;
  372.                     $SNDM_endoffset   = $thisfile_riff_WAVE_SNDM_0['size'];
  373.  
  374.                     while ($SNDM_startoffset < $SNDM_endoffset) {
  375.                         $SNDM_thisTagOffset = 0;
  376.                         $SNDM_thisTagSize      = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4));
  377.                         $SNDM_thisTagOffset += 4;
  378.                         $SNDM_thisTagKey       =                           substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4);
  379.                         $SNDM_thisTagOffset += 4;
  380.                         $SNDM_thisTagDataSize  = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
  381.                         $SNDM_thisTagOffset += 2;
  382.                         $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
  383.                         $SNDM_thisTagOffset += 2;
  384.                         $SNDM_thisTagDataText =                            substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize);
  385.                         $SNDM_thisTagOffset += $SNDM_thisTagDataSize;
  386.  
  387.                         if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) {
  388.                             $this->warning('RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
  389.                             break;
  390.                         } elseif ($SNDM_thisTagSize <= 0) {
  391.                             $this->warning('RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
  392.                             break;
  393.                         }
  394.                         $SNDM_startoffset += $SNDM_thisTagSize;
  395.  
  396.                         $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText;
  397.                         if ($parsedkey = self::waveSNDMtagLookup($SNDM_thisTagKey)) {
  398.                             $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText;
  399.                         } else {
  400.                             $this->warning('RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
  401.                         }
  402.                     }
  403.  
  404.                     $tagmapping = array(
  405.                         'tracktitle'=>'title',
  406.                         'category'  =>'genre',
  407.                         'cdtitle'   =>'album',
  408.                         'tracktitle'=>'title',
  409.                     );
  410.                     foreach ($tagmapping as $fromkey => $tokey) {
  411.                         if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) {
  412.                             $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey];
  413.                         }
  414.                     }
  415.                 }
  416.  
  417.                 if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) {
  418.                     // requires functions simplexml_load_string and get_object_vars
  419.                     if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) {
  420.                         $thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML;
  421.                         if (isset($parsedXML['SPEED']['MASTER_SPEED'])) {
  422.                             @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']);
  423.                             $thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000);
  424.                         }
  425.                         if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) {
  426.                             @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']);
  427.                             $thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000);
  428.                         }
  429.                         if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) {
  430.                             $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0'));
  431.                             $timestamp_sample_rate = (is_array($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) ? max($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) : $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']); // XML could possibly contain more than one TIMESTAMP_SAMPLE_RATE tag, returning as array instead of integer [why? does it make sense? perhaps doesn't matter but getID3 needs to deal with it] - see https://github.com/JamesHeinrich/getID3/issues/105
  432.                             $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $timestamp_sample_rate;
  433.                             $h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds']       / 3600);
  434.                             $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600))      / 60);
  435.                             $s = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60));
  436.                             $f =       ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate'];
  437.                             $thisfile_riff_WAVE['iXML'][0]['timecode_string']       = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s,       $f);
  438.                             $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d',   $h, $m, $s, round($f));
  439.                             unset($samples_since_midnight, $timestamp_sample_rate, $h, $m, $s, $f);
  440.                         }
  441.                         unset($parsedXML);
  442.                     }
  443.                 }
  444.  
  445.  
  446.  
  447.                 if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
  448.                     $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
  449.                     $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
  450.                 }
  451.  
  452.                 if (!empty($info['wavpack'])) {
  453.                     $thisfile_audio_dataformat = 'wavpack';
  454.                     $thisfile_audio['bitrate_mode'] = 'vbr';
  455.                     $thisfile_audio['encoder']      = 'WavPack v'.$info['wavpack']['version'];
  456.  
  457.                     // Reset to the way it was - RIFF parsing will have messed this up
  458.                     $info['avdataend']        = $Original['avdataend'];
  459.                     $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
  460.  
  461.                     $this->fseek($info['avdataoffset'] - 44);
  462.                     $RIFFdata = $this->fread(44);
  463.                     $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata,  4, 4)) +  8;
  464.                     $OrignalRIFFdataSize   = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
  465.  
  466.                     if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
  467.                         $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
  468.                         $this->fseek($info['avdataend']);
  469.                         $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
  470.                     }
  471.  
  472.                     // move the data chunk after all other chunks (if any)
  473.                     // so that the RIFF parser doesn't see EOF when trying
  474.                     // to skip over the data chunk
  475.                     $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
  476.                     $getid3_riff = new getid3_riff($this->getid3);
  477.                     $getid3_riff->ParseRIFFdata($RIFFdata);
  478.                     unset($getid3_riff);
  479.                 }
  480.  
  481.                 if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
  482.                     switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
  483.                         case 0x0001: // PCM
  484.                             if (!empty($info['ac3'])) {
  485.                                 // Dolby Digital WAV files masquerade as PCM-WAV, but they're not
  486.                                 $thisfile_audio['wformattag']  = 0x2000;
  487.                                 $thisfile_audio['codec']       = self::wFormatTagLookup($thisfile_audio['wformattag']);
  488.                                 $thisfile_audio['lossless']    = false;
  489.                                 $thisfile_audio['bitrate']     = $info['ac3']['bitrate'];
  490.                                 $thisfile_audio['sample_rate'] = $info['ac3']['sample_rate'];
  491.                             }
  492.                             if (!empty($info['dts'])) {
  493.                                 // Dolby DTS files masquerade as PCM-WAV, but they're not
  494.                                 $thisfile_audio['wformattag']  = 0x2001;
  495.                                 $thisfile_audio['codec']       = self::wFormatTagLookup($thisfile_audio['wformattag']);
  496.                                 $thisfile_audio['lossless']    = false;
  497.                                 $thisfile_audio['bitrate']     = $info['dts']['bitrate'];
  498.                                 $thisfile_audio['sample_rate'] = $info['dts']['sample_rate'];
  499.                             }
  500.                             break;
  501.                         case 0x08AE: // ClearJump LiteWave
  502.                             $thisfile_audio['bitrate_mode'] = 'vbr';
  503.                             $thisfile_audio_dataformat   = 'litewave';
  504.  
  505.                             //typedef struct tagSLwFormat {
  506.                             //  WORD    m_wCompFormat;     // low byte defines compression method, high byte is compression flags
  507.                             //  DWORD   m_dwScale;         // scale factor for lossy compression
  508.                             //  DWORD   m_dwBlockSize;     // number of samples in encoded blocks
  509.                             //  WORD    m_wQuality;        // alias for the scale factor
  510.                             //  WORD    m_wMarkDistance;   // distance between marks in bytes
  511.                             //  WORD    m_wReserved;
  512.                             //
  513.                             //  //following paramters are ignored if CF_FILESRC is not set
  514.                             //  DWORD   m_dwOrgSize;       // original file size in bytes
  515.                             //  WORD    m_bFactExists;     // indicates if 'fact' chunk exists in the original file
  516.                             //  DWORD   m_dwRiffChunkSize; // riff chunk size in the original file
  517.                             //
  518.                             //  PCMWAVEFORMAT m_OrgWf;     // original wave format
  519.                             // }SLwFormat, *PSLwFormat;
  520.  
  521.                             // shortcut
  522.                             $thisfile_riff['litewave']['raw'] = array();
  523.                             $riff_litewave     = &$thisfile_riff['litewave'];
  524.                             $riff_litewave_raw = &$riff_litewave['raw'];
  525.  
  526.                             $flags = array(
  527.                                 'compression_method' => 1,
  528.                                 'compression_flags'  => 1,
  529.                                 'm_dwScale'          => 4,
  530.                                 'm_dwBlockSize'      => 4,
  531.                                 'm_wQuality'         => 2,
  532.                                 'm_wMarkDistance'    => 2,
  533.                                 'm_wReserved'        => 2,
  534.                                 'm_dwOrgSize'        => 4,
  535.                                 'm_bFactExists'      => 2,
  536.                                 'm_dwRiffChunkSize'  => 4,
  537.                             );
  538.                             $litewave_offset = 18;
  539.                             foreach ($flags as $flag => $length) {
  540.                                 $riff_litewave_raw[$flag] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], $litewave_offset, $length));
  541.                                 $litewave_offset += $length;
  542.                             }
  543.  
  544.                             //$riff_litewave['quality_factor'] = intval(round((2000 - $riff_litewave_raw['m_dwScale']) / 20));
  545.                             $riff_litewave['quality_factor'] = $riff_litewave_raw['m_wQuality'];
  546.  
  547.                             $riff_litewave['flags']['raw_source']    = ($riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
  548.                             $riff_litewave['flags']['vbr_blocksize'] = ($riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
  549.                             $riff_litewave['flags']['seekpoints']    =        (bool) ($riff_litewave_raw['compression_flags'] & 0x04);
  550.  
  551.                             $thisfile_audio['lossless']        = (($riff_litewave_raw['m_wQuality'] == 100) ? true : false);
  552.                             $thisfile_audio['encoder_options'] = '-q'.$riff_litewave['quality_factor'];
  553.                             break;
  554.  
  555.                         default:
  556.                             break;
  557.                     }
  558.                 }
  559.                 if ($info['avdataend'] > $info['filesize']) {
  560.                     switch (!empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') {
  561.                         case 'wavpack': // WavPack
  562.                         case 'lpac':    // LPAC
  563.                         case 'ofr':     // OptimFROG
  564.                         case 'ofs':     // OptimFROG DualStream
  565.                             // lossless compressed audio formats that keep original RIFF headers - skip warning
  566.                             break;
  567.  
  568.                         case 'litewave':
  569.                             if (($info['avdataend'] - $info['filesize']) == 1) {
  570.                                 // LiteWave appears to incorrectly *not* pad actual output file
  571.                                 // to nearest WORD boundary so may appear to be short by one
  572.                                 // byte, in which case - skip warning
  573.                             } else {
  574.                                 // Short by more than one byte, throw warning
  575.                                 $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)');
  576.                                 $info['avdataend'] = $info['filesize'];
  577.                             }
  578.                             break;
  579.  
  580.                         default:
  581.                             if ((($info['avdataend'] - $info['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($info['filesize'] - $info['avdataoffset']) % 2) == 1)) {
  582.                                 // output file appears to be incorrectly *not* padded to nearest WORD boundary
  583.                                 // Output less severe warning
  584.                                 $this->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)');
  585.                                 $info['avdataend'] = $info['filesize'];
  586.                             } else {
  587.                                 // Short by more than one byte, throw warning
  588.                                 $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)');
  589.                                 $info['avdataend'] = $info['filesize'];
  590.                             }
  591.                             break;
  592.                     }
  593.                 }
  594.                 if (!empty($info['mpeg']['audio']['LAME']['audio_bytes'])) {
  595.                     if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
  596.                         $info['avdataend']--;
  597.                         $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored');
  598.                     }
  599.                 }
  600.                 if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) {
  601.                     unset($thisfile_audio['bits_per_sample']);
  602.                     if (!empty($info['ac3']['bitrate']) && ($info['ac3']['bitrate'] != $thisfile_audio['bitrate'])) {
  603.                         $thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
  604.                     }
  605.                 }
  606.                 break;
  607.  
  608.             // http://en.wikipedia.org/wiki/Audio_Video_Interleave
  609.             case 'AVI ':
  610.                 $info['fileformat'] = 'avi';
  611.                 $info['mime_type']  = 'video/avi';
  612.  
  613.                 $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
  614.                 $thisfile_video['dataformat']   = 'avi';
  615.  
  616.                 if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) {
  617.                     $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8;
  618.                     if (isset($thisfile_riff['AVIX'])) {
  619.                         $info['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size'];
  620.                     } else {
  621.                         $info['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size'];
  622.                     }
  623.                     if ($info['avdataend'] > $info['filesize']) {
  624.                         $this->warning('Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)');
  625.                         $info['avdataend'] = $info['filesize'];
  626.                     }
  627.                 }
  628.  
  629.                 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) {
  630.                     //$bIndexType = array(
  631.                     //    0x00 => 'AVI_INDEX_OF_INDEXES',
  632.                     //    0x01 => 'AVI_INDEX_OF_CHUNKS',
  633.                     //    0x80 => 'AVI_INDEX_IS_DATA',
  634.                     //);
  635.                     //$bIndexSubtype = array(
  636.                     //    0x01 => array(
  637.                     //        0x01 => 'AVI_INDEX_2FIELD',
  638.                     //    ),
  639.                     //);
  640.                     foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) {
  641.                         $ahsisd = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data'];
  642.  
  643.                         $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = $this->EitherEndian2Int(substr($ahsisd,  0, 2));
  644.                         $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']  = $this->EitherEndian2Int(substr($ahsisd,  2, 1));
  645.                         $thisfile_riff_raw['indx'][$streamnumber]['bIndexType']     = $this->EitherEndian2Int(substr($ahsisd,  3, 1));
  646.                         $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse']  = $this->EitherEndian2Int(substr($ahsisd,  4, 4));
  647.                         $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId']      =                         substr($ahsisd,  8, 4);
  648.                         $thisfile_riff_raw['indx'][$streamnumber]['dwReserved']     = $this->EitherEndian2Int(substr($ahsisd, 12, 4));
  649.  
  650.                         //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name']    =    $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']];
  651.                         //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']];
  652.  
  653.                         unset($ahsisd);
  654.                     }
  655.                 }
  656.                 if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) {
  657.                     $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'];
  658.  
  659.                     // shortcut
  660.                     $thisfile_riff_raw['avih'] = array();
  661.                     $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih'];
  662.  
  663.                     $thisfile_riff_raw_avih['dwMicroSecPerFrame']    = $this->EitherEndian2Int(substr($avihData,  0, 4)); // frame display rate (or 0L)
  664.                     if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) {
  665.                         $this->error('Corrupt RIFF file: avih.dwMicroSecPerFrame == zero');
  666.                         return false;
  667.                     }
  668.  
  669.                     $flags = array(
  670.                         'dwMaxBytesPerSec',       // max. transfer rate
  671.                         'dwPaddingGranularity',   // pad to multiples of this size; normally 2K.
  672.                         'dwFlags',                // the ever-present flags
  673.                         'dwTotalFrames',          // # frames in file
  674.                         'dwInitialFrames',        //
  675.                         'dwStreams',              //
  676.                         'dwSuggestedBufferSize',  //
  677.                         'dwWidth',                //
  678.                         'dwHeight',               //
  679.                         'dwScale',                //
  680.                         'dwRate',                 //
  681.                         'dwStart',                //
  682.                         'dwLength',               //
  683.                     );
  684.                     $avih_offset = 4;
  685.                     foreach ($flags as $flag) {
  686.                         $thisfile_riff_raw_avih[$flag] = $this->EitherEndian2Int(substr($avihData, $avih_offset, 4));
  687.                         $avih_offset += 4;
  688.                     }
  689.  
  690.                     $flags = array(
  691.                         'hasindex'     => 0x00000010,
  692.                         'mustuseindex' => 0x00000020,
  693.                         'interleaved'  => 0x00000100,
  694.                         'trustcktype'  => 0x00000800,
  695.                         'capturedfile' => 0x00010000,
  696.                         'copyrighted'  => 0x00020010,
  697.                     );
  698.                     foreach ($flags as $flag => $value) {
  699.                         $thisfile_riff_raw_avih['flags'][$flag] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & $value);
  700.                     }
  701.  
  702.                     // shortcut
  703.                     $thisfile_riff_video[$streamindex] = array();
  704.                     $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex];
  705.  
  706.                     if ($thisfile_riff_raw_avih['dwWidth'] > 0) {
  707.                         $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth'];
  708.                         $thisfile_video['resolution_x']             = $thisfile_riff_video_current['frame_width'];
  709.                     }
  710.                     if ($thisfile_riff_raw_avih['dwHeight'] > 0) {
  711.                         $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight'];
  712.                         $thisfile_video['resolution_y']              = $thisfile_riff_video_current['frame_height'];
  713.                     }
  714.                     if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) {
  715.                         $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames'];
  716.                         $thisfile_video['total_frames']              = $thisfile_riff_video_current['total_frames'];
  717.                     }
  718.  
  719.                     $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3);
  720.                     $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate'];
  721.                 }
  722.                 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
  723.                     if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) {
  724.                         for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
  725.                             if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
  726.                                 $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
  727.                                 $strhfccType = substr($strhData,  0, 4);
  728.  
  729.                                 if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
  730.                                     $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
  731.  
  732.                                     // shortcut
  733.                                     $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex];
  734.  
  735.                                     switch ($strhfccType) {
  736.                                         case 'auds':
  737.                                             $thisfile_audio['bitrate_mode'] = 'cbr';
  738.                                             $thisfile_audio_dataformat      = 'wav';
  739.                                             if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) {
  740.                                                 $streamindex = count($thisfile_riff_audio);
  741.                                             }
  742.  
  743.                                             $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($strfData);
  744.                                             $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
  745.  
  746.                                             // shortcut
  747.                                             $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
  748.                                             $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex];
  749.  
  750.                                             if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) {
  751.                                                 unset($thisfile_audio_streams_currentstream['bits_per_sample']);
  752.                                             }
  753.                                             $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag'];
  754.                                             unset($thisfile_audio_streams_currentstream['raw']);
  755.  
  756.                                             // shortcut
  757.                                             $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw'];
  758.  
  759.                                             unset($thisfile_riff_audio[$streamindex]['raw']);
  760.                                             $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
  761.  
  762.                                             $thisfile_audio['lossless'] = false;
  763.                                             switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) {
  764.                                                 case 0x0001:  // PCM
  765.                                                     $thisfile_audio_dataformat  = 'wav';
  766.                                                     $thisfile_audio['lossless'] = true;
  767.                                                     break;
  768.  
  769.                                                 case 0x0050: // MPEG Layer 2 or Layer 1
  770.                                                     $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2
  771.                                                     break;
  772.  
  773.                                                 case 0x0055: // MPEG Layer 3
  774.                                                     $thisfile_audio_dataformat = 'mp3';
  775.                                                     break;
  776.  
  777.                                                 case 0x00FF: // AAC
  778.                                                     $thisfile_audio_dataformat = 'aac';
  779.                                                     break;
  780.  
  781.                                                 case 0x0161: // Windows Media v7 / v8 / v9
  782.                                                 case 0x0162: // Windows Media Professional v9
  783.                                                 case 0x0163: // Windows Media Lossess v9
  784.                                                     $thisfile_audio_dataformat = 'wma';
  785.                                                     break;
  786.  
  787.                                                 case 0x2000: // AC-3
  788.                                                     $thisfile_audio_dataformat = 'ac3';
  789.                                                     break;
  790.  
  791.                                                 case 0x2001: // DTS
  792.                                                     $thisfile_audio_dataformat = 'dts';
  793.                                                     break;
  794.  
  795.                                                 default:
  796.                                                     $thisfile_audio_dataformat = 'wav';
  797.                                                     break;
  798.                                             }
  799.                                             $thisfile_audio_streams_currentstream['dataformat']   = $thisfile_audio_dataformat;
  800.                                             $thisfile_audio_streams_currentstream['lossless']     = $thisfile_audio['lossless'];
  801.                                             $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
  802.                                             break;
  803.  
  804.  
  805.                                         case 'iavs':
  806.                                         case 'vids':
  807.                                             // shortcut
  808.                                             $thisfile_riff_raw['strh'][$i]                  = array();
  809.                                             $thisfile_riff_raw_strh_current                 = &$thisfile_riff_raw['strh'][$i];
  810.  
  811.                                             $thisfile_riff_raw_strh_current['fccType']               =                         substr($strhData,  0, 4);  // same as $strhfccType;
  812.                                             $thisfile_riff_raw_strh_current['fccHandler']            =                         substr($strhData,  4, 4);
  813.                                             $thisfile_riff_raw_strh_current['dwFlags']               = $this->EitherEndian2Int(substr($strhData,  8, 4)); // Contains AVITF_* flags
  814.                                             $thisfile_riff_raw_strh_current['wPriority']             = $this->EitherEndian2Int(substr($strhData, 12, 2));
  815.                                             $thisfile_riff_raw_strh_current['wLanguage']             = $this->EitherEndian2Int(substr($strhData, 14, 2));
  816.                                             $thisfile_riff_raw_strh_current['dwInitialFrames']       = $this->EitherEndian2Int(substr($strhData, 16, 4));
  817.                                             $thisfile_riff_raw_strh_current['dwScale']               = $this->EitherEndian2Int(substr($strhData, 20, 4));
  818.                                             $thisfile_riff_raw_strh_current['dwRate']                = $this->EitherEndian2Int(substr($strhData, 24, 4));
  819.                                             $thisfile_riff_raw_strh_current['dwStart']               = $this->EitherEndian2Int(substr($strhData, 28, 4));
  820.                                             $thisfile_riff_raw_strh_current['dwLength']              = $this->EitherEndian2Int(substr($strhData, 32, 4));
  821.                                             $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($strhData, 36, 4));
  822.                                             $thisfile_riff_raw_strh_current['dwQuality']             = $this->EitherEndian2Int(substr($strhData, 40, 4));
  823.                                             $thisfile_riff_raw_strh_current['dwSampleSize']          = $this->EitherEndian2Int(substr($strhData, 44, 4));
  824.                                             $thisfile_riff_raw_strh_current['rcFrame']               = $this->EitherEndian2Int(substr($strhData, 48, 4));
  825.  
  826.                                             $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strh_current['fccHandler']);
  827.                                             $thisfile_video['fourcc']             = $thisfile_riff_raw_strh_current['fccHandler'];
  828.                                             if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
  829.                                                 $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']);
  830.                                                 $thisfile_video['fourcc']             = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
  831.                                             }
  832.                                             $thisfile_video['codec']              = $thisfile_riff_video_current['codec'];
  833.                                             $thisfile_video['pixel_aspect_ratio'] = (float) 1;
  834.                                             switch ($thisfile_riff_raw_strh_current['fccHandler']) {
  835.                                                 case 'HFYU': // Huffman Lossless Codec
  836.                                                 case 'IRAW': // Intel YUV Uncompressed
  837.                                                 case 'YUY2': // Uncompressed YUV 4:2:2
  838.                                                     $thisfile_video['lossless'] = true;
  839.                                                     break;
  840.  
  841.                                                 default:
  842.                                                     $thisfile_video['lossless'] = false;
  843.                                                     break;
  844.                                             }
  845.  
  846.                                             switch ($strhfccType) {
  847.                                                 case 'vids':
  848.                                                     $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($this->container == 'riff'));
  849.                                                     $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'];
  850.  
  851.                                                     if ($thisfile_riff_video_current['codec'] == 'DV') {
  852.                                                         $thisfile_riff_video_current['dv_type'] = 2;
  853.                                                     }
  854.                                                     break;
  855.  
  856.                                                 case 'iavs':
  857.                                                     $thisfile_riff_video_current['dv_type'] = 1;
  858.                                                     break;
  859.                                             }
  860.                                             break;
  861.  
  862.                                         default:
  863.                                             $this->warning('Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"');
  864.                                             break;
  865.  
  866.                                     }
  867.                                 }
  868.                             }
  869.  
  870.                             if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) {
  871.  
  872.                                 $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'];
  873.                                 if (self::fourccLookup($thisfile_video['fourcc'])) {
  874.                                     $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_video['fourcc']);
  875.                                     $thisfile_video['codec']              = $thisfile_riff_video_current['codec'];
  876.                                 }
  877.  
  878.                                 switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) {
  879.                                     case 'HFYU': // Huffman Lossless Codec
  880.                                     case 'IRAW': // Intel YUV Uncompressed
  881.                                     case 'YUY2': // Uncompressed YUV 4:2:2
  882.                                         $thisfile_video['lossless']        = true;
  883.                                         //$thisfile_video['bits_per_sample'] = 24;
  884.                                         break;
  885.  
  886.                                     default:
  887.                                         $thisfile_video['lossless']        = false;
  888.                                         //$thisfile_video['bits_per_sample'] = 24;
  889.                                         break;
  890.                                 }
  891.  
  892.                             }
  893.                         }
  894.                     }
  895.                 }
  896.                 break;
  897.  
  898.  
  899.             case 'AMV ':
  900.                 $info['fileformat'] = 'amv';
  901.                 $info['mime_type']  = 'video/amv';
  902.  
  903.                 $thisfile_video['bitrate_mode']    = 'vbr'; // it's MJPEG, presumably contant-quality encoding, thereby VBR
  904.                 $thisfile_video['dataformat']      = 'mjpeg';
  905.                 $thisfile_video['codec']           = 'mjpeg';
  906.                 $thisfile_video['lossless']        = false;
  907.                 $thisfile_video['bits_per_sample'] = 24;
  908.  
  909.                 $thisfile_audio['dataformat']   = 'adpcm';
  910.                 $thisfile_audio['lossless']     = false;
  911.                 break;
  912.  
  913.  
  914.             // http://en.wikipedia.org/wiki/CD-DA
  915.             case 'CDDA':
  916.                 $info['fileformat'] = 'cda';
  917.                 unset($info['mime_type']);
  918.  
  919.                 $thisfile_audio_dataformat      = 'cda';
  920.  
  921.                 $info['avdataoffset'] = 44;
  922.  
  923.                 if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) {
  924.                     // shortcut
  925.                     $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0];
  926.  
  927.                     $thisfile_riff_CDDA_fmt_0['unknown1']           = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'],  0, 2));
  928.                     $thisfile_riff_CDDA_fmt_0['track_num']          = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'],  2, 2));
  929.                     $thisfile_riff_CDDA_fmt_0['disc_id']            = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'],  4, 4));
  930.                     $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'],  8, 4));
  931.                     $thisfile_riff_CDDA_fmt_0['playtime_frames']    = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4));
  932.                     $thisfile_riff_CDDA_fmt_0['unknown6']           = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4));
  933.                     $thisfile_riff_CDDA_fmt_0['unknown7']           = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4));
  934.  
  935.                     $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75;
  936.                     $thisfile_riff_CDDA_fmt_0['playtime_seconds']     = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75;
  937.                     $info['comments']['track']                = $thisfile_riff_CDDA_fmt_0['track_num'];
  938.                     $info['playtime_seconds']                 = $thisfile_riff_CDDA_fmt_0['playtime_seconds'];
  939.  
  940.                     // hardcoded data for CD-audio
  941.                     $thisfile_audio['lossless']        = true;
  942.                     $thisfile_audio['sample_rate']     = 44100;
  943.                     $thisfile_audio['channels']        = 2;
  944.                     $thisfile_audio['bits_per_sample'] = 16;
  945.                     $thisfile_audio['bitrate']         = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample'];
  946.                     $thisfile_audio['bitrate_mode']    = 'cbr';
  947.                 }
  948.                 break;
  949.  
  950.             // http://en.wikipedia.org/wiki/AIFF
  951.             case 'AIFF':
  952.             case 'AIFC':
  953.                 $info['fileformat'] = 'aiff';
  954.                 $info['mime_type']  = 'audio/x-aiff';
  955.  
  956.                 $thisfile_audio['bitrate_mode'] = 'cbr';
  957.                 $thisfile_audio_dataformat      = 'aiff';
  958.                 $thisfile_audio['lossless']     = true;
  959.  
  960.                 if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) {
  961.                     $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8;
  962.                     $info['avdataend']    = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size'];
  963.                     if ($info['avdataend'] > $info['filesize']) {
  964.                         if (($info['avdataend'] == ($info['filesize'] + 1)) && (($info['filesize'] % 2) == 1)) {
  965.                             // structures rounded to 2-byte boundary, but dumb encoders
  966.                             // forget to pad end of file to make this actually work
  967.                         } else {
  968.                             $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found');
  969.                         }
  970.                         $info['avdataend'] = $info['filesize'];
  971.                     }
  972.                 }
  973.  
  974.                 if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) {
  975.  
  976.                     // shortcut
  977.                     $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data'];
  978.  
  979.                     $thisfile_riff_audio['channels']         =         getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data,  0,  2), true);
  980.                     $thisfile_riff_audio['total_samples']    =         getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data,  2,  4), false);
  981.                     $thisfile_riff_audio['bits_per_sample']  =         getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data,  6,  2), true);
  982.                     $thisfile_riff_audio['sample_rate']      = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data,  8, 10));
  983.  
  984.                     if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) {
  985.                         $thisfile_riff_audio['codec_fourcc'] =                                   substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18,  4);
  986.                         $CodecNameSize                       =         getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22,  1), false);
  987.                         $thisfile_riff_audio['codec_name']   =                                   substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23,  $CodecNameSize);
  988.                         switch ($thisfile_riff_audio['codec_name']) {
  989.                             case 'NONE':
  990.                                 $thisfile_audio['codec']    = 'Pulse Code Modulation (PCM)';
  991.                                 $thisfile_audio['lossless'] = true;
  992.                                 break;
  993.  
  994.                             case '':
  995.                                 switch ($thisfile_riff_audio['codec_fourcc']) {
  996.                                     // http://developer.apple.com/qa/snd/snd07.html
  997.                                     case 'sowt':
  998.                                         $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
  999.                                         $thisfile_audio['lossless'] = true;
  1000.                                         break;
  1001.  
  1002.                                     case 'twos':
  1003.                                         $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
  1004.                                         $thisfile_audio['lossless'] = true;
  1005.                                         break;
  1006.  
  1007.                                     default:
  1008.                                         break;
  1009.                                 }
  1010.                                 break;
  1011.  
  1012.                             default:
  1013.                                 $thisfile_audio['codec']    = $thisfile_riff_audio['codec_name'];
  1014.                                 $thisfile_audio['lossless'] = false;
  1015.                                 break;
  1016.                         }
  1017.                     }
  1018.  
  1019.                     $thisfile_audio['channels']        = $thisfile_riff_audio['channels'];
  1020.                     if ($thisfile_riff_audio['bits_per_sample'] > 0) {
  1021.                         $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample'];
  1022.                     }
  1023.                     $thisfile_audio['sample_rate']     = $thisfile_riff_audio['sample_rate'];
  1024.                     if ($thisfile_audio['sample_rate'] == 0) {
  1025.                         $this->error('Corrupted AIFF file: sample_rate == zero');
  1026.                         return false;
  1027.                     }
  1028.                     $info['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate'];
  1029.                 }
  1030.  
  1031.                 if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) {
  1032.                     $offset = 0;
  1033.                     $CommentCount                                   = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
  1034.                     $offset += 2;
  1035.                     for ($i = 0; $i < $CommentCount; $i++) {
  1036.                         $info['comments_raw'][$i]['timestamp']      = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false);
  1037.                         $offset += 4;
  1038.                         $info['comments_raw'][$i]['marker_id']      = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true);
  1039.                         $offset += 2;
  1040.                         $CommentLength                              = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false);
  1041.                         $offset += 2;
  1042.                         $info['comments_raw'][$i]['comment']        =                           substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength);
  1043.                         $offset += $CommentLength;
  1044.  
  1045.                         $info['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($info['comments_raw'][$i]['timestamp']);
  1046.                         $thisfile_riff['comments']['comment'][] = $info['comments_raw'][$i]['comment'];
  1047.                     }
  1048.                 }
  1049.  
  1050.                 $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
  1051.                 foreach ($CommentsChunkNames as $key => $value) {
  1052.                     if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
  1053.                         $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
  1054.                     }
  1055.                 }
  1056. /*
  1057.                 if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) {
  1058.                     getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  1059.                     $getid3_temp = new getID3();
  1060.                     $getid3_temp->openfile($this->getid3->filename);
  1061.                     $getid3_id3v2 = new getid3_id3v2($getid3_temp);
  1062.                     $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8;
  1063.                     if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
  1064.                         $info['id3v2'] = $getid3_temp->info['id3v2'];
  1065.                     }
  1066.                     unset($getid3_temp, $getid3_id3v2);
  1067.                 }
  1068. */
  1069.                 break;
  1070.  
  1071.             // http://en.wikipedia.org/wiki/8SVX
  1072.             case '8SVX':
  1073.                 $info['fileformat'] = '8svx';
  1074.                 $info['mime_type']  = 'audio/8svx';
  1075.  
  1076.                 $thisfile_audio['bitrate_mode']    = 'cbr';
  1077.                 $thisfile_audio_dataformat         = '8svx';
  1078.                 $thisfile_audio['bits_per_sample'] = 8;
  1079.                 $thisfile_audio['channels']        = 1; // overridden below, if need be
  1080.  
  1081.                 if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) {
  1082.                     $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8;
  1083.                     $info['avdataend']    = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size'];
  1084.                     if ($info['avdataend'] > $info['filesize']) {
  1085.                         $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found');
  1086.                     }
  1087.                 }
  1088.  
  1089.                 if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) {
  1090.                     // shortcut
  1091.                     $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0];
  1092.  
  1093.                     $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples']  =   getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'],  0, 4));
  1094.                     $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples']   =   getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'],  4, 4));
  1095.                     $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] =   getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'],  8, 4));
  1096.                     $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec']     =   getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2));
  1097.                     $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave']          =   getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1));
  1098.                     $thisfile_riff_RIFFsubtype_VHDR_0['sCompression']      =   getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1));
  1099.                     $thisfile_riff_RIFFsubtype_VHDR_0['Volume']            = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4));
  1100.  
  1101.                     $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'];
  1102.  
  1103.                     switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) {
  1104.                         case 0:
  1105.                             $thisfile_audio['codec']    = 'Pulse Code Modulation (PCM)';
  1106.                             $thisfile_audio['lossless'] = true;
  1107.                             $ActualBitsPerSample        = 8;
  1108.                             break;
  1109.  
  1110.                         case 1:
  1111.                             $thisfile_audio['codec']    = 'Fibonacci-delta encoding';
  1112.                             $thisfile_audio['lossless'] = false;
  1113.                             $ActualBitsPerSample        = 4;
  1114.                             break;
  1115.  
  1116.                         default:
  1117.                             $this->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"');
  1118.                             break;
  1119.                     }
  1120.                 }
  1121.  
  1122.                 if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) {
  1123.                     $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4));
  1124.                     switch ($ChannelsIndex) {
  1125.                         case 6: // Stereo
  1126.                             $thisfile_audio['channels'] = 2;
  1127.                             break;
  1128.  
  1129.                         case 2: // Left channel only
  1130.                         case 4: // Right channel only
  1131.                             $thisfile_audio['channels'] = 1;
  1132.                             break;
  1133.  
  1134.                         default:
  1135.                             $this->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"');
  1136.                             break;
  1137.                     }
  1138.  
  1139.                 }
  1140.  
  1141.                 $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment');
  1142.                 foreach ($CommentsChunkNames as $key => $value) {
  1143.                     if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) {
  1144.                         $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data'];
  1145.                     }
  1146.                 }
  1147.  
  1148.                 $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels'];
  1149.                 if (!empty($thisfile_audio['bitrate'])) {
  1150.                     $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($thisfile_audio['bitrate'] / 8);
  1151.                 }
  1152.                 break;
  1153.  
  1154.             case 'CDXA':
  1155.                 $info['fileformat'] = 'vcd'; // Asume Video CD
  1156.                 $info['mime_type']  = 'video/mpeg';
  1157.  
  1158.                 if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) {
  1159.                     getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true);
  1160.  
  1161.                     $getid3_temp = new getID3();
  1162.                     $getid3_temp->openfile($this->getid3->filename);
  1163.                     $getid3_mpeg = new getid3_mpeg($getid3_temp);
  1164.                     $getid3_mpeg->Analyze();
  1165.                     if (empty($getid3_temp->info['error'])) {
  1166.                         $info['audio']   = $getid3_temp->info['audio'];
  1167.                         $info['video']   = $getid3_temp->info['video'];
  1168.                         $info['mpeg']    = $getid3_temp->info['mpeg'];
  1169.                         $info['warning'] = $getid3_temp->info['warning'];
  1170.                     }
  1171.                     unset($getid3_temp, $getid3_mpeg);
  1172.                 }
  1173.                 break;
  1174.  
  1175.             case 'WEBP':
  1176.                 // https://developers.google.com/speed/webp/docs/riff_container
  1177.                 // https://tools.ietf.org/html/rfc6386
  1178.                 // https://chromium.googlesource.com/webm/libwebp/+/master/doc/webp-lossless-bitstream-spec.txt
  1179.                 $info['fileformat'] = 'webp';
  1180.                 $info['mime_type']  = 'image/webp';
  1181.  
  1182.                 if (!empty($thisfile_riff['WEBP']['VP8 '][0]['size'])) {
  1183.                     $old_offset = $this->ftell();
  1184.                     $this->fseek($thisfile_riff['WEBP']['VP8 '][0]['offset'] + 8); // 4 bytes "VP8 " + 4 bytes chunk size
  1185.                     $WEBP_VP8_header = $this->fread(10);
  1186.                     $this->fseek($old_offset);
  1187.                     if (substr($WEBP_VP8_header, 3, 3) == "\x9D\x01\x2A") {
  1188.                         $thisfile_riff['WEBP']['VP8 '][0]['keyframe']   = !(getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x800000);
  1189.                         $thisfile_riff['WEBP']['VP8 '][0]['version']    =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x700000) >> 20;
  1190.                         $thisfile_riff['WEBP']['VP8 '][0]['show_frame'] =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x080000);
  1191.                         $thisfile_riff['WEBP']['VP8 '][0]['data_bytes'] =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x07FFFF) >>  0;
  1192.  
  1193.                         $thisfile_riff['WEBP']['VP8 '][0]['scale_x']    =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 6, 2)) & 0xC000) >> 14;
  1194.                         $thisfile_riff['WEBP']['VP8 '][0]['width']      =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 6, 2)) & 0x3FFF);
  1195.                         $thisfile_riff['WEBP']['VP8 '][0]['scale_y']    =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 8, 2)) & 0xC000) >> 14;
  1196.                         $thisfile_riff['WEBP']['VP8 '][0]['height']     =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 8, 2)) & 0x3FFF);
  1197.  
  1198.                         $info['video']['resolution_x'] = $thisfile_riff['WEBP']['VP8 '][0]['width'];
  1199.                         $info['video']['resolution_y'] = $thisfile_riff['WEBP']['VP8 '][0]['height'];
  1200.                     } else {
  1201.                         $this->error('Expecting 9D 01 2A at offset '.($thisfile_riff['WEBP']['VP8 '][0]['offset'] + 8 + 3).', found "'.getid3_lib::PrintHexBytes(substr($WEBP_VP8_header, 3, 3)).'"');
  1202.                     }
  1203.  
  1204.                 }
  1205.                 if (!empty($thisfile_riff['WEBP']['VP8L'][0]['size'])) {
  1206.                     $old_offset = $this->ftell();
  1207.                     $this->fseek($thisfile_riff['WEBP']['VP8L'][0]['offset'] + 8); // 4 bytes "VP8L" + 4 bytes chunk size
  1208.                     $WEBP_VP8L_header = $this->fread(10);
  1209.                     $this->fseek($old_offset);
  1210.                     if (substr($WEBP_VP8L_header, 0, 1) == "\x2F") {
  1211.                         $width_height_flags = getid3_lib::LittleEndian2Bin(substr($WEBP_VP8L_header, 1, 4));
  1212.                         $thisfile_riff['WEBP']['VP8L'][0]['width']         =        bindec(substr($width_height_flags, 18, 14)) + 1;
  1213.                         $thisfile_riff['WEBP']['VP8L'][0]['height']        =        bindec(substr($width_height_flags,  4, 14)) + 1;
  1214.                         $thisfile_riff['WEBP']['VP8L'][0]['alpha_is_used'] = (bool) bindec(substr($width_height_flags,  3,  1));
  1215.                         $thisfile_riff['WEBP']['VP8L'][0]['version']       =        bindec(substr($width_height_flags,  0,  3));
  1216.  
  1217.                         $info['video']['resolution_x'] = $thisfile_riff['WEBP']['VP8L'][0]['width'];
  1218.                         $info['video']['resolution_y'] = $thisfile_riff['WEBP']['VP8L'][0]['height'];
  1219.                     } else {
  1220.                         $this->error('Expecting 2F at offset '.($thisfile_riff['WEBP']['VP8L'][0]['offset'] + 8).', found "'.getid3_lib::PrintHexBytes(substr($WEBP_VP8L_header, 0, 1)).'"');
  1221.                     }
  1222.  
  1223.                 }
  1224.                 break;
  1225.  
  1226.             default:
  1227.                 $this->error('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA|WEBP), found "'.$RIFFsubtype.'" instead');
  1228.                 //unset($info['fileformat']);
  1229.         }
  1230.  
  1231.         switch ($RIFFsubtype) {
  1232.             case 'WAVE':
  1233.             case 'AIFF':
  1234.             case 'AIFC':
  1235.                 $ID3v2_key_good = 'id3 ';
  1236.                 $ID3v2_keys_bad = array('ID3 ', 'tag ');
  1237.                 foreach ($ID3v2_keys_bad as $ID3v2_key_bad) {
  1238.                     if (isset($thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]) && !array_key_exists($ID3v2_key_good, $thisfile_riff[$RIFFsubtype])) {
  1239.                         $thisfile_riff[$RIFFsubtype][$ID3v2_key_good] = $thisfile_riff[$RIFFsubtype][$ID3v2_key_bad];
  1240.                         $this->warning('mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"');
  1241.                     }
  1242.                 }
  1243.  
  1244.                 if (isset($thisfile_riff[$RIFFsubtype]['id3 '])) {
  1245.                     getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  1246.  
  1247.                     $getid3_temp = new getID3();
  1248.                     $getid3_temp->openfile($this->getid3->filename);
  1249.                     $getid3_id3v2 = new getid3_id3v2($getid3_temp);
  1250.                     $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8;
  1251.                     if ($thisfile_riff[$RIFFsubtype]['id3 '][0]['valid'] = $getid3_id3v2->Analyze()) {
  1252.                         $info['id3v2'] = $getid3_temp->info['id3v2'];
  1253.                     }
  1254.                     unset($getid3_temp, $getid3_id3v2);
  1255.                 }
  1256.                 break;
  1257.         }
  1258.  
  1259.         if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) {
  1260.             $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4));
  1261.         }
  1262.         if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) {
  1263.             self::parseComments($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']);
  1264.         }
  1265.         if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) {
  1266.             self::parseComments($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']);
  1267.         }
  1268.  
  1269.         if (empty($thisfile_audio['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version'])) {
  1270.             $thisfile_audio['encoder'] = $info['mpeg']['audio']['LAME']['short_version'];
  1271.         }
  1272.  
  1273.         if (!isset($info['playtime_seconds'])) {
  1274.             $info['playtime_seconds'] = 0;
  1275.         }
  1276.         if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
  1277.             // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie
  1278.             $info['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
  1279.         } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) {
  1280.             $info['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
  1281.         }
  1282.  
  1283.         if ($info['playtime_seconds'] > 0) {
  1284.             if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
  1285.  
  1286.                 if (!isset($info['bitrate'])) {
  1287.                     $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1288.                 }
  1289.  
  1290.             } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) {
  1291.  
  1292.                 if (!isset($thisfile_audio['bitrate'])) {
  1293.                     $thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1294.                 }
  1295.  
  1296.             } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) {
  1297.  
  1298.                 if (!isset($thisfile_video['bitrate'])) {
  1299.                     $thisfile_video['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1300.                 }
  1301.  
  1302.             }
  1303.         }
  1304.  
  1305.  
  1306.         if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($info['playtime_seconds'] > 0)) {
  1307.  
  1308.             $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
  1309.             $thisfile_audio['bitrate'] = 0;
  1310.             $thisfile_video['bitrate'] = $info['bitrate'];
  1311.             foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) {
  1312.                 $thisfile_video['bitrate'] -= $audioinfoarray['bitrate'];
  1313.                 $thisfile_audio['bitrate'] += $audioinfoarray['bitrate'];
  1314.             }
  1315.             if ($thisfile_video['bitrate'] <= 0) {
  1316.                 unset($thisfile_video['bitrate']);
  1317.             }
  1318.             if ($thisfile_audio['bitrate'] <= 0) {
  1319.                 unset($thisfile_audio['bitrate']);
  1320.             }
  1321.         }
  1322.  
  1323.         if (isset($info['mpeg']['audio'])) {
  1324.             $thisfile_audio_dataformat      = 'mp'.$info['mpeg']['audio']['layer'];
  1325.             $thisfile_audio['sample_rate']  = $info['mpeg']['audio']['sample_rate'];
  1326.             $thisfile_audio['channels']     = $info['mpeg']['audio']['channels'];
  1327.             $thisfile_audio['bitrate']      = $info['mpeg']['audio']['bitrate'];
  1328.             $thisfile_audio['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  1329.             if (!empty($info['mpeg']['audio']['codec'])) {
  1330.                 $thisfile_audio['codec'] = $info['mpeg']['audio']['codec'].' '.$thisfile_audio['codec'];
  1331.             }
  1332.             if (!empty($thisfile_audio['streams'])) {
  1333.                 foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) {
  1334.                     if ($streamdata['dataformat'] == $thisfile_audio_dataformat) {
  1335.                         $thisfile_audio['streams'][$streamnumber]['sample_rate']  = $thisfile_audio['sample_rate'];
  1336.                         $thisfile_audio['streams'][$streamnumber]['channels']     = $thisfile_audio['channels'];
  1337.                         $thisfile_audio['streams'][$streamnumber]['bitrate']      = $thisfile_audio['bitrate'];
  1338.                         $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
  1339.                         $thisfile_audio['streams'][$streamnumber]['codec']        = $thisfile_audio['codec'];
  1340.                     }
  1341.                 }
  1342.             }
  1343.             $getid3_mp3 = new getid3_mp3($this->getid3);
  1344.             $thisfile_audio['encoder_options'] = $getid3_mp3->GuessEncoderOptions();
  1345.             unset($getid3_mp3);
  1346.         }
  1347.  
  1348.  
  1349.         if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
  1350.             switch ($thisfile_audio_dataformat) {
  1351.                 case 'ac3':
  1352.                     // ignore bits_per_sample
  1353.                     break;
  1354.  
  1355.                 default:
  1356.                     $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample'];
  1357.                     break;
  1358.             }
  1359.         }
  1360.  
  1361.  
  1362.         if (empty($thisfile_riff_raw)) {
  1363.             unset($thisfile_riff['raw']);
  1364.         }
  1365.         if (empty($thisfile_riff_audio)) {
  1366.             unset($thisfile_riff['audio']);
  1367.         }
  1368.         if (empty($thisfile_riff_video)) {
  1369.             unset($thisfile_riff['video']);
  1370.         }
  1371.  
  1372.         return true;
  1373.     }
  1374.  
  1375.     public function ParseRIFFAMV($startoffset, $maxoffset) {
  1376.         // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
  1377.  
  1378.         // https://code.google.com/p/amv-codec-tools/wiki/AmvDocumentation
  1379.         //typedef struct _amvmainheader {
  1380.         //FOURCC fcc; // 'amvh'
  1381.         //DWORD cb;
  1382.         //DWORD dwMicroSecPerFrame;
  1383.         //BYTE reserve[28];
  1384.         //DWORD dwWidth;
  1385.         //DWORD dwHeight;
  1386.         //DWORD dwSpeed;
  1387.         //DWORD reserve0;
  1388.         //DWORD reserve1;
  1389.         //BYTE bTimeSec;
  1390.         //BYTE bTimeMin;
  1391.         //WORD wTimeHour;
  1392.         //} AMVMAINHEADER;
  1393.  
  1394.         $info = &$this->getid3->info;
  1395.         $RIFFchunk = false;
  1396.  
  1397.         try {
  1398.  
  1399.             $this->fseek($startoffset);
  1400.             $maxoffset = min($maxoffset, $info['avdataend']);
  1401.             $AMVheader = $this->fread(284);
  1402.             if (substr($AMVheader,   0,  8) != 'hdrlamvh') {
  1403.                 throw new Exception('expecting "hdrlamv" at offset '.($startoffset +   0).', found "'.substr($AMVheader,   0, 8).'"');
  1404.             }
  1405.             if (substr($AMVheader,   8,  4) != "\x38\x00\x00\x00") { // "amvh" chunk size, hardcoded to 0x38 = 56 bytes
  1406.                 throw new Exception('expecting "0x38000000" at offset '.($startoffset +   8).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader,   8, 4)).'"');
  1407.             }
  1408.             $RIFFchunk = array();
  1409.             $RIFFchunk['amvh']['us_per_frame']   = getid3_lib::LittleEndian2Int(substr($AMVheader,  12,  4));
  1410.             $RIFFchunk['amvh']['reserved28']     =                              substr($AMVheader,  16, 28);  // null? reserved?
  1411.             $RIFFchunk['amvh']['resolution_x']   = getid3_lib::LittleEndian2Int(substr($AMVheader,  44,  4));
  1412.             $RIFFchunk['amvh']['resolution_y']   = getid3_lib::LittleEndian2Int(substr($AMVheader,  48,  4));
  1413.             $RIFFchunk['amvh']['frame_rate_int'] = getid3_lib::LittleEndian2Int(substr($AMVheader,  52,  4));
  1414.             $RIFFchunk['amvh']['reserved0']      = getid3_lib::LittleEndian2Int(substr($AMVheader,  56,  4)); // 1? reserved?
  1415.             $RIFFchunk['amvh']['reserved1']      = getid3_lib::LittleEndian2Int(substr($AMVheader,  60,  4)); // 0? reserved?
  1416.             $RIFFchunk['amvh']['runtime_sec']    = getid3_lib::LittleEndian2Int(substr($AMVheader,  64,  1));
  1417.             $RIFFchunk['amvh']['runtime_min']    = getid3_lib::LittleEndian2Int(substr($AMVheader,  65,  1));
  1418.             $RIFFchunk['amvh']['runtime_hrs']    = getid3_lib::LittleEndian2Int(substr($AMVheader,  66,  2));
  1419.  
  1420.             $info['video']['frame_rate']   = 1000000 / $RIFFchunk['amvh']['us_per_frame'];
  1421.             $info['video']['resolution_x'] = $RIFFchunk['amvh']['resolution_x'];
  1422.             $info['video']['resolution_y'] = $RIFFchunk['amvh']['resolution_y'];
  1423.             $info['playtime_seconds']      = ($RIFFchunk['amvh']['runtime_hrs'] * 3600) + ($RIFFchunk['amvh']['runtime_min'] * 60) + $RIFFchunk['amvh']['runtime_sec'];
  1424.  
  1425.             // the rest is all hardcoded(?) and does not appear to be useful until you get to audio info at offset 256, even then everything is probably hardcoded
  1426.  
  1427.             if (substr($AMVheader,  68, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x38\x00\x00\x00") {
  1428.                 throw new Exception('expecting "LIST<0x00000000>strlstrh<0x38000000>" at offset '.($startoffset +  68).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader,  68, 20)).'"');
  1429.             }
  1430.             // followed by 56 bytes of null: substr($AMVheader,  88, 56) -> 144
  1431.             if (substr($AMVheader, 144,  8) != 'strf'."\x24\x00\x00\x00") {
  1432.                 throw new Exception('expecting "strf<0x24000000>" at offset '.($startoffset + 144).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 144,  8)).'"');
  1433.             }
  1434.             // followed by 36 bytes of null: substr($AMVheader, 144, 36) -> 180
  1435.  
  1436.             if (substr($AMVheader, 188, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x30\x00\x00\x00") {
  1437.                 throw new Exception('expecting "LIST<0x00000000>strlstrh<0x30000000>" at offset '.($startoffset + 188).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 188, 20)).'"');
  1438.             }
  1439.             // followed by 48 bytes of null: substr($AMVheader, 208, 48) -> 256
  1440.             if (substr($AMVheader, 256,  8) != 'strf'."\x14\x00\x00\x00") {
  1441.                 throw new Exception('expecting "strf<0x14000000>" at offset '.($startoffset + 256).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 256,  8)).'"');
  1442.             }
  1443.             // followed by 20 bytes of a modified WAVEFORMATEX:
  1444.             // typedef struct {
  1445.             // WORD wFormatTag;       //(Fixme: this is equal to PCM's 0x01 format code)
  1446.             // WORD nChannels;        //(Fixme: this is always 1)
  1447.             // DWORD nSamplesPerSec;  //(Fixme: for all known sample files this is equal to 22050)
  1448.             // DWORD nAvgBytesPerSec; //(Fixme: for all known sample files this is equal to 44100)
  1449.             // WORD nBlockAlign;      //(Fixme: this seems to be 2 in AMV files, is this correct ?)
  1450.             // WORD wBitsPerSample;   //(Fixme: this seems to be 16 in AMV files instead of the expected 4)
  1451.             // WORD cbSize;           //(Fixme: this seems to be 0 in AMV files)
  1452.             // WORD reserved;
  1453.             // } WAVEFORMATEX;
  1454.             $RIFFchunk['strf']['wformattag']      = getid3_lib::LittleEndian2Int(substr($AMVheader,  264,  2));
  1455.             $RIFFchunk['strf']['nchannels']       = getid3_lib::LittleEndian2Int(substr($AMVheader,  266,  2));
  1456.             $RIFFchunk['strf']['nsamplespersec']  = getid3_lib::LittleEndian2Int(substr($AMVheader,  268,  4));
  1457.             $RIFFchunk['strf']['navgbytespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader,  272,  4));
  1458.             $RIFFchunk['strf']['nblockalign']     = getid3_lib::LittleEndian2Int(substr($AMVheader,  276,  2));
  1459.             $RIFFchunk['strf']['wbitspersample']  = getid3_lib::LittleEndian2Int(substr($AMVheader,  278,  2));
  1460.             $RIFFchunk['strf']['cbsize']          = getid3_lib::LittleEndian2Int(substr($AMVheader,  280,  2));
  1461.             $RIFFchunk['strf']['reserved']        = getid3_lib::LittleEndian2Int(substr($AMVheader,  282,  2));
  1462.  
  1463.  
  1464.             $info['audio']['lossless']        = false;
  1465.             $info['audio']['sample_rate']     = $RIFFchunk['strf']['nsamplespersec'];
  1466.             $info['audio']['channels']        = $RIFFchunk['strf']['nchannels'];
  1467.             $info['audio']['bits_per_sample'] = $RIFFchunk['strf']['wbitspersample'];
  1468.             $info['audio']['bitrate']         = $info['audio']['sample_rate'] * $info['audio']['channels'] * $info['audio']['bits_per_sample'];
  1469.             $info['audio']['bitrate_mode']    = 'cbr';
  1470.  
  1471.  
  1472.         } catch (getid3_exception $e) {
  1473.             if ($e->getCode() == 10) {
  1474.                 $this->warning('RIFFAMV parser: '.$e->getMessage());
  1475.             } else {
  1476.                 throw $e;
  1477.             }
  1478.         }
  1479.  
  1480.         return $RIFFchunk;
  1481.     }
  1482.  
  1483.  
  1484.     public function ParseRIFF($startoffset, $maxoffset) {
  1485.         $info = &$this->getid3->info;
  1486.  
  1487.         $RIFFchunk = false;
  1488.         $FoundAllChunksWeNeed = false;
  1489.  
  1490.         try {
  1491.             $this->fseek($startoffset);
  1492.             $maxoffset = min($maxoffset, $info['avdataend']);
  1493.             while ($this->ftell() < $maxoffset) {
  1494.                 $chunknamesize = $this->fread(8);
  1495.                 //$chunkname =                          substr($chunknamesize, 0, 4);
  1496.                 $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
  1497.                 $chunksize =  $this->EitherEndian2Int(substr($chunknamesize, 4, 4));
  1498.                 //if (strlen(trim($chunkname, "\x00")) < 4) {
  1499.                 if (strlen($chunkname) < 4) {
  1500.                     $this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.');
  1501.                     break;
  1502.                 }
  1503.                 if (($chunksize == 0) && ($chunkname != 'JUNK')) {
  1504.                     $this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.');
  1505.                     break;
  1506.                 }
  1507.                 if (($chunksize % 2) != 0) {
  1508.                     // all structures are packed on word boundaries
  1509.                     $chunksize++;
  1510.                 }
  1511.  
  1512.                 switch ($chunkname) {
  1513.                     case 'LIST':
  1514.                         $listname = $this->fread(4);
  1515.                         if (preg_match('#^(movi|rec )$#i', $listname)) {
  1516.                             $RIFFchunk[$listname]['offset'] = $this->ftell() - 4;
  1517.                             $RIFFchunk[$listname]['size']   = $chunksize;
  1518.  
  1519.                             if (!$FoundAllChunksWeNeed) {
  1520.                                 $WhereWeWere      = $this->ftell();
  1521.                                 $AudioChunkHeader = $this->fread(12);
  1522.                                 $AudioChunkStreamNum  =                              substr($AudioChunkHeader, 0, 2);
  1523.                                 $AudioChunkStreamType =                              substr($AudioChunkHeader, 2, 2);
  1524.                                 $AudioChunkSize       = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4));
  1525.  
  1526.                                 if ($AudioChunkStreamType == 'wb') {
  1527.                                     $FirstFourBytes = substr($AudioChunkHeader, 8, 4);
  1528.                                     if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) {
  1529.                                         // MP3
  1530.                                         if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) {
  1531.                                             $getid3_temp = new getID3();
  1532.                                             $getid3_temp->openfile($this->getid3->filename);
  1533.                                             $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
  1534.                                             $getid3_temp->info['avdataend']    = $this->ftell() + $AudioChunkSize;
  1535.                                             $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
  1536.                                             $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
  1537.                                             if (isset($getid3_temp->info['mpeg']['audio'])) {
  1538.                                                 $info['mpeg']['audio']         = $getid3_temp->info['mpeg']['audio'];
  1539.                                                 $info['audio']                 = $getid3_temp->info['audio'];
  1540.                                                 $info['audio']['dataformat']   = 'mp'.$info['mpeg']['audio']['layer'];
  1541.                                                 $info['audio']['sample_rate']  = $info['mpeg']['audio']['sample_rate'];
  1542.                                                 $info['audio']['channels']     = $info['mpeg']['audio']['channels'];
  1543.                                                 $info['audio']['bitrate']      = $info['mpeg']['audio']['bitrate'];
  1544.                                                 $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  1545.                                                 //$info['bitrate']               = $info['audio']['bitrate'];
  1546.                                             }
  1547.                                             unset($getid3_temp, $getid3_mp3);
  1548.                                         }
  1549.  
  1550.                                     } elseif (strpos($FirstFourBytes, getid3_ac3::syncword) === 0) {
  1551.  
  1552.                                         // AC3
  1553.                                         $getid3_temp = new getID3();
  1554.                                         $getid3_temp->openfile($this->getid3->filename);
  1555.                                         $getid3_temp->info['avdataoffset'] = $this->ftell() - 4;
  1556.                                         $getid3_temp->info['avdataend']    = $this->ftell() + $AudioChunkSize;
  1557.                                         $getid3_ac3 = new getid3_ac3($getid3_temp);
  1558.                                         $getid3_ac3->Analyze();
  1559.                                         if (empty($getid3_temp->info['error'])) {
  1560.                                             $info['audio']   = $getid3_temp->info['audio'];
  1561.                                             $info['ac3']     = $getid3_temp->info['ac3'];
  1562.                                             if (!empty($getid3_temp->info['warning'])) {
  1563.                                                 foreach ($getid3_temp->info['warning'] as $key => $value) {
  1564.                                                     $this->warning($value);
  1565.                                                 }
  1566.                                             }
  1567.                                         }
  1568.                                         unset($getid3_temp, $getid3_ac3);
  1569.                                     }
  1570.                                 }
  1571.                                 $FoundAllChunksWeNeed = true;
  1572.                                 $this->fseek($WhereWeWere);
  1573.                             }
  1574.                             $this->fseek($chunksize - 4, SEEK_CUR);
  1575.  
  1576.                         } else {
  1577.  
  1578.                             if (!isset($RIFFchunk[$listname])) {
  1579.                                 $RIFFchunk[$listname] = array();
  1580.                             }
  1581.                             $LISTchunkParent    = $listname;
  1582.                             $LISTchunkMaxOffset = $this->ftell() - 4 + $chunksize;
  1583.                             if ($parsedChunk = $this->ParseRIFF($this->ftell(), $LISTchunkMaxOffset)) {
  1584.                                 $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk);
  1585.                             }
  1586.  
  1587.                         }
  1588.                         break;
  1589.  
  1590.                     default:
  1591.                         if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) {
  1592.                             $this->fseek($chunksize, SEEK_CUR);
  1593.                             break;
  1594.                         }
  1595.                         $thisindex = 0;
  1596.                         if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) {
  1597.                             $thisindex = count($RIFFchunk[$chunkname]);
  1598.                         }
  1599.                         $RIFFchunk[$chunkname][$thisindex]['offset'] = $this->ftell() - 8;
  1600.                         $RIFFchunk[$chunkname][$thisindex]['size']   = $chunksize;
  1601.                         switch ($chunkname) {
  1602.                             case 'data':
  1603.                                 $info['avdataoffset'] = $this->ftell();
  1604.                                 $info['avdataend']    = $info['avdataoffset'] + $chunksize;
  1605.  
  1606.                                 $testData = $this->fread(36);
  1607.                                 if ($testData === '') {
  1608.                                     break;
  1609.                                 }
  1610.                                 if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($testData, 0, 4))) {
  1611.  
  1612.                                     // Probably is MP3 data
  1613.                                     if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) {
  1614.                                         $getid3_temp = new getID3();
  1615.                                         $getid3_temp->openfile($this->getid3->filename);
  1616.                                         $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1617.                                         $getid3_temp->info['avdataend']    = $info['avdataend'];
  1618.                                         $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__);
  1619.                                         $getid3_mp3->getOnlyMPEGaudioInfo($info['avdataoffset'], false);
  1620.                                         if (empty($getid3_temp->info['error'])) {
  1621.                                             $info['audio'] = $getid3_temp->info['audio'];
  1622.                                             $info['mpeg']  = $getid3_temp->info['mpeg'];
  1623.                                         }
  1624.                                         unset($getid3_temp, $getid3_mp3);
  1625.                                     }
  1626.  
  1627.                                 } elseif (($isRegularAC3 = (substr($testData, 0, 2) == getid3_ac3::syncword)) || substr($testData, 8, 2) == strrev(getid3_ac3::syncword)) {
  1628.  
  1629.                                     // This is probably AC-3 data
  1630.                                     $getid3_temp = new getID3();
  1631.                                     if ($isRegularAC3) {
  1632.                                         $getid3_temp->openfile($this->getid3->filename);
  1633.                                         $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1634.                                         $getid3_temp->info['avdataend']    = $info['avdataend'];
  1635.                                     }
  1636.                                     $getid3_ac3 = new getid3_ac3($getid3_temp);
  1637.                                     if ($isRegularAC3) {
  1638.                                         $getid3_ac3->Analyze();
  1639.                                     } else {
  1640.                                         // Dolby Digital WAV
  1641.                                         // AC-3 content, but not encoded in same format as normal AC-3 file
  1642.                                         // For one thing, byte order is swapped
  1643.                                         $ac3_data = '';
  1644.                                         for ($i = 0; $i < 28; $i += 2) {
  1645.                                             $ac3_data .= substr($testData, 8 + $i + 1, 1);
  1646.                                             $ac3_data .= substr($testData, 8 + $i + 0, 1);
  1647.                                         }
  1648.                                         $getid3_ac3->AnalyzeString($ac3_data);
  1649.                                     }
  1650.  
  1651.                                     if (empty($getid3_temp->info['error'])) {
  1652.                                         $info['audio'] = $getid3_temp->info['audio'];
  1653.                                         $info['ac3']   = $getid3_temp->info['ac3'];
  1654.                                         if (!empty($getid3_temp->info['warning'])) {
  1655.                                             foreach ($getid3_temp->info['warning'] as $newerror) {
  1656.                                                 $this->warning('getid3_ac3() says: ['.$newerror.']');
  1657.                                             }
  1658.                                         }
  1659.                                     }
  1660.                                     unset($getid3_temp, $getid3_ac3);
  1661.  
  1662.                                 } elseif (preg_match('/^('.implode('|', array_map('preg_quote', getid3_dts::$syncwords)).')/', $testData)) {
  1663.  
  1664.                                     // This is probably DTS data
  1665.                                     $getid3_temp = new getID3();
  1666.                                     $getid3_temp->openfile($this->getid3->filename);
  1667.                                     $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
  1668.                                     $getid3_dts = new getid3_dts($getid3_temp);
  1669.                                     $getid3_dts->Analyze();
  1670.                                     if (empty($getid3_temp->info['error'])) {
  1671.                                         $info['audio']            = $getid3_temp->info['audio'];
  1672.                                         $info['dts']              = $getid3_temp->info['dts'];
  1673.                                         $info['playtime_seconds'] = $getid3_temp->info['playtime_seconds']; // may not match RIFF calculations since DTS-WAV often used 14/16 bit-word packing
  1674.                                         if (!empty($getid3_temp->info['warning'])) {
  1675.                                             foreach ($getid3_temp->info['warning'] as $newerror) {
  1676.                                                 $this->warning('getid3_dts() says: ['.$newerror.']');
  1677.                                             }
  1678.                                         }
  1679.                                     }
  1680.  
  1681.                                     unset($getid3_temp, $getid3_dts);
  1682.  
  1683.                                 } elseif (substr($testData, 0, 4) == 'wvpk') {
  1684.  
  1685.                                     // This is WavPack data
  1686.                                     $info['wavpack']['offset'] = $info['avdataoffset'];
  1687.                                     $info['wavpack']['size']   = getid3_lib::LittleEndian2Int(substr($testData, 4, 4));
  1688.                                     $this->parseWavPackHeader(substr($testData, 8, 28));
  1689.  
  1690.                                 } else {
  1691.                                     // This is some other kind of data (quite possibly just PCM)
  1692.                                     // do nothing special, just skip it
  1693.                                 }
  1694.                                 $nextoffset = $info['avdataend'];
  1695.                                 $this->fseek($nextoffset);
  1696.                                 break;
  1697.  
  1698.                             case 'iXML':
  1699.                             case 'bext':
  1700.                             case 'cart':
  1701.                             case 'fmt ':
  1702.                             case 'strh':
  1703.                             case 'strf':
  1704.                             case 'indx':
  1705.                             case 'MEXT':
  1706.                             case 'DISP':
  1707.                                 // always read data in
  1708.                             case 'JUNK':
  1709.                                 // should be: never read data in
  1710.                                 // but some programs write their version strings in a JUNK chunk (e.g. VirtualDub, AVIdemux, etc)
  1711.                                 if ($chunksize < 1048576) {
  1712.                                     if ($chunksize > 0) {
  1713.                                         $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize);
  1714.                                         if ($chunkname == 'JUNK') {
  1715.                                             if (preg_match('#^([\\x20-\\x7F]+)#', $RIFFchunk[$chunkname][$thisindex]['data'], $matches)) {
  1716.                                                 // only keep text characters [chr(32)-chr(127)]
  1717.                                                 $info['riff']['comments']['junk'][] = trim($matches[1]);
  1718.                                             }
  1719.                                             // but if nothing there, ignore
  1720.                                             // remove the key in either case
  1721.                                             unset($RIFFchunk[$chunkname][$thisindex]['data']);
  1722.                                         }
  1723.                                     }
  1724.                                 } else {
  1725.                                     $this->warning('Chunk "'.$chunkname.'" at offset '.$this->ftell().' is unexpectedly larger than 1MB (claims to be '.number_format($chunksize).' bytes), skipping data');
  1726.                                     $this->fseek($chunksize, SEEK_CUR);
  1727.                                 }
  1728.                                 break;
  1729.  
  1730.                             //case 'IDVX':
  1731.                             //    $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunksize));
  1732.                             //    break;
  1733.  
  1734.                             default:
  1735.                                 if (!empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) {
  1736.                                     $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset'];
  1737.                                     $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size']   = $RIFFchunk[$chunkname][$thisindex]['size'];
  1738.                                     unset($RIFFchunk[$chunkname][$thisindex]['offset']);
  1739.                                     unset($RIFFchunk[$chunkname][$thisindex]['size']);
  1740.                                     if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) {
  1741.                                         unset($RIFFchunk[$chunkname][$thisindex]);
  1742.                                     }
  1743.                                     if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) {
  1744.                                         unset($RIFFchunk[$chunkname]);
  1745.                                     }
  1746.                                     $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = $this->fread($chunksize);
  1747.                                 } elseif ($chunksize < 2048) {
  1748.                                     // only read data in if smaller than 2kB
  1749.                                     $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize);
  1750.                                 } else {
  1751.                                     $this->fseek($chunksize, SEEK_CUR);
  1752.                                 }
  1753.                                 break;
  1754.                         }
  1755.                         break;
  1756.                 }
  1757.             }
  1758.  
  1759.         } catch (getid3_exception $e) {
  1760.             if ($e->getCode() == 10) {
  1761.                 $this->warning('RIFF parser: '.$e->getMessage());
  1762.             } else {
  1763.                 throw $e;
  1764.             }
  1765.         }
  1766.  
  1767.         return $RIFFchunk;
  1768.     }
  1769.  
  1770.     public function ParseRIFFdata(&$RIFFdata) {
  1771.         $info = &$this->getid3->info;
  1772.         if ($RIFFdata) {
  1773.             $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3');
  1774.             $fp_temp  = fopen($tempfile, 'wb');
  1775.             $RIFFdataLength = strlen($RIFFdata);
  1776.             $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4);
  1777.             for ($i = 0; $i < 4; $i++) {
  1778.                 $RIFFdata[($i + 4)] = $NewLengthString[$i];
  1779.             }
  1780.             fwrite($fp_temp, $RIFFdata);
  1781.             fclose($fp_temp);
  1782.  
  1783.             $getid3_temp = new getID3();
  1784.             $getid3_temp->openfile($tempfile);
  1785.             $getid3_temp->info['filesize']     = $RIFFdataLength;
  1786.             $getid3_temp->info['filenamepath'] = $info['filenamepath'];
  1787.             $getid3_temp->info['tags']         = $info['tags'];
  1788.             $getid3_temp->info['warning']      = $info['warning'];
  1789.             $getid3_temp->info['error']        = $info['error'];
  1790.             $getid3_temp->info['comments']     = $info['comments'];
  1791.             $getid3_temp->info['audio']        = (isset($info['audio']) ? $info['audio'] : array());
  1792.             $getid3_temp->info['video']        = (isset($info['video']) ? $info['video'] : array());
  1793.             $getid3_riff = new getid3_riff($getid3_temp);
  1794.             $getid3_riff->Analyze();
  1795.  
  1796.             $info['riff']     = $getid3_temp->info['riff'];
  1797.             $info['warning']  = $getid3_temp->info['warning'];
  1798.             $info['error']    = $getid3_temp->info['error'];
  1799.             $info['tags']     = $getid3_temp->info['tags'];
  1800.             $info['comments'] = $getid3_temp->info['comments'];
  1801.             unset($getid3_riff, $getid3_temp);
  1802.             unlink($tempfile);
  1803.         }
  1804.         return false;
  1805.     }
  1806.  
  1807.     public static function parseComments(&$RIFFinfoArray, &$CommentsTargetArray) {
  1808.         $RIFFinfoKeyLookup = array(
  1809.             'IARL'=>'archivallocation',
  1810.             'IART'=>'artist',
  1811.             'ICDS'=>'costumedesigner',
  1812.             'ICMS'=>'commissionedby',
  1813.             'ICMT'=>'comment',
  1814.             'ICNT'=>'country',
  1815.             'ICOP'=>'copyright',
  1816.             'ICRD'=>'creationdate',
  1817.             'IDIM'=>'dimensions',
  1818.             'IDIT'=>'digitizationdate',
  1819.             'IDPI'=>'resolution',
  1820.             'IDST'=>'distributor',
  1821.             'IEDT'=>'editor',
  1822.             'IENG'=>'engineers',
  1823.             'IFRM'=>'accountofparts',
  1824.             'IGNR'=>'genre',
  1825.             'IKEY'=>'keywords',
  1826.             'ILGT'=>'lightness',
  1827.             'ILNG'=>'language',
  1828.             'IMED'=>'orignalmedium',
  1829.             'IMUS'=>'composer',
  1830.             'INAM'=>'title',
  1831.             'IPDS'=>'productiondesigner',
  1832.             'IPLT'=>'palette',
  1833.             'IPRD'=>'product',
  1834.             'IPRO'=>'producer',
  1835.             'IPRT'=>'part',
  1836.             'IRTD'=>'rating',
  1837.             'ISBJ'=>'subject',
  1838.             'ISFT'=>'software',
  1839.             'ISGN'=>'secondarygenre',
  1840.             'ISHP'=>'sharpness',
  1841.             'ISRC'=>'sourcesupplier',
  1842.             'ISRF'=>'digitizationsource',
  1843.             'ISTD'=>'productionstudio',
  1844.             'ISTR'=>'starring',
  1845.             'ITCH'=>'encoded_by',
  1846.             'IWEB'=>'url',
  1847.             'IWRI'=>'writer',
  1848.             '____'=>'comment',
  1849.         );
  1850.         foreach ($RIFFinfoKeyLookup as $key => $value) {
  1851.             if (isset($RIFFinfoArray[$key])) {
  1852.                 foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) {
  1853.                     if (trim($commentdata['data']) != '') {
  1854.                         if (isset($CommentsTargetArray[$value])) {
  1855.                             $CommentsTargetArray[$value][] =     trim($commentdata['data']);
  1856.                         } else {
  1857.                             $CommentsTargetArray[$value] = array(trim($commentdata['data']));
  1858.                         }
  1859.                     }
  1860.                 }
  1861.             }
  1862.         }
  1863.         return true;
  1864.     }
  1865.  
  1866.     public static function parseWAVEFORMATex($WaveFormatExData) {
  1867.         // shortcut
  1868.         $WaveFormatEx['raw'] = array();
  1869.         $WaveFormatEx_raw    = &$WaveFormatEx['raw'];
  1870.  
  1871.         $WaveFormatEx_raw['wFormatTag']      = substr($WaveFormatExData,  0, 2);
  1872.         $WaveFormatEx_raw['nChannels']       = substr($WaveFormatExData,  2, 2);
  1873.         $WaveFormatEx_raw['nSamplesPerSec']  = substr($WaveFormatExData,  4, 4);
  1874.         $WaveFormatEx_raw['nAvgBytesPerSec'] = substr($WaveFormatExData,  8, 4);
  1875.         $WaveFormatEx_raw['nBlockAlign']     = substr($WaveFormatExData, 12, 2);
  1876.         $WaveFormatEx_raw['wBitsPerSample']  = substr($WaveFormatExData, 14, 2);
  1877.         if (strlen($WaveFormatExData) > 16) {
  1878.             $WaveFormatEx_raw['cbSize']      = substr($WaveFormatExData, 16, 2);
  1879.         }
  1880.         $WaveFormatEx_raw = array_map('getid3_lib::LittleEndian2Int', $WaveFormatEx_raw);
  1881.  
  1882.         $WaveFormatEx['codec']           = self::wFormatTagLookup($WaveFormatEx_raw['wFormatTag']);
  1883.         $WaveFormatEx['channels']        = $WaveFormatEx_raw['nChannels'];
  1884.         $WaveFormatEx['sample_rate']     = $WaveFormatEx_raw['nSamplesPerSec'];
  1885.         $WaveFormatEx['bitrate']         = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8;
  1886.         $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample'];
  1887.  
  1888.         return $WaveFormatEx;
  1889.     }
  1890.  
  1891.     public function parseWavPackHeader($WavPackChunkData) {
  1892.         // typedef struct {
  1893.         //     char ckID [4];
  1894.         //     long ckSize;
  1895.         //     short version;
  1896.         //     short bits;                // added for version 2.00
  1897.         //     short flags, shift;        // added for version 3.00
  1898.         //     long total_samples, crc, crc2;
  1899.         //     char extension [4], extra_bc, extras [3];
  1900.         // } WavpackHeader;
  1901.  
  1902.         // shortcut
  1903.         $info = &$this->getid3->info;
  1904.         $info['wavpack']  = array();
  1905.         $thisfile_wavpack = &$info['wavpack'];
  1906.  
  1907.         $thisfile_wavpack['version']           = getid3_lib::LittleEndian2Int(substr($WavPackChunkData,  0, 2));
  1908.         if ($thisfile_wavpack['version'] >= 2) {
  1909.             $thisfile_wavpack['bits']          = getid3_lib::LittleEndian2Int(substr($WavPackChunkData,  2, 2));
  1910.         }
  1911.         if ($thisfile_wavpack['version'] >= 3) {
  1912.             $thisfile_wavpack['flags_raw']     = getid3_lib::LittleEndian2Int(substr($WavPackChunkData,  4, 2));
  1913.             $thisfile_wavpack['shift']         = getid3_lib::LittleEndian2Int(substr($WavPackChunkData,  6, 2));
  1914.             $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData,  8, 4));
  1915.             $thisfile_wavpack['crc1']          = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4));
  1916.             $thisfile_wavpack['crc2']          = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4));
  1917.             $thisfile_wavpack['extension']     =                              substr($WavPackChunkData, 20, 4);
  1918.             $thisfile_wavpack['extra_bc']      = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1));
  1919.             for ($i = 0; $i <= 2; $i++) {
  1920.                 $thisfile_wavpack['extras'][]  = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1));
  1921.             }
  1922.  
  1923.             // shortcut
  1924.             $thisfile_wavpack['flags'] = array();
  1925.             $thisfile_wavpack_flags = &$thisfile_wavpack['flags'];
  1926.  
  1927.             $thisfile_wavpack_flags['mono']                 = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001);
  1928.             $thisfile_wavpack_flags['fast_mode']            = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002);
  1929.             $thisfile_wavpack_flags['raw_mode']             = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004);
  1930.             $thisfile_wavpack_flags['calc_noise']           = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008);
  1931.             $thisfile_wavpack_flags['high_quality']         = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010);
  1932.             $thisfile_wavpack_flags['3_byte_samples']       = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020);
  1933.             $thisfile_wavpack_flags['over_20_bits']         = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040);
  1934.             $thisfile_wavpack_flags['use_wvc']              = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080);
  1935.             $thisfile_wavpack_flags['noiseshaping']         = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100);
  1936.             $thisfile_wavpack_flags['very_fast_mode']       = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200);
  1937.             $thisfile_wavpack_flags['new_high_quality']     = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400);
  1938.             $thisfile_wavpack_flags['cancel_extreme']       = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800);
  1939.             $thisfile_wavpack_flags['cross_decorrelation']  = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000);
  1940.             $thisfile_wavpack_flags['new_decorrelation']    = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000);
  1941.             $thisfile_wavpack_flags['joint_stereo']         = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000);
  1942.             $thisfile_wavpack_flags['extra_decorrelation']  = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000);
  1943.             $thisfile_wavpack_flags['override_noiseshape']  = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000);
  1944.             $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000);
  1945.             $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000);
  1946.             $thisfile_wavpack_flags['create_exe']           = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000);
  1947.         }
  1948.  
  1949.         return true;
  1950.     }
  1951.  
  1952.     public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) {
  1953.  
  1954.         $parsed['biSize']          = substr($BITMAPINFOHEADER,  0, 4); // number of bytes required by the BITMAPINFOHEADER structure
  1955.         $parsed['biWidth']         = substr($BITMAPINFOHEADER,  4, 4); // width of the bitmap in pixels
  1956.         $parsed['biHeight']        = substr($BITMAPINFOHEADER,  8, 4); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
  1957.         $parsed['biPlanes']        = substr($BITMAPINFOHEADER, 12, 2); // number of color planes on the target device. In most cases this value must be set to 1
  1958.         $parsed['biBitCount']      = substr($BITMAPINFOHEADER, 14, 2); // Specifies the number of bits per pixels
  1959.         $parsed['biSizeImage']     = substr($BITMAPINFOHEADER, 20, 4); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
  1960.         $parsed['biXPelsPerMeter'] = substr($BITMAPINFOHEADER, 24, 4); // horizontal resolution, in pixels per metre, of the target device
  1961.         $parsed['biYPelsPerMeter'] = substr($BITMAPINFOHEADER, 28, 4); // vertical resolution, in pixels per metre, of the target device
  1962.         $parsed['biClrUsed']       = substr($BITMAPINFOHEADER, 32, 4); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
  1963.         $parsed['biClrImportant']  = substr($BITMAPINFOHEADER, 36, 4); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
  1964.         $parsed = array_map('getid3_lib::'.($littleEndian ? 'Little' : 'Big').'Endian2Int', $parsed);
  1965.  
  1966.         $parsed['fourcc']          = substr($BITMAPINFOHEADER, 16, 4);  // compression identifier
  1967.  
  1968.         return $parsed;
  1969.     }
  1970.  
  1971.     public static function ParseDIVXTAG($DIVXTAG, $raw=false) {
  1972.         // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/
  1973.         // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip
  1974.         // 'Byte Layout:                   '1111111111111111
  1975.         // '32 for Movie - 1               '1111111111111111
  1976.         // '28 for Author - 6              '6666666666666666
  1977.         // '4  for year - 2                '6666666666662222
  1978.         // '3  for genre - 3               '7777777777777777
  1979.         // '48 for Comments - 7            '7777777777777777
  1980.         // '1  for Rating - 4              '7777777777777777
  1981.         // '5  for Future Additions - 0    '333400000DIVXTAG
  1982.         // '128 bytes total
  1983.  
  1984.         static $DIVXTAGgenre  = array(
  1985.              0 => 'Action',
  1986.              1 => 'Action/Adventure',
  1987.              2 => 'Adventure',
  1988.              3 => 'Adult',
  1989.              4 => 'Anime',
  1990.              5 => 'Cartoon',
  1991.              6 => 'Claymation',
  1992.              7 => 'Comedy',
  1993.              8 => 'Commercial',
  1994.              9 => 'Documentary',
  1995.             10 => 'Drama',
  1996.             11 => 'Home Video',
  1997.             12 => 'Horror',
  1998.             13 => 'Infomercial',
  1999.             14 => 'Interactive',
  2000.             15 => 'Mystery',
  2001.             16 => 'Music Video',
  2002.             17 => 'Other',
  2003.             18 => 'Religion',
  2004.             19 => 'Sci Fi',
  2005.             20 => 'Thriller',
  2006.             21 => 'Western',
  2007.         ),
  2008.         $DIVXTAGrating = array(
  2009.              0 => 'Unrated',
  2010.              1 => 'G',
  2011.              2 => 'PG',
  2012.              3 => 'PG-13',
  2013.              4 => 'R',
  2014.              5 => 'NC-17',
  2015.         );
  2016.  
  2017.         $parsed['title']     =        trim(substr($DIVXTAG,   0, 32));
  2018.         $parsed['artist']    =        trim(substr($DIVXTAG,  32, 28));
  2019.         $parsed['year']      = intval(trim(substr($DIVXTAG,  60,  4)));
  2020.         $parsed['comment']   =        trim(substr($DIVXTAG,  64, 48));
  2021.         $parsed['genre_id']  = intval(trim(substr($DIVXTAG, 112,  3)));
  2022.         $parsed['rating_id'] =         ord(substr($DIVXTAG, 115,  1));
  2023.         //$parsed['padding'] =             substr($DIVXTAG, 116,  5);  // 5-byte null
  2024.         //$parsed['magic']   =             substr($DIVXTAG, 121,  7);  // "DIVXTAG"
  2025.  
  2026.         $parsed['genre']  = (isset($DIVXTAGgenre[$parsed['genre_id']])   ? $DIVXTAGgenre[$parsed['genre_id']]   : $parsed['genre_id']);
  2027.         $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']);
  2028.  
  2029.         if (!$raw) {
  2030.             unset($parsed['genre_id'], $parsed['rating_id']);
  2031.             foreach ($parsed as $key => $value) {
  2032.                 if (!$value === '') {
  2033.                     unset($parsed['key']);
  2034.                 }
  2035.             }
  2036.         }
  2037.  
  2038.         foreach ($parsed as $tag => $value) {
  2039.             $parsed[$tag] = array($value);
  2040.         }
  2041.  
  2042.         return $parsed;
  2043.     }
  2044.  
  2045.     public static function waveSNDMtagLookup($tagshortname) {
  2046.         $begin = __LINE__;
  2047.  
  2048.         /** This is not a comment!
  2049.  
  2050.             ┬⌐kwd    keywords
  2051.             ┬⌐BPM    bpm
  2052.             ┬⌐trt    tracktitle
  2053.             ┬⌐des    description
  2054.             ┬⌐gen    category
  2055.             ┬⌐fin    featuredinstrument
  2056.             ┬⌐LID    longid
  2057.             ┬⌐bex    bwdescription
  2058.             ┬⌐pub    publisher
  2059.             ┬⌐cdt    cdtitle
  2060.             ┬⌐alb    library
  2061.             ┬⌐com    composer
  2062.  
  2063.         */
  2064.  
  2065.         return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm');
  2066.     }
  2067.  
  2068.     public static function wFormatTagLookup($wFormatTag) {
  2069.  
  2070.         $begin = __LINE__;
  2071.  
  2072.         /** This is not a comment!
  2073.  
  2074.             0x0000    Microsoft Unknown Wave Format
  2075.             0x0001    Pulse Code Modulation (PCM)
  2076.             0x0002    Microsoft ADPCM
  2077.             0x0003    IEEE Float
  2078.             0x0004    Compaq Computer VSELP
  2079.             0x0005    IBM CVSD
  2080.             0x0006    Microsoft A-Law
  2081.             0x0007    Microsoft mu-Law
  2082.             0x0008    Microsoft DTS
  2083.             0x0010    OKI ADPCM
  2084.             0x0011    Intel DVI/IMA ADPCM
  2085.             0x0012    Videologic MediaSpace ADPCM
  2086.             0x0013    Sierra Semiconductor ADPCM
  2087.             0x0014    Antex Electronics G.723 ADPCM
  2088.             0x0015    DSP Solutions DigiSTD
  2089.             0x0016    DSP Solutions DigiFIX
  2090.             0x0017    Dialogic OKI ADPCM
  2091.             0x0018    MediaVision ADPCM
  2092.             0x0019    Hewlett-Packard CU
  2093.             0x0020    Yamaha ADPCM
  2094.             0x0021    Speech Compression Sonarc
  2095.             0x0022    DSP Group TrueSpeech
  2096.             0x0023    Echo Speech EchoSC1
  2097.             0x0024    Audiofile AF36
  2098.             0x0025    Audio Processing Technology APTX
  2099.             0x0026    AudioFile AF10
  2100.             0x0027    Prosody 1612
  2101.             0x0028    LRC
  2102.             0x0030    Dolby AC2
  2103.             0x0031    Microsoft GSM 6.10
  2104.             0x0032    MSNAudio
  2105.             0x0033    Antex Electronics ADPCME
  2106.             0x0034    Control Resources VQLPC
  2107.             0x0035    DSP Solutions DigiREAL
  2108.             0x0036    DSP Solutions DigiADPCM
  2109.             0x0037    Control Resources CR10
  2110.             0x0038    Natural MicroSystems VBXADPCM
  2111.             0x0039    Crystal Semiconductor IMA ADPCM
  2112.             0x003A    EchoSC3
  2113.             0x003B    Rockwell ADPCM
  2114.             0x003C    Rockwell Digit LK
  2115.             0x003D    Xebec
  2116.             0x0040    Antex Electronics G.721 ADPCM
  2117.             0x0041    G.728 CELP
  2118.             0x0042    MSG723
  2119.             0x0050    MPEG Layer-2 or Layer-1
  2120.             0x0052    RT24
  2121.             0x0053    PAC
  2122.             0x0055    MPEG Layer-3
  2123.             0x0059    Lucent G.723
  2124.             0x0060    Cirrus
  2125.             0x0061    ESPCM
  2126.             0x0062    Voxware
  2127.             0x0063    Canopus Atrac
  2128.             0x0064    G.726 ADPCM
  2129.             0x0065    G.722 ADPCM
  2130.             0x0066    DSAT
  2131.             0x0067    DSAT Display
  2132.             0x0069    Voxware Byte Aligned
  2133.             0x0070    Voxware AC8
  2134.             0x0071    Voxware AC10
  2135.             0x0072    Voxware AC16
  2136.             0x0073    Voxware AC20
  2137.             0x0074    Voxware MetaVoice
  2138.             0x0075    Voxware MetaSound
  2139.             0x0076    Voxware RT29HW
  2140.             0x0077    Voxware VR12
  2141.             0x0078    Voxware VR18
  2142.             0x0079    Voxware TQ40
  2143.             0x0080    Softsound
  2144.             0x0081    Voxware TQ60
  2145.             0x0082    MSRT24
  2146.             0x0083    G.729A
  2147.             0x0084    MVI MV12
  2148.             0x0085    DF G.726
  2149.             0x0086    DF GSM610
  2150.             0x0088    ISIAudio
  2151.             0x0089    Onlive
  2152.             0x0091    SBC24
  2153.             0x0092    Dolby AC3 SPDIF
  2154.             0x0093    MediaSonic G.723
  2155.             0x0094    Aculab PLC    Prosody 8kbps
  2156.             0x0097    ZyXEL ADPCM
  2157.             0x0098    Philips LPCBB
  2158.             0x0099    Packed
  2159.             0x00FF    AAC
  2160.             0x0100    Rhetorex ADPCM
  2161.             0x0101    IBM mu-law
  2162.             0x0102    IBM A-law
  2163.             0x0103    IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM)
  2164.             0x0111    Vivo G.723
  2165.             0x0112    Vivo Siren
  2166.             0x0123    Digital G.723
  2167.             0x0125    Sanyo LD ADPCM
  2168.             0x0130    Sipro Lab Telecom ACELP NET
  2169.             0x0131    Sipro Lab Telecom ACELP 4800
  2170.             0x0132    Sipro Lab Telecom ACELP 8V3
  2171.             0x0133    Sipro Lab Telecom G.729
  2172.             0x0134    Sipro Lab Telecom G.729A
  2173.             0x0135    Sipro Lab Telecom Kelvin
  2174.             0x0140    Windows Media Video V8
  2175.             0x0150    Qualcomm PureVoice
  2176.             0x0151    Qualcomm HalfRate
  2177.             0x0155    Ring Zero Systems TUB GSM
  2178.             0x0160    Microsoft Audio 1
  2179.             0x0161    Windows Media Audio V7 / V8 / V9
  2180.             0x0162    Windows Media Audio Professional V9
  2181.             0x0163    Windows Media Audio Lossless V9
  2182.             0x0200    Creative Labs ADPCM
  2183.             0x0202    Creative Labs Fastspeech8
  2184.             0x0203    Creative Labs Fastspeech10
  2185.             0x0210    UHER Informatic GmbH ADPCM
  2186.             0x0220    Quarterdeck
  2187.             0x0230    I-link Worldwide VC
  2188.             0x0240    Aureal RAW Sport
  2189.             0x0250    Interactive Products HSX
  2190.             0x0251    Interactive Products RPELP
  2191.             0x0260    Consistent Software CS2
  2192.             0x0270    Sony SCX
  2193.             0x0300    Fujitsu FM Towns Snd
  2194.             0x0400    BTV Digital
  2195.             0x0401    Intel Music Coder
  2196.             0x0450    QDesign Music
  2197.             0x0680    VME VMPCM
  2198.             0x0681    AT&T Labs TPC
  2199.             0x08AE    ClearJump LiteWave
  2200.             0x1000    Olivetti GSM
  2201.             0x1001    Olivetti ADPCM
  2202.             0x1002    Olivetti CELP
  2203.             0x1003    Olivetti SBC
  2204.             0x1004    Olivetti OPR
  2205.             0x1100    Lernout & Hauspie Codec (0x1100)
  2206.             0x1101    Lernout & Hauspie CELP Codec (0x1101)
  2207.             0x1102    Lernout & Hauspie SBC Codec (0x1102)
  2208.             0x1103    Lernout & Hauspie SBC Codec (0x1103)
  2209.             0x1104    Lernout & Hauspie SBC Codec (0x1104)
  2210.             0x1400    Norris
  2211.             0x1401    AT&T ISIAudio
  2212.             0x1500    Soundspace Music Compression
  2213.             0x181C    VoxWare RT24 Speech
  2214.             0x1FC4    NCT Soft ALF2CD (www.nctsoft.com)
  2215.             0x2000    Dolby AC3
  2216.             0x2001    Dolby DTS
  2217.             0x2002    WAVE_FORMAT_14_4
  2218.             0x2003    WAVE_FORMAT_28_8
  2219.             0x2004    WAVE_FORMAT_COOK
  2220.             0x2005    WAVE_FORMAT_DNET
  2221.             0x674F    Ogg Vorbis 1
  2222.             0x6750    Ogg Vorbis 2
  2223.             0x6751    Ogg Vorbis 3
  2224.             0x676F    Ogg Vorbis 1+
  2225.             0x6770    Ogg Vorbis 2+
  2226.             0x6771    Ogg Vorbis 3+
  2227.             0x7A21    GSM-AMR (CBR, no SID)
  2228.             0x7A22    GSM-AMR (VBR, including SID)
  2229.             0xFFFE    WAVE_FORMAT_EXTENSIBLE
  2230.             0xFFFF    WAVE_FORMAT_DEVELOPMENT
  2231.  
  2232.         */
  2233.  
  2234.         return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag');
  2235.     }
  2236.  
  2237.     public static function fourccLookup($fourcc) {
  2238.  
  2239.         $begin = __LINE__;
  2240.  
  2241.         /** This is not a comment!
  2242.  
  2243.             swot    http://developer.apple.com/qa/snd/snd07.html
  2244.             ____    No Codec (____)
  2245.             _BIT    BI_BITFIELDS (Raw RGB)
  2246.             _JPG    JPEG compressed
  2247.             _PNG    PNG compressed W3C/ISO/IEC (RFC-2083)
  2248.             _RAW    Full Frames (Uncompressed)
  2249.             _RGB    Raw RGB Bitmap
  2250.             _RL4    RLE 4bpp RGB
  2251.             _RL8    RLE 8bpp RGB
  2252.             3IV1    3ivx MPEG-4 v1
  2253.             3IV2    3ivx MPEG-4 v2
  2254.             3IVX    3ivx MPEG-4
  2255.             AASC    Autodesk Animator
  2256.             ABYR    Kensington ?ABYR?
  2257.             AEMI    Array Microsystems VideoONE MPEG1-I Capture
  2258.             AFLC    Autodesk Animator FLC
  2259.             AFLI    Autodesk Animator FLI
  2260.             AMPG    Array Microsystems VideoONE MPEG
  2261.             ANIM    Intel RDX (ANIM)
  2262.             AP41    AngelPotion Definitive
  2263.             ASV1    Asus Video v1
  2264.             ASV2    Asus Video v2
  2265.             ASVX    Asus Video 2.0 (audio)
  2266.             AUR2    AuraVision Aura 2 Codec - YUV 4:2:2
  2267.             AURA    AuraVision Aura 1 Codec - YUV 4:1:1
  2268.             AVDJ    Independent JPEG Group\'s codec (AVDJ)
  2269.             AVRN    Independent JPEG Group\'s codec (AVRN)
  2270.             AYUV    4:4:4 YUV (AYUV)
  2271.             AZPR    Quicktime Apple Video (AZPR)
  2272.             BGR     Raw RGB32
  2273.             BLZ0    Blizzard DivX MPEG-4
  2274.             BTVC    Conexant Composite Video
  2275.             BINK    RAD Game Tools Bink Video
  2276.             BT20    Conexant Prosumer Video
  2277.             BTCV    Conexant Composite Video Codec
  2278.             BW10    Data Translation Broadway MPEG Capture
  2279.             CC12    Intel YUV12
  2280.             CDVC    Canopus DV
  2281.             CFCC    Digital Processing Systems DPS Perception
  2282.             CGDI    Microsoft Office 97 Camcorder Video
  2283.             CHAM    Winnov Caviara Champagne
  2284.             CJPG    Creative WebCam JPEG
  2285.             CLJR    Cirrus Logic YUV 4:1:1
  2286.             CMYK    Common Data Format in Printing (Colorgraph)
  2287.             CPLA    Weitek 4:2:0 YUV Planar
  2288.             CRAM    Microsoft Video 1 (CRAM)
  2289.             cvid    Radius Cinepak
  2290.             CVID    Radius Cinepak
  2291.             CWLT    Microsoft Color WLT DIB
  2292.             CYUV    Creative Labs YUV
  2293.             CYUY    ATI YUV
  2294.             D261    H.261
  2295.             D263    H.263
  2296.             DIB     Device Independent Bitmap
  2297.             DIV1    FFmpeg OpenDivX
  2298.             DIV2    Microsoft MPEG-4 v1/v2
  2299.             DIV3    DivX ;-) MPEG-4 v3.x Low-Motion
  2300.             DIV4    DivX ;-) MPEG-4 v3.x Fast-Motion
  2301.             DIV5    DivX MPEG-4 v5.x
  2302.             DIV6    DivX ;-) (MS MPEG-4 v3.x)
  2303.             DIVX    DivX MPEG-4 v4 (OpenDivX / Project Mayo)
  2304.             divx    DivX MPEG-4
  2305.             DMB1    Matrox Rainbow Runner hardware MJPEG
  2306.             DMB2    Paradigm MJPEG
  2307.             DSVD    ?DSVD?
  2308.             DUCK    Duck TrueMotion 1.0
  2309.             DPS0    DPS/Leitch Reality Motion JPEG
  2310.             DPSC    DPS/Leitch PAR Motion JPEG
  2311.             DV25    Matrox DVCPRO codec
  2312.             DV50    Matrox DVCPRO50 codec
  2313.             DVC     IEC 61834 and SMPTE 314M (DVC/DV Video)
  2314.             DVCP    IEC 61834 and SMPTE 314M (DVC/DV Video)
  2315.             DVHD    IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps
  2316.             DVMA    Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com)
  2317.             DVSL    IEC Standard DV compressed in SD (SDL)
  2318.             DVAN    ?DVAN?
  2319.             DVE2    InSoft DVE-2 Videoconferencing
  2320.             dvsd    IEC 61834 and SMPTE 314M DVC/DV Video
  2321.             DVSD    IEC 61834 and SMPTE 314M DVC/DV Video
  2322.             DVX1    Lucent DVX1000SP Video Decoder
  2323.             DVX2    Lucent DVX2000S Video Decoder
  2324.             DVX3    Lucent DVX3000S Video Decoder
  2325.             DX50    DivX v5
  2326.             DXT1    Microsoft DirectX Compressed Texture (DXT1)
  2327.             DXT2    Microsoft DirectX Compressed Texture (DXT2)
  2328.             DXT3    Microsoft DirectX Compressed Texture (DXT3)
  2329.             DXT4    Microsoft DirectX Compressed Texture (DXT4)
  2330.             DXT5    Microsoft DirectX Compressed Texture (DXT5)
  2331.             DXTC    Microsoft DirectX Compressed Texture (DXTC)
  2332.             DXTn    Microsoft DirectX Compressed Texture (DXTn)
  2333.             EM2V    Etymonix MPEG-2 I-frame (www.etymonix.com)
  2334.             EKQ0    Elsa ?EKQ0?
  2335.             ELK0    Elsa ?ELK0?
  2336.             ESCP    Eidos Escape
  2337.             ETV1    eTreppid Video ETV1
  2338.             ETV2    eTreppid Video ETV2
  2339.             ETVC    eTreppid Video ETVC
  2340.             FLIC    Autodesk FLI/FLC Animation
  2341.             FLV1    Sorenson Spark
  2342.             FLV4    On2 TrueMotion VP6
  2343.             FRWT    Darim Vision Forward Motion JPEG (www.darvision.com)
  2344.             FRWU    Darim Vision Forward Uncompressed (www.darvision.com)
  2345.             FLJP    D-Vision Field Encoded Motion JPEG
  2346.             FPS1    FRAPS v1
  2347.             FRWA    SoftLab-Nsk Forward Motion JPEG w/ alpha channel
  2348.             FRWD    SoftLab-Nsk Forward Motion JPEG
  2349.             FVF1    Iterated Systems Fractal Video Frame
  2350.             GLZW    Motion LZW (gabest@freemail.hu)
  2351.             GPEG    Motion JPEG (gabest@freemail.hu)
  2352.             GWLT    Microsoft Greyscale WLT DIB
  2353.             H260    Intel ITU H.260 Videoconferencing
  2354.             H261    Intel ITU H.261 Videoconferencing
  2355.             H262    Intel ITU H.262 Videoconferencing
  2356.             H263    Intel ITU H.263 Videoconferencing
  2357.             H264    Intel ITU H.264 Videoconferencing
  2358.             H265    Intel ITU H.265 Videoconferencing
  2359.             H266    Intel ITU H.266 Videoconferencing
  2360.             H267    Intel ITU H.267 Videoconferencing
  2361.             H268    Intel ITU H.268 Videoconferencing
  2362.             H269    Intel ITU H.269 Videoconferencing
  2363.             HFYU    Huffman Lossless Codec
  2364.             HMCR    Rendition Motion Compensation Format (HMCR)
  2365.             HMRR    Rendition Motion Compensation Format (HMRR)
  2366.             I263    FFmpeg I263 decoder
  2367.             IF09    Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane")
  2368.             IUYV    Interlaced version of UYVY (www.leadtools.com)
  2369.             IY41    Interlaced version of Y41P (www.leadtools.com)
  2370.             IYU1    12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec    IEEE standard
  2371.             IYU2    24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec    IEEE standard
  2372.             IYUV    Planar YUV format (8-bpp Y plane, followed by 8-bpp 2├ù2 U and V planes)
  2373.             i263    Intel ITU H.263 Videoconferencing (i263)
  2374.             I420    Intel Indeo 4
  2375.             IAN     Intel Indeo 4 (RDX)
  2376.             ICLB    InSoft CellB Videoconferencing
  2377.             IGOR    Power DVD
  2378.             IJPG    Intergraph JPEG
  2379.             ILVC    Intel Layered Video
  2380.             ILVR    ITU-T H.263+
  2381.             IPDV    I-O Data Device Giga AVI DV Codec
  2382.             IR21    Intel Indeo 2.1
  2383.             IRAW    Intel YUV Uncompressed
  2384.             IV30    Intel Indeo 3.0
  2385.             IV31    Intel Indeo 3.1
  2386.             IV32    Ligos Indeo 3.2
  2387.             IV33    Ligos Indeo 3.3
  2388.             IV34    Ligos Indeo 3.4
  2389.             IV35    Ligos Indeo 3.5
  2390.             IV36    Ligos Indeo 3.6
  2391.             IV37    Ligos Indeo 3.7
  2392.             IV38    Ligos Indeo 3.8
  2393.             IV39    Ligos Indeo 3.9
  2394.             IV40    Ligos Indeo Interactive 4.0
  2395.             IV41    Ligos Indeo Interactive 4.1
  2396.             IV42    Ligos Indeo Interactive 4.2
  2397.             IV43    Ligos Indeo Interactive 4.3
  2398.             IV44    Ligos Indeo Interactive 4.4
  2399.             IV45    Ligos Indeo Interactive 4.5
  2400.             IV46    Ligos Indeo Interactive 4.6
  2401.             IV47    Ligos Indeo Interactive 4.7
  2402.             IV48    Ligos Indeo Interactive 4.8
  2403.             IV49    Ligos Indeo Interactive 4.9
  2404.             IV50    Ligos Indeo Interactive 5.0
  2405.             JBYR    Kensington ?JBYR?
  2406.             JPEG    Still Image JPEG DIB
  2407.             JPGL    Pegasus Lossless Motion JPEG
  2408.             KMVC    Team17 Software Karl Morton\'s Video Codec
  2409.             LSVM    Vianet Lighting Strike Vmail (Streaming) (www.vianet.com)
  2410.             LEAD    LEAD Video Codec
  2411.             Ljpg    LEAD MJPEG Codec
  2412.             MDVD    Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de)
  2413.             MJPA    Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com)
  2414.             MJPB    Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com)
  2415.             MMES    Matrox MPEG-2 I-frame
  2416.             MP2v    Microsoft S-Mpeg 4 version 1 (MP2v)
  2417.             MP42    Microsoft S-Mpeg 4 version 2 (MP42)
  2418.             MP43    Microsoft S-Mpeg 4 version 3 (MP43)
  2419.             MP4S    Microsoft S-Mpeg 4 version 3 (MP4S)
  2420.             MP4V    FFmpeg MPEG-4
  2421.             MPG1    FFmpeg MPEG 1/2
  2422.             MPG2    FFmpeg MPEG 1/2
  2423.             MPG3    FFmpeg DivX ;-) (MS MPEG-4 v3)
  2424.             MPG4    Microsoft MPEG-4
  2425.             MPGI    Sigma Designs MPEG
  2426.             MPNG    PNG images decoder
  2427.             MSS1    Microsoft Windows Screen Video
  2428.             MSZH    LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
  2429.             M261    Microsoft H.261
  2430.             M263    Microsoft H.263
  2431.             M4S2    Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2)
  2432.             m4s2    Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2)
  2433.             MC12    ATI Motion Compensation Format (MC12)
  2434.             MCAM    ATI Motion Compensation Format (MCAM)
  2435.             MJ2C    Morgan Multimedia Motion JPEG2000
  2436.             mJPG    IBM Motion JPEG w/ Huffman Tables
  2437.             MJPG    Microsoft Motion JPEG DIB
  2438.             MP42    Microsoft MPEG-4 (low-motion)
  2439.             MP43    Microsoft MPEG-4 (fast-motion)
  2440.             MP4S    Microsoft MPEG-4 (MP4S)
  2441.             mp4s    Microsoft MPEG-4 (mp4s)
  2442.             MPEG    Chromatic Research MPEG-1 Video I-Frame
  2443.             MPG4    Microsoft MPEG-4 Video High Speed Compressor
  2444.             MPGI    Sigma Designs MPEG
  2445.             MRCA    FAST Multimedia Martin Regen Codec
  2446.             MRLE    Microsoft Run Length Encoding
  2447.             MSVC    Microsoft Video 1
  2448.             MTX1    Matrox ?MTX1?
  2449.             MTX2    Matrox ?MTX2?
  2450.             MTX3    Matrox ?MTX3?
  2451.             MTX4    Matrox ?MTX4?
  2452.             MTX5    Matrox ?MTX5?
  2453.             MTX6    Matrox ?MTX6?
  2454.             MTX7    Matrox ?MTX7?
  2455.             MTX8    Matrox ?MTX8?
  2456.             MTX9    Matrox ?MTX9?
  2457.             MV12    Motion Pixels Codec (old)
  2458.             MWV1    Aware Motion Wavelets
  2459.             nAVI    SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm)
  2460.             NT00    NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com)
  2461.             NUV1    NuppelVideo
  2462.             NTN1    Nogatech Video Compression 1
  2463.             NVS0    nVidia GeForce Texture (NVS0)
  2464.             NVS1    nVidia GeForce Texture (NVS1)
  2465.             NVS2    nVidia GeForce Texture (NVS2)
  2466.             NVS3    nVidia GeForce Texture (NVS3)
  2467.             NVS4    nVidia GeForce Texture (NVS4)
  2468.             NVS5    nVidia GeForce Texture (NVS5)
  2469.             NVT0    nVidia GeForce Texture (NVT0)
  2470.             NVT1    nVidia GeForce Texture (NVT1)
  2471.             NVT2    nVidia GeForce Texture (NVT2)
  2472.             NVT3    nVidia GeForce Texture (NVT3)
  2473.             NVT4    nVidia GeForce Texture (NVT4)
  2474.             NVT5    nVidia GeForce Texture (NVT5)
  2475.             PIXL    MiroXL, Pinnacle PCTV
  2476.             PDVC    I-O Data Device Digital Video Capture DV codec
  2477.             PGVV    Radius Video Vision
  2478.             PHMO    IBM Photomotion
  2479.             PIM1    MPEG Realtime (Pinnacle Cards)
  2480.             PIM2    Pegasus Imaging ?PIM2?
  2481.             PIMJ    Pegasus Imaging Lossless JPEG
  2482.             PVEZ    Horizons Technology PowerEZ
  2483.             PVMM    PacketVideo Corporation MPEG-4
  2484.             PVW2    Pegasus Imaging Wavelet Compression
  2485.             Q1.0    Q-Team\'s QPEG 1.0 (www.q-team.de)
  2486.             Q1.1    Q-Team\'s QPEG 1.1 (www.q-team.de)
  2487.             QPEG    Q-Team QPEG 1.0
  2488.             qpeq    Q-Team QPEG 1.1
  2489.             RGB     Raw BGR32
  2490.             RGBA    Raw RGB w/ Alpha
  2491.             RMP4    REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com)
  2492.             ROQV    Id RoQ File Video Decoder
  2493.             RPZA    Quicktime Apple Video (RPZA)
  2494.             RUD0    Rududu video codec (http://rududu.ifrance.com/rududu/)
  2495.             RV10    RealVideo 1.0 (aka RealVideo 5.0)
  2496.             RV13    RealVideo 1.0 (RV13)
  2497.             RV20    RealVideo G2
  2498.             RV30    RealVideo 8
  2499.             RV40    RealVideo 9
  2500.             RGBT    Raw RGB w/ Transparency
  2501.             RLE     Microsoft Run Length Encoder
  2502.             RLE4    Run Length Encoded (4bpp, 16-color)
  2503.             RLE8    Run Length Encoded (8bpp, 256-color)
  2504.             RT21    Intel Indeo RealTime Video 2.1
  2505.             rv20    RealVideo G2
  2506.             rv30    RealVideo 8
  2507.             RVX     Intel RDX (RVX )
  2508.             SMC     Apple Graphics (SMC )
  2509.             SP54    Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2
  2510.             SPIG    Radius Spigot
  2511.             SVQ3    Sorenson Video 3 (Apple Quicktime 5)
  2512.             s422    Tekram VideoCap C210 YUV 4:2:2
  2513.             SDCC    Sun Communication Digital Camera Codec
  2514.             SFMC    CrystalNet Surface Fitting Method
  2515.             SMSC    Radius SMSC
  2516.             SMSD    Radius SMSD
  2517.             smsv    WorldConnect Wavelet Video
  2518.             SPIG    Radius Spigot
  2519.             SPLC    Splash Studios ACM Audio Codec (www.splashstudios.net)
  2520.             SQZ2    Microsoft VXTreme Video Codec V2
  2521.             STVA    ST Microelectronics CMOS Imager Data (Bayer)
  2522.             STVB    ST Microelectronics CMOS Imager Data (Nudged Bayer)
  2523.             STVC    ST Microelectronics CMOS Imager Data (Bunched)
  2524.             STVX    ST Microelectronics CMOS Imager Data (Extended CODEC Data Format)
  2525.             STVY    ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data)
  2526.             SV10    Sorenson Video R1
  2527.             SVQ1    Sorenson Video
  2528.             T420    Toshiba YUV 4:2:0
  2529.             TM2A    Duck TrueMotion Archiver 2.0 (www.duck.com)
  2530.             TVJP    Pinnacle/Truevision Targa 2000 board (TVJP)
  2531.             TVMJ    Pinnacle/Truevision Targa 2000 board (TVMJ)
  2532.             TY0N    Tecomac Low-Bit Rate Codec (www.tecomac.com)
  2533.             TY2C    Trident Decompression Driver
  2534.             TLMS    TeraLogic Motion Intraframe Codec (TLMS)
  2535.             TLST    TeraLogic Motion Intraframe Codec (TLST)
  2536.             TM20    Duck TrueMotion 2.0
  2537.             TM2X    Duck TrueMotion 2X
  2538.             TMIC    TeraLogic Motion Intraframe Codec (TMIC)
  2539.             TMOT    Horizons Technology TrueMotion S
  2540.             tmot    Horizons TrueMotion Video Compression
  2541.             TR20    Duck TrueMotion RealTime 2.0
  2542.             TSCC    TechSmith Screen Capture Codec
  2543.             TV10    Tecomac Low-Bit Rate Codec
  2544.             TY2N    Trident ?TY2N?
  2545.             U263    UB Video H.263/H.263+/H.263++ Decoder
  2546.             UMP4    UB Video MPEG 4 (www.ubvideo.com)
  2547.             UYNV    Nvidia UYVY packed 4:2:2
  2548.             UYVP    Evans & Sutherland YCbCr 4:2:2 extended precision
  2549.             UCOD    eMajix.com ClearVideo
  2550.             ULTI    IBM Ultimotion
  2551.             UYVY    UYVY packed 4:2:2
  2552.             V261    Lucent VX2000S
  2553.             VIFP    VFAPI Reader Codec (www.yks.ne.jp/~hori/)
  2554.             VIV1    FFmpeg H263+ decoder
  2555.             VIV2    Vivo H.263
  2556.             VQC2    Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf)
  2557.             VTLP    Alaris VideoGramPiX
  2558.             VYU9    ATI YUV (VYU9)
  2559.             VYUY    ATI YUV (VYUY)
  2560.             V261    Lucent VX2000S
  2561.             V422    Vitec Multimedia 24-bit YUV 4:2:2 Format
  2562.             V655    Vitec Multimedia 16-bit YUV 4:2:2 Format
  2563.             VCR1    ATI Video Codec 1
  2564.             VCR2    ATI Video Codec 2
  2565.             VCR3    ATI VCR 3.0
  2566.             VCR4    ATI VCR 4.0
  2567.             VCR5    ATI VCR 5.0
  2568.             VCR6    ATI VCR 6.0
  2569.             VCR7    ATI VCR 7.0
  2570.             VCR8    ATI VCR 8.0
  2571.             VCR9    ATI VCR 9.0
  2572.             VDCT    Vitec Multimedia Video Maker Pro DIB
  2573.             VDOM    VDOnet VDOWave
  2574.             VDOW    VDOnet VDOLive (H.263)
  2575.             VDTZ    Darim Vison VideoTizer YUV
  2576.             VGPX    Alaris VideoGramPiX
  2577.             VIDS    Vitec Multimedia YUV 4:2:2 CCIR 601 for V422
  2578.             VIVO    Vivo H.263 v2.00
  2579.             vivo    Vivo H.263
  2580.             VIXL    Miro/Pinnacle Video XL
  2581.             VLV1    VideoLogic/PURE Digital Videologic Capture
  2582.             VP30    On2 VP3.0
  2583.             VP31    On2 VP3.1
  2584.             VP6F    On2 TrueMotion VP6
  2585.             VX1K    Lucent VX1000S Video Codec
  2586.             VX2K    Lucent VX2000S Video Codec
  2587.             VXSP    Lucent VX1000SP Video Codec
  2588.             WBVC    Winbond W9960
  2589.             WHAM    Microsoft Video 1 (WHAM)
  2590.             WINX    Winnov Software Compression
  2591.             WJPG    AverMedia Winbond JPEG
  2592.             WMV1    Windows Media Video V7
  2593.             WMV2    Windows Media Video V8
  2594.             WMV3    Windows Media Video V9
  2595.             WNV1    Winnov Hardware Compression
  2596.             XYZP    Extended PAL format XYZ palette (www.riff.org)
  2597.             x263    Xirlink H.263
  2598.             XLV0    NetXL Video Decoder
  2599.             XMPG    Xing MPEG (I-Frame only)
  2600.             XVID    XviD MPEG-4 (www.xvid.org)
  2601.             XXAN    ?XXAN?
  2602.             YU92    Intel YUV (YU92)
  2603.             YUNV    Nvidia Uncompressed YUV 4:2:2
  2604.             YUVP    Extended PAL format YUV palette (www.riff.org)
  2605.             Y211    YUV 2:1:1 Packed
  2606.             Y411    YUV 4:1:1 Packed
  2607.             Y41B    Weitek YUV 4:1:1 Planar
  2608.             Y41P    Brooktree PC1 YUV 4:1:1 Packed
  2609.             Y41T    Brooktree PC1 YUV 4:1:1 with transparency
  2610.             Y42B    Weitek YUV 4:2:2 Planar
  2611.             Y42T    Brooktree UYUV 4:2:2 with transparency
  2612.             Y422    ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera
  2613.             Y800    Simple, single Y plane for monochrome images
  2614.             Y8      Grayscale video
  2615.             YC12    Intel YUV 12 codec
  2616.             YUV8    Winnov Caviar YUV8
  2617.             YUV9    Intel YUV9
  2618.             YUY2    Uncompressed YUV 4:2:2
  2619.             YUYV    Canopus YUV
  2620.             YV12    YVU12 Planar
  2621.             YVU9    Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes)
  2622.             YVYU    YVYU 4:2:2 Packed
  2623.             ZLIB    Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)
  2624.             ZPEG    Metheus Video Zipper
  2625.  
  2626.         */
  2627.  
  2628.         return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc');
  2629.     }
  2630.  
  2631.     private function EitherEndian2Int($byteword, $signed=false) {
  2632.         if ($this->container == 'riff') {
  2633.             return getid3_lib::LittleEndian2Int($byteword, $signed);
  2634.         }
  2635.         return getid3_lib::BigEndian2Int($byteword, false, $signed);
  2636.     }
  2637.  
  2638. }
  2639.