Nessuna descrizione

module.audio-video.asf.php 125KB

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