!function(e){"function"==typeof define&&define.amd?define(["crypto-js"],e):e()}((function(){"use strict";var e,t=(e="undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("decoder-pro-audio.js",document.baseURI).href,async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};var r,i,s;(s=t).ready=new Promise(((e,t)=>{r=e,i=t})),(s=void 0!==s?s:{}).locateFile=function(e){return"decoder-pro-audio.wasm"==e&&"undefined"!=typeof JESSIBUCA_PRO_AUDIO_WASM_URL&&""!=JESSIBUCA_PRO_AUDIO_WASM_URL?JESSIBUCA_PRO_AUDIO_WASM_URL:e};var n,a,o,d=Object.assign({},s),l="./this.program",u="object"==typeof window,c="function"==typeof importScripts,h="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,f="";function p(e){return s.locateFile?s.locateFile(e,f):f+e}if(h){const{createRequire:e}=await import("module");var m=e("undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("decoder-pro-audio.js",document.baseURI).href),_=m("fs"),g=m("path");f=c?g.dirname(f)+"/":m("url").fileURLToPath(new URL("./","undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("decoder-pro-audio.js",document.baseURI).href)),n=(e,t)=>(e=J(e)?new URL(e):g.normalize(e),_.readFileSync(e,t?void 0:"utf8")),o=e=>{var t=n(e,!0);return t.buffer||(t=new Uint8Array(t)),t},a=function(e,t,r){let i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];e=J(e)?new URL(e):g.normalize(e),_.readFile(e,i?void 0:"utf8",((e,s)=>{e?r(e):t(i?s.buffer:s)}))},!s.thisProgram&&process.argv.length>1&&(l=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),s.inspect=()=>"[Emscripten Module object]"}else(u||c)&&(c?f=self.location.href:"undefined"!=typeof document&&document.currentScript&&(f=document.currentScript.src),e&&(f=e),f=0!==f.indexOf("blob:")?f.substr(0,f.replace(/[?#].*/,"").lastIndexOf("/")+1):"",n=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText},c&&(o=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),a=(e,t,r)=>{var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=()=>{200==i.status||0==i.status&&i.response?t(i.response):r()},i.onerror=r,i.send(null)});var y,b,v=s.print||console.log.bind(console),w=s.printErr||console.error.bind(console);Object.assign(s,d),d=null,s.arguments&&s.arguments,s.thisProgram&&(l=s.thisProgram),s.quit&&s.quit,s.wasmBinary&&(y=s.wasmBinary),s.noExitRuntime,"object"!=typeof WebAssembly&&j("no native wasm support detected");var S,E,A,U,x,B,T,C,k=!1;function D(e,t){e||j(t)}function I(){var e=b.buffer;s.HEAP8=S=new Int8Array(e),s.HEAP16=A=new Int16Array(e),s.HEAPU8=E=new Uint8Array(e),s.HEAPU16=U=new Uint16Array(e),s.HEAP32=x=new Int32Array(e),s.HEAPU32=B=new Uint32Array(e),s.HEAPF32=T=new Float32Array(e),s.HEAPF64=C=new Float64Array(e)}var F=[],P=[],L=[];function M(){if(s.preRun)for("function"==typeof s.preRun&&(s.preRun=[s.preRun]);s.preRun.length;)N(s.preRun.shift());se(F)}function R(){s.noFSInit||Ce.init.initialized||Ce.init(),Ce.ignorePermissions=!1,se(P)}function z(){if(s.postRun)for("function"==typeof s.postRun&&(s.postRun=[s.postRun]);s.postRun.length;)G(s.postRun.shift());se(L)}function N(e){F.unshift(e)}function O(e){P.unshift(e)}function G(e){L.unshift(e)}var $=0,H=null;function V(e){$++,s.monitorRunDependencies&&s.monitorRunDependencies($)}function W(e){if($--,s.monitorRunDependencies&&s.monitorRunDependencies($),0==$&&H){var t=H;H=null,t()}}function j(e){s.onAbort&&s.onAbort(e),w(e="Aborted("+e+")"),k=!0,e+=". Build with -sASSERTIONS for more info.";var t=new WebAssembly.RuntimeError(e);throw i(t),t}var q,Y,K,X="data:application/octet-stream;base64,";function Z(e){return e.startsWith(X)}function J(e){return e.startsWith("file://")}function Q(e){if(e==q&&y)return new Uint8Array(y);if(o)return o(e);throw"both async and sync fetching of the wasm failed"}function ee(e){if(!y&&(u||c)){if("function"==typeof fetch&&!J(e))return fetch(e,{credentials:"same-origin"}).then((t=>{if(!t.ok)throw"failed to load wasm binary file at '"+e+"'";return t.arrayBuffer()})).catch((()=>Q(e)));if(a)return new Promise(((t,r)=>{a(e,(e=>t(new Uint8Array(e))),r)}))}return Promise.resolve().then((()=>Q(e)))}function te(e,t,r){return ee(e).then((e=>WebAssembly.instantiate(e,t))).then((e=>e)).then(r,(e=>{w(`failed to asynchronously prepare wasm: ${e}`),j(e)}))}function re(e,t,r,i){return e||"function"!=typeof WebAssembly.instantiateStreaming||Z(t)||J(t)||h||"function"!=typeof fetch?te(t,r,i):fetch(t,{credentials:"same-origin"}).then((e=>WebAssembly.instantiateStreaming(e,r).then(i,(function(e){return w(`wasm streaming compile failed: ${e}`),w("falling back to ArrayBuffer instantiation"),te(t,r,i)}))))}function ie(){var e={a:ti};function t(e,t){return ri=e.exports,b=ri.D,I(),Ft=ri.G,O(ri.E),W(),ri}if(V(),s.instantiateWasm)try{return s.instantiateWasm(e,t)}catch(e){w(`Module.instantiateWasm callback failed with error: ${e}`),i(e)}return re(y,q,e,(function(e){t(e.instance)})).catch(i),{}}s.locateFile?Z(q="decoder-pro-audio.wasm")||(q=p(q)):q=new URL("decoder-pro-audio.wasm","undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("decoder-pro-audio.js",document.baseURI).href).href;var se=e=>{for(;e.length>0;)e.shift()(s)};function ne(e){this.excPtr=e,this.ptr=e-24,this.set_type=function(e){B[this.ptr+4>>2]=e},this.get_type=function(){return B[this.ptr+4>>2]},this.set_destructor=function(e){B[this.ptr+8>>2]=e},this.get_destructor=function(){return B[this.ptr+8>>2]},this.set_caught=function(e){e=e?1:0,S[this.ptr+12>>0]=e},this.get_caught=function(){return 0!=S[this.ptr+12>>0]},this.set_rethrown=function(e){e=e?1:0,S[this.ptr+13>>0]=e},this.get_rethrown=function(){return 0!=S[this.ptr+13>>0]},this.init=function(e,t){this.set_adjusted_ptr(0),this.set_type(e),this.set_destructor(t)},this.set_adjusted_ptr=function(e){B[this.ptr+16>>2]=e},this.get_adjusted_ptr=function(){return B[this.ptr+16>>2]},this.get_exception_ptr=function(){if(di(this.get_type()))return B[this.excPtr>>2];var e=this.get_adjusted_ptr();return 0!==e?e:this.excPtr}}var ae=(e,t,r)=>{throw new ne(e).init(t,r),e},oe=e=>(x[si()>>2]=e,e),de={isAbs:e=>"/"===e.charAt(0),splitPath:e=>/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1),normalizeArray:(e,t)=>{for(var r=0,i=e.length-1;i>=0;i--){var s=e[i];"."===s?e.splice(i,1):".."===s?(e.splice(i,1),r++):r&&(e.splice(i,1),r--)}if(t)for(;r;r--)e.unshift("..");return e},normalize:e=>{var t=de.isAbs(e),r="/"===e.substr(-1);return(e=de.normalizeArray(e.split("/").filter((e=>!!e)),!t).join("/"))||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e},dirname:e=>{var t=de.splitPath(e),r=t[0],i=t[1];return r||i?(i&&(i=i.substr(0,i.length-1)),r+i):"."},basename:e=>{if("/"===e)return"/";var t=(e=(e=de.normalize(e)).replace(/\/$/,"")).lastIndexOf("/");return-1===t?e:e.substr(t+1)},join:function(){var e=Array.prototype.slice.call(arguments);return de.normalize(e.join("/"))},join2:(e,t)=>de.normalize(e+"/"+t)},le=()=>{if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues)return e=>crypto.getRandomValues(e);if(h)try{var e=m("crypto");if(e.randomFillSync)return t=>e.randomFillSync(t);var t=e.randomBytes;return e=>(e.set(t(e.byteLength)),e)}catch(e){}j("initRandomDevice")},ue=e=>(ue=le())(e),ce={resolve:function(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var i=r>=0?arguments[r]:Ce.cwd();if("string"!=typeof i)throw new TypeError("Arguments to path.resolve must be strings");if(!i)return"";e=i+"/"+e,t=de.isAbs(i)}return(t?"/":"")+(e=de.normalizeArray(e.split("/").filter((e=>!!e)),!t).join("/"))||"."},relative:(e,t)=>{function r(e){for(var t=0;t=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=ce.resolve(e).substr(1),t=ce.resolve(t).substr(1);for(var i=r(e.split("/")),s=r(t.split("/")),n=Math.min(i.length,s.length),a=n,o=0;o{for(var i=t+r,s=t;e[s]&&!(s>=i);)++s;if(s-t>16&&e.buffer&&he)return he.decode(e.subarray(t,s));for(var n="";t>10,56320|1023&l)}}else n+=String.fromCharCode((31&a)<<6|o)}else n+=String.fromCharCode(a)}return n},pe=[],me=e=>{for(var t=0,r=0;r=55296&&i<=57343?(t+=4,++r):t+=3}return t},_e=(e,t,r,i)=>{if(!(i>0))return 0;for(var s=r,n=r+i-1,a=0;a=55296&&o<=57343&&(o=65536+((1023&o)<<10)|1023&e.charCodeAt(++a)),o<=127){if(r>=n)break;t[r++]=o}else if(o<=2047){if(r+1>=n)break;t[r++]=192|o>>6,t[r++]=128|63&o}else if(o<=65535){if(r+2>=n)break;t[r++]=224|o>>12,t[r++]=128|o>>6&63,t[r++]=128|63&o}else{if(r+3>=n)break;t[r++]=240|o>>18,t[r++]=128|o>>12&63,t[r++]=128|o>>6&63,t[r++]=128|63&o}}return t[r]=0,r-s};function ge(e,t,r){var i=r>0?r:me(e)+1,s=new Array(i),n=_e(e,s,0,s.length);return t&&(s.length=n),s}var ye=()=>{if(!pe.length){var e=null;if(h){var t=Buffer.alloc(256),r=0,i=process.stdin.fd;try{r=_.readSync(i,t)}catch(e){if(!e.toString().includes("EOF"))throw e;r=0}e=r>0?t.slice(0,r).toString("utf-8"):null}else"undefined"!=typeof window&&"function"==typeof window.prompt?null!==(e=window.prompt("Input: "))&&(e+="\n"):"function"==typeof readline&&null!==(e=readline())&&(e+="\n");if(!e)return null;pe=ge(e,!0)}return pe.shift()},be={ttys:[],init(){},shutdown(){},register(e,t){be.ttys[e]={input:[],output:[],ops:t},Ce.registerDevice(e,be.stream_ops)},stream_ops:{open(e){var t=be.ttys[e.node.rdev];if(!t)throw new Ce.ErrnoError(43);e.tty=t,e.seekable=!1},close(e){e.tty.ops.fsync(e.tty)},fsync(e){e.tty.ops.fsync(e.tty)},read(e,t,r,i,s){if(!e.tty||!e.tty.ops.get_char)throw new Ce.ErrnoError(60);for(var n=0,a=0;aye(),put_char(e,t){null===t||10===t?(v(fe(e.output,0)),e.output=[]):0!=t&&e.output.push(t)},fsync(e){e.output&&e.output.length>0&&(v(fe(e.output,0)),e.output=[])},ioctl_tcgets:e=>({c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}),ioctl_tcsets:(e,t,r)=>0,ioctl_tiocgwinsz:e=>[24,80]},default_tty1_ops:{put_char(e,t){null===t||10===t?(w(fe(e.output,0)),e.output=[]):0!=t&&e.output.push(t)},fsync(e){e.output&&e.output.length>0&&(w(fe(e.output,0)),e.output=[])}}},ve=e=>{j()},we={ops_table:null,mount:e=>we.createNode(null,"/",16895,0),createNode(e,t,r,i){if(Ce.isBlkdev(r)||Ce.isFIFO(r))throw new Ce.ErrnoError(63);we.ops_table||(we.ops_table={dir:{node:{getattr:we.node_ops.getattr,setattr:we.node_ops.setattr,lookup:we.node_ops.lookup,mknod:we.node_ops.mknod,rename:we.node_ops.rename,unlink:we.node_ops.unlink,rmdir:we.node_ops.rmdir,readdir:we.node_ops.readdir,symlink:we.node_ops.symlink},stream:{llseek:we.stream_ops.llseek}},file:{node:{getattr:we.node_ops.getattr,setattr:we.node_ops.setattr},stream:{llseek:we.stream_ops.llseek,read:we.stream_ops.read,write:we.stream_ops.write,allocate:we.stream_ops.allocate,mmap:we.stream_ops.mmap,msync:we.stream_ops.msync}},link:{node:{getattr:we.node_ops.getattr,setattr:we.node_ops.setattr,readlink:we.node_ops.readlink},stream:{}},chrdev:{node:{getattr:we.node_ops.getattr,setattr:we.node_ops.setattr},stream:Ce.chrdev_stream_ops}});var s=Ce.createNode(e,t,r,i);return Ce.isDir(s.mode)?(s.node_ops=we.ops_table.dir.node,s.stream_ops=we.ops_table.dir.stream,s.contents={}):Ce.isFile(s.mode)?(s.node_ops=we.ops_table.file.node,s.stream_ops=we.ops_table.file.stream,s.usedBytes=0,s.contents=null):Ce.isLink(s.mode)?(s.node_ops=we.ops_table.link.node,s.stream_ops=we.ops_table.link.stream):Ce.isChrdev(s.mode)&&(s.node_ops=we.ops_table.chrdev.node,s.stream_ops=we.ops_table.chrdev.stream),s.timestamp=Date.now(),e&&(e.contents[t]=s,e.timestamp=s.timestamp),s},getFileDataAsTypedArray:e=>e.contents?e.contents.subarray?e.contents.subarray(0,e.usedBytes):new Uint8Array(e.contents):new Uint8Array(0),expandFileStorage(e,t){var r=e.contents?e.contents.length:0;if(!(r>=t)){t=Math.max(t,r*(r<1048576?2:1.125)>>>0),0!=r&&(t=Math.max(t,256));var i=e.contents;e.contents=new Uint8Array(t),e.usedBytes>0&&e.contents.set(i.subarray(0,e.usedBytes),0)}},resizeFileStorage(e,t){if(e.usedBytes!=t)if(0==t)e.contents=null,e.usedBytes=0;else{var r=e.contents;e.contents=new Uint8Array(t),r&&e.contents.set(r.subarray(0,Math.min(t,e.usedBytes))),e.usedBytes=t}},node_ops:{getattr(e){var t={};return t.dev=Ce.isChrdev(e.mode)?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,Ce.isDir(e.mode)?t.size=4096:Ce.isFile(e.mode)?t.size=e.usedBytes:Ce.isLink(e.mode)?t.size=e.link.length:t.size=0,t.atime=new Date(e.timestamp),t.mtime=new Date(e.timestamp),t.ctime=new Date(e.timestamp),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},setattr(e,t){void 0!==t.mode&&(e.mode=t.mode),void 0!==t.timestamp&&(e.timestamp=t.timestamp),void 0!==t.size&&we.resizeFileStorage(e,t.size)},lookup(e,t){throw Ce.genericErrors[44]},mknod:(e,t,r,i)=>we.createNode(e,t,r,i),rename(e,t,r){if(Ce.isDir(e.mode)){var i;try{i=Ce.lookupNode(t,r)}catch(e){}if(i)for(var s in i.contents)throw new Ce.ErrnoError(55)}delete e.parent.contents[e.name],e.parent.timestamp=Date.now(),e.name=r,t.contents[r]=e,t.timestamp=e.parent.timestamp,e.parent=t},unlink(e,t){delete e.contents[t],e.timestamp=Date.now()},rmdir(e,t){var r=Ce.lookupNode(e,t);for(var i in r.contents)throw new Ce.ErrnoError(55);delete e.contents[t],e.timestamp=Date.now()},readdir(e){var t=[".",".."];for(var r in e.contents)e.contents.hasOwnProperty(r)&&t.push(r);return t},symlink(e,t,r){var i=we.createNode(e,t,41471,0);return i.link=r,i},readlink(e){if(!Ce.isLink(e.mode))throw new Ce.ErrnoError(28);return e.link}},stream_ops:{read(e,t,r,i,s){var n=e.node.contents;if(s>=e.node.usedBytes)return 0;var a=Math.min(e.node.usedBytes-s,i);if(a>8&&n.subarray)t.set(n.subarray(s,s+a),r);else for(var o=0;o0||r+t(we.stream_ops.write(e,t,0,i,r,!1),0)}},Se=(e,t,r,i)=>{var s=i?"":`al ${e}`;a(e,(r=>{D(r,`Loading data file "${e}" failed (no arrayBuffer).`),t(new Uint8Array(r)),s&&W()}),(t=>{if(!r)throw`Loading data file "${e}" failed.`;r()})),s&&V()},Ee=(e,t,r,i,s,n)=>Ce.createDataFile(e,t,r,i,s,n),Ae=s.preloadPlugins||[],Ue=(e,t,r,i)=>{"undefined"!=typeof Browser&&Browser.init();var s=!1;return Ae.forEach((n=>{s||n.canHandle(t)&&(n.handle(e,t,r,i),s=!0)})),s},xe=(e,t,r,i,s,n,a,o,d,l)=>{var u=t?ce.resolve(de.join2(e,t)):e;function c(r){function c(r){l&&l(),o||Ee(e,t,r,i,s,d),n&&n(),W()}Ue(r,u,c,(()=>{a&&a(),W()}))||c(r)}V(),"string"==typeof r?Se(r,(e=>c(e)),a):c(r)},Be=e=>{var t={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[e];if(void 0===t)throw new Error(`Unknown file open mode: ${e}`);return t},Te=(e,t)=>{var r=0;return e&&(r|=365),t&&(r|=146),r},Ce={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:!1,ignorePermissions:!0,ErrnoError:null,genericErrors:{},filesystems:null,syncFSRequests:0,lookupPath(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(e=ce.resolve(e)))return{path:"",node:null};if(t=Object.assign({follow_mount:!0,recurse_count:0},t),t.recurse_count>8)throw new Ce.ErrnoError(32);for(var r=e.split("/").filter((e=>!!e)),i=Ce.root,s="/",n=0;n40)throw new Ce.ErrnoError(32)}}return{path:s,node:i}},getPath(e){for(var t;;){if(Ce.isRoot(e)){var r=e.mount.mountpoint;return t?"/"!==r[r.length-1]?`${r}/${t}`:r+t:r}t=t?`${e.name}/${t}`:e.name,e=e.parent}},hashName(e,t){for(var r=0,i=0;i>>0)%Ce.nameTable.length},hashAddNode(e){var t=Ce.hashName(e.parent.id,e.name);e.name_next=Ce.nameTable[t],Ce.nameTable[t]=e},hashRemoveNode(e){var t=Ce.hashName(e.parent.id,e.name);if(Ce.nameTable[t]===e)Ce.nameTable[t]=e.name_next;else for(var r=Ce.nameTable[t];r;){if(r.name_next===e){r.name_next=e.name_next;break}r=r.name_next}},lookupNode(e,t){var r=Ce.mayLookup(e);if(r)throw new Ce.ErrnoError(r,e);for(var i=Ce.hashName(e.id,t),s=Ce.nameTable[i];s;s=s.name_next){var n=s.name;if(s.parent.id===e.id&&n===t)return s}return Ce.lookup(e,t)},createNode(e,t,r,i){var s=new Ce.FSNode(e,t,r,i);return Ce.hashAddNode(s),s},destroyNode(e){Ce.hashRemoveNode(e)},isRoot:e=>e===e.parent,isMountpoint:e=>!!e.mounted,isFile:e=>32768==(61440&e),isDir:e=>16384==(61440&e),isLink:e=>40960==(61440&e),isChrdev:e=>8192==(61440&e),isBlkdev:e=>24576==(61440&e),isFIFO:e=>4096==(61440&e),isSocket:e=>49152==(49152&e),flagsToPermissionString(e){var t=["r","w","rw"][3&e];return 512&e&&(t+="w"),t},nodePermissions:(e,t)=>Ce.ignorePermissions||(!t.includes("r")||292&e.mode)&&(!t.includes("w")||146&e.mode)&&(!t.includes("x")||73&e.mode)?0:2,mayLookup(e){var t=Ce.nodePermissions(e,"x");return t||(e.node_ops.lookup?0:2)},mayCreate(e,t){try{return Ce.lookupNode(e,t),20}catch(e){}return Ce.nodePermissions(e,"wx")},mayDelete(e,t,r){var i;try{i=Ce.lookupNode(e,t)}catch(e){return e.errno}var s=Ce.nodePermissions(e,"wx");if(s)return s;if(r){if(!Ce.isDir(i.mode))return 54;if(Ce.isRoot(i)||Ce.getPath(i)===Ce.cwd())return 10}else if(Ce.isDir(i.mode))return 31;return 0},mayOpen:(e,t)=>e?Ce.isLink(e.mode)?32:Ce.isDir(e.mode)&&("r"!==Ce.flagsToPermissionString(t)||512&t)?31:Ce.nodePermissions(e,Ce.flagsToPermissionString(t)):44,MAX_OPEN_FDS:4096,nextfd(){for(var e=0;e<=Ce.MAX_OPEN_FDS;e++)if(!Ce.streams[e])return e;throw new Ce.ErrnoError(33)},getStreamChecked(e){var t=Ce.getStream(e);if(!t)throw new Ce.ErrnoError(8);return t},getStream:e=>Ce.streams[e],createStream(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1;return Ce.FSStream||(Ce.FSStream=function(){this.shared={}},Ce.FSStream.prototype={},Object.defineProperties(Ce.FSStream.prototype,{object:{get(){return this.node},set(e){this.node=e}},isRead:{get(){return 1!=(2097155&this.flags)}},isWrite:{get(){return 0!=(2097155&this.flags)}},isAppend:{get(){return 1024&this.flags}},flags:{get(){return this.shared.flags},set(e){this.shared.flags=e}},position:{get(){return this.shared.position},set(e){this.shared.position=e}}})),e=Object.assign(new Ce.FSStream,e),-1==t&&(t=Ce.nextfd()),e.fd=t,Ce.streams[t]=e,e},closeStream(e){Ce.streams[e]=null},chrdev_stream_ops:{open(e){var t=Ce.getDevice(e.node.rdev);e.stream_ops=t.stream_ops,e.stream_ops.open&&e.stream_ops.open(e)},llseek(){throw new Ce.ErrnoError(70)}},major:e=>e>>8,minor:e=>255&e,makedev:(e,t)=>e<<8|t,registerDevice(e,t){Ce.devices[e]={stream_ops:t}},getDevice:e=>Ce.devices[e],getMounts(e){for(var t=[],r=[e];r.length;){var i=r.pop();t.push(i),r.push.apply(r,i.mounts)}return t},syncfs(e,t){"function"==typeof e&&(t=e,e=!1),Ce.syncFSRequests++,Ce.syncFSRequests>1&&w(`warning: ${Ce.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var r=Ce.getMounts(Ce.root.mount),i=0;function s(e){return Ce.syncFSRequests--,t(e)}function n(e){if(e)return n.errored?void 0:(n.errored=!0,s(e));++i>=r.length&&s(null)}r.forEach((t=>{if(!t.type.syncfs)return n(null);t.type.syncfs(t,e,n)}))},mount(e,t,r){var i,s="/"===r,n=!r;if(s&&Ce.root)throw new Ce.ErrnoError(10);if(!s&&!n){var a=Ce.lookupPath(r,{follow_mount:!1});if(r=a.path,i=a.node,Ce.isMountpoint(i))throw new Ce.ErrnoError(10);if(!Ce.isDir(i.mode))throw new Ce.ErrnoError(54)}var o={type:e,opts:t,mountpoint:r,mounts:[]},d=e.mount(o);return d.mount=o,o.root=d,s?Ce.root=d:i&&(i.mounted=o,i.mount&&i.mount.mounts.push(o)),d},unmount(e){var t=Ce.lookupPath(e,{follow_mount:!1});if(!Ce.isMountpoint(t.node))throw new Ce.ErrnoError(28);var r=t.node,i=r.mounted,s=Ce.getMounts(i);Object.keys(Ce.nameTable).forEach((e=>{for(var t=Ce.nameTable[e];t;){var r=t.name_next;s.includes(t.mount)&&Ce.destroyNode(t),t=r}})),r.mounted=null;var n=r.mount.mounts.indexOf(i);r.mount.mounts.splice(n,1)},lookup:(e,t)=>e.node_ops.lookup(e,t),mknod(e,t,r){var i=Ce.lookupPath(e,{parent:!0}).node,s=de.basename(e);if(!s||"."===s||".."===s)throw new Ce.ErrnoError(28);var n=Ce.mayCreate(i,s);if(n)throw new Ce.ErrnoError(n);if(!i.node_ops.mknod)throw new Ce.ErrnoError(63);return i.node_ops.mknod(i,s,t,r)},create:(e,t)=>(t=void 0!==t?t:438,t&=4095,t|=32768,Ce.mknod(e,t,0)),mkdir:(e,t)=>(t=void 0!==t?t:511,t&=1023,t|=16384,Ce.mknod(e,t,0)),mkdirTree(e,t){for(var r=e.split("/"),i="",s=0;s(void 0===r&&(r=t,t=438),t|=8192,Ce.mknod(e,t,r)),symlink(e,t){if(!ce.resolve(e))throw new Ce.ErrnoError(44);var r=Ce.lookupPath(t,{parent:!0}).node;if(!r)throw new Ce.ErrnoError(44);var i=de.basename(t),s=Ce.mayCreate(r,i);if(s)throw new Ce.ErrnoError(s);if(!r.node_ops.symlink)throw new Ce.ErrnoError(63);return r.node_ops.symlink(r,i,e)},rename(e,t){var r,i,s=de.dirname(e),n=de.dirname(t),a=de.basename(e),o=de.basename(t);if(r=Ce.lookupPath(e,{parent:!0}).node,i=Ce.lookupPath(t,{parent:!0}).node,!r||!i)throw new Ce.ErrnoError(44);if(r.mount!==i.mount)throw new Ce.ErrnoError(75);var d,l=Ce.lookupNode(r,a),u=ce.relative(e,n);if("."!==u.charAt(0))throw new Ce.ErrnoError(28);if("."!==(u=ce.relative(t,s)).charAt(0))throw new Ce.ErrnoError(55);try{d=Ce.lookupNode(i,o)}catch(e){}if(l!==d){var c=Ce.isDir(l.mode),h=Ce.mayDelete(r,a,c);if(h)throw new Ce.ErrnoError(h);if(h=d?Ce.mayDelete(i,o,c):Ce.mayCreate(i,o))throw new Ce.ErrnoError(h);if(!r.node_ops.rename)throw new Ce.ErrnoError(63);if(Ce.isMountpoint(l)||d&&Ce.isMountpoint(d))throw new Ce.ErrnoError(10);if(i!==r&&(h=Ce.nodePermissions(r,"w")))throw new Ce.ErrnoError(h);Ce.hashRemoveNode(l);try{r.node_ops.rename(l,i,o)}catch(e){throw e}finally{Ce.hashAddNode(l)}}},rmdir(e){var t=Ce.lookupPath(e,{parent:!0}).node,r=de.basename(e),i=Ce.lookupNode(t,r),s=Ce.mayDelete(t,r,!0);if(s)throw new Ce.ErrnoError(s);if(!t.node_ops.rmdir)throw new Ce.ErrnoError(63);if(Ce.isMountpoint(i))throw new Ce.ErrnoError(10);t.node_ops.rmdir(t,r),Ce.destroyNode(i)},readdir(e){var t=Ce.lookupPath(e,{follow:!0}).node;if(!t.node_ops.readdir)throw new Ce.ErrnoError(54);return t.node_ops.readdir(t)},unlink(e){var t=Ce.lookupPath(e,{parent:!0}).node;if(!t)throw new Ce.ErrnoError(44);var r=de.basename(e),i=Ce.lookupNode(t,r),s=Ce.mayDelete(t,r,!1);if(s)throw new Ce.ErrnoError(s);if(!t.node_ops.unlink)throw new Ce.ErrnoError(63);if(Ce.isMountpoint(i))throw new Ce.ErrnoError(10);t.node_ops.unlink(t,r),Ce.destroyNode(i)},readlink(e){var t=Ce.lookupPath(e).node;if(!t)throw new Ce.ErrnoError(44);if(!t.node_ops.readlink)throw new Ce.ErrnoError(28);return ce.resolve(Ce.getPath(t.parent),t.node_ops.readlink(t))},stat(e,t){var r=Ce.lookupPath(e,{follow:!t}).node;if(!r)throw new Ce.ErrnoError(44);if(!r.node_ops.getattr)throw new Ce.ErrnoError(63);return r.node_ops.getattr(r)},lstat:e=>Ce.stat(e,!0),chmod(e,t,r){var i;if(!(i="string"==typeof e?Ce.lookupPath(e,{follow:!r}).node:e).node_ops.setattr)throw new Ce.ErrnoError(63);i.node_ops.setattr(i,{mode:4095&t|-4096&i.mode,timestamp:Date.now()})},lchmod(e,t){Ce.chmod(e,t,!0)},fchmod(e,t){var r=Ce.getStreamChecked(e);Ce.chmod(r.node,t)},chown(e,t,r,i){var s;if(!(s="string"==typeof e?Ce.lookupPath(e,{follow:!i}).node:e).node_ops.setattr)throw new Ce.ErrnoError(63);s.node_ops.setattr(s,{timestamp:Date.now()})},lchown(e,t,r){Ce.chown(e,t,r,!0)},fchown(e,t,r){var i=Ce.getStreamChecked(e);Ce.chown(i.node,t,r)},truncate(e,t){if(t<0)throw new Ce.ErrnoError(28);var r;if(!(r="string"==typeof e?Ce.lookupPath(e,{follow:!0}).node:e).node_ops.setattr)throw new Ce.ErrnoError(63);if(Ce.isDir(r.mode))throw new Ce.ErrnoError(31);if(!Ce.isFile(r.mode))throw new Ce.ErrnoError(28);var i=Ce.nodePermissions(r,"w");if(i)throw new Ce.ErrnoError(i);r.node_ops.setattr(r,{size:t,timestamp:Date.now()})},ftruncate(e,t){var r=Ce.getStreamChecked(e);if(0==(2097155&r.flags))throw new Ce.ErrnoError(28);Ce.truncate(r.node,t)},utime(e,t,r){var i=Ce.lookupPath(e,{follow:!0}).node;i.node_ops.setattr(i,{timestamp:Math.max(t,r)})},open(e,t,r){if(""===e)throw new Ce.ErrnoError(44);var i;if(r=void 0===r?438:r,r=64&(t="string"==typeof t?Be(t):t)?4095&r|32768:0,"object"==typeof e)i=e;else{e=de.normalize(e);try{i=Ce.lookupPath(e,{follow:!(131072&t)}).node}catch(e){}}var n=!1;if(64&t)if(i){if(128&t)throw new Ce.ErrnoError(20)}else i=Ce.mknod(e,r,0),n=!0;if(!i)throw new Ce.ErrnoError(44);if(Ce.isChrdev(i.mode)&&(t&=-513),65536&t&&!Ce.isDir(i.mode))throw new Ce.ErrnoError(54);if(!n){var a=Ce.mayOpen(i,t);if(a)throw new Ce.ErrnoError(a)}512&t&&!n&&Ce.truncate(i,0),t&=-131713;var o=Ce.createStream({node:i,path:Ce.getPath(i),flags:t,seekable:!0,position:0,stream_ops:i.stream_ops,ungotten:[],error:!1});return o.stream_ops.open&&o.stream_ops.open(o),!s.logReadFiles||1&t||(Ce.readFiles||(Ce.readFiles={}),e in Ce.readFiles||(Ce.readFiles[e]=1)),o},close(e){if(Ce.isClosed(e))throw new Ce.ErrnoError(8);e.getdents&&(e.getdents=null);try{e.stream_ops.close&&e.stream_ops.close(e)}catch(e){throw e}finally{Ce.closeStream(e.fd)}e.fd=null},isClosed:e=>null===e.fd,llseek(e,t,r){if(Ce.isClosed(e))throw new Ce.ErrnoError(8);if(!e.seekable||!e.stream_ops.llseek)throw new Ce.ErrnoError(70);if(0!=r&&1!=r&&2!=r)throw new Ce.ErrnoError(28);return e.position=e.stream_ops.llseek(e,t,r),e.ungotten=[],e.position},read(e,t,r,i,s){if(i<0||s<0)throw new Ce.ErrnoError(28);if(Ce.isClosed(e))throw new Ce.ErrnoError(8);if(1==(2097155&e.flags))throw new Ce.ErrnoError(8);if(Ce.isDir(e.node.mode))throw new Ce.ErrnoError(31);if(!e.stream_ops.read)throw new Ce.ErrnoError(28);var n=void 0!==s;if(n){if(!e.seekable)throw new Ce.ErrnoError(70)}else s=e.position;var a=e.stream_ops.read(e,t,r,i,s);return n||(e.position+=a),a},write(e,t,r,i,s,n){if(i<0||s<0)throw new Ce.ErrnoError(28);if(Ce.isClosed(e))throw new Ce.ErrnoError(8);if(0==(2097155&e.flags))throw new Ce.ErrnoError(8);if(Ce.isDir(e.node.mode))throw new Ce.ErrnoError(31);if(!e.stream_ops.write)throw new Ce.ErrnoError(28);e.seekable&&1024&e.flags&&Ce.llseek(e,0,2);var a=void 0!==s;if(a){if(!e.seekable)throw new Ce.ErrnoError(70)}else s=e.position;var o=e.stream_ops.write(e,t,r,i,s,n);return a||(e.position+=o),o},allocate(e,t,r){if(Ce.isClosed(e))throw new Ce.ErrnoError(8);if(t<0||r<=0)throw new Ce.ErrnoError(28);if(0==(2097155&e.flags))throw new Ce.ErrnoError(8);if(!Ce.isFile(e.node.mode)&&!Ce.isDir(e.node.mode))throw new Ce.ErrnoError(43);if(!e.stream_ops.allocate)throw new Ce.ErrnoError(138);e.stream_ops.allocate(e,t,r)},mmap(e,t,r,i,s){if(0!=(2&i)&&0==(2&s)&&2!=(2097155&e.flags))throw new Ce.ErrnoError(2);if(1==(2097155&e.flags))throw new Ce.ErrnoError(2);if(!e.stream_ops.mmap)throw new Ce.ErrnoError(43);return e.stream_ops.mmap(e,t,r,i,s)},msync:(e,t,r,i,s)=>e.stream_ops.msync?e.stream_ops.msync(e,t,r,i,s):0,munmap:e=>0,ioctl(e,t,r){if(!e.stream_ops.ioctl)throw new Ce.ErrnoError(59);return e.stream_ops.ioctl(e,t,r)},readFile(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t.flags=t.flags||0,t.encoding=t.encoding||"binary","utf8"!==t.encoding&&"binary"!==t.encoding)throw new Error(`Invalid encoding type "${t.encoding}"`);var r,i=Ce.open(e,t.flags),s=Ce.stat(e).size,n=new Uint8Array(s);return Ce.read(i,n,0,s,0),"utf8"===t.encoding?r=fe(n,0):"binary"===t.encoding&&(r=n),Ce.close(i),r},writeFile(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r.flags=r.flags||577;var i=Ce.open(e,r.flags,r.mode);if("string"==typeof t){var s=new Uint8Array(me(t)+1),n=_e(t,s,0,s.length);Ce.write(i,s,0,n,void 0,r.canOwn)}else{if(!ArrayBuffer.isView(t))throw new Error("Unsupported data type");Ce.write(i,t,0,t.byteLength,void 0,r.canOwn)}Ce.close(i)},cwd:()=>Ce.currentPath,chdir(e){var t=Ce.lookupPath(e,{follow:!0});if(null===t.node)throw new Ce.ErrnoError(44);if(!Ce.isDir(t.node.mode))throw new Ce.ErrnoError(54);var r=Ce.nodePermissions(t.node,"x");if(r)throw new Ce.ErrnoError(r);Ce.currentPath=t.path},createDefaultDirectories(){Ce.mkdir("/tmp"),Ce.mkdir("/home"),Ce.mkdir("/home/web_user")},createDefaultDevices(){Ce.mkdir("/dev"),Ce.registerDevice(Ce.makedev(1,3),{read:()=>0,write:(e,t,r,i,s)=>i}),Ce.mkdev("/dev/null",Ce.makedev(1,3)),be.register(Ce.makedev(5,0),be.default_tty_ops),be.register(Ce.makedev(6,0),be.default_tty1_ops),Ce.mkdev("/dev/tty",Ce.makedev(5,0)),Ce.mkdev("/dev/tty1",Ce.makedev(6,0));var e=new Uint8Array(1024),t=0,r=()=>(0===t&&(t=ue(e).byteLength),e[--t]);Ce.createDevice("/dev","random",r),Ce.createDevice("/dev","urandom",r),Ce.mkdir("/dev/shm"),Ce.mkdir("/dev/shm/tmp")},createSpecialDirectories(){Ce.mkdir("/proc");var e=Ce.mkdir("/proc/self");Ce.mkdir("/proc/self/fd"),Ce.mount({mount(){var t=Ce.createNode(e,"fd",16895,73);return t.node_ops={lookup(e,t){var r=+t,i=Ce.getStreamChecked(r),s={parent:null,mount:{mountpoint:"fake"},node_ops:{readlink:()=>i.path}};return s.parent=s,s}},t}},{},"/proc/self/fd")},createStandardStreams(){s.stdin?Ce.createDevice("/dev","stdin",s.stdin):Ce.symlink("/dev/tty","/dev/stdin"),s.stdout?Ce.createDevice("/dev","stdout",null,s.stdout):Ce.symlink("/dev/tty","/dev/stdout"),s.stderr?Ce.createDevice("/dev","stderr",null,s.stderr):Ce.symlink("/dev/tty1","/dev/stderr"),Ce.open("/dev/stdin",0),Ce.open("/dev/stdout",1),Ce.open("/dev/stderr",1)},ensureErrnoError(){Ce.ErrnoError||(Ce.ErrnoError=function(e,t){this.name="ErrnoError",this.node=t,this.setErrno=function(e){this.errno=e},this.setErrno(e),this.message="FS error"},Ce.ErrnoError.prototype=new Error,Ce.ErrnoError.prototype.constructor=Ce.ErrnoError,[44].forEach((e=>{Ce.genericErrors[e]=new Ce.ErrnoError(e),Ce.genericErrors[e].stack=""})))},staticInit(){Ce.ensureErrnoError(),Ce.nameTable=new Array(4096),Ce.mount(we,{},"/"),Ce.createDefaultDirectories(),Ce.createDefaultDevices(),Ce.createSpecialDirectories(),Ce.filesystems={MEMFS:we}},init(e,t,r){Ce.init.initialized=!0,Ce.ensureErrnoError(),s.stdin=e||s.stdin,s.stdout=t||s.stdout,s.stderr=r||s.stderr,Ce.createStandardStreams()},quit(){Ce.init.initialized=!1;for(var e=0;ethis.length-1||e<0)){var t=e%this.chunkSize,r=e/this.chunkSize|0;return this.getter(r)[t]}},n.prototype.setDataGetter=function(e){this.getter=e},n.prototype.cacheLength=function(){var e=new XMLHttpRequest;if(e.open("HEAD",r,!1),e.send(null),!(e.status>=200&&e.status<300||304===e.status))throw new Error("Couldn't load "+r+". Status: "+e.status);var t,i=Number(e.getResponseHeader("Content-length")),s=(t=e.getResponseHeader("Accept-Ranges"))&&"bytes"===t,n=(t=e.getResponseHeader("Content-Encoding"))&&"gzip"===t,a=1048576;s||(a=i);var o=this;o.setDataGetter((e=>{var t=e*a,s=(e+1)*a-1;if(s=Math.min(s,i-1),void 0===o.chunks[e]&&(o.chunks[e]=((e,t)=>{if(e>t)throw new Error("invalid range ("+e+", "+t+") or no bytes requested!");if(t>i-1)throw new Error("only "+i+" bytes available! programmer error!");var s=new XMLHttpRequest;if(s.open("GET",r,!1),i!==a&&s.setRequestHeader("Range","bytes="+e+"-"+t),s.responseType="arraybuffer",s.overrideMimeType&&s.overrideMimeType("text/plain; charset=x-user-defined"),s.send(null),!(s.status>=200&&s.status<300||304===s.status))throw new Error("Couldn't load "+r+". Status: "+s.status);return void 0!==s.response?new Uint8Array(s.response||[]):ge(s.responseText||"",!0)})(t,s)),void 0===o.chunks[e])throw new Error("doXHR failed!");return o.chunks[e]})),!n&&i||(a=i=1,i=this.getter(0).length,a=i,v("LazyFiles on gzip forces download of the whole file when length is accessed")),this._length=i,this._chunkSize=a,this.lengthKnown=!0},"undefined"!=typeof XMLHttpRequest){if(!c)throw"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";var a=new n;Object.defineProperties(a,{length:{get:function(){return this.lengthKnown||this.cacheLength(),this._length}},chunkSize:{get:function(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}});var o={isDevice:!1,contents:a}}else o={isDevice:!1,url:r};var d=Ce.createFile(e,t,o,i,s);o.contents?d.contents=o.contents:o.url&&(d.contents=null,d.url=o.url),Object.defineProperties(d,{usedBytes:{get:function(){return this.contents.length}}});var l={};function u(e,t,r,i,s){var n=e.node.contents;if(s>=n.length)return 0;var a=Math.min(n.length-s,i);if(n.slice)for(var o=0;o{var t=d.stream_ops[e];l[e]=function(){return Ce.forceLoadFile(d),t.apply(null,arguments)}})),l.read=(e,t,r,i,s)=>(Ce.forceLoadFile(d),u(e,t,r,i,s)),l.mmap=(e,t,r,i,s)=>{Ce.forceLoadFile(d);var n=ve();if(!n)throw new Ce.ErrnoError(48);return u(e,S,n,t,r),{ptr:n,allocated:!0}},d.stream_ops=l,d}},ke=(e,t)=>e?fe(E,e,t):"",De={DEFAULT_POLLMASK:5,calculateAt(e,t,r){if(de.isAbs(t))return t;var i;if(i=-100===e?Ce.cwd():De.getStreamFromFD(e).path,0==t.length){if(!r)throw new Ce.ErrnoError(44);return i}return de.join2(i,t)},doStat(e,t,r){try{var i=e(t)}catch(e){if(e&&e.node&&de.normalize(t)!==de.normalize(Ce.getPath(e.node)))return-54;throw e}x[r>>2]=i.dev,x[r+4>>2]=i.mode,B[r+8>>2]=i.nlink,x[r+12>>2]=i.uid,x[r+16>>2]=i.gid,x[r+20>>2]=i.rdev,K=[i.size>>>0,(Y=i.size,+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[r+24>>2]=K[0],x[r+28>>2]=K[1],x[r+32>>2]=4096,x[r+36>>2]=i.blocks;var s=i.atime.getTime(),n=i.mtime.getTime(),a=i.ctime.getTime();return K=[Math.floor(s/1e3)>>>0,(Y=Math.floor(s/1e3),+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[r+40>>2]=K[0],x[r+44>>2]=K[1],B[r+48>>2]=s%1e3*1e3,K=[Math.floor(n/1e3)>>>0,(Y=Math.floor(n/1e3),+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[r+56>>2]=K[0],x[r+60>>2]=K[1],B[r+64>>2]=n%1e3*1e3,K=[Math.floor(a/1e3)>>>0,(Y=Math.floor(a/1e3),+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[r+72>>2]=K[0],x[r+76>>2]=K[1],B[r+80>>2]=a%1e3*1e3,K=[i.ino>>>0,(Y=i.ino,+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[r+88>>2]=K[0],x[r+92>>2]=K[1],0},doMsync(e,t,r,i,s){if(!Ce.isFile(t.node.mode))throw new Ce.ErrnoError(43);if(2&i)return 0;var n=E.slice(e,e+r);Ce.msync(t,n,s,r,i)},varargs:void 0,get(){var e=x[+De.varargs>>2];return De.varargs+=4,e},getp:()=>De.get(),getStr:e=>ke(e),getStreamFromFD:e=>Ce.getStreamChecked(e)};function Ie(e,t,r){De.varargs=r;try{var i=De.getStreamFromFD(e);switch(t){case 0:if((s=De.get())<0)return-28;for(;Ce.streams[s];)s++;return Ce.createStream(i,s).fd;case 1:case 2:case 6:case 7:return 0;case 3:return i.flags;case 4:var s=De.get();return i.flags|=s,0;case 5:return s=De.getp(),A[s+0>>1]=2,0;case 16:case 8:default:return-28;case 9:return oe(28),-1}}catch(e){if(void 0===Ce||"ErrnoError"!==e.name)throw e;return-e.errno}}function Fe(e,t,r,i){De.varargs=i;try{t=De.getStr(t),t=De.calculateAt(e,t);var s=i?De.get():0;return Ce.open(t,r,s).fd}catch(e){if(void 0===Ce||"ErrnoError"!==e.name)throw e;return-e.errno}}var Pe,Le,Me,Re=(e,t,r,i,s)=>{},ze=()=>{for(var e=new Array(256),t=0;t<256;++t)e[t]=String.fromCharCode(t);Pe=e},Ne=e=>{for(var t="",r=e;E[r];)t+=Pe[E[r++]];return t},Oe={},Ge={},$e={},He=e=>{throw new Le(e)},Ve=e=>{throw new Me(e)},We=(e,t,r)=>{function i(t){var i=r(t);i.length!==e.length&&Ve("Mismatched type converter count");for(var s=0;s{Ge.hasOwnProperty(e)?s[t]=Ge[e]:(n.push(e),Oe.hasOwnProperty(e)||(Oe[e]=[]),Oe[e].push((()=>{s[t]=Ge[e],++a===n.length&&i(s)})))})),0===n.length&&i(s)};function je(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var i=t.name;if(e||He(`type "${i}" must have a positive integer typeid pointer`),Ge.hasOwnProperty(e)){if(r.ignoreDuplicateRegistrations)return;He(`Cannot register type '${i}' twice`)}if(Ge[e]=t,delete $e[e],Oe.hasOwnProperty(e)){var s=Oe[e];delete Oe[e],s.forEach((e=>e()))}}function qe(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!("argPackAdvance"in t))throw new TypeError("registerType registeredInstance requires argPackAdvance");return je(e,t,r)}var Ye,Ke=8,Xe=(e,t,r,i)=>{qe(e,{name:t=Ne(t),fromWireType:function(e){return!!e},toWireType:function(e,t){return t?r:i},argPackAdvance:Ke,readValueFromPointer:function(e){return this.fromWireType(E[e])},destructorFunction:null})},Ze=e=>({count:e.count,deleteScheduled:e.deleteScheduled,preservePointerOnDelete:e.preservePointerOnDelete,ptr:e.ptr,ptrType:e.ptrType,smartPtr:e.smartPtr,smartPtrType:e.smartPtrType}),Je=e=>{He(e.$$.ptrType.registeredClass.name+" instance already deleted")},Qe=!1,et=e=>{},tt=e=>{e.smartPtr?e.smartPtrType.rawDestructor(e.smartPtr):e.ptrType.registeredClass.rawDestructor(e.ptr)},rt=e=>{e.count.value-=1,0===e.count.value&&tt(e)},it=(e,t,r)=>{if(t===r)return e;if(void 0===r.baseClass)return null;var i=it(e,t,r.baseClass);return null===i?null:r.downcast(i)},st={},nt=()=>Object.keys(ct).length,at=()=>{var e=[];for(var t in ct)ct.hasOwnProperty(t)&&e.push(ct[t]);return e},ot=[],dt=()=>{for(;ot.length;){var e=ot.pop();e.$$.deleteScheduled=!1,e.delete()}},lt=e=>{Ye=e,ot.length&&Ye&&Ye(dt)},ut=()=>{s.getInheritedInstanceCount=nt,s.getLiveInheritedInstances=at,s.flushPendingDeletes=dt,s.setDelayFunction=lt},ct={},ht=(e,t)=>{for(void 0===t&&He("ptr should not be undefined");e.baseClass;)t=e.upcast(t),e=e.baseClass;return t},ft=(e,t)=>(t=ht(e,t),ct[t]),pt=(e,t)=>(t.ptrType&&t.ptr||Ve("makeClassHandle requires ptr and ptrType"),!!t.smartPtrType!=!!t.smartPtr&&Ve("Both smartPtrType and smartPtr must be specified"),t.count={value:1},_t(Object.create(e,{$$:{value:t}})));function mt(e){var t=this.getPointee(e);if(!t)return this.destructor(e),null;var r=ft(this.registeredClass,t);if(void 0!==r){if(0===r.$$.count.value)return r.$$.ptr=t,r.$$.smartPtr=e,r.clone();var i=r.clone();return this.destructor(e),i}function s(){return this.isSmartPointer?pt(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:t,smartPtrType:this,smartPtr:e}):pt(this.registeredClass.instancePrototype,{ptrType:this,ptr:e})}var n,a=this.registeredClass.getActualType(t),o=st[a];if(!o)return s.call(this);n=this.isConst?o.constPointerType:o.pointerType;var d=it(t,this.registeredClass,n.registeredClass);return null===d?s.call(this):this.isSmartPointer?pt(n.registeredClass.instancePrototype,{ptrType:n,ptr:d,smartPtrType:this,smartPtr:e}):pt(n.registeredClass.instancePrototype,{ptrType:n,ptr:d})}var _t=e=>"undefined"==typeof FinalizationRegistry?(_t=e=>e,e):(Qe=new FinalizationRegistry((e=>{rt(e.$$)})),_t=e=>{var t=e.$$;if(t.smartPtr){var r={$$:t};Qe.register(e,r,e)}return e},et=e=>Qe.unregister(e),_t(e)),gt=()=>{Object.assign(yt.prototype,{isAliasOf(e){if(!(this instanceof yt))return!1;if(!(e instanceof yt))return!1;var t=this.$$.ptrType.registeredClass,r=this.$$.ptr;e.$$=e.$$;for(var i=e.$$.ptrType.registeredClass,s=e.$$.ptr;t.baseClass;)r=t.upcast(r),t=t.baseClass;for(;i.baseClass;)s=i.upcast(s),i=i.baseClass;return t===i&&r===s},clone(){if(this.$$.ptr||Je(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var e=_t(Object.create(Object.getPrototypeOf(this),{$$:{value:Ze(this.$$)}}));return e.$$.count.value+=1,e.$$.deleteScheduled=!1,e},delete(){this.$$.ptr||Je(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&He("Object already scheduled for deletion"),et(this),rt(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)},isDeleted(){return!this.$$.ptr},deleteLater(){return this.$$.ptr||Je(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&He("Object already scheduled for deletion"),ot.push(this),1===ot.length&&Ye&&Ye(dt),this.$$.deleteScheduled=!0,this}})};function yt(){}var bt=48,vt=57,wt=e=>{if(void 0===e)return"_unknown";var t=(e=e.replace(/[^a-zA-Z0-9_]/g,"$")).charCodeAt(0);return t>=bt&&t<=vt?`_${e}`:e};function St(e,t){return{[e=wt(e)]:function(){return t.apply(this,arguments)}}[e]}var Et=(e,t,r)=>{if(void 0===e[t].overloadTable){var i=e[t];e[t]=function(){return e[t].overloadTable.hasOwnProperty(arguments.length)||He(`Function '${r}' called with an invalid number of arguments (${arguments.length}) - expects one of (${e[t].overloadTable})!`),e[t].overloadTable[arguments.length].apply(this,arguments)},e[t].overloadTable=[],e[t].overloadTable[i.argCount]=i}},At=(e,t,r)=>{s.hasOwnProperty(e)?((void 0===r||void 0!==s[e].overloadTable&&void 0!==s[e].overloadTable[r])&&He(`Cannot register public name '${e}' twice`),Et(s,e,e),s.hasOwnProperty(r)&&He(`Cannot register multiple overloads of a function with the same number of arguments (${r})!`),s[e].overloadTable[r]=t):(s[e]=t,void 0!==r&&(s[e].numArguments=r))};function Ut(e,t,r,i,s,n,a,o){this.name=e,this.constructor=t,this.instancePrototype=r,this.rawDestructor=i,this.baseClass=s,this.getActualType=n,this.upcast=a,this.downcast=o,this.pureVirtualFunctions=[]}var xt=(e,t,r)=>{for(;t!==r;)t.upcast||He(`Expected null or instance of ${r.name}, got an instance of ${t.name}`),e=t.upcast(e),t=t.baseClass;return e};function Bt(e,t){if(null===t)return this.isReference&&He(`null is not a valid ${this.name}`),0;t.$$||He(`Cannot pass "${or(t)}" as a ${this.name}`),t.$$.ptr||He(`Cannot pass deleted object as a pointer of type ${this.name}`);var r=t.$$.ptrType.registeredClass;return xt(t.$$.ptr,r,this.registeredClass)}function Tt(e,t){var r;if(null===t)return this.isReference&&He(`null is not a valid ${this.name}`),this.isSmartPointer?(r=this.rawConstructor(),null!==e&&e.push(this.rawDestructor,r),r):0;t.$$||He(`Cannot pass "${or(t)}" as a ${this.name}`),t.$$.ptr||He(`Cannot pass deleted object as a pointer of type ${this.name}`),!this.isConst&&t.$$.ptrType.isConst&&He(`Cannot convert argument of type ${t.$$.smartPtrType?t.$$.smartPtrType.name:t.$$.ptrType.name} to parameter type ${this.name}`);var i=t.$$.ptrType.registeredClass;if(r=xt(t.$$.ptr,i,this.registeredClass),this.isSmartPointer)switch(void 0===t.$$.smartPtr&&He("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:t.$$.smartPtrType===this?r=t.$$.smartPtr:He(`Cannot convert argument of type ${t.$$.smartPtrType?t.$$.smartPtrType.name:t.$$.ptrType.name} to parameter type ${this.name}`);break;case 1:r=t.$$.smartPtr;break;case 2:if(t.$$.smartPtrType===this)r=t.$$.smartPtr;else{var s=t.clone();r=this.rawShare(r,sr.toHandle((()=>s.delete()))),null!==e&&e.push(this.rawDestructor,r)}break;default:He("Unsupporting sharing policy")}return r}function Ct(e,t){if(null===t)return this.isReference&&He(`null is not a valid ${this.name}`),0;t.$$||He(`Cannot pass "${or(t)}" as a ${this.name}`),t.$$.ptr||He(`Cannot pass deleted object as a pointer of type ${this.name}`),t.$$.ptrType.isConst&&He(`Cannot convert argument of type ${t.$$.ptrType.name} to parameter type ${this.name}`);var r=t.$$.ptrType.registeredClass;return xt(t.$$.ptr,r,this.registeredClass)}function kt(e){return this.fromWireType(B[e>>2])}var Dt=()=>{Object.assign(It.prototype,{getPointee(e){return this.rawGetPointee&&(e=this.rawGetPointee(e)),e},destructor(e){this.rawDestructor&&this.rawDestructor(e)},argPackAdvance:Ke,readValueFromPointer:kt,deleteObject(e){null!==e&&e.delete()},fromWireType:mt})};function It(e,t,r,i,s,n,a,o,d,l,u){this.name=e,this.registeredClass=t,this.isReference=r,this.isConst=i,this.isSmartPointer=s,this.pointeeType=n,this.sharingPolicy=a,this.rawGetPointee=o,this.rawConstructor=d,this.rawShare=l,this.rawDestructor=u,s||void 0!==t.baseClass?this.toWireType=Tt:i?(this.toWireType=Bt,this.destructorFunction=null):(this.toWireType=Ct,this.destructorFunction=null)}var Ft,Pt,Lt=(e,t,r)=>{s.hasOwnProperty(e)||Ve("Replacing nonexistant public symbol"),void 0!==s[e].overloadTable&&void 0!==r?s[e].overloadTable[r]=t:(s[e]=t,s[e].argCount=r)},Mt=(e,t,r)=>{var i=s["dynCall_"+e];return r&&r.length?i.apply(null,[t].concat(r)):i.call(null,t)},Rt=[],zt=e=>{var t=Rt[e];return t||(e>=Rt.length&&(Rt.length=e+1),Rt[e]=t=Ft.get(e)),t},Nt=(e,t,r)=>e.includes("j")?Mt(e,t,r):zt(t).apply(null,r),Ot=(e,t)=>{var r=[];return function(){return r.length=0,Object.assign(r,arguments),Nt(e,t,r)}},Gt=(e,t)=>{var r=(e=Ne(e)).includes("j")?Ot(e,t):zt(t);return"function"!=typeof r&&He(`unknown function pointer with signature ${e}: ${t}`),r},$t=(e,t)=>{var r=St(t,(function(e){this.name=t,this.message=e;var r=new Error(e).stack;void 0!==r&&(this.stack=this.toString()+"\n"+r.replace(/^Error(:[^\n]*)?\n/,""))}));return r.prototype=Object.create(e.prototype),r.prototype.constructor=r,r.prototype.toString=function(){return void 0===this.message?this.name:`${this.name}: ${this.message}`},r},Ht=e=>{var t=ni(e),r=Ne(t);return ii(t),r},Vt=(e,t)=>{var r=[],i={};throw t.forEach((function e(t){i[t]||Ge[t]||($e[t]?$e[t].forEach(e):(r.push(t),i[t]=!0))})),new Pt(`${e}: `+r.map(Ht).join([", "]))},Wt=(e,t,r,i,s,n,a,o,d,l,u,c,h)=>{u=Ne(u),n=Gt(s,n),o&&(o=Gt(a,o)),l&&(l=Gt(d,l)),h=Gt(c,h);var f=wt(u);At(f,(function(){Vt(`Cannot construct ${u} due to unbound types`,[i])})),We([e,t,r],i?[i]:[],(function(t){var r,s;t=t[0],s=i?(r=t.registeredClass).instancePrototype:yt.prototype;var a=St(f,(function(){if(Object.getPrototypeOf(this)!==d)throw new Le("Use 'new' to construct "+u);if(void 0===c.constructor_body)throw new Le(u+" has no accessible constructor");var e=c.constructor_body[arguments.length];if(void 0===e)throw new Le(`Tried to invoke ctor of ${u} with invalid number of parameters (${arguments.length}) - expected (${Object.keys(c.constructor_body).toString()}) parameters instead!`);return e.apply(this,arguments)})),d=Object.create(s,{constructor:{value:a}});a.prototype=d;var c=new Ut(u,a,d,h,r,n,o,l);c.baseClass&&(void 0===c.baseClass.__derivedClasses&&(c.baseClass.__derivedClasses=[]),c.baseClass.__derivedClasses.push(c));var p=new It(u,c,!0,!1,!1),m=new It(u+"*",c,!1,!1,!1),_=new It(u+" const*",c,!1,!0,!1);return st[e]={pointerType:m,constPointerType:_},Lt(f,a),[p,m,_]}))},jt=(e,t)=>{for(var r=[],i=0;i>2]);return r},qt=e=>{for(;e.length;){var t=e.pop();e.pop()(t)}};function Yt(e,t){if(!(e instanceof Function))throw new TypeError(`new_ called with constructor type ${typeof e} which is not a function`);var r=St(e.name||"unknownFunctionName",(function(){}));r.prototype=e.prototype;var i=new r,s=e.apply(i,t);return s instanceof Object?s:i}function Kt(e,t,r,i,s,n){var a=t.length;a<2&&He("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var o=null!==t[1]&&null!==r,d=!1,l=1;l0?", ":"")+h),f+=(u||n?"var rv = ":"")+"invoker(fn"+(h.length>0?", ":"")+h+");\n",d)f+="runDestructors(destructors);\n";else for(l=o?1:2;l{var a=jt(t,r);s=Gt(i,s),We([],[e],(function(e){var r=`constructor ${(e=e[0]).name}`;if(void 0===e.registeredClass.constructor_body&&(e.registeredClass.constructor_body=[]),void 0!==e.registeredClass.constructor_body[t-1])throw new Le(`Cannot register multiple constructors with identical number of parameters (${t-1}) for class '${e.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return e.registeredClass.constructor_body[t-1]=()=>{Vt(`Cannot construct ${e.name} due to unbound types`,a)},We([],a,(i=>(i.splice(1,0,null),e.registeredClass.constructor_body[t-1]=Kt(r,i,null,s,n),[]))),[]}))},Zt=(e,t,r,i,s,n,a,o,d)=>{var l=jt(r,i);t=Ne(t),n=Gt(s,n),We([],[e],(function(e){var i=`${(e=e[0]).name}.${t}`;function s(){Vt(`Cannot call ${i} due to unbound types`,l)}t.startsWith("@@")&&(t=Symbol[t.substring(2)]),o&&e.registeredClass.pureVirtualFunctions.push(t);var u=e.registeredClass.instancePrototype,c=u[t];return void 0===c||void 0===c.overloadTable&&c.className!==e.name&&c.argCount===r-2?(s.argCount=r-2,s.className=e.name,u[t]=s):(Et(u,t,i),u[t].overloadTable[r-2]=s),We([],l,(function(s){var o=Kt(i,s,e,n,a,d);return void 0===u[t].overloadTable?(o.argCount=r-2,u[t]=o):u[t].overloadTable[r-2]=o,[]})),[]}))};function Jt(){Object.assign(Qt.prototype,{get(e){return this.allocated[e]},has(e){return void 0!==this.allocated[e]},allocate(e){var t=this.freelist.pop()||this.allocated.length;return this.allocated[t]=e,t},free(e){this.allocated[e]=void 0,this.freelist.push(e)}})}function Qt(){this.allocated=[void 0],this.freelist=[]}var er=new Qt,tr=e=>{e>=er.reserved&&0==--er.get(e).refcount&&er.free(e)},rr=()=>{for(var e=0,t=er.reserved;t{er.allocated.push({value:void 0},{value:null},{value:!0},{value:!1}),er.reserved=er.allocated.length,s.count_emval_handles=rr},sr={toValue:e=>(e||He("Cannot use deleted val. handle = "+e),er.get(e).value),toHandle:e=>{switch(e){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:return er.allocate({refcount:1,value:e})}}};function nr(e){return this.fromWireType(x[e>>2])}var ar=(e,t)=>{qe(e,{name:t=Ne(t),fromWireType:e=>{var t=sr.toValue(e);return tr(e),t},toWireType:(e,t)=>sr.toHandle(t),argPackAdvance:Ke,readValueFromPointer:nr,destructorFunction:null})},or=e=>{if(null===e)return"null";var t=typeof e;return"object"===t||"array"===t||"function"===t?e.toString():""+e},dr=(e,t)=>{switch(t){case 4:return function(e){return this.fromWireType(T[e>>2])};case 8:return function(e){return this.fromWireType(C[e>>3])};default:throw new TypeError(`invalid float width (${t}): ${e}`)}},lr=(e,t,r)=>{qe(e,{name:t=Ne(t),fromWireType:e=>e,toWireType:(e,t)=>t,argPackAdvance:Ke,readValueFromPointer:dr(t,r),destructorFunction:null})},ur=(e,t,r)=>{switch(t){case 1:return r?e=>S[e>>0]:e=>E[e>>0];case 2:return r?e=>A[e>>1]:e=>U[e>>1];case 4:return r?e=>x[e>>2]:e=>B[e>>2];default:throw new TypeError(`invalid integer width (${t}): ${e}`)}},cr=(e,t,r,i,s)=>{t=Ne(t);var n=e=>e;if(0===i){var a=32-8*r;n=e=>e<>>a}var o=t.includes("unsigned");qe(e,{name:t,fromWireType:n,toWireType:o?function(e,t){return this.name,t>>>0}:function(e,t){return this.name,t},argPackAdvance:Ke,readValueFromPointer:ur(t,r,0!==i),destructorFunction:null})},hr=(e,t,r)=>{var i=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][t];function s(e){var t=B[e>>2],r=B[e+4>>2];return new i(S.buffer,r,t)}qe(e,{name:r=Ne(r),fromWireType:s,argPackAdvance:Ke,readValueFromPointer:s},{ignoreDuplicateRegistrations:!0})},fr=(e,t,r)=>_e(e,E,t,r),pr=(e,t)=>{var r="std::string"===(t=Ne(t));qe(e,{name:t,fromWireType(e){var t,i=B[e>>2],s=e+4;if(r)for(var n=s,a=0;a<=i;++a){var o=s+a;if(a==i||0==E[o]){var d=ke(n,o-n);void 0===t?t=d:(t+=String.fromCharCode(0),t+=d),n=o+1}}else{var l=new Array(i);for(a=0;a>2]=i,r&&s)fr(t,a,i+1);else if(s)for(var o=0;o255&&(ii(a),He("String has UTF-16 code units that do not fit in 8 bits")),E[a+o]=d}else for(o=0;o{for(var r=e,i=r>>1,s=i+t/2;!(i>=s)&&U[i];)++i;if((r=i<<1)-e>32&&mr)return mr.decode(E.subarray(e,r));for(var n="",a=0;!(a>=t/2);++a){var o=A[e+2*a>>1];if(0==o)break;n+=String.fromCharCode(o)}return n},gr=(e,t,r)=>{if(void 0===r&&(r=2147483647),r<2)return 0;for(var i=t,s=(r-=2)<2*e.length?r/2:e.length,n=0;n>1]=a,t+=2}return A[t>>1]=0,t-i},yr=e=>2*e.length,br=(e,t)=>{for(var r=0,i="";!(r>=t/4);){var s=x[e+4*r>>2];if(0==s)break;if(++r,s>=65536){var n=s-65536;i+=String.fromCharCode(55296|n>>10,56320|1023&n)}else i+=String.fromCharCode(s)}return i},vr=(e,t,r)=>{if(void 0===r&&(r=2147483647),r<4)return 0;for(var i=t,s=i+r-4,n=0;n=55296&&a<=57343&&(a=65536+((1023&a)<<10)|1023&e.charCodeAt(++n)),x[t>>2]=a,(t+=4)+4>s)break}return x[t>>2]=0,t-i},wr=e=>{for(var t=0,r=0;r=55296&&i<=57343&&++r,t+=4}return t},Sr=(e,t,r)=>{var i,s,n,a,o;r=Ne(r),2===t?(i=_r,s=gr,a=yr,n=()=>U,o=1):4===t&&(i=br,s=vr,a=wr,n=()=>B,o=2),qe(e,{name:r,fromWireType:e=>{for(var r,s=B[e>>2],a=n(),d=e+4,l=0;l<=s;++l){var u=e+4+l*t;if(l==s||0==a[u>>o]){var c=i(d,u-d);void 0===r?r=c:(r+=String.fromCharCode(0),r+=c),d=u+t}}return ii(e),r},toWireType:(e,i)=>{"string"!=typeof i&&He(`Cannot pass non-string to C++ string type ${r}`);var n=a(i),d=oi(4+n+t);return B[d>>2]=n>>o,s(i,d+4,n+t),null!==e&&e.push(ii,d),d},argPackAdvance:Ke,readValueFromPointer:nr,destructorFunction(e){ii(e)}})},Er=(e,t)=>{qe(e,{isVoid:!0,name:t=Ne(t),argPackAdvance:0,fromWireType:()=>{},toWireType:(e,t)=>{}})},Ar={},Ur=e=>{var t=Ar[e];return void 0===t?Ne(e):t},xr=[],Br=(e,t,r,i)=>{(e=xr[e])(t=sr.toValue(t),r=Ur(r),null,i)},Tr=e=>{var t=xr.length;return xr.push(e),t},Cr=(e,t)=>{var r=Ge[e];return void 0===r&&He(t+" has unknown type "+Ht(e)),r},kr=(e,t)=>{for(var r=new Array(e),i=0;i>2],"parameter "+i);return r},Dr={},Ir=(e,t)=>{var r=kr(e,t),i=r[0],s=i.name+"_$"+r.slice(1).map((function(e){return e.name})).join("_")+"$",n=Dr[s];if(void 0!==n)return n;for(var a=["retType"],o=[i],d="",l=0;lt+2097152>>>0<4194305-!!e?(e>>>0)+4294967296*t:NaN,Pr=()=>{j("")},Lr=()=>Date.now(),Mr=(e,t,r)=>E.copyWithin(e,t,t+r),Rr=e=>{j("OOM")},zr=e=>{E.length,Rr()},Nr={},Or=()=>l||"./this.program",Gr=()=>{if(!Gr.strings){var e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:Or()};for(var t in Nr)void 0===Nr[t]?delete e[t]:e[t]=Nr[t];var r=[];for(var t in e)r.push(`${t}=${e[t]}`);Gr.strings=r}return Gr.strings},$r=(e,t)=>{for(var r=0;r>0]=e.charCodeAt(r);S[t>>0]=0},Hr=(e,t)=>{var r=0;return Gr().forEach(((i,s)=>{var n=t+r;B[e+4*s>>2]=n,$r(i,n),r+=i.length+1})),0},Vr=(e,t)=>{var r=Gr();B[e>>2]=r.length;var i=0;return r.forEach((e=>i+=e.length+1)),B[t>>2]=i,0};function Wr(e){try{var t=De.getStreamFromFD(e);return Ce.close(t),0}catch(e){if(void 0===Ce||"ErrnoError"!==e.name)throw e;return e.errno}}function jr(e,t){try{var r=De.getStreamFromFD(e),i=r.tty?2:Ce.isDir(r.mode)?3:Ce.isLink(r.mode)?7:4;return S[t>>0]=i,A[t+2>>1]=0,K=[0,(Y=0,+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[t+8>>2]=K[0],x[t+12>>2]=K[1],K=[0,(Y=0,+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[t+16>>2]=K[0],x[t+20>>2]=K[1],0}catch(e){if(void 0===Ce||"ErrnoError"!==e.name)throw e;return e.errno}}var qr=(e,t,r,i)=>{for(var s=0,n=0;n>2],o=B[t+4>>2];t+=8;var d=Ce.read(e,S,a,o,i);if(d<0)return-1;if(s+=d,d>2]=n,0}catch(e){if(void 0===Ce||"ErrnoError"!==e.name)throw e;return e.errno}}function Kr(e,t,r,i,s){var n=Fr(t,r);try{if(isNaN(n))return 61;var a=De.getStreamFromFD(e);return Ce.llseek(a,n,i),K=[a.position>>>0,(Y=a.position,+Math.abs(Y)>=1?Y>0?+Math.floor(Y/4294967296)>>>0:~~+Math.ceil((Y-+(~~Y>>>0))/4294967296)>>>0:0)],x[s>>2]=K[0],x[s+4>>2]=K[1],a.getdents&&0===n&&0===i&&(a.getdents=null),0}catch(e){if(void 0===Ce||"ErrnoError"!==e.name)throw e;return e.errno}}var Xr=(e,t,r,i)=>{for(var s=0,n=0;n>2],o=B[t+4>>2];t+=8;var d=Ce.write(e,S,a,o,i);if(d<0)return-1;s+=d,void 0!==i&&(i+=d)}return s};function Zr(e,t,r,i){try{var s=De.getStreamFromFD(e),n=Xr(s,t,r);return B[i>>2]=n,0}catch(e){if(void 0===Ce||"ErrnoError"!==e.name)throw e;return e.errno}}var Jr=function(e,t,r,i){e||(e=this),this.parent=e,this.mount=e.mount,this.mounted=null,this.id=Ce.nextInode++,this.name=t,this.mode=r,this.node_ops={},this.stream_ops={},this.rdev=i},Qr=365,ei=146;Object.defineProperties(Jr.prototype,{read:{get:function(){return(this.mode&Qr)===Qr},set:function(e){e?this.mode|=Qr:this.mode&=~Qr}},write:{get:function(){return(this.mode&ei)===ei},set:function(e){e?this.mode|=ei:this.mode&=~ei}},isFolder:{get:function(){return Ce.isDir(this.mode)}},isDevice:{get:function(){return Ce.isChrdev(this.mode)}}}),Ce.FSNode=Jr,Ce.createPreloadedFile=xe,Ce.staticInit(),ze(),Le=s.BindingError=class extends Error{constructor(e){super(e),this.name="BindingError"}},Me=s.InternalError=class extends Error{constructor(e){super(e),this.name="InternalError"}},gt(),ut(),Dt(),Pt=s.UnboundTypeError=$t(Error,"UnboundTypeError"),Jt(),ir();var ti={p:ae,B:Ie,v:Fe,t:Re,n:Xe,r:Wt,q:Xt,f:Zt,C:ar,m:lr,c:cr,b:hr,l:pr,h:Sr,o:Er,d:Br,i:tr,e:Ir,a:Pr,g:Lr,z:Mr,u:zr,x:Hr,y:Vr,k:Wr,w:jr,A:Yr,s:Kr,j:Zr},ri=ie(),ii=e=>(ii=ri.F)(e),si=()=>(si=ri.H)(),ni=e=>(ni=ri.I)(e);s.__embind_initialize_bindings=()=>(s.__embind_initialize_bindings=ri.J)();var ai,oi=e=>(oi=ri.K)(e),di=e=>(di=ri.M)(e);function li(){function e(){ai||(ai=!0,s.calledRun=!0,k||(R(),r(s),s.onRuntimeInitialized&&s.onRuntimeInitialized(),z()))}$>0||(M(),$>0||(s.setStatus?(s.setStatus("Running..."),setTimeout((function(){setTimeout((function(){s.setStatus("")}),1),e()}),1)):e()))}if(s.dynCall_viiijj=(e,t,r,i,n,a,o,d)=>(s.dynCall_viiijj=ri.N)(e,t,r,i,n,a,o,d),s.dynCall_jij=(e,t,r,i)=>(s.dynCall_jij=ri.O)(e,t,r,i),s.dynCall_jii=(e,t,r)=>(s.dynCall_jii=ri.P)(e,t,r),s.dynCall_jiji=(e,t,r,i,n)=>(s.dynCall_jiji=ri.Q)(e,t,r,i,n),H=function e(){ai||li(),ai||(H=e)},s.preInit)for("function"==typeof s.preInit&&(s.preInit=[s.preInit]);s.preInit.length>0;)s.preInit.pop()();return li(),t.ready}),r=1e-6,s="undefined"!=typeof Float32Array?Float32Array:Array;function n(){var e=new s(16);return s!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function a(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});var o,d=function(e,t,r,i,s,n,a){var o=1/(t-r),d=1/(i-s),l=1/(n-a);return e[0]=-2*o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*d,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+r)*o,e[13]=(s+i)*d,e[14]=(a+n)*l,e[15]=1,e};function l(e,t,r){var i=new s(3);return i[0]=e,i[1]=t,i[2]=r,i}o=new s(3),s!=Float32Array&&(o[0]=0,o[1]=0,o[2]=0);var u=(e,t)=>{t&&e.pixelStorei(e.UNPACK_ALIGNMENT,1);const i=function(){const t=m(e.VERTEX_SHADER,"\n attribute vec4 aVertexPosition;\n attribute vec2 aTexturePosition;\n uniform mat4 uModelMatrix;\n uniform mat4 uViewMatrix;\n uniform mat4 uProjectionMatrix;\n varying lowp vec2 vTexturePosition;\n void main(void) {\n gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * aVertexPosition;\n vTexturePosition = aTexturePosition;\n }\n "),r=m(e.FRAGMENT_SHADER,"\n precision highp float;\n varying highp vec2 vTexturePosition;\n uniform int isyuv;\n uniform sampler2D rgbaTexture;\n uniform sampler2D yTexture;\n uniform sampler2D uTexture;\n uniform sampler2D vTexture;\n\n const mat4 YUV2RGB = mat4( 1.1643828125, 0, 1.59602734375, -.87078515625,\n 1.1643828125, -.39176171875, -.81296875, .52959375,\n 1.1643828125, 2.017234375, 0, -1.081390625,\n 0, 0, 0, 1);\n\n\n void main(void) {\n\n if (isyuv>0) {\n\n highp float y = texture2D(yTexture, vTexturePosition).r;\n highp float u = texture2D(uTexture, vTexturePosition).r;\n highp float v = texture2D(vTexture, vTexturePosition).r;\n gl_FragColor = vec4(y, u, v, 1) * YUV2RGB;\n\n } else {\n gl_FragColor = texture2D(rgbaTexture, vTexturePosition);\n }\n }\n "),i=e.createProgram();if(e.attachShader(i,t),e.attachShader(i,r),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))return console.log("Unable to initialize the shader program: "+e.getProgramInfoLog(i)),null;return i}();let s={program:i,attribLocations:{vertexPosition:e.getAttribLocation(i,"aVertexPosition"),texturePosition:e.getAttribLocation(i,"aTexturePosition")},uniformLocations:{projectionMatrix:e.getUniformLocation(i,"uProjectionMatrix"),modelMatrix:e.getUniformLocation(i,"uModelMatrix"),viewMatrix:e.getUniformLocation(i,"uViewMatrix"),rgbatexture:e.getUniformLocation(i,"rgbaTexture"),ytexture:e.getUniformLocation(i,"yTexture"),utexture:e.getUniformLocation(i,"uTexture"),vtexture:e.getUniformLocation(i,"vTexture"),isyuv:e.getUniformLocation(i,"isyuv")}},o=function(){const t=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,t);e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1]),e.STATIC_DRAW);var r=[];r=r.concat([0,1],[1,1],[1,0],[0,0]);const i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,new Float32Array(r),e.STATIC_DRAW);const s=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,s);return e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,1,2,0,2,3]),e.STATIC_DRAW),{position:t,texPosition:i,indices:s}}(),u=p(),c=p(),h=p(),f=p();function p(){let t=e.createTexture();return e.bindTexture(e.TEXTURE_2D,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),t}function m(t,r){const i=e.createShader(t);return e.shaderSource(i,r),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS)?i:(console.log("An error occurred compiling the shaders: "+e.getShaderInfoLog(i)),e.deleteShader(i),null)}function _(t,i){e.viewport(0,0,t,i),e.clearColor(0,0,0,0),e.clearDepth(1),e.enable(e.DEPTH_TEST),e.depthFunc(e.LEQUAL),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);const u=n();d(u,-1,1,-1,1,.1,100);const p=n();a(p);const m=n();!function(e,t,i,s){var n,o,d,l,u,c,h,f,p,m,_=t[0],g=t[1],y=t[2],b=s[0],v=s[1],w=s[2],S=i[0],E=i[1],A=i[2];Math.abs(_-S)32&&console.error("ExpGolomb: readBits() bits exceeded max 32bits!"),e<=this._current_word_bits_left){let t=this._current_word>>>32-e;return this._current_word<<=e,this._current_word_bits_left-=e,t}let t=this._current_word_bits_left?this._current_word:0;t>>>=32-this._current_word_bits_left;let r=e-this._current_word_bits_left;this._fillCurrentWord();let i=Math.min(r,this._current_word_bits_left),s=this._current_word>>>32-i;return this._current_word<<=i,this._current_word_bits_left-=i,t=t<>>e))return this._current_word<<=e,this._current_word_bits_left-=e,e;return this._fillCurrentWord(),e+this._skipLeadingZero()}readUEG(){let e=this._skipLeadingZero();return this.readBits(e+1)-1}readSEG(){let e=this.readUEG();return 1&e?e+1>>>1:-1*(e>>>1)}}const Gt=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350,-1,-1,-1],$t=Gt,Ht=Gt;function Vt(e){let{profile:t,sampleRate:r,channel:i}=e;return new Uint8Array([175,0,t<<3|(14&r)>>1,(1&r)<<7|i<<3])}function Wt(e){return jt(e)&&e[1]===xt}function jt(e){return e[0]>>4===Le}const qt=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];function Yt(e){let t=new Uint8Array(e),r=null,i=0,s=0,n=0,a=null;if(i=s=t[0]>>>3,n=(7&t[0])<<1|t[1]>>>7,n<0||n>=qt.length)return void console.error("Flv: AAC invalid sampling frequency index!");let o=qt[n],d=(120&t[1])>>>3;if(d<0||d>=8)return void console.log("Flv: AAC invalid channel configuration");5===i&&(a=(7&t[1])<<1|t[2]>>>7,t[2]);let l=self.navigator.userAgent.toLowerCase();return-1!==l.indexOf("firefox")?n>=6?(i=5,r=new Array(4),a=n-3):(i=2,r=new Array(2),a=n):-1!==l.indexOf("android")?(i=2,r=new Array(2),a=n):(i=5,a=n,r=new Array(4),n>=6?a=n-3:1===d&&(i=2,r=new Array(2),a=n)),r[0]=i<<3,r[0]|=(15&n)>>>1,r[1]=(15&n)<<7,r[1]|=(15&d)<<3,5===i&&(r[1]|=(15&a)>>>1,r[2]=(1&a)<<7,r[2]|=8,r[3]=0),{audioType:"aac",config:r,sampleRate:o,channelCount:d,objectType:i,codec:"mp4a.40."+i,originalCodec:"mp4a.40."+s}}class Kt{constructor(e){this.data_=e,this.eof_flag_=!1,this.current_syncword_offset_=this.findNextSyncwordOffset(0),this.eof_flag_&&console.error("Could not found ADTS syncword until payload end")}findNextSyncwordOffset(e){let t=e,r=this.data_;for(;;){if(t+7>=r.byteLength)return this.eof_flag_=!0,r.byteLength;if(4095===(r[t+0]<<8|r[t+1])>>>4)return t;t++}}readNextAACFrame(){let e=this.data_,t=null;for(;null==t&&!this.eof_flag_;){let r=this.current_syncword_offset_,i=(8&e[r+1])>>>3,s=(6&e[r+1])>>>1,n=1&e[r+1],a=(192&e[r+2])>>>6,o=(60&e[r+2])>>>2,d=(1&e[r+2])<<2|(192&e[r+3])>>>6,l=(3&e[r+3])<<11|e[r+4]<<3|(224&e[r+5])>>>5;if(e[r+6],r+l>this.data_.byteLength){this.eof_flag_=!0,this.has_last_incomplete_data=!0;break}let u=1===n?7:9,c=l-u;r+=u;let h=this.findNextSyncwordOffset(r+c);if(this.current_syncword_offset_=h,0!==i&&1!==i||0!==s)continue;let f=e.subarray(r,r+c);t={},t.audio_object_type=a+1,t.sampling_freq_index=o,t.sampling_frequency=$t[o],t.channel_config=d,t.data=f}return t}hasIncompleteData(){return this.has_last_incomplete_data}getIncompleteData(){return this.has_last_incomplete_data?this.data_.subarray(this.current_syncword_offset_):null}}class Xt{constructor(e){this.data_=e,this.eof_flag_=!1,this.current_syncword_offset_=this.findNextSyncwordOffset(0),this.eof_flag_&&console.error("Could not found ADTS syncword until payload end")}findNextSyncwordOffset(e){let t=e,r=this.data_;for(;;){if(t+1>=r.byteLength)return this.eof_flag_=!0,r.byteLength;if(695===(r[t+0]<<3|r[t+1]>>>5))return t;t++}}getLATMValue(e){let t=e.readBits(2),r=0;for(let i=0;i<=t;i++)r<<=8,r|=e.readByte();return r}readNextAACFrame(e){let t=this.data_,r=null;for(;null==r&&!this.eof_flag_;){let i=this.current_syncword_offset_,s=(31&t[i+1])<<8|t[i+2];if(i+3+s>=this.data_.byteLength){this.eof_flag_=!0,this.has_last_incomplete_data=!0;break}let n=new Ot(t.subarray(i+3,i+3+s)),a=null;if(n.readBool()){if(null==e){console.warn("StreamMuxConfig Missing"),this.current_syncword_offset_=this.findNextSyncwordOffset(i+3+s),n.destroy();continue}a=e}else{let e=n.readBool();if(e&&n.readBool()){console.error("audioMuxVersionA is Not Supported"),n.destroy();break}if(e&&this.getLATMValue(n),!n.readBool()){console.error("allStreamsSameTimeFraming zero is Not Supported"),n.destroy();break}if(0!==n.readBits(6)){console.error("more than 2 numSubFrames Not Supported"),n.destroy();break}if(0!==n.readBits(4)){console.error("more than 2 numProgram Not Supported"),n.destroy();break}if(0!==n.readBits(3)){console.error("more than 2 numLayer Not Supported"),n.destroy();break}let t=e?this.getLATMValue(n):0,r=n.readBits(5);t-=5;let i=n.readBits(4);t-=4;let s=n.readBits(4);t-=4,n.readBits(3),t-=3,t>0&&n.readBits(t);let o=n.readBits(3);if(0!==o){console.error(`frameLengthType = ${o}. Only frameLengthType = 0 Supported`),n.destroy();break}n.readByte();let d=n.readBool();if(d)if(e)this.getLATMValue(n);else{let e=0;for(;;){e<<=8;let t=n.readBool();if(e+=n.readByte(),!t)break}console.log(e)}n.readBool()&&n.readByte(),a={},a.audio_object_type=r,a.sampling_freq_index=i,a.sampling_frequency=$t[a.sampling_freq_index],a.channel_config=s,a.other_data_present=d}let o=0;for(;;){let e=n.readByte();if(o+=e,255!==e)break}let d=new Uint8Array(o);for(let e=0;e1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+(e[t+3]||0)}function Jt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(e.length<4)return;const r=e.length,i=[];let s,n=0;for(;n+t>>=8),n+=t,s){if(n+s>r)break;i.push(e.subarray(n,n+s)),n+=s}return i}function Qt(e){const t=e.byteLength,r=new Uint8Array(4);r[0]=t>>>24&255,r[1]=t>>>16&255,r[2]=t>>>8&255,r[3]=255&t;const i=new Uint8Array(t+4);return i.set(r,0),i.set(e,4),i}function er(e,t){let r=null;return t?e.length>=28&&(r=1+(3&e[26])):e.length>=12&&(r=1+(3&e[9])),r}function tr(){return(new Date).getTime()}function rr(e,t,r){return Math.max(Math.min(e,Math.max(t,r)),Math.min(t,r))}function ir(){return performance&&"function"==typeof performance.now?performance.now():Date.now()}function sr(e){let t=0,r=ir();return i=>{if(s=i,"[object Number]"!==Object.prototype.toString.call(s))return;var s;t+=i;const n=ir(),a=n-r;a>=1e3&&(e(t/a*1e3),r=n,t=0)}}(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const e=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(e instanceof WebAssembly.Module)return new WebAssembly.Instance(e)instanceof WebAssembly.Instance}}catch(e){}})();function nr(){const e=window.navigator.userAgent.toLowerCase();return/firefox/i.test(e)}function ar(){let e=!1;return"MediaSource"in self&&(self.MediaSource.isTypeSupported(ht)||self.MediaSource.isTypeSupported(ft)||self.MediaSource.isTypeSupported(pt)||self.MediaSource.isTypeSupported(mt)||self.MediaSource.isTypeSupported(_t))&&(e=!0),e}function or(e){return null==e}function dr(e){return!or(e)}function lr(e){return"function"==typeof e}function ur(e){let t=null,r=31&e[0];return r!==Ne&&r!==Oe||(t=Fe),t||(r=(126&e[0])>>1,r!==et&&r!==rt&&r!==st||(t=Pe)),t}function cr(){return"undefined"!=typeof WritableStream}function hr(e){e.close()}function fr(e,t){t&&(e=e.filter((e=>e.type&&e.type===t)));let r=e[0],i=null,s=1;if(e.length>0){let t=e[1];t&&t.ts-r.ts>1e5&&(r=t,s=2)}if(r)for(let n=s;n=1e3){e[n-1].ts-r.ts<1e3&&(i=n+1)}}}return i}function pr(e){return e.ok&&e.status>=200&&e.status<=299}function mr(){return function(e){let t="";if("object"==typeof e)try{t=JSON.stringify(e),t=JSON.parse(t)}catch(r){t=e}else t=e;return t}(E)}function _r(e){return e[0]>>4===Bt&&e[1]===xt}function gr(e){return!0===e||"true"===e}function yr(e){return!0!==e&&"true"!==e}function br(){return!!(self.Worker&&self.MediaSource&&"canConstructInDedicatedWorker"in self.MediaSource&&!0===self.MediaSource.canConstructInDedicatedWorker)}function vr(e,t){const r=Jt(e.slice(5));let i=!1;return r.forEach((e=>{const r=t?e[0]>>>1&63:31&e[0];(t&&(r===Ye||r===Xe||r===Je)||yr(t)&&r===Ge)&&(i=!0)})),i}var wr=function(e,t,r,i){return new(r||(r=Promise))((function(s,n){function a(e){try{d(i.next(e))}catch(e){n(e)}}function o(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}d((i=i.apply(e,t||[])).next())}))};const Sr=Symbol(32),Er=Symbol(16),Ar=Symbol(8);class Ur{constructor(e){this.g=e,this.consumed=0,e&&(this.need=e.next().value)}setG(e){this.g=e,this.demand(e.next().value,!0)}consume(){this.buffer&&this.consumed&&(this.buffer.copyWithin(0,this.consumed),this.buffer=this.buffer.subarray(0,this.buffer.length-this.consumed),this.consumed=0)}demand(e,t){return t&&this.consume(),this.need=e,this.flush()}read(e){return wr(this,void 0,void 0,(function*(){return this.lastReadPromise&&(yield this.lastReadPromise),this.lastReadPromise=new Promise(((t,r)=>{var i;this.reject=r,this.resolve=e=>{delete this.lastReadPromise,delete this.resolve,delete this.need,t(e)};this.demand(e,!0)||null===(i=this.pull)||void 0===i||i.call(this,e)}))}))}readU32(){return this.read(Sr)}readU16(){return this.read(Er)}readU8(){return this.read(Ar)}close(){var e;this.g&&this.g.return(),this.buffer&&this.buffer.subarray(0,0),null===(e=this.reject)||void 0===e||e.call(this,new Error("EOF")),delete this.lastReadPromise}flush(){if(!this.buffer||!this.need)return;let e=null;const t=this.buffer.subarray(this.consumed);let r=0;const i=e=>t.length<(r=e);if("number"==typeof this.need){if(i(this.need))return;e=t.subarray(0,r)}else if(this.need===Sr){if(i(4))return;e=t[0]<<24|t[1]<<16|t[2]<<8|t[3]}else if(this.need===Er){if(i(2))return;e=t[0]<<8|t[1]}else if(this.need===Ar){if(i(1))return;e=t[0]}else if("buffer"in this.need){if("byteOffset"in this.need){if(i(this.need.byteLength-this.need.byteOffset))return;new Uint8Array(this.need.buffer,this.need.byteOffset).set(t.subarray(0,r)),e=this.need}else if(this.g)return void this.g.throw(new Error("Unsupported type"))}else{if(i(this.need.byteLength))return;new Uint8Array(this.need).set(t.subarray(0,r)),e=this.need}return this.consumed+=r,this.g?this.demand(this.g.next(e).value,!0):this.resolve&&this.resolve(e),e}write(e){if(e instanceof Uint8Array?this.malloc(e.length).set(e):"buffer"in e?this.malloc(e.byteLength).set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)):this.malloc(e.byteLength).set(new Uint8Array(e)),!this.g&&!this.resolve)return new Promise((e=>this.pull=e));this.flush()}writeU32(e){this.malloc(4).set([e>>24&255,e>>16&255,e>>8&255,255&e]),this.flush()}writeU16(e){this.malloc(2).set([e>>8&255,255&e]),this.flush()}writeU8(e){this.malloc(1)[0]=e,this.flush()}malloc(e){if(this.buffer){const t=this.buffer.length,r=t+e;if(r<=this.buffer.buffer.byteLength-this.buffer.byteOffset)this.buffer=new Uint8Array(this.buffer.buffer,this.buffer.byteOffset,r);else{const e=new Uint8Array(r);e.set(this.buffer),this.buffer=e}return this.buffer.subarray(t,r)}return this.buffer=new Uint8Array(e),this.buffer}}Ur.U32=Sr,Ur.U16=Er,Ur.U8=Ar;class xr{constructor(e){this.log=function(t){if(e._opt.debug&&e._opt.debugLevel==y){const n=e._opt.debugUuid?`[${e._opt.debugUuid}]`:"";for(var r=arguments.length,i=new Array(r>1?r-1:0),s=1;s1?r-1:0),s=1;s1?i-1:0),n=1;n=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(i[s]=t[e],s++);return new Uint8Array(i.buffer,0,s)}static parseSPS(e){let t=Br._ebsp2rbsp(e),r=new Ot(t);r.readByte();let i=r.readByte();r.readByte();let s=r.readByte();r.readUEG();let n=Br.getProfileString(i),a=Br.getLevelString(s),o=1,d=420,l=[0,420,422,444],u=8;if((100===i||110===i||122===i||244===i||44===i||83===i||86===i||118===i||128===i||138===i||144===i)&&(o=r.readUEG(),3===o&&r.readBits(1),o<=3&&(d=l[o]),u=r.readUEG()+8,r.readUEG(),r.readBits(1),r.readBool())){let e=3!==o?8:12;for(let t=0;t0&&e<16?(v=t[e-1],w=i[e-1]):255===e&&(v=r.readByte()<<8|r.readByte(),w=r.readByte()<<8|r.readByte())}if(r.readBool()&&r.readBool(),r.readBool()&&(r.readBits(4),r.readBool()&&r.readBits(24)),r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool()){let e=r.readBits(32),t=r.readBits(32);E=r.readBool(),A=t,U=2*e,S=A/U}}let x=1;1===v&&1===w||(x=v/w);let B=0,T=0;if(0===o)B=1,T=2-m;else{B=3===o?1:2,T=(1===o?2:1)*(2-m)}let C=16*(f+1),k=16*(p+1)*(2-m);C-=(_+g)*B,k-=(y+b)*T;let D=Math.ceil(C*x);return r.destroy(),r=null,{profile_string:n,level_string:a,bit_depth:u,ref_frames:h,chroma_format:d,chroma_format_string:Br.getChromaFormatString(d),frame_rate:{fixed:E,fps:S,fps_den:U,fps_num:A},sar_ratio:{width:v,height:w},codec_size:{width:C,height:k},present_size:{width:D,height:k}}}static parseSPS$2(e){let t=e.subarray(1,4),r="avc1.";for(let e=0;e<3;e++){let i=t[e].toString(16);i.length<2&&(i="0"+i),r+=i}let i=Br._ebsp2rbsp(e),s=new Ot(i);s.readByte();let n=s.readByte();s.readByte();let a=s.readByte();s.readUEG();let o=Br.getProfileString(n),d=Br.getLevelString(a),l=1,u=420,c=[0,420,422,444],h=8,f=8;if((100===n||110===n||122===n||244===n||44===n||83===n||86===n||118===n||128===n||138===n||144===n)&&(l=s.readUEG(),3===l&&s.readBits(1),l<=3&&(u=c[l]),h=s.readUEG()+8,f=s.readUEG()+8,s.readBits(1),s.readBool())){let e=3!==l?8:12;for(let t=0;t0&&e<16?(E=t[e-1],A=r[e-1]):255===e&&(E=s.readByte()<<8|s.readByte(),A=s.readByte()<<8|s.readByte())}if(s.readBool()&&s.readBool(),s.readBool()&&(s.readBits(4),s.readBool()&&s.readBits(24)),s.readBool()&&(s.readUEG(),s.readUEG()),s.readBool()){let e=s.readBits(32),t=s.readBits(32);x=s.readBool(),B=t,T=2*e,U=B/T}}let C=1;1===E&&1===A||(C=E/A);let k=0,D=0;if(0===l)k=1,D=2-y;else{k=3===l?1:2,D=(1===l?2:1)*(2-y)}let I=16*(_+1),F=16*(g+1)*(2-y);I-=(b+v)*k,F-=(w+S)*D;let P=Math.ceil(I*C);return s.destroy(),s=null,{codec_mimetype:r,profile_idc:n,level_idc:a,profile_string:o,level_string:d,chroma_format_idc:l,bit_depth:h,bit_depth_luma:h,bit_depth_chroma:f,ref_frames:m,chroma_format:u,chroma_format_string:Br.getChromaFormatString(u),frame_rate:{fixed:x,fps:U,fps_den:T,fps_num:B},sar_ratio:{width:E,height:A},codec_size:{width:I,height:F},present_size:{width:P,height:F}}}static _skipScalingList(e,t){let r=8,i=8,s=0;for(let n=0;n=this.buflen)return this.iserro=!0,0;this.iserro=!1,r=this.bufoff+e>8?8-this.bufoff:e,t<<=r,t+=this.buffer[this.bufpos]>>8-this.bufoff-r&255>>8-r,this.bufoff+=r,e-=r,8==this.bufoff&&(this.bufpos++,this.bufoff=0)}return t}look(e){let t=this.bufpos,r=this.bufoff,i=this.read(e);return this.bufpos=t,this.bufoff=r,i}read_golomb(){let e;for(e=0;0===this.read(1)&&!this.iserro;e++);return(1<>>24&255,e>>>16&255,e>>>8&255,255&e]),i=new Uint8Array(e+4);i.set(r,0),i.set(t.sps,4),t.sps=i}if(t.pps){const e=t.pps.byteLength,r=new Uint8Array([e>>>24&255,e>>>16&255,e>>>8&255,255&e]),i=new Uint8Array(e+4);i.set(r,0),i.set(t.pps,4),t.pps=i}return t}function kr(e){let{sps:t,pps:r}=e;const i=[23,0,0,0,0,1,66,0,30,255];i[0]=23,i[6]=t[1],i[7]=t[2],i[8]=t[3],i[10]=225,i[11]=t.byteLength>>8&255,i[12]=255&t.byteLength,i.push(...t,1,r.byteLength>>8&255,255&r.byteLength,...r);return new Uint8Array(i)}function Dr(e){let{sps:t,pps:r}=e,i=8+t.byteLength+1+2+r.byteLength,s=!1;const n=Br.parseSPS$2(t);66!==t[3]&&77!==t[3]&&88!==t[3]&&(s=!0,i+=4);let a=new Uint8Array(i);a[0]=1,a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=255,a[5]=225;let o=t.byteLength;a[6]=o>>>8,a[7]=255&o;let d=8;a.set(t,8),d+=o,a[d]=1;let l=r.byteLength;a[d+1]=l>>>8,a[d+2]=255&l,a.set(r,d+3),d+=3+l,s&&(a[d]=252|n.chroma_format_idc,a[d+1]=248|n.bit_depth_luma-8,a[d+2]=248|n.bit_depth_chroma-8,a[d+3]=0,d+=4);const u=[23,0,0,0,0],c=new Uint8Array(u.length+a.byteLength);return c.set(u,0),c.set(a,u.length),c}function Ir(e,t){let r=[];r[0]=t?23:39,r[1]=1,r[2]=0,r[3]=0,r[4]=0,r[5]=e.byteLength>>24&255,r[6]=e.byteLength>>16&255,r[7]=e.byteLength>>8&255,r[8]=255&e.byteLength;const i=new Uint8Array(r.length+e.byteLength);return i.set(r,0),i.set(e,r.length),i}function Fr(e,t){let r=[];r[0]=t?23:39,r[1]=1,r[2]=0,r[3]=0,r[4]=0;const i=new Uint8Array(r.length+e.byteLength);return i.set(r,0),i.set(e,r.length),i}function Pr(e){return 31&e[0]}function Lr(e){return e===Ve}function Mr(e){return!function(e){return e===Ne||e===Oe}(e)&&!Lr(e)}function Rr(e){return e===Ge}function zr(e){if(0===e.length)return!1;const t=Pr(e[0]);for(let r=1;r=r.byteLength)return this.eofFlag=!0,r.byteLength;let e=r[t+0]<<24|r[t+1]<<16|r[t+2]<<8|r[t+3],i=r[t+0]<<16|r[t+1]<<8|r[t+2];if(1===e||1===i)return t;t++}}readNextNaluPayload(){let e=this.data,t=null;for(;null==t&&!this.eofFlag;){let r=this.currentStartcodeOffset;r+=1===(e[r]<<24|e[r+1]<<16|e[r+2]<<8|e[r+3])?4:3;let i=31&e[r],s=(128&e[r])>>>7,n=this.findNextStartCodeOffset(r);this.currentStartcodeOffset=n,i>=qe||0===s&&(t={type:i,data:e.subarray(r,n)})}return t}}class Or{constructor(e){let t=e.data.byteLength;this.type=e.type,this.data=new Uint8Array(4+t),new DataView(this.data.buffer).setUint32(0,t),this.data.set(e.data,4)}}const Gr=e=>{let t=e,r=t.byteLength,i=new Uint8Array(r),s=0;for(let e=0;e=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(i[s]=t[e],s++);return new Uint8Array(i.buffer,0,s)},$r=e=>{switch(e){case 0:return"4:0:0";case 1:return"4:2:0";case 2:return"4:2:2";case 3:return"4:4:4";default:return"Unknown"}};class Hr{static _ebsp2rbsp(e){let t=e,r=t.byteLength,i=new Uint8Array(r),s=0;for(let e=0;e=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(i[s]=t[e],s++);return new Uint8Array(i.buffer,0,s)}static parseVPS(e){let t=Hr._ebsp2rbsp(e),r=new Ot(t);return r.readByte(),r.readByte(),r.readBits(4),r.readBits(2),r.readBits(6),{num_temporal_layers:r.readBits(3)+1,temporal_id_nested:r.readBool()}}static parseSPS(e){let t=Hr._ebsp2rbsp(e),r=new Ot(t);r.readByte(),r.readByte();let i=0,s=0,n=0,a=0;r.readBits(4);let o=r.readBits(3);r.readBool();let d=r.readBits(2),l=r.readBool(),u=r.readBits(5),c=r.readByte(),h=r.readByte(),f=r.readByte(),p=r.readByte(),m=r.readByte(),_=r.readByte(),g=r.readByte(),y=r.readByte(),b=r.readByte(),v=r.readByte(),w=r.readByte(),S=[],E=[];for(let e=0;e0)for(let e=o;e<8;e++)r.readBits(2);for(let e=0;e1&&r.readSEG();for(let e=0;e0&&e<=16?(P=t[e-1],L=i[e-1]):255===e&&(P=r.readBits(16),L=r.readBits(16))}if(r.readBool()&&r.readBool(),r.readBool()){r.readBits(3),r.readBool(),r.readBool()&&(r.readByte(),r.readByte(),r.readByte())}if(r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool(),r.readBool(),r.readBool(),I=r.readBool(),I&&(r.readUEG(),r.readUEG(),r.readUEG(),r.readUEG()),r.readBool()){if(R=r.readBits(32),z=r.readBits(32),r.readBool()&&r.readUEG(),r.readBool()){let e=!1,t=!1,i=!1;e=r.readBool(),t=r.readBool(),(e||t)&&(i=r.readBool(),i&&(r.readByte(),r.readBits(5),r.readBool(),r.readBits(5)),r.readBits(4),r.readBits(4),i&&r.readBits(4),r.readBits(5),r.readBits(5),r.readBits(5));for(let s=0;s<=o;s++){let s=r.readBool();M=s;let n=!0,a=1;s||(n=r.readBool());let o=!1;if(n?r.readUEG():o=r.readBool(),o||(a=r.readUEG()+1),e){for(let e=0;e>6&3,r.general_tier_flag=e[1]>>5&1,r.general_profile_idc=31&e[1],r.general_profile_compatibility_flags=e[2]<<24|e[3]<<16|e[4]<<8|e[5],r.general_constraint_indicator_flags=e[6]<<24|e[7]<<16|e[8]<<8|e[9],r.general_constraint_indicator_flags=r.general_constraint_indicator_flags<<16|e[10]<<8|e[11],r.general_level_idc=e[12],r.min_spatial_segmentation_idc=(15&e[13])<<8|e[14],r.parallelismType=3&e[15],r.chromaFormat=3&e[16],r.bitDepthLumaMinus8=7&e[17],r.bitDepthChromaMinus8=7&e[18],r.avgFrameRate=e[19]<<8|e[20],r.constantFrameRate=e[21]>>6&3,r.numTemporalLayers=e[21]>>3&7,r.temporalIdNested=e[21]>>2&1,r.lengthSizeMinusOne=3&e[21];let i=e[22],s=e.slice(23);for(let e=0;e0)for(let t=r;t<8;t++)e.read(2);i.sub_layer_profile_space=[],i.sub_layer_tier_flag=[],i.sub_layer_profile_idc=[],i.sub_layer_profile_compatibility_flag=[],i.sub_layer_progressive_source_flag=[],i.sub_layer_interlaced_source_flag=[],i.sub_layer_non_packed_constraint_flag=[],i.sub_layer_frame_only_constraint_flag=[],i.sub_layer_level_idc=[];for(let t=0;t{let t=Gr(e),r=new Ot(t);return r.readByte(),r.readByte(),r.readBits(4),r.readBits(2),r.readBits(6),{num_temporal_layers:r.readBits(3)+1,temporal_id_nested:r.readBool()}})(t),a=(e=>{let t=Gr(e),r=new Ot(t);r.readByte(),r.readByte();let i=0,s=0,n=0,a=0;r.readBits(4);let o=r.readBits(3);r.readBool();let d=r.readBits(2),l=r.readBool(),u=r.readBits(5),c=r.readByte(),h=r.readByte(),f=r.readByte(),p=r.readByte(),m=r.readByte(),_=r.readByte(),g=r.readByte(),y=r.readByte(),b=r.readByte(),v=r.readByte(),w=r.readByte(),S=[],E=[];for(let e=0;e0)for(let e=o;e<8;e++)r.readBits(2);for(let e=0;e1&&r.readSEG();for(let e=0;e0&&e<16?(P=t[e-1],L=i[e-1]):255===e&&(P=r.readBits(16),L=r.readBits(16))}if(r.readBool()&&r.readBool(),r.readBool()&&(r.readBits(3),r.readBool(),r.readBool()&&(r.readByte(),r.readByte(),r.readByte())),r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool(),r.readBool(),r.readBool(),I=r.readBool(),I&&(i+=r.readUEG(),s+=r.readUEG(),n+=r.readUEG(),a+=r.readUEG()),r.readBool()&&(R=r.readBits(32),z=r.readBits(32),r.readBool()&&(r.readUEG(),r.readBool()))){let e=!1,t=!1,i=!1;e=r.readBool(),t=r.readBool(),(e||t)&&(i=r.readBool(),i&&(r.readByte(),r.readBits(5),r.readBool(),r.readBits(5)),r.readBits(4),r.readBits(4),i&&r.readBits(4),r.readBits(5),r.readBits(5),r.readBits(5));for(let s=0;s<=o;s++){let s=r.readBool();M=s;let n=!1,a=1;s||(n=r.readBool());let o=!1;if(n?r.readSEG():o=r.readBool(),o||(cpbcnt=r.readUEG()+1),e)for(let e=0;e{let t=Gr(e),r=new Ot(t);r.readByte(),r.readByte(),r.readUEG(),r.readUEG(),r.readBool(),r.readBool(),r.readBits(3),r.readBool(),r.readBool(),r.readUEG(),r.readUEG(),r.readSEG(),r.readBool(),r.readBool(),r.readBool()&&r.readUEG(),r.readSEG(),r.readSEG(),r.readBool(),r.readBool(),r.readBool(),r.readBool();let i=r.readBool(),s=r.readBool(),n=1;return s&&i?n=0:s?n=3:i&&(n=2),{parallelismType:n}})(r);s=Object.assign(s,n,a,o);let d=23+(5+t.byteLength)+(5+i.byteLength)+(5+r.byteLength),l=new Uint8Array(d);l[0]=1,l[1]=(3&s.general_profile_space)<<6|(s.general_tier_flag?1:0)<<5|31&s.general_profile_idc,l[2]=s.general_profile_compatibility_flags_1||0,l[3]=s.general_profile_compatibility_flags_2||0,l[4]=s.general_profile_compatibility_flags_3||0,l[5]=s.general_profile_compatibility_flags_4||0,l[6]=s.general_constraint_indicator_flags_1||0,l[7]=s.general_constraint_indicator_flags_2||0,l[8]=s.general_constraint_indicator_flags_3||0,l[9]=s.general_constraint_indicator_flags_4||0,l[10]=s.general_constraint_indicator_flags_5||0,l[11]=s.general_constraint_indicator_flags_6||0,l[12]=60,l[13]=240|(3840&s.min_spatial_segmentation_idc)>>8,l[14]=255&s.min_spatial_segmentation_idc,l[15]=252|3&s.parallelismType,l[16]=252|3&s.chroma_format_idc,l[17]=248|7&s.bit_depth_luma_minus8,l[18]=248|7&s.bit_depth_chroma_minus8,l[19]=0,l[20]=0,l[21]=(3&s.constant_frame_rate)<<6|(7&s.num_temporal_layers)<<3|(s.temporal_id_nested?1:0)<<2|3,l[22]=3,l[23]=128|et,l[24]=0,l[25]=1,l[26]=(65280&t.byteLength)>>8,l[27]=(255&t.byteLength)>>0,l.set(t,28),l[23+(5+t.byteLength)+0]=128|rt,l[23+(5+t.byteLength)+1]=0,l[23+(5+t.byteLength)+2]=1,l[23+(5+t.byteLength)+3]=(65280&i.byteLength)>>8,l[23+(5+t.byteLength)+4]=(255&i.byteLength)>>0,l.set(i,23+(5+t.byteLength)+5),l[23+(5+t.byteLength+5+i.byteLength)+0]=128|st,l[23+(5+t.byteLength+5+i.byteLength)+1]=0,l[23+(5+t.byteLength+5+i.byteLength)+2]=1,l[23+(5+t.byteLength+5+i.byteLength)+3]=(65280&r.byteLength)>>8,l[23+(5+t.byteLength+5+i.byteLength)+4]=(255&r.byteLength)>>0,l.set(r,23+(5+t.byteLength+5+i.byteLength)+5);const u=[28,0,0,0,0],c=new Uint8Array(u.length+l.byteLength);return c.set(u,0),c.set(l,u.length),c}function Yr(e,t){let r=[];r[0]=t?28:44,r[1]=1,r[2]=0,r[3]=0,r[4]=0,r[5]=e.byteLength>>24&255,r[6]=e.byteLength>>16&255,r[7]=e.byteLength>>8&255,r[8]=255&e.byteLength;const i=new Uint8Array(r.length+e.byteLength);return i.set(r,0),i.set(e,r.length),i}function Kr(e,t){let r=[];r[0]=t?28:44,r[1]=1,r[2]=0,r[3]=0,r[4]=0;const i=new Uint8Array(r.length+e.byteLength);return i.set(r,0),i.set(e,r.length),i}function Xr(e){return(126&e[0])>>1}function Zr(e){return e===at}function Jr(e){return!function(e){return e>=32&&e<=40}(e)}function Qr(e){return e>=16&&e<=21}function ei(e){if(0===e.length)return!1;const t=Xr(e[0]);for(let r=1;r=r.byteLength)return this.eofFlag=!0,r.byteLength;let e=r[t+0]<<24|r[t+1]<<16|r[t+2]<<8|r[t+3],i=r[t+0]<<16|r[t+1]<<8|r[t+2];if(1===e||1===i)return t;t++}}readNextNaluPayload(){let e=this.data,t=null;for(;null==t&&!this.eofFlag;){let r=this.currentStartcodeOffset;r+=1===(e[r]<<24|e[r+1]<<16|e[r+2]<<8|e[r+3])?4:3;let i=e[r]>>1&63,s=(128&e[r])>>>7,n=this.findNextStartCodeOffset(r);this.currentStartcodeOffset=n,0===s&&(t={type:i,data:e.subarray(r,n)})}return t}}class ri{constructor(e){let t=e.data.byteLength;this.type=e.type,this.data=new Uint8Array(4+t),new DataView(this.data.buffer).setUint32(0,t),this.data.set(e.data,4)}}function ii(e){return parseInt(e)===e}function si(e){if(!ii(e.length))return!1;for(var t=0;t255)return!1;return!0}function ni(e,t){if(e.buffer&&"Uint8Array"===e.name)return t&&(e=e.slice?e.slice():Array.prototype.slice.call(e)),e;if(Array.isArray(e)){if(!si(e))throw new Error("Array contains invalid value: "+e);return new Uint8Array(e)}if(ii(e.length)&&si(e))return new Uint8Array(e);throw new Error("unsupported array-like object")}function ai(e){return new Uint8Array(e)}function oi(e,t,r,i,s){null==i&&null==s||(e=e.slice?e.slice(i,s):Array.prototype.slice.call(e,i,s)),t.set(e,r)}var di,li={toBytes:function(e){var t=[],r=0;for(e=encodeURI(e);r191&&i<224?(t.push(String.fromCharCode((31&i)<<6|63&e[r+1])),r+=2):(t.push(String.fromCharCode((15&i)<<12|(63&e[r+1])<<6|63&e[r+2])),r+=3)}return t.join("")}},ui=(di="0123456789abcdef",{toBytes:function(e){for(var t=[],r=0;r>4]+di[15&i])}return t.join("")}}),ci={16:10,24:12,32:14},hi=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],fi=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],pi=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],mi=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],_i=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],gi=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],yi=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],bi=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],vi=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],wi=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239e3,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],Si=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998e3,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],Ei=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],Ai=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],Ui=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239e3,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],xi=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998e3,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function Bi(e){for(var t=[],r=0;r>2,this._Ke[r][t%4]=n[t],this._Kd[e-r][t%4]=n[t];for(var a,o=0,d=s;d>16&255]<<24^fi[a>>8&255]<<16^fi[255&a]<<8^fi[a>>24&255]^hi[o]<<24,o+=1,8!=s)for(t=1;t>8&255]<<8^fi[a>>16&255]<<16^fi[a>>24&255]<<24;for(t=s/2+1;t>2,u=d%4,this._Ke[l][u]=n[t],this._Kd[e-l][u]=n[t++],d++}for(var l=1;l>24&255]^Ai[a>>16&255]^Ui[a>>8&255]^xi[255&a]},Ti.prototype.encrypt=function(e){if(16!=e.length)throw new Error("invalid plaintext size (must be 16 bytes)");for(var t=this._Ke.length-1,r=[0,0,0,0],i=Bi(e),s=0;s<4;s++)i[s]^=this._Ke[0][s];for(var n=1;n>24&255]^_i[i[(s+1)%4]>>16&255]^gi[i[(s+2)%4]>>8&255]^yi[255&i[(s+3)%4]]^this._Ke[n][s];i=r.slice()}var a,o=ai(16);for(s=0;s<4;s++)a=this._Ke[t][s],o[4*s]=255&(fi[i[s]>>24&255]^a>>24),o[4*s+1]=255&(fi[i[(s+1)%4]>>16&255]^a>>16),o[4*s+2]=255&(fi[i[(s+2)%4]>>8&255]^a>>8),o[4*s+3]=255&(fi[255&i[(s+3)%4]]^a);return o},Ti.prototype.decrypt=function(e){if(16!=e.length)throw new Error("invalid ciphertext size (must be 16 bytes)");for(var t=this._Kd.length-1,r=[0,0,0,0],i=Bi(e),s=0;s<4;s++)i[s]^=this._Kd[0][s];for(var n=1;n>24&255]^vi[i[(s+3)%4]>>16&255]^wi[i[(s+2)%4]>>8&255]^Si[255&i[(s+1)%4]]^this._Kd[n][s];i=r.slice()}var a,o=ai(16);for(s=0;s<4;s++)a=this._Kd[t][s],o[4*s]=255&(pi[i[s]>>24&255]^a>>24),o[4*s+1]=255&(pi[i[(s+3)%4]>>16&255]^a>>16),o[4*s+2]=255&(pi[i[(s+2)%4]>>8&255]^a>>8),o[4*s+3]=255&(pi[255&i[(s+1)%4]]^a);return o};var Ci=function(e){if(!(this instanceof Ci))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new Ti(e)};Ci.prototype.encrypt=function(e){if((e=ni(e)).length%16!=0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var t=ai(e.length),r=ai(16),i=0;iNumber.MAX_SAFE_INTEGER)throw new Error("integer value out of safe range");for(var t=15;t>=0;--t)this._counter[t]=e%256,e=parseInt(e/256)},Fi.prototype.setBytes=function(e){if(16!=(e=ni(e,!0)).length)throw new Error("invalid counter bytes size (must be 16 bytes)");this._counter=e},Fi.prototype.increment=function(){for(var e=15;e>=0;e--){if(255!==this._counter[e]){this._counter[e]++;break}this._counter[e]=0}};var Pi=function(e,t){if(!(this instanceof Pi))throw Error("AES must be instanitated with `new`");this.description="Counter",this.name="ctr",t instanceof Fi||(t=new Fi(t)),this._counter=t,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new Ti(e)};Pi.prototype.encrypt=function(e){for(var t=ni(e,!0),r=0;r16)throw new Error("PKCS#7 padding byte out of range");for(var r=e.length-t,i=0;i3&&void 0!==arguments[3]&&arguments[3];t=new Uint8Array(t),r=new Uint8Array(r);const s=e.byteLength;let n=5;for(;ns)break;let o=e[n+4],d=!1;if(i?(o=o>>>1&63,d=[0,1,2,3,4,5,6,7,8,9,16,17,18,19,20,21].includes(o)):(o&=31,d=1===o||5===o),d){const i=e.slice(n+4+2,n+4+a);let s=new Li.ModeOfOperation.ctr(t,new Li.Counter(r));const o=s.decrypt(i);s=null,e.set(o,n+4+2)}n=n+4+a}return e}function zi(e,t,r){if(e.byteLength<=30)return e;const i=e.slice(32);let s=new Li.ModeOfOperation.ctr(t,new Li.Counter(r));const n=s.decrypt(i);return s=null,e.set(n,32),e}var Ni=Nt((function(e,t){var r,s,n,a=(r=new Date,s=4,n={setLogLevel:function(e){s=e==this.debug?1:e==this.info?2:e==this.warn?3:(this.error,4)},debug:function(e,t){void 0===console.debug&&(console.debug=console.log),1>=s&&console.debug("["+a.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)},log:function(e,t){this.debug(e.msg)},info:function(e,t){2>=s&&console.info("["+a.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)},warn:function(e,t){3>=s&&console.warn("["+a.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)},error:function(e,t){4>=s&&console.error("["+a.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)}},n);a.getDurationString=function(e,t){var r;function i(e,t){for(var r=(""+e).split(".");r[0].length0){for(var r="",i=0;i0&&(r+=","),r+="["+a.getDurationString(e.start(i))+","+a.getDurationString(e.end(i))+"]";return r}return"(empty)"},t.Log=a;var o=function(e){if(!(e instanceof ArrayBuffer))throw"Needs an array buffer";this.buffer=e,this.dataview=new DataView(e),this.position=0};o.prototype.getPosition=function(){return this.position},o.prototype.getEndPosition=function(){return this.buffer.byteLength},o.prototype.getLength=function(){return this.buffer.byteLength},o.prototype.seek=function(e){var t=Math.max(0,Math.min(this.buffer.byteLength,e));return this.position=isNaN(t)||!isFinite(t)?0:t,!0},o.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},o.prototype.readAnyInt=function(e,t){var r=0;if(this.position+e<=this.buffer.byteLength){switch(e){case 1:r=t?this.dataview.getInt8(this.position):this.dataview.getUint8(this.position);break;case 2:r=t?this.dataview.getInt16(this.position):this.dataview.getUint16(this.position);break;case 3:if(t)throw"No method for reading signed 24 bits values";r=this.dataview.getUint8(this.position)<<16,r|=this.dataview.getUint8(this.position+1)<<8,r|=this.dataview.getUint8(this.position+2);break;case 4:r=t?this.dataview.getInt32(this.position):this.dataview.getUint32(this.position);break;case 8:if(t)throw"No method for reading signed 64 bits values";r=this.dataview.getUint32(this.position)<<32,r|=this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+e}return this.position+=e,r}throw"Not enough bytes in buffer"},o.prototype.readUint8=function(){return this.readAnyInt(1,!1)},o.prototype.readUint16=function(){return this.readAnyInt(2,!1)},o.prototype.readUint24=function(){return this.readAnyInt(3,!1)},o.prototype.readUint32=function(){return this.readAnyInt(4,!1)},o.prototype.readUint64=function(){return this.readAnyInt(8,!1)},o.prototype.readString=function(e){if(this.position+e<=this.buffer.byteLength){for(var t="",r=0;rthis._byteLength&&(this._byteLength=t);else{for(r<1&&(r=1);t>r;)r*=2;var i=new ArrayBuffer(r),s=new Uint8Array(this._buffer);new Uint8Array(i,0,s.length).set(s),this.buffer=i,this._byteLength=t}}},d.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var e=new ArrayBuffer(this._byteLength),t=new Uint8Array(e),r=new Uint8Array(this._buffer,0,t.length);t.set(r),this.buffer=e}},d.BIG_ENDIAN=!1,d.LITTLE_ENDIAN=!0,d.prototype._byteLength=0,Object.defineProperty(d.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}}),Object.defineProperty(d.prototype,"buffer",{get:function(){return this._trimAlloc(),this._buffer},set:function(e){this._buffer=e,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(d.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(e){this._byteOffset=e,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(d.prototype,"dataView",{get:function(){return this._dataView},set:function(e){this._byteOffset=e.byteOffset,this._buffer=e.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+e.byteLength}}),d.prototype.seek=function(e){var t=Math.max(0,Math.min(this.byteLength,e));this.position=isNaN(t)||!isFinite(t)?0:t},d.prototype.isEof=function(){return this.position>=this._byteLength},d.prototype.mapUint8Array=function(e){this._realloc(1*e);var t=new Uint8Array(this._buffer,this.byteOffset+this.position,e);return this.position+=1*e,t},d.prototype.readInt32Array=function(e,t){e=null==e?this.byteLength-this.position/4:e;var r=new Int32Array(e);return d.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT),d.arrayToNative(r,null==t?this.endianness:t),this.position+=r.byteLength,r},d.prototype.readInt16Array=function(e,t){e=null==e?this.byteLength-this.position/2:e;var r=new Int16Array(e);return d.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT),d.arrayToNative(r,null==t?this.endianness:t),this.position+=r.byteLength,r},d.prototype.readInt8Array=function(e){e=null==e?this.byteLength-this.position:e;var t=new Int8Array(e);return d.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT),this.position+=t.byteLength,t},d.prototype.readUint32Array=function(e,t){e=null==e?this.byteLength-this.position/4:e;var r=new Uint32Array(e);return d.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT),d.arrayToNative(r,null==t?this.endianness:t),this.position+=r.byteLength,r},d.prototype.readUint16Array=function(e,t){e=null==e?this.byteLength-this.position/2:e;var r=new Uint16Array(e);return d.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT),d.arrayToNative(r,null==t?this.endianness:t),this.position+=r.byteLength,r},d.prototype.readUint8Array=function(e){e=null==e?this.byteLength-this.position:e;var t=new Uint8Array(e);return d.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT),this.position+=t.byteLength,t},d.prototype.readFloat64Array=function(e,t){e=null==e?this.byteLength-this.position/8:e;var r=new Float64Array(e);return d.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT),d.arrayToNative(r,null==t?this.endianness:t),this.position+=r.byteLength,r},d.prototype.readFloat32Array=function(e,t){e=null==e?this.byteLength-this.position/4:e;var r=new Float32Array(e);return d.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT),d.arrayToNative(r,null==t?this.endianness:t),this.position+=r.byteLength,r},d.prototype.readInt32=function(e){var t=this._dataView.getInt32(this.position,null==e?this.endianness:e);return this.position+=4,t},d.prototype.readInt16=function(e){var t=this._dataView.getInt16(this.position,null==e?this.endianness:e);return this.position+=2,t},d.prototype.readInt8=function(){var e=this._dataView.getInt8(this.position);return this.position+=1,e},d.prototype.readUint32=function(e){var t=this._dataView.getUint32(this.position,null==e?this.endianness:e);return this.position+=4,t},d.prototype.readUint16=function(e){var t=this._dataView.getUint16(this.position,null==e?this.endianness:e);return this.position+=2,t},d.prototype.readUint8=function(){var e=this._dataView.getUint8(this.position);return this.position+=1,e},d.prototype.readFloat32=function(e){var t=this._dataView.getFloat32(this.position,null==e?this.endianness:e);return this.position+=4,t},d.prototype.readFloat64=function(e){var t=this._dataView.getFloat64(this.position,null==e?this.endianness:e);return this.position+=8,t},d.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0,d.memcpy=function(e,t,r,i,s){var n=new Uint8Array(e,t,s),a=new Uint8Array(r,i,s);n.set(a)},d.arrayToNative=function(e,t){return t==this.endianness?e:this.flipArrayEndianness(e)},d.nativeToEndian=function(e,t){return this.endianness==t?e:this.flipArrayEndianness(e)},d.flipArrayEndianness=function(e){for(var t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=0;rs;i--,s++){var n=t[s];t[s]=t[i],t[i]=n}return e},d.prototype.failurePosition=0,String.fromCharCodeUint8=function(e){for(var t=[],r=0;r>16),this.writeUint8((65280&e)>>8),this.writeUint8(255&e)},d.prototype.adjustUint32=function(e,t){var r=this.position;this.seek(e),this.writeUint32(t),this.seek(r)},d.prototype.mapInt32Array=function(e,t){this._realloc(4*e);var r=new Int32Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(r,null==t?this.endianness:t),this.position+=4*e,r},d.prototype.mapInt16Array=function(e,t){this._realloc(2*e);var r=new Int16Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(r,null==t?this.endianness:t),this.position+=2*e,r},d.prototype.mapInt8Array=function(e){this._realloc(1*e);var t=new Int8Array(this._buffer,this.byteOffset+this.position,e);return this.position+=1*e,t},d.prototype.mapUint32Array=function(e,t){this._realloc(4*e);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(r,null==t?this.endianness:t),this.position+=4*e,r},d.prototype.mapUint16Array=function(e,t){this._realloc(2*e);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(r,null==t?this.endianness:t),this.position+=2*e,r},d.prototype.mapFloat64Array=function(e,t){this._realloc(8*e);var r=new Float64Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(r,null==t?this.endianness:t),this.position+=8*e,r},d.prototype.mapFloat32Array=function(e,t){this._realloc(4*e);var r=new Float32Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(r,null==t?this.endianness:t),this.position+=4*e,r};var u=function(e){this.buffers=[],this.bufferIndex=-1,e&&(this.insertBuffer(e),this.bufferIndex=0)};(u.prototype=new d(new ArrayBuffer,0,d.BIG_ENDIAN)).initialized=function(){var e;return this.bufferIndex>-1||(this.buffers.length>0?0===(e=this.buffers[0]).fileStart?(this.buffer=e,this.bufferIndex=0,a.debug("MultiBufferStream","Stream ready for parsing"),!0):(a.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1):(a.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1))},ArrayBuffer.concat=function(e,t){a.debug("ArrayBuffer","Trying to create a new buffer of size: "+(e.byteLength+t.byteLength));var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(new Uint8Array(e),0),r.set(new Uint8Array(t),e.byteLength),r.buffer},u.prototype.reduceBuffer=function(e,t,r){var i;return(i=new Uint8Array(r)).set(new Uint8Array(e,t,r)),i.buffer.fileStart=e.fileStart+t,i.buffer.usedBytes=0,i.buffer},u.prototype.insertBuffer=function(e){for(var t=!0,r=0;ri.byteLength){this.buffers.splice(r,1),r--;continue}a.warn("MultiBufferStream","Buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+") already appended, ignoring")}else e.fileStart+e.byteLength<=i.fileStart||(e=this.reduceBuffer(e,0,i.fileStart-e.fileStart)),a.debug("MultiBufferStream","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")"),this.buffers.splice(r,0,e),0===r&&(this.buffer=e);t=!1;break}if(e.fileStart0)){t=!1;break}e=this.reduceBuffer(e,s,n)}}t&&(a.debug("MultiBufferStream","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")"),this.buffers.push(e),0===r&&(this.buffer=e))},u.prototype.logBufferLevel=function(e){var t,r,i,s,n,o=[],d="";for(i=0,s=0,t=0;t0&&(d+=n.end-1+"]");var l=e?a.info:a.debug;0===this.buffers.length?l("MultiBufferStream","No more buffer in memory"):l("MultiBufferStream",this.buffers.length+" stored buffer(s) ("+i+"/"+s+" bytes), continuous ranges: "+d)},u.prototype.cleanBuffers=function(){var e,t;for(e=0;e"+this.buffer.byteLength+")"),!0}return!1}return!1},u.prototype.findPosition=function(e,t,r){var i,s=null,n=-1;for(i=!0===e?0:this.bufferIndex;i=t?(a.debug("MultiBufferStream","Found position in existing buffer #"+n),n):-1},u.prototype.findEndContiguousBuf=function(e){var t,r,i,s=void 0!==e?e:this.bufferIndex;if(r=this.buffers[s],this.buffers.length>s+1)for(t=s+1;t>3;return 31===i&&r.data.length>=2&&(i=32+((7&r.data[0])<<3)+((224&r.data[1])>>5)),i}return null},r.DecoderConfigDescriptor=function(e){r.Descriptor.call(this,4,e)},r.DecoderConfigDescriptor.prototype=new r.Descriptor,r.DecoderConfigDescriptor.prototype.parse=function(e){this.oti=e.readUint8(),this.streamType=e.readUint8(),this.upStream=0!=(this.streamType>>1&1),this.streamType=this.streamType>>>2,this.bufferSize=e.readUint24(),this.maxBitrate=e.readUint32(),this.avgBitrate=e.readUint32(),this.size-=13,this.parseRemainingDescriptors(e)},r.DecoderSpecificInfo=function(e){r.Descriptor.call(this,5,e)},r.DecoderSpecificInfo.prototype=new r.Descriptor,r.SLConfigDescriptor=function(e){r.Descriptor.call(this,6,e)},r.SLConfigDescriptor.prototype=new r.Descriptor,this};t.MPEG4DescriptorParser=c;var h={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"],["grpl"],["j2kH"],["etyp",["tyco"]]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){h.FullBox.prototype=new h.Box,h.ContainerBox.prototype=new h.Box,h.SampleEntry.prototype=new h.Box,h.TrackGroupTypeBox.prototype=new h.FullBox,h.BASIC_BOXES.forEach((function(e){h.createBoxCtor(e)})),h.FULL_BOXES.forEach((function(e){h.createFullBoxCtor(e)})),h.CONTAINER_BOXES.forEach((function(e){h.createContainerBoxCtor(e[0],null,e[1])}))},Box:function(e,t,r){this.type=e,this.size=t,this.uuid=r},FullBox:function(e,t,r){h.Box.call(this,e,t,r),this.flags=0,this.version=0},ContainerBox:function(e,t,r){h.Box.call(this,e,t,r),this.boxes=[]},SampleEntry:function(e,t,r,i){h.ContainerBox.call(this,e,t),this.hdr_size=r,this.start=i},SampleGroupEntry:function(e){this.grouping_type=e},TrackGroupTypeBox:function(e,t){h.FullBox.call(this,e,t)},createBoxCtor:function(e,t){h.boxCodes.push(e),h[e+"Box"]=function(t){h.Box.call(this,e,t)},h[e+"Box"].prototype=new h.Box,t&&(h[e+"Box"].prototype.parse=t)},createFullBoxCtor:function(e,t){h[e+"Box"]=function(t){h.FullBox.call(this,e,t)},h[e+"Box"].prototype=new h.FullBox,h[e+"Box"].prototype.parse=function(e){this.parseFullHeader(e),t&&t.call(this,e)}},addSubBoxArrays:function(e){if(e){this.subBoxNames=e;for(var t=e.length,r=0;rr?(a.error("BoxParser","Box of type '"+u+"' has a size "+l+" greater than its container size "+r),{code:h.ERR_NOT_ENOUGH_DATA,type:u,size:l,hdr_size:d,start:o}):0!==l&&o+l>e.getEndPosition()?(e.seek(o),a.info("BoxParser","Not enough data in stream to parse the entire '"+u+"' box"),{code:h.ERR_NOT_ENOUGH_DATA,type:u,size:l,hdr_size:d,start:o}):t?{code:h.OK,type:u,size:l,hdr_size:d,start:o}:(h[u+"Box"]?i=new h[u+"Box"](l):"uuid"!==u?(a.warn("BoxParser","Unknown box type: '"+u+"'"),(i=new h.Box(u,l)).has_unparsed_data=!0):h.UUIDBoxes[n]?i=new h.UUIDBoxes[n](l):(a.warn("BoxParser","Unknown uuid type: '"+n+"'"),(i=new h.Box(u,l)).uuid=n,i.has_unparsed_data=!0),i.hdr_size=d,i.start=o,i.write===h.Box.prototype.write&&"mdat"!==i.type&&(a.info("BoxParser","'"+c+"' box writing not yet implemented, keeping unparsed data in memory for later write"),i.parseDataAndRewind(e)),i.parse(e),(s=e.getPosition()-(i.start+i.size))<0?(a.warn("BoxParser","Parsing of box '"+c+"' did not read the entire indicated box data size (missing "+-s+" bytes), seeking forward"),e.seek(i.start+i.size)):s>0&&(a.error("BoxParser","Parsing of box '"+c+"' read "+s+" more bytes than the indicated box data size, seeking backwards"),0!==i.size&&e.seek(i.start+i.size)),{code:h.OK,box:i,size:i.size})},h.Box.prototype.parse=function(e){"mdat"!=this.type?this.data=e.readUint8Array(this.size-this.hdr_size):0===this.size?e.seek(e.getEndPosition()):e.seek(this.start+this.size)},h.Box.prototype.parseDataAndRewind=function(e){this.data=e.readUint8Array(this.size-this.hdr_size),e.position-=this.size-this.hdr_size},h.FullBox.prototype.parseDataAndRewind=function(e){this.parseFullHeader(e),this.data=e.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,e.position-=this.size-this.hdr_size},h.FullBox.prototype.parseFullHeader=function(e){this.version=e.readUint8(),this.flags=e.readUint24(),this.hdr_size+=4},h.FullBox.prototype.parse=function(e){this.parseFullHeader(e),this.data=e.readUint8Array(this.size-this.hdr_size)},h.ContainerBox.prototype.parse=function(e){for(var t,r;e.getPosition()>10&31,t[1]=this.language>>5&31,t[2]=31&this.language,this.languageString=String.fromCharCode(t[0]+96,t[1]+96,t[2]+96)},h.SAMPLE_ENTRY_TYPE_VISUAL="Visual",h.SAMPLE_ENTRY_TYPE_AUDIO="Audio",h.SAMPLE_ENTRY_TYPE_HINT="Hint",h.SAMPLE_ENTRY_TYPE_METADATA="Metadata",h.SAMPLE_ENTRY_TYPE_SUBTITLE="Subtitle",h.SAMPLE_ENTRY_TYPE_SYSTEM="System",h.SAMPLE_ENTRY_TYPE_TEXT="Text",h.SampleEntry.prototype.parseHeader=function(e){e.readUint8Array(6),this.data_reference_index=e.readUint16(),this.hdr_size+=8},h.SampleEntry.prototype.parse=function(e){this.parseHeader(e),this.data=e.readUint8Array(this.size-this.hdr_size)},h.SampleEntry.prototype.parseDataAndRewind=function(e){this.parseHeader(e),this.data=e.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,e.position-=this.size-this.hdr_size},h.SampleEntry.prototype.parseFooter=function(e){h.ContainerBox.prototype.parse.call(this,e)},h.createMediaSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_HINT),h.createMediaSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_METADATA),h.createMediaSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SUBTITLE),h.createMediaSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SYSTEM),h.createMediaSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_TEXT),h.createMediaSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,(function(e){var t;this.parseHeader(e),e.readUint16(),e.readUint16(),e.readUint32Array(3),this.width=e.readUint16(),this.height=e.readUint16(),this.horizresolution=e.readUint32(),this.vertresolution=e.readUint32(),e.readUint32(),this.frame_count=e.readUint16(),t=Math.min(31,e.readUint8()),this.compressorname=e.readString(t),t<31&&e.readString(31-t),this.depth=e.readUint16(),e.readUint16(),this.parseFooter(e)})),h.createMediaSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,(function(e){this.parseHeader(e),e.readUint32Array(2),this.channel_count=e.readUint16(),this.samplesize=e.readUint16(),e.readUint16(),e.readUint16(),this.samplerate=e.readUint32()/65536,this.parseFooter(e)})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"avc1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"avc2"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"avc3"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"avc4"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"av01"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"dav1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"hvc1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"hev1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"hvt1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"lhe1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"dvh1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"dvhe"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"vvc1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"vvi1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"vvs1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"vvcN"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"vp08"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"vp09"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"avs3"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"j2ki"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"mjp2"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"mjpg"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"uncv"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"mp4a"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"ac-3"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"ac-4"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"ec-3"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"Opus"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"mha1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"mha2"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"mhm1"),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"mhm2"),h.createEncryptedSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_VISUAL,"encv"),h.createEncryptedSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_AUDIO,"enca"),h.createEncryptedSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SUBTITLE,"encu"),h.createEncryptedSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SYSTEM,"encs"),h.createEncryptedSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_TEXT,"enct"),h.createEncryptedSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_METADATA,"encm"),h.createBoxCtor("a1lx",(function(e){var t=16*(1+(1&(1&e.readUint8())));this.layer_size=[];for(var r=0;r<3;r++)this.layer_size[r]=16==t?e.readUint16():e.readUint32()})),h.createBoxCtor("a1op",(function(e){this.op_index=e.readUint8()})),h.createFullBoxCtor("auxC",(function(e){this.aux_type=e.readCString();var t=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=e.readUint8Array(t)})),h.createBoxCtor("av1C",(function(e){var t=e.readUint8();if(t>>7&!1)a.error("av1C marker problem");else if(this.version=127&t,1===this.version)if(t=e.readUint8(),this.seq_profile=t>>5&7,this.seq_level_idx_0=31&t,t=e.readUint8(),this.seq_tier_0=t>>7&1,this.high_bitdepth=t>>6&1,this.twelve_bit=t>>5&1,this.monochrome=t>>4&1,this.chroma_subsampling_x=t>>3&1,this.chroma_subsampling_y=t>>2&1,this.chroma_sample_position=3&t,t=e.readUint8(),this.reserved_1=t>>5&7,0===this.reserved_1){if(this.initial_presentation_delay_present=t>>4&1,1===this.initial_presentation_delay_present)this.initial_presentation_delay_minus_one=15&t;else if(this.reserved_2=15&t,0!==this.reserved_2)return void a.error("av1C reserved_2 parsing problem");var r=this.size-this.hdr_size-4;this.configOBUs=e.readUint8Array(r)}else a.error("av1C reserved_1 parsing problem");else a.error("av1C version "+this.version+" not supported")})),h.createBoxCtor("avcC",(function(e){var t,r;for(this.configurationVersion=e.readUint8(),this.AVCProfileIndication=e.readUint8(),this.profile_compatibility=e.readUint8(),this.AVCLevelIndication=e.readUint8(),this.lengthSizeMinusOne=3&e.readUint8(),this.nb_SPS_nalus=31&e.readUint8(),r=this.size-this.hdr_size-6,this.SPS=[],t=0;t0&&(this.ext=e.readUint8Array(r))})),h.createBoxCtor("btrt",(function(e){this.bufferSizeDB=e.readUint32(),this.maxBitrate=e.readUint32(),this.avgBitrate=e.readUint32()})),h.createFullBoxCtor("ccst",(function(e){var t=e.readUint8();this.all_ref_pics_intra=128==(128&t),this.intra_pred_used=64==(64&t),this.max_ref_per_pic=(63&t)>>2,e.readUint24()})),h.createBoxCtor("cdef",(function(e){var t;for(this.channel_count=e.readUint16(),this.channel_indexes=[],this.channel_types=[],this.channel_associations=[],t=0;t=32768&&this.component_type_urls.push(e.readCString())}})),h.createFullBoxCtor("co64",(function(e){var t,r;if(t=e.readUint32(),this.chunk_offsets=[],0===this.version)for(r=0;r>7}else("rICC"===this.colour_type||"prof"===this.colour_type)&&(this.ICC_profile=e.readUint8Array(this.size-4))})),h.createFullBoxCtor("cprt",(function(e){this.parseLanguage(e),this.notice=e.readCString()})),h.createFullBoxCtor("cslg",(function(e){0===this.version&&(this.compositionToDTSShift=e.readInt32(),this.leastDecodeToDisplayDelta=e.readInt32(),this.greatestDecodeToDisplayDelta=e.readInt32(),this.compositionStartTime=e.readInt32(),this.compositionEndTime=e.readInt32())})),h.createFullBoxCtor("ctts",(function(e){var t,r;if(t=e.readUint32(),this.sample_counts=[],this.sample_offsets=[],0===this.version)for(r=0;r>6,this.bsid=t>>1&31,this.bsmod=(1&t)<<2|r>>6&3,this.acmod=r>>3&7,this.lfeon=r>>2&1,this.bit_rate_code=3&r|i>>5&7})),h.createBoxCtor("dec3",(function(e){var t=e.readUint16();this.data_rate=t>>3,this.num_ind_sub=7&t,this.ind_subs=[];for(var r=0;r>6,i.bsid=s>>1&31,i.bsmod=(1&s)<<4|n>>4&15,i.acmod=n>>1&7,i.lfeon=1&n,i.num_dep_sub=a>>1&15,i.num_dep_sub>0&&(i.chan_loc=(1&a)<<8|e.readUint8())}})),h.createFullBoxCtor("dfLa",(function(e){var t=[],r=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];for(this.parseFullHeader(e);;){var i=e.readUint8(),s=Math.min(127&i,r.length-1);if(s?e.readUint8Array(e.readUint24()):(e.readUint8Array(13),this.samplerate=e.readUint32()>>12,e.readUint8Array(20)),t.push(r[s]),128&i)break}this.numMetadataBlocks=t.length+" ("+t.join(", ")+")"})),h.createBoxCtor("dimm",(function(e){this.bytessent=e.readUint64()})),h.createBoxCtor("dmax",(function(e){this.time=e.readUint32()})),h.createBoxCtor("dmed",(function(e){this.bytessent=e.readUint64()})),h.createBoxCtor("dOps",(function(e){if(this.Version=e.readUint8(),this.OutputChannelCount=e.readUint8(),this.PreSkip=e.readUint16(),this.InputSampleRate=e.readUint32(),this.OutputGain=e.readInt16(),this.ChannelMappingFamily=e.readUint8(),0!==this.ChannelMappingFamily){this.StreamCount=e.readUint8(),this.CoupledCount=e.readUint8(),this.ChannelMapping=[];for(var t=0;t=4;)this.compatible_brands[r]=e.readString(4),t-=4,r++})),h.createFullBoxCtor("hdlr",(function(e){0===this.version&&(e.readUint32(),this.handler=e.readString(4),e.readUint32Array(3),this.name=e.readString(this.size-this.hdr_size-20),"\0"===this.name[this.name.length-1]&&(this.name=this.name.slice(0,-1)))})),h.createBoxCtor("hvcC",(function(e){var t,r,i,s;this.configurationVersion=e.readUint8(),s=e.readUint8(),this.general_profile_space=s>>6,this.general_tier_flag=(32&s)>>5,this.general_profile_idc=31&s,this.general_profile_compatibility=e.readUint32(),this.general_constraint_indicator=e.readUint8Array(6),this.general_level_idc=e.readUint8(),this.min_spatial_segmentation_idc=4095&e.readUint16(),this.parallelismType=3&e.readUint8(),this.chroma_format_idc=3&e.readUint8(),this.bit_depth_luma_minus8=7&e.readUint8(),this.bit_depth_chroma_minus8=7&e.readUint8(),this.avgFrameRate=e.readUint16(),s=e.readUint8(),this.constantFrameRate=s>>6,this.numTemporalLayers=(13&s)>>3,this.temporalIdNested=(4&s)>>2,this.lengthSizeMinusOne=3&s,this.nalu_arrays=[];var n=e.readUint8();for(t=0;t>7,a.nalu_type=63&s;var o=e.readUint16();for(r=0;r>4&15,this.length_size=15&t,t=e.readUint8(),this.base_offset_size=t>>4&15,1===this.version||2===this.version?this.index_size=15&t:this.index_size=0,this.items=[];var r=0;if(this.version<2)r=e.readUint16();else{if(2!==this.version)throw"version of iloc box not supported";r=e.readUint32()}for(var i=0;i>7,this.axis=1&t})),h.createFullBoxCtor("infe",(function(e){if(0!==this.version&&1!==this.version||(this.item_ID=e.readUint16(),this.item_protection_index=e.readUint16(),this.item_name=e.readCString(),this.content_type=e.readCString(),this.content_encoding=e.readCString()),1===this.version)return this.extension_type=e.readString(4),a.warn("BoxParser","Cannot parse extension type"),void e.seek(this.start+this.size);this.version>=2&&(2===this.version?this.item_ID=e.readUint16():3===this.version&&(this.item_ID=e.readUint32()),this.item_protection_index=e.readUint16(),this.item_type=e.readString(4),this.item_name=e.readCString(),"mime"===this.item_type?(this.content_type=e.readCString(),this.content_encoding=e.readCString()):"uri "===this.item_type&&(this.item_uri_type=e.readCString()))})),h.createFullBoxCtor("ipma",(function(e){var t,r;for(entry_count=e.readUint32(),this.associations=[],t=0;t>7==1,1&this.flags?a.property_index=(127&n)<<8|e.readUint8():a.property_index=127&n}}})),h.createFullBoxCtor("iref",(function(e){var t,r;for(this.references=[];e.getPosition()>7,i.assignment_type=127&s,i.assignment_type){case 0:i.grouping_type=e.readString(4);break;case 1:i.grouping_type=e.readString(4),i.grouping_type_parameter=e.readUint32();break;case 2:case 3:break;case 4:i.sub_track_id=e.readUint32();break;default:a.warn("BoxParser","Unknown leva assignement type")}}})),h.createBoxCtor("lsel",(function(e){this.layer_id=e.readUint16()})),h.createBoxCtor("maxr",(function(e){this.period=e.readUint32(),this.bytes=e.readUint32()})),f.prototype.toString=function(){return"("+this.x+","+this.y+")"},h.createBoxCtor("mdcv",(function(e){this.display_primaries=[],this.display_primaries[0]=new f(e.readUint16(),e.readUint16()),this.display_primaries[1]=new f(e.readUint16(),e.readUint16()),this.display_primaries[2]=new f(e.readUint16(),e.readUint16()),this.white_point=new f(e.readUint16(),e.readUint16()),this.max_display_mastering_luminance=e.readUint32(),this.min_display_mastering_luminance=e.readUint32()})),h.createFullBoxCtor("mdhd",(function(e){1==this.version?(this.creation_time=e.readUint64(),this.modification_time=e.readUint64(),this.timescale=e.readUint32(),this.duration=e.readUint64()):(this.creation_time=e.readUint32(),this.modification_time=e.readUint32(),this.timescale=e.readUint32(),this.duration=e.readUint32()),this.parseLanguage(e),e.readUint16()})),h.createFullBoxCtor("mehd",(function(e){1&this.flags&&(a.warn("BoxParser","mehd box incorrectly uses flags set to 1, converting version to 1"),this.version=1),1==this.version?this.fragment_duration=e.readUint64():this.fragment_duration=e.readUint32()})),h.createFullBoxCtor("meta",(function(e){this.boxes=[],h.ContainerBox.prototype.parse.call(this,e)})),h.createFullBoxCtor("mfhd",(function(e){this.sequence_number=e.readUint32()})),h.createFullBoxCtor("mfro",(function(e){this._size=e.readUint32()})),h.createFullBoxCtor("mskC",(function(e){this.bits_per_pixel=e.readUint8()})),h.createFullBoxCtor("mvhd",(function(e){1==this.version?(this.creation_time=e.readUint64(),this.modification_time=e.readUint64(),this.timescale=e.readUint32(),this.duration=e.readUint64()):(this.creation_time=e.readUint32(),this.modification_time=e.readUint32(),this.timescale=e.readUint32(),this.duration=e.readUint32()),this.rate=e.readUint32(),this.volume=e.readUint16()>>8,e.readUint16(),e.readUint32Array(2),this.matrix=e.readUint32Array(9),e.readUint32Array(6),this.next_track_id=e.readUint32()})),h.createBoxCtor("npck",(function(e){this.packetssent=e.readUint32()})),h.createBoxCtor("nump",(function(e){this.packetssent=e.readUint64()})),h.createFullBoxCtor("padb",(function(e){var t=e.readUint32();this.padbits=[];for(var r=0;r0){var t=e.readUint32();this.kid=[];for(var r=0;r0&&(this.data=e.readUint8Array(i))})),h.createFullBoxCtor("clef",(function(e){this.width=e.readUint32(),this.height=e.readUint32()})),h.createFullBoxCtor("enof",(function(e){this.width=e.readUint32(),this.height=e.readUint32()})),h.createFullBoxCtor("prof",(function(e){this.width=e.readUint32(),this.height=e.readUint32()})),h.createContainerBoxCtor("tapt",null,["clef","prof","enof"]),h.createBoxCtor("rtp ",(function(e){this.descriptionformat=e.readString(4),this.sdptext=e.readString(this.size-this.hdr_size-4)})),h.createFullBoxCtor("saio",(function(e){1&this.flags&&(this.aux_info_type=e.readUint32(),this.aux_info_type_parameter=e.readUint32());var t=e.readUint32();this.offset=[];for(var r=0;r>7,this.avgRateFlag=t>>6&1,this.durationFlag&&(this.duration=e.readUint32()),this.avgRateFlag&&(this.accurateStatisticsFlag=e.readUint8(),this.avgBitRate=e.readUint16(),this.avgFrameRate=e.readUint16()),this.dependency=[];for(var r=e.readUint8(),i=0;i>7,this.num_leading_samples=127&t})),h.createSampleGroupCtor("rash",(function(e){if(this.operation_point_count=e.readUint16(),this.description_length!==2+(1===this.operation_point_count?2:6*this.operation_point_count)+9)a.warn("BoxParser","Mismatch in "+this.grouping_type+" sample group length"),this.data=e.readUint8Array(this.description_length-2);else{if(1===this.operation_point_count)this.target_rate_share=e.readUint16();else{this.target_rate_share=[],this.available_bitrate=[];for(var t=0;t>4,this.skip_byte_block=15&t,this.isProtected=e.readUint8(),this.Per_Sample_IV_Size=e.readUint8(),this.KID=h.parseHex16(e),this.constant_IV_size=0,this.constant_IV=0,1===this.isProtected&&0===this.Per_Sample_IV_Size&&(this.constant_IV_size=e.readUint8(),this.constant_IV=e.readUint8Array(this.constant_IV_size))})),h.createSampleGroupCtor("stsa",(function(e){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("sync",(function(e){var t=e.readUint8();this.NAL_unit_type=63&t})),h.createSampleGroupCtor("tele",(function(e){var t=e.readUint8();this.level_independently_decodable=t>>7})),h.createSampleGroupCtor("tsas",(function(e){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("tscl",(function(e){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("vipr",(function(e){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createFullBoxCtor("sbgp",(function(e){this.grouping_type=e.readString(4),1===this.version?this.grouping_type_parameter=e.readUint32():this.grouping_type_parameter=0,this.entries=[];for(var t=e.readUint32(),r=0;r>6,this.sample_depends_on[i]=t>>4&3,this.sample_is_depended_on[i]=t>>2&3,this.sample_has_redundancy[i]=3&t})),h.createFullBoxCtor("senc"),h.createFullBoxCtor("sgpd",(function(e){this.grouping_type=e.readString(4),a.debug("BoxParser","Found Sample Groups of type "+this.grouping_type),1===this.version?this.default_length=e.readUint32():this.default_length=0,this.version>=2&&(this.default_group_description_index=e.readUint32()),this.entries=[];for(var t=e.readUint32(),r=0;r>31&1,i.referenced_size=2147483647&s,i.subsegment_duration=e.readUint32(),s=e.readUint32(),i.starts_with_SAP=s>>31&1,i.SAP_type=s>>28&7,i.SAP_delta_time=268435455&s}})),h.SingleItemTypeReferenceBox=function(e,t,r,i){h.Box.call(this,e,t),this.hdr_size=r,this.start=i},h.SingleItemTypeReferenceBox.prototype=new h.Box,h.SingleItemTypeReferenceBox.prototype.parse=function(e){this.from_item_ID=e.readUint16();var t=e.readUint16();this.references=[];for(var r=0;r>4&15,this.sample_sizes[t+1]=15&i}else if(8===this.field_size)for(t=0;t0)for(r=0;r>4&15,this.default_skip_byte_block=15&t}this.default_isProtected=e.readUint8(),this.default_Per_Sample_IV_Size=e.readUint8(),this.default_KID=h.parseHex16(e),1===this.default_isProtected&&0===this.default_Per_Sample_IV_Size&&(this.default_constant_IV_size=e.readUint8(),this.default_constant_IV=e.readUint8Array(this.default_constant_IV_size))})),h.createFullBoxCtor("tfdt",(function(e){1==this.version?this.baseMediaDecodeTime=e.readUint64():this.baseMediaDecodeTime=e.readUint32()})),h.createFullBoxCtor("tfhd",(function(e){var t=0;this.track_id=e.readUint32(),this.size-this.hdr_size>t&&this.flags&h.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=e.readUint64(),t+=8):this.base_data_offset=0,this.size-this.hdr_size>t&&this.flags&h.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=e.readUint32(),t+=4):this.default_sample_description_index=0,this.size-this.hdr_size>t&&this.flags&h.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=e.readUint32(),t+=4):this.default_sample_duration=0,this.size-this.hdr_size>t&&this.flags&h.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=e.readUint32(),t+=4):this.default_sample_size=0,this.size-this.hdr_size>t&&this.flags&h.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=e.readUint32(),t+=4):this.default_sample_flags=0})),h.createFullBoxCtor("tfra",(function(e){this.track_ID=e.readUint32(),e.readUint24();var t=e.readUint8();this.length_size_of_traf_num=t>>4&3,this.length_size_of_trun_num=t>>2&3,this.length_size_of_sample_num=3&t,this.entries=[];for(var r=e.readUint32(),i=0;i>8,e.readUint16(),this.matrix=e.readInt32Array(9),this.width=e.readUint32(),this.height=e.readUint32()})),h.createBoxCtor("tmax",(function(e){this.time=e.readUint32()})),h.createBoxCtor("tmin",(function(e){this.time=e.readUint32()})),h.createBoxCtor("totl",(function(e){this.bytessent=e.readUint32()})),h.createBoxCtor("tpay",(function(e){this.bytessent=e.readUint32()})),h.createBoxCtor("tpyl",(function(e){this.bytessent=e.readUint64()})),h.TrackGroupTypeBox.prototype.parse=function(e){this.parseFullHeader(e),this.track_group_id=e.readUint32()},h.createTrackGroupCtor("msrc"),h.TrackReferenceTypeBox=function(e,t,r,i){h.Box.call(this,e,t),this.hdr_size=r,this.start=i},h.TrackReferenceTypeBox.prototype=new h.Box,h.TrackReferenceTypeBox.prototype.parse=function(e){this.track_ids=e.readUint32Array((this.size-this.hdr_size)/4)},h.trefBox.prototype.parse=function(e){for(var t,r;e.getPosition()t&&this.flags&h.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=e.readInt32(),t+=4):this.data_offset=0,this.size-this.hdr_size>t&&this.flags&h.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=e.readUint32(),t+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>t)for(var r=0;r>7&1,this.block_pad_lsb=r>>6&1,this.block_little_endian=r>>5&1,this.block_reversed=r>>4&1,this.pad_unknown=r>>3&1,this.pixel_size=e.readUint32(),this.row_align_size=e.readUint32(),this.tile_align_size=e.readUint32(),this.num_tile_cols_minus_one=e.readUint32(),this.num_tile_rows_minus_one=e.readUint32()}})),h.createFullBoxCtor("url ",(function(e){1!==this.flags&&(this.location=e.readCString())})),h.createFullBoxCtor("urn ",(function(e){this.name=e.readCString(),this.size-this.hdr_size-this.name.length-1>0&&(this.location=e.readCString())})),h.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66",!0,!1,(function(e){this.LiveServerManifest=e.readString(this.size-this.hdr_size).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")})),h.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3",!0,!1,(function(e){this.system_id=h.parseHex16(e);var t=e.readUint32();t>0&&(this.data=e.readUint8Array(t))})),h.createUUIDBox("a2394f525a9b4f14a2446c427c648df4",!0,!1),h.createUUIDBox("8974dbce7be74c5184f97148f9882554",!0,!1,(function(e){this.default_AlgorithmID=e.readUint24(),this.default_IV_size=e.readUint8(),this.default_KID=h.parseHex16(e)})),h.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f",!0,!1,(function(e){this.fragment_count=e.readUint8(),this.entries=[];for(var t=0;t>4,this.chromaSubsampling=t>>1&7,this.videoFullRangeFlag=1&t,this.colourPrimaries=e.readUint8(),this.transferCharacteristics=e.readUint8(),this.matrixCoefficients=e.readUint8(),this.codecIntializationDataSize=e.readUint16(),this.codecIntializationData=e.readUint8Array(this.codecIntializationDataSize)):(this.profile=e.readUint8(),this.level=e.readUint8(),t=e.readUint8(),this.bitDepth=t>>4&15,this.colorSpace=15&t,t=e.readUint8(),this.chromaSubsampling=t>>4&15,this.transferFunction=t>>1&7,this.videoFullRangeFlag=1&t,this.codecIntializationDataSize=e.readUint16(),this.codecIntializationData=e.readUint8Array(this.codecIntializationDataSize))})),h.createBoxCtor("vttC",(function(e){this.text=e.readString(this.size-this.hdr_size)})),h.createFullBoxCtor("vvcC",(function(e){var t,r,i={held_bits:void 0,num_held_bits:0,stream_read_1_bytes:function(e){this.held_bits=e.readUint8(),this.num_held_bits=8},stream_read_2_bytes:function(e){this.held_bits=e.readUint16(),this.num_held_bits=16},extract_bits:function(e){var t=this.held_bits>>this.num_held_bits-e&(1<1){for(i.stream_read_1_bytes(e),this.ptl_sublayer_present_mask=0,r=this.num_sublayers-2;r>=0;--r){var a=i.extract_bits(1);this.ptl_sublayer_present_mask|=a<1;++r)i.extract_bits(1);for(this.sublayer_level_idc=[],r=this.num_sublayers-2;r>=0;--r)this.ptl_sublayer_present_mask&1<>=1;t+=h.decimalToHex(i,0),t+=".",0===this.hvcC.general_tier_flag?t+="L":t+="H",t+=this.hvcC.general_level_idc;var s=!1,n="";for(e=5;e>=0;e--)(this.hvcC.general_constraint_indicator[e]||s)&&(n="."+h.decimalToHex(this.hvcC.general_constraint_indicator[e],0)+n,s=!0);t+=n}return t},h.vvc1SampleEntry.prototype.getCodec=h.vvi1SampleEntry.prototype.getCodec=function(){var e,t=h.SampleEntry.prototype.getCodec.call(this);if(this.vvcC){t+="."+this.vvcC.general_profile_idc,this.vvcC.general_tier_flag?t+=".H":t+=".L",t+=this.vvcC.general_level_idc;var r="";if(this.vvcC.general_constraint_info){var i,s=[],n=0;for(n|=this.vvcC.ptl_frame_only_constraint<<7,n|=this.vvcC.ptl_multilayer_enabled<<6,e=0;e>2&63,s.push(n),n&&(i=e),n=this.vvcC.general_constraint_info[e]>>2&3;if(void 0===i)r=".CA";else{r=".C";var a="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",o=0,d=0;for(e=0;e<=i;++e)for(o=o<<8|s[e],d+=8;d>=5;){r+=a[o>>d-5&31],o&=(1<<(d-=5))-1}d&&(r+=a[31&(o<<=5-d)])}}t+=r}return t},h.mp4aSampleEntry.prototype.getCodec=function(){var e=h.SampleEntry.prototype.getCodec.call(this);if(this.esds&&this.esds.esd){var t=this.esds.esd.getOTI(),r=this.esds.esd.getAudioConfig();return e+"."+h.decimalToHex(t)+(r?"."+r:"")}return e},h.stxtSampleEntry.prototype.getCodec=function(){var e=h.SampleEntry.prototype.getCodec.call(this);return this.mime_format?e+"."+this.mime_format:e},h.vp08SampleEntry.prototype.getCodec=h.vp09SampleEntry.prototype.getCodec=function(){var e=h.SampleEntry.prototype.getCodec.call(this),t=this.vpcC.level;0==t&&(t="00");var r=this.vpcC.bitDepth;return 8==r&&(r="08"),e+".0"+this.vpcC.profile+"."+t+"."+r},h.av01SampleEntry.prototype.getCodec=function(){var e,t=h.SampleEntry.prototype.getCodec.call(this),r=this.av1C.seq_level_idx_0;return r<10&&(r="0"+r),2===this.av1C.seq_profile&&1===this.av1C.high_bitdepth?e=1===this.av1C.twelve_bit?"12":"10":this.av1C.seq_profile<=2&&(e=1===this.av1C.high_bitdepth?"10":"08"),t+"."+this.av1C.seq_profile+"."+r+(this.av1C.seq_tier_0?"H":"M")+"."+e},h.Box.prototype.writeHeader=function(e,t){this.size+=8,this.size>l&&(this.size+=8),"uuid"===this.type&&(this.size+=16),a.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+e.getPosition()+(t||"")),this.size>l?e.writeUint32(1):(this.sizePosition=e.getPosition(),e.writeUint32(this.size)),e.writeString(this.type,null,4),"uuid"===this.type&&e.writeUint8Array(this.uuid),this.size>l&&e.writeUint64(this.size)},h.FullBox.prototype.writeHeader=function(e){this.size+=4,h.Box.prototype.writeHeader.call(this,e," v="+this.version+" f="+this.flags),e.writeUint8(this.version),e.writeUint24(this.flags)},h.Box.prototype.write=function(e){"mdat"===this.type?this.data&&(this.size=this.data.length,this.writeHeader(e),e.writeUint8Array(this.data)):(this.size=this.data?this.data.length:0,this.writeHeader(e),this.data&&e.writeUint8Array(this.data))},h.ContainerBox.prototype.write=function(e){this.size=0,this.writeHeader(e);for(var t=0;t=2&&e.writeUint32(this.default_sample_description_index),e.writeUint32(this.entries.length),t=0;t0)for(t=0;t+1t?1:0,this.flags=0,this.size=4,1===this.version&&(this.size+=4),this.writeHeader(e),1===this.version?e.writeUint64(this.baseMediaDecodeTime):e.writeUint32(this.baseMediaDecodeTime)},h.tfhdBox.prototype.write=function(e){this.version=0,this.size=4,this.flags&h.TFHD_FLAG_BASE_DATA_OFFSET&&(this.size+=8),this.flags&h.TFHD_FLAG_SAMPLE_DESC&&(this.size+=4),this.flags&h.TFHD_FLAG_SAMPLE_DUR&&(this.size+=4),this.flags&h.TFHD_FLAG_SAMPLE_SIZE&&(this.size+=4),this.flags&h.TFHD_FLAG_SAMPLE_FLAGS&&(this.size+=4),this.writeHeader(e),e.writeUint32(this.track_id),this.flags&h.TFHD_FLAG_BASE_DATA_OFFSET&&e.writeUint64(this.base_data_offset),this.flags&h.TFHD_FLAG_SAMPLE_DESC&&e.writeUint32(this.default_sample_description_index),this.flags&h.TFHD_FLAG_SAMPLE_DUR&&e.writeUint32(this.default_sample_duration),this.flags&h.TFHD_FLAG_SAMPLE_SIZE&&e.writeUint32(this.default_sample_size),this.flags&h.TFHD_FLAG_SAMPLE_FLAGS&&e.writeUint32(this.default_sample_flags)},h.tkhdBox.prototype.write=function(e){this.version=0,this.size=80,this.writeHeader(e),e.writeUint32(this.creation_time),e.writeUint32(this.modification_time),e.writeUint32(this.track_id),e.writeUint32(0),e.writeUint32(this.duration),e.writeUint32(0),e.writeUint32(0),e.writeInt16(this.layer),e.writeInt16(this.alternate_group),e.writeInt16(this.volume<<8),e.writeUint16(0),e.writeInt32Array(this.matrix),e.writeUint32(this.width),e.writeUint32(this.height)},h.trexBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=20,this.writeHeader(e),e.writeUint32(this.track_id),e.writeUint32(this.default_sample_description_index),e.writeUint32(this.default_sample_duration),e.writeUint32(this.default_sample_size),e.writeUint32(this.default_sample_flags)},h.trunBox.prototype.write=function(e){this.version=0,this.size=4,this.flags&h.TRUN_FLAGS_DATA_OFFSET&&(this.size+=4),this.flags&h.TRUN_FLAGS_FIRST_FLAG&&(this.size+=4),this.flags&h.TRUN_FLAGS_DURATION&&(this.size+=4*this.sample_duration.length),this.flags&h.TRUN_FLAGS_SIZE&&(this.size+=4*this.sample_size.length),this.flags&h.TRUN_FLAGS_FLAGS&&(this.size+=4*this.sample_flags.length),this.flags&h.TRUN_FLAGS_CTS_OFFSET&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(e),e.writeUint32(this.sample_count),this.flags&h.TRUN_FLAGS_DATA_OFFSET&&(this.data_offset_position=e.getPosition(),e.writeInt32(this.data_offset)),this.flags&h.TRUN_FLAGS_FIRST_FLAG&&e.writeUint32(this.first_sample_flags);for(var t=0;t-1||e[r]instanceof h.Box||t[r]instanceof h.Box||void 0===e[r]||void 0===t[r]||"function"==typeof e[r]||"function"==typeof t[r]||e.subBoxNames&&e.subBoxNames.indexOf(r.slice(0,4))>-1||t.subBoxNames&&t.subBoxNames.indexOf(r.slice(0,4))>-1||"data"===r||"start"===r||"size"===r||"creation_time"===r||"modification_time"===r||h.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(r)>-1||e[r]===t[r]))return!1;return!0},h.boxEqual=function(e,t){if(!h.boxEqualFields(e,t))return!1;for(var r=0;r1)for(t=1;t-1&&this.fragmentedTracks.splice(t,1)},g.prototype.setExtractionOptions=function(e,t,r){var i=this.getTrackById(e);if(i){var s={};this.extractedTracks.push(s),s.id=e,s.user=t,s.trak=i,i.nextSample=0,s.nb_samples=1e3,s.samples=[],r&&r.nbSamples&&(s.nb_samples=r.nbSamples)}},g.prototype.unsetExtractionOptions=function(e){for(var t=-1,r=0;r-1&&this.extractedTracks.splice(t,1)},g.prototype.parse=function(){var e,t;if(!this.restoreParsePosition||this.restoreParsePosition())for(;;){if(this.hasIncompleteMdat&&this.hasIncompleteMdat()){if(this.processIncompleteMdat())continue;return}if(this.saveParsePosition&&this.saveParsePosition(),(e=h.parseOneBox(this.stream,false)).code===h.ERR_NOT_ENOUGH_DATA){if(this.processIncompleteBox){if(this.processIncompleteBox(e))continue;return}return}var r;switch(r="uuid"!==(t=e.box).type?t.type:t.uuid,this.boxes.push(t),r){case"mdat":this.mdats.push(t);break;case"moof":this.moofs.push(t);break;case"moov":this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0);default:void 0!==this[r]&&a.warn("ISOFile","Duplicate Box of type: "+r+", overriding previous occurrence"),this[r]=t}this.updateUsedBytes&&this.updateUsedBytes(t,e)}},g.prototype.checkBuffer=function(e){if(null==e)throw"Buffer must be defined and non empty";if(void 0===e.fileStart)throw"Buffer must have a fileStart property";return 0===e.byteLength?(a.warn("ISOFile","Ignoring empty buffer (fileStart: "+e.fileStart+")"),this.stream.logBufferLevel(),!1):(a.info("ISOFile","Processing buffer (fileStart: "+e.fileStart+")"),e.usedBytes=0,this.stream.insertBuffer(e),this.stream.logBufferLevel(),!!this.stream.initialized()||(a.warn("ISOFile","Not ready to start parsing"),!1))},g.prototype.appendBuffer=function(e,t){var r;if(this.checkBuffer(e))return this.parse(),this.moovStartFound&&!this.moovStartSent&&(this.moovStartSent=!0,this.onMoovStart&&this.onMoovStart()),this.moov?(this.sampleListBuilt||(this.buildSampleLists(),this.sampleListBuilt=!0),this.updateSampleLists(),this.onReady&&!this.readySent&&(this.readySent=!0,this.onReady(this.getInfo())),this.processSamples(t),this.nextSeekPosition?(r=this.nextSeekPosition,this.nextSeekPosition=void 0):r=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(r=this.stream.getEndFilePositionAfter(r))):r=this.nextParsePosition?this.nextParsePosition:0,this.sidx&&this.onSidx&&!this.sidxSent&&(this.onSidx(this.sidx),this.sidxSent=!0),this.meta&&(this.flattenItemInfo&&!this.itemListBuilt&&(this.flattenItemInfo(),this.itemListBuilt=!0),this.processItems&&this.processItems(this.onItem)),this.stream.cleanBuffers&&(a.info("ISOFile","Done processing buffer (fileStart: "+e.fileStart+") - next buffer to fetch should have a fileStart position of "+r),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),a.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),r},g.prototype.getInfo=function(){var e,t,r,i,s,n,a={},o=new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(a.hasMoov=!0,a.duration=this.moov.mvhd.duration,a.timescale=this.moov.mvhd.timescale,a.isFragmented=null!=this.moov.mvex,a.isFragmented&&this.moov.mvex.mehd&&(a.fragment_duration=this.moov.mvex.mehd.fragment_duration),a.isProgressive=this.isProgressive,a.hasIOD=null!=this.moov.iods,a.brands=[],a.brands.push(this.ftyp.major_brand),a.brands=a.brands.concat(this.ftyp.compatible_brands),a.created=new Date(o+1e3*this.moov.mvhd.creation_time),a.modified=new Date(o+1e3*this.moov.mvhd.modification_time),a.tracks=[],a.audioTracks=[],a.videoTracks=[],a.subtitleTracks=[],a.metadataTracks=[],a.hintTracks=[],a.otherTracks=[],e=0;e0?a.mime+='video/mp4; codecs="':a.audioTracks&&a.audioTracks.length>0?a.mime+='audio/mp4; codecs="':a.mime+='application/mp4; codecs="',e=0;e=r.samples.length)&&(a.info("ISOFile","Sending fragmented data on track #"+i.id+" for samples ["+Math.max(0,r.nextSample-i.nb_samples)+","+(r.nextSample-1)+"]"),a.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(i.id,i.user,i.segmentStream.buffer,r.nextSample,e||r.nextSample>=r.samples.length),i.segmentStream=null,i!==this.fragmentedTracks[t]))break}}if(null!==this.onSamples)for(t=0;t=r.samples.length)&&(a.debug("ISOFile","Sending samples on track #"+n.id+" for sample "+r.nextSample),this.onSamples&&this.onSamples(n.id,n.user,n.samples),n.samples=[],n!==this.extractedTracks[t]))break}}}},g.prototype.getBox=function(e){var t=this.getBoxes(e,!0);return t.length?t[0]:null},g.prototype.getBoxes=function(e,t){var r=[];return g._sweep.call(this,e,r,t),r},g._sweep=function(e,t,r){for(var i in this.type&&this.type==e&&t.push(this),this.boxes){if(t.length&&r)return;g._sweep.call(this.boxes[i],e,t,r)}},g.prototype.getTrackSamplesInfo=function(e){var t=this.getTrackById(e);return t?t.samples:void 0},g.prototype.getTrackSample=function(e,t){var r=this.getTrackById(e);return this.getSample(r,t)},g.prototype.releaseUsedSamples=function(e,t){var r=0,i=this.getTrackById(e);i.lastValidSample||(i.lastValidSample=0);for(var s=i.lastValidSample;se*s.timescale){l=i-1;break}t&&s.is_sync&&(d=i)}for(t&&(l=d),e=r.samples[l].cts,r.nextSample=l;r.samples[l].alreadyRead===r.samples[l].size&&r.samples[l+1];)l++;return n=r.samples[l].offset+r.samples[l].alreadyRead,a.info("ISOFile","Seeking to "+(t?"RAP":"")+" sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(e,o)+" and offset: "+n),{offset:n,time:e/o}},g.prototype.getTrackDuration=function(e){var t;return e.samples?((t=e.samples[e.samples.length-1]).cts+t.duration)/t.timescale:1/0},g.prototype.seek=function(e,t){var r,i,s,n=this.moov,o={offset:1/0,time:1/0};if(this.moov){for(s=0;sthis.getTrackDuration(r)||((i=this.seekTrack(e,t,r)).offset-1){a=d;break}switch(a){case"Visual":if(s.add("vmhd").set("graphicsmode",0).set("opcolor",[0,0,0]),n.set("width",t.width).set("height",t.height).set("horizresolution",72<<16).set("vertresolution",72<<16).set("frame_count",1).set("compressorname",t.type+" Compressor").set("depth",24),t.avcDecoderConfigRecord){var c=new h.avcCBox;c.parse(new o(t.avcDecoderConfigRecord)),n.addBox(c)}else if(t.hevcDecoderConfigRecord){var f=new h.hvcCBox;f.parse(new o(t.hevcDecoderConfigRecord)),n.addBox(f)}break;case"Audio":s.add("smhd").set("balance",t.balance||0),n.set("channel_count",t.channel_count||2).set("samplesize",t.samplesize||16).set("samplerate",t.samplerate||65536);break;case"Hint":s.add("hmhd");break;case"Subtitle":if(s.add("sthd"),"stpp"===t.type)n.set("namespace",t.namespace||"nonamespace").set("schema_location",t.schema_location||"").set("auxiliary_mime_types",t.auxiliary_mime_types||"");break;default:s.add("nmhd")}t.description&&n.addBox(t.description),t.description_boxes&&t.description_boxes.forEach((function(e){n.addBox(e)})),s.add("dinf").add("dref").addEntry((new h["url Box"]).set("flags",1));var p=s.add("stbl");return p.add("stsd").addEntry(n),p.add("stts").set("sample_counts",[]).set("sample_deltas",[]),p.add("stsc").set("first_chunk",[]).set("samples_per_chunk",[]).set("sample_description_index",[]),p.add("stco").set("chunk_offsets",[]),p.add("stsz").set("sample_sizes",[]),this.moov.mvex.add("trex").set("track_id",t.id).set("default_sample_description_index",t.default_sample_description_index||1).set("default_sample_duration",t.default_sample_duration||0).set("default_sample_size",t.default_sample_size||0).set("default_sample_flags",t.default_sample_flags||0),this.buildTrakSampleLists(r),t.id}},h.Box.prototype.computeSize=function(e){var t=e||new d;t.endianness=d.BIG_ENDIAN,this.write(t)},g.prototype.addSample=function(e,t,r){var i=r||{},s={},n=this.getTrackById(e);if(null!==n){s.number=n.samples.length,s.track_id=n.tkhd.track_id,s.timescale=n.mdia.mdhd.timescale,s.description_index=i.sample_description_index?i.sample_description_index-1:0,s.description=n.mdia.minf.stbl.stsd.entries[s.description_index],s.data=t,s.size=t.byteLength,s.alreadyRead=s.size,s.duration=i.duration||1,s.cts=i.cts||0,s.dts=i.dts||0,s.is_sync=i.is_sync||!1,s.is_leading=i.is_leading||0,s.depends_on=i.depends_on||0,s.is_depended_on=i.is_depended_on||0,s.has_redundancy=i.has_redundancy||0,s.degradation_priority=i.degradation_priority||0,s.offset=0,s.subsamples=i.subsamples,n.samples.push(s),n.samples_size+=s.size,n.samples_duration+=s.duration,void 0===n.first_dts&&(n.first_dts=i.dts),this.processSamples();var a=this.createSingleSampleMoof(s);return this.addBox(a),a.computeSize(),a.trafs[0].truns[0].data_offset=a.size+8,this.add("mdat").data=new Uint8Array(t),s}},g.prototype.createSingleSampleMoof=function(e){var t=0;t=e.is_sync?1<<25:65536;var r=new h.moofBox;r.add("mfhd").set("sequence_number",this.nextMoofNumber),this.nextMoofNumber++;var i=r.add("traf"),s=this.getTrackById(e.track_id);return i.add("tfhd").set("track_id",e.track_id).set("flags",h.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),i.add("tfdt").set("baseMediaDecodeTime",e.dts-(s.first_dts||0)),i.add("trun").set("flags",h.TRUN_FLAGS_DATA_OFFSET|h.TRUN_FLAGS_DURATION|h.TRUN_FLAGS_SIZE|h.TRUN_FLAGS_FLAGS|h.TRUN_FLAGS_CTS_OFFSET).set("data_offset",0).set("first_sample_flags",0).set("sample_count",1).set("sample_duration",[e.duration]).set("sample_size",[e.size]).set("sample_flags",[t]).set("sample_composition_time_offset",[e.cts-e.dts]),r},g.prototype.lastMoofIndex=0,g.prototype.samplesDataSize=0,g.prototype.resetTables=function(){var e,t,r,i,s,n;for(this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0,e=0;e=2&&(d=s[a].grouping_type+"/0",(o=new l(s[a].grouping_type,0)).is_fragment=!0,t.sample_groups_info[d]||(t.sample_groups_info[d]=o))}else for(a=0;a=2&&(d=i[a].grouping_type+"/0",o=new l(i[a].grouping_type,0),e.sample_groups_info[d]||(e.sample_groups_info[d]=o))},g.setSampleGroupProperties=function(e,t,r,i){var s,n;for(s in t.sample_groups=[],i){var a;if(t.sample_groups[s]={},t.sample_groups[s].grouping_type=i[s].grouping_type,t.sample_groups[s].grouping_type_parameter=i[s].grouping_type_parameter,r>=i[s].last_sample_in_run&&(i[s].last_sample_in_run<0&&(i[s].last_sample_in_run=0),i[s].entry_index++,i[s].entry_index<=i[s].sbgp.entries.length-1&&(i[s].last_sample_in_run+=i[s].sbgp.entries[i[s].entry_index].sample_count)),i[s].entry_index<=i[s].sbgp.entries.length-1?t.sample_groups[s].group_description_index=i[s].sbgp.entries[i[s].entry_index].group_description_index:t.sample_groups[s].group_description_index=-1,0!==t.sample_groups[s].group_description_index)a=i[s].fragment_description?i[s].fragment_description:i[s].description,t.sample_groups[s].group_description_index>0?(n=t.sample_groups[s].group_description_index>65535?(t.sample_groups[s].group_description_index>>16)-1:t.sample_groups[s].group_description_index-1,a&&n>=0&&(t.sample_groups[s].description=a.entries[n])):a&&a.version>=2&&a.default_group_description_index>0&&(t.sample_groups[s].description=a.entries[a.default_group_description_index-1])}},g.process_sdtp=function(e,t,r){t&&(e?(t.is_leading=e.is_leading[r],t.depends_on=e.sample_depends_on[r],t.is_depended_on=e.sample_is_depended_on[r],t.has_redundancy=e.sample_has_redundancy[r]):(t.is_leading=0,t.depends_on=0,t.is_depended_on=0,t.has_redundancy=0))},g.prototype.buildSampleLists=function(){var e,t;for(e=0;eb&&(v++,b<0&&(b=0),b+=n.sample_counts[v]),t>0?(e.samples[t-1].duration=n.sample_deltas[v],e.samples_duration+=e.samples[t-1].duration,x.dts=e.samples[t-1].dts+e.samples[t-1].duration):x.dts=0,a?(t>=w&&(S++,w<0&&(w=0),w+=a.sample_counts[S]),x.cts=e.samples[t].dts+a.sample_offsets[S]):x.cts=x.dts,o?(t==o.sample_numbers[E]-1?(x.is_sync=!0,E++):(x.is_sync=!1,x.degradation_priority=0),l&&l.entries[A].sample_delta+U==t+1&&(x.subsamples=l.entries[A].subsamples,U+=l.entries[A].sample_delta,A++)):x.is_sync=!0,g.process_sdtp(e.mdia.minf.stbl.sdtp,x,x.number),x.degradation_priority=h?h.priority[t]:0,l&&l.entries[A].sample_delta+U==t&&(x.subsamples=l.entries[A].subsamples,U+=l.entries[A].sample_delta),(u.length>0||c.length>0)&&g.setSampleGroupProperties(e,x,t,e.sample_groups_info)}t>0&&(e.samples[t-1].duration=Math.max(e.mdia.mdhd.duration-e.samples[t-1].dts,0),e.samples_duration+=e.samples[t-1].duration)}},g.prototype.updateSampleLists=function(){var e,t,r,i,s,n,a,o,d,l,u,c,f,p,m;if(void 0!==this.moov)for(;this.lastMoofIndex0&&g.initSampleGroups(c,u,u.sbgps,c.mdia.minf.stbl.sgpds,u.sgpds),t=0;t0?p.dts=c.samples[c.samples.length-2].dts+c.samples[c.samples.length-2].duration:(u.tfdt?p.dts=u.tfdt.baseMediaDecodeTime:p.dts=0,c.first_traf_merged=!0),p.cts=p.dts,_.flags&h.TRUN_FLAGS_CTS_OFFSET&&(p.cts=p.dts+_.sample_composition_time_offset[r]),m=a,_.flags&h.TRUN_FLAGS_FLAGS?m=_.sample_flags[r]:0===r&&_.flags&h.TRUN_FLAGS_FIRST_FLAG&&(m=_.first_sample_flags),p.is_sync=!(m>>16&1),p.is_leading=m>>26&3,p.depends_on=m>>24&3,p.is_depended_on=m>>22&3,p.has_redundancy=m>>20&3,p.degradation_priority=65535&m;var y=!!(u.tfhd.flags&h.TFHD_FLAG_BASE_DATA_OFFSET),b=!!(u.tfhd.flags&h.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),v=!!(_.flags&h.TRUN_FLAGS_DATA_OFFSET),w=0;w=y?u.tfhd.base_data_offset:b||0===t?l.start:o,p.offset=0===t&&0===r?v?w+_.data_offset:w:o,o=p.offset+p.size,(u.sbgps.length>0||u.sgpds.length>0||c.mdia.minf.stbl.sbgps.length>0||c.mdia.minf.stbl.sgpds.length>0)&&g.setSampleGroupProperties(c,p,p.number_in_traf,u.sample_groups_info)}}if(u.subs){c.has_fragment_subsamples=!0;var S=u.first_sample_index;for(t=0;t-1))return null;var n=(r=this.stream.buffers[s]).byteLength-(i.offset+i.alreadyRead-r.fileStart);if(i.size-i.alreadyRead<=n)return a.debug("ISOFile","Getting sample #"+t+" data (alreadyRead: "+i.alreadyRead+" offset: "+(i.offset+i.alreadyRead-r.fileStart)+" read size: "+(i.size-i.alreadyRead)+" full size: "+i.size+")"),d.memcpy(i.data.buffer,i.alreadyRead,r,i.offset+i.alreadyRead-r.fileStart,i.size-i.alreadyRead),r.usedBytes+=i.size-i.alreadyRead,this.stream.logBufferLevel(),i.alreadyRead=i.size,i;if(0===n)return null;a.debug("ISOFile","Getting sample #"+t+" partial data (alreadyRead: "+i.alreadyRead+" offset: "+(i.offset+i.alreadyRead-r.fileStart)+" read size: "+n+" full size: "+i.size+")"),d.memcpy(i.data.buffer,i.alreadyRead,r,i.offset+i.alreadyRead-r.fileStart,n),i.alreadyRead+=n,r.usedBytes+=n,this.stream.logBufferLevel()}},g.prototype.releaseSample=function(e,t){var r=e.samples[t];return r.data?(this.samplesDataSize-=r.size,r.data=null,r.alreadyRead=0,r.size):0},g.prototype.getAllocatedSampleDataSize=function(){return this.samplesDataSize},g.prototype.getCodecs=function(){var e,t="";for(e=0;e0&&(t+=","),t+=this.moov.traks[e].mdia.minf.stbl.stsd.entries[0].getCodec()}return t},g.prototype.getTrexById=function(e){var t;if(!this.moov||!this.moov.mvex)return null;for(t=0;t0&&(r.protection=n.ipro.protections[n.iinf.item_infos[e].protection_index-1]),n.iinf.item_infos[e].item_type?r.type=n.iinf.item_infos[e].item_type:r.type="mime",r.content_type=n.iinf.item_infos[e].content_type,r.content_encoding=n.iinf.item_infos[e].content_encoding;if(n.grpl)for(e=0;e0&&h.property_index-1-1))return null;var o=(t=this.stream.buffers[n]).byteLength-(s.offset+s.alreadyRead-t.fileStart);if(!(s.length-s.alreadyRead<=o))return a.debug("ISOFile","Getting item #"+e+" extent #"+i+" partial data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-t.fileStart)+" read size: "+o+" full extent size: "+s.length+" full item size: "+r.size+")"),d.memcpy(r.data.buffer,r.alreadyRead,t,s.offset+s.alreadyRead-t.fileStart,o),s.alreadyRead+=o,r.alreadyRead+=o,t.usedBytes+=o,this.stream.logBufferLevel(),null;a.debug("ISOFile","Getting item #"+e+" extent #"+i+" data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-t.fileStart)+" read size: "+(s.length-s.alreadyRead)+" full extent size: "+s.length+" full item size: "+r.size+")"),d.memcpy(r.data.buffer,r.alreadyRead,t,s.offset+s.alreadyRead-t.fileStart,s.length-s.alreadyRead),t.usedBytes+=s.length-s.alreadyRead,this.stream.logBufferLevel(),r.alreadyRead+=s.length-s.alreadyRead,s.alreadyRead=s.length}}return r.alreadyRead===r.size?r:null},g.prototype.releaseItem=function(e){var t=this.items[e];if(t.data){this.itemsDataSize-=t.size,t.data=null,t.alreadyRead=0;for(var r=0;r0?this.moov.traks[e].samples[0].duration:0),t.push(i)}return t},h.Box.prototype.printHeader=function(e){this.size+=8,this.size>l&&(this.size+=8),"uuid"===this.type&&(this.size+=16),e.log(e.indent+"size:"+this.size),e.log(e.indent+"type:"+this.type)},h.FullBox.prototype.printHeader=function(e){this.size+=4,h.Box.prototype.printHeader.call(this,e),e.log(e.indent+"version:"+this.version),e.log(e.indent+"flags:"+this.flags)},h.Box.prototype.print=function(e){this.printHeader(e)},h.ContainerBox.prototype.print=function(e){this.printHeader(e);for(var t=0;t>8)),e.log(e.indent+"matrix: "+this.matrix.join(", ")),e.log(e.indent+"next_track_id: "+this.next_track_id)},h.tkhdBox.prototype.print=function(e){h.FullBox.prototype.printHeader.call(this,e),e.log(e.indent+"creation_time: "+this.creation_time),e.log(e.indent+"modification_time: "+this.modification_time),e.log(e.indent+"track_id: "+this.track_id),e.log(e.indent+"duration: "+this.duration),e.log(e.indent+"volume: "+(this.volume>>8)),e.log(e.indent+"matrix: "+this.matrix.join(", ")),e.log(e.indent+"layer: "+this.layer),e.log(e.indent+"alternate_group: "+this.alternate_group),e.log(e.indent+"width: "+this.width),e.log(e.indent+"height: "+this.height)};var y={createFile:function(e,t){var r=void 0===e||e,i=new g(t);return i.discardMdatData=!r,i}};t.createFile=y.createFile}));function Oi(e){return e.reduce(((e,t)=>256*e+t))}function Gi(e){const t=[101,103,119,99],r=e.length-28,i=e.slice(r,r+t.length);return t.every(((e,t)=>e===i[t]))}Ni.Log,Ni.MP4BoxStream,Ni.DataStream,Ni.MultiBufferStream,Ni.MPEG4DescriptorParser,Ni.BoxParser,Ni.XMLSubtitlein4Parser,Ni.Textin4Parser,Ni.ISOFile,Ni.createFile;class $i{constructor(){this.s=null,this.a=null,this.l=0,this.c=0,this.u=1/0,this.A=!1,this.d=!1,this.r=4194304,this.n=new Uint8Array([30,158,90,33,244,57,83,165,2,70,35,87,215,231,226,108]),this.t=this.n.slice().reverse()}destroy(){this.s=null,this.a=null,this.l=0,this.c=0,this.u=1/0,this.A=!1,this.d=!1,this.r=4194304,this.n=null,this.t=null}transport(e){if(!this.s&&this.l>50)return e;if(this.l++,this.d)return e;const t=new Uint8Array(e);if(this.A){if(!(this.c~e))}(e.slice(r+32,r+32+t))]}return null}(t,this.t);if(!r)return e;const i=function(e){try{if("object"!=typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)throw null;{const e=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(!(e instanceof WebAssembly.Module&&new WebAssembly.Instance(e)instanceof WebAssembly.Instance))throw null}}catch(e){return new Error("video_error_4")}let t;try{t={env:{__handle_stack_overflow:()=>e(new Error("video_error_1")),memory:new WebAssembly.Memory({initial:256,maximum:256})}}}catch(e){return new Error("video_error_5")}return t}(e);if(i instanceof Error)return console.error(i.message),this.d=!0,e;this.A=!0,this.u=r[1],Gi(t)&&this.c++,WebAssembly.instantiate(r[2],i).then((e=>{if("function"!=typeof(t=e.instance.exports).parse||"object"!=typeof t.memory)return this.d=!0,void console.error("video_error_3");var t;this.s=e.instance.exports,this.a=new Uint8Array(this.s.memory.buffer)})).catch((e=>{this.d=!0,console.error("video_error_6")}))}return e}}const Hi=16,Vi=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],Wi=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];function ji(e){const t=[];for(let r=0,i=e.length;r1===(e=e.toString(16)).length?"0"+e:e)).join("")}function Yi(e){const t=[];for(let r=0,i=e.length;r>>6),t.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)t.push(224|i>>>12),t.push(128|i>>>6&63),t.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw t.push(i),new Error("input is not supported");r++,t.push(240|i>>>18&28),t.push(128|i>>>12&63),t.push(128|i>>>6&63),t.push(128|63&i)}}return t}function Ki(e){const t=[];for(let r=0,i=e.length;r=240&&e[r]<=247?(t.push(String.fromCodePoint(((7&e[r])<<18)+((63&e[r+1])<<12)+((63&e[r+2])<<6)+(63&e[r+3]))),r+=3):e[r]>=224&&e[r]<=239?(t.push(String.fromCodePoint(((15&e[r])<<12)+((63&e[r+1])<<6)+(63&e[r+2]))),r+=2):e[r]>=192&&e[r]<=223?(t.push(String.fromCodePoint(((31&e[r])<<6)+(63&e[r+1]))),r++):t.push(String.fromCodePoint(e[r]));return t.join("")}function Xi(e,t){const r=31&t;return e<>>32-r}function Zi(e){return(255&Vi[e>>>24&255])<<24|(255&Vi[e>>>16&255])<<16|(255&Vi[e>>>8&255])<<8|255&Vi[255&e]}function Ji(e){return e^Xi(e,2)^Xi(e,10)^Xi(e,18)^Xi(e,24)}function Qi(e){return e^Xi(e,13)^Xi(e,23)}function es(e,t,r){const i=new Array(4),s=new Array(4);for(let t=0;t<4;t++)s[0]=255&e[4*t],s[1]=255&e[4*t+1],s[2]=255&e[4*t+2],s[3]=255&e[4*t+3],i[t]=s[0]<<24|s[1]<<16|s[2]<<8|s[3];for(let e,t=0;t<32;t+=4)e=i[1]^i[2]^i[3]^r[t+0],i[0]^=Ji(Zi(e)),e=i[2]^i[3]^i[0]^r[t+1],i[1]^=Ji(Zi(e)),e=i[3]^i[0]^i[1]^r[t+2],i[2]^=Ji(Zi(e)),e=i[0]^i[1]^i[2]^r[t+3],i[3]^=Ji(Zi(e));for(let e=0;e<16;e+=4)t[e]=i[3-e/4]>>>24&255,t[e+1]=i[3-e/4]>>>16&255,t[e+2]=i[3-e/4]>>>8&255,t[e+3]=255&i[3-e/4]}function ts(e,t,r){const i=new Array(4),s=new Array(4);for(let t=0;t<4;t++)s[0]=255&e[0+4*t],s[1]=255&e[1+4*t],s[2]=255&e[2+4*t],s[3]=255&e[3+4*t],i[t]=s[0]<<24|s[1]<<16|s[2]<<8|s[3];i[0]^=2746333894,i[1]^=1453994832,i[2]^=1736282519,i[3]^=2993693404;for(let e,r=0;r<32;r+=4)e=i[1]^i[2]^i[3]^Wi[r+0],t[r+0]=i[0]^=Qi(Zi(e)),e=i[2]^i[3]^i[0]^Wi[r+1],t[r+1]=i[1]^=Qi(Zi(e)),e=i[3]^i[0]^i[1]^Wi[r+2],t[r+2]=i[2]^=Qi(Zi(e)),e=i[0]^i[1]^i[2]^Wi[r+3],t[r+3]=i[3]^=Qi(Zi(e));if(0===r)for(let e,r=0;r<16;r++)e=t[r],t[r]=t[31-r],t[31-r]=e}function rs(e,t,r){let{padding:i="pkcs#7",mode:s,iv:n=[],output:a="string"}=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("cbc"===s&&("string"==typeof n&&(n=ji(n)),16!==n.length))throw new Error("iv is invalid");if("string"==typeof t&&(t=ji(t)),16!==t.length)throw new Error("key is invalid");if(e="string"==typeof e?0!==r?Yi(e):ji(e):[...e],("pkcs#5"===i||"pkcs#7"===i)&&0!==r){const t=Hi-e.length%Hi;for(let r=0;r=Hi;){const t=e.slice(c,c+16),i=new Array(16);if("cbc"===s)for(let e=0;e2&&void 0!==arguments[2]&&arguments[2];const i=e.byteLength;let s=5;for(;si)break;let a=e[s+4],o=!1;if(r?(a=a>>>1&63,o=[0,1,2,3,4,5,6,7,8,9,16,17,18,19,20,21].includes(a)):(a&=31,o=1===a||5===a),o){const r=rs(e.slice(s+4+2,s+4+n),t,0,{padding:"none",output:"array"});e.set(r,s+4+2)}s=s+4+n}return e}const ns={init:0,findFirstStartCode:1,findSecondStartCode:2};class as extends class{on(e,t,r){const i=this.e||(this.e={});return(i[e]||(i[e]=[])).push({fn:t,ctx:r}),this}once(e,t,r){const i=this;function s(){i.off(e,s);for(var n=arguments.length,a=new Array(n),o=0;o1?r-1:0),s=1;s{delete r[e]})),void delete this.e;const i=r[e],s=[];if(i&&t)for(let e=0,r=i.length;e=2&&!this.isDestroyed;)if(255==this.tempBuffer[this.parsedOffset]){if(!(!1&this.tempBuffer[this.parsedOffset+1])){this.versionLayer=this.tempBuffer[this.parsedOffset+1],this.state=ns.findFirstStartCode,this.fisrtStartCodeOffset=this.parsedOffset,this.parsedOffset+=2,e=!0;break}this.parsedOffset++}else this.parsedOffset++;if(e)continue;break}if(this.state==ns.findFirstStartCode){let e=!1;for(;this.tempBuffer.length-this.parsedOffset>=2&&!this.isDestroyed;)if(255==this.tempBuffer[this.parsedOffset]){if(this.tempBuffer[this.parsedOffset+1]==this.versionLayer){this.state=ns.findSecondStartCode,this.secondStartCodeOffset=this.parsedOffset,this.parsedOffset+=2,e=!0;break}this.parsedOffset++}else this.parsedOffset++;if(e)continue;break}if(this.state==ns.findSecondStartCode){let e=this.tempBuffer.slice(this.fisrtStartCodeOffset,this.secondStartCodeOffset);this.emit("data",e,t),this.tempBuffer=this.tempBuffer.slice(this.secondStartCodeOffset),this.fisrtStartCodeOffset=0,this.parsedOffset=2,this.state=ns.findFirstStartCode}}}}function os(e,t,r){for(let i=2;i3&&void 0!==arguments[3]&&arguments[3];const s=e.byteLength;let n=5;for(;ns)break;let o=e[n+4],d=!1;if(i?(o=o>>>1&63,d=[0,1,2,3,4,5,6,7,8,9,16,17,18,19,20,21].includes(o)):(o&=31,d=1===o||5===o),d){const i=os(e.slice(n+4,n+4+a),t,r);e.set(i,n+4)}n=n+4+a}return e}function us(){for(var e=arguments.length,t=new Array(e),r=0;re+t.byteLength),0));let s=0;return t.forEach((e=>{i.set(e,s),s+=e.byteLength})),i}class cs{constructor(e){this.destroys=[],this.proxy=this.proxy.bind(this),this.master=e}proxy(e,t,r){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(!e)return;if(Array.isArray(t))return t.map((t=>this.proxy(e,t,r,i)));e.addEventListener(t,r,i);const s=()=>{lr(e.removeEventListener)&&e.removeEventListener(t,r,i)};return this.destroys.push(s),s}destroy(){this.master.debug&&this.master.debug.log("Events","destroy"),this.destroys.forEach((e=>e())),this.destroys=[]}}class hs{static init(){hs.types={avc1:[],avcC:[],hvc1:[],hvcC:[],av01:[],av1C:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[],".mp3":[],Opus:[],dOps:[],"ac-3":[],dac3:[],"ec-3":[],dec3:[]};for(let e in hs.types)hs.types.hasOwnProperty(e)&&(hs.types[e]=[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]);let e=hs.constants={};e.FTYP=new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]),e.STSD_PREFIX=new Uint8Array([0,0,0,0,0,0,0,1]),e.STTS=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSC=e.STCO=e.STTS,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.HDLR_VIDEO=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),e.HDLR_AUDIO=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]),e.DREF=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0])}static box(e){let t=8,r=null,i=Array.prototype.slice.call(arguments,1),s=i.length;for(let e=0;e>>24&255,r[1]=t>>>16&255,r[2]=t>>>8&255,r[3]=255&t,r.set(e,4);let n=8;for(let e=0;e>>24&255,e>>>16&255,e>>>8&255,255&e,t>>>24&255,t>>>16&255,t>>>8&255,255&t,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]))}static trak(e){return hs.box(hs.types.trak,hs.tkhd(e),hs.mdia(e))}static tkhd(e){let t=e.id,r=e.duration,i=e.presentWidth,s=e.presentHeight;return hs.box(hs.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,t>>>24&255,t>>>16&255,t>>>8&255,255&t,0,0,0,0,r>>>24&255,r>>>16&255,r>>>8&255,255&r,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,i>>>8&255,255&i,0,0,s>>>8&255,255&s,0,0]))}static mdia(e){return hs.box(hs.types.mdia,hs.mdhd(e),hs.hdlr(e),hs.minf(e))}static mdhd(e){let t=e.timescale,r=e.duration;return hs.box(hs.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,t>>>24&255,t>>>16&255,t>>>8&255,255&t,r>>>24&255,r>>>16&255,r>>>8&255,255&r,85,196,0,0]))}static hdlr(e){let t=null;return t="audio"===e.type?hs.constants.HDLR_AUDIO:hs.constants.HDLR_VIDEO,hs.box(hs.types.hdlr,t)}static minf(e){let t=null;return t="audio"===e.type?hs.box(hs.types.smhd,hs.constants.SMHD):hs.box(hs.types.vmhd,hs.constants.VMHD),hs.box(hs.types.minf,t,hs.dinf(),hs.stbl(e))}static dinf(){return hs.box(hs.types.dinf,hs.box(hs.types.dref,hs.constants.DREF))}static stbl(e){return hs.box(hs.types.stbl,hs.stsd(e),hs.box(hs.types.stts,hs.constants.STTS),hs.box(hs.types.stsc,hs.constants.STSC),hs.box(hs.types.stsz,hs.constants.STSZ),hs.box(hs.types.stco,hs.constants.STCO))}static stsd(e){return"audio"===e.type?"mp3"===e.audioType?hs.box(hs.types.stsd,hs.constants.STSD_PREFIX,hs.mp3(e)):hs.box(hs.types.stsd,hs.constants.STSD_PREFIX,hs.mp4a(e)):"avc"===e.videoType?hs.box(hs.types.stsd,hs.constants.STSD_PREFIX,hs.avc1(e)):hs.box(hs.types.stsd,hs.constants.STSD_PREFIX,hs.hvc1(e))}static mp3(e){let t=e.channelCount,r=e.audioSampleRate,i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t,0,16,0,0,0,0,r>>>8&255,255&r,0,0]);return hs.box(hs.types[".mp3"],i)}static mp4a(e){let t=e.channelCount,r=e.audioSampleRate,i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t,0,16,0,0,0,0,r>>>8&255,255&r,0,0]);return hs.box(hs.types.mp4a,i,hs.esds(e))}static esds(e){let t=e.config||[],r=t.length,i=new Uint8Array([0,0,0,0,3,23+r,0,1,0,4,15+r,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([r]).concat(t).concat([6,1,2]));return hs.box(hs.types.esds,i)}static avc1(e){let t=e.avcc;const r=e.codecWidth,i=e.codecHeight;let s=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,r>>>8&255,255&r,i>>>8&255,255&i,0,72,0,0,0,72,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,255,255]);return hs.box(hs.types.avc1,s,hs.box(hs.types.avcC,t))}static hvc1(e){let t=e.avcc;const r=e.codecWidth,i=e.codecHeight;let s=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,r>>>8&255,255&r,i>>>8&255,255&i,0,72,0,0,0,72,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,255,255]);return hs.box(hs.types.hvc1,s,hs.box(hs.types.hvcC,t))}static mvex(e){return hs.box(hs.types.mvex,hs.trex(e))}static trex(e){let t=e.id,r=new Uint8Array([0,0,0,0,t>>>24&255,t>>>16&255,t>>>8&255,255&t,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]);return hs.box(hs.types.trex,r)}static moof(e,t){return hs.box(hs.types.moof,hs.mfhd(e.sequenceNumber),hs.traf(e,t))}static mfhd(e){let t=new Uint8Array([0,0,0,0,e>>>24&255,e>>>16&255,e>>>8&255,255&e]);return hs.box(hs.types.mfhd,t)}static traf(e,t){let r=e.id,i=hs.box(hs.types.tfhd,new Uint8Array([0,0,0,0,r>>>24&255,r>>>16&255,r>>>8&255,255&r])),s=hs.box(hs.types.tfdt,new Uint8Array([0,0,0,0,t>>>24&255,t>>>16&255,t>>>8&255,255&t])),n=hs.sdtp(e),a=hs.trun(e,n.byteLength+16+16+8+16+8+8);return hs.box(hs.types.traf,i,s,a,n)}static sdtp(e){let t=new Uint8Array(5),r=e.flags;return t[4]=r.isLeading<<6|r.dependsOn<<4|r.isDependedOn<<2|r.hasRedundancy,hs.box(hs.types.sdtp,t)}static trun(e,t){let r=new Uint8Array(28);t+=36,r.set([0,0,15,1,0,0,0,1,t>>>24&255,t>>>16&255,t>>>8&255,255&t],0);let i=e.duration,s=e.size,n=e.flags,a=e.cts;return r.set([i>>>24&255,i>>>16&255,i>>>8&255,255&i,s>>>24&255,s>>>16&255,s>>>8&255,255&s,n.isLeading<<2|n.dependsOn,n.isDependedOn<<6|n.hasRedundancy<<4|n.isNonSync,0,0,a>>>24&255,a>>>16&255,a>>>8&255,255&a],12),hs.box(hs.types.trun,r)}static mdat(e){return hs.box(hs.types.mdat,e)}}hs.init();var fs,ps=Nt((function(e){e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports}));(fs=ps)&&fs.__esModule&&Object.prototype.hasOwnProperty.call(fs,"default")&&fs.default;const ms=[44100,48e3,32e3,0],_s=[22050,24e3,16e3,0],gs=[11025,12e3,8e3,0],ys=[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1],bs=[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1],vs=[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1];function ws(e){if(e.length<4)return void console.error("Invalid MP3 packet, header missing!");let t=new Uint8Array(e.buffer),r=null;if(255!==t[0])return void console.error("Invalid MP3 packet, first byte != 0xFF ");let i=t[1]>>>3&3,s=(6&t[1])>>1,n=(240&t[2])>>>4,a=(12&t[2])>>>2,o=3!==(t[3]>>>6&3)?2:1,d=0,l=0;switch(i){case 0:d=gs[a];break;case 2:d=_s[a];break;case 3:d=ms[a]}switch(s){case 1:n=e[s]&&t=6?(i=5,t=new Array(4),a=s-3):(i=2,t=new Array(2),a=s):-1!==o.indexOf("android")?(i=2,t=new Array(2),a=s):(i=5,a=s,t=new Array(4),s>=6?a=s-3:1===n&&(i=2,t=new Array(2),a=s)),t[0]=i<<3,t[0]|=(15&s)>>>1,t[1]=(15&s)<<7,t[1]|=(15&n)<<3,5===i&&(t[1]|=(15&a)>>>1,t[2]=(1&a)<<7,t[2]|=8,t[3]=0),this.config=t,this.sampling_rate=Ms[s],this.sampling_index=s,this.channel_count=n,this.object_type=i,this.original_object_type=r,this.codec_mimetype="mp4a.40."+i,this.original_codec_mimetype="mp4a.40."+r}}Date.now||(Date.now=function(){return(new Date).getTime()}),t({printErr:function(e){console.warn("JbPro[❌❌❌][worker]:",e)}}).then((e=>{!function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=[],s=[],n={},a=new AbortController,o=null,d=null,l=null,y=null,b=!1,E=null,ge=null,ye=!1,Ge=!1,qe=!!gr(r),Ye=!1,Xe=null,Je=null,at=null,ft=[],pt=null,mt=null,_t=0,Et=0,At=null,Bt=null,Nt=0,Ot=0,Gt=!1,$t=!1,qt=!1,Zt=null,ir=null,wr=null,Sr=!1,Er=!0,Ar=()=>{const e=mr();return{debug:e.debug,debugLevel:e.debugLevel,debugUuid:e.debugUuid,useOffscreen:e.useOffscreen,useWCS:e.useWCS,useMSE:e.useMSE,videoBuffer:e.videoBuffer,videoBufferDelay:e.videoBufferDelay,openWebglAlignment:e.openWebglAlignment,playType:e.playType,hasAudio:e.hasAudio,hasVideo:e.hasVideo,playbackRate:1,playbackForwardMaxRateDecodeIFrame:e.playbackForwardMaxRateDecodeIFrame,playbackIsCacheBeforeDecodeForFpsRender:e.playbackConfig.isCacheBeforeDecodeForFpsRender,sampleRate:0,networkDelay:e.networkDelay,visibility:!0,useSIMD:e.useSIMD,isRecording:!1,recordType:e.recordType,isNakedFlow:e.isNakedFlow,checkFirstIFrame:e.checkFirstIFrame,audioBufferSize:1024,isM7sCrypto:e.isM7sCrypto,m7sCryptoAudio:e.m7sCryptoAudio,cryptoKey:e.cryptoKey,cryptoIV:e.cryptoIV,isSm4Crypto:e.isSm4Crypto,sm4CryptoKey:e.sm4CryptoKey,isXorCrypto:e.isXorCrypto,isHls265:!1,isFlv:e.isFlv,isFmp4:e.isFmp4,isMpeg4:e.isMpeg4,isTs:e.isTs,isFmp4Private:e.isFmp4Private,isEmitSEI:e.isEmitSEI,isRecordTypeFlv:!1,isWasmMp4:!1,isChrome:!1,isDropSameTimestampGop:e.isDropSameTimestampGop,mseDecodeAudio:e.mseDecodeAudio,nakedFlowH265DemuxUseNew:e.nakedFlowH265DemuxUseNew,mseDecoderUseWorker:e.mseDecoderUseWorker,mseAutoCleanupSourceBuffer:e.mseAutoCleanupSourceBuffer,mseAutoCleanupMaxBackwardDuration:e.mseAutoCleanupMaxBackwardDuration,mseAutoCleanupMinBackwardDuration:e.mseAutoCleanupMinBackwardDuration,mseCorrectTimeDuration:e.mseCorrectTimeDuration,mseCorrectAudioTimeDuration:e.mseCorrectAudioTimeDuration}};"VideoEncoder"in self&&(n={hasInit:!1,isEmitInfo:!1,offscreenCanvas:null,offscreenCanvasCtx:null,decoder:new VideoDecoder({output:function(e){if(n.isEmitInfo||(ni.debug.log("worker","Webcodecs Video Decoder initSize"),postMessage({cmd:U,w:e.codedWidth,h:e.codedHeight}),n.isEmitInfo=!0,n.offscreenCanvas=new OffscreenCanvas(e.codedWidth,e.codedHeight),n.offscreenCanvasCtx=n.offscreenCanvas.getContext("2d")),lr(e.createImageBitmap))e.createImageBitmap().then((t=>{n.offscreenCanvasCtx.drawImage(t,0,0,e.codedWidth,e.codedHeight);let r=n.offscreenCanvas.transferToImageBitmap();postMessage({cmd:x,buffer:r,delay:ni.delay,ts:0},[r]),hr(e)}));else{n.offscreenCanvasCtx.drawImage(e,0,0,e.codedWidth,e.codedHeight);let t=n.offscreenCanvas.transferToImageBitmap();postMessage({cmd:x,buffer:t,delay:ni.delay,ts:0},[t]),hr(e)}},error:function(e){ni.debug.error("worker","VideoDecoder error",e)}}),decode:function(e,t,r){const i=e[0]>>4==1;if(n.hasInit){const r=new EncodedVideoChunk({data:e.slice(5),timestamp:t,type:i?lt:ut});n.decoder.decode(r)}else if(i&&0===e[1]){const t=15&e[0];postMessage({cmd:I,code:t});const r=new Uint8Array(e);postMessage({cmd:F,buffer:r,codecId:t},[r.buffer]);let i=null,s=null;const a=e.slice(5);t===ke?(s=Cr(a),i={codec:s.codec,description:a}):t===De&&(s=Wr(a),i={codec:s.codec,description:a}),s&&s.codecWidth&&s.codecHeight&&(i.codedHeight=s.codecHeight,i.codedWidth=s.codecWidth);try{n.decoder.configure(i),n.hasInit=!0}catch(e){ni.debug.log("worker","VideoDecoder configure error",e.code,e)}}},reset(){n.hasInit=!1,n.isEmitInfo=!1,n.offscreenCanvas=null,n.offscreenCanvasCtx=null}});let Tr=function(){if(Sr=!0,ni.fetchStatus!==kt||yr(ni._opt.isChrome)){if(a)try{a.abort(),a=null}catch(e){ni.debug.log("worker","abort catch",e)}}else a=null,ni.debug.log("worker",`abort() and not abortController.abort() _status is ${ni.fetchStatus} and _isChrome is ${ni._opt.isChrome}`)},Gr={init(){Gr.lastBuf=null,Gr.vps=null,Gr.sps=null,Gr.pps=null,Gr.streamType=null,Gr.localDts=0,Gr.isSendSeqHeader=!1},destroy(){Gr.lastBuf=null,Gr.vps=null,Gr.sps=null,Gr.pps=null,Gr.streamType=null,Gr.localDts=0,Gr.isSendSeqHeader=!1},dispatch(e){const t=new Uint8Array(e);Gr.extractNALu$2(t)},getNaluDts(){let e=Gr.localDts;return Gr.localDts=Gr.localDts+40,e},getNaluAudioDts(){const e=ni._opt.sampleRate,t=ni._opt.audioBufferSize;return Gr.localDts+parseInt(t/e*1e3)},extractNALu(e){let t,r,i=0,s=e.byteLength,n=0,a=[];for(;i1)for(let e=0;e{const t=Pr(e);t===Oe||t===Ne?Gr.handleVideoH264Nalu(e):Mr(t)&&i.push(e)})),1===i.length)Gr.handleVideoH264Nalu(i[0]);else if(zr(i)){const e=Pr(i[0]),t=Rr(e);Gr.handleVideoH264NaluList(i,t,e)}else i.forEach((e=>{Gr.handleVideoH264Nalu(e)}))}else if(Gr.streamType===Pe)if(ni._opt.nakedFlowH265DemuxUseNew){const t=Gr.handleAddNaluStartCode(e),r=Gr.extractNALu(t);if(0===r.length)return void ni.debug.warn("worker","handleVideoNalu","h265 naluList.length === 0");const i=[];if(r.forEach((e=>{const t=Xr(e);t===st||t===rt||t===et?Gr.handleVideoH265Nalu(e):Jr(t)&&i.push(e)})),1===i.length)Gr.handleVideoH265Nalu(i[0]);else if(ei(i)){const e=Xr(i[0]),t=Qr(e);Gr.handleVideoH265NaluList(i,t,e)}else i.forEach((e=>{Gr.handleVideoH265Nalu(e)}))}else Xr(e)===st?Gr.extractH265PPS(e):Gr.handleVideoH265Nalu(e)},extractH264PPS(e){const t=Gr.handleAddNaluStartCode(e);Gr.extractNALu(t).forEach((e=>{Lr(Pr(e))?Gr.extractH264SEI(e):Gr.handleVideoH264Nalu(e)}))},extractH265PPS(e){const t=Gr.handleAddNaluStartCode(e);Gr.extractNALu(t).forEach((e=>{Zr(Xr(e))?Gr.extractH265SEI(e):Gr.handleVideoH265Nalu(e)}))},extractH264SEI(e){const t=Gr.handleAddNaluStartCode(e);Gr.extractNALu(t).forEach((e=>{Gr.handleVideoH264Nalu(e)}))},extractH265SEI(e){const t=Gr.handleAddNaluStartCode(e);Gr.extractNALu(t).forEach((e=>{Gr.handleVideoH265Nalu(e)}))},handleAddNaluStartCode(e){const t=[0,0,0,1],r=new Uint8Array(e.length+t.length);return r.set(t),r.set(e,t.length),r},handleVideoH264Nalu(e){const t=Pr(e);switch(t){case Ne:Gr.sps=e;break;case Oe:Gr.pps=e}if(Gr.isSendSeqHeader){if(Gr.sps&&Gr.pps){const e=kr({sps:Gr.sps,pps:Gr.pps}),t=Gr.getNaluDts();ni.decode(e,{type:ie,ts:t,isIFrame:!0,cts:0}),Gr.sps=null,Gr.pps=null}if(Mr(t)){const r=Rr(t),i=Gr.getNaluDts(),s=Ir(e,r);Gr.doDecode(s,{type:ie,ts:i,isIFrame:r,cts:0})}else ni.debug.warn("worker",`handleVideoH264Nalu Avc Seq Head is ${t}`)}else if(Gr.sps&&Gr.pps){Gr.isSendSeqHeader=!0;const e=kr({sps:Gr.sps,pps:Gr.pps});ni.decode(e,{type:ie,ts:0,isIFrame:!0,cts:0}),Gr.sps=null,Gr.pps=null}},handleVideoH264NaluList(e,t,r){if(Gr.isSendSeqHeader){const i=Gr.getNaluDts(),s=Fr(e.reduce(((e,t)=>{const r=Qt(e),i=Qt(t),s=new Uint8Array(r.byteLength+i.byteLength);return s.set(r,0),s.set(i,r.byteLength),s})),t);Gr.doDecode(s,{type:ie,ts:i,isIFrame:t,cts:0}),ni.debug.log("worker",`handleVideoH264NaluList list size is ${e.length} package length is ${s.byteLength} isIFrame is ${t},nalu type is ${r}, dts is ${i}`)}else ni.debug.warn("worker","handleVideoH264NaluList isSendSeqHeader is false")},handleVideoH265Nalu(e){const t=Xr(e);switch(t){case et:Gr.vps=e;break;case rt:Gr.sps=e;break;case st:Gr.pps=e}if(Gr.isSendSeqHeader){if(Gr.vps&&Gr.sps&&Gr.pps){const e=qr({vps:Gr.vps,sps:Gr.sps,pps:Gr.pps}),t=Gr.getNaluDts();ni.decode(e,{type:ie,ts:t,isIFrame:!0,cts:0}),Gr.vps=null,Gr.sps=null,Gr.pps=null}if(Jr(t)){const r=Qr(t),i=Gr.getNaluDts(),s=Yr(e,r);Gr.doDecode(s,{type:ie,ts:i,isIFrame:r,cts:0})}else ni.debug.warn("work",`handleVideoH265Nalu HevcSeqHead is ${t}`)}else if(Gr.vps&&Gr.sps&&Gr.pps){Gr.isSendSeqHeader=!0;const e=qr({vps:Gr.vps,sps:Gr.sps,pps:Gr.pps});ni.decode(e,{type:ie,ts:0,isIFrame:!0,cts:0}),Gr.vps=null,Gr.sps=null,Gr.pps=null}},handleVideoH265NaluList(e,t,r){if(Gr.isSendSeqHeader){const i=Gr.getNaluDts(),s=Kr(e.reduce(((e,t)=>{const r=Qt(e),i=Qt(t),s=new Uint8Array(r.byteLength+i.byteLength);return s.set(r,0),s.set(i,r.byteLength),s})),t);Gr.doDecode(s,{type:ie,ts:i,isIFrame:t,cts:0}),ni.debug.log("worker",`handleVideoH265NaluList list size is ${e.length} package length is ${s.byteLength} isIFrame is ${t},nalu type is ${r}, dts is ${i}`)}else ni.debug.warn("worker","handleVideoH265NaluList isSendSeqHeader is false")},doDecode(e,t){ni.calcNetworkDelay(t.ts),t.isIFrame&&ni.calcIframeIntervalTimestamp(t.ts),ni.decode(e,t)}},$r={LOG_NAME:"worker fmp4Demuxer",mp4Box:null,offset:0,videoTrackId:null,audioTrackId:null,isHevc:!1,listenMp4Box(){$r.mp4Box=Ni.createFile(),$r.mp4Box.onReady=$r.onReady,$r.mp4Box.onError=$r.onError,$r.mp4Box.onSamples=$r.onSamples},initTransportDescarmber(){$r.transportDescarmber=new $i},_getSeqHeader(e){const t=$r.mp4Box.getTrackById(e.id);for(const e of t.mdia.minf.stbl.stsd.entries)if(e.avcC||e.hvcC){const t=new Ni.DataStream(void 0,0,Ni.DataStream.BIG_ENDIAN);let r=[];e.avcC?(e.avcC.write(t),r=[23,0,0,0,0]):($r.isHevc=!0,Zt=!0,e.hvcC.write(t),r=[28,0,0,0,0]);const i=new Uint8Array(t.buffer,8),s=new Uint8Array(r.length+i.length);return s.set(r,0),s.set(i,r.length),s}return null},onReady(e){ni.debug.log($r.LOG_NAME,"onReady()");const t=e.videoTracks[0],r=e.audioTracks[0];if(t){$r.videoTrackId=t.id;const e=$r._getSeqHeader(t);e&&(ni.debug.log($r.LOG_NAME,"seqHeader"),ni.decodeVideo(e,0,!0,0)),$r.mp4Box.setExtractionOptions(t.id)}if(r&&ni._opt.hasAudio){$r.audioTrackId=r.id;const e=r.audio||{},t=Ht.indexOf(e.sample_rate),i=r.codec.replace("mp4a.40.","");$r.mp4Box.setExtractionOptions(r.id);const s=Vt({profile:parseInt(i,10),sampleRate:t,channel:e.channel_count});ni.debug.log($r.LOG_NAME,"aacADTSHeader"),ni.decodeAudio(s,0)}$r.mp4Box.start()},onError(e){ni.debug.error($r.LOG_NAME,"mp4Box onError",e)},onSamples(e,t,r){if(e===$r.videoTrackId)for(const t of r){const r=t.data,i=t.is_sync,s=1e3*t.cts/t.timescale;t.duration,t.timescale,i&&ni.calcIframeIntervalTimestamp(s);let n=null;n=$r.isHevc?Kr(r,i):Fr(r,i),ni.decode(n,{type:ie,ts:s,isIFrame:i,cts:0}),$r.mp4Box.releaseUsedSamples(e,t.number)}else if(e===$r.audioTrackId){if(ni._opt.hasAudio)for(const t of r){const r=t.data,i=1e3*t.cts/t.timescale;t.duration,t.timescale;const s=new Uint8Array(r.byteLength+2);s.set([175,1],0),s.set(r,2),ni.decode(s,{type:re,ts:i,isIFrame:!1,cts:0}),$r.mp4Box.releaseUsedSamples(e,t.number)}}else ni.debug.warn($r.LOG_NAME,"onSamples() trackId error",e)},dispatch(e){let t=new Uint8Array(e);$r.transportDescarmber&&(t=$r.transportDescarmber.transport(t)),t.buffer.fileStart=$r.offset,$r.offset+=t.byteLength,$r.mp4Box.appendBuffer(t.buffer)},destroy(){$r.mp4Box&&($r.mp4Box.stop(),$r.mp4Box.flush(),$r.mp4Box.destroy(),$r.mp4Box=null),$r.transportDescarmber&&($r.transportDescarmber.destroy(),$r.transportDescarmber=null),$r.offset=0,$r.videoTrackId=null,$r.audioTrackId=null,$r.isHevc=!1}},jr={LOG_NAME:"worker mpeg4Demuxer",lastBuffer:new Uint8Array(0),parsedOffset:0,firstStartCodeOffset:0,secondStartCodeOffset:0,state:"init",hasInitVideoCodec:!1,localDts:0,dispatch(e){const t=new Uint8Array(e);jr.extractNALu(t)},destroy(){jr.lastBuffer=new Uint8Array(0),jr.parsedOffset=0,jr.firstStartCodeOffset=0,jr.secondStartCodeOffset=0,jr.state="init",jr.hasInitVideoCodec=!1,jr.localDts=0},extractNALu(e){if(!e||e.byteLength<1)return void ni.debug.warn(jr.LOG_NAME,"extractNALu() buffer error",e);const t=new Uint8Array(jr.lastBuffer.length+e.length);for(t.set(jr.lastBuffer,0),t.set(new Uint8Array(e),jr.lastBuffer.length),jr.lastBuffer=t;;){if("init"===jr.state){let e=!1;for(;jr.lastBuffer.length-jr.parsedOffset>=4;)if(0===jr.lastBuffer[jr.parsedOffset])if(0===jr.lastBuffer[jr.parsedOffset+1])if(1===jr.lastBuffer[jr.parsedOffset+2]){if(182===jr.lastBuffer[jr.parsedOffset+3]){jr.state="findFirstStartCode",jr.firstStartCodeOffset=jr.parsedOffset,jr.parsedOffset+=4,e=!0;break}jr.parsedOffset++}else jr.parsedOffset++;else jr.parsedOffset++;else jr.parsedOffset++;if(e)continue;break}if("findFirstStartCode"===jr.state){let e=!1;for(;jr.lastBuffer.length-jr.parsedOffset>=4;)if(0===jr.lastBuffer[jr.parsedOffset])if(0===jr.lastBuffer[jr.parsedOffset+1])if(1===jr.lastBuffer[jr.parsedOffset+2]){if(182===jr.lastBuffer[jr.parsedOffset+3]){jr.state="findSecondStartCode",jr.secondStartCodeOffset=jr.parsedOffset,jr.parsedOffset+=4,e=!0;break}jr.parsedOffset++}else jr.parsedOffset++;else jr.parsedOffset++;else jr.parsedOffset++;if(e)continue;break}if("findSecondStartCode"===jr.state){if(!(jr.lastBuffer.length-jr.parsedOffset>0))break;{let e,t,r=192&jr.lastBuffer[jr.parsedOffset];e=0==r?jr.secondStartCodeOffset-14:jr.secondStartCodeOffset;let i=0==(192&jr.lastBuffer[jr.firstStartCodeOffset+4]);if(i){if(jr.firstStartCodeOffset-14<0)return void ni.debug.warn(jr.LOG_NAME,"firstStartCodeOffset -14 is",jr.firstStartCodeOffset-14);jr.hasInitVideoCodec||(jr.hasInitVideoCodec=!0,ni.debug.log(jr.LOG_NAME,"setCodec"),oi.setCodec(Ie,"")),t=jr.lastBuffer.subarray(jr.firstStartCodeOffset-14,e)}else t=jr.lastBuffer.subarray(jr.firstStartCodeOffset,e);let s=jr.getNaluDts();jr.hasInitVideoCodec?(postMessage({cmd:R,type:Se,value:t.byteLength}),postMessage({cmd:R,type:Ee,value:s}),oi.decode(t,i?1:0,s)):ni.debug.warn(jr.LOG_NAME,"has not init video codec"),jr.lastBuffer=jr.lastBuffer.subarray(e),jr.firstStartCodeOffset=0==r?14:0,jr.parsedOffset=jr.firstStartCodeOffset+4,jr.state="findFirstStartCode"}}}},getNaluDts(){let e=jr.localDts;return jr.localDts=jr.localDts+40,e}},ii={TAG_NAME:"worker TsLoaderV2",first_parse_:!0,tsPacketSize:0,syncOffset:0,pmt_:null,config_:null,media_info_:new Rs,timescale_:90,duration_:0,pat_:{version_number:0,network_pid:0,program_map_pid:{}},current_program_:null,current_pmt_pid_:-1,program_pmt_map_:{},pes_slice_queues_:{},section_slice_queues_:{},video_metadata_:{vps:null,sps:null,pps:null,details:null},audio_metadata_:{codec:null,audio_object_type:null,sampling_freq_index:null,sampling_frequency:null,channel_config:null},last_pcr_:null,audio_last_sample_pts_:void 0,aac_last_incomplete_data_:null,has_video_:!1,has_audio_:!1,video_init_segment_dispatched_:!1,audio_init_segment_dispatched_:!1,video_metadata_changed_:!1,audio_metadata_changed_:!1,loas_previous_frame:null,video_track_:{type:"video",id:1,sequenceNumber:0,samples:[],length:0},audio_track_:{type:"audio",id:2,sequenceNumber:0,samples:[],length:0},_remainingPacketData:null,init(){},destroy(){ii.media_info_=null,ii.pes_slice_queues_=null,ii.section_slice_queues_=null,ii.video_metadata_=null,ii.audio_metadata_=null,ii.aac_last_incomplete_data_=null,ii.video_track_=null,ii.audio_track_=null,ii._remainingPacketData=null},probe(e){let t=new Uint8Array(e),r=-1,i=188;if(t.byteLength<=3*i)return{needMoreData:!0};for(;-1===r;){let e=Math.min(1e3,t.byteLength-3*i);for(let s=0;s=4&&(r-=4),{match:!0,consumed:0,ts_packet_size:i,sync_offset:r})},_initPmt:()=>({program_number:0,version_number:0,pcr_pid:0,pid_stream_type:{},common_pids:{h264:void 0,h265:void 0,adts_aac:void 0,loas_aac:void 0,opus:void 0,ac3:void 0,eac3:void 0,mp3:void 0},pes_private_data_pids:{},timed_id3_pids:{},synchronous_klv_pids:{},asynchronous_klv_pids:{},scte_35_pids:{},smpte2038_pids:{}}),dispatch(e){ii._remainingPacketData&&(e=us(ii._remainingPacketData,e),ii._remainingPacketData=null);let t=e.buffer;const r=ii.parseChunks(t);r?ii._remainingPacketData=e.subarray(r):e.length>>6;r[1];let n=(31&r[1])<<8|r[2],a=(48&r[3])>>>4,o=15&r[3],d=!(!ii.pmt_||ii.pmt_.pcr_pid!==n),l={},u=4;if(2==a||3==a){let e=r[4];if(e>0&&(d||3==a)&&(l.discontinuity_indicator=(128&r[5])>>>7,l.random_access_indicator=(64&r[5])>>>6,l.elementary_stream_priority_indicator=(32&r[5])>>>5,(16&r[5])>>>4)){let e=300*(r[6]<<25|r[7]<<17|r[8]<<9|r[9]<<1|r[10]>>>7)+((1&r[10])<<8|r[11]);ii.last_pcr_=e}if(2==a||5+e===188){t+=188,204===ii.tsPacketSize&&(t+=16);continue}u=5+e}if(1==a||3==a)if(0===n||n===ii.current_pmt_pid_||null!=ii.pmt_&&ii.pmt_.pid_stream_type[n]===ks){let r=188-u;ii.handleSectionSlice(e,t+u,r,{pid:n,payload_unit_start_indicator:s,continuity_conunter:o,random_access_indicator:l.random_access_indicator})}else if(null!=ii.pmt_&&null!=ii.pmt_.pid_stream_type[n]){let r=188-u,i=ii.pmt_.pid_stream_type[n];n!==ii.pmt_.common_pids.h264&&n!==ii.pmt_.common_pids.h265&&n!==ii.pmt_.common_pids.adts_aac&&n!==ii.pmt_.common_pids.loas_aac&&n!==ii.pmt_.common_pids.ac3&&n!==ii.pmt_.common_pids.eac3&&n!==ii.pmt_.common_pids.opus&&n!==ii.pmt_.common_pids.mp3&&!0!==ii.pmt_.pes_private_data_pids[n]&&!0!==ii.pmt_.timed_id3_pids[n]&&!0!==ii.pmt_.synchronous_klv_pids[n]&&!0!==ii.pmt_.asynchronous_klv_pids[n]||ii.handlePESSlice(e,t+u,r,{pid:n,stream_type:i,payload_unit_start_indicator:s,continuity_conunter:o,random_access_indicator:l.random_access_indicator})}t+=188,204===ii.tsPacketSize&&(t+=16)}return ii.dispatchAudioVideoMediaSegment(),t},handleSectionSlice(e,t,r,i){let s=new Uint8Array(e,t,r),n=ii.section_slice_queues_[i.pid];if(i.payload_unit_start_indicator){let a=s[0];if(null!=n&&0!==n.total_length){let s=new Uint8Array(e,t+1,Math.min(r,a));n.slices.push(s),n.total_length+=s.byteLength,n.total_length===n.expected_length?ii.emitSectionSlices(n,i):ii.clearSlices(n,i)}for(let o=1+a;o=n.expected_length&&ii.clearSlices(n,i),o+=d.byteLength}}else if(null!=n&&0!==n.total_length){let s=new Uint8Array(e,t,Math.min(r,n.expected_length-n.total_length));n.slices.push(s),n.total_length+=s.byteLength,n.total_length===n.expected_length?ii.emitSectionSlices(n,i):n.total_length>=n.expected_length&&ii.clearSlices(n,i)}},handlePESSlice(e,t,r,i){let s=new Uint8Array(e,t,r),n=s[0]<<16|s[1]<<8|s[2];s[3];let a=s[4]<<8|s[5];if(i.payload_unit_start_indicator){if(1!==n)return void ni.debug.warn(ii.TAG_NAME,`handlePESSlice: packet_start_code_prefix should be 1 but with value ${n}`);let e=ii.pes_slice_queues_[i.pid];e&&(0===e.expected_length||e.expected_length===e.total_length?ii.emitPESSlices(e,i):ii.clearSlices(e,i)),ii.pes_slice_queues_[i.pid]=new Fs,ii.pes_slice_queues_[i.pid].random_access_indicator=i.random_access_indicator}if(null==ii.pes_slice_queues_[i.pid])return;let o=ii.pes_slice_queues_[i.pid];o.slices.push(s),i.payload_unit_start_indicator&&(o.expected_length=0===a?0:a+6),o.total_length+=s.byteLength,o.expected_length>0&&o.expected_length===o.total_length?ii.emitPESSlices(o,i):o.expected_length>0&&o.expected_length>>6,o=t[8];2!==a&&3!==a||(r=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,n=3===a?536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2:r);let d,l=9+o;if(0!==s){if(s<3+o)return void ni.debug.warn(ii.TAG_NAME,"Malformed PES: PES_packet_length < 3 + PES_header_data_length");d=s-3-o}else d=t.byteLength-l;let u=t.subarray(l,l+d);switch(e.stream_type){case Ss:case Es:ii.parseMP3Payload(u,r);break;case As:ii.pmt_.common_pids.opus===e.pid||ii.pmt_.common_pids.ac3===e.pid||ii.pmt_.common_pids.eac3===e.pid||(ii.pmt_.asynchronous_klv_pids[e.pid]?ii.parseAsynchronousKLVMetadataPayload(u,e.pid,i):ii.pmt_.smpte2038_pids[e.pid]?ii.parseSMPTE2038MetadataPayload(u,r,n,e.pid,i):ii.parsePESPrivateDataPayload(u,r,n,e.pid,i));break;case Us:ii.parseADTSAACPayload(u,r);break;case xs:ii.parseLOASAACPayload(u,r);break;case Bs:case Ts:break;case Cs:ii.pmt_.timed_id3_pids[e.pid]?ii.parseTimedID3MetadataPayload(u,r,n,e.pid,i):ii.pmt_.synchronous_klv_pids[e.pid]&&ii.parseSynchronousKLVMetadataPayload(u,r,n,e.pid,i);break;case Ds:ii.parseH264Payload(u,r,n,e.random_access_indicator);break;case Is:ii.parseH265Payload(u,r,n,e.random_access_indicator)}}else if((188===i||191===i||240===i||241===i||255===i||242===i||248===i)&&e.stream_type===As){let r,n=6;r=0!==s?s:t.byteLength-n;let a=t.subarray(n,n+r);ii.parsePESPrivateDataPayload(a,void 0,void 0,e.pid,i)}}else ni.debug.error(ii.TAG_NAME,`parsePES: packet_start_code_prefix should be 1 but with value ${r}`)},parsePAT(e){let t=e[0];if(0!==t)return void Log.e(ii.TAG,`parsePAT: table_id ${t} is not corresponded to PAT!`);let r=(15&e[1])<<8|e[2];e[3],e[4];let i=(62&e[5])>>>1,s=1&e[5],n=e[6];e[7];let a=null;if(1===s&&0===n)a={version_number:0,network_pid:0,program_pmt_pid:{}},a.version_number=i;else if(a=ii.pat_,null==a)return;let o=r-5-4,d=-1,l=-1;for(let t=8;t<8+o;t+=4){let r=e[t]<<8|e[t+1],i=(31&e[t+2])<<8|e[t+3];0===r?a.network_pid=i:(a.program_pmt_pid[r]=i,-1===d&&(d=r),-1===l&&(l=i))}1===s&&0===n&&(null==ii.pat_&&ni.debug.log(ii.TAG_NAME,`Parsed first PAT: ${JSON.stringify(a)}`),ii.pat_=a,ii.current_program_=d,ii.current_pmt_pid_=l)},parsePMT(e){let t=e[0];if(2!==t)return void ni.debug.error(ii.TAG_NAME,`parsePMT: table_id ${t} is not corresponded to PMT!`);let r,i=(15&e[1])<<8|e[2],s=e[3]<<8|e[4],n=(62&e[5])>>>1,a=1&e[5],o=e[6];if(e[7],1===a&&0===o)r=ii._initPmt(),r.program_number=s,r.version_number=n,ii.program_pmt_map_[s]=r;else if(r=ii.program_pmt_map_[s],null==r)return;r.pcr_pid=(31&e[8])<<8|e[9];let d=(15&e[10])<<8|e[11],l=12+d,u=i-9-d-4;for(let t=l;t0){for(let i=t+5;i0)for(let i=t+5;iii.has_video_&&ii.has_audio_?ii.video_init_segment_dispatched_&&ii.audio_init_segment_dispatched_:ii.has_video_&&!ii.has_audio_?ii.video_init_segment_dispatched_:!(ii.has_video_||!ii.has_audio_)&&ii.audio_init_segment_dispatched_,dispatchVideoInitSegment(){let e=ii.video_metadata_.details,t={type:"video"};t.id=ii.video_track_.id,t.timescale=1e3,t.duration=ii.duration_,t.codecWidth=e.codec_size.width,t.codecHeight=e.codec_size.height,t.presentWidth=e.present_size.width,t.presentHeight=e.present_size.height,t.profile=e.profile_string,t.level=e.level_string,t.bitDepth=e.bit_depth,t.chromaFormat=e.chroma_format,t.sarRatio=e.sar_ratio,t.frameRate=e.frame_rate;let r=t.frameRate.fps_den,i=t.frameRate.fps_num;if(t.refSampleDuration=r/i*1e3,t.codec=e.codec_mimetype,ii.video_metadata_.vps){let e=ii.video_metadata_.vps.data.subarray(4),r=ii.video_metadata_.sps.data.subarray(4),i=ii.video_metadata_.pps.data.subarray(4);t.hvcc=qr({vps:e,sps:r,pps:i}),0==ii.video_init_segment_dispatched_&&ni.debug.log(ii.TAG_NAME,`Generated first HEVCDecoderConfigurationRecord for mimeType: ${t.codec}`),t.hvcc&&ni.decodeVideo(t.hvcc,0,!0,0)}else{let e=ii.video_metadata_.sps.data.subarray(4),r=ii.video_metadata_.pps.data.subarray(4);t.avcc=Dr({sps:e,pps:r}),0==ii.video_init_segment_dispatched_&&ni.debug.log(ii.TAG_NAME,`Generated first AVCDecoderConfigurationRecord for mimeType: ${t.codec}`),t.avcc&&ni.decodeVideo(t.avcc,0,!0,0)}ii.video_init_segment_dispatched_=!0,ii.video_metadata_changed_=!1;let s=ii.media_info_;s.hasVideo=!0,s.width=t.codecWidth,s.height=t.codecHeight,s.fps=t.frameRate.fps,s.profile=t.profile,s.level=t.level,s.refFrames=e.ref_frames,s.chromaFormat=e.chroma_format_string,s.sarNum=t.sarRatio.width,s.sarDen=t.sarRatio.height,s.videoCodec=t.codec,s.hasAudio&&s.audioCodec?s.mimeType=`video/mp2t; codecs="${s.videoCodec},${s.audioCodec}"`:s.mimeType=`video/mp2t; codecs="${s.videoCodec}"`},dispatchVideoMediaSegment(){ii.isInitSegmentDispatched()&&ii.video_track_.length&&ii._preDoDecode()},dispatchAudioMediaSegment(){ii.isInitSegmentDispatched()&&ii.audio_track_.length&&ii._preDoDecode()},dispatchAudioVideoMediaSegment(){ii.isInitSegmentDispatched()&&(ii.audio_track_.length||ii.video_track_.length)&&ii._preDoDecode()},parseADTSAACPayload(e,t){if(ii.has_video_&&!ii.video_init_segment_dispatched_)return;if(ii.aac_last_incomplete_data_){let t=new Uint8Array(e.byteLength+ii.aac_last_incomplete_data_.byteLength);t.set(ii.aac_last_incomplete_data_,0),t.set(e,ii.aac_last_incomplete_data_.byteLength),e=t}let r,i;if(null!=t&&(i=t/ii.timescale_),"aac"===ii.audio_metadata_.codec){if(null==t&&null!=ii.audio_last_sample_pts_)r=1024/ii.audio_metadata_.sampling_frequency*1e3,i=ii.audio_last_sample_pts_+r;else if(null==t)return void ni.debug.warn(ii.TAG_NAME,"AAC: Unknown pts");if(ii.aac_last_incomplete_data_&&ii.audio_last_sample_pts_){r=1024/ii.audio_metadata_.sampling_frequency*1e3;let e=ii.audio_last_sample_pts_+r;Math.abs(e-i)>1&&(ni.debug.warn(ii.TAG_NAME,`AAC: Detected pts overlapped, expected: ${e}ms, PES pts: ${i}ms`),i=e)}}let s,n=new Kt(e),a=null,o=i;for(;null!=(a=n.readNextAACFrame());){r=1024/a.sampling_frequency*1e3;const e={codec:"aac",data:a};0==ii.audio_init_segment_dispatched_?(ii.audio_metadata_={codec:"aac",audio_object_type:a.audio_object_type,sampling_freq_index:a.sampling_freq_index,sampling_frequency:a.sampling_frequency,channel_config:a.channel_config},ii.dispatchAudioInitSegment(e)):ii.detectAudioMetadataChange(e)&&(ii.dispatchAudioMediaSegment(),ii.dispatchAudioInitSegment(e)),s=o;let t=Math.floor(o);const i=new Uint8Array(a.data.length+2);i.set([175,1],0),i.set(a.data,2);let n={payload:i,length:i.byteLength,pts:t,dts:t,type:re};ii.audio_track_.samples.push(n),ii.audio_track_.length+=i.byteLength,o+=r}n.hasIncompleteData()&&(ii.aac_last_incomplete_data_=n.getIncompleteData()),s&&(ii.audio_last_sample_pts_=s)},parseLOASAACPayload(e,t){if(ii.has_video_&&!ii.video_init_segment_dispatched_)return;if(ii.aac_last_incomplete_data_){let t=new Uint8Array(e.byteLength+ii.aac_last_incomplete_data_.byteLength);t.set(ii.aac_last_incomplete_data_,0),t.set(e,ii.aac_last_incomplete_data_.byteLength),e=t}let r,i;if(null!=t&&(i=t/ii.timescale_),"aac"===ii.audio_metadata_.codec){if(null==t&&null!=ii.audio_last_sample_pts_)r=1024/ii.audio_metadata_.sampling_frequency*1e3,i=ii.audio_last_sample_pts_+r;else if(null==t)return void ni.debug.warn(ii.TAG_NAME,"AAC: Unknown pts");if(ii.aac_last_incomplete_data_&&ii.audio_last_sample_pts_){r=1024/ii.audio_metadata_.sampling_frequency*1e3;let e=ii.audio_last_sample_pts_+r;Math.abs(e-i)>1&&(ni.debug.warn(ii.TAG,`AAC: Detected pts overlapped, expected: ${e}ms, PES pts: ${i}ms`),i=e)}}let s,n=new Xt(e),a=null,o=i;for(;null!=(a=n.readNextAACFrame(or(this.loas_previous_frame)?void 0:this.loas_previous_frame));){ii.loas_previous_frame=a,r=1024/a.sampling_frequency*1e3;const e={codec:"aac",data:a};0==ii.audio_init_segment_dispatched_?(ii.audio_metadata_={codec:"aac",audio_object_type:a.audio_object_type,sampling_freq_index:a.sampling_freq_index,sampling_frequency:a.sampling_frequency,channel_config:a.channel_config},ii.dispatchAudioInitSegment(e)):ii.detectAudioMetadataChange(e)&&(ii.dispatchAudioMediaSegment(),ii.dispatchAudioInitSegment(e)),s=o;let t=Math.floor(o);const i=new Uint8Array(a.data.length+2);i.set([175,1],0),i.set(a.data,2);let n={payload:i,length:i.byteLength,pts:t,dts:t,type:re};ii.audio_track_.samples.push(n),ii.audio_track_.length+=i.byteLength,o+=r}n.hasIncompleteData()&&(ii.aac_last_incomplete_data_=n.getIncompleteData()),s&&(ii.audio_last_sample_pts_=s)},parseAC3Payload(e,t){},parseEAC3Payload(e,t){},parseOpusPayload(e,t){},parseMP3Payload(e,t){if(ii.has_video_&&!ii.video_init_segment_dispatched_)return;let r=[44100,48e3,32e3,0],i=[22050,24e3,16e3,0],s=[11025,12e3,8e3,0],n=e[1]>>>3&3,a=(6&e[1])>>1;e[2];let o=(12&e[2])>>>2,d=3!=(e[3]>>>6&3)?2:1,l=0,u=34;switch(n){case 0:l=s[o];break;case 2:l=i[o];break;case 3:l=r[o]}switch(a){case 1:u=34;break;case 2:u=33;break;case 3:u=32}const c={};c.object_type=u,c.sample_rate=l,c.channel_count=d,c.data=e;const h={codec:"mp3",data:c};0==ii.audio_init_segment_dispatched_?(ii.audio_metadata_={codec:"mp3",object_type:u,sample_rate:l,channel_count:d},ii.dispatchAudioInitSegment(h)):ii.detectAudioMetadataChange(h)&&(ii.dispatchAudioMediaSegment(),ii.dispatchAudioInitSegment(h));let f={payload:e,length:e.byteLength,pts:t/ii.timescale_,dts:t/ii.timescale_,type:re};ii.audio_track_.samples.push(f),ii.audio_track_.length+=e.byteLength},detectAudioMetadataChange(e){if(e.codec!==ii.audio_metadata_.codec)return ni.debug.log(ii.TAG_NAME,`Audio: Audio Codecs changed from ${ii.audio_metadata_.codec} to ${e.codec}`),!0;if("aac"===e.codec&&"aac"===ii.audio_metadata_.codec){const t=e.data;if(t.audio_object_type!==ii.audio_metadata_.audio_object_type)return ni.debug.log(ii.TAG_NAME,`AAC: AudioObjectType changed from ${ii.audio_metadata_.audio_object_type} to ${t.audio_object_type}`),!0;if(t.sampling_freq_index!==ii.audio_metadata_.sampling_freq_index)return ni.debug.log(ii.TAG_NAME,`AAC: SamplingFrequencyIndex changed from ${ii.audio_metadata_.sampling_freq_index} to ${t.sampling_freq_index}`),!0;if(t.channel_config!==ii.audio_metadata_.channel_config)return ni.debug.log(ii.TAG_NAME,`AAC: Channel configuration changed from ${ii.audio_metadata_.channel_config} to ${t.channel_config}`),!0}else if("ac-3"===e.codec&&"ac-3"===ii.audio_metadata_.codec){const t=e.data;if(t.sampling_frequency!==ii.audio_metadata_.sampling_frequency)return ni.debug.log(ii.TAG_NAME,`AC3: Sampling Frequency changed from ${ii.audio_metadata_.sampling_frequency} to ${t.sampling_frequency}`),!0;if(t.bit_stream_identification!==ii.audio_metadata_.bit_stream_identification)return ni.debug.log(ii.TAG_NAME,`AC3: Bit Stream Identification changed from ${ii.audio_metadata_.bit_stream_identification} to ${t.bit_stream_identification}`),!0;if(t.bit_stream_mode!==ii.audio_metadata_.bit_stream_mode)return ni.debug.log(ii.TAG_NAME,`AC3: BitStream Mode changed from ${ii.audio_metadata_.bit_stream_mode} to ${t.bit_stream_mode}`),!0;if(t.channel_mode!==ii.audio_metadata_.channel_mode)return ni.debug.log(ii.TAG_NAME,`AC3: Channel Mode changed from ${ii.audio_metadata_.channel_mode} to ${t.channel_mode}`),!0;if(t.low_frequency_effects_channel_on!==ii.audio_metadata_.low_frequency_effects_channel_on)return ni.debug.log(ii.TAG_NAME,`AC3: Low Frequency Effects Channel On changed from ${ii.audio_metadata_.low_frequency_effects_channel_on} to ${t.low_frequency_effects_channel_on}`),!0}else if("opus"===e.codec&&"opus"===ii.audio_metadata_.codec){const t=e.meta;if(t.sample_rate!==ii.audio_metadata_.sample_rate)return ni.debug.log(ii.TAG_NAME,`Opus: SamplingFrequencyIndex changed from ${ii.audio_metadata_.sample_rate} to ${t.sample_rate}`),!0;if(t.channel_count!==ii.audio_metadata_.channel_count)return ni.debug.log(ii.TAG_NAME,`Opus: Channel count changed from ${ii.audio_metadata_.channel_count} to ${t.channel_count}`),!0}else if("mp3"===e.codec&&"mp3"===ii.audio_metadata_.codec){const t=e.data;if(t.object_type!==ii.audio_metadata_.object_type)return ni.debug.log(ii.TAG_NAME,`MP3: AudioObjectType changed from ${ii.audio_metadata_.object_type} to ${t.object_type}`),!0;if(t.sample_rate!==ii.audio_metadata_.sample_rate)return ni.debug.log(ii.TAG_NAME,`MP3: SamplingFrequencyIndex changed from ${ii.audio_metadata_.sample_rate} to ${t.sample_rate}`),!0;if(t.channel_count!==ii.audio_metadata_.channel_count)return ni.debug.log(ii.TAG_NAME,`MP3: Channel count changed from ${ii.audio_metadata_.channel_count} to ${t.channel_count}`),!0}return!1},dispatchAudioInitSegment(e){let t={type:"audio"};if(t.id=ii.audio_track_.id,t.timescale=1e3,t.duration=ii.duration_,"aac"===ii.audio_metadata_.codec){let r="aac"===e.codec?e.data:null,i=new zs(r);t.audioSampleRate=i.sampling_rate,t.audioSampleRateIndex=i.sampling_index,t.channelCount=i.channel_count,t.codec=i.codec_mimetype,t.originalCodec=i.original_codec_mimetype,t.config=i.config,t.refSampleDuration=1024/t.audioSampleRate*t.timescale;const s=Vt({profile:ni._opt.mseDecodeAudio?i.object_type:i.original_object_type,sampleRate:t.audioSampleRateIndex,channel:t.channelCount});ni.decodeAudio(s,0)}else"ac-3"===ii.audio_metadata_.codec||"ec-3"===ii.audio_metadata_.codec||"opus"===ii.audio_metadata_.codec||"mp3"===ii.audio_metadata_.codec&&(t.audioSampleRate=ii.audio_metadata_.sample_rate,t.channelCount=ii.audio_metadata_.channel_count,t.codec="mp3",t.originalCodec="mp3",t.config=void 0);0==ii.audio_init_segment_dispatched_&&ni.debug.log(ii.TAG_NAME,`Generated first AudioSpecificConfig for mimeType: ${t.codec}`),ii.audio_init_segment_dispatched_=!0,ii.video_metadata_changed_=!1;let r=ii.media_info_;r.hasAudio=!0,r.audioCodec=t.originalCodec,r.audioSampleRate=t.audioSampleRate,r.audioChannelCount=t.channelCount,r.hasVideo&&r.videoCodec?r.mimeType=`video/mp2t; codecs="${r.videoCodec},${r.audioCodec}"`:r.mimeType=`video/mp2t; codecs="${r.audioCodec}"`},dispatchPESPrivateDataDescriptor(e,t,r){},parsePESPrivateDataPayload(e,t,r,i,s){let n=new Ls;if(n.pid=i,n.stream_id=s,n.len=e.byteLength,n.data=e,null!=t){let e=Math.floor(t/ii.timescale_);n.pts=e}else n.nearest_pts=ii.getNearestTimestampMilliseconds();if(null!=r){let e=Math.floor(r/ii.timescale_);n.dts=e}},parseTimedID3MetadataPayload(e,t,r,i,s){ni.debug.log(ii.TAG_NAME,`Timed ID3 Metadata: pid=${i}, pts=${t}, dts=${r}, stream_id=${s}`)},parseSynchronousKLVMetadataPayload(e,t,r,i,s){ni.debug.log(ii.TAG_NAME,`Synchronous KLV Metadata: pid=${i}, pts=${t}, dts=${r}, stream_id=${s}`)},parseAsynchronousKLVMetadataPayload(e,t,r){ni.debug.log(ii.TAG_NAME,`Asynchronous KLV Metadata: pid=${t}, stream_id=${r}`)},parseSMPTE2038MetadataPayload(e,t,r,i,s){ni.debug.log(ii.TAG_NAME,`SMPTE 2038 Metadata: pid=${i}, pts=${t}, dts=${r}, stream_id=${s}`)},getNearestTimestampMilliseconds:()=>null!=ii.audio_last_sample_pts_?Math.floor(ii.audio_last_sample_pts_):null!=ii.last_pcr_?Math.floor(ii.last_pcr_/300/ii.timescale_):void 0,_preDoDecode(){const e=ii.video_track_,t=ii.audio_track_;let r=e.samples;t.samples.length>0&&(r=e.samples.concat(t.samples),r=r.sort(((e,t)=>e.dts-t.dts))),r.forEach((e=>{const t=new Uint8Array(e.payload);delete e.payload,e.type===ie?ii._doDecodeVideo({...e,payload:t}):e.type===re&&ii._doDecodeAudio({...e,payload:t})})),e.samples=[],e.length=0,t.samples=[],t.length=0},_doDecodeVideo(e){const t=new Uint8Array(e.payload);let r=null;r=e.isHevc?Kr(t,e.isIFrame):Fr(t,e.isIFrame),e.isIFrame&&ni.calcIframeIntervalTimestamp(e.dts);let i=ni.cryptoPayload(r,e.isIFrame);ni.decode(i,{type:ie,ts:e.dts,isIFrame:e.isIFrame,cts:e.cts})},_doDecodeAudio(e){const t=new Uint8Array(e.payload);let r=t;gr(ni._opt.m7sCryptoAudio)&&(r=ni.cryptoPayloadAudio(t)),ni.decode(r,{type:re,ts:e.dts,isIFrame:!1,cts:0})}},si=null;br()&&(si={TAG_NAME:"worker MediaSource",_resetInIt(){si.isAvc=null,si.isAAC=null,si.videoInfo={},si.videoMeta={},si.audioMeta={},si.sourceBuffer=null,si.audioSourceBuffer=null,si.hasInit=!1,si.hasAudioInit=!1,si.isAudioInitInfo=!1,si.videoMimeType="",si.audioMimeType="",si.cacheTrack={},si.cacheAudioTrack={},si.timeInit=!1,si.sequenceNumber=0,si.audioSequenceNumber=0,si.firstRenderTime=null,si.firstAudioTime=null,si.mediaSourceAppendBufferFull=!1,si.mediaSourceAppendBufferError=!1,si.mediaSourceAddSourceBufferError=!1,si.mediaSourceBufferError=!1,si.mediaSourceError=!1,si.prevTimestamp=null,si.decodeDiffTimestamp=null,si.prevDts=null,si.prevAudioDts=null,si.prevPayloadBufferSize=0,si.isWidthOrHeightChanged=!1,si.prevTs=null,si.prevAudioTs=null,si.eventListenList=[],si.pendingRemoveRanges=[],si.pendingSegments=[],si.pendingAudioRemoveRanges=[],si.pendingAudioSegments=[],si.supportVideoFrameCallbackHandle=null,si.audioSourceBufferCheckTimeout=null,si.audioSourceNoDataCheckTimeout=null,si.hasPendingEos=!1,si.$video={currentTime:0,readyState:0}},init(){si.events=new cs,si._resetInIt(),si.mediaSource=new self.MediaSource,si.isDecodeFirstIIframe=!!yr(ni._opt.checkFirstIFrame),si._bindMediaSourceEvents()},destroy(){si.stop(),si._clearAudioSourceBufferCheckTimeout(),si.eventListenList&&si.eventListenList.length&&(si.eventListenList.forEach((e=>e())),si.eventListenList=[]),si._resetInIt(),si.mediaSource=null},getState:()=>si.mediaSource&&si.mediaSource.readyState,isStateOpen:()=>si.getState()===yt,isStateClosed:()=>si.getState()===bt,isStateEnded:()=>si.getState()===gt,_bindMediaSourceEvents(){const{proxy:e}=si.events,t=e(si.mediaSource,wt,(()=>{ni.debug.log(si.TAG_NAME,"sourceOpen"),si._onMediaSourceSourceOpen()})),r=e(si.mediaSource,vt,(()=>{ni.debug.log(si.TAG_NAME,"sourceClose")})),i=e(si.mediaSource,St,(()=>{ni.debug.log(si.TAG_NAME,"sourceended")}));si.eventListenList.push(t,r,i)},_onMediaSourceSourceOpen(){si.sourceBuffer||(ni.debug.log(si.TAG_NAME,"onMediaSourceSourceOpen() sourceBuffer is null and next init"),si._initSourceBuffer()),si.audioSourceBuffer||(ni.debug.log(si.TAG_NAME,"onMediaSourceSourceOpen() audioSourceBuffer is null and next init"),si._initAudioSourceBuffer()),si._hasPendingSegments()&&si._doAppendSegments()},decodeVideo(e,t,r,i){if(ni.isDestroyed)ni.debug.warn(si.TAG_NAME,"decodeVideo() and decoder is destroyed");else if(yr(si.hasInit))if(r&&e[1]===xt){const i=15&e[0];if(i===De&&yr(ar()))return void si.emitError(Te.mediaSourceH265NotSupport);si.videoInfo.codec=i,postMessage({cmd:I,code:i});const s=new Uint8Array(e);postMessage({cmd:F,buffer:s,codecId:i},[s.buffer]),si.hasInit=si._decodeConfigurationRecord(e,t,r,i)}else ni.debug.warn(si.TAG_NAME,`decodeVideo has not init , isIframe is ${r} , payload is ${e[1]}`);else if(!si.isDecodeFirstIIframe&&r&&(si.isDecodeFirstIIframe=!0),si.isDecodeFirstIIframe){if(r&&0===e[1]){const t=15&e[0];let r={};t===ke?r=Cr(e.slice(5)):t===De&&(r=Vr(e));const i=si.videoInfo;i&&i.codecWidth&&i.codecWidth&&r&&r.codecWidth&&r.codecHeight&&(r.codecWidth!==i.codecWidth||r.codecHeight!==i.codecWidth)&&(ni.debug.warn(si.TAG_NAME,`\n decodeVideo: video width or height is changed,\n old width is ${i.codecWidth}, old height is ${i.codecWidth},\n new width is ${r.codecWidth}, new height is ${r.codecHeight},\n and emit change event`),si.isWidthOrHeightChanged=!0,si.emitError(Te.mseWidthOrHeightChange))}if(si.isWidthOrHeightChanged)return void ni.debug.warn(si.TAG_NAME,"decodeVideo: video width or height is changed, and return");if(_r(e))return void ni.debug.warn(si.TAG_NAME,"decodeVideo and payload is video sequence header so drop this frame");if(e.byteLength300&&(si.firstAudioTime-=e,ni.debug.warn(si.TAG_NAME,`video\n firstAudioTime is ${si.firstRenderTime} and current time is ${si.prevTs}\n play time is ${e} and firstAudioTime ${t} - ${e} = ${si.firstAudioTime}`))}r=t-si.firstAudioTime,r<0&&(ni.debug.warn(si.TAG_NAME,`decodeAudio\n local dts is < 0 , ts is ${t} and prevTs is ${si.prevAudioTs},\n firstAudioTime is ${si.firstAudioTime}`),r=null===si.prevAudioDts?0:si.prevAudioDts+ni._opt.mseCorrectAudioTimeDuration),null!==si.prevAudioTs&&r<=si.prevAudioDts&&(ni.debug.warn(si.TAG_NAME,`\n decodeAudio dts is less than(or equal) prev dts ,\n dts is ${r} and prev dts is ${si.prevAudioDts} ,\n and now ts is ${t} and prev ts is ${si.prevAudioTs} ,\n and diff is ${t-si.prevAudioTs}`),r=si.prevAudioDts+ni._opt.mseCorrectAudioTimeDuration)}ni.isPlayer?si._decodeAudio(e,r,t):ni.isPlayback,si.prevAudioTs=t,si.prevAudioDts=r}else ni.debug.log(si.TAG_NAME,"decodeAudio first frame is not iFrame")}},_checkTsIsMaxDiff:e=>si.prevTs>0&&ev,_decodeConfigurationRecord(e,t,r,i){let s=e.slice(5),n={};if(i===ke?n=Cr(s):i===De&&(n=Wr(s)),si.videoInfo.width=n.codecWidth,si.videoInfo.height=n.codecHeight,0===n.codecWidth&&0===n.codecHeight)return ni.debug.warn(si.TAG_NAME,"_decodeConfigurationRecord error",JSON.stringify(n)),si.emitError(Te.mediaSourceDecoderConfigurationError),!1;const a={id:It,type:"video",timescale:1e3,duration:0,avcc:s,codecWidth:n.codecWidth,codecHeight:n.codecHeight,videoType:n.videoType},o=hs.generateInitSegment(a);si.isAvc=i===ke;let d=n.codec;return si.videoMimeType=d?`video/mp4; codecs="${n.codec}"`:si.isAvc?ct:ht,postMessage({cmd:U,w:n.codecWidth,h:n.codecHeight}),si._initSourceBuffer(),si.appendBuffer(o.buffer),si.sequenceNumber=0,si.cacheTrack={},si.timeInit=!1,!0},_decodeAudioConfigurationRecord(e,t){const r=e[0]>>4,i=e[0]>>1&1,s=r===ze,n=r===Le;if(yr(n||s))return ni.debug.warn(si.TAG_NAME,`_decodeAudioConfigurationRecord audio codec is not support , codecId is ${r} ant auto wasm decode`),si.emitError(Te.mediaSourceAudioG711NotSupport),!1;const a={id:Ft,type:"audio",timescale:1e3};let o={};if(Wt(e)){if(o=Yt(e.slice(2)),!o)return!1;a.audioSampleRate=o.sampleRate,a.channelCount=o.channelCount,a.config=o.config,a.refSampleDuration=1024/a.audioSampleRate*a.timescale}else{if(!s)return!1;if(o=ws(e),!o)return!1;a.audioSampleRate=o.samplingRate,a.channelCount=o.channelCount,a.refSampleDuration=1152/a.audioSampleRate*a.timescale}a.codec=o.codec,a.duration=0;let d="mp4",l=o.codec,u=null;s&&yr(nr())?(d="mpeg",l="",u=new Uint8Array):u=hs.generateInitSegment(a);let c=`${a.type}/${d}`;return l&&l.length>0&&(c+=`;codecs=${l}`),yr(si.isAudioInitInfo)&&(wr=r===Le?i?16:8:0===i?8:16,postMessage({cmd:C,code:r}),postMessage({cmd:T,sampleRate:a.audioSampleRate,channels:a.channelCount,depth:wr}),si.isAudioInitInfo=!0),si.audioMimeType=c,si.isAAC=n,si._initAudioSourceBuffer(),si.appendAudioBuffer(u.buffer),!0},_initSourceBuffer(){const{proxy:e}=si.events;if(null===si.sourceBuffer&&null!==si.mediaSource&&si.isStateOpen()&&si.videoMimeType){try{si.sourceBuffer=si.mediaSource.addSourceBuffer(si.videoMimeType),ni.debug.log(si.TAG_NAME,"_initSourceBuffer() mseDecoder.mediaSource.addSourceBuffer()",si.videoMimeType)}catch(e){return ni.debug.error(si.TAG_NAME,"appendBuffer() mseDecoder.mediaSource.addSourceBuffer()",e.code,e),si.emitError(Te.mseAddSourceBufferError,e.code),void(si.mediaSourceAddSourceBufferError=!0)}if(si.sourceBuffer){const t=e(si.sourceBuffer,"error",(e=>{si.mediaSourceBufferError=!0,ni.debug.error(si.TAG_NAME,"mseSourceBufferError mseDecoder.sourceBuffer",e),si.emitError(Te.mseSourceBufferError,e.code)})),r=e(si.sourceBuffer,"updateend",(()=>{si._hasPendingRemoveRanges()?si._doRemoveRanges():si._hasPendingSegments()?si._doAppendSegments():si.hasPendingEos&&(ni.debug.log(si.TAG_NAME,"videoSourceBuffer updateend and hasPendingEos is true, next endOfStream()"),si.endOfStream())}));si.eventListenList.push(t,r)}}else ni.debug.log(si.TAG_NAME,`_initSourceBuffer and mseDecoder.isStateOpen is ${si.isStateOpen()} and mseDecoder.isAvc === null is ${null===si.isAvc}`)},_initAudioSourceBuffer(){const{proxy:e}=si.events;if(null===si.audioSourceBuffer&&null!==si.mediaSource&&si.isStateOpen()&&si.audioMimeType){try{si.audioSourceBuffer=si.mediaSource.addSourceBuffer(si.audioMimeType),si._clearAudioSourceBufferCheckTimeout(),ni.debug.log(si.TAG_NAME,"_initAudioSourceBuffer() mseDecoder.mediaSource.addSourceBuffer()",si.audioMimeType)}catch(e){return ni.debug.error(si.TAG_NAME,"appendAudioBuffer() mseDecoder.mediaSource.addSourceBuffer()",e.code,e),si.emitError(Te.mseAddSourceBufferError,e.code),void(si.mediaSourceAddSourceBufferError=!0)}if(si.audioSourceBuffer){const t=e(si.audioSourceBuffer,"error",(e=>{si.mediaSourceBufferError=!0,ni.debug.error(si.TAG_NAME,"mseSourceBufferError mseDecoder.audioSourceBuffer",e),si.emitError(Te.mseSourceBufferError,e.code)})),r=e(si.audioSourceBuffer,"updateend",(()=>{si._hasPendingRemoveRanges()?si._doRemoveRanges():si._hasPendingSegments()?si._doAppendSegments():si.hasPendingEos&&(ni.debug.log(si.TAG_NAME,"audioSourceBuffer updateend and hasPendingEos is true, next endOfStream()"),si.endOfStream())}));si.eventListenList.push(t,r),null===si.audioSourceNoDataCheckTimeout&&(si.audioSourceNoDataCheckTimeout=setTimeout((()=>{si._clearAudioNoDataCheckTimeout(),si.emitError(Te.mediaSourceAudioNoDataTimeout)}),1e3))}}else ni.debug.log(si.TAG_NAME,`_initAudioSourceBuffer and mseDecoder.isStateOpen is ${si.isStateOpen()} and mseDecoder.audioMimeType is ${si.audioMimeType}`)},_decodeVideo(e,t,r,i,s){let n=e.slice(5),a=n.byteLength;if(0===a)return void ni.debug.warn(si.TAG_NAME,"_decodeVideo payload bytes is 0 and return");let o=(new Date).getTime(),d=!1;si.prevTimestamp||(si.prevTimestamp=o,d=!0);const l=o-si.prevTimestamp;if(si.decodeDiffTimestamp=l,l>500&&!d&&ni.isPlayer&&ni.debug.warn(si.TAG_NAME,`_decodeVideo now time is ${o} and prev time is ${si.prevTimestamp}, diff time is ${l} ms`),si.cacheTrack.id&&t>=si.cacheTrack.dts){let e=8+si.cacheTrack.size,r=new Uint8Array(e);r[0]=e>>>24&255,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=255&e,r.set(hs.types.mdat,4),r.set(si.cacheTrack.data,8),si.cacheTrack.duration=t-si.cacheTrack.dts;let i=hs.moof(si.cacheTrack,si.cacheTrack.dts);si.cacheTrack={};let s=new Uint8Array(i.byteLength+r.byteLength);s.set(i,0),s.set(r,i.byteLength),si.appendBuffer(s.buffer)}else ni.debug.log(si.TAG_NAME,`timeInit set false , cacheTrack = {} now dts is ${t}, and ts is ${s} cacheTrack dts is ${si.cacheTrack&&si.cacheTrack.dts}`),si.timeInit=!1,si.cacheTrack={};si.cacheTrack||(si.cacheTrack={}),si.cacheTrack.id=It,si.cacheTrack.sequenceNumber=++si.sequenceNumber,si.cacheTrack.size=a,si.cacheTrack.dts=t,si.cacheTrack.cts=i,si.cacheTrack.isKeyframe=r,si.cacheTrack.data=n,si.cacheTrack.flags={isLeading:0,dependsOn:r?2:1,isDependedOn:r?1:0,hasRedundancy:0,isNonSync:r?0:1},si.prevTimestamp=(new Date).getTime()},_decodeAudio(e,t,r){let i=si.isAAC?e.slice(2):e.slice(1),s=i.byteLength;if(si.cacheAudioTrack.id&&t>=si.cacheAudioTrack.dts){let e=8+si.cacheAudioTrack.size,r=new Uint8Array(e);r[0]=e>>>24&255,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=255&e,r.set(hs.types.mdat,4),r.set(si.cacheAudioTrack.data,8),si.cacheAudioTrack.duration=t-si.cacheAudioTrack.dts;let i=hs.moof(si.cacheAudioTrack,si.cacheAudioTrack.dts);si.cacheAudioTrack={};let s=new Uint8Array(i.byteLength+r.byteLength);s.set(i,0),s.set(r,i.byteLength),si.appendAudioBuffer(s.buffer)}else si.cacheAudioTrack={};si.cacheAudioTrack||(si.cacheAudioTrack={}),si.cacheAudioTrack.id=Ft,si.cacheAudioTrack.sequenceNumber=++si.audioSequenceNumber,si.cacheAudioTrack.size=s,si.cacheAudioTrack.dts=t,si.cacheAudioTrack.cts=0,si.cacheAudioTrack.data=i,si.cacheAudioTrack.flags={isLeading:0,dependsOn:1,isDependedOn:0,hasRedundancy:0}},appendBuffer(e){ni.isDestroyed?ni.debug.warn(si.TAG_NAME,"appendBuffer() player is destroyed"):si.mediaSourceAddSourceBufferError?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceAddSourceBufferError is true"):si.mediaSourceAppendBufferFull?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceAppendBufferFull is true"):si.mediaSourceAppendBufferError?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceAppendBufferError is true"):si.mediaSourceBufferError?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceBufferError is true"):(si.pendingSegments.push(e),si.sourceBuffer&&(ni._opt.mseAutoCleanupSourceBuffer&&si._needCleanupSourceBuffer()&&si._doCleanUpSourceBuffer(),yr(si.getSourceBufferUpdating())&&si.isStateOpen()&&yr(si._hasPendingRemoveRanges()))?si._doAppendSegments():si.isStateClosed()?(si.mediaSourceBufferError=!0,si.emitError(Te.mseSourceBufferError,"mediaSource is not attached to video or mediaSource is closed")):si.isStateEnded()?(si.mediaSourceBufferError=!0,si.emitError(Te.mseSourceBufferError,"mediaSource is end")):si._hasPendingRemoveRanges()&&ni.debug.log(si.TAG_NAME,`video has pending remove ranges and video length is ${si.pendingRemoveRanges.length}, audio length is ${si.pendingAudioRemoveRanges.length}`))},appendAudioBuffer(e){ni.isDestroyed?ni.debug.warn(si.TAG_NAME,"appendAudioBuffer() player is destroyed"):si.mediaSourceAddSourceBufferError?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceAddSourceBufferError is true"):si.mediaSourceAppendBufferFull?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceAppendBufferFull is true"):si.mediaSourceAppendBufferError?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceAppendBufferError is true"):si.mediaSourceBufferError?ni.debug.warn(si.TAG_NAME,"mseDecoder.mediaSourceBufferError is true"):(si.pendingAudioSegments.push(e),si.audioSourceBuffer&&(ni._opt.mseAutoCleanupSourceBuffer&&si._needCleanupSourceBuffer()&&si._doCleanUpSourceBuffer(),yr(si.getAudioSourceBufferUpdating())&&si.isStateOpen()&&yr(si._hasPendingRemoveRanges()))?si._doAppendSegments():si.isStateClosed()?(si.mediaSourceBufferError=!0,si.emitError(Te.mseSourceBufferError,"mediaSource is not attached to video or mediaSource is closed")):si.isStateEnded()?(si.mediaSourceBufferError=!0,si.emitError(Te.mseSourceBufferError,"mediaSource is end")):si._hasPendingRemoveRanges()&&ni.debug.log(si.TAG_NAME,`audio has pending remove ranges and video length is ${si.pendingRemoveRanges.length}, audio length is ${si.pendingAudioRemoveRanges.length}`))},getSourceBufferUpdating:()=>si.sourceBuffer&&si.sourceBuffer.updating,getAudioSourceBufferUpdating:()=>si.audioSourceBuffer&&si.audioSourceBuffer.updating,stop(){si.abortSourceBuffer(),si.removeSourceBuffer(),si.endOfStream()},clearUpAllSourceBuffer(){if(si.sourceBuffer){const e=si.sourceBuffer.buffered;for(let t=0;tsi.pendingSegments.length>0||si.pendingAudioSegments.length>0,getPendingSegmentsLength:()=>si.pendingSegments.length,_handleUpdatePlaybackRate(){},_doAppendSegments(){if(si.isStateClosed()||si.isStateEnded())ni.debug.log(si.TAG_NAME,"_doAppendSegments() mediaSource is closed or ended and return");else if(null!==si.sourceBuffer){if(si.needInitAudio()&&null===si.audioSourceBuffer)return ni.debug.log(si.TAG_NAME,"_doAppendSegments() audioSourceBuffer is null and need init audio source buffer"),void(null===si.audioSourceBufferCheckTimeout&&(si.audioSourceBufferCheckTimeout=setTimeout((()=>{si._clearAudioSourceBufferCheckTimeout(),si.emitError(Te.mediaSourceAudioInitTimeout)}),1e3)));if(yr(si.getSourceBufferUpdating())&&si.pendingSegments.length>0){const e=si.pendingSegments.shift();try{si.sourceBuffer.appendBuffer(e)}catch(e){ni.debug.error(si.TAG_NAME,"mseDecoder.sourceBuffer.appendBuffer()",e.code,e),22===e.code?(si.stop(),si.mediaSourceAppendBufferFull=!0,si.emitError(Te.mediaSourceFull)):11===e.code?(si.stop(),si.mediaSourceAppendBufferError=!0,si.emitError(Te.mediaSourceAppendBufferError)):(si.stop(),si.mediaSourceBufferError=!0,si.emitError(Te.mseSourceBufferError,e.code))}}if(yr(si.getAudioSourceBufferUpdating())&&si.pendingAudioSegments.length>0){const e=si.pendingAudioSegments.shift();try{si.audioSourceBuffer.appendBuffer(e)}catch(e){ni.debug.error(si.TAG_NAME,"mseDecoder.audioSourceBuffer.appendBuffer()",e.code,e),22===e.code?(si.stop(),si.mediaSourceAppendBufferFull=!0,si.emitError(Te.mediaSourceFull)):11===e.code?(si.stop(),si.mediaSourceAppendBufferError=!0,si.emitError(Te.mediaSourceAppendBufferError)):(si.stop(),si.mediaSourceBufferError=!0,si.emitError(Te.mseSourceBufferError,e.code))}}}else ni.debug.log(si.TAG_NAME,"_doAppendSegments() sourceBuffer is null and wait init and return")},_doCleanUpSourceBuffer(){const e=si.$video.currentTime;if(si.sourceBuffer){const t=si.sourceBuffer.buffered;let r=!1;for(let i=0;i=ni._opt.mseAutoCleanupMaxBackwardDuration){r=!0;let t=e-ni._opt.mseAutoCleanupMinBackwardDuration;si.pendingRemoveRanges.push({start:s,end:t})}}else n=ni._opt.mseAutoCleanupMaxBackwardDuration){r=!0;let t=e-ni._opt.mseAutoCleanupMinBackwardDuration;si.pendingAudioRemoveRanges.push({start:s,end:t})}}else nsi.pendingRemoveRanges.length>0||si.pendingAudioRemoveRanges.length>0,needInitAudio:()=>ni._opt.hasAudio&&ni._opt.mseDecodeAudio,_doRemoveRanges(){if(si.sourceBuffer&&yr(si.getSourceBufferUpdating())){let e=si.pendingRemoveRanges;for(;e.length&&yr(si.getSourceBufferUpdating());){let t=e.shift();try{si.sourceBuffer.remove(t.start,t.end)}catch(e){ni.debug.warn(si.TAG_NAME,"_doRemoveRanges() sourceBuffer error",e)}}}if(si.audioSourceBuffer&&yr(si.getAudioSourceBufferUpdating())){let e=si.pendingAudioRemoveRanges;for(;e.length&&yr(si.getAudioSourceBufferUpdating());){let t=e.shift();try{si.audioSourceBuffer.remove(t.start,t.end)}catch(e){ni.debug.warn(si.TAG_NAME,"_doRemoveRanges() audioSourceBuffer error",e)}}}},_getPlaybackRate(){},_needCleanupSourceBuffer(){if(yr(ni._opt.mseAutoCleanupSourceBuffer))return!1;const e=si.$video.currentTime;if(si.sourceBuffer){let t=si.sourceBuffer.buffered;if(t.length>=1&&e-t.start(0)>=ni._opt.mseAutoCleanupMaxBackwardDuration)return!0}if(si.audioSourceBuffer){let t=si.audioSourceBuffer.buffered;if(t.length>=1&&e-t.start(0)>=ni._opt.mseAutoCleanupMaxBackwardDuration)return!0}return!1},_clearAudioSourceBufferCheckTimeout(){si.audioSourceBufferCheckTimeout&&(clearTimeout(si.audioSourceBufferCheckTimeout),si.audioSourceBufferCheckTimeout=null)},_clearAudioNoDataCheckTimeout(){si.audioSourceNoDataCheckTimeout&&(clearTimeout(si.audioSourceNoDataCheckTimeout),si.audioSourceNoDataCheckTimeout=null)},getHandle:()=>si.mediaSource.handle,emitError(e){postMessage({cmd:te,value:e,msg:arguments.length>1&&void 0!==arguments[1]?arguments[1]:""})}});let ni={isPlayer:!0,isPlayback:!1,dropping:!1,isPushDropping:!1,isWorkerFetch:!1,isDestroyed:!1,fetchStatus:Ct,_opt:Ar(),mp3Demuxer:null,delay:-1,pushLatestDelay:-1,firstTimestamp:null,startTimestamp:null,preDelayTimestamp:null,stopId:null,streamFps:null,streamAudioFps:null,streamVideoFps:null,writableStream:null,networkDelay:0,webglObj:null,startStreamRateAndStatsInterval:function(){ni.stopStreamRateAndStatsInterval(),l=setInterval((()=>{d&&d(0);const e=JSON.stringify({demuxBufferDelay:ni.getVideoBufferLength(),audioDemuxBufferDelay:ni.getAudioBufferLength(),streamBufferByteLength:ni.getStreamBufferLength(),netBuf:ni.networkDelay||0,pushLatestDelay:ni.pushLatestDelay||0,latestDelay:ni.delay,isStreamTsMoreThanLocal:Ye});postMessage({cmd:R,type:Ue,value:e})}),1e3)},stopStreamRateAndStatsInterval:function(){l&&(clearInterval(l),l=null)},useOffscreen:function(){return ni._opt.useOffscreen&&"undefined"!=typeof OffscreenCanvas},getDelay:function(e,t){if(!e||ni._opt.hasVideo&&!qe)return-1;if(t===re)return ni.delay;if(ni.preDelayTimestamp&&ni.preDelayTimestamp>e)return ni.preDelayTimestamp-e>1e3&&ni.debug.warn("worker",`getDelay() and preDelayTimestamp is ${ni.preDelayTimestamp} > timestamp is ${e} more than ${ni.preDelayTimestamp-e}ms and return ${ni.delay}`),ni.preDelayTimestamp=e,ni.delay;if(ni.firstTimestamp){if(e){const t=Date.now()-ni.startTimestamp,r=e-ni.firstTimestamp;t>=r?(Ye=!1,ni.delay=t-r):(Ye=!0,ni.delay=r-t)}}else ni.firstTimestamp=e,ni.startTimestamp=Date.now(),ni.delay=-1;return ni.preDelayTimestamp=e,ni.delay},getDelayNotUpdateDelay:function(e,t){if(!e||ni._opt.hasVideo&&!qe)return-1;if(t===re)return ni.pushLatestDelay;if(ni.preDelayTimestamp&&ni.preDelayTimestamp-e>1e3)return ni.debug.warn("worker",`getDelayNotUpdateDelay() and preDelayTimestamp is ${ni.preDelayTimestamp} > timestamp is ${e} more than ${ni.preDelayTimestamp-e}ms and return -1`),-1;if(ni.firstTimestamp){let t=-1;if(e){const r=Date.now()-ni.startTimestamp,i=e-ni.firstTimestamp;r>=i?(Ye=!1,t=r-i):(Ye=!0,t=i-r)}return t}return-1},resetDelay:function(){ni.firstTimestamp=null,ni.startTimestamp=null,ni.delay=-1,ni.dropping=!1},resetAllDelay:function(){ni.resetDelay(),ni.preDelayTimestamp=null},doDecode:function(e){ni._opt.isEmitSEI&&e.type===ie&&ni.isWorkerFetch&&ni.findSei(e.payload,e.ts),ni.isPlayUseMSEAndDecoderInWorker()?e.type===re?ni._opt.mseDecodeAudio?si.decodeAudio(e.payload,e.ts):e.decoder.decode(e.payload,e.ts):e.type===ie&&si.decodeVideo(e.payload,e.ts,e.isIFrame,e.cts):ni._opt.useWCS&&ni.useOffscreen()&&e.type===ie&&n.decode?n.decode(e.payload,e.ts,e.cts):e.decoder.decode(e.payload,e.ts,e.isIFrame,e.cts)},decodeNext(e){if(0===i.length)return;const t=e.ts,s=i[0],n=e.type===ie&&_r(e.payload);if(yr(r))n&&(ni.debug.log("worker",`decode data type is ${e.type} and\n ts is ${t} next data type is ${s.type} ts is ${s.ts}\n isVideoSqeHeader is ${n}`),i.shift(),ni.doDecode(s));else{const r=s.ts-t,a=s.type===re&&e.type===ie;(r<=20||a||n)&&(ni.debug.log("worker",`decode data type is ${e.type} and\n ts is ${t} next data type is ${s.type} ts is ${s.ts}\n diff is ${r} and isVideoAndNextAudio is ${a} and isVideoSqeHeader is ${n}`),i.shift(),ni.doDecode(s))}},init:function(){ni.debug.log("worker","init and opt is",JSON.stringify(ni._opt));const e=ni._opt.playType===m,t=ni._opt.playType===_;if(Gr.init(),ni.isPlayer=e,ni.isPlayback=t,ni.isPlayUseMSEAndDecoderInWorker()&&si&&si.init(),ni.isPlaybackCacheBeforeDecodeForFpsRender())ni.debug.log("worker","playback and playbackIsCacheBeforeDecodeForFpsRender is true");else{ni.debug.log("worker","setInterval()");const t=ni._opt.videoBuffer+ni._opt.videoBufferDelay,r=()=>{let r=null;if(i.length){if(ni.isPushDropping)return void ni.debug.warn("worker",`loop() isPushDropping is true and bufferList length is ${i.length}`);if(ni.dropping){for(r=i.shift(),ni.debug.warn("worker",`loop() dropBuffer is dropping and isIFrame ${r.isIFrame} and delay is ${ni.delay} and bufferlist is ${i.length}`);!r.isIFrame&&i.length;)r=i.shift();const e=ni.getDelayNotUpdateDelay(r.ts,r.type);r.isIFrame&&e<=ni.getNotDroppingDelayTs()&&(ni.debug.log("worker","loop() is dropping = false, is iFrame"),ni.dropping=!1,ni.doDecode(r),ni.decodeNext(r))}else if(ni.isPlayback||ni.isPlayUseMSE()||0===ni._opt.videoBuffer)for(;i.length;)r=i.shift(),ni.doDecode(r);else if(r=i[0],-1===ni.getDelay(r.ts,r.type))ni.debug.log("worker","loop() common dumex delay is -1 ,data.ts is",r.ts),i.shift(),ni.doDecode(r),ni.decodeNext(r);else if(ni.delay>t&&e)ni.hasIframeInBufferList()?(ni.debug.log("worker",`delay is ${ni.delay} > maxDelay ${t}, set dropping is true`),ni.resetAllDelay(),ni.dropping=!0,postMessage({cmd:N})):(i.shift(),ni.doDecode(r),ni.decodeNext(r));else for(;i.length;){if(r=i[0],!(ni.getDelay(r.ts,r.type)>ni._opt.videoBuffer)){ni.delay<0&&ni.debug.warn("worker",`loop() do not decode and delay is ${ni.delay}, bufferList is ${i.length}`);break}i.shift(),ni.doDecode(r)}}else-1!==ni.delay&&ni.debug.log("worker","loop() bufferList is empty and reset delay"),ni.resetAllDelay()};ni.stopId=setInterval((()=>{let e=(new Date).getTime();Xe||(Xe=e);const t=e-Xe;t>100&&ni.debug.warn("worker",`loop demux diff time is ${t}`),r(),Xe=(new Date).getTime()}),20)}if(yr(ni._opt.checkFirstIFrame)&&(qe=!0),ni.isPlayUseMSEAndDecoderInWorker()&&si){const e=si.getHandle();e&&postMessage({cmd:Q,mseHandle:e},[e])}},playbackCacheLoop:function(){ni.stopId&&(clearInterval(ni.stopId),ni.stopId=null);const e=()=>{let e=null;i.length&&(e=i.shift(),ni.doDecode(e))};e();const t=Math.ceil(1e3/(ni.streamFps*ni._opt.playbackRate));ni.debug.log("worker",`playbackCacheLoop fragDuration is ${t}, streamFps is ${ni.streamFps}, streamAudioFps is ${ni.streamAudioFps} ,streamVideoFps is ${ni.streamVideoFps} playbackRate is ${ni._opt.playbackRate}`),ni.stopId=setInterval(e,t)},close:function(){if(ni.debug.log("worker","close"),ni.isDestroyed=!0,Tr(),!o||1!==o.readyState&&2!==o.readyState?o&&ni.debug.log("worker",`close() and socket.readyState is ${o.readyState}`):(Sr=!0,o.close(1e3,"Client disconnecting")),o=null,ni.stopStreamRateAndStatsInterval(),ni.stopId&&(clearInterval(ni.stopId),ni.stopId=null),ni.mp3Demuxer&&(ni.mp3Demuxer.destroy(),ni.mp3Demuxer=null),ni.writableStream&&yr(ni.writableStream.locked)&&ni.writableStream.close().catch((e=>{ni.debug.log("worker","close() and writableStream.close() error",e)})),ni.writableStream=null,ai)try{ai.clear&&ai.clear(),ai=null}catch(e){ni.debug.warn("worker","close() and audioDecoder.clear error",e)}if(oi)try{oi.clear&&oi.clear(),oi=null}catch(e){ni.debug.warn("worker","close() and videoDecoder.clear error",e)}d=null,Xe=null,Ye=!1,n&&(n.reset&&n.reset(),n=null),si&&(si.destroy(),si=null),ni.firstTimestamp=null,ni.startTimestamp=null,ni.networkDelay=0,ni.streamFps=null,ni.streamAudioFps=null,ni.streamVideoFps=null,ni.delay=-1,ni.pushLatestDelay=-1,ni.preDelayTimestamp=null,ni.dropping=!1,ni.isPushDropping=!1,ni.isPlayer=!0,ni.isPlayback=!1,ni.isWorkerFetch=!1,ni._opt=Ar(),ni.webglObj&&(ni.webglObj.destroy(),ni.offscreenCanvas.removeEventListener("webglcontextlost",ni.onOffscreenCanvasWebglContextLost),ni.offscreenCanvas.removeEventListener("webglcontextrestored",ni.onOffscreenCanvasWebglContextRestored),ni.offscreenCanvas=null,ni.offscreenCanvasGL=null,ni.offscreenCanvasCtx=null),i=[],s=[],y&&(y.buffer=null,y=null),E=null,ge=null,ye=!1,Ge=!1,qe=!1,Gt=!1,$t=!1,qt=!1,Zt=null,ir=null,ft=[],_t=0,Et=0,Je=null,at=null,At=null,Bt=null,wr=null,Nt=0,Ot=0,pt=null,mt=null,ni.fetchStatus=Ct,Er=!0,Gr.destroy(),$r.destroy(),jr.destroy(),ii.destroy(),postMessage({cmd:W})},pushBuffer:function(e,t){if(t.type===re&&Wt(e)){if(ni.debug.log("worker",`pushBuffer audio ts is ${t.ts}, isAacCodecPacket is true`),ni._opt.isRecordTypeFlv){const t=new Uint8Array(e);postMessage({cmd:K,buffer:t},[t.buffer])}ni.decodeAudio(e,t.ts)}else if(t.type===ie&&t.isIFrame&&_r(e)){if(ni.debug.log("worker",`pushBuffer video ts is ${t.ts}, isVideoSequenceHeader is true`),ni._opt.isRecordTypeFlv){const t=new Uint8Array(e);postMessage({cmd:X,buffer:t},[t.buffer])}ni.decodeVideo(e,t.ts,t.isIFrame,t.cts)}else{if(ni._opt.isRecording)if(ni._opt.isRecordTypeFlv){const r=new Uint8Array(e);postMessage({cmd:Z,type:t.type,buffer:r,ts:t.ts},[r.buffer])}else if(ni._opt.recordType===g)if(t.type===ie){const r=new Uint8Array(e).slice(5);postMessage({cmd:P,buffer:r,isIFrame:t.isIFrame,ts:t.ts,cts:t.cts},[r.buffer])}else if(t.type===re&&ni._opt.isWasmMp4){const r=new Uint8Array(e),i=jt(r)?r.slice(2):r.slice(1);postMessage({cmd:k,buffer:i,ts:t.ts},[i.buffer])}if(ni.isPlayer&&Nt>0&&Bt>0&&t.type===ie){const e=t.ts-Bt,r=Nt+Nt/2;e>r&&ni.debug.log("worker",`pushBuffer video\n ts is ${t.ts}, preTimestamp is ${Bt},\n diff is ${e} and preTimestampDuration is ${Nt} and maxDiff is ${r}\n maybe trigger black screen or flower screen\n `)}if(ni.isPlayer&&Bt>0&&t.type===ie&&t.tsv&&(ni.debug.warn("worker",`pushBuffer,\n preTimestamp is ${Bt}, options.ts is ${t.ts},\n diff is ${Bt-t.ts} more than 3600000,\n and resetAllDelay`),ni.resetAllDelay(),Bt=null,Nt=0),ni.isPlayer&&Bt>0&&t.ts<=Bt&&t.type===ie&&(ni.debug.warn("worker",`pushBuffer() and isIFrame is ${t.isIFrame} and,\n options.ts is ${t.ts} less than (or equal) preTimestamp is ${Bt} and\n payloadBufferSize is ${e.byteLength} and prevPayloadBufferSize is ${Ot}`),ni._opt.isDropSameTimestampGop&&yr(t.isIFrame)&&qe)){const e=ni.hasIframeInBufferList(),t=yr(ni.isPushDropping);return ni.debug.log("worker",`pushBuffer, isDropSameTimestampGop is true and\n hasIframe is ${e} and isNotPushDropping is ${t} and next dropBuffer`),void(e&&t?ni.dropBuffer$2():(ni.clearBuffer(!0),gr(ni._opt.checkFirstIFrame)&&gr(r)&&(ni.isPlayUseMSEAndDecoderInWorker()?si.isDecodeFirstIIframe=!1:postMessage({cmd:J}))))}if(ni.isPlayer&&qe){const e=ni._opt.videoBuffer+ni._opt.videoBufferDelay,r=ni.getDelayNotUpdateDelay(t.ts,t.type);ni.pushLatestDelay=r,r>e&&ni.delay0&&ni.hasIframeInBufferList()&&!1===ni.isPushDropping&&(ni.debug.log("worker",`pushBuffer(), pushLatestDelay is ${r} more than ${e} and decoder.delay is ${ni.delay} and has iIframe and next decoder.dropBuffer$2()`),ni.dropBuffer$2())}if(ni.isPlayer&&t.type===ie&&(Bt>0&&(Nt=t.ts-Bt),Ot=e.byteLength,Bt=t.ts),t.type===re?i.push({ts:t.ts,payload:e,decoder:{decode:ni.decodeAudio},type:re,isIFrame:!1}):t.type===ie&&i.push({ts:t.ts,cts:t.cts,payload:e,decoder:{decode:ni.decodeVideo},type:ie,isIFrame:t.isIFrame}),ni.isPlaybackCacheBeforeDecodeForFpsRender()&&(or(ni.streamVideoFps)||or(ni.streamAudioFps))){let e=ni.streamVideoFps,t=ni.streamAudioFps;if(or(ni.streamVideoFps)&&(e=fr(i,ie),e&&(ni.streamVideoFps=e,postMessage({cmd:G,value:ni.streamVideoFps}),ni.streamFps=t?e+t:e,yr(ni._opt.hasAudio)&&(ni.debug.log("worker","playbackCacheBeforeDecodeForFpsRender, _opt.hasAudio is false and set streamAudioFps is 0"),ni.streamAudioFps=0),ni.playbackCacheLoop())),or(ni.streamAudioFps)&&(t=fr(i,re),t&&(ni.streamAudioFps=t,ni.streamFps=e?e+t:t,ni.playbackCacheLoop())),or(ni.streamVideoFps)&&or(ni.streamAudioFps)){const r=i.map((e=>({type:e.type,ts:e.ts})));ni.debug.log("worker",`playbackCacheBeforeDecodeForFpsRender, calc streamAudioFps is ${t}, streamVideoFps is ${e}, bufferListLength is ${i.length}, and ts list is ${JSON.stringify(r)}`)}const r=ni.getAudioBufferLength()>0,s=r?60:40;i.length>=s&&(ni.debug.warn("worker",`playbackCacheBeforeDecodeForFpsRender, bufferListLength is ${i.length} more than ${s}, and hasAudio is ${r} an set streamFps is 25`),ni.streamVideoFps=25,postMessage({cmd:G,value:ni.streamVideoFps}),r?(ni.streamAudioFps=25,ni.streamFps=ni.streamVideoFps+ni.streamAudioFps):ni.streamFps=ni.streamVideoFps,ni.playbackCacheLoop())}}},getVideoBufferLength(){let e=0;return i.forEach((t=>{t.type===ie&&(e+=1)})),e},hasIframeInBufferList:()=>i.some((e=>e.type===ie&&e.isIFrame)),isAllIframeInBufferList(){const e=ni.getVideoBufferLength();let t=0;return i.forEach((e=>{e.type===ie&&e.isIFrame&&(t+=1)})),e===t},getNotDroppingDelayTs:()=>ni._opt.videoBuffer+ni._opt.videoBufferDelay/2,getAudioBufferLength(){let e=0;return i.forEach((t=>{t.type===re&&(e+=1)})),e},getStreamBufferLength(){let e=0;return y&&y.buffer&&(e=y.buffer.byteLength),ni._opt.isNakedFlow?Gr.lastBuf&&(e=Gr.lastBuf.byteLength):ni._opt.isTs?ii._remainingPacketData&&(e=ii._remainingPacketData.byteLength):ni._opt.isFmp4&&$r.mp4Box&&(e=$r.mp4Box.getAllocatedSampleDataSize()),e},fetchStream:function(e,t){ni.debug.log("worker","fetchStream, url is "+e,"options:",JSON.stringify(t)),ni.isWorkerFetch=!0,t.isFlv?ni._opt.isFlv=!0:t.isFmp4?ni._opt.isFmp4=!0:t.isMpeg4?ni._opt.isMpeg4=!0:t.isNakedFlow?ni._opt.isNakedFlow=!0:t.isTs&&(ni._opt.isTs=!0),d=sr((e=>{postMessage({cmd:R,type:ve,value:e})})),ni.startStreamRateAndStatsInterval(),t.isFmp4&&($r.listenMp4Box(),ni._opt.isFmp4Private&&$r.initTransportDescarmber()),t.protocol===h?(y=new Ur(ni.demuxFlv()),fetch(e,{signal:a.signal}).then((e=>{if(gr(Sr))return ni.debug.log("worker","request abort and run res.body.cancel()"),ni.fetchStatus=Ct,void e.body.cancel();if(!pr(e))return ni.debug.warn("worker",`fetch response status is ${e.status} and ok is ${e.ok} and emit error and next abort()`),Tr(),void postMessage({cmd:R,type:Te.fetchError,value:`fetch response status is ${e.status} and ok is ${e.ok}`});if(postMessage({cmd:R,type:Ae}),cr())ni.writableStream=new WritableStream({write:e=>a&&a.signal&&a.signal.aborted?(ni.debug.log("worker","writableStream write() and abortController.signal.aborted is true so return"),void(ni.fetchStatus=Dt)):gr(Sr)?(ni.debug.log("worker","writableStream write() and requestAbort is true so return"),void(ni.fetchStatus=Dt)):void("string"!=typeof e?(ni.fetchStatus=kt,d(e.byteLength),t.isFlv?y.write(e):t.isFmp4?ni.demuxFmp4(e):t.isMpeg4?ni.demuxMpeg4(e):t.isTs&&ni.demuxTs(e)):ni.debug.warn("worker",`writableStream write() and value is "${e}" string so return`)),close:()=>{ni.debug.log("worker","writableStream close()"),ni.fetchStatus=Dt,y=null,Tr(),postMessage({cmd:R,type:be,value:f,msg:"fetch done"})},abort:e=>{if(a&&a.signal&&a.signal.aborted)return ni.debug.log("worker","writableStream abort() and abortController.signal.aborted is true so return"),void(ni.fetchStatus=Dt);y=null,e.name!==Ut?(ni.debug.log("worker",`writableStream abort() and e is ${e.toString()}`),Tr(),postMessage({cmd:R,type:Te.fetchError,value:e.toString()})):ni.debug.log("worker","writableStream abort() and e.name is AbortError so return")}}),e.body.pipeTo(ni.writableStream);else{const r=e.body.getReader(),i=()=>{r.read().then((e=>{let{done:r,value:s}=e;return r?(ni.debug.log("worker","fetchNext().then() and done is true"),ni.fetchStatus=Dt,y=null,Tr(),void postMessage({cmd:R,type:be,value:f,msg:"fetch done"})):a&&a.signal&&a.signal.aborted?(ni.debug.log("worker","fetchNext().then() and abortController.signal.aborted is true so return"),void(ni.fetchStatus=Dt)):gr(Sr)?(ni.debug.log("worker","fetchNext().then() and requestAbort is true so return"),void(ni.fetchStatus=Dt)):void("string"!=typeof s?(ni.fetchStatus=kt,d(s.byteLength),t.isFlv?y.write(s):t.isFmp4?ni.demuxFmp4(s):t.isMpeg4?ni.demuxMpeg4(s):t.isTs&&ni.demuxTs(s),i()):ni.debug.warn("worker",`fetchNext().then() and value "${s}" is string so return`))})).catch((e=>{if(a&&a.signal&&a.signal.aborted)return ni.debug.log("worker","fetchNext().catch() and abortController.signal.aborted is true so return"),void(ni.fetchStatus=Dt);y=null,e.name!==Ut?(ni.debug.log("worker",`fetchNext().catch() and e is ${e.toString()}`),Tr(),postMessage({cmd:R,type:Te.fetchError,value:e.toString()})):ni.debug.log("worker","fetchNext().catch() and e.name is AbortError so return")}))};i()}})).catch((e=>{a&&a.signal&&a.signal.aborted?ni.debug.log("worker","fetch().catch() and abortController.signal.aborted is true so return"):e.name!==Ut?(ni.debug.log("worker",`fetch().catch() and e is ${e.toString()}`),Tr(),postMessage({cmd:R,type:Te.fetchError,value:e.toString()}),y=null):ni.debug.log("worker","fetch().catch() and e.name is AbortError so return")}))):t.protocol===c&&(t.isFlv&&(y=new Ur(ni.demuxFlv())),o=new WebSocket(e),o.binaryType="arraybuffer",o.onopen=()=>{ni.debug.log("worker","fetchStream, WebsocketStream socket open"),postMessage({cmd:R,type:Ae}),postMessage({cmd:R,type:Be})},o.onclose=e=>{b?ni.debug.log("worker","fetchStream, WebsocketStream socket close and isSocketError is true , so return"):(ni.debug.log("worker",`fetchStream, WebsocketStream socket close and code is ${e.code}`),1006===e.code&&ni.debug.error("worker",`fetchStream, WebsocketStream socket close abnormally and code is ${e.code}`),gr(Sr)?ni.debug.log("worker","fetchStream, WebsocketStream socket close and requestAbort is true so return"):(y=null,postMessage({cmd:R,type:be,value:p,msg:e.code})))},o.onerror=e=>{ni.debug.error("worker","fetchStream, WebsocketStream socket error",e),b=!0,y=null,postMessage({cmd:R,type:Te.websocketError,value:e.isTrusted?"websocket user aborted":"websocket error"})},o.onmessage=e=>{"string"!=typeof e.data?(d(e.data.byteLength),t.isFlv?y.write(e.data):t.isFmp4?ni.demuxFmp4(e.data):t.isMpeg4?ni.demuxMpeg4(e.data):ni._opt.isNakedFlow?ni.demuxNakedFlow(e.data):ni.demuxM7s(e.data)):ni.debug.warn("worker",`socket on message is string "${e.data}" and return`)})},demuxFlv:function*(){yield 9;const e=new ArrayBuffer(4),t=new Uint8Array(e),r=new Uint32Array(e);for(;;){t[3]=0;const e=yield 15,i=e[4];t[0]=e[7],t[1]=e[6],t[2]=e[5];const s=r[0];t[0]=e[10],t[1]=e[9],t[2]=e[8],t[3]=e[11];let n=r[0];const a=(yield s).slice();switch(i){case se:if(a.byteLength>0){let e=a;gr(ni._opt.m7sCryptoAudio)&&(e=ni.cryptoPayloadAudio(a)),ni.decode(e,{type:re,ts:n})}else ni.debug.warn("worker",`demuxFlv() type is audio and payload.byteLength is ${a.byteLength} and return`);break;case ne:if(a.byteLength>=6){const e=a[0];if(ni._isEnhancedH265Header(e))ni._decodeEnhancedH265Video(a,n);else{const e=15&a[0];let t=a[0]>>4===Tt;const i=e===De;if(yr(t)&&gr(vr(a,i))&&(ni.debug.log("worker","demux() isIFrame is false and unit type is IDR and update to true"),t=!0),t&&_r(a)&&null===Zt){const e=15&a[0];Zt=e===De,ir=er(a,Zt),ni.debug.log("worker",`demuxFlv() isVideoSequenceHeader is true and isHevc is ${Zt} and nalUnitSize is ${ir}`)}t&&ni.calcIframeIntervalTimestamp(n),ni.isPlayer&&ni.calcNetworkDelay(n),r[0]=a[4],r[1]=a[3],r[2]=a[2],r[3]=0;let s=r[0],o=ni.cryptoPayload(a,t);ni.decode(o,{type:ie,ts:n,isIFrame:t,cts:s})}}else ni.debug.warn("worker",`demuxFlv() type is video and payload.byteLength is ${a.byteLength} and return`);break;case ae:postMessage({cmd:Y,buffer:a},[a.buffer]);break;default:ni.debug.log("worker",`demuxFlv() type is ${i}`)}}},decode:function(e,t){t.type===re?ni._opt.hasAudio&&(postMessage({cmd:R,type:we,value:e.byteLength}),ni.isPlayer?ni.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts}):ni.isPlayback&&(ni.isPlaybackOnlyDecodeIFrame()||(ni.isPlaybackCacheBeforeDecodeForFpsRender(),ni.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts})))):t.type===ie&&ni._opt.hasVideo&&(postMessage({cmd:R,type:Se,value:e.byteLength}),postMessage({cmd:R,type:Ee,value:t.ts}),ni.isPlayer?ni.pushBuffer(e,{type:t.type,ts:t.ts,isIFrame:t.isIFrame,cts:t.cts}):ni.isPlayback&&(ni.isPlaybackOnlyDecodeIFrame()?t.isIFrame&&ni.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts,isIFrame:t.isIFrame}):(ni.isPlaybackCacheBeforeDecodeForFpsRender(),ni.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts,isIFrame:t.isIFrame}))))},cryptoPayload:function(e,t){let r=e;return ni._opt.isM7sCrypto?ni._opt.cryptoIV&&ni._opt.cryptoIV.byteLength>0&&ni._opt.cryptoKey&&ni._opt.cryptoKey.byteLength>0?r=Ri(e,ni._opt.cryptoKey,ni._opt.cryptoIV,Zt):ni.debug.error("worker",`isM7sCrypto cryptoKey.length is ${ni._opt.cryptoKey&&ni._opt.cryptoKey.byteLength} or cryptoIV.length is ${ni._opt.cryptoIV&&ni._opt.cryptoIV.byteLength} null`):ni._opt.isSm4Crypto?ni._opt.sm4CryptoKey&&t?r=ss(e,ni._opt.sm4CryptoKey):ni._opt.sm4CryptoKey||ni.debug.error("worker","isSm4Crypto opt.sm4CryptoKey is null"):ni._opt.isXorCrypto&&(ni._opt.cryptoIV&&ni._opt.cryptoIV.byteLength>0&&ni._opt.cryptoKey&&ni._opt.cryptoKey.byteLength>0?r=ls(e,ni._opt.cryptoKey,ni._opt.cryptoIV,Zt):ni.debug.error("worker",`isXorCrypto cryptoKey.length is ${ni._opt.cryptoKey&&ni._opt.cryptoKey.byteLength} or cryptoIV.length is ${ni._opt.cryptoIV&&ni._opt.cryptoIV.byteLength} null`)),r},cryptoPayloadAudio:function(e){let t=e;return ni._opt.isM7sCrypto&&(ni._opt.cryptoIV&&ni._opt.cryptoIV.byteLength>0&&ni._opt.cryptoKey&&ni._opt.cryptoKey.byteLength>0?e[0]>>4===Le&&(t=zi(e,ni._opt.cryptoKey,ni._opt.cryptoIV)):ni.debug.error("worker",`isM7sCrypto cryptoKey.length is ${ni._opt.cryptoKey&&ni._opt.cryptoKey.byteLength} or cryptoIV.length is ${ni._opt.cryptoIV&&ni._opt.cryptoIV.byteLength} null`)),t},setCodecAudio:function(e,t){const r=e[0]>>4,i=e[0]>>1&1;if(wr=r===Le?i?16:8:0===i?8:16,ai&&ai.setCodec)if(Wt(e)||r===Me||r===Re||r===ze){ni.debug.log("worker",`setCodecAudio: init audio codec, codeId is ${r}`);const i=r===Le?e.slice(2):new Uint8Array(0);ai.setCodec(r,ni._opt.sampleRate,i),r===Le&&postMessage({cmd:D,buffer:i},[i.buffer]),Ge=!0,r!==Le&&(r===ze?(ni.mp3Demuxer||(ni.mp3Demuxer=new as(ni),ni.mp3Demuxer.on("data",((e,t)=>{ai.decode(e,t)}))),ni.mp3Demuxer.dispatch(e.slice(1),t)):ai.decode(e.slice(1),t));{const e=Number("1")||1;setTimeout((()=>{ni.debug.error("worker","Jb pro 体验结束,请刷新页面再次体验(wasm内部会暂停解码),如需要购买商业授权,可以联系微信:bosswancheng"),ni.close(),postMessage({cmd:O})}),60*e*60*1e3)}}else ni.debug.warn("worker","setCodecAudio: hasInitAudioCodec is false, codecId is ",r);else ni.debug.error("worker","setCodecAudio: audioDecoder or audioDecoder.setCodec is null")},decodeAudio:function(e,t){if(ni.isDestroyed)ni.debug.log("worker","decodeAudio, decoder is destroyed and return");else if(ni.isPlayUseMSEAndDecoderInWorkerAndMseDecodeAudio())si.decodeAudio(e,t);else if(gr(r)&&gr(ni._opt.mseDecodeAudio))postMessage({cmd:M,payload:e,ts:t,cts:t},[e.buffer]);else{const r=e[0]>>4;if(Ge){if(Wt(e))return void ni.debug.log("worker","decodeAudio and has already initialized and payload is aac codec packet so drop this frame");r===ze?ni.mp3Demuxer.dispatch(e.slice(1),t):ai.decode(r===Le?e.slice(2):e.slice(1),t)}else ni.setCodecAudio(e,t)}},setCodecVideo:function(e){const t=15&e[0];if(oi&&oi.setCodec)if(_r(e))if(t===ke||t===De){ni.debug.log("worker",`setCodecVideo: init video codec , codecId is ${t}`);const r=e.slice(5);if(t===ke&&ni._opt.useSIMD){const e=Cr(r);if(e.codecWidth>w||e.codecHeight>w)return postMessage({cmd:V}),void ni.debug.warn("worker",`setCodecVideo: SIMD H264 decode video width is too large, width is ${e.codecWidth}, height is ${e.codecHeight}`)}const i=new Uint8Array(e);ye=!0,oi.setCodec(t,r),postMessage({cmd:I,code:t}),postMessage({cmd:F,buffer:i,codecId:t},[i.buffer])}else ni.debug.warn("worker",`setCodecVideo: hasInitVideoCodec is false, codecId is ${t} is not H264 or H265`);else ni.debug.warn("worker",`decodeVideo: hasInitVideoCodec is false, codecId is ${t} and frameType is ${e[0]>>4} and packetType is ${e[1]}`);else ni.debug.error("worker","setCodecVideo: videoDecoder or videoDecoder.setCodec is null")},decodeVideo:function(e,t,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;if(ni.isDestroyed)ni.debug.log("worker","decodeVideo, decoder is destroyed and return");else if(ni.isPlayUseMSEAndDecoderInWorker())si.decodeVideo(e,t,i,s);else if(gr(r))postMessage({cmd:L,payload:e,isIFrame:i,ts:t,cts:s,delay:ni.delay},[e.buffer]);else if(ye)if(!qe&&i&&(qe=!0),qe){if(i&&_r(e)){const t=15&e[0];let r={};t===ke?r=Cr(e.slice(5)):t===De&&(r=Vr(e)),r.codecWidth&&r.codecHeight&&E&&ge&&(r.codecWidth!==E||r.codecHeight!==ge)&&(ni.debug.warn("worker",`\n decodeVideo: video width or height is changed,\n old width is ${E}, old height is ${ge},\n new width is ${r.codecWidth}, new height is ${r.codecHeight},\n and emit change event`),$t=!0,postMessage({cmd:$}))}if($t)return void ni.debug.warn("worker","decodeVideo: video width or height is changed, and return");if(qt)return void ni.debug.warn("worker","decodeVideo: simd decode error, and return");if(_r(e))return void ni.debug.warn("worker","decodeVideo and payload is video sequence header so drop this frame");if(e.byteLength0&&void 0!==arguments[0]&&arguments[0];ni.debug.log("worker",`clearBuffer,bufferList length is ${i.length}, need clear is ${e}`),e&&(i=[]),ni.isPlayer&&(ni.resetAllDelay(),gr(ni._opt.checkFirstIFrame)&&(ni.dropping=!0,postMessage({cmd:N}))),gr(ni._opt.checkFirstIFrame)&&yr(r)&&(qe=!1)},dropBuffer$2:function(){if(i.length>0){let e=i.findIndex((e=>gr(e.isIFrame)&&e.type===ie));if(ni.isAllIframeInBufferList())for(let t=0;t=ni.getNotDroppingDelayTs()){ni.debug.log("worker",`dropBuffer$2() isAllIframeInBufferList() is true, and index is ${t} and tempDelay is ${s} and notDroppingDelayTs is ${ni.getNotDroppingDelayTs()}`),e=t;break}}if(e>=0){ni.isPushDropping=!0,postMessage({cmd:N});const t=i.length;i=i.slice(e);const r=i.shift();ni.resetAllDelay(),ni.getDelay(r.ts,r.type),ni.doDecode(r),ni.isPushDropping=!1,ni.debug.log("worker",`dropBuffer$2() iFrameIndex is ${e},and old bufferList length is ${t} ,new bufferList is ${i.length} and new delay is ${ni.delay} `)}else ni.isPushDropping=!1}0===i.length&&(ni.isPushDropping=!1)},demuxM7s:function(e){const t=new DataView(e),r=t.getUint32(1,!1),i=t.getUint8(0),s=new ArrayBuffer(4),n=new Uint32Array(s);switch(i){case re:ni.decode(new Uint8Array(e,5),{type:re,ts:r});break;case ie:if(t.byteLength>=11){const i=new Uint8Array(e,5),s=i[0];if(ni._isEnhancedH265Header(s))ni._decodeEnhancedH265Video(i,r);else{const e=t.getUint8(5)>>4==1;if(e&&(ni.calcIframeIntervalTimestamp(r),_r(i)&&null===Zt)){const e=15&i[0];Zt=e===De}ni.isPlayer&&ni.calcNetworkDelay(r),n[0]=i[4],n[1]=i[3],n[2]=i[2],n[3]=0;let s=n[0],a=ni.cryptoPayload(i,e);ni.decode(a,{type:ie,ts:r,isIFrame:e,cts:s})}}else ni.debug.warn("worker",`demuxM7s() type is video and arrayBuffer length is ${e.byteLength} and return`)}},demuxNakedFlow:function(e){Gr.dispatch(e)},demuxFmp4:function(e){$r.dispatch(e)},demuxMpeg4:function(e){jr.dispatch(e)},demuxTs:function(e){ii.dispatch(e)},_decodeEnhancedH265Video:function(e,t){const r=e[0],i=48&r,s=15&r,n=e.slice(1,5),a=new ArrayBuffer(4),o=new Uint32Array(a),d="a"==String.fromCharCode(n[0]);if(Zt=yr(d),s===Lt){if(i===zt){const r=e.slice(5);if(d);else{const i=new Uint8Array(5+r.length);i.set([28,0,0,0,0],0),i.set(r,5),ir=er(e,Zt),ni.debug.log("worker",`demuxFlv() isVideoSequenceHeader(enhancedH265) is true and isHevc is ${Zt} and nalUnitSize is ${ir}`),ni.decode(i,{type:ie,ts:t,isIFrame:!0,cts:0})}}}else if(s===Mt){let r=e,s=0;const n=i===zt;n&&ni.calcIframeIntervalTimestamp(t),d||(o[0]=e[4],o[1]=e[3],o[2]=e[2],o[3]=0,s=o[0],r=Kr(e.slice(8),n),r=ni.cryptoPayload(r,n),ni.decode(r,{type:ie,ts:t,isIFrame:n,cts:s}))}else if(s===Rt){const r=i===zt;r&&ni.calcIframeIntervalTimestamp(t);let s=Kr(e.slice(5),r);s=ni.cryptoPayload(s,r),ni.decode(s,{type:ie,ts:t,isIFrame:r,cts:0})}},_isEnhancedH265Header:function(e){return(e&Pt)===Pt},findSei:function(e,t){let r=4;dr(ir)&&(r=ir),Jt(e.slice(5),r).forEach((e=>{const r=Zt?e[0]>>>1&63:31&e[0];(Zt&&(r===dt||r===ot)||yr(Zt)&&r===Ve)&&postMessage({cmd:q,buffer:e,ts:t},[e.buffer])}))},calcNetworkDelay:function(e){if(!(qe&&e>0))return;null===Je?(Je=e,at=tr()):et?r-t:0;ni.networkDelay=i,i>ni._opt.networkDelay&&ni._opt.playType===m&&(ni.debug.warn("worker",`calcNetworkDelay now dts:${e}, start dts is ${Je} vs start is ${t},local diff is ${r} ,delay is ${i}`),postMessage({cmd:R,type:xe,value:i}))},calcIframeIntervalTimestamp:function(e){null===At?At=e:At=ni._opt.playbackForwardMaxRateDecodeIFrame},isPlayUseMSE:function(){return ni.isPlayer&&ni._opt.useMSE&&gr(r)},isPlayUseMSEAndDecoderInWorker:function(){return ni.isPlayUseMSE()&&ni._opt.mseDecoderUseWorker},isPlayUseMSEAndDecoderInWorkerAndMseDecodeAudio:function(){return ni.isPlayUseMSEAndDecoderInWorker()&&ni._opt.mseDecodeAudio},playbackUpdatePlaybackRate:function(){ni.clearBuffer(!0)},onOffscreenCanvasWebglContextLost:function(e){ni.debug.error("worker","handleOffscreenCanvasWebglContextLost and next try to create webgl"),e.preventDefault(),Gt=!0,ni.webglObj.destroy(),ni.webglObj=null,ni.offscreenCanvasGL=null,setTimeout((()=>{ni.offscreenCanvasGL=ni.offscreenCanvas.getContext("webgl"),ni.offscreenCanvasGL&&ni.offscreenCanvasGL.getContextAttributes().stencil?(ni.webglObj=u(ni.offscreenCanvasGL,ni._opt.openWebglAlignment),Gt=!1):ni.debug.error("worker","handleOffscreenCanvasWebglContextLost, stencil is false")}),500)},onOffscreenCanvasWebglContextRestored:function(e){ni.debug.log("worker","handleOffscreenCanvasWebglContextRestored"),e.preventDefault()},videoInfo:function(e,t,r){postMessage({cmd:I,code:e}),postMessage({cmd:U,w:t,h:r}),E=t,ge=r,ni.useOffscreen()&&(ni.offscreenCanvas=new OffscreenCanvas(t,r),ni.offscreenCanvasGL=ni.offscreenCanvas.getContext("webgl"),ni.webglObj=u(ni.offscreenCanvasGL,ni._opt.openWebglAlignment),ni.offscreenCanvas.addEventListener("webglcontextlost",ni.onOffscreenCanvasWebglContextLost,!1),ni.offscreenCanvas.addEventListener("webglcontextrestored",ni.onOffscreenCanvasWebglContextRestored,!1))},audioInfo:function(e,t,r){postMessage({cmd:C,code:e}),postMessage({cmd:T,sampleRate:t,channels:r,depth:wr}),Et=r},yuvData:function(t,r){if(ni.isDestroyed)return void ni.debug.log("worker","yuvData, decoder is destroyed and return");const i=E*ge*3/2;let s=e.HEAPU8.subarray(t,t+i),n=new Uint8Array(s);if(pt=null,ni.useOffscreen())try{if(Gt)return;ni.webglObj.renderYUV(E,ge,n);let e=ni.offscreenCanvas.transferToImageBitmap();postMessage({cmd:x,buffer:e,delay:ni.delay,ts:r},[e])}catch(e){ni.debug.error("worker","yuvData, transferToImageBitmap error is",e)}else postMessage({cmd:x,output:n,delay:ni.delay,ts:r},[n.buffer])},pcmData:function(e,r,i){if(ni.isDestroyed)return void ni.debug.log("worker","pcmData, decoder is destroyed and return");let n=r,a=[],o=0,d=ni._opt.audioBufferSize;for(let r=0;r<2;r++){let i=t.HEAPU32[(e>>2)+r]>>2;a[r]=t.HEAPF32.subarray(i,i+n)}if(_t){if(!(n>=(r=d-_t)))return _t+=n,s[0]=Float32Array.of(...s[0],...a[0]),void(2==Et&&(s[1]=Float32Array.of(...s[1],...a[1])));ft[0]=Float32Array.of(...s[0],...a[0].subarray(0,r)),2==Et&&(ft[1]=Float32Array.of(...s[1],...a[1].subarray(0,r))),postMessage({cmd:B,buffer:ft,ts:i},ft.map((e=>e.buffer))),o=r,n-=r}for(_t=n;_t>=d;_t-=d)ft[0]=a[0].slice(o,o+=d),2==Et&&(ft[1]=a[1].slice(o-d,o)),postMessage({cmd:B,buffer:ft,ts:i},ft.map((e=>e.buffer)));_t&&(s[0]=a[0].slice(o),2==Et&&(s[1]=a[1].slice(o))),a=[]},errorInfo:function(e){null===pt&&(pt=tr());const t=tr(),r=rr(mt>0?2*mt:5e3,1e3,5e3),i=t-pt;i>r&&(ni.debug.warn("worker",`errorInfo() emit simdDecodeError and\n iframeIntervalTimestamp is ${mt} and diff is ${i} and maxDiff is ${r}\n and replay`),qt=!0,postMessage({cmd:H}))},sendWebsocketMessage:function(e){o?o.readyState===Ce?o.send(e):ni.debug.error("worker","socket is not open"):ni.debug.error("worker","socket is null")},timeEnd:function(){ni.debug.error("worker","Jb pro 体验结束,请刷新页面再次体验(wasm内部会暂停解码),如需要购买商业授权,可以联系微信:bosswancheng"),ni.close(),postMessage({cmd:O})},postStreamToMain(e,t){postMessage({cmd:j,type:t,buffer:e},[e.buffer])}};ni.debug=new xr(ni);let ai=null;t.AudioDecoder&&(ai=new t.AudioDecoder(ni));let oi=null;e.VideoDecoder&&(oi=new e.VideoDecoder(ni)),postMessage({cmd:A}),self.onmessage=function(e){let t=e.data;switch(t.cmd){case oe:try{ni._opt=Object.assign(ni._opt,JSON.parse(t.opt))}catch(e){}ni.init();break;case de:ni.pushBuffer(t.buffer,t.options);break;case le:ni.decodeAudio(t.buffer,t.ts);break;case ue:ni.decodeVideo(t.buffer,t.ts,t.isIFrame);break;case fe:ni.clearBuffer(t.needClear);break;case pe:ni.fetchStream(t.url,JSON.parse(t.opt));break;case ce:ni.debug.log("worker","close",JSON.stringify(t.options)),t.options&&yr(t.options.isVideoInited)&&(Er=t.options.isVideoInited),ni.close();break;case he:ni.debug.log("worker","updateConfig",t.key,t.value),ni._opt[t.key]=t.value,"playbackRate"===t.key&&(ni.playbackUpdatePlaybackRate(),ni.isPlaybackCacheBeforeDecodeForFpsRender()&&ni.playbackCacheLoop());break;case me:ni.sendWebsocketMessage(t.message);break;case _e:si.$video.currentTime=Number(t.message)}}}(e,e)}))}));