Esempio n. 1
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $au_header = fread($getid3->fp, 8);
     // Magic bytes: .snd
     $getid3->info['au'] = array();
     $info_au =& $getid3->info['au'];
     $getid3->info['fileformat'] = 'au';
     $getid3->info['audio']['dataformat'] = 'au';
     $getid3->info['audio']['bitrate_mode'] = 'cbr';
     $info_au['encoding'] = 'ISO-8859-1';
     $info_au['header_length'] = getid3_lib::BigEndian2Int(substr($au_header, 4, 4));
     $au_header .= fread($getid3->fp, $info_au['header_length'] - 8);
     $getid3->info['avdataoffset'] += $info_au['header_length'];
     getid3_lib::ReadSequence('BigEndian2Int', $info_au, $au_header, 8, array('data_size' => 4, 'data_format_id' => 4, 'sample_rate' => 4, 'channels' => 4));
     $info_au['comments']['comment'][] = trim(substr($au_header, 24));
     $info_au['data_format'] = getid3_au::AUdataFormatNameLookup($info_au['data_format_id']);
     $info_au['used_bits_per_sample'] = getid3_au::AUdataFormatUsedBitsPerSampleLookup($info_au['data_format_id']);
     if ($info_au['bits_per_sample'] = getid3_au::AUdataFormatBitsPerSampleLookup($info_au['data_format_id'])) {
         $getid3->info['audio']['bits_per_sample'] = $info_au['bits_per_sample'];
     } else {
         unset($info_au['bits_per_sample']);
     }
     $getid3->info['audio']['sample_rate'] = $info_au['sample_rate'];
     $getid3->info['audio']['channels'] = $info_au['channels'];
     if ($getid3->info['avdataoffset'] + $info_au['data_size'] > $getid3->info['avdataend']) {
         $getid3->warning('Possible truncated file - expecting "' . $info_au['data_size'] . '" bytes of audio data, only found ' . ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) . ' bytes"');
     }
     $getid3->info['playtime_seconds'] = $info_au['data_size'] / ($info_au['sample_rate'] * $info_au['channels'] * ($info_au['used_bits_per_sample'] / 8));
     $getid3->info['audio']['bitrate'] = $info_au['data_size'] * 8 / $getid3->info['playtime_seconds'];
     return true;
 }
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->info['fileformat'] = 'tta';
     $getid3->info['audio']['dataformat'] = 'tta';
     $getid3->info['audio']['lossless'] = true;
     $getid3->info['audio']['bitrate_mode'] = 'vbr';
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $tta_header = fread($getid3->fp, 26);
     $getid3->info['tta']['magic'] = 'TTA';
     // Magic bytes
     switch ($tta_header[3]) {
         case "":
             // TTA v1.x
         // TTA v1.x
         case "":
             // TTA v1.x
         // TTA v1.x
         case "":
             // TTA v1.x
             // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year."
             $getid3->info['tta']['major_version'] = 1;
             $getid3->info['avdataoffset'] += 16;
             getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array('channels' => 2, 'bits_per_sample' => 2, 'sample_rate' => 4, 'samples_per_channel' => 4));
             $getid3->info['tta']['compression_level'] = ord($tta_header[3]);
             $getid3->info['audio']['encoder_options'] = '-e' . $getid3->info['tta']['compression_level'];
             $getid3->info['playtime_seconds'] = $getid3->info['tta']['samples_per_channel'] / $getid3->info['tta']['sample_rate'];
             break;
         case '2':
             // TTA v2.x
             // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4."
             $getid3->info['tta']['major_version'] = 2;
             $getid3->info['avdataoffset'] += 20;
             getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array('compression_level' => 2, 'audio_format' => 2, 'channels' => 2, 'bits_per_sample' => 2, 'sample_rate' => 4, 'data_length' => 4));
             $getid3->info['audio']['encoder_options'] = '-e' . $getid3->info['tta']['compression_level'];
             $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate'];
             break;
         case '1':
             // TTA v3.x
             // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher."
             $getid3->info['tta']['major_version'] = 3;
             $getid3->info['avdataoffset'] += 26;
             getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, array('audio_format' => 2, 'channels' => 2, 'bits_per_sample' => 2, 'sample_rate' => 4, 'data_length' => 4, 'crc32_footer' => -4, 'seek_point' => 4));
             $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate'];
             break;
         default:
             throw new getid3_exception('This version of getID3() only knows how to handle TTA v1, v2 and v3 - it may not work correctly with this file which appears to be TTA v' . $tta_header[3]);
             return false;
             break;
     }
     $getid3->info['audio']['encoder'] = 'TTA v' . $getid3->info['tta']['major_version'];
     $getid3->info['audio']['bits_per_sample'] = $getid3->info['tta']['bits_per_sample'];
     $getid3->info['audio']['sample_rate'] = $getid3->info['tta']['sample_rate'];
     $getid3->info['audio']['channels'] = $getid3->info['tta']['channels'];
     $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     return true;
 }
 public function Analyze()
 {
     $getid3 = $this->getid3;
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $rkau_header = fread($getid3->fp, 20);
     // Magic bytes 'RKA'
     $getid3->info['fileformat'] = 'rkau';
     $getid3->info['audio']['dataformat'] = 'rkau';
     $getid3->info['audio']['bitrate_mode'] = 'vbr';
     // Shortcut
     $getid3->info['rkau'] = array();
     $info_rkau =& $getid3->info['rkau'];
     $info_rkau['raw']['version'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 3, 1));
     $info_rkau['version'] = '1.' . str_pad($info_rkau['raw']['version'] & 0xf, 2, '0', STR_PAD_LEFT);
     if ($info_rkau['version'] > 1.07 || $info_rkau['version'] < 1.06) {
         throw new getid3_exception('This version of getID3() can only parse RKAU files v1.06 and 1.07 (this file is v' . $info_rkau['version'] . ')');
     }
     getid3_lib::ReadSequence('LittleEndian2Int', $info_rkau, $rkau_header, 4, array('source_bytes' => 4, 'sample_rate' => 4, 'channels' => 1, 'bits_per_sample' => 1));
     $info_rkau['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 14, 1));
     $quality = $info_rkau['raw']['quality'] & 0xf;
     $info_rkau['lossless'] = $quality == 0 ? true : false;
     $info_rkau['compression_level'] = (($info_rkau['raw']['quality'] & 0xf0) >> 4) + 1;
     if (!$info_rkau['lossless']) {
         $info_rkau['quality_setting'] = $quality;
     }
     $info_rkau['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 15, 1));
     $info_rkau['flags']['joint_stereo'] = (bool) (!($info_rkau['raw']['flags'] & 0x1));
     $info_rkau['flags']['streaming'] = (bool) ($info_rkau['raw']['flags'] & 0x2);
     $info_rkau['flags']['vrq_lossy_mode'] = (bool) ($info_rkau['raw']['flags'] & 0x4);
     if ($info_rkau['flags']['streaming']) {
         $getid3->info['avdataoffset'] += 20;
         $info_rkau['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 16, 4));
     } else {
         $getid3->info['avdataoffset'] += 16;
         $info_rkau['compressed_bytes'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'] - 1;
     }
     // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes,
     // sometimes it's more, sometimes less. No idea why(?)
     $getid3->info['audio']['lossless'] = $info_rkau['lossless'];
     $getid3->info['audio']['channels'] = $info_rkau['channels'];
     $getid3->info['audio']['bits_per_sample'] = $info_rkau['bits_per_sample'];
     $getid3->info['audio']['sample_rate'] = $info_rkau['sample_rate'];
     $getid3->info['playtime_seconds'] = $info_rkau['source_bytes'] / ($info_rkau['sample_rate'] * $info_rkau['channels'] * ($info_rkau['bits_per_sample'] / 8));
     $getid3->info['audio']['bitrate'] = $info_rkau['compressed_bytes'] * 8 / $getid3->info['playtime_seconds'];
     return true;
 }
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->info['fileformat'] = 'gif';
     $getid3->info['video']['dataformat'] = 'gif';
     $getid3->info['video']['lossless'] = true;
     $getid3->info['video']['pixel_aspect_ratio'] = (double) 1;
     $getid3->info['gif']['header'] = array();
     $info_gif_header =& $getid3->info['gif']['header'];
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $gif_header = fread($getid3->fp, 13);
     // Magic bytes
     $info_gif_header['raw']['identifier'] = 'GIF';
     getid3_lib::ReadSequence('LittleEndian2Int', $info_gif_header['raw'], $gif_header, 3, array('version' => -3, 'width' => 2, 'height' => 2, 'flags' => 1, 'bg_color_index' => 1, 'aspect_ratio' => 1));
     $getid3->info['video']['resolution_x'] = $info_gif_header['raw']['width'];
     $getid3->info['video']['resolution_y'] = $info_gif_header['raw']['height'];
     $getid3->info['gif']['version'] = $info_gif_header['raw']['version'];
     $info_gif_header['flags']['global_color_table'] = (bool) ($info_gif_header['raw']['flags'] & 0x80);
     if ($info_gif_header['raw']['flags'] & 0x80) {
         // Number of bits per primary color available to the original image, minus 1
         $info_gif_header['bits_per_pixel'] = 3 * ((($info_gif_header['raw']['flags'] & 0x70) >> 4) + 1);
     } else {
         $info_gif_header['bits_per_pixel'] = 0;
     }
     $info_gif_header['flags']['global_color_sorted'] = (bool) ($info_gif_header['raw']['flags'] & 0x40);
     if ($info_gif_header['flags']['global_color_table']) {
         // the number of bytes contained in the Global Color Table. To determine that
         // actual size of the color table, raise 2 to [the value of the field + 1]
         $info_gif_header['global_color_size'] = pow(2, ($info_gif_header['raw']['flags'] & 0x7) + 1);
         $getid3->info['video']['bits_per_sample'] = ($info_gif_header['raw']['flags'] & 0x7) + 1;
     } else {
         $info_gif_header['global_color_size'] = 0;
     }
     if ($info_gif_header['raw']['aspect_ratio'] != 0) {
         // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64
         $info_gif_header['aspect_ratio'] = ($info_gif_header['raw']['aspect_ratio'] + 15) / 64;
     }
     return true;
 }
Esempio n. 5
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->info['midi']['raw'] = array();
     $info_midi =& $getid3->info['midi'];
     $info_midi_raw =& $info_midi['raw'];
     $getid3->info['fileformat'] = 'midi';
     $getid3->info['audio']['dataformat'] = 'midi';
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $midi_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
     // Magic bytes: 'MThd'
     getid3_lib::ReadSequence('BigEndian2Int', $info_midi_raw, $midi_data, 4, array('headersize' => 4, 'fileformat' => 2, 'tracks' => 2, 'ticksperqnote' => 2));
     $offset = 14;
     for ($i = 0; $i < $info_midi_raw['tracks']; $i++) {
         if (strlen($midi_data) - $offset < 8) {
             $midi_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
         }
         $track_id = substr($midi_data, $offset, 4);
         $offset += 4;
         if ($track_id != 'MTrk') {
             throw new getid3_exception('Expecting "MTrk" at ' . $offset . ', found ' . $track_id . ' instead');
         }
         $track_size = getid3_lib::BigEndian2Int(substr($midi_data, $offset, 4));
         $offset += 4;
         $track_data_array[$i] = substr($midi_data, $offset, $track_size);
         $offset += $track_size;
     }
     if (!isset($track_data_array) || !is_array($track_data_array)) {
         throw new getid3_exception('Cannot find MIDI track information');
     }
     $info_midi['totalticks'] = 0;
     $getid3->info['playtime_seconds'] = 0;
     $current_ms_per_beat = 500000;
     // 120 beats per minute;  60,000,000 microseconds per minute -> 500,000 microseconds per beat
     $current_beats_per_min = 120;
     // 120 beats per minute;  60,000,000 microseconds per minute -> 500,000 microseconds per beat
     $ms_per_quarter_note_after = array();
     foreach ($track_data_array as $track_number => $track_data) {
         $events_offset = $last_issued_midi_command = $last_issued_midi_channel = $cumulative_delta_time = $ticks_at_current_bpm = 0;
         while ($events_offset < strlen($track_data)) {
             $event_id = 0;
             if (isset($midi_events[$track_number]) && is_array($midi_events[$track_number])) {
                 $event_id = count($midi_events[$track_number]);
             }
             $delta_time = 0;
             for ($i = 0; $i < 4; $i++) {
                 $delta_time_byte = ord($track_data[$events_offset++]);
                 $delta_time = ($delta_time << 7) + ($delta_time_byte & 0x7f);
                 if ($delta_time_byte & 0x80) {
                     // another byte follows
                 } else {
                     break;
                 }
             }
             $cumulative_delta_time += $delta_time;
             $ticks_at_current_bpm += $delta_time;
             $midi_events[$track_number][$event_id]['deltatime'] = $delta_time;
             $midi_event_channel = ord($track_data[$events_offset++]);
             // OK, normal event - MIDI command has MSB set
             if ($midi_event_channel & 0x80) {
                 $last_issued_midi_command = $midi_event_channel >> 4;
                 $last_issued_midi_channel = $midi_event_channel & 0xf;
             } else {
                 $events_offset--;
             }
             $midi_events[$track_number][$event_id]['eventid'] = $last_issued_midi_command;
             $midi_events[$track_number][$event_id]['channel'] = $last_issued_midi_channel;
             switch ($midi_events[$track_number][$event_id]['eventid']) {
                 case 0x8:
                     // Note off (key is released)
                 // Note off (key is released)
                 case 0x9:
                     // Note on (key is pressed)
                 // Note on (key is pressed)
                 case 0xa:
                     // Key after-touch
                     //$notenumber = ord($track_data{$events_offset++});
                     //$velocity   = ord($track_data{$events_offset++});
                     $events_offset += 2;
                     break;
                 case 0xb:
                     // Control Change
                     //$controllernum = ord($track_data{$events_offset++});
                     //$newvalue      = ord($track_data{$events_offset++});
                     $events_offset += 2;
                     break;
                 case 0xc:
                     // Program (patch) change
                     $new_program_num = ord($track_data[$events_offset++]);
                     $info_midi_raw['track'][$track_number]['instrumentid'] = $new_program_num;
                     $info_midi_raw['track'][$track_number]['instrument'] = $track_number == 10 ? getid3_midi::GeneralMIDIpercussionLookup($new_program_num) : getid3_midi::GeneralMIDIinstrumentLookup($new_program_num);
                     break;
                 case 0xd:
                     // Channel after-touch
                     //$channelnumber = ord($track_data{$events_offset++});
                     break;
                 case 0xe:
                     // Pitch wheel change (2000H is normal or no change)
                     //$changeLSB = ord($track_data{$events_offset++});
                     //$changeMSB = ord($track_data{$events_offset++});
                     //$pitchwheelchange = (($changeMSB & 0x7F) << 7) & ($changeLSB & 0x7F);
                     $events_offset += 2;
                     break;
                 case 0xf:
                     if ($midi_events[$track_number][$event_id]['channel'] == 0xf) {
                         $meta_event_command = ord($track_data[$events_offset++]);
                         $meta_event_length = ord($track_data[$events_offset++]);
                         $meta_event_data = substr($track_data, $events_offset, $meta_event_length);
                         $events_offset += $meta_event_length;
                         switch ($meta_event_command) {
                             case 0x0:
                                 // Set track sequence number
                                 //$track_sequence_number = getid3_lib::BigEndian2Int(substr($meta_event_data, 0, $meta_event_length));
                                 //$info_midi_raw['events'][$track_number][$event_id]['seqno'] = $track_sequence_number;
                                 break;
                             case 0x1:
                                 // Text: generic
                                 $text_generic = substr($meta_event_data, 0, $meta_event_length);
                                 //$info_midi_raw['events'][$track_number][$event_id]['text'] = $text_generic;
                                 $info_midi['comments']['comment'][] = $text_generic;
                                 break;
                             case 0x2:
                                 // Text: copyright
                                 $text_copyright = substr($meta_event_data, 0, $meta_event_length);
                                 //$info_midi_raw['events'][$track_number][$event_id]['copyright'] = $text_copyright;
                                 $info_midi['comments']['copyright'][] = $text_copyright;
                                 break;
                             case 0x3:
                                 // Text: track name
                                 $text_trackname = substr($meta_event_data, 0, $meta_event_length);
                                 $info_midi_raw['track'][$track_number]['name'] = $text_trackname;
                                 break;
                             case 0x4:
                                 // Text: track instrument name
                                 //$text_instrument = substr($meta_event_data, 0, $meta_event_length);
                                 //$info_midi_raw['events'][$track_number][$event_id]['instrument'] = $text_instrument;
                                 break;
                             case 0x5:
                                 // Text: lyrics
                                 $text_lyrics = substr($meta_event_data, 0, $meta_event_length);
                                 //$info_midi_raw['events'][$track_number][$event_id]['lyrics'] = $text_lyrics;
                                 if (!isset($info_midi['lyrics'])) {
                                     $info_midi['lyrics'] = '';
                                 }
                                 $info_midi['lyrics'] .= $text_lyrics . "\n";
                                 break;
                             case 0x6:
                                 // Text: marker
                                 //$text_marker = substr($meta_event_data, 0, $meta_event_length);
                                 //$info_midi_raw['events'][$track_number][$event_id]['marker'] = $text_marker;
                                 break;
                             case 0x7:
                                 // Text: cue point
                                 //$text_cuepoint = substr($meta_event_data, 0, $meta_event_length);
                                 //$info_midi_raw['events'][$track_number][$event_id]['cuepoint'] = $text_cuepoint;
                                 break;
                             case 0x2f:
                                 // End Of Track
                                 //$info_midi_raw['events'][$track_number][$event_id]['EOT'] = $cumulative_delta_time;
                                 break;
                             case 0x51:
                                 // Tempo: microseconds / quarter note
                                 $current_ms_per_beat = getid3_lib::BigEndian2Int(substr($meta_event_data, 0, $meta_event_length));
                                 $info_midi_raw['events'][$track_number][$cumulative_delta_time]['us_qnote'] = $current_ms_per_beat;
                                 $current_beats_per_min = 1000000 / $current_ms_per_beat * 60;
                                 $ms_per_quarter_note_after[$cumulative_delta_time] = $current_ms_per_beat;
                                 $ticks_at_current_bpm = 0;
                                 break;
                             case 0x58:
                                 // Time signature
                                 $timesig_numerator = getid3_lib::BigEndian2Int($meta_event_data[0]);
                                 $timesig_denominator = pow(2, getid3_lib::BigEndian2Int($meta_event_data[1]));
                                 // $02 -> x/4, $03 -> x/8, etc
                                 //$timesig_32inqnote   = getid3_lib::BigEndian2Int($meta_event_data[2]);         // number of 32nd notes to the quarter note
                                 //$info_midi_raw['events'][$track_number][$event_id]['timesig_32inqnote']   = $timesig_32inqnote;
                                 //$info_midi_raw['events'][$track_number][$event_id]['timesig_numerator']   = $timesig_numerator;
                                 //$info_midi_raw['events'][$track_number][$event_id]['timesig_denominator'] = $timesig_denominator;
                                 //$info_midi_raw['events'][$track_number][$event_id]['timesig_text']        = $timesig_numerator.'/'.$timesig_denominator;
                                 $info_midi['timesignature'][] = $timesig_numerator . '/' . $timesig_denominator;
                                 break;
                             case 0x59:
                                 // Keysignature
                                 $keysig_sharpsflats = getid3_lib::BigEndian2Int($meta_event_data[0]);
                                 if ($keysig_sharpsflats & 0x80) {
                                     // (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps)
                                     $keysig_sharpsflats -= 256;
                                 }
                                 $keysig_majorminor = getid3_lib::BigEndian2Int($meta_event_data[1]);
                                 // 0 -> major, 1 -> minor
                                 $keysigs = array(-7 => 'Cb', -6 => 'Gb', -5 => 'Db', -4 => 'Ab', -3 => 'Eb', -2 => 'Bb', -1 => 'F', 0 => 'C', 1 => 'G', 2 => 'D', 3 => 'A', 4 => 'E', 5 => 'B', 6 => 'F#', 7 => 'C#');
                                 //$info_midi_raw['events'][$track_number][$event_id]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0);
                                 //$info_midi_raw['events'][$track_number][$event_id]['keysig_flats']  = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0);
                                 //$info_midi_raw['events'][$track_number][$event_id]['keysig_minor']  = (bool)$keysig_majorminor;
                                 //$info_midi_raw['events'][$track_number][$event_id]['keysig_text']   = $keysigs[$keysig_sharpsflats].' '.($info_midi_raw['events'][$track_number][$event_id]['keysig_minor'] ? 'minor' : 'major');
                                 // $keysigs[$keysig_sharpsflats] gets an int key (correct) - $keysigs["$keysig_sharpsflats"] gets a string key (incorrect)
                                 $info_midi['keysignature'][] = $keysigs[$keysig_sharpsflats] . ' ' . ((bool) $keysig_majorminor ? 'minor' : 'major');
                                 break;
                             case 0x7f:
                                 // Sequencer specific information
                                 $custom_data = substr($meta_event_data, 0, $meta_event_length);
                                 break;
                             default:
                                 $getid3->warning('Unhandled META Event Command: ' . $meta_event_command);
                         }
                     }
                     break;
                 default:
                     $getid3->warning('Unhandled MIDI Event ID: ' . $midi_events[$track_number][$event_id]['eventid']);
             }
         }
         if ($track_number > 0 || count($track_data_array) == 1) {
             $info_midi['totalticks'] = max($info_midi['totalticks'], $cumulative_delta_time);
         }
     }
     $previous_tick_offset = null;
     ksort($ms_per_quarter_note_after);
     foreach ($ms_per_quarter_note_after as $tick_offset => $ms_per_beat) {
         if (is_null($previous_tick_offset)) {
             $prev_ms_per_beat = $ms_per_beat;
             $previous_tick_offset = $tick_offset;
             continue;
         }
         if ($info_midi['totalticks'] > $tick_offset) {
             $getid3->info['playtime_seconds'] += ($tick_offset - $previous_tick_offset) / $info_midi_raw['ticksperqnote'] * ($prev_ms_per_beat / 1000000);
             $prev_ms_per_beat = $ms_per_beat;
             $previous_tick_offset = $tick_offset;
         }
     }
     if ($info_midi['totalticks'] > $previous_tick_offset) {
         $getid3->info['playtime_seconds'] += ($info_midi['totalticks'] - $previous_tick_offset) / $info_midi_raw['ticksperqnote'] * ($ms_per_beat / 1000000);
     }
     if (@$getid3->info['playtime_seconds'] > 0) {
         $getid3->info['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     }
     if (!empty($info_midi['lyrics'])) {
         $info_midi['comments']['lyrics'][] = $info_midi['lyrics'];
     }
     return true;
 }
Esempio n. 6
0
 protected function ParseAPEheaderFooter($data, &$target)
 {
     // http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html
     if (substr($data, 0, 8) != 'APETAGEX') {
         return false;
     }
     // shortcut
     $target['raw'] = array();
     $target_raw =& $target['raw'];
     $target_raw['footer_tag'] = 'APETAGEX';
     getid3_lib::ReadSequence("LittleEndian2Int", $target_raw, $data, 8, array('version' => 4, 'tagsize' => 4, 'tag_items' => 4, 'global_flags' => 4));
     $target_raw['reserved'] = substr($data, 24, 8);
     $target['tag_version'] = $target_raw['version'] / 1000;
     if ($target['tag_version'] >= 2) {
         $target['flags'] = $this->ParseAPEtagFlags($target_raw['global_flags']);
     }
     return true;
 }
 private function ZIPparseEndOfCentralDirectory()
 {
     // shortcut
     $getid3 = $this->getid3;
     $end_of_central_directory['offset'] = ftell($getid3->fp);
     $zip_end_of_central_directory = fread($getid3->fp, 22);
     $end_of_central_directory['signature'] = getid3_lib::LittleEndian2Int(substr($zip_end_of_central_directory, 0, 4));
     // invalid End Of Central Directory Signature
     if ($end_of_central_directory['signature'] != 0x6054b50) {
         fseek($getid3->fp, $end_of_central_directory['offset'], SEEK_SET);
         // seek back to where filepointer originally was so it can be handled properly
         return false;
     }
     getid3_lib::ReadSequence('LittleEndian2Int', $end_of_central_directory, $zip_end_of_central_directory, 4, array('disk_number_current' => 2, 'disk_number_start_directory' => 2, 'directory_entries_this_disk' => 2, 'directory_entries_total' => 2, 'directory_size' => 4, 'directory_offset' => 4, 'comment_length' => 2));
     if ($end_of_central_directory['comment_length'] > 0) {
         $end_of_central_directory['comment'] = fread($getid3->fp, $end_of_central_directory['comment_length']);
     }
     return $end_of_central_directory;
 }
Esempio n. 8
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $original_av_data_offset = $getid3->info['avdataoffset'];
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $voc_header = fread($getid3->fp, 26);
     // Magic bytes: 'Creative Voice File'
     $info_audio =& $getid3->info['audio'];
     $getid3->info['voc'] = array();
     $info_voc =& $getid3->info['voc'];
     $getid3->info['fileformat'] = 'voc';
     $info_audio['dataformat'] = 'voc';
     $info_audio['bitrate_mode'] = 'cbr';
     $info_audio['lossless'] = true;
     $info_audio['channels'] = 1;
     // might be overriden below
     $info_audio['bits_per_sample'] = 8;
     // might be overriden below
     // byte #     Description
     // ------     ------------------------------------------
     // 00-12      'Creative Voice File'
     // 13         1A (eof to abort printing of file)
     // 14-15      Offset of first datablock in .voc file (std 1A 00 in Intel Notation)
     // 16-17      Version number (minor,major) (VOC-HDR puts 0A 01)
     // 18-19      2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
     getid3_lib::ReadSequence('LittleEndian2Int', $info_voc['header'], $voc_header, 20, array('datablock_offset' => 2, 'minor_version' => 1, 'major_version' => 1));
     do {
         $block_offset = ftell($getid3->fp);
         $block_data = fread($getid3->fp, 4);
         $block_type = ord($block_data[0]);
         $block_size = getid3_lib::LittleEndian2Int(substr($block_data, 1, 3));
         $this_block = array();
         @$info_voc['blocktypes'][$block_type]++;
         switch ($block_type) {
             case 0:
                 // Terminator
                 // do nothing, we'll break out of the loop down below
                 break;
             case 1:
                 // Sound data
                 $block_data .= fread($getid3->fp, 2);
                 if ($getid3->info['avdataoffset'] <= $original_av_data_offset) {
                     $getid3->info['avdataoffset'] = ftell($getid3->fp);
                 }
                 fseek($getid3->fp, $block_size - 2, SEEK_CUR);
                 getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4, array('sample_rate_id' => 1, 'compression_type' => 1));
                 $this_block['compression_name'] = getid3_voc::VOCcompressionTypeLookup($this_block['compression_type']);
                 if ($this_block['compression_type'] <= 3) {
                     $info_voc['compressed_bits_per_sample'] = (int) str_replace('-bit', '', $this_block['compression_name']);
                 }
                 // Less accurate sample_rate calculation than the Extended block (#8) data (but better than nothing if Extended Block is not available)
                 if (empty($info_audio['sample_rate'])) {
                     // SR byte = 256 - (1000000 / sample_rate)
                     $info_audio['sample_rate'] = (int) floor(1000000 / (256 - $this_block['sample_rate_id']) / $info_audio['channels']);
                 }
                 break;
             case 2:
                 // Sound continue
             // Sound continue
             case 3:
                 // Silence
             // Silence
             case 4:
                 // Marker
             // Marker
             case 6:
                 // Repeat
             // Repeat
             case 7:
                 // End repeat
                 // nothing useful, just skip
                 fseek($getid3->fp, $block_size, SEEK_CUR);
                 break;
             case 8:
                 // Extended
                 $block_data .= fread($getid3->fp, 4);
                 //00-01  Time Constant:
                 //   Mono: 65536 - (256000000 / sample_rate)
                 // Stereo: 65536 - (256000000 / (sample_rate * 2))
                 getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4, array('time_constant' => 2, 'pack_method' => 1, 'stereo' => 1));
                 $this_block['stereo'] = (bool) $this_block['stereo'];
                 $info_audio['channels'] = $this_block['stereo'] ? 2 : 1;
                 $info_audio['sample_rate'] = (int) floor(256000000 / (65536 - $this_block['time_constant']) / $info_audio['channels']);
                 break;
             case 9:
                 // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit
                 $block_data .= fread($getid3->fp, 12);
                 if ($getid3->info['avdataoffset'] <= $original_av_data_offset) {
                     $getid3->info['avdataoffset'] = ftell($getid3->fp);
                 }
                 fseek($getid3->fp, $block_size - 12, SEEK_CUR);
                 getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4, array('sample_rate' => 4, 'bits_per_sample' => 1, 'channels' => 1, 'wFormat' => 2));
                 $this_block['compression_name'] = getid3_voc::VOCwFormatLookup($this_block['wFormat']);
                 if (getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat'])) {
                     $info_voc['compressed_bits_per_sample'] = getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat']);
                 }
                 $info_audio['sample_rate'] = $this_block['sample_rate'];
                 $info_audio['bits_per_sample'] = $this_block['bits_per_sample'];
                 $info_audio['channels'] = $this_block['channels'];
                 break;
             default:
                 $getid3->warning('Unhandled block type "' . $block_type . '" at offset ' . $block_offset);
                 fseek($getid3->fp, $block_size, SEEK_CUR);
                 break;
         }
         if (!empty($this_block)) {
             $this_block['block_offset'] = $block_offset;
             $this_block['block_size'] = $block_size;
             $this_block['block_type_id'] = $block_type;
             $info_voc['blocks'][] = $this_block;
         }
     } while (!feof($getid3->fp) && $block_type != 0);
     // Terminator block doesn't have size field, so seek back 3 spaces
     fseek($getid3->fp, -3, SEEK_CUR);
     ksort($info_voc['blocktypes']);
     if (!empty($info_voc['compressed_bits_per_sample'])) {
         $getid3->info['playtime_seconds'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / ($info_voc['compressed_bits_per_sample'] * $info_audio['channels'] * $info_audio['sample_rate']);
         $info_audio['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     }
     return true;
 }
Esempio n. 9
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     // based loosely on code from TTwinVQ by Jurgen Faul <jfaulØgmx*de>
     // http://jfaul.de/atl  or  http://j-faul.virtualave.net/atl/atl.html
     $getid3->info['fileformat'] = 'vqf';
     $getid3->info['audio']['dataformat'] = 'vqf';
     $getid3->info['audio']['bitrate_mode'] = 'cbr';
     $getid3->info['audio']['lossless'] = false;
     // Shortcuts
     $getid3->info['vqf']['raw'] = array();
     $info_vqf =& $getid3->info['vqf'];
     $info_vqf_raw =& $info_vqf['raw'];
     // Get header
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $vqf_header_data = fread($getid3->fp, 16);
     $info_vqf_raw['header_tag'] = 'TWIN';
     // Magic bytes
     $info_vqf_raw['version'] = substr($vqf_header_data, 4, 8);
     $info_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($vqf_header_data, 12, 4));
     while (ftell($getid3->fp) < $getid3->info['avdataend']) {
         $chunk_base_offset = ftell($getid3->fp);
         $chunk_data = fread($getid3->fp, 8);
         $chunk_name = substr($chunk_data, 0, 4);
         if ($chunk_name == 'DATA') {
             $getid3->info['avdataoffset'] = $chunk_base_offset;
             break;
         }
         $chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4));
         if ($chunk_size > $getid3->info['avdataend'] - ftell($getid3->fp)) {
             throw new getid3_exception('Invalid chunk size (' . $chunk_size . ') for chunk "' . $chunk_name . '" at offset 8.');
         }
         if ($chunk_size > 0) {
             $chunk_data .= fread($getid3->fp, $chunk_size);
         }
         switch ($chunk_name) {
             case 'COMM':
                 $info_vqf['COMM'] = array();
                 getid3_lib::ReadSequence('BigEndian2Int', $info_vqf['COMM'], $chunk_data, 8, array('channel_mode' => 4, 'bitrate' => 4, 'sample_rate' => 4, 'security_level' => 4));
                 $getid3->info['audio']['channels'] = $info_vqf['COMM']['channel_mode'] + 1;
                 $getid3->info['audio']['sample_rate'] = getid3_vqf::VQFchannelFrequencyLookup($info_vqf['COMM']['sample_rate']);
                 $getid3->info['audio']['bitrate'] = $info_vqf['COMM']['bitrate'] * 1000;
                 $getid3->info['audio']['encoder_options'] = 'CBR' . ceil($getid3->info['audio']['bitrate'] / 1000);
                 if ($getid3->info['audio']['bitrate'] == 0) {
                     throw new getid3_exception('Corrupt VQF file: bitrate_audio == zero');
                 }
                 break;
             case 'NAME':
             case 'AUTH':
             case '(c) ':
             case 'FILE':
             case 'COMT':
             case 'ALBM':
                 $info_vqf['comments'][getid3_vqf::VQFcommentNiceNameLookup($chunk_name)][] = trim(substr($chunk_data, 8));
                 break;
             case 'DSIZ':
                 $info_vqf['DSIZ'] = getid3_lib::BigEndian2Int(substr($chunk_data, 8, 4));
                 break;
             default:
                 $getid3->warning('Unhandled chunk type "' . $chunk_name . '" at offset 8');
                 break;
         }
     }
     $getid3->info['playtime_seconds'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['audio']['bitrate'];
     if (isset($info_vqf['DSIZ']) && $info_vqf['DSIZ'] != $getid3->info['avdataend'] - $getid3->info['avdataoffset'] - strlen('DATA')) {
         switch ($info_vqf['DSIZ']) {
             case 0:
             case 1:
                 $getid3->warning('Invalid DSIZ value "' . $info_vqf['DSIZ'] . '". This is known to happen with VQF files encoded by Ahead Nero, and seems to be its way of saying this is TwinVQF v' . ($info_vqf['DSIZ'] + 1) . '.0');
                 $getid3->info['audio']['encoder'] = 'Ahead Nero';
                 break;
             default:
                 $getid3->warning('Probable corrupted file - should be ' . $info_vqf['DSIZ'] . ' bytes, actually ' . ($getid3->info['avdataend'] - $getid3->info['avdataoffset'] - strlen('DATA')));
                 break;
         }
     }
     return true;
 }
