PageRenderTime 52ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/application/libraries/getid3/module.audio-video.asf.php

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