PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/ID3/module.audio-video.asf.php

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