Esempio n. 10
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;
 }
Esempio n. 11
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
     // all versions
     // WORD    bfType;
     // DWORD   bfSize;
     // WORD    bfReserved1;
     // WORD    bfReserved2;
     // DWORD   bfOffBits;
     // shortcuts
     $getid3->info['bmp']['header']['raw'] = array();
     $info_bmp =& $getid3->info['bmp'];
     $info_bmp_header =& $info_bmp['header'];
     $info_bmp_header_raw =& $info_bmp_header['raw'];
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $bmp_header = fread($getid3->fp, 14 + 40);
     // Magic bytes
     $info_bmp_header_raw['identifier'] = 'BM';
     getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 2, array('filesize' => 4, 'reserved1' => 2, 'reserved2' => 2, 'data_offset' => 4, 'header_size' => 4));
     // Check if the hardcoded-to-1 "planes" is at offset 22 or 26
     $planes22 = getid3_lib::LittleEndian2Int(substr($bmp_header, 22, 2));
     $planes26 = getid3_lib::LittleEndian2Int(substr($bmp_header, 26, 2));
     if ($planes22 == 1 && $planes26 != 1) {
         $info_bmp['type_os'] = 'OS/2';
         $info_bmp['type_version'] = 1;
     } elseif ($planes26 == 1 && $planes22 != 1) {
         $info_bmp['type_os'] = 'Windows';
         $info_bmp['type_version'] = 1;
     } elseif ($info_bmp_header_raw['header_size'] == 12) {
         $info_bmp['type_os'] = 'OS/2';
         $info_bmp['type_version'] = 1;
     } elseif ($info_bmp_header_raw['header_size'] == 40) {
         $info_bmp['type_os'] = 'Windows';
         $info_bmp['type_version'] = 1;
     } elseif ($info_bmp_header_raw['header_size'] == 84) {
         $info_bmp['type_os'] = 'Windows';
         $info_bmp['type_version'] = 4;
     } elseif ($info_bmp_header_raw['header_size'] == 100) {
         $info_bmp['type_os'] = 'Windows';
         $info_bmp['type_version'] = 5;
     } else {
         throw new getid3_exception('Unknown BMP subtype (or not a BMP file)');
     }
     $getid3->info['fileformat'] = 'bmp';
     $getid3->info['video']['dataformat'] = 'bmp';
     $getid3->info['video']['lossless'] = true;
     $getid3->info['video']['pixel_aspect_ratio'] = (double) 1;
     if ($info_bmp['type_os'] == 'OS/2') {
         // OS/2-format BMP
         // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm
         // DWORD  Size;             /* Size of this structure in bytes */
         // DWORD  Width;            /* Bitmap width in pixels */
         // DWORD  Height;           /* Bitmap height in pixel */
         // WORD   NumPlanes;        /* Number of bit planes (color depth) */
         // WORD   BitsPerPixel;     /* Number of bits per pixel per plane */
         getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18, array('width' => 2, 'height' => 2, 'planes' => 2, 'bits_per_pixel' => 2));
         $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width'];
         $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height'];
         $getid3->info['video']['codec'] = 'BI_RGB ' . $info_bmp_header_raw['bits_per_pixel'] . '-bit';
         $getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel'];
         if ($info_bmp['type_version'] >= 2) {
             // DWORD  Compression;      /* Bitmap compression scheme */
             // DWORD  ImageDataSize;    /* Size of bitmap data in bytes */
             // DWORD  XResolution;      /* X resolution of display device */
             // DWORD  YResolution;      /* Y resolution of display device */
             // DWORD  ColorsUsed;       /* Number of color table indices used */
             // DWORD  ColorsImportant;  /* Number of important color indices */
             // WORD   Units;            /* Type of units used to measure resolution */
             // WORD   Reserved;         /* Pad structure to 4-byte boundary */
             // WORD   Recording;        /* Recording algorithm */
             // WORD   Rendering;        /* Halftoning algorithm used */
             // DWORD  Size1;            /* Reserved for halftoning algorithm use */
             // DWORD  Size2;            /* Reserved for halftoning algorithm use */
             // DWORD  ColorEncoding;    /* Color model used in bitmap */
             // DWORD  Identifier;       /* Reserved for application use */
             getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 26, array('compression' => 4, 'bmp_data_size' => 4, 'resolution_h' => 4, 'resolution_v' => 4, 'colors_used' => 4, 'colors_important' => 4, 'resolution_units' => 2, 'reserved1' => 2, 'recording' => 2, 'rendering' => 2, 'size1' => 4, 'size2' => 4, 'color_encoding' => 4, 'identifier' => 4));
             $info_bmp_header['compression'] = getid3_bmp::BMPcompressionOS2Lookup($info_bmp_header_raw['compression']);
             $getid3->info['video']['codec'] = $info_bmp_header['compression'] . ' ' . $info_bmp_header_raw['bits_per_pixel'] . '-bit';
         }
         return true;
     }
     if ($info_bmp['type_os'] == 'Windows') {
         // Windows-format BMP
         // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
         // all versions
         // DWORD  biSize;
         // LONG   biWidth;
         // LONG   biHeight;
         // WORD   biPlanes;
         // WORD   biBitCount;
         // DWORD  biCompression;
         // DWORD  biSizeImage;
         // LONG   biXPelsPerMeter;
         // LONG   biYPelsPerMeter;
         // DWORD  biClrUsed;
         // DWORD  biClrImportant;
         getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18, array('width' => -4, 'height' => -4, 'planes' => 2, 'bits_per_pixel' => 2, 'compression' => 4, 'bmp_data_size' => 4, 'resolution_h' => -4, 'resolution_v' => -4, 'colors_used' => 4, 'colors_important' => 4));
         foreach (array('width', 'height', 'resolution_h', 'resolution_v') as $key) {
             $info_bmp_header_raw[$key] = getid3_lib::LittleEndian2Int($info_bmp_header_raw[$key], true);
         }
         $info_bmp_header['compression'] = getid3_bmp::BMPcompressionWindowsLookup($info_bmp_header_raw['compression']);
         $getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width'];
         $getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height'];
         $getid3->info['video']['codec'] = $info_bmp_header['compression'] . ' ' . $info_bmp_header_raw['bits_per_pixel'] . '-bit';
         $getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel'];
         // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen
         if ($info_bmp['type_version'] >= 4 || $info_bmp_header_raw['compression'] == 3) {
             $bmp_header .= fread($getid3->fp, 44);
             // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp
             // Win95+, WinNT4.0+
             // DWORD        bV4RedMask;
             // DWORD        bV4GreenMask;
             // DWORD        bV4BlueMask;
             // DWORD        bV4AlphaMask;
             // DWORD        bV4CSType;
             // CIEXYZTRIPLE bV4Endpoints;
             // DWORD        bV4GammaRed;
             // DWORD        bV4GammaGreen;
             // DWORD        bV4GammaBlue;
             getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 54, array('red_mask' => 4, 'green_mask' => 4, 'blue_mask' => 4, 'alpha_mask' => 4, 'cs_type' => 4, 'ciexyz_red' => -4, 'ciexyz_green' => -4, 'ciexyz_blue' => -4, 'gamma_red' => 4, 'gamma_green' => 4, 'gamma_blue' => 4));
             $info_bmp_header['ciexyz_red'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_red']));
             $info_bmp_header['ciexyz_green'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_green']));
             $info_bmp_header['ciexyz_blue'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_blue']));
             if ($info_bmp['type_version'] >= 5) {
                 $bmp_header .= fread($getid3->fp, 16);
                 // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp
                 // Win98+, Win2000+
                 // DWORD        bV5Intent;
                 // DWORD        bV5ProfileData;
                 // DWORD        bV5ProfileSize;
                 // DWORD        bV5Reserved;
                 getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 98, array('intent' => 4, 'profile_data_offset' => 4, 'profile_data_size' => 4, 'reserved3' => 4));
             }
         }
         return true;
     }
     throw new getid3_exception('Unknown BMP format in header.');
 }
