Decoder.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. // universal module definition
  2. (function(root, factory) {
  3. if(typeof define === 'function' && define.amd) {
  4. // AMD. Register as an anonymous module.
  5. define([], factory);
  6. } else if(typeof exports === 'object') {
  7. // Node. Does not work with strict CommonJS, but
  8. // only CommonJS-like environments that support module.exports,
  9. // like Node.
  10. module.exports = factory();
  11. } else {
  12. // Browser globals (root is window)
  13. root.Decoder = factory();
  14. }
  15. }(this, function() {
  16. var global;
  17. function initglobal() {
  18. global = this;
  19. if(!global) {
  20. if(typeof window != "undefined") {
  21. global = window;
  22. } else if(typeof self != "undefined") {
  23. global = self;
  24. };
  25. };
  26. };
  27. initglobal();
  28. function error(message) {
  29. console.error(message);
  30. console.trace();
  31. };
  32. function assert(condition, message) {
  33. if(!condition) {
  34. error(message);
  35. };
  36. };
  37. var getModule = function(par_broadwayOnHeadersDecoded, par_broadwayOnPictureDecoded) {
  38. /*var ModuleX = {
  39. 'print': function(text) { console.log('stdout: ' + text); },
  40. 'printErr': function(text) { console.log('stderr: ' + text); }
  41. };*/
  42. /*
  43. The reason why this is all packed into one file is that this file can also function as worker.
  44. you can integrate the file into your build system and provide the original file to be loaded into a worker.
  45. */
  46. //var Module = (function(){
  47. var Module = typeof Module !== "undefined" ? Module : {};
  48. var moduleOverrides = {};
  49. var key;
  50. for(key in Module) {
  51. if(Module.hasOwnProperty(key)) {
  52. moduleOverrides[key] = Module[key]
  53. }
  54. }
  55. Module["arguments"] = [];
  56. Module["thisProgram"] = "./this.program";
  57. Module["quit"] = (function(status, toThrow) {
  58. throw toThrow
  59. });
  60. Module["preRun"] = [];
  61. Module["postRun"] = [];
  62. var ENVIRONMENT_IS_WEB = false;
  63. var ENVIRONMENT_IS_WORKER = false;
  64. var ENVIRONMENT_IS_NODE = false;
  65. var ENVIRONMENT_IS_SHELL = false;
  66. if(Module["ENVIRONMENT"]) {
  67. if(Module["ENVIRONMENT"] === "WEB") {
  68. ENVIRONMENT_IS_WEB = true
  69. } else if(Module["ENVIRONMENT"] === "WORKER") {
  70. ENVIRONMENT_IS_WORKER = true
  71. } else if(Module["ENVIRONMENT"] === "NODE") {
  72. ENVIRONMENT_IS_NODE = true
  73. } else if(Module["ENVIRONMENT"] === "SHELL") {
  74. ENVIRONMENT_IS_SHELL = true
  75. } else {
  76. throw new Error("Module['ENVIRONMENT'] value is not valid. must be one of: WEB|WORKER|NODE|SHELL.")
  77. }
  78. } else {
  79. ENVIRONMENT_IS_WEB = typeof window === "object";
  80. ENVIRONMENT_IS_WORKER = typeof importScripts === "function";
  81. ENVIRONMENT_IS_NODE = typeof process === "object" && typeof null === "function" && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER;
  82. ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER
  83. }
  84. if(ENVIRONMENT_IS_NODE) {
  85. var nodeFS;
  86. var nodePath;
  87. Module["read"] = function shell_read(filename, binary) {
  88. var ret;
  89. if(!nodeFS) nodeFS = (null)("fs");
  90. if(!nodePath) nodePath = (null)("path");
  91. filename = nodePath["normalize"](filename);
  92. ret = nodeFS["readFileSync"](filename);
  93. return binary ? ret : ret.toString()
  94. };
  95. Module["readBinary"] = function readBinary(filename) {
  96. var ret = Module["read"](filename, true);
  97. if(!ret.buffer) {
  98. ret = new Uint8Array(ret)
  99. }
  100. assert(ret.buffer);
  101. return ret
  102. };
  103. if(process["argv"].length > 1) {
  104. Module["thisProgram"] = process["argv"][1].replace(/\\/g, "/")
  105. }
  106. Module["arguments"] = process["argv"].slice(2);
  107. if(typeof module !== "undefined") {
  108. module["exports"] = Module
  109. }
  110. process["on"]("uncaughtException", (function(ex) {
  111. if(!(ex instanceof ExitStatus)) {
  112. throw ex
  113. }
  114. }));
  115. process["on"]("unhandledRejection", (function(reason, p) {
  116. process["exit"](1)
  117. }));
  118. Module["inspect"] = (function() {
  119. return "[Emscripten Module object]"
  120. })
  121. } else if(ENVIRONMENT_IS_SHELL) {
  122. if(typeof read != "undefined") {
  123. Module["read"] = function shell_read(f) {
  124. return read(f)
  125. }
  126. }
  127. Module["readBinary"] = function readBinary(f) {
  128. var data;
  129. if(typeof readbuffer === "function") {
  130. return new Uint8Array(readbuffer(f))
  131. }
  132. data = read(f, "binary");
  133. assert(typeof data === "object");
  134. return data
  135. };
  136. if(typeof scriptArgs != "undefined") {
  137. Module["arguments"] = scriptArgs
  138. } else if(typeof arguments != "undefined") {
  139. Module["arguments"] = arguments
  140. }
  141. if(typeof quit === "function") {
  142. Module["quit"] = (function(status, toThrow) {
  143. quit(status)
  144. })
  145. }
  146. } else if(ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  147. Module["read"] = function shell_read(url) {
  148. var xhr = new XMLHttpRequest;
  149. xhr.open("GET", url, false);
  150. xhr.send(null);
  151. return xhr.responseText
  152. };
  153. if(ENVIRONMENT_IS_WORKER) {
  154. Module["readBinary"] = function readBinary(url) {
  155. var xhr = new XMLHttpRequest;
  156. xhr.open("GET", url, false);
  157. xhr.responseType = "arraybuffer";
  158. xhr.send(null);
  159. return new Uint8Array(xhr.response)
  160. }
  161. }
  162. Module["readAsync"] = function readAsync(url, onload, onerror) {
  163. var xhr = new XMLHttpRequest;
  164. xhr.open("GET", url, true);
  165. xhr.responseType = "arraybuffer";
  166. xhr.onload = function xhr_onload() {
  167. if(xhr.status == 200 || xhr.status == 0 && xhr.response) {
  168. onload(xhr.response);
  169. return
  170. }
  171. onerror()
  172. };
  173. xhr.onerror = onerror;
  174. xhr.send(null)
  175. };
  176. Module["setWindowTitle"] = (function(title) {
  177. document.title = title
  178. })
  179. } else {
  180. throw new Error("not compiled for this environment")
  181. }
  182. Module["print"] = typeof console !== "undefined" ? console.log.bind(console) : typeof print !== "undefined" ? print : null;
  183. Module["printErr"] = typeof printErr !== "undefined" ? printErr : typeof console !== "undefined" && console.warn.bind(console) || Module["print"];
  184. Module.print = Module["print"];
  185. Module.printErr = Module["printErr"];
  186. for(key in moduleOverrides) {
  187. if(moduleOverrides.hasOwnProperty(key)) {
  188. Module[key] = moduleOverrides[key]
  189. }
  190. }
  191. moduleOverrides = undefined;
  192. var STACK_ALIGN = 16;
  193. function staticAlloc(size) {
  194. assert(!staticSealed);
  195. var ret = STATICTOP;
  196. STATICTOP = STATICTOP + size + 15 & -16;
  197. return ret
  198. }
  199. function alignMemory(size, factor) {
  200. if(!factor) factor = STACK_ALIGN;
  201. var ret = size = Math.ceil(size / factor) * factor;
  202. return ret
  203. }
  204. var asm2wasmImports = {
  205. "f64-rem": (function(x, y) {
  206. return x % y
  207. }),
  208. "debugger": (function() {
  209. debugger
  210. })
  211. };
  212. var functionPointers = new Array(0);
  213. var GLOBAL_BASE = 1024;
  214. var ABORT = 0;
  215. var EXITSTATUS = 0;
  216. function assert(condition, text) {
  217. if(!condition) {
  218. abort("Assertion failed: " + text)
  219. }
  220. }
  221. function Pointer_stringify(ptr, length) {
  222. if(length === 0 || !ptr) return "";
  223. var hasUtf = 0;
  224. var t;
  225. var i = 0;
  226. while(1) {
  227. t = HEAPU8[ptr + i >> 0];
  228. hasUtf |= t;
  229. if(t == 0 && !length) break;
  230. i++;
  231. if(length && i == length) break
  232. }
  233. if(!length) length = i;
  234. var ret = "";
  235. if(hasUtf < 128) {
  236. var MAX_CHUNK = 1024;
  237. var curr;
  238. while(length > 0) {
  239. curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK)));
  240. ret = ret ? ret + curr : curr;
  241. ptr += MAX_CHUNK;
  242. length -= MAX_CHUNK
  243. }
  244. return ret
  245. }
  246. return UTF8ToString(ptr)
  247. }
  248. var UTF8Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf8") : undefined;
  249. function UTF8ArrayToString(u8Array, idx) {
  250. var endPtr = idx;
  251. while(u8Array[endPtr]) ++endPtr;
  252. if(endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) {
  253. return UTF8Decoder.decode(u8Array.subarray(idx, endPtr))
  254. } else {
  255. var u0, u1, u2, u3, u4, u5;
  256. var str = "";
  257. while(1) {
  258. u0 = u8Array[idx++];
  259. if(!u0) return str;
  260. if(!(u0 & 128)) {
  261. str += String.fromCharCode(u0);
  262. continue
  263. }
  264. u1 = u8Array[idx++] & 63;
  265. if((u0 & 224) == 192) {
  266. str += String.fromCharCode((u0 & 31) << 6 | u1);
  267. continue
  268. }
  269. u2 = u8Array[idx++] & 63;
  270. if((u0 & 240) == 224) {
  271. u0 = (u0 & 15) << 12 | u1 << 6 | u2
  272. } else {
  273. u3 = u8Array[idx++] & 63;
  274. if((u0 & 248) == 240) {
  275. u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | u3
  276. } else {
  277. u4 = u8Array[idx++] & 63;
  278. if((u0 & 252) == 248) {
  279. u0 = (u0 & 3) << 24 | u1 << 18 | u2 << 12 | u3 << 6 | u4
  280. } else {
  281. u5 = u8Array[idx++] & 63;
  282. u0 = (u0 & 1) << 30 | u1 << 24 | u2 << 18 | u3 << 12 | u4 << 6 | u5
  283. }
  284. }
  285. }
  286. if(u0 < 65536) {
  287. str += String.fromCharCode(u0)
  288. } else {
  289. var ch = u0 - 65536;
  290. str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023)
  291. }
  292. }
  293. }
  294. }
  295. function UTF8ToString(ptr) {
  296. return UTF8ArrayToString(HEAPU8, ptr)
  297. }
  298. var UTF16Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-16le") : undefined;
  299. var WASM_PAGE_SIZE = 65536;
  300. var ASMJS_PAGE_SIZE = 16777216;
  301. function alignUp(x, multiple) {
  302. if(x % multiple > 0) {
  303. x += multiple - x % multiple
  304. }
  305. return x
  306. }
  307. var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
  308. function updateGlobalBuffer(buf) {
  309. Module["buffer"] = buffer = buf
  310. }
  311. function updateGlobalBufferViews() {
  312. Module["HEAP8"] = HEAP8 = new Int8Array(buffer);
  313. Module["HEAP16"] = HEAP16 = new Int16Array(buffer);
  314. Module["HEAP32"] = HEAP32 = new Int32Array(buffer);
  315. Module["HEAPU8"] = HEAPU8 = new Uint8Array(buffer);
  316. Module["HEAPU16"] = HEAPU16 = new Uint16Array(buffer);
  317. Module["HEAPU32"] = HEAPU32 = new Uint32Array(buffer);
  318. Module["HEAPF32"] = HEAPF32 = new Float32Array(buffer);
  319. Module["HEAPF64"] = HEAPF64 = new Float64Array(buffer)
  320. }
  321. var STATIC_BASE, STATICTOP, staticSealed;
  322. var STACK_BASE, STACKTOP, STACK_MAX;
  323. var DYNAMIC_BASE, DYNAMICTOP_PTR;
  324. STATIC_BASE = STATICTOP = STACK_BASE = STACKTOP = STACK_MAX = DYNAMIC_BASE = DYNAMICTOP_PTR = 0;
  325. staticSealed = false;
  326. function abortOnCannotGrowMemory() {
  327. abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value " + TOTAL_MEMORY + ", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")
  328. }
  329. function enlargeMemory() {
  330. abortOnCannotGrowMemory()
  331. }
  332. var TOTAL_STACK = Module["TOTAL_STACK"] || 5242880;
  333. var TOTAL_MEMORY = Module["TOTAL_MEMORY"] || 52428800;
  334. if(TOTAL_MEMORY < TOTAL_STACK) Module.printErr("TOTAL_MEMORY should be larger than TOTAL_STACK, was " + TOTAL_MEMORY + "! (TOTAL_STACK=" + TOTAL_STACK + ")");
  335. if(Module["buffer"]) {
  336. buffer = Module["buffer"]
  337. } else {
  338. if(typeof WebAssembly === "object" && typeof WebAssembly.Memory === "function") {
  339. Module["wasmMemory"] = new WebAssembly.Memory({
  340. "initial": TOTAL_MEMORY / WASM_PAGE_SIZE,
  341. "maximum": TOTAL_MEMORY / WASM_PAGE_SIZE
  342. });
  343. buffer = Module["wasmMemory"].buffer
  344. } else {
  345. buffer = new ArrayBuffer(TOTAL_MEMORY)
  346. }
  347. Module["buffer"] = buffer
  348. }
  349. updateGlobalBufferViews();
  350. function getTotalMemory() {
  351. return TOTAL_MEMORY
  352. }
  353. HEAP32[0] = 1668509029;
  354. HEAP16[1] = 25459;
  355. if(HEAPU8[2] !== 115 || HEAPU8[3] !== 99) throw "Runtime error: expected the system to be little-endian!";
  356. function callRuntimeCallbacks(callbacks) {
  357. while(callbacks.length > 0) {
  358. var callback = callbacks.shift();
  359. if(typeof callback == "function") {
  360. callback();
  361. continue
  362. }
  363. var func = callback.func;
  364. if(typeof func === "number") {
  365. if(callback.arg === undefined) {
  366. Module["dynCall_v"](func)
  367. } else {
  368. Module["dynCall_vi"](func, callback.arg)
  369. }
  370. } else {
  371. func(callback.arg === undefined ? null : callback.arg)
  372. }
  373. }
  374. }
  375. var __ATPRERUN__ = [];
  376. var __ATINIT__ = [];
  377. var __ATMAIN__ = [];
  378. var __ATEXIT__ = [];
  379. var __ATPOSTRUN__ = [];
  380. var runtimeInitialized = false;
  381. var runtimeExited = false;
  382. function preRun() {
  383. if(Module["preRun"]) {
  384. if(typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]];
  385. while(Module["preRun"].length) {
  386. addOnPreRun(Module["preRun"].shift())
  387. }
  388. }
  389. callRuntimeCallbacks(__ATPRERUN__)
  390. }
  391. function ensureInitRuntime() {
  392. if(runtimeInitialized) return;
  393. runtimeInitialized = true;
  394. callRuntimeCallbacks(__ATINIT__)
  395. }
  396. function preMain() {
  397. callRuntimeCallbacks(__ATMAIN__)
  398. }
  399. function exitRuntime() {
  400. callRuntimeCallbacks(__ATEXIT__);
  401. runtimeExited = true
  402. }
  403. function postRun() {
  404. if(Module["postRun"]) {
  405. if(typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]];
  406. while(Module["postRun"].length) {
  407. addOnPostRun(Module["postRun"].shift())
  408. }
  409. }
  410. callRuntimeCallbacks(__ATPOSTRUN__)
  411. }
  412. function addOnPreRun(cb) {
  413. __ATPRERUN__.unshift(cb)
  414. }
  415. function addOnPostRun(cb) {
  416. __ATPOSTRUN__.unshift(cb)
  417. }
  418. var Math_abs = Math.abs;
  419. var Math_cos = Math.cos;
  420. var Math_sin = Math.sin;
  421. var Math_tan = Math.tan;
  422. var Math_acos = Math.acos;
  423. var Math_asin = Math.asin;
  424. var Math_atan = Math.atan;
  425. var Math_atan2 = Math.atan2;
  426. var Math_exp = Math.exp;
  427. var Math_log = Math.log;
  428. var Math_sqrt = Math.sqrt;
  429. var Math_ceil = Math.ceil;
  430. var Math_floor = Math.floor;
  431. var Math_pow = Math.pow;
  432. var Math_imul = Math.imul;
  433. var Math_fround = Math.fround;
  434. var Math_round = Math.round;
  435. var Math_min = Math.min;
  436. var Math_max = Math.max;
  437. var Math_clz32 = Math.clz32;
  438. var Math_trunc = Math.trunc;
  439. var runDependencies = 0;
  440. var runDependencyWatcher = null;
  441. var dependenciesFulfilled = null;
  442. function addRunDependency(id) {
  443. runDependencies++;
  444. if(Module["monitorRunDependencies"]) {
  445. Module["monitorRunDependencies"](runDependencies)
  446. }
  447. }
  448. function removeRunDependency(id) {
  449. runDependencies--;
  450. if(Module["monitorRunDependencies"]) {
  451. Module["monitorRunDependencies"](runDependencies)
  452. }
  453. if(runDependencies == 0) {
  454. if(runDependencyWatcher !== null) {
  455. clearInterval(runDependencyWatcher);
  456. runDependencyWatcher = null
  457. }
  458. if(dependenciesFulfilled) {
  459. var callback = dependenciesFulfilled;
  460. dependenciesFulfilled = null;
  461. callback()
  462. }
  463. }
  464. }
  465. Module["preloadedImages"] = {};
  466. Module["preloadedAudios"] = {};
  467. var dataURIPrefix = "data:application/octet-stream;base64,";
  468. function isDataURI(filename) {
  469. return String.prototype.startsWith ? filename.startsWith(dataURIPrefix) : filename.indexOf(dataURIPrefix) === 0
  470. }
  471. function integrateWasmJS() {
  472. var wasmTextFile = "avc.wast";
  473. var wasmBinaryFile = "../static/avc.wasm";
  474. var asmjsCodeFile = "avc.temp.asm.js";
  475. if(typeof Module["locateFile"] === "function") {
  476. if(!isDataURI(wasmTextFile)) {
  477. wasmTextFile = Module["locateFile"](wasmTextFile)
  478. }
  479. if(!isDataURI(wasmBinaryFile)) {
  480. wasmBinaryFile = Module["locateFile"](wasmBinaryFile)
  481. }
  482. if(!isDataURI(asmjsCodeFile)) {
  483. asmjsCodeFile = Module["locateFile"](asmjsCodeFile)
  484. }
  485. }
  486. var wasmPageSize = 64 * 1024;
  487. var info = {
  488. "global": null,
  489. "env": null,
  490. "asm2wasm": asm2wasmImports,
  491. "parent": Module
  492. };
  493. var exports = null;
  494. function mergeMemory(newBuffer) {
  495. var oldBuffer = Module["buffer"];
  496. if(newBuffer.byteLength < oldBuffer.byteLength) {
  497. Module["printErr"]("the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here")
  498. }
  499. var oldView = new Int8Array(oldBuffer);
  500. var newView = new Int8Array(newBuffer);
  501. newView.set(oldView);
  502. updateGlobalBuffer(newBuffer);
  503. updateGlobalBufferViews()
  504. }
  505. function fixImports(imports) {
  506. return imports
  507. }
  508. function getBinary() {
  509. try {
  510. if(Module["wasmBinary"]) {
  511. return new Uint8Array(Module["wasmBinary"])
  512. }
  513. if(Module["readBinary"]) {
  514. return Module["readBinary"](wasmBinaryFile)
  515. } else {
  516. throw "on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)"
  517. }
  518. } catch(err) {
  519. abort(err)
  520. }
  521. }
  522. function getBinaryPromise() {
  523. if(!Module["wasmBinary"] && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === "function") {
  524. return fetch(wasmBinaryFile, {
  525. credentials: "same-origin"
  526. }).then((function(response) {
  527. if(!response["ok"]) {
  528. throw "failed to load wasm binary file at '" + wasmBinaryFile + "'"
  529. }
  530. return response["arrayBuffer"]()
  531. })).catch((function() {
  532. return getBinary()
  533. }))
  534. }
  535. return new Promise((function(resolve, reject) {
  536. resolve(getBinary())
  537. }))
  538. }
  539. function doNativeWasm(global, env, providedBuffer) {
  540. if(typeof WebAssembly !== "object") {
  541. Module["printErr"]("no native wasm support detected");
  542. return false
  543. }
  544. if(!(Module["wasmMemory"] instanceof WebAssembly.Memory)) {
  545. Module["printErr"]("no native wasm Memory in use");
  546. return false
  547. }
  548. env["memory"] = Module["wasmMemory"];
  549. info["global"] = {
  550. "NaN": NaN,
  551. "Infinity": Infinity
  552. };
  553. info["global.Math"] = Math;
  554. info["env"] = env;
  555. function receiveInstance(instance, module) {
  556. exports = instance.exports;
  557. if(exports.memory) mergeMemory(exports.memory);
  558. Module["asm"] = exports;
  559. Module["usingWasm"] = true;
  560. removeRunDependency("wasm-instantiate")
  561. }
  562. addRunDependency("wasm-instantiate");
  563. if(Module["instantiateWasm"]) {
  564. try {
  565. return Module["instantiateWasm"](info, receiveInstance)
  566. } catch(e) {
  567. Module["printErr"]("Module.instantiateWasm callback failed with error: " + e);
  568. return false
  569. }
  570. }
  571. function receiveInstantiatedSource(output) {
  572. receiveInstance(output["instance"], output["module"])
  573. }
  574. function instantiateArrayBuffer(receiver) {
  575. getBinaryPromise().then((function(binary) {
  576. return WebAssembly.instantiate(binary, info)
  577. })).then(receiver).catch((function(reason) {
  578. Module["printErr"]("failed to asynchronously prepare wasm: " + reason);
  579. abort(reason)
  580. }))
  581. }
  582. if(!Module["wasmBinary"] && typeof WebAssembly.instantiateStreaming === "function" && !isDataURI(wasmBinaryFile) && typeof fetch === "function") {
  583. WebAssembly.instantiateStreaming(fetch(wasmBinaryFile, {
  584. credentials: "same-origin"
  585. }), info).then(receiveInstantiatedSource).catch((function(reason) {
  586. Module["printErr"]("wasm streaming compile failed: " + reason);
  587. Module["printErr"]("falling back to ArrayBuffer instantiation");
  588. instantiateArrayBuffer(receiveInstantiatedSource)
  589. }))
  590. } else {
  591. instantiateArrayBuffer(receiveInstantiatedSource)
  592. }
  593. return {}
  594. }
  595. Module["asmPreload"] = Module["asm"];
  596. var asmjsReallocBuffer = Module["reallocBuffer"];
  597. var wasmReallocBuffer = (function(size) {
  598. var PAGE_MULTIPLE = Module["usingWasm"] ? WASM_PAGE_SIZE : ASMJS_PAGE_SIZE;
  599. size = alignUp(size, PAGE_MULTIPLE);
  600. var old = Module["buffer"];
  601. var oldSize = old.byteLength;
  602. if(Module["usingWasm"]) {
  603. try {
  604. var result = Module["wasmMemory"].grow((size - oldSize) / wasmPageSize);
  605. if(result !== (-1 | 0)) {
  606. return Module["buffer"] = Module["wasmMemory"].buffer
  607. } else {
  608. return null
  609. }
  610. } catch(e) {
  611. return null
  612. }
  613. }
  614. });
  615. Module["reallocBuffer"] = (function(size) {
  616. if(finalMethod === "asmjs") {
  617. return asmjsReallocBuffer(size)
  618. } else {
  619. return wasmReallocBuffer(size)
  620. }
  621. });
  622. var finalMethod = "";
  623. Module["asm"] = (function(global, env, providedBuffer) {
  624. env = fixImports(env);
  625. if(!env["table"]) {
  626. var TABLE_SIZE = Module["wasmTableSize"];
  627. if(TABLE_SIZE === undefined) TABLE_SIZE = 1024;
  628. var MAX_TABLE_SIZE = Module["wasmMaxTableSize"];
  629. if(typeof WebAssembly === "object" && typeof WebAssembly.Table === "function") {
  630. if(MAX_TABLE_SIZE !== undefined) {
  631. env["table"] = new WebAssembly.Table({
  632. "initial": TABLE_SIZE,
  633. "maximum": MAX_TABLE_SIZE,
  634. "element": "anyfunc"
  635. })
  636. } else {
  637. env["table"] = new WebAssembly.Table({
  638. "initial": TABLE_SIZE,
  639. element: "anyfunc"
  640. })
  641. }
  642. } else {
  643. env["table"] = new Array(TABLE_SIZE)
  644. }
  645. Module["wasmTable"] = env["table"]
  646. }
  647. if(!env["memoryBase"]) {
  648. env["memoryBase"] = Module["STATIC_BASE"]
  649. }
  650. if(!env["tableBase"]) {
  651. env["tableBase"] = 0
  652. }
  653. var exports;
  654. exports = doNativeWasm(global, env, providedBuffer);
  655. assert(exports, "no binaryen method succeeded.");
  656. return exports
  657. })
  658. }
  659. integrateWasmJS();
  660. STATIC_BASE = GLOBAL_BASE;
  661. STATICTOP = STATIC_BASE + 9888;
  662. __ATINIT__.push();
  663. var STATIC_BUMP = 9888;
  664. Module["STATIC_BASE"] = STATIC_BASE;
  665. Module["STATIC_BUMP"] = STATIC_BUMP;
  666. STATICTOP += 16;
  667. var SYSCALLS = {
  668. varargs: 0,
  669. get: (function(varargs) {
  670. SYSCALLS.varargs += 4;
  671. var ret = HEAP32[SYSCALLS.varargs - 4 >> 2];
  672. return ret
  673. }),
  674. getStr: (function() {
  675. var ret = Pointer_stringify(SYSCALLS.get());
  676. return ret
  677. }),
  678. get64: (function() {
  679. var low = SYSCALLS.get(),
  680. high = SYSCALLS.get();
  681. if(low >= 0) assert(high === 0);
  682. else assert(high === -1);
  683. return low
  684. }),
  685. getZero: (function() {
  686. assert(SYSCALLS.get() === 0)
  687. })
  688. };
  689. function ___syscall140(which, varargs) {
  690. SYSCALLS.varargs = varargs;
  691. try {
  692. var stream = SYSCALLS.getStreamFromFD(),
  693. offset_high = SYSCALLS.get(),
  694. offset_low = SYSCALLS.get(),
  695. result = SYSCALLS.get(),
  696. whence = SYSCALLS.get();
  697. var offset = offset_low;
  698. FS.llseek(stream, offset, whence);
  699. HEAP32[result >> 2] = stream.position;
  700. if(stream.getdents && offset === 0 && whence === 0) stream.getdents = null;
  701. return 0
  702. } catch(e) {
  703. if(typeof FS === "undefined" || !(e instanceof FS.ErrnoError)) abort(e);
  704. return -e.errno
  705. }
  706. }
  707. function ___syscall146(which, varargs) {
  708. SYSCALLS.varargs = varargs;
  709. try {
  710. var stream = SYSCALLS.get(),
  711. iov = SYSCALLS.get(),
  712. iovcnt = SYSCALLS.get();
  713. var ret = 0;
  714. if(!___syscall146.buffers) {
  715. ___syscall146.buffers = [null, [],
  716. []
  717. ];
  718. ___syscall146.printChar = (function(stream, curr) {
  719. var buffer = ___syscall146.buffers[stream];
  720. assert(buffer);
  721. if(curr === 0 || curr === 10) {
  722. (stream === 1 ? Module["print"] : Module["printErr"])(UTF8ArrayToString(buffer, 0));
  723. buffer.length = 0
  724. } else {
  725. buffer.push(curr)
  726. }
  727. })
  728. }
  729. for(var i = 0; i < iovcnt; i++) {
  730. var ptr = HEAP32[iov + i * 8 >> 2];
  731. var len = HEAP32[iov + (i * 8 + 4) >> 2];
  732. for(var j = 0; j < len; j++) {
  733. ___syscall146.printChar(stream, HEAPU8[ptr + j])
  734. }
  735. ret += len
  736. }
  737. return ret
  738. } catch(e) {
  739. if(typeof FS === "undefined" || !(e instanceof FS.ErrnoError)) abort(e);
  740. return -e.errno
  741. }
  742. }
  743. function ___syscall54(which, varargs) {
  744. SYSCALLS.varargs = varargs;
  745. try {
  746. return 0
  747. } catch(e) {
  748. if(typeof FS === "undefined" || !(e instanceof FS.ErrnoError)) abort(e);
  749. return -e.errno
  750. }
  751. }
  752. function ___syscall6(which, varargs) {
  753. SYSCALLS.varargs = varargs;
  754. try {
  755. var stream = SYSCALLS.getStreamFromFD();
  756. FS.close(stream);
  757. return 0
  758. } catch(e) {
  759. if(typeof FS === "undefined" || !(e instanceof FS.ErrnoError)) abort(e);
  760. return -e.errno
  761. }
  762. }
  763. function _broadwayOnHeadersDecoded() {
  764. par_broadwayOnHeadersDecoded()
  765. }
  766. Module["_broadwayOnHeadersDecoded"] = _broadwayOnHeadersDecoded;
  767. function _broadwayOnPictureDecoded($buffer, width, height) {
  768. par_broadwayOnPictureDecoded($buffer, width, height)
  769. }
  770. Module["_broadwayOnPictureDecoded"] = _broadwayOnPictureDecoded;
  771. function _emscripten_memcpy_big(dest, src, num) {
  772. HEAPU8.set(HEAPU8.subarray(src, src + num), dest);
  773. return dest
  774. }
  775. function ___setErrNo(value) {
  776. if(Module["___errno_location"]) HEAP32[Module["___errno_location"]() >> 2] = value;
  777. return value
  778. }
  779. DYNAMICTOP_PTR = staticAlloc(4);
  780. STACK_BASE = STACKTOP = alignMemory(STATICTOP);
  781. STACK_MAX = STACK_BASE + TOTAL_STACK;
  782. DYNAMIC_BASE = alignMemory(STACK_MAX);
  783. HEAP32[DYNAMICTOP_PTR >> 2] = DYNAMIC_BASE;
  784. staticSealed = true;
  785. Module["wasmTableSize"] = 10;
  786. Module["wasmMaxTableSize"] = 10;
  787. Module.asmGlobalArg = {};
  788. Module.asmLibraryArg = {
  789. "abort": abort,
  790. "enlargeMemory": enlargeMemory,
  791. "getTotalMemory": getTotalMemory,
  792. "abortOnCannotGrowMemory": abortOnCannotGrowMemory,
  793. "___setErrNo": ___setErrNo,
  794. "___syscall140": ___syscall140,
  795. "___syscall146": ___syscall146,
  796. "___syscall54": ___syscall54,
  797. "___syscall6": ___syscall6,
  798. "_broadwayOnHeadersDecoded": _broadwayOnHeadersDecoded,
  799. "_broadwayOnPictureDecoded": _broadwayOnPictureDecoded,
  800. "_emscripten_memcpy_big": _emscripten_memcpy_big,
  801. "DYNAMICTOP_PTR": DYNAMICTOP_PTR,
  802. "STACKTOP": STACKTOP
  803. };
  804. var asm = Module["asm"](Module.asmGlobalArg, Module.asmLibraryArg, buffer);
  805. Module["asm"] = asm;
  806. var _broadwayCreateStream = Module["_broadwayCreateStream"] = (function() {
  807. return Module["asm"]["_broadwayCreateStream"].apply(null, arguments)
  808. });
  809. var _broadwayExit = Module["_broadwayExit"] = (function() {
  810. return Module["asm"]["_broadwayExit"].apply(null, arguments)
  811. });
  812. var _broadwayGetMajorVersion = Module["_broadwayGetMajorVersion"] = (function() {
  813. return Module["asm"]["_broadwayGetMajorVersion"].apply(null, arguments)
  814. });
  815. var _broadwayGetMinorVersion = Module["_broadwayGetMinorVersion"] = (function() {
  816. return Module["asm"]["_broadwayGetMinorVersion"].apply(null, arguments)
  817. });
  818. var _broadwayInit = Module["_broadwayInit"] = (function() {
  819. return Module["asm"]["_broadwayInit"].apply(null, arguments)
  820. });
  821. var _broadwayPlayStream = Module["_broadwayPlayStream"] = (function() {
  822. return Module["asm"]["_broadwayPlayStream"].apply(null, arguments)
  823. });
  824. Module["asm"] = asm;
  825. function ExitStatus(status) {
  826. this.name = "ExitStatus";
  827. this.message = "Program terminated with exit(" + status + ")";
  828. this.status = status
  829. }
  830. ExitStatus.prototype = new Error;
  831. ExitStatus.prototype.constructor = ExitStatus;
  832. var initialStackTop;
  833. dependenciesFulfilled = function runCaller() {
  834. if(!Module["calledRun"]) run();
  835. if(!Module["calledRun"]) dependenciesFulfilled = runCaller
  836. };
  837. function run(args) {
  838. args = args || Module["arguments"];
  839. if(runDependencies > 0) {
  840. return
  841. }
  842. preRun();
  843. if(runDependencies > 0) return;
  844. if(Module["calledRun"]) return;
  845. function doRun() {
  846. if(Module["calledRun"]) return;
  847. Module["calledRun"] = true;
  848. if(ABORT) return;
  849. ensureInitRuntime();
  850. preMain();
  851. if(Module["onRuntimeInitialized"]) Module["onRuntimeInitialized"]();
  852. postRun()
  853. }
  854. if(Module["setStatus"]) {
  855. Module["setStatus"]("Running...");
  856. setTimeout((function() {
  857. setTimeout((function() {
  858. Module["setStatus"]("")
  859. }), 1);
  860. doRun()
  861. }), 1)
  862. } else {
  863. doRun()
  864. }
  865. }
  866. Module["run"] = run;
  867. function exit(status, implicit) {
  868. if(implicit && Module["noExitRuntime"] && status === 0) {
  869. return
  870. }
  871. if(Module["noExitRuntime"]) {} else {
  872. ABORT = true;
  873. EXITSTATUS = status;
  874. STACKTOP = initialStackTop;
  875. exitRuntime();
  876. if(Module["onExit"]) Module["onExit"](status)
  877. }
  878. if(ENVIRONMENT_IS_NODE) {
  879. process["exit"](status)
  880. }
  881. Module["quit"](status, new ExitStatus(status))
  882. }
  883. Module["exit"] = exit;
  884. function abort(what) {
  885. if(Module["onAbort"]) {
  886. Module["onAbort"](what)
  887. }
  888. if(what !== undefined) {
  889. Module.print(what);
  890. Module.printErr(what);
  891. what = JSON.stringify(what)
  892. } else {
  893. what = ""
  894. }
  895. ABORT = true;
  896. EXITSTATUS = 1;
  897. throw "abort(" + what + "). Build with -s ASSERTIONS=1 for more info."
  898. }
  899. Module["abort"] = abort;
  900. if(Module["preInit"]) {
  901. if(typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]];
  902. while(Module["preInit"].length > 0) {
  903. Module["preInit"].pop()()
  904. }
  905. }
  906. Module["noExitRuntime"] = true;
  907. run()
  908. // return Module;
  909. //})();
  910. var resultModule;
  911. if(typeof global !== "undefined") {
  912. if(global.Module) {
  913. resultModule = global.Module;
  914. };
  915. };
  916. if(typeof Module != "undefined") {
  917. resultModule = Module;
  918. };
  919. resultModule._broadwayOnHeadersDecoded = par_broadwayOnHeadersDecoded;
  920. resultModule._broadwayOnPictureDecoded = par_broadwayOnPictureDecoded;
  921. var moduleIsReady = false;
  922. var cbFun;
  923. var moduleReady = function() {
  924. moduleIsReady = true;
  925. if(cbFun) {
  926. cbFun(resultModule);
  927. }
  928. };
  929. resultModule.onRuntimeInitialized = function() {
  930. moduleReady(resultModule);
  931. };
  932. return function(callback) {
  933. if(moduleIsReady) {
  934. callback(resultModule);
  935. } else {
  936. cbFun = callback;
  937. };
  938. };
  939. };
  940. return(function() {
  941. "use strict";
  942. var nowValue = function() {
  943. return(new Date()).getTime();
  944. };
  945. if(typeof performance != "undefined") {
  946. if(performance.now) {
  947. nowValue = function() {
  948. return performance.now();
  949. };
  950. };
  951. };
  952. var Decoder = function(parOptions) {
  953. this.options = parOptions || {};
  954. this.now = nowValue;
  955. var asmInstance;
  956. var fakeWindow = {};
  957. var toU8Array;
  958. var toU32Array;
  959. var onPicFun = function($buffer, width, height) {
  960. var buffer = this.pictureBuffers[$buffer];
  961. if(!buffer) {
  962. buffer = this.pictureBuffers[$buffer] = toU8Array($buffer, (width * height * 3) / 2);
  963. };
  964. var infos;
  965. var doInfo = false;
  966. if(this.infoAr.length) {
  967. doInfo = true;
  968. infos = this.infoAr;
  969. };
  970. this.infoAr = [];
  971. if(this.options.rgb) {
  972. if(!asmInstance) {
  973. asmInstance = getAsm(width, height);
  974. };
  975. asmInstance.inp.set(buffer);
  976. asmInstance.doit();
  977. var copyU8 = new Uint8Array(asmInstance.outSize);
  978. copyU8.set(asmInstance.out);
  979. if(doInfo) {
  980. infos[0].finishDecoding = nowValue();
  981. };
  982. this.onPictureDecoded(copyU8, width, height, infos);
  983. return;
  984. };
  985. if(doInfo) {
  986. infos[0].finishDecoding = nowValue();
  987. };
  988. this.onPictureDecoded(buffer, width, height, infos);
  989. }.bind(this);
  990. var ignore = false;
  991. if(this.options.sliceMode) {
  992. onPicFun = function($buffer, width, height, $sliceInfo) {
  993. if(ignore) {
  994. return;
  995. };
  996. var buffer = this.pictureBuffers[$buffer];
  997. if(!buffer) {
  998. buffer = this.pictureBuffers[$buffer] = toU8Array($buffer, (width * height * 3) / 2);
  999. };
  1000. var sliceInfo = this.pictureBuffers[$sliceInfo];
  1001. if(!sliceInfo) {
  1002. sliceInfo = this.pictureBuffers[$sliceInfo] = toU32Array($sliceInfo, 18);
  1003. };
  1004. var infos;
  1005. var doInfo = false;
  1006. if(this.infoAr.length) {
  1007. doInfo = true;
  1008. infos = this.infoAr;
  1009. };
  1010. this.infoAr = [];
  1011. /*if (this.options.rgb){
  1012. no rgb in slice mode
  1013. };*/
  1014. infos[0].finishDecoding = nowValue();
  1015. var sliceInfoAr = [];
  1016. for(var i = 0; i < 20; ++i) {
  1017. sliceInfoAr.push(sliceInfo[i]);
  1018. };
  1019. infos[0].sliceInfoAr = sliceInfoAr;
  1020. this.onPictureDecoded(buffer, width, height, infos);
  1021. }.bind(this);
  1022. };
  1023. var ModuleCallback = getModule.apply(fakeWindow, [function() {}, onPicFun]);
  1024. var MAX_STREAM_BUFFER_LENGTH = 1024 * 1024;
  1025. var instance = this;
  1026. this.onPictureDecoded = function(buffer, width, height, infos) {
  1027. };
  1028. this.onDecoderReady = function() {};
  1029. var bufferedCalls = [];
  1030. this.decode = function decode(typedAr, parInfo, copyDoneFun) {
  1031. bufferedCalls.push([typedAr, parInfo, copyDoneFun]);
  1032. };
  1033. ModuleCallback(function(Module) {
  1034. var HEAP8 = Module.HEAP8;
  1035. var HEAPU8 = Module.HEAPU8;
  1036. var HEAP16 = Module.HEAP16;
  1037. var HEAP32 = Module.HEAP32;
  1038. // from old constructor
  1039. Module._broadwayInit();
  1040. /**
  1041. * Creates a typed array from a HEAP8 pointer.
  1042. */
  1043. toU8Array = function(ptr, length) {
  1044. return HEAPU8.subarray(ptr, ptr + length);
  1045. };
  1046. toU32Array = function(ptr, length) {
  1047. //var tmp = HEAPU8.subarray(ptr, ptr + (length * 4));
  1048. return new Uint32Array(HEAPU8.buffer, ptr, length);
  1049. };
  1050. instance.streamBuffer = toU8Array(Module._broadwayCreateStream(MAX_STREAM_BUFFER_LENGTH), MAX_STREAM_BUFFER_LENGTH);
  1051. instance.pictureBuffers = {};
  1052. // collect extra infos that are provided with the nal units
  1053. instance.infoAr = [];
  1054. /**
  1055. * Decodes a stream buffer. This may be one single (unframed) NAL unit without the
  1056. * start code, or a sequence of NAL units with framing start code prefixes. This
  1057. * function overwrites stream buffer allocated by the codec with the supplied buffer.
  1058. */
  1059. var sliceNum = 0;
  1060. if(instance.options.sliceMode) {
  1061. sliceNum = instance.options.sliceNum;
  1062. instance.decode = function decode(typedAr, parInfo, copyDoneFun) {
  1063. instance.infoAr.push(parInfo);
  1064. parInfo.startDecoding = nowValue();
  1065. var nals = parInfo.nals;
  1066. var i;
  1067. if(!nals) {
  1068. nals = [];
  1069. parInfo.nals = nals;
  1070. var l = typedAr.length;
  1071. var foundSomething = false;
  1072. var lastFound = 0;
  1073. var lastStart = 0;
  1074. for(i = 0; i < l; ++i) {
  1075. if(typedAr[i] === 1) {
  1076. if(
  1077. typedAr[i - 1] === 0 &&
  1078. typedAr[i - 2] === 0
  1079. ) {
  1080. var startPos = i - 2;
  1081. if(typedAr[i - 3] === 0) {
  1082. startPos = i - 3;
  1083. };
  1084. // its a nal;
  1085. if(foundSomething) {
  1086. nals.push({
  1087. offset: lastFound,
  1088. end: startPos,
  1089. type: typedAr[lastStart] & 31
  1090. });
  1091. };
  1092. lastFound = startPos;
  1093. lastStart = startPos + 3;
  1094. if(typedAr[i - 3] === 0) {
  1095. lastStart = startPos + 4;
  1096. };
  1097. foundSomething = true;
  1098. };
  1099. };
  1100. };
  1101. if(foundSomething) {
  1102. nals.push({
  1103. offset: lastFound,
  1104. end: i,
  1105. type: typedAr[lastStart] & 31
  1106. });
  1107. };
  1108. };
  1109. var currentSlice = 0;
  1110. var playAr;
  1111. var offset = 0;
  1112. for(i = 0; i < nals.length; ++i) {
  1113. if(nals[i].type === 1 || nals[i].type === 5) {
  1114. if(currentSlice === sliceNum) {
  1115. playAr = typedAr.subarray(nals[i].offset, nals[i].end);
  1116. instance.streamBuffer[offset] = 0;
  1117. offset += 1;
  1118. instance.streamBuffer.set(playAr, offset);
  1119. offset += playAr.length;
  1120. };
  1121. currentSlice += 1;
  1122. } else {
  1123. playAr = typedAr.subarray(nals[i].offset, nals[i].end);
  1124. instance.streamBuffer[offset] = 0;
  1125. offset += 1;
  1126. instance.streamBuffer.set(playAr, offset);
  1127. offset += playAr.length;
  1128. Module._broadwayPlayStream(offset);
  1129. offset = 0;
  1130. };
  1131. };
  1132. copyDoneFun();
  1133. Module._broadwayPlayStream(offset);
  1134. };
  1135. } else {
  1136. instance.decode = function decode(typedAr, parInfo) {
  1137. // console.info("Decoding: " + buffer.length);
  1138. // collect infos
  1139. if(parInfo) {
  1140. instance.infoAr.push(parInfo);
  1141. parInfo.startDecoding = nowValue();
  1142. };
  1143. instance.streamBuffer.set(typedAr);
  1144. Module._broadwayPlayStream(typedAr.length);
  1145. };
  1146. };
  1147. if(bufferedCalls.length) {
  1148. var bi = 0;
  1149. for(bi = 0; bi < bufferedCalls.length; ++bi) {
  1150. instance.decode(bufferedCalls[bi][0], bufferedCalls[bi][1], bufferedCalls[bi][2]);
  1151. };
  1152. bufferedCalls = [];
  1153. };
  1154. instance.onDecoderReady(instance);
  1155. });
  1156. };
  1157. Decoder.prototype = {
  1158. };
  1159. /*
  1160. asm.js implementation of a yuv to rgb convertor
  1161. provided by @soliton4
  1162. based on
  1163. http://www.wordsaretoys.com/2013/10/18/making-yuv-conversion-a-little-faster/
  1164. */
  1165. // factory to create asm.js yuv -> rgb convertor for a given resolution
  1166. var asmInstances = {};
  1167. var getAsm = function(parWidth, parHeight) {
  1168. var idStr = "" + parWidth + "x" + parHeight;
  1169. if(asmInstances[idStr]) {
  1170. return asmInstances[idStr];
  1171. };
  1172. var lumaSize = parWidth * parHeight;
  1173. var chromaSize = (lumaSize | 0) >> 2;
  1174. var inpSize = lumaSize + chromaSize + chromaSize;
  1175. var outSize = parWidth * parHeight * 4;
  1176. var cacheSize = Math.pow(2, 24) * 4;
  1177. var size = inpSize + outSize + cacheSize;
  1178. var chunkSize = Math.pow(2, 24);
  1179. var heapSize = chunkSize;
  1180. while(heapSize < size) {
  1181. heapSize += chunkSize;
  1182. };
  1183. var heap = new ArrayBuffer(heapSize);
  1184. var res = asmFactory(global, {}, heap);
  1185. res.init(parWidth, parHeight);
  1186. asmInstances[idStr] = res;
  1187. res.heap = heap;
  1188. res.out = new Uint8Array(heap, 0, outSize);
  1189. res.inp = new Uint8Array(heap, outSize, inpSize);
  1190. res.outSize = outSize;
  1191. return res;
  1192. };
  1193. function asmFactory(stdlib, foreign, heap) {
  1194. "use asm";
  1195. var imul = stdlib.Math.imul;
  1196. var min = stdlib.Math.min;
  1197. var max = stdlib.Math.max;
  1198. var pow = stdlib.Math.pow;
  1199. var out = new stdlib.Uint8Array(heap);
  1200. var out32 = new stdlib.Uint32Array(heap);
  1201. var inp = new stdlib.Uint8Array(heap);
  1202. var mem = new stdlib.Uint8Array(heap);
  1203. var mem32 = new stdlib.Uint32Array(heap);
  1204. // for double algo
  1205. /*var vt = 1.370705;
  1206. var gt = 0.698001;
  1207. var gt2 = 0.337633;
  1208. var bt = 1.732446;*/
  1209. var width = 0;
  1210. var height = 0;
  1211. var lumaSize = 0;
  1212. var chromaSize = 0;
  1213. var inpSize = 0;
  1214. var outSize = 0;
  1215. var inpStart = 0;
  1216. var outStart = 0;
  1217. var widthFour = 0;
  1218. var cacheStart = 0;
  1219. function init(parWidth, parHeight) {
  1220. parWidth = parWidth | 0;
  1221. parHeight = parHeight | 0;
  1222. var i = 0;
  1223. var s = 0;
  1224. width = parWidth;
  1225. widthFour = imul(parWidth, 4) | 0;
  1226. height = parHeight;
  1227. lumaSize = imul(width | 0, height | 0) | 0;
  1228. chromaSize = (lumaSize | 0) >> 2;
  1229. outSize = imul(imul(width, height) | 0, 4) | 0;
  1230. inpSize = ((lumaSize + chromaSize) | 0 + chromaSize) | 0;
  1231. outStart = 0;
  1232. inpStart = (outStart + outSize) | 0;
  1233. cacheStart = (inpStart + inpSize) | 0;
  1234. // initializing memory (to be on the safe side)
  1235. s = ~~(+pow(+2, +24));
  1236. s = imul(s, 4) | 0;
  1237. for(i = 0 | 0;
  1238. ((i | 0) < (s | 0)) | 0; i = (i + 4) | 0) {
  1239. mem32[((cacheStart + i) | 0) >> 2] = 0;
  1240. };
  1241. };
  1242. function doit() {
  1243. var ystart = 0;
  1244. var ustart = 0;
  1245. var vstart = 0;
  1246. var y = 0;
  1247. var yn = 0;
  1248. var u = 0;
  1249. var v = 0;
  1250. var o = 0;
  1251. var line = 0;
  1252. var col = 0;
  1253. var usave = 0;
  1254. var vsave = 0;
  1255. var ostart = 0;
  1256. var cacheAdr = 0;
  1257. ostart = outStart | 0;
  1258. ystart = inpStart | 0;
  1259. ustart = (ystart + lumaSize | 0) | 0;
  1260. vstart = (ustart + chromaSize) | 0;
  1261. for(line = 0;
  1262. (line | 0) < (height | 0); line = (line + 2) | 0) {
  1263. usave = ustart;
  1264. vsave = vstart;
  1265. for(col = 0;
  1266. (col | 0) < (width | 0); col = (col + 2) | 0) {
  1267. y = inp[ystart >> 0] | 0;
  1268. yn = inp[((ystart + width) | 0) >> 0] | 0;
  1269. u = inp[ustart >> 0] | 0;
  1270. v = inp[vstart >> 0] | 0;
  1271. cacheAdr = (((((y << 16) | 0) + ((u << 8) | 0)) | 0) + v) | 0;
  1272. o = mem32[((cacheStart + cacheAdr) | 0) >> 2] | 0;
  1273. if(o) {} else {
  1274. o = yuv2rgbcalc(y, u, v) | 0;
  1275. mem32[((cacheStart + cacheAdr) | 0) >> 2] = o | 0;
  1276. };
  1277. mem32[ostart >> 2] = o;
  1278. cacheAdr = (((((yn << 16) | 0) + ((u << 8) | 0)) | 0) + v) | 0;
  1279. o = mem32[((cacheStart + cacheAdr) | 0) >> 2] | 0;
  1280. if(o) {} else {
  1281. o = yuv2rgbcalc(yn, u, v) | 0;
  1282. mem32[((cacheStart + cacheAdr) | 0) >> 2] = o | 0;
  1283. };
  1284. mem32[((ostart + widthFour) | 0) >> 2] = o;
  1285. //yuv2rgb5(y, u, v, ostart);
  1286. //yuv2rgb5(yn, u, v, (ostart + widthFour)|0);
  1287. ostart = (ostart + 4) | 0;
  1288. // next step only for y. u and v stay the same
  1289. ystart = (ystart + 1) | 0;
  1290. y = inp[ystart >> 0] | 0;
  1291. yn = inp[((ystart + width) | 0) >> 0] | 0;
  1292. //yuv2rgb5(y, u, v, ostart);
  1293. cacheAdr = (((((y << 16) | 0) + ((u << 8) | 0)) | 0) + v) | 0;
  1294. o = mem32[((cacheStart + cacheAdr) | 0) >> 2] | 0;
  1295. if(o) {} else {
  1296. o = yuv2rgbcalc(y, u, v) | 0;
  1297. mem32[((cacheStart + cacheAdr) | 0) >> 2] = o | 0;
  1298. };
  1299. mem32[ostart >> 2] = o;
  1300. //yuv2rgb5(yn, u, v, (ostart + widthFour)|0);
  1301. cacheAdr = (((((yn << 16) | 0) + ((u << 8) | 0)) | 0) + v) | 0;
  1302. o = mem32[((cacheStart + cacheAdr) | 0) >> 2] | 0;
  1303. if(o) {} else {
  1304. o = yuv2rgbcalc(yn, u, v) | 0;
  1305. mem32[((cacheStart + cacheAdr) | 0) >> 2] = o | 0;
  1306. };
  1307. mem32[((ostart + widthFour) | 0) >> 2] = o;
  1308. ostart = (ostart + 4) | 0;
  1309. //all positions inc 1
  1310. ystart = (ystart + 1) | 0;
  1311. ustart = (ustart + 1) | 0;
  1312. vstart = (vstart + 1) | 0;
  1313. };
  1314. ostart = (ostart + widthFour) | 0;
  1315. ystart = (ystart + width) | 0;
  1316. };
  1317. };
  1318. function yuv2rgbcalc(y, u, v) {
  1319. y = y | 0;
  1320. u = u | 0;
  1321. v = v | 0;
  1322. var r = 0;
  1323. var g = 0;
  1324. var b = 0;
  1325. var o = 0;
  1326. var a0 = 0;
  1327. var a1 = 0;
  1328. var a2 = 0;
  1329. var a3 = 0;
  1330. var a4 = 0;
  1331. a0 = imul(1192, (y - 16) | 0) | 0;
  1332. a1 = imul(1634, (v - 128) | 0) | 0;
  1333. a2 = imul(832, (v - 128) | 0) | 0;
  1334. a3 = imul(400, (u - 128) | 0) | 0;
  1335. a4 = imul(2066, (u - 128) | 0) | 0;
  1336. r = (((a0 + a1) | 0) >> 10) | 0;
  1337. g = (((((a0 - a2) | 0) - a3) | 0) >> 10) | 0;
  1338. b = (((a0 + a4) | 0) >> 10) | 0;
  1339. if((((r & 255) | 0) != (r | 0)) | 0) {
  1340. r = min(255, max(0, r | 0) | 0) | 0;
  1341. };
  1342. if((((g & 255) | 0) != (g | 0)) | 0) {
  1343. g = min(255, max(0, g | 0) | 0) | 0;
  1344. };
  1345. if((((b & 255) | 0) != (b | 0)) | 0) {
  1346. b = min(255, max(0, b | 0) | 0) | 0;
  1347. };
  1348. o = 255;
  1349. o = (o << 8) | 0;
  1350. o = (o + b) | 0;
  1351. o = (o << 8) | 0;
  1352. o = (o + g) | 0;
  1353. o = (o << 8) | 0;
  1354. o = (o + r) | 0;
  1355. return o | 0;
  1356. };
  1357. return {
  1358. init: init,
  1359. doit: doit
  1360. };
  1361. };
  1362. /*
  1363. potential worker initialization
  1364. */
  1365. if(typeof self != "undefined") {
  1366. var isWorker = false;
  1367. var decoder;
  1368. var reuseMemory = false;
  1369. var sliceMode = false;
  1370. var sliceNum = 0;
  1371. var sliceCnt = 0;
  1372. var lastSliceNum = 0;
  1373. var sliceInfoAr;
  1374. var lastBuf;
  1375. var awaiting = 0;
  1376. var pile = [];
  1377. var startDecoding;
  1378. var finishDecoding;
  1379. var timeDecoding;
  1380. var memAr = [];
  1381. var getMem = function(length) {
  1382. if(memAr.length) {
  1383. var u = memAr.shift();
  1384. while(u && u.byteLength !== length) {
  1385. u = memAr.shift();
  1386. };
  1387. if(u) {
  1388. return u;
  1389. };
  1390. };
  1391. return new ArrayBuffer(length);
  1392. };
  1393. var copySlice = function(source, target, infoAr, width, height) {
  1394. var length = width * height;
  1395. var length4 = length / 4
  1396. var plane2 = length;
  1397. var plane3 = length + length4;
  1398. var copy16 = function(parBegin, parEnd) {
  1399. var i = 0;
  1400. for(i = 0; i < 16; ++i) {
  1401. var begin = parBegin + (width * i);
  1402. var end = parEnd + (width * i)
  1403. target.set(source.subarray(begin, end), begin);
  1404. };
  1405. };
  1406. var copy8 = function(parBegin, parEnd) {
  1407. var i = 0;
  1408. for(i = 0; i < 8; ++i) {
  1409. var begin = parBegin + ((width / 2) * i);
  1410. var end = parEnd + ((width / 2) * i)
  1411. target.set(source.subarray(begin, end), begin);
  1412. };
  1413. };
  1414. var copyChunk = function(begin, end) {
  1415. target.set(source.subarray(begin, end), begin);
  1416. };
  1417. var begin = infoAr[0];
  1418. var end = infoAr[1];
  1419. if(end > 0) {
  1420. copy16(begin, end);
  1421. copy8(infoAr[2], infoAr[3]);
  1422. copy8(infoAr[4], infoAr[5]);
  1423. };
  1424. begin = infoAr[6];
  1425. end = infoAr[7];
  1426. if(end > 0) {
  1427. copy16(begin, end);
  1428. copy8(infoAr[8], infoAr[9]);
  1429. copy8(infoAr[10], infoAr[11]);
  1430. };
  1431. begin = infoAr[12];
  1432. end = infoAr[15];
  1433. if(end > 0) {
  1434. copyChunk(begin, end);
  1435. copyChunk(infoAr[13], infoAr[16]);
  1436. copyChunk(infoAr[14], infoAr[17]);
  1437. };
  1438. };
  1439. var sliceMsgFun = function() {};
  1440. var setSliceCnt = function(parSliceCnt) {
  1441. sliceCnt = parSliceCnt;
  1442. lastSliceNum = sliceCnt - 1;
  1443. };
  1444. self.addEventListener('message', function(e) {
  1445. if(isWorker) {
  1446. if(reuseMemory) {
  1447. if(e.data.reuse) {
  1448. memAr.push(e.data.reuse);
  1449. };
  1450. };
  1451. if(e.data.buf) {
  1452. if(sliceMode && awaiting !== 0) {
  1453. pile.push(e.data);
  1454. } else {
  1455. decoder.decode(
  1456. new Uint8Array(e.data.buf, e.data.offset || 0, e.data.length),
  1457. e.data.info,
  1458. function() {
  1459. if(sliceMode && sliceNum !== lastSliceNum) {
  1460. postMessage(e.data, [e.data.buf]);
  1461. };
  1462. }
  1463. );
  1464. };
  1465. return;
  1466. };
  1467. if(e.data.slice) {
  1468. // update ref pic
  1469. var copyStart = nowValue();
  1470. copySlice(new Uint8Array(e.data.slice), lastBuf, e.data.infos[0].sliceInfoAr, e.data.width, e.data.height);
  1471. // is it the one? then we need to update it
  1472. if(e.data.theOne) {
  1473. copySlice(lastBuf, new Uint8Array(e.data.slice), sliceInfoAr, e.data.width, e.data.height);
  1474. if(timeDecoding > e.data.infos[0].timeDecoding) {
  1475. e.data.infos[0].timeDecoding = timeDecoding;
  1476. };
  1477. e.data.infos[0].timeCopy += (nowValue() - copyStart);
  1478. };
  1479. // move on
  1480. postMessage(e.data, [e.data.slice]);
  1481. // next frame in the pipe?
  1482. awaiting -= 1;
  1483. if(awaiting === 0 && pile.length) {
  1484. var data = pile.shift();
  1485. decoder.decode(
  1486. new Uint8Array(data.buf, data.offset || 0, data.length),
  1487. data.info,
  1488. function() {
  1489. if(sliceMode && sliceNum !== lastSliceNum) {
  1490. postMessage(data, [data.buf]);
  1491. };
  1492. }
  1493. );
  1494. };
  1495. return;
  1496. };
  1497. if(e.data.setSliceCnt) {
  1498. setSliceCnt(e.data.sliceCnt);
  1499. return;
  1500. };
  1501. } else {
  1502. if(e.data && e.data.type === "Broadway.js - Worker init") {
  1503. isWorker = true;
  1504. decoder = new Decoder(e.data.options);
  1505. if(e.data.options.sliceMode) {
  1506. reuseMemory = true;
  1507. sliceMode = true;
  1508. sliceNum = e.data.options.sliceNum;
  1509. setSliceCnt(e.data.options.sliceCnt);
  1510. decoder.onPictureDecoded = function(buffer, width, height, infos) {
  1511. // buffer needs to be copied because we give up ownership
  1512. var copyU8 = new Uint8Array(getMem(buffer.length));
  1513. copySlice(buffer, copyU8, infos[0].sliceInfoAr, width, height);
  1514. startDecoding = infos[0].startDecoding;
  1515. finishDecoding = infos[0].finishDecoding;
  1516. timeDecoding = finishDecoding - startDecoding;
  1517. infos[0].timeDecoding = timeDecoding;
  1518. infos[0].timeCopy = 0;
  1519. postMessage({
  1520. slice: copyU8.buffer,
  1521. sliceNum: sliceNum,
  1522. width: width,
  1523. height: height,
  1524. infos: infos
  1525. }, [copyU8.buffer]); // 2nd parameter is used to indicate transfer of ownership
  1526. awaiting = sliceCnt - 1;
  1527. lastBuf = buffer;
  1528. sliceInfoAr = infos[0].sliceInfoAr;
  1529. };
  1530. } else if(e.data.options.reuseMemory) {
  1531. reuseMemory = true;
  1532. decoder.onPictureDecoded = function(buffer, width, height, infos) {
  1533. // buffer needs to be copied because we give up ownership
  1534. var copyU8 = new Uint8Array(getMem(buffer.length));
  1535. copyU8.set(buffer, 0, buffer.length);
  1536. postMessage({
  1537. buf: copyU8.buffer,
  1538. length: buffer.length,
  1539. width: width,
  1540. height: height,
  1541. infos: infos
  1542. }, [copyU8.buffer]); // 2nd parameter is used to indicate transfer of ownership
  1543. };
  1544. } else {
  1545. decoder.onPictureDecoded = function(buffer, width, height, infos) {
  1546. if(buffer) {
  1547. buffer = new Uint8Array(buffer);
  1548. };
  1549. // buffer needs to be copied because we give up ownership
  1550. var copyU8 = new Uint8Array(buffer.length);
  1551. copyU8.set(buffer, 0, buffer.length);
  1552. postMessage({
  1553. buf: copyU8.buffer,
  1554. length: buffer.length,
  1555. width: width,
  1556. height: height,
  1557. infos: infos
  1558. }, [copyU8.buffer]); // 2nd parameter is used to indicate transfer of ownership
  1559. };
  1560. };
  1561. postMessage({
  1562. consoleLog: "broadway worker initialized"
  1563. });
  1564. };
  1565. };
  1566. }, false);
  1567. };
  1568. Decoder.nowValue = nowValue;
  1569. return Decoder;
  1570. })();
  1571. }));