ZYC_web/public/js/jessibuca-pro/decoder-pro-simd.js

15 lines
167 KiB
JavaScript
Raw Permalink Normal View History

2025-05-22 16:27:24 +08:00
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("path"),require("fs"),require("crypto")):"function"==typeof define&&define.amd?define(["path","fs","crypto"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).path,e.fs,e.crypto$1)}(this,function(e,m,g){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var Tt=t(e),Bt=t(m),At=t(g);function y(e,t){return e(t={exports:{}},t.exports),t.exports}var _=y(function(I){var t,m,M,$,N,G,a,g=void 0!==g?g:{},O=Object.assign({},g),V="./this.program",z="object"==typeof window,d="function"==typeof importScripts,j="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,e="",W=(j?(e=d?Tt.default.dirname(e)+"/":__dirname+"/",G=()=>{N||($=Bt.default,N=Tt.default)},t=function(e,t){return G(),e=N.normalize(e),$.readFileSync(e,t?void 0:"utf8")},M=e=>{e=t(e,!0);return e=e.buffer?e:new Uint8Array(e)},m=(e,r,n)=>{G(),e=N.normalize(e),$.readFile(e,function(e,t){e?n(e):r(t.buffer)})},1<process.argv.length&&(V=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),I.exports=g,process.on("uncaughtException",function(e){throw e}),process.on("unhandledRejection",function(e){throw e}),g.inspect=function(){return"[Emscripten Module object]"}):(z||d)&&(d?e=self.location.href:"undefined"!=typeof document&&document.currentScript&&(e=document.currentScript.src),e=0!==e.indexOf("blob:")?e.substr(0,e.replace(/[?#].*/,"").lastIndexOf("/")+1):"",t=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText},d&&(M=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),m=(e,t,r)=>{var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{200==n.status||0==n.status&&n.response?t(n.response):r()},n.onerror=r,n.send(null)}),g.print||console.log.bind(console)),s=g.printErr||console.warn.bind(console),H=(Object.assign(g,O),g.arguments&&g.arguments,g.thisProgram&&(V=g.thisProgram),g.quit&&g.quit,g.wasmBinary&&(a=g.wasmBinary),g.noExitRuntime,"object"!=typeof WebAssembly&&w("no native wasm support detected"),!1);function q(e,t){e||w(t)}var X,c,f,l,K,u,p,Y,J,Z,Q="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function i(e,t,r){for(var n=t+r,o=t;e[o]&&!(n<=o);)++o;if(16<o-t&&e.buffer&&Q)return Q.decode(e.subarray(t,o));for(var a="";t<o;){var i,s,l=e[t++];128&l?(i=63&e[t++],192!=(224&l)?(s=63&e[t++],(l=224==(240&l)?(15&l)<<12|i<<6|s:(7&l)<<18|i<<12|s<<6|63&e[t++])<65536?a+=String.fromCharCode(l):(s=l-65536,a+=String.fromCharCode(55296|s>>10,56320|1023&s))):a+=String.fromCharCode((31&l)<<6|i)):a+=String.fromCharCode(l)}return a}function ee(e,t){return e?i(f,e,t):""}function te(e,t,r,n){if(!(0<n))return 0;for(var o=r,a=r+n-1,i=0;i<e.length;++i){var s=e.charCodeAt(i);if((s=55296<=s&&s<=57343?65536+((1023&s)<<10)|1023&e.charCodeAt(++i):s)<=127){if(a<=r)break;t[r++]=s}else{if(s<=2047){if(a<=r+1)break;t[r++]=192|s>>6}else{if(s<=65535){if(a<=r+2)break;t[r++]=224|s>>12}else{if(a<=r+3)break;t[r++]=240|s>>18,t[r++]=128|s>>12&63}t[r++]=128|s>>6&63}t[r++]=128|63&s}}return t[r]=0,r-o}function re(e){for(var t=0,r=0;r<e.length;++r){var n=e.charCodeAt(r);n<=127?t++:n<=2047?t+=2:55296<=n&&n<=57343?(t+=4,++r):t+=3}return t}g.INITIAL_MEMORY;var h,y,_,ne=[],oe=[],ae=[],r=0,n=null;function ie(){r++,g.monitorRunDependencies&&g.monitorRunDependencies(r)}function se(){var e;r--,g.monitorRunDependencies&&g.monitorRunDependencies(r),0==r&&n&&(e=n,n=null,e())}function w(e){throw g.onAbort&&g.onAbort(e),s(e="Aborted("+e+")"),H=!0,e+=". Build with -sASSERTIONS for more info.",new WebAssembly.RuntimeError(e)}function le(e){return e.startsWith("data:application/octet-stream;base64,")}function ue(e){return e.startsWith("file://")}function de(e){try{if(e==h&&a)return new Uint8Array(a);if(M)return M(e);throw"both async and sync fetching of the wasm failed"}catch(e){w(e)}}function ce(e){for(;0<e.length;)e.shift()(g)}function fe(e){this.excPtr=e,this.ptr=e-24,this.set_type=function(e){p[this.ptr+4>>2]=e},thi
ts is ${t.ts}, preTimestamp is ${k},
diff is ${e} and preTimestampDuration is ${T}
maybe trigger black screen or flower screen
`)}if(F.isPlayer&&0<k&&2===t.type&&t.ts<k&&36e5<k-t.ts&&(F.debug.warn("worker",`pushBuffer,
preTimestamp is ${k}, options.ts is ${t.ts},
diff is ${k-t.ts} more than 3600000,
and resetAllDelay`),F.resetAllDelay()),F.isPlayer&&t.ts<=k&&0<k&&2===t.type&&F.debug.warn("worker",`pushBuffer,
options.ts is ${t.ts} less than (or equal) preTimestamp is ${k} and
payloadBufferSize is ${e.byteLength} and prevPayloadBufferSize is `+B),F.isPlayer&&m){const e=F._opt.videoBuffer+F._opt.videoBufferDelay,o=F.getDelayNotUpdateDelay(t.ts);(F.pushLatestDelay=o)>e&&F.delay<e&&0<F.delay&&F.hasIframeInBufferList()&&!1===F.isPushDropping&&(F.debug.log("worker",`pushBuffer, pushLatestDelay is ${o} more than ${e} and decoder.delay is ${F.delay} and has iIframe and next decoder.dropBuffer$2()`),F.dropBuffer$2())}if(2===t.type&&(0<k&&(T=t.ts-k),B=e.byteLength,k=t.ts),1===t.type?o.push({ts:t.ts,payload:e,decoder:{decode:F.decodeAudio},type:1,isIFrame:!1}):2===t.type&&o.push({ts:t.ts,cts:t.cts,payload:e,decoder:{decode:F.decodeVideo},type:2,isIFrame:t.isIFrame}),F.isPlaybackCacheBeforeDecodeForFpsRender()&&(H(F.streamVideoFps)||H(F.streamAudioFps))){let e=F.streamVideoFps,t=F.streamAudioFps;H(F.streamVideoFps)&&(e=ce(o,2))&&(F.streamVideoFps=e,postMessage({cmd:"playbackStreamVideoFps",value:F.streamVideoFps}),F.streamFps=t?e+t:e,F.playbackCacheLoop()),H(F.streamAudioFps)&&(t=ce(o,1))&&(F.streamAudioFps=t,F.streamFps=e?e+t:t,F.playbackCacheLoop()),H(F.streamVideoFps)&&H(F.streamAudioFps)&&F.debug.log("worker",`playbackCacheBeforeDecodeForFpsRender, calc streamAudioFps is ${t}, streamVideoFps is ${e}, bufferListLength is `+o.length)}}},getVideoBufferLength(){let t=0;return o.forEach(e=>{2===e.type&&(t+=1)}),t},hasIframeInBufferList:()=>o.some(e=>2===e.type&&e.isIFrame),getNotDroppingDelayTs:()=>F._opt.videoBuffer+F._opt.videoBufferDelay/2,getAudioBufferLength(){let t=0;return o.forEach(e=>{1===e.type&&(t+=1)}),t},getFlvBufferLength(){let e=0;return d&&d.buffer&&(e=d.buffer.byteLength),e=F._opt.isNakedFlow&&C.lastBuf?C.lastBuf.byteLength:e},fetchStream:function(e,t){F.debug.log("worker","fetchStream, url is "+e,"options:",JSON.stringify(t)),s=function(r){let n=0,o=de();return e=>{var t;"[object Number]"===Object.prototype.toString.call(e)&&(n+=e,1e3<=(t=(e=de())-o))&&(r(n/t*1e3),o=e,n=0)}}(e=>{postMessage({cmd:I,type:"streamRate",value:e})}),F.startStreamRateAndStatsInterval(),2===t.protocol?(d=new q(F.demuxFlv()),fetch(e,{signal:r.signal}).then(e=>{if(e.ok&&200<=e.status&&e.status<=299)if(postMessage({cmd:I,type:oe}),"undefined"!=typeof WritableStream)e.body.pipeTo(new WritableStream({write:e=>{s(e.byteLength),d.write(e)},close:()=>{d=null,n(),postMessage({cmd:I,type:M,value:Z})},abort:e=>{d=null,e.name!==W&&(n(),postMessage({cmd:I,type:$,value:e.toString()}))}}));else{const t=e.body.getReader(),r=()=>{t.read().then(e=>{var{done:e,value:t}=e;e?(d=null,n(),postMessage({cmd:I,type:M,value:Z})):(s(t.byteLength),d.write(t),r())}).catch(e=>{d=null,e.name!==W&&(n(),postMessage({cmd:I,type:$,value:e.toString()}))})};r()}else F.debug.error("worker",`fetch response status is ${e.status} and ok is ${e.ok} and emit error and next abort()`),n(),postMessage({cmd:I,type:$,value:`fetch response status is ${e.status} and ok is `+e.ok})}).catch(e=>{e.name!==W&&(n(),postMessage({cmd:I,type:$,value:e.toString()}),d=null)})):1===t.protocol&&(t.isFlv&&(d=new q(F.demuxFlv())),(i=new WebSocket(e)).binaryType="arraybuffer",i.onopen=()=>{F.debug.log("worker","fetchStream, WebsocketStream socket open"),postMessage({cmd:I,type:oe}),postMessage({cmd:I,type:"websocketOpen"})},i.onclose=()=>{F.debug.log("worker","fetchStream, WebsocketStream socket close"),d=null,postMessage({cmd:I,type:M,value:"websocket"})},i.onerror=e=>{F.debug.error("worker","fetchStream, WebsocketStream socket error",e),d=null,postMessage({cmd:I,type:"websocketError",value:e.isTrusted?"websocket user aborted":"websocket error"})},i.onmessage=e=>{s(e.data.byteLength),t.isFlv?d.write(e.data):F._opt.isNakedFlow?F.demuxNakedFlow(e.data):F.demuxM7s(e.data)})},demuxFlv:function*(){yield 9;const r=new ArrayBuffer(4),e=new Uint8Array(r),n=new Uint32Array(r);for(;;){e[3]=0;const r=yield 15,i=r[4];e[0]=r[7],e[1]=r[6],e[2]=r[5];var t=n[0],o=(e[0]=r[10],e[1]=r[9],e[2]=r[8],e[3]=r[11],n[0]),a=(yield t).slice();switch(i){case 8:F.decode(a,{type:1,ts:o});break;case 9:if(0<a.byteLength){const r=a[0]>>4==1;F.isPlayer&&(F.calcNetworkDelay(o),r)&&F.calcIframe
decodeVideo: video width or height is changed,
old width is ${c}, old height is ${f},
new width is ${e.codecWidth}, new height is ${e.codecHeight},
and emit change event`),D=!0,postMessage({cmd:"wasmWidthOrHeightChange"}))}var o;D?F.debug.warn("worker","decodeVideo: video width or height is changed, and return"):F.isVideoSequenceHeader(t)?F.debug.warn("worker","decodeVideo and payload is video sequence header so drop this frame"):t.byteLength<12?F.debug.warn("worker","decodeVideo and payload is too small , payload length is "+t.byteLength):(o=t.slice(5),P.decode(o,e?1:0,r),F._opt.isRecording&&F._opt.recordType===L&&postMessage({cmd:"videoNalu",buffer:o,isIFrame:e,ts:r,cts:n},[t.buffer]))}else F.debug.warn("worker","decodeVideo: first frame is not iframe");else F.setCodecVideo(t)},clearBuffer:function(){var e=0<arguments.length&&void 0!==arguments[0]&&arguments[0];F.debug.log("worker",`clearBuffer,bufferList length is ${o.length}, need clear is `+e),e&&(o=[]),F.resetAllDelay(),F.dropping=!0},dropBuffer$2:function(){var e,t,r;0<o.length&&(F.isPushDropping=!0,0<=(e=o.findIndex(e=>fe(e.isIFrame)&&2===e.type))?(t=(o=o.slice(e)).shift(),r=F.getDelayNotUpdateDelay(t.ts),F.doDecode(t),F.isPushDropping=!1,F.debug.log("worker",`dropBuffer$2() iFrameIndex is ${e},and bufferList length is ${o.length} and tempDelay is ${r} ,delay is ${F.delay} `)):F.isPushDropping=!1),0===o.length&&(F.isPushDropping=!1)},demuxM7s:function(e){var t,r=new DataView(e),n=r.getUint32(1,!1);switch(r.getUint8(0)){case 1:F.decode(new Uint8Array(e,5),{type:1,ts:n});break;case 2:5<r.byteLength&&(t=r.getUint8(5)>>4==1,F.isPlayer&&(F.calcNetworkDelay(n),t)&&F.calcIframeIntervalTimestamp(n),F.decode(new Uint8Array(e,5),{type:2,ts:n,isIFrame:t}))}},demuxNakedFlow:function(e){C.dispatch(e)},calcNetworkDelay:function(e){var t,r,n;m&&0<e&&(null===_?(_=e,w=ue()):e<_&&(F.debug.warn("worker",`calcNetworkDelay, dts is ${e} less than bufferStartDts is `+_),_=e,w=ue()),n=(t=e-_)<(r=ue()-w)?r-t:0,(F.networkDelay=n)>F._opt.networkDelay)&&F._opt.playType===x&&(F.debug.warn("worker",`calcNetworkDelay now dts:${e}, start dts is ${_} vs start is ${t},local diff is ${r} ,delay is `+n),postMessage({cmd:I,type:"networkDelayTimeout",value:n}))},calcIframeIntervalTimestamp:function(e){null===t?t=e:t<e&&(postMessage({cmd:"iframeIntervalTs",value:e-t}),t=e)},canVisibilityDecodeNotDrop:function(){return F._opt.visibility&&c*f<=2073600},isPlaybackCacheBeforeDecodeForFpsRender:function(){return!F.isPlayer&&F._opt.playbackIsCacheBeforeDecodeForFpsRender},isPlaybackOnlyDecodeIFrame:function(){return F._opt.playbackRate>=F._opt.playbackForwardMaxRateDecodeIFrame},playbackUpdatePlaybackRate:function(){F.clearBuffer(!0)},isVideoSequenceHeader:function(e){return e[0]>>4==1&&e[1]===se},onOffscreenCanvasWebglContextLost:function(e){F.debug.error("worker","handleOffscreenCanvasWebglContextLost and next try to create webgl"),e.preventDefault(),A=!0,F.webglObj.destroy(),F.webglObj=null,F.offscreenCanvasGL=null,setTimeout(()=>{F.offscreenCanvasGL=F.offscreenCanvas.getContext("webgl"),F.offscreenCanvasGL&&F.offscreenCanvasGL.getContextAttributes().stencil?(F.webglObj=J(F.offscreenCanvasGL,F._opt.openWebglAlignment),A=!1):F.debug.error("worker","handleOffscreenCanvasWebglContextLost, stencil is false")},500)},onOffscreenCanvasWebglContextRestored:function(e){F.debug.log("worker","handleOffscreenCanvasWebglContextRestored"),e.preventDefault()},videoInfo:function(e,t,r){postMessage({cmd:re,code:e}),postMessage({cmd:ee,w:t,h:r}),c=t,f=r,F.useOffscreen()&&(F.offscreenCanvas=new OffscreenCanvas(t,r),F.offscreenCanvasGL=F.offscreenCanvas.getContext("webgl"),F.webglObj=J(F.offscreenCanvasGL,F._opt.openWebglAlignment),F.offscreenCanvas.addEventListener("webglcontextlost",F.onOffscreenCanvasWebglContextLost,!1),F.offscreenCanvas.addEventListener("webglcontextrestored",F.onOffscreenCanvasWebglContextRestored,!1))},audioInfo:function(e,t,r){postMessage({cmd:"audioCode",code:e}),postMessage({cmd:"initAudio",sampleRate:t,channels:r}),E=r},yuvData:function(e,t){if(F.isDestroyed)F.debug.log("worker","yuvData, decoder is destroyed and return");else{var r,n=c*f*3/2,e=l.HEAPU8.subarray(e,e+n),n=new Uint8Array(e);if(F.useOffscreen())try{