Esempio n. 12
0
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->info['png'] = array();
     $info_png =& $getid3->info['png'];
     $getid3->info['fileformat'] = 'png';
     $getid3->info['video']['dataformat'] = 'png';
     $getid3->info['video']['lossless'] = false;
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $png_filedata = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
     // Magic bytes  "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
     $offset = 8;
     while (ftell($getid3->fp) - (strlen($png_filedata) - $offset) < $getid3->info['filesize']) {
         $chunk['data_length'] = getid3_lib::BigEndian2Int(substr($png_filedata, $offset, 4));
         $offset += 4;
         while (strlen($png_filedata) - $offset < $chunk['data_length'] + 4 && ftell($getid3->fp) < $getid3->info['filesize']) {
             $png_filedata .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
         }
         $chunk['type_text'] = substr($png_filedata, $offset, 4);
         $chunk['type_raw'] = getid3_lib::BigEndian2Int($chunk['type_text']);
         $offset += 4;
         $chunk['data'] = substr($png_filedata, $offset, $chunk['data_length']);
         $offset += $chunk['data_length'];
         $chunk['crc'] = getid3_lib::BigEndian2Int(substr($png_filedata, $offset, 4));
         $offset += 4;
         $chunk['flags']['ancilliary'] = (bool) ($chunk['type_raw'] & 0x20000000);
         $chunk['flags']['private'] = (bool) ($chunk['type_raw'] & 0x200000);
         $chunk['flags']['reserved'] = (bool) ($chunk['type_raw'] & 0x2000);
         $chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x20);
         // shortcut
         $info_png[$chunk['type_text']] = array();
         $info_png_chunk_type_text =& $info_png[$chunk['type_text']];
         switch ($chunk['type_text']) {
             case 'IHDR':
                 // Image Header
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['width'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4));
                 $info_png_chunk_type_text['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4));
                 getid3_lib::ReadSequence('BigEndian2Int', $info_png_chunk_type_text['raw'], $chunk['data'], 8, array('bit_depth' => 1, 'color_type' => 1, 'compression_method' => 1, 'filter_method' => 1, 'interlace_method' => 1));
                 $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['raw']['compression_method']);
                 $info_png_chunk_type_text['color_type']['palette'] = (bool) ($info_png_chunk_type_text['raw']['color_type'] & 0x1);
                 $info_png_chunk_type_text['color_type']['true_color'] = (bool) ($info_png_chunk_type_text['raw']['color_type'] & 0x2);
                 $info_png_chunk_type_text['color_type']['alpha'] = (bool) ($info_png_chunk_type_text['raw']['color_type'] & 0x4);
                 $getid3->info['video']['resolution_x'] = $info_png_chunk_type_text['width'];
                 $getid3->info['video']['resolution_y'] = $info_png_chunk_type_text['height'];
                 $getid3->info['video']['bits_per_sample'] = getid3_png::IHDRcalculateBitsPerSample($info_png_chunk_type_text['raw']['color_type'], $info_png_chunk_type_text['raw']['bit_depth']);
                 break;
             case 'PLTE':
                 // Palette
                 $info_png_chunk_type_text['header'] = $chunk;
                 $palette_offset = 0;
                 for ($i = 0; $i <= 255; $i++) {
                     $red = @getid3_lib::BigEndian2Int($chunk['data'][$palette_offset++]);
                     $green = @getid3_lib::BigEndian2Int($chunk['data'][$palette_offset++]);
                     $blue = @getid3_lib::BigEndian2Int($chunk['data'][$palette_offset++]);
                     $info_png_chunk_type_text[$i] = $red << 16 | $green << 8 | $blue;
                 }
                 break;
             case 'tRNS':
                 // Transparency
                 $info_png_chunk_type_text['header'] = $chunk;
                 switch ($info_png['IHDR']['raw']['color_type']) {
                     case 0:
                         $info_png_chunk_type_text['transparent_color_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
                         break;
                     case 2:
                         $info_png_chunk_type_text['transparent_color_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
                         $info_png_chunk_type_text['transparent_color_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 2));
                         $info_png_chunk_type_text['transparent_color_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 2));
                         break;
                     case 3:
                         for ($i = 0; $i < strlen($chunk['data']); $i++) {
                             $info_png_chunk_type_text['palette_opacity'][$i] = getid3_lib::BigEndian2Int($chunk['data'][$i]);
                         }
                         break;
                     case 4:
                     case 6:
                         throw new getid3_exception('Invalid color_type in tRNS chunk: ' . $info_png['IHDR']['raw']['color_type']);
                     default:
                         $getid3->warning('Unhandled color_type in tRNS chunk: ' . $info_png['IHDR']['raw']['color_type']);
                         break;
                 }
                 break;
             case 'gAMA':
                 // Image Gamma
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['gamma'] = getid3_lib::BigEndian2Int($chunk['data']) / 100000;
                 break;
             case 'cHRM':
                 // Primary Chromaticities
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['white_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)) / 100000;
                 $info_png_chunk_type_text['white_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)) / 100000;
                 $info_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 4)) / 100000;
                 $info_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000;
                 $info_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000;
                 $info_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000;
                 $info_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000;
                 $info_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000;
                 break;
             case 'sRGB':
                 // Standard RGB Color Space
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['reindering_intent'] = getid3_lib::BigEndian2Int($chunk['data']);
                 $info_png_chunk_type_text['reindering_intent_text'] = getid3_png::PNGsRGBintentLookup($info_png_chunk_type_text['reindering_intent']);
                 break;
             case 'iCCP':
                 // Embedded ICC Profile
                 $info_png_chunk_type_text['header'] = $chunk;
                 list($profilename, $compressiondata) = explode("", $chunk['data'], 2);
                 $info_png_chunk_type_text['profile_name'] = $profilename;
                 $info_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int($compressiondata[0]);
                 $info_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1);
                 $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
                 break;
             case 'tEXt':
                 // Textual Data
                 $info_png_chunk_type_text['header'] = $chunk;
                 list($keyword, $text) = explode("", $chunk['data'], 2);
                 $info_png_chunk_type_text['keyword'] = $keyword;
                 $info_png_chunk_type_text['text'] = $text;
                 $info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
                 break;
             case 'zTXt':
                 // Compressed Textual Data
                 $info_png_chunk_type_text['header'] = $chunk;
                 list($keyword, $otherdata) = explode("", $chunk['data'], 2);
                 $info_png_chunk_type_text['keyword'] = $keyword;
                 $info_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));
                 $info_png_chunk_type_text['compressed_text'] = substr($otherdata, 1);
                 $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
                 if ($info_png_chunk_type_text['compression_method'] != 0) {
                     // unknown compression method
                     break;
                 }
                 if (function_exists('gzuncompress')) {
                     $info_png_chunk_type_text['text'] = gzuncompress($info_png_chunk_type_text['compressed_text']);
                 } else {
                     if (!@$this->zlib_warning) {
                         $getid3->warning('PHP does not have --with-zlib support - cannot gzuncompress()');
                     }
                     $this->zlib_warning = true;
                 }
                 if (isset($info_png_chunk_type_text['text'])) {
                     $info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
                 }
                 break;
             case 'iTXt':
                 // International Textual Data
                 $info_png_chunk_type_text['header'] = $chunk;
                 list($keyword, $otherdata) = explode("", $chunk['data'], 2);
                 $info_png_chunk_type_text['keyword'] = $keyword;
                 $info_png_chunk_type_text['compression'] = (bool) getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));
                 $info_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int($otherdata[1]);
                 $info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
                 list($languagetag, $translatedkeyword, $text) = explode("", substr($otherdata, 2), 3);
                 $info_png_chunk_type_text['language_tag'] = $languagetag;
                 $info_png_chunk_type_text['translated_keyword'] = $translatedkeyword;
                 if ($info_png_chunk_type_text['compression']) {
                     switch ($info_png_chunk_type_text['compression_method']) {
                         case 0:
                             if (function_exists('gzuncompress')) {
                                 $info_png_chunk_type_text['text'] = gzuncompress($text);
                             } else {
                                 if (!@$this->zlib_warning) {
                                     $getid3->warning('PHP does not have --with-zlib support - cannot gzuncompress()');
                                 }
                                 $this->zlib_warning = true;
                             }
                             break;
                         default:
                             // unknown compression method
                             break;
                     }
                 } else {
                     $info_png_chunk_type_text['text'] = $text;
                 }
                 if (isset($info_png_chunk_type_text['text'])) {
                     $info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
                 }
                 break;
             case 'bKGD':
                 // Background Color
                 $info_png_chunk_type_text['header'] = $chunk;
                 switch ($info_png['IHDR']['raw']['color_type']) {
                     case 0:
                     case 4:
                         $info_png_chunk_type_text['background_gray'] = getid3_lib::BigEndian2Int($chunk['data']);
                         break;
                     case 2:
                     case 6:
                         $info_png_chunk_type_text['background_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
                         $info_png_chunk_type_text['background_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
                         $info_png_chunk_type_text['background_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
                         break;
                     case 3:
                         $info_png_chunk_type_text['background_index'] = getid3_lib::BigEndian2Int($chunk['data']);
                         break;
                     default:
                         break;
                 }
                 break;
             case 'pHYs':
                 // Physical Pixel Dimensions
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['pixels_per_unit_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4));
                 $info_png_chunk_type_text['pixels_per_unit_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4));
                 $info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1));
                 $info_png_chunk_type_text['unit'] = getid3_png::PNGpHYsUnitLookup($info_png_chunk_type_text['unit_specifier']);
                 break;
             case 'sBIT':
                 // Significant Bits
                 $info_png_chunk_type_text['header'] = $chunk;
                 switch ($info_png['IHDR']['raw']['color_type']) {
                     case 0:
                         $info_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1));
                         break;
                     case 2:
                     case 3:
                         $info_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
                         $info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
                         $info_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int($chunk['data'][2]);
                         break;
                     case 4:
                         $info_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
                         $info_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
                         break;
                     case 6:
                         $info_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
                         $info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
                         $info_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int($chunk['data'][2]);
                         $info_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int($chunk['data'][3]);
                         break;
                     default:
                         break;
                 }
                 break;
             case 'sPLT':
                 // Suggested Palette
                 $info_png_chunk_type_text['header'] = $chunk;
                 list($palettename, $otherdata) = explode("", $chunk['data'], 2);
                 $info_png_chunk_type_text['palette_name'] = $palettename;
                 $info_png_chunk_type_text['sample_depth_bits'] = getid3_lib::BigEndian2Int($otherdata[0]);
                 $info_png_chunk_type_text['sample_depth_bytes'] = $info_png_chunk_type_text['sample_depth_bits'] / 8;
                 $s_plt_offset = 1;
                 $paletteCounter = 0;
                 while ($s_plt_offset < strlen($otherdata)) {
                     $info_png_chunk_type_text['red'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
                     $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
                     $info_png_chunk_type_text['green'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
                     $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
                     $info_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
                     $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
                     $info_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
                     $s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
                     $info_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, 2));
                     $s_plt_offset += 2;
                     $paletteCounter++;
                 }
                 break;
             case 'hIST':
                 // Palette Histogram
                 $info_png_chunk_type_text['header'] = $chunk;
                 $h_ist_counter = 0;
                 while ($h_ist_counter < strlen($chunk['data'])) {
                     $info_png_chunk_type_text[$h_ist_counter] = getid3_lib::BigEndian2Int(substr($chunk['data'], $h_ist_counter / 2, 2));
                     $h_ist_counter += 2;
                 }
                 break;
             case 'tIME':
                 // Image Last-Modification Time
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['year'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
                 $info_png_chunk_type_text['month'] = getid3_lib::BigEndian2Int($chunk['data'][2]);
                 $info_png_chunk_type_text['day'] = getid3_lib::BigEndian2Int($chunk['data'][3]);
                 $info_png_chunk_type_text['hour'] = getid3_lib::BigEndian2Int($chunk['data'][4]);
                 $info_png_chunk_type_text['minute'] = getid3_lib::BigEndian2Int($chunk['data'][5]);
                 $info_png_chunk_type_text['second'] = getid3_lib::BigEndian2Int($chunk['data'][6]);
                 $info_png_chunk_type_text['unix'] = gmmktime($info_png_chunk_type_text['hour'], $info_png_chunk_type_text['minute'], $info_png_chunk_type_text['second'], $info_png_chunk_type_text['month'], $info_png_chunk_type_text['day'], $info_png_chunk_type_text['year']);
                 break;
             case 'oFFs':
                 // Image Offset
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['position_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
                 $info_png_chunk_type_text['position_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
                 $info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int($chunk['data'][8]);
                 $info_png_chunk_type_text['unit'] = getid3_png::PNGoFFsUnitLookup($info_png_chunk_type_text['unit_specifier']);
                 break;
             case 'pCAL':
                 // Calibration Of Pixel Values
                 $info_png_chunk_type_text['header'] = $chunk;
                 list($calibrationname, $otherdata) = explode("", $chunk['data'], 2);
                 $info_png_chunk_type_text['calibration_name'] = $calibrationname;
                 $info_png_chunk_type_text['original_zero'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
                 $info_png_chunk_type_text['original_max'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
                 $info_png_chunk_type_text['equation_type'] = getid3_lib::BigEndian2Int($chunk['data'][8]);
                 $info_png_chunk_type_text['equation_type_text'] = getid3_png::PNGpCALequationTypeLookup($info_png_chunk_type_text['equation_type']);
                 $info_png_chunk_type_text['parameter_count'] = getid3_lib::BigEndian2Int($chunk['data'][9]);
                 $info_png_chunk_type_text['parameters'] = explode("", substr($chunk['data'], 10));
                 break;
             case 'sCAL':
                 // Physical Scale Of Image Subject
                 $info_png_chunk_type_text['header'] = $chunk;
                 $info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1));
                 $info_png_chunk_type_text['unit'] = getid3_png::PNGsCALUnitLookup($info_png_chunk_type_text['unit_specifier']);
                 list($info_png_chunk_type_text['pixel_width'], $info_png_chunk_type_text['pixel_height']) = explode("", substr($chunk['data'], 1));
                 break;
             case 'gIFg':
                 // GIF Graphic Control Extension
                 $gIFg_counter = 0;
                 if (isset($info_png_chunk_type_text) && is_array($info_png_chunk_type_text)) {
                     $gIFg_counter = count($info_png_chunk_type_text);
                 }
                 $info_png_chunk_type_text[$gIFg_counter]['header'] = $chunk;
                 $info_png_chunk_type_text[$gIFg_counter]['disposal_method'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
                 $info_png_chunk_type_text[$gIFg_counter]['user_input_flag'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
                 $info_png_chunk_type_text[$gIFg_counter]['delay_time'] = getid3_lib::BigEndian2Int($chunk['data'][2]);
                 break;
             case 'gIFx':
                 // GIF Application Extension
                 $gIFx_counter = 0;
                 if (isset($info_png_chunk_type_text) && is_array($info_png_chunk_type_text)) {
                     $gIFx_counter = count($info_png_chunk_type_text);
                 }
                 $info_png_chunk_type_text[$gIFx_counter]['header'] = $chunk;
                 $info_png_chunk_type_text[$gIFx_counter]['application_identifier'] = substr($chunk['data'], 0, 8);
                 $info_png_chunk_type_text[$gIFx_counter]['authentication_code'] = substr($chunk['data'], 8, 3);
                 $info_png_chunk_type_text[$gIFx_counter]['application_data'] = substr($chunk['data'], 11);
                 break;
             case 'IDAT':
                 // Image Data
                 $idat_information_field_index = 0;
                 if (isset($info_png['IDAT']) && is_array($info_png['IDAT'])) {
                     $idat_information_field_index = count($info_png['IDAT']);
                 }
                 unset($chunk['data']);
                 $info_png_chunk_type_text[$idat_information_field_index]['header'] = $chunk;
                 break;
             case 'IEND':
                 // Image Trailer
                 $info_png_chunk_type_text['header'] = $chunk;
                 break;
             default:
                 $info_png_chunk_type_text['header'] = $chunk;
                 $getid3->warning('Unhandled chunk type: ' . $chunk['type_text']);
                 break;
         }
     }
     return true;
 }
Esempio n. 13
0
 private function HandleBonkTags(&$bonk_tag_name)
 {
     // Shortcut to getid3 pointer
     $getid3 = $this->getid3;
     $info_audio =& $getid3->info['audio'];
     switch ($bonk_tag_name) {
         case 'BONK':
             // shortcut
             $info_bonk_BONK =& $getid3->info['bonk']['BONK'];
             $bonk_data = "" . 'BONK' . fread($getid3->fp, 17);
             getid3_lib::ReadSequence('LittleEndian2Int', $info_bonk_BONK, $bonk_data, 5, array('version' => 1, 'number_samples' => 4, 'sample_rate' => 4, 'channels' => 1, 'lossless' => 1, 'joint_stereo' => 1, 'number_taps' => 2, 'downsampling_ratio' => 1, 'samples_per_packet' => 2));
             $info_bonk_BONK['lossless'] = (bool) $info_bonk_BONK['lossless'];
             $info_bonk_BONK['joint_stereo'] = (bool) $info_bonk_BONK['joint_stereo'];
             $getid3->info['avdataoffset'] = $info_bonk_BONK['offset'] + 5 + 17;
             $getid3->info['avdataend'] = $info_bonk_BONK['offset'] + $info_bonk_BONK['size'];
             $getid3->info['fileformat'] = 'bonk';
             $info_audio['dataformat'] = 'bonk';
             $info_audio['bitrate_mode'] = 'vbr';
             // assumed
             $info_audio['channels'] = $info_bonk_BONK['channels'];
             $info_audio['sample_rate'] = $info_bonk_BONK['sample_rate'];
             $info_audio['channelmode'] = $info_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo';
             $info_audio['lossless'] = $info_bonk_BONK['lossless'];
             $info_audio['codec'] = 'bonk';
             $getid3->info['playtime_seconds'] = $info_bonk_BONK['number_samples'] / ($info_bonk_BONK['sample_rate'] * $info_bonk_BONK['channels']);
             if ($getid3->info['playtime_seconds'] > 0) {
                 $info_audio['bitrate'] = ($getid3->info['bonk']['dataend'] - $getid3->info['bonk']['dataoffset']) * 8 / $getid3->info['playtime_seconds'];
             }
             break;
         case 'INFO':
             // shortcut
             $info_bonk_INFO =& $getid3->info['bonk']['INFO'];
             $info_bonk_INFO['version'] = getid3_lib::LittleEndian2Int(fread($getid3->fp, 1));
             $info_bonk_INFO['entries_count'] = 0;
             $next_info_data_pair = fread($getid3->fp, 5);
             if (!getid3_bonk::BonkIsValidTagName(substr($next_info_data_pair, 1, 4))) {
                 while (!feof($getid3->fp)) {
                     $next_info_data_pair = fread($getid3->fp, 5);
                     if (getid3_bonk::BonkIsValidTagName(substr($next_info_data_pair, 1, 4))) {
                         fseek($getid3->fp, -5, SEEK_CUR);
                         break;
                     }
                     $info_bonk_INFO['entries_count']++;
                 }
             }
             break;
         case 'META':
             $bonk_data = "" . 'META' . fread($getid3->fp, $getid3->info['bonk']['META']['size'] - 5);
             $getid3->info['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($bonk_data, 5, 1));
             $meta_tag_entries = floor((strlen($bonk_data) - 8 - 6) / 8);
             // BonkData - xxxxmeta - ØMETA
             $offset = 6;
             for ($i = 0; $i < $meta_tag_entries; $i++) {
                 $meta_entry_tag_name = substr($bonk_data, $offset, 4);
                 $offset += 4;
                 $meta_entry_tag_offset = getid3_lib::LittleEndian2Int(substr($bonk_data, $offset, 4));
                 $offset += 4;
                 $getid3->info['bonk']['META']['tags'][$meta_entry_tag_name] = $meta_entry_tag_offset;
             }
             break;
         case ' ID3':
             $info_audio['encoder'] = 'Extended BONK v0.9+';
             // ID3v2 checking is optional
             if (class_exists('getid3_id3v2')) {
                 $id3v2 = new getid3_id3v2($getid3);
                 $id3v2->option_starting_offset = $getid3->info['bonk'][' ID3']['offset'] + 2;
                 $getid3->info['bonk'][' ID3']['valid'] = $id3v2->Analyze();
             }
             break;
         default:
             $getid3->warning('Unexpected Bonk tag "' . $bonk_tag_name . '" at offset ' . $getid3->info['bonk'][$bonk_tag_name]['offset']);
             break;
     }
 }
 private function QuicktimeParseAtom($atom_name, $atom_size, $atom_data, $base_offset, &$atom_hierarchy)
 {
     // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
     $getid3 = $this->getid3;
     $info =& $getid3->info;
     $info_quicktime =& $info['quicktime'];
     array_push($atom_hierarchy, $atom_name);
     $atom_structure['hierarchy'] = implode(' ', $atom_hierarchy);
     $atom_structure['name'] = $atom_name;
     $atom_structure['size'] = $atom_size;
     $atom_structure['offset'] = $base_offset;
     switch ($atom_name) {
         case 'moov':
             // MOVie container atom
         // MOVie container atom
         case 'trak':
             // TRAcK container atom
         // TRAcK container atom
         case 'clip':
             // CLIPping container atom
         // CLIPping container atom
         case 'matt':
             // track MATTe container atom
         // track MATTe container atom
         case 'edts':
             // EDiTS container atom
         // EDiTS container atom
         case 'tref':
             // Track REFerence container atom
         // Track REFerence container atom
         case 'mdia':
             // MeDIA container atom
         // MeDIA container atom
         case 'minf':
             // Media INFormation container atom
         // Media INFormation container atom
         case 'dinf':
             // Data INFormation container atom
         // Data INFormation container atom
         case 'udta':
             // User DaTA container atom
         // User DaTA container atom
         case 'stbl':
             // Sample TaBLe container atom
         // Sample TaBLe container atom
         case 'cmov':
             // Compressed MOVie container atom
         // Compressed MOVie container atom
         case 'rmra':
             // Reference Movie Record Atom
         // Reference Movie Record Atom
         case 'rmda':
             // Reference Movie Descriptor Atom
         // Reference Movie Descriptor Atom
         case 'gmhd':
             // Generic Media info HeaDer atom (seen on QTVR)
             $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $base_offset + 8, $atom_hierarchy);
             break;
         case '©cpy':
         case '©day':
         case '©dir':
         case '©ed1':
         case '©ed2':
         case '©ed3':
         case '©ed4':
         case '©ed5':
         case '©ed6':
         case '©ed7':
         case '©ed8':
         case '©ed9':
         case '©fmt':
         case '©inf':
         case '©prd':
         case '©prf':
         case '©req':
         case '©src':
         case '©wrt':
         case '©nam':
         case '©cmt':
         case '©wrn':
         case '©hst':
         case '©mak':
         case '©mod':
         case '©PRD':
         case '©swr':
         case '©aut':
         case '©ART':
         case '©trk':
         case '©alb':
         case '©com':
         case '©gen':
         case '©ope':
         case '©url':
         case '©enc':
             $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
             $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
             $atom_structure['data'] = substr($atom_data, 4);
             $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
             if (empty($info['comments']['language']) || !in_array($atom_structure['language'], $info['comments']['language'])) {
                 $info['comments']['language'][] = $atom_structure['language'];
             }
             $this->CopyToAppropriateCommentsSection($atom_name, $atom_structure['data']);
             break;
         case 'play':
             // auto-PLAY atom
             $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
             $info_quicktime['autoplay'] = $atom_structure['autoplay'];
             break;
         case 'WLOC':
             // Window LOCation atom
             $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
             $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2));
             break;
         case 'LOOP':
             // LOOPing atom
         // LOOPing atom
         case 'SelO':
             // play SELection Only atom
         // play SELection Only atom
         case 'AllF':
             // play ALL Frames atom
             $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data);
             break;
         case 'name':
             //
         //
         case 'MCPS':
             // Media Cleaner PRo
         // Media Cleaner PRo
         case '@PRM':
             // adobe PReMiere version
         // adobe PReMiere version
         case '@PRQ':
             // adobe PRemiere Quicktime version
             $atom_structure['data'] = $atom_data;
             break;
         case 'cmvd':
             // Compressed MooV Data atom
             // Code by ubergeekØubergeek*tv based on information from
             // http://developer.apple.com/quicktime/icefloe/dispatch012.html
             $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             $compressed_file_data = substr($atom_data, 4);
             if (!function_exists('gzuncompress')) {
                 $getid3->warning('PHP does not have zlib support - cannot decompress MOV atom at offset ' . $atom_structure['offset']);
             } elseif ($uncompressed_header = @gzuncompress($compressed_file_data)) {
                 $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($uncompressed_header, 0, $atom_hierarchy);
             } else {
                 $getid3->warning('Error decompressing compressed MOV atom at offset ' . $atom_structure['offset']);
             }
             break;
         case 'dcom':
             // Data COMpression atom
             $atom_structure['compression_id'] = $atom_data;
             $atom_structure['compression_text'] = getid3_quicktime::QuicktimeDCOMLookup($atom_data);
             break;
         case 'rdrf':
             // Reference movie Data ReFerence atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'reference_type_name' => -4, 'reference_length' => 4));
             $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x1);
             switch ($atom_structure['reference_type_name']) {
                 case 'url ':
                     $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12));
                     break;
                 case 'alis':
                     $atom_structure['file_alias'] = substr($atom_data, 12);
                     break;
                 case 'rsrc':
                     $atom_structure['resource_alias'] = substr($atom_data, 12);
                     break;
                 default:
                     $atom_structure['data'] = substr($atom_data, 12);
                     break;
             }
             break;
         case 'rmqu':
             // Reference Movie QUality atom
             $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data);
             break;
         case 'rmcs':
             // Reference Movie Cpu Speed atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'cpu_speed_rating' => 2));
             break;
         case 'rmvc':
             // Reference Movie Version Check atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'gestalt_selector' => -4, 'gestalt_value_mask' => 4, 'gestalt_value' => 4, 'gestalt_check_type' => 2));
             break;
         case 'rmcd':
             // Reference Movie Component check atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'component_type' => -4, 'component_subtype' => -4, 'component_manufacturer' => -4, 'component_flags_raw' => 4, 'component_flags_mask' => 4, 'component_min_version' => 4));
             break;
         case 'rmdr':
             // Reference Movie Data Rate atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'data_rate' => 4));
             $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10;
             break;
         case 'rmla':
             // Reference Movie Language Atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'language_id' => 2));
             $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
             if (empty($info['comments']['language']) || !in_array($atom_structure['language'], $info['comments']['language'])) {
                 $info['comments']['language'][] = $atom_structure['language'];
             }
             break;
         case 'rmla':
             // Reference Movie Language Atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'track_id' => 2));
             break;
         case 'ptv ':
             // Print To Video - defines a movie's full screen mode
             // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('display_size_raw' => 2, 'reserved_1' => 2, 'reserved_2' => 2, 'slide_show_flag' => 1, 'play_on_open_flag' => 1));
             $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag'];
             $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag'];
             $ptv_lookup[0] = 'normal';
             $ptv_lookup[1] = 'double';
             $ptv_lookup[2] = 'half';
             $ptv_lookup[3] = 'full';
             $ptv_lookup[4] = 'current';
             if (isset($ptv_lookup[$atom_structure['display_size_raw']])) {
                 $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']];
             } else {
                 $getid3->warning('unknown "ptv " display constant (' . $atom_structure['display_size_raw'] . ')');
             }
             break;
         case 'stsd':
             // Sample Table Sample Description atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             $stsd_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_data, $stsd_entries_data_offset, array('size' => 4, 'data_format' => -4, 'reserved' => 6, 'reference_index' => 2));
                 $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, 16 + $stsd_entries_data_offset, $atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
                 $stsd_entries_data_offset += 16 + ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2);
                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 0, array('encoder_version' => 2, 'encoder_revision' => 2, 'encoder_vendor' => -4));
                 switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) {
                     case "":
                         // audio atom
                         getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 8, array('audio_channels' => 2, 'audio_bit_depth' => 2, 'audio_compression_id' => 2, 'audio_packet_size' => 2));
                         $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_quicktime::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4));
                         switch ($atom_structure['sample_description_table'][$i]['data_format']) {
                             case 'mp4v':
                                 $info['fileformat'] = 'mp4';
                                 throw new getid3_exception('This version of getID3() does not fully support MPEG-4 audio/video streams');
                             case 'qtvr':
                                 $info['video']['dataformat'] = 'quicktimevr';
                                 break;
                             case 'mp4a':
                             default:
                                 $info_quicktime['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
                                 $info_quicktime['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate'];
                                 $info_quicktime['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels'];
                                 $info_quicktime['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth'];
                                 $info['audio']['codec'] = $info_quicktime['audio']['codec'];
                                 $info['audio']['sample_rate'] = $info_quicktime['audio']['sample_rate'];
                                 $info['audio']['channels'] = $info_quicktime['audio']['channels'];
                                 $info['audio']['bits_per_sample'] = $info_quicktime['audio']['bit_depth'];
                                 switch ($atom_structure['sample_description_table'][$i]['data_format']) {
                                     case 'raw ':
                                         // PCM
                                     // PCM
                                     case 'alac':
                                         // Apple Lossless Audio Codec
                                         $info['audio']['lossless'] = true;
                                         break;
                                     default:
                                         $info['audio']['lossless'] = false;
                                         break;
                                 }
                                 break;
                         }
                         break;
                     default:
                         switch ($atom_structure['sample_description_table'][$i]['data_format']) {
                             case 'mp4s':
                                 $info['fileformat'] = 'mp4';
                                 break;
                             default:
                                 // video atom
                                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 8, array('video_temporal_quality' => 4, 'video_spatial_quality' => 4, 'video_frame_width' => 2, 'video_frame_height' => 2));
                                 $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_quicktime::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4));
                                 $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_quicktime::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4));
                                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['sample_description_table'][$i], $atom_structure['sample_description_table'][$i]['data'], 28, array('video_data_size' => 4, 'video_frame_count' => 2, 'video_encoder_name_len' => 1));
                                 $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']);
                                 $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2));
                                 $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2));
                                 $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32 ? 'grayscale' : 'color';
                                 $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']);
                                 if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') {
                                     $info_quicktime['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format'];
                                     $info_quicktime['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']);
                                     $info_quicktime['video']['codec'] = $atom_structure['sample_description_table'][$i]['video_encoder_name'];
                                     $info_quicktime['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'];
                                     $info_quicktime['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name'];
                                     $info['video']['codec'] = $info_quicktime['video']['codec'];
                                     $info['video']['bits_per_sample'] = $info_quicktime['video']['color_depth'];
                                 }
                                 $info['video']['lossless'] = false;
                                 $info['video']['pixel_aspect_ratio'] = (double) 1;
                                 break;
                         }
                         break;
                 }
                 switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) {
                     case 'mp4a':
                         $info['audio']['dataformat'] = $info_quicktime['audio']['codec'] = 'mp4';
                         break;
                     case '3ivx':
                     case '3iv1':
                     case '3iv2':
                         $info['video']['dataformat'] = '3ivx';
                         break;
                     case 'xvid':
                         $info['video']['dataformat'] = 'xvid';
                         break;
                     case 'mp4v':
                         $info['video']['dataformat'] = 'mpeg4';
                         break;
                     case 'divx':
                     case 'div1':
                     case 'div2':
                     case 'div3':
                     case 'div4':
                     case 'div5':
                     case 'div6':
                         //$TDIVXileInfo['video']['dataformat'] = 'divx';
                         break;
                     default:
                         // do nothing
                         break;
                 }
                 unset($atom_structure['sample_description_table'][$i]['data']);
             }
             break;
         case 'stts':
             // Sample Table Time-to-Sample atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             $stts_entries_data_offset = 8;
             $frame_rate_calculator_array = array();
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $stts_entries_data_offset, 4));
                 $stts_entries_data_offset += 4;
                 $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $stts_entries_data_offset, 4));
                 $stts_entries_data_offset += 4;
                 if (!empty($info_quicktime['time_scale']) && @$atoms_structure['time_to_sample_table'][$i]['sample_duration'] > 0) {
                     $stts_new_framerate = $info_quicktime['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'];
                     if ($stts_new_framerate <= 60) {
                         // some atoms have durations of "1" giving a very large framerate, which probably is not right
                         $info['video']['frame_rate'] = max(@$info['video']['frame_rate'], $stts_new_framerate);
                     }
                 }
                 //@$frame_rate_calculator_array[($info_quicktime['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count'];
             }
             /*
             $stts_frames_total  = 0;
             $stts_seconds_total = 0;
             foreach ($frame_rate_calculator_array as $frames_per_second => $frame_count) {
                 if (($frames_per_second > 60) || ($frames_per_second < 1)) {
                     // not video FPS information, probably audio information
                     $stts_frames_total  = 0;
                     $stts_seconds_total = 0;
                     break;
                 }
                 $stts_frames_total  += $frame_count;
                 $stts_seconds_total += $frame_count / $frames_per_second;
             }
             if (($stts_frames_total > 0) && ($stts_seconds_total > 0)) {
                 if (($stts_frames_total / $stts_seconds_total) > @$info['video']['frame_rate']) {
                     $info['video']['frame_rate'] = $stts_frames_total / $stts_seconds_total;
                 }
             }
             */
             break;
         case 'stss':
             // Sample Table Sync Sample (key frames) atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $stss_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stss_entries_data_offset, 4));
                 $stss_entries_data_offset += 4;
             }
             */
             break;
         case 'stsc':
             // Sample Table Sample-to-Chunk atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $stsc_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['sample_to_chunk_table'][$i]['first_chunk']        = getid3_lib::BigEndian2Int(substr($atom_data, $stsc_entries_data_offset, 4));
                 $stsc_entries_data_offset += 4;
                 $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk']  = getid3_lib::BigEndian2Int(substr($atom_data, $stsc_entries_data_offset, 4));
                 $stsc_entries_data_offset += 4;
                 $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsc_entries_data_offset, 4));
                 $stsc_entries_data_offset += 4;
             }
             */
             break;
         case 'stsz':
             // Sample Table SiZe atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['sample_size']    = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  8, 4));
             $stsz_entries_data_offset = 12;
             if ($atom_structure['sample_size'] == 0) {
                 for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                     $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stsz_entries_data_offset, 4));
                     $stsz_entries_data_offset += 4;
                 }
             }
             */
             break;
         case 'stco':
             // Sample Table Chunk Offset atom
             /*
             $atom_structure['version']        = getid3_lib::BigEndian2Int(substr($atom_data,  0, 1));
             $atom_structure['flags_raw']      = getid3_lib::BigEndian2Int(substr($atom_data,  1, 3)); // hardcoded: 0x0000
             $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data,  4, 4));
             $stco_entries_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stco_entries_data_offset, 4));
                 $stco_entries_data_offset += 4;
             }
             */
             break;
         case 'dref':
             // Data REFerence atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             $dref_data_offset = 8;
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 getid3_lib::ReadSequence('BigEndian2Int', $atom_structure['data_references'][$i], $atom_data, $dref_data_offset, array('size' => 4, 'type' => -4, 'version' => 1, 'flags_raw' => 3));
                 $dref_data_offset += 12;
                 $atom_structure['data_references'][$i]['data'] = substr($atom_data, $dref_data_offset, $atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3);
                 $dref_data_offset += $atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3;
                 $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x1);
             }
             break;
         case 'gmin':
             // base Media INformation atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'graphics_mode' => 2, 'opcolor_red' => 2, 'opcolor_green' => 2, 'opcolor_blue' => 2, 'balance' => 2, 'reserved' => 2));
             break;
         case 'smhd':
             // Sound Media information HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'balance' => 2, 'reserved' => 2));
             break;
         case 'vmhd':
             // Video Media information HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'graphics_mode' => 2, 'opcolor_red' => 2, 'opcolor_green' => 2, 'opcolor_blue' => 2));
             $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x1);
             break;
         case 'hdlr':
             // HanDLeR reference atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'component_type' => -4, 'component_subtype' => -4, 'component_manufacturer' => -4, 'component_flags_raw' => 4, 'component_flags_mask' => 4));
             $atom_structure['component_name'] = substr(substr($atom_data, 24), 1);
             /// Pascal2String
             if ($atom_structure['component_subtype'] == 'STpn' && $atom_structure['component_manufacturer'] == 'zzzz') {
                 $info['video']['dataformat'] = 'quicktimevr';
             }
             break;
         case 'mdhd':
             // MeDia HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'creation_time' => 4, 'modify_time' => 4, 'time_scale' => 4, 'duration' => 4, 'language_id' => 2, 'quality' => 2));
             if ($atom_structure['time_scale'] == 0) {
                 throw new getid3_exception('Corrupt Quicktime file: mdhd.time_scale == zero');
             }
             $info_quicktime['time_scale'] = max(@$info['quicktime']['time_scale'], $atom_structure['time_scale']);
             $atom_structure['creation_time_unix'] = (int) ($atom_structure['creation_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['modify_time_unix'] = (int) ($atom_structure['modify_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
             $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']);
             if (empty($info['comments']['language']) || !in_array($atom_structure['language'], $info['comments']['language'])) {
                 $info['comments']['language'][] = $atom_structure['language'];
             }
             break;
         case 'pnot':
             // Preview atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('modification_date' => 4, 'version_number' => 2, 'atom_type' => -4, 'atom_index' => 2));
             $atom_structure['modification_date_unix'] = (int) ($atom_structure['modification_date'] - 2082844800);
             // DateMac2Unix()
             break;
         case 'crgn':
             // Clipping ReGioN atom
             $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2));
             // The Region size, Region boundary box,
             $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8));
             // and Clipping region data fields
             $atom_structure['clipping_data'] = substr($atom_data, 10);
             // constitute a QuickDraw region.
             break;
         case 'load':
             // track LOAD settings atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('preload_start_time' => 4, 'preload_duration' => 4, 'preload_flags_raw' => 4, 'default_hints_raw' => 4));
             $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x20);
             $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x100);
             break;
         case 'tmcd':
             // TiMe CoDe atom
         // TiMe CoDe atom
         case 'chap':
             // CHAPter list atom
         // CHAPter list atom
         case 'sync':
             // SYNChronization atom
         // SYNChronization atom
         case 'scpt':
             // tranSCriPT atom
         // tranSCriPT atom
         case 'ssrc':
             // non-primary SouRCe atom
             for ($i = 0; $i < strlen($atom_data) % 4; $i++) {
                 $atom_structure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $i * 4, 4));
             }
             break;
         case 'elst':
             // Edit LiST atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'number_entries' => 4));
             for ($i = 0; $i < $atom_structure['number_entries']; $i++) {
                 $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $i * 12 + 0, 4));
                 $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $i * 12 + 4, 4));
                 $atom_structure['edit_list'][$i]['media_rate'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 8 + $i * 12 + 8, 4));
             }
             break;
         case 'kmat':
             // compressed MATte atom
             $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1));
             $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3));
             // hardcoded: 0x0000
             $atom_structure['matte_data_raw'] = substr($atom_data, 4);
             break;
         case 'ctab':
             // Color TABle atom
             $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             // hardcoded: 0x00000000
             $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2));
             // hardcoded: 0x8000
             $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1;
             for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) {
                 $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 0, 2));
                 $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 2, 2));
                 $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 4, 2));
                 $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + $colortableentry * 8 + 6, 2));
             }
             break;
         case 'mvhd':
             // MoVie HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'creation_time' => 4, 'modify_time' => 4, 'time_scale' => 4, 'duration' => 4));
             $atom_structure['preferred_rate'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 20, 4));
             $atom_structure['preferred_volume'] = getid3_quicktime::FixedPoint8_8(substr($atom_data, 24, 2));
             $atom_structure['reserved'] = substr($atom_data, 26, 10);
             $atom_structure['matrix_a'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 36, 4));
             $atom_structure['matrix_b'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 40, 4));
             $atom_structure['matrix_u'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 44, 4));
             $atom_structure['matrix_c'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 48, 4));
             $atom_structure['matrix_d'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 52, 4));
             $atom_structure['matrix_v'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 56, 4));
             $atom_structure['matrix_x'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 60, 4));
             $atom_structure['matrix_y'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 64, 4));
             $atom_structure['matrix_w'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 68, 4));
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 72, array('preview_time' => 4, 'preview_duration' => 4, 'poster_time' => 4, 'selection_time' => 4, 'selection_duration' => 4, 'current_time' => 4, 'next_track_id' => 4));
             if ($atom_structure['time_scale'] == 0) {
                 throw new getid3_exception('Corrupt Quicktime file: mvhd.time_scale == zero');
             }
             $atom_structure['creation_time_unix'] = (int) ($atom_structure['creation_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['modify_time_unix'] = (int) ($atom_structure['modify_time'] - 2082844800);
             // DateMac2Unix()
             $info_quicktime['time_scale'] = max(@$info['quicktime']['time_scale'], $atom_structure['time_scale']);
             $info_quicktime['display_scale'] = $atom_structure['matrix_a'];
             $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale'];
             break;
         case 'tkhd':
             // TracK HeaDer atom
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('version' => 1, 'flags_raw' => 3, 'creation_time' => 4, 'modify_time' => 4, 'trackid' => 4, 'reserved1' => 4, 'duration' => 4, 'reserved2' => 8, 'layer' => 2, 'alternate_group' => 2));
             $atom_structure['volume'] = getid3_quicktime::FixedPoint8_8(substr($atom_data, 36, 2));
             $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2));
             $atom_structure['matrix_a'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 40, 4));
             $atom_structure['matrix_b'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 44, 4));
             $atom_structure['matrix_u'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 48, 4));
             $atom_structure['matrix_c'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 52, 4));
             $atom_structure['matrix_v'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 56, 4));
             $atom_structure['matrix_d'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 60, 4));
             $atom_structure['matrix_x'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 64, 4));
             $atom_structure['matrix_y'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 68, 4));
             $atom_structure['matrix_w'] = getid3_quicktime::FixedPoint2_30(substr($atom_data, 72, 4));
             $atom_structure['width'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 76, 4));
             $atom_structure['height'] = getid3_quicktime::FixedPoint16_16(substr($atom_data, 80, 4));
             $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x1);
             $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x2);
             $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x4);
             $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x8);
             $atom_structure['creation_time_unix'] = (int) ($atom_structure['creation_time'] - 2082844800);
             // DateMac2Unix()
             $atom_structure['modify_time_unix'] = (int) ($atom_structure['modify_time'] - 2082844800);
             // DateMac2Unix()
             if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) {
                 $info['video']['resolution_x'] = $atom_structure['width'];
                 $info['video']['resolution_y'] = $atom_structure['height'];
             }
             if ($atom_structure['flags']['enabled'] == 1) {
                 $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']);
                 $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']);
             }
             if (!empty($info['video']['resolution_x']) && !empty($info['video']['resolution_y'])) {
                 $info_quicktime['video']['resolution_x'] = $info['video']['resolution_x'];
                 $info_quicktime['video']['resolution_y'] = $info['video']['resolution_y'];
             } else {
                 unset($info['video']['resolution_x']);
                 unset($info['video']['resolution_y']);
                 unset($info_quicktime['video']);
             }
             break;
         case 'meta':
             // METAdata atom
             // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
             $next_tag_position = strpos($atom_data, '©');
             while ($next_tag_position < strlen($atom_data)) {
                 $meta_item_size = getid3_lib::BigEndian2Int(substr($atom_data, $next_tag_position - 4, 4)) - 4;
                 if ($meta_item_size == -4) {
                     break;
                 }
                 $meta_item_raw = substr($atom_data, $next_tag_position, $meta_item_size);
                 $meta_item_key = substr($meta_item_raw, 0, 4);
                 $meta_item_data = substr($meta_item_raw, 20);
                 $next_tag_position += $meta_item_size + 4;
                 $this->CopyToAppropriateCommentsSection($meta_item_key, $meta_item_data);
             }
             break;
         case 'ftyp':
             // FileTYPe (?) atom (for MP4 it seems)
             getid3_lib::ReadSequence('BigEndian2Int', $atom_structure, $atom_data, 0, array('signature' => -4, 'unknown_1' => 4, 'fourcc' => -4));
             break;
         case 'mdat':
             // Media DATa atom
         // Media DATa atom
         case 'free':
             // FREE space atom
         // FREE space atom
         case 'skip':
             // SKIP atom
         // SKIP atom
         case 'wide':
             // 64-bit expansion placeholder atom
             // 'mdat' data is too big to deal with, contains no useful metadata
             // 'free', 'skip' and 'wide' are just padding, contains no useful data at all
             // When writing QuickTime files, it is sometimes necessary to update an atom's size.
             // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom
             // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime
             // puts an 8-byte placeholder atom before any atoms it may have to update the size of.
             // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the
             // placeholder atom can be overwritten to obtain the necessary 8 extra bytes.
             // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ).
             break;
         case 'nsav':
             // NoSAVe atom
             // http://developer.apple.com/technotes/tn/tn2038.html
             $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             break;
         case 'ctyp':
             // Controller TYPe atom (seen on QTVR)
             // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
             // some controller names are:
             //   0x00 + 'std' for linear movie
             //   'none' for no controls
             $atom_structure['ctyp'] = substr($atom_data, 0, 4);
             switch ($atom_structure['ctyp']) {
                 case 'qtvr':
                     $info['video']['dataformat'] = 'quicktimevr';
                     break;
             }
             break;
         case 'pano':
             // PANOrama track (seen on QTVR)
             $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4));
             break;
         case 'hint':
             // HINT track
         // HINT track
         case 'hinf':
             //
         //
         case 'hinv':
             //
         //
         case 'hnti':
             //
             $info['quicktime']['hinting'] = true;
             break;
         case 'imgt':
             // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR)
             for ($i = 0; $i < $atom_structure['size'] - 8; $i += 4) {
                 $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4));
             }
             break;
         case 'FXTC':
             // Something to do with Adobe After Effects (?)
         // Something to do with Adobe After Effects (?)
         case 'PrmA':
         case 'code':
         case 'FIEL':
             // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html
             // Observed-but-not-handled atom types are just listed here
             // to prevent warnings being generated
             $atom_structure['data'] = $atom_data;
             break;
         default:
             $getid3->warning('Unknown QuickTime atom type: "' . $atom_name . '" at offset ' . $base_offset);
             $atom_structure['data'] = $atom_data;
             break;
     }
     array_pop($atom_hierarchy);
     return $atom_structure;
 }
