getid3_asf

The WordPress Core getid3 asf class.

Defined (1)

The class is defined in the following location(s).

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