PageRenderTime 61ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/mp3player/player/php/getid3/module.audio-video.asf.php

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