PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/components/com_jce/editor/tiny_mce/plugins/mediamanager/classes/getid3/module.audio-video.asf.php

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