Esempio n. 15
0
 private function ParseDirectoryRecord($directory_data)
 {
     $getid3 = $this->getid3;
     $text_encoding = isset($getid3->info['iso']['supplementary_volume_descriptor']) ? 'UTF-16BE' : 'ISO-8859-1';
     fseek($getid3->fp, $directory_data['location_bytes'], SEEK_SET);
     $directory_record_data = fread($getid3->fp, 1);
     while (ord($directory_record_data[0]) > 33) {
         $directory_record_data .= fread($getid3->fp, ord($directory_record_data[0]) - 1);
         $this_directory_record = array();
         $this_directory_record['raw'] = array();
         $this_directory_record_raw =& $this_directory_record['raw'];
         getid3_lib::ReadSequence('LittleEndian2Int', $this_directory_record_raw, $directory_record_data, 0, array('length' => 1, 'extended_attribute_length' => 1, 'offset_logical' => 4, 'IGNORE-1' => 4, 'filesize' => 4, 'IGNORE-2' => 4, 'recording_date_time' => -7, 'file_flags' => 1, 'file_unit_size' => 1, 'interleave_gap_size' => 1, 'volume_sequence_number' => 2, 'IGNORE-3' => 2, 'file_identifier_length' => 1));
         $this_directory_record_raw['file_identifier'] = substr($directory_record_data, 33, $this_directory_record_raw['file_identifier_length']);
         $this_directory_record['file_identifier_ascii'] = $getid3->iconv($text_encoding, $getid3->encoding, $this_directory_record_raw['file_identifier'], true);
         $this_directory_record['filesize'] = $this_directory_record_raw['filesize'];
         $this_directory_record['offset_bytes'] = $this_directory_record_raw['offset_logical'] * 2048;
         $this_directory_record['file_flags']['hidden'] = (bool) ($this_directory_record_raw['file_flags'] & 0x1);
         $this_directory_record['file_flags']['directory'] = (bool) ($this_directory_record_raw['file_flags'] & 0x2);
         $this_directory_record['file_flags']['associated'] = (bool) ($this_directory_record_raw['file_flags'] & 0x4);
         $this_directory_record['file_flags']['extended'] = (bool) ($this_directory_record_raw['file_flags'] & 0x8);
         $this_directory_record['file_flags']['permissions'] = (bool) ($this_directory_record_raw['file_flags'] & 0x10);
         $this_directory_record['file_flags']['multiple'] = (bool) ($this_directory_record_raw['file_flags'] & 0x80);
         $this_directory_record['recording_timestamp'] = getid3_iso::ISOtime2UNIXtime($this_directory_record_raw['recording_date_time']);
         if ($this_directory_record['file_flags']['directory']) {
             $this_directory_record['filename'] = $directory_data['full_path'];
         } else {
             $this_directory_record['filename'] = $directory_data['full_path'] . getid3_iso::ISOstripFilenameVersion($this_directory_record['file_identifier_ascii']);
             $getid3->info['iso']['files'] = getid3_iso::array_merge_clobber($getid3->info['iso']['files'], getid3_iso::CreateDeepArray($this_directory_record['filename'], '/', $this_directory_record['filesize']));
         }
         $directory_record[] = $this_directory_record;
         $directory_record_data = fread($getid3->fp, 1);
     }
     return $directory_record;
 }
