module.audio-video.asf.php 125 KB

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