module.audio-video.asf.php 133 KB

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