Esempio n. 16
0
 private function FLACparseSTREAMINFO($meta_data_block_data)
 {
     $getid3 = $this->getid3;
     getid3_lib::ReadSequence('BigEndian2Int', $getid3->info['flac']['STREAMINFO'], $meta_data_block_data, 0, array('min_block_size' => 2, 'max_block_size' => 2, 'min_frame_size' => 3, 'max_frame_size' => 3));
     $sample_rate_channels_sample_bits_stream_samples = getid3_lib::BigEndian2Bin(substr($meta_data_block_data, 10, 8));
     $getid3->info['flac']['STREAMINFO']['sample_rate'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 0, 20));
     $getid3->info['flac']['STREAMINFO']['channels'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 20, 3)) + 1;
     $getid3->info['flac']['STREAMINFO']['bits_per_sample'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 23, 5)) + 1;
     $getid3->info['flac']['STREAMINFO']['samples_stream'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 28, 36));
     // bindec() returns float in case of int overrun
     $getid3->info['flac']['STREAMINFO']['audio_signature'] = substr($meta_data_block_data, 18, 16);
     if (!empty($getid3->info['flac']['STREAMINFO']['sample_rate'])) {
         $getid3->info['audio']['bitrate_mode'] = 'vbr';
         $getid3->info['audio']['sample_rate'] = $getid3->info['flac']['STREAMINFO']['sample_rate'];
         $getid3->info['audio']['channels'] = $getid3->info['flac']['STREAMINFO']['channels'];
         $getid3->info['audio']['bits_per_sample'] = $getid3->info['flac']['STREAMINFO']['bits_per_sample'];
         $getid3->info['playtime_seconds'] = $getid3->info['flac']['STREAMINFO']['samples_stream'] / $getid3->info['flac']['STREAMINFO']['sample_rate'];
         $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     } else {
         throw new getid3_exception('Corrupt METAdata block: STREAMINFO');
     }
     unset($getid3->info['flac']['STREAMINFO']['raw']);
     return true;
 }
