annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.asf.php @ 13:f16185fe9ed9 judyates

[svn r14]
author rlm
date Mon, 12 Apr 2010 03:30:00 -0400
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.audio-video.php |
rlm@3 18 // | Module for analyzing Microsoft ASF, WMA and WMV files. |
rlm@3 19 // | dependencies: module.audio-video.riff.php |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio-video.asf.php,v 1.7 2006/12/01 22:39:48 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_asf extends getid3_handler
rlm@3 27 {
rlm@3 28
rlm@3 29 const Extended_Stream_Properties_Object = '14E6A5CB-C672-4332-8399-A96952065B5A';
rlm@3 30 const Padding_Object = '1806D474-CADF-4509-A4BA-9AABCB96AAE8';
rlm@3 31 const Payload_Ext_Syst_Pixel_Aspect_Ratio = '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8';
rlm@3 32 const Script_Command_Object = '1EFB1A30-0B62-11D0-A39B-00A0C90348F6';
rlm@3 33 const No_Error_Correction = '20FB5700-5B55-11CF-A8FD-00805F5C442B';
rlm@3 34 const Content_Branding_Object = '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E';
rlm@3 35 const Content_Encryption_Object = '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E';
rlm@3 36 const Digital_Signature_Object = '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E';
rlm@3 37 const Extended_Content_Encryption_Object = '298AE614-2622-4C17-B935-DAE07EE9289C';
rlm@3 38 const Simple_Index_Object = '33000890-E5B1-11CF-89F4-00A0C90349CB';
rlm@3 39 const Degradable_JPEG_Media = '35907DE0-E415-11CF-A917-00805F5C442B';
rlm@3 40 const Payload_Extension_System_Timecode = '399595EC-8667-4E2D-8FDB-98814CE76C1E';
rlm@3 41 const Binary_Media = '3AFB65E2-47EF-40F2-AC2C-70A90D71D343';
rlm@3 42 const Timecode_Index_Object = '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C';
rlm@3 43 const Metadata_Library_Object = '44231C94-9498-49D1-A141-1D134E457054';
rlm@3 44 const Reserved_3 = '4B1ACBE3-100B-11D0-A39B-00A0C90348F6';
rlm@3 45 const Reserved_4 = '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB';
rlm@3 46 const Command_Media = '59DACFC0-59E6-11D0-A3AC-00A0C90348F6';
rlm@3 47 const Header_Extension_Object = '5FBF03B5-A92E-11CF-8EE3-00C00C205365';
rlm@3 48 const Media_Object_Index_Parameters_Obj = '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7';
rlm@3 49 const Header_Object = '75B22630-668E-11CF-A6D9-00AA0062CE6C';
rlm@3 50 const Content_Description_Object = '75B22633-668E-11CF-A6D9-00AA0062CE6C';
rlm@3 51 const Error_Correction_Object = '75B22635-668E-11CF-A6D9-00AA0062CE6C';
rlm@3 52 const Data_Object = '75B22636-668E-11CF-A6D9-00AA0062CE6C';
rlm@3 53 const Web_Stream_Media_Subtype = '776257D4-C627-41CB-8F81-7AC7FF1C40CC';
rlm@3 54 const Stream_Bitrate_Properties_Object = '7BF875CE-468D-11D1-8D82-006097C9A2B2';
rlm@3 55 const Language_List_Object = '7C4346A9-EFE0-4BFC-B229-393EDE415C85';
rlm@3 56 const Codec_List_Object = '86D15240-311D-11D0-A3A4-00A0C90348F6';
rlm@3 57 const Reserved_2 = '86D15241-311D-11D0-A3A4-00A0C90348F6';
rlm@3 58 const File_Properties_Object = '8CABDCA1-A947-11CF-8EE4-00C00C205365';
rlm@3 59 const File_Transfer_Media = '91BD222C-F21C-497A-8B6D-5AA86BFC0185';
rlm@3 60 const Old_RTP_Extension_Data = '96800C63-4C94-11D1-837B-0080C7A37F95';
rlm@3 61 const Advanced_Mutual_Exclusion_Object = 'A08649CF-4775-4670-8A16-6E35357566CD';
rlm@3 62 const Bandwidth_Sharing_Object = 'A69609E6-517B-11D2-B6AF-00C04FD908E9';
rlm@3 63 const Reserved_1 = 'ABD3D211-A9BA-11CF-8EE6-00C00C205365';
rlm@3 64 const Bandwidth_Sharing_Exclusive = 'AF6060AA-5197-11D2-B6AF-00C04FD908E9';
rlm@3 65 const Bandwidth_Sharing_Partial = 'AF6060AB-5197-11D2-B6AF-00C04FD908E9';
rlm@3 66 const JFIF_Media = 'B61BE100-5B4E-11CF-A8FD-00805F5C442B';
rlm@3 67 const Stream_Properties_Object = 'B7DC0791-A9B7-11CF-8EE6-00C00C205365';
rlm@3 68 const Video_Media = 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B';
rlm@3 69 const Audio_Spread = 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220';
rlm@3 70 const Metadata_Object = 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA';
rlm@3 71 const Payload_Ext_Syst_Sample_Duration = 'C6BD9450-867F-4907-83A3-C77921B733AD';
rlm@3 72 const Group_Mutual_Exclusion_Object = 'D1465A40-5A79-4338-B71B-E36B8FD6C249';
rlm@3 73 const Extended_Content_Description_Object = 'D2D0A440-E307-11D2-97F0-00A0C95EA850';
rlm@3 74 const Stream_Prioritization_Object = 'D4FED15B-88D3-454F-81F0-ED5C45999E24';
rlm@3 75 const Payload_Ext_System_Content_Type = 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC';
rlm@3 76 const Old_File_Properties_Object = 'D6E229D0-35DA-11D1-9034-00A0C90349BE';
rlm@3 77 const Old_ASF_Header_Object = 'D6E229D1-35DA-11D1-9034-00A0C90349BE';
rlm@3 78 const Old_ASF_Data_Object = 'D6E229D2-35DA-11D1-9034-00A0C90349BE';
rlm@3 79 const Index_Object = 'D6E229D3-35DA-11D1-9034-00A0C90349BE';
rlm@3 80 const Old_Stream_Properties_Object = 'D6E229D4-35DA-11D1-9034-00A0C90349BE';
rlm@3 81 const Old_Content_Description_Object = 'D6E229D5-35DA-11D1-9034-00A0C90349BE';
rlm@3 82 const Old_Script_Command_Object = 'D6E229D6-35DA-11D1-9034-00A0C90349BE';
rlm@3 83 const Old_Marker_Object = 'D6E229D7-35DA-11D1-9034-00A0C90349BE';
rlm@3 84 const Old_Component_Download_Object = 'D6E229D8-35DA-11D1-9034-00A0C90349BE';
rlm@3 85 const Old_Stream_Group_Object = 'D6E229D9-35DA-11D1-9034-00A0C90349BE';
rlm@3 86 const Old_Scalable_Object = 'D6E229DA-35DA-11D1-9034-00A0C90349BE';
rlm@3 87 const Old_Prioritization_Object = 'D6E229DB-35DA-11D1-9034-00A0C90349BE';
rlm@3 88 const Bitrate_Mutual_Exclusion_Object = 'D6E229DC-35DA-11D1-9034-00A0C90349BE';
rlm@3 89 const Old_Inter_Media_Dependency_Object = 'D6E229DD-35DA-11D1-9034-00A0C90349BE';
rlm@3 90 const Old_Rating_Object = 'D6E229DE-35DA-11D1-9034-00A0C90349BE';
rlm@3 91 const Index_Parameters_Object = 'D6E229DF-35DA-11D1-9034-00A0C90349BE';
rlm@3 92 const Old_Color_Table_Object = 'D6E229E0-35DA-11D1-9034-00A0C90349BE';
rlm@3 93 const Old_Language_List_Object = 'D6E229E1-35DA-11D1-9034-00A0C90349BE';
rlm@3 94 const Old_Audio_Media = 'D6E229E2-35DA-11D1-9034-00A0C90349BE';
rlm@3 95 const Old_Video_Media = 'D6E229E3-35DA-11D1-9034-00A0C90349BE';
rlm@3 96 const Old_Image_Media = 'D6E229E4-35DA-11D1-9034-00A0C90349BE';
rlm@3 97 const Old_Timecode_Media = 'D6E229E5-35DA-11D1-9034-00A0C90349BE';
rlm@3 98 const Old_Text_Media = 'D6E229E6-35DA-11D1-9034-00A0C90349BE';
rlm@3 99 const Old_MIDI_Media = 'D6E229E7-35DA-11D1-9034-00A0C90349BE';
rlm@3 100 const Old_Command_Media = 'D6E229E8-35DA-11D1-9034-00A0C90349BE';
rlm@3 101 const Old_No_Error_Concealment = 'D6E229EA-35DA-11D1-9034-00A0C90349BE';
rlm@3 102 const Old_Scrambled_Audio = 'D6E229EB-35DA-11D1-9034-00A0C90349BE';
rlm@3 103 const Old_No_Color_Table = 'D6E229EC-35DA-11D1-9034-00A0C90349BE';
rlm@3 104 const Old_SMPTE_Time = 'D6E229ED-35DA-11D1-9034-00A0C90349BE';
rlm@3 105 const Old_ASCII_Text = 'D6E229EE-35DA-11D1-9034-00A0C90349BE';
rlm@3 106 const Old_Unicode_Text = 'D6E229EF-35DA-11D1-9034-00A0C90349BE';
rlm@3 107 const Old_HTML_Text = 'D6E229F0-35DA-11D1-9034-00A0C90349BE';
rlm@3 108 const Old_URL_Command = 'D6E229F1-35DA-11D1-9034-00A0C90349BE';
rlm@3 109 const Old_Filename_Command = 'D6E229F2-35DA-11D1-9034-00A0C90349BE';
rlm@3 110 const Old_ACM_Codec = 'D6E229F3-35DA-11D1-9034-00A0C90349BE';
rlm@3 111 const Old_VCM_Codec = 'D6E229F4-35DA-11D1-9034-00A0C90349BE';
rlm@3 112 const Old_QuickTime_Codec = 'D6E229F5-35DA-11D1-9034-00A0C90349BE';
rlm@3 113 const Old_DirectShow_Transform_Filter = 'D6E229F6-35DA-11D1-9034-00A0C90349BE';
rlm@3 114 const Old_DirectShow_Rendering_Filter = 'D6E229F7-35DA-11D1-9034-00A0C90349BE';
rlm@3 115 const Old_No_Enhancement = 'D6E229F8-35DA-11D1-9034-00A0C90349BE';
rlm@3 116 const Old_Unknown_Enhancement_Type = 'D6E229F9-35DA-11D1-9034-00A0C90349BE';
rlm@3 117 const Old_Temporal_Enhancement = 'D6E229FA-35DA-11D1-9034-00A0C90349BE';
rlm@3 118 const Old_Spatial_Enhancement = 'D6E229FB-35DA-11D1-9034-00A0C90349BE';
rlm@3 119 const Old_Quality_Enhancement = 'D6E229FC-35DA-11D1-9034-00A0C90349BE';
rlm@3 120 const Old_Number_of_Channels_Enhancement = 'D6E229FD-35DA-11D1-9034-00A0C90349BE';
rlm@3 121 const Old_Frequency_Response_Enhancement = 'D6E229FE-35DA-11D1-9034-00A0C90349BE';
rlm@3 122 const Old_Media_Object = 'D6E229FF-35DA-11D1-9034-00A0C90349BE';
rlm@3 123 const Mutex_Language = 'D6E22A00-35DA-11D1-9034-00A0C90349BE';
rlm@3 124 const Mutex_Bitrate = 'D6E22A01-35DA-11D1-9034-00A0C90349BE';
rlm@3 125 const Mutex_Unknown = 'D6E22A02-35DA-11D1-9034-00A0C90349BE';
rlm@3 126 const Old_ASF_Placeholder_Object = 'D6E22A0E-35DA-11D1-9034-00A0C90349BE';
rlm@3 127 const Old_Data_Unit_Extension_Object = 'D6E22A0F-35DA-11D1-9034-00A0C90349BE';
rlm@3 128 const Web_Stream_Format = 'DA1E6B13-8359-4050-B398-388E965BF00C';
rlm@3 129 const Payload_Ext_System_File_Name = 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B';
rlm@3 130 const Marker_Object = 'F487CD01-A951-11CF-8EE6-00C00C205365';
rlm@3 131 const Timecode_Index_Parameters_Object = 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24';
rlm@3 132 const Audio_Media = 'F8699E40-5B4D-11CF-A8FD-00805F5C442B';
rlm@3 133 const Media_Object_Index_Object = 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C';
rlm@3 134 const Alt_Extended_Content_Encryption_Obj = 'FF889EF1-ADEE-40DA-9E71-98704BB928CE';
rlm@3 135
rlm@3 136
rlm@3 137
rlm@3 138 public function Analyze() {
rlm@3 139
rlm@3 140 $getid3 = $this->getid3;
rlm@3 141
rlm@3 142 $getid3->include_module('audio-video.riff');
rlm@3 143
rlm@3 144 !isset($getid3->info['audio']) and $getid3->info['audio'] = array ();
rlm@3 145 !isset($getid3->info['video']) and $getid3->info['video'] = array ();
rlm@3 146 $getid3->info['asf']['comments'] = $getid3->info['asf']['header_object'] = array ();
rlm@3 147
rlm@3 148 $info_audio = &$getid3->info['audio'];
rlm@3 149 $info_video = &$getid3->info['video'];
rlm@3 150 $info_asf = &$getid3->info['asf'];
rlm@3 151 $info_asf_comments = &$info_asf['comments'];
rlm@3 152 $info_asf_header_object = &$info_asf['header_object'];
rlm@3 153
rlm@3 154 // ASF structure:
rlm@3 155 // * Header Object [required]
rlm@3 156 // * File Properties Object [required] (global file attributes)
rlm@3 157 // * Stream Properties Object [required] (defines media stream & characteristics)
rlm@3 158 // * Header Extension Object [required] (additional functionality)
rlm@3 159 // * Content Description Object (bibliographic information)
rlm@3 160 // * Script Command Object (commands for during playback)
rlm@3 161 // * Marker Object (named jumped points within the file)
rlm@3 162 // * Data Object [required]
rlm@3 163 // * Data Packets
rlm@3 164 // * Index Object
rlm@3 165
rlm@3 166 // Header Object: (mandatory, one only)
rlm@3 167 // Field Name Field Type Size (bits)
rlm@3 168 // Object ID GUID 128 // GUID for header object - getid3_asf::Header_Object
rlm@3 169 // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header
rlm@3 170 // Number of Header Objects DWORD 32 // number of objects in header object
rlm@3 171 // Reserved1 BYTE 8 // hardcoded: 0x01
rlm@3 172 // Reserved2 BYTE 8 // hardcoded: 0x02
rlm@3 173
rlm@3 174 $getid3->info['fileformat'] = 'asf';
rlm@3 175
rlm@3 176 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 177 $header_object_data = fread($getid3->fp, 30);
rlm@3 178
rlm@3 179 $info_asf_header_object['objectid_guid'] = getid3_asf::BytestringToGUID(substr($header_object_data, 0, 16));
rlm@3 180
rlm@3 181 if ($info_asf_header_object['objectid_guid'] != getid3_asf::Header_Object) {
rlm@3 182 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.'}');
rlm@3 183 }
rlm@3 184
rlm@3 185 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_header_object, $header_object_data, 16,
rlm@3 186 array (
rlm@3 187 'objectsize' => 8,
rlm@3 188 'headerobjects' => 4,
rlm@3 189 'reserved1' => 1,
rlm@3 190 'reserved2' => 1
rlm@3 191 )
rlm@3 192 );
rlm@3 193
rlm@3 194 $asf_header_data = fread($getid3->fp, $info_asf_header_object['objectsize'] - 30);
rlm@3 195 $offset = 0;
rlm@3 196
rlm@3 197 for ($header_objects_counter = 0; $header_objects_counter < $info_asf_header_object['headerobjects']; $header_objects_counter++) {
rlm@3 198
rlm@3 199 $next_object_guid = substr($asf_header_data, $offset, 16);
rlm@3 200 $offset += 16;
rlm@3 201
rlm@3 202 $next_object_size = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 8));
rlm@3 203 $offset += 8;
rlm@3 204
rlm@3 205 $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid);
rlm@3 206
rlm@3 207 switch ($next_object_guidtext) {
rlm@3 208
rlm@3 209 case getid3_asf::File_Properties_Object:
rlm@3 210
rlm@3 211 // File Properties Object: (mandatory, one only)
rlm@3 212 // Field Name Field Type Size (bits)
rlm@3 213 // Object ID GUID 128 // GUID for file properties object - getid3_asf::File_Properties_Object
rlm@3 214 // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header
rlm@3 215 // File ID GUID 128 // unique ID - identical to File ID in Data Object
rlm@3 216 // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1
rlm@3 217 // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1
rlm@3 218 // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1
rlm@3 219 // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
rlm@3 220 // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
rlm@3 221 // 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
rlm@3 222 // Flags DWORD 32 //
rlm@3 223 // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid
rlm@3 224 // * Seekable Flag bits 1 (0x02) // is file seekable
rlm@3 225 // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero
rlm@3 226 // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
rlm@3 227 // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
rlm@3 228 // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
rlm@3 229
rlm@3 230 $info_asf['file_properties_object'] = array ();
rlm@3 231 $info_asf_file_properties_object = &$info_asf['file_properties_object'];
rlm@3 232
rlm@3 233 $info_asf_file_properties_object['objectid_guid'] = $next_object_guidtext;
rlm@3 234 $info_asf_file_properties_object['objectsize'] = $next_object_size;
rlm@3 235
rlm@3 236 $info_asf_file_properties_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
rlm@3 237 $offset += 16;
rlm@3 238
rlm@3 239 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_file_properties_object, $asf_header_data, $offset,
rlm@3 240 array (
rlm@3 241 'filesize' => 8,
rlm@3 242 'creation_date' => 8,
rlm@3 243 'data_packets' => 8,
rlm@3 244 'play_duration' => 8,
rlm@3 245 'send_duration' => 8,
rlm@3 246 'preroll' => 8,
rlm@3 247 'flags_raw' => 4,
rlm@3 248 'min_packet_size' => 4,
rlm@3 249 'max_packet_size' => 4,
rlm@3 250 'max_bitrate' => 4
rlm@3 251 )
rlm@3 252 );
rlm@3 253
rlm@3 254 $offset += 64 ;
rlm@3 255
rlm@3 256 $info_asf_file_properties_object['creation_date_unix'] = getid3_asf::FiletimeToUNIXtime($info_asf_file_properties_object['creation_date']);
rlm@3 257 $info_asf_file_properties_object['flags']['broadcast'] = (bool)($info_asf_file_properties_object['flags_raw'] & 0x0001);
rlm@3 258 $info_asf_file_properties_object['flags']['seekable'] = (bool)($info_asf_file_properties_object['flags_raw'] & 0x0002);
rlm@3 259
rlm@3 260 $getid3->info['playtime_seconds'] = ($info_asf_file_properties_object['play_duration'] / 10000000) - ($info_asf_file_properties_object['preroll'] / 1000);
rlm@3 261 $getid3->info['bitrate'] = ($info_asf_file_properties_object['filesize'] * 8) / $getid3->info['playtime_seconds'];
rlm@3 262 break;
rlm@3 263
rlm@3 264
rlm@3 265 case getid3_asf::Stream_Properties_Object:
rlm@3 266
rlm@3 267 // Stream Properties Object: (mandatory, one per media stream)
rlm@3 268 // Field Name Field Type Size (bits)
rlm@3 269 // Object ID GUID 128 // GUID for stream properties object - getid3_asf::Stream_Properties_Object
rlm@3 270 // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header
rlm@3 271 // Stream Type GUID 128 // getid3_asf::Audio_Media, getid3_asf::Video_Media or getid3_asf::Command_Media
rlm@3 272 // Error Correction Type GUID 128 // getid3_asf::Audio_Spread for audio-only streams, getid3_asf::No_Error_Correction for other stream types
rlm@3 273 // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
rlm@3 274 // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field
rlm@3 275 // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field
rlm@3 276 // Flags WORD 16 //
rlm@3 277 // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127
rlm@3 278 // * Reserved bits 8 (0x7F80) // reserved - set to zero
rlm@3 279 // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set
rlm@3 280 // Reserved DWORD 32 // reserved - set to zero
rlm@3 281 // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type
rlm@3 282 // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type
rlm@3 283
rlm@3 284 // There is one getid3_asf::Stream_Properties_Object for each stream (audio, video) but the
rlm@3 285 // stream number isn't known until halfway through decoding the structure, hence it
rlm@3 286 // it is decoded to a temporary variable and then stuck in the appropriate index later
rlm@3 287
rlm@3 288 $stream_properties_object_data['objectid_guid'] = $next_object_guidtext;
rlm@3 289 $stream_properties_object_data['objectsize'] = $next_object_size;
rlm@3 290
rlm@3 291 getid3_lib::ReadSequence('LittleEndian2Int', $stream_properties_object_data, $asf_header_data, $offset,
rlm@3 292 array (
rlm@3 293 'stream_type' => -16,
rlm@3 294 'error_correct_type' => -16,
rlm@3 295 'time_offset' => 8,
rlm@3 296 'type_data_length' => 4,
rlm@3 297 'error_data_length' => 4,
rlm@3 298 'flags_raw' => 2
rlm@3 299 )
rlm@3 300 );
rlm@3 301
rlm@3 302 $stream_properties_stream_number = $stream_properties_object_data['flags_raw'] & 0x007F;
rlm@3 303 $stream_properties_object_data['flags']['encrypted'] = (bool)($stream_properties_object_data['flags_raw'] & 0x8000);
rlm@3 304
rlm@3 305 $stream_properties_object_data['stream_type_guid'] = getid3_asf::BytestringToGUID($stream_properties_object_data['stream_type']);
rlm@3 306 $stream_properties_object_data['error_correct_guid'] = getid3_asf::BytestringToGUID($stream_properties_object_data['error_correct_type']);
rlm@3 307
rlm@3 308 $offset += 54; // 50 bytes + 4 bytes reserved - DWORD
rlm@3 309
rlm@3 310 $stream_properties_object_data['type_specific_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['type_data_length']);
rlm@3 311 $offset += $stream_properties_object_data['type_data_length'];
rlm@3 312
rlm@3 313 $stream_properties_object_data['error_correct_data'] = substr($asf_header_data, $offset, $stream_properties_object_data['error_data_length']);
rlm@3 314 $offset += $stream_properties_object_data['error_data_length'];
rlm@3 315
rlm@3 316 switch ($stream_properties_object_data['stream_type_guid']) {
rlm@3 317
rlm@3 318 case getid3_asf::Audio_Media:
rlm@3 319
rlm@3 320 $info_audio['dataformat'] = (@$info_audio['dataformat'] ? $info_audio['dataformat'] : 'asf');
rlm@3 321 $info_audio['bitrate_mode'] = (@$info_audio['bitrate_mode'] ? $info_audio['bitrate_mode'] : 'cbr');
rlm@3 322
rlm@3 323 $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($stream_properties_object_data['type_specific_data'], 0, 16));
rlm@3 324 unset($audiodata['raw']);
rlm@3 325 $info_audio = getid3_riff::array_merge_noclobber($audiodata, $info_audio);
rlm@3 326 break;
rlm@3 327
rlm@3 328
rlm@3 329 case getid3_asf::Video_Media:
rlm@3 330
rlm@3 331 $info_video['dataformat'] = (@$info_video['dataformat'] ? $info_video['dataformat'] : 'asf');
rlm@3 332 $info_video['bitrate_mode'] = (@$info_video['bitrate_mode'] ? $info_video['bitrate_mode'] : 'cbr');
rlm@3 333 break;
rlm@3 334
rlm@3 335
rlm@3 336 /* does nothing but eat memory
rlm@3 337 case getid3_asf::Command_Media:
rlm@3 338 default:
rlm@3 339 // do nothing
rlm@3 340 break;
rlm@3 341 */
rlm@3 342 }
rlm@3 343
rlm@3 344 $info_asf['stream_properties_object'][$stream_properties_stream_number] = $stream_properties_object_data;
rlm@3 345 unset($stream_properties_object_data); // clear for next stream, if any
rlm@3 346 break;
rlm@3 347
rlm@3 348
rlm@3 349 case getid3_asf::Header_Extension_Object:
rlm@3 350
rlm@3 351 // Header Extension Object: (mandatory, one only)
rlm@3 352 // Field Name Field Type Size (bits)
rlm@3 353 // Object ID GUID 128 // GUID for Header Extension object - getid3_asf::Header_Extension_Object
rlm@3 354 // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header
rlm@3 355 // Reserved Field 1 GUID 128 // hardcoded: getid3_asf::Reserved_1
rlm@3 356 // Reserved Field 2 WORD 16 // hardcoded: 0x00000006
rlm@3 357 // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46
rlm@3 358 // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects
rlm@3 359
rlm@3 360 $info_asf['header_extension_object'] = array ();
rlm@3 361 $info_asf_header_extension_object = &$info_asf['header_extension_object'];
rlm@3 362
rlm@3 363 $info_asf_header_extension_object['objectid_guid'] = $next_object_guidtext;
rlm@3 364 $info_asf_header_extension_object['objectsize'] = $next_object_size;
rlm@3 365 $info_asf_header_extension_object['reserved_1_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
rlm@3 366 $offset += 16;
rlm@3 367
rlm@3 368 if ($info_asf_header_extension_object['reserved_1_guid'] != getid3_asf::Reserved_1) {
rlm@3 369 $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.')');
rlm@3 370 break;
rlm@3 371 }
rlm@3 372
rlm@3 373 $info_asf_header_extension_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 374 $offset += 2;
rlm@3 375
rlm@3 376 if ($info_asf_header_extension_object['reserved_2'] != 6) {
rlm@3 377 $getid3->warning('header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($info_asf_header_extension_object['reserved_2']).') does not match expected value of "6"');
rlm@3 378 break;
rlm@3 379 }
rlm@3 380
rlm@3 381 $info_asf_header_extension_object['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
rlm@3 382 $offset += 4;
rlm@3 383
rlm@3 384 $info_asf_header_extension_object['extension_data'] = substr($asf_header_data, $offset, $info_asf_header_extension_object['extension_data_size']);
rlm@3 385 $offset += $info_asf_header_extension_object['extension_data_size'];
rlm@3 386 break;
rlm@3 387
rlm@3 388
rlm@3 389 case getid3_asf::Codec_List_Object:
rlm@3 390
rlm@3 391 // Codec List Object: (optional, one only)
rlm@3 392 // Field Name Field Type Size (bits)
rlm@3 393 // Object ID GUID 128 // GUID for Codec List object - getid3_asf::Codec_List_Object
rlm@3 394 // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header
rlm@3 395 // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
rlm@3 396 // Codec Entries Count DWORD 32 // number of entries in Codec Entries array
rlm@3 397 // Codec Entries array of: variable //
rlm@3 398 // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
rlm@3 399 // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field
rlm@3 400 // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content
rlm@3 401 // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field
rlm@3 402 // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content
rlm@3 403 // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field
rlm@3 404 // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content
rlm@3 405
rlm@3 406 $info_asf['codec_list_object'] = array ();
rlm@3 407 $info_asf_codec_list_object = &$info_asf['codec_list_object'];
rlm@3 408
rlm@3 409 $info_asf_codec_list_object['objectid_guid'] = $next_object_guidtext;
rlm@3 410 $info_asf_codec_list_object['objectsize'] = $next_object_size;
rlm@3 411
rlm@3 412 $info_asf_codec_list_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
rlm@3 413 $offset += 16;
rlm@3 414
rlm@3 415 if ($info_asf_codec_list_object['reserved_guid'] != '86D15241-311D-11D0-A3A4-00A0C90348F6') {
rlm@3 416 $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}');
rlm@3 417 break;
rlm@3 418 }
rlm@3 419
rlm@3 420 $info_asf_codec_list_object['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
rlm@3 421 $offset += 4;
rlm@3 422
rlm@3 423 for ($codec_entry_counter = 0; $codec_entry_counter < $info_asf_codec_list_object['codec_entries_count']; $codec_entry_counter++) {
rlm@3 424
rlm@3 425 $info_asf_codec_list_object['codec_entries'][$codec_entry_counter] = array ();
rlm@3 426 $info_asf_codec_list_object_codecentries_current = &$info_asf_codec_list_object['codec_entries'][$codec_entry_counter];
rlm@3 427
rlm@3 428 $info_asf_codec_list_object_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 429 $offset += 2;
rlm@3 430
rlm@3 431 $info_asf_codec_list_object_codecentries_current['type'] = getid3_asf::ASFCodecListObjectTypeLookup($info_asf_codec_list_object_codecentries_current['type_raw']);
rlm@3 432
rlm@3 433 $codec_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character
rlm@3 434 $offset += 2;
rlm@3 435
rlm@3 436 $info_asf_codec_list_object_codecentries_current['name'] = substr($asf_header_data, $offset, $codec_name_length);
rlm@3 437 $offset += $codec_name_length;
rlm@3 438
rlm@3 439 $codec_description_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character
rlm@3 440 $offset += 2;
rlm@3 441
rlm@3 442 $info_asf_codec_list_object_codecentries_current['description'] = substr($asf_header_data, $offset, $codec_description_length);
rlm@3 443 $offset += $codec_description_length;
rlm@3 444
rlm@3 445 $codec_information_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 446 $offset += 2;
rlm@3 447
rlm@3 448 $info_asf_codec_list_object_codecentries_current['information'] = substr($asf_header_data, $offset, $codec_information_length);
rlm@3 449 $offset += $codec_information_length;
rlm@3 450
rlm@3 451 if ($info_asf_codec_list_object_codecentries_current['type_raw'] == 2) {
rlm@3 452
rlm@3 453 // audio codec
rlm@3 454 if (strpos($info_asf_codec_list_object_codecentries_current['description'], ',') === false) {
rlm@3 455 throw new getid3_exception('[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'].'"');
rlm@3 456 }
rlm@3 457 list($audio_codec_bitrate, $audio_codec_frequency, $audio_codec_channels) = explode(',', $this->TrimConvert($info_asf_codec_list_object_codecentries_current['description']));
rlm@3 458 $info_audio['codec'] = $this->TrimConvert($info_asf_codec_list_object_codecentries_current['name']);
rlm@3 459
rlm@3 460 if (!isset($info_audio['bitrate']) && strstr($audio_codec_bitrate, 'kbps')) {
rlm@3 461 $info_audio['bitrate'] = (int)(trim(str_replace('kbps', '', $audio_codec_bitrate)) * 1000);
rlm@3 462 }
rlm@3 463
rlm@3 464 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)) {
rlm@3 465 $info_video['bitrate'] = $info_asf['file_properties_object']['max_bitrate'] - $info_audio['bitrate'];
rlm@3 466 }
rlm@3 467
rlm@3 468 if (!@$info_video['bitrate'] && @$info_audio['bitrate'] && @$getid3->info['bitrate']) {
rlm@3 469 $info_video['bitrate'] = $getid3->info['bitrate'] - $info_audio['bitrate'];
rlm@3 470 }
rlm@3 471
rlm@3 472 $audio_codec_frequency = (int)trim(str_replace('kHz', '', $audio_codec_frequency));
rlm@3 473
rlm@3 474 static $sample_rate_lookup = array (
rlm@3 475 8 => 8000, 8000 => 8000,
rlm@3 476 11 => 11025, 11025 => 11025,
rlm@3 477 12 => 12000, 12000 => 12000,
rlm@3 478 16 => 16000, 16000 => 16000,
rlm@3 479 22 => 22050, 22050 => 22050,
rlm@3 480 24 => 24000, 24000 => 24000,
rlm@3 481 32 => 32000, 32000 => 32000,
rlm@3 482 44 => 44100, 44100 => 44100,
rlm@3 483 48 => 48000, 48000 => 48000,
rlm@3 484 );
rlm@3 485
rlm@3 486 $info_audio['sample_rate'] = @$sample_rate_lookup[$audio_codec_frequency];
rlm@3 487
rlm@3 488 if (!$info_audio['sample_rate']) {
rlm@3 489 $getid3->warning('unknown frequency: "'.$audio_codec_frequency.'" ('.$this->TrimConvert($info_asf_codec_list_object_codecentries_current['description']).')');
rlm@3 490 break;
rlm@3 491 }
rlm@3 492
rlm@3 493 if (!isset($info_audio['channels'])) {
rlm@3 494 if (strstr($audio_codec_channels, 'stereo')) {
rlm@3 495 $info_audio['channels'] = 2;
rlm@3 496 } elseif (strstr($audio_codec_channels, 'mono')) {
rlm@3 497 $info_audio['channels'] = 1;
rlm@3 498 }
rlm@3 499 }
rlm@3 500 }
rlm@3 501 }
rlm@3 502 break;
rlm@3 503
rlm@3 504
rlm@3 505 case getid3_asf::Script_Command_Object:
rlm@3 506
rlm@3 507 // Script Command Object: (optional, one only)
rlm@3 508 // Field Name Field Type Size (bits)
rlm@3 509 // Object ID GUID 128 // GUID for Script Command object - getid3_asf::Script_Command_Object
rlm@3 510 // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header
rlm@3 511 // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
rlm@3 512 // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects
rlm@3 513 // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects
rlm@3 514 // Command Types array of: variable //
rlm@3 515 // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name
rlm@3 516 // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command
rlm@3 517 // Commands array of: variable //
rlm@3 518 // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds
rlm@3 519 // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object
rlm@3 520 // * Command Name Length WORD 16 // number of Unicode characters for Command Name
rlm@3 521 // * Command Name WCHAR variable // array of Unicode characters - name of this command
rlm@3 522
rlm@3 523 // shortcut
rlm@3 524 $info_asf['script_command_object'] = array ();
rlm@3 525 $info_asf_script_command_object = &$info_asf['script_command_object'];
rlm@3 526
rlm@3 527 $info_asf_script_command_object['objectid_guid'] = $next_object_guidtext;
rlm@3 528 $info_asf_script_command_object['objectsize'] = $next_object_size;
rlm@3 529 $info_asf_script_command_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
rlm@3 530 $offset += 16;
rlm@3 531
rlm@3 532 if ($info_asf_script_command_object['reserved_guid'] != '4B1ACBE3-100B-11D0-A39B-00A0C90348F6') {
rlm@3 533 $getid3->warning('script_command_object.reserved GUID {'.$info_asf_script_command_object['reserved_guid'].'} does not match expected GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}');
rlm@3 534 break;
rlm@3 535 }
rlm@3 536
rlm@3 537 $info_asf_script_command_object['commands_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 538 $offset += 2;
rlm@3 539
rlm@3 540 $info_asf_script_command_object['command_types_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 541 $offset += 2;
rlm@3 542
rlm@3 543 for ($command_types_counter = 0; $command_types_counter < $info_asf_script_command_object['command_types_count']; $command_types_counter++) {
rlm@3 544
rlm@3 545 $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character
rlm@3 546 $offset += 2;
rlm@3 547
rlm@3 548 $info_asf_script_command_object['command_types'][$command_types_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length);
rlm@3 549 $offset += $command_type_name_length;
rlm@3 550 }
rlm@3 551
rlm@3 552 for ($commands_counter = 0; $commands_counter < $info_asf_script_command_object['commands_count']; $commands_counter++) {
rlm@3 553
rlm@3 554 $info_asf_script_command_object['commands'][$commands_counter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
rlm@3 555 $offset += 4;
rlm@3 556
rlm@3 557 $info_asf_script_command_object['commands'][$commands_counter]['type_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 558 $offset += 2;
rlm@3 559
rlm@3 560 $command_type_name_length = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2)) * 2; // 2 bytes per character
rlm@3 561 $offset += 2;
rlm@3 562
rlm@3 563 $info_asf_script_command_object['commands'][$commands_counter]['name'] = substr($asf_header_data, $offset, $command_type_name_length);
rlm@3 564 $offset += $command_type_name_length;
rlm@3 565 }
rlm@3 566 break;
rlm@3 567
rlm@3 568
rlm@3 569 case getid3_asf::Marker_Object:
rlm@3 570
rlm@3 571 // Marker Object: (optional, one only)
rlm@3 572 // Field Name Field Type Size (bits)
rlm@3 573 // Object ID GUID 128 // GUID for Marker object - getid3_asf::Marker_Object
rlm@3 574 // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header
rlm@3 575 // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
rlm@3 576 // Markers Count DWORD 32 // number of Marker structures in Marker Object
rlm@3 577 // Reserved WORD 16 // hardcoded: 0x0000
rlm@3 578 // Name Length WORD 16 // number of bytes in the Name field
rlm@3 579 // Name WCHAR variable // name of the Marker Object
rlm@3 580 // Markers array of: variable //
rlm@3 581 // * Offset QWORD 64 // byte offset into Data Object
rlm@3 582 // * Presentation Time QWORD 64 // in 100-nanosecond units
rlm@3 583 // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
rlm@3 584 // * Send Time DWORD 32 // in milliseconds
rlm@3 585 // * Flags DWORD 32 // hardcoded: 0x00000000
rlm@3 586 // * Marker Description Length DWORD 32 // number of bytes in Marker Description field
rlm@3 587 // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry
rlm@3 588 // * Padding BYTESTREAM variable // optional padding bytes
rlm@3 589
rlm@3 590 $info_asf['marker_object'] = array ();
rlm@3 591 $info_asf_marker_object = &$info_asf['marker_object'];
rlm@3 592
rlm@3 593 $info_asf_marker_object['objectid_guid'] = $next_object_guidtext;
rlm@3 594 $info_asf_marker_object['objectsize'] = $next_object_size;
rlm@3 595 $info_asf_marker_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
rlm@3 596 $offset += 16;
rlm@3 597
rlm@3 598 if ($info_asf_marker_object['reserved_guid'] != '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB') {
rlm@3 599 $getid3->warning('marker_object.reserved GUID {'.$info_asf_marker_object['reserved_guid'].'} does not match expected GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}');
rlm@3 600 break;
rlm@3 601 }
rlm@3 602
rlm@3 603 $info_asf_marker_object['markers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
rlm@3 604 $offset += 4;
rlm@3 605
rlm@3 606 $info_asf_marker_object['reserved_2'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 607 $offset += 2;
rlm@3 608
rlm@3 609 if ($info_asf_marker_object['reserved_2'] != 0) {
rlm@3 610 $getid3->warning('marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($info_asf_marker_object['reserved_2']).') does not match expected value of "0"');
rlm@3 611 break;
rlm@3 612 }
rlm@3 613
rlm@3 614 $info_asf_marker_object['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 615 $offset += 2;
rlm@3 616
rlm@3 617 $info_asf_marker_object['name'] = substr($asf_header_data, $offset, $info_asf_marker_object['name_length']);
rlm@3 618 $offset += $info_asf_marker_object['name_length'];
rlm@3 619
rlm@3 620 for ($markers_counter = 0; $markers_counter < $info_asf_marker_object['markers_count']; $markers_counter++) {
rlm@3 621
rlm@3 622 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_marker_object['markers'][$markers_counter], $asf_header_data, $offset,
rlm@3 623 array (
rlm@3 624 'offset' => 8,
rlm@3 625 'presentation_time' => 8,
rlm@3 626 'entry_length' => 2,
rlm@3 627 'send_time' => 4,
rlm@3 628 'flags' => 4,
rlm@3 629 'marker_description_length' => 4
rlm@3 630 )
rlm@3 631 );
rlm@3 632 $offset += 30;
rlm@3 633
rlm@3 634 $info_asf_marker_object['markers'][$markers_counter]['marker_description'] = substr($asf_header_data, $offset, $info_asf_marker_object['markers'][$markers_counter]['marker_description_length']);
rlm@3 635 $offset += $info_asf_marker_object['markers'][$markers_counter]['marker_description_length'];
rlm@3 636
rlm@3 637 $padding_length = $info_asf_marker_object['markers'][$markers_counter]['entry_length'] - 4 - 4 - 4 - $info_asf_marker_object['markers'][$markers_counter]['marker_description_length'];
rlm@3 638 if ($padding_length > 0) {
rlm@3 639 $info_asf_marker_object['markers'][$markers_counter]['padding'] = substr($asf_header_data, $offset, $padding_length);
rlm@3 640 $offset += $padding_length;
rlm@3 641 }
rlm@3 642 }
rlm@3 643 break;
rlm@3 644
rlm@3 645
rlm@3 646 case getid3_asf::Bitrate_Mutual_Exclusion_Object:
rlm@3 647
rlm@3 648 // Bitrate Mutual Exclusion Object: (optional)
rlm@3 649 // Field Name Field Type Size (bits)
rlm@3 650 // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - getid3_asf::Bitrate_Mutual_Exclusion_Object
rlm@3 651 // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
rlm@3 652 // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (getid3_asf::Mutex_Bitrate, getid3_asf::Mutex_Unknown)
rlm@3 653 // Stream Numbers Count WORD 16 // number of video streams
rlm@3 654 // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127
rlm@3 655
rlm@3 656 // shortcut
rlm@3 657 $info_asf['bitrate_mutual_exclusion_object'] = array ();
rlm@3 658 $info_asf_bitrate_mutual_exclusion_object = &$info_asf['bitrate_mutual_exclusion_object'];
rlm@3 659
rlm@3 660 $info_asf_bitrate_mutual_exclusion_object['objectid_guid'] = $next_object_guidtext;
rlm@3 661 $info_asf_bitrate_mutual_exclusion_object['objectsize'] = $next_object_size;
rlm@3 662 $info_asf_bitrate_mutual_exclusion_object['reserved_guid'] = getid3_asf::BytestringToGUID(substr($asf_header_data, $offset, 16));
rlm@3 663 $offset += 16;
rlm@3 664
rlm@3 665 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) {
rlm@3 666 $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.'}');
rlm@3 667 break;
rlm@3 668 }
rlm@3 669
rlm@3 670 $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 671 $offset += 2;
rlm@3 672
rlm@3 673 for ($stream_number_counter = 0; $stream_number_counter < $info_asf_bitrate_mutual_exclusion_object['stream_numbers_count']; $stream_number_counter++) {
rlm@3 674 $info_asf_bitrate_mutual_exclusion_object['stream_numbers'][$stream_number_counter] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 675 $offset += 2;
rlm@3 676 }
rlm@3 677 break;
rlm@3 678
rlm@3 679
rlm@3 680 case getid3_asf::Error_Correction_Object:
rlm@3 681
rlm@3 682 // Error Correction Object: (optional, one only)
rlm@3 683 // Field Name Field Type Size (bits)
rlm@3 684 // Object ID GUID 128 // GUID for Error Correction object - getid3_asf::Error_Correction_Object
rlm@3 685 // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header
rlm@3 686 // Error Correction Type GUID 128 // type of error correction. one of: (getid3_asf::No_Error_Correction, getid3_asf::Audio_Spread)
rlm@3 687 // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field
rlm@3 688 // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field
rlm@3 689
rlm@3 690 $info_asf['error_correction_object'] = array ();
rlm@3 691 $info_asf_error_correction_object = &$info_asf['error_correction_object'];
rlm@3 692
rlm@3 693 $info_asf_error_correction_object['objectid_guid'] = $next_object_guidtext;
rlm@3 694 $info_asf_error_correction_object['objectsize'] = $next_object_size;
rlm@3 695 $info_asf_error_correction_object['error_correction_type'] = substr($asf_header_data, $offset, 16);
rlm@3 696 $offset += 16;
rlm@3 697
rlm@3 698 $info_asf_error_correction_object['error_correction_guid'] = getid3_asf::BytestringToGUID($info_asf_error_correction_object['error_correction_type']);
rlm@3 699 $info_asf_error_correction_object['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
rlm@3 700 $offset += 4;
rlm@3 701
rlm@3 702 switch ($info_asf_error_correction_object['error_correction_type_guid']) {
rlm@3 703
rlm@3 704 case getid3_asf::No_Error_Correction:
rlm@3 705
rlm@3 706 // should be no data, but just in case there is, skip to the end of the field
rlm@3 707 $offset += $info_asf_error_correction_object['error_correction_data_length'];
rlm@3 708 break;
rlm@3 709
rlm@3 710
rlm@3 711 case getid3_asf::Audio_Spread:
rlm@3 712
rlm@3 713 // Field Name Field Type Size (bits)
rlm@3 714 // Span BYTE 8 // number of packets over which audio will be spread.
rlm@3 715 // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream
rlm@3 716 // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream
rlm@3 717 // Silence Data Length WORD 16 // number of bytes in Silence Data field
rlm@3 718 // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes
rlm@3 719
rlm@3 720 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_error_correction_object, $asf_header_data, $offset,
rlm@3 721 array (
rlm@3 722 'span' => 1,
rlm@3 723 'virtual_packet_length' => 2,
rlm@3 724 'virtual_chunk_length' => 2,
rlm@3 725 'silence_data_length' => 2
rlm@3 726 )
rlm@3 727 );
rlm@3 728 $offset += 7;
rlm@3 729
rlm@3 730 $info_asf_error_correction_object['silence_data'] = substr($asf_header_data, $offset, $info_asf_error_correction_object['silence_data_length']);
rlm@3 731 $offset += $info_asf_error_correction_object['silence_data_length'];
rlm@3 732 break;
rlm@3 733
rlm@3 734 default:
rlm@3 735 $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.'}');
rlm@3 736 break;
rlm@3 737 }
rlm@3 738
rlm@3 739 break;
rlm@3 740
rlm@3 741
rlm@3 742 case getid3_asf::Content_Description_Object:
rlm@3 743
rlm@3 744 // Content Description Object: (optional, one only)
rlm@3 745 // Field Name Field Type Size (bits)
rlm@3 746 // Object ID GUID 128 // GUID for Content Description object - getid3_asf::Content_Description_Object
rlm@3 747 // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header
rlm@3 748 // Title Length WORD 16 // number of bytes in Title field
rlm@3 749 // Author Length WORD 16 // number of bytes in Author field
rlm@3 750 // Copyright Length WORD 16 // number of bytes in Copyright field
rlm@3 751 // Description Length WORD 16 // number of bytes in Description field
rlm@3 752 // Rating Length WORD 16 // number of bytes in Rating field
rlm@3 753 // Title WCHAR 16 // array of Unicode characters - Title
rlm@3 754 // Author WCHAR 16 // array of Unicode characters - Author
rlm@3 755 // Copyright WCHAR 16 // array of Unicode characters - Copyright
rlm@3 756 // Description WCHAR 16 // array of Unicode characters - Description
rlm@3 757 // Rating WCHAR 16 // array of Unicode characters - Rating
rlm@3 758
rlm@3 759 $info_asf['content_description_object'] = array ();
rlm@3 760 $info_asf_content_description_object = &$info_asf['content_description_object'];
rlm@3 761
rlm@3 762 $info_asf_content_description_object['objectid_guid'] = $next_object_guidtext;
rlm@3 763 $info_asf_content_description_object['objectsize'] = $next_object_size;
rlm@3 764
rlm@3 765 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_content_description_object, $asf_header_data, $offset,
rlm@3 766 array (
rlm@3 767 'title_length' => 2,
rlm@3 768 'author_length' => 2,
rlm@3 769 'copyright_length' => 2,
rlm@3 770 'description_length' => 2,
rlm@3 771 'rating_length' => 2
rlm@3 772 )
rlm@3 773 );
rlm@3 774 $offset += 10;
rlm@3 775
rlm@3 776 $info_asf_content_description_object['title'] = substr($asf_header_data, $offset, $info_asf_content_description_object['title_length']);
rlm@3 777 $offset += $info_asf_content_description_object['title_length'];
rlm@3 778
rlm@3 779 $info_asf_content_description_object['author'] = substr($asf_header_data, $offset, $info_asf_content_description_object['author_length']);
rlm@3 780 $offset += $info_asf_content_description_object['author_length'];
rlm@3 781
rlm@3 782 $info_asf_content_description_object['copyright'] = substr($asf_header_data, $offset, $info_asf_content_description_object['copyright_length']);
rlm@3 783 $offset += $info_asf_content_description_object['copyright_length'];
rlm@3 784
rlm@3 785 $info_asf_content_description_object['description'] = substr($asf_header_data, $offset, $info_asf_content_description_object['description_length']);
rlm@3 786 $offset += $info_asf_content_description_object['description_length'];
rlm@3 787
rlm@3 788 $info_asf_content_description_object['rating'] = substr($asf_header_data, $offset, $info_asf_content_description_object['rating_length']);
rlm@3 789 $offset += $info_asf_content_description_object['rating_length'];
rlm@3 790
rlm@3 791 foreach (array ('title'=>'title', 'author'=>'artist', 'copyright'=>'copyright', 'description'=>'comment', 'rating'=>'rating') as $key_to_copy_from => $key_to_copy_to) {
rlm@3 792 if (!empty($info_asf_content_description_object[$key_to_copy_from])) {
rlm@3 793 $info_asf_comments[$key_to_copy_to][] = getid3_asf::TrimTerm($info_asf_content_description_object[$key_to_copy_from]);
rlm@3 794 }
rlm@3 795 }
rlm@3 796 break;
rlm@3 797
rlm@3 798
rlm@3 799 case getid3_asf::Extended_Content_Description_Object:
rlm@3 800
rlm@3 801 // Extended Content Description Object: (optional, one only)
rlm@3 802 // Field Name Field Type Size (bits)
rlm@3 803 // Object ID GUID 128 // GUID for Extended Content Description object - getid3_asf::Extended_Content_Description_Object
rlm@3 804 // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
rlm@3 805 // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list
rlm@3 806 // Content Descriptors array of: variable //
rlm@3 807 // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field
rlm@3 808 // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name
rlm@3 809 // * Descriptor Value Data Type WORD 16 // Lookup array:
rlm@3 810 // 0x0000 = Unicode String (variable length)
rlm@3 811 // 0x0001 = BYTE array (variable length)
rlm@3 812 // 0x0002 = BOOL (DWORD, 32 bits)
rlm@3 813 // 0x0003 = DWORD (DWORD, 32 bits)
rlm@3 814 // 0x0004 = QWORD (QWORD, 64 bits)
rlm@3 815 // 0x0005 = WORD (WORD, 16 bits)
rlm@3 816 // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field
rlm@3 817 // * Descriptor Value variable variable // value for Content Descriptor
rlm@3 818
rlm@3 819 $info_asf['extended_content_description_object'] = array ();
rlm@3 820 $info_asf_extended_content_description_object = &$info_asf['extended_content_description_object'];
rlm@3 821
rlm@3 822 $info_asf_extended_content_description_object['objectid_guid'] = $next_object_guidtext;
rlm@3 823 $info_asf_extended_content_description_object['objectsize'] = $next_object_size;
rlm@3 824 $info_asf_extended_content_description_object['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 825 $offset += 2;
rlm@3 826
rlm@3 827 for ($extended_content_descriptors_counter = 0; $extended_content_descriptors_counter < $info_asf_extended_content_description_object['content_descriptors_count']; $extended_content_descriptors_counter++) {
rlm@3 828
rlm@3 829 $info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter] = array ();
rlm@3 830 $info_asf_extended_content_description_object_content_descriptor_current = &$info_asf_extended_content_description_object['content_descriptors'][$extended_content_descriptors_counter];
rlm@3 831
rlm@3 832 $info_asf_extended_content_description_object_content_descriptor_current['base_offset'] = $offset + 30;
rlm@3 833 $info_asf_extended_content_description_object_content_descriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 834 $offset += 2;
rlm@3 835
rlm@3 836 $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']);
rlm@3 837 $offset += $info_asf_extended_content_description_object_content_descriptor_current['name_length'];
rlm@3 838
rlm@3 839 $info_asf_extended_content_description_object_content_descriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 840 $offset += 2;
rlm@3 841
rlm@3 842 $info_asf_extended_content_description_object_content_descriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 843 $offset += 2;
rlm@3 844
rlm@3 845 $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']);
rlm@3 846 $offset += $info_asf_extended_content_description_object_content_descriptor_current['value_length'];
rlm@3 847
rlm@3 848 switch ($info_asf_extended_content_description_object_content_descriptor_current['value_type']) {
rlm@3 849
rlm@3 850 case 0x0000: // Unicode string
rlm@3 851 break;
rlm@3 852
rlm@3 853 case 0x0001: // BYTE array
rlm@3 854 // do nothing
rlm@3 855 break;
rlm@3 856
rlm@3 857 case 0x0002: // BOOL
rlm@3 858 $info_asf_extended_content_description_object_content_descriptor_current['value'] = (bool)getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value']);
rlm@3 859 break;
rlm@3 860
rlm@3 861 case 0x0003: // DWORD
rlm@3 862 case 0x0004: // QWORD
rlm@3 863 case 0x0005: // WORD
rlm@3 864 $info_asf_extended_content_description_object_content_descriptor_current['value'] = getid3_lib::LittleEndian2Int($info_asf_extended_content_description_object_content_descriptor_current['value']);
rlm@3 865 break;
rlm@3 866
rlm@3 867 default:
rlm@3 868 $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'].')');
rlm@3 869 break;
rlm@3 870 }
rlm@3 871
rlm@3 872 switch ($this->TrimConvert(strtolower($info_asf_extended_content_description_object_content_descriptor_current['name']))) {
rlm@3 873
rlm@3 874 case 'wm/albumartist':
rlm@3 875 case 'artist':
rlm@3 876 $info_asf_comments['artist'] = array (getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
rlm@3 877 break;
rlm@3 878
rlm@3 879
rlm@3 880 case 'wm/albumtitle':
rlm@3 881 case 'album':
rlm@3 882 $info_asf_comments['album'] = array (getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
rlm@3 883 break;
rlm@3 884
rlm@3 885
rlm@3 886 case 'wm/genre':
rlm@3 887 case 'genre':
rlm@3 888 $genre = getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']);
rlm@3 889 $info_asf_comments['genre'] = array ($genre);
rlm@3 890 break;
rlm@3 891
rlm@3 892
rlm@3 893 case 'wm/tracknumber':
rlm@3 894 case 'tracknumber':
rlm@3 895 $info_asf_comments['track'] = array (intval(getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value'])));
rlm@3 896 break;
rlm@3 897
rlm@3 898
rlm@3 899 case 'wm/track':
rlm@3 900 if (empty($info_asf_comments['track'])) {
rlm@3 901 $info_asf_comments['track'] = array (1 + $this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['value']));
rlm@3 902 }
rlm@3 903 break;
rlm@3 904
rlm@3 905
rlm@3 906 case 'wm/year':
rlm@3 907 case 'year':
rlm@3 908 case 'date':
rlm@3 909 $info_asf_comments['year'] = array ( getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
rlm@3 910 break;
rlm@3 911
rlm@3 912
rlm@3 913 case 'wm/lyrics':
rlm@3 914 case 'lyrics':
rlm@3 915 $info_asf_comments['lyrics'] = array ( getid3_asf::TrimTerm($info_asf_extended_content_description_object_content_descriptor_current['value']));
rlm@3 916 break;
rlm@3 917
rlm@3 918
rlm@3 919 case 'isvbr':
rlm@3 920 if ($info_asf_extended_content_description_object_content_descriptor_current['value']) {
rlm@3 921 $info_audio['bitrate_mode'] = 'vbr';
rlm@3 922 $info_video['bitrate_mode'] = 'vbr';
rlm@3 923 }
rlm@3 924 break;
rlm@3 925
rlm@3 926
rlm@3 927 case 'id3':
rlm@3 928
rlm@3 929 // id3v2 parsing might not be enabled
rlm@3 930 if (class_exists('getid3_id3v2')) {
rlm@3 931
rlm@3 932 // Clone getid3
rlm@3 933 $clone = clone $getid3;
rlm@3 934
rlm@3 935 // Analyse clone by string
rlm@3 936 $id3v2 = new getid3_id3v2($clone);
rlm@3 937 $id3v2->AnalyzeString($info_asf_extended_content_description_object_content_descriptor_current['value']);
rlm@3 938
rlm@3 939 // Import from clone and destroy
rlm@3 940 $getid3->info['id3v2'] = $clone->info['id3v2'];
rlm@3 941 $getid3->warnings($clone->warnings());
rlm@3 942 unset($clone);
rlm@3 943 }
rlm@3 944 break;
rlm@3 945
rlm@3 946
rlm@3 947 case 'wm/encodingtime':
rlm@3 948 $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']);
rlm@3 949 $info_asf_comments['encoding_time_unix'] = array ($info_asf_extended_content_description_object_content_descriptor_current['encoding_time_unix']);
rlm@3 950 break;
rlm@3 951
rlm@3 952
rlm@3 953 case 'wm/picture':
rlm@3 954
rlm@3 955 //typedef struct _WMPicture{
rlm@3 956 // LPWSTR pwszMIMEType;
rlm@3 957 // BYTE bPictureType;
rlm@3 958 // LPWSTR pwszDescription;
rlm@3 959 // DWORD dwDataLen;
rlm@3 960 // BYTE* pbData;
rlm@3 961 //} WM_PICTURE;
rlm@3 962
rlm@3 963 $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});
rlm@3 964 $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']);
rlm@3 965 $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));
rlm@3 966 $info_asf_extended_content_description_object_content_descriptor_current['image_mime'] = '';
rlm@3 967
rlm@3 968 $wm_picture_offset = 5;
rlm@3 969
rlm@3 970 do {
rlm@3 971 $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2);
rlm@3 972 $wm_picture_offset += 2;
rlm@3 973 $info_asf_extended_content_description_object_content_descriptor_current['image_mime'] .= $next_byte_pair;
rlm@3 974 } while ($next_byte_pair !== "\x00\x00");
rlm@3 975
rlm@3 976 $info_asf_extended_content_description_object_content_descriptor_current['image_description'] = '';
rlm@3 977
rlm@3 978 do {
rlm@3 979 $next_byte_pair = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset, 2);
rlm@3 980 $wm_picture_offset += 2;
rlm@3 981 $info_asf_extended_content_description_object_content_descriptor_current['image_description'] .= $next_byte_pair;
rlm@3 982 } while ($next_byte_pair !== "\x00\x00");
rlm@3 983
rlm@3 984 $info_asf_extended_content_description_object_content_descriptor_current['dataoffset'] = $wm_picture_offset;
rlm@3 985 $info_asf_extended_content_description_object_content_descriptor_current['data'] = substr($info_asf_extended_content_description_object_content_descriptor_current['value'], $wm_picture_offset);
rlm@3 986 unset($info_asf_extended_content_description_object_content_descriptor_current['value']);
rlm@3 987 break;
rlm@3 988
rlm@3 989 default:
rlm@3 990 switch ($info_asf_extended_content_description_object_content_descriptor_current['value_type']) {
rlm@3 991 case 0: // Unicode string
rlm@3 992 if (substr($this->TrimConvert($info_asf_extended_content_description_object_content_descriptor_current['name']), 0, 3) == 'WM/') {
rlm@3 993 $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']));
rlm@3 994 }
rlm@3 995 break;
rlm@3 996
rlm@3 997 case 1:
rlm@3 998 break;
rlm@3 999 }
rlm@3 1000 break;
rlm@3 1001 }
rlm@3 1002
rlm@3 1003 }
rlm@3 1004 break;
rlm@3 1005
rlm@3 1006
rlm@3 1007 case getid3_asf::Stream_Bitrate_Properties_Object:
rlm@3 1008
rlm@3 1009 // Stream Bitrate Properties Object: (optional, one only)
rlm@3 1010 // Field Name Field Type Size (bits)
rlm@3 1011 // Object ID GUID 128 // GUID for Stream Bitrate Properties object - getid3_asf::Stream_Bitrate_Properties_Object
rlm@3 1012 // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
rlm@3 1013 // Bitrate Records Count WORD 16 // number of records in Bitrate Records
rlm@3 1014 // Bitrate Records array of: variable //
rlm@3 1015 // * Flags WORD 16 //
rlm@3 1016 // * * Stream Number bits 7 (0x007F) // number of this stream
rlm@3 1017 // * * Reserved bits 9 (0xFF80) // hardcoded: 0
rlm@3 1018 // * Average Bitrate DWORD 32 // in bits per second
rlm@3 1019
rlm@3 1020 // shortcut
rlm@3 1021 $info_asf['stream_bitrate_properties_object'] = array ();
rlm@3 1022 $info_asf_stream_bitrate_properties_object = &$info_asf['stream_bitrate_properties_object'];
rlm@3 1023
rlm@3 1024 $info_asf_stream_bitrate_properties_object['objectid_guid'] = $next_object_guidtext;
rlm@3 1025 $info_asf_stream_bitrate_properties_object['objectsize'] = $next_object_size;
rlm@3 1026 $info_asf_stream_bitrate_properties_object['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 1027 $offset += 2;
rlm@3 1028
rlm@3 1029 for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties_object['bitrate_records_count']; $bitrate_records_counter++) {
rlm@3 1030
rlm@3 1031 $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 2));
rlm@3 1032 $offset += 2;
rlm@3 1033
rlm@3 1034 $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'] & 0x007F;
rlm@3 1035
rlm@3 1036 $info_asf_stream_bitrate_properties_object['bitrate_records'][$bitrate_records_counter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_data, $offset, 4));
rlm@3 1037 $offset += 4;
rlm@3 1038 }
rlm@3 1039 break;
rlm@3 1040
rlm@3 1041
rlm@3 1042 case getid3_asf::Padding_Object:
rlm@3 1043
rlm@3 1044 // Padding Object: (optional)
rlm@3 1045 // Field Name Field Type Size (bits)
rlm@3 1046 // Object ID GUID 128 // GUID for Padding object - getid3_asf::Padding_Object
rlm@3 1047 // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header
rlm@3 1048 // Padding Data BYTESTREAM variable // ignore
rlm@3 1049
rlm@3 1050 // shortcut
rlm@3 1051 $info_asf['padding_object'] = array ();
rlm@3 1052 $info_asf_paddingobject = &$info_asf['padding_object'];
rlm@3 1053
rlm@3 1054 $info_asf_paddingobject['objectid_guid'] = $next_object_guidtext;
rlm@3 1055 $info_asf_paddingobject['objectsize'] = $next_object_size;
rlm@3 1056 $info_asf_paddingobject['padding_length'] = $info_asf_paddingobject['objectsize'] - 16 - 8;
rlm@3 1057 $info_asf_paddingobject['padding'] = substr($asf_header_data, $offset, $info_asf_paddingobject['padding_length']);
rlm@3 1058 $offset += ($next_object_size - 16 - 8);
rlm@3 1059 break;
rlm@3 1060
rlm@3 1061
rlm@3 1062 case getid3_asf::Extended_Content_Encryption_Object:
rlm@3 1063 case getid3_asf::Content_Encryption_Object:
rlm@3 1064
rlm@3 1065 // WMA DRM - just ignore
rlm@3 1066 $offset += ($next_object_size - 16 - 8);
rlm@3 1067 break;
rlm@3 1068
rlm@3 1069
rlm@3 1070 default:
rlm@3 1071
rlm@3 1072 // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
rlm@3 1073 if (getid3_asf::GUIDname($next_object_guidtext)) {
rlm@3 1074 $getid3->warning('unhandled GUID "'.getid3_asf::GUIDname($next_object_guidtext).'" {'.$next_object_guidtext.'} in ASF header at offset '.($offset - 16 - 8));
rlm@3 1075 } else {
rlm@3 1076 $getid3->warning('unknown GUID {'.$next_object_guidtext.'} in ASF header at offset '.($offset - 16 - 8));
rlm@3 1077 }
rlm@3 1078 $offset += ($next_object_size - 16 - 8);
rlm@3 1079 break;
rlm@3 1080 }
rlm@3 1081 }
rlm@3 1082
rlm@3 1083 if (isset($info_asf_stream_bitrate_properties['bitrate_records_count'])) {
rlm@3 1084 $asf_bitrate_audio = 0;
rlm@3 1085 $asf_bitrate_video = 0;
rlm@3 1086
rlm@3 1087 for ($bitrate_records_counter = 0; $bitrate_records_counter < $info_asf_stream_bitrate_properties['bitrate_records_count']; $bitrate_records_counter++) {
rlm@3 1088 if (isset($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter])) {
rlm@3 1089 switch ($info_asf_codec_list_object['codec_entries'][$bitrate_records_counter]['type_raw']) {
rlm@3 1090
rlm@3 1091 case 1:
rlm@3 1092 $asf_bitrate_video += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate'];
rlm@3 1093 break;
rlm@3 1094
rlm@3 1095 case 2:
rlm@3 1096 $asf_bitrate_audio += $info_asf_stream_bitrate_properties['bitrate_records'][$bitrate_records_counter]['bitrate'];
rlm@3 1097 break;
rlm@3 1098 }
rlm@3 1099 }
rlm@3 1100 }
rlm@3 1101 if ($asf_bitrate_audio > 0) {
rlm@3 1102 $info_audio['bitrate'] = $asf_bitrate_audio;
rlm@3 1103 }
rlm@3 1104 if ($asf_bitrate_video > 0) {
rlm@3 1105 $info_video['bitrate'] = $asf_bitrate_video;
rlm@3 1106 }
rlm@3 1107 }
rlm@3 1108
rlm@3 1109 if (isset($info_asf['stream_properties_object']) && is_array($info_asf['stream_properties_object'])) {
rlm@3 1110
rlm@3 1111 $info_audio['bitrate'] = 0;
rlm@3 1112 $info_video['bitrate'] = 0;
rlm@3 1113
rlm@3 1114 foreach ($info_asf['stream_properties_object'] as $stream_number => $stream_data) {
rlm@3 1115
rlm@3 1116 switch ($stream_data['stream_type_guid']) {
rlm@3 1117
rlm@3 1118 case getid3_asf::Audio_Media:
rlm@3 1119
rlm@3 1120 // Field Name Field Type Size (bits)
rlm@3 1121 // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
rlm@3 1122 // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
rlm@3 1123 // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
rlm@3 1124 // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
rlm@3 1125 // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
rlm@3 1126 // 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
rlm@3 1127 // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
rlm@3 1128 // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
rlm@3 1129
rlm@3 1130 // shortcut
rlm@3 1131 $info_asf['audio_media'][$stream_number] = array ();
rlm@3 1132 $info_asf_audio_media_current_stream = &$info_asf['audio_media'][$stream_number];
rlm@3 1133
rlm@3 1134 $audio_media_offset = 0;
rlm@3 1135
rlm@3 1136 $info_asf_audio_media_current_stream = getid3_riff::RIFFparseWAVEFORMATex(substr($stream_data['type_specific_data'], $audio_media_offset, 16));
rlm@3 1137
rlm@3 1138 $audio_media_offset += 16;
rlm@3 1139
rlm@3 1140 $info_audio['lossless'] = false;
rlm@3 1141 switch ($info_asf_audio_media_current_stream['raw']['wFormatTag']) {
rlm@3 1142 case 0x0001: // PCM
rlm@3 1143 case 0x0163: // WMA9 Lossless
rlm@3 1144 $info_audio['lossless'] = true;
rlm@3 1145 break;
rlm@3 1146 }
rlm@3 1147
rlm@3 1148 if (!empty($info_asf['stream_bitrate_properties_object']['bitrate_records'])) {
rlm@3 1149 foreach ($info_asf['stream_bitrate_properties_object']['bitrate_records'] as $data_array) {
rlm@3 1150 if (@$data_array['flags']['stream_number'] == $stream_number) {
rlm@3 1151 $info_asf_audio_media_current_stream['bitrate'] = $data_array['bitrate'];
rlm@3 1152 $info_audio['bitrate'] += $data_array['bitrate'];
rlm@3 1153 break;
rlm@3 1154 }
rlm@3 1155 }
rlm@3 1156 } else {
rlm@3 1157 if (@$info_asf_audio_media_current_stream['bytes_sec']) {
rlm@3 1158 $info_audio['bitrate'] += $info_asf_audio_media_current_stream['bytes_sec'] * 8;
rlm@3 1159 } elseif (@$info_asf_audio_media_current_stream['bitrate']) {
rlm@3 1160 $info_audio['bitrate'] += $info_asf_audio_media_current_stream['bitrate'];
rlm@3 1161 }
rlm@3 1162 }
rlm@3 1163
rlm@3 1164 $info_audio['streams'][$stream_number] = $info_asf_audio_media_current_stream;
rlm@3 1165 $info_audio['streams'][$stream_number]['wformattag'] = $info_asf_audio_media_current_stream['raw']['wFormatTag'];
rlm@3 1166 $info_audio['streams'][$stream_number]['lossless'] = $info_audio['lossless'];
rlm@3 1167 $info_audio['streams'][$stream_number]['bitrate'] = $info_audio['bitrate'];
rlm@3 1168 unset($info_audio['streams'][$stream_number]['raw']);
rlm@3 1169
rlm@3 1170 $info_asf_audio_media_current_stream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($stream_data['type_specific_data'], $audio_media_offset, 2));
rlm@3 1171 $audio_media_offset += 2;
rlm@3 1172
rlm@3 1173 $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']);
rlm@3 1174 $audio_media_offset += $info_asf_audio_media_current_stream['codec_data_size'];
rlm@3 1175 break;
rlm@3 1176
rlm@3 1177
rlm@3 1178 case getid3_asf::Video_Media:
rlm@3 1179
rlm@3 1180 // Field Name Field Type Size (bits)
rlm@3 1181 // Encoded Image Width DWORD 32 // width of image in pixels
rlm@3 1182 // Encoded Image Height DWORD 32 // height of image in pixels
rlm@3 1183 // Reserved Flags BYTE 8 // hardcoded: 0x02
rlm@3 1184 // Format Data Size WORD 16 // size of Format Data field in bytes
rlm@3 1185 // Format Data array of: variable //
rlm@3 1186 // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
rlm@3 1187 // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
rlm@3 1188 // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
rlm@3 1189 // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
rlm@3 1190 // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
rlm@3 1191 // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
rlm@3 1192 // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
rlm@3 1193 // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
rlm@3 1194 // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
rlm@3 1195 // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
rlm@3 1196 // * 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
rlm@3 1197 // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
rlm@3 1198
rlm@3 1199 $info_asf['video_media'][$stream_number] = array ();
rlm@3 1200 $info_asf_video_media_current_stream = &$info_asf['video_media'][$stream_number];
rlm@3 1201
rlm@3 1202 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream, $stream_data['type_specific_data'], 0,
rlm@3 1203 array (
rlm@3 1204 'image_width' => 4,
rlm@3 1205 'image_height' => 4,
rlm@3 1206 'flags' => 1,
rlm@3 1207 'format_data_size'=> 2
rlm@3 1208 )
rlm@3 1209 );
rlm@3 1210
rlm@3 1211 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_video_media_current_stream['format_data'], $stream_data['type_specific_data'], 11,
rlm@3 1212 array (
rlm@3 1213 'format_data_size' => 4,
rlm@3 1214 'image_width' => 4,
rlm@3 1215 'image_height' => 4,
rlm@3 1216 'reserved' => 2,
rlm@3 1217 'bits_per_pixel' => 2,
rlm@3 1218 'codec_fourcc' => -4,
rlm@3 1219 'image_size' => 4,
rlm@3 1220 'horizontal_pels' => 4,
rlm@3 1221 'vertical_pels' => 4,
rlm@3 1222 'colors_used' => 4,
rlm@3 1223 'colors_important' => 4
rlm@3 1224 )
rlm@3 1225 );
rlm@3 1226
rlm@3 1227 $info_asf_video_media_current_stream['format_data']['codec_data'] = substr($stream_data['type_specific_data'], 51);
rlm@3 1228
rlm@3 1229 if (!empty($info_asf['stream_bitrate_properties_object']['bitrate_records'])) {
rlm@3 1230 foreach ($info_asf['stream_bitrate_properties_object']['bitrate_records'] as $data_array) {
rlm@3 1231 if (@$data_array['flags']['stream_number'] == $stream_number) {
rlm@3 1232 $info_asf_video_media_current_stream['bitrate'] = $data_array['bitrate'];
rlm@3 1233 $info_video['streams'][$stream_number]['bitrate'] = $data_array['bitrate'];
rlm@3 1234 $info_video['bitrate'] += $data_array['bitrate'];
rlm@3 1235
rlm@3 1236 break;
rlm@3 1237 }
rlm@3 1238 }
rlm@3 1239 }
rlm@3 1240
rlm@3 1241 $info_asf_video_media_current_stream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($info_asf_video_media_current_stream['format_data']['codec_fourcc']);
rlm@3 1242
rlm@3 1243 $info_video['streams'][$stream_number]['fourcc'] = $info_asf_video_media_current_stream['format_data']['codec_fourcc'];
rlm@3 1244 $info_video['streams'][$stream_number]['codec'] = $info_asf_video_media_current_stream['format_data']['codec'];
rlm@3 1245 $info_video['streams'][$stream_number]['resolution_x'] = $info_asf_video_media_current_stream['image_width'];
rlm@3 1246 $info_video['streams'][$stream_number]['resolution_y'] = $info_asf_video_media_current_stream['image_height'];
rlm@3 1247 $info_video['streams'][$stream_number]['bits_per_sample'] = $info_asf_video_media_current_stream['format_data']['bits_per_pixel'];
rlm@3 1248 break;
rlm@3 1249
rlm@3 1250 default:
rlm@3 1251 break;
rlm@3 1252 }
rlm@3 1253 }
rlm@3 1254 }
rlm@3 1255
rlm@3 1256 while (ftell($getid3->fp) < $getid3->info['avdataend']) {
rlm@3 1257
rlm@3 1258 $next_object_data_header = fread($getid3->fp, 24);
rlm@3 1259 $offset = 0;
rlm@3 1260
rlm@3 1261 $next_object_guid = substr($next_object_data_header, 0, 16);
rlm@3 1262 $offset += 16;
rlm@3 1263
rlm@3 1264 $next_object_guidtext = getid3_asf::BytestringToGUID($next_object_guid);
rlm@3 1265 $next_object_size = getid3_lib::LittleEndian2Int(substr($next_object_data_header, $offset, 8));
rlm@3 1266 $offset += 8;
rlm@3 1267
rlm@3 1268 switch ($next_object_guidtext) {
rlm@3 1269
rlm@3 1270 case getid3_asf::Data_Object:
rlm@3 1271
rlm@3 1272 // Data Object: (mandatory, one only)
rlm@3 1273 // Field Name Field Type Size (bits)
rlm@3 1274 // Object ID GUID 128 // GUID for Data object - getid3_asf::Data_Object
rlm@3 1275 // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
rlm@3 1276 // File ID GUID 128 // unique identifier. identical to File ID field in Header Object
rlm@3 1277 // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
rlm@3 1278 // Reserved WORD 16 // hardcoded: 0x0101
rlm@3 1279
rlm@3 1280 // shortcut
rlm@3 1281 $info_asf['data_object'] = array ();
rlm@3 1282 $info_asf_data_object = &$info_asf['data_object'];
rlm@3 1283
rlm@3 1284 $data_object_data = $next_object_data_header.fread($getid3->fp, 50 - 24);
rlm@3 1285 $offset = 24;
rlm@3 1286
rlm@3 1287 $info_asf_data_object['objectid_guid'] = $next_object_guidtext;
rlm@3 1288 $info_asf_data_object['objectsize'] = $next_object_size;
rlm@3 1289
rlm@3 1290 $info_asf_data_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($data_object_data, $offset, 16));
rlm@3 1291 $offset += 16;
rlm@3 1292
rlm@3 1293 $info_asf_data_object['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 8));
rlm@3 1294 $offset += 8;
rlm@3 1295
rlm@3 1296 $info_asf_data_object['reserved'] = getid3_lib::LittleEndian2Int(substr($data_object_data, $offset, 2));
rlm@3 1297 $offset += 2;
rlm@3 1298
rlm@3 1299 if ($info_asf_data_object['reserved'] != 0x0101) {
rlm@3 1300 $getid3->warning('data_object.reserved ('.getid3_lib::PrintHexBytes($info_asf_data_object['reserved']).') does not match expected value of "0x0101"');
rlm@3 1301 break;
rlm@3 1302 }
rlm@3 1303
rlm@3 1304 // Data Packets array of: variable //
rlm@3 1305 // * Error Correction Flags BYTE 8 //
rlm@3 1306 // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
rlm@3 1307 // * * Opaque Data Present bits 1 //
rlm@3 1308 // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00
rlm@3 1309 // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure
rlm@3 1310 // * Error Correction Data
rlm@3 1311
rlm@3 1312 $getid3->info['avdataoffset'] = ftell($getid3->fp);
rlm@3 1313 fseek($getid3->fp, ($info_asf_data_object['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data
rlm@3 1314 $getid3->info['avdataend'] = ftell($getid3->fp);
rlm@3 1315 break;
rlm@3 1316
rlm@3 1317
rlm@3 1318 case getid3_asf::Simple_Index_Object:
rlm@3 1319
rlm@3 1320 // Simple Index Object: (optional, recommended, one per video stream)
rlm@3 1321 // Field Name Field Type Size (bits)
rlm@3 1322 // Object ID GUID 128 // GUID for Simple Index object - getid3_asf::Data_Object
rlm@3 1323 // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header
rlm@3 1324 // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
rlm@3 1325 // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units
rlm@3 1326 // Maximum Packet Count DWORD 32 // maximum packet count for all index entries
rlm@3 1327 // Index Entries Count DWORD 32 // number of Index Entries structures
rlm@3 1328 // Index Entries array of: variable //
rlm@3 1329 // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry
rlm@3 1330 // * Packet Count WORD 16 // number of Data Packets to sent at this index entry
rlm@3 1331
rlm@3 1332 // shortcut
rlm@3 1333 $info_asf['simple_index_object'] = array ();
rlm@3 1334 $info_asf_simple_index_object = &$info_asf['simple_index_object'];
rlm@3 1335
rlm@3 1336 $info_asf_simple_index_object['objectid_guid'] = $next_object_guidtext;
rlm@3 1337 $info_asf_simple_index_object['objectsize'] = $next_object_size;
rlm@3 1338
rlm@3 1339 $simple_index_object_data = $next_object_data_header.fread($getid3->fp, 56 - 24);
rlm@3 1340
rlm@3 1341 $info_asf_simple_index_object['fileid_guid'] = getid3_asf::BytestringToGUID(substr($simple_index_object_data, 24, 16));
rlm@3 1342
rlm@3 1343 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_simple_index_object, $simple_index_object_data, 40,
rlm@3 1344 array (
rlm@3 1345 'index_entry_time_interval' => 8,
rlm@3 1346 'maximum_packet_count' => 4,
rlm@3 1347 'index_entries_count' => 4
rlm@3 1348 )
rlm@3 1349 );
rlm@3 1350
rlm@3 1351 $offset = 56;
rlm@3 1352
rlm@3 1353 $index_entries_data = $simple_index_object_data.fread($getid3->fp, 6 * $info_asf_simple_index_object['index_entries_count']);
rlm@3 1354 for ($index_entries_counter = 0; $index_entries_counter < $info_asf_simple_index_object['index_entries_count']; $index_entries_counter++) {
rlm@3 1355
rlm@3 1356 $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4));
rlm@3 1357 $offset += 4;
rlm@3 1358
rlm@3 1359 $info_asf_simple_index_object['index_entries'][$index_entries_counter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($index_entries_data, $offset, 4));
rlm@3 1360 $offset += 2;
rlm@3 1361 }
rlm@3 1362 break;
rlm@3 1363
rlm@3 1364
rlm@3 1365 case getid3_asf::Index_Object:
rlm@3 1366
rlm@3 1367 // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
rlm@3 1368 // Field Name Field Type Size (bits)
rlm@3 1369 // Object ID GUID 128 // GUID for the Index Object - getid3_asf::Index_Object
rlm@3 1370 // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
rlm@3 1371 // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms.
rlm@3 1372 // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object.
rlm@3 1373 // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object.
rlm@3 1374
rlm@3 1375 // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0.
rlm@3 1376 // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater.
rlm@3 1377 // Index Specifiers array of: varies //
rlm@3 1378 // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127.
rlm@3 1379 // * Index Type WORD 16 // Specifies Index Type values as follows:
rlm@3 1380 // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
rlm@3 1381 // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
rlm@3 1382 // 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.
rlm@3 1383 // Nearest Past Cleanpoint is the most common type of index.
rlm@3 1384 // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block.
rlm@3 1385 // * 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.
rlm@3 1386 // * Index Entries array of: varies //
rlm@3 1387 // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value
rlm@3 1388
rlm@3 1389 // shortcut
rlm@3 1390 $info_asf['asf_index_object'] = array ();
rlm@3 1391 $info_asf_asf_index_object = &$info_asf['asf_index_object'];
rlm@3 1392
rlm@3 1393 $asf_index_object_data = $next_object_data_header.fread($getid3->fp, 34 - 24);
rlm@3 1394
rlm@3 1395 $info_asf_asf_index_object['objectid_guid'] = $next_object_guidtext;
rlm@3 1396 $info_asf_asf_index_object['objectsize'] = $next_object_size;
rlm@3 1397
rlm@3 1398 getid3_lib::ReadSequence('LittleEndian2Int', $info_asf_asf_index_object, $asf_index_object_data, 24,
rlm@3 1399 array (
rlm@3 1400 'entry_time_interval' =>4,
rlm@3 1401 'index_specifiers_count' =>2,
rlm@3 1402 'index_blocks_count' =>4
rlm@3 1403 )
rlm@3 1404 );
rlm@3 1405
rlm@3 1406 $offset = 34;
rlm@3 1407
rlm@3 1408 $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count']);
rlm@3 1409
rlm@3 1410 for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) {
rlm@3 1411
rlm@3 1412 $index_specifier_stream_number = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2));
rlm@3 1413 $offset += 2;
rlm@3 1414
rlm@3 1415 $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['stream_number'] = $index_specifier_stream_number;
rlm@3 1416
rlm@3 1417 $info_asf_asf_index_object['index_specifiers'][$index_specifiers_counter]['index_type'] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 2));
rlm@3 1418 $offset += 2;
rlm@3 1419
rlm@3 1420 $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']);
rlm@3 1421 }
rlm@3 1422
rlm@3 1423 $asf_index_object_data .= fread($getid3->fp, 4);
rlm@3 1424 $info_asf_asf_index_object['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 4));
rlm@3 1425 $offset += 4;
rlm@3 1426
rlm@3 1427 $asf_index_object_data .= fread($getid3->fp, 8 * $info_asf_asf_index_object['index_specifiers_count']);
rlm@3 1428
rlm@3 1429 for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) {
rlm@3 1430 $info_asf_asf_index_object['block_positions'][$index_specifiers_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 8));
rlm@3 1431 $offset += 8;
rlm@3 1432 }
rlm@3 1433
rlm@3 1434 $asf_index_object_data .= fread($getid3->fp, 4 * $info_asf_asf_index_object['index_specifiers_count'] * $info_asf_asf_index_object['index_entry_count']);
rlm@3 1435
rlm@3 1436 for ($index_entry_counter = 0; $index_entry_counter < $info_asf_asf_index_object['index_entry_count']; $index_entry_counter++) {
rlm@3 1437 for ($index_specifiers_counter = 0; $index_specifiers_counter < $info_asf_asf_index_object['index_specifiers_count']; $index_specifiers_counter++) {
rlm@3 1438 $info_asf_asf_index_object['offsets'][$index_specifiers_counter][$index_entry_counter] = getid3_lib::LittleEndian2Int(substr($asf_index_object_data, $offset, 4));
rlm@3 1439 $offset += 4;
rlm@3 1440 }
rlm@3 1441 }
rlm@3 1442 break;
rlm@3 1443
rlm@3 1444
rlm@3 1445 default:
rlm@3 1446
rlm@3 1447 // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
rlm@3 1448 if (getid3_asf::GUIDname($next_object_guidtext)) {
rlm@3 1449 $getid3->warning('unhandled GUID "'.getid3_asf::GUIDname($next_object_guidtext).'" {'.$next_object_guidtext.'} in ASF body at offset '.($offset - 16 - 8));
rlm@3 1450 } else {
rlm@3 1451 $getid3->warning('unknown GUID {'.$next_object_guidtext.'} in ASF body at offset '.(ftell($getid3->fp) - 16 - 8));
rlm@3 1452 }
rlm@3 1453 fseek($getid3->fp, ($next_object_size - 16 - 8), SEEK_CUR);
rlm@3 1454 break;
rlm@3 1455 }
rlm@3 1456 }
rlm@3 1457
rlm@3 1458 if (isset($info_asf_codec_list_object['codec_entries']) && is_array($info_asf_codec_list_object['codec_entries'])) {
rlm@3 1459 foreach ($info_asf_codec_list_object['codec_entries'] as $stream_number => $stream_data) {
rlm@3 1460 switch ($stream_data['information']) {
rlm@3 1461 case 'WMV1':
rlm@3 1462 case 'WMV2':
rlm@3 1463 case 'WMV3':
rlm@3 1464 case 'MSS1':
rlm@3 1465 case 'MSS2':
rlm@3 1466 case 'WMVA':
rlm@3 1467 case 'WVC1':
rlm@3 1468 case 'WMVP':
rlm@3 1469 case 'WVP2':
rlm@3 1470 $info_video['dataformat'] = 'wmv';
rlm@3 1471 $getid3->info['mime_type'] = 'video/x-ms-wmv';
rlm@3 1472 break;
rlm@3 1473
rlm@3 1474 case 'MP42':
rlm@3 1475 case 'MP43':
rlm@3 1476 case 'MP4S':
rlm@3 1477 case 'mp4s':
rlm@3 1478 $info_video['dataformat'] = 'asf';
rlm@3 1479 $getid3->info['mime_type'] = 'video/x-ms-asf';
rlm@3 1480 break;
rlm@3 1481
rlm@3 1482 default:
rlm@3 1483 switch ($stream_data['type_raw']) {
rlm@3 1484 case 1:
rlm@3 1485 if (strstr($this->TrimConvert($stream_data['name']), 'Windows Media')) {
rlm@3 1486 $info_video['dataformat'] = 'wmv';
rlm@3 1487 if ($getid3->info['mime_type'] == 'video/x-ms-asf') {
rlm@3 1488 $getid3->info['mime_type'] = 'video/x-ms-wmv';
rlm@3 1489 }
rlm@3 1490 }
rlm@3 1491 break;
rlm@3 1492
rlm@3 1493 case 2:
rlm@3 1494 if (strstr($this->TrimConvert($stream_data['name']), 'Windows Media')) {
rlm@3 1495 $info_audio['dataformat'] = 'wma';
rlm@3 1496 if ($getid3->info['mime_type'] == 'video/x-ms-asf') {
rlm@3 1497 $getid3->info['mime_type'] = 'audio/x-ms-wma';
rlm@3 1498 }
rlm@3 1499 }
rlm@3 1500 break;
rlm@3 1501
rlm@3 1502 }
rlm@3 1503 break;
rlm@3 1504 }
rlm@3 1505 }
rlm@3 1506 }
rlm@3 1507
rlm@3 1508 switch (@$info_audio['codec']) {
rlm@3 1509 case 'MPEG Layer-3':
rlm@3 1510 $info_audio['dataformat'] = 'mp3';
rlm@3 1511 break;
rlm@3 1512
rlm@3 1513 default:
rlm@3 1514 break;
rlm@3 1515 }
rlm@3 1516
rlm@3 1517 if (isset($info_asf_codec_list_object['codec_entries'])) {
rlm@3 1518 foreach ($info_asf_codec_list_object['codec_entries'] as $stream_number => $stream_data) {
rlm@3 1519 switch ($stream_data['type_raw']) {
rlm@3 1520
rlm@3 1521 case 1: // video
rlm@3 1522 $info_video['encoder'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][$stream_number]['name']);
rlm@3 1523 break;
rlm@3 1524
rlm@3 1525 case 2: // audio
rlm@3 1526 $info_audio['encoder'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][$stream_number]['name']);
rlm@3 1527 $info_audio['encoder_options'] = $this->TrimConvert($info_asf_codec_list_object['codec_entries'][0]['description']);
rlm@3 1528 $info_audio['codec'] = $info_audio['encoder'];
rlm@3 1529 break;
rlm@3 1530
rlm@3 1531 default:
rlm@3 1532 $getid3->warning('Unknown streamtype: [codec_list_object][codec_entries]['.$stream_number.'][type_raw] == '.$stream_data['type_raw']);
rlm@3 1533 break;
rlm@3 1534
rlm@3 1535 }
rlm@3 1536 }
rlm@3 1537 }
rlm@3 1538
rlm@3 1539 if (isset($getid3->info['audio'])) {
rlm@3 1540 $info_audio['lossless'] = (isset($info_audio['lossless']) ? $info_audio['lossless'] : false);
rlm@3 1541 $info_audio['dataformat'] = (!empty($info_audio['dataformat']) ? $info_audio['dataformat'] : 'asf');
rlm@3 1542 }
rlm@3 1543
rlm@3 1544 if (!empty($info_video['dataformat'])) {
rlm@3 1545 $info_video['lossless'] = (isset($info_audio['lossless']) ? $info_audio['lossless'] : false);
rlm@3 1546 $info_video['pixel_aspect_ratio'] = (isset($info_audio['pixel_aspect_ratio']) ? $info_audio['pixel_aspect_ratio'] : (float)1);
rlm@3 1547 $info_video['dataformat'] = (!empty($info_video['dataformat']) ? $info_video['dataformat'] : 'asf');
rlm@3 1548 }
rlm@3 1549
rlm@3 1550 $getid3->info['bitrate'] = @$info_audio['bitrate'] + @$info_video['bitrate'];
rlm@3 1551
rlm@3 1552 if (empty($info_audio)) {
rlm@3 1553 unset($getid3->info['audio']);
rlm@3 1554 }
rlm@3 1555
rlm@3 1556 if (empty($info_video)) {
rlm@3 1557 unset($getid3->info['video']);
rlm@3 1558 }
rlm@3 1559
rlm@3 1560 return true;
rlm@3 1561 }
rlm@3 1562
rlm@3 1563
rlm@3 1564
rlm@3 1565 // Remove terminator 00 00 and convert UNICODE to Latin-1
rlm@3 1566 private function TrimConvert($string) {
rlm@3 1567
rlm@3 1568 // remove terminator, only if present (it should be, but...)
rlm@3 1569 if (substr($string, strlen($string) - 2, 2) == "\x00\x00") {
rlm@3 1570 $string = substr($string, 0, strlen($string) - 2);
rlm@3 1571 }
rlm@3 1572
rlm@3 1573 // convert
rlm@3 1574 return trim($this->getid3->iconv('UTF-16LE', 'ISO-8859-1', $string), ' ');
rlm@3 1575 }
rlm@3 1576
rlm@3 1577
rlm@3 1578
rlm@3 1579 private function WMpictureTypeLookup($wm_picture_type) {
rlm@3 1580
rlm@3 1581 static $lookup = array (
rlm@3 1582 0x03 => 'Front Cover',
rlm@3 1583 0x04 => 'Back Cover',
rlm@3 1584 0x00 => 'User Defined',
rlm@3 1585 0x05 => 'Leaflet Page',
rlm@3 1586 0x06 => 'Media Label',
rlm@3 1587 0x07 => 'Lead Artist',
rlm@3 1588 0x08 => 'Artist',
rlm@3 1589 0x09 => 'Conductor',
rlm@3 1590 0x0A => 'Band',
rlm@3 1591 0x0B => 'Composer',
rlm@3 1592 0x0C => 'Lyricist',
rlm@3 1593 0x0D => 'Recording Location',
rlm@3 1594 0x0E => 'During Recording',
rlm@3 1595 0x0F => 'During Performance',
rlm@3 1596 0x10 => 'Video Screen Capture',
rlm@3 1597 0x12 => 'Illustration',
rlm@3 1598 0x13 => 'Band Logotype',
rlm@3 1599 0x14 => 'Publisher Logotype'
rlm@3 1600 );
rlm@3 1601
rlm@3 1602 return isset($lookup[$wm_picture_type]) ? $this->getid3->iconv('ISO-8859-1', 'UTF-16LE', $lookup[$wm_picture_type]) : '';
rlm@3 1603 }
rlm@3 1604
rlm@3 1605
rlm@3 1606
rlm@3 1607 public static function ASFCodecListObjectTypeLookup($codec_list_type) {
rlm@3 1608
rlm@3 1609 static $lookup = array (
rlm@3 1610 0x0001 => 'Video Codec',
rlm@3 1611 0x0002 => 'Audio Codec',
rlm@3 1612 0xFFFF => 'Unknown Codec'
rlm@3 1613 );
rlm@3 1614
rlm@3 1615 return (isset($lookup[$codec_list_type]) ? $lookup[$codec_list_type] : 'Invalid Codec Type');
rlm@3 1616 }
rlm@3 1617
rlm@3 1618
rlm@3 1619
rlm@3 1620 public static function GUIDname($guid_string) {
rlm@3 1621
rlm@3 1622 static $lookup = array (
rlm@3 1623 getid3_asf::Extended_Stream_Properties_Object => 'Extended_Stream_Properties_Object',
rlm@3 1624 getid3_asf::Padding_Object => 'Padding_Object',
rlm@3 1625 getid3_asf::Payload_Ext_Syst_Pixel_Aspect_Ratio => 'Payload_Ext_Syst_Pixel_Aspect_Ratio',
rlm@3 1626 getid3_asf::Script_Command_Object => 'Script_Command_Object',
rlm@3 1627 getid3_asf::No_Error_Correction => 'No_Error_Correction',
rlm@3 1628 getid3_asf::Content_Branding_Object => 'Content_Branding_Object',
rlm@3 1629 getid3_asf::Content_Encryption_Object => 'Content_Encryption_Object',
rlm@3 1630 getid3_asf::Digital_Signature_Object => 'Digital_Signature_Object',
rlm@3 1631 getid3_asf::Extended_Content_Encryption_Object => 'Extended_Content_Encryption_Object',
rlm@3 1632 getid3_asf::Simple_Index_Object => 'Simple_Index_Object',
rlm@3 1633 getid3_asf::Degradable_JPEG_Media => 'Degradable_JPEG_Media',
rlm@3 1634 getid3_asf::Payload_Extension_System_Timecode => 'Payload_Extension_System_Timecode',
rlm@3 1635 getid3_asf::Binary_Media => 'Binary_Media',
rlm@3 1636 getid3_asf::Timecode_Index_Object => 'Timecode_Index_Object',
rlm@3 1637 getid3_asf::Metadata_Library_Object => 'Metadata_Library_Object',
rlm@3 1638 getid3_asf::Reserved_3 => 'Reserved_3',
rlm@3 1639 getid3_asf::Reserved_4 => 'Reserved_4',
rlm@3 1640 getid3_asf::Command_Media => 'Command_Media',
rlm@3 1641 getid3_asf::Header_Extension_Object => 'Header_Extension_Object',
rlm@3 1642 getid3_asf::Media_Object_Index_Parameters_Obj => 'Media_Object_Index_Parameters_Obj',
rlm@3 1643 getid3_asf::Header_Object => 'Header_Object',
rlm@3 1644 getid3_asf::Content_Description_Object => 'Content_Description_Object',
rlm@3 1645 getid3_asf::Error_Correction_Object => 'Error_Correction_Object',
rlm@3 1646 getid3_asf::Data_Object => 'Data_Object',
rlm@3 1647 getid3_asf::Web_Stream_Media_Subtype => 'Web_Stream_Media_Subtype',
rlm@3 1648 getid3_asf::Stream_Bitrate_Properties_Object => 'Stream_Bitrate_Properties_Object',
rlm@3 1649 getid3_asf::Language_List_Object => 'Language_List_Object',
rlm@3 1650 getid3_asf::Codec_List_Object => 'Codec_List_Object',
rlm@3 1651 getid3_asf::Reserved_2 => 'Reserved_2',
rlm@3 1652 getid3_asf::File_Properties_Object => 'File_Properties_Object',
rlm@3 1653 getid3_asf::File_Transfer_Media => 'File_Transfer_Media',
rlm@3 1654 getid3_asf::Old_RTP_Extension_Data => 'Old_RTP_Extension_Data',
rlm@3 1655 getid3_asf::Advanced_Mutual_Exclusion_Object => 'Advanced_Mutual_Exclusion_Object',
rlm@3 1656 getid3_asf::Bandwidth_Sharing_Object => 'Bandwidth_Sharing_Object',
rlm@3 1657 getid3_asf::Reserved_1 => 'Reserved_1',
rlm@3 1658 getid3_asf::Bandwidth_Sharing_Exclusive => 'Bandwidth_Sharing_Exclusive',
rlm@3 1659 getid3_asf::Bandwidth_Sharing_Partial => 'Bandwidth_Sharing_Partial',
rlm@3 1660 getid3_asf::JFIF_Media => 'JFIF_Media',
rlm@3 1661 getid3_asf::Stream_Properties_Object => 'Stream_Properties_Object',
rlm@3 1662 getid3_asf::Video_Media => 'Video_Media',
rlm@3 1663 getid3_asf::Audio_Spread => 'Audio_Spread',
rlm@3 1664 getid3_asf::Metadata_Object => 'Metadata_Object',
rlm@3 1665 getid3_asf::Payload_Ext_Syst_Sample_Duration => 'Payload_Ext_Syst_Sample_Duration',
rlm@3 1666 getid3_asf::Group_Mutual_Exclusion_Object => 'Group_Mutual_Exclusion_Object',
rlm@3 1667 getid3_asf::Extended_Content_Description_Object => 'Extended_Content_Description_Object',
rlm@3 1668 getid3_asf::Stream_Prioritization_Object => 'Stream_Prioritization_Object',
rlm@3 1669 getid3_asf::Payload_Ext_System_Content_Type => 'Payload_Ext_System_Content_Type',
rlm@3 1670 getid3_asf::Old_File_Properties_Object => 'Old_File_Properties_Object',
rlm@3 1671 getid3_asf::Old_ASF_Header_Object => 'Old_ASF_Header_Object',
rlm@3 1672 getid3_asf::Old_ASF_Data_Object => 'Old_ASF_Data_Object',
rlm@3 1673 getid3_asf::Index_Object => 'Index_Object',
rlm@3 1674 getid3_asf::Old_Stream_Properties_Object => 'Old_Stream_Properties_Object',
rlm@3 1675 getid3_asf::Old_Content_Description_Object => 'Old_Content_Description_Object',
rlm@3 1676 getid3_asf::Old_Script_Command_Object => 'Old_Script_Command_Object',
rlm@3 1677 getid3_asf::Old_Marker_Object => 'Old_Marker_Object',
rlm@3 1678 getid3_asf::Old_Component_Download_Object => 'Old_Component_Download_Object',
rlm@3 1679 getid3_asf::Old_Stream_Group_Object => 'Old_Stream_Group_Object',
rlm@3 1680 getid3_asf::Old_Scalable_Object => 'Old_Scalable_Object',
rlm@3 1681 getid3_asf::Old_Prioritization_Object => 'Old_Prioritization_Object',
rlm@3 1682 getid3_asf::Bitrate_Mutual_Exclusion_Object => 'Bitrate_Mutual_Exclusion_Object',
rlm@3 1683 getid3_asf::Old_Inter_Media_Dependency_Object => 'Old_Inter_Media_Dependency_Object',
rlm@3 1684 getid3_asf::Old_Rating_Object => 'Old_Rating_Object',
rlm@3 1685 getid3_asf::Index_Parameters_Object => 'Index_Parameters_Object',
rlm@3 1686 getid3_asf::Old_Color_Table_Object => 'Old_Color_Table_Object',
rlm@3 1687 getid3_asf::Old_Language_List_Object => 'Old_Language_List_Object',
rlm@3 1688 getid3_asf::Old_Audio_Media => 'Old_Audio_Media',
rlm@3 1689 getid3_asf::Old_Video_Media => 'Old_Video_Media',
rlm@3 1690 getid3_asf::Old_Image_Media => 'Old_Image_Media',
rlm@3 1691 getid3_asf::Old_Timecode_Media => 'Old_Timecode_Media',
rlm@3 1692 getid3_asf::Old_Text_Media => 'Old_Text_Media',
rlm@3 1693 getid3_asf::Old_MIDI_Media => 'Old_MIDI_Media',
rlm@3 1694 getid3_asf::Old_Command_Media => 'Old_Command_Media',
rlm@3 1695 getid3_asf::Old_No_Error_Concealment => 'Old_No_Error_Concealment',
rlm@3 1696 getid3_asf::Old_Scrambled_Audio => 'Old_Scrambled_Audio',
rlm@3 1697 getid3_asf::Old_No_Color_Table => 'Old_No_Color_Table',
rlm@3 1698 getid3_asf::Old_SMPTE_Time => 'Old_SMPTE_Time',
rlm@3 1699 getid3_asf::Old_ASCII_Text => 'Old_ASCII_Text',
rlm@3 1700 getid3_asf::Old_Unicode_Text => 'Old_Unicode_Text',
rlm@3 1701 getid3_asf::Old_HTML_Text => 'Old_HTML_Text',
rlm@3 1702 getid3_asf::Old_URL_Command => 'Old_URL_Command',
rlm@3 1703 getid3_asf::Old_Filename_Command => 'Old_Filename_Command',
rlm@3 1704 getid3_asf::Old_ACM_Codec => 'Old_ACM_Codec',
rlm@3 1705 getid3_asf::Old_VCM_Codec => 'Old_VCM_Codec',
rlm@3 1706 getid3_asf::Old_QuickTime_Codec => 'Old_QuickTime_Codec',
rlm@3 1707 getid3_asf::Old_DirectShow_Transform_Filter => 'Old_DirectShow_Transform_Filter',
rlm@3 1708 getid3_asf::Old_DirectShow_Rendering_Filter => 'Old_DirectShow_Rendering_Filter',
rlm@3 1709 getid3_asf::Old_No_Enhancement => 'Old_No_Enhancement',
rlm@3 1710 getid3_asf::Old_Unknown_Enhancement_Type => 'Old_Unknown_Enhancement_Type',
rlm@3 1711 getid3_asf::Old_Temporal_Enhancement => 'Old_Temporal_Enhancement',
rlm@3 1712 getid3_asf::Old_Spatial_Enhancement => 'Old_Spatial_Enhancement',
rlm@3 1713 getid3_asf::Old_Quality_Enhancement => 'Old_Quality_Enhancement',
rlm@3 1714 getid3_asf::Old_Number_of_Channels_Enhancement => 'Old_Number_of_Channels_Enhancement',
rlm@3 1715 getid3_asf::Old_Frequency_Response_Enhancement => 'Old_Frequency_Response_Enhancement',
rlm@3 1716 getid3_asf::Old_Media_Object => 'Old_Media_Object',
rlm@3 1717 getid3_asf::Mutex_Language => 'Mutex_Language',
rlm@3 1718 getid3_asf::Mutex_Bitrate => 'Mutex_Bitrate',
rlm@3 1719 getid3_asf::Mutex_Unknown => 'Mutex_Unknown',
rlm@3 1720 getid3_asf::Old_ASF_Placeholder_Object => 'Old_ASF_Placeholder_Object',
rlm@3 1721 getid3_asf::Old_Data_Unit_Extension_Object => 'Old_Data_Unit_Extension_Object',
rlm@3 1722 getid3_asf::Web_Stream_Format => 'Web_Stream_Format',
rlm@3 1723 getid3_asf::Payload_Ext_System_File_Name => 'Payload_Ext_System_File_Name',
rlm@3 1724 getid3_asf::Marker_Object => 'Marker_Object',
rlm@3 1725 getid3_asf::Timecode_Index_Parameters_Object => 'Timecode_Index_Parameters_Object',
rlm@3 1726 getid3_asf::Audio_Media => 'Audio_Media',
rlm@3 1727 getid3_asf::Media_Object_Index_Object => 'Media_Object_Index_Object',
rlm@3 1728 getid3_asf::Alt_Extended_Content_Encryption_Obj => 'Alt_Extended_Content_Encryption_Obj'
rlm@3 1729 );
rlm@3 1730
rlm@3 1731 return @$lookup[$guid_string];
rlm@3 1732 }
rlm@3 1733
rlm@3 1734
rlm@3 1735
rlm@3 1736 public static function ASFIndexObjectIndexTypeLookup($id) {
rlm@3 1737
rlm@3 1738 static $lookup = array (
rlm@3 1739 1 => 'Nearest Past Data Packet',
rlm@3 1740 2 => 'Nearest Past Media Object',
rlm@3 1741 3 => 'Nearest Past Cleanpoint'
rlm@3 1742 );
rlm@3 1743
rlm@3 1744 return (isset($lookup[$id]) ? $lookup[$id] : 'invalid');
rlm@3 1745 }
rlm@3 1746
rlm@3 1747
rlm@3 1748
rlm@3 1749 public static function GUIDtoBytestring($guid_string) {
rlm@3 1750
rlm@3 1751 // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way:
rlm@3 1752 // first 4 bytes are in little-endian order
rlm@3 1753 // next 2 bytes are appended in little-endian order
rlm@3 1754 // next 2 bytes are appended in little-endian order
rlm@3 1755 // next 2 bytes are appended in big-endian order
rlm@3 1756 // next 6 bytes are appended in big-endian order
rlm@3 1757
rlm@3 1758 // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string:
rlm@3 1759 // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp
rlm@3 1760
rlm@3 1761 $hex_byte_char_string = chr(hexdec(substr($guid_string, 6, 2)));
rlm@3 1762 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 4, 2)));
rlm@3 1763 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 2, 2)));
rlm@3 1764 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 0, 2)));
rlm@3 1765
rlm@3 1766 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 11, 2)));
rlm@3 1767 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 9, 2)));
rlm@3 1768
rlm@3 1769 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 16, 2)));
rlm@3 1770 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 14, 2)));
rlm@3 1771
rlm@3 1772 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 19, 2)));
rlm@3 1773 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 21, 2)));
rlm@3 1774
rlm@3 1775 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 24, 2)));
rlm@3 1776 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 26, 2)));
rlm@3 1777 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 28, 2)));
rlm@3 1778 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 30, 2)));
rlm@3 1779 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 32, 2)));
rlm@3 1780 $hex_byte_char_string .= chr(hexdec(substr($guid_string, 34, 2)));
rlm@3 1781
rlm@3 1782 return $hex_byte_char_string;
rlm@3 1783 }
rlm@3 1784
rlm@3 1785
rlm@3 1786
rlm@3 1787 public static function BytestringToGUID($byte_string) {
rlm@3 1788
rlm@3 1789 $guid_string = str_pad(dechex(ord($byte_string{3})), 2, '0', STR_PAD_LEFT);
rlm@3 1790 $guid_string .= str_pad(dechex(ord($byte_string{2})), 2, '0', STR_PAD_LEFT);
rlm@3 1791 $guid_string .= str_pad(dechex(ord($byte_string{1})), 2, '0', STR_PAD_LEFT);
rlm@3 1792 $guid_string .= str_pad(dechex(ord($byte_string{0})), 2, '0', STR_PAD_LEFT);
rlm@3 1793 $guid_string .= '-';
rlm@3 1794 $guid_string .= str_pad(dechex(ord($byte_string{5})), 2, '0', STR_PAD_LEFT);
rlm@3 1795 $guid_string .= str_pad(dechex(ord($byte_string{4})), 2, '0', STR_PAD_LEFT);
rlm@3 1796 $guid_string .= '-';
rlm@3 1797 $guid_string .= str_pad(dechex(ord($byte_string{7})), 2, '0', STR_PAD_LEFT);
rlm@3 1798 $guid_string .= str_pad(dechex(ord($byte_string{6})), 2, '0', STR_PAD_LEFT);
rlm@3 1799 $guid_string .= '-';
rlm@3 1800 $guid_string .= str_pad(dechex(ord($byte_string{8})), 2, '0', STR_PAD_LEFT);
rlm@3 1801 $guid_string .= str_pad(dechex(ord($byte_string{9})), 2, '0', STR_PAD_LEFT);
rlm@3 1802 $guid_string .= '-';
rlm@3 1803 $guid_string .= str_pad(dechex(ord($byte_string{10})), 2, '0', STR_PAD_LEFT);
rlm@3 1804 $guid_string .= str_pad(dechex(ord($byte_string{11})), 2, '0', STR_PAD_LEFT);
rlm@3 1805 $guid_string .= str_pad(dechex(ord($byte_string{12})), 2, '0', STR_PAD_LEFT);
rlm@3 1806 $guid_string .= str_pad(dechex(ord($byte_string{13})), 2, '0', STR_PAD_LEFT);
rlm@3 1807 $guid_string .= str_pad(dechex(ord($byte_string{14})), 2, '0', STR_PAD_LEFT);
rlm@3 1808 $guid_string .= str_pad(dechex(ord($byte_string{15})), 2, '0', STR_PAD_LEFT);
rlm@3 1809
rlm@3 1810 return strtoupper($guid_string);
rlm@3 1811 }
rlm@3 1812
rlm@3 1813
rlm@3 1814
rlm@3 1815 public static function FiletimeToUNIXtime($file_time, $round=true) {
rlm@3 1816
rlm@3 1817 // FILETIME is a 64-bit unsigned integer representing
rlm@3 1818 // the number of 100-nanosecond intervals since January 1, 1601
rlm@3 1819 // UNIX timestamp is number of seconds since January 1, 1970
rlm@3 1820 // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days
rlm@3 1821
rlm@3 1822 $time = ($file_time - 116444736000000000) / 10000000;
rlm@3 1823
rlm@3 1824 if ($round) {
rlm@3 1825 return intval(round($time));
rlm@3 1826 }
rlm@3 1827
rlm@3 1828 return $time;
rlm@3 1829 }
rlm@3 1830
rlm@3 1831
rlm@3 1832
rlm@3 1833 public static function TrimTerm($string) {
rlm@3 1834
rlm@3 1835 // remove terminator, only if present (it should be, but...)
rlm@3 1836 if (substr($string, -2) == "\x00\x00") {
rlm@3 1837 $string = substr($string, 0, -2);
rlm@3 1838 }
rlm@3 1839 return $string;
rlm@3 1840 }
rlm@3 1841
rlm@3 1842
rlm@3 1843 }
rlm@3 1844
rlm@3 1845
rlm@3 1846 ?>