Example #1
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->include_module('audio-video.riff');
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $shn_header = fread($getid3->fp, 8);
     // Magic bytes: "ajkg"
     $getid3->info['fileformat'] = 'shn';
     $getid3->info['audio']['dataformat'] = 'shn';
     $getid3->info['audio']['lossless'] = true;
     $getid3->info['audio']['bitrate_mode'] = 'vbr';
     $getid3->info['shn']['version'] = getid3_lib::LittleEndian2Int($shn_header[4]);
     fseek($getid3->fp, $getid3->info['avdataend'] - 12, SEEK_SET);
     $seek_table_signature_test = fread($getid3->fp, 12);
     $getid3->info['shn']['seektable']['present'] = (bool) (substr($seek_table_signature_test, 4, 8) == 'SHNAMPSK');
     if ($getid3->info['shn']['seektable']['present']) {
         $getid3->info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($seek_table_signature_test, 0, 4));
         $getid3->info['shn']['seektable']['offset'] = $getid3->info['avdataend'] - $getid3->info['shn']['seektable']['length'];
         fseek($getid3->fp, $getid3->info['shn']['seektable']['offset'], SEEK_SET);
         $seek_table_magic = fread($getid3->fp, 4);
         if ($seek_table_magic != 'SEEK') {
             throw new getid3_exception('Expecting "SEEK" at offset ' . $getid3->info['shn']['seektable']['offset'] . ', found "' . $seek_table_magic . '"');
         }
         $seek_table_data = fread($getid3->fp, $getid3->info['shn']['seektable']['length'] - 16);
         $getid3->info['shn']['seektable']['entry_count'] = floor(strlen($seek_table_data) / 80);
     }
     $commandline = 'shorten -x ' . escapeshellarg(realpath($getid3->filename)) . ' - | head -c 64';
     $output = `{$commandline}`;
     if (@$output && substr($output, 12, 4) == 'fmt ') {
         $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4));
         $decoded_wav_format_ex = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size));
         $getid3->info['audio']['channels'] = $decoded_wav_format_ex['channels'];
         $getid3->info['audio']['bits_per_sample'] = $decoded_wav_format_ex['bits_per_sample'];
         $getid3->info['audio']['sample_rate'] = $decoded_wav_format_ex['sample_rate'];
         if (substr($output, 20 + $fmt_size, 4) == 'data') {
             $getid3->info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $decoded_wav_format_ex['raw']['nAvgBytesPerSec'];
         } else {
             throw new getid3_exception('shorten failed to decode DATA chunk to expected location, cannot determine playtime');
         }
         $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['playtime_seconds'] * 8;
     } else {
         throw new getid3_exception('shorten failed to decode file to WAV for parsing');
         return false;
     }
     return true;
 }
 public function ParseRIFFdata(&$RIFFdata)
 {
     $info =& $this->getid3->info;
     if ($RIFFdata) {
         $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3');
         $fp_temp = fopen($tempfile, 'wb');
         $RIFFdataLength = strlen($RIFFdata);
         $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4);
         for ($i = 0; $i < 4; $i++) {
             $RIFFdata[$i + 4] = $NewLengthString[$i];
         }
         fwrite($fp_temp, $RIFFdata);
         fclose($fp_temp);
         $getid3_temp = new getID3();
         $getid3_temp->openfile($tempfile);
         $getid3_temp->info['filesize'] = $RIFFdataLength;
         $getid3_temp->info['filenamepath'] = $info['filenamepath'];
         $getid3_temp->info['tags'] = $info['tags'];
         $getid3_temp->info['warning'] = $info['warning'];
         $getid3_temp->info['error'] = $info['error'];
         $getid3_temp->info['comments'] = $info['comments'];
         $getid3_temp->info['audio'] = isset($info['audio']) ? $info['audio'] : array();
         $getid3_temp->info['video'] = isset($info['video']) ? $info['video'] : array();
         $getid3_riff = new getid3_riff($getid3_temp);
         $getid3_riff->Analyze();
         $info['riff'] = $getid3_temp->info['riff'];
         $info['warning'] = $getid3_temp->info['warning'];
         $info['error'] = $getid3_temp->info['error'];
         $info['tags'] = $getid3_temp->info['tags'];
         $info['comments'] = $getid3_temp->info['comments'];
         unset($getid3_riff, $getid3_temp);
         unlink($tempfile);
     }
     return false;
 }
 public function Analyze()
 {
     $info =& $this->getid3->info;
     // parse container
     try {
         $this->parseEBML($info);
     } catch (Exception $e) {
         $info['error'][] = 'EBML parser: ' . $e->getMessage();
     }
     // calculate playtime
     if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
         foreach ($info['matroska']['info'] as $key => $infoarray) {
             if (isset($infoarray['Duration'])) {
                 // TimecodeScale is how many nanoseconds each Duration unit is
                 $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
                 break;
             }
         }
     }
     // extract tags
     if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) {
         foreach ($info['matroska']['tags'] as $key => $infoarray) {
             $this->ExtractCommentsSimpleTag($infoarray);
         }
     }
     // process tracks
     if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
         foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) {
             $track_info = array();
             $track_info['dataformat'] = self::CodecIDtoCommonName($trackarray['CodecID']);
             $track_info['default'] = isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true;
             if (isset($trackarray['Name'])) {
                 $track_info['name'] = $trackarray['Name'];
             }
             switch ($trackarray['TrackType']) {
                 case 1:
                     // Video
                     $track_info['resolution_x'] = $trackarray['PixelWidth'];
                     $track_info['resolution_y'] = $trackarray['PixelHeight'];
                     $track_info['display_unit'] = self::displayUnit(isset($trackarray['DisplayUnit']) ? $trackarray['DisplayUnit'] : 0);
                     $track_info['display_x'] = isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth'];
                     $track_info['display_y'] = isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight'];
                     if (isset($trackarray['PixelCropBottom'])) {
                         $track_info['crop_bottom'] = $trackarray['PixelCropBottom'];
                     }
                     if (isset($trackarray['PixelCropTop'])) {
                         $track_info['crop_top'] = $trackarray['PixelCropTop'];
                     }
                     if (isset($trackarray['PixelCropLeft'])) {
                         $track_info['crop_left'] = $trackarray['PixelCropLeft'];
                     }
                     if (isset($trackarray['PixelCropRight'])) {
                         $track_info['crop_right'] = $trackarray['PixelCropRight'];
                     }
                     if (isset($trackarray['DefaultDuration'])) {
                         $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3);
                     }
                     if (isset($trackarray['CodecName'])) {
                         $track_info['codec'] = $trackarray['CodecName'];
                     }
                     switch ($trackarray['CodecID']) {
                         case 'V_MS/VFW/FOURCC':
                             getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, true);
                             $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']);
                             $track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']);
                             $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
                             break;
                             /*case 'V_MPEG4/ISO/AVC':
                             		$h264['profile']    = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 1, 1));
                             		$h264['level']      = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 3, 1));
                             		$rn                 = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 4, 1));
                             		$h264['NALUlength'] = ($rn & 3) + 1;
                             		$rn                 = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 5, 1));
                             		$nsps               = ($rn & 31);
                             		$offset             = 6;
                             		for ($i = 0; $i < $nsps; $i ++) {
                             			$length        = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2));
                             			$h264['SPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length);
                             			$offset       += 2 + $length;
                             		}
                             		$npps               = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 1));
                             		$offset            += 1;
                             		for ($i = 0; $i < $npps; $i ++) {
                             			$length        = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2));
                             			$h264['PPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length);
                             			$offset       += 2 + $length;
                             		}
                             		$info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $h264;
                             		break;*/
                     }
                     $info['video']['streams'][] = $track_info;
                     break;
                 case 2:
                     // Audio
                     $track_info['sample_rate'] = isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0;
                     $track_info['channels'] = isset($trackarray['Channels']) ? $trackarray['Channels'] : 1;
                     $track_info['language'] = isset($trackarray['Language']) ? $trackarray['Language'] : 'eng';
                     if (isset($trackarray['BitDepth'])) {
                         $track_info['bits_per_sample'] = $trackarray['BitDepth'];
                     }
                     if (isset($trackarray['CodecName'])) {
                         $track_info['codec'] = $trackarray['CodecName'];
                     }
                     switch ($trackarray['CodecID']) {
                         case 'A_PCM/INT/LIT':
                         case 'A_PCM/INT/BIG':
                             $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
                             break;
                         case 'A_AC3':
                         case 'A_DTS':
                         case 'A_MPEG/L3':
                         case 'A_MPEG/L2':
                         case 'A_FLAC':
                             getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.' . ($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']) . '.php', __FILE__, true);
                             if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
                                 $this->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because $info[matroska][track_data_offsets][' . $trackarray['TrackNumber'] . '] not set');
                                 break;
                             }
                             // create temp instance
                             $getid3_temp = new getID3();
                             if ($track_info['dataformat'] != 'flac') {
                                 $getid3_temp->openfile($this->getid3->filename);
                             }
                             $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                             if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') {
                                 $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length'];
                             }
                             // analyze
                             $class = 'getid3_' . ($track_info['dataformat'] == 'mp2' ? 'mp3' : $track_info['dataformat']);
                             $header_data_key = $track_info['dataformat'][0] == 'm' ? 'mpeg' : $track_info['dataformat'];
                             $getid3_audio = new $class($getid3_temp, __CLASS__);
                             if ($track_info['dataformat'] == 'flac') {
                                 $getid3_audio->AnalyzeString($trackarray['CodecPrivate']);
                             } else {
                                 $getid3_audio->Analyze();
                             }
                             if (!empty($getid3_temp->info[$header_data_key])) {
                                 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key];
                                 if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                     foreach ($getid3_temp->info['audio'] as $key => $value) {
                                         $track_info[$key] = $value;
                                     }
                                 }
                             } else {
                                 $this->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because ' . $class . '::Analyze() failed at offset ' . $getid3_temp->info['avdataoffset']);
                             }
                             // copy errors and warnings
                             if (!empty($getid3_temp->info['error'])) {
                                 foreach ($getid3_temp->info['error'] as $newerror) {
                                     $this->warning($class . '() says: [' . $newerror . ']');
                                 }
                             }
                             if (!empty($getid3_temp->info['warning'])) {
                                 foreach ($getid3_temp->info['warning'] as $newerror) {
                                     $this->warning($class . '() says: [' . $newerror . ']');
                                 }
                             }
                             unset($getid3_temp, $getid3_audio);
                             break;
                         case 'A_AAC':
                         case 'A_AAC/MPEG2/LC':
                         case 'A_AAC/MPEG2/LC/SBR':
                         case 'A_AAC/MPEG4/LC':
                         case 'A_AAC/MPEG4/LC/SBR':
                             $this->warning($trackarray['CodecID'] . ' audio data contains no header, audio/video bitrates can\'t be calculated');
                             break;
                         case 'A_VORBIS':
                             if (!isset($trackarray['CodecPrivate'])) {
                                 $this->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because CodecPrivate data not set');
                                 break;
                             }
                             $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1);
                             if ($vorbis_offset === false) {
                                 $this->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because CodecPrivate data does not contain "vorbis" keyword');
                                 break;
                             }
                             $vorbis_offset -= 1;
                             getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.ogg.php', __FILE__, true);
                             // create temp instance
                             $getid3_temp = new getID3();
                             // analyze
                             $getid3_ogg = new getid3_ogg($getid3_temp);
                             $oggpageinfo['page_seqno'] = 0;
                             $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo);
                             if (!empty($getid3_temp->info['ogg'])) {
                                 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg'];
                                 if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                     foreach ($getid3_temp->info['audio'] as $key => $value) {
                                         $track_info[$key] = $value;
                                     }
                                 }
                             }
                             // copy errors and warnings
                             if (!empty($getid3_temp->info['error'])) {
                                 foreach ($getid3_temp->info['error'] as $newerror) {
                                     $this->warning('getid3_ogg() says: [' . $newerror . ']');
                                 }
                             }
                             if (!empty($getid3_temp->info['warning'])) {
                                 foreach ($getid3_temp->info['warning'] as $newerror) {
                                     $this->warning('getid3_ogg() says: [' . $newerror . ']');
                                 }
                             }
                             if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) {
                                 $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal'];
                             }
                             unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset);
                             break;
                         case 'A_MS/ACM':
                             getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, true);
                             $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']);
                             foreach ($parsed as $key => $value) {
                                 if ($key != 'raw') {
                                     $track_info[$key] = $value;
                                 }
                             }
                             $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
                             break;
                         default:
                             $this->warning('Unhandled audio type "' . (isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '') . '"');
                             break;
                     }
                     $info['audio']['streams'][] = $track_info;
                     break;
             }
         }
         if (!empty($info['video']['streams'])) {
             $info['video'] = self::getDefaultStreamInfo($info['video']['streams']);
         }
         if (!empty($info['audio']['streams'])) {
             $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']);
         }
     }
     // process attachments
     if (isset($info['matroska']['attachments']) && $this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE) {
         foreach ($info['matroska']['attachments'] as $i => $entry) {
             if (strpos($entry['FileMimeType'], 'image/') === 0 && !empty($entry['FileData'])) {
                 $info['matroska']['comments']['picture'][] = array('data' => $entry['FileData'], 'image_mime' => $entry['FileMimeType'], 'filename' => $entry['FileName']);
             }
         }
     }
     // determine mime type
     if (!empty($info['video']['streams'])) {
         $info['mime_type'] = $info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska';
     } elseif (!empty($info['audio']['streams'])) {
         $info['mime_type'] = $info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska';
     } elseif (isset($info['mime_type'])) {
         unset($info['mime_type']);
     }
     return true;
 }
 function Analyze()
 {
     $info =& $this->getid3->info;
     // http://www.matroska.org/technical/specs/index.html#EBMLBasics
     $offset = $info['avdataoffset'];
     $EBMLdata = '';
     $EBMLdata_offset = $offset;
     if (!getid3_lib::intValueSupported($info['avdataend'])) {
         $this->warnings[] = 'This version of getID3() [' . $this->getid3->version() . '] may or may not correctly handle Matroska files larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB';
     }
     while ($offset < $info['avdataend']) {
         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
         $top_element_offset = $offset;
         $top_element_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
         $top_element_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
         if ($top_element_length === false) {
             $this->warnings[] = 'invalid chunk length at ' . $top_element_offset;
             $offset = PHP_INT_MAX + 1;
             break;
         }
         $top_element_endoffset = $offset + $top_element_length;
         switch ($top_element_id) {
             case EBML_ID_EBML:
                 $info['fileformat'] = 'matroska';
                 $info['matroska']['header']['offset'] = $top_element_offset;
                 $info['matroska']['header']['length'] = $top_element_length;
                 while ($offset < $top_element_endoffset) {
                     $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                     $element_data = array();
                     $element_data_offset = $offset;
                     $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     $element_data['id_name'] = $this->EBMLidName($element_data['id']);
                     $element_data['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     $end_offset = $offset + $element_data['length'];
                     switch ($element_data['id']) {
                         case EBML_ID_VOID:
                             // padding, ignore
                             break;
                         case EBML_ID_EBMLVERSION:
                         case EBML_ID_EBMLREADVERSION:
                         case EBML_ID_EBMLMAXIDLENGTH:
                         case EBML_ID_EBMLMAXSIZELENGTH:
                         case EBML_ID_DOCTYPEVERSION:
                         case EBML_ID_DOCTYPEREADVERSION:
                             $element_data['data'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']));
                             break;
                         case EBML_ID_DOCTYPE:
                             $element_data['data'] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']), "");
                             break;
                         case EBML_ID_CRC32:
                             // probably not useful, ignore
                             unset($element_data);
                             break;
                         default:
                             $this->warnings[] = 'Unhandled track.video element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $element_data['id'] . '::' . $element_data['id_name'] . ') at ' . $element_data_offset;
                             break;
                     }
                     $offset = $end_offset;
                     if (!empty($element_data)) {
                         $info['matroska']['header']['elements'][] = $element_data;
                     }
                 }
                 break;
             case EBML_ID_SEGMENT:
                 $info['matroska']['segment'][0]['offset'] = $top_element_offset;
                 $info['matroska']['segment'][0]['length'] = $top_element_length;
                 $segment_key = -1;
                 while ($offset < $info['avdataend']) {
                     $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                     $element_data = array();
                     $element_data['offset'] = $offset;
                     $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     $element_data['id_name'] = $this->EBMLidName($element_data['id']);
                     $element_data['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     if ($element_data['length'] === false) {
                         $this->warnings[] = 'invalid chunk length at ' . $element_data['offset'];
                         //$offset = PHP_INT_MAX + 1;
                         $offset = $info['avdataend'];
                         break;
                     }
                     $element_end = $offset + $element_data['length'];
                     switch ($element_data['id']) {
                         //case EBML_ID_CLUSTER:
                         //	// too many cluster entries, probably not useful
                         //	break;
                         case false:
                             $this->warnings[] = 'invalid ID at ' . $element_data['offset'];
                             $offset = $element_end;
                             continue 3;
                         default:
                             $info['matroska']['segments'][] = $element_data;
                             break;
                     }
                     $segment_key++;
                     switch ($element_data['id']) {
                         case EBML_ID_SEEKHEAD:
                             // Contains the position of other level 1 elements
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $seek_entry = array();
                                 $seek_entry['offset'] = $offset;
                                 $seek_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $seek_entry['id_name'] = $this->EBMLidName($seek_entry['id']);
                                 $seek_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $seek_end_offset = $offset + $seek_entry['length'];
                                 switch ($seek_entry['id']) {
                                     case EBML_ID_SEEK:
                                         // Contains a single seek entry to an EBML element
                                         while ($offset < $seek_end_offset) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $value = substr($EBMLdata, $offset - $EBMLdata_offset, $length);
                                             $offset += $length;
                                             switch ($id) {
                                                 case EBML_ID_SEEKID:
                                                     $dummy = 0;
                                                     $seek_entry['target_id'] = $this->readEBMLint($value, $dummy);
                                                     $seek_entry['target_name'] = $this->EBMLidName($seek_entry['target_id']);
                                                     break;
                                                 case EBML_ID_SEEKPOSITION:
                                                     $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($value);
                                                     break;
                                                 case EBML_ID_CRC32:
                                                     // probably not useful, ignore
                                                     //$seek_entry['crc32'] = getid3_lib::PrintHexBytes($value, true, false, false);
                                                     unset($seek_entry);
                                                     break;
                                                 default:
                                                     $info['error'][] = 'Unhandled segment [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $id . ') at ' . $offset;
                                                     break;
                                             }
                                         }
                                         if (!empty($seek_entry)) {
                                             $info['matroska']['seek'][] = $seek_entry;
                                         }
                                         //switch ($seek_entry['target_id']) {
                                         //	case EBML_ID_CLUSTER:
                                         //		// too many cluster seek points, probably not useful
                                         //		break;
                                         //	default:
                                         //		$info['matroska']['seek'][] = $seek_entry;
                                         //		break;
                                         //}
                                         break;
                                     case EBML_ID_CRC32:
                                         // probably not useful, ignore
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled seekhead element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $seek_entry['id'] . '::' . $seek_entry['id_name'] . ') at ' . $offset;
                                         break;
                                 }
                                 $offset = $seek_end_offset;
                             }
                             break;
                         case EBML_ID_TRACKS:
                             // information about all tracks in segment
                             $info['matroska']['tracks'] = $element_data;
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $track_entry = array();
                                 $track_entry['offset'] = $offset;
                                 $track_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $track_entry['id_name'] = $this->EBMLidName($track_entry['id']);
                                 $track_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $track_entry_endoffset = $offset + $track_entry['length'];
                                 // $track_entry['offset'] is not the same as $offset, even though they were set equal a few lines up: $offset has been automagically incremented by readEMLint()
                                 switch ($track_entry['id']) {
                                     case EBML_ID_TRACKENTRY:
                                         //subelements: Describes a track with all elements.
                                         while ($offset < $track_entry_endoffset) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $subelement_offset = $offset;
                                             $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $subelement_idname = $this->EBMLidName($subelement_id);
                                             $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $subelement_end = $offset + $subelement_length;
                                             switch ($subelement_id) {
                                                 case EBML_ID_TRACKNUMBER:
                                                 case EBML_ID_TRACKUID:
                                                 case EBML_ID_TRACKTYPE:
                                                 case EBML_ID_MINCACHE:
                                                 case EBML_ID_MAXCACHE:
                                                 case EBML_ID_MAXBLOCKADDITIONID:
                                                 case EBML_ID_DEFAULTDURATION:
                                                     // nanoseconds per frame
                                                     $track_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                                     break;
                                                 case EBML_ID_TRACKTIMECODESCALE:
                                                     $track_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                                     break;
                                                 case EBML_ID_CODECID:
                                                 case EBML_ID_LANGUAGE:
                                                 case EBML_ID_NAME:
                                                 case EBML_ID_CODECNAME:
                                                 case EBML_ID_CODECPRIVATE:
                                                     $track_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "");
                                                     break;
                                                     // thought maybe it was a nice wFormatTag entry, but it's not :(
                                                     //case EBML_ID_CODECPRIVATE:
                                                     //$track_entry[$subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
                                                     //if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
                                                     //	$track_entry[$subelement_idname.'_decoded'] = getid3_riff::RIFFparseWAVEFORMATex($track_entry[$subelement_idname]);
                                                     //	if (isset($track_entry[$subelement_idname.'_decoded']['raw']['wFormatTag'])) {
                                                     //	}
                                                     //} else {
                                                     //	$this->warnings[] = 'failed to include "module.audio-video.riff.php" for parsing codec private data';
                                                     //}
                                                     //break;
                                                 // thought maybe it was a nice wFormatTag entry, but it's not :(
                                                 //case EBML_ID_CODECPRIVATE:
                                                 //$track_entry[$subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
                                                 //if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
                                                 //	$track_entry[$subelement_idname.'_decoded'] = getid3_riff::RIFFparseWAVEFORMATex($track_entry[$subelement_idname]);
                                                 //	if (isset($track_entry[$subelement_idname.'_decoded']['raw']['wFormatTag'])) {
                                                 //	}
                                                 //} else {
                                                 //	$this->warnings[] = 'failed to include "module.audio-video.riff.php" for parsing codec private data';
                                                 //}
                                                 //break;
                                                 case EBML_ID_FLAGENABLED:
                                                 case EBML_ID_FLAGDEFAULT:
                                                 case EBML_ID_FLAGFORCED:
                                                 case EBML_ID_FLAGLACING:
                                                 case EBML_ID_CODECDECODEALL:
                                                     $track_entry[$subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                                     break;
                                                 case EBML_ID_VIDEO:
                                                     while ($offset < $subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_offset = $offset;
                                                         $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                                         $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_end = $offset + $sub_subelement_length;
                                                         switch ($sub_subelement_id) {
                                                             case EBML_ID_PIXELWIDTH:
                                                             case EBML_ID_PIXELHEIGHT:
                                                             case EBML_ID_STEREOMODE:
                                                             case EBML_ID_PIXELCROPBOTTOM:
                                                             case EBML_ID_PIXELCROPTOP:
                                                             case EBML_ID_PIXELCROPLEFT:
                                                             case EBML_ID_PIXELCROPRIGHT:
                                                             case EBML_ID_DISPLAYWIDTH:
                                                             case EBML_ID_DISPLAYHEIGHT:
                                                             case EBML_ID_DISPLAYUNIT:
                                                             case EBML_ID_ASPECTRATIOTYPE:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_FLAGINTERLACED:
                                                                 $track_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_GAMMAVALUE:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_COLOURSPACE:
                                                                 $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "");
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled track.video element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_subelement_end;
                                                     }
                                                     if (isset($track_entry[$this->EBMLidName(EBML_ID_CODECID)]) && $track_entry[$this->EBMLidName(EBML_ID_CODECID)] == 'V_MS/VFW/FOURCC' && isset($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)])) {
                                                         if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, false)) {
                                                             $track_entry['codec_private_parsed'] = getid3_riff::ParseBITMAPINFOHEADER($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)]);
                                                         } else {
                                                             $this->warnings[] = 'Unable to parse codec private data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio-video.riff.php"';
                                                         }
                                                     }
                                                     break;
                                                 case EBML_ID_AUDIO:
                                                     while ($offset < $subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_offset = $offset;
                                                         $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                                         $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_end = $offset + $sub_subelement_length;
                                                         switch ($sub_subelement_id) {
                                                             case EBML_ID_CHANNELS:
                                                             case EBML_ID_BITDEPTH:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_SAMPLINGFREQUENCY:
                                                             case EBML_ID_OUTPUTSAMPLINGFREQUENCY:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_CHANNELPOSITIONS:
                                                                 $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "");
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled track.audio element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_subelement_end;
                                                     }
                                                     break;
                                                 case EBML_ID_CONTENTENCODINGS:
                                                     while ($offset < $subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_offset = $offset;
                                                         $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                                         $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_end = $offset + $sub_subelement_length;
                                                         switch ($sub_subelement_id) {
                                                             case EBML_ID_CONTENTENCODING:
                                                                 while ($offset < $sub_subelement_end) {
                                                                     $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_subelement_offset = $offset;
                                                                     $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                                     $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                                     switch ($sub_sub_subelement_id) {
                                                                         case EBML_ID_CONTENTENCODINGORDER:
                                                                         case EBML_ID_CONTENTENCODINGSCOPE:
                                                                         case EBML_ID_CONTENTENCODINGTYPE:
                                                                             $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                             break;
                                                                         case EBML_ID_CONTENTCOMPRESSION:
                                                                             while ($offset < $sub_sub_subelement_end) {
                                                                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                                                 $sub_sub_sub_subelement_offset = $offset;
                                                                                 $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                                 $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                                                 $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                                 $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
                                                                                 switch ($sub_sub_sub_subelement_id) {
                                                                                     case EBML_ID_CONTENTCOMPALGO:
                                                                                         $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
                                                                                         break;
                                                                                     case EBML_ID_CONTENTCOMPSETTINGS:
                                                                                         $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
                                                                                         break;
                                                                                     default:
                                                                                         $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                                                                         break;
                                                                                 }
                                                                                 $offset = $sub_sub_sub_subelement_end;
                                                                             }
                                                                             break;
                                                                         case EBML_ID_CONTENTENCRYPTION:
                                                                             while ($offset < $sub_sub_subelement_end) {
                                                                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                                                 $sub_sub_sub_subelement_offset = $offset;
                                                                                 $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                                 $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                                                 $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                                 $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
                                                                                 switch ($sub_sub_sub_subelement_id) {
                                                                                     case EBML_ID_CONTENTENCALGO:
                                                                                     case EBML_ID_CONTENTSIGALGO:
                                                                                     case EBML_ID_CONTENTSIGHASHALGO:
                                                                                         $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
                                                                                         break;
                                                                                     case EBML_ID_CONTENTENCKEYID:
                                                                                     case EBML_ID_CONTENTSIGNATURE:
                                                                                     case EBML_ID_CONTENTSIGKEYID:
                                                                                         $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
                                                                                         break;
                                                                                     default:
                                                                                         $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                                                                         break;
                                                                                 }
                                                                                 $offset = $sub_sub_sub_subelement_end;
                                                                             }
                                                                             break;
                                                                         default:
                                                                             $this->warnings[] = 'Unhandled track.contentencodings.contentencoding element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                                                             break;
                                                                     }
                                                                     $offset = $sub_sub_subelement_end;
                                                                 }
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled track.contentencodings element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_subelement_end;
                                                     }
                                                     break;
                                                 case EBML_ID_CRC32:
                                                     // probably not useful, ignore
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled track element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                                     break;
                                             }
                                             $offset = $subelement_end;
                                         }
                                         break;
                                     case EBML_ID_CRC32:
                                         // probably not useful, ignore
                                         $offset = $track_entry_endoffset;
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled track element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $track_entry['id'] . '::' . $track_entry['id_name'] . ') at ' . $track_entry['offset'];
                                         $offset = $track_entry_endoffset;
                                         break;
                                 }
                                 $info['matroska']['tracks']['tracks'][] = $track_entry;
                             }
                             break;
                         case EBML_ID_INFO:
                             // Contains the position of other level 1 elements
                             $info_entry = array();
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
                                     case EBML_ID_CHAPTERTRANSLATECODEC:
                                     case EBML_ID_TIMECODESCALE:
                                         $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                         break;
                                     case EBML_ID_DURATION:
                                         $info_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                         break;
                                     case EBML_ID_DATEUTC:
                                         $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                         $info_entry[$subelement_idname . '_unix'] = $this->EBMLdate2unix($info_entry[$subelement_idname]);
                                         break;
                                     case EBML_ID_SEGMENTUID:
                                     case EBML_ID_PREVUID:
                                     case EBML_ID_NEXTUID:
                                     case EBML_ID_SEGMENTFAMILY:
                                     case EBML_ID_CHAPTERTRANSLATEID:
                                         $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "");
                                         break;
                                     case EBML_ID_SEGMENTFILENAME:
                                     case EBML_ID_PREVFILENAME:
                                     case EBML_ID_NEXTFILENAME:
                                     case EBML_ID_TITLE:
                                     case EBML_ID_MUXINGAPP:
                                     case EBML_ID_WRITINGAPP:
                                         $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "");
                                         $info['matroska']['comments'][strtolower($subelement_idname)][] = $info_entry[$subelement_idname];
                                         break;
                                     case EBML_ID_CRC32:
                                         // probably not useful, ignore
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled info element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             $info['matroska']['info'][] = $info_entry;
                             break;
                         case EBML_ID_CUES:
                             $cues_entry = array();
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_CUEPOINT:
                                         $cuepoint_entry = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_CUETRACKPOSITIONS:
                                                     while ($offset < $sub_subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_offset = $offset;
                                                         $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                         $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                         switch ($sub_sub_subelement_id) {
                                                             case EBML_ID_CUETRACK:
                                                                 $cuepoint_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled cues.cuepoint.cuetrackpositions element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_sub_subelement_id . '::' . $sub_sub_subelement_idname . ') at ' . $sub_sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_subelement_end;
                                                     }
                                                     break;
                                                 case EBML_ID_CUETIME:
                                                     $cuepoint_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled cues.cuepoint element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $cues_entry[] = $cuepoint_entry;
                                         $offset = $sub_subelement_end;
                                         break;
                                     case EBML_ID_CRC32:
                                         // probably not useful, ignore
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled cues element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             $info['matroska']['cues'] = $cues_entry;
                             break;
                         case EBML_ID_TAGS:
                             $tags_entry = array();
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 $tag_entry = array();
                                 switch ($subelement_id) {
                                     case EBML_ID_WRITINGAPP:
                                         $tag_entry[$subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length);
                                         break;
                                     case EBML_ID_TAG:
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_TARGETS:
                                                     $targets_entry = array();
                                                     while ($offset < $sub_subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_offset = $offset;
                                                         $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                         $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                         switch ($sub_sub_subelement_id) {
                                                             case EBML_ID_TARGETTYPEVALUE:
                                                                 $targets_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 $targets_entry[strtolower($sub_sub_subelement_idname) . '_long'] = $this->MatroskaTargetTypeValue($targets_entry[$sub_sub_subelement_idname]);
                                                                 break;
                                                             case EBML_ID_EDITIONUID:
                                                             case EBML_ID_CHAPTERUID:
                                                             case EBML_ID_ATTACHMENTUID:
                                                             case EBML_ID_TAGTRACKUID:
                                                             case EBML_ID_TAGCHAPTERUID:
                                                                 $targets_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled tag.targets element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_sub_subelement_id . '::' . $sub_sub_subelement_idname . ') at ' . $sub_sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_sub_subelement_end;
                                                     }
                                                     $tag_entry[$sub_subelement_idname][] = $targets_entry;
                                                     break;
                                                 case EBML_ID_SIMPLETAG:
                                                     //$tag_entry[$sub_subelement_idname][] = $simpletag_entry;
                                                     $tag_entry[$sub_subelement_idname][] = $this->Handle_EMBL_ID_SIMPLETAG($offset, $sub_subelement_end);
                                                     break;
                                                 case EBML_ID_TARGETTYPE:
                                                     $tag_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
                                                     break;
                                                 case EBML_ID_TRACKUID:
                                                     $tag_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled tags.tag element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $offset = $sub_subelement_end;
                                         break;
                                     case EBML_ID_CRC32:
                                         // probably not useful, ignore
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled tags element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                         break;
                                 }
                                 $tags_entry['tags'][] = $tag_entry;
                                 $offset = $subelement_end;
                             }
                             $info['matroska']['tags'] = $tags_entry['tags'];
                             break;
                         case EBML_ID_ATTACHMENTS:
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_ATTACHEDFILE:
                                         $attachedfile_entry = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_FILEDESCRIPTION:
                                                 case EBML_ID_FILENAME:
                                                 case EBML_ID_FILEMIMETYPE:
                                                     $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
                                                     break;
                                                 case EBML_ID_FILEDATA:
                                                     $attachedfile_entry['data_offset'] = $offset;
                                                     $attachedfile_entry['data_length'] = $sub_subelement_length;
                                                     do {
                                                         if ($this->inline_attachments === false) {
                                                             // skip entirely
                                                             break;
                                                         }
                                                         if ($this->inline_attachments === true) {
                                                             // great
                                                         } elseif (is_int($this->inline_attachments)) {
                                                             if ($this->inline_attachments < $sub_subelement_length) {
                                                                 // too big, skip
                                                                 $this->warnings[] = 'attachment at ' . $sub_subelement_offset . ' is too large to process inline (' . number_format($sub_subelement_length) . ' bytes)';
                                                                 break;
                                                             }
                                                         } elseif (is_string($this->inline_attachments)) {
                                                             $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
                                                             if (!is_dir($this->inline_attachments) || !is_writable($this->inline_attachments)) {
                                                                 // cannot write, skip
                                                                 $this->warnings[] = 'attachment at ' . $sub_subelement_offset . ' cannot be saved to "' . $this->inline_attachments . '" (not writable)';
                                                                 break;
                                                             }
                                                         }
                                                         // if we get this far, must be OK
                                                         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset, $sub_subelement_length);
                                                         $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
                                                         if (is_string($this->inline_attachments)) {
                                                             $destination_filename = $this->inline_attachments . DIRECTORY_SEPARATOR . md5($info['filenamepath']) . '_' . $attachedfile_entry['data_offset'];
                                                             if (!file_exists($destination_filename) || is_writable($destination_filename)) {
                                                                 file_put_contents($destination_filename, $attachedfile_entry[$sub_subelement_idname]);
                                                             } else {
                                                                 $this->warnings[] = 'attachment at ' . $sub_subelement_offset . ' cannot be saved to "' . $destination_filename . '" (not writable)';
                                                             }
                                                             $attachedfile_entry[$sub_subelement_idname . '_filename'] = $destination_filename;
                                                             unset($attachedfile_entry[$sub_subelement_idname]);
                                                         }
                                                     } while (false);
                                                     break;
                                                 case EBML_ID_FILEUID:
                                                     $attachedfile_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled attachment.attachedfile element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         if (!empty($attachedfile_entry[$this->EBMLidName(EBML_ID_FILEDATA)]) && !empty($attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)]) && preg_match('#^image/#i', $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)])) {
                                             if ($this->inline_attachments === true || is_int($this->inline_attachments) && $this->inline_attachments >= strlen($attachedfile_entry[$this->EBMLidName(EBML_ID_FILEDATA)])) {
                                                 $attachedfile_entry['data'] = $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEDATA)];
                                                 $attachedfile_entry['image_mime'] = $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)];
                                                 $info['matroska']['comments']['picture'][] = array('data' => $attachedfile_entry['data'], 'image_mime' => $attachedfile_entry['image_mime'], 'filename' => !empty($attachedfile_entry[$this->EBMLidName(EBML_ID_FILENAME)]) ? $attachedfile_entry[$this->EBMLidName(EBML_ID_FILENAME)] : '');
                                                 unset($attachedfile_entry[$this->EBMLidName(EBML_ID_FILEDATA)], $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)]);
                                             }
                                         }
                                         if (!empty($attachedfile_entry['image_mime']) && preg_match('#^image/#i', $attachedfile_entry['image_mime'])) {
                                             // don't add a second copy of attached images, which are grouped under the standard location [comments][picture]
                                         } else {
                                             $info['matroska']['attachments'][] = $attachedfile_entry;
                                         }
                                         $offset = $sub_subelement_end;
                                         break;
                                     case EBML_ID_CRC32:
                                         // probably not useful, ignore
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled tags element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             break;
                         case EBML_ID_CHAPTERS:
                             // not important to us, contains mostly actual audio/video data, ignore
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_EDITIONENTRY:
                                         $editionentry_entry = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_EDITIONUID:
                                                     $editionentry_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 case EBML_ID_EDITIONFLAGHIDDEN:
                                                 case EBML_ID_EDITIONFLAGDEFAULT:
                                                 case EBML_ID_EDITIONFLAGORDERED:
                                                     $editionentry_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 case EBML_ID_CHAPTERATOM:
                                                     $chapteratom_entry = array();
                                                     while ($offset < $sub_subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_offset = $offset;
                                                         $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                         $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                         switch ($sub_sub_subelement_id) {
                                                             case EBML_ID_CHAPTERSEGMENTUID:
                                                             case EBML_ID_CHAPTERSEGMENTEDITIONUID:
                                                                 $chapteratom_entry[$sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
                                                                 break;
                                                             case EBML_ID_CHAPTERFLAGENABLED:
                                                             case EBML_ID_CHAPTERFLAGHIDDEN:
                                                                 $chapteratom_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_CHAPTERUID:
                                                             case EBML_ID_CHAPTERTIMESTART:
                                                             case EBML_ID_CHAPTERTIMEEND:
                                                                 $chapteratom_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_CHAPTERTRACK:
                                                                 $chaptertrack_entry = array();
                                                                 while ($offset < $sub_sub_subelement_end) {
                                                                     $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_offset = $offset;
                                                                     $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                                     $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
                                                                     switch ($sub_sub_sub_subelement_id) {
                                                                         case EBML_ID_CHAPTERTRACKNUMBER:
                                                                             $chaptertrack_entry[$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
                                                                             break;
                                                                         default:
                                                                             $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chaptertrack element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_sub_sub_subelement_id . '::' . $sub_sub_sub_subelement_idname . ') at ' . $sub_sub_sub_subelement_offset;
                                                                             break;
                                                                     }
                                                                     $offset = $sub_sub_sub_subelement_end;
                                                                 }
                                                                 $chapteratom_entry[$sub_sub_subelement_idname][] = $chaptertrack_entry;
                                                                 break;
                                                             case EBML_ID_CHAPTERDISPLAY:
                                                                 $chapterdisplay_entry = array();
                                                                 while ($offset < $sub_sub_subelement_end) {
                                                                     $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_offset = $offset;
                                                                     $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_sub_subelement_id);
                                                                     $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
                                                                     switch ($sub_sub_sub_subelement_id) {
                                                                         case EBML_ID_CHAPSTRING:
                                                                         case EBML_ID_CHAPLANGUAGE:
                                                                         case EBML_ID_CHAPCOUNTRY:
                                                                             $chapterdisplay_entry[$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
                                                                             break;
                                                                         default:
                                                                             $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chapterdisplay element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_sub_sub_subelement_id . '::' . $sub_sub_sub_subelement_idname . ') at ' . $sub_sub_sub_subelement_offset;
                                                                             break;
                                                                     }
                                                                     $offset = $sub_sub_sub_subelement_end;
                                                                 }
                                                                 $chapteratom_entry[$sub_sub_subelement_idname][] = $chapterdisplay_entry;
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_sub_subelement_id . '::' . $sub_sub_subelement_idname . ') at ' . $sub_sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_sub_subelement_end;
                                                     }
                                                     $editionentry_entry[$sub_subelement_idname][] = $chapteratom_entry;
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled chapters.editionentry element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $info['matroska']['chapters'][] = $editionentry_entry;
                                         $offset = $sub_subelement_end;
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled chapters element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             break;
                         case EBML_ID_VOID:
                             // padding, ignore
                             $void_entry = array();
                             $void_entry['offset'] = $offset;
                             $info['matroska']['void'][] = $void_entry;
                             break;
                         case EBML_ID_CLUSTER:
                             // not important to us, contains mostly actual audio/video data, ignore
                             $cluster_entry = array();
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_CLUSTERTIMECODE:
                                     case EBML_ID_CLUSTERPOSITION:
                                     case EBML_ID_CLUSTERPREVSIZE:
                                         $cluster_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                         break;
                                     case EBML_ID_CLUSTERSILENTTRACKS:
                                         $cluster_silent_tracks = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_CLUSTERSILENTTRACKNUMBER:
                                                     $cluster_silent_tracks[] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled clusters.silenttracks element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $cluster_entry[$subelement_idname][] = $cluster_silent_tracks;
                                         $offset = $sub_subelement_end;
                                         break;
                                     case EBML_ID_CLUSTERBLOCKGROUP:
                                         $cluster_block_group = array('offset' => $offset);
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_CLUSTERBLOCK:
                                                     $cluster_block_data = array();
                                                     $cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                     $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2));
                                                     $offset += 2;
                                                     // unsure whether this is 1 octect or 2 octets? (http://matroska.org/technical/specs/index.html#block_structure)
                                                     $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
                                                     $offset += 1;
                                                     //$cluster_block_data['flags']['reserved1'] =      (($cluster_block_data['flags_raw'] & 0xF0) >> 4);
                                                     $cluster_block_data['flags']['invisible'] = (bool) (($cluster_block_data['flags_raw'] & 0x8) >> 3);
                                                     $cluster_block_data['flags']['lacing'] = ($cluster_block_data['flags_raw'] & 0x6) >> 1;
                                                     //$cluster_block_data['flags']['reserved2'] =      (($cluster_block_data['flags_raw'] & 0x01) >> 0);
                                                     $cluster_block_data['flags']['lacing_type'] = $this->MatroskaBlockLacingType($cluster_block_data['flags']['lacing']);
                                                     if ($cluster_block_data['flags']['lacing'] != 0) {
                                                         $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
                                                         // Number of frames in the lace-1 (uint8)
                                                         $offset += 1;
                                                         if ($cluster_block_data['flags']['lacing'] != 2) {
                                                             $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
                                                             // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace).
                                                             $offset += 1;
                                                         }
                                                     }
                                                     if (!isset($info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
                                                         $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['offset'] = $offset;
                                                         $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['length'] = $subelement_length;
                                                     }
                                                     $cluster_block_group[$sub_subelement_idname] = $cluster_block_data;
                                                     break;
                                                 case EBML_ID_CLUSTERREFERENCEPRIORITY:
                                                     // unsigned-int
                                                 // unsigned-int
                                                 case EBML_ID_CLUSTERBLOCKDURATION:
                                                     // unsigned-int
                                                     $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 case EBML_ID_CLUSTERREFERENCEBLOCK:
                                                     // signed-int
                                                     $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), false, true);
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled clusters.blockgroup element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $cluster_entry[$subelement_idname][] = $cluster_block_group;
                                         $offset = $sub_subelement_end;
                                         break;
                                     case EBML_ID_CLUSTERSIMPLEBLOCK:
                                         // http://www.matroska.org/technical/specs/index.html#simpleblock_structure
                                         $cluster_block_data = array();
                                         $cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                         $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2));
                                         $offset += 2;
                                         $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
                                         $offset += 1;
                                         $cluster_block_data['flags']['keyframe'] = ($cluster_block_data['flags_raw'] & 0x80) >> 7;
                                         $cluster_block_data['flags']['reserved1'] = ($cluster_block_data['flags_raw'] & 0x70) >> 4;
                                         $cluster_block_data['flags']['invisible'] = ($cluster_block_data['flags_raw'] & 0x8) >> 3;
                                         $cluster_block_data['flags']['lacing'] = ($cluster_block_data['flags_raw'] & 0x6) >> 1;
                                         // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing
                                         $cluster_block_data['flags']['discardable'] = $cluster_block_data['flags_raw'] & 0x1;
                                         if ($cluster_block_data['flags']['lacing'] > 0) {
                                             $cluster_block_data['lace_frames'] = 1 + getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
                                             $offset += 1;
                                             if ($cluster_block_data['flags']['lacing'] != 0x2) {
                                                 // *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace).
                                                 $cluster_block_data['lace_frame_size'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
                                                 $offset += 1;
                                             }
                                         }
                                         if (!isset($info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
                                             $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['offset'] = $offset;
                                             $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['length'] = $subelement_length;
                                         }
                                         $cluster_block_group[$sub_subelement_idname] = $cluster_block_data;
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled cluster element [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ' [' . $subelement_length . ' bytes]) at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             $info['matroska']['cluster'][] = $cluster_entry;
                             // check to see if all the data we need exists already, if so, break out of the loop
                             if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
                                 if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
                                     break 2;
                                 }
                             }
                             break;
                         default:
                             if ($element_data['id_name'] == dechex($element_data['id'])) {
                                 $info['error'][] = 'Unhandled segment [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $element_data['id'] . ') at ' . $element_data_offset;
                             } else {
                                 $this->warnings[] = 'Unhandled segment [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $element_data['id'] . '::' . $element_data['id_name'] . ') at ' . $element_data['offset'];
                             }
                             break;
                     }
                     $offset = $element_end;
                 }
                 break;
             default:
                 $info['error'][] = 'Unhandled chunk [' . basename(__FILE__) . ':' . __LINE__ . '] (' . $top_element_id . ') at ' . $offset;
                 break;
         }
         $offset = $top_element_endoffset;
     }
     if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
         foreach ($info['matroska']['info'] as $key => $infoarray) {
             if (isset($infoarray['Duration'])) {
                 // TimecodeScale is how many nanoseconds each Duration unit is
                 $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
                 break;
             }
         }
     }
     if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) {
         foreach ($info['matroska']['tags'] as $key => $infoarray) {
             $this->ExtractCommentsSimpleTag($infoarray);
         }
     }
     if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
         foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) {
             $track_info = array();
             if (isset($trackarray['FlagDefault'])) {
                 $track_info['default'] = $trackarray['FlagDefault'];
             }
             switch (isset($trackarray['TrackType']) ? $trackarray['TrackType'] : '') {
                 case 1:
                     // Video
                     if (!empty($trackarray['PixelWidth'])) {
                         $track_info['resolution_x'] = $trackarray['PixelWidth'];
                     }
                     if (!empty($trackarray['PixelHeight'])) {
                         $track_info['resolution_y'] = $trackarray['PixelHeight'];
                     }
                     if (!empty($trackarray['DisplayWidth'])) {
                         $track_info['display_x'] = $trackarray['DisplayWidth'];
                     }
                     if (!empty($trackarray['DisplayHeight'])) {
                         $track_info['display_y'] = $trackarray['DisplayHeight'];
                     }
                     if (!empty($trackarray['DefaultDuration'])) {
                         $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3);
                     }
                     if (!empty($trackarray['CodecID'])) {
                         $track_info['dataformat'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);
                     }
                     if (!empty($trackarray['codec_private_parsed']['fourcc'])) {
                         $track_info['fourcc'] = $trackarray['codec_private_parsed']['fourcc'];
                     }
                     $info['video']['streams'][] = $track_info;
                     if (isset($track_info['resolution_x']) && empty($info['video']['resolution_x'])) {
                         foreach ($track_info as $key => $value) {
                             $info['video'][$key] = $value;
                         }
                     }
                     break;
                 case 2:
                     // Audio
                     if (!empty($trackarray['CodecID'])) {
                         $track_info['dataformat'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);
                     }
                     if (!empty($trackarray['SamplingFrequency'])) {
                         $track_info['sample_rate'] = $trackarray['SamplingFrequency'];
                     }
                     if (!empty($trackarray['Channels'])) {
                         $track_info['channels'] = $trackarray['Channels'];
                     }
                     if (!empty($trackarray['BitDepth'])) {
                         $track_info['bits_per_sample'] = $trackarray['BitDepth'];
                     }
                     if (!empty($trackarray['Language'])) {
                         $track_info['language'] = $trackarray['Language'];
                     }
                     switch (isset($trackarray[$this->EBMLidName(EBML_ID_CODECID)]) ? $trackarray[$this->EBMLidName(EBML_ID_CODECID)] : '') {
                         case 'A_PCM/INT/LIT':
                         case 'A_PCM/INT/BIG':
                             $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
                             break;
                         case 'A_AC3':
                             if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.ac3.php', __FILE__, false)) {
                                 if (isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'])) {
                                     $getid3_temp = new getID3();
                                     $getid3_temp->openfile($this->getid3->filename);
                                     $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                                     $getid3_ac3 = new getid3_ac3($getid3_temp);
                                     $getid3_ac3->Analyze();
                                     unset($getid3_temp->info['ac3']['GETID3_VERSION']);
                                     $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ac3'];
                                     if (!empty($getid3_temp->info['error'])) {
                                         foreach ($getid3_temp->info['error'] as $newerror) {
                                             $this->warnings[] = 'getid3_ac3() says: [' . $newerror . ']';
                                         }
                                     }
                                     if (!empty($getid3_temp->info['warning'])) {
                                         foreach ($getid3_temp->info['warning'] as $newerror) {
                                             $this->warnings[] = 'getid3_ac3() says: [' . $newerror . ']';
                                         }
                                     }
                                     if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                         foreach ($getid3_temp->info['audio'] as $key => $value) {
                                             $track_info[$key] = $value;
                                         }
                                     }
                                     unset($getid3_temp, $getid3_ac3);
                                 } else {
                                     $this->warnings[] = 'Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because $info[matroska][track_data_offsets][' . $trackarray['TrackNumber'] . '][offset] not set';
                                 }
                             } else {
                                 $this->warnings[] = 'Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio.ac3.php"';
                             }
                             break;
                         case 'A_DTS':
                             $dts_offset = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                             // this is a NASTY hack, but sometimes audio data is off by a byte or two and not sure why, email info@getid3.org if you can explain better
                             fseek($this->getid3->fp, $dts_offset, SEEK_SET);
                             $magic_test = fread($this->getid3->fp, 8);
                             for ($i = 0; $i < 4; $i++) {
                                 // look to see if DTS "magic" is here, if so adjust offset by that many bytes
                                 if (substr($magic_test, $i, 4) == "þ€") {
                                     $dts_offset += $i;
                                     break;
                                 }
                             }
                             if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.dts.php', __FILE__, false)) {
                                 $getid3_temp = new getID3();
                                 $getid3_temp->openfile($this->getid3->filename);
                                 $getid3_temp->info['avdataoffset'] = $dts_offset;
                                 $getid3_dts = new getid3_dts($getid3_temp);
                                 $getid3_dts->Analyze();
                                 unset($getid3_temp->info['dts']['GETID3_VERSION']);
                                 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['dts'];
                                 if (!empty($getid3_temp->info['error'])) {
                                     foreach ($getid3_temp->info['error'] as $newerror) {
                                         $this->warnings[] = 'getid3_dts() says: [' . $newerror . ']';
                                     }
                                 }
                                 if (!empty($getid3_temp->info['warning'])) {
                                     foreach ($getid3_temp->info['warning'] as $newerror) {
                                         $this->warnings[] = 'getid3_dts() says: [' . $newerror . ']';
                                     }
                                 }
                                 if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                     foreach ($getid3_temp->info['audio'] as $key => $value) {
                                         $track_info[$key] = $value;
                                     }
                                 }
                                 unset($getid3_temp, $getid3_dts);
                             } else {
                                 $this->warnings[] = 'Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio.dts.php"';
                             }
                             break;
                         case 'A_AAC':
                             $this->warnings[] = 'This version of getID3() [v' . $this->getid3->version() . '] has problems parsing AAC audio in Matroska containers [' . basename(__FILE__) . ':' . __LINE__ . ']';
                             if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.aac.php', __FILE__, false)) {
                                 $getid3_temp = new getID3();
                                 $getid3_temp->openfile($this->getid3->filename);
                                 $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                                 $getid3_aac = new getid3_aac($getid3_temp);
                                 $getid3_aac->Analyze();
                                 unset($getid3_temp->info['aac']['GETID3_VERSION']);
                                 if (!empty($getid3_temp->info['audio']['dataformat'])) {
                                     $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['aac'];
                                     if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                         foreach ($getid3_temp->info['audio'] as $key => $value) {
                                             $track_info[$key] = $value;
                                         }
                                     }
                                 } else {
                                     $this->warnings[] = 'Failed to parse ' . $trackarray[$this->EBMLidName(EBML_ID_CODECID)] . ' audio data [' . basename(__FILE__) . ':' . __LINE__ . ']';
                                 }
                                 unset($getid3_temp, $getid3_aac);
                             } else {
                                 $this->warnings[] = 'Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio.aac.php"';
                             }
                             break;
                         case 'A_MPEG/L3':
                             if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.mp3.php', __FILE__, false)) {
                                 $getid3_temp = new getID3();
                                 $getid3_temp->openfile($this->getid3->filename);
                                 $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                                 $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length'];
                                 $getid3_mp3 = new getid3_mp3($getid3_temp);
                                 $getid3_mp3->allow_bruteforce = true;
                                 $getid3_mp3->Analyze();
                                 if (!empty($getid3_temp->info['mpeg'])) {
                                     unset($getid3_temp->info['mpeg']['GETID3_VERSION']);
                                     $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['mpeg'];
                                     if (!empty($getid3_temp->info['error'])) {
                                         foreach ($getid3_temp->info['error'] as $newerror) {
                                             $this->warnings[] = 'getid3_mp3() says: [' . $newerror . ']';
                                         }
                                     }
                                     if (!empty($getid3_temp->info['warning'])) {
                                         foreach ($getid3_temp->info['warning'] as $newerror) {
                                             $this->warnings[] = 'getid3_mp3() says: [' . $newerror . ']';
                                         }
                                     }
                                     if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                         foreach ($getid3_temp->info['audio'] as $key => $value) {
                                             $track_info[$key] = $value;
                                         }
                                     }
                                 } else {
                                     $this->warnings[] = 'Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because getid3_mp3::Analyze failed at offset ' . $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                                 }
                                 unset($getid3_temp, $getid3_mp3);
                             } else {
                                 $this->warnings[] = 'Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio.mp3.php"';
                             }
                             break;
                         case 'A_VORBIS':
                             if (isset($trackarray['CodecPrivate'])) {
                                 // this is a NASTY hack, email info@getid3.org if you have a better idea how to get this info out
                                 $found_vorbis = false;
                                 for ($vorbis_offset = 1; $vorbis_offset < 16; $vorbis_offset++) {
                                     if (substr($trackarray['CodecPrivate'], $vorbis_offset, 6) == 'vorbis') {
                                         $vorbis_offset--;
                                         $found_vorbis = true;
                                         break;
                                     }
                                 }
                                 if ($found_vorbis) {
                                     if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.ogg.php', __FILE__, false)) {
                                         $oggpageinfo['page_seqno'] = 0;
                                         $getid3_temp = new getID3();
                                         $getid3_temp->openfile($this->getid3->filename);
                                         $getid3_ogg = new getid3_ogg($getid3_temp);
                                         $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo);
                                         $vorbis_fileinfo = $getid3_temp->info;
                                         unset($getid3_temp, $getid3_ogg);
                                         if (isset($vorbis_fileinfo['audio'])) {
                                             $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']]['audio'] = $vorbis_fileinfo['audio'];
                                         }
                                         if (isset($vorbis_fileinfo['ogg'])) {
                                             $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']]['ogg'] = $vorbis_fileinfo['ogg'];
                                         }
                                         if (!empty($vorbis_fileinfo['error'])) {
                                             foreach ($vorbis_fileinfo['error'] as $newerror) {
                                                 $this->warnings[] = 'getid3_ogg() says: [' . $newerror . ']';
                                             }
                                         }
                                         if (!empty($vorbis_fileinfo['warning'])) {
                                             foreach ($vorbis_fileinfo['warning'] as $newerror) {
                                                 $this->warnings[] = 'getid3_ogg() says: [' . $newerror . ']';
                                             }
                                         }
                                         if (isset($vorbis_fileinfo['audio']) && is_array($vorbis_fileinfo['audio'])) {
                                             foreach ($vorbis_fileinfo['audio'] as $key => $value) {
                                                 $track_info[$key] = $value;
                                             }
                                         }
                                         if (!empty($vorbis_fileinfo['ogg']['bitrate_average'])) {
                                             $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_average'];
                                         } elseif (!empty($vorbis_fileinfo['ogg']['bitrate_nominal'])) {
                                             $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_nominal'];
                                         }
                                         unset($vorbis_fileinfo);
                                         unset($oggpageinfo);
                                     } else {
                                         $this->warnings[] = 'Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio.ogg.php"';
                                     }
                                 } else {
                                 }
                             } else {
                             }
                             break;
                         default:
                             $this->warnings[] = 'Unhandled audio type "' . (isset($trackarray[$this->EBMLidName(EBML_ID_CODECID)]) ? $trackarray[$this->EBMLidName(EBML_ID_CODECID)] : '') . '"';
                             break;
                     }
                     $info['audio']['streams'][] = $track_info;
                     if (isset($track_info['dataformat']) && empty($info['audio']['dataformat'])) {
                         foreach ($track_info as $key => $value) {
                             $info['audio'][$key] = $value;
                         }
                     }
                     break;
                 default:
                     // ignore, do nothing
                     break;
             }
         }
     }
     if ($this->hide_clusters) {
         // too much data returned that is usually not useful
         if (isset($info['matroska']['segments']) && is_array($info['matroska']['segments'])) {
             foreach ($info['matroska']['segments'] as $key => $segmentsarray) {
                 if ($segmentsarray['id'] == EBML_ID_CLUSTER) {
                     unset($info['matroska']['segments'][$key]);
                 }
             }
         }
         if (isset($info['matroska']['seek']) && is_array($info['matroska']['seek'])) {
             foreach ($info['matroska']['seek'] as $key => $seekarray) {
                 if ($seekarray['target_id'] == EBML_ID_CLUSTER) {
                     unset($info['matroska']['seek'][$key]);
                 }
             }
         }
         //unset($info['matroska']['cluster']);
         //unset($info['matroska']['track_data_offsets']);
     }
     if (!empty($info['video']['streams'])) {
         $info['mime_type'] = 'video/x-matroska';
     } elseif (!empty($info['audio']['streams'])) {
         $info['mime_type'] = 'audio/x-matroska';
     } elseif (isset($info['mime_type'])) {
         unset($info['mime_type']);
     }
     foreach ($this->warnings as $key => $value) {
         $info['warning'][] = $value;
     }
     return true;
 }
 function ParseOptimFROGheader45(&$fd, &$ThisFileInfo)
 {
     // for fileformat of v4.50a and higher
     $RIFFdata = '';
     fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
     while (!feof($fd) && ftell($fd) < $ThisFileInfo['avdataend']) {
         $BlockOffset = ftell($fd);
         $BlockData = fread($fd, 8);
         $offset = 8;
         $BlockName = substr($BlockData, 0, 4);
         $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4));
         if ($BlockName == 'OFRX') {
             $BlockName = 'OFR ';
         }
         if (!isset($ThisFileInfo['ofr'][$BlockName])) {
             $ThisFileInfo['ofr'][$BlockName] = array();
         }
         $thisfile_ofr_thisblock =& $ThisFileInfo['ofr'][$BlockName];
         switch ($BlockName) {
             case 'OFR ':
                 // shortcut
                 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
                 $thisfile_ofr_thisblock['size'] = $BlockSize;
                 $ThisFileInfo['audio']['encoder'] = 'OptimFROG 4.50 alpha';
                 switch ($BlockSize) {
                     case 12:
                     case 15:
                         // good
                         break;
                     default:
                         $ThisFileInfo['warning'][] = '"' . $BlockName . '" contains more data than expected (expected 12 or 15 bytes, found ' . $BlockSize . ' bytes)';
                         break;
                 }
                 $BlockData .= fread($fd, $BlockSize);
                 $thisfile_ofr_thisblock['total_samples'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 6));
                 $offset += 6;
                 $thisfile_ofr_thisblock['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
                 $thisfile_ofr_thisblock['sample_type'] = $this->OptimFROGsampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']);
                 $offset += 1;
                 $thisfile_ofr_thisblock['channel_config'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
                 $thisfile_ofr_thisblock['channels'] = $thisfile_ofr_thisblock['channel_config'];
                 $offset += 1;
                 $thisfile_ofr_thisblock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
                 $offset += 4;
                 if ($BlockSize > 12) {
                     // OFR 4.504b or higher
                     $thisfile_ofr_thisblock['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($thisfile_ofr_thisblock['channel_config']);
                     $thisfile_ofr_thisblock['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
                     $thisfile_ofr_thisblock['encoder'] = $this->OptimFROGencoderNameLookup($thisfile_ofr_thisblock['raw']['encoder_id']);
                     $offset += 2;
                     $thisfile_ofr_thisblock['raw']['compression'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
                     $thisfile_ofr_thisblock['compression'] = $this->OptimFROGcompressionLookup($thisfile_ofr_thisblock['raw']['compression']);
                     $thisfile_ofr_thisblock['speedup'] = $this->OptimFROGspeedupLookup($thisfile_ofr_thisblock['raw']['compression']);
                     $offset += 1;
                     $ThisFileInfo['audio']['encoder'] = 'OptimFROG ' . $thisfile_ofr_thisblock['encoder'];
                     $ThisFileInfo['audio']['encoder_options'] = '--mode ' . $thisfile_ofr_thisblock['compression'];
                     if (($thisfile_ofr_thisblock['raw']['encoder_id'] & 0xf0) >> 4 == 7) {
                         // v4.507
                         if (strtolower(getid3_lib::fileextension($ThisFileInfo['filename'])) == 'ofs') {
                             // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference
                             // between lossless and lossy other than the file extension.
                             $ThisFileInfo['audio']['dataformat'] = 'ofs';
                             $ThisFileInfo['audio']['lossless'] = true;
                         }
                     }
                 }
                 $ThisFileInfo['audio']['channels'] = $thisfile_ofr_thisblock['channels'];
                 $ThisFileInfo['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate'];
                 $ThisFileInfo['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']);
                 break;
             case 'COMP':
                 // unlike other block types, there CAN be multiple COMP blocks
                 $COMPdata['offset'] = $BlockOffset;
                 $COMPdata['size'] = $BlockSize;
                 if ($ThisFileInfo['avdataoffset'] == 0) {
                     $ThisFileInfo['avdataoffset'] = $BlockOffset;
                 }
                 // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data
                 $BlockData .= fread($fd, 14);
                 fseek($fd, $BlockSize - 14, SEEK_CUR);
                 $COMPdata['crc_32'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
                 $offset += 4;
                 $COMPdata['sample_count'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
                 $offset += 4;
                 $COMPdata['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
                 $COMPdata['sample_type'] = $this->OptimFROGsampleTypeLookup($COMPdata['raw']['sample_type']);
                 $offset += 1;
                 $COMPdata['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
                 $COMPdata['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($COMPdata['raw']['channel_configuration']);
                 $offset += 1;
                 $COMPdata['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
                 //$COMPdata['algorithm']                    = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']);
                 $offset += 2;
                 if ($ThisFileInfo['ofr']['OFR ']['size'] > 12) {
                     // OFR 4.504b or higher
                     $COMPdata['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
                     $COMPdata['encoder'] = $this->OptimFROGencoderNameLookup($COMPdata['raw']['encoder_id']);
                     $offset += 2;
                 }
                 if ($COMPdata['crc_32'] == 0x454e4f4e) {
                     // ASCII value of 'NONE' - placeholder value in v4.50a
                     $COMPdata['crc_32'] = false;
                 }
                 $thisfile_ofr_thisblock[] = $COMPdata;
                 break;
             case 'HEAD':
                 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
                 $thisfile_ofr_thisblock['size'] = $BlockSize;
                 $RIFFdata .= fread($fd, $BlockSize);
                 break;
             case 'TAIL':
                 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
                 $thisfile_ofr_thisblock['size'] = $BlockSize;
                 if ($BlockSize > 0) {
                     $RIFFdata .= fread($fd, $BlockSize);
                 }
                 break;
             case 'RECV':
                 // block contains no useful meta data - simply note and skip
                 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
                 $thisfile_ofr_thisblock['size'] = $BlockSize;
                 fseek($fd, $BlockSize, SEEK_CUR);
                 break;
             case 'APET':
                 // APEtag v2
                 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
                 $thisfile_ofr_thisblock['size'] = $BlockSize;
                 $ThisFileInfo['warning'][] = 'APEtag processing inside OptimFROG not supported in this version (' . GETID3_VERSION . ') of getID3()';
                 fseek($fd, $BlockSize, SEEK_CUR);
                 break;
             case 'MD5 ':
                 // APEtag v2
                 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
                 $thisfile_ofr_thisblock['size'] = $BlockSize;
                 if ($BlockSize == 16) {
                     $thisfile_ofr_thisblock['md5_binary'] = fread($fd, $BlockSize);
                     $thisfile_ofr_thisblock['md5_string'] = getid3_lib::PrintHexBytes($thisfile_ofr_thisblock['md5_binary'], true, false, false);
                     $ThisFileInfo['md5_data_source'] = $thisfile_ofr_thisblock['md5_string'];
                 } else {
                     $ThisFileInfo['warning'][] = 'Expecting block size of 16 in "MD5 " chunk, found ' . $BlockSize . ' instead';
                     fseek($fd, $BlockSize, SEEK_CUR);
                 }
                 break;
             default:
                 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
                 $thisfile_ofr_thisblock['size'] = $BlockSize;
                 $ThisFileInfo['warning'][] = 'Unhandled OptimFROG block type "' . $BlockName . '" at offset ' . $thisfile_ofr_thisblock['offset'];
                 fseek($fd, $BlockSize, SEEK_CUR);
                 break;
         }
     }
     if (isset($ThisFileInfo['ofr']['TAIL']['offset'])) {
         $ThisFileInfo['avdataend'] = $ThisFileInfo['ofr']['TAIL']['offset'];
     }
     $ThisFileInfo['playtime_seconds'] = (double) $ThisFileInfo['ofr']['OFR ']['total_samples'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate']);
     $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
     // move the data chunk after all other chunks (if any)
     // so that the RIFF parser doesn't see EOF when trying
     // to skip over the data chunk
     $RIFFdata = substr($RIFFdata, 0, 36) . substr($RIFFdata, 44) . substr($RIFFdata, 36, 8);
     getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo);
     return true;
 }
 private function parseEBML(&$info)
 {
     // http://www.matroska.org/technical/specs/index.html#EBMLBasics
     $this->current_offset = $info['avdataoffset'];
     while ($this->getEBMLelement($top_element, $info['avdataend'])) {
         switch ($top_element['id']) {
             case EBML_ID_EBML:
                 $info['fileformat'] = 'matroska';
                 $info['matroska']['header']['offset'] = $top_element['offset'];
                 $info['matroska']['header']['length'] = $top_element['length'];
                 while ($this->getEBMLelement($element_data, $top_element['end'], true)) {
                     switch ($element_data['id']) {
                         case EBML_ID_EBMLVERSION:
                         case EBML_ID_EBMLREADVERSION:
                         case EBML_ID_EBMLMAXIDLENGTH:
                         case EBML_ID_EBMLMAXSIZELENGTH:
                         case EBML_ID_DOCTYPEVERSION:
                         case EBML_ID_DOCTYPEREADVERSION:
                             $element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']);
                             break;
                         case EBML_ID_DOCTYPE:
                             $element_data['data'] = getid3_lib::trimNullByte($element_data['data']);
                             break;
                         case EBML_ID_CRC32:
                             // not useful, ignore
                             $this->current_offset = $element_data['end'];
                             unset($element_data);
                             break;
                         default:
                             $this->unhandledElement('header', __LINE__, $element_data);
                     }
                     if (!empty($element_data)) {
                         unset($element_data['offset'], $element_data['end']);
                         $info['matroska']['header']['elements'][] = $element_data;
                     }
                 }
                 break;
             case EBML_ID_SEGMENT:
                 $info['matroska']['segment'][0]['offset'] = $top_element['offset'];
                 $info['matroska']['segment'][0]['length'] = $top_element['length'];
                 while ($this->getEBMLelement($element_data, $top_element['end'])) {
                     if ($element_data['id'] != EBML_ID_CLUSTER || !self::$hide_clusters) {
                         // collect clusters only if required
                         $info['matroska']['segments'][] = $element_data;
                     }
                     switch ($element_data['id']) {
                         case EBML_ID_SEEKHEAD:
                             // Contains the position of other level 1 elements.
                             while ($this->getEBMLelement($seek_entry, $element_data['end'])) {
                                 switch ($seek_entry['id']) {
                                     case EBML_ID_SEEK:
                                         // Contains a single seek entry to an EBML element
                                         while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) {
                                             switch ($sub_seek_entry['id']) {
                                                 case EBML_ID_SEEKID:
                                                     $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']);
                                                     $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']);
                                                     break;
                                                 case EBML_ID_SEEKPOSITION:
                                                     $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']);
                                                     break;
                                                 default:
                                                     $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry);
                                             }
                                         }
                                         if ($seek_entry['target_id'] != EBML_ID_CLUSTER || !self::$hide_clusters) {
                                             // collect clusters only if required
                                             $info['matroska']['seek'][] = $seek_entry;
                                         }
                                         break;
                                     default:
                                         $this->unhandledElement('seekhead', __LINE__, $seek_entry);
                                 }
                             }
                             break;
                         case EBML_ID_TRACKS:
                             // A top-level block of information with many tracks described.
                             $info['matroska']['tracks'] = $element_data;
                             while ($this->getEBMLelement($track_entry, $element_data['end'])) {
                                 switch ($track_entry['id']) {
                                     case EBML_ID_TRACKENTRY:
                                         //subelements: Describes a track with all elements.
                                         while ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS))) {
                                             switch ($subelement['id']) {
                                                 case EBML_ID_TRACKNUMBER:
                                                 case EBML_ID_TRACKUID:
                                                 case EBML_ID_TRACKTYPE:
                                                 case EBML_ID_MINCACHE:
                                                 case EBML_ID_MAXCACHE:
                                                 case EBML_ID_MAXBLOCKADDITIONID:
                                                 case EBML_ID_DEFAULTDURATION:
                                                     // nanoseconds per frame
                                                     $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
                                                     break;
                                                 case EBML_ID_TRACKTIMECODESCALE:
                                                     $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']);
                                                     break;
                                                 case EBML_ID_CODECID:
                                                 case EBML_ID_LANGUAGE:
                                                 case EBML_ID_NAME:
                                                 case EBML_ID_CODECNAME:
                                                 case EBML_ID_CODECPRIVATE:
                                                     $track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
                                                     break;
                                                 case EBML_ID_FLAGENABLED:
                                                 case EBML_ID_FLAGDEFAULT:
                                                 case EBML_ID_FLAGFORCED:
                                                 case EBML_ID_FLAGLACING:
                                                 case EBML_ID_CODECDECODEALL:
                                                     $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']);
                                                     break;
                                                 case EBML_ID_VIDEO:
                                                     while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
                                                         switch ($sub_subelement['id']) {
                                                             case EBML_ID_PIXELWIDTH:
                                                             case EBML_ID_PIXELHEIGHT:
                                                             case EBML_ID_STEREOMODE:
                                                             case EBML_ID_PIXELCROPBOTTOM:
                                                             case EBML_ID_PIXELCROPTOP:
                                                             case EBML_ID_PIXELCROPLEFT:
                                                             case EBML_ID_PIXELCROPRIGHT:
                                                             case EBML_ID_DISPLAYWIDTH:
                                                             case EBML_ID_DISPLAYHEIGHT:
                                                             case EBML_ID_DISPLAYUNIT:
                                                             case EBML_ID_ASPECTRATIOTYPE:
                                                                 $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                                 break;
                                                             case EBML_ID_FLAGINTERLACED:
                                                                 $track_entry[$sub_subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                                 break;
                                                             case EBML_ID_GAMMAVALUE:
                                                                 $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']);
                                                                 break;
                                                             case EBML_ID_COLOURSPACE:
                                                                 $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
                                                                 break;
                                                             default:
                                                                 $this->unhandledElement('track.video', __LINE__, $sub_subelement);
                                                         }
                                                     }
                                                     if (isset($track_entry[$this->EBMLidName(EBML_ID_CODECID)]) && $track_entry[$this->EBMLidName(EBML_ID_CODECID)] == 'V_MS/VFW/FOURCC' && isset($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)])) {
                                                         if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, false)) {
                                                             $track_entry['codec_private_parsed'] = getid3_riff::ParseBITMAPINFOHEADER($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)]);
                                                         } else {
                                                             $this->getid3->warning('Unable to parse codec private data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio-video.riff.php"');
                                                         }
                                                     }
                                                     break;
                                                 case EBML_ID_AUDIO:
                                                     while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
                                                         switch ($sub_subelement['id']) {
                                                             case EBML_ID_CHANNELS:
                                                             case EBML_ID_BITDEPTH:
                                                                 $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                                 break;
                                                             case EBML_ID_SAMPLINGFREQUENCY:
                                                             case EBML_ID_OUTPUTSAMPLINGFREQUENCY:
                                                                 $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']);
                                                                 break;
                                                             case EBML_ID_CHANNELPOSITIONS:
                                                                 $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
                                                                 break;
                                                             default:
                                                                 $this->unhandledElement('track.audio', __LINE__, $sub_subelement);
                                                         }
                                                     }
                                                     break;
                                                 case EBML_ID_CONTENTENCODINGS:
                                                     while ($this->getEBMLelement($sub_subelement, $subelement['end'])) {
                                                         switch ($sub_subelement['id']) {
                                                             case EBML_ID_CONTENTENCODING:
                                                                 while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CONTENTCOMPRESSION, EBML_ID_CONTENTENCRYPTION))) {
                                                                     switch ($sub_sub_subelement['id']) {
                                                                         case EBML_ID_CONTENTENCODINGORDER:
                                                                         case EBML_ID_CONTENTENCODINGSCOPE:
                                                                         case EBML_ID_CONTENTENCODINGTYPE:
                                                                             $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
                                                                             break;
                                                                         case EBML_ID_CONTENTCOMPRESSION:
                                                                             while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
                                                                                 switch ($sub_sub_sub_subelement['id']) {
                                                                                     case EBML_ID_CONTENTCOMPALGO:
                                                                                         $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
                                                                                         break;
                                                                                     case EBML_ID_CONTENTCOMPSETTINGS:
                                                                                         $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
                                                                                         break;
                                                                                     default:
                                                                                         $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
                                                                                 }
                                                                             }
                                                                             break;
                                                                         case EBML_ID_CONTENTENCRYPTION:
                                                                             while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
                                                                                 switch ($sub_sub_sub_subelement['id']) {
                                                                                     case EBML_ID_CONTENTENCALGO:
                                                                                     case EBML_ID_CONTENTSIGALGO:
                                                                                     case EBML_ID_CONTENTSIGHASHALGO:
                                                                                         $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
                                                                                         break;
                                                                                     case EBML_ID_CONTENTENCKEYID:
                                                                                     case EBML_ID_CONTENTSIGNATURE:
                                                                                     case EBML_ID_CONTENTSIGKEYID:
                                                                                         $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
                                                                                         break;
                                                                                     default:
                                                                                         $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
                                                                                 }
                                                                             }
                                                                             break;
                                                                         default:
                                                                             $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement);
                                                                     }
                                                                 }
                                                                 break;
                                                             default:
                                                                 $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement);
                                                         }
                                                     }
                                                     break;
                                                 default:
                                                     $this->unhandledElement('track', __LINE__, $subelement);
                                             }
                                         }
                                         $info['matroska']['tracks']['tracks'][] = $track_entry;
                                         break;
                                     default:
                                         $this->unhandledElement('tracks', __LINE__, $track_entry);
                                 }
                             }
                             break;
                         case EBML_ID_INFO:
                             // Contains miscellaneous general information and statistics on the file.
                             $info_entry = array();
                             while ($this->getEBMLelement($subelement, $element_data['end'], true)) {
                                 switch ($subelement['id']) {
                                     case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
                                     case EBML_ID_CHAPTERTRANSLATECODEC:
                                     case EBML_ID_TIMECODESCALE:
                                         $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
                                         break;
                                     case EBML_ID_DURATION:
                                         $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']);
                                         break;
                                     case EBML_ID_DATEUTC:
                                         $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
                                         $info_entry[$subelement['id_name'] . '_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]);
                                         break;
                                     case EBML_ID_SEGMENTUID:
                                     case EBML_ID_PREVUID:
                                     case EBML_ID_NEXTUID:
                                     case EBML_ID_SEGMENTFAMILY:
                                     case EBML_ID_CHAPTERTRANSLATEID:
                                         $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
                                         break;
                                     case EBML_ID_SEGMENTFILENAME:
                                     case EBML_ID_PREVFILENAME:
                                     case EBML_ID_NEXTFILENAME:
                                     case EBML_ID_TITLE:
                                     case EBML_ID_MUXINGAPP:
                                     case EBML_ID_WRITINGAPP:
                                         $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']);
                                         $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']];
                                         break;
                                     default:
                                         $this->unhandledElement('info', __LINE__, $subelement);
                                 }
                             }
                             $info['matroska']['info'][] = $info_entry;
                             break;
                         case EBML_ID_CUES:
                             // A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non "live" streams.
                             if (self::$hide_clusters) {
                                 // do not parse cues if hide clusters is "ON" till they point to clusters anyway
                                 $this->current_offset = $element_data['end'];
                                 break;
                             }
                             $cues_entry = array();
                             while ($this->getEBMLelement($subelement, $element_data['end'])) {
                                 switch ($subelement['id']) {
                                     case EBML_ID_CUEPOINT:
                                         $cuepoint_entry = array();
                                         while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) {
                                             switch ($sub_subelement['id']) {
                                                 case EBML_ID_CUETRACKPOSITIONS:
                                                     while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
                                                         switch ($sub_sub_subelement['id']) {
                                                             case EBML_ID_CUETRACK:
                                                             case EBML_ID_CUECLUSTERPOSITION:
                                                                 $cuepoint_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
                                                                 break;
                                                             default:
                                                                 $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement);
                                                         }
                                                     }
                                                     break;
                                                 case EBML_ID_CUETIME:
                                                     $cuepoint_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                     break;
                                                 default:
                                                     $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement);
                                             }
                                         }
                                         $cues_entry[] = $cuepoint_entry;
                                         break;
                                     default:
                                         $this->unhandledElement('cues', __LINE__, $subelement);
                                 }
                             }
                             $info['matroska']['cues'] = $cues_entry;
                             break;
                         case EBML_ID_TAGS:
                             // Element containing elements specific to Tracks/Chapters.
                             $tags_entry = array();
                             while ($this->getEBMLelement($subelement, $element_data['end'], array(EBML_ID_TAG))) {
                                 $tag_entry = array();
                                 switch ($subelement['id']) {
                                     case EBML_ID_WRITINGAPP:
                                         $tag_entry[$subelement['id_name']] = $subelement['data'];
                                         break;
                                     case EBML_ID_TAG:
                                         while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_TARGETS, EBML_ID_SIMPLETAG))) {
                                             switch ($sub_subelement['id']) {
                                                 case EBML_ID_TARGETS:
                                                     $targets_entry = array();
                                                     while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
                                                         switch ($sub_sub_subelement['id']) {
                                                             case EBML_ID_TARGETTYPEVALUE:
                                                                 $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
                                                                 $targets_entry[strtolower($sub_sub_subelement['id_name']) . '_long'] = $this->MatroskaTargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]);
                                                                 break;
                                                             case EBML_ID_EDITIONUID:
                                                             case EBML_ID_CHAPTERUID:
                                                             case EBML_ID_ATTACHMENTUID:
                                                             case EBML_ID_TAGTRACKUID:
                                                             case EBML_ID_TAGCHAPTERUID:
                                                                 $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
                                                                 break;
                                                             default:
                                                                 $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement);
                                                         }
                                                     }
                                                     $tag_entry[$sub_subelement['id_name']][] = $targets_entry;
                                                     break;
                                                 case EBML_ID_SIMPLETAG:
                                                     $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']);
                                                     break;
                                                 case EBML_ID_TARGETTYPE:
                                                     $tag_entry[$sub_subelement['id_name']] = $sub_subelement['data'];
                                                     break;
                                                 case EBML_ID_TRACKUID:
                                                     $tag_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                     break;
                                                 default:
                                                     $this->unhandledElement('tags.tag', __LINE__, $sub_subelement);
                                             }
                                         }
                                         break;
                                     default:
                                         $this->unhandledElement('tags', __LINE__, $subelement);
                                 }
                                 $tags_entry['tags'][] = $tag_entry;
                             }
                             $info['matroska']['tags'] = $tags_entry['tags'];
                             break;
                         case EBML_ID_ATTACHMENTS:
                             // Contain attached files.
                             while ($this->getEBMLelement($subelement, $element_data['end'])) {
                                 switch ($subelement['id']) {
                                     case EBML_ID_ATTACHEDFILE:
                                         $attachedfile_entry = array();
                                         while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_FILEDATA))) {
                                             switch ($sub_subelement['id']) {
                                                 case EBML_ID_FILEDESCRIPTION:
                                                 case EBML_ID_FILENAME:
                                                 case EBML_ID_FILEMIMETYPE:
                                                     $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data'];
                                                     break;
                                                 case EBML_ID_FILEDATA:
                                                     $attachedfile_entry['data_offset'] = $this->current_offset;
                                                     $attachedfile_entry['data_length'] = $sub_subelement['length'];
                                                     $this->getid3->saveAttachment($attachedfile_entry[$sub_subelement['id_name']], $attachedfile_entry[$this->EBMLidName(EBML_ID_FILENAME)], $attachedfile_entry['data_offset'], $attachedfile_entry['data_length']);
                                                     if (@$attachedfile_entry[$sub_subelement['id_name']] && is_file($attachedfile_entry[$sub_subelement['id_name']])) {
                                                         $attachedfile_entry[$sub_subelement['id_name'] . '_filename'] = $attachedfile_entry[$sub_subelement['id_name']];
                                                         unset($attachedfile_entry[$sub_subelement['id_name']]);
                                                     }
                                                     $this->current_offset = $sub_subelement['end'];
                                                     break;
                                                 case EBML_ID_FILEUID:
                                                     $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                     break;
                                                 default:
                                                     $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement);
                                             }
                                         }
                                         if (!empty($attachedfile_entry[$this->EBMLidName(EBML_ID_FILEDATA)]) && !empty($attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)]) && preg_match('#^image/#i', $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)])) {
                                             if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
                                                 $attachedfile_entry['data'] = $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEDATA)];
                                                 $attachedfile_entry['image_mime'] = $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)];
                                                 $info['matroska']['comments']['picture'][] = array('data' => $attachedfile_entry['data'], 'image_mime' => $attachedfile_entry['image_mime'], 'filename' => !empty($attachedfile_entry[$this->EBMLidName(EBML_ID_FILENAME)]) ? $attachedfile_entry[$this->EBMLidName(EBML_ID_FILENAME)] : '');
                                                 unset($attachedfile_entry[$this->EBMLidName(EBML_ID_FILEDATA)], $attachedfile_entry[$this->EBMLidName(EBML_ID_FILEMIMETYPE)]);
                                             }
                                         }
                                         if (!empty($attachedfile_entry['image_mime']) && preg_match('#^image/#i', $attachedfile_entry['image_mime'])) {
                                             // don't add a second copy of attached images, which are grouped under the standard location [comments][picture]
                                         } else {
                                             $info['matroska']['attachments'][] = $attachedfile_entry;
                                         }
                                         break;
                                     default:
                                         $this->unhandledElement('attachments', __LINE__, $subelement);
                                 }
                             }
                             break;
                         case EBML_ID_CHAPTERS:
                             while ($this->getEBMLelement($subelement, $element_data['end'])) {
                                 switch ($subelement['id']) {
                                     case EBML_ID_EDITIONENTRY:
                                         $editionentry_entry = array();
                                         while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CHAPTERATOM))) {
                                             switch ($sub_subelement['id']) {
                                                 case EBML_ID_EDITIONUID:
                                                     $editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                     break;
                                                 case EBML_ID_EDITIONFLAGHIDDEN:
                                                 case EBML_ID_EDITIONFLAGDEFAULT:
                                                 case EBML_ID_EDITIONFLAGORDERED:
                                                     $editionentry_entry[$sub_subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                     break;
                                                 case EBML_ID_CHAPTERATOM:
                                                     $chapteratom_entry = array();
                                                     while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CHAPTERTRACK, EBML_ID_CHAPTERDISPLAY))) {
                                                         switch ($sub_sub_subelement['id']) {
                                                             case EBML_ID_CHAPTERSEGMENTUID:
                                                             case EBML_ID_CHAPTERSEGMENTEDITIONUID:
                                                                 $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data'];
                                                                 break;
                                                             case EBML_ID_CHAPTERFLAGENABLED:
                                                             case EBML_ID_CHAPTERFLAGHIDDEN:
                                                                 $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
                                                                 break;
                                                             case EBML_ID_CHAPTERUID:
                                                             case EBML_ID_CHAPTERTIMESTART:
                                                             case EBML_ID_CHAPTERTIMEEND:
                                                                 $chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
                                                                 break;
                                                             case EBML_ID_CHAPTERTRACK:
                                                                 $chaptertrack_entry = array();
                                                                 while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
                                                                     switch ($sub_sub_sub_subelement['id']) {
                                                                         case EBML_ID_CHAPTERTRACKNUMBER:
                                                                             $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
                                                                             break;
                                                                         default:
                                                                             $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement);
                                                                     }
                                                                 }
                                                                 $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry;
                                                                 break;
                                                             case EBML_ID_CHAPTERDISPLAY:
                                                                 $chapterdisplay_entry = array();
                                                                 while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) {
                                                                     switch ($sub_sub_sub_subelement['id']) {
                                                                         case EBML_ID_CHAPSTRING:
                                                                         case EBML_ID_CHAPLANGUAGE:
                                                                         case EBML_ID_CHAPCOUNTRY:
                                                                             $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
                                                                             break;
                                                                         default:
                                                                             $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement);
                                                                     }
                                                                 }
                                                                 $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry;
                                                                 break;
                                                             default:
                                                                 $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement);
                                                         }
                                                     }
                                                     $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry;
                                                     break;
                                                 default:
                                                     $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement);
                                             }
                                         }
                                         $info['matroska']['chapters'][] = $editionentry_entry;
                                         break;
                                     default:
                                         $this->unhandledElement('chapters', __LINE__, $subelement);
                                 }
                             }
                             break;
                         case EBML_ID_VOID:
                             // padding, ignore
                             $void_entry = array();
                             // TODO: do we really need to collect void's?
                             $void_entry['offset'] = $this->current_offset;
                             $info['matroska']['void'][] = $void_entry;
                             $this->current_offset = $element_data['end'];
                             break;
                         case EBML_ID_CLUSTER:
                             // The lower level element containing the (monolithic) Block structure.
                             $cluster_entry = array();
                             while ($this->getEBMLelement($subelement, $element_data['end'], array(EBML_ID_CLUSTERSILENTTRACKS, EBML_ID_CLUSTERBLOCKGROUP, EBML_ID_CLUSTERSIMPLEBLOCK))) {
                                 switch ($subelement['id']) {
                                     case EBML_ID_CLUSTERTIMECODE:
                                     case EBML_ID_CLUSTERPOSITION:
                                     case EBML_ID_CLUSTERPREVSIZE:
                                         $cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
                                         break;
                                     case EBML_ID_CLUSTERSILENTTRACKS:
                                         $cluster_silent_tracks = array();
                                         while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
                                             switch ($sub_subelement['id']) {
                                                 case EBML_ID_CLUSTERSILENTTRACKNUMBER:
                                                     $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                     break;
                                                 default:
                                                     $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement);
                                             }
                                         }
                                         $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks;
                                         break;
                                     case EBML_ID_CLUSTERBLOCKGROUP:
                                         $cluster_block_group = array('offset' => $this->current_offset);
                                         while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CLUSTERBLOCK))) {
                                             switch ($sub_subelement['id']) {
                                                 case EBML_ID_CLUSTERBLOCK:
                                                     $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, EBML_ID_CLUSTERBLOCK, $info);
                                                     break;
                                                 case EBML_ID_CLUSTERREFERENCEPRIORITY:
                                                     // unsigned-int
                                                 // unsigned-int
                                                 case EBML_ID_CLUSTERBLOCKDURATION:
                                                     // unsigned-int
                                                     $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
                                                     break;
                                                 case EBML_ID_CLUSTERREFERENCEBLOCK:
                                                     // signed-int
                                                     $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data'], false, true);
                                                     break;
                                                 default:
                                                     $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement);
                                             }
                                         }
                                         $cluster_entry[$subelement['id_name']][] = $cluster_block_group;
                                         break;
                                     case EBML_ID_CLUSTERSIMPLEBLOCK:
                                         $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info);
                                         break;
                                     default:
                                         $this->unhandledElement('cluster', __LINE__, $subelement);
                                 }
                                 $this->current_offset = $subelement['end'];
                             }
                             if (!self::$hide_clusters) {
                                 $info['matroska']['cluster'][] = $cluster_entry;
                             }
                             // check to see if all the data we need exists already, if so, break out of the loop
                             if (!self::$parse_whole_file) {
                                 if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
                                     if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
                                         return;
                                     }
                                 }
                             }
                             break;
                         default:
                             $this->unhandledElement('segment', __LINE__, $element_data);
                     }
                 }
                 break;
             default:
                 $this->unhandledElement('root', __LINE__, $top_element);
         }
     }
 }
 function RIFFparseWAVEFORMATex($WaveFormatExData)
 {
     // shortcut
     $WaveFormatEx['raw'] = array();
     $WaveFormatEx_raw =& $WaveFormatEx['raw'];
     $WaveFormatEx_raw['wFormatTag'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 0, 2));
     $WaveFormatEx_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 2, 2));
     $WaveFormatEx_raw['nSamplesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 4, 4));
     $WaveFormatEx_raw['nAvgBytesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 8, 4));
     $WaveFormatEx_raw['nBlockAlign'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 12, 2));
     $WaveFormatEx_raw['wBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 14, 2));
     if (strlen($WaveFormatExData) > 16) {
         $WaveFormatEx_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 16, 2));
     }
     $WaveFormatEx['codec'] = getid3_riff::RIFFwFormatTagLookup($WaveFormatEx_raw['wFormatTag']);
     $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels'];
     $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec'];
     $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8;
     $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample'];
     return $WaveFormatEx;
 }
 function Analyze()
 {
     $info =& $this->getid3->info;
     fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     while (true) {
         $wavpackheader = fread($this->getid3->fp, 32);
         if (ftell($this->getid3->fp) >= $info['avdataend']) {
             break;
         } elseif (feof($this->getid3->fp)) {
             break;
         } elseif (isset($info['wavpack']['blockheader']['total_samples']) && isset($info['wavpack']['blockheader']['block_samples']) && $info['wavpack']['blockheader']['total_samples'] > 0 && $info['wavpack']['blockheader']['block_samples'] > 0 && (!isset($info['wavpack']['riff_trailer_size']) || $info['wavpack']['riff_trailer_size'] <= 0) && (isset($info['wavpack']['config_flags']['md5_checksum']) && $info['wavpack']['config_flags']['md5_checksum'] === false || !empty($info['md5_data_source']))) {
             break;
         }
         $blockheader_offset = ftell($this->getid3->fp) - 32;
         $blockheader_magic = substr($wavpackheader, 0, 4);
         $blockheader_size = getid3_lib::LittleEndian2Int(substr($wavpackheader, 4, 4));
         $magic = 'wvpk';
         if ($blockheader_magic != $magic) {
             $info['error'][] = 'Expecting "' . getid3_lib::PrintHexBytes($magic) . '" at offset ' . $blockheader_offset . ', found "' . getid3_lib::PrintHexBytes($blockheader_magic) . '"';
             switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') {
                 case 'wavpack':
                 case 'wvc':
                     break;
                 default:
                     unset($info['fileformat']);
                     unset($info['audio']);
                     unset($info['wavpack']);
                     break;
             }
             return false;
         }
         if (empty($info['wavpack']['blockheader']['block_samples']) || empty($info['wavpack']['blockheader']['total_samples']) || $info['wavpack']['blockheader']['block_samples'] <= 0 || $info['wavpack']['blockheader']['total_samples'] <= 0) {
             // Also, it is possible that the first block might not have
             // any samples (block_samples == 0) and in this case you should skip blocks
             // until you find one with samples because the other information (like
             // total_samples) are not guaranteed to be correct until (block_samples > 0)
             // Finally, I have defined a format for files in which the length is not known
             // (for example when raw files are created using pipes). In these cases
             // total_samples will be -1 and you must seek to the final block to determine
             // the total number of samples.
             $info['audio']['dataformat'] = 'wavpack';
             $info['fileformat'] = 'wavpack';
             $info['audio']['lossless'] = true;
             $info['audio']['bitrate_mode'] = 'vbr';
             $info['wavpack']['blockheader']['offset'] = $blockheader_offset;
             $info['wavpack']['blockheader']['magic'] = $blockheader_magic;
             $info['wavpack']['blockheader']['size'] = $blockheader_size;
             if ($info['wavpack']['blockheader']['size'] >= 0x100000) {
                 $info['error'][] = 'Expecting WavPack block size less than "0x100000", found "' . $info['wavpack']['blockheader']['size'] . '" at offset ' . $info['wavpack']['blockheader']['offset'];
                 switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') {
                     case 'wavpack':
                     case 'wvc':
                         break;
                     default:
                         unset($info['fileformat']);
                         unset($info['audio']);
                         unset($info['wavpack']);
                         break;
                 }
                 return false;
             }
             $info['wavpack']['blockheader']['minor_version'] = ord($wavpackheader[8]);
             $info['wavpack']['blockheader']['major_version'] = ord($wavpackheader[9]);
             if ($info['wavpack']['blockheader']['major_version'] != 4 || $info['wavpack']['blockheader']['minor_version'] < 4 && $info['wavpack']['blockheader']['minor_version'] > 16) {
                 $info['error'][] = 'Expecting WavPack version between "4.2" and "4.16", found version "' . $info['wavpack']['blockheader']['major_version'] . '.' . $info['wavpack']['blockheader']['minor_version'] . '" at offset ' . $info['wavpack']['blockheader']['offset'];
                 switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') {
                     case 'wavpack':
                     case 'wvc':
                         break;
                     default:
                         unset($info['fileformat']);
                         unset($info['audio']);
                         unset($info['wavpack']);
                         break;
                 }
                 return false;
             }
             $info['wavpack']['blockheader']['track_number'] = ord($wavpackheader[10]);
             // unused
             $info['wavpack']['blockheader']['index_number'] = ord($wavpackheader[11]);
             // unused
             $info['wavpack']['blockheader']['total_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 12, 4));
             $info['wavpack']['blockheader']['block_index'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 16, 4));
             $info['wavpack']['blockheader']['block_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 20, 4));
             $info['wavpack']['blockheader']['flags_raw'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 24, 4));
             $info['wavpack']['blockheader']['crc'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 28, 4));
             $info['wavpack']['blockheader']['flags']['bytes_per_sample'] = 1 + ($info['wavpack']['blockheader']['flags_raw'] & 0x3);
             $info['wavpack']['blockheader']['flags']['mono'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x4);
             $info['wavpack']['blockheader']['flags']['hybrid'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x8);
             $info['wavpack']['blockheader']['flags']['joint_stereo'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x10);
             $info['wavpack']['blockheader']['flags']['cross_decorrelation'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x20);
             $info['wavpack']['blockheader']['flags']['hybrid_noiseshape'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x40);
             $info['wavpack']['blockheader']['flags']['ieee_32bit_float'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x80);
             $info['wavpack']['blockheader']['flags']['int_32bit'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x100);
             $info['wavpack']['blockheader']['flags']['hybrid_bitrate_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x200);
             $info['wavpack']['blockheader']['flags']['hybrid_balance_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x400);
             $info['wavpack']['blockheader']['flags']['multichannel_initial'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x800);
             $info['wavpack']['blockheader']['flags']['multichannel_final'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x1000);
             $info['audio']['lossless'] = !$info['wavpack']['blockheader']['flags']['hybrid'];
         }
         while (!feof($this->getid3->fp) && ftell($this->getid3->fp) < $blockheader_offset + $blockheader_size + 8) {
             $metablock = array('offset' => ftell($this->getid3->fp));
             $metablockheader = fread($this->getid3->fp, 2);
             if (feof($this->getid3->fp)) {
                 break;
             }
             $metablock['id'] = ord($metablockheader[0]);
             $metablock['function_id'] = $metablock['id'] & 0x3f;
             $metablock['function_name'] = $this->WavPackMetablockNameLookup($metablock['function_id']);
             // The 0x20 bit in the id of the meta subblocks (which is defined as
             // ID_OPTIONAL_DATA) is a permanent part of the id. The idea is that
             // if a decoder encounters an id that it does not know about, it uses
             // that "ID_OPTIONAL_DATA" flag to determine what to do. If it is set
             // then the decoder simply ignores the metadata, but if it is zero
             // then the decoder should quit because it means that an understanding
             // of the metadata is required to correctly decode the audio.
             $metablock['non_decoder'] = (bool) ($metablock['id'] & 0x20);
             $metablock['padded_data'] = (bool) ($metablock['id'] & 0x40);
             $metablock['large_block'] = (bool) ($metablock['id'] & 0x80);
             if ($metablock['large_block']) {
                 $metablockheader .= fread($this->getid3->fp, 2);
             }
             $metablock['size'] = getid3_lib::LittleEndian2Int(substr($metablockheader, 1)) * 2;
             // size is stored in words
             $metablock['data'] = null;
             if ($metablock['size'] > 0) {
                 switch ($metablock['function_id']) {
                     case 0x21:
                         // ID_RIFF_HEADER
                     // ID_RIFF_HEADER
                     case 0x22:
                         // ID_RIFF_TRAILER
                     // ID_RIFF_TRAILER
                     case 0x23:
                         // ID_REPLAY_GAIN
                     // ID_REPLAY_GAIN
                     case 0x24:
                         // ID_CUESHEET
                     // ID_CUESHEET
                     case 0x25:
                         // ID_CONFIG_BLOCK
                     // ID_CONFIG_BLOCK
                     case 0x26:
                         // ID_MD5_CHECKSUM
                         $metablock['data'] = fread($this->getid3->fp, $metablock['size']);
                         if ($metablock['padded_data']) {
                             // padded to the nearest even byte
                             $metablock['size']--;
                             $metablock['data'] = substr($metablock['data'], 0, -1);
                         }
                         break;
                     case 0x0:
                         // ID_DUMMY
                     // ID_DUMMY
                     case 0x1:
                         // ID_ENCODER_INFO
                     // ID_ENCODER_INFO
                     case 0x2:
                         // ID_DECORR_TERMS
                     // ID_DECORR_TERMS
                     case 0x3:
                         // ID_DECORR_WEIGHTS
                     // ID_DECORR_WEIGHTS
                     case 0x4:
                         // ID_DECORR_SAMPLES
                     // ID_DECORR_SAMPLES
                     case 0x5:
                         // ID_ENTROPY_VARS
                     // ID_ENTROPY_VARS
                     case 0x6:
                         // ID_HYBRID_PROFILE
                     // ID_HYBRID_PROFILE
                     case 0x7:
                         // ID_SHAPING_WEIGHTS
                     // ID_SHAPING_WEIGHTS
                     case 0x8:
                         // ID_FLOAT_INFO
                     // ID_FLOAT_INFO
                     case 0x9:
                         // ID_INT32_INFO
                     // ID_INT32_INFO
                     case 0xa:
                         // ID_WV_BITSTREAM
                     // ID_WV_BITSTREAM
                     case 0xb:
                         // ID_WVC_BITSTREAM
                     // ID_WVC_BITSTREAM
                     case 0xc:
                         // ID_WVX_BITSTREAM
                     // ID_WVX_BITSTREAM
                     case 0xd:
                         // ID_CHANNEL_INFO
                         fseek($this->getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET);
                         break;
                     default:
                         $info['warning'][] = 'Unexpected metablock type "0x' . str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT) . '" at offset ' . $metablock['offset'];
                         fseek($this->getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET);
                         break;
                 }
                 switch ($metablock['function_id']) {
                     case 0x21:
                         // ID_RIFF_HEADER
                         getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, true);
                         $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4));
                         $getid3_temp = new getID3();
                         $getid3_temp->openfile($this->getid3->filename);
                         $getid3_riff = new getid3_riff($getid3_temp);
                         $getid3_riff->ParseRIFFdata($metablock['data']);
                         $metablock['riff'] = $getid3_temp->info['riff'];
                         $info['audio']['sample_rate'] = $getid3_temp->info['riff']['raw']['fmt ']['nSamplesPerSec'];
                         unset($getid3_riff, $getid3_temp);
                         $metablock['riff']['original_filesize'] = $original_wav_filesize;
                         $info['wavpack']['riff_trailer_size'] = $original_wav_filesize - $metablock['riff']['WAVE']['data'][0]['size'] - $metablock['riff']['header_size'];
                         $info['playtime_seconds'] = $info['wavpack']['blockheader']['total_samples'] / $info['audio']['sample_rate'];
                         // Safe RIFF header in case there's a RIFF footer later
                         $metablockRIFFheader = $metablock['data'];
                         break;
                     case 0x22:
                         // ID_RIFF_TRAILER
                         $metablockRIFFfooter = $metablockRIFFheader . $metablock['data'];
                         getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, true);
                         $startoffset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2);
                         $getid3_temp = new getID3();
                         $getid3_temp->openfile($this->getid3->filename);
                         $getid3_temp->info['avdataend'] = $info['avdataend'];
                         $getid3_temp->info['fileformat'] = 'riff';
                         $getid3_riff = new getid3_riff($getid3_temp);
                         $metablock['riff'] = $getid3_riff->ParseRIFF($startoffset, $startoffset + $metablock['size']);
                         if (!empty($metablock['riff']['INFO'])) {
                             $getid3_riff->RIFFcommentsParse($metablock['riff']['INFO'], $metablock['comments']);
                             $info['tags']['riff'] = $metablock['comments'];
                         }
                         unset($getid3_temp, $getid3_riff);
                         break;
                     case 0x23:
                         // ID_REPLAY_GAIN
                         $info['warning'][] = 'WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset ' . $metablock['offset'];
                         break;
                     case 0x24:
                         // ID_CUESHEET
                         $info['warning'][] = 'WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset ' . $metablock['offset'];
                         break;
                     case 0x25:
                         // ID_CONFIG_BLOCK
                         $metablock['flags_raw'] = getid3_lib::LittleEndian2Int(substr($metablock['data'], 0, 3));
                         $metablock['flags']['adobe_mode'] = (bool) ($metablock['flags_raw'] & 0x1);
                         // "adobe" mode for 32-bit floats
                         $metablock['flags']['fast_flag'] = (bool) ($metablock['flags_raw'] & 0x2);
                         // fast mode
                         $metablock['flags']['very_fast_flag'] = (bool) ($metablock['flags_raw'] & 0x4);
                         // double fast
                         $metablock['flags']['high_flag'] = (bool) ($metablock['flags_raw'] & 0x8);
                         // high quality mode
                         $metablock['flags']['very_high_flag'] = (bool) ($metablock['flags_raw'] & 0x10);
                         // double high (not used yet)
                         $metablock['flags']['bitrate_kbps'] = (bool) ($metablock['flags_raw'] & 0x20);
                         // bitrate is kbps, not bits / sample
                         $metablock['flags']['auto_shaping'] = (bool) ($metablock['flags_raw'] & 0x40);
                         // automatic noise shaping
                         $metablock['flags']['shape_override'] = (bool) ($metablock['flags_raw'] & 0x80);
                         // shaping mode specified
                         $metablock['flags']['joint_override'] = (bool) ($metablock['flags_raw'] & 0x100);
                         // joint-stereo mode specified
                         $metablock['flags']['copy_time'] = (bool) ($metablock['flags_raw'] & 0x200);
                         // copy file-time from source
                         $metablock['flags']['create_exe'] = (bool) ($metablock['flags_raw'] & 0x400);
                         // create executable
                         $metablock['flags']['create_wvc'] = (bool) ($metablock['flags_raw'] & 0x800);
                         // create correction file
                         $metablock['flags']['optimize_wvc'] = (bool) ($metablock['flags_raw'] & 0x1000);
                         // maximize bybrid compression
                         $metablock['flags']['quality_mode'] = (bool) ($metablock['flags_raw'] & 0x2000);
                         // psychoacoustic quality mode
                         $metablock['flags']['raw_flag'] = (bool) ($metablock['flags_raw'] & 0x4000);
                         // raw mode (not implemented yet)
                         $metablock['flags']['calc_noise'] = (bool) ($metablock['flags_raw'] & 0x8000);
                         // calc noise in hybrid mode
                         $metablock['flags']['lossy_mode'] = (bool) ($metablock['flags_raw'] & 0x10000);
                         // obsolete (for information)
                         $metablock['flags']['extra_mode'] = (bool) ($metablock['flags_raw'] & 0x20000);
                         // extra processing mode
                         $metablock['flags']['skip_wvx'] = (bool) ($metablock['flags_raw'] & 0x40000);
                         // no wvx stream w/ floats & big ints
                         $metablock['flags']['md5_checksum'] = (bool) ($metablock['flags_raw'] & 0x80000);
                         // compute & store MD5 signature
                         $metablock['flags']['quiet_mode'] = (bool) ($metablock['flags_raw'] & 0x100000);
                         // don't report progress %
                         $info['wavpack']['config_flags'] = $metablock['flags'];
                         $info['audio']['encoder_options'] = '';
                         if ($info['wavpack']['blockheader']['flags']['hybrid']) {
                             $info['audio']['encoder_options'] .= ' -b???';
                         }
                         $info['audio']['encoder_options'] .= $metablock['flags']['adobe_mode'] ? ' -a' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['optimize_wvc'] ? ' -cc' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['create_exe'] ? ' -e' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['fast_flag'] ? ' -f' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['joint_override'] ? ' -j?' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['high_flag'] ? ' -h' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['md5_checksum'] ? ' -m' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['calc_noise'] ? ' -n' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['shape_override'] ? ' -s?' : '';
                         $info['audio']['encoder_options'] .= $metablock['flags']['extra_mode'] ? ' -x?' : '';
                         if (!empty($info['audio']['encoder_options'])) {
                             $info['audio']['encoder_options'] = trim($info['audio']['encoder_options']);
                         } elseif (isset($info['audio']['encoder_options'])) {
                             unset($info['audio']['encoder_options']);
                         }
                         break;
                     case 0x26:
                         // ID_MD5_CHECKSUM
                         if (strlen($metablock['data']) == 16) {
                             $info['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false));
                         } else {
                             $info['warning'][] = 'Expecting 16 bytes of WavPack "MD5 Checksum" in metablock at offset ' . $metablock['offset'] . ', but found ' . strlen($metablock['data']) . ' bytes';
                         }
                         break;
                     case 0x0:
                         // ID_DUMMY
                     // ID_DUMMY
                     case 0x1:
                         // ID_ENCODER_INFO
                     // ID_ENCODER_INFO
                     case 0x2:
                         // ID_DECORR_TERMS
                     // ID_DECORR_TERMS
                     case 0x3:
                         // ID_DECORR_WEIGHTS
                     // ID_DECORR_WEIGHTS
                     case 0x4:
                         // ID_DECORR_SAMPLES
                     // ID_DECORR_SAMPLES
                     case 0x5:
                         // ID_ENTROPY_VARS
                     // ID_ENTROPY_VARS
                     case 0x6:
                         // ID_HYBRID_PROFILE
                     // ID_HYBRID_PROFILE
                     case 0x7:
                         // ID_SHAPING_WEIGHTS
                     // ID_SHAPING_WEIGHTS
                     case 0x8:
                         // ID_FLOAT_INFO
                     // ID_FLOAT_INFO
                     case 0x9:
                         // ID_INT32_INFO
                     // ID_INT32_INFO
                     case 0xa:
                         // ID_WV_BITSTREAM
                     // ID_WV_BITSTREAM
                     case 0xb:
                         // ID_WVC_BITSTREAM
                     // ID_WVC_BITSTREAM
                     case 0xc:
                         // ID_WVX_BITSTREAM
                     // ID_WVX_BITSTREAM
                     case 0xd:
                         // ID_CHANNEL_INFO
                         unset($metablock);
                         break;
                 }
             }
             if (!empty($metablock)) {
                 $info['wavpack']['metablocks'][] = $metablock;
             }
         }
     }
     $info['audio']['encoder'] = 'WavPack v' . $info['wavpack']['blockheader']['major_version'] . '.' . str_pad($info['wavpack']['blockheader']['minor_version'], 2, '0', STR_PAD_LEFT);
     $info['audio']['bits_per_sample'] = $info['wavpack']['blockheader']['flags']['bytes_per_sample'] * 8;
     $info['audio']['channels'] = $info['wavpack']['blockheader']['flags']['mono'] ? 1 : 2;
     if (!empty($info['playtime_seconds'])) {
         $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds'];
     } else {
         $info['audio']['dataformat'] = 'wvc';
     }
     return true;
 }
 public function Analyze()
 {
     $info =& $this->getid3->info;
     // parse container
     try {
         $this->parseEBML($info);
     } catch (Exception $e) {
         $info['error'][] = 'EBML parser: ' . $e->getMessage();
     }
     // calculate playtime
     if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) {
         foreach ($info['matroska']['info'] as $key => $infoarray) {
             if (isset($infoarray['Duration'])) {
                 // TimecodeScale is how many nanoseconds each Duration unit is
                 $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
                 break;
             }
         }
     }
     // extract tags
     if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) {
         foreach ($info['matroska']['tags'] as $key => $infoarray) {
             $this->ExtractCommentsSimpleTag($infoarray);
         }
     }
     // process tracks
     if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) {
         foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) {
             $track_info = array();
             $track_info['dataformat'] = self::MatroskaCodecIDtoCommonName($trackarray['CodecID']);
             $track_info['default'] = isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true;
             if (isset($trackarray['Name'])) {
                 $track_info['name'] = $trackarray['Name'];
             }
             switch ($trackarray['TrackType']) {
                 case 1:
                     // Video
                     $track_info['resolution_x'] = $trackarray['PixelWidth'];
                     $track_info['resolution_y'] = $trackarray['PixelHeight'];
                     if (isset($trackarray['DisplayWidth'])) {
                         $track_info['display_x'] = $trackarray['DisplayWidth'];
                     }
                     if (isset($trackarray['DisplayHeight'])) {
                         $track_info['display_y'] = $trackarray['DisplayHeight'];
                     }
                     if (isset($trackarray['DefaultDuration'])) {
                         $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3);
                     }
                     //if (isset($trackarray['CodecName']))       { $track_info['codec']      = $trackarray['CodecName']; }
                     switch ($trackarray['CodecID']) {
                         case 'V_MS/VFW/FOURCC':
                             if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, false)) {
                                 $this->getid3->warning('Unable to parse codec private data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio-video.riff.php"');
                                 break;
                             }
                             $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']);
                             $track_info['codec'] = getid3_riff::RIFFfourccLookup($parsed['fourcc']);
                             $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
                             break;
                     }
                     $info['video']['streams'][] = $track_info;
                     break;
                 case 2:
                     // Audio
                     $track_info['sample_rate'] = isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0;
                     $track_info['channels'] = isset($trackarray['Channels']) ? $trackarray['Channels'] : 1;
                     $track_info['language'] = isset($trackarray['Language']) ? $trackarray['Language'] : 'eng';
                     if (isset($trackarray['BitDepth'])) {
                         $track_info['bits_per_sample'] = $trackarray['BitDepth'];
                     }
                     //if (isset($trackarray['CodecName'])) { $track_info['codec']           = $trackarray['CodecName']; }
                     switch ($trackarray['CodecID']) {
                         case 'A_PCM/INT/LIT':
                         case 'A_PCM/INT/BIG':
                             $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
                             break;
                         case 'A_AC3':
                         case 'A_DTS':
                         case 'A_MPEG/L3':
                             //case 'A_FLAC':
                             if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.' . $track_info['dataformat'] . '.php', __FILE__, false)) {
                                 $this->getid3->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio.' . $track_info['dataformat'] . '.php"');
                                 break;
                             }
                             if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
                                 $this->getid3->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because $info[matroska][track_data_offsets][' . $trackarray['TrackNumber'] . '] not set');
                                 break;
                             }
                             // create temp instance
                             $getid3_temp = new getID3();
                             $getid3_temp->openfile($this->getid3->filename);
                             $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                             if ($track_info['dataformat'] == 'mp3' || $track_info['dataformat'] == 'flac') {
                                 $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length'];
                             }
                             // analyze
                             $class = 'getid3_' . $track_info['dataformat'];
                             $header_data_key = $track_info['dataformat'] == 'mp3' ? 'mpeg' : $track_info['dataformat'];
                             $getid3_audio = new $class($getid3_temp);
                             if ($track_info['dataformat'] == 'mp3') {
                                 $getid3_audio->allow_bruteforce = true;
                             }
                             if ($track_info['dataformat'] == 'flac') {
                                 $getid3_audio->AnalyzeString($trackarray['CodecPrivate']);
                             } else {
                                 $getid3_audio->Analyze();
                             }
                             if (!empty($getid3_temp->info[$header_data_key])) {
                                 unset($getid3_temp->info[$header_data_key]['GETID3_VERSION']);
                                 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key];
                                 if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                     foreach ($getid3_temp->info['audio'] as $key => $value) {
                                         $track_info[$key] = $value;
                                     }
                                 }
                             } else {
                                 $this->getid3->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because ' . $class . '::Analyze() failed at offset ' . $getid3_temp->info['avdataoffset']);
                             }
                             // copy errors and warnings
                             if (!empty($getid3_temp->info['error'])) {
                                 foreach ($getid3_temp->info['error'] as $newerror) {
                                     $this->getid3->warning($class . '() says: [' . $newerror . ']');
                                 }
                             }
                             if (!empty($getid3_temp->info['warning'])) {
                                 foreach ($getid3_temp->info['warning'] as $newerror) {
                                     if ($track_info['dataformat'] == 'mp3' && preg_match('/^Probable truncated file: expecting \\d+ bytes of audio data, only found \\d+ \\(short by \\d+ bytes\\)$/', $newerror)) {
                                         // LAME/Xing header is probably set, but audio data is chunked into Matroska file and near-impossible to verify if audio stream is complete, so ignore useless warning
                                         continue;
                                     }
                                     $this->getid3->warning($class . '() says: [' . $newerror . ']');
                                 }
                             }
                             unset($getid3_temp, $getid3_audio);
                             break;
                         case 'A_AAC':
                         case 'A_AAC/MPEG2/LC':
                         case 'A_AAC/MPEG4/LC':
                         case 'A_AAC/MPEG4/LC/SBR':
                             $this->getid3->warning($trackarray['CodecID'] . ' audio data contains no header, audio/video bitrates can\'t be calculated');
                             break;
                         case 'A_VORBIS':
                             if (!isset($trackarray['CodecPrivate'])) {
                                 $this->getid3->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because CodecPrivate data not set');
                                 break;
                             }
                             $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1);
                             if ($vorbis_offset === false) {
                                 $this->getid3->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because CodecPrivate data does not contain "vorbis" keyword');
                                 break;
                             }
                             $vorbis_offset -= 1;
                             if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio.ogg.php', __FILE__, false)) {
                                 $this->getid3->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio.ogg.php"');
                             }
                             // create temp instance
                             $getid3_temp = new getID3();
                             $getid3_temp->openfile($this->getid3->filename);
                             // analyze
                             $getid3_ogg = new getid3_ogg($getid3_temp);
                             $oggpageinfo['page_seqno'] = 0;
                             $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo);
                             if (!empty($getid3_temp->info['ogg'])) {
                                 $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg'];
                                 if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
                                     foreach ($getid3_temp->info['audio'] as $key => $value) {
                                         $track_info[$key] = $value;
                                     }
                                 }
                             }
                             // copy errors and warnings
                             if (!empty($getid3_temp->info['error'])) {
                                 foreach ($getid3_temp->info['error'] as $newerror) {
                                     $this->getid3->warning('getid3_ogg() says: [' . $newerror . ']');
                                 }
                             }
                             if (!empty($getid3_temp->info['warning'])) {
                                 foreach ($getid3_temp->info['warning'] as $newerror) {
                                     $this->getid3->warning('getid3_ogg() says: [' . $newerror . ']');
                                 }
                             }
                             if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) {
                                 $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal'];
                             }
                             unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset);
                             break;
                         case 'A_MS/ACM':
                             if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, false)) {
                                 $this->getid3->warning('Unable to parse audio data [' . basename(__FILE__) . ':' . __LINE__ . '] because cannot include "module.audio-video.riff.php"');
                                 break;
                             }
                             $parsed = getid3_riff::RIFFparseWAVEFORMATex($trackarray['CodecPrivate']);
                             foreach ($parsed as $key => $value) {
                                 if ($key != 'raw') {
                                     $track_info[$key] = $value;
                                 }
                             }
                             $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
                             break;
                         default:
                             $this->getid3->warning('Unhandled audio type "' . (isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '') . '"');
                     }
                     $info['audio']['streams'][] = $track_info;
                     break;
             }
         }
         if (!empty($info['video']['streams'])) {
             $info['video'] = self::getDefaultStreamInfo($info['video']['streams']);
         }
         if (!empty($info['audio']['streams'])) {
             $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']);
         }
     }
     // determine mime type
     if (!empty($info['video']['streams'])) {
         $info['mime_type'] = $info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska';
     } elseif (!empty($info['audio']['streams'])) {
         $info['mime_type'] = $info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska';
     } elseif (isset($info['mime_type'])) {
         unset($info['mime_type']);
     }
     return true;
 }
 function getid3_real(&$fd, &$ThisFileInfo)
 {
     $ThisFileInfo['fileformat'] = 'real';
     $ThisFileInfo['bitrate'] = 0;
     $ThisFileInfo['playtime_seconds'] = 0;
     fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
     $ChunkCounter = 0;
     while (ftell($fd) < $ThisFileInfo['avdataend']) {
         $ChunkData = fread($fd, 8);
         $ChunkName = substr($ChunkData, 0, 4);
         $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, 4, 4));
         if ($ChunkName == '.ra' . "ý") {
             $ChunkData .= fread($fd, $ChunkSize - 8);
             if ($this->ParseOldRAheader(substr($ChunkData, 0, 128), $ThisFileInfo['real']['old_ra_header'])) {
                 $ThisFileInfo['audio']['dataformat'] = 'real';
                 $ThisFileInfo['audio']['lossless'] = false;
                 $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['real']['old_ra_header']['sample_rate'];
                 $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['real']['old_ra_header']['bits_per_sample'];
                 $ThisFileInfo['audio']['channels'] = $ThisFileInfo['real']['old_ra_header']['channels'];
                 $ThisFileInfo['playtime_seconds'] = 60 * ($ThisFileInfo['real']['old_ra_header']['audio_bytes'] / $ThisFileInfo['real']['old_ra_header']['bytes_per_minute']);
                 $ThisFileInfo['audio']['bitrate'] = 8 * ($ThisFileInfo['real']['old_ra_header']['audio_bytes'] / $ThisFileInfo['playtime_seconds']);
                 $ThisFileInfo['audio']['codec'] = $this->RealAudioCodecFourCClookup($ThisFileInfo['real']['old_ra_header']['fourcc'], $ThisFileInfo['audio']['bitrate']);
                 foreach ($ThisFileInfo['real']['old_ra_header']['comments'] as $key => $valuearray) {
                     if (strlen(trim($valuearray[0])) > 0) {
                         $ThisFileInfo['real']['comments'][$key][] = trim($valuearray[0]);
                     }
                 }
                 break;
             }
             $ThisFileInfo['error'][] = 'There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or info@getid3.org';
             unset($ThisFileInfo['bitrate']);
             unset($ThisFileInfo['playtime_seconds']);
             return false;
         }
         // shortcut
         $ThisFileInfo['real']['chunks'][$ChunkCounter] = array();
         $thisfile_real_chunks_currentchunk =& $ThisFileInfo['real']['chunks'][$ChunkCounter];
         $thisfile_real_chunks_currentchunk['name'] = $ChunkName;
         $thisfile_real_chunks_currentchunk['offset'] = ftell($fd) - 8;
         $thisfile_real_chunks_currentchunk['length'] = $ChunkSize;
         if ($thisfile_real_chunks_currentchunk['offset'] + $thisfile_real_chunks_currentchunk['length'] > $ThisFileInfo['avdataend']) {
             $ThisFileInfo['warning'][] = 'Chunk "' . $thisfile_real_chunks_currentchunk['name'] . '" at offset ' . $thisfile_real_chunks_currentchunk['offset'] . ' claims to be ' . $thisfile_real_chunks_currentchunk['length'] . ' bytes long, which is beyond end of file';
             return false;
         }
         if ($ChunkSize > GETID3_FREAD_BUFFER_SIZE + 8) {
             $ChunkData .= fread($fd, GETID3_FREAD_BUFFER_SIZE - 8);
             fseek($fd, $thisfile_real_chunks_currentchunk['offset'] + $ChunkSize, SEEK_SET);
         } else {
             $ChunkData .= fread($fd, $ChunkSize - 8);
         }
         $offset = 8;
         switch ($ChunkName) {
             case '.RMF':
                 // RealMedia File Header
                 $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                 $offset += 2;
                 switch ($thisfile_real_chunks_currentchunk['object_version']) {
                     case 0:
                         $thisfile_real_chunks_currentchunk['file_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                         $offset += 4;
                         $thisfile_real_chunks_currentchunk['headers_count'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                         $offset += 4;
                         break;
                     default:
                         //$ThisFileInfo['warning'][] = 'Expected .RMF-object_version to be "0", actual value is "'.$thisfile_real_chunks_currentchunk['object_version'].'" (should not be a problem)';
                         break;
                 }
                 break;
             case 'PROP':
                 // Properties Header
                 $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                 $offset += 2;
                 if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
                     $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['num_packets'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['index_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['data_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['num_streams'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $thisfile_real_chunks_currentchunk['flags_raw'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $ThisFileInfo['playtime_seconds'] = $thisfile_real_chunks_currentchunk['duration'] / 1000;
                     if ($thisfile_real_chunks_currentchunk['duration'] > 0) {
                         $ThisFileInfo['bitrate'] += $thisfile_real_chunks_currentchunk['avg_bit_rate'];
                     }
                     $thisfile_real_chunks_currentchunk['flags']['save_enabled'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x1);
                     $thisfile_real_chunks_currentchunk['flags']['perfect_play'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x2);
                     $thisfile_real_chunks_currentchunk['flags']['live_broadcast'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x4);
                 }
                 break;
             case 'MDPR':
                 // Media Properties Header
                 $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                 $offset += 2;
                 if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
                     $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['start_time'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['stream_name_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1));
                     $offset += 1;
                     $thisfile_real_chunks_currentchunk['stream_name'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['stream_name_size']);
                     $offset += $thisfile_real_chunks_currentchunk['stream_name_size'];
                     $thisfile_real_chunks_currentchunk['mime_type_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1));
                     $offset += 1;
                     $thisfile_real_chunks_currentchunk['mime_type'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['mime_type_size']);
                     $offset += $thisfile_real_chunks_currentchunk['mime_type_size'];
                     $thisfile_real_chunks_currentchunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['type_specific_data'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['type_specific_len']);
                     $offset += $thisfile_real_chunks_currentchunk['type_specific_len'];
                     // shortcut
                     $thisfile_real_chunks_currentchunk_typespecificdata =& $thisfile_real_chunks_currentchunk['type_specific_data'];
                     switch ($thisfile_real_chunks_currentchunk['mime_type']) {
                         case 'video/x-pn-realvideo':
                         case 'video/x-pn-multirate-realvideo':
                             // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
                             // shortcut
                             $thisfile_real_chunks_currentchunk['video_info'] = array();
                             $thisfile_real_chunks_currentchunk_videoinfo =& $thisfile_real_chunks_currentchunk['video_info'];
                             $thisfile_real_chunks_currentchunk_videoinfo['dwSize'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 0, 4));
                             $thisfile_real_chunks_currentchunk_videoinfo['fourcc1'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 4, 4);
                             $thisfile_real_chunks_currentchunk_videoinfo['fourcc2'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 8, 4);
                             $thisfile_real_chunks_currentchunk_videoinfo['width'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 12, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['height'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 14, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 16, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown1'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 18, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown2'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 20, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 22, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown3'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 24, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown4'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 26, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown5'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 28, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown6'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 30, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown7'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 32, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown8'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 34, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['unknown9'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 36, 2));
                             $thisfile_real_chunks_currentchunk_videoinfo['codec'] = getid3_riff::RIFFfourccLookup($thisfile_real_chunks_currentchunk_videoinfo['fourcc2']);
                             $ThisFileInfo['video']['resolution_x'] = $thisfile_real_chunks_currentchunk_videoinfo['width'];
                             $ThisFileInfo['video']['resolution_y'] = $thisfile_real_chunks_currentchunk_videoinfo['height'];
                             $ThisFileInfo['video']['frame_rate'] = (double) $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second'];
                             $ThisFileInfo['video']['codec'] = $thisfile_real_chunks_currentchunk_videoinfo['codec'];
                             $ThisFileInfo['video']['bits_per_sample'] = $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample'];
                             break;
                         case 'audio/x-pn-realaudio':
                         case 'audio/x-pn-multirate-realaudio':
                             $this->ParseOldRAheader($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk['parsed_audio_data']);
                             $ThisFileInfo['audio']['sample_rate'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['sample_rate'];
                             $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['bits_per_sample'];
                             $ThisFileInfo['audio']['channels'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['channels'];
                             if (!empty($ThisFileInfo['audio']['dataformat'])) {
                                 foreach ($ThisFileInfo['audio'] as $key => $value) {
                                     if ($key != 'streams') {
                                         $ThisFileInfo['audio']['streams'][$thisfile_real_chunks_currentchunk['stream_number']][$key] = $value;
                                     }
                                 }
                             }
                             break;
                         case 'logical-fileinfo':
                             // shortcut
                             $thisfile_real_chunks_currentchunk['logical_fileinfo'] = array();
                             $thisfile_real_chunks_currentchunk_logicalfileinfo =& $thisfile_real_chunks_currentchunk['logical_fileinfo'];
                             $thisfile_real_chunks_currentchunk_logicalfileinfo['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 0, 4));
                             $thisfile_real_chunks_currentchunk_logicalfileinfo['a'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 4, 4));
                             $thisfile_real_chunks_currentchunk_logicalfileinfo['b'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 8, 4));
                             $thisfile_real_chunks_currentchunk_logicalfileinfo['c'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 12, 4));
                             break;
                     }
                     if (empty($ThisFileInfo['playtime_seconds'])) {
                         $ThisFileInfo['playtime_seconds'] = max($ThisFileInfo['playtime_seconds'], ($thisfile_real_chunks_currentchunk['duration'] + $thisfile_real_chunks_currentchunk['start_time']) / 1000);
                     }
                     if ($thisfile_real_chunks_currentchunk['duration'] > 0) {
                         switch ($thisfile_real_chunks_currentchunk['mime_type']) {
                             case 'audio/x-pn-realaudio':
                             case 'audio/x-pn-multirate-realaudio':
                                 $ThisFileInfo['audio']['bitrate'] = (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate'];
                                 $ThisFileInfo['audio']['codec'] = $this->RealAudioCodecFourCClookup($thisfile_real_chunks_currentchunk['parsed_audio_data']['fourcc'], $ThisFileInfo['audio']['bitrate']);
                                 $ThisFileInfo['audio']['dataformat'] = 'real';
                                 $ThisFileInfo['audio']['lossless'] = false;
                                 break;
                             case 'video/x-pn-realvideo':
                             case 'video/x-pn-multirate-realvideo':
                                 $ThisFileInfo['video']['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate'];
                                 $ThisFileInfo['video']['birate_mode'] = 'cbr';
                                 $ThisFileInfo['video']['dataformat'] = 'real';
                                 $ThisFileInfo['video']['lossless'] = false;
                                 $ThisFileInfo['video']['pixel_aspect_ratio'] = (double) 1;
                                 break;
                         }
                         $ThisFileInfo['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0);
                     }
                 }
                 break;
             case 'CONT':
                 // Content Description Header
                 $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                 $offset += 2;
                 if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
                     $thisfile_real_chunks_currentchunk['title_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $thisfile_real_chunks_currentchunk['title'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['title_len']);
                     $offset += $thisfile_real_chunks_currentchunk['title_len'];
                     $thisfile_real_chunks_currentchunk['artist_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $thisfile_real_chunks_currentchunk['artist'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['artist_len']);
                     $offset += $thisfile_real_chunks_currentchunk['artist_len'];
                     $thisfile_real_chunks_currentchunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $thisfile_real_chunks_currentchunk['copyright'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['copyright_len']);
                     $offset += $thisfile_real_chunks_currentchunk['copyright_len'];
                     $thisfile_real_chunks_currentchunk['comment_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $thisfile_real_chunks_currentchunk['comment'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['comment_len']);
                     $offset += $thisfile_real_chunks_currentchunk['comment_len'];
                     $commentkeystocopy = array('title' => 'title', 'artist' => 'artist', 'copyright' => 'copyright', 'comment' => 'comment');
                     foreach ($commentkeystocopy as $key => $val) {
                         if ($thisfile_real_chunks_currentchunk[$key]) {
                             $ThisFileInfo['real']['comments'][$val][] = trim($thisfile_real_chunks_currentchunk[$key]);
                         }
                     }
                 }
                 break;
             case 'DATA':
                 // Data Chunk Header
                 // do nothing
                 break;
             case 'INDX':
                 // Index Section Header
                 $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                 $offset += 2;
                 if ($thisfile_real_chunks_currentchunk['object_version'] == 0) {
                     $thisfile_real_chunks_currentchunk['num_indices'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2));
                     $offset += 2;
                     $thisfile_real_chunks_currentchunk['next_index_header'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4));
                     $offset += 4;
                     if ($thisfile_real_chunks_currentchunk['next_index_header'] == 0) {
                         // last index chunk found, ignore rest of file
                         break 2;
                     } else {
                         // non-last index chunk, seek to next index chunk (skipping actual index data)
                         fseek($fd, $thisfile_real_chunks_currentchunk['next_index_header'], SEEK_SET);
                     }
                 }
                 break;
             default:
                 $ThisFileInfo['warning'][] = 'Unhandled RealMedia chunk "' . $ChunkName . '" at offset ' . $thisfile_real_chunks_currentchunk['offset'];
                 break;
         }
         $ChunkCounter++;
     }
     if (!empty($ThisFileInfo['audio']['streams'])) {
         $ThisFileInfo['audio']['bitrate'] = 0;
         foreach ($ThisFileInfo['audio']['streams'] as $key => $valuearray) {
             $ThisFileInfo['audio']['bitrate'] += $valuearray['bitrate'];
         }
     }
     return true;
 }
 public static function array_merge_noclobber($array1, $array2)
 {
     if (!is_array($array1) || !is_array($array2)) {
         return false;
     }
     $new_array = $array1;
     foreach ($array2 as $key => $val) {
         if (is_array($val) && isset($new_array[$key]) && is_array($new_array[$key])) {
             $new_array[$key] = getid3_riff::array_merge_noclobber($new_array[$key], $val);
         } elseif (!isset($new_array[$key])) {
             $new_array[$key] = $val;
         }
     }
     return $new_array;
 }
 function Analyze()
 {
     $info =& $this->getid3->info;
     $offset = 0;
     fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     $rawdata = fread($this->getid3->fp, $this->getid3->fread_buffer_size());
     switch (substr($rawdata, $offset, 4)) {
         case 'LA02':
         case 'LA03':
         case 'LA04':
             $info['fileformat'] = 'la';
             $info['audio']['dataformat'] = 'la';
             $info['audio']['lossless'] = true;
             $info['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1);
             $info['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1);
             $info['la']['version'] = (double) $info['la']['version_major'] + $info['la']['version_minor'] / 10;
             $offset += 4;
             $info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
             $offset += 4;
             if ($info['la']['uncompressed_size'] == 0) {
                 $info['error'][] = 'Corrupt LA file: uncompressed_size == zero';
                 return false;
             }
             $WAVEchunk = substr($rawdata, $offset, 4);
             if ($WAVEchunk !== 'WAVE') {
                 $info['error'][] = 'Expected "WAVE" (' . getid3_lib::PrintHexBytes('WAVE') . ') at offset ' . $offset . ', found "' . $WAVEchunk . '" (' . getid3_lib::PrintHexBytes($WAVEchunk) . ') instead.';
                 return false;
             }
             $offset += 4;
             $info['la']['fmt_size'] = 24;
             if ($info['la']['version'] >= 0.3) {
                 $info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
                 $info['la']['header_size'] = 49 + $info['la']['fmt_size'] - 24;
                 $offset += 4;
             } else {
                 // version 0.2 didn't support additional data blocks
                 $info['la']['header_size'] = 41;
             }
             $fmt_chunk = substr($rawdata, $offset, 4);
             if ($fmt_chunk !== 'fmt ') {
                 $info['error'][] = 'Expected "fmt " (' . getid3_lib::PrintHexBytes('fmt ') . ') at offset ' . $offset . ', found "' . $fmt_chunk . '" (' . getid3_lib::PrintHexBytes($fmt_chunk) . ') instead.';
                 return false;
             }
             $offset += 4;
             $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
             $offset += 4;
             $info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
             $offset += 2;
             $info['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
             $offset += 2;
             if ($info['la']['channels'] == 0) {
                 $info['error'][] = 'Corrupt LA file: channels == zero';
                 return false;
             }
             $info['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
             $offset += 4;
             if ($info['la']['sample_rate'] == 0) {
                 $info['error'][] = 'Corrupt LA file: sample_rate == zero';
                 return false;
             }
             $info['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
             $offset += 4;
             $info['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
             $offset += 2;
             $info['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
             $offset += 2;
             $info['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
             $offset += 4;
             $info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1));
             $offset += 1;
             $info['la']['flags']['seekable'] = (bool) ($info['la']['raw']['flags'] & 0x1);
             if ($info['la']['version'] >= 0.4) {
                 $info['la']['flags']['high_compression'] = (bool) ($info['la']['raw']['flags'] & 0x2);
             }
             $info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
             $offset += 4;
             // mikeØbevin*de
             // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16
             // in earlier versions. A seekpoint is added every blocksize * seekevery
             // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should
             // give the number of bytes used for the seekpoints. Of course, if seeking
             // is disabled, there are no seekpoints stored.
             if ($info['la']['version'] >= 0.4) {
                 $info['la']['blocksize'] = 61440;
                 $info['la']['seekevery'] = 19;
             } else {
                 $info['la']['blocksize'] = 73728;
                 $info['la']['seekevery'] = 16;
             }
             $info['la']['seekpoint_count'] = 0;
             if ($info['la']['flags']['seekable']) {
                 $info['la']['seekpoint_count'] = floor($info['la']['samples'] / ($info['la']['blocksize'] * $info['la']['seekevery']));
                 for ($i = 0; $i < $info['la']['seekpoint_count']; $i++) {
                     $info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
                     $offset += 4;
                 }
             }
             if ($info['la']['version'] >= 0.3) {
                 // Following the main header information, the program outputs all of the
                 // seekpoints. Following these is what I called the 'footer start',
                 // i.e. the position immediately after the La audio data is finished.
                 $info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
                 $offset += 4;
                 if ($info['la']['footerstart'] > $info['filesize']) {
                     $info['warning'][] = 'FooterStart value points to offset ' . $info['la']['footerstart'] . ' which is beyond end-of-file (' . $info['filesize'] . ')';
                     $info['la']['footerstart'] = $info['filesize'];
                 }
             } else {
                 // La v0.2 didn't have FooterStart value
                 $info['la']['footerstart'] = $info['avdataend'];
             }
             if ($info['la']['footerstart'] < $info['avdataend']) {
                 if ($RIFFtempfilename = tempnam(GETID3_TEMP_DIR, 'id3')) {
                     if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) {
                         $RIFFdata = 'WAVE';
                         if ($info['la']['version'] == 0.2) {
                             $RIFFdata .= substr($rawdata, 12, 24);
                         } else {
                             $RIFFdata .= substr($rawdata, 16, 24);
                         }
                         if ($info['la']['footerstart'] < $info['avdataend']) {
                             fseek($this->getid3->fp, $info['la']['footerstart'], SEEK_SET);
                             $RIFFdata .= fread($this->getid3->fp, $info['avdataend'] - $info['la']['footerstart']);
                         }
                         $RIFFdata = 'RIFF' . getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false) . $RIFFdata;
                         fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata));
                         fclose($RIFF_fp);
                         $getid3_temp = new getID3();
                         $getid3_temp->openfile($RIFFtempfilename);
                         $getid3_riff = new getid3_riff($getid3_temp);
                         $getid3_riff->Analyze();
                         if (empty($getid3_temp->info['error'])) {
                             $info['riff'] = $getid3_temp->info['riff'];
                         } else {
                             $info['warning'][] = 'Error parsing RIFF portion of La file: ' . implode($getid3_temp->info['error']);
                         }
                         unset($getid3_temp, $getid3_riff);
                     }
                     unlink($RIFFtempfilename);
                 }
             }
             // $info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway
             $info['avdataend'] = $info['avdataoffset'] + $info['la']['footerstart'];
             $info['avdataoffset'] = $info['avdataoffset'] + $offset;
             //$info['la']['codec']                = RIFFwFormatTagLookup($info['la']['raw']['format']);
             $info['la']['compression_ratio'] = (double) (($info['avdataend'] - $info['avdataoffset']) / $info['la']['uncompressed_size']);
             $info['playtime_seconds'] = (double) ($info['la']['samples'] / $info['la']['sample_rate']) / $info['la']['channels'];
             if ($info['playtime_seconds'] == 0) {
                 $info['error'][] = 'Corrupt LA file: playtime_seconds == zero';
                 return false;
             }
             $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds'];
             //$info['audio']['codec']              = $info['la']['codec'];
             $info['audio']['bits_per_sample'] = $info['la']['bits_per_sample'];
             break;
         default:
             if (substr($rawdata, $offset, 2) == 'LA') {
                 $info['error'][] = 'This version of getID3() [' . $this->getid3->version() . '] does not support LA version ' . substr($rawdata, $offset + 2, 1) . '.' . substr($rawdata, $offset + 3, 1) . ' which this appears to be - check http://getid3.sourceforge.net for updates.';
             } else {
                 $info['error'][] = 'Not a LA (Lossless-Audio) file';
             }
             return false;
             break;
     }
     $info['audio']['channels'] = $info['la']['channels'];
     $info['audio']['sample_rate'] = (int) $info['la']['sample_rate'];
     $info['audio']['encoder'] = 'LA v' . $info['la']['version'];
     return true;
 }
 function getid3_matroska(&$fd, &$ThisFileInfo)
 {
     // http://www.matroska.org/technical/specs/index.html#EBMLBasics
     $offset = $ThisFileInfo['avdataoffset'];
     $EBMLdata = '';
     $EBMLdata_offset = $offset;
     if ($ThisFileInfo['avdataend'] > 2147483648) {
         $this->warnings[] = 'This version of getID3() may or may not correctly handle Matroska files larger than 2GB';
     }
     while ($offset < $ThisFileInfo['avdataend']) {
         $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
         $top_element_offset = $offset;
         $top_element_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
         $top_element_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
         if ($top_element_length === false) {
             $this->warnings[] = 'invalid chunk length at ' . $top_element_offset;
             $offset = pow(2, 63);
             break;
         }
         $top_element_endoffset = $offset + $top_element_length;
         switch ($top_element_id) {
             case EBML_ID_EBML:
                 $ThisFileInfo['fileformat'] = 'matroska';
                 $ThisFileInfo['matroska']['header']['offset'] = $top_element_offset;
                 $ThisFileInfo['matroska']['header']['length'] = $top_element_length;
                 while ($offset < $top_element_endoffset) {
                     $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                     $element_data = array();
                     $element_data_offset = $offset;
                     $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     $element_data['id_name'] = $this->EBMLidName($element_data['id']);
                     $element_data_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     $end_offset = $offset + $element_data_length;
                     switch ($element_data['id']) {
                         case EBML_ID_EBMLVERSION:
                         case EBML_ID_EBMLREADVERSION:
                         case EBML_ID_EBMLMAXIDLENGTH:
                         case EBML_ID_EBMLMAXSIZELENGTH:
                         case EBML_ID_DOCTYPEVERSION:
                         case EBML_ID_DOCTYPEREADVERSION:
                             $element_data['data'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data_length));
                             break;
                         case EBML_ID_DOCTYPE:
                             $element_data['data'] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data_length), "");
                             break;
                         default:
                             $this->warnings[] = 'Unhandled track.video element[' . __LINE__ . '] (' . $element_data['id'] . '::' . $element_data['id_name'] . ') at ' . $element_data_offset;
                             break;
                     }
                     $offset = $end_offset;
                     $ThisFileInfo['matroska']['header']['elements'][] = $element_data;
                 }
                 break;
             case EBML_ID_SEGMENT:
                 $ThisFileInfo['matroska']['segment'][0]['offset'] = $top_element_offset;
                 $ThisFileInfo['matroska']['segment'][0]['length'] = $top_element_length;
                 $segment_key = -1;
                 while ($offset < $ThisFileInfo['avdataend']) {
                     $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                     $element_data = array();
                     $element_data['offset'] = $offset;
                     $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     $element_data['id_name'] = $this->EBMLidName($element_data['id']);
                     $element_data_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                     if ($element_data_length === false) {
                         $this->warnings[] = 'invalid chunk length at ' . $element_data['offset'];
                         $offset = pow(2, 63);
                         break;
                     }
                     $element_end = $offset + $element_data_length;
                     switch ($element_data['id']) {
                         //case EBML_ID_CLUSTER:
                         //	// too many cluster entries, probably not useful
                         //	break;
                         case false:
                             $this->warnings[] = 'invalid ID at ' . $element_data['offset'];
                             $offset = $element_end;
                             continue 3;
                         default:
                             $ThisFileInfo['matroska']['segments'][] = $element_data;
                             break;
                     }
                     $segment_key++;
                     switch ($element_data['id']) {
                         case EBML_ID_SEEKHEAD:
                             // Contains the position of other level 1 elements
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                 $seek_entry = array();
                                 $seek_entry['offset'] = $offset;
                                 $seek_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $seek_entry['id_name'] = $this->EBMLidName($seek_entry['id']);
                                 $seek_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $seek_end_offset = $offset + $seek_entry['length'];
                                 switch ($seek_entry['id']) {
                                     case EBML_ID_SEEK:
                                         // Contains a single seek entry to an EBML element
                                         while ($offset < $seek_end_offset) {
                                             $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                             $id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $value = substr($EBMLdata, $offset - $EBMLdata_offset, $length);
                                             $offset += $length;
                                             switch ($id) {
                                                 case EBML_ID_SEEKID:
                                                     $dummy = 0;
                                                     $seek_entry['target_id'] = $this->readEBMLint($value, $dummy);
                                                     $seek_entry['target_name'] = $this->EBMLidName($seek_entry['target_id']);
                                                     break;
                                                 case EBML_ID_SEEKPOSITION:
                                                     $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($value);
                                                     break;
                                                 default:
                                                     $ThisFileInfo['error'][] = 'Unhandled segment[' . __LINE__ . '] (' . $id . ') at ' . $offset;
                                                     break;
                                             }
                                         }
                                         $ThisFileInfo['matroska']['seek'][] = $seek_entry;
                                         //switch ($seek_entry['target_id']) {
                                         //	case EBML_ID_CLUSTER:
                                         //		// too many cluster seek points, probably not useful
                                         //		break;
                                         //	default:
                                         //		$ThisFileInfo['matroska']['seek'][] = $seek_entry;
                                         //		break;
                                         //}
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled seekhead element[' . __LINE__ . '] (' . $seek_entry['id'] . ') at ' . $offset;
                                         break;
                                 }
                                 $offset = $seek_end_offset;
                             }
                             break;
                         case EBML_ID_TRACKS:
                             // information about all tracks in segment
                             $ThisFileInfo['matroska']['tracks'] = $element_data;
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                 $track_entry = array();
                                 $track_entry['offset'] = $offset;
                                 $track_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $track_entry['id_name'] = $this->EBMLidName($track_entry['id']);
                                 $track_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $track_entry_endoffset = $offset + $track_entry['length'];
                                 switch ($track_entry['id']) {
                                     case EBML_ID_TRACKENTRY:
                                         //subelements: Describes a track with all elements.
                                         while ($offset < $track_entry_endoffset) {
                                             $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                             $subelement_offset = $offset;
                                             $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $subelement_idname = $this->EBMLidName($subelement_id);
                                             $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $subelement_end = $offset + $subelement_length;
                                             switch ($subelement_id) {
                                                 case EBML_ID_TRACKNUMBER:
                                                 case EBML_ID_TRACKUID:
                                                 case EBML_ID_TRACKTYPE:
                                                 case EBML_ID_MINCACHE:
                                                 case EBML_ID_MAXCACHE:
                                                 case EBML_ID_MAXBLOCKADDITIONID:
                                                 case EBML_ID_DEFAULTDURATION:
                                                     // nanoseconds per frame
                                                     $track_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                                     break;
                                                 case EBML_ID_TRACKTIMECODESCALE:
                                                     $track_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                                     break;
                                                 case EBML_ID_CODECID:
                                                 case EBML_ID_LANGUAGE:
                                                 case EBML_ID_NAME:
                                                 case EBML_ID_CODECPRIVATE:
                                                     $track_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "");
                                                     break;
                                                 case EBML_ID_FLAGENABLED:
                                                 case EBML_ID_FLAGDEFAULT:
                                                 case EBML_ID_FLAGFORCED:
                                                 case EBML_ID_FLAGLACING:
                                                 case EBML_ID_CODECDECODEALL:
                                                     $track_entry[$subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                                     break;
                                                 case EBML_ID_VIDEO:
                                                     while ($offset < $subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_offset = $offset;
                                                         $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                                         $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_end = $offset + $sub_subelement_length;
                                                         switch ($sub_subelement_id) {
                                                             case EBML_ID_PIXELWIDTH:
                                                             case EBML_ID_PIXELHEIGHT:
                                                             case EBML_ID_STEREOMODE:
                                                             case EBML_ID_PIXELCROPBOTTOM:
                                                             case EBML_ID_PIXELCROPTOP:
                                                             case EBML_ID_PIXELCROPLEFT:
                                                             case EBML_ID_PIXELCROPRIGHT:
                                                             case EBML_ID_DISPLAYWIDTH:
                                                             case EBML_ID_DISPLAYHEIGHT:
                                                             case EBML_ID_DISPLAYUNIT:
                                                             case EBML_ID_ASPECTRATIOTYPE:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_FLAGINTERLACED:
                                                                 $track_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_GAMMAVALUE:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_COLOURSPACE:
                                                                 $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "");
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled track.video element[' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_subelement_end;
                                                     }
                                                     if (@$track_entry[$this->EBMLidName(EBML_ID_CODECID)] == 'V_MS/VFW/FOURCC' && isset($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)])) {
                                                         if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, false)) {
                                                             $track_entry['codec_private_parsed'] = getid3_riff::ParseBITMAPINFOHEADER($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)]);
                                                         } else {
                                                             $this->warnings[] = 'Unable to parse codec private data[' . __LINE__ . '] because cannot include "module.audio-video.riff.php"';
                                                         }
                                                     }
                                                     break;
                                                 case EBML_ID_AUDIO:
                                                     while ($offset < $subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_offset = $offset;
                                                         $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                                         $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_subelement_end = $offset + $sub_subelement_length;
                                                         switch ($sub_subelement_id) {
                                                             case EBML_ID_CHANNELS:
                                                             case EBML_ID_BITDEPTH:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_SAMPLINGFREQUENCY:
                                                             case EBML_ID_OUTPUTSAMPLINGFREQUENCY:
                                                                 $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_CHANNELPOSITIONS:
                                                                 $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "");
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled track.video element[' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_subelement_end;
                                                     }
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled track element[' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ') at ' . $subelement_offset;
                                                     break;
                                             }
                                             $offset = $subelement_end;
                                         }
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled track element[' . __LINE__ . '] (' . $track_entry['id'] . '::' . $track_entry['id_name'] . ') at ' . $track_entry['offset'];
                                         $offset = $track_entry_endoffset;
                                         break;
                                 }
                                 $ThisFileInfo['matroska']['tracks']['tracks'][] = $track_entry;
                             }
                             break;
                         case EBML_ID_INFO:
                             // Contains the position of other level 1 elements
                             $info_entry = array();
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
                                     case EBML_ID_CHAPTERTRANSLATECODEC:
                                     case EBML_ID_TIMECODESCALE:
                                         $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                         break;
                                     case EBML_ID_DURATION:
                                         $info_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                         break;
                                     case EBML_ID_DATEUTC:
                                         $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
                                         $info_entry[$subelement_idname . '_unix'] = $this->EBMLdate2unix($info_entry[$subelement_idname]);
                                         break;
                                     case EBML_ID_SEGMENTUID:
                                     case EBML_ID_PREVUID:
                                     case EBML_ID_NEXTUID:
                                     case EBML_ID_SEGMENTFAMILY:
                                     case EBML_ID_CHAPTERTRANSLATEID:
                                         $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "");
                                         break;
                                     case EBML_ID_SEGMENTFILENAME:
                                     case EBML_ID_PREVFILENAME:
                                     case EBML_ID_NEXTFILENAME:
                                     case EBML_ID_TITLE:
                                     case EBML_ID_MUXINGAPP:
                                     case EBML_ID_WRITINGAPP:
                                         $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "");
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled info element[' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ') at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             $ThisFileInfo['matroska']['info'][] = $info_entry;
                             break;
                         case EBML_ID_CUES:
                             $cues_entry = array();
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_CUEPOINT:
                                         $cuepoint_entry = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_CUETRACKPOSITIONS:
                                                     while ($offset < $sub_subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_offset = $offset;
                                                         $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                         $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                         switch ($sub_sub_subelement_id) {
                                                             case EBML_ID_CUETRACK:
                                                                 $cuepoint_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled cues.cuepoint.cuetrackpositions element[' . __LINE__ . '] (' . $sub_sub_subelement_id . '::' . $sub_sub_subelement_idname . ') at ' . $sub_sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_subelement_end;
                                                     }
                                                     break;
                                                 case EBML_ID_CUETIME:
                                                     $cuepoint_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled cues.cuepoint element[' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $cues_entry[] = $cuepoint_entry;
                                         $offset = $sub_subelement_end;
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled cues element[' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ') at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             $ThisFileInfo['matroska']['cues'] = $cues_entry;
                             break;
                         case EBML_ID_TAGS:
                             $tags_entry = array();
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_WRITINGAPP:
                                         $tags_entry[$subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length);
                                         break;
                                     case EBML_ID_TAG:
                                         $tag_entry = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_TARGETS:
                                                     $targets_entry = array();
                                                     while ($offset < $sub_subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_offset = $offset;
                                                         $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                         $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                         switch ($sub_sub_subelement_id) {
                                                             case EBML_ID_TARGETTYPEVALUE:
                                                             case EBML_ID_EDITIONUID:
                                                             case EBML_ID_CHAPTERUID:
                                                             case EBML_ID_ATTACHMENTUID:
                                                             case EBML_ID_TAGTRACKUID:
                                                             case EBML_ID_TAGCHAPTERUID:
                                                                 $targets_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled tag.targets element[' . __LINE__ . '] (' . $sub_sub_subelement_id . '::' . $sub_sub_subelement_idname . ') at ' . $sub_sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_sub_subelement_end;
                                                     }
                                                     $tag_entry[$sub_subelement_idname][] = $targets_entry;
                                                     break;
                                                 case EBML_ID_SIMPLETAG:
                                                     $simpletag_entry = array();
                                                     while ($offset < $sub_subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_offset = $offset;
                                                         $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                         $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                         switch ($sub_sub_subelement_id) {
                                                             case EBML_ID_TAGNAME:
                                                             case EBML_ID_TAGLANGUAGE:
                                                             case EBML_ID_TAGSTRING:
                                                             case EBML_ID_TAGBINARY:
                                                                 $simpletag_entry[$sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
                                                                 break;
                                                             case EBML_ID_TAGDEFAULT:
                                                                 $simpletag_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled tag.simpletag element[' . __LINE__ . '] (' . $sub_sub_subelement_id . '::' . $sub_sub_subelement_idname . ') at ' . $sub_sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_sub_subelement_end;
                                                     }
                                                     $tag_entry[$sub_subelement_idname][] = $simpletag_entry;
                                                     break;
                                                 case EBML_ID_TARGETTYPE:
                                                     $tag_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
                                                     break;
                                                 case EBML_ID_TRACKUID:
                                                     $tag_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled tags.tag element[' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $tags_entry['tags'][] = $tag_entry;
                                         $offset = $sub_subelement_end;
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled tags element[' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ') at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             $ThisFileInfo['matroska']['tags'] = $tags_entry;
                             break;
                         case EBML_ID_ATTACHMENTS:
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_ATTACHEDFILE:
                                         $attachedfile_entry = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_FILEDESCRIPTION:
                                                 case EBML_ID_FILENAME:
                                                 case EBML_ID_FILEMIMETYPE:
                                                     $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
                                                     break;
                                                 case EBML_ID_FILEDATA:
                                                     $attachedfile_entry['data_offset'] = $offset;
                                                     $attachedfile_entry['data_length'] = $sub_subelement_length;
                                                     if ($sub_subelement_length < 1024) {
                                                         $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
                                                     }
                                                     break;
                                                 case EBML_ID_FILEUID:
                                                     $attachedfile_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled attachment.attachedfile element[' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $ThisFileInfo['matroska']['attachments'][] = $attachedfile_entry;
                                         $offset = $sub_subelement_end;
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled tags element[' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ') at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             break;
                         case EBML_ID_CHAPTERS:
                             // not important to us, contains mostly actual audio/video data, ignore
                             while ($offset < $element_end) {
                                 $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_offset = $offset;
                                 $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_idname = $this->EBMLidName($subelement_id);
                                 $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                 $subelement_end = $offset + $subelement_length;
                                 switch ($subelement_id) {
                                     case EBML_ID_EDITIONENTRY:
                                         $editionentry_entry = array();
                                         while ($offset < $subelement_end) {
                                             $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_offset = $offset;
                                             $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
                                             $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                             $sub_subelement_end = $offset + $sub_subelement_length;
                                             switch ($sub_subelement_id) {
                                                 case EBML_ID_EDITIONUID:
                                                     $editionentry_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 case EBML_ID_EDITIONFLAGHIDDEN:
                                                 case EBML_ID_EDITIONFLAGDEFAULT:
                                                 case EBML_ID_EDITIONFLAGORDERED:
                                                     $editionentry_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
                                                     break;
                                                 case EBML_ID_CHAPTERATOM:
                                                     $chapteratom_entry = array();
                                                     while ($offset < $sub_subelement_end) {
                                                         $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_offset = $offset;
                                                         $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                         $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                         $sub_sub_subelement_end = $offset + $sub_sub_subelement_length;
                                                         switch ($sub_sub_subelement_id) {
                                                             case EBML_ID_CHAPTERSEGMENTUID:
                                                             case EBML_ID_CHAPTERSEGMENTEDITIONUID:
                                                                 $chapteratom_entry[$sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
                                                                 break;
                                                             case EBML_ID_CHAPTERFLAGENABLED:
                                                             case EBML_ID_CHAPTERFLAGHIDDEN:
                                                                 $chapteratom_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_CHAPTERUID:
                                                             case EBML_ID_CHAPTERTIMESTART:
                                                             case EBML_ID_CHAPTERTIMEEND:
                                                                 $chapteratom_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                 break;
                                                             case EBML_ID_CHAPTERTRACK:
                                                                 $chaptertrack_entry = array();
                                                                 while ($offset < $sub_sub_subelement_end) {
                                                                     $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_offset = $offset;
                                                                     $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
                                                                     $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
                                                                     switch ($sub_sub_sub_subelement_id) {
                                                                         case EBML_ID_CHAPTERTRACKNUMBER:
                                                                             $chaptertrack_entry[$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
                                                                             break;
                                                                         default:
                                                                             $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chaptertrack element[' . __LINE__ . '] (' . $sub_sub_sub_subelement_id . '::' . $sub_sub_sub_subelement_idname . ') at ' . $sub_sub_sub_subelement_offset;
                                                                             break;
                                                                     }
                                                                     $offset = $sub_sub_sub_subelement_end;
                                                                 }
                                                                 $chapteratom_entry[$sub_sub_subelement_idname][] = $chaptertrack_entry;
                                                                 break;
                                                             case EBML_ID_CHAPTERDISPLAY:
                                                                 $chapterdisplay_entry = array();
                                                                 while ($offset < $sub_sub_subelement_end) {
                                                                     $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_offset = $offset;
                                                                     $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_sub_subelement_id);
                                                                     $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
                                                                     $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length;
                                                                     switch ($sub_sub_sub_subelement_id) {
                                                                         case EBML_ID_CHAPSTRING:
                                                                         case EBML_ID_CHAPLANGUAGE:
                                                                         case EBML_ID_CHAPCOUNTRY:
                                                                             $chapterdisplay_entry[$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
                                                                             break;
                                                                         default:
                                                                             $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chapterdisplay element[' . __LINE__ . '] (' . $sub_sub_sub_subelement_id . '::' . $sub_sub_sub_subelement_idname . ') at ' . $sub_sub_sub_subelement_offset;
                                                                             break;
                                                                     }
                                                                     $offset = $sub_sub_sub_subelement_end;
                                                                 }
                                                                 $chapteratom_entry[$sub_sub_subelement_idname][] = $chapterdisplay_entry;
                                                                 break;
                                                             default:
                                                                 $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom element[' . __LINE__ . '] (' . $sub_sub_subelement_id . '::' . $sub_sub_subelement_idname . ') at ' . $sub_sub_subelement_offset;
                                                                 break;
                                                         }
                                                         $offset = $sub_sub_subelement_end;
                                                     }
                                                     $editionentry_entry[$sub_subelement_idname][] = $chapteratom_entry;
                                                     break;
                                                 default:
                                                     $this->warnings[] = 'Unhandled chapters.editionentry element[' . __LINE__ . '] (' . $sub_subelement_id . '::' . $sub_subelement_idname . ') at ' . $sub_subelement_offset;
                                                     break;
                                             }
                                             $offset = $sub_subelement_end;
                                         }
                                         $ThisFileInfo['matroska']['chapters'][] = $editionentry_entry;
                                         $offset = $sub_subelement_end;
                                         break;
                                     default:
                                         $this->warnings[] = 'Unhandled chapters element[' . __LINE__ . '] (' . $subelement_id . '::' . $subelement_idname . ') at ' . $subelement_offset;
                                         break;
                                 }
                                 $offset = $subelement_end;
                             }
                             break;
                         case EBML_ID_VOID:
                             // padding, ignore
                         // padding, ignore
                         case EBML_ID_CLUSTER:
                             // not important to us, contains mostly actual audio/video data, ignore
                             break;
                         default:
                             if ($element_data['id_name'] == dechex($element_data['id'])) {
                                 $ThisFileInfo['error'][] = 'Unhandled segment[' . __LINE__ . '] (' . $element_data['id'] . ') at ' . $element_data_offset;
                             } else {
                                 $this->warnings[] = 'Unhandled segment[' . __LINE__ . '] (' . $element_data['id'] . '::' . $element_data['id_name'] . ') at ' . $element_data['offset'];
                             }
                             break;
                     }
                     $offset = $element_end;
                 }
                 break;
             default:
                 $ThisFileInfo['error'][] = 'Unhandled chunk[' . __LINE__ . '] (' . $top_element_id . ') at ' . $offset;
                 break;
         }
         $offset = $top_element_endoffset;
     }
     if ($this->hide_clusters) {
         // too much data returned that is usually not useful
         if (isset($ThisFileInfo['matroska']['segments']) && is_array($ThisFileInfo['matroska']['segments'])) {
             foreach ($ThisFileInfo['matroska']['segments'] as $key => $segmentsarray) {
                 if ($segmentsarray['id'] == EBML_ID_CLUSTER) {
                     unset($ThisFileInfo['matroska']['segments'][$key]);
                 }
             }
         }
         if (isset($ThisFileInfo['matroska']['seek']) && is_array($ThisFileInfo['matroska']['seek'])) {
             foreach ($ThisFileInfo['matroska']['seek'] as $key => $seekarray) {
                 if ($seekarray['target_id'] == EBML_ID_CLUSTER) {
                     unset($ThisFileInfo['matroska']['seek'][$key]);
                 }
             }
         }
     }
     if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) {
         foreach ($ThisFileInfo['matroska']['info'] as $key => $infoarray) {
             if (isset($infoarray['Duration'])) {
                 // TimecodeScale is how many nanoseconds each Duration unit is
                 $ThisFileInfo['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
                 break;
             }
         }
     }
     if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) {
         foreach ($ThisFileInfo['matroska']['tracks']['tracks'] as $key => $trackarray) {
             $track_info = array();
             switch (@$trackarray['TrackType']) {
                 case 1:
                     // Video
                     if (@$trackarray['PixelWidth']) {
                         $track_info['resolution_x'] = $trackarray['PixelWidth'];
                     }
                     if (@$trackarray['PixelHeight']) {
                         $track_info['resolution_y'] = $trackarray['PixelHeight'];
                     }
                     if (@$trackarray['DisplayWidth']) {
                         $track_info['display_x'] = $trackarray['DisplayWidth'];
                     }
                     if (@$trackarray['DisplayHeight']) {
                         $track_info['display_y'] = $trackarray['DisplayHeight'];
                     }
                     if (@$trackarray['DefaultDuration']) {
                         $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3);
                     }
                     if (@$trackarray['CodecID']) {
                         $track_info['codec'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);
                     }
                     if (!empty($trackarray['codec_private_parsed']['fourcc'])) {
                         $track_info['fourcc'] = $trackarray['codec_private_parsed']['fourcc'];
                     }
                     $ThisFileInfo['video']['streams'][] = $track_info;
                     if (isset($track_info['resolution_x']) && empty($ThisFileInfo['video']['resolution_x'])) {
                         foreach ($track_info as $key => $value) {
                             $ThisFileInfo['video'][$key] = $value;
                         }
                     }
                     break;
                 case 2:
                     // Audio
                     if (@$trackarray['CodecID']) {
                         $track_info['dataformat'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);
                     }
                     if (@$trackarray['SamplingFrequency']) {
                         $track_info['sample_rate'] = $trackarray['SamplingFrequency'];
                     }
                     if (@$trackarray['Channels']) {
                         $track_info['channels'] = $trackarray['Channels'];
                     }
                     if (@$trackarray['BitDepth']) {
                         $track_info['bits_per_sample'] = $trackarray['BitDepth'];
                     }
                     switch (@$trackarray[$this->EBMLidName(EBML_ID_CODECID)]) {
                         case 'A_PCM/INT/LIT':
                         case 'A_PCM/INT/BIG':
                             $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
                             break;
                         default:
                             break;
                     }
                     $ThisFileInfo['audio']['streams'][] = $track_info;
                     if (isset($track_info['dataformat']) && empty($ThisFileInfo['audio']['dataformat'])) {
                         foreach ($track_info as $key => $value) {
                             $ThisFileInfo['audio'][$key] = $value;
                         }
                     }
                     break;
                 default:
                     // ignore, do nothing
                     break;
             }
         }
     }
     if (!empty($ThisFileInfo['video']['streams'])) {
         $ThisFileInfo['mime_type'] = 'video/x-matroska';
     } elseif (!empty($ThisFileInfo['video']['streams'])) {
         $ThisFileInfo['mime_type'] = 'audio/x-matroska';
     } elseif (isset($ThisFileInfo['mime_type'])) {
         unset($ThisFileInfo['mime_type']);
     }
     foreach ($this->warnings as $key => $value) {
         $ThisFileInfo['warning'][] = $value;
     }
     return true;
 }
	function getid3_matroska(&$fd, &$ThisFileInfo) {

		// http://www.matroska.org/technical/specs/index.html#EBMLBasics
		$offset = $ThisFileInfo['avdataoffset'];
		$EBMLdata = '';
		$EBMLdata_offset = $offset;

		if ($ThisFileInfo['avdataend'] > 2147483648) {
			$this->warnings[] = 'This version of getID3() may or may not correctly handle Matroska files larger than 2GB';
		}

		while ($offset < $ThisFileInfo['avdataend']) {
			$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);

			$top_element_offset    = $offset;
			$top_element_id        = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
			$top_element_length    = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
			if ($top_element_length === false) {
				$this->warnings[] = 'invalid chunk length at '.$top_element_offset;
				$offset = pow(2, 63);
				break;
			}
			$top_element_endoffset = $offset + $top_element_length;
			switch ($top_element_id) {
				case EBML_ID_EBML:
					$ThisFileInfo['fileformat'] = 'matroska';
					$ThisFileInfo['matroska']['header']['offset'] = $top_element_offset;
					$ThisFileInfo['matroska']['header']['length'] = $top_element_length;

					while ($offset < $top_element_endoffset) {
						$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
						$element_data = array();
						$element_data_offset     = $offset;
						$element_data['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
						$element_data['id_name'] = $this->EBMLidName($element_data['id']);
						$element_data['length']     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
						$end_offset              = $offset + $element_data['length'];

						switch ($element_data['id']) {
							case EBML_ID_VOID:    // padding, ignore
								break;
							case EBML_ID_EBMLVERSION:
							case EBML_ID_EBMLREADVERSION:
							case EBML_ID_EBMLMAXIDLENGTH:
							case EBML_ID_EBMLMAXSIZELENGTH:
							case EBML_ID_DOCTYPEVERSION:
							case EBML_ID_DOCTYPEREADVERSION:
								$element_data['data'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']));
								break;
							case EBML_ID_DOCTYPE:
								$element_data['data'] =                      trim(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']), "\x00");
								break;
							default:
								$this->warnings[] = 'Unhandled track.video element ['.basename(__FILE__).':'.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data_offset;
								break;
						}
						$offset = $end_offset;
						$ThisFileInfo['matroska']['header']['elements'][] = $element_data;
					}
					break;


				case EBML_ID_SEGMENT:
					$ThisFileInfo['matroska']['segment'][0]['offset'] = $top_element_offset;
					$ThisFileInfo['matroska']['segment'][0]['length'] = $top_element_length;

					$segment_key = -1;
					while ($offset < $ThisFileInfo['avdataend']) {
						$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);

						$element_data = array();
						$element_data['offset']  = $offset;
						$element_data['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
						$element_data['id_name'] = $this->EBMLidName($element_data['id']);
						$element_data['length']  = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
						if ($element_data['length'] === false) {
							$this->warnings[] = 'invalid chunk length at '.$element_data['offset'];
							//$offset = pow(2, 63);
							$offset = $ThisFileInfo['avdataend'];
							break;
						}
						$element_end             = $offset + $element_data['length'];
						switch ($element_data['id']) {
							//case EBML_ID_CLUSTER:
							//	// too many cluster entries, probably not useful
							//	break;
							case false:
								$this->warnings[] = 'invalid ID at '.$element_data['offset'];
								$offset = $element_end;
								continue 3;
							default:
								$ThisFileInfo['matroska']['segments'][] = $element_data;
								break;
						}
						$segment_key++;

						switch ($element_data['id']) {
							case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$seek_entry = array();
									$seek_entry['offset']  = $offset;
									$seek_entry['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$seek_entry['id_name'] = $this->EBMLidName($seek_entry['id']);
									$seek_entry['length']  = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$seek_end_offset       = $offset + $seek_entry['length'];
									switch ($seek_entry['id']) {
										case EBML_ID_SEEK: // Contains a single seek entry to an EBML element
											while ($offset < $seek_end_offset) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$value  =             substr($EBMLdata, $offset - $EBMLdata_offset, $length);
												$offset += $length;
												switch ($id) {
													case EBML_ID_SEEKID:
														$dummy = 0;
														$seek_entry['target_id']   = $this->readEBMLint($value, $dummy);
														$seek_entry['target_name'] = $this->EBMLidName($seek_entry['target_id']);
														break;
													case EBML_ID_SEEKPOSITION:
														$seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($value);
														break;
													default:
														$ThisFileInfo['error'][] = 'Unhandled segment ['.basename(__FILE__).':'.__LINE__.'] ('.$id.') at '.$offset;
														break;
												}
											}
											$ThisFileInfo['matroska']['seek'][] = $seek_entry;
											//switch ($seek_entry['target_id']) {
											//	case EBML_ID_CLUSTER:
											//		// too many cluster seek points, probably not useful
											//		break;
											//	default:
											//		$ThisFileInfo['matroska']['seek'][] = $seek_entry;
											//		break;
											//}
											break;
										default:
											$this->warnings[] = 'Unhandled seekhead element ['.basename(__FILE__).':'.__LINE__.'] ('.$seek_entry['id'].') at '.$offset;
											break;
									}
									$offset = $seek_end_offset;
								}
								break;

							case EBML_ID_TRACKS: // information about all tracks in segment
								$ThisFileInfo['matroska']['tracks'] = $element_data;
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$track_entry = array();
									$track_entry['offset']  = $offset;
									$track_entry['id']      = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$track_entry['id_name'] = $this->EBMLidName($track_entry['id']);
									$track_entry['length']  = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$track_entry_endoffset  = $offset + $track_entry['length'];
									switch ($track_entry['id']) {
										case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements.
											while ($offset < $track_entry_endoffset) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$subelement_offset = $offset;
												$subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$subelement_idname = $this->EBMLidName($subelement_id);
												$subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$subelement_end    = $offset + $subelement_length;
												switch ($subelement_id) {
													case EBML_ID_TRACKNUMBER:
													case EBML_ID_TRACKUID:
													case EBML_ID_TRACKTYPE:
													case EBML_ID_MINCACHE:
													case EBML_ID_MAXCACHE:
													case EBML_ID_MAXBLOCKADDITIONID:
													case EBML_ID_DEFAULTDURATION: // nanoseconds per frame
														$track_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
														break;

													case EBML_ID_TRACKTIMECODESCALE:
														$track_entry[$subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
														break;

													case EBML_ID_CODECID:
													case EBML_ID_LANGUAGE:
													case EBML_ID_NAME:
													case EBML_ID_CODECNAME:
													case EBML_ID_CODECPRIVATE:
														$track_entry[$subelement_idname] =                              trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
														break;

													case EBML_ID_FLAGENABLED:
													case EBML_ID_FLAGDEFAULT:
													case EBML_ID_FLAGFORCED:
													case EBML_ID_FLAGLACING:
													case EBML_ID_CODECDECODEALL:
														$track_entry[$subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
														break;

													case EBML_ID_VIDEO:
														while ($offset < $subelement_end) {
															$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_offset = $offset;
															$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
															$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_end    = $offset + $sub_subelement_length;
															switch ($sub_subelement_id) {
																case EBML_ID_PIXELWIDTH:
																case EBML_ID_PIXELHEIGHT:
																case EBML_ID_STEREOMODE:
																case EBML_ID_PIXELCROPBOTTOM:
																case EBML_ID_PIXELCROPTOP:
																case EBML_ID_PIXELCROPLEFT:
																case EBML_ID_PIXELCROPRIGHT:
																case EBML_ID_DISPLAYWIDTH:
																case EBML_ID_DISPLAYHEIGHT:
																case EBML_ID_DISPLAYUNIT:
																case EBML_ID_ASPECTRATIOTYPE:
																	$track_entry[$sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
																	break;
																case EBML_ID_FLAGINTERLACED:
																	$track_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
																	break;
																case EBML_ID_GAMMAVALUE:
																	$track_entry[$sub_subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
																	break;
																case EBML_ID_COLOURSPACE:
																	$track_entry[$sub_subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00");
																	break;
																default:
																	$this->warnings[] = 'Unhandled track.video element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
																	break;
															}
															$offset = $sub_subelement_end;
														}

														if (isset($track_entry[$this->EBMLidName(EBML_ID_CODECID)]) && ($track_entry[$this->EBMLidName(EBML_ID_CODECID)] == 'V_MS/VFW/FOURCC') && isset($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)])) {
															if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
																$track_entry['codec_private_parsed'] = getid3_riff::ParseBITMAPINFOHEADER($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)]);
															} else {
																$this->warnings[] = 'Unable to parse codec private data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"';
															}
														}
														break;

													case EBML_ID_AUDIO:
														while ($offset < $subelement_end) {
															$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_offset = $offset;
															$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
															$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_end    = $offset + $sub_subelement_length;
															switch ($sub_subelement_id) {
																case EBML_ID_CHANNELS:
																case EBML_ID_BITDEPTH:
																	$track_entry[$sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
																	break;
																case EBML_ID_SAMPLINGFREQUENCY:
																case EBML_ID_OUTPUTSAMPLINGFREQUENCY:
																	$track_entry[$sub_subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
																	break;
																case EBML_ID_CHANNELPOSITIONS:
																	$track_entry[$sub_subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00");
																	break;
																default:
																	$this->warnings[] = 'Unhandled track.video element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
																	break;
															}
															$offset = $sub_subelement_end;
														}
														break;

													case EBML_ID_CONTENTENCODINGS:
														while ($offset < $subelement_end) {
															$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_offset = $offset;
															$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
															$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_subelement_end    = $offset + $sub_subelement_length;
															switch ($sub_subelement_id) {
																case EBML_ID_CONTENTENCODING:
																	while ($offset < $sub_subelement_end) {
																		$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_subelement_offset = $offset;
																		$sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
																		$sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
																		switch ($sub_sub_subelement_id) {
																			case EBML_ID_CONTENTENCODINGORDER:
																			case EBML_ID_CONTENTENCODINGSCOPE:
																			case EBML_ID_CONTENTENCODINGTYPE:
																				$track_entry[$sub_subelement_idname][$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
																				break;
																			case EBML_ID_CONTENTCOMPRESSION:
																				while ($offset < $sub_sub_subelement_end) {
																					$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
																					$sub_sub_sub_subelement_offset = $offset;
																					$sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																					$sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
																					$sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																					$sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
																					switch ($sub_sub_sub_subelement_id) {
																						case EBML_ID_CONTENTCOMPALGO:
																							$track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
																							break;
																						case EBML_ID_CONTENTCOMPSETTINGS:
																							$track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
																							break;
																						default:
																							$this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
																							break;
																					}
																					$offset = $sub_sub_sub_subelement_end;
																				}
																				break;

																			case EBML_ID_CONTENTENCRYPTION:
																				while ($offset < $sub_sub_subelement_end) {
																					$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
																					$sub_sub_sub_subelement_offset = $offset;
																					$sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																					$sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
																					$sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																					$sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
																					switch ($sub_sub_sub_subelement_id) {
																						case EBML_ID_CONTENTENCALGO:
																						case EBML_ID_CONTENTSIGALGO:
																						case EBML_ID_CONTENTSIGHASHALGO:
																							$track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
																							break;
																						case EBML_ID_CONTENTENCKEYID:
																						case EBML_ID_CONTENTSIGNATURE:
																						case EBML_ID_CONTENTSIGKEYID:
																							$track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
																							break;
																						default:
																							$this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
																							break;
																					}
																					$offset = $sub_sub_sub_subelement_end;
																				}
																				break;

																			default:
																				$this->warnings[] = 'Unhandled track.contentencodings.contentencoding element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
																				break;
																		}
																		$offset = $sub_sub_subelement_end;
																	}
																	break;
																default:
																	$this->warnings[] = 'Unhandled track.contentencodings element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
																	break;
															}
															$offset = $sub_subelement_end;
														}
														break;

													default:
														$this->warnings[] = 'Unhandled track element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
														break;
												}
												$offset = $subelement_end;
											}
											break;
										default:
											$this->warnings[] = 'Unhandled track element ['.basename(__FILE__).':'.__LINE__.'] ('.$track_entry['id'].'::'.$track_entry['id_name'].') at '.$track_entry['offset'];
											$offset = $track_entry_endoffset;
											break;
									}
									$ThisFileInfo['matroska']['tracks']['tracks'][] = $track_entry;
								}
								break;

							case EBML_ID_INFO: // Contains the position of other level 1 elements
								$info_entry = array();
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$subelement_offset = $offset;
									$subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_idname = $this->EBMLidName($subelement_id);
									$subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_end    = $offset + $subelement_length;
									switch ($subelement_id) {
										case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
										case EBML_ID_CHAPTERTRANSLATECODEC:
										case EBML_ID_TIMECODESCALE:
											$info_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
											break;
										case EBML_ID_DURATION:
											$info_entry[$subelement_idname] =      getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
											break;
										case EBML_ID_DATEUTC:
											$info_entry[$subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
											$info_entry[$subelement_idname.'_unix'] = $this->EBMLdate2unix($info_entry[$subelement_idname]);
											break;
										case EBML_ID_SEGMENTUID:
										case EBML_ID_PREVUID:
										case EBML_ID_NEXTUID:
										case EBML_ID_SEGMENTFAMILY:
										case EBML_ID_CHAPTERTRANSLATEID:
											$info_entry[$subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
											break;
										case EBML_ID_SEGMENTFILENAME:
										case EBML_ID_PREVFILENAME:
										case EBML_ID_NEXTFILENAME:
										case EBML_ID_TITLE:
										case EBML_ID_MUXINGAPP:
										case EBML_ID_WRITINGAPP:
											$info_entry[$subelement_idname] =                             trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00");
											break;
										default:
											$this->warnings[] = 'Unhandled info element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
											break;
									}
									$offset = $subelement_end;
								}
								$ThisFileInfo['matroska']['info'][] = $info_entry;
								break;

							case EBML_ID_CUES:
								$cues_entry = array();
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$subelement_offset = $offset;
									$subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_idname = $this->EBMLidName($subelement_id);
									$subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_end    = $offset + $subelement_length;
									switch ($subelement_id) {
										case EBML_ID_CUEPOINT:
											$cuepoint_entry = array();
											while ($offset < $subelement_end) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_offset = $offset;
												$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
												$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_end    = $offset + $sub_subelement_length;
												switch ($sub_subelement_id) {
													case EBML_ID_CUETRACKPOSITIONS:
														while ($offset < $sub_subelement_end) {
															$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_offset = $offset;
															$sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
															$sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
															switch ($sub_sub_subelement_id) {
																case EBML_ID_CUETRACK:
																	$cuepoint_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
																	break;
																default:
																	$this->warnings[] = 'Unhandled cues.cuepoint.cuetrackpositions element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
																	break;
															}
															$offset = $sub_subelement_end;
														}
														break;
													case EBML_ID_CUETIME:
														$cuepoint_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
														break;
													default:
														$this->warnings[] = 'Unhandled cues.cuepoint element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
														break;
												}
												$offset = $sub_subelement_end;
											}
											$cues_entry[] = $cuepoint_entry;
											$offset = $sub_subelement_end;
											break;
										default:
											$this->warnings[] = 'Unhandled cues element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
											break;
									}
									$offset = $subelement_end;
								}
								$ThisFileInfo['matroska']['cues'] = $cues_entry;
								break;

							case EBML_ID_TAGS:
								$tags_entry = array();
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$subelement_offset = $offset;
									$subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_idname = $this->EBMLidName($subelement_id);
									$subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_end    = $offset + $subelement_length;
									switch ($subelement_id) {
										case EBML_ID_WRITINGAPP:
											$tags_entry[$subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length);
											break;
										case EBML_ID_TAG:
											$tag_entry = array();
											while ($offset < $subelement_end) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_offset = $offset;
												$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
												$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_end    = $offset + $sub_subelement_length;
												switch ($sub_subelement_id) {
													case EBML_ID_TARGETS:
														$targets_entry = array();
														while ($offset < $sub_subelement_end) {
															$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_offset = $offset;
															$sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
															$sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
															switch ($sub_sub_subelement_id) {
																case EBML_ID_TARGETTYPEVALUE:
																case EBML_ID_EDITIONUID:
																case EBML_ID_CHAPTERUID:
																case EBML_ID_ATTACHMENTUID:
																case EBML_ID_TAGTRACKUID:
																case EBML_ID_TAGCHAPTERUID:
																	$targets_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
																	break;
																default:
																	$this->warnings[] = 'Unhandled tag.targets element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
																	break;
															}
															$offset = $sub_sub_subelement_end;
														}
														$tag_entry[$sub_subelement_idname][] = $targets_entry;
														break;
													case EBML_ID_SIMPLETAG:
														$simpletag_entry = array();
														while ($offset < $sub_subelement_end) {
															$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_offset = $offset;
															$sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
															$sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
															switch ($sub_sub_subelement_id) {
																case EBML_ID_TAGNAME:
																case EBML_ID_TAGLANGUAGE:
																case EBML_ID_TAGSTRING:
																case EBML_ID_TAGBINARY:
																	$simpletag_entry[$sub_sub_subelement_idname] =                                  substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
																	break;
																case EBML_ID_TAGDEFAULT:
																	$simpletag_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
																	break;
																default:
																	$this->warnings[] = 'Unhandled tag.simpletag element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
																	break;
															}
															$offset = $sub_sub_subelement_end;
														}
														$tag_entry[$sub_subelement_idname][] = $simpletag_entry;
														break;
													case EBML_ID_TARGETTYPE:
														$tag_entry[$sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
														break;
													case EBML_ID_TRACKUID:
														$tag_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
														break;
													default:
														$this->warnings[] = 'Unhandled tags.tag element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
														break;
												}
												$offset = $sub_subelement_end;
											}
											$tags_entry['tags'][] = $tag_entry;
											$offset = $sub_subelement_end;
											break;
										default:
											$this->warnings[] = 'Unhandled tags element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
											break;
									}
									$offset = $subelement_end;
								}
								$ThisFileInfo['matroska']['tags'] = $tags_entry;
								break;


							case EBML_ID_ATTACHMENTS:
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$subelement_offset = $offset;
									$subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_idname = $this->EBMLidName($subelement_id);
									$subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_end    = $offset + $subelement_length;
									switch ($subelement_id) {
										case EBML_ID_ATTACHEDFILE:
											$attachedfile_entry = array();
											while ($offset < $subelement_end) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_offset = $offset;
												$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
												$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_end    = $offset + $sub_subelement_length;
												switch ($sub_subelement_id) {
													case EBML_ID_FILEDESCRIPTION:
													case EBML_ID_FILENAME:
													case EBML_ID_FILEMIMETYPE:
														$attachedfile_entry[$sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
														break;

													case EBML_ID_FILEDATA:
														$attachedfile_entry['data_offset'] = $offset;
														$attachedfile_entry['data_length'] = $sub_subelement_length;
														if ($sub_subelement_length < 1024) {
															$attachedfile_entry[$sub_subelement_idname] =                           substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length);
														}
														break;

													case EBML_ID_FILEUID:
														$attachedfile_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
														break;

													default:
														$this->warnings[] = 'Unhandled attachment.attachedfile element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
														break;
												}
												$offset = $sub_subelement_end;
											}
											$ThisFileInfo['matroska']['attachments'][] = $attachedfile_entry;
											$offset = $sub_subelement_end;
											break;
										default:
											$this->warnings[] = 'Unhandled tags element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
											break;
									}
									$offset = $subelement_end;
								}
								break;


							case EBML_ID_CHAPTERS: // not important to us, contains mostly actual audio/video data, ignore
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$subelement_offset = $offset;
									$subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_idname = $this->EBMLidName($subelement_id);
									$subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_end    = $offset + $subelement_length;
									switch ($subelement_id) {
										case EBML_ID_EDITIONENTRY:
											$editionentry_entry = array();
											while ($offset < $subelement_end) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_offset = $offset;
												$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
												$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_end    = $offset + $sub_subelement_length;
												switch ($sub_subelement_id) {
													case EBML_ID_EDITIONUID:
														$editionentry_entry[$sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
														break;
													case EBML_ID_EDITIONFLAGHIDDEN:
													case EBML_ID_EDITIONFLAGDEFAULT:
													case EBML_ID_EDITIONFLAGORDERED:
														$editionentry_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
														break;
													case EBML_ID_CHAPTERATOM:
														$chapteratom_entry = array();
														while ($offset < $sub_subelement_end) {
															$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_offset = $offset;
															$sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
															$sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
															$sub_sub_subelement_end    = $offset + $sub_sub_subelement_length;
															switch ($sub_sub_subelement_id) {
																case EBML_ID_CHAPTERSEGMENTUID:
																case EBML_ID_CHAPTERSEGMENTEDITIONUID:
																	$chapteratom_entry[$sub_sub_subelement_idname] =                                  substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length);
																	break;
																case EBML_ID_CHAPTERFLAGENABLED:
																case EBML_ID_CHAPTERFLAGHIDDEN:
																	$chapteratom_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
																	break;
																case EBML_ID_CHAPTERUID:
																case EBML_ID_CHAPTERTIMESTART:
																case EBML_ID_CHAPTERTIMEEND:
																	$chapteratom_entry[$sub_sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length));
																	break;
																case EBML_ID_CHAPTERTRACK:
																	$chaptertrack_entry = array();
																	while ($offset < $sub_sub_subelement_end) {
																		$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_sub_subelement_offset = $offset;
																		$sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id);
																		$sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
																		switch ($sub_sub_sub_subelement_id) {
																			case EBML_ID_CHAPTERTRACKNUMBER:
																				$chaptertrack_entry[$sub_sub_sub_subelement_idname] =        getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length));
																				break;
																			default:
																				$this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chaptertrack element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset;
																				break;
																		}
																		$offset = $sub_sub_sub_subelement_end;
																	}
																	$chapteratom_entry[$sub_sub_subelement_idname][] = $chaptertrack_entry;
																	break;
																case EBML_ID_CHAPTERDISPLAY:
																	$chapterdisplay_entry = array();
																	while ($offset < $sub_sub_subelement_end) {
																		$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_sub_subelement_offset = $offset;
																		$sub_sub_sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_sub_subelement_id);
																		$sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
																		$sub_sub_sub_subelement_end    = $offset + $sub_sub_sub_subelement_length;
																		switch ($sub_sub_sub_subelement_id) {
																			case EBML_ID_CHAPSTRING:
																			case EBML_ID_CHAPLANGUAGE:
																			case EBML_ID_CHAPCOUNTRY:
																				$chapterdisplay_entry[$sub_sub_sub_subelement_idname] =                                  substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length);
																				break;
																			default:
																				$this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chapterdisplay element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset;
																				break;
																		}
																		$offset = $sub_sub_sub_subelement_end;
																	}
																	$chapteratom_entry[$sub_sub_subelement_idname][] = $chapterdisplay_entry;
																	break;
																default:
																	$this->warnings[] = 'Unhandled chapters.editionentry.chapteratom element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset;
																	break;
															}
															$offset = $sub_sub_subelement_end;
														}
														$editionentry_entry[$sub_subelement_idname][] = $chapteratom_entry;
														break;
													default:
														$this->warnings[] = 'Unhandled chapters.editionentry element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
														break;
												}
												$offset = $sub_subelement_end;
											}
											$ThisFileInfo['matroska']['chapters'][] = $editionentry_entry;
											$offset = $sub_subelement_end;
											break;
										default:
											$this->warnings[] = 'Unhandled chapters element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
											break;
									}
									$offset = $subelement_end;
								}
								break;


							case EBML_ID_VOID:    // padding, ignore
								$void_entry = array();
								$void_entry['offset'] = $offset;
								$ThisFileInfo['matroska']['void'][] = $void_entry;
								break;

							case EBML_ID_CLUSTER: // not important to us, contains mostly actual audio/video data, ignore
								$cluster_entry = array();
								while ($offset < $element_end) {
									$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
									$subelement_offset = $offset;
									$subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_idname = $this->EBMLidName($subelement_id);
									$subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
									$subelement_end    = $offset + $subelement_length;
									switch ($subelement_id) {
										case EBML_ID_CLUSTERTIMECODE:
										case EBML_ID_CLUSTERPOSITION:
										case EBML_ID_CLUSTERPREVSIZE:
											$cluster_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length));
											break;

										case EBML_ID_CLUSTERSILENTTRACKS:
											$cluster_silent_tracks = array();
											while ($offset < $subelement_end) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_offset = $offset;
												$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
												$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_end    = $offset + $sub_subelement_length;
												switch ($sub_subelement_id) {
													case EBML_ID_CLUSTERSILENTTRACKNUMBER:
														$cluster_silent_tracks[] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
														break;
													default:
														$this->warnings[] = 'Unhandled clusters.silenttracks element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
														break;
												}
												$offset = $sub_subelement_end;
											}
											$cluster_entry[$subelement_idname][] = $cluster_silent_tracks;
											$offset = $sub_subelement_end;
											break;

										case EBML_ID_CLUSTERBLOCKGROUP:
											$cluster_block_group = array('offset'=>$offset);
											while ($offset < $subelement_end) {
												$this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_offset = $offset;
												$sub_subelement_id     = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_idname = $this->EBMLidName($sub_subelement_id);
												$sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
												$sub_subelement_end    = $offset + $sub_subelement_length;
												switch ($sub_subelement_id) {
													case EBML_ID_CLUSTERBLOCK:
														$cluster_block_data = array();
														$cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
														$cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2));
														$offset += 2;
														// unsure whether this is 1 octect or 2 octets? (http://matroska.org/technical/specs/index.html#block_structure)
														$cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
														$offset += 1;
														//$cluster_block_data['flags']['reserved1'] =      (($cluster_block_data['flags_raw'] & 0xF0) >> 4);
														$cluster_block_data['flags']['invisible'] = (bool) (($cluster_block_data['flags_raw'] & 0x08) >> 3);
														$cluster_block_data['flags']['lacing']    =        (($cluster_block_data['flags_raw'] & 0x06) >> 1);
														//$cluster_block_data['flags']['reserved2'] =      (($cluster_block_data['flags_raw'] & 0x01) >> 0);
														$cluster_block_data['flags']['lacing_type'] = $this->MatroskaBlockLacingType($cluster_block_data['flags']['lacing']);
														if ($cluster_block_data['flags']['lacing'] != 0) {
															$cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // Number of frames in the lace-1 (uint8)
															$offset += 1;
															if ($cluster_block_data['flags']['lacing'] != 2) {
																$cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace).
																$offset += 1;
															}
														}
														if (!isset($ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
															$ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']] = $offset;
														}
														$cluster_block_group[$sub_subelement_idname] = $cluster_block_data;
														break;

													case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int
													case EBML_ID_CLUSTERBLOCKDURATION:     // unsigned-int
														$cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length));
														break;

													case EBML_ID_CLUSTERREFERENCEBLOCK:    // signed-int
														$cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), false, true);
														break;

													default:
														$this->warnings[] = 'Unhandled clusters.blockgroup element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset;
														break;
												}
												$offset = $sub_subelement_end;
											}
											$cluster_entry[$subelement_idname][] = $cluster_block_group;
											$offset = $sub_subelement_end;
											break;

										case EBML_ID_CLUSTERSIMPLEBLOCK:
											// http://www.matroska.org/technical/specs/index.html#simpleblock_structure
											$cluster_block_data = array();
											$cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset);
											$cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2));
											$offset += 2;
											$cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
											$offset += 1;
											$cluster_block_data['flags']['keyframe']    = (($cluster_block_data['flags_raw'] & 0x80) >> 7);
											$cluster_block_data['flags']['reserved1']   = (($cluster_block_data['flags_raw'] & 0x70) >> 4);
											$cluster_block_data['flags']['invisible']   = (($cluster_block_data['flags_raw'] & 0x08) >> 3);
											$cluster_block_data['flags']['lacing']      = (($cluster_block_data['flags_raw'] & 0x06) >> 1);  // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing
											$cluster_block_data['flags']['discardable'] = (($cluster_block_data['flags_raw'] & 0x01));

											if ($cluster_block_data['flags']['lacing'] > 0) {
												$cluster_block_data['lace_frames'] = 1 + getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
												$offset += 1;
												if ($cluster_block_data['flags']['lacing'] != 0x02) {
													// *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace).
													$cluster_block_data['lace_frame_size'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1));
													$offset += 1;
												}
											}

											if (!isset($ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
												$ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']] = $offset;
											}
											$cluster_block_group[$sub_subelement_idname] = $cluster_block_data;
											break;

										default:
											$this->warnings[] = 'Unhandled cluster element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset;
											break;
									}
									$offset = $subelement_end;
								}
								$ThisFileInfo['matroska']['cluster'][] = $cluster_entry;

								// check to see if all the data we need exists already, if so, break out of the loop
								if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) {
									if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) {
										break 2;
									}
								}
								break;

							default:
								if ($element_data['id_name'] == dechex($element_data['id'])) {
									$ThisFileInfo['error'][] = 'Unhandled segment ['.basename(__FILE__).':'.__LINE__.'] ('.$element_data['id'].') at '.$element_data_offset;
								} else {
									$this->warnings[] = 'Unhandled segment ['.basename(__FILE__).':'.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data['offset'];
								}
								break;
						}
						$offset = $element_end;
					}
					break;


				default:
					$ThisFileInfo['error'][] = 'Unhandled chunk ['.basename(__FILE__).':'.__LINE__.'] ('.$top_element_id.') at '.$offset;
					break;
			}
			$offset = $top_element_endoffset;
		}



		if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) {
			foreach ($ThisFileInfo['matroska']['info'] as $key => $infoarray) {
				if (isset($infoarray['Duration'])) {
					// TimecodeScale is how many nanoseconds each Duration unit is
					$ThisFileInfo['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000);
					break;
				}
			}
		}
		if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) {
			foreach ($ThisFileInfo['matroska']['tracks']['tracks'] as $key => $trackarray) {
				$track_info = array();
				switch (isset($trackarray['TrackType']) ? $trackarray['TrackType'] : '') {
					case 1: // Video
						if (!empty($trackarray['PixelWidth']))                     { $track_info['resolution_x']  =                                    $trackarray['PixelWidth'];                     }
						if (!empty($trackarray['PixelHeight']))                    { $track_info['resolution_y']  =                                    $trackarray['PixelHeight'];                    }
						if (!empty($trackarray['DisplayWidth']))                   { $track_info['display_x']     =                                    $trackarray['DisplayWidth'];                   }
						if (!empty($trackarray['DisplayHeight']))                  { $track_info['display_y']     =                                    $trackarray['DisplayHeight'];                  }
						if (!empty($trackarray['DefaultDuration']))                { $track_info['frame_rate']    =                 round(1000000000 / $trackarray['DefaultDuration'], 3);            }
						if (!empty($trackarray['CodecID']))                        { $track_info['dataformat']    = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);                       }
						if (!empty($trackarray['codec_private_parsed']['fourcc'])) { $track_info['fourcc']        =                                    $trackarray['codec_private_parsed']['fourcc']; }
						$ThisFileInfo['video']['streams'][] = $track_info;
						if (isset($track_info['resolution_x']) && empty($ThisFileInfo['video']['resolution_x'])) {
							foreach ($track_info as $key => $value) {
								$ThisFileInfo['video'][$key] = $value;
							}
						}
						break;
					case 2: // Audio
						if (!empty($trackarray['CodecID']))           { $track_info['dataformat']      = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']);          }
						if (!empty($trackarray['SamplingFrequency'])) { $track_info['sample_rate']     =                                    $trackarray['SamplingFrequency']; }
						if (!empty($trackarray['Channels']))          { $track_info['channels']        =                                    $trackarray['Channels'];          }
						if (!empty($trackarray['BitDepth']))          { $track_info['bits_per_sample'] =                                    $trackarray['BitDepth'];          }
						switch (isset($trackarray[$this->EBMLidName(EBML_ID_CODECID)]) ? $trackarray[$this->EBMLidName(EBML_ID_CODECID)] : '') {
							case 'A_PCM/INT/LIT':
							case 'A_PCM/INT/BIG':
								$track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
								break;

							case 'A_AC3':
								if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) {
									if (isset($ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
										$ac3_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]);
										$getid3_ac3 = new getid3_ac3($fd, $ac3_thisfileinfo);
										$ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $ac3_thisfileinfo;
										if (!empty($ac3_thisfileinfo['error'])) {
											foreach ($ac3_thisfileinfo['error'] as $newerror) {
												$this->warnings[] = 'getid3_ac3() says: ['.$newerror.']';
											}
										}
										if (!empty($ac3_thisfileinfo['warning'])) {
											foreach ($ac3_thisfileinfo['warning'] as $newerror) {
												$this->warnings[] = 'getid3_ac3() says: ['.$newerror.']';
											}
										}
										if (isset($ac3_thisfileinfo['audio']) && is_array($ac3_thisfileinfo['audio'])) {
											foreach ($ac3_thisfileinfo['audio'] as $key => $value) {
												$track_info[$key] = $value;
											}
										}
										unset($ac3_thisfileinfo);
										unset($getid3_ac3);
									} else {
										$this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $ThisFileInfo[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set';
									}
								} else {
									$this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.ac3.php"';
								}
								break;

							case 'A_DTS':
								$dts_offset = $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']];
								// this is a NASTY hack, but sometimes audio data is off by a byte or two and not sure why, email info@getid3.org if you can explain better
								fseek($fd, $dts_offset, SEEK_SET);
								$magic_test = fread($fd, 8);
								for ($i = 0; $i < 4; $i++) {
									// look to see if DTS "magic" is here, if so adjust offset by that many bytes
									if (substr($magic_test, $i, 4) == "\x7F\xFE\x80\x01") {
										$dts_offset += $i;
										break;
									}
								}
								if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, false)) {
									$dts_thisfileinfo = array('avdataoffset'=>$dts_offset);
									$getid3_dts = new getid3_dts($fd, $dts_thisfileinfo);
									$ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $dts_thisfileinfo;
									if (!empty($dts_thisfileinfo['error'])) {
										foreach ($dts_thisfileinfo['error'] as $newerror) {
											$this->warnings[] = 'getid3_dts() says: ['.$newerror.']';
										}
									}
									if (!empty($dts_thisfileinfo['warning'])) {
										foreach ($dts_thisfileinfo['warning'] as $newerror) {
											$this->warnings[] = 'getid3_dts() says: ['.$newerror.']';
										}
									}
									if (isset($dts_thisfileinfo['audio']) && is_array($dts_thisfileinfo['audio'])) {
										foreach ($dts_thisfileinfo['audio'] as $key => $value) {
											$track_info[$key] = $value;
										}
									}
									unset($dts_thisfileinfo);
									unset($getid3_dts);
								} else {
									$this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.dts.php"';
								}
								break;

							case 'A_AAC':
$this->warnings[] = 'This version of getID3() [v'.GETID3_VERSION.'] has problems parsing AAC audio in Matroska containers ['.basename(__FILE__).':'.__LINE__.']';
								if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.aac.php', __FILE__, false)) {
							//		$aac_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]);
							//		$getid3_aac = new getid3_aac($fd, $aac_thisfileinfo);
							//		$ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $aac_thisfileinfo;
							//		if (isset($aac_thisfileinfo['audio']) && is_array($aac_thisfileinfo['audio'])) {
							//			foreach ($aac_thisfileinfo['audio'] as $key => $value) {
							//				$track_info[$key] = $value;
							//			}
							//		}
							//		unset($aac_thisfileinfo);
							//		unset($getid3_aac);
								} else {
									$this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.aac.php"';
								}
								break;

							case 'A_MPEG/L3':
								if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, false)) {
									$mp3_thisfileinfo = array(
										'avdataoffset' => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']],
										'avdataend'    => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']] + 1024,
									);
									$getid3_mp3 = new getid3_mp3($fd, $mp3_thisfileinfo);
									$getid3_mp3->allow_bruteforce = true;
									//getid3_mp3::getOnlyMPEGaudioInfo($fd, $mp3_thisfileinfo, $offset, false);
									$ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $mp3_thisfileinfo;
									if (!empty($mp3_thisfileinfo['error'])) {
										foreach ($mp3_thisfileinfo['error'] as $newerror) {
											$this->warnings[] = 'getid3_mp3() says: ['.$newerror.']';
										}
									}
									if (!empty($mp3_thisfileinfo['warning'])) {
										foreach ($mp3_thisfileinfo['warning'] as $newerror) {
											$this->warnings[] = 'getid3_mp3() says: ['.$newerror.']';
										}
									}
									if (isset($mp3_thisfileinfo['audio']) && is_array($mp3_thisfileinfo['audio'])) {
										foreach ($mp3_thisfileinfo['audio'] as $key => $value) {
											$track_info[$key] = $value;
										}
									}
									unset($mp3_thisfileinfo);
									unset($getid3_mp3);
								} else {
									$this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.mp3.php"';
								}
								break;

							case 'A_VORBIS':
								if (isset($trackarray['CodecPrivate'])) {
									// this is a NASTY hack, email info@getid3.org if you have a better idea how to get this info out
									$found_vorbis = false;
									for ($vorbis_offset = 1; $vorbis_offset < 16; $vorbis_offset++) {
										if (substr($trackarray['CodecPrivate'], $vorbis_offset, 6) == 'vorbis') {
											$vorbis_offset--;
											$found_vorbis = true;
											break;
										}
									}
									if ($found_vorbis) {
										if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, false)) {
											$vorbis_fileinfo = array();
											$oggpageinfo['page_seqno'] = 0;
											getid3_ogg::ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $vorbis_fileinfo, $oggpageinfo);
											$ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $vorbis_fileinfo;
											if (!empty($vorbis_fileinfo['error'])) {
												foreach ($vorbis_fileinfo['error'] as $newerror) {
													$this->warnings[] = 'getid3_ogg() says: ['.$newerror.']';
												}
											}
											if (!empty($vorbis_fileinfo['warning'])) {
												foreach ($vorbis_fileinfo['warning'] as $newerror) {
													$this->warnings[] = 'getid3_ogg() says: ['.$newerror.']';
												}
											}
											if (isset($vorbis_fileinfo['audio']) && is_array($vorbis_fileinfo['audio'])) {
												foreach ($vorbis_fileinfo['audio'] as $key => $value) {
													$track_info[$key] = $value;
												}
											}
											if (!empty($vorbis_fileinfo['ogg']['bitrate_average'])) {
												$track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_average'];
											} elseif (!empty($vorbis_fileinfo['ogg']['bitrate_nominal'])) {
												$track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_nominal'];
											}
											unset($vorbis_fileinfo);
											unset($oggpageinfo);
										} else {
											$this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.ogg.php"';
										}
									} else {
									}
								} else {
								}
								break;

							default:
								$this->warnings[] = 'Unhandled audio type "'.(isset($trackarray[$this->EBMLidName(EBML_ID_CODECID)]) ? $trackarray[$this->EBMLidName(EBML_ID_CODECID)] : '').'"';
								break;
						}


						$ThisFileInfo['audio']['streams'][] = $track_info;
						if (isset($track_info['dataformat']) && empty($ThisFileInfo['audio']['dataformat'])) {
							foreach ($track_info as $key => $value) {
								$ThisFileInfo['audio'][$key] = $value;
							}
						}
						break;
					default:
						// ignore, do nothing
						break;
				}
			}
		}

		if ($this->hide_clusters) {
			// too much data returned that is usually not useful
			if (isset($ThisFileInfo['matroska']['segments']) && is_array($ThisFileInfo['matroska']['segments'])) {
				foreach ($ThisFileInfo['matroska']['segments'] as $key => $segmentsarray) {
					if ($segmentsarray['id'] == EBML_ID_CLUSTER) {
						unset($ThisFileInfo['matroska']['segments'][$key]);
					}
				}
			}
			if (isset($ThisFileInfo['matroska']['seek']) && is_array($ThisFileInfo['matroska']['seek'])) {
				foreach ($ThisFileInfo['matroska']['seek'] as $key => $seekarray) {
					if ($seekarray['target_id'] == EBML_ID_CLUSTER) {
						unset($ThisFileInfo['matroska']['seek'][$key]);
					}
				}
			}
			//unset($ThisFileInfo['matroska']['cluster']);
			//unset($ThisFileInfo['matroska']['track_data_offsets']);
		}

		if (!empty($ThisFileInfo['video']['streams'])) {
			$ThisFileInfo['mime_type'] = 'video/x-matroska';
		} elseif (!empty($ThisFileInfo['video']['streams'])) {
			$ThisFileInfo['mime_type'] = 'audio/x-matroska';
		} elseif (isset($ThisFileInfo['mime_type'])) {
			unset($ThisFileInfo['mime_type']);
		}

		foreach ($this->warnings as $key => $value) {
			$ThisFileInfo['warning'][] = $value;
		}

		return true;
	}
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->include_module('audio-video.riff');
     $getid3->info['fileformat'] = 'real';
     $getid3->info['bitrate'] = 0;
     $getid3->info['playtime_seconds'] = 0;
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $chunk_counter = 0;
     while (ftell($getid3->fp) < $getid3->info['avdataend']) {
         $chunk_data = fread($getid3->fp, 8);
         $chunk_name = substr($chunk_data, 0, 4);
         $chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4));
         if ($chunk_name == '.ra' . "ý") {
             $chunk_data .= fread($getid3->fp, $chunk_size - 8);
             if ($this->ParseOldRAheader(substr($chunk_data, 0, 128), $getid3->info['real']['old_ra_header'])) {
                 $getid3->info['audio']['dataformat'] = 'real';
                 $getid3->info['audio']['lossless'] = false;
                 $getid3->info['audio']['sample_rate'] = $getid3->info['real']['old_ra_header']['sample_rate'];
                 $getid3->info['audio']['bits_per_sample'] = $getid3->info['real']['old_ra_header']['bits_per_sample'];
                 $getid3->info['audio']['channels'] = $getid3->info['real']['old_ra_header']['channels'];
                 $getid3->info['playtime_seconds'] = 60 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['real']['old_ra_header']['bytes_per_minute']);
                 $getid3->info['audio']['bitrate'] = 8 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['playtime_seconds']);
                 $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($getid3->info['real']['old_ra_header']['fourcc'], $getid3->info['audio']['bitrate']);
                 foreach ($getid3->info['real']['old_ra_header']['comments'] as $key => $value_array) {
                     if (strlen(trim($value_array[0])) > 0) {
                         $getid3->info['real']['comments'][$key][] = trim($value_array[0]);
                     }
                 }
                 return true;
             }
             throw new getid3_exception('There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or info@getid3.org');
         }
         $getid3->info['real']['chunks'][$chunk_counter] = array();
         $info_real_chunks_current_chunk =& $getid3->info['real']['chunks'][$chunk_counter];
         $info_real_chunks_current_chunk['name'] = $chunk_name;
         $info_real_chunks_current_chunk['offset'] = ftell($getid3->fp) - 8;
         $info_real_chunks_current_chunk['length'] = $chunk_size;
         if ($info_real_chunks_current_chunk['offset'] + $info_real_chunks_current_chunk['length'] > $getid3->info['avdataend']) {
             $getid3->warning('Chunk "' . $info_real_chunks_current_chunk['name'] . '" at offset ' . $info_real_chunks_current_chunk['offset'] . ' claims to be ' . $info_real_chunks_current_chunk['length'] . ' bytes long, which is beyond end of file');
             return false;
         }
         if ($chunk_size > getid3::FREAD_BUFFER_SIZE + 8) {
             $chunk_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE - 8);
             fseek($getid3->fp, $info_real_chunks_current_chunk['offset'] + $chunk_size, SEEK_SET);
         } elseif ($chunk_size - 8 > 0) {
             $chunk_data .= fread($getid3->fp, $chunk_size - 8);
         }
         $offset = 8;
         switch ($chunk_name) {
             case '.RMF':
                 // RealMedia File Header
                 $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                 $offset += 2;
                 switch ($info_real_chunks_current_chunk['object_version']) {
                     case 0:
                         $info_real_chunks_current_chunk['file_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
                         $offset += 4;
                         $info_real_chunks_current_chunk['headers_count'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
                         $offset += 4;
                         break;
                     default:
                         //$getid3->warning('Expected .RMF-object_version to be "0", actual value is "'.$info_real_chunks_current_chunk['object_version'].'" (should not be a problem)';
                         break;
                 }
                 break;
             case 'PROP':
                 // Properties Header
                 $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                 $offset += 2;
                 if ($info_real_chunks_current_chunk['object_version'] == 0) {
                     getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, array('max_bit_rate' => 4, 'avg_bit_rate' => 4, 'max_packet_size' => 4, 'avg_packet_size' => 4, 'num_packets' => 4, 'duration' => 4, 'preroll' => 4, 'index_offset' => 4, 'data_offset' => 4, 'num_streams' => 2, 'flags_raw' => 2));
                     $offset += 40;
                     $getid3->info['playtime_seconds'] = $info_real_chunks_current_chunk['duration'] / 1000;
                     if ($info_real_chunks_current_chunk['duration'] > 0) {
                         $getid3->info['bitrate'] += $info_real_chunks_current_chunk['avg_bit_rate'];
                     }
                     $info_real_chunks_current_chunk['flags']['save_enabled'] = (bool) ($info_real_chunks_current_chunk['flags_raw'] & 0x1);
                     $info_real_chunks_current_chunk['flags']['perfect_play'] = (bool) ($info_real_chunks_current_chunk['flags_raw'] & 0x2);
                     $info_real_chunks_current_chunk['flags']['live_broadcast'] = (bool) ($info_real_chunks_current_chunk['flags_raw'] & 0x4);
                 }
                 break;
             case 'MDPR':
                 // Media Properties Header
                 $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                 $offset += 2;
                 if ($info_real_chunks_current_chunk['object_version'] == 0) {
                     getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, array('stream_number' => 2, 'max_bit_rate' => 4, 'avg_bit_rate' => 4, 'max_packet_size' => 4, 'avg_packet_size' => 4, 'start_time' => 4, 'preroll' => 4, 'duration' => 4, 'stream_name_size' => 1));
                     $offset += 31;
                     $info_real_chunks_current_chunk['stream_name'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['stream_name_size']);
                     $offset += $info_real_chunks_current_chunk['stream_name_size'];
                     $info_real_chunks_current_chunk['mime_type_size'] = getid3_lib::BigEndian2Int($chunk_data[$offset++]);
                     $info_real_chunks_current_chunk['mime_type'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['mime_type_size']);
                     $offset += $info_real_chunks_current_chunk['mime_type_size'];
                     $info_real_chunks_current_chunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
                     $offset += 4;
                     $info_real_chunks_current_chunk['type_specific_data'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['type_specific_len']);
                     $offset += $info_real_chunks_current_chunk['type_specific_len'];
                     $info_real_chunks_current_chunk_typespecificdata =& $info_real_chunks_current_chunk['type_specific_data'];
                     switch ($info_real_chunks_current_chunk['mime_type']) {
                         case 'video/x-pn-realvideo':
                         case 'video/x-pn-multirate-realvideo':
                             // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
                             $info_real_chunks_current_chunk['video_info'] = array();
                             $info_real_chunks_current_chunk_video_info =& $info_real_chunks_current_chunk['video_info'];
                             getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk_video_info, $info_real_chunks_current_chunk_typespecificdata, 0, array('dwSize' => 4, 'fourcc1' => -4, 'fourcc2' => -4, 'width' => 2, 'height' => 2, 'bits_per_sample' => 2, 'IGNORE-unknown1' => 2, 'IGNORE-unknown2' => 2, 'frames_per_second' => 2, 'IGNORE-unknown3' => 2, 'IGNORE-unknown4' => 2, 'IGNORE-unknown5' => 2, 'IGNORE-unknown6' => 2, 'IGNORE-unknown7' => 2, 'IGNORE-unknown8' => 2, 'IGNORE-unknown9' => 2));
                             $info_real_chunks_current_chunk_video_info['codec'] = getid3_riff::RIFFfourccLookup($info_real_chunks_current_chunk_video_info['fourcc2']);
                             $getid3->info['video']['resolution_x'] = $info_real_chunks_current_chunk_video_info['width'];
                             $getid3->info['video']['resolution_y'] = $info_real_chunks_current_chunk_video_info['height'];
                             $getid3->info['video']['frame_rate'] = (double) $info_real_chunks_current_chunk_video_info['frames_per_second'];
                             $getid3->info['video']['codec'] = $info_real_chunks_current_chunk_video_info['codec'];
                             $getid3->info['video']['bits_per_sample'] = $info_real_chunks_current_chunk_video_info['bits_per_sample'];
                             break;
                         case 'audio/x-pn-realaudio':
                         case 'audio/x-pn-multirate-realaudio':
                             $this->ParseOldRAheader($info_real_chunks_current_chunk_typespecificdata, $info_real_chunks_current_chunk['parsed_audio_data']);
                             $getid3->info['audio']['sample_rate'] = $info_real_chunks_current_chunk['parsed_audio_data']['sample_rate'];
                             $getid3->info['audio']['bits_per_sample'] = $info_real_chunks_current_chunk['parsed_audio_data']['bits_per_sample'];
                             $getid3->info['audio']['channels'] = $info_real_chunks_current_chunk['parsed_audio_data']['channels'];
                             if (!empty($getid3->info['audio']['dataformat'])) {
                                 foreach ($getid3->info['audio'] as $key => $value) {
                                     if ($key != 'streams') {
                                         $getid3->info['audio']['streams'][$info_real_chunks_current_chunk['stream_number']][$key] = $value;
                                     }
                                 }
                             }
                             break;
                         case 'logical-fileinfo':
                             $info_real_chunks_current_chunk['logical_fileinfo']['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 0, 4));
                             // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown1']             = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 4, 4));
                             $info_real_chunks_current_chunk['logical_fileinfo']['num_tags'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 8, 4));
                             // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown2']             = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 12, 4));
                             break;
                     }
                     if (empty($getid3->info['playtime_seconds'])) {
                         $getid3->info['playtime_seconds'] = max($getid3->info['playtime_seconds'], ($info_real_chunks_current_chunk['duration'] + $info_real_chunks_current_chunk['start_time']) / 1000);
                     }
                     if ($info_real_chunks_current_chunk['duration'] > 0) {
                         switch ($info_real_chunks_current_chunk['mime_type']) {
                             case 'audio/x-pn-realaudio':
                             case 'audio/x-pn-multirate-realaudio':
                                 $getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
                                 $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info_real_chunks_current_chunk['parsed_audio_data']['fourcc'], $getid3->info['audio']['bitrate']);
                                 $getid3->info['audio']['dataformat'] = 'real';
                                 $getid3->info['audio']['lossless'] = false;
                                 break;
                             case 'video/x-pn-realvideo':
                             case 'video/x-pn-multirate-realvideo':
                                 $getid3->info['video']['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
                                 $getid3->info['video']['bitrate_mode'] = 'cbr';
                                 $getid3->info['video']['dataformat'] = 'real';
                                 $getid3->info['video']['lossless'] = false;
                                 $getid3->info['video']['pixel_aspect_ratio'] = (double) 1;
                                 break;
                             case 'audio/x-ralf-mpeg4-generic':
                                 $getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
                                 $getid3->info['audio']['codec'] = 'RealAudio Lossless';
                                 $getid3->info['audio']['dataformat'] = 'real';
                                 $getid3->info['audio']['lossless'] = true;
                                 break;
                         }
                         $getid3->info['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0);
                     }
                 }
                 break;
             case 'CONT':
                 // Content Description Header (text comments)
                 $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                 $offset += 2;
                 if ($info_real_chunks_current_chunk['object_version'] == 0) {
                     $info_real_chunks_current_chunk['title_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                     $offset += 2;
                     $info_real_chunks_current_chunk['title'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['title_len']);
                     $offset += $info_real_chunks_current_chunk['title_len'];
                     $info_real_chunks_current_chunk['artist_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                     $offset += 2;
                     $info_real_chunks_current_chunk['artist'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['artist_len']);
                     $offset += $info_real_chunks_current_chunk['artist_len'];
                     $info_real_chunks_current_chunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                     $offset += 2;
                     $info_real_chunks_current_chunk['copyright'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['copyright_len']);
                     $offset += $info_real_chunks_current_chunk['copyright_len'];
                     $info_real_chunks_current_chunk['comment_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                     $offset += 2;
                     $info_real_chunks_current_chunk['comment'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['comment_len']);
                     $offset += $info_real_chunks_current_chunk['comment_len'];
                     foreach (array('title' => 'title', 'artist' => 'artist', 'copyright' => 'copyright', 'comment' => 'comment') as $key => $val) {
                         if ($info_real_chunks_current_chunk[$key]) {
                             $getid3->info['real']['comments'][$val][] = trim($info_real_chunks_current_chunk[$key]);
                         }
                     }
                 }
                 break;
             case 'DATA':
                 // Data Chunk Header
                 // do nothing
                 break;
             case 'INDX':
                 // Index Section Header
                 $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
                 $offset += 2;
                 if ($info_real_chunks_current_chunk['object_version'] == 0) {
                     getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, array('num_indices' => 4, 'stream_number' => 2, 'next_index_header' => 4));
                     $offset += 10;
                     if ($info_real_chunks_current_chunk['next_index_header'] == 0) {
                         // last index chunk found, ignore rest of file
                         break 2;
                     } else {
                         // non-last index chunk, seek to next index chunk (skipping actual index data)
                         fseek($getid3->fp, $info_real_chunks_current_chunk['next_index_header'], SEEK_SET);
                     }
                 }
                 break;
             default:
                 $getid3->warning('Unhandled RealMedia chunk "' . $chunk_name . '" at offset ' . $info_real_chunks_current_chunk['offset']);
                 break;
         }
         $chunk_counter++;
     }
     if (!empty($getid3->info['audio']['streams'])) {
         $getid3->info['audio']['bitrate'] = 0;
         foreach ($getid3->info['audio']['streams'] as $key => $value_array) {
             $getid3->info['audio']['bitrate'] += $value_array['bitrate'];
         }
     }
     return true;
 }
 function getid3_shorten(&$fd, &$ThisFileInfo)
 {
     fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
     $ShortenHeader = fread($fd, 8);
     if (substr($ShortenHeader, 0, 4) != 'ajkg') {
         $ThisFileInfo['error'][] = 'Expecting "ajkg" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . substr($ShortenHeader, 0, 4) . '"';
         return false;
     }
     $ThisFileInfo['fileformat'] = 'shn';
     $ThisFileInfo['audio']['dataformat'] = 'shn';
     $ThisFileInfo['audio']['lossless'] = true;
     $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
     $ThisFileInfo['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1));
     fseek($fd, $ThisFileInfo['avdataend'] - 12, SEEK_SET);
     $SeekTableSignatureTest = fread($fd, 12);
     $ThisFileInfo['shn']['seektable']['present'] = (bool) (substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK');
     if ($ThisFileInfo['shn']['seektable']['present']) {
         $ThisFileInfo['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4));
         $ThisFileInfo['shn']['seektable']['offset'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['shn']['seektable']['length'];
         fseek($fd, $ThisFileInfo['shn']['seektable']['offset'], SEEK_SET);
         $SeekTableMagic = fread($fd, 4);
         if ($SeekTableMagic != 'SEEK') {
             $ThisFileInfo['error'][] = 'Expecting "SEEK" at offset ' . $ThisFileInfo['shn']['seektable']['offset'] . ', found "' . $SeekTableMagic . '"';
             return false;
         } else {
             // typedef struct tag_TSeekEntry
             // {
             //   unsigned long SampleNumber;
             //   unsigned long SHNFileByteOffset;
             //   unsigned long SHNLastBufferReadPosition;
             //   unsigned short SHNByteGet;
             //   unsigned short SHNBufferOffset;
             //   unsigned short SHNFileBitOffset;
             //   unsigned long SHNGBuffer;
             //   unsigned short SHNBitShift;
             //   long CBuf0[3];
             //   long CBuf1[3];
             //   long Offset0[4];
             //   long Offset1[4];
             // }TSeekEntry;
             $SeekTableData = fread($fd, $ThisFileInfo['shn']['seektable']['length'] - 16);
             $ThisFileInfo['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80);
             //$ThisFileInfo['shn']['seektable']['entries'] = array();
             //$SeekTableOffset = 0;
             //for ($i = 0; $i < $ThisFileInfo['shn']['seektable']['entry_count']; $i++) {
             //	$SeekTableEntry['sample_number'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //	$SeekTableOffset += 4;
             //	$SeekTableEntry['shn_file_byte_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //	$SeekTableOffset += 4;
             //	$SeekTableEntry['shn_last_buffer_read_position'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //	$SeekTableOffset += 4;
             //	$SeekTableEntry['shn_byte_get'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
             //	$SeekTableOffset += 2;
             //	$SeekTableEntry['shn_buffer_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
             //	$SeekTableOffset += 2;
             //	$SeekTableEntry['shn_file_bit_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
             //	$SeekTableOffset += 2;
             //	$SeekTableEntry['shn_gbuffer'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //	$SeekTableOffset += 4;
             //	$SeekTableEntry['shn_bit_shift'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
             //	$SeekTableOffset += 2;
             //	for ($j = 0; $j < 3; $j++) {
             //		$SeekTableEntry['cbuf0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //		$SeekTableOffset += 4;
             //	}
             //	for ($j = 0; $j < 3; $j++) {
             //		$SeekTableEntry['cbuf1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //		$SeekTableOffset += 4;
             //	}
             //	for ($j = 0; $j < 4; $j++) {
             //		$SeekTableEntry['offset0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //		$SeekTableOffset += 4;
             //	}
             //	for ($j = 0; $j < 4; $j++) {
             //		$SeekTableEntry['offset1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
             //		$SeekTableOffset += 4;
             //	}
             //
             //	$ThisFileInfo['shn']['seektable']['entries'][] = $SeekTableEntry;
             //}
         }
     }
     if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
         $ThisFileInfo['error'][] = 'PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files';
         return false;
     }
     if (GETID3_OS_ISWINDOWS) {
         $RequiredFiles = array('shorten.exe', 'cygwin1.dll', 'head.exe');
         foreach ($RequiredFiles as $required_file) {
             if (!is_readable(GETID3_HELPERAPPSDIR . $required_file)) {
                 $ThisFileInfo['error'][] = GETID3_HELPERAPPSDIR . $required_file . ' does not exist';
                 return false;
             }
         }
         $commandline = GETID3_HELPERAPPSDIR . 'shorten.exe -x "' . $ThisFileInfo['filenamepath'] . '" - | ' . GETID3_HELPERAPPSDIR . 'head.exe -c 64';
         $commandline = str_replace('/', '\\', $commandline);
     } else {
         static $shorten_present;
         if (!isset($shorten_present)) {
             $shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`;
         }
         if (!$shorten_present) {
             $ThisFileInfo['error'][] = 'shorten binary was not found in path or /usr/local/bin';
             return false;
         }
         $commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '') . 'shorten -x ' . escapeshellarg($ThisFileInfo['filenamepath']) . ' - | head -c 64';
     }
     $output = `{$commandline}`;
     if (!empty($output) && substr($output, 12, 4) == 'fmt ') {
         getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.audio-video.riff.php', __FILE__, true);
         $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4));
         $DecodedWAVFORMATEX = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size));
         $ThisFileInfo['audio']['channels'] = $DecodedWAVFORMATEX['channels'];
         $ThisFileInfo['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample'];
         $ThisFileInfo['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate'];
         if (substr($output, 20 + $fmt_size, 4) == 'data') {
             $ThisFileInfo['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec'];
         } else {
             $ThisFileInfo['error'][] = 'shorten failed to decode DATA chunk to expected location, cannot determine playtime';
             return false;
         }
         $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds'] * 8;
     } else {
         $ThisFileInfo['error'][] = 'shorten failed to decode file to WAV for parsing';
         return false;
     }
     return true;
 }
Example #17
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->include_module('audio-video.riff');
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $raw_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
     $getid3->info['fileformat'] = 'la';
     $getid3->info['audio']['dataformat'] = 'la';
     $getid3->info['audio']['lossless'] = true;
     $getid3->info['la']['version_major'] = (int) $raw_data[2];
     $getid3->info['la']['version_minor'] = (int) $raw_data[3];
     $getid3->info['la']['version'] = (double) $getid3->info['la']['version_major'] + $getid3->info['la']['version_minor'] / 10;
     $getid3->info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, 4, 4));
     $wave_chunk = substr($raw_data, 8, 4);
     if ($wave_chunk !== 'WAVE') {
         throw new getid3_exception('Expected "WAVE" (' . getid3_lib::PrintHexBytes('WAVE') . ') at offset 8, found "' . $wave_chunk . '" (' . getid3_lib::PrintHexBytes($wave_chunk) . ') instead.');
     }
     $offset = 12;
     $getid3->info['la']['fmt_size'] = 24;
     if ($getid3->info['la']['version'] >= 0.3) {
         $getid3->info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
         $getid3->info['la']['header_size'] = 49 + $getid3->info['la']['fmt_size'] - 24;
         $offset += 4;
     } else {
         // version 0.2 didn't support additional data blocks
         $getid3->info['la']['header_size'] = 41;
     }
     $fmt_chunk = substr($raw_data, $offset, 4);
     if ($fmt_chunk !== 'fmt ') {
         throw new getid3_exception('Expected "fmt " (' . getid3_lib::PrintHexBytes('fmt ') . ') at offset ' . $offset . ', found "' . $fmt_chunk . '" (' . getid3_lib::PrintHexBytes($fmt_chunk) . ') instead.');
     }
     $offset += 4;
     $fmt_size = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
     $offset += 4;
     $getid3->info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 2));
     $offset += 2;
     getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['la'], $raw_data, $offset, array('channels' => 2, 'sample_rate' => 4, 'bytes_per_second' => 4, 'bytes_per_sample' => 2, 'bits_per_sample' => 2, 'samples' => 4));
     $offset += 18;
     $getid3->info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int($raw_data[$offset++]);
     $getid3->info['la']['flags']['seekable'] = (bool) ($getid3->info['la']['raw']['flags'] & 0x1);
     if ($getid3->info['la']['version'] >= 0.4) {
         $getid3->info['la']['flags']['high_compression'] = (bool) ($getid3->info['la']['raw']['flags'] & 0x2);
     }
     $getid3->info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
     $offset += 4;
     // mikeØbevin*de
     // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16
     // in earlier versions. A seekpoint is added every blocksize * seekevery
     // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should
     // give the number of bytes used for the seekpoints. Of course, if seeking
     // is disabled, there are no seekpoints stored.
     if ($getid3->info['la']['version'] >= 0.4) {
         $getid3->info['la']['blocksize'] = 61440;
         $getid3->info['la']['seekevery'] = 19;
     } else {
         $getid3->info['la']['blocksize'] = 73728;
         $getid3->info['la']['seekevery'] = 16;
     }
     $getid3->info['la']['seekpoint_count'] = 0;
     if ($getid3->info['la']['flags']['seekable']) {
         $getid3->info['la']['seekpoint_count'] = floor($getid3->info['la']['samples'] / ($getid3->info['la']['blocksize'] * $getid3->info['la']['seekevery']));
         for ($i = 0; $i < $getid3->info['la']['seekpoint_count']; $i++) {
             $getid3->info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
             $offset += 4;
         }
     }
     if ($getid3->info['la']['version'] >= 0.3) {
         // Following the main header information, the program outputs all of the
         // seekpoints. Following these is what I called the 'footer start',
         // i.e. the position immediately after the La audio data is finished.
         $getid3->info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
         $offset += 4;
         if ($getid3->info['la']['footerstart'] > $getid3->info['filesize']) {
             $getid3->warning('FooterStart value points to offset ' . $getid3->info['la']['footerstart'] . ' which is beyond end-of-file (' . $getid3->info['filesize'] . ')');
             $getid3->info['la']['footerstart'] = $getid3->info['filesize'];
         }
     } else {
         // La v0.2 didn't have FooterStart value
         $getid3->info['la']['footerstart'] = $getid3->info['avdataend'];
     }
     if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) {
         // Create riff header
         $riff_data = 'WAVE';
         if ($getid3->info['la']['version'] == 0.2) {
             $riff_data .= substr($raw_data, 12, 24);
         } else {
             $riff_data .= substr($raw_data, 16, 24);
         }
         if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) {
             fseek($getid3->fp, $getid3->info['la']['footerstart'], SEEK_SET);
             $riff_data .= fread($getid3->fp, $getid3->info['avdataend'] - $getid3->info['la']['footerstart']);
         }
         $riff_data = 'RIFF' . getid3_lib::LittleEndian2String(strlen($riff_data), 4, false) . $riff_data;
         // Clone getid3 - messing with offsets - better safe than sorry
         $clone = clone $getid3;
         // Analyze clone by string
         $riff = new getid3_riff($clone);
         $riff->AnalyzeString($riff_data);
         // Import from clone and destroy
         $getid3->info['riff'] = $clone->info['riff'];
         $getid3->warnings($clone->warnings());
         unset($clone);
     }
     // $getid3->info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway
     $getid3->info['avdataend'] = $getid3->info['avdataoffset'] + $getid3->info['la']['footerstart'];
     $getid3->info['avdataoffset'] = $getid3->info['avdataoffset'] + $offset;
     $getid3->info['la']['compression_ratio'] = (double) (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['la']['uncompressed_size']);
     $getid3->info['playtime_seconds'] = (double) ($getid3->info['la']['samples'] / $getid3->info['la']['sample_rate']) / $getid3->info['la']['channels'];
     $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     $getid3->info['audio']['bits_per_sample'] = $getid3->info['la']['bits_per_sample'];
     $getid3->info['audio']['channels'] = $getid3->info['la']['channels'];
     $getid3->info['audio']['sample_rate'] = (int) $getid3->info['la']['sample_rate'];
     $getid3->info['audio']['encoder'] = 'LA v' . $getid3->info['la']['version'];
     return true;
 }
 function Analyze()
 {
     $info =& $this->getid3->info;
     fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     $LPACheader = fread($this->getid3->fp, 14);
     if (substr($LPACheader, 0, 4) != 'LPAC') {
         $info['error'][] = 'Expected "LPAC" at offset ' . $info['avdataoffset'] . ', found "' . $StreamMarker . '"';
         return false;
     }
     $info['avdataoffset'] += 14;
     $info['fileformat'] = 'lpac';
     $info['audio']['dataformat'] = 'lpac';
     $info['audio']['lossless'] = true;
     $info['audio']['bitrate_mode'] = 'vbr';
     $info['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader, 4, 1));
     $flags['audio_type'] = getid3_lib::BigEndian2Int(substr($LPACheader, 5, 1));
     $info['lpac']['total_samples'] = getid3_lib::BigEndian2Int(substr($LPACheader, 6, 4));
     $flags['parameters'] = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4));
     $info['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40);
     $info['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x4);
     $info['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x2);
     $info['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x1);
     if ($info['lpac']['flags']['24_bit'] && $info['lpac']['flags']['16_bit']) {
         $info['warning'][] = '24-bit and 16-bit flags cannot both be set';
     }
     $info['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000);
     $info['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x8000000);
     $info['lpac']['block_length'] = pow(2, ($flags['parameters'] & 0x7000000) >> 24) * 256;
     $info['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x800000);
     $info['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x400000);
     $info['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x40000);
     $info['lpac']['quantization'] = ($flags['parameters'] & 0x1f00) >> 8;
     $info['lpac']['max_prediction_order'] = $flags['parameters'] & 0x3f;
     if ($info['lpac']['flags']['fast_compress'] && $info['lpac']['max_prediction_order'] != 3) {
         $info['warning'][] = 'max_prediction_order expected to be "3" if fast_compress is true, actual value is "' . $info['lpac']['max_prediction_order'] . '"';
     }
     switch ($info['lpac']['file_version']) {
         case 6:
             if ($info['lpac']['flags']['adaptive_quantization']) {
                 $info['warning'][] = 'adaptive_quantization expected to be false in LPAC file stucture v6, actually true';
             }
             if ($info['lpac']['quantization'] != 20) {
                 $info['warning'][] = 'Quantization expected to be 20 in LPAC file stucture v6, actually ' . $info['lpac']['flags']['Q'];
             }
             break;
         default:
             //$info['warning'][] = 'This version of getID3() ['.$this->getid3->version().'] only supports LPAC file format version 6, this file is version '.$info['lpac']['file_version'].' - please report to info@getid3.org';
             break;
     }
     $getid3_temp = new getID3();
     $getid3_temp->openfile($this->getid3->filename);
     $getid3_temp->info = $info;
     $getid3_riff = new getid3_riff($getid3_temp);
     $getid3_riff->Analyze();
     $info['avdataoffset'] = $getid3_temp->info['avdataoffset'];
     $info['riff'] = $getid3_temp->info['riff'];
     $info['error'] = $getid3_temp->info['error'];
     $info['warning'] = $getid3_temp->info['warning'];
     $info['lpac']['comments']['comment'] = $getid3_temp->info['comments'];
     $info['audio']['sample_rate'] = $getid3_temp->info['audio']['sample_rate'];
     unset($getid3_temp, $getid3_riff);
     $info['audio']['channels'] = $info['lpac']['flags']['stereo'] ? 2 : 1;
     if ($info['lpac']['flags']['24_bit']) {
         $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample'];
     } elseif ($info['lpac']['flags']['16_bit']) {
         $info['audio']['bits_per_sample'] = 16;
     } else {
         $info['audio']['bits_per_sample'] = 8;
     }
     if ($info['lpac']['flags']['fast_compress']) {
         // fast
         $info['audio']['encoder_options'] = '-1';
     } else {
         switch ($info['lpac']['max_prediction_order']) {
             case 20:
                 // simple
                 $info['audio']['encoder_options'] = '-2';
                 break;
             case 30:
                 // medium
                 $info['audio']['encoder_options'] = '-3';
                 break;
             case 40:
                 // high
                 $info['audio']['encoder_options'] = '-4';
                 break;
             case 60:
                 // extrahigh
                 $info['audio']['encoder_options'] = '-5';
                 break;
         }
     }
     $info['playtime_seconds'] = $info['lpac']['total_samples'] / $info['audio']['sample_rate'];
     $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds'];
     return true;
 }
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->include_module('audio-video.riff');
     // Magic bytes - 'LPAC'
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $lpac_header = fread($getid3->fp, 14);
     $getid3->info['avdataoffset'] += 14;
     $getid3->info['lpac'] = array();
     $info_lpac =& $getid3->info['lpac'];
     $getid3->info['fileformat'] = 'lpac';
     $getid3->info['audio']['dataformat'] = 'lpac';
     $getid3->info['audio']['lossless'] = true;
     $getid3->info['audio']['bitrate_mode'] = 'vbr';
     $info_lpac['file_version'] = getid3_lib::BigEndian2Int($lpac_header[4]);
     $flags['audio_type'] = getid3_lib::BigEndian2Int($lpac_header[5]);
     $info_lpac['total_samples'] = getid3_lib::BigEndian2Int(substr($lpac_header, 6, 4));
     $flags['parameters'] = getid3_lib::BigEndian2Int(substr($lpac_header, 10, 4));
     $info_lpac['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40);
     $info_lpac['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x4);
     $info_lpac['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x2);
     $info_lpac['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x1);
     if ($info_lpac['flags']['24_bit'] && $info_lpac['flags']['16_bit']) {
         $getid3->warning('24-bit and 16-bit flags cannot both be set');
     }
     $info_lpac['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000);
     $info_lpac['flags']['random_access'] = (bool) ($flags['parameters'] & 0x8000000);
     $info_lpac['block_length'] = pow(2, ($flags['parameters'] & 0x7000000) >> 24) * 256;
     $info_lpac['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x800000);
     $info_lpac['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x400000);
     $info_lpac['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x40000);
     $info_lpac['quantization'] = ($flags['parameters'] & 0x1f00) >> 8;
     $info_lpac['max_prediction_order'] = $flags['parameters'] & 0x3f;
     if ($info_lpac['flags']['fast_compress'] && $info_lpac['max_prediction_order'] != 3) {
         $getid3->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "' . $info_lpac['max_prediction_order'] . '"');
     }
     switch ($info_lpac['file_version']) {
         case 6:
             if ($info_lpac['flags']['adaptive_quantization']) {
                 $getid3->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true');
             }
             if ($info_lpac['quantization'] != 20) {
                 $getid3->warning('Quantization expected to be 20 in LPAC file stucture v6, actually ' . $info_lpac['flags']['Q']);
             }
             break;
         default:
             //$getid3->warning('This version of getID3() only supports LPAC file format version 6, this file is version '.$info_lpac['file_version'].' - please report to info@getid3.org');
             break;
     }
     // Clone getid3 - messing with something - better safe than sorry
     $clone = clone $getid3;
     // Analyze clone by fp
     $riff = new getid3_riff($clone);
     $riff->Analyze();
     // Import from clone and destroy
     $getid3->info['avdataoffset'] = $clone->info['avdataoffset'];
     $getid3->info['riff'] = $clone->info['riff'];
     //$info_lpac['comments']['comment'] = $clone->info['comments'];
     $getid3->info['audio']['sample_rate'] = $clone->info['audio']['sample_rate'];
     $getid3->warnings($clone->warnings());
     unset($clone);
     $getid3->info['audio']['channels'] = $info_lpac['flags']['stereo'] ? 2 : 1;
     if ($info_lpac['flags']['24_bit']) {
         $getid3->info['audio']['bits_per_sample'] = $getid3->info['riff']['audio'][0]['bits_per_sample'];
     } elseif ($info_lpac['flags']['16_bit']) {
         $getid3->info['audio']['bits_per_sample'] = 16;
     } else {
         $getid3->info['audio']['bits_per_sample'] = 8;
     }
     if ($info_lpac['flags']['fast_compress']) {
         // fast
         $getid3->info['audio']['encoder_options'] = '-1';
     } else {
         switch ($info_lpac['max_prediction_order']) {
             case 20:
                 // simple
                 $getid3->info['audio']['encoder_options'] = '-2';
                 break;
             case 30:
                 // medium
                 $getid3->info['audio']['encoder_options'] = '-3';
                 break;
             case 40:
                 // high
                 $getid3->info['audio']['encoder_options'] = '-4';
                 break;
             case 60:
                 // extrahigh
                 $getid3->info['audio']['encoder_options'] = '-5';
                 break;
         }
     }
     $getid3->info['playtime_seconds'] = $info_lpac['total_samples'] / $getid3->info['audio']['sample_rate'];
     $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     return true;
 }
 private function ParseOptimFROGheader45()
 {
     $getid3 = $this->getid3;
     // for fileformat of v4.50a and higher
     $riff_data = '';
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     while (!feof($getid3->fp) && ftell($getid3->fp) < $getid3->info['avdataend']) {
         $block_offset = ftell($getid3->fp);
         $block_data = fread($getid3->fp, 8);
         $offset = 8;
         $block_name = substr($block_data, 0, 4);
         $block_size = getid3_lib::LittleEndian2Int(substr($block_data, 4, 4));
         if ($block_name == 'OFRX') {
             $block_name = 'OFR ';
         }
         if (!isset($getid3->info['ofr'][$block_name])) {
             $getid3->info['ofr'][$block_name] = array();
         }
         $info_ofr_this_block =& $getid3->info['ofr'][$block_name];
         switch ($block_name) {
             case 'OFR ':
                 // shortcut
                 $info_ofr_this_block['offset'] = $block_offset;
                 $info_ofr_this_block['size'] = $block_size;
                 $getid3->info['audio']['encoder'] = 'OptimFROG 4.50 alpha';
                 switch ($block_size) {
                     case 12:
                     case 15:
                         // good
                         break;
                     default:
                         $getid3->warning('"' . $block_name . '" contains more data than expected (expected 12 or 15 bytes, found ' . $block_size . ' bytes)');
                         break;
                 }
                 $block_data .= fread($getid3->fp, $block_size);
                 $info_ofr_this_block['total_samples'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 6));
                 $offset += 6;
                 $info_ofr_this_block['raw']['sample_type'] = getid3_lib::LittleEndian2Int($block_data[$offset++]);
                 $info_ofr_this_block['sample_type'] = $this->OptimFROGsampleTypeLookup($info_ofr_this_block['raw']['sample_type']);
                 $info_ofr_this_block['channel_config'] = getid3_lib::LittleEndian2Int($block_data[$offset++]);
                 $info_ofr_this_block['channels'] = $info_ofr_this_block['channel_config'];
                 $info_ofr_this_block['sample_rate'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4));
                 $offset += 4;
                 if ($block_size > 12) {
                     // OFR 4.504b or higher
                     $info_ofr_this_block['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($info_ofr_this_block['channel_config']);
                     $info_ofr_this_block['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 2));
                     $info_ofr_this_block['encoder'] = $this->OptimFROGencoderNameLookup($info_ofr_this_block['raw']['encoder_id']);
                     $offset += 2;
                     $info_ofr_this_block['raw']['compression'] = getid3_lib::LittleEndian2Int($block_data[$offset++]);
                     $info_ofr_this_block['compression'] = $this->OptimFROGcompressionLookup($info_ofr_this_block['raw']['compression']);
                     $info_ofr_this_block['speedup'] = $this->OptimFROGspeedupLookup($info_ofr_this_block['raw']['compression']);
                     $getid3->info['audio']['encoder'] = 'OptimFROG ' . $info_ofr_this_block['encoder'];
                     $getid3->info['audio']['encoder_options'] = '--mode ' . $info_ofr_this_block['compression'];
                     if (($info_ofr_this_block['raw']['encoder_id'] & 0xf0) >> 4 == 7) {
                         // v4.507
                         if (preg_match('/\\.ofs$/i', $getid3->filename)) {
                             // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference
                             // between lossless and lossy other than the file extension.
                             $getid3->info['audio']['dataformat'] = 'ofs';
                             $getid3->info['audio']['lossless'] = true;
                         }
                     }
                 }
                 $getid3->info['audio']['channels'] = $info_ofr_this_block['channels'];
                 $getid3->info['audio']['sample_rate'] = $info_ofr_this_block['sample_rate'];
                 $getid3->info['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($info_ofr_this_block['raw']['sample_type']);
                 break;
             case 'COMP':
                 // unlike other block types, there CAN be multiple COMP blocks
                 $comp_data['offset'] = $block_offset;
                 $comp_data['size'] = $block_size;
                 if ($getid3->info['avdataoffset'] == 0) {
                     $getid3->info['avdataoffset'] = $block_offset;
                 }
                 // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data
                 $block_data .= fread($getid3->fp, 14);
                 fseek($getid3->fp, $block_size - 14, SEEK_CUR);
                 $comp_data['crc_32'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4));
                 $offset += 4;
                 $comp_data['sample_count'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4));
                 $offset += 4;
                 $comp_data['raw']['sample_type'] = getid3_lib::LittleEndian2Int($block_data[$offset++]);
                 $comp_data['sample_type'] = $this->OptimFROGsampleTypeLookup($comp_data['raw']['sample_type']);
                 $comp_data['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int($block_data[$offset++]);
                 $comp_data['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($comp_data['raw']['channel_configuration']);
                 $comp_data['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 2));
                 $offset += 2;
                 if ($getid3->info['ofr']['OFR ']['size'] > 12) {
                     // OFR 4.504b or higher
                     $comp_data['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 2));
                     $comp_data['encoder'] = $this->OptimFROGencoderNameLookup($comp_data['raw']['encoder_id']);
                     $offset += 2;
                 }
                 if ($comp_data['crc_32'] == 0x454e4f4e) {
                     // ASCII value of 'NONE' - placeholder value in v4.50a
                     $comp_data['crc_32'] = false;
                 }
                 $info_ofr_this_block[] = $comp_data;
                 break;
             case 'HEAD':
                 $info_ofr_this_block['offset'] = $block_offset;
                 $info_ofr_this_block['size'] = $block_size;
                 $riff_data .= fread($getid3->fp, $block_size);
                 break;
             case 'TAIL':
                 $info_ofr_this_block['offset'] = $block_offset;
                 $info_ofr_this_block['size'] = $block_size;
                 if ($block_size > 0) {
                     $riff_data .= fread($getid3->fp, $block_size);
                 }
                 break;
             case 'RECV':
                 // block contains no useful meta data - simply note and skip
                 $info_ofr_this_block['offset'] = $block_offset;
                 $info_ofr_this_block['size'] = $block_size;
                 fseek($getid3->fp, $block_size, SEEK_CUR);
                 break;
             case 'APET':
                 // APEtag v2
                 $info_ofr_this_block['offset'] = $block_offset;
                 $info_ofr_this_block['size'] = $block_size;
                 $getid3->warning('APEtag processing inside OptimFROG not supported in this version (' . GETID3_VERSION . ') of getID3()');
                 fseek($getid3->fp, $block_size, SEEK_CUR);
                 break;
             case 'MD5 ':
                 // APEtag v2
                 $info_ofr_this_block['offset'] = $block_offset;
                 $info_ofr_this_block['size'] = $block_size;
                 if ($block_size == 16) {
                     $info_ofr_this_block['md5_binary'] = fread($getid3->fp, $block_size);
                     $info_ofr_this_block['md5_string'] = getid3_lib::PrintHexBytes($info_ofr_this_block['md5_binary'], true, false, false);
                     $getid3->info['md5_data_source'] = $info_ofr_this_block['md5_string'];
                 } else {
                     $getid3->warning('Expecting block size of 16 in "MD5 " chunk, found ' . $block_size . ' instead');
                     fseek($getid3->fp, $block_size, SEEK_CUR);
                 }
                 break;
             default:
                 $info_ofr_this_block['offset'] = $block_offset;
                 $info_ofr_this_block['size'] = $block_size;
                 $getid3->warning('Unhandled OptimFROG block type "' . $block_name . '" at offset ' . $info_ofr_this_block['offset']);
                 fseek($getid3->fp, $block_size, SEEK_CUR);
                 break;
         }
     }
     if (isset($getid3->info['ofr']['TAIL']['offset'])) {
         $getid3->info['avdataend'] = $getid3->info['ofr']['TAIL']['offset'];
     }
     $getid3->info['playtime_seconds'] = (double) $getid3->info['ofr']['OFR ']['total_samples'] / ($getid3->info['audio']['channels'] * $getid3->info['audio']['sample_rate']);
     $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     // move the data chunk after all other chunks (if any)
     // so that the RIFF parser doesn't see EOF when trying
     // to skip over the data chunk
     $riff_data = substr($riff_data, 0, 36) . substr($riff_data, 44) . substr($riff_data, 36, 8);
     // Save audio info key
     $saved_info_audio = $getid3->info['audio'];
     // Instantiate riff module and analyze string
     $riff = new getid3_riff($getid3);
     $riff->AnalyzeString($riff_data);
     // Restore info key
     $getid3->info['audio'] = $saved_info_audio;
     $getid3->info['fileformat'] = 'ofr';
     return true;
 }
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->include_module('audio-video.riff');
     !isset($getid3->info['audio']) and $getid3->info['audio'] = array();
     !isset($getid3->info['video']) and $getid3->info['video'] = array();
     $getid3->info['asf']['comments'] = $getid3->info['asf']['header_object'] = array();
     $info_audio =& $getid3->info['audio'];
     $info_video =& $getid3->info['video'];
     $info_asf =& $getid3->info['asf'];
     $info_asf_comments =& $info_asf['comments'];
     $info_asf_header_object =& $info_asf['header_object'];
     // ASF structure:
     // * Header Object [required]
     //   * File Properties Object [required]   (global file attributes)
     //   * Stream Properties Object [required] (defines media stream & characteristics)
     //   * Header Extension Object [required]  (additional functionality)
     //   * Content Description Object          (bibliographic information)
     //   * Script Command Object               (commands for during playback)
     //   * Marker Object                       (named jumped points within the file)
     // * Data Object [required]
     //   * Data Packets
     // * Index Object
     // Header Object: (mandatory, one only)
     // Field Name                   Field Type   Size (bits)
     // Object ID                    GUID         128             // GUID for header object - getid3_asf::Header_Object
     // Object Size                  QWORD        64              // size of header object, including 30 bytes of Header Object header
     // Number of Header Objects     DWORD        32              // number of objects in header object
     // Reserved1                    BYTE         8               // hardcoded: 0x01
     // Reserved2                    BYTE         8               // hardcoded: 0x02
     $getid3->info['fileformat'] = 'asf';
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $header_object_data = fread($getid3->fp, 30);
     $info_asf_header_object['objectid_guid'] = getid3_asf::BytestringToGUID(substr($header_object_data, 0, 16));
     if ($info_asf_header_object['objectid_guid'] != getid3_asf::Header_Object) {
         throw new getid3_exception('ASF header GUID {' . $info_asf_header_object['objectid_guid'] . '} does not match expected "getid3_asf::Header_Object" GUID {' . getid3_asf::Header_Object . '}');
     }
     getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_header_object, $header_object_data, 16, array('objectsize' => 8, 'headerobjects' => 4, 'reserved1' => 1, 'reserved2' => 1));
     $asf_header_data = fread($getid3->fp, $info_asf_header_object['objectsize'] - 30);
     $offset = 0;
     for ($header_objects_counter = 0; $header_objects_counter < $info_asf_header_object['headerobjects']; $header_objects_counter++) {
         $next_object_guid = substr($asf_header_data, $offset, 16);
         $offset += 16;
         $next_object_size = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 8));
         $offset += 8;
         $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid);
         switch ($next_object_guidtext) {
             case getid3_asf::File_Properties_Object:
                 // File Properties Object: (mandatory, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for file properties object - getid3_asf::File_Properties_Object
                 // Object Size                  QWORD        64              // size of file properties object, including 104 bytes of File Properties Object header
                 // File ID                      GUID         128             // unique ID - identical to File ID in Data Object
                 // File Size                    QWORD        64              // entire file in bytes. Invalid if Broadcast Flag == 1
                 // Creation Date                QWORD        64              // date & time of file creation. Maybe invalid if Broadcast Flag == 1
                 // Data Packets Count           QWORD        64              // number of data packets in Data Object. Invalid if Broadcast Flag == 1
                 // Play Duration                QWORD        64              // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
                 // Send Duration                QWORD        64              // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
                 // Preroll                      QWORD        64              // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount
                 // Flags                        DWORD        32              //
                 // * Broadcast Flag             bits         1  (0x01)       // file is currently being written, some header values are invalid
                 // * Seekable Flag              bits         1  (0x02)       // is file seekable
                 // * Reserved                   bits         30 (0xFFFFFFFC) // reserved - set to zero
                 // Minimum Data Packet Size     DWORD        32              // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
                 // Maximum Data Packet Size     DWORD        32              // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
                 // Maximum Bitrate              DWORD        32              // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
                 $info_asf['file_properties_object'] = array();
                 $info_asf_file_properties_object =& $info_asf['file_properties_object'];
                 $info_asf_file_properties_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_file_properties_object['objectsize'] = $next_object_size;
                 $info_asf_file_properties_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
                 $offset += 16;
                 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_file_properties_object, $asf_header_data, $offset, array('filesize' => 8, 'creation_date' => 8, 'data_packets' => 8, 'play_duration' => 8, 'send_duration' => 8, 'preroll' => 8, 'flags_raw' => 4, 'min_packet_size' => 4, 'max_packet_size' => 4, 'max_bitrate' => 4));
                 $offset += 64;
                 if ($info_asf_file_properties_object['filesize'] > $getid3->info['filesize']) {
                     $getid3->warning('Probable truncated file: file_properties_object.filesize (' . number_format($info_asf_file_properties_object['filesize']) . ') > filesize (' . number_format($getid3->info['filesize']) . ')');
                 }
                 $info_asf_file_properties_object['creation_date_unix'] = getid3_asf::FiletimeToUNIXtime($info_asf_file_properties_object['creation_date']);
                 $info_asf_file_properties_object['flags']['broadcast'] = (bool) ($info_asf_file_properties_object['flags_raw'] & 0x1);
                 $info_asf_file_properties_object['flags']['seekable'] = (bool) ($info_asf_file_properties_object['flags_raw'] & 0x2);
                 $getid3->info['playtime_seconds'] = $info_asf_file_properties_object['play_duration'] / 10000000 - $info_asf_file_properties_object['preroll'] / 1000;
                 $getid3->info['bitrate'] = $info_asf_file_properties_object['filesize'] * 8 / $getid3->info['playtime_seconds'];
                 break;
             case getid3_asf::Stream_Properties_Object:
                 // Stream Properties Object: (mandatory, one per media stream)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for stream properties object - getid3_asf::Stream_Properties_Object
                 // Object Size                  QWORD        64              // size of stream properties object, including 78 bytes of Stream Properties Object header
                 // Stream Type                  GUID         128             // getid3_asf::Audio_Media, getid3_asf::Video_Media or getid3_asf::Command_Media
                 // Error Correction Type        GUID         128             // getid3_asf::Audio_Spread for audio-only streams, getid3_asf::No_Error_Correction for other stream types
                 // Time Offset                  QWORD        64              // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
                 // Type-Specific Data Length    DWORD        32              // number of bytes for Type-Specific Data field
                 // Error Correction Data Length DWORD        32              // number of bytes for Error Correction Data field
                 // Flags                        WORD         16              //
                 // * Stream Number              bits         7 (0x007F)      // number of this stream.  1 <= valid <= 127
                 // * Reserved                   bits         8 (0x7F80)      // reserved - set to zero
                 // * Encrypted Content Flag     bits         1 (0x8000)      // stream contents encrypted if set
                 // Reserved                     DWORD        32              // reserved - set to zero
                 // Type-Specific Data           BYTESTREAM   variable        // type-specific format data, depending on value of Stream Type
                 // Error Correction Data        BYTESTREAM   variable        // error-correction-specific format data, depending on value of Error Correct Type
                 // There is one getid3_asf::Stream_Properties_Object for each stream (audio, video) but the
                 // stream number isn't known until halfway through decoding the structure, hence it
                 // it is decoded to a temporary variable and then stuck in the appropriate index later
                 $stream_properties_object_data['objectid_guid'] = $next_object_guidtext;
                 $stream_properties_object_data['objectsize'] = $next_object_size;
                 getid3_lib::ReadSequence('LittleEndian2Int', $stream_properties_object_data, $asf_header_data, $offset, array('stream_type' => -16, 'error_correct_type' => -16, 'time_offset' => 8, 'type_data_length' => 4, 'error_data_length' => 4, 'flags_raw' => 2));
                 $stream_properties_stream_number = $stream_properties_object_data['flags_raw'] & 0x7f;
                 $stream_properties_object_data['flags']['encrypted'] = (bool) ($stream_properties_object_data['flags_raw'] & 0x8000);
                 $stream_properties_object_data['stream_type_guid'] = getid3_asf::BytestringToGUID($stream_properties_object_data['stream_type']);
                 $stream_properties_object_data['error_correct_guid'] = getid3_asf::BytestringToGUID($stream_properties_object_data['error_correct_type']);
                 $offset += 54;
                 // 50 bytes + 4 bytes reserved - DWORD
                 $stream_properties_object_data['type_specific_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['type_data_length']);
                 $offset += $stream_properties_object_data['type_data_length'];
                 $stream_properties_object_data['error_correct_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['error_data_length']);
                 $offset += $stream_properties_object_data['error_data_length'];
                 switch ($stream_properties_object_data['stream_type_guid']) {
                     case getid3_asf::Audio_Media:
                         $info_audio['dataformat'] = @$info_audio['dataformat'] ? $info_audio['dataformat'] : 'asf';
                         $info_audio['bitrate_mode'] = @$info_audio['bitrate_mode'] ? $info_audio['bitrate_mode'] : 'cbr';
                         $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($stream_properties_object_data['type_specific_data'], 0, 16));
                         unset($audiodata['raw']);
                         $info_audio = getid3_riff::array_merge_noclobber($audiodata, $info_audio);
                         break;
                     case getid3_asf::Video_Media:
                         $info_video['dataformat'] = @$info_video['dataformat'] ? $info_video['dataformat'] : 'asf';
                         $info_video['bitrate_mode'] = @$info_video['bitrate_mode'] ? $info_video['bitrate_mode'] : 'cbr';
                         break;
                         /* does nothing but eat memory
                            case getid3_asf::Command_Media:
                            default:
                                // do nothing
                                break;
                            */
                 }
                 $info_asf['stream_properties_object'][$stream_properties_stream_number] = $stream_properties_object_data;
                 unset($stream_properties_object_data);
                 // clear for next stream, if any
                 break;
             case getid3_asf::Header_Extension_Object:
                 // Header Extension Object: (mandatory, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Header Extension object - getid3_asf::Header_Extension_Object
                 // Object Size                  QWORD        64              // size of Header Extension object, including 46 bytes of Header Extension Object header
                 // Reserved Field 1             GUID         128             // hardcoded: getid3_asf::Reserved_1
                 // Reserved Field 2             WORD         16              // hardcoded: 0x00000006
                 // Header Extension Data Size   DWORD        32              // in bytes. valid: 0, or > 24. equals object size minus 46
                 // Header Extension Data        BYTESTREAM   variable        // array of zero or more extended header objects
                 $info_asf['header_extension_object'] = array();
                 $info_asf_header_extension_object =& $info_asf['header_extension_object'];
                 $info_asf_header_extension_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_header_extension_object['objectsize'] = $next_object_size;
                 $info_asf_header_extension_object['reserved_1_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
                 $offset += 16;
                 if ($info_asf_header_extension_object['reserved_1_guid'] != getid3_asf::Reserved_1) {
                     $getid3->warning('header_extension_object.reserved_1 GUID (' . $info_asf_header_extension_object['reserved_1_guid'] . ') does not match expected "getid3_asf::Reserved_1" GUID (' . getid3_asf::Reserved_1 . ')');
                     break;
                 }
                 $info_asf_header_extension_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 if ($info_asf_header_extension_object['reserved_2'] != 6) {
                     $getid3->warning('header_extension_object.reserved_2 (' . getid3_lib::PrintHexBytes($info_asf_header_extension_object['reserved_2']) . ') does not match expected value of "6"');
                     break;
                 }
                 $info_asf_header_extension_object['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
                 $offset += 4;
                 $info_asf_header_extension_object['extension_data'] = substr($asf_header_data, $offset, $info_asf_header_extension_object['extension_data_size']);
                 $offset += $info_asf_header_extension_object['extension_data_size'];
                 break;
             case getid3_asf::Codec_List_Object:
                 // Codec List Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Codec List object - getid3_asf::Codec_List_Object
                 // Object Size                  QWORD        64              // size of Codec List object, including 44 bytes of Codec List Object header
                 // Reserved                     GUID         128             // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
                 // Codec Entries Count          DWORD        32              // number of entries in Codec Entries array
                 // Codec Entries                array of:    variable        //
                 // * Type                       WORD         16              // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
                 // * Codec Name Length          WORD         16              // number of Unicode characters stored in the Codec Name field
                 // * Codec Name                 WCHAR        variable        // array of Unicode characters - name of codec used to create the content
                 // * Codec Description Length   WORD         16              // number of Unicode characters stored in the Codec Description field
                 // * Codec Description          WCHAR        variable        // array of Unicode characters - description of format used to create the content
                 // * Codec Information Length   WORD         16              // number of Unicode characters stored in the Codec Information field
                 // * Codec Information          BYTESTREAM   variable        // opaque array of information bytes about the codec used to create the content
                 $info_asf['codec_list_object'] = array();
                 $info_asf_codec_list_object =& $info_asf['codec_list_object'];
                 $info_asf_codec_list_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_codec_list_object['objectsize'] = $next_object_size;
                 $info_asf_codec_list_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
                 $offset += 16;
                 if ($info_asf_codec_list_object['reserved_guid'] != '86D15241-311D-11D0-A3A4-00A0C90348F6') {
                     $getid3->warning('codec_list_object.reserved GUID {' . $info_asf_codec_list_object['reserved_guid'] . '} does not match expected "getid3_asf::Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}');
                     break;
                 }
                 $info_asf_codec_list_object['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
                 $offset += 4;
                 for ($codec_entry_counter = 0; $codec_entry_counter < $info_asf_codec_list_object['codec_entries_count']; $codec_entry_counter++) {
                     $info_asf_codec_list_object['codec_entries'][$codec_entry_counter] = array();
                     $info_asf_codec_list_object_codecentries_current =& $info_asf_codec_list_object['codec_entries'][$codec_entry_counter];
                     $info_asf_codec_list_object_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                     $info_asf_codec_list_object_codecentries_current['type'] = getid3_asf::ASFCodecListObjectTypeLookup($info_asf_codec_list_object_codecentries_current['type_raw']);
                     $codec_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $info_asf_codec_list_object_codecentries_current['name'] = substr($asf_header_data, $offset, $codec_name_length);
                     $offset += $codec_name_length;
                     $codec_description_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $info_asf_codec_list_object_codecentries_current['description'] = substr($asf_header_data, $offset, $codec_description_length);
                     $offset += $codec_description_length;
                     $codec_information_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                     $info_asf_codec_list_object_codecentries_current['information'] = substr($asf_header_data, $offset, $codec_information_length);
                     $offset += $codec_information_length;
                     if ($info_asf_codec_list_object_codecentries_current['type_raw'] == 2) {
                         // audio codec
                         if (strpos($info_asf_codec_list_object_codecentries_current['description'], ',') === false) {
                             $getid3->warning('[asf][codec_list_object][codec_entries][' . $codec_entry_counter . '][description] expected to contain comma-seperated list of parameters: "' . $info_asf_codec_list_object_codecentries_current['description'] . '"');
                         } else {
                             list($audio_codec_bitrate, $audio_codec_frequency, $audio_codec_channels) = explode(',', $this->TrimConvert($info_asf_codec_list_object_codecentries_current['description']));
                             $info_audio['codec'] = $this->TrimConvert($info_asf_codec_list_object_codecentries_current['name']);
                             if (!isset($info_audio['bitrate']) && strstr($audio_codec_bitrate, 'kbps')) {
                                 $info_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $audio_codec_bitrate)) * 1000);
                             }
                             if (!isset($info_video['bitrate']) && isset($info_audio['bitrate']) && isset($info_asf['file_properties_object']['max_bitrate']) && $info_asf_codec_list_object['codec_entries_count'] > 1) {
                                 $info_video['bitrate'] = $info_asf['file_properties_object']['max_bitrate'] - $info_audio['bitrate'];
                             }
                             if (!@$info_video['bitrate'] && @$info_audio['bitrate'] && @$getid3->info['bitrate']) {
                                 $info_video['bitrate'] = $getid3->info['bitrate'] - $info_audio['bitrate'];
                             }
                             $audio_codec_frequency = (int) trim(str_replace('kHz', '', $audio_codec_frequency));
                             static $sample_rate_lookup = array(8 => 8000, 8000 => 8000, 11 => 11025, 11025 => 11025, 12 => 12000, 12000 => 12000, 16 => 16000, 16000 => 16000, 22 => 22050, 22050 => 22050, 24 => 24000, 24000 => 24000, 32 => 32000, 32000 => 32000, 44 => 44100, 44100 => 44100, 48 => 48000, 48000 => 48000);
                             $info_audio['sample_rate'] = @$sample_rate_lookup[$audio_codec_frequency];
                             if (!$info_audio['sample_rate']) {
                                 $getid3->warning('unknown frequency: "' . $audio_codec_frequency . '" (' . $this->TrimConvert($info_asf_codec_list_object_codecentries_current['description']) . ')');
                                 break;
                             }
                             if (!isset($info_audio['channels'])) {
                                 if (strstr($audio_codec_channels, 'stereo')) {
                                     $info_audio['channels'] = 2;
                                 } elseif (strstr($audio_codec_channels, 'mono')) {
                                     $info_audio['channels'] = 1;
                                 }
                             }
                         }
                     }
                 }
                 break;
             case getid3_asf::Script_Command_Object:
                 // Script Command Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Script Command object - getid3_asf::Script_Command_Object
                 // Object Size                  QWORD        64              // size of Script Command object, including 44 bytes of Script Command Object header
                 // Reserved                     GUID         128             // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
                 // Commands Count               WORD         16              // number of Commands structures in the Script Commands Objects
                 // Command Types Count          WORD         16              // number of Command Types structures in the Script Commands Objects
                 // Command Types                array of:    variable        //
                 // * Command Type Name Length   WORD         16              // number of Unicode characters for Command Type Name
                 // * Command Type Name          WCHAR        variable        // array of Unicode characters - name of a type of command
                 // Commands                     array of:    variable        //
                 // * Presentation Time          DWORD        32              // presentation time of that command, in milliseconds
                 // * Type Index                 WORD         16              // type of this command, as a zero-based index into the array of Command Types of this object
                 // * Command Name Length        WORD         16              // number of Unicode characters for Command Name
                 // * Command Name               WCHAR        variable        // array of Unicode characters - name of this command
                 // shortcut
                 $info_asf['script_command_object'] = array();
                 $info_asf_script_command_object =& $info_asf['script_command_object'];
                 $info_asf_script_command_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_script_command_object['objectsize'] = $next_object_size;
                 $info_asf_script_command_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
                 $offset += 16;
                 if ($info_asf_script_command_object['reserved_guid'] != '4B1ACBE3-100B-11D0-A39B-00A0C90348F6') {
                     $getid3->warning('script_command_object.reserved GUID {' . $info_asf_script_command_object['reserved_guid'] . '} does not match expected GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}');
                     break;
                 }
                 $info_asf_script_command_object['commands_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 $info_asf_script_command_object['command_types_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 for ($command_types_counter = 0; $command_types_counter < $info_asf_script_command_object['command_types_count']; $command_types_counter++) {
                     $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $info_asf_script_command_object['command_types'][$command_types_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length);
                     $offset += $command_type_name_length;
                 }
                 for ($commands_counter = 0; $commands_counter < $info_asf_script_command_object['commands_count']; $commands_counter++) {
                     $info_asf_script_command_object['commands'][$commands_counter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
                     $offset += 4;
                     $info_asf_script_command_object['commands'][$commands_counter]['type_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                     $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $info_asf_script_command_object['commands'][$commands_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length);
                     $offset += $command_type_name_length;
                 }
                 break;
             case getid3_asf::Marker_Object:
                 // Marker Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Marker object - getid3_asf::Marker_Object
                 // Object Size                  QWORD        64              // size of Marker object, including 48 bytes of Marker Object header
                 // Reserved                     GUID         128             // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
                 // Markers Count                DWORD        32              // number of Marker structures in Marker Object
                 // Reserved                     WORD         16              // hardcoded: 0x0000
                 // Name Length                  WORD         16              // number of bytes in the Name field
                 // Name                         WCHAR        variable        // name of the Marker Object
                 // Markers                      array of:    variable        //
                 // * Offset                     QWORD        64              // byte offset into Data Object
                 // * Presentation Time          QWORD        64              // in 100-nanosecond units
                 // * Entry Length               WORD         16              // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
                 // * Send Time                  DWORD        32              // in milliseconds
                 // * Flags                      DWORD        32              // hardcoded: 0x00000000
                 // * Marker Description Length  DWORD        32              // number of bytes in Marker Description field
                 // * Marker Description         WCHAR        variable        // array of Unicode characters - description of marker entry
                 // * Padding                    BYTESTREAM   variable        // optional padding bytes
                 $info_asf['marker_object'] = array();
                 $info_asf_marker_object =& $info_asf['marker_object'];
                 $info_asf_marker_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_marker_object['objectsize'] = $next_object_size;
                 $info_asf_marker_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
                 $offset += 16;
                 if ($info_asf_marker_object['reserved_guid'] != '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB') {
                     $getid3->warning('marker_object.reserved GUID {' . $info_asf_marker_object['reserved_guid'] . '} does not match expected GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}');
                     break;
                 }
                 $info_asf_marker_object['markers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
                 $offset += 4;
                 $info_asf_marker_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 if ($info_asf_marker_object['reserved_2'] != 0) {
                     $getid3->warning('marker_object.reserved_2 (' . getid3_lib::PrintHexBytes($info_asf_marker_object['reserved_2']) . ') does not match expected value of "0"');
                     break;
                 }
                 $info_asf_marker_object['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 $info_asf_marker_object['name'] = substr($asf_header_data, $offset, $info_asf_marker_object['name_length']);
                 $offset += $info_asf_marker_object['name_length'];
                 for ($markers_counter = 0; $markers_counter < $info_asf_marker_object['markers_count']; $markers_counter++) {
                     getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_marker_object['markers'][$markers_counter], $asf_header_data, $offset, array('offset' => 8, 'presentation_time' => 8, 'entry_length' => 2, 'send_time' => 4, 'flags' => 4, 'marker_description_length' => 4));
                     $offset += 30;
                     $info_asf_marker_object['markers'][$markers_counter]['marker_description'] = substr($asf_header_data, $offset, $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']);
                     $offset += $info_asf_marker_object['markers'][$markers_counter]['marker_description_length'];
                     $padding_length = $info_asf_marker_object['markers'][$markers_counter]['entry_length'] - 4 - 4 - 4 - $info_asf_marker_object['markers'][$markers_counter]['marker_description_length'];
                     if ($padding_length > 0) {
                         $info_asf_marker_object['markers'][$markers_counter]['padding'] = substr($asf_header_data, $offset, $padding_length);
                         $offset += $padding_length;
                     }
                 }
                 break;
             case getid3_asf::Bitrate_Mutual_Exclusion_Object:
                 // Bitrate Mutual Exclusion Object: (optional)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Bitrate Mutual Exclusion object - getid3_asf::Bitrate_Mutual_Exclusion_Object
                 // Object Size                  QWORD        64              // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
                 // Exlusion Type                GUID         128             // nature of mutual exclusion relationship. one of: (getid3_asf::Mutex_Bitrate, getid3_asf::Mutex_Unknown)
                 // Stream Numbers Count         WORD         16              // number of video streams
                 // Stream Numbers               WORD         variable        // array of mutually exclusive video stream numbers. 1 <= valid <= 127
                 // shortcut
                 $info_asf['bitrate_mutual_exclusion_object'] = array();
                 $info_asf_bitrate_mutual_exclusion_object =& $info_asf['bitrate_mutual_exclusion_object'];
                 $info_asf_bitrate_mutual_exclusion_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_bitrate_mutual_exclusion_object['objectsize'] = $next_object_size;
                 $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
                 $offset += 16;
                 if ($info_asf_bitrate_mutual_exclusion_object['reserved_guid'] != getid3_asf::Mutex_Bitrate && $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] != getid3_asf::Mutex_Unknown) {
                     $getid3->warning('bitrate_mutual_exclusion_object.reserved GUID {' . $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] . '} does not match expected "getid3_asf::Mutex_Bitrate" GUID {' . getid3_asf::Mutex_Bitrate . '} or  "getid3_asf::Mutex_Unknown" GUID {' . getid3_asf::Mutex_Unknown . '}');
                     break;
                 }
                 $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 for ($stream_number_counter = 0; $stream_number_counter < $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count']; $stream_number_counter++) {
                     $info_asf_bitrate_mutual_exclusion_object['stream_numbers'][$stream_number_counter] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                 }
                 break;
             case getid3_asf::Error_Correction_Object:
                 // Error Correction Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Error Correction object - getid3_asf::Error_Correction_Object
                 // Object Size                  QWORD        64              // size of Error Correction object, including 44 bytes of Error Correction Object header
                 // Error Correction Type        GUID         128             // type of error correction. one of: (getid3_asf::No_Error_Correction, getid3_asf::Audio_Spread)
                 // Error Correction Data Length DWORD        32              // number of bytes in Error Correction Data field
                 // Error Correction Data        BYTESTREAM   variable        // structure depends on value of Error Correction Type field
                 $info_asf['error_correction_object'] = array();
                 $info_asf_error_correction_object =& $info_asf['error_correction_object'];
                 $info_asf_error_correction_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_error_correction_object['objectsize'] = $next_object_size;
                 $info_asf_error_correction_object['error_correction_type'] = substr($asf_header_data, $offset, 16);
                 $offset += 16;
                 $info_asf_error_correction_object['error_correction_guid'] = getid3_asf::BytestringToGUID($info_asf_error_correction_object['error_correction_type']);
                 $info_asf_error_correction_object['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
                 $offset += 4;
                 switch ($info_asf_error_correction_object['error_correction_type_guid']) {
                     case getid3_asf::No_Error_Correction:
                         // should be no data, but just in case there is, skip to the end of the field
                         $offset += $info_asf_error_correction_object['error_correction_data_length'];
                         break;
                     case getid3_asf::Audio_Spread:
                         // Field Name                   Field Type   Size (bits)
                         // Span                         BYTE         8               // number of packets over which audio will be spread.
                         // Virtual Packet Length        WORD         16              // size of largest audio payload found in audio stream
                         // Virtual Chunk Length         WORD         16              // size of largest audio payload found in audio stream
                         // Silence Data Length          WORD         16              // number of bytes in Silence Data field
                         // Silence Data                 BYTESTREAM   variable        // hardcoded: 0x00 * (Silence Data Length) bytes
                         getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_error_correction_object, $asf_header_data, $offset, array('span' => 1, 'virtual_packet_length' => 2, 'virtual_chunk_length' => 2, 'silence_data_length' => 2));
                         $offset += 7;
                         $info_asf_error_correction_object['silence_data'] = substr($asf_header_data, $offset, $info_asf_error_correction_object['silence_data_length']);
                         $offset += $info_asf_error_correction_object['silence_data_length'];
                         break;
                     default:
                         $getid3->warning('error_correction_object.error_correction_type GUID {' . $info_asf_error_correction_object['reserved_guid'] . '} does not match expected "getid3_asf::No_Error_Correction" GUID {' . getid3_asf::No_Error_Correction . '} or  "getid3_asf::Audio_Spread" GUID {' . getid3_asf::Audio_Spread . '}');
                         break;
                 }
                 break;
             case getid3_asf::Content_Description_Object:
                 // Content Description Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Content Description object - getid3_asf::Content_Description_Object
                 // Object Size                  QWORD        64              // size of Content Description object, including 34 bytes of Content Description Object header
                 // Title Length                 WORD         16              // number of bytes in Title field
                 // Author Length                WORD         16              // number of bytes in Author field
                 // Copyright Length             WORD         16              // number of bytes in Copyright field
                 // Description Length           WORD         16              // number of bytes in Description field
                 // Rating Length                WORD         16              // number of bytes in Rating field
                 // Title                        WCHAR        16              // array of Unicode characters - Title
                 // Author                       WCHAR        16              // array of Unicode characters - Author
                 // Copyright                    WCHAR        16              // array of Unicode characters - Copyright
                 // Description                  WCHAR        16              // array of Unicode characters - Description
                 // Rating                       WCHAR        16              // array of Unicode characters - Rating
                 $info_asf['content_description_object'] = array();
                 $info_asf_content_description_object =& $info_asf['content_description_object'];
                 $info_asf_content_description_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_content_description_object['objectsize'] = $next_object_size;
                 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_content_description_object, $asf_header_data, $offset, array('title_length' => 2, 'author_length' => 2, 'copyright_length' => 2, 'description_length' => 2, 'rating_length' => 2));
                 $offset += 10;
                 $info_asf_content_description_object['title'] = substr($asf_header_data, $offset, $info_asf_content_description_object['title_length']);
                 $offset += $info_asf_content_description_object['title_length'];
                 $info_asf_content_description_object['author'] = substr($asf_header_data, $offset, $info_asf_content_description_object['author_length']);
                 $offset += $info_asf_content_description_object['author_length'];
                 $info_asf_content_description_object['copyright'] = substr($asf_header_data, $offset, $info_asf_content_description_object['copyright_length']);
                 $offset += $info_asf_content_description_object['copyright_length'];
                 $info_asf_content_description_object['description'] = substr($asf_header_data, $offset, $info_asf_content_description_object['description_length']);
                 $offset += $info_asf_content_description_object['description_length'];
                 $info_asf_content_description_object['rating'] = substr($asf_header_data, $offset, $info_asf_content_description_object['rating_length']);
                 $offset += $info_asf_content_description_object['rating_length'];
                 foreach (array('title' => 'title', 'author' => 'artist', 'copyright' => 'copyright', 'description' => 'comment', 'rating' => 'rating') as $key_to_copy_from => $key_to_copy_to) {
                     if (!empty($info_asf_content_description_object[$key_to_copy_from])) {
                         $info_asf_comments[$key_to_copy_to][] = getid3_asf::TrimTerm($info_asf_content_description_object[$key_to_copy_from]);
                     }
                 }
                 break;
             case getid3_asf::Extended_Content_Description_Object:
                 // Extended Content Description Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Extended Content Description object - getid3_asf::Extended_Content_Description_Object
                 // Object Size                  QWORD        64              // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
                 // Content Descriptors Count    WORD         16              // number of entries in Content Descriptors list
                 // Content Descriptors          array of:    variable        //
                 // * Descriptor Name Length     WORD         16              // size in bytes of Descriptor Name field
                 // * Descriptor Name            WCHAR        variable        // array of Unicode characters - Descriptor Name
                 // * Descriptor Value Data Type WORD         16              // Lookup array:
                 // 0x0000 = Unicode String (variable length)
                 // 0x0001 = BYTE array     (variable length)
                 // 0x0002 = BOOL           (DWORD, 32 bits)
                 // 0x0003 = DWORD          (DWORD, 32 bits)
                 // 0x0004 = QWORD          (QWORD, 64 bits)
                 // 0x0005 = WORD           (WORD,  16 bits)
                 // * Descriptor Value Length    WORD         16              // number of bytes stored in Descriptor Value field
                 // * Descriptor Value           variable     variable        // value for Content Descriptor
                 $info_asf['extended_content_description_object'] = array();
                 $info_asf_extended_content_description_object =& $info_asf['extended_content_description_object'];
                 $info_asf_extended_content_description_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_extended_content_description_object['objectsize'] = $next_object_size;
                 $info_asf_extended_content_description_object['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 for ($extended_content_descriptors_counter = 0; $extended_content_descriptors_counter < $info_asf_extended_content_description_object['content_descriptors_count']; $extended_content_descriptors_counter++) {
                     $info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter] = array();
                     $info_asf_extended_content_description_object_content_descriptor_current =& $info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter];
                     $info_asf_extended_content_description_object_content_descriptor_current['base_offset'] = $offset + 30;
                     $info_asf_extended_content_description_object_content_descriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                     $info_asf_extended_content_description_object_content_descriptor_current['name'] = substr($asf_header_data, $offset, $info_asf_extended_content_description_object_content_descriptor_current['name_length']);
                     $offset += $info_asf_extended_content_description_object_content_descriptor_current['name_length'];
                     $info_asf_extended_content_description_object_content_descriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                     $info_asf_extended_content_description_object_content_descriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                     $info_asf_extended_content_description_object_content_descriptor_current['value'] = substr($asf_header_data, $offset, $info_asf_extended_content_description_object_content_descriptor_current['value_length']);
                     $offset += $info_asf_extended_content_description_object_content_descriptor_current['value_length'];
                     switch ($info_asf_extended_content_description_object_content_descriptor_current['value_type']) {
                         case 0x0:
                             // Unicode string
                             break;
                         case 0x1:
                             // BYTE array
                             // do nothing
                             break;
                         case 0x2:
                             // BOOL
                             $info_asf_extended_content_description_object_content_descriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value']);
                             break;
                         case 0x3:
                             // DWORD
                         // DWORD
                         case 0x4:
                             // QWORD
                         // QWORD
                         case 0x5:
                             // WORD
                             $info_asf_extended_content_description_object_content_descriptor_current['value'] = getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value']);
                             break;
                         default:
                             $getid3->warning('extended_content_description.content_descriptors.' . $extended_content_descriptors_counter . '.value_type is invalid (' . $info_asf_extended_content_description_object_content_descriptor_current['value_type'] . ')');
                             break;
                     }
                     switch ($this->TrimConvert(strtolower($info_asf_extended_content_description_object_content_descriptor_current['name']))) {
                         case 'wm/albumartist':
                         case 'artist':
                             $info_asf_comments['albumartist'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
                             break;
                         case 'wm/albumtitle':
                         case 'album':
                             $info_asf_comments['album'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
                             break;
                         case 'wm/genre':
                         case 'genre':
                             $genre = getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']);
                             $info_asf_comments['genre'] = array($genre);
                             break;
                         case 'wm/tracknumber':
                         case 'tracknumber':
                             // be careful casting to int: casting unicode strings to int gives unexpected results (stops parsing at first non-numeric character)
                             $info_asf_comments['track'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
                             foreach ($info_asf_comments['track'] as $key => $value) {
                                 if (preg_match('/^[0-9\\x00]+$/', $value)) {
                                     $info_asf_comments['track'][$key] = intval(str_replace("", '', $value));
                                 }
                             }
                             break;
                         case 'wm/partofset':
                             $info_asf_comments['partofset'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
                             break;
                         case 'wm/track':
                             if (empty($info_asf_comments['track'])) {
                                 $info_asf_comments['track'] = array(1 + $this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['value']));
                             }
                             break;
                         case 'wm/year':
                         case 'year':
                         case 'date':
                             $info_asf_comments['year'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
                             break;
                         case 'wm/lyrics':
                         case 'lyrics':
                             $info_asf_comments['lyrics'] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
                             break;
                         case 'isvbr':
                             if ($info_asf_extended_content_description_object_content_descriptor_current['value']) {
                                 $info_audio['bitrate_mode'] = 'vbr';
                                 $info_video['bitrate_mode'] = 'vbr';
                             }
                             break;
                         case 'id3':
                             // id3v2 parsing might not be enabled
                             if (class_exists('getid3_id3v2')) {
                                 // Clone getid3
                                 $clone = clone $getid3;
                                 // Analyse clone by string
                                 $id3v2 = new getid3_id3v2($clone);
                                 $id3v2->AnalyzeString($info_asf_extended_content_description_object_content_descriptor_current['value']);
                                 // Import from clone and destroy
                                 $getid3->info['id3v2'] = $clone->info['id3v2'];
                                 $getid3->warnings($clone->warnings());
                                 unset($clone);
                             }
                             break;
                         case 'wm/encodingtime':
                             $info_asf_extended_content_description_object_content_descriptor_current['encoding_time_unix'] = getid3_asf::FiletimeToUNIXtime($info_asf_extended_content_description_object_content_descriptor_current['value']);
                             $info_asf_comments['encoding_time_unix'] = array($info_asf_extended_content_description_object_content_descriptor_current['encoding_time_unix']);
                             break;
                         case 'wm/picture':
                             //typedef struct _WMPicture{
                             //  LPWSTR  pwszMIMEType;
                             //  BYTE  bPictureType;
                             //  LPWSTR  pwszDescription;
                             //  DWORD  dwDataLen;
                             //  BYTE*  pbData;
                             //} WM_PICTURE;
                             $info_asf_extended_content_description_object_content_descriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value'][0]);
                             $info_asf_extended_content_description_object_content_descriptor_current['image_type'] = getid3_asf::WMpictureTypeLookup($info_asf_extended_content_description_object_content_descriptor_current['image_type_id']);
                             $info_asf_extended_content_description_object_content_descriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($info_asf_extended_content_description_object_content_descriptor_current['value'], 1, 4));
                             $info_asf_extended_content_description_object_content_descriptor_current['image_mime'] = '';
                             $wm_picture_offset = 5;
                             do {
                                 $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2);
                                 $wm_picture_offset += 2;
                                 $info_asf_extended_content_description_object_content_descriptor_current['image_mime'] .= $next_byte_pair;
                             } while ($next_byte_pair !== "");
                             $info_asf_extended_content_description_object_content_descriptor_current['image_description'] = '';
                             do {
                                 $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2);
                                 $wm_picture_offset += 2;
                                 $info_asf_extended_content_description_object_content_descriptor_current['image_description'] .= $next_byte_pair;
                             } while ($next_byte_pair !== "");
                             $info_asf_extended_content_description_object_content_descriptor_current['dataoffset'] = $wm_picture_offset;
                             $info_asf_extended_content_description_object_content_descriptor_current['data'] = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset);
                             unset($info_asf_extended_content_description_object_content_descriptor_current['value']);
                             $info_asf_comments['picture'] = $info_asf_extended_content_description_object_content_descriptor_current['data'];
                             break;
                         default:
                             switch ($info_asf_extended_content_description_object_content_descriptor_current['value_type']) {
                                 case 0:
                                     // Unicode string
                                     if (substr($this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['name']), 0, 3) == 'WM/') {
                                         $info_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['name'])))] = array(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
                                     }
                                     break;
                                 case 1:
                                     break;
                             }
                             break;
                     }
                 }
                 break;
             case getid3_asf::Stream_Bitrate_Properties_Object:
                 // Stream Bitrate Properties Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Stream Bitrate Properties object - getid3_asf::Stream_Bitrate_Properties_Object
                 // Object Size                  QWORD        64              // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
                 // Bitrate Records Count        WORD         16              // number of records in Bitrate Records
                 // Bitrate Records              array of:    variable        //
                 // * Flags                      WORD         16              //
                 // * * Stream Number            bits         7  (0x007F)     // number of this stream
                 // * * Reserved                 bits         9  (0xFF80)     // hardcoded: 0
                 // * Average Bitrate            DWORD        32              // in bits per second
                 // shortcut
                 $info_asf['stream_bitrate_properties_object'] = array();
                 $info_asf_stream_bitrate_properties_object =& $info_asf['stream_bitrate_properties_object'];
                 $info_asf_stream_bitrate_properties_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_stream_bitrate_properties_object['objectsize'] = $next_object_size;
                 $info_asf_stream_bitrate_properties_object['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                 $offset += 2;
                 for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties_object['bitrate_records_count']; $bitrate_records_counter++) {
                     $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
                     $offset += 2;
                     $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags']['stream_number'] = $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags_raw'] & 0x7f;
                     $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
                     $offset += 4;
                 }
                 break;
             case getid3_asf::Padding_Object:
                 // Padding Object: (optional)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Padding object - getid3_asf::Padding_Object
                 // Object Size                  QWORD        64              // size of Padding object, including 24 bytes of ASF Padding Object header
                 // Padding Data                 BYTESTREAM   variable        // ignore
                 // shortcut
                 $info_asf['padding_object'] = array();
                 $info_asf_paddingobject =& $info_asf['padding_object'];
                 $info_asf_paddingobject['objectid_guid'] = $next_object_guidtext;
                 $info_asf_paddingobject['objectsize'] = $next_object_size;
                 $info_asf_paddingobject['padding_length'] = $info_asf_paddingobject['objectsize'] - 16 - 8;
                 $info_asf_paddingobject['padding'] = substr($asf_header_data, $offset, $info_asf_paddingobject['padding_length']);
                 $offset += $next_object_size - 16 - 8;
                 break;
             case getid3_asf::Extended_Content_Encryption_Object:
             case getid3_asf::Content_Encryption_Object:
                 // WMA DRM - just ignore
                 $offset += $next_object_size - 16 - 8;
                 break;
             default:
                 // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
                 if (getid3_asf::GUIDname($next_object_guidtext)) {
                     $getid3->warning('unhandled GUID "' . getid3_asf::GUIDname($next_object_guidtext) . '" {' . $next_object_guidtext . '} in ASF header at offset ' . ($offset - 16 - 8));
                 } else {
                     $getid3->warning('unknown GUID {' . $next_object_guidtext . '} in ASF header at offset ' . ($offset - 16 - 8));
                 }
                 $offset += $next_object_size - 16 - 8;
                 break;
         }
     }
     if (isset($info_asf_stream_bitrate_properties['bitrate_records_count'])) {
         $asf_bitrate_audio = 0;
         $asf_bitrate_video = 0;
         for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties['bitrate_records_count']; $bitrate_records_counter++) {
             if (isset($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter])) {
                 switch ($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter]['type_raw']) {
                     case 1:
                         $asf_bitrate_video += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate'];
                         break;
                     case 2:
                         $asf_bitrate_audio += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate'];
                         break;
                 }
             }
         }
         if ($asf_bitrate_audio > 0) {
             $info_audio['bitrate'] = $asf_bitrate_audio;
         }
         if ($asf_bitrate_video > 0) {
             $info_video['bitrate'] = $asf_bitrate_video;
         }
     }
     if (isset($info_asf['stream_properties_object']) && is_array($info_asf['stream_properties_object'])) {
         $info_audio['bitrate'] = 0;
         $info_video['bitrate'] = 0;
         foreach ($info_asf['stream_properties_object'] as $stream_number => $stream_data) {
             switch ($stream_data['stream_type_guid']) {
                 case getid3_asf::Audio_Media:
                     // Field Name                   Field Type   Size (bits)
                     // Codec ID / Format Tag        WORD         16              // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
                     // Number of Channels           WORD         16              // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
                     // Samples Per Second           DWORD        32              // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
                     // Average number of Bytes/sec  DWORD        32              // bytes/sec of audio stream  - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
                     // Block Alignment              WORD         16              // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
                     // Bits per sample              WORD         16              // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure
                     // Codec Specific Data Size     WORD         16              // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
                     // Codec Specific Data          BYTESTREAM   variable        // array of codec-specific data bytes
                     // shortcut
                     $info_asf['audio_media'][$stream_number] = array();
                     $info_asf_audio_media_current_stream =& $info_asf['audio_media'][$stream_number];
                     $audio_media_offset = 0;
                     $info_asf_audio_media_current_stream = getid3_riff::RIFFparseWAVEFORMATex(substr($stream_data['type_specific_data'], $audio_media_offset, 16));
                     $audio_media_offset += 16;
                     $info_audio['lossless'] = false;
                     switch ($info_asf_audio_media_current_stream['raw']['wFormatTag']) {
                         case 0x1:
                             // PCM
                         // PCM
                         case 0x163:
                             // WMA9 Lossless
                             $info_audio['lossless'] = true;
                             break;
                     }
                     if (!empty($info_asf['stream_bitrate_properties_object']['bitrate_records'])) {
                         foreach ($info_asf['stream_bitrate_properties_object']['bitrate_records'] as $data_array) {
                             if (@$data_array['flags']['stream_number'] == $stream_number) {
                                 $info_asf_audio_media_current_stream['bitrate'] = $data_array['bitrate'];
                                 $info_audio['bitrate'] += $data_array['bitrate'];
                                 break;
                             }
                         }
                     } else {
                         if (@$info_asf_audio_media_current_stream['bytes_sec']) {
                             $info_audio['bitrate'] += $info_asf_audio_media_current_stream['bytes_sec'] * 8;
                         } elseif (@$info_asf_audio_media_current_stream['bitrate']) {
                             $info_audio['bitrate'] += $info_asf_audio_media_current_stream['bitrate'];
                         }
                     }
                     $info_audio['streams'][$stream_number] = $info_asf_audio_media_current_stream;
                     $info_audio['streams'][$stream_number]['wformattag'] = $info_asf_audio_media_current_stream['raw']['wFormatTag'];
                     $info_audio['streams'][$stream_number]['lossless'] = $info_audio['lossless'];
                     $info_audio['streams'][$stream_number]['bitrate'] = $info_audio['bitrate'];
                     unset($info_audio['streams'][$stream_number]['raw']);
                     $info_asf_audio_media_current_stream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($stream_data['type_specific_data'], $audio_media_offset, 2));
                     $audio_media_offset += 2;
                     $info_asf_audio_media_current_stream['codec_data'] = substr($stream_data['type_specific_data'], $audio_media_offset, $info_asf_audio_media_current_stream['codec_data_size']);
                     $audio_media_offset += $info_asf_audio_media_current_stream['codec_data_size'];
                     break;
                 case getid3_asf::Video_Media:
                     // Field Name                   Field Type   Size (bits)
                     // Encoded Image Width          DWORD        32              // width of image in pixels
                     // Encoded Image Height         DWORD        32              // height of image in pixels
                     // Reserved Flags               BYTE         8               // hardcoded: 0x02
                     // Format Data Size             WORD         16              // size of Format Data field in bytes
                     // Format Data                  array of:    variable        //
                     // * Format Data Size           DWORD        32              // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
                     // * Image Width                LONG         32              // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
                     // * Image Height               LONG         32              // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
                     // * Reserved                   WORD         16              // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
                     // * Bits Per Pixel Count       WORD         16              // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
                     // * Compression ID             FOURCC       32              // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
                     // * Image Size                 DWORD        32              // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
                     // * Horizontal Pixels / Meter  DWORD        32              // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
                     // * Vertical Pixels / Meter    DWORD        32              // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
                     // * Colors Used Count          DWORD        32              // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
                     // * Important Colors Count     DWORD        32              // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure
                     // * Codec Specific Data        BYTESTREAM   variable        // array of codec-specific data bytes
                     $info_asf['video_media'][$stream_number] = array();
                     $info_asf_video_media_current_stream =& $info_asf['video_media'][$stream_number];
                     getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream, $stream_data['type_specific_data'], 0, array('image_width' => 4, 'image_height' => 4, 'flags' => 1, 'format_data_size' => 2));
                     getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream['format_data'], $stream_data['type_specific_data'], 11, array('format_data_size' => 4, 'image_width' => 4, 'image_height' => 4, 'reserved' => 2, 'bits_per_pixel' => 2, 'codec_fourcc' => -4, 'image_size' => 4, 'horizontal_pels' => 4, 'vertical_pels' => 4, 'colors_used' => 4, 'colors_important' => 4));
                     $info_asf_video_media_current_stream['format_data']['codec_data'] = substr($stream_data['type_specific_data'], 51);
                     if (!empty($info_asf['stream_bitrate_properties_object']['bitrate_records'])) {
                         foreach ($info_asf['stream_bitrate_properties_object']['bitrate_records'] as $data_array) {
                             if (@$data_array['flags']['stream_number'] == $stream_number) {
                                 $info_asf_video_media_current_stream['bitrate'] = $data_array['bitrate'];
                                 $info_video['streams'][$stream_number]['bitrate'] = $data_array['bitrate'];
                                 $info_video['bitrate'] += $data_array['bitrate'];
                                 break;
                             }
                         }
                     }
                     $info_asf_video_media_current_stream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($info_asf_video_media_current_stream['format_data']['codec_fourcc']);
                     $info_video['streams'][$stream_number]['fourcc'] = $info_asf_video_media_current_stream['format_data']['codec_fourcc'];
                     $info_video['streams'][$stream_number]['codec'] = $info_asf_video_media_current_stream['format_data']['codec'];
                     $info_video['streams'][$stream_number]['resolution_x'] = $info_asf_video_media_current_stream['image_width'];
                     $info_video['streams'][$stream_number]['resolution_y'] = $info_asf_video_media_current_stream['image_height'];
                     $info_video['streams'][$stream_number]['bits_per_sample'] = $info_asf_video_media_current_stream['format_data']['bits_per_pixel'];
                     break;
                 default:
                     break;
             }
         }
     }
     while (ftell($getid3->fp) < $getid3->info['avdataend']) {
         $next_object_data_header = fread($getid3->fp, 24);
         $offset = 0;
         $next_object_guid = substr($next_object_data_header, 0, 16);
         $offset += 16;
         $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid);
         $next_object_size = getid3_lib::LittleEndian2Int(substr($next_object_data_header, $offset, 8));
         $offset += 8;
         switch ($next_object_guidtext) {
             case getid3_asf::Data_Object:
                 // Data Object: (mandatory, one only)
                 // Field Name                       Field Type   Size (bits)
                 // Object ID                        GUID         128             // GUID for Data object - getid3_asf::Data_Object
                 // Object Size                      QWORD        64              // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
                 // File ID                          GUID         128             // unique identifier. identical to File ID field in Header Object
                 // Total Data Packets               QWORD        64              // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
                 // Reserved                         WORD         16              // hardcoded: 0x0101
                 // shortcut
                 $info_asf['data_object'] = array();
                 $info_asf_data_object =& $info_asf['data_object'];
                 $data_object_data = $next_object_data_header . fread($getid3->fp, 50 - 24);
                 $offset = 24;
                 $info_asf_data_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_data_object['objectsize'] = $next_object_size;
                 $info_asf_data_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($data_object_data, $offset, 16));
                 $offset += 16;
                 $info_asf_data_object['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 8));
                 $offset += 8;
                 $info_asf_data_object['reserved'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 2));
                 $offset += 2;
                 if ($info_asf_data_object['reserved'] != 0x101) {
                     $getid3->warning('data_object.reserved (' . getid3_lib::PrintHexBytes($info_asf_data_object['reserved']) . ') does not match expected value of "0x0101"');
                     break;
                 }
                 // Data Packets                     array of:    variable        //
                 // * Error Correction Flags         BYTE         8               //
                 // * * Error Correction Data Length bits         4               // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
                 // * * Opaque Data Present          bits         1               //
                 // * * Error Correction Length Type bits         2               // number of bits for size of the error correction data. hardcoded: 00
                 // * * Error Correction Present     bits         1               // If set, use Opaque Data Packet structure, else use Payload structure
                 // * Error Correction Data
                 $getid3->info['avdataoffset'] = ftell($getid3->fp);
                 fseek($getid3->fp, $info_asf_data_object['objectsize'] - 50, SEEK_CUR);
                 // skip actual audio/video data
                 $getid3->info['avdataend'] = ftell($getid3->fp);
                 break;
             case getid3_asf::Simple_Index_Object:
                 // Simple Index Object: (optional, recommended, one per video stream)
                 // Field Name                       Field Type   Size (bits)
                 // Object ID                        GUID         128             // GUID for Simple Index object - getid3_asf::Data_Object
                 // Object Size                      QWORD        64              // size of Simple Index object, including 56 bytes of Simple Index Object header
                 // File ID                          GUID         128             // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
                 // Index Entry Time Interval        QWORD        64              // interval between index entries in 100-nanosecond units
                 // Maximum Packet Count             DWORD        32              // maximum packet count for all index entries
                 // Index Entries Count              DWORD        32              // number of Index Entries structures
                 // Index Entries                    array of:    variable        //
                 // * Packet Number                  DWORD        32              // number of the Data Packet associated with this index entry
                 // * Packet Count                   WORD         16              // number of Data Packets to sent at this index entry
                 // shortcut
                 $info_asf['simple_index_object'] = array();
                 $info_asf_simple_index_object =& $info_asf['simple_index_object'];
                 $info_asf_simple_index_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_simple_index_object['objectsize'] = $next_object_size;
                 $simple_index_object_data = $next_object_data_header . fread($getid3->fp, 56 - 24);
                 $info_asf_simple_index_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($simple_index_object_data, 24, 16));
                 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_simple_index_object, $simple_index_object_data, 40, array('index_entry_time_interval' => 8, 'maximum_packet_count' => 4, 'index_entries_count' => 4));
                 $offset = 56;
                 $index_entries_data = $simple_index_object_data . fread($getid3->fp, 6 * $info_asf_simple_index_object['index_entries_count']);
                 for ($index_entries_counter = 0; $index_entries_counter < $info_asf_simple_index_object['index_entries_count']; $index_entries_counter++) {
                     $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4));
                     $offset += 4;
                     $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4));
                     $offset += 2;
                 }
                 break;
             case getid3_asf::Index_Object:
                 // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
                 // Field Name                       Field Type   Size (bits)
                 // Object ID                        GUID         128             // GUID for the Index Object - getid3_asf::Index_Object
                 // Object Size                      QWORD        64              // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
                 // Index Entry Time Interval        DWORD        32              // Specifies the time interval between each index entry in ms.
                 // Index Specifiers Count           WORD         16              // Specifies the number of Index Specifiers structures in this Index Object.
                 // Index Blocks Count               DWORD        32              // Specifies the number of Index Blocks structures in this Index Object.
                 // Index Entry Time Interval        DWORD        32              // Specifies the time interval between index entries in milliseconds.  This value cannot be 0.
                 // Index Specifiers Count           WORD         16              // Specifies the number of entries in the Index Specifiers list.  Valid values are 1 and greater.
                 // Index Specifiers                 array of:    varies          //
                 // * Stream Number                  WORD         16              // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127.
                 // * Index Type                     WORD         16              // Specifies Index Type values as follows:
                 //   1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
                 //   2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
                 //   3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set.
                 //   Nearest Past Cleanpoint is the most common type of index.
                 // Index Entry Count                DWORD        32              // Specifies the number of Index Entries in the block.
                 // * Block Positions                QWORD        varies          // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed.
                 // * Index Entries                  array of:    varies          //
                 // * * Offsets                      DWORD        varies          // An offset value of 0xffffffff indicates an invalid offset value
                 // shortcut
                 $info_asf['asf_index_object'] = array();
                 $info_asf_asf_index_object =& $info_asf['asf_index_object'];
                 $asf_index_object_data = $next_object_data_header . fread($getid3->fp, 34 - 24);
                 $info_asf_asf_index_object['objectid_guid'] = $next_object_guidtext;
                 $info_asf_asf_index_object['objectsize'] = $next_object_size;
                 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_asf_index_object, $asf_index_object_data, 24, array('entry_time_interval' => 4, 'index_specifiers_count' => 2, 'index_blocks_count' => 4));
                 $offset = 34;
                 $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count']);
                 for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) {
                     $index_specifier_stream_number = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2));
                     $offset += 2;
                     $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['stream_number'] = $index_specifier_stream_number;
                     $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type'] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2));
                     $offset += 2;
                     $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type_text'] = getid3_asf::ASFIndexObjectIndexTypeLookup($info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type']);
                 }
                 $asf_index_object_data .= fread($getid3->fp, 4);
                 $info_asf_asf_index_object['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 4));
                 $offset += 4;
                 $asf_index_object_data .= fread($getid3->fp, 8 * $info_asf_asf_index_object['index_specifiers_count']);
                 for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) {
                     $info_asf_asf_index_object['block_positions'][$index_specifiers_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 8));
                     $offset += 8;
                 }
                 $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count'] * $info_asf_asf_index_object['index_entry_count']);
                 for ($index_entry_counter = 0; $index_entry_counter < $info_asf_asf_index_object['index_entry_count']; $index_entry_counter++) {
                     for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) {
                         $info_asf_asf_index_object['offsets'][$index_specifiers_counter][$index_entry_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 4));
                         $offset += 4;
                     }
                 }
                 break;
             default:
                 // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
                 if (getid3_asf::GUIDname($next_object_guidtext)) {
                     $getid3->warning('unhandled GUID "' . getid3_asf::GUIDname($next_object_guidtext) . '" {' . $next_object_guidtext . '} in ASF body at offset ' . ($offset - 16 - 8));
                 } else {
                     $getid3->warning('unknown GUID {' . $next_object_guidtext . '} in ASF body at offset ' . (ftell($getid3->fp) - 16 - 8));
                 }
                 fseek($getid3->fp, $next_object_size - 16 - 8, SEEK_CUR);
                 break;
         }
     }
     if (isset($info_asf_codec_list_object['codec_entries']) && is_array($info_asf_codec_list_object['codec_entries'])) {
         foreach ($info_asf_codec_list_object['codec_entries'] as $stream_number => $stream_data) {
             switch ($stream_data['information']) {
                 case 'WMV1':
                 case 'WMV2':
                 case 'WMV3':
                 case 'MSS1':
                 case 'MSS2':
                 case 'WMVA':
                 case 'WVC1':
                 case 'WMVP':
                 case 'WVP2':
                     $info_video['dataformat'] = 'wmv';
                     $getid3->info['mime_type'] = 'video/x-ms-wmv';
                     break;
                 case 'MP42':
                 case 'MP43':
                 case 'MP4S':
                 case 'mp4s':
                     $info_video['dataformat'] = 'asf';
                     $getid3->info['mime_type'] = 'video/x-ms-asf';
                     break;
                 default:
                     switch ($stream_data['type_raw']) {
                         case 1:
                             if (strstr($this->TrimConvert($stream_data['name']), 'Windows Media')) {
                                 $info_video['dataformat'] = 'wmv';
                                 if ($getid3->info['mime_type'] == 'video/x-ms-asf') {
                                     $getid3->info['mime_type'] = 'video/x-ms-wmv';
                                 }
                             }
                             break;
                         case 2:
                             if (strstr($this->TrimConvert($stream_data['name']), 'Windows Media')) {
                                 $info_audio['dataformat'] = 'wma';
                                 if ($getid3->info['mime_type'] == 'video/x-ms-asf') {
                                     $getid3->info['mime_type'] = 'audio/x-ms-wma';
                                 }
                             }
                             break;
                     }
                     break;
             }
         }
     }
     switch (@$info_audio['codec']) {
         case 'MPEG Layer-3':
             $info_audio['dataformat'] = 'mp3';
             break;
         default:
             break;
     }
     if (isset($info_asf_codec_list_object['codec_entries'])) {
         foreach ($info_asf_codec_list_object['codec_entries'] as $stream_number => $stream_data) {
             switch ($stream_data['type_raw']) {
                 case 1:
                     // video
                     $info_video['encoder'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][$stream_number]['name']);
                     break;
                 case 2:
                     // audio
                     $info_audio['encoder'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][$stream_number]['name']);
                     $info_audio['encoder_options'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][0]['description']);
                     $info_audio['codec'] = $info_audio['encoder'];
                     break;
                 default:
                     $getid3->warning('Unknown streamtype: [codec_list_object][codec_entries][' . $stream_number . '][type_raw] == ' . $stream_data['type_raw']);
                     break;
             }
         }
     }
     if (isset($getid3->info['audio'])) {
         $info_audio['lossless'] = isset($info_audio['lossless']) ? $info_audio['lossless'] : false;
         $info_audio['dataformat'] = !empty($info_audio['dataformat']) ? $info_audio['dataformat'] : 'asf';
     }
     if (!empty($info_video['dataformat'])) {
         $info_video['lossless'] = isset($info_audio['lossless']) ? $info_audio['lossless'] : false;
         $info_video['pixel_aspect_ratio'] = isset($info_audio['pixel_aspect_ratio']) ? $info_audio['pixel_aspect_ratio'] : (double) 1;
         $info_video['dataformat'] = !empty($info_video['dataformat']) ? $info_video['dataformat'] : 'asf';
     }
     $getid3->info['bitrate'] = @$info_audio['bitrate'] + @$info_video['bitrate'];
     if (empty($info_audio)) {
         unset($getid3->info['audio']);
     }
     if (empty($info_video)) {
         unset($getid3->info['video']);
     }
     return true;
 }
 function getid3_asf(&$fd, &$ThisFileInfo)
 {
     // Shortcuts
     $thisfile_audio =& $ThisFileInfo['audio'];
     $thisfile_video =& $ThisFileInfo['video'];
     $ThisFileInfo['asf'] = array();
     $thisfile_asf =& $ThisFileInfo['asf'];
     $thisfile_asf['comments'] = array();
     $thisfile_asf_comments =& $thisfile_asf['comments'];
     $thisfile_asf['header_object'] = array();
     $thisfile_asf_headerobject =& $thisfile_asf['header_object'];
     // ASF structure:
     // * Header Object [required]
     //   * File Properties Object [required]   (global file attributes)
     //   * Stream Properties Object [required] (defines media stream & characteristics)
     //   * Header Extension Object [required]  (additional functionality)
     //   * Content Description Object          (bibliographic information)
     //   * Script Command Object               (commands for during playback)
     //   * Marker Object                       (named jumped points within the file)
     // * Data Object [required]
     //   * Data Packets
     // * Index Object
     // Header Object: (mandatory, one only)
     // Field Name                   Field Type   Size (bits)
     // Object ID                    GUID         128             // GUID for header object - GETID3_ASF_Header_Object
     // Object Size                  QWORD        64              // size of header object, including 30 bytes of Header Object header
     // Number of Header Objects     DWORD        32              // number of objects in header object
     // Reserved1                    BYTE         8               // hardcoded: 0x01
     // Reserved2                    BYTE         8               // hardcoded: 0x02
     $ThisFileInfo['fileformat'] = 'asf';
     fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
     $HeaderObjectData = fread($fd, 30);
     $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16);
     $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']);
     if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) {
         $ThisFileInfo['warning'][] = 'ASF header GUID {' . $this->BytestringToGUID($thisfile_asf_headerobject['objectid']) . '} does not match expected "GETID3_ASF_Header_Object" GUID {' . $this->BytestringToGUID(GETID3_ASF_Header_Object) . '}';
         unset($ThisFileInfo['fileformat']);
         unset($ThisFileInfo['asf']);
         return false;
         break;
     }
     $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8));
     $thisfile_asf_headerobject['headerobjects'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 24, 4));
     $thisfile_asf_headerobject['reserved1'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 28, 1));
     $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1));
     //$ASFHeaderData  = $HeaderObjectData;
     $ASFHeaderData = fread($fd, $thisfile_asf_headerobject['objectsize'] - 30);
     //$offset = 30;
     $offset = 0;
     for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) {
         $NextObjectGUID = substr($ASFHeaderData, $offset, 16);
         $offset += 16;
         $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
         $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
         $offset += 8;
         switch ($NextObjectGUID) {
             case GETID3_ASF_File_Properties_Object:
                 // File Properties Object: (mandatory, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for file properties object - GETID3_ASF_File_Properties_Object
                 // Object Size                  QWORD        64              // size of file properties object, including 104 bytes of File Properties Object header
                 // File ID                      GUID         128             // unique ID - identical to File ID in Data Object
                 // File Size                    QWORD        64              // entire file in bytes. Invalid if Broadcast Flag == 1
                 // Creation Date                QWORD        64              // date & time of file creation. Maybe invalid if Broadcast Flag == 1
                 // Data Packets Count           QWORD        64              // number of data packets in Data Object. Invalid if Broadcast Flag == 1
                 // Play Duration                QWORD        64              // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
                 // Send Duration                QWORD        64              // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
                 // Preroll                      QWORD        64              // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount
                 // Flags                        DWORD        32              //
                 // * Broadcast Flag             bits         1  (0x01)       // file is currently being written, some header values are invalid
                 // * Seekable Flag              bits         1  (0x02)       // is file seekable
                 // * Reserved                   bits         30 (0xFFFFFFFC) // reserved - set to zero
                 // Minimum Data Packet Size     DWORD        32              // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
                 // Maximum Data Packet Size     DWORD        32              // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
                 // Maximum Bitrate              DWORD        32              // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
                 // shortcut
                 $thisfile_asf['file_properties_object'] = array();
                 $thisfile_asf_filepropertiesobject =& $thisfile_asf['file_properties_object'];
                 $thisfile_asf_filepropertiesobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_filepropertiesobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_filepropertiesobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_filepropertiesobject['fileid'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_filepropertiesobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_filepropertiesobject['fileid']);
                 $thisfile_asf_filepropertiesobject['filesize'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                 $offset += 8;
                 $thisfile_asf_filepropertiesobject['creation_date'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                 $thisfile_asf_filepropertiesobject['creation_date_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_filepropertiesobject['creation_date']);
                 $offset += 8;
                 $thisfile_asf_filepropertiesobject['data_packets'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                 $offset += 8;
                 $thisfile_asf_filepropertiesobject['play_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                 $offset += 8;
                 $thisfile_asf_filepropertiesobject['send_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                 $offset += 8;
                 $thisfile_asf_filepropertiesobject['preroll'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                 $offset += 8;
                 $ThisFileInfo['playtime_seconds'] = $thisfile_asf_filepropertiesobject['play_duration'] / 10000000 - $thisfile_asf_filepropertiesobject['preroll'] / 1000;
                 $thisfile_asf_filepropertiesobject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $thisfile_asf_filepropertiesobject['flags']['broadcast'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x1);
                 $thisfile_asf_filepropertiesobject['flags']['seekable'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x2);
                 $thisfile_asf_filepropertiesobject['min_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $thisfile_asf_filepropertiesobject['max_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $thisfile_asf_filepropertiesobject['max_bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $ThisFileInfo['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate'];
                 break;
             case GETID3_ASF_Stream_Properties_Object:
                 // Stream Properties Object: (mandatory, one per media stream)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for stream properties object - GETID3_ASF_Stream_Properties_Object
                 // Object Size                  QWORD        64              // size of stream properties object, including 78 bytes of Stream Properties Object header
                 // Stream Type                  GUID         128             // GETID3_ASF_Audio_Media, GETID3_ASF_Video_Media or GETID3_ASF_Command_Media
                 // Error Correction Type        GUID         128             // GETID3_ASF_Audio_Spread for audio-only streams, GETID3_ASF_No_Error_Correction for other stream types
                 // Time Offset                  QWORD        64              // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
                 // Type-Specific Data Length    DWORD        32              // number of bytes for Type-Specific Data field
                 // Error Correction Data Length DWORD        32              // number of bytes for Error Correction Data field
                 // Flags                        WORD         16              //
                 // * Stream Number              bits         7 (0x007F)      // number of this stream.  1 <= valid <= 127
                 // * Reserved                   bits         8 (0x7F80)      // reserved - set to zero
                 // * Encrypted Content Flag     bits         1 (0x8000)      // stream contents encrypted if set
                 // Reserved                     DWORD        32              // reserved - set to zero
                 // Type-Specific Data           BYTESTREAM   variable        // type-specific format data, depending on value of Stream Type
                 // Error Correction Data        BYTESTREAM   variable        // error-correction-specific format data, depending on value of Error Correct Type
                 // There is one GETID3_ASF_Stream_Properties_Object for each stream (audio, video) but the
                 // stream number isn't known until halfway through decoding the structure, hence it
                 // it is decoded to a temporary variable and then stuck in the appropriate index later
                 $StreamPropertiesObjectData['objectid'] = $NextObjectGUID;
                 $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext;
                 $StreamPropertiesObjectData['objectsize'] = $NextObjectSize;
                 $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $StreamPropertiesObjectData['stream_type_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['stream_type']);
                 $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $StreamPropertiesObjectData['error_correct_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['error_correct_type']);
                 $StreamPropertiesObjectData['time_offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                 $offset += 8;
                 $StreamPropertiesObjectData['type_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $StreamPropertiesObjectData['error_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $StreamPropertiesObjectData['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x7f;
                 $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000);
                 $offset += 4;
                 // reserved - DWORD
                 $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']);
                 $offset += $StreamPropertiesObjectData['type_data_length'];
                 $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']);
                 $offset += $StreamPropertiesObjectData['error_data_length'];
                 switch ($StreamPropertiesObjectData['stream_type']) {
                     case GETID3_ASF_Audio_Media:
                         $thisfile_audio['dataformat'] = !empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf';
                         $thisfile_audio['bitrate_mode'] = !empty($thisfile_audio['bitrate_mode']) ? $thisfile_audio['bitrate_mode'] : 'cbr';
                         $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16));
                         unset($audiodata['raw']);
                         $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio);
                         break;
                     case GETID3_ASF_Video_Media:
                         $thisfile_video['dataformat'] = !empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf';
                         $thisfile_video['bitrate_mode'] = !empty($thisfile_video['bitrate_mode']) ? $thisfile_video['bitrate_mode'] : 'cbr';
                         break;
                     case GETID3_ASF_Command_Media:
                     default:
                         // do nothing
                         break;
                 }
                 $thisfile_asf['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData;
                 unset($StreamPropertiesObjectData);
                 // clear for next stream, if any
                 break;
             case GETID3_ASF_Header_Extension_Object:
                 // Header Extension Object: (mandatory, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Header Extension object - GETID3_ASF_Header_Extension_Object
                 // Object Size                  QWORD        64              // size of Header Extension object, including 46 bytes of Header Extension Object header
                 // Reserved Field 1             GUID         128             // hardcoded: GETID3_ASF_Reserved_1
                 // Reserved Field 2             WORD         16              // hardcoded: 0x00000006
                 // Header Extension Data Size   DWORD        32              // in bytes. valid: 0, or > 24. equals object size minus 46
                 // Header Extension Data        BYTESTREAM   variable        // array of zero or more extended header objects
                 // shortcut
                 $thisfile_asf['header_extension_object'] = array();
                 $thisfile_asf_headerextensionobject =& $thisfile_asf['header_extension_object'];
                 $thisfile_asf_headerextensionobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_headerextensionobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_headerextensionobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_headerextensionobject['reserved_1'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_headerextensionobject['reserved_1_guid'] = $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']);
                 if ($thisfile_asf_headerextensionobject['reserved_1'] != GETID3_ASF_Reserved_1) {
                     $ThisFileInfo['warning'][] = 'header_extension_object.reserved_1 GUID (' . $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']) . ') does not match expected "GETID3_ASF_Reserved_1" GUID (' . $this->BytestringToGUID(GETID3_ASF_Reserved_1) . ')';
                     //return false;
                     break;
                 }
                 $thisfile_asf_headerextensionobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 if ($thisfile_asf_headerextensionobject['reserved_2'] != 6) {
                     $ThisFileInfo['warning'][] = 'header_extension_object.reserved_2 (' . getid3_lib::PrintHexBytes($thisfile_asf_headerextensionobject['reserved_2']) . ') does not match expected value of "6"';
                     //return false;
                     break;
                 }
                 $thisfile_asf_headerextensionobject['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']);
                 $offset += $thisfile_asf_headerextensionobject['extension_data_size'];
                 break;
             case GETID3_ASF_Codec_List_Object:
                 // Codec List Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Codec List object - GETID3_ASF_Codec_List_Object
                 // Object Size                  QWORD        64              // size of Codec List object, including 44 bytes of Codec List Object header
                 // Reserved                     GUID         128             // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
                 // Codec Entries Count          DWORD        32              // number of entries in Codec Entries array
                 // Codec Entries                array of:    variable        //
                 // * Type                       WORD         16              // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
                 // * Codec Name Length          WORD         16              // number of Unicode characters stored in the Codec Name field
                 // * Codec Name                 WCHAR        variable        // array of Unicode characters - name of codec used to create the content
                 // * Codec Description Length   WORD         16              // number of Unicode characters stored in the Codec Description field
                 // * Codec Description          WCHAR        variable        // array of Unicode characters - description of format used to create the content
                 // * Codec Information Length   WORD         16              // number of Unicode characters stored in the Codec Information field
                 // * Codec Information          BYTESTREAM   variable        // opaque array of information bytes about the codec used to create the content
                 // shortcut
                 $thisfile_asf['codec_list_object'] = array();
                 $thisfile_asf_codeclistobject =& $thisfile_asf['codec_list_object'];
                 $thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_codeclistobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_codeclistobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_codeclistobject['reserved'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_codeclistobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']);
                 if ($thisfile_asf_codeclistobject['reserved'] != $this->GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) {
                     $ThisFileInfo['warning'][] = 'codec_list_object.reserved GUID {' . $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']) . '} does not match expected "GETID3_ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}';
                     //return false;
                     break;
                 }
                 $thisfile_asf_codeclistobject['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) {
                     // shortcut
                     $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter] = array();
                     $thisfile_asf_codeclistobject_codecentries_current =& $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter];
                     $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_codeclistobject_codecentries_current['type'] = $this->ASFCodecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']);
                     $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $thisfile_asf_codeclistobject_codecentries_current['name'] = substr($ASFHeaderData, $offset, $CodecNameLength);
                     $offset += $CodecNameLength;
                     $CodecDescriptionLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $thisfile_asf_codeclistobject_codecentries_current['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength);
                     $offset += $CodecDescriptionLength;
                     $CodecInformationLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_codeclistobject_codecentries_current['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength);
                     $offset += $CodecInformationLength;
                     if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) {
                         // audio codec
                         $thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']);
                         list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']));
                         if (!isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) {
                             $thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000);
                         }
                         if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && $thisfile_asf_codeclistobject['codec_entries_count'] > 1) {
                             $thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate'];
                         }
                         $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency));
                         switch ($AudioCodecFrequency) {
                             case 8:
                                 $thisfile_audio['sample_rate'] = 8000;
                                 break;
                             case 11:
                                 $thisfile_audio['sample_rate'] = 11025;
                                 break;
                             case 12:
                                 $thisfile_audio['sample_rate'] = 12000;
                                 break;
                             case 16:
                                 $thisfile_audio['sample_rate'] = 16000;
                                 break;
                             case 22:
                                 $thisfile_audio['sample_rate'] = 22050;
                                 break;
                             case 24:
                                 $thisfile_audio['sample_rate'] = 24000;
                                 break;
                             case 32:
                                 $thisfile_audio['sample_rate'] = 32000;
                                 break;
                             case 44:
                                 $thisfile_audio['sample_rate'] = 44100;
                                 break;
                             case 48:
                                 $thisfile_audio['sample_rate'] = 48000;
                                 break;
                             default:
                                 $ThisFileInfo['warning'][] = 'unknown frequency: "' . $AudioCodecFrequency . '" (' . $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']) . ')';
                                 //                                return false;
                                 break;
                         }
                         if (!isset($thisfile_audio['channels'])) {
                             if (strstr($AudioCodecChannels, 'stereo')) {
                                 $thisfile_audio['channels'] = 2;
                             } elseif (strstr($AudioCodecChannels, 'mono')) {
                                 $thisfile_audio['channels'] = 1;
                             }
                         }
                     }
                 }
                 break;
             case GETID3_ASF_Script_Command_Object:
                 // Script Command Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Script Command object - GETID3_ASF_Script_Command_Object
                 // Object Size                  QWORD        64              // size of Script Command object, including 44 bytes of Script Command Object header
                 // Reserved                     GUID         128             // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
                 // Commands Count               WORD         16              // number of Commands structures in the Script Commands Objects
                 // Command Types Count          WORD         16              // number of Command Types structures in the Script Commands Objects
                 // Command Types                array of:    variable        //
                 // * Command Type Name Length   WORD         16              // number of Unicode characters for Command Type Name
                 // * Command Type Name          WCHAR        variable        // array of Unicode characters - name of a type of command
                 // Commands                     array of:    variable        //
                 // * Presentation Time          DWORD        32              // presentation time of that command, in milliseconds
                 // * Type Index                 WORD         16              // type of this command, as a zero-based index into the array of Command Types of this object
                 // * Command Name Length        WORD         16              // number of Unicode characters for Command Name
                 // * Command Name               WCHAR        variable        // array of Unicode characters - name of this command
                 // shortcut
                 $thisfile_asf['script_command_object'] = array();
                 $thisfile_asf_scriptcommandobject =& $thisfile_asf['script_command_object'];
                 $thisfile_asf_scriptcommandobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_scriptcommandobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_scriptcommandobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_scriptcommandobject['reserved'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_scriptcommandobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']);
                 if ($thisfile_asf_scriptcommandobject['reserved'] != $this->GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) {
                     $ThisFileInfo['warning'][] = 'script_command_object.reserved GUID {' . $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']) . '} does not match expected "GETID3_ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}';
                     //return false;
                     break;
                 }
                 $thisfile_asf_scriptcommandobject['commands_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_scriptcommandobject['command_types_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 for ($CommandTypesCounter = 0; $CommandTypesCounter < $thisfile_asf_scriptcommandobject['command_types_count']; $CommandTypesCounter++) {
                     $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $thisfile_asf_scriptcommandobject['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
                     $offset += $CommandTypeNameLength;
                 }
                 for ($CommandsCounter = 0; $CommandsCounter < $thisfile_asf_scriptcommandobject['commands_count']; $CommandsCounter++) {
                     $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                     $offset += 4;
                     $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['type_index'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2;
                     // 2 bytes per character
                     $offset += 2;
                     $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
                     $offset += $CommandTypeNameLength;
                 }
                 break;
             case GETID3_ASF_Marker_Object:
                 // Marker Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Marker object - GETID3_ASF_Marker_Object
                 // Object Size                  QWORD        64              // size of Marker object, including 48 bytes of Marker Object header
                 // Reserved                     GUID         128             // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
                 // Markers Count                DWORD        32              // number of Marker structures in Marker Object
                 // Reserved                     WORD         16              // hardcoded: 0x0000
                 // Name Length                  WORD         16              // number of bytes in the Name field
                 // Name                         WCHAR        variable        // name of the Marker Object
                 // Markers                      array of:    variable        //
                 // * Offset                     QWORD        64              // byte offset into Data Object
                 // * Presentation Time          QWORD        64              // in 100-nanosecond units
                 // * Entry Length               WORD         16              // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
                 // * Send Time                  DWORD        32              // in milliseconds
                 // * Flags                      DWORD        32              // hardcoded: 0x00000000
                 // * Marker Description Length  DWORD        32              // number of bytes in Marker Description field
                 // * Marker Description         WCHAR        variable        // array of Unicode characters - description of marker entry
                 // * Padding                    BYTESTREAM   variable        // optional padding bytes
                 // shortcut
                 $thisfile_asf['marker_object'] = array();
                 $thisfile_asf_markerobject =& $thisfile_asf['marker_object'];
                 $thisfile_asf_markerobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_markerobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_markerobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_markerobject['reserved'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_markerobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_markerobject['reserved']);
                 if ($thisfile_asf_markerobject['reserved'] != $this->GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) {
                     $ThisFileInfo['warning'][] = 'marker_object.reserved GUID {' . $this->BytestringToGUID($thisfile_asf_markerobject['reserved_1']) . '} does not match expected "GETID3_ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}';
                     break;
                 }
                 $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 if ($thisfile_asf_markerobject['reserved_2'] != 0) {
                     $ThisFileInfo['warning'][] = 'marker_object.reserved_2 (' . getid3_lib::PrintHexBytes($thisfile_asf_markerobject['reserved_2']) . ') does not match expected value of "0"';
                     break;
                 }
                 $thisfile_asf_markerobject['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_markerobject['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['name_length']);
                 $offset += $thisfile_asf_markerobject['name_length'];
                 for ($MarkersCounter = 0; $MarkersCounter < $thisfile_asf_markerobject['markers_count']; $MarkersCounter++) {
                     $thisfile_asf_markerobject['markers'][$MarkersCounter]['offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                     $offset += 8;
                     $thisfile_asf_markerobject['markers'][$MarkersCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
                     $offset += 8;
                     $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_markerobject['markers'][$MarkersCounter]['send_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                     $offset += 4;
                     $thisfile_asf_markerobject['markers'][$MarkersCounter]['flags'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                     $offset += 4;
                     $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                     $offset += 4;
                     $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']);
                     $offset += $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
                     $PaddingLength = $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
                     if ($PaddingLength > 0) {
                         $thisfile_asf_markerobject['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength);
                         $offset += $PaddingLength;
                     }
                 }
                 break;
             case GETID3_ASF_Bitrate_Mutual_Exclusion_Object:
                 // Bitrate Mutual Exclusion Object: (optional)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Bitrate Mutual Exclusion object - GETID3_ASF_Bitrate_Mutual_Exclusion_Object
                 // Object Size                  QWORD        64              // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
                 // Exlusion Type                GUID         128             // nature of mutual exclusion relationship. one of: (GETID3_ASF_Mutex_Bitrate, GETID3_ASF_Mutex_Unknown)
                 // Stream Numbers Count         WORD         16              // number of video streams
                 // Stream Numbers               WORD         variable        // array of mutually exclusive video stream numbers. 1 <= valid <= 127
                 // shortcut
                 $thisfile_asf['bitrate_mutual_exclusion_object'] = array();
                 $thisfile_asf_bitratemutualexclusionobject =& $thisfile_asf['bitrate_mutual_exclusion_object'];
                 $thisfile_asf_bitratemutualexclusionobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_bitratemutualexclusionobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_bitratemutualexclusionobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_bitratemutualexclusionobject['reserved'] = substr($ASFHeaderData, $offset, 16);
                 $thisfile_asf_bitratemutualexclusionobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']);
                 $offset += 16;
                 if ($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Bitrate && $thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Unknown) {
                     $ThisFileInfo['warning'][] = 'bitrate_mutual_exclusion_object.reserved GUID {' . $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']) . '} does not match expected "GETID3_ASF_Mutex_Bitrate" GUID {' . $this->BytestringToGUID(GETID3_ASF_Mutex_Bitrate) . '} or  "GETID3_ASF_Mutex_Unknown" GUID {' . $this->BytestringToGUID(GETID3_ASF_Mutex_Unknown) . '}';
                     //return false;
                     break;
                 }
                 $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 for ($StreamNumberCounter = 0; $StreamNumberCounter < $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count']; $StreamNumberCounter++) {
                     $thisfile_asf_bitratemutualexclusionobject['stream_numbers'][$StreamNumberCounter] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                 }
                 break;
             case GETID3_ASF_Error_Correction_Object:
                 // Error Correction Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Error Correction object - GETID3_ASF_Error_Correction_Object
                 // Object Size                  QWORD        64              // size of Error Correction object, including 44 bytes of Error Correction Object header
                 // Error Correction Type        GUID         128             // type of error correction. one of: (GETID3_ASF_No_Error_Correction, GETID3_ASF_Audio_Spread)
                 // Error Correction Data Length DWORD        32              // number of bytes in Error Correction Data field
                 // Error Correction Data        BYTESTREAM   variable        // structure depends on value of Error Correction Type field
                 // shortcut
                 $thisfile_asf['error_correction_object'] = array();
                 $thisfile_asf_errorcorrectionobject =& $thisfile_asf['error_correction_object'];
                 $thisfile_asf_errorcorrectionobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_errorcorrectionobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_errorcorrectionobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_errorcorrectionobject['error_correction_type'] = substr($ASFHeaderData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_errorcorrectionobject['error_correction_guid'] = $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']);
                 $thisfile_asf_errorcorrectionobject['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                 $offset += 4;
                 switch ($thisfile_asf_errorcorrectionobject['error_correction_type']) {
                     case GETID3_ASF_No_Error_Correction:
                         // should be no data, but just in case there is, skip to the end of the field
                         $offset += $thisfile_asf_errorcorrectionobject['error_correction_data_length'];
                         break;
                     case GETID3_ASF_Audio_Spread:
                         // Field Name                   Field Type   Size (bits)
                         // Span                         BYTE         8               // number of packets over which audio will be spread.
                         // Virtual Packet Length        WORD         16              // size of largest audio payload found in audio stream
                         // Virtual Chunk Length         WORD         16              // size of largest audio payload found in audio stream
                         // Silence Data Length          WORD         16              // number of bytes in Silence Data field
                         // Silence Data                 BYTESTREAM   variable        // hardcoded: 0x00 * (Silence Data Length) bytes
                         $thisfile_asf_errorcorrectionobject['span'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 1));
                         $offset += 1;
                         $thisfile_asf_errorcorrectionobject['virtual_packet_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                         $offset += 2;
                         $thisfile_asf_errorcorrectionobject['virtual_chunk_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                         $offset += 2;
                         $thisfile_asf_errorcorrectionobject['silence_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                         $offset += 2;
                         $thisfile_asf_errorcorrectionobject['silence_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_errorcorrectionobject['silence_data_length']);
                         $offset += $thisfile_asf_errorcorrectionobject['silence_data_length'];
                         break;
                     default:
                         $ThisFileInfo['warning'][] = 'error_correction_object.error_correction_type GUID {' . $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['reserved']) . '} does not match expected "GETID3_ASF_No_Error_Correction" GUID {' . $this->BytestringToGUID(GETID3_ASF_No_Error_Correction) . '} or  "GETID3_ASF_Audio_Spread" GUID {' . $this->BytestringToGUID(GETID3_ASF_Audio_Spread) . '}';
                         //return false;
                         break;
                 }
                 break;
             case GETID3_ASF_Content_Description_Object:
                 // Content Description Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Content Description object - GETID3_ASF_Content_Description_Object
                 // Object Size                  QWORD        64              // size of Content Description object, including 34 bytes of Content Description Object header
                 // Title Length                 WORD         16              // number of bytes in Title field
                 // Author Length                WORD         16              // number of bytes in Author field
                 // Copyright Length             WORD         16              // number of bytes in Copyright field
                 // Description Length           WORD         16              // number of bytes in Description field
                 // Rating Length                WORD         16              // number of bytes in Rating field
                 // Title                        WCHAR        16              // array of Unicode characters - Title
                 // Author                       WCHAR        16              // array of Unicode characters - Author
                 // Copyright                    WCHAR        16              // array of Unicode characters - Copyright
                 // Description                  WCHAR        16              // array of Unicode characters - Description
                 // Rating                       WCHAR        16              // array of Unicode characters - Rating
                 // shortcut
                 $thisfile_asf['content_description_object'] = array();
                 $thisfile_asf_contentdescriptionobject =& $thisfile_asf['content_description_object'];
                 $thisfile_asf_contentdescriptionobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_contentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_contentdescriptionobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_contentdescriptionobject['title_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_contentdescriptionobject['author_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_contentdescriptionobject['copyright_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_contentdescriptionobject['description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_contentdescriptionobject['rating_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_contentdescriptionobject['title'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['title_length']);
                 $offset += $thisfile_asf_contentdescriptionobject['title_length'];
                 $thisfile_asf_contentdescriptionobject['author'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['author_length']);
                 $offset += $thisfile_asf_contentdescriptionobject['author_length'];
                 $thisfile_asf_contentdescriptionobject['copyright'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['copyright_length']);
                 $offset += $thisfile_asf_contentdescriptionobject['copyright_length'];
                 $thisfile_asf_contentdescriptionobject['description'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['description_length']);
                 $offset += $thisfile_asf_contentdescriptionobject['description_length'];
                 $thisfile_asf_contentdescriptionobject['rating'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['rating_length']);
                 $offset += $thisfile_asf_contentdescriptionobject['rating_length'];
                 $ASFcommentKeysToCopy = array('title' => 'title', 'author' => 'artist', 'copyright' => 'copyright', 'description' => 'comment', 'rating' => 'rating');
                 foreach ($ASFcommentKeysToCopy as $keytocopyfrom => $keytocopyto) {
                     if (!empty($thisfile_asf_contentdescriptionobject[$keytocopyfrom])) {
                         $thisfile_asf_comments[$keytocopyto][] = $this->TrimTerm($thisfile_asf_contentdescriptionobject[$keytocopyfrom]);
                     }
                 }
                 break;
             case GETID3_ASF_Extended_Content_Description_Object:
                 // Extended Content Description Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Extended Content Description object - GETID3_ASF_Extended_Content_Description_Object
                 // Object Size                  QWORD        64              // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
                 // Content Descriptors Count    WORD         16              // number of entries in Content Descriptors list
                 // Content Descriptors          array of:    variable        //
                 // * Descriptor Name Length     WORD         16              // size in bytes of Descriptor Name field
                 // * Descriptor Name            WCHAR        variable        // array of Unicode characters - Descriptor Name
                 // * Descriptor Value Data Type WORD         16              // Lookup array:
                 // 0x0000 = Unicode String (variable length)
                 // 0x0001 = BYTE array     (variable length)
                 // 0x0002 = BOOL           (DWORD, 32 bits)
                 // 0x0003 = DWORD          (DWORD, 32 bits)
                 // 0x0004 = QWORD          (QWORD, 64 bits)
                 // 0x0005 = WORD           (WORD,  16 bits)
                 // * Descriptor Value Length    WORD         16              // number of bytes stored in Descriptor Value field
                 // * Descriptor Value           variable     variable        // value for Content Descriptor
                 // shortcut
                 $thisfile_asf['extended_content_description_object'] = array();
                 $thisfile_asf_extendedcontentdescriptionobject =& $thisfile_asf['extended_content_description_object'];
                 $thisfile_asf_extendedcontentdescriptionobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_extendedcontentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_extendedcontentdescriptionobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) {
                     // shortcut
                     $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter] = array();
                     $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current =& $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter];
                     $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['base_offset'] = $offset + 30;
                     $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']);
                     $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'];
                     $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']);
                     $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'];
                     switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
                         case 0x0:
                             // Unicode string
                             break;
                         case 0x1:
                             // BYTE array
                             // do nothing
                             break;
                         case 0x2:
                             // BOOL
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
                             break;
                         case 0x3:
                             // DWORD
                         // DWORD
                         case 0x4:
                             // QWORD
                         // QWORD
                         case 0x5:
                             // WORD
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
                             break;
                         default:
                             $ThisFileInfo['warning'][] = 'extended_content_description.content_descriptors.' . $ExtendedContentDescriptorsCounter . '.value_type is invalid (' . $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] . ')';
                             //return false;
                             break;
                     }
                     switch ($this->TrimConvert(strtolower($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']))) {
                         case 'wm/albumartist':
                         case 'artist':
                             $thisfile_asf_comments['artist'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
                             break;
                         case 'wm/albumtitle':
                         case 'album':
                             $thisfile_asf_comments['album'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
                             break;
                         case 'wm/genre':
                         case 'genre':
                             $genre = $this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
                             // id3v1 module might not be loaded
                             $GETID3_ERRORARRAY =& $ThisFileInfo['warning'];
                             if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.tag.id3v1.php', __FILE__, false)) {
                                 $CleanedGenre = getid3_id3v1::StandardiseID3v1GenreName($genre);
                                 // convert to standard GenreID and back to standard spelling/capitalization
                                 if ($CleanedGenre != $genre) {
                                     $genre = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', $CleanedGenre);
                                 }
                             }
                             $thisfile_asf_comments['genre'] = array($genre);
                             break;
                         case 'wm/tracknumber':
                         case 'tracknumber':
                             $thisfile_asf_comments['track'] = array(intval($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])));
                             break;
                         case 'wm/track':
                             if (empty($thisfile_asf_comments['track'])) {
                                 $thisfile_asf_comments['track'] = array(1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
                             }
                             break;
                         case 'wm/year':
                         case 'year':
                         case 'date':
                             $thisfile_asf_comments['year'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
                             break;
                         case 'isvbr':
                             if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']) {
                                 $thisfile_audio['bitrate_mode'] = 'vbr';
                                 $thisfile_video['bitrate_mode'] = 'vbr';
                             }
                             break;
                         case 'id3':
                             // id3v2 module might not be loaded
                             if (class_exists('getid3_id3v2')) {
                                 if ($tempfilehandle = tmpfile()) {
                                     $tempThisfileInfo = array('encoding' => $ThisFileInfo['encoding']);
                                     fwrite($tempfilehandle, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
                                     $id3 = new getid3_id3v2($tempfilehandle, $tempThisfileInfo);
                                     fclose($tempfilehandle);
                                     $ThisFileInfo['id3v2'] = $tempThisfileInfo['id3v2'];
                                 }
                             }
                             break;
                         case 'wm/encodingtime':
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
                             $thisfile_asf_comments['encoding_time_unix'] = array($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix']);
                             break;
                         case 'wm/picture':
                             //typedef struct _WMPicture{
                             //  LPWSTR  pwszMIMEType;
                             //  BYTE  bPictureType;
                             //  LPWSTR  pwszDescription;
                             //  DWORD  dwDataLen;
                             //  BYTE*  pbData;
                             //} WM_PICTURE;
                             $wm_picture_offset = 0;
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1));
                             $wm_picture_offset += 1;
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = $this->WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']);
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4));
                             $wm_picture_offset += 4;
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = '';
                             do {
                                 $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
                                 $wm_picture_offset += 2;
                                 $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] .= $next_byte_pair;
                             } while ($next_byte_pair !== "");
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] = '';
                             do {
                                 $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
                                 $wm_picture_offset += 2;
                                 $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] .= $next_byte_pair;
                             } while ($next_byte_pair !== "");
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['dataoffset'] = $wm_picture_offset;
                             $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'] = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset);
                             unset($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
                             break;
                         default:
                             switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
                                 case 0:
                                     // Unicode string
                                     if (substr($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']), 0, 3) == 'WM/') {
                                         $thisfile_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'])))] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
                                     }
                                     break;
                                 case 1:
                                     break;
                             }
                             break;
                     }
                 }
                 break;
             case GETID3_ASF_Stream_Bitrate_Properties_Object:
                 // Stream Bitrate Properties Object: (optional, one only)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Stream Bitrate Properties object - GETID3_ASF_Stream_Bitrate_Properties_Object
                 // Object Size                  QWORD        64              // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
                 // Bitrate Records Count        WORD         16              // number of records in Bitrate Records
                 // Bitrate Records              array of:    variable        //
                 // * Flags                      WORD         16              //
                 // * * Stream Number            bits         7  (0x007F)     // number of this stream
                 // * * Reserved                 bits         9  (0xFF80)     // hardcoded: 0
                 // * Average Bitrate            DWORD        32              // in bits per second
                 // shortcut
                 $thisfile_asf['stream_bitrate_properties_object'] = array();
                 $thisfile_asf_streambitratepropertiesobject =& $thisfile_asf['stream_bitrate_properties_object'];
                 $thisfile_asf_streambitrateproperties['objectid'] = $NextObjectGUID;
                 $thisfile_asf_streambitrateproperties['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_streambitrateproperties['objectsize'] = $NextObjectSize;
                 $thisfile_asf_streambitrateproperties['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                 $offset += 2;
                 for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) {
                     $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x7f;
                     $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
                     $offset += 4;
                 }
                 break;
             case GETID3_ASF_Padding_Object:
                 // Padding Object: (optional)
                 // Field Name                   Field Type   Size (bits)
                 // Object ID                    GUID         128             // GUID for Padding object - GETID3_ASF_Padding_Object
                 // Object Size                  QWORD        64              // size of Padding object, including 24 bytes of ASF Padding Object header
                 // Padding Data                 BYTESTREAM   variable        // ignore
                 // shortcut
                 $thisfile_asf['padding_object'] = array();
                 $thisfile_asf_paddingobject =& $thisfile_asf['padding_object'];
                 $thisfile_asf_paddingobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_paddingobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_paddingobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_paddingobject['padding_length'] = $thisfile_asf_paddingobject['objectsize'] - 16 - 8;
                 $thisfile_asf_paddingobject['padding'] = substr($ASFHeaderData, $offset, $thisfile_asf_paddingobject['padding_length']);
                 break;
             case GETID3_ASF_Extended_Content_Encryption_Object:
             case GETID3_ASF_Content_Encryption_Object:
                 // WMA DRM - just ignore
                 $offset += $NextObjectSize - 16 - 8;
                 break;
             default:
                 // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
                 if ($this->GUIDname($NextObjectGUIDtext)) {
                     $ThisFileInfo['warning'][] = 'unhandled GUID "' . $this->GUIDname($NextObjectGUIDtext) . '" {' . $NextObjectGUIDtext . '} in ASF header at offset ' . ($offset - 16 - 8);
                 } else {
                     $ThisFileInfo['warning'][] = 'unknown GUID {' . $NextObjectGUIDtext . '} in ASF header at offset ' . ($offset - 16 - 8);
                 }
                 $offset += $NextObjectSize - 16 - 8;
                 break;
         }
     }
     if (isset($thisfile_asf_streambitrateproperties['bitrate_records_count'])) {
         $ASFbitrateAudio = 0;
         $ASFbitrateVideo = 0;
         for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) {
             if (isset($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter])) {
                 switch ($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter]['type_raw']) {
                     case 1:
                         $ASFbitrateVideo += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
                         break;
                     case 2:
                         $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
                         break;
                     default:
                         // do nothing
                         break;
                 }
             }
         }
         if ($ASFbitrateAudio > 0) {
             $thisfile_audio['bitrate'] = $ASFbitrateAudio;
         }
         if ($ASFbitrateVideo > 0) {
             $thisfile_video['bitrate'] = $ASFbitrateVideo;
         }
     }
     if (isset($thisfile_asf['stream_properties_object']) && is_array($thisfile_asf['stream_properties_object'])) {
         foreach ($thisfile_asf['stream_properties_object'] as $streamnumber => $streamdata) {
             switch ($streamdata['stream_type']) {
                 case GETID3_ASF_Audio_Media:
                     // Field Name                   Field Type   Size (bits)
                     // Codec ID / Format Tag        WORD         16              // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
                     // Number of Channels           WORD         16              // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
                     // Samples Per Second           DWORD        32              // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
                     // Average number of Bytes/sec  DWORD        32              // bytes/sec of audio stream  - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
                     // Block Alignment              WORD         16              // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
                     // Bits per sample              WORD         16              // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure
                     // Codec Specific Data Size     WORD         16              // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
                     // Codec Specific Data          BYTESTREAM   variable        // array of codec-specific data bytes
                     // shortcut
                     $thisfile_asf['audio_media'][$streamnumber] = array();
                     $thisfile_asf_audiomedia_currentstream =& $thisfile_asf['audio_media'][$streamnumber];
                     $audiomediaoffset = 0;
                     $thisfile_asf_audiomedia_currentstream = getid3_riff::RIFFparseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16));
                     $audiomediaoffset += 16;
                     $thisfile_audio['lossless'] = false;
                     switch ($thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']) {
                         case 0x1:
                             // PCM
                         // PCM
                         case 0x163:
                             // WMA9 Lossless
                             $thisfile_audio['lossless'] = true;
                             break;
                     }
                     if (!isset($thisfile_audio['bitrate'])) {
                         $thisfile_audio['bitrate'] = $thisfile_asf_audiomedia_currentstream['bytes_sec'] * 8;
                     }
                     $thisfile_audio['streams'][$streamnumber] = $thisfile_asf_audiomedia_currentstream;
                     $thisfile_audio['streams'][$streamnumber]['wformattag'] = $thisfile_asf_audiomedia_currentstream['raw']['wFormatTag'];
                     $thisfile_audio['streams'][$streamnumber]['lossless'] = $thisfile_audio['lossless'];
                     $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
                     unset($thisfile_audio['streams'][$streamnumber]['raw']);
                     $thisfile_asf_audiomedia_currentstream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2));
                     $audiomediaoffset += 2;
                     $thisfile_asf_audiomedia_currentstream['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $thisfile_asf_audiomedia_currentstream['codec_data_size']);
                     $audiomediaoffset += $thisfile_asf_audiomedia_currentstream['codec_data_size'];
                     break;
                 case GETID3_ASF_Video_Media:
                     // Field Name                   Field Type   Size (bits)
                     // Encoded Image Width          DWORD        32              // width of image in pixels
                     // Encoded Image Height         DWORD        32              // height of image in pixels
                     // Reserved Flags               BYTE         8               // hardcoded: 0x02
                     // Format Data Size             WORD         16              // size of Format Data field in bytes
                     // Format Data                  array of:    variable        //
                     // * Format Data Size           DWORD        32              // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
                     // * Image Width                LONG         32              // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
                     // * Image Height               LONG         32              // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
                     // * Reserved                   WORD         16              // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
                     // * Bits Per Pixel Count       WORD         16              // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
                     // * Compression ID             FOURCC       32              // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
                     // * Image Size                 DWORD        32              // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
                     // * Horizontal Pixels / Meter  DWORD        32              // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
                     // * Vertical Pixels / Meter    DWORD        32              // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
                     // * Colors Used Count          DWORD        32              // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
                     // * Important Colors Count     DWORD        32              // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure
                     // * Codec Specific Data        BYTESTREAM   variable        // array of codec-specific data bytes
                     // shortcut
                     $thisfile_asf['video_media'][$streamnumber] = array();
                     $thisfile_asf_videomedia_currentstream =& $thisfile_asf['video_media'][$streamnumber];
                     $videomediaoffset = 0;
                     $thisfile_asf_videomedia_currentstream['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['flags'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1));
                     $videomediaoffset += 1;
                     $thisfile_asf_videomedia_currentstream['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
                     $videomediaoffset += 2;
                     $thisfile_asf_videomedia_currentstream['format_data']['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['reserved'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
                     $videomediaoffset += 2;
                     $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
                     $videomediaoffset += 2;
                     $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4);
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['image_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['horizontal_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['vertical_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['colors_used'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['colors_important'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
                     $videomediaoffset += 4;
                     $thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset);
                     $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']);
                     $thisfile_video['fourcc'] = $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'];
                     $thisfile_video['codec'] = $thisfile_asf_videomedia_currentstream['format_data']['codec'];
                     $thisfile_video['resolution_x'] = $thisfile_asf_videomedia_currentstream['image_width'];
                     $thisfile_video['resolution_y'] = $thisfile_asf_videomedia_currentstream['image_height'];
                     $thisfile_video['bits_per_sample'] = $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'];
                     break;
                 default:
                     break;
             }
         }
     }
     while (ftell($fd) < $ThisFileInfo['avdataend']) {
         $NextObjectDataHeader = fread($fd, 24);
         $offset = 0;
         $NextObjectGUID = substr($NextObjectDataHeader, 0, 16);
         $offset += 16;
         $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
         $NextObjectSize = getid3_lib::LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8));
         $offset += 8;
         switch ($NextObjectGUID) {
             case GETID3_ASF_Data_Object:
                 // Data Object: (mandatory, one only)
                 // Field Name                       Field Type   Size (bits)
                 // Object ID                        GUID         128             // GUID for Data object - GETID3_ASF_Data_Object
                 // Object Size                      QWORD        64              // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
                 // File ID                          GUID         128             // unique identifier. identical to File ID field in Header Object
                 // Total Data Packets               QWORD        64              // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
                 // Reserved                         WORD         16              // hardcoded: 0x0101
                 // shortcut
                 $thisfile_asf['data_object'] = array();
                 $thisfile_asf_dataobject =& $thisfile_asf['data_object'];
                 $DataObjectData = $NextObjectDataHeader . fread($fd, 50 - 24);
                 $offset = 24;
                 $thisfile_asf_dataobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_dataobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_dataobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_dataobject['fileid'] = substr($DataObjectData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_dataobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_dataobject['fileid']);
                 $thisfile_asf_dataobject['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 8));
                 $offset += 8;
                 $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2));
                 $offset += 2;
                 if ($thisfile_asf_dataobject['reserved'] != 0x101) {
                     $ThisFileInfo['warning'][] = 'data_object.reserved (' . getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']) . ') does not match expected value of "0x0101"';
                     //return false;
                     break;
                 }
                 // Data Packets                     array of:    variable        //
                 // * Error Correction Flags         BYTE         8               //
                 // * * Error Correction Data Length bits         4               // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
                 // * * Opaque Data Present          bits         1               //
                 // * * Error Correction Length Type bits         2               // number of bits for size of the error correction data. hardcoded: 00
                 // * * Error Correction Present     bits         1               // If set, use Opaque Data Packet structure, else use Payload structure
                 // * Error Correction Data
                 $ThisFileInfo['avdataoffset'] = ftell($fd);
                 fseek($fd, $thisfile_asf_dataobject['objectsize'] - 50, SEEK_CUR);
                 // skip actual audio/video data
                 $ThisFileInfo['avdataend'] = ftell($fd);
                 break;
             case GETID3_ASF_Simple_Index_Object:
                 // Simple Index Object: (optional, recommended, one per video stream)
                 // Field Name                       Field Type   Size (bits)
                 // Object ID                        GUID         128             // GUID for Simple Index object - GETID3_ASF_Data_Object
                 // Object Size                      QWORD        64              // size of Simple Index object, including 56 bytes of Simple Index Object header
                 // File ID                          GUID         128             // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
                 // Index Entry Time Interval        QWORD        64              // interval between index entries in 100-nanosecond units
                 // Maximum Packet Count             DWORD        32              // maximum packet count for all index entries
                 // Index Entries Count              DWORD        32              // number of Index Entries structures
                 // Index Entries                    array of:    variable        //
                 // * Packet Number                  DWORD        32              // number of the Data Packet associated with this index entry
                 // * Packet Count                   WORD         16              // number of Data Packets to sent at this index entry
                 // shortcut
                 $thisfile_asf['simple_index_object'] = array();
                 $thisfile_asf_simpleindexobject =& $thisfile_asf['simple_index_object'];
                 $SimpleIndexObjectData = $NextObjectDataHeader . fread($fd, 56 - 24);
                 $offset = 24;
                 $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_simpleindexobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_simpleindexobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_simpleindexobject['fileid'] = substr($SimpleIndexObjectData, $offset, 16);
                 $offset += 16;
                 $thisfile_asf_simpleindexobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_simpleindexobject['fileid']);
                 $thisfile_asf_simpleindexobject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8));
                 $offset += 8;
                 $thisfile_asf_simpleindexobject['maximum_packet_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
                 $offset += 4;
                 $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
                 $offset += 4;
                 $IndexEntriesData = $SimpleIndexObjectData . fread($fd, 6 * $thisfile_asf_simpleindexobject['index_entries_count']);
                 for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) {
                     $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
                     $offset += 4;
                     $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
                     $offset += 2;
                 }
                 break;
             case GETID3_ASF_Index_Object:
                 // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
                 // Field Name                       Field Type   Size (bits)
                 // Object ID                        GUID         128             // GUID for the Index Object - GETID3_ASF_Index_Object
                 // Object Size                      QWORD        64              // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
                 // Index Entry Time Interval        DWORD        32              // Specifies the time interval between each index entry in ms.
                 // Index Specifiers Count           WORD         16              // Specifies the number of Index Specifiers structures in this Index Object.
                 // Index Blocks Count               DWORD        32              // Specifies the number of Index Blocks structures in this Index Object.
                 // Index Entry Time Interval        DWORD        32              // Specifies the time interval between index entries in milliseconds.  This value cannot be 0.
                 // Index Specifiers Count           WORD         16              // Specifies the number of entries in the Index Specifiers list.  Valid values are 1 and greater.
                 // Index Specifiers                 array of:    varies          //
                 // * Stream Number                  WORD         16              // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127.
                 // * Index Type                     WORD         16              // Specifies Index Type values as follows:
                 //   1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
                 //   2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
                 //   3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set.
                 //   Nearest Past Cleanpoint is the most common type of index.
                 // Index Entry Count                DWORD        32              // Specifies the number of Index Entries in the block.
                 // * Block Positions                QWORD        varies          // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed.
                 // * Index Entries                  array of:    varies          //
                 // * * Offsets                      DWORD        varies          // An offset value of 0xffffffff indicates an invalid offset value
                 // shortcut
                 $thisfile_asf['asf_index_object'] = array();
                 $thisfile_asf_asfindexobject =& $thisfile_asf['asf_index_object'];
                 $ASFIndexObjectData = $NextObjectDataHeader . fread($fd, 34 - 24);
                 $offset = 24;
                 $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID;
                 $thisfile_asf_asfindexobject['objectid_guid'] = $NextObjectGUIDtext;
                 $thisfile_asf_asfindexobject['objectsize'] = $NextObjectSize;
                 $thisfile_asf_asfindexobject['entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                 $offset += 4;
                 $thisfile_asf_asfindexobject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
                 $offset += 2;
                 $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                 $offset += 4;
                 $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count']);
                 for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
                     $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber;
                     $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
                     $offset += 2;
                     $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']);
                 }
                 $ASFIndexObjectData .= fread($fd, 4);
                 $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                 $offset += 4;
                 $ASFIndexObjectData .= fread($fd, 8 * $thisfile_asf_asfindexobject['index_specifiers_count']);
                 for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
                     $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8));
                     $offset += 8;
                 }
                 $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']);
                 for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) {
                     for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) {
                         $thisfile_asf_asfindexobject['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
                         $offset += 4;
                     }
                 }
                 break;
             default:
                 // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
                 if ($this->GUIDname($NextObjectGUIDtext)) {
                     $ThisFileInfo['warning'][] = 'unhandled GUID "' . $this->GUIDname($NextObjectGUIDtext) . '" {' . $NextObjectGUIDtext . '} in ASF body at offset ' . ($offset - 16 - 8);
                 } else {
                     $ThisFileInfo['warning'][] = 'unknown GUID {' . $NextObjectGUIDtext . '} in ASF body at offset ' . (ftell($fd) - 16 - 8);
                 }
                 fseek($fd, $NextObjectSize - 16 - 8, SEEK_CUR);
                 break;
         }
     }
     if (isset($thisfile_asf_codeclistobject['codec_entries']) && is_array($thisfile_asf_codeclistobject['codec_entries'])) {
         foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
             switch ($streamdata['information']) {
                 case 'WMV1':
                 case 'WMV2':
                 case 'WMV3':
                     $thisfile_video['dataformat'] = 'wmv';
                     $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
                     break;
                 case 'MP42':
                 case 'MP43':
                 case 'MP4S':
                 case 'mp4s':
                     $thisfile_video['dataformat'] = 'asf';
                     $ThisFileInfo['mime_type'] = 'video/x-ms-asf';
                     break;
                 default:
                     switch ($streamdata['type_raw']) {
                         case 1:
                             if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
                                 $thisfile_video['dataformat'] = 'wmv';
                                 if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
                                     $ThisFileInfo['mime_type'] = 'video/x-ms-wmv';
                                 }
                             }
                             break;
                         case 2:
                             if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
                                 $thisfile_audio['dataformat'] = 'wma';
                                 if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') {
                                     $ThisFileInfo['mime_type'] = 'audio/x-ms-wma';
                                 }
                             }
                             break;
                     }
                     break;
             }
         }
     }
     switch ($thisfile_audio['codec']) {
         case 'MPEG Layer-3':
             $thisfile_audio['dataformat'] = 'mp3';
             break;
         default:
             break;
     }
     if (isset($thisfile_asf_codeclistobject['codec_entries'])) {
         foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
             switch ($streamdata['type_raw']) {
                 case 1:
                     // video
                     $thisfile_video['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
                     break;
                 case 2:
                     // audio
                     $thisfile_audio['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
                     // AH 2003-10-01
                     $thisfile_audio['encoder_options'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][0]['description']);
                     $thisfile_audio['codec'] = $thisfile_audio['encoder'];
                     break;
                 default:
                     $ThisFileInfo['warning'][] = 'Unknown streamtype: [codec_list_object][codec_entries][' . $streamnumber . '][type_raw] == ' . $streamdata['type_raw'];
                     break;
             }
         }
     }
     if (isset($ThisFileInfo['audio'])) {
         $thisfile_audio['lossless'] = isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false;
         $thisfile_audio['dataformat'] = !empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf';
     }
     if (!empty($thisfile_video['dataformat'])) {
         $thisfile_video['lossless'] = isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false;
         $thisfile_video['pixel_aspect_ratio'] = isset($thisfile_audio['pixel_aspect_ratio']) ? $thisfile_audio['pixel_aspect_ratio'] : (double) 1;
         $thisfile_video['dataformat'] = !empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf';
     }
     return true;
 }