Esempio n. 17
0
 private function getNSVfHeader($file_offset = 0, $get_toc_offsets = false)
 {
     $getid3 = $this->getid3;
     fseek($getid3->fp, $file_offset, SEEK_SET);
     $nsvf_header = fread($getid3->fp, 28);
     $getid3->info['nsv']['NSVf'] = array();
     $info_nsv_NSVf =& $getid3->info['nsv']['NSVf'];
     $info_nsv_NSVf['identifier'] = substr($nsvf_header, 0, 4);
     if ($info_nsv_NSVf['identifier'] != 'NSVf') {
         throw new getid3_exception('expected "NSVf" at offset (' . $file_offset . '), found "' . $info_nsv_NSVf['identifier'] . '" instead');
     }
     $getid3->info['nsv']['NSVs']['offset'] = $file_offset;
     getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVf, $nsvf_header, 4, array('header_length' => 4, 'file_size' => 4, 'playtime_ms' => 4, 'meta_size' => 4, 'TOC_entries_1' => 4, 'TOC_entries_2' => 4));
     if ($info_nsv_NSVf['playtime_ms'] == 0) {
         throw new getid3_exception('Corrupt NSV file: NSVf.playtime_ms == zero');
     }
     if ($info_nsv_NSVf['file_size'] > $getid3->info['avdataend']) {
         $getid3->warning('truncated file - NSVf header indicates ' . $info_nsv_NSVf['file_size'] . ' bytes, file actually ' . $getid3->info['avdataend'] . ' bytes');
     }
     $nsvf_header .= fread($getid3->fp, $info_nsv_NSVf['meta_size'] + 4 * $info_nsv_NSVf['TOC_entries_1'] + 4 * $info_nsv_NSVf['TOC_entries_2']);
     $nsvf_headerlength = strlen($nsvf_header);
     $info_nsv_NSVf['metadata'] = substr($nsvf_header, 28, $info_nsv_NSVf['meta_size']);
     $offset = 28 + $info_nsv_NSVf['meta_size'];
     if ($get_toc_offsets) {
         $toc_counter = 0;
         while ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
             if ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
                 $info_nsv_NSVf['TOC_1'][$toc_counter] = getid3_lib::LittleEndian2Int(substr($nsvf_header, $offset, 4));
                 $offset += 4;
                 $toc_counter++;
             }
         }
     }
     if (trim($info_nsv_NSVf['metadata']) != '') {
         $info_nsv_NSVf['metadata'] = str_replace('`', "", $info_nsv_NSVf['metadata']);
         $comment_pair_array = explode("" . ' ', $info_nsv_NSVf['metadata']);
         foreach ($comment_pair_array as $comment_pair) {
             if (strstr($comment_pair, '=' . "")) {
                 list($key, $value) = explode('=' . "", $comment_pair, 2);
                 $getid3->info['nsv']['comments'][strtolower($key)][] = trim(str_replace("", '', $value));
             }
         }
     }
     $getid3->info['playtime_seconds'] = $info_nsv_NSVf['playtime_ms'] / 1000;
     $getid3->info['bitrate'] = $info_nsv_NSVf['file_size'] * 8 / $getid3->info['playtime_seconds'];
     return true;
 }
 public static function RIFFparseWAVEFORMATex($wave_format_ex_data)
 {
     $wave_format_ex['raw'] = array();
     $wave_format_ex_raw =& $wave_format_ex['raw'];
     getid3_lib::ReadSequence('LittleEndian2Int', $wave_format_ex_raw, $wave_format_ex_data, 0, array('wFormatTag' => 2, 'nChannels' => 2, 'nSamplesPerSec' => 4, 'nAvgBytesPerSec' => 4, 'nBlockAlign' => 2, 'wBitsPerSample' => 2));
     if (strlen($wave_format_ex_data) > 16) {
         $wave_format_ex_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($wave_format_ex_data, 16, 2));
     }
     $wave_format_ex['codec'] = getid3_riff::RIFFwFormatTagLookup($wave_format_ex_raw['wFormatTag']);
     $wave_format_ex['channels'] = $wave_format_ex_raw['nChannels'];
     $wave_format_ex['sample_rate'] = $wave_format_ex_raw['nSamplesPerSec'];
     $wave_format_ex['bitrate'] = $wave_format_ex_raw['nAvgBytesPerSec'] * 8;
     if (@$wave_format_ex_raw['wBitsPerSample']) {
         $wave_format_ex['bits_per_sample'] = $wave_format_ex_raw['wBitsPerSample'];
     }
     return $wave_format_ex;
 }
 public function Analyze()
 {
     $getid3 = $this->getid3;
     // based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de>
     // http://jfaul.de/atl  or  http://j-faul.virtualave.net/atl/atl.html
     $getid3->info['fileformat'] = 'mac';
     $getid3->info['audio']['dataformat'] = 'mac';
     $getid3->info['audio']['bitrate_mode'] = 'vbr';
     $getid3->info['audio']['lossless'] = true;
     $getid3->info['monkeys_audio']['raw'] = array();
     $info_monkeys_audio =& $getid3->info['monkeys_audio'];
     $info_monkeys_audio_raw =& $info_monkeys_audio['raw'];
     // Read file header
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     $mac_header_data = fread($getid3->fp, 74);
     $info_monkeys_audio_raw['magic'] = 'MAC ';
     // Magic bytes
     // Read MAC version
     $info_monkeys_audio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($mac_header_data, 4, 2));
     // appears to be uint32 in 3.98+
     // Parse MAC Header < v3980
     if ($info_monkeys_audio_raw['nVersion'] < 3980) {
         getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 6, array('nCompressionLevel' => 2, 'nFormatFlags' => 2, 'nChannels' => 2, 'nSampleRate' => 4, 'nHeaderDataBytes' => 4, 'nWAVTerminatingBytes' => 4, 'nTotalFrames' => 4, 'nFinalFrameSamples' => 4, 'nPeakLevel' => 4, 'IGNORE-1' => 2, 'nSeekElements' => 2));
     } else {
         getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 8, array('nDescriptorBytes' => 4, 'nHeaderBytes' => 4, 'nSeekTableBytes' => 4, 'nHeaderDataBytes' => 4, 'nAPEFrameDataBytes' => 4, 'nAPEFrameDataBytesHigh' => 4, 'nTerminatingDataBytes' => 4, 'cFileMD5' => -16, 'nCompressionLevel' => 2, 'nFormatFlags' => 2, 'nBlocksPerFrame' => 4, 'nFinalFrameBlocks' => 4, 'nTotalFrames' => 4, 'nBitsPerSample' => 2, 'nChannels' => 2, 'nSampleRate' => 4));
     }
     // Process data
     $info_monkeys_audio['flags']['8-bit'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x1);
     $info_monkeys_audio['flags']['crc-32'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x2);
     $info_monkeys_audio['flags']['peak_level'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x4);
     $info_monkeys_audio['flags']['24-bit'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x8);
     $info_monkeys_audio['flags']['seek_elements'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x10);
     $info_monkeys_audio['flags']['no_wav_header'] = (bool) ($info_monkeys_audio_raw['nFormatFlags'] & 0x20);
     $info_monkeys_audio['version'] = $info_monkeys_audio_raw['nVersion'] / 1000;
     $info_monkeys_audio['compression'] = getid3_monkey::MonkeyCompressionLevelNameLookup($info_monkeys_audio_raw['nCompressionLevel']);
     $info_monkeys_audio['bits_per_sample'] = $info_monkeys_audio['flags']['24-bit'] ? 24 : ($info_monkeys_audio['flags']['8-bit'] ? 8 : 16);
     $info_monkeys_audio['channels'] = $info_monkeys_audio_raw['nChannels'];
     $getid3->info['audio']['channels'] = $info_monkeys_audio['channels'];
     $info_monkeys_audio['sample_rate'] = $info_monkeys_audio_raw['nSampleRate'];
     $getid3->info['audio']['sample_rate'] = $info_monkeys_audio['sample_rate'];
     if ($info_monkeys_audio['flags']['peak_level']) {
         $info_monkeys_audio['peak_level'] = $info_monkeys_audio_raw['nPeakLevel'];
         $info_monkeys_audio['peak_ratio'] = $info_monkeys_audio['peak_level'] / pow(2, $info_monkeys_audio['bits_per_sample'] - 1);
     }
     // MAC >= v3980
     if ($info_monkeys_audio_raw['nVersion'] >= 3980) {
         $info_monkeys_audio['samples'] = ($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio_raw['nBlocksPerFrame'] + $info_monkeys_audio_raw['nFinalFrameBlocks'];
     } else {
         $info_monkeys_audio['samples_per_frame'] = getid3_monkey::MonkeySamplesPerFrame($info_monkeys_audio_raw['nVersion'], $info_monkeys_audio_raw['nCompressionLevel']);
         $info_monkeys_audio['samples'] = ($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio['samples_per_frame'] + $info_monkeys_audio_raw['nFinalFrameSamples'];
     }
     $info_monkeys_audio['playtime'] = $info_monkeys_audio['samples'] / $info_monkeys_audio['sample_rate'];
     $getid3->info['playtime_seconds'] = $info_monkeys_audio['playtime'];
     $info_monkeys_audio['compressed_size'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'];
     $info_monkeys_audio['uncompressed_size'] = $info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * ($info_monkeys_audio['bits_per_sample'] / 8);
     $info_monkeys_audio['compression_ratio'] = $info_monkeys_audio['compressed_size'] / ($info_monkeys_audio['uncompressed_size'] + $info_monkeys_audio_raw['nHeaderDataBytes']);
     $info_monkeys_audio['bitrate'] = $info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * $info_monkeys_audio['bits_per_sample'] / $info_monkeys_audio['playtime'] * $info_monkeys_audio['compression_ratio'];
     $getid3->info['audio']['bitrate'] = $info_monkeys_audio['bitrate'];
     $getid3->info['audio']['bits_per_sample'] = $info_monkeys_audio['bits_per_sample'];
     $getid3->info['audio']['encoder'] = 'MAC v' . number_format($info_monkeys_audio['version'], 2);
     $getid3->info['audio']['encoder_options'] = ucfirst($info_monkeys_audio['compression']) . ' compression';
     // MAC >= v3980 - get avdataoffsets from MAC header
     if ($info_monkeys_audio_raw['nVersion'] >= 3980) {
         $getid3->info['avdataoffset'] += $info_monkeys_audio_raw['nDescriptorBytes'] + $info_monkeys_audio_raw['nHeaderBytes'] + $info_monkeys_audio_raw['nSeekTableBytes'] + $info_monkeys_audio_raw['nHeaderDataBytes'];
         $getid3->info['avdataend'] -= $info_monkeys_audio_raw['nTerminatingDataBytes'];
     } else {
         $getid3->info['avdataoffset'] += 8;
     }
     // Convert md5sum to 32 byte string
     if (@$info_monkeys_audio_raw['cFileMD5']) {
         if ($info_monkeys_audio_raw['cFileMD5'] !== str_repeat("", 16)) {
             $getid3->info['md5_data_source'] = '';
             $md5 = $info_monkeys_audio_raw['cFileMD5'];
             for ($i = 0; $i < strlen($md5); $i++) {
                 $getid3->info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT);
             }
             if (!preg_match('/^[0-9a-f]{32}$/', $getid3->info['md5_data_source'])) {
                 unset($getid3->info['md5_data_source']);
             }
         }
     }
     return true;
 }
 public function Analyze()
 {
     $getid3 = $this->getid3;
     $getid3->include_module('audio-video.riff');
     $getid3->info['wavpack'] = array();
     $info_wavpack =& $getid3->info['wavpack'];
     fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
     while (true) {
         $wavpack_header = fread($getid3->fp, 32);
         if (ftell($getid3->fp) >= $getid3->info['avdataend']) {
             break;
         } elseif (feof($getid3->fp)) {
             break;
         } elseif (@$info_wavpack_blockheader['total_samples'] > 0 && @$info_wavpack_blockheader['block_samples'] > 0 && (!isset($info_wavpack['riff_trailer_size']) || $info_wavpack['riff_trailer_size'] <= 0) && (@$info_wavpack['config_flags']['md5_checksum'] === false || !empty($getid3->info['md5_data_source']))) {
             break;
         }
         $block_header_offset = ftell($getid3->fp) - 32;
         $block_header_magic = substr($wavpack_header, 0, 4);
         $block_header_size = getid3_lib::LittleEndian2Int(substr($wavpack_header, 4, 4));
         if ($block_header_magic != 'wvpk') {
             throw new getid3_exception('Expecting "wvpk" at offset ' . $block_header_offset . ', found "' . $block_header_magic . '"');
         }
         if (@$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.
             $getid3->info['audio']['dataformat'] = 'wavpack';
             $getid3->info['fileformat'] = 'wavpack';
             $getid3->info['audio']['lossless'] = true;
             $getid3->info['audio']['bitrate_mode'] = 'vbr';
             $info_wavpack['blockheader']['offset'] = $block_header_offset;
             $info_wavpack['blockheader']['magic'] = $block_header_magic;
             $info_wavpack['blockheader']['size'] = $block_header_size;
             $info_wavpack_blockheader =& $info_wavpack['blockheader'];
             if ($info_wavpack_blockheader['size'] >= 0x100000) {
                 throw new getid3_exception('Expecting WavPack block size less than "0x100000", found "' . $info_wavpack_blockheader['size'] . '" at offset ' . $info_wavpack_blockheader['offset']);
             }
             $info_wavpack_blockheader['minor_version'] = ord($wavpack_header[8]);
             $info_wavpack_blockheader['major_version'] = ord($wavpack_header[9]);
             if ($info_wavpack_blockheader['major_version'] != 4 || $info_wavpack_blockheader['minor_version'] < 4 && $info_wavpack_blockheader['minor_version'] > 16) {
                 throw new getid3_exception('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']);
             }
             $info_wavpack_blockheader['track_number'] = ord($wavpack_header[10]);
             // unused
             $info_wavpack_blockheader['index_number'] = ord($wavpack_header[11]);
             // unused
             getid3_lib::ReadSequence('LittleEndian2Int', $info_wavpack_blockheader, $wavpack_header, 12, array('total_samples' => 4, 'block_index' => 4, 'block_samples' => 4, 'flags_raw' => 4, 'crc' => 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);
             $getid3->info['audio']['lossless'] = !$info_wavpack_blockheader['flags']['hybrid'];
         }
         while (!feof($getid3->fp) && ftell($getid3->fp) < $block_header_offset + $block_header_size + 8) {
             $metablock = array('offset' => ftell($getid3->fp));
             $metablockheader = fread($getid3->fp, 2);
             if (feof($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($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($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($getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET);
                         break;
                     default:
                         $getid3->warning('Unexpected metablock type "0x' . str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT) . '" at offset ' . $metablock['offset']);
                         fseek($getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET);
                         break;
                 }
                 switch ($metablock['function_id']) {
                     case 0x21:
                         // ID_RIFF_HEADER
                         $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4));
                         // Clone getid3
                         $clone = clone $getid3;
                         // Analyze clone by string
                         $riff = new getid3_riff($clone);
                         $riff->AnalyzeString($metablock['data']);
                         // Import from clone and destroy
                         $metablock['riff'] = $clone->info['riff'];
                         $getid3->warnings($clone->warnings());
                         unset($clone);
                         // Save RIFF header - we may need it later for RIFF footer parsing
                         $this->riff_header = $metablock['data'];
                         $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'];
                         $getid3->info['audio']['sample_rate'] = $metablock['riff']['raw']['fmt ']['nSamplesPerSec'];
                         $getid3->info['playtime_seconds'] = $info_wavpack_blockheader['total_samples'] / $getid3->info['audio']['sample_rate'];
                         // Safe RIFF header in case there's a RIFF footer later
                         $metablock_riff_header = $metablock['data'];
                         break;
                     case 0x22:
                         // ID_RIFF_TRAILER
                         $metablock_riff_footer = $metablock_riff_header . $metablock['data'];
                         $start_offset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2);
                         $ftell_old = ftell($getid3->fp);
                         // Clone getid3
                         $clone = clone $getid3;
                         // Call public method that really should be private
                         $riff = new getid3_riff($clone);
                         $metablock['riff'] = $riff->ParseRIFF($start_offset, $start_offset + $metablock['size']);
                         unset($clone);
                         fseek($getid3->fp, $ftell_old, SEEK_SET);
                         if (!empty($metablock['riff']['INFO'])) {
                             getid3_riff::RIFFCommentsParse($metablock['riff']['INFO'], $metablock['comments']);
                             $getid3->info['tags']['riff'] = $metablock['comments'];
                         }
                         break;
                     case 0x23:
                         // ID_REPLAY_GAIN
                         $getid3->warning('WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset ' . $metablock['offset']);
                         break;
                     case 0x24:
                         // ID_CUESHEET
                         $getid3->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'];
                         $getid3->info['audio']['encoder_options'] = trim(($info_wavpack_blockheader['flags']['hybrid'] ? ' -b???' : '') . ($metablock['flags']['adobe_mode'] ? ' -a' : '') . ($metablock['flags']['optimize_wvc'] ? ' -cc' : '') . ($metablock['flags']['create_exe'] ? ' -e' : '') . ($metablock['flags']['fast_flag'] ? ' -f' : '') . ($metablock['flags']['joint_override'] ? ' -j?' : '') . ($metablock['flags']['high_flag'] ? ' -h' : '') . ($metablock['flags']['md5_checksum'] ? ' -m' : '') . ($metablock['flags']['calc_noise'] ? ' -n' : '') . ($metablock['flags']['shape_override'] ? ' -s?' : '') . ($metablock['flags']['extra_mode'] ? ' -x?' : ''));
                         if (!$getid3->info['audio']['encoder_options']) {
                             unset($getid3->info['audio']['encoder_options']);
                         }
                         break;
                     case 0x26:
                         // ID_MD5_CHECKSUM
                         if (strlen($metablock['data']) == 16) {
                             $getid3->info['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false));
                         } else {
                             $getid3->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;
             }
         }
     }
     $getid3->info['audio']['encoder'] = 'WavPack v' . $info_wavpack_blockheader['major_version'] . '.' . str_pad($info_wavpack_blockheader['minor_version'], 2, '0', STR_PAD_LEFT);
     $getid3->info['audio']['bits_per_sample'] = $info_wavpack_blockheader['flags']['bytes_per_sample'] * 8;
     $getid3->info['audio']['channels'] = $info_wavpack_blockheader['flags']['mono'] ? 1 : 2;
     if (@$getid3->info['playtime_seconds']) {
         $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
     } else {
         $getid3->info['audio']['dataformat'] = 'wvc';
     }
     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;
 }
 public static function ParseOldRAheader($old_ra_header_data, &$parsed_array)
 {
     // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
     $parsed_array = array();
     $parsed_array['magic'] = substr($old_ra_header_data, 0, 4);
     if ($parsed_array['magic'] != '.ra' . "ý") {
         return false;
     }
     $parsed_array['version1'] = getid3_lib::BigEndian2Int(substr($old_ra_header_data, 4, 2));
     if ($parsed_array['version1'] < 3) {
         return false;
     }
     if ($parsed_array['version1'] == 3) {
         $parsed_array['fourcc1'] = '.ra3';
         $parsed_array['bits_per_sample'] = 16;
         // hard-coded for old versions?
         $parsed_array['sample_rate'] = 8000;
         // hard-coded for old versions?
         getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6, array('header_size' => 2, 'channels' => 2, 'IGNORE-unknown1' => 2, 'IGNORE-unknown2' => 2, 'IGNORE-unknown3' => 2, 'bytes_per_minute' => 2, 'audio_bytes' => 4));
         $parsed_array['comments_raw'] = substr($old_ra_header_data, 22, $parsed_array['header_size'] - 22 + 1);
         // not including null terminator
         $comment_offset = 0;
         foreach (array('title', 'artist', 'copyright') as $name) {
             $comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw'][$comment_offset++]);
             $parsed_array['comments'][$name][] = substr($parsed_array['comments_raw'], $comment_offset, $comment_length);
             $comment_offset += $comment_length;
         }
         $comment_offset++;
         // final null terminator (?)
         $comment_offset++;
         // fourcc length (?) should be 4
         $parsed_array['fourcc'] = substr($old_ra_header_data, 23 + $comment_offset, 4);
     } elseif ($parsed_array['version1'] <= 5) {
         getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6, array('IGNORE-unknown1' => 2, 'fourcc1' => -4, 'file_size' => 4, 'version2' => 2, 'header_size' => 4, 'codec_flavor_id' => 2, 'coded_frame_size' => 4, 'audio_bytes' => 4, 'bytes_per_minute' => 4, 'IGNORE-unknown5' => 4, 'sub_packet_h' => 2, 'frame_size' => 2, 'sub_packet_size' => 2, 'IGNORE-unknown6' => 2));
         switch ($parsed_array['version1']) {
             case 4:
                 getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48, array('sample_rate' => 2, 'IGNORE-unknown8' => 2, 'bits_per_sample' => 2, 'channels' => 2, 'length_fourcc2' => 1, 'fourcc2' => -4, 'length_fourcc3' => 1, 'fourcc3' => -4, 'IGNORE-unknown9' => 1, 'IGNORE-unknown10' => 2));
                 $parsed_array['comments_raw'] = substr($old_ra_header_data, 69, $parsed_array['header_size'] - 69 + 16);
                 $comment_offset = 0;
                 foreach (array('title', 'artist', 'copyright') as $name) {
                     $comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw'][$comment_offset++]);
                     $parsed_array['comments'][$name][] = substr($parsed_array['comments_raw'], $comment_offset, $comment_length);
                     $comment_offset += $comment_length;
                 }
                 break;
             case 5:
                 getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48, array('sample_rate' => 4, 'sample_rate2' => 4, 'bits_per_sample' => 4, 'channels' => 2, 'genr' => -4, 'fourcc3' => -4));
                 $parsed_array['comments'] = array();
                 break;
         }
         $parsed_array['fourcc'] = $parsed_array['fourcc3'];
     }
     foreach ($parsed_array['comments'] as $key => $value) {
         if ($parsed_array['comments'][$key][0] === false) {
             $parsed_array['comments'][$key][0] = '';
         }
     }
     return true;
 }