decoder-pro-hard-not-wasm.js 366 KB

1
  1. !function(e){"function"==typeof define&&define.amd?define(["crypto-js"],e):e()}((function(){"use strict";var e=1e-6,t="undefined"!=typeof Float32Array?Float32Array:Array;function r(){var e=new t(16);return t!=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 s(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 a,n=function(e,t,i,r,s,a,n){var o=1/(t-i),d=1/(r-s),l=1/(a-n);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+i)*o,e[13]=(s+r)*d,e[14]=(n+a)*l,e[15]=1,e};function o(e,i,r){var s=new t(3);return s[0]=e,s[1]=i,s[2]=r,s}a=new t(3),t!=Float32Array&&(a[0]=0,a[1]=0,a[2]=0);var d=(t,i)=>{i&&t.pixelStorei(t.UNPACK_ALIGNMENT,1);const a=function(){const e=_(t.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 "),i=_(t.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 "),r=t.createProgram();if(t.attachShader(r,e),t.attachShader(r,i),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))return console.log("Unable to initialize the shader program: "+t.getProgramInfoLog(r)),null;return r}();let d={program:a,attribLocations:{vertexPosition:t.getAttribLocation(a,"aVertexPosition"),texturePosition:t.getAttribLocation(a,"aTexturePosition")},uniformLocations:{projectionMatrix:t.getUniformLocation(a,"uProjectionMatrix"),modelMatrix:t.getUniformLocation(a,"uModelMatrix"),viewMatrix:t.getUniformLocation(a,"uViewMatrix"),rgbatexture:t.getUniformLocation(a,"rgbaTexture"),ytexture:t.getUniformLocation(a,"yTexture"),utexture:t.getUniformLocation(a,"uTexture"),vtexture:t.getUniformLocation(a,"vTexture"),isyuv:t.getUniformLocation(a,"isyuv")}},l=function(){const e=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,e);t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1]),t.STATIC_DRAW);var i=[];i=i.concat([0,1],[1,1],[1,0],[0,0]);const r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.bufferData(t.ARRAY_BUFFER,new Float32Array(i),t.STATIC_DRAW);const s=t.createBuffer();t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,s);return t.bufferData(t.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,1,2,0,2,3]),t.STATIC_DRAW),{position:e,texPosition:r,indices:s}}(),c=p(),u=p(),h=p(),f=p();function p(){let e=t.createTexture();return t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}function _(e,i){const r=t.createShader(e);return t.shaderSource(r,i),t.compileShader(r),t.getShaderParameter(r,t.COMPILE_STATUS)?r:(console.log("An error occurred compiling the shaders: "+t.getShaderInfoLog(r)),t.deleteShader(r),null)}function m(i,a){t.viewport(0,0,i,a),t.clearColor(0,0,0,0),t.clearDepth(1),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);const c=r();n(c,-1,1,-1,1,.1,100);const p=r();s(p);const _=r();!function(t,i,r,a){var n,o,d,l,c,u,h,f,p,_,m=i[0],g=i[1],y=i[2],b=a[0],S=a[1],v=a[2],w=r[0],A=r[1],U=r[2];Math.abs(m-w)<e&&Math.abs(g-A)<e&&Math.abs(y-U)<e?s(t):(h=m-w,f=g-A,p=y-U,n=S*(p*=_=1/Math.hypot(h,f,p))-v*(f*=_),o=v*(h*=_)-b*p,d=b*f-S*h,(_=Math.hypot(n,o,d))?(n*=_=1/_,o*=_,d*=_):(n=0,o=0,d=0),l=f*d-p*o,c=p*n-h*d,u=h*o-f*n,(_=Math.hypot(l,c,u))?(l*=_=1/_,c*=_,u*=_):(l=0,c=0,u=0),t[0]=n,t[1]=l,t[2]=h,t[3]=0,t[4]=o,t[5]=c,t[6]=f,t[7]=0,t[8]=d,t[9]=u,t[10]=p,t[11]=0,t[12]=-(n*m+o*g+d*y),t[13]=-(l*m+c*g+u*y),t[14]=-(h*m+f*g+p*y),t[15]=1)}(_,o(0,0,0),o(0,0,-1),o(0,1,0));{const e=3,i=t.FLOAT,r=!1,s=0,a=0;t.bindBuffer(t.ARRAY_BUFFER,l.position),t.vertexAttribPointer(d.attribLocations.vertexPosition,e,i,r,s,a),t.enableVertexAttribArray(d.attribLocations.vertexPosition)}{const e=2,i=t.FLOAT,r=!1,s=0,a=0;t.bindBuffer(t.ARRAY_BUFFER,l.texPosition),t.vertexAttribPointer(d.attribLocations.texturePosition,e,i,r,s,a),t.enableVertexAttribArray(d.attribLocations.texturePosition)}t.activeTexture(t.TEXTURE0+3),t.bindTexture(t.TEXTURE_2D,u),t.activeTexture(t.TEXTURE0+4),t.bindTexture(t.TEXTURE_2D,h),t.activeTexture(t.TEXTURE0+5),t.bindTexture(t.TEXTURE_2D,f),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,l.indices),t.useProgram(d.program),t.uniformMatrix4fv(d.uniformLocations.projectionMatrix,!1,c),t.uniformMatrix4fv(d.uniformLocations.modelMatrix,!1,p),t.uniformMatrix4fv(d.uniformLocations.viewMatrix,!1,_),t.uniform1i(d.uniformLocations.rgbatexture,2),t.uniform1i(d.uniformLocations.ytexture,3),t.uniform1i(d.uniformLocations.utexture,4),t.uniform1i(d.uniformLocations.vtexture,5),t.uniform1i(d.uniformLocations.isyuv,1);{const e=6,i=t.UNSIGNED_SHORT,r=0;t.drawElements(t.TRIANGLES,e,i,r)}}return{render:function(e,i,r,s,a){t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,u),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,e,i,0,t.LUMINANCE,t.UNSIGNED_BYTE,r),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,h),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,e/2,i/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,s),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,f),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,e/2,i/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,a),m(e,i)},renderYUV:function(e,i,r){let s=r.slice(0,e*i),a=r.slice(e*i,e*i*5/4),n=r.slice(e*i*5/4,e*i*3/2);t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,u),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,e,i,0,t.LUMINANCE,t.UNSIGNED_BYTE,s),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,h),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,e/2,i/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,a),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,f),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,e/2,i/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,n),m(e,i)},destroy:function(){t.deleteProgram(d.program),t.deleteBuffer(l.position),t.deleteBuffer(l.texPosition),t.deleteBuffer(l.indices),t.deleteTexture(c),t.deleteTexture(u),t.deleteTexture(h),t.deleteTexture(f),d=null,l=null,c=null,u=null,h=null,f=null}}};const l=1,c=2,u="fetch",h="websocket",f="player",p="playbackTF",_="mp4",m="debug",g="warn",y=36e5,b=4080,S=12,v={playType:f,container:"",videoBuffer:1e3,videoBufferDelay:1e3,networkDelay:1e4,isResize:!0,isFullResize:!1,isFlv:!1,isHls:!1,isFmp4:!1,isFmp4Private:!1,isWebrtc:!1,isWebrtcForZLM:!1,isWebrtcForSRS:!1,isWebrtcForOthers:!1,isNakedFlow:!1,isMpeg4:!1,isAliyunRtc:!1,isTs:!1,debug:!1,debugLevel:g,debugUuid:"",isMulti:!0,multiIndex:-1,hotKey:!1,loadingTimeout:10,heartTimeout:10,timeout:10,pageVisibilityHiddenTimeout:300,loadingTimeoutReplay:!0,heartTimeoutReplay:!0,loadingTimeoutReplayTimes:3,heartTimeoutReplayTimes:3,heartTimeoutReplayUseLastFrameShow:!0,replayUseLastFrameShow:!0,replayShowLoadingIcon:!1,supportDblclickFullscreen:!1,showBandwidth:!1,showPerformance:!1,mseCorrectTimeDuration:20,mseCorrectAudioTimeDuration:20,keepScreenOn:!0,isNotMute:!1,muted:!0,hasAudio:!0,hasVideo:!0,operateBtns:{fullscreen:!1,screenshot:!1,play:!1,audio:!1,record:!1,ptz:!1,quality:!1,zoom:!1,close:!1,scale:!1,performance:!1,logSave:!1,aiFace:!1,aiObject:!1,aiOcclusion:!1,fullscreenFn:null,fullscreenExitFn:null,screenshotFn:null,playFn:null,pauseFn:null,recordFn:null,recordStopFn:null},extendOperateBtns:[],contextmenuBtns:[],watermarkConfig:{},controlAutoHide:!1,hasControl:!1,loadingIcon:!0,loadingIconStyle:{},loadingText:"",background:"",poster:"",backgroundLoadingShow:!0,loadingBackground:"",loadingBackgroundWidth:0,loadingBackgroundHeight:0,decoder:"decoder-pro.js",decoderAudio:"decoder-pro-audio.js",decoderHard:"decoder-pro-hard.js",decoderHardNotWasm:"decoder-pro-hard-not-wasm.js",wasmMp4RecorderDecoder:"jessibuca-pro-mp4-recorder-decoder.js",decoderWASM:"",isDecoderUseCDN:!1,url:"",rotate:0,mirrorRotate:"none",aspectRatio:"default",playbackConfig:{playList:[],fps:"",showControl:!0,controlType:"normal",duration:0,startTime:"",showRateBtn:!1,rateConfig:[],showPrecision:"",showPrecisionBtn:!0,isCacheBeforeDecodeForFpsRender:!1,uiUsePlaybackPause:!1,isPlaybackPauseClearCache:!0,isUseFpsRender:!1,isUseLocalCalculateTime:!1,localOneFrameTimestamp:40,supportWheel:!1,useWCS:!1,useMSE:!1},qualityConfig:[],defaultStreamQuality:"",scaleConfig:["拉伸","缩放","正常"],forceNoOffscreen:!0,hiddenAutoPause:!1,protocol:c,demuxType:"flv",useWasm:!1,useMSE:!1,useWCS:!1,useSIMD:!0,useMThreading:!1,wcsUseVideoRender:!0,wcsUseWebgl2Render:!0,wasmUseVideoRender:!0,mseUseCanvasRender:!1,hlsUseCanvasRender:!1,webrtcUseCanvasRender:!1,useOffscreen:!1,useWebGPU:!1,mseDecodeErrorReplay:!0,wcsDecodeErrorReplay:!0,wasmDecodeErrorReplay:!0,simdDecodeErrorReplay:!0,simdDecodeErrorReplayType:"wasm",autoWasm:!0,decoderErrorAutoWasm:!0,hardDecodingNotSupportAutoWasm:!0,webglAlignmentErrorReplay:!0,webglContextLostErrorReplay:!0,openWebglAlignment:!1,syncAudioAndVideo:!0,syncAudioAndVideoDiff:400,playbackDelayTime:1e3,playbackFps:25,playbackForwardMaxRateDecodeIFrame:4,playbackCurrentTimeMove:!0,useVideoRender:!0,useCanvasRender:!1,networkDelayTimeoutReplay:!1,recordType:_,checkFirstIFrame:!0,nakedFlowFps:25,audioEngine:null,isShowRecordingUI:!0,isShowZoomingUI:!0,useFaceDetector:!1,useObjectDetector:!1,useImageDetector:!1,useOcclusionDetector:!1,ptzPositionConfig:{},ptzShowType:"vertical",ptzClickType:"click",ptzStopEmitDelay:.3,ptzZoomShow:!1,ptzApertureShow:!1,ptzFocusShow:!1,ptzMoreArrowShow:!1,ptzCruiseShow:!1,ptzFogShow:!1,ptzWiperShow:!1,ptzSupportDraggable:!1,weiXinInAndroidAudioBufferSize:4800,isM7sCrypto:!1,m7sCryptoAudio:!1,isSm4Crypto:!1,isXorCrypto:!1,sm4CryptoKey:"",m7sCryptoKey:"",xorCryptoKey:"",cryptoKey:"",cryptoIV:"",cryptoKeyUrl:"",autoResize:!1,useWebFullScreen:!1,ptsMaxDiff:3600,aiFaceDetectLevel:2,aiFaceDetectWidth:240,aiFaceDetectShowRect:!0,aiFaceDetectInterval:1e3,aiFaceDetectRectConfig:{},aiObjectDetectLevel:2,aiObjectDetectWidth:240,aiObjectDetectShowRect:!0,aiObjectDetectInterval:1e3,aiObjectDetectRectConfig:{},aiOcclusionDetectInterval:1e3,aiImageDetectDrop:!1,aiImageDetectActive:!1,videoRenderSupportScale:!0,mediaSourceTsIsMaxDiffReplay:!0,controlHtml:"",isH265:!1,isWebrtcH265:!1,supportLockScreenPlayAudio:!0,supportHls265:!0,isEmitSEI:!1,pauseAndNextPlayUseLastFrameShow:!1,demuxUseWorker:!0,playFailedAndReplay:!0,showMessageConfig:{webglAlignmentError:"Webgl 渲染失败",webglContextLostError:"webgl 上下文丢失",mediaSourceH265NotSupport:"不支持硬解码H265",mediaSourceFull:"缓冲区已满",mediaSourceAppendBufferError:"初始化解码器失败",mseSourceBufferError:"解码失败",mseAddSourceBufferError:"初始化解码器失败",mediaSourceDecoderConfigurationError:"初始化解码器失败",mediaSourceTsIsMaxDiff:"流异常",mseWidthOrHeightChange:"流异常",mediaSourceAudioG711NotSupport:"硬解码不支持G711a/u音频格式",mediaSourceUseCanvasRenderPlayFailed:"MediaSource解码使用canvas渲染失败",webcodecsH265NotSupport:"不支持硬解码H265",webcodecsUnsupportedConfigurationError:"初始化解码器失败",webcodecsDecodeConfigureError:"初始化解码器失败",webcodecsDecodeError:"解码失败",wcsWidthOrHeightChange:"解码失败",wasmDecodeError:"解码失败",simdDecodeError:"解码失败",wasmWidthOrHeightChange:"流异常",wasmUseVideoRenderError:"video自动渲染失败",videoElementPlayingFailed:"video自动渲染失败",simdH264DecodeVideoWidthIsTooLarge:"不支持该分辨率的视频",networkDelayTimeout:"网络超时重播失败",fetchError:"请求失败",streamEnd:"请求结束",websocketError:"请求失败",webrtcError:"请求失败",hlsError:"请求失败",decoderWorkerInitError:"初始化worker失败",videoElementPlayingFailedForWebrtc:"video自动渲染失败",videoInfoError:"解析视频分辨率失败",webrtcStreamH265:"webrtc不支持H265",delayTimeout:"播放超时重播失败",loadingTimeout:"加载超时重播失败",loadingTimeoutRetryEnd:"加载超时重播失败",delayTimeoutRetryEnd:"播放超时重播失败"},videoElementPlayingFailedReplay:!0,mp4RecordUseWasm:!0,mseAutoCleanupSourceBuffer:!0,mseAutoCleanupMaxBackwardDuration:30,mseAutoCleanupMinBackwardDuration:10,widthOrHeightChangeReplay:!0,simdH264DecodeVideoWidthIsTooLargeReplay:!0,mediaSourceAudioG711NotSupportReplay:!0,mediaSourceAudioInitTimeoutReplay:!0,mediaSourceUseCanvasRenderPlayFailedReplay:!0,mediaSourceUseCanvasRenderPlayFailedReplayType:"video",widthOrHeightChangeReplayDelayTime:0,ghostWatermarkConfig:{on:5,off:5,content:"",fontSize:12,color:"white",opacity:.15,speed:.2},dynamicWatermarkConfig:{content:"",speed:.2,fontSize:12,color:"white",opacity:.15},isDropSameTimestampGop:!1,mseDecodeAudio:!0,nakedFlowH265DemuxUseNew:!0,extendDomConfig:{html:"",showBeforePlay:!1,showAfterLoading:!0},disableContextmenu:!1,mseDecoderUseWorker:!0,openMemoryLog:!1,mainThreadFetchUseWorker:!0,playFailedAndPausedShowPlayBtn:!0,mseCorrectionTimestamp:!0,flvDemuxBufferSizeTooLargeReplay:!1,flvDemuxBufferSizeTooLargeEmitFailed:!1,flvDemuxBufferSizeMaxLarge:1048576,isCheckInView:!1,hiddenControl:!1,disableModule:{ptz:!1,record:!1,zoom:!1,watermark:!1}},w="init",A="initVideo",U="render",E="playAudio",x="initAudio",B="audioCode",T="audioNalu",C="audioAACSequenceHeader",k="videoCode",I="videoCodec",D="videoNalu",L="videoPayload",F="audioPayload",P="workerFetch",M="iframeIntervalTs",R="isDropping",z="workerEnd",N="playbackStreamVideoFps",G="wasmWidthOrHeightChange",O="simdDecodeError",H="simdH264DecodeVideoWidthIsTooLarge",V="closeEnd",$="tempStream",W="videoSEI",Y="flvScriptData",q="aacSequenceHeader",j="videoSequenceHeader",K="flvBufferData",X="checkFirstIFrame",Z="mseHandle",J="mseFirstRenderTime",Q="mseError",ee=1,te=2,ie=8,re=9,se=18,ae="init",ne="decode",oe="audioDecode",de="videoDecode",le="close",ce="updateConfig",ue="clearBuffer",he="fetchStream",fe="sendWsMessage",pe="mseUpdateVideoTimestamp",_e="delayTimeout",me="loadingTimeout",ge="streamEnd",ye="streamRate",be="streamAbps",Se="streamVbps",ve="streamDts",we="streamSuccess",Ae="streamStats",Ue="networkDelayTimeout",Ee="websocketOpen",xe={playError:"playIsNotPauseOrUrlIsNull",fetchError:"fetchError",websocketError:"websocketError",webcodecsH265NotSupport:"webcodecsH265NotSupport",webcodecsDecodeError:"webcodecsDecodeError",webcodecsUnsupportedConfigurationError:"webcodecsUnsupportedConfigurationError",webcodecsDecodeConfigureError:"webcodecsDecodeConfigureError",mediaSourceH265NotSupport:"mediaSourceH265NotSupport",mediaSourceAudioG711NotSupport:"mediaSourceAudioG711NotSupport",mediaSourceAudioInitTimeout:"mediaSourceAudioInitTimeout",mediaSourceAudioNoDataTimeout:"mediaSourceAudioNoDataTimeout",mediaSourceDecoderConfigurationError:"mediaSourceDecoderConfigurationError",mediaSourceFull:"mseSourceBufferFull",mseSourceBufferError:"mseSourceBufferError",mseAddSourceBufferError:"mseAddSourceBufferError",mediaSourceAppendBufferError:"mediaSourceAppendBufferError",mediaSourceTsIsMaxDiff:"mediaSourceTsIsMaxDiff",mediaSourceUseCanvasRenderPlayFailed:"mediaSourceUseCanvasRenderPlayFailed",mediaSourceBufferedIsZeroError:"mediaSourceBufferedIsZeroError",wasmDecodeError:"wasmDecodeError",wasmUseVideoRenderError:"wasmUseVideoRenderError",hlsError:"hlsError",webrtcError:"webrtcError",webrtcClosed:"webrtcClosed",webrtcIceCandidateError:"webrtcIceCandidateError",webglAlignmentError:"webglAlignmentError",wasmWidthOrHeightChange:"wasmWidthOrHeightChange",mseWidthOrHeightChange:"mseWidthOrHeightChange",wcsWidthOrHeightChange:"wcsWidthOrHeightChange",widthOrHeightChange:"widthOrHeightChange",tallWebsocketClosedByError:"tallWebsocketClosedByError",flvDemuxBufferSizeTooLarge:"flvDemuxBufferSizeTooLarge",wasmDecodeVideoNoResponseError:"wasmDecodeVideoNoResponseError",audioChannelError:"audioChannelError",simdH264DecodeVideoWidthIsTooLarge:"simdH264DecodeVideoWidthIsTooLarge",simdDecodeError:"simdDecodeError",webglContextLostError:"webglContextLostError",videoElementPlayingFailed:"videoElementPlayingFailed",videoElementPlayingFailedForWebrtc:"videoElementPlayingFailedForWebrtc",decoderWorkerInitError:"decoderWorkerInitError",videoInfoError:"videoInfoError",videoCodecIdError:"videoCodecIdError",streamEnd:ge,websocket1006Error:"websocket1006Error",delayTimeout:_e,loadingTimeout:me,networkDelayTimeout:Ue,aliyunRtcError:"aliyunRtcError",...{talkStreamError:"talkStreamError",talkStreamClose:"talkStreamClose"}},Be=1,Te=7,Ce=12,ke=99,Ie="H264(AVC)",De="H265(HEVC)",Le=10,Fe=7,Pe=8,Me=2,Re=7,ze=8,Ne=5,Ge=1,Oe=5,He=6,Ve=7,$e=8,We=14,Ye=19,qe=19,je=20,Ke=20,Xe=21,Ze=21,Je=32,Qe=32,et=33,tt=33,it=34,rt=34,st=39,at=39,nt=40,ot="key",dt="delta",lt='video/mp4; codecs="avc1.64002A"',ct='video/mp4; codecs="hev1.1.6.L123.b0"',ut='video/mp4;codecs="hev1.1.6.L120.90"',ht='video/mp4;codecs="hev1.2.4.L120.90"',ft='video/mp4;codecs="hev1.3.E.L120.90"',pt='video/mp4;codecs="hev1.4.10.L120.90"',_t="ended",mt="open",gt="closed",yt="sourceclose",bt="sourceopen",St="sourceended",vt="avc",wt="hevc",At="AbortError",Ut=0,Et=1,xt=1,Bt="idle",Tt="buffering",Ct="complete",kt=1,It=2,Dt=128,Lt=0,Ft=1,Pt=3,Mt=16;function Rt(e,t){return e(t={exports:{}},t.exports),t.exports}Rt((function(e){!function(){var t="undefined"!=typeof window&&void 0!==window.document?window.document:{},i=e.exports,r=function(){for(var e,i=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],r=0,s=i.length,a={};r<s;r++)if((e=i[r])&&e[1]in t){for(r=0;r<e.length;r++)a[i[0][r]]=e[r];return a}return!1}(),s={change:r.fullscreenchange,error:r.fullscreenerror},a={request:function(e,i){return new Promise(function(s,a){var n=function(){this.off("change",n),s()}.bind(this);this.on("change",n);var o=(e=e||t.documentElement)[r.requestFullscreen](i);o instanceof Promise&&o.then(n).catch(a)}.bind(this))},exit:function(){return new Promise(function(e,i){if(this.isFullscreen){var s=function(){this.off("change",s),e()}.bind(this);this.on("change",s);var a=t[r.exitFullscreen]();a instanceof Promise&&a.then(s).catch(i)}else e()}.bind(this))},toggle:function(e,t){return this.isFullscreen?this.exit():this.request(e,t)},onchange:function(e){this.on("change",e)},onerror:function(e){this.on("error",e)},on:function(e,i){var r=s[e];r&&t.addEventListener(r,i,!1)},off:function(e,i){var r=s[e];r&&t.removeEventListener(r,i,!1)},raw:r};r?(Object.defineProperties(a,{isFullscreen:{get:function(){return Boolean(t[r.fullscreenElement])}},element:{enumerable:!0,get:function(){return t[r.fullscreenElement]}},isEnabled:{enumerable:!0,get:function(){return Boolean(t[r.fullscreenEnabled])}}}),i?e.exports=a:window.screenfull=a):i?e.exports={isEnabled:!1}:window.screenfull={isEnabled:!1}}()})).isEnabled;class zt{constructor(e){this._buffer=e,this._buffer_index=0,this._total_bytes=e.byteLength,this._total_bits=8*e.byteLength,this._current_word=0,this._current_word_bits_left=0}destroy(){this._buffer=null}_fillCurrentWord(){let e=this._total_bytes-this._buffer_index;if(e<=0)return void console.error("ExpGolomb: _fillCurrentWord() but no bytes available",this._total_bytes,this._buffer_index);let t=Math.min(4,e),i=new Uint8Array(4);i.set(this._buffer.subarray(this._buffer_index,this._buffer_index+t)),this._current_word=new DataView(i.buffer).getUint32(0,!1),this._buffer_index+=t,this._current_word_bits_left=8*t}readBits(e){if(e>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 i=e-this._current_word_bits_left;this._fillCurrentWord();let r=Math.min(i,this._current_word_bits_left),s=this._current_word>>>32-r;return this._current_word<<=r,this._current_word_bits_left-=r,t=t<<r|s,t}readBool(){return 1===this.readBits(1)}readByte(){return this.readBits(8)}_skipLeadingZero(){let e;for(e=0;e<this._current_word_bits_left;e++)if(0!=(this._current_word&2147483648>>>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 Nt=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350,-1,-1,-1],Gt=Nt,Ot=Nt;function Ht(e){let{profile:t,sampleRate:i,channel:r}=e;return new Uint8Array([175,0,t<<3|(14&i)>>1,(1&i)<<7|r<<3])}function Vt(e){return $t(e)&&e[1]===Ut}function $t(e){return e[0]>>4===Le}const Wt=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];function Yt(e){let t=new Uint8Array(e),i=null,r=0,s=0,a=0,n=null;if(r=s=t[0]>>>3,a=(7&t[0])<<1|t[1]>>>7,a<0||a>=Wt.length)return void console.error("Flv: AAC invalid sampling frequency index!");let o=Wt[a],d=(120&t[1])>>>3;if(d<0||d>=8)return void console.log("Flv: AAC invalid channel configuration");5===r&&(n=(7&t[1])<<1|t[2]>>>7,t[2]);let l=self.navigator.userAgent.toLowerCase();return-1!==l.indexOf("firefox")?a>=6?(r=5,i=new Array(4),n=a-3):(r=2,i=new Array(2),n=a):-1!==l.indexOf("android")?(r=2,i=new Array(2),n=a):(r=5,n=a,i=new Array(4),a>=6?n=a-3:1===d&&(r=2,i=new Array(2),n=a)),i[0]=r<<3,i[0]|=(15&a)>>>1,i[1]=(15&a)<<7,i[1]|=(15&d)<<3,5===r&&(i[1]|=(15&n)>>>1,i[2]=(1&n)<<7,i[2]|=8,i[3]=0),{audioType:"aac",config:i,sampleRate:o,channelCount:d,objectType:r,codec:"mp4a.40."+r,originalCodec:"mp4a.40."+s}}class qt{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,i=this.data_;for(;;){if(t+7>=i.byteLength)return this.eof_flag_=!0,i.byteLength;if(4095===(i[t+0]<<8|i[t+1])>>>4)return t;t++}}readNextAACFrame(){let e=this.data_,t=null;for(;null==t&&!this.eof_flag_;){let i=this.current_syncword_offset_,r=(8&e[i+1])>>>3,s=(6&e[i+1])>>>1,a=1&e[i+1],n=(192&e[i+2])>>>6,o=(60&e[i+2])>>>2,d=(1&e[i+2])<<2|(192&e[i+3])>>>6,l=(3&e[i+3])<<11|e[i+4]<<3|(224&e[i+5])>>>5;if(e[i+6],i+l>this.data_.byteLength){this.eof_flag_=!0,this.has_last_incomplete_data=!0;break}let c=1===a?7:9,u=l-c;i+=c;let h=this.findNextSyncwordOffset(i+u);if(this.current_syncword_offset_=h,0!==r&&1!==r||0!==s)continue;let f=e.subarray(i,i+u);t={},t.audio_object_type=n+1,t.sampling_freq_index=o,t.sampling_frequency=Gt[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 jt{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,i=this.data_;for(;;){if(t+1>=i.byteLength)return this.eof_flag_=!0,i.byteLength;if(695===(i[t+0]<<3|i[t+1]>>>5))return t;t++}}getLATMValue(e){let t=e.readBits(2),i=0;for(let r=0;r<=t;r++)i<<=8,i|=e.readByte();return i}readNextAACFrame(e){let t=this.data_,i=null;for(;null==i&&!this.eof_flag_;){let r=this.current_syncword_offset_,s=(31&t[r+1])<<8|t[r+2];if(r+3+s>=this.data_.byteLength){this.eof_flag_=!0,this.has_last_incomplete_data=!0;break}let a=new zt(t.subarray(r+3,r+3+s)),n=null;if(a.readBool()){if(null==e){console.warn("StreamMuxConfig Missing"),this.current_syncword_offset_=this.findNextSyncwordOffset(r+3+s),a.destroy();continue}n=e}else{let e=a.readBool();if(e&&a.readBool()){console.error("audioMuxVersionA is Not Supported"),a.destroy();break}if(e&&this.getLATMValue(a),!a.readBool()){console.error("allStreamsSameTimeFraming zero is Not Supported"),a.destroy();break}if(0!==a.readBits(6)){console.error("more than 2 numSubFrames Not Supported"),a.destroy();break}if(0!==a.readBits(4)){console.error("more than 2 numProgram Not Supported"),a.destroy();break}if(0!==a.readBits(3)){console.error("more than 2 numLayer Not Supported"),a.destroy();break}let t=e?this.getLATMValue(a):0,i=a.readBits(5);t-=5;let r=a.readBits(4);t-=4;let s=a.readBits(4);t-=4,a.readBits(3),t-=3,t>0&&a.readBits(t);let o=a.readBits(3);if(0!==o){console.error(`frameLengthType = ${o}. Only frameLengthType = 0 Supported`),a.destroy();break}a.readByte();let d=a.readBool();if(d)if(e)this.getLATMValue(a);else{let e=0;for(;;){e<<=8;let t=a.readBool();if(e+=a.readByte(),!t)break}console.log(e)}a.readBool()&&a.readByte(),n={},n.audio_object_type=i,n.sampling_freq_index=r,n.sampling_frequency=Gt[n.sampling_freq_index],n.channel_config=s,n.other_data_present=d}let o=0;for(;;){let e=a.readByte();if(o+=e,255!==e)break}let d=new Uint8Array(o);for(let e=0;e<o;e++)d[e]=a.readByte();i={},i.audio_object_type=n.audio_object_type,i.sampling_freq_index=n.sampling_freq_index,i.sampling_frequency=Gt[n.sampling_freq_index],i.channel_config=n.channel_config,i.other_data_present=n.other_data_present,i.data=d,this.current_syncword_offset_=this.findNextSyncwordOffset(r+3+s)}return i}hasIncompleteData(){return this.has_last_incomplete_data}getIncompleteData(){return this.has_last_incomplete_data?this.data_.subarray(this.current_syncword_offset_):null}}function Kt(e){let t=arguments.length>1&&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 Xt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(e.length<4)return;const i=e.length,r=[];let s,a=0;for(;a+t<i;)if(s=Kt(e,a),3===t&&(s>>>=8),a+=t,s){if(a+s>i)break;r.push(e.subarray(a,a+s)),a+=s}return r}function Zt(e){const t=e.byteLength,i=new Uint8Array(4);i[0]=t>>>24&255,i[1]=t>>>16&255,i[2]=t>>>8&255,i[3]=255&t;const r=new Uint8Array(t+4);return r.set(i,0),r.set(e,4),r}function Jt(e,t){let i=null;return t?e.length>=28&&(i=1+(3&e[26])):e.length>=12&&(i=1+(3&e[9])),i}function Qt(){return(new Date).getTime()}function ei(e,t,i){return Math.max(Math.min(e,Math.max(t,i)),Math.min(t,i))}function ti(){return performance&&"function"==typeof performance.now?performance.now():Date.now()}function ii(e){let t=0,i=ti();return r=>{if(s=r,"[object Number]"!==Object.prototype.toString.call(s))return;var s;t+=r;const a=ti(),n=a-i;n>=1e3&&(e(t/n*1e3),i=a,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 ri(){const e=window.navigator.userAgent.toLowerCase();return/firefox/i.test(e)}function si(){let e=!1;return"MediaSource"in self&&(self.MediaSource.isTypeSupported(ct)||self.MediaSource.isTypeSupported(ut)||self.MediaSource.isTypeSupported(ht)||self.MediaSource.isTypeSupported(ft)||self.MediaSource.isTypeSupported(pt))&&(e=!0),e}function ai(e){return null==e}function ni(e){return!ai(e)}function oi(e){return"function"==typeof e}function di(e){let t=null,i=31&e[0];return i!==Re&&i!==ze||(t=Ie),t||(i=(126&e[0])>>1,i!==Je&&i!==et&&i!==it||(t=De)),t}function li(){return"undefined"!=typeof WritableStream}function ci(e){e.close()}function ui(e,t){t&&(e=e.filter((e=>e.type&&e.type===t)));let i=e[0],r=null,s=1;if(e.length>0){let t=e[1];t&&t.ts-i.ts>1e5&&(i=t,s=2)}if(i)for(let a=s;a<e.length;a++){let s=e[a];if(t&&s.type&&s.type!==t&&(s=null),s){if(s.ts-i.ts>=1e3){e[a-1].ts-i.ts<1e3&&(r=a+1)}}}return r}function hi(e){return e.ok&&e.status>=200&&e.status<=299}function fi(){return function(e){let t="";if("object"==typeof e)try{t=JSON.stringify(e),t=JSON.parse(t)}catch(i){t=e}else t=e;return t}(v)}function pi(e){return e[0]>>4===Et&&e[1]===Ut}function _i(e){return!0===e||"true"===e}function mi(e){return!0!==e&&"true"!==e}function gi(){return!!(self.Worker&&self.MediaSource&&"canConstructInDedicatedWorker"in self.MediaSource&&!0===self.MediaSource.canConstructInDedicatedWorker)}function yi(e,t){const i=Xt(e.slice(5));let r=!1;return i.forEach((e=>{const i=t?e[0]>>>1&63:31&e[0];(t&&(i===Ye||i===je||i===Xe)||mi(t)&&i===Ne)&&(r=!0)})),r}var bi=function(e,t,i,r){return new(i||(i=Promise))((function(s,a){function n(e){try{d(r.next(e))}catch(e){a(e)}}function o(e){try{d(r.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,o)}d((r=r.apply(e,t||[])).next())}))};const Si=Symbol(32),vi=Symbol(16),wi=Symbol(8);class Ai{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 bi(this,void 0,void 0,(function*(){return this.lastReadPromise&&(yield this.lastReadPromise),this.lastReadPromise=new Promise(((t,i)=>{var r;this.reject=i,this.resolve=e=>{delete this.lastReadPromise,delete this.resolve,delete this.need,t(e)};this.demand(e,!0)||null===(r=this.pull)||void 0===r||r.call(this,e)}))}))}readU32(){return this.read(Si)}readU16(){return this.read(vi)}readU8(){return this.read(wi)}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 i=0;const r=e=>t.length<(i=e);if("number"==typeof this.need){if(r(this.need))return;e=t.subarray(0,i)}else if(this.need===Si){if(r(4))return;e=t[0]<<24|t[1]<<16|t[2]<<8|t[3]}else if(this.need===vi){if(r(2))return;e=t[0]<<8|t[1]}else if(this.need===wi){if(r(1))return;e=t[0]}else if("buffer"in this.need){if("byteOffset"in this.need){if(r(this.need.byteLength-this.need.byteOffset))return;new Uint8Array(this.need.buffer,this.need.byteOffset).set(t.subarray(0,i)),e=this.need}else if(this.g)return void this.g.throw(new Error("Unsupported type"))}else{if(r(this.need.byteLength))return;new Uint8Array(this.need).set(t.subarray(0,i)),e=this.need}return this.consumed+=i,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,i=t+e;if(i<=this.buffer.buffer.byteLength-this.buffer.byteOffset)this.buffer=new Uint8Array(this.buffer.buffer,this.buffer.byteOffset,i);else{const e=new Uint8Array(i);e.set(this.buffer),this.buffer=e}return this.buffer.subarray(t,i)}return this.buffer=new Uint8Array(e),this.buffer}}Ai.U32=Si,Ai.U16=vi,Ai.U8=wi;class Ui{constructor(e){this.log=function(t){if(e._opt.debug&&e._opt.debugLevel==m){const a=e._opt.debugUuid?`[${e._opt.debugUuid}]`:"";for(var i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];console.log(`JbPro${a}[✅✅✅][${t}]`,...r)}},this.warn=function(t){if(e._opt.debug&&(e._opt.debugLevel==m||e._opt.debugLevel==g)){const a=e._opt.debugUuid?`[${e._opt.debugUuid}]`:"";for(var i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];console.log(`JbPro${a}[❗❗❗][${t}]`,...r)}},this.error=function(t){const i=e._opt.debugUuid?`[${e._opt.debugUuid}]`:"";for(var r=arguments.length,s=new Array(r>1?r-1:0),a=1;a<r;a++)s[a-1]=arguments[a];console.error(`JbPro${i}[❌❌❌][${t}]`,...s)}}}class Ei{static _ebsp2rbsp(e){let t=e,i=t.byteLength,r=new Uint8Array(i),s=0;for(let e=0;e<i;e++)e>=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(r[s]=t[e],s++);return new Uint8Array(r.buffer,0,s)}static parseSPS(e){let t=Ei._ebsp2rbsp(e),i=new zt(t);i.readByte();let r=i.readByte();i.readByte();let s=i.readByte();i.readUEG();let a=Ei.getProfileString(r),n=Ei.getLevelString(s),o=1,d=420,l=[0,420,422,444],c=8;if((100===r||110===r||122===r||244===r||44===r||83===r||86===r||118===r||128===r||138===r||144===r)&&(o=i.readUEG(),3===o&&i.readBits(1),o<=3&&(d=l[o]),c=i.readUEG()+8,i.readUEG(),i.readBits(1),i.readBool())){let e=3!==o?8:12;for(let t=0;t<e;t++)i.readBool()&&(t<6?Ei._skipScalingList(i,16):Ei._skipScalingList(i,64))}i.readUEG();let u=i.readUEG();if(0===u)i.readUEG();else if(1===u){i.readBits(1),i.readSEG(),i.readSEG();let e=i.readUEG();for(let t=0;t<e;t++)i.readSEG()}let h=i.readUEG();i.readBits(1);let f=i.readUEG(),p=i.readUEG(),_=i.readBits(1);0===_&&i.readBits(1),i.readBits(1);let m=0,g=0,y=0,b=0;i.readBool()&&(m=i.readUEG(),g=i.readUEG(),y=i.readUEG(),b=i.readUEG());let S=1,v=1,w=0,A=!0,U=0,E=0;if(i.readBool()){if(i.readBool()){let e=i.readByte(),t=[1,12,10,16,40,24,20,32,80,18,15,64,160,4,3,2],r=[1,11,11,11,33,11,11,11,33,11,11,33,99,3,2,1];e>0&&e<16?(S=t[e-1],v=r[e-1]):255===e&&(S=i.readByte()<<8|i.readByte(),v=i.readByte()<<8|i.readByte())}if(i.readBool()&&i.readBool(),i.readBool()&&(i.readBits(4),i.readBool()&&i.readBits(24)),i.readBool()&&(i.readUEG(),i.readUEG()),i.readBool()){let e=i.readBits(32),t=i.readBits(32);A=i.readBool(),U=t,E=2*e,w=U/E}}let x=1;1===S&&1===v||(x=S/v);let B=0,T=0;if(0===o)B=1,T=2-_;else{B=3===o?1:2,T=(1===o?2:1)*(2-_)}let C=16*(f+1),k=16*(p+1)*(2-_);C-=(m+g)*B,k-=(y+b)*T;let I=Math.ceil(C*x);return i.destroy(),i=null,{profile_string:a,level_string:n,bit_depth:c,ref_frames:h,chroma_format:d,chroma_format_string:Ei.getChromaFormatString(d),frame_rate:{fixed:A,fps:w,fps_den:E,fps_num:U},sar_ratio:{width:S,height:v},codec_size:{width:C,height:k},present_size:{width:I,height:k}}}static parseSPS$2(e){let t=e.subarray(1,4),i="avc1.";for(let e=0;e<3;e++){let r=t[e].toString(16);r.length<2&&(r="0"+r),i+=r}let r=Ei._ebsp2rbsp(e),s=new zt(r);s.readByte();let a=s.readByte();s.readByte();let n=s.readByte();s.readUEG();let o=Ei.getProfileString(a),d=Ei.getLevelString(n),l=1,c=420,u=[0,420,422,444],h=8,f=8;if((100===a||110===a||122===a||244===a||44===a||83===a||86===a||118===a||128===a||138===a||144===a)&&(l=s.readUEG(),3===l&&s.readBits(1),l<=3&&(c=u[l]),h=s.readUEG()+8,f=s.readUEG()+8,s.readBits(1),s.readBool())){let e=3!==l?8:12;for(let t=0;t<e;t++)s.readBool()&&(t<6?Ei._skipScalingList(s,16):Ei._skipScalingList(s,64))}s.readUEG();let p=s.readUEG();if(0===p)s.readUEG();else if(1===p){s.readBits(1),s.readSEG(),s.readSEG();let e=s.readUEG();for(let t=0;t<e;t++)s.readSEG()}let _=s.readUEG();s.readBits(1);let m=s.readUEG(),g=s.readUEG(),y=s.readBits(1);0===y&&s.readBits(1),s.readBits(1);let b=0,S=0,v=0,w=0;s.readBool()&&(b=s.readUEG(),S=s.readUEG(),v=s.readUEG(),w=s.readUEG());let A=1,U=1,E=0,x=!0,B=0,T=0;if(s.readBool()){if(s.readBool()){let e=s.readByte(),t=[1,12,10,16,40,24,20,32,80,18,15,64,160,4,3,2],i=[1,11,11,11,33,11,11,11,33,11,11,33,99,3,2,1];e>0&&e<16?(A=t[e-1],U=i[e-1]):255===e&&(A=s.readByte()<<8|s.readByte(),U=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,E=B/T}}let C=1;1===A&&1===U||(C=A/U);let k=0,I=0;if(0===l)k=1,I=2-y;else{k=3===l?1:2,I=(1===l?2:1)*(2-y)}let D=16*(m+1),L=16*(g+1)*(2-y);D-=(b+S)*k,L-=(v+w)*I;let F=Math.ceil(D*C);return s.destroy(),s=null,{codec_mimetype:i,profile_idc:a,level_idc:n,profile_string:o,level_string:d,chroma_format_idc:l,bit_depth:h,bit_depth_luma:h,bit_depth_chroma:f,ref_frames:_,chroma_format:c,chroma_format_string:Ei.getChromaFormatString(c),frame_rate:{fixed:x,fps:E,fps_den:T,fps_num:B},sar_ratio:{width:A,height:U},codec_size:{width:D,height:L},present_size:{width:F,height:L}}}static _skipScalingList(e,t){let i=8,r=8,s=0;for(let a=0;a<t;a++)0!==r&&(s=e.readSEG(),r=(i+s+256)%256),i=0===r?i:r}static getProfileString(e){switch(e){case 66:return"Baseline";case 77:return"Main";case 88:return"Extended";case 100:return"High";case 110:return"High10";case 122:return"High422";case 244:return"High444";default:return"Unknown"}}static getLevelString(e){return(e/10).toFixed(1)}static getChromaFormatString(e){switch(e){case 420:return"4:2:0";case 422:return"4:2:2";case 444:return"4:4:4";default:return"Unknown"}}}class xi{constructor(e){this.buffer=e,this.buflen=e.length,this.bufpos=0,this.bufoff=0,this.iserro=!1}read(e){let t=0,i=0;for(;e;){if(e<0||this.bufpos>=this.buflen)return this.iserro=!0,0;this.iserro=!1,i=this.bufoff+e>8?8-this.bufoff:e,t<<=i,t+=this.buffer[this.bufpos]>>8-this.bufoff-i&255>>8-i,this.bufoff+=i,e-=i,8==this.bufoff&&(this.bufpos++,this.bufoff=0)}return t}look(e){let t=this.bufpos,i=this.bufoff,r=this.read(e);return this.bufpos=t,this.bufoff=i,r}read_golomb(){let e;for(e=0;0===this.read(1)&&!this.iserro;e++);return(1<<e)+this.read(e)-1}}function Bi(e){const t={};let i=function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),256===new Int16Array(e)[0]}();const r=new DataView(e.buffer);let s=r.getUint8(0),a=r.getUint8(1);if(r.getUint8(2),r.getUint8(3),1!==s||0===a)return{};const n=1+(3&r.getUint8(4));if(3!==n&&4!==n)return{};let o=31&r.getUint8(5);if(0===o)return{};let d=6;for(let s=0;s<o;s++){let a=r.getUint16(d,!i);if(d+=2,0===a)continue;let n=new Uint8Array(e.buffer,d,a);d+=a;let o=Ei.parseSPS(n);if(0!==s)continue;t.sps=n,t.timescale=1e3,t.codecWidth=o.codec_size.width,t.codecHeight=o.codec_size.height,t.presentWidth=o.present_size.width,t.presentHeight=o.present_size.height,t.profile=o.profile_string,t.level=o.level_string,t.bitDepth=o.bit_depth,t.chromaFormat=o.chroma_format,t.sarRatio=o.sar_ratio,t.frameRate=o.frame_rate,!1!==o.frame_rate.fixed&&0!==o.frame_rate.fps_num&&0!==o.frame_rate.fps_den||(t.frameRate={fixed:!0,fps:25,fps_num:25e3,fps_den:1e3});let l=t.frameRate.fps_den,c=t.frameRate.fps_num;t.refSampleDuration=t.timescale*(l/c);let u=n.subarray(1,4),h="avc1.";for(let e=0;e<3;e++){let t=u[e].toString(16);t.length<2&&(t="0"+t),h+=t}t.codec=h}let l=r.getUint8(d);if(0===l)return{};d++;for(let s=0;s<l;s++){let s=r.getUint16(d,!i);if(d+=2,0===s)continue;let a=new Uint8Array(e.buffer,d,s);d+=s,t.pps=a}if(t.videoType=vt,t.sps){const e=t.sps.byteLength,i=new Uint8Array([e>>>24&255,e>>>16&255,e>>>8&255,255&e]),r=new Uint8Array(e+4);r.set(i,0),r.set(t.sps,4),t.sps=r}if(t.pps){const e=t.pps.byteLength,i=new Uint8Array([e>>>24&255,e>>>16&255,e>>>8&255,255&e]),r=new Uint8Array(e+4);r.set(i,0),r.set(t.pps,4),t.pps=r}return t}function Ti(e){let{sps:t,pps:i}=e;const r=[23,0,0,0,0,1,66,0,30,255];r[0]=23,r[6]=t[1],r[7]=t[2],r[8]=t[3],r[10]=225,r[11]=t.byteLength>>8&255,r[12]=255&t.byteLength,r.push(...t,1,i.byteLength>>8&255,255&i.byteLength,...i);return new Uint8Array(r)}function Ci(e){let{sps:t,pps:i}=e,r=8+t.byteLength+1+2+i.byteLength,s=!1;const a=Ei.parseSPS$2(t);66!==t[3]&&77!==t[3]&&88!==t[3]&&(s=!0,r+=4);let n=new Uint8Array(r);n[0]=1,n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=255,n[5]=225;let o=t.byteLength;n[6]=o>>>8,n[7]=255&o;let d=8;n.set(t,8),d+=o,n[d]=1;let l=i.byteLength;n[d+1]=l>>>8,n[d+2]=255&l,n.set(i,d+3),d+=3+l,s&&(n[d]=252|a.chroma_format_idc,n[d+1]=248|a.bit_depth_luma-8,n[d+2]=248|a.bit_depth_chroma-8,n[d+3]=0,d+=4);const c=[23,0,0,0,0],u=new Uint8Array(c.length+n.byteLength);return u.set(c,0),u.set(n,c.length),u}function ki(e,t){let i=[];i[0]=t?23:39,i[1]=1,i[2]=0,i[3]=0,i[4]=0,i[5]=e.byteLength>>24&255,i[6]=e.byteLength>>16&255,i[7]=e.byteLength>>8&255,i[8]=255&e.byteLength;const r=new Uint8Array(i.length+e.byteLength);return r.set(i,0),r.set(e,i.length),r}function Ii(e,t){let i=[];i[0]=t?23:39,i[1]=1,i[2]=0,i[3]=0,i[4]=0;const r=new Uint8Array(i.length+e.byteLength);return r.set(i,0),r.set(e,i.length),r}function Di(e){return 31&e[0]}function Li(e){return e===He}function Fi(e){return!function(e){return e===Re||e===ze}(e)&&!Li(e)}function Pi(e){return e===Ne}function Mi(e){if(0===e.length)return!1;const t=Di(e[0]);for(let i=1;i<e.length;i++)if(t!==Di(e[i]))return!1;return!0}class Ri{constructor(e){this.data=e,this.eofFlag=!1,this.currentStartcodeOffset=this.findNextStartCodeOffset(0),this.eofFlag&&console.error("Could not find H264 startcode until payload end!")}findNextStartCodeOffset(e){let t=e,i=this.data;for(;;){if(t+3>=i.byteLength)return this.eofFlag=!0,i.byteLength;let e=i[t+0]<<24|i[t+1]<<16|i[t+2]<<8|i[t+3],r=i[t+0]<<16|i[t+1]<<8|i[t+2];if(1===e||1===r)return t;t++}}readNextNaluPayload(){let e=this.data,t=null;for(;null==t&&!this.eofFlag;){let i=this.currentStartcodeOffset;i+=1===(e[i]<<24|e[i+1]<<16|e[i+2]<<8|e[i+3])?4:3;let r=31&e[i],s=(128&e[i])>>>7,a=this.findNextStartCodeOffset(i);this.currentStartcodeOffset=a,r>=We||0===s&&(t={type:r,data:e.subarray(i,a)})}return t}}class zi{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 Ni=e=>{let t=e,i=t.byteLength,r=new Uint8Array(i),s=0;for(let e=0;e<i;e++)e>=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(r[s]=t[e],s++);return new Uint8Array(r.buffer,0,s)},Gi=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 Oi{static _ebsp2rbsp(e){let t=e,i=t.byteLength,r=new Uint8Array(i),s=0;for(let e=0;e<i;e++)e>=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(r[s]=t[e],s++);return new Uint8Array(r.buffer,0,s)}static parseVPS(e){let t=Oi._ebsp2rbsp(e),i=new zt(t);return i.readByte(),i.readByte(),i.readBits(4),i.readBits(2),i.readBits(6),{num_temporal_layers:i.readBits(3)+1,temporal_id_nested:i.readBool()}}static parseSPS(e){let t=Oi._ebsp2rbsp(e),i=new zt(t);i.readByte(),i.readByte();let r=0,s=0,a=0,n=0;i.readBits(4);let o=i.readBits(3);i.readBool();let d=i.readBits(2),l=i.readBool(),c=i.readBits(5),u=i.readByte(),h=i.readByte(),f=i.readByte(),p=i.readByte(),_=i.readByte(),m=i.readByte(),g=i.readByte(),y=i.readByte(),b=i.readByte(),S=i.readByte(),v=i.readByte(),w=[],A=[];for(let e=0;e<o;e++)w.push(i.readBool()),A.push(i.readBool());if(o>0)for(let e=o;e<8;e++)i.readBits(2);for(let e=0;e<o;e++)w[e]&&(i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte()),A[e]&&i.readByte();i.readUEG();let U=i.readUEG();3==U&&i.readBits(1);let E=i.readUEG(),x=i.readUEG();i.readBool()&&(r+=i.readUEG(),s+=i.readUEG(),a+=i.readUEG(),n+=i.readUEG());let B=i.readUEG(),T=i.readUEG(),C=i.readUEG();for(let e=i.readBool()?0:o;e<=o;e++)i.readUEG(),i.readUEG(),i.readUEG();if(i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readBool()){if(i.readBool())for(let e=0;e<4;e++)for(let t=0;t<(3===e?2:6);t++){if(i.readBool()){let t=Math.min(64,1<<4+(e<<1));e>1&&i.readSEG();for(let e=0;e<t;e++)i.readSEG()}else i.readUEG()}}i.readBool(),i.readBool(),i.readBool()&&(i.readByte(),i.readUEG(),i.readUEG(),i.readBool());let k=i.readUEG(),I=0;for(let e=0;e<k;e++){let t=!1;if(0!==e&&(t=i.readBool()),t){e===k&&i.readUEG(),i.readBool(),i.readUEG();let t=0;for(let e=0;e<=I;e++){let e=i.readBool(),r=!1;e||(r=i.readBool()),(e||r)&&t++}I=t}else{let e=i.readUEG(),t=i.readUEG();I=e+t;for(let t=0;t<e;t++)i.readUEG(),i.readBool();for(let e=0;e<t;e++)i.readUEG(),i.readBool()}}if(i.readBool()){let e=i.readUEG();for(let t=0;t<e;t++){for(let e=0;e<C+4;e++)i.readBits(1);i.readBits(1)}}let D=!1,L=0,F=1,P=1,M=!1,R=1,z=1;if(i.readBool(),i.readBool(),i.readBool()){if(i.readBool()){let e=i.readByte(),t=[1,12,10,16,40,24,20,32,80,18,15,64,160,4,3,2],r=[1,11,11,11,33,11,11,11,33,11,11,33,99,3,2,1];e>0&&e<=16?(F=t[e-1],P=r[e-1]):255===e&&(F=i.readBits(16),P=i.readBits(16))}if(i.readBool()&&i.readBool(),i.readBool()){i.readBits(3),i.readBool(),i.readBool()&&(i.readByte(),i.readByte(),i.readByte())}if(i.readBool()&&(i.readUEG(),i.readUEG()),i.readBool(),i.readBool(),i.readBool(),D=i.readBool(),D&&(i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG()),i.readBool()){if(R=i.readBits(32),z=i.readBits(32),i.readBool()&&i.readUEG(),i.readBool()){let e=!1,t=!1,r=!1;e=i.readBool(),t=i.readBool(),(e||t)&&(r=i.readBool(),r&&(i.readByte(),i.readBits(5),i.readBool(),i.readBits(5)),i.readBits(4),i.readBits(4),r&&i.readBits(4),i.readBits(5),i.readBits(5),i.readBits(5));for(let s=0;s<=o;s++){let s=i.readBool();M=s;let a=!0,n=1;s||(a=i.readBool());let o=!1;if(a?i.readUEG():o=i.readBool(),o||(n=i.readUEG()+1),e){for(let e=0;e<n;e++)i.readUEG(),i.readUEG(),r&&(i.readUEG(),i.readUEG());i.readBool()}if(t){for(let e=0;e<n;e++)i.readUEG(),i.readUEG(),r&&(i.readUEG(),i.readUEG());i.readBool()}}}}i.readBool()&&(i.readBool(),i.readBool(),i.readBool(),L=i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG())}i.readBool();let N=`hvc1.${c}.1.L${v}.B0`,G=E-(r+s)*(1===U||2===U?2:1),O=x-(a+n)*(1===U?2:1),H=1;return 1!==F&&1!==P&&(H=F/P),i.destroy(),i=null,{codec_mimetype:N,profile_string:Oi.getProfileString(c),level_string:Oi.getLevelString(v),profile_idc:c,bit_depth:B+8,ref_frames:1,chroma_format:U,chroma_format_string:Oi.getChromaFormatString(U),general_level_idc:v,general_profile_space:d,general_tier_flag:l,general_profile_idc:c,general_profile_compatibility_flags_1:u,general_profile_compatibility_flags_2:h,general_profile_compatibility_flags_3:f,general_profile_compatibility_flags_4:p,general_constraint_indicator_flags_1:_,general_constraint_indicator_flags_2:m,general_constraint_indicator_flags_3:g,general_constraint_indicator_flags_4:y,general_constraint_indicator_flags_5:b,general_constraint_indicator_flags_6:S,min_spatial_segmentation_idc:L,constant_frame_rate:0,chroma_format_idc:U,bit_depth_luma_minus8:B,bit_depth_chroma_minus8:T,frame_rate:{fixed:M,fps:z/R,fps_den:R,fps_num:z},sar_ratio:{width:F,height:P},codec_size:{width:G,height:O},present_size:{width:G*H,height:O}}}static parsePPS(e){let t=Oi._ebsp2rbsp(e),i=new zt(t);i.readByte(),i.readByte(),i.readUEG(),i.readUEG(),i.readBool(),i.readBool(),i.readBits(3),i.readBool(),i.readBool(),i.readUEG(),i.readUEG(),i.readSEG(),i.readBool(),i.readBool(),i.readBool()&&i.readUEG(),i.readSEG(),i.readSEG(),i.readBool(),i.readBool(),i.readBool(),i.readBool();let r=i.readBool(),s=i.readBool(),a=1;return s&&r?a=0:s?a=3:r&&(a=2),{parallelismType:a}}static getChromaFormatString(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"}}static getProfileString(e){switch(e){case 1:return"Main";case 2:return"Main10";case 3:return"MainSP";case 4:return"Rext";case 9:return"SCC";default:return"Unknown"}}static getLevelString(e){return(e/30).toFixed(1)}}function Hi(e){let t={codecWidth:0,codecHeight:0,videoType:wt,width:0,height:0,profile:0,level:0};e=e.slice(5);do{let i={};if(e.length<23){console.warn("parseHEVCDecoderConfigurationRecord$2",`arrayBuffer.length ${e.length} < 23`);break}if(i.configurationVersion=e[0],1!=i.configurationVersion)break;i.general_profile_space=e[1]>>6&3,i.general_tier_flag=e[1]>>5&1,i.general_profile_idc=31&e[1],i.general_profile_compatibility_flags=e[2]<<24|e[3]<<16|e[4]<<8|e[5],i.general_constraint_indicator_flags=e[6]<<24|e[7]<<16|e[8]<<8|e[9],i.general_constraint_indicator_flags=i.general_constraint_indicator_flags<<16|e[10]<<8|e[11],i.general_level_idc=e[12],i.min_spatial_segmentation_idc=(15&e[13])<<8|e[14],i.parallelismType=3&e[15],i.chromaFormat=3&e[16],i.bitDepthLumaMinus8=7&e[17],i.bitDepthChromaMinus8=7&e[18],i.avgFrameRate=e[19]<<8|e[20],i.constantFrameRate=e[21]>>6&3,i.numTemporalLayers=e[21]>>3&7,i.temporalIdNested=e[21]>>2&1,i.lengthSizeMinusOne=3&e[21];let r=e[22],s=e.slice(23);for(let e=0;e<r&&!(s.length<3);e++){let e=63&s[0],r=s[1]<<8|s[2];s=s.slice(3);for(let a=0;a<r&&!(s.length<2);a++){let r=s[0]<<8|s[1];if(s.length<2+r)break;if(s=s.slice(2),33==e){let e=new Uint8Array(r);e.set(s.slice(0,r),0),i.psps=$i(e,i),t.profile=i.general_profile_idc,t.level=i.general_level_idc/30,t.width=i.psps.pic_width_in_luma_samples-(i.psps.conf_win_left_offset+i.psps.conf_win_right_offset),t.height=i.psps.pic_height_in_luma_samples-(i.psps.conf_win_top_offset+i.psps.conf_win_bottom_offset)}s=s.slice(r)}}}while(0);return t.codecWidth=t.width||1920,t.codecHeight=t.height||1080,t.presentHeight=t.codecHeight,t.presentWidth=t.codecWidth,t.timescale=1e3,t.refSampleDuration=1e3/23976*1e3,t}function Vi(e){const t=e;if(t.length<22)return console.error(`Invalid HEVCDecoderConfigurationRecord, lack of data! ${t.length} < 22`),{};let i={codecWidth:0,codecHeight:0,videoType:wt},r=function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),256===new Int16Array(e)[0]}(),s=new DataView(t.buffer),a=s.getUint8(0),n=31&s.getUint8(1);if(1!==a||0===n)return console.error(`Invalid HEVCDecoderConfigurationRecord,version is ${a}, hevcProfile is ${n}`),{};let o=1+(3&s.getUint8(21));if(3!==o&&4!==o)return console.error("Invalid HEVCDecoderConfigurationRecord, Strange NaluLengthSizeMinusOne: "+(o-1)),{};let d=s.getUint8(22);for(let e=0,a=23;e<d;e++){let e=63&s.getUint8(a+0),n=s.getUint16(a+1,!r);a+=3;for(let o=0;o<n;o++){let n=s.getUint16(a+0,!r);if(0===o)if(33===e){a+=2;let e=new Uint8Array(t.buffer,a,n),r=Oi.parseSPS(e);i.codecWidth=r.codec_size.width,i.codecHeight=r.codec_size.height,i.presentWidth=r.present_size.width,i.presentHeight=r.present_size.height,i.profile=r.profile_string,i.level=r.level_string,i.bitDepth=r.bit_depth,i.chromaFormat=r.chroma_format,i.sarRatio=r.sar_ratio,i.frameRate=r.frame_rate,!1!==r.frame_rate.fixed&&0!==r.frame_rate.fps_num&&0!==r.frame_rate.fps_den||(i.frameRate={fixed:!0,fps:23.976,fps_num:23976,fps_den:1e3}),i.frameRate.fps_den,i.frameRate.fps_num,i.codec=r.codec_mimetype,a+=n}else a+=2+n;else a+=2+n}}return i.hvcc=new Uint8Array(t),i}function $i(e,t){let i={},r=e.length,s=[],a=new xi(e);a.read(1),a.read(6),a.read(6),a.read(3);for(let e=2;e<r;e++)e+2<r&&3==a.look(24)?(s.push(a.read(8)),s.push(a.read(8)),e+=2,a.read(8)):s.push(a.read(8));let n=new Uint8Array(s),o=new xi(n);if(i.sps_video_parameter_set_id=o.read(4),i.sps_max_sub_layers_minus1=o.read(3),i.sps_temporal_id_nesting_flag=o.read(1),i.profile_tier_level=function(e,t,i){let r={};r.profile_space=e.read(2),r.tier_flag=e.read(1),r.profile_idc=e.read(5),r.profile_compatibility_flags=e.read(32),r.general_progressive_source_flag=e.read(1),r.general_interlaced_source_flag=e.read(1),r.general_non_packed_constraint_flag=e.read(1),r.general_frame_only_constraint_flag=e.read(1),e.read(32),e.read(12),r.level_idc=e.read(8),r.sub_layer_profile_present_flag=[],r.sub_layer_level_present_flag=[];for(let t=0;t<i;t++)r.sub_layer_profile_present_flag[t]=e.read(1),r.sub_layer_level_present_flag[t]=e.read(1);if(i>0)for(let t=i;t<8;t++)e.read(2);r.sub_layer_profile_space=[],r.sub_layer_tier_flag=[],r.sub_layer_profile_idc=[],r.sub_layer_profile_compatibility_flag=[],r.sub_layer_progressive_source_flag=[],r.sub_layer_interlaced_source_flag=[],r.sub_layer_non_packed_constraint_flag=[],r.sub_layer_frame_only_constraint_flag=[],r.sub_layer_level_idc=[];for(let t=0;t<i;t++)r.sub_layer_profile_present_flag[t]&&(r.sub_layer_profile_space[t]=e.read(2),r.sub_layer_tier_flag[t]=e.read(1),r.sub_layer_profile_idc[t]=e.read(5),r.sub_layer_profile_compatibility_flag[t]=e.read(32),r.sub_layer_progressive_source_flag[t]=e.read(1),r.sub_layer_interlaced_source_flag[t]=e.read(1),r.sub_layer_non_packed_constraint_flag[t]=e.read(1),r.sub_layer_frame_only_constraint_flag[t]=e.read(1),e.read(32),e.read(12)),r.sub_layer_level_present_flag[t]?r.sub_layer_level_idc[t]=e.read(8):r.sub_layer_level_idc[t]=1;return r}(o,0,i.sps_max_sub_layers_minus1),i.sps_seq_parameter_set_id=o.read_golomb(),i.chroma_format_idc=o.read_golomb(),3==i.chroma_format_idc?i.separate_colour_plane_flag=o.read(1):i.separate_colour_plane_flag=0,i.pic_width_in_luma_samples=o.read_golomb(),i.pic_height_in_luma_samples=o.read_golomb(),i.conformance_window_flag=o.read(1),i.conformance_window_flag){let e=1+(i.chroma_format_idc<2),t=1+(i.chroma_format_idc<3);i.conf_win_left_offset=o.read_golomb()*t,i.conf_win_right_offset=o.read_golomb()*t,i.conf_win_top_offset=o.read_golomb()*e,i.conf_win_bottom_offset=o.read_golomb()*e}else i.conf_win_left_offset=0,i.conf_win_right_offset=0,i.conf_win_top_offset=0,i.conf_win_bottom_offset=0;return i}function Wi(e){let{vps:t,pps:i,sps:r}=e,s={configurationVersion:1};const a=(e=>{let t=Ni(e),i=new zt(t);return i.readByte(),i.readByte(),i.readBits(4),i.readBits(2),i.readBits(6),{num_temporal_layers:i.readBits(3)+1,temporal_id_nested:i.readBool()}})(t),n=(e=>{let t=Ni(e),i=new zt(t);i.readByte(),i.readByte();let r=0,s=0,a=0,n=0;i.readBits(4);let o=i.readBits(3);i.readBool();let d=i.readBits(2),l=i.readBool(),c=i.readBits(5),u=i.readByte(),h=i.readByte(),f=i.readByte(),p=i.readByte(),_=i.readByte(),m=i.readByte(),g=i.readByte(),y=i.readByte(),b=i.readByte(),S=i.readByte(),v=i.readByte(),w=[],A=[];for(let e=0;e<o;e++)w.push(i.readBool()),A.push(i.readBool());if(o>0)for(let e=o;e<8;e++)i.readBits(2);for(let e=0;e<o;e++)w[e]&&(i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte(),i.readByte()),w[e]&&i.readByte();i.readUEG();let U=i.readUEG();3==U&&i.readBits(1);let E=i.readUEG(),x=i.readUEG();i.readBool()&&(r+=i.readUEG(),s+=i.readUEG(),a+=i.readUEG(),n+=i.readUEG());let B=i.readUEG(),T=i.readUEG(),C=i.readUEG();for(let e=i.readBool()?0:o;e<=o;e++)i.readUEG(),i.readUEG(),i.readUEG();if(i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readBool()&&i.readBool())for(let e=0;e<4;e++)for(let t=0;t<(3===e?2:6);t++)if(i.readBool()){let t=Math.min(64,1<<4+(e<<1));e>1&&i.readSEG();for(let e=0;e<t;e++)i.readSEG()}else i.readUEG();i.readBool(),i.readBool(),i.readBool()&&(i.readByte(),i.readUEG(),i.readUEG(),i.readBool());let k=i.readUEG(),I=0;for(let e=0;e<k;e++){let t=!1;if(0!==e&&(t=i.readBool()),t){e===k&&i.readUEG(),i.readBool(),i.readUEG();let t=0;for(let e=0;e<=I;e++){let e=i.readBool(),r=!1;e||(r=i.readBool()),(e||r)&&t++}I=t}else{let e=i.readUEG(),t=i.readUEG();I=e+t;for(let t=0;t<e;t++)i.readUEG(),i.readBool();for(let e=0;e<t;e++)i.readUEG(),i.readBool()}}if(i.readBool()){let e=i.readUEG();for(let t=0;t<e;t++){for(let e=0;e<C+4;e++)i.readBits(1);i.readBits(1)}}let D=!1,L=0,F=1,P=1,M=!1,R=1,z=1;if(i.readBool(),i.readBool(),i.readBool()){if(i.readBool()){let e=i.readByte(),t=[1,12,10,16,40,24,20,32,80,18,15,64,160,4,3,2],r=[1,11,11,11,33,11,11,11,33,11,11,33,99,3,2,1];e>0&&e<16?(F=t[e-1],P=r[e-1]):255===e&&(F=i.readBits(16),P=i.readBits(16))}if(i.readBool()&&i.readBool(),i.readBool()&&(i.readBits(3),i.readBool(),i.readBool()&&(i.readByte(),i.readByte(),i.readByte())),i.readBool()&&(i.readUEG(),i.readUEG()),i.readBool(),i.readBool(),i.readBool(),D=i.readBool(),D&&(r+=i.readUEG(),s+=i.readUEG(),a+=i.readUEG(),n+=i.readUEG()),i.readBool()&&(R=i.readBits(32),z=i.readBits(32),i.readBool()&&(i.readUEG(),i.readBool()))){let e=!1,t=!1,r=!1;e=i.readBool(),t=i.readBool(),(e||t)&&(r=i.readBool(),r&&(i.readByte(),i.readBits(5),i.readBool(),i.readBits(5)),i.readBits(4),i.readBits(4),r&&i.readBits(4),i.readBits(5),i.readBits(5),i.readBits(5));for(let s=0;s<=o;s++){let s=i.readBool();M=s;let a=!1,n=1;s||(a=i.readBool());let o=!1;if(a?i.readSEG():o=i.readBool(),o||(cpbcnt=i.readUEG()+1),e)for(let e=0;e<n;e++)i.readUEG(),i.readUEG(),r&&(i.readUEG(),i.readUEG());if(t)for(let e=0;e<n;e++)i.readUEG(),i.readUEG(),r&&(i.readUEG(),i.readUEG())}}i.readBool()&&(i.readBool(),i.readBool(),i.readBool(),L=i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG(),i.readUEG())}i.readBool();let N=`hvc1.${c}.1.L${v}.B0`,G=E,O=x,H=1;return 1!==F&&1!==P&&(H=F/P),i.destroy(),i=null,{codec_mimetype:N,level_string:(V=v,(V/30).toFixed(1)),profile_idc:c,bit_depth:B+8,ref_frames:1,chroma_format:U,chroma_format_string:Gi(U),general_level_idc:v,general_profile_space:d,general_tier_flag:l,general_profile_idc:c,general_profile_compatibility_flags_1:u,general_profile_compatibility_flags_2:h,general_profile_compatibility_flags_3:f,general_profile_compatibility_flags_4:p,general_constraint_indicator_flags_1:_,general_constraint_indicator_flags_2:m,general_constraint_indicator_flags_3:g,general_constraint_indicator_flags_4:y,general_constraint_indicator_flags_5:b,general_constraint_indicator_flags_6:S,min_spatial_segmentation_idc:L,constant_frame_rate:0,chroma_format_idc:U,bit_depth_luma_minus8:B,bit_depth_chroma_minus8:T,frame_rate:{fixed:M,fps:z/R,fps_den:R,fps_num:z},sar_ratio:{width:F,height:P},codec_size:{width:G,height:O},present_size:{width:G*H,height:O}};var V})(r),o=(e=>{let t=Ni(e),i=new zt(t);i.readByte(),i.readByte(),i.readUEG(),i.readUEG(),i.readBool(),i.readBool(),i.readBits(3),i.readBool(),i.readBool(),i.readUEG(),i.readUEG(),i.readSEG(),i.readBool(),i.readBool(),i.readBool()&&i.readUEG(),i.readSEG(),i.readSEG(),i.readBool(),i.readBool(),i.readBool(),i.readBool();let r=i.readBool(),s=i.readBool(),a=1;return s&&r?a=0:s?a=3:r&&(a=2),{parallelismType:a}})(i);s=Object.assign(s,a,n,o);let d=23+(5+t.byteLength)+(5+r.byteLength)+(5+i.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|Je,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|et,l[23+(5+t.byteLength)+1]=0,l[23+(5+t.byteLength)+2]=1,l[23+(5+t.byteLength)+3]=(65280&r.byteLength)>>8,l[23+(5+t.byteLength)+4]=(255&r.byteLength)>>0,l.set(r,23+(5+t.byteLength)+5),l[23+(5+t.byteLength+5+r.byteLength)+0]=128|it,l[23+(5+t.byteLength+5+r.byteLength)+1]=0,l[23+(5+t.byteLength+5+r.byteLength)+2]=1,l[23+(5+t.byteLength+5+r.byteLength)+3]=(65280&i.byteLength)>>8,l[23+(5+t.byteLength+5+r.byteLength)+4]=(255&i.byteLength)>>0,l.set(i,23+(5+t.byteLength+5+r.byteLength)+5);const c=[28,0,0,0,0],u=new Uint8Array(c.length+l.byteLength);return u.set(c,0),u.set(l,c.length),u}function Yi(e,t){let i=[];i[0]=t?28:44,i[1]=1,i[2]=0,i[3]=0,i[4]=0,i[5]=e.byteLength>>24&255,i[6]=e.byteLength>>16&255,i[7]=e.byteLength>>8&255,i[8]=255&e.byteLength;const r=new Uint8Array(i.length+e.byteLength);return r.set(i,0),r.set(e,i.length),r}function qi(e,t){let i=[];i[0]=t?28:44,i[1]=1,i[2]=0,i[3]=0,i[4]=0;const r=new Uint8Array(i.length+e.byteLength);return r.set(i,0),r.set(e,i.length),r}function ji(e){return(126&e[0])>>1}function Ki(e){return e===st}function Xi(e){return!function(e){return e>=32&&e<=40}(e)}function Zi(e){return e>=16&&e<=21}function Ji(e){if(0===e.length)return!1;const t=ji(e[0]);for(let i=1;i<e.length;i++)if(t!==ji(e[i]))return!1;return!0}class Qi{constructor(e){this.data=e,this.eofFlag=!1,this.currentStartcodeOffset=this.findNextStartCodeOffset(0),this.eofFlag&&console.error("Could not find H265 startcode until payload end!")}findNextStartCodeOffset(e){let t=e,i=this.data;for(;;){if(t+3>=i.byteLength)return this.eofFlag=!0,i.byteLength;let e=i[t+0]<<24|i[t+1]<<16|i[t+2]<<8|i[t+3],r=i[t+0]<<16|i[t+1]<<8|i[t+2];if(1===e||1===r)return t;t++}}readNextNaluPayload(){let e=this.data,t=null;for(;null==t&&!this.eofFlag;){let i=this.currentStartcodeOffset;i+=1===(e[i]<<24|e[i+1]<<16|e[i+2]<<8|e[i+3])?4:3;let r=e[i]>>1&63,s=(128&e[i])>>>7,a=this.findNextStartCodeOffset(i);this.currentStartcodeOffset=a,0===s&&(t={type:r,data:e.subarray(i,a)})}return t}}class er{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 tr(e){return parseInt(e)===e}function ir(e){if(!tr(e.length))return!1;for(var t=0;t<e.length;t++)if(!tr(e[t])||e[t]<0||e[t]>255)return!1;return!0}function rr(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(!ir(e))throw new Error("Array contains invalid value: "+e);return new Uint8Array(e)}if(tr(e.length)&&ir(e))return new Uint8Array(e);throw new Error("unsupported array-like object")}function sr(e){return new Uint8Array(e)}function ar(e,t,i,r,s){null==r&&null==s||(e=e.slice?e.slice(r,s):Array.prototype.slice.call(e,r,s)),t.set(e,i)}var nr,or={toBytes:function(e){var t=[],i=0;for(e=encodeURI(e);i<e.length;){var r=e.charCodeAt(i++);37===r?(t.push(parseInt(e.substr(i,2),16)),i+=2):t.push(r)}return rr(t)},fromBytes:function(e){for(var t=[],i=0;i<e.length;){var r=e[i];r<128?(t.push(String.fromCharCode(r)),i++):r>191&&r<224?(t.push(String.fromCharCode((31&r)<<6|63&e[i+1])),i+=2):(t.push(String.fromCharCode((15&r)<<12|(63&e[i+1])<<6|63&e[i+2])),i+=3)}return t.join("")}},dr=(nr="0123456789abcdef",{toBytes:function(e){for(var t=[],i=0;i<e.length;i+=2)t.push(parseInt(e.substr(i,2),16));return t},fromBytes:function(e){for(var t=[],i=0;i<e.length;i++){var r=e[i];t.push(nr[(240&r)>>4]+nr[15&r])}return t.join("")}}),lr={16:10,24:12,32:14},cr=[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],ur=[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],hr=[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],fr=[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],pr=[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],_r=[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],mr=[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],gr=[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],yr=[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],br=[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],Sr=[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],vr=[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],wr=[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],Ar=[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],Ur=[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 Er(e){for(var t=[],i=0;i<e.length;i+=4)t.push(e[i]<<24|e[i+1]<<16|e[i+2]<<8|e[i+3]);return t}var xr=function(e){if(!(this instanceof xr))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:rr(e,!0)}),this._prepare()};xr.prototype._prepare=function(){var e=lr[this.key.length];if(null==e)throw new Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var t=0;t<=e;t++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);var i,r=4*(e+1),s=this.key.length/4,a=Er(this.key);for(t=0;t<s;t++)i=t>>2,this._Ke[i][t%4]=a[t],this._Kd[e-i][t%4]=a[t];for(var n,o=0,d=s;d<r;){if(n=a[s-1],a[0]^=ur[n>>16&255]<<24^ur[n>>8&255]<<16^ur[255&n]<<8^ur[n>>24&255]^cr[o]<<24,o+=1,8!=s)for(t=1;t<s;t++)a[t]^=a[t-1];else{for(t=1;t<s/2;t++)a[t]^=a[t-1];n=a[s/2-1],a[s/2]^=ur[255&n]^ur[n>>8&255]<<8^ur[n>>16&255]<<16^ur[n>>24&255]<<24;for(t=s/2+1;t<s;t++)a[t]^=a[t-1]}for(t=0;t<s&&d<r;)l=d>>2,c=d%4,this._Ke[l][c]=a[t],this._Kd[e-l][c]=a[t++],d++}for(var l=1;l<e;l++)for(var c=0;c<4;c++)n=this._Kd[l][c],this._Kd[l][c]=vr[n>>24&255]^wr[n>>16&255]^Ar[n>>8&255]^Ur[255&n]},xr.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,i=[0,0,0,0],r=Er(e),s=0;s<4;s++)r[s]^=this._Ke[0][s];for(var a=1;a<t;a++){for(s=0;s<4;s++)i[s]=fr[r[s]>>24&255]^pr[r[(s+1)%4]>>16&255]^_r[r[(s+2)%4]>>8&255]^mr[255&r[(s+3)%4]]^this._Ke[a][s];r=i.slice()}var n,o=sr(16);for(s=0;s<4;s++)n=this._Ke[t][s],o[4*s]=255&(ur[r[s]>>24&255]^n>>24),o[4*s+1]=255&(ur[r[(s+1)%4]>>16&255]^n>>16),o[4*s+2]=255&(ur[r[(s+2)%4]>>8&255]^n>>8),o[4*s+3]=255&(ur[255&r[(s+3)%4]]^n);return o},xr.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,i=[0,0,0,0],r=Er(e),s=0;s<4;s++)r[s]^=this._Kd[0][s];for(var a=1;a<t;a++){for(s=0;s<4;s++)i[s]=gr[r[s]>>24&255]^yr[r[(s+3)%4]>>16&255]^br[r[(s+2)%4]>>8&255]^Sr[255&r[(s+1)%4]]^this._Kd[a][s];r=i.slice()}var n,o=sr(16);for(s=0;s<4;s++)n=this._Kd[t][s],o[4*s]=255&(hr[r[s]>>24&255]^n>>24),o[4*s+1]=255&(hr[r[(s+3)%4]>>16&255]^n>>16),o[4*s+2]=255&(hr[r[(s+2)%4]>>8&255]^n>>8),o[4*s+3]=255&(hr[255&r[(s+1)%4]]^n);return o};var Br=function(e){if(!(this instanceof Br))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new xr(e)};Br.prototype.encrypt=function(e){if((e=rr(e)).length%16!=0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var t=sr(e.length),i=sr(16),r=0;r<e.length;r+=16)ar(e,i,0,r,r+16),ar(i=this._aes.encrypt(i),t,r);return t},Br.prototype.decrypt=function(e){if((e=rr(e)).length%16!=0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var t=sr(e.length),i=sr(16),r=0;r<e.length;r+=16)ar(e,i,0,r,r+16),ar(i=this._aes.decrypt(i),t,r);return t};var Tr=function(e,t){if(!(this instanceof Tr))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",t){if(16!=t.length)throw new Error("invalid initialation vector size (must be 16 bytes)")}else t=sr(16);this._lastCipherblock=rr(t,!0),this._aes=new xr(e)};Tr.prototype.encrypt=function(e){if((e=rr(e)).length%16!=0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var t=sr(e.length),i=sr(16),r=0;r<e.length;r+=16){ar(e,i,0,r,r+16);for(var s=0;s<16;s++)i[s]^=this._lastCipherblock[s];this._lastCipherblock=this._aes.encrypt(i),ar(this._lastCipherblock,t,r)}return t},Tr.prototype.decrypt=function(e){if((e=rr(e)).length%16!=0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var t=sr(e.length),i=sr(16),r=0;r<e.length;r+=16){ar(e,i,0,r,r+16),i=this._aes.decrypt(i);for(var s=0;s<16;s++)t[r+s]=i[s]^this._lastCipherblock[s];ar(e,this._lastCipherblock,0,r,r+16)}return t};var Cr=function(e,t,i){if(!(this instanceof Cr))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",t){if(16!=t.length)throw new Error("invalid initialation vector size (must be 16 size)")}else t=sr(16);i||(i=1),this.segmentSize=i,this._shiftRegister=rr(t,!0),this._aes=new xr(e)};Cr.prototype.encrypt=function(e){if(e.length%this.segmentSize!=0)throw new Error("invalid plaintext size (must be segmentSize bytes)");for(var t,i=rr(e,!0),r=0;r<i.length;r+=this.segmentSize){t=this._aes.encrypt(this._shiftRegister);for(var s=0;s<this.segmentSize;s++)i[r+s]^=t[s];ar(this._shiftRegister,this._shiftRegister,0,this.segmentSize),ar(i,this._shiftRegister,16-this.segmentSize,r,r+this.segmentSize)}return i},Cr.prototype.decrypt=function(e){if(e.length%this.segmentSize!=0)throw new Error("invalid ciphertext size (must be segmentSize bytes)");for(var t,i=rr(e,!0),r=0;r<i.length;r+=this.segmentSize){t=this._aes.encrypt(this._shiftRegister);for(var s=0;s<this.segmentSize;s++)i[r+s]^=t[s];ar(this._shiftRegister,this._shiftRegister,0,this.segmentSize),ar(e,this._shiftRegister,16-this.segmentSize,r,r+this.segmentSize)}return i};var kr=function(e,t){if(!(this instanceof kr))throw Error("AES must be instanitated with `new`");if(this.description="Output Feedback",this.name="ofb",t){if(16!=t.length)throw new Error("invalid initialation vector size (must be 16 bytes)")}else t=sr(16);this._lastPrecipher=rr(t,!0),this._lastPrecipherIndex=16,this._aes=new xr(e)};kr.prototype.encrypt=function(e){for(var t=rr(e,!0),i=0;i<t.length;i++)16===this._lastPrecipherIndex&&(this._lastPrecipher=this._aes.encrypt(this._lastPrecipher),this._lastPrecipherIndex=0),t[i]^=this._lastPrecipher[this._lastPrecipherIndex++];return t},kr.prototype.decrypt=kr.prototype.encrypt;var Ir=function(e){if(!(this instanceof Ir))throw Error("Counter must be instanitated with `new`");0===e||e||(e=1),"number"==typeof e?(this._counter=sr(16),this.setValue(e)):this.setBytes(e)};Ir.prototype.setValue=function(e){if("number"!=typeof e||parseInt(e)!=e)throw new Error("invalid counter value (must be an integer)");if(e>Number.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)},Ir.prototype.setBytes=function(e){if(16!=(e=rr(e,!0)).length)throw new Error("invalid counter bytes size (must be 16 bytes)");this._counter=e},Ir.prototype.increment=function(){for(var e=15;e>=0;e--){if(255!==this._counter[e]){this._counter[e]++;break}this._counter[e]=0}};var Dr=function(e,t){if(!(this instanceof Dr))throw Error("AES must be instanitated with `new`");this.description="Counter",this.name="ctr",t instanceof Ir||(t=new Ir(t)),this._counter=t,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new xr(e)};Dr.prototype.encrypt=function(e){for(var t=rr(e,!0),i=0;i<t.length;i++)16===this._remainingCounterIndex&&(this._remainingCounter=this._aes.encrypt(this._counter._counter),this._remainingCounterIndex=0,this._counter.increment()),t[i]^=this._remainingCounter[this._remainingCounterIndex++];return t},Dr.prototype.decrypt=Dr.prototype.encrypt;const Lr={AES:xr,Counter:Ir,ModeOfOperation:{ecb:Br,cbc:Tr,cfb:Cr,ofb:kr,ctr:Dr},utils:{hex:dr,utf8:or},padding:{pkcs7:{pad:function(e){var t=16-(e=rr(e,!0)).length%16,i=sr(e.length+t);ar(e,i);for(var r=e.length;r<i.length;r++)i[r]=t;return i},strip:function(e){if((e=rr(e,!0)).length<16)throw new Error("PKCS#7 invalid length");var t=e[e.length-1];if(t>16)throw new Error("PKCS#7 padding byte out of range");for(var i=e.length-t,r=0;r<t;r++)if(e[i+r]!==t)throw new Error("PKCS#7 invalid padding byte");var s=sr(i);return ar(e,s,0,0,i),s}}},_arrayTest:{coerceArray:rr,createArray:sr,copyArray:ar}};function Fr(e){return e[3]|e[2]<<8|e[1]<<16|e[0]<<24}function Pr(e,t,i){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];t=new Uint8Array(t),i=new Uint8Array(i);const s=e.byteLength;let a=5;for(;a<s;){let n=Fr(e.slice(a,a+4));if(n>s)break;let o=e[a+4],d=!1;if(r?(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 r=e.slice(a+4+2,a+4+n);let s=new Lr.ModeOfOperation.ctr(t,new Lr.Counter(i));const o=s.decrypt(r);s=null,e.set(o,a+4+2)}a=a+4+n}return e}function Mr(e,t,i){if(e.byteLength<=30)return e;const r=e.slice(32);let s=new Lr.ModeOfOperation.ctr(t,new Lr.Counter(i));const a=s.decrypt(r);return s=null,e.set(a,32),e}var Rr=Rt((function(e,t){var r,s,a,n=(r=new Date,s=4,a={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("["+n.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)},log:function(e,t){this.debug(e.msg)},info:function(e,t){2>=s&&console.info("["+n.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)},warn:function(e,t){3>=s&&console.warn("["+n.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)},error:function(e,t){4>=s&&console.error("["+n.getDurationString(new Date-r,1e3)+"]","["+e+"]",t)}},a);n.getDurationString=function(e,t){var i;function r(e,t){for(var i=(""+e).split(".");i[0].length<t;)i[0]="0"+i[0];return i.join(".")}e<0?(i=!0,e=-e):i=!1;var s=e/(t||1),a=Math.floor(s/3600);s-=3600*a;var n=Math.floor(s/60),o=1e3*(s-=60*n);return o-=1e3*(s=Math.floor(s)),o=Math.floor(o),(i?"-":"")+a+":"+r(n,2)+":"+r(s,2)+"."+r(o,3)},n.printRanges=function(e){var t=e.length;if(t>0){for(var i="",r=0;r<t;r++)r>0&&(i+=","),i+="["+n.getDurationString(e.start(r))+","+n.getDurationString(e.end(r))+"]";return i}return"(empty)"},t.Log=n;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 i=0;if(this.position+e<=this.buffer.byteLength){switch(e){case 1:i=t?this.dataview.getInt8(this.position):this.dataview.getUint8(this.position);break;case 2:i=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";i=this.dataview.getUint8(this.position)<<16,i|=this.dataview.getUint8(this.position+1)<<8,i|=this.dataview.getUint8(this.position+2);break;case 4:i=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";i=this.dataview.getUint32(this.position)<<32,i|=this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+e}return this.position+=e,i}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="",i=0;i<e;i++)t+=String.fromCharCode(this.readUint8());return t}throw"Not enough bytes in buffer"},o.prototype.readCString=function(){for(var e=[];;){var t=this.readUint8();if(0===t)break;e.push(t)}return String.fromCharCode.apply(null,e)},o.prototype.readInt8=function(){return this.readAnyInt(1,!0)},o.prototype.readInt16=function(){return this.readAnyInt(2,!0)},o.prototype.readInt32=function(){return this.readAnyInt(4,!0)},o.prototype.readInt64=function(){return this.readAnyInt(8,!1)},o.prototype.readUint8Array=function(e){for(var t=new Uint8Array(e),i=0;i<e;i++)t[i]=this.readUint8();return t},o.prototype.readInt16Array=function(e){for(var t=new Int16Array(e),i=0;i<e;i++)t[i]=this.readInt16();return t},o.prototype.readUint16Array=function(e){for(var t=new Int16Array(e),i=0;i<e;i++)t[i]=this.readUint16();return t},o.prototype.readUint32Array=function(e){for(var t=new Uint32Array(e),i=0;i<e;i++)t[i]=this.readUint32();return t},o.prototype.readInt32Array=function(e){for(var t=new Int32Array(e),i=0;i<e;i++)t[i]=this.readInt32();return t},t.MP4BoxStream=o;var d=function(e,t,i){this._byteOffset=t||0,e instanceof ArrayBuffer?this.buffer=e:"object"==typeof e?(this.dataView=e,t&&(this._byteOffset+=t)):this.buffer=new ArrayBuffer(e||0),this.position=0,this.endianness=null==i?d.LITTLE_ENDIAN:i};d.prototype={},d.prototype.getPosition=function(){return this.position},d.prototype._realloc=function(e){if(this._dynamicSize){var t=this._byteOffset+this.position+e,i=this._buffer.byteLength;if(t<=i)t>this._byteLength&&(this._byteLength=t);else{for(i<1&&(i=1);t>i;)i*=2;var r=new ArrayBuffer(i),s=new Uint8Array(this._buffer);new Uint8Array(r,0,s.length).set(s),this.buffer=r,this._byteLength=t}}},d.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var e=new ArrayBuffer(this._byteLength),t=new Uint8Array(e),i=new Uint8Array(this._buffer,0,t.length);t.set(i),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 i=new Int32Array(e);return d.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,e*i.BYTES_PER_ELEMENT),d.arrayToNative(i,null==t?this.endianness:t),this.position+=i.byteLength,i},d.prototype.readInt16Array=function(e,t){e=null==e?this.byteLength-this.position/2:e;var i=new Int16Array(e);return d.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,e*i.BYTES_PER_ELEMENT),d.arrayToNative(i,null==t?this.endianness:t),this.position+=i.byteLength,i},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 i=new Uint32Array(e);return d.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,e*i.BYTES_PER_ELEMENT),d.arrayToNative(i,null==t?this.endianness:t),this.position+=i.byteLength,i},d.prototype.readUint16Array=function(e,t){e=null==e?this.byteLength-this.position/2:e;var i=new Uint16Array(e);return d.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,e*i.BYTES_PER_ELEMENT),d.arrayToNative(i,null==t?this.endianness:t),this.position+=i.byteLength,i},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 i=new Float64Array(e);return d.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,e*i.BYTES_PER_ELEMENT),d.arrayToNative(i,null==t?this.endianness:t),this.position+=i.byteLength,i},d.prototype.readFloat32Array=function(e,t){e=null==e?this.byteLength-this.position/4:e;var i=new Float32Array(e);return d.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,e*i.BYTES_PER_ELEMENT),d.arrayToNative(i,null==t?this.endianness:t),this.position+=i.byteLength,i},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,i,r,s){var a=new Uint8Array(e,t,s),n=new Uint8Array(i,r,s);a.set(n)},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),i=0;i<e.byteLength;i+=e.BYTES_PER_ELEMENT)for(var r=i+e.BYTES_PER_ELEMENT-1,s=i;r>s;r--,s++){var a=t[s];t[s]=t[r],t[r]=a}return e},d.prototype.failurePosition=0,String.fromCharCodeUint8=function(e){for(var t=[],i=0;i<e.length;i++)t[i]=e[i];return String.fromCharCode.apply(null,t)},d.prototype.readString=function(e,t){return null==t||"ASCII"==t?String.fromCharCodeUint8.apply(null,[this.mapUint8Array(null==e?this.byteLength-this.position:e)]):new TextDecoder(t).decode(this.mapUint8Array(e))},d.prototype.readCString=function(e){var t=this.byteLength-this.position,i=new Uint8Array(this._buffer,this._byteOffset+this.position),r=t;null!=e&&(r=Math.min(e,t));for(var s=0;s<r&&0!==i[s];s++);var a=String.fromCharCodeUint8.apply(null,[this.mapUint8Array(s)]);return null!=e?this.position+=r-s:s!=t&&(this.position+=1),a};var l=Math.pow(2,32);d.prototype.readInt64=function(){return this.readInt32()*l+this.readUint32()},d.prototype.readUint64=function(){return this.readUint32()*l+this.readUint32()},d.prototype.readInt64=function(){return this.readUint32()*l+this.readUint32()},d.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()},t.DataStream=d,d.prototype.save=function(e){var t=new Blob([this.buffer]);if(!window.URL||!URL.createObjectURL)throw"DataStream.save: Can't create object URL.";var i=window.URL.createObjectURL(t),r=document.createElement("a");document.body.appendChild(r),r.setAttribute("href",i),r.setAttribute("download",e),r.setAttribute("target","_self"),r.click(),window.URL.revokeObjectURL(i)},d.prototype._dynamicSize=!0,Object.defineProperty(d.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(e){e||this._trimAlloc(),this._dynamicSize=e}}),d.prototype.shift=function(e){var t=new ArrayBuffer(this._byteLength-e),i=new Uint8Array(t),r=new Uint8Array(this._buffer,e,i.length);i.set(r),this.buffer=t,this.position-=e},d.prototype.writeInt32Array=function(e,t){if(this._realloc(4*e.length),e instanceof Int32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapInt32Array(e.length,t);else for(var i=0;i<e.length;i++)this.writeInt32(e[i],t)},d.prototype.writeInt16Array=function(e,t){if(this._realloc(2*e.length),e instanceof Int16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapInt16Array(e.length,t);else for(var i=0;i<e.length;i++)this.writeInt16(e[i],t)},d.prototype.writeInt8Array=function(e){if(this._realloc(1*e.length),e instanceof Int8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapInt8Array(e.length);else for(var t=0;t<e.length;t++)this.writeInt8(e[t])},d.prototype.writeUint32Array=function(e,t){if(this._realloc(4*e.length),e instanceof Uint32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapUint32Array(e.length,t);else for(var i=0;i<e.length;i++)this.writeUint32(e[i],t)},d.prototype.writeUint16Array=function(e,t){if(this._realloc(2*e.length),e instanceof Uint16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapUint16Array(e.length,t);else for(var i=0;i<e.length;i++)this.writeUint16(e[i],t)},d.prototype.writeUint8Array=function(e){if(this._realloc(1*e.length),e instanceof Uint8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapUint8Array(e.length);else for(var t=0;t<e.length;t++)this.writeUint8(e[t])},d.prototype.writeFloat64Array=function(e,t){if(this._realloc(8*e.length),e instanceof Float64Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapFloat64Array(e.length,t);else for(var i=0;i<e.length;i++)this.writeFloat64(e[i],t)},d.prototype.writeFloat32Array=function(e,t){if(this._realloc(4*e.length),e instanceof Float32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0)d.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength),this.mapFloat32Array(e.length,t);else for(var i=0;i<e.length;i++)this.writeFloat32(e[i],t)},d.prototype.writeInt32=function(e,t){this._realloc(4),this._dataView.setInt32(this.position,e,null==t?this.endianness:t),this.position+=4},d.prototype.writeInt16=function(e,t){this._realloc(2),this._dataView.setInt16(this.position,e,null==t?this.endianness:t),this.position+=2},d.prototype.writeInt8=function(e){this._realloc(1),this._dataView.setInt8(this.position,e),this.position+=1},d.prototype.writeUint32=function(e,t){this._realloc(4),this._dataView.setUint32(this.position,e,null==t?this.endianness:t),this.position+=4},d.prototype.writeUint16=function(e,t){this._realloc(2),this._dataView.setUint16(this.position,e,null==t?this.endianness:t),this.position+=2},d.prototype.writeUint8=function(e){this._realloc(1),this._dataView.setUint8(this.position,e),this.position+=1},d.prototype.writeFloat32=function(e,t){this._realloc(4),this._dataView.setFloat32(this.position,e,null==t?this.endianness:t),this.position+=4},d.prototype.writeFloat64=function(e,t){this._realloc(8),this._dataView.setFloat64(this.position,e,null==t?this.endianness:t),this.position+=8},d.prototype.writeUCS2String=function(e,t,i){null==i&&(i=e.length);for(var r=0;r<e.length&&r<i;r++)this.writeUint16(e.charCodeAt(r),t);for(;r<i;r++)this.writeUint16(0)},d.prototype.writeString=function(e,t,i){var r=0;if(null==t||"ASCII"==t)if(null!=i){var s=Math.min(e.length,i);for(r=0;r<s;r++)this.writeUint8(e.charCodeAt(r));for(;r<i;r++)this.writeUint8(0)}else for(r=0;r<e.length;r++)this.writeUint8(e.charCodeAt(r));else this.writeUint8Array(new TextEncoder(t).encode(e.substring(0,i)))},d.prototype.writeCString=function(e,t){var i=0;if(null!=t){var r=Math.min(e.length,t);for(i=0;i<r;i++)this.writeUint8(e.charCodeAt(i));for(;i<t;i++)this.writeUint8(0)}else{for(i=0;i<e.length;i++)this.writeUint8(e.charCodeAt(i));this.writeUint8(0)}},d.prototype.writeStruct=function(e,t){for(var i=0;i<e.length;i+=2){var r=e[i+1];this.writeType(r,t[e[i]],t)}},d.prototype.writeType=function(e,t,i){var r;if("function"==typeof e)return e(this,t);if("object"==typeof e&&!(e instanceof Array))return e.set(this,t,i);var s=null,a="ASCII",n=this.position;switch("string"==typeof e&&/:/.test(e)&&(r=e.split(":"),e=r[0],s=parseInt(r[1])),"string"==typeof e&&/,/.test(e)&&(r=e.split(","),e=r[0],a=parseInt(r[1])),e){case"uint8":this.writeUint8(t);break;case"int8":this.writeInt8(t);break;case"uint16":this.writeUint16(t,this.endianness);break;case"int16":this.writeInt16(t,this.endianness);break;case"uint32":this.writeUint32(t,this.endianness);break;case"int32":this.writeInt32(t,this.endianness);break;case"float32":this.writeFloat32(t,this.endianness);break;case"float64":this.writeFloat64(t,this.endianness);break;case"uint16be":this.writeUint16(t,d.BIG_ENDIAN);break;case"int16be":this.writeInt16(t,d.BIG_ENDIAN);break;case"uint32be":this.writeUint32(t,d.BIG_ENDIAN);break;case"int32be":this.writeInt32(t,d.BIG_ENDIAN);break;case"float32be":this.writeFloat32(t,d.BIG_ENDIAN);break;case"float64be":this.writeFloat64(t,d.BIG_ENDIAN);break;case"uint16le":this.writeUint16(t,d.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(t,d.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(t,d.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(t,d.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(t,d.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(t,d.LITTLE_ENDIAN);break;case"cstring":this.writeCString(t,s);break;case"string":this.writeString(t,a,s);break;case"u16string":this.writeUCS2String(t,this.endianness,s);break;case"u16stringle":this.writeUCS2String(t,d.LITTLE_ENDIAN,s);break;case"u16stringbe":this.writeUCS2String(t,d.BIG_ENDIAN,s);break;default:if(3==e.length){for(var o=e[1],l=0;l<t.length;l++)this.writeType(o,t[l]);break}this.writeStruct(e,t)}null!=s&&(this.position=n,this._realloc(s),this.position=n+s)},d.prototype.writeUint64=function(e){var t=Math.floor(e/l);this.writeUint32(t),this.writeUint32(4294967295&e)},d.prototype.writeUint24=function(e){this.writeUint8((16711680&e)>>16),this.writeUint8((65280&e)>>8),this.writeUint8(255&e)},d.prototype.adjustUint32=function(e,t){var i=this.position;this.seek(e),this.writeUint32(t),this.seek(i)},d.prototype.mapInt32Array=function(e,t){this._realloc(4*e);var i=new Int32Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(i,null==t?this.endianness:t),this.position+=4*e,i},d.prototype.mapInt16Array=function(e,t){this._realloc(2*e);var i=new Int16Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(i,null==t?this.endianness:t),this.position+=2*e,i},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 i=new Uint32Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(i,null==t?this.endianness:t),this.position+=4*e,i},d.prototype.mapUint16Array=function(e,t){this._realloc(2*e);var i=new Uint16Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(i,null==t?this.endianness:t),this.position+=2*e,i},d.prototype.mapFloat64Array=function(e,t){this._realloc(8*e);var i=new Float64Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(i,null==t?this.endianness:t),this.position+=8*e,i},d.prototype.mapFloat32Array=function(e,t){this._realloc(4*e);var i=new Float32Array(this._buffer,this.byteOffset+this.position,e);return d.arrayToNative(i,null==t?this.endianness:t),this.position+=4*e,i};var c=function(e){this.buffers=[],this.bufferIndex=-1,e&&(this.insertBuffer(e),this.bufferIndex=0)};(c.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,n.debug("MultiBufferStream","Stream ready for parsing"),!0):(n.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1):(n.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1))},ArrayBuffer.concat=function(e,t){n.debug("ArrayBuffer","Trying to create a new buffer of size: "+(e.byteLength+t.byteLength));var i=new Uint8Array(e.byteLength+t.byteLength);return i.set(new Uint8Array(e),0),i.set(new Uint8Array(t),e.byteLength),i.buffer},c.prototype.reduceBuffer=function(e,t,i){var r;return(r=new Uint8Array(i)).set(new Uint8Array(e,t,i)),r.buffer.fileStart=e.fileStart+t,r.buffer.usedBytes=0,r.buffer},c.prototype.insertBuffer=function(e){for(var t=!0,i=0;i<this.buffers.length;i++){var r=this.buffers[i];if(e.fileStart<=r.fileStart){if(e.fileStart===r.fileStart){if(e.byteLength>r.byteLength){this.buffers.splice(i,1),i--;continue}n.warn("MultiBufferStream","Buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+") already appended, ignoring")}else e.fileStart+e.byteLength<=r.fileStart||(e=this.reduceBuffer(e,0,r.fileStart-e.fileStart)),n.debug("MultiBufferStream","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")"),this.buffers.splice(i,0,e),0===i&&(this.buffer=e);t=!1;break}if(e.fileStart<r.fileStart+r.byteLength){var s=r.fileStart+r.byteLength-e.fileStart,a=e.byteLength-s;if(!(a>0)){t=!1;break}e=this.reduceBuffer(e,s,a)}}t&&(n.debug("MultiBufferStream","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")"),this.buffers.push(e),0===i&&(this.buffer=e))},c.prototype.logBufferLevel=function(e){var t,i,r,s,a,o=[],d="";for(r=0,s=0,t=0;t<this.buffers.length;t++)i=this.buffers[t],0===t?(a={},o.push(a),a.start=i.fileStart,a.end=i.fileStart+i.byteLength,d+="["+a.start+"-"):a.end===i.fileStart?a.end=i.fileStart+i.byteLength:((a={}).start=i.fileStart,d+=o[o.length-1].end-1+"], ["+a.start+"-",a.end=i.fileStart+i.byteLength,o.push(a)),r+=i.usedBytes,s+=i.byteLength;o.length>0&&(d+=a.end-1+"]");var l=e?n.info:n.debug;0===this.buffers.length?l("MultiBufferStream","No more buffer in memory"):l("MultiBufferStream",this.buffers.length+" stored buffer(s) ("+r+"/"+s+" bytes), continuous ranges: "+d)},c.prototype.cleanBuffers=function(){var e,t;for(e=0;e<this.buffers.length;e++)(t=this.buffers[e]).usedBytes===t.byteLength&&(n.debug("MultiBufferStream","Removing buffer #"+e),this.buffers.splice(e,1),e--)},c.prototype.mergeNextBuffer=function(){var e;if(this.bufferIndex+1<this.buffers.length){if((e=this.buffers[this.bufferIndex+1]).fileStart===this.buffer.fileStart+this.buffer.byteLength){var t=this.buffer.byteLength,i=this.buffer.usedBytes,r=this.buffer.fileStart;return this.buffers[this.bufferIndex]=ArrayBuffer.concat(this.buffer,e),this.buffer=this.buffers[this.bufferIndex],this.buffers.splice(this.bufferIndex+1,1),this.buffer.usedBytes=i,this.buffer.fileStart=r,n.debug("ISOFile","Concatenating buffer for box parsing (length: "+t+"->"+this.buffer.byteLength+")"),!0}return!1}return!1},c.prototype.findPosition=function(e,t,i){var r,s=null,a=-1;for(r=!0===e?0:this.bufferIndex;r<this.buffers.length&&(s=this.buffers[r]).fileStart<=t;)a=r,i&&(s.fileStart+s.byteLength<=t?s.usedBytes=s.byteLength:s.usedBytes=t-s.fileStart,this.logBufferLevel()),r++;return-1!==a&&(s=this.buffers[a]).fileStart+s.byteLength>=t?(n.debug("MultiBufferStream","Found position in existing buffer #"+a),a):-1},c.prototype.findEndContiguousBuf=function(e){var t,i,r,s=void 0!==e?e:this.bufferIndex;if(i=this.buffers[s],this.buffers.length>s+1)for(t=s+1;t<this.buffers.length&&(r=this.buffers[t]).fileStart===i.fileStart+i.byteLength;t++)i=r;return i.fileStart+i.byteLength},c.prototype.getEndFilePositionAfter=function(e){var t=this.findPosition(!0,e,!1);return-1!==t?this.findEndContiguousBuf(t):e},c.prototype.addUsedBytes=function(e){this.buffer.usedBytes+=e,this.logBufferLevel()},c.prototype.setAllUsedBytes=function(){this.buffer.usedBytes=this.buffer.byteLength,this.logBufferLevel()},c.prototype.seek=function(e,t,i){var r;return-1!==(r=this.findPosition(t,e,i))?(this.buffer=this.buffers[r],this.bufferIndex=r,this.position=e-this.buffer.fileStart,n.debug("MultiBufferStream","Repositioning parser at buffer position: "+this.position),!0):(n.debug("MultiBufferStream","Position "+e+" not found in buffered data"),!1)},c.prototype.getPosition=function(){if(-1===this.bufferIndex||null===this.buffers[this.bufferIndex])throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.position},c.prototype.getLength=function(){return this.byteLength},c.prototype.getEndPosition=function(){if(-1===this.bufferIndex||null===this.buffers[this.bufferIndex])throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.byteLength},c.prototype.destroy=function(){this.buffers=[],this.bufferIndex},t.MultiBufferStream=c;var u=function(){var e=[];e[3]="ES_Descriptor",e[4]="DecoderConfigDescriptor",e[5]="DecoderSpecificInfo",e[6]="SLConfigDescriptor",this.getDescriptorName=function(t){return e[t]};var t=this,i={};return this.parseOneDescriptor=function(t){var r,s,a,o=0;for(r=t.readUint8(),a=t.readUint8();128&a;)o=(127&a)<<7,a=t.readUint8();return o+=127&a,n.debug("MPEG4DescriptorParser","Found "+(e[r]||"Descriptor "+r)+", size "+o+" at position "+t.getPosition()),(s=e[r]?new i[e[r]](o):new i.Descriptor(o)).parse(t),s},i.Descriptor=function(e,t){this.tag=e,this.size=t,this.descs=[]},i.Descriptor.prototype.parse=function(e){this.data=e.readUint8Array(this.size)},i.Descriptor.prototype.findDescriptor=function(e){for(var t=0;t<this.descs.length;t++)if(this.descs[t].tag==e)return this.descs[t];return null},i.Descriptor.prototype.parseRemainingDescriptors=function(e){for(var i=e.position;e.position<i+this.size;){var r=t.parseOneDescriptor(e);this.descs.push(r)}},i.ES_Descriptor=function(e){i.Descriptor.call(this,3,e)},i.ES_Descriptor.prototype=new i.Descriptor,i.ES_Descriptor.prototype.parse=function(e){if(this.ES_ID=e.readUint16(),this.flags=e.readUint8(),this.size-=3,128&this.flags?(this.dependsOn_ES_ID=e.readUint16(),this.size-=2):this.dependsOn_ES_ID=0,64&this.flags){var t=e.readUint8();this.URL=e.readString(t),this.size-=t+1}else this.URL="";32&this.flags?(this.OCR_ES_ID=e.readUint16(),this.size-=2):this.OCR_ES_ID=0,this.parseRemainingDescriptors(e)},i.ES_Descriptor.prototype.getOTI=function(e){var t=this.findDescriptor(4);return t?t.oti:0},i.ES_Descriptor.prototype.getAudioConfig=function(e){var t=this.findDescriptor(4);if(!t)return null;var i=t.findDescriptor(5);if(i&&i.data){var r=(248&i.data[0])>>3;return 31===r&&i.data.length>=2&&(r=32+((7&i.data[0])<<3)+((224&i.data[1])>>5)),r}return null},i.DecoderConfigDescriptor=function(e){i.Descriptor.call(this,4,e)},i.DecoderConfigDescriptor.prototype=new i.Descriptor,i.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)},i.DecoderSpecificInfo=function(e){i.Descriptor.call(this,5,e)},i.DecoderSpecificInfo.prototype=new i.Descriptor,i.SLConfigDescriptor=function(e){i.Descriptor.call(this,6,e)},i.SLConfigDescriptor.prototype=new i.Descriptor,this};t.MPEG4DescriptorParser=u;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,i){this.type=e,this.size=t,this.uuid=i},FullBox:function(e,t,i){h.Box.call(this,e,t,i),this.flags=0,this.version=0},ContainerBox:function(e,t,i){h.Box.call(this,e,t,i),this.boxes=[]},SampleEntry:function(e,t,i,r){h.ContainerBox.call(this,e,t),this.hdr_size=i,this.start=r},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,i=0;i<t;i++)this[e[i]+"s"]=[]}},createContainerBoxCtor:function(e,t,i){h[e+"Box"]=function(t){h.ContainerBox.call(this,e,t),h.addSubBoxArrays.call(this,i)},h[e+"Box"].prototype=new h.ContainerBox,t&&(h[e+"Box"].prototype.parse=t)},createMediaSampleEntryCtor:function(e,t,i){h.sampleEntryCodes[e]=[],h[e+"SampleEntry"]=function(e,t){h.SampleEntry.call(this,e,t),h.addSubBoxArrays.call(this,i)},h[e+"SampleEntry"].prototype=new h.SampleEntry,t&&(h[e+"SampleEntry"].prototype.parse=t)},createSampleEntryCtor:function(e,t,i,r){h.sampleEntryCodes[e].push(t),h[t+"SampleEntry"]=function(i){h[e+"SampleEntry"].call(this,t,i),h.addSubBoxArrays.call(this,r)},h[t+"SampleEntry"].prototype=new h[e+"SampleEntry"],i&&(h[t+"SampleEntry"].prototype.parse=i)},createEncryptedSampleEntryCtor:function(e,t,i){h.createSampleEntryCtor.call(this,e,t,i,["sinf"])},createSampleGroupCtor:function(e,t){h[e+"SampleGroupEntry"]=function(t){h.SampleGroupEntry.call(this,e,t)},h[e+"SampleGroupEntry"].prototype=new h.SampleGroupEntry,t&&(h[e+"SampleGroupEntry"].prototype.parse=t)},createTrackGroupCtor:function(e,t){h[e+"TrackGroupTypeBox"]=function(t){h.TrackGroupTypeBox.call(this,e,t)},h[e+"TrackGroupTypeBox"].prototype=new h.TrackGroupTypeBox,t&&(h[e+"TrackGroupTypeBox"].prototype.parse=t)},createUUIDBox:function(e,t,i,r){h.UUIDs.push(e),h.UUIDBoxes[e]=function(r){t?h.FullBox.call(this,"uuid",r,e):i?h.ContainerBox.call(this,"uuid",r,e):h.Box.call(this,"uuid",r,e)},h.UUIDBoxes[e].prototype=t?new h.FullBox:i?new h.ContainerBox:new h.Box,r&&(h.UUIDBoxes[e].prototype.parse=t?function(e){this.parseFullHeader(e),r&&r.call(this,e)}:r)}};function f(e,t){this.x=e,this.y=t}function p(e,t){this.bad_pixel_row=e,this.bad_pixel_column=t}h.initialize(),h.TKHD_FLAG_ENABLED=1,h.TKHD_FLAG_IN_MOVIE=2,h.TKHD_FLAG_IN_PREVIEW=4,h.TFHD_FLAG_BASE_DATA_OFFSET=1,h.TFHD_FLAG_SAMPLE_DESC=2,h.TFHD_FLAG_SAMPLE_DUR=8,h.TFHD_FLAG_SAMPLE_SIZE=16,h.TFHD_FLAG_SAMPLE_FLAGS=32,h.TFHD_FLAG_DUR_EMPTY=65536,h.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072,h.TRUN_FLAGS_DATA_OFFSET=1,h.TRUN_FLAGS_FIRST_FLAG=4,h.TRUN_FLAGS_DURATION=256,h.TRUN_FLAGS_SIZE=512,h.TRUN_FLAGS_FLAGS=1024,h.TRUN_FLAGS_CTS_OFFSET=2048,h.Box.prototype.add=function(e){return this.addBox(new h[e+"Box"])},h.Box.prototype.addBox=function(e){return this.boxes.push(e),this[e.type+"s"]?this[e.type+"s"].push(e):this[e.type]=e,e},h.Box.prototype.set=function(e,t){return this[e]=t,this},h.Box.prototype.addEntry=function(e,t){var i=t||"entries";return this[i]||(this[i]=[]),this[i].push(e),this},t.BoxParser=h,h.parseUUID=function(e){return h.parseHex16(e)},h.parseHex16=function(e){for(var t="",i=0;i<16;i++){var r=e.readUint8().toString(16);t+=1===r.length?"0"+r:r}return t},h.parseOneBox=function(e,t,i){var r,s,a,o=e.getPosition(),d=0;if(e.getEndPosition()-o<8)return n.debug("BoxParser","Not enough data in stream to parse the type and size of the box"),{code:h.ERR_NOT_ENOUGH_DATA};if(i&&i<8)return n.debug("BoxParser","Not enough bytes left in the parent box to parse a new box"),{code:h.ERR_NOT_ENOUGH_DATA};var l=e.readUint32(),c=e.readString(4),u=c;if(n.debug("BoxParser","Found box of type '"+c+"' and size "+l+" at position "+o),d=8,"uuid"==c){if(e.getEndPosition()-e.getPosition()<16||i-d<16)return e.seek(o),n.debug("BoxParser","Not enough bytes left in the parent box to parse a UUID box"),{code:h.ERR_NOT_ENOUGH_DATA};d+=16,u=a=h.parseUUID(e)}if(1==l){if(e.getEndPosition()-e.getPosition()<8||i&&i-d<8)return e.seek(o),n.warn("BoxParser",'Not enough data in stream to parse the extended size of the "'+c+'" box'),{code:h.ERR_NOT_ENOUGH_DATA};l=e.readUint64(),d+=8}else if(0===l)if(i)l=i;else if("mdat"!==c)return n.error("BoxParser","Unlimited box size not supported for type: '"+c+"'"),r=new h.Box(c,l),{code:h.OK,box:r,size:r.size};return 0!==l&&l<d?(n.error("BoxParser","Box of type "+c+" has an invalid size "+l+" (too small to be a box)"),{code:h.ERR_NOT_ENOUGH_DATA,type:c,size:l,hdr_size:d,start:o}):0!==l&&i&&l>i?(n.error("BoxParser","Box of type '"+c+"' has a size "+l+" greater than its container size "+i),{code:h.ERR_NOT_ENOUGH_DATA,type:c,size:l,hdr_size:d,start:o}):0!==l&&o+l>e.getEndPosition()?(e.seek(o),n.info("BoxParser","Not enough data in stream to parse the entire '"+c+"' box"),{code:h.ERR_NOT_ENOUGH_DATA,type:c,size:l,hdr_size:d,start:o}):t?{code:h.OK,type:c,size:l,hdr_size:d,start:o}:(h[c+"Box"]?r=new h[c+"Box"](l):"uuid"!==c?(n.warn("BoxParser","Unknown box type: '"+c+"'"),(r=new h.Box(c,l)).has_unparsed_data=!0):h.UUIDBoxes[a]?r=new h.UUIDBoxes[a](l):(n.warn("BoxParser","Unknown uuid type: '"+a+"'"),(r=new h.Box(c,l)).uuid=a,r.has_unparsed_data=!0),r.hdr_size=d,r.start=o,r.write===h.Box.prototype.write&&"mdat"!==r.type&&(n.info("BoxParser","'"+u+"' box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(e)),r.parse(e),(s=e.getPosition()-(r.start+r.size))<0?(n.warn("BoxParser","Parsing of box '"+u+"' did not read the entire indicated box data size (missing "+-s+" bytes), seeking forward"),e.seek(r.start+r.size)):s>0&&(n.error("BoxParser","Parsing of box '"+u+"' read "+s+" more bytes than the indicated box data size, seeking backwards"),0!==r.size&&e.seek(r.start+r.size)),{code:h.OK,box:r,size:r.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,i;e.getPosition()<this.start+this.size;){if((t=h.parseOneBox(e,!1,this.size-(e.getPosition()-this.start))).code!==h.OK)return;if(i=t.box,this.boxes.push(i),this.subBoxNames&&-1!=this.subBoxNames.indexOf(i.type))this[this.subBoxNames[this.subBoxNames.indexOf(i.type)]+"s"].push(i);else{var r="uuid"!==i.type?i.type:i.uuid;this[r]?n.warn("Box of type "+r+" already stored in field of this type"):this[r]=i}}},h.Box.prototype.parseLanguage=function(e){this.language=e.readUint16();var t=[];t[0]=this.language>>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 i=0;i<3;i++)this.layer_size[i]=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)n.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 n.error("av1C reserved_2 parsing problem");var i=this.size-this.hdr_size-4;this.configOBUs=e.readUint8Array(i)}else n.error("av1C reserved_1 parsing problem");else n.error("av1C version "+this.version+" not supported")})),h.createBoxCtor("avcC",(function(e){var t,i;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(),i=this.size-this.hdr_size-6,this.SPS=[],t=0;t<this.nb_SPS_nalus;t++)this.SPS[t]={},this.SPS[t].length=e.readUint16(),this.SPS[t].nalu=e.readUint8Array(this.SPS[t].length),i-=2+this.SPS[t].length;for(this.nb_PPS_nalus=e.readUint8(),i--,this.PPS=[],t=0;t<this.nb_PPS_nalus;t++)this.PPS[t]={},this.PPS[t].length=e.readUint16(),this.PPS[t].nalu=e.readUint8Array(this.PPS[t].length),i-=2+this.PPS[t].length;i>0&&(this.ext=e.readUint8Array(i))})),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<this.channel_count;t++)this.channel_indexes.push(e.readUint16()),this.channel_types.push(e.readUint16()),this.channel_associations.push(e.readUint16())})),h.createBoxCtor("clap",(function(e){this.cleanApertureWidthN=e.readUint32(),this.cleanApertureWidthD=e.readUint32(),this.cleanApertureHeightN=e.readUint32(),this.cleanApertureHeightD=e.readUint32(),this.horizOffN=e.readUint32(),this.horizOffD=e.readUint32(),this.vertOffN=e.readUint32(),this.vertOffD=e.readUint32()})),h.createBoxCtor("clli",(function(e){this.max_content_light_level=e.readUint16(),this.max_pic_average_light_level=e.readUint16()})),h.createFullBoxCtor("cmex",(function(e){1&this.flags&&(this.pos_x=e.readInt32()),2&this.flags&&(this.pos_y=e.readInt32()),4&this.flags&&(this.pos_z=e.readInt32()),8&this.flags&&(0==this.version?16&this.flags?(this.quat_x=e.readInt32(),this.quat_y=e.readInt32(),this.quat_z=e.readInt32()):(this.quat_x=e.readInt16(),this.quat_y=e.readInt16(),this.quat_z=e.readInt16()):this.version),32&this.flags&&(this.id=e.readUint32())})),h.createFullBoxCtor("cmin",(function(e){this.focal_length_x=e.readInt32(),this.principal_point_x=e.readInt32(),this.principal_point_y=e.readInt32(),1&this.flags&&(this.focal_length_y=e.readInt32(),this.skew_factor=e.readInt32())})),h.createBoxCtor("cmpd",(function(e){for(this.component_count=e.readUint32(),this.component_types=[],this.component_type_urls=[],i=0;i<this.component_count;i++){var t=e.readUint16();this.component_types.push(t),t>=32768&&this.component_type_urls.push(e.readCString())}})),h.createFullBoxCtor("co64",(function(e){var t,i;if(t=e.readUint32(),this.chunk_offsets=[],0===this.version)for(i=0;i<t;i++)this.chunk_offsets.push(e.readUint64())})),h.createFullBoxCtor("CoLL",(function(e){this.maxCLL=e.readUint16(),this.maxFALL=e.readUint16()})),h.createBoxCtor("colr",(function(e){if(this.colour_type=e.readString(4),"nclx"===this.colour_type){this.colour_primaries=e.readUint16(),this.transfer_characteristics=e.readUint16(),this.matrix_coefficients=e.readUint16();var t=e.readUint8();this.full_range_flag=t>>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,i;if(t=e.readUint32(),this.sample_counts=[],this.sample_offsets=[],0===this.version)for(i=0;i<t;i++){this.sample_counts.push(e.readUint32());var r=e.readInt32();r<0&&n.warn("BoxParser","ctts box uses negative values without using version 1"),this.sample_offsets.push(r)}else if(1==this.version)for(i=0;i<t;i++)this.sample_counts.push(e.readUint32()),this.sample_offsets.push(e.readInt32())})),h.createBoxCtor("dac3",(function(e){var t=e.readUint8(),i=e.readUint8(),r=e.readUint8();this.fscod=t>>6,this.bsid=t>>1&31,this.bsmod=(1&t)<<2|i>>6&3,this.acmod=i>>3&7,this.lfeon=i>>2&1,this.bit_rate_code=3&i|r>>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 i=0;i<this.num_ind_sub+1;i++){var r={};this.ind_subs.push(r);var s=e.readUint8(),a=e.readUint8(),n=e.readUint8();r.fscod=s>>6,r.bsid=s>>1&31,r.bsmod=(1&s)<<4|a>>4&15,r.acmod=a>>1&7,r.lfeon=1&a,r.num_dep_sub=n>>1&15,r.num_dep_sub>0&&(r.chan_loc=(1&n)<<8|e.readUint8())}})),h.createFullBoxCtor("dfLa",(function(e){var t=[],i=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];for(this.parseFullHeader(e);;){var r=e.readUint8(),s=Math.min(127&r,i.length-1);if(s?e.readUint8Array(e.readUint24()):(e.readUint8Array(13),this.samplerate=e.readUint32()>>12,e.readUint8Array(20)),t.push(i[s]),128&r)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<this.OutputChannelCount;t++)this.ChannelMapping[t]=e.readUint8()}})),h.createFullBoxCtor("dref",(function(e){var t,i;this.entries=[];for(var r=e.readUint32(),s=0;s<r;s++){if((t=h.parseOneBox(e,!1,this.size-(e.getPosition()-this.start))).code!==h.OK)return;i=t.box,this.entries.push(i)}})),h.createBoxCtor("drep",(function(e){this.bytessent=e.readUint64()})),h.createFullBoxCtor("elng",(function(e){this.extended_language=e.readString(this.size-this.hdr_size)})),h.createFullBoxCtor("elst",(function(e){this.entries=[];for(var t=e.readUint32(),i=0;i<t;i++){var r={};this.entries.push(r),1===this.version?(r.segment_duration=e.readUint64(),r.media_time=e.readInt64()):(r.segment_duration=e.readUint32(),r.media_time=e.readInt32()),r.media_rate_integer=e.readInt16(),r.media_rate_fraction=e.readInt16()}})),h.createFullBoxCtor("emsg",(function(e){1==this.version?(this.timescale=e.readUint32(),this.presentation_time=e.readUint64(),this.event_duration=e.readUint32(),this.id=e.readUint32(),this.scheme_id_uri=e.readCString(),this.value=e.readCString()):(this.scheme_id_uri=e.readCString(),this.value=e.readCString(),this.timescale=e.readUint32(),this.presentation_time_delta=e.readUint32(),this.event_duration=e.readUint32(),this.id=e.readUint32());var t=this.size-this.hdr_size-(16+(this.scheme_id_uri.length+1)+(this.value.length+1));1==this.version&&(t-=4),this.message_data=e.readUint8Array(t)})),h.createEntityToGroupCtor=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){if(this.parseFullHeader(e),t)t.call(this,e);else for(this.group_id=e.readUint32(),this.num_entities_in_group=e.readUint32(),this.entity_ids=[],i=0;i<this.num_entities_in_group;i++){var r=e.readUint32();this.entity_ids.push(r)}}},h.createEntityToGroupCtor("aebr"),h.createEntityToGroupCtor("afbr"),h.createEntityToGroupCtor("albc"),h.createEntityToGroupCtor("altr"),h.createEntityToGroupCtor("brst"),h.createEntityToGroupCtor("dobr"),h.createEntityToGroupCtor("eqiv"),h.createEntityToGroupCtor("favc"),h.createEntityToGroupCtor("fobr"),h.createEntityToGroupCtor("iaug"),h.createEntityToGroupCtor("pano"),h.createEntityToGroupCtor("slid"),h.createEntityToGroupCtor("ster"),h.createEntityToGroupCtor("tsyn"),h.createEntityToGroupCtor("wbbr"),h.createEntityToGroupCtor("prgr"),h.createFullBoxCtor("esds",(function(e){var t=e.readUint8Array(this.size-this.hdr_size),i=new u;this.esd=i.parseOneDescriptor(new d(t.buffer,0,d.BIG_ENDIAN))})),h.createBoxCtor("fiel",(function(e){this.fieldCount=e.readUint8(),this.fieldOrdering=e.readUint8()})),h.createBoxCtor("frma",(function(e){this.data_format=e.readString(4)})),h.createBoxCtor("ftyp",(function(e){var t=this.size-this.hdr_size;this.major_brand=e.readString(4),this.minor_version=e.readUint32(),t-=8,this.compatible_brands=[];for(var i=0;t>=4;)this.compatible_brands[i]=e.readString(4),t-=4,i++})),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,i,r,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 a=e.readUint8();for(t=0;t<a;t++){var n=[];this.nalu_arrays.push(n),s=e.readUint8(),n.completeness=(128&s)>>7,n.nalu_type=63&s;var o=e.readUint16();for(i=0;i<o;i++){var d={};n.push(d),r=e.readUint16(),d.data=e.readUint8Array(r)}}})),h.createFullBoxCtor("iinf",(function(e){var t;0===this.version?this.entry_count=e.readUint16():this.entry_count=e.readUint32(),this.item_infos=[];for(var i=0;i<this.entry_count;i++){if((t=h.parseOneBox(e,!1,this.size-(e.getPosition()-this.start))).code!==h.OK)return;"infe"!==t.box.type&&n.error("BoxParser","Expected 'infe' box, got "+t.box.type),this.item_infos[i]=t.box}})),h.createFullBoxCtor("iloc",(function(e){var t;t=e.readUint8(),this.offset_size=t>>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 i=0;if(this.version<2)i=e.readUint16();else{if(2!==this.version)throw"version of iloc box not supported";i=e.readUint32()}for(var r=0;r<i;r++){var s={};if(this.items.push(s),this.version<2)s.item_ID=e.readUint16();else{if(2!==this.version)throw"version of iloc box not supported";s.item_ID=e.readUint32()}switch(1===this.version||2===this.version?s.construction_method=15&e.readUint16():s.construction_method=0,s.data_reference_index=e.readUint16(),this.base_offset_size){case 0:s.base_offset=0;break;case 4:s.base_offset=e.readUint32();break;case 8:s.base_offset=e.readUint64();break;default:throw"Error reading base offset size"}var a=e.readUint16();s.extents=[];for(var n=0;n<a;n++){var o={};if(s.extents.push(o),1===this.version||2===this.version)switch(this.index_size){case 0:o.extent_index=0;break;case 4:o.extent_index=e.readUint32();break;case 8:o.extent_index=e.readUint64();break;default:throw"Error reading extent index"}switch(this.offset_size){case 0:o.extent_offset=0;break;case 4:o.extent_offset=e.readUint32();break;case 8:o.extent_offset=e.readUint64();break;default:throw"Error reading extent index"}switch(this.length_size){case 0:o.extent_length=0;break;case 4:o.extent_length=e.readUint32();break;case 8:o.extent_length=e.readUint64();break;default:throw"Error reading extent index"}}}})),h.createBoxCtor("imir",(function(e){var t=e.readUint8();this.reserved=t>>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),n.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,i;for(entry_count=e.readUint32(),this.associations=[],t=0;t<entry_count;t++){var r={};this.associations.push(r),this.version<1?r.id=e.readUint16():r.id=e.readUint32();var s=e.readUint8();for(r.props=[],i=0;i<s;i++){var a=e.readUint8(),n={};r.props.push(n),n.essential=(128&a)>>7==1,1&this.flags?n.property_index=(127&a)<<8|e.readUint8():n.property_index=127&a}}})),h.createFullBoxCtor("iref",(function(e){var t,i;for(this.references=[];e.getPosition()<this.start+this.size;){if((t=h.parseOneBox(e,!0,this.size-(e.getPosition()-this.start))).code!==h.OK)return;(i=0===this.version?new h.SingleItemTypeReferenceBox(t.type,t.size,t.hdr_size,t.start):new h.SingleItemTypeReferenceBoxLarge(t.type,t.size,t.hdr_size,t.start)).write===h.Box.prototype.write&&"mdat"!==i.type&&(n.warn("BoxParser",i.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),i.parseDataAndRewind(e)),i.parse(e),this.references.push(i)}})),h.createBoxCtor("irot",(function(e){this.angle=3&e.readUint8()})),h.createFullBoxCtor("ispe",(function(e){this.image_width=e.readUint32(),this.image_height=e.readUint32()})),h.createFullBoxCtor("kind",(function(e){this.schemeURI=e.readCString(),this.value=e.readCString()})),h.createFullBoxCtor("leva",(function(e){var t=e.readUint8();this.levels=[];for(var i=0;i<t;i++){var r={};this.levels[i]=r,r.track_ID=e.readUint32();var s=e.readUint8();switch(r.padding_flag=s>>7,r.assignment_type=127&s,r.assignment_type){case 0:r.grouping_type=e.readString(4);break;case 1:r.grouping_type=e.readString(4),r.grouping_type_parameter=e.readUint32();break;case 2:case 3:break;case 4:r.sub_track_id=e.readUint32();break;default:n.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&&(n.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 i=0;i<Math.floor((t+1)/2);i++)this.padbits=e.readUint8()})),h.createBoxCtor("pasp",(function(e){this.hSpacing=e.readUint32(),this.vSpacing=e.readUint32()})),h.createBoxCtor("payl",(function(e){this.text=e.readString(this.size-this.hdr_size)})),h.createBoxCtor("payt",(function(e){this.payloadID=e.readUint32();var t=e.readUint8();this.rtpmap_string=e.readString(t)})),h.createFullBoxCtor("pdin",(function(e){var t=(this.size-this.hdr_size)/8;this.rate=[],this.initial_delay=[];for(var i=0;i<t;i++)this.rate[i]=e.readUint32(),this.initial_delay[i]=e.readUint32()})),h.createFullBoxCtor("pitm",(function(e){0===this.version?this.item_id=e.readUint16():this.item_id=e.readUint32()})),h.createFullBoxCtor("pixi",(function(e){var t;for(this.num_channels=e.readUint8(),this.bits_per_channels=[],t=0;t<this.num_channels;t++)this.bits_per_channels[t]=e.readUint8()})),h.createBoxCtor("pmax",(function(e){this.bytes=e.readUint32()})),h.createFullBoxCtor("prdi",(function(e){if(this.step_count=e.readUint16(),this.item_count=[],2&this.flags)for(var t=0;t<this.step_count;t++)this.item_count[t]=e.readUint16()})),h.createFullBoxCtor("prft",(function(e){this.ref_track_id=e.readUint32(),this.ntp_timestamp=e.readUint64(),0===this.version?this.media_time=e.readUint32():this.media_time=e.readUint64()})),h.createFullBoxCtor("pssh",(function(e){if(this.system_id=h.parseHex16(e),this.version>0){var t=e.readUint32();this.kid=[];for(var i=0;i<t;i++)this.kid[i]=h.parseHex16(e)}var r=e.readUint32();r>0&&(this.data=e.readUint8Array(r))})),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 i=0;i<t;i++)0===this.version?this.offset[i]=e.readUint32():this.offset[i]=e.readUint64()})),h.createFullBoxCtor("saiz",(function(e){1&this.flags&&(this.aux_info_type=e.readUint32(),this.aux_info_type_parameter=e.readUint32()),this.default_sample_info_size=e.readUint8();var t=e.readUint32();if(this.sample_info_size=[],0===this.default_sample_info_size)for(var i=0;i<t;i++)this.sample_info_size[i]=e.readUint8()})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_METADATA,"mett",(function(e){this.parseHeader(e),this.content_encoding=e.readCString(),this.mime_format=e.readCString(),this.parseFooter(e)})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_METADATA,"metx",(function(e){this.parseHeader(e),this.content_encoding=e.readCString(),this.namespace=e.readCString(),this.schema_location=e.readCString(),this.parseFooter(e)})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SUBTITLE,"sbtt",(function(e){this.parseHeader(e),this.content_encoding=e.readCString(),this.mime_format=e.readCString(),this.parseFooter(e)})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SUBTITLE,"stpp",(function(e){this.parseHeader(e),this.namespace=e.readCString(),this.schema_location=e.readCString(),this.auxiliary_mime_types=e.readCString(),this.parseFooter(e)})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SUBTITLE,"stxt",(function(e){this.parseHeader(e),this.content_encoding=e.readCString(),this.mime_format=e.readCString(),this.parseFooter(e)})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_SUBTITLE,"tx3g",(function(e){this.parseHeader(e),this.displayFlags=e.readUint32(),this.horizontal_justification=e.readInt8(),this.vertical_justification=e.readInt8(),this.bg_color_rgba=e.readUint8Array(4),this.box_record=e.readInt16Array(4),this.style_record=e.readUint8Array(12),this.parseFooter(e)})),h.createSampleEntryCtor(h.SAMPLE_ENTRY_TYPE_METADATA,"wvtt",(function(e){this.parseHeader(e),this.parseFooter(e)})),h.createSampleGroupCtor("alst",(function(e){var t,i=e.readUint16();for(this.first_output_sample=e.readUint16(),this.sample_offset=[],t=0;t<i;t++)this.sample_offset[t]=e.readUint32();var r=this.description_length-4-4*i;for(this.num_output_samples=[],this.num_total_samples=[],t=0;t<r/4;t++)this.num_output_samples[t]=e.readUint16(),this.num_total_samples[t]=e.readUint16()})),h.createSampleGroupCtor("avll",(function(e){this.layerNumber=e.readUint8(),this.accurateStatisticsFlag=e.readUint8(),this.avgBitRate=e.readUint16(),this.avgFrameRate=e.readUint16()})),h.createSampleGroupCtor("avss",(function(e){this.subSequenceIdentifier=e.readUint16(),this.layerNumber=e.readUint8();var t=e.readUint8();this.durationFlag=t>>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 i=e.readUint8(),r=0;r<i;r++){var s={};this.dependency.push(s),s.subSeqDirectionFlag=e.readUint8(),s.layerNumber=e.readUint8(),s.subSequenceIdentifier=e.readUint16()}})),h.createSampleGroupCtor("dtrt",(function(e){n.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("mvif",(function(e){n.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("prol",(function(e){this.roll_distance=e.readInt16()})),h.createSampleGroupCtor("rap ",(function(e){var t=e.readUint8();this.num_leading_samples_known=t>>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)n.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<this.operation_point_count;t++)this.available_bitrate[t]=e.readUint32(),this.target_rate_share[t]=e.readUint16()}this.maximum_bitrate=e.readUint32(),this.minimum_bitrate=e.readUint32(),this.discard_priority=e.readUint8()}})),h.createSampleGroupCtor("roll",(function(e){this.roll_distance=e.readInt16()})),h.SampleGroupEntry.prototype.parse=function(e){n.warn("BoxParser","Unknown Sample Group type: "+this.grouping_type),this.data=e.readUint8Array(this.description_length)},h.createSampleGroupCtor("scif",(function(e){n.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("scnm",(function(e){n.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("seig",(function(e){this.reserved=e.readUint8();var t=e.readUint8();this.crypt_byte_block=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){n.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){n.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("tscl",(function(e){n.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")})),h.createSampleGroupCtor("vipr",(function(e){n.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(),i=0;i<t;i++){var r={};this.entries.push(r),r.sample_count=e.readInt32(),r.group_description_index=e.readInt32()}})),p.prototype.toString=function(){return"[row: "+this.bad_pixel_row+", column: "+this.bad_pixel_column+"]"},h.createFullBoxCtor("sbpm",(function(e){var t;for(this.component_count=e.readUint16(),this.component_index=[],t=0;t<this.component_count;t++)this.component_index.push(e.readUint16());var i=e.readUint8();for(this.correction_applied=128==(128&i),this.num_bad_rows=e.readUint32(),this.num_bad_cols=e.readUint32(),this.num_bad_pixels=e.readUint32(),this.bad_rows=[],this.bad_columns=[],this.bad_pixels=[],t=0;t<this.num_bad_rows;t++)this.bad_rows.push(e.readUint32());for(t=0;t<this.num_bad_cols;t++)this.bad_columns.push(e.readUint32());for(t=0;t<this.num_bad_pixels;t++){var r=e.readUint32(),s=e.readUint32();this.bad_pixels.push(new p(r,s))}})),h.createFullBoxCtor("schm",(function(e){this.scheme_type=e.readString(4),this.scheme_version=e.readUint32(),1&this.flags&&(this.scheme_uri=e.readString(this.size-this.hdr_size-8))})),h.createBoxCtor("sdp ",(function(e){this.sdptext=e.readString(this.size-this.hdr_size)})),h.createFullBoxCtor("sdtp",(function(e){var t,i=this.size-this.hdr_size;this.is_leading=[],this.sample_depends_on=[],this.sample_is_depended_on=[],this.sample_has_redundancy=[];for(var r=0;r<i;r++)t=e.readUint8(),this.is_leading[r]=t>>6,this.sample_depends_on[r]=t>>4&3,this.sample_is_depended_on[r]=t>>2&3,this.sample_has_redundancy[r]=3&t})),h.createFullBoxCtor("senc"),h.createFullBoxCtor("sgpd",(function(e){this.grouping_type=e.readString(4),n.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(),i=0;i<t;i++){var r;r=h[this.grouping_type+"SampleGroupEntry"]?new h[this.grouping_type+"SampleGroupEntry"](this.grouping_type):new h.SampleGroupEntry(this.grouping_type),this.entries.push(r),1===this.version&&0===this.default_length?r.description_length=e.readUint32():r.description_length=this.default_length,r.write===h.SampleGroupEntry.prototype.write&&(n.info("BoxParser","SampleGroup for type "+this.grouping_type+" writing not yet implemented, keeping unparsed data in memory for later write"),r.data=e.readUint8Array(r.description_length),e.position-=r.description_length),r.parse(e)}})),h.createFullBoxCtor("sidx",(function(e){this.reference_ID=e.readUint32(),this.timescale=e.readUint32(),0===this.version?(this.earliest_presentation_time=e.readUint32(),this.first_offset=e.readUint32()):(this.earliest_presentation_time=e.readUint64(),this.first_offset=e.readUint64()),e.readUint16(),this.references=[];for(var t=e.readUint16(),i=0;i<t;i++){var r={};this.references.push(r);var s=e.readUint32();r.reference_type=s>>31&1,r.referenced_size=2147483647&s,r.subsegment_duration=e.readUint32(),s=e.readUint32(),r.starts_with_SAP=s>>31&1,r.SAP_type=s>>28&7,r.SAP_delta_time=268435455&s}})),h.SingleItemTypeReferenceBox=function(e,t,i,r){h.Box.call(this,e,t),this.hdr_size=i,this.start=r},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 i=0;i<t;i++)this.references[i]={},this.references[i].to_item_ID=e.readUint16()},h.SingleItemTypeReferenceBoxLarge=function(e,t,i,r){h.Box.call(this,e,t),this.hdr_size=i,this.start=r},h.SingleItemTypeReferenceBoxLarge.prototype=new h.Box,h.SingleItemTypeReferenceBoxLarge.prototype.parse=function(e){this.from_item_ID=e.readUint32();var t=e.readUint16();this.references=[];for(var i=0;i<t;i++)this.references[i]={},this.references[i].to_item_ID=e.readUint32()},h.createFullBoxCtor("SmDm",(function(e){this.primaryRChromaticity_x=e.readUint16(),this.primaryRChromaticity_y=e.readUint16(),this.primaryGChromaticity_x=e.readUint16(),this.primaryGChromaticity_y=e.readUint16(),this.primaryBChromaticity_x=e.readUint16(),this.primaryBChromaticity_y=e.readUint16(),this.whitePointChromaticity_x=e.readUint16(),this.whitePointChromaticity_y=e.readUint16(),this.luminanceMax=e.readUint32(),this.luminanceMin=e.readUint32()})),h.createFullBoxCtor("smhd",(function(e){this.balance=e.readUint16(),e.readUint16()})),h.createFullBoxCtor("ssix",(function(e){this.subsegments=[];for(var t=e.readUint32(),i=0;i<t;i++){var r={};this.subsegments.push(r),r.ranges=[];for(var s=e.readUint32(),a=0;a<s;a++){var n={};r.ranges.push(n),n.level=e.readUint8(),n.range_size=e.readUint24()}}})),h.createFullBoxCtor("stco",(function(e){var t;if(t=e.readUint32(),this.chunk_offsets=[],0===this.version)for(var i=0;i<t;i++)this.chunk_offsets.push(e.readUint32())})),h.createFullBoxCtor("stdp",(function(e){var t=(this.size-this.hdr_size)/2;this.priority=[];for(var i=0;i<t;i++)this.priority[i]=e.readUint16()})),h.createFullBoxCtor("sthd"),h.createFullBoxCtor("stri",(function(e){this.switch_group=e.readUint16(),this.alternate_group=e.readUint16(),this.sub_track_id=e.readUint32();var t=(this.size-this.hdr_size-8)/4;this.attribute_list=[];for(var i=0;i<t;i++)this.attribute_list[i]=e.readUint32()})),h.createFullBoxCtor("stsc",(function(e){var t,i;if(t=e.readUint32(),this.first_chunk=[],this.samples_per_chunk=[],this.sample_description_index=[],0===this.version)for(i=0;i<t;i++)this.first_chunk.push(e.readUint32()),this.samples_per_chunk.push(e.readUint32()),this.sample_description_index.push(e.readUint32())})),h.createFullBoxCtor("stsd",(function(e){var t,i,r,s;for(this.entries=[],r=e.readUint32(),t=1;t<=r;t++){if((i=h.parseOneBox(e,!0,this.size-(e.getPosition()-this.start))).code!==h.OK)return;h[i.type+"SampleEntry"]?((s=new h[i.type+"SampleEntry"](i.size)).hdr_size=i.hdr_size,s.start=i.start):(n.warn("BoxParser","Unknown sample entry type: "+i.type),s=new h.SampleEntry(i.type,i.size,i.hdr_size,i.start)),s.write===h.SampleEntry.prototype.write&&(n.info("BoxParser","SampleEntry "+s.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),s.parseDataAndRewind(e)),s.parse(e),this.entries.push(s)}})),h.createFullBoxCtor("stsg",(function(e){this.grouping_type=e.readUint32();var t=e.readUint16();this.group_description_index=[];for(var i=0;i<t;i++)this.group_description_index[i]=e.readUint32()})),h.createFullBoxCtor("stsh",(function(e){var t,i;if(t=e.readUint32(),this.shadowed_sample_numbers=[],this.sync_sample_numbers=[],0===this.version)for(i=0;i<t;i++)this.shadowed_sample_numbers.push(e.readUint32()),this.sync_sample_numbers.push(e.readUint32())})),h.createFullBoxCtor("stss",(function(e){var t,i;if(i=e.readUint32(),0===this.version)for(this.sample_numbers=[],t=0;t<i;t++)this.sample_numbers.push(e.readUint32())})),h.createFullBoxCtor("stsz",(function(e){var t;if(this.sample_sizes=[],0===this.version)for(this.sample_size=e.readUint32(),this.sample_count=e.readUint32(),t=0;t<this.sample_count;t++)0===this.sample_size?this.sample_sizes.push(e.readUint32()):this.sample_sizes[t]=this.sample_size})),h.createFullBoxCtor("stts",(function(e){var t,i,r;if(t=e.readUint32(),this.sample_counts=[],this.sample_deltas=[],0===this.version)for(i=0;i<t;i++)this.sample_counts.push(e.readUint32()),(r=e.readInt32())<0&&(n.warn("BoxParser","File uses negative stts sample delta, using value 1 instead, sync may be lost!"),r=1),this.sample_deltas.push(r)})),h.createFullBoxCtor("stvi",(function(e){var t=e.readUint32();this.single_view_allowed=3&t,this.stereo_scheme=e.readUint32();var i,r,s=e.readUint32();for(this.stereo_indication_type=e.readString(s),this.boxes=[];e.getPosition()<this.start+this.size;){if((i=h.parseOneBox(e,!1,this.size-(e.getPosition()-this.start))).code!==h.OK)return;r=i.box,this.boxes.push(r),this[r.type]=r}})),h.createBoxCtor("styp",(function(e){h.ftypBox.prototype.parse.call(this,e)})),h.createFullBoxCtor("stz2",(function(e){var t,i;if(this.sample_sizes=[],0===this.version)if(this.reserved=e.readUint24(),this.field_size=e.readUint8(),i=e.readUint32(),4===this.field_size)for(t=0;t<i;t+=2){var r=e.readUint8();this.sample_sizes[t]=r>>4&15,this.sample_sizes[t+1]=15&r}else if(8===this.field_size)for(t=0;t<i;t++)this.sample_sizes[t]=e.readUint8();else if(16===this.field_size)for(t=0;t<i;t++)this.sample_sizes[t]=e.readUint16();else n.error("BoxParser","Error in length field in stz2 box")})),h.createFullBoxCtor("subs",(function(e){var t,i,r,s;for(r=e.readUint32(),this.entries=[],t=0;t<r;t++){var a={};if(this.entries[t]=a,a.sample_delta=e.readUint32(),a.subsamples=[],(s=e.readUint16())>0)for(i=0;i<s;i++){var n={};a.subsamples.push(n),1==this.version?n.size=e.readUint32():n.size=e.readUint16(),n.priority=e.readUint8(),n.discardable=e.readUint8(),n.codec_specific_parameters=e.readUint32()}}})),h.createFullBoxCtor("tenc",(function(e){if(e.readUint8(),0===this.version)e.readUint8();else{var t=e.readUint8();this.default_crypt_byte_block=t>>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 i=e.readUint32(),r=0;r<i;r++)1===this.version?(this.time=e.readUint64(),this.moof_offset=e.readUint64()):(this.time=e.readUint32(),this.moof_offset=e.readUint32()),this.traf_number=e["readUint"+8*(this.length_size_of_traf_num+1)](),this.trun_number=e["readUint"+8*(this.length_size_of_trun_num+1)](),this.sample_number=e["readUint"+8*(this.length_size_of_sample_num+1)]()})),h.createFullBoxCtor("tkhd",(function(e){1==this.version?(this.creation_time=e.readUint64(),this.modification_time=e.readUint64(),this.track_id=e.readUint32(),e.readUint32(),this.duration=e.readUint64()):(this.creation_time=e.readUint32(),this.modification_time=e.readUint32(),this.track_id=e.readUint32(),e.readUint32(),this.duration=e.readUint32()),e.readUint32Array(2),this.layer=e.readInt16(),this.alternate_group=e.readInt16(),this.volume=e.readInt16()>>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,i,r){h.Box.call(this,e,t),this.hdr_size=i,this.start=r},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,i;e.getPosition()<this.start+this.size;){if((t=h.parseOneBox(e,!0,this.size-(e.getPosition()-this.start))).code!==h.OK)return;(i=new h.TrackReferenceTypeBox(t.type,t.size,t.hdr_size,t.start)).write===h.Box.prototype.write&&"mdat"!==i.type&&(n.info("BoxParser","TrackReference "+i.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),i.parseDataAndRewind(e)),i.parse(e),this.boxes.push(i)}},h.createFullBoxCtor("trep",(function(e){for(this.track_ID=e.readUint32(),this.boxes=[];e.getPosition()<this.start+this.size;){if(ret=h.parseOneBox(e,!1,this.size-(e.getPosition()-this.start)),ret.code!==h.OK)return;box=ret.box,this.boxes.push(box)}})),h.createFullBoxCtor("trex",(function(e){this.track_id=e.readUint32(),this.default_sample_description_index=e.readUint32(),this.default_sample_duration=e.readUint32(),this.default_sample_size=e.readUint32(),this.default_sample_flags=e.readUint32()})),h.createBoxCtor("trpy",(function(e){this.bytessent=e.readUint64()})),h.createFullBoxCtor("trun",(function(e){var t=0;if(this.sample_count=e.readUint32(),t+=4,this.size-this.hdr_size>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 i=0;i<this.sample_count;i++)this.flags&h.TRUN_FLAGS_DURATION&&(this.sample_duration[i]=e.readUint32()),this.flags&h.TRUN_FLAGS_SIZE&&(this.sample_size[i]=e.readUint32()),this.flags&h.TRUN_FLAGS_FLAGS&&(this.sample_flags[i]=e.readUint32()),this.flags&h.TRUN_FLAGS_CTS_OFFSET&&(0===this.version?this.sample_composition_time_offset[i]=e.readUint32():this.sample_composition_time_offset[i]=e.readInt32())})),h.createFullBoxCtor("tsel",(function(e){this.switch_group=e.readUint32();var t=(this.size-this.hdr_size-4)/4;this.attribute_list=[];for(var i=0;i<t;i++)this.attribute_list[i]=e.readUint32()})),h.createFullBoxCtor("txtC",(function(e){this.config=e.readCString()})),h.createBoxCtor("tyco",(function(e){var t=(this.size-this.hdr_size)/4;this.compatible_brands=[];for(var i=0;i<t;i++)this.compatible_brands[i]=e.readString(4)})),h.createFullBoxCtor("udes",(function(e){this.lang=e.readCString(),this.name=e.readCString(),this.description=e.readCString(),this.tags=e.readCString()})),h.createFullBoxCtor("uncC",(function(e){var t;if(this.profile=e.readUint32(),1==this.version);else if(0==this.version){for(this.component_count=e.readUint32(),this.component_index=[],this.component_bit_depth_minus_one=[],this.component_format=[],this.component_align_size=[],t=0;t<this.component_count;t++)this.component_index.push(e.readUint16()),this.component_bit_depth_minus_one.push(e.readUint8()),this.component_format.push(e.readUint8()),this.component_align_size.push(e.readUint8());this.sampling_type=e.readUint8(),this.interleave_type=e.readUint8(),this.block_size=e.readUint8();var i=e.readUint8();this.component_little_endian=i>>7&1,this.block_pad_lsb=i>>6&1,this.block_little_endian=i>>5&1,this.block_reversed=i>>4&1,this.pad_unknown=i>>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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")})),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<this.fragment_count;t++){var i={},r=0,s=0;1===this.version?(r=e.readUint64(),s=e.readUint64()):(r=e.readUint32(),s=e.readUint32()),i.absolute_time=r,i.absolute_duration=s,this.entries.push(i)}})),h.createUUIDBox("6d1d9b0542d544e680e2141daff757b2",!0,!1,(function(e){1===this.version?(this.absolute_time=e.readUint64(),this.duration=e.readUint64()):(this.absolute_time=e.readUint32(),this.duration=e.readUint32())})),h.createFullBoxCtor("vmhd",(function(e){this.graphicsmode=e.readUint16(),this.opcolor=e.readUint16Array(3)})),h.createFullBoxCtor("vpcC",(function(e){var t;1===this.version?(this.profile=e.readUint8(),this.level=e.readUint8(),t=e.readUint8(),this.bitDepth=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,i,r={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<<e)-1;return this.num_held_bits-=e,t}};if(r.stream_read_1_bytes(e),r.extract_bits(5),this.lengthSizeMinusOne=r.extract_bits(2),this.ptl_present_flag=r.extract_bits(1),this.ptl_present_flag){if(r.stream_read_2_bytes(e),this.ols_idx=r.extract_bits(9),this.num_sublayers=r.extract_bits(3),this.constant_frame_rate=r.extract_bits(2),this.chroma_format_idc=r.extract_bits(2),r.stream_read_1_bytes(e),this.bit_depth_minus8=r.extract_bits(3),r.extract_bits(5),r.stream_read_2_bytes(e),r.extract_bits(2),this.num_bytes_constraint_info=r.extract_bits(6),this.general_profile_idc=r.extract_bits(7),this.general_tier_flag=r.extract_bits(1),this.general_level_idc=e.readUint8(),r.stream_read_1_bytes(e),this.ptl_frame_only_constraint_flag=r.extract_bits(1),this.ptl_multilayer_enabled_flag=r.extract_bits(1),this.general_constraint_info=new Uint8Array(this.num_bytes_constraint_info),this.num_bytes_constraint_info){for(t=0;t<this.num_bytes_constraint_info-1;t++){var s=r.extract_bits(6);r.stream_read_1_bytes(e);var a=r.extract_bits(2);this.general_constraint_info[t]=s<<2|a}this.general_constraint_info[this.num_bytes_constraint_info-1]=r.extract_bits(6)}else r.extract_bits(6);if(this.num_sublayers>1){for(r.stream_read_1_bytes(e),this.ptl_sublayer_present_mask=0,i=this.num_sublayers-2;i>=0;--i){var n=r.extract_bits(1);this.ptl_sublayer_present_mask|=n<<i}for(i=this.num_sublayers;i<=8&&this.num_sublayers>1;++i)r.extract_bits(1);for(this.sublayer_level_idc=[],i=this.num_sublayers-2;i>=0;--i)this.ptl_sublayer_present_mask&1<<i&&(this.sublayer_level_idc[i]=e.readUint8())}if(this.ptl_num_sub_profiles=e.readUint8(),this.general_sub_profile_idc=[],this.ptl_num_sub_profiles)for(t=0;t<this.ptl_num_sub_profiles;t++)this.general_sub_profile_idc.push(e.readUint32());this.max_picture_width=e.readUint16(),this.max_picture_height=e.readUint16(),this.avg_frame_rate=e.readUint16()}this.nalu_arrays=[];var o=e.readUint8();for(t=0;t<o;t++){var d=[];this.nalu_arrays.push(d),r.stream_read_1_bytes(e),d.completeness=r.extract_bits(1),r.extract_bits(2),d.nalu_type=r.extract_bits(5);var l=1;for(13!=d.nalu_type&&12!=d.nalu_type&&(l=e.readUint16()),i=0;i<l;i++){var c=e.readUint16();d.push({data:e.readUint8Array(c),length:c})}}})),h.createFullBoxCtor("vvnC",(function(e){var t=strm.readUint8();this.lengthSizeMinusOne=3&t})),h.SampleEntry.prototype.isVideo=function(){return!1},h.SampleEntry.prototype.isAudio=function(){return!1},h.SampleEntry.prototype.isSubtitle=function(){return!1},h.SampleEntry.prototype.isMetadata=function(){return!1},h.SampleEntry.prototype.isHint=function(){return!1},h.SampleEntry.prototype.getCodec=function(){return this.type.replace(".","")},h.SampleEntry.prototype.getWidth=function(){return""},h.SampleEntry.prototype.getHeight=function(){return""},h.SampleEntry.prototype.getChannelCount=function(){return""},h.SampleEntry.prototype.getSampleRate=function(){return""},h.SampleEntry.prototype.getSampleSize=function(){return""},h.VisualSampleEntry.prototype.isVideo=function(){return!0},h.VisualSampleEntry.prototype.getWidth=function(){return this.width},h.VisualSampleEntry.prototype.getHeight=function(){return this.height},h.AudioSampleEntry.prototype.isAudio=function(){return!0},h.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count},h.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate},h.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize},h.SubtitleSampleEntry.prototype.isSubtitle=function(){return!0},h.MetadataSampleEntry.prototype.isMetadata=function(){return!0},h.decimalToHex=function(e,t){var i=Number(e).toString(16);for(t=null==t?t=2:t;i.length<t;)i="0"+i;return i},h.avc1SampleEntry.prototype.getCodec=h.avc2SampleEntry.prototype.getCodec=h.avc3SampleEntry.prototype.getCodec=h.avc4SampleEntry.prototype.getCodec=function(){var e=h.SampleEntry.prototype.getCodec.call(this);return this.avcC?e+"."+h.decimalToHex(this.avcC.AVCProfileIndication)+h.decimalToHex(this.avcC.profile_compatibility)+h.decimalToHex(this.avcC.AVCLevelIndication):e},h.hev1SampleEntry.prototype.getCodec=h.hvc1SampleEntry.prototype.getCodec=function(){var e,t=h.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){switch(t+=".",this.hvcC.general_profile_space){case 0:t+="";break;case 1:t+="A";break;case 2:t+="B";break;case 3:t+="C"}t+=this.hvcC.general_profile_idc,t+=".";var i=this.hvcC.general_profile_compatibility,r=0;for(e=0;e<32&&(r|=1&i,31!=e);e++)r<<=1,i>>=1;t+=h.decimalToHex(r,0),t+=".",0===this.hvcC.general_tier_flag?t+="L":t+="H",t+=this.hvcC.general_level_idc;var s=!1,a="";for(e=5;e>=0;e--)(this.hvcC.general_constraint_indicator[e]||s)&&(a="."+h.decimalToHex(this.hvcC.general_constraint_indicator[e],0)+a,s=!0);t+=a}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 i="";if(this.vvcC.general_constraint_info){var r,s=[],a=0;for(a|=this.vvcC.ptl_frame_only_constraint<<7,a|=this.vvcC.ptl_multilayer_enabled<<6,e=0;e<this.vvcC.general_constraint_info.length;++e)a|=this.vvcC.general_constraint_info[e]>>2&63,s.push(a),a&&(r=e),a=this.vvcC.general_constraint_info[e]>>2&3;if(void 0===r)i=".CA";else{i=".C";var n="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",o=0,d=0;for(e=0;e<=r;++e)for(o=o<<8|s[e],d+=8;d>=5;){i+=n[o>>d-5&31],o&=(1<<(d-=5))-1}d&&(i+=n[31&(o<<=5-d)])}}t+=i}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(),i=this.esds.esd.getAudioConfig();return e+"."+h.decimalToHex(t)+(i?"."+i:"")}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 i=this.vpcC.bitDepth;return 8==i&&(i="08"),e+".0"+this.vpcC.profile+"."+t+"."+i},h.av01SampleEntry.prototype.getCodec=function(){var e,t=h.SampleEntry.prototype.getCodec.call(this),i=this.av1C.seq_level_idx_0;return i<10&&(i="0"+i),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+"."+i+(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),n.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<this.boxes.length;t++)this.boxes[t]&&(this.boxes[t].write(e),this.size+=this.boxes[t].size);n.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),e.adjustUint32(this.sizePosition,this.size)},h.TrackReferenceTypeBox.prototype.write=function(e){this.size=4*this.track_ids.length,this.writeHeader(e),e.writeUint32Array(this.track_ids)},h.avcCBox.prototype.write=function(e){var t;for(this.size=7,t=0;t<this.SPS.length;t++)this.size+=2+this.SPS[t].length;for(t=0;t<this.PPS.length;t++)this.size+=2+this.PPS[t].length;for(this.ext&&(this.size+=this.ext.length),this.writeHeader(e),e.writeUint8(this.configurationVersion),e.writeUint8(this.AVCProfileIndication),e.writeUint8(this.profile_compatibility),e.writeUint8(this.AVCLevelIndication),e.writeUint8(this.lengthSizeMinusOne+252),e.writeUint8(this.SPS.length+224),t=0;t<this.SPS.length;t++)e.writeUint16(this.SPS[t].length),e.writeUint8Array(this.SPS[t].nalu);for(e.writeUint8(this.PPS.length),t=0;t<this.PPS.length;t++)e.writeUint16(this.PPS[t].length),e.writeUint8Array(this.PPS[t].nalu);this.ext&&e.writeUint8Array(this.ext)},h.co64Box.prototype.write=function(e){var t;for(this.version=0,this.flags=0,this.size=4+8*this.chunk_offsets.length,this.writeHeader(e),e.writeUint32(this.chunk_offsets.length),t=0;t<this.chunk_offsets.length;t++)e.writeUint64(this.chunk_offsets[t])},h.cslgBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=20,this.writeHeader(e),e.writeInt32(this.compositionToDTSShift),e.writeInt32(this.leastDecodeToDisplayDelta),e.writeInt32(this.greatestDecodeToDisplayDelta),e.writeInt32(this.compositionStartTime),e.writeInt32(this.compositionEndTime)},h.cttsBox.prototype.write=function(e){var t;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(e),e.writeUint32(this.sample_counts.length),t=0;t<this.sample_counts.length;t++)e.writeUint32(this.sample_counts[t]),1===this.version?e.writeInt32(this.sample_offsets[t]):e.writeUint32(this.sample_offsets[t])},h.drefBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=4,this.writeHeader(e),e.writeUint32(this.entries.length);for(var t=0;t<this.entries.length;t++)this.entries[t].write(e),this.size+=this.entries[t].size;n.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),e.adjustUint32(this.sizePosition,this.size)},h.elngBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=this.extended_language.length,this.writeHeader(e),e.writeString(this.extended_language)},h.elstBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=4+12*this.entries.length,this.writeHeader(e),e.writeUint32(this.entries.length);for(var t=0;t<this.entries.length;t++){var i=this.entries[t];e.writeUint32(i.segment_duration),e.writeInt32(i.media_time),e.writeInt16(i.media_rate_integer),e.writeInt16(i.media_rate_fraction)}},h.emsgBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=16+this.message_data.length+(this.scheme_id_uri.length+1)+(this.value.length+1),this.writeHeader(e),e.writeCString(this.scheme_id_uri),e.writeCString(this.value),e.writeUint32(this.timescale),e.writeUint32(this.presentation_time_delta),e.writeUint32(this.event_duration),e.writeUint32(this.id),e.writeUint8Array(this.message_data)},h.ftypBox.prototype.write=function(e){this.size=8+4*this.compatible_brands.length,this.writeHeader(e),e.writeString(this.major_brand,null,4),e.writeUint32(this.minor_version);for(var t=0;t<this.compatible_brands.length;t++)e.writeString(this.compatible_brands[t],null,4)},h.hdlrBox.prototype.write=function(e){this.size=20+this.name.length+1,this.version=0,this.flags=0,this.writeHeader(e),e.writeUint32(0),e.writeString(this.handler,null,4),e.writeUint32(0),e.writeUint32(0),e.writeUint32(0),e.writeCString(this.name)},h.hvcCBox.prototype.write=function(e){var t,i;for(this.size=23,t=0;t<this.nalu_arrays.length;t++)for(this.size+=3,i=0;i<this.nalu_arrays[t].length;i++)this.size+=2+this.nalu_arrays[t][i].data.length;for(this.writeHeader(e),e.writeUint8(this.configurationVersion),e.writeUint8(this.general_profile_space<<6+this.general_tier_flag<<5+this.general_profile_idc),e.writeUint32(this.general_profile_compatibility),e.writeUint8Array(this.general_constraint_indicator),e.writeUint8(this.general_level_idc),e.writeUint16(this.min_spatial_segmentation_idc+(15<<24)),e.writeUint8(this.parallelismType+252),e.writeUint8(this.chroma_format_idc+252),e.writeUint8(this.bit_depth_luma_minus8+248),e.writeUint8(this.bit_depth_chroma_minus8+248),e.writeUint16(this.avgFrameRate),e.writeUint8((this.constantFrameRate<<6)+(this.numTemporalLayers<<3)+(this.temporalIdNested<<2)+this.lengthSizeMinusOne),e.writeUint8(this.nalu_arrays.length),t=0;t<this.nalu_arrays.length;t++)for(e.writeUint8((this.nalu_arrays[t].completeness<<7)+this.nalu_arrays[t].nalu_type),e.writeUint16(this.nalu_arrays[t].length),i=0;i<this.nalu_arrays[t].length;i++)e.writeUint16(this.nalu_arrays[t][i].data.length),e.writeUint8Array(this.nalu_arrays[t][i].data)},h.kindBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=this.schemeURI.length+1+(this.value.length+1),this.writeHeader(e),e.writeCString(this.schemeURI),e.writeCString(this.value)},h.mdhdBox.prototype.write=function(e){this.size=20,this.flags=0,this.version=0,this.writeHeader(e),e.writeUint32(this.creation_time),e.writeUint32(this.modification_time),e.writeUint32(this.timescale),e.writeUint32(this.duration),e.writeUint16(this.language),e.writeUint16(0)},h.mehdBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=4,this.writeHeader(e),e.writeUint32(this.fragment_duration)},h.mfhdBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=4,this.writeHeader(e),e.writeUint32(this.sequence_number)},h.mvhdBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=96,this.writeHeader(e),e.writeUint32(this.creation_time),e.writeUint32(this.modification_time),e.writeUint32(this.timescale),e.writeUint32(this.duration),e.writeUint32(this.rate),e.writeUint16(this.volume<<8),e.writeUint16(0),e.writeUint32(0),e.writeUint32(0),e.writeUint32Array(this.matrix),e.writeUint32(0),e.writeUint32(0),e.writeUint32(0),e.writeUint32(0),e.writeUint32(0),e.writeUint32(0),e.writeUint32(this.next_track_id)},h.SampleEntry.prototype.writeHeader=function(e){this.size=8,h.Box.prototype.writeHeader.call(this,e),e.writeUint8(0),e.writeUint8(0),e.writeUint8(0),e.writeUint8(0),e.writeUint8(0),e.writeUint8(0),e.writeUint16(this.data_reference_index)},h.SampleEntry.prototype.writeFooter=function(e){for(var t=0;t<this.boxes.length;t++)this.boxes[t].write(e),this.size+=this.boxes[t].size;n.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),e.adjustUint32(this.sizePosition,this.size)},h.SampleEntry.prototype.write=function(e){this.writeHeader(e),e.writeUint8Array(this.data),this.size+=this.data.length,n.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),e.adjustUint32(this.sizePosition,this.size)},h.VisualSampleEntry.prototype.write=function(e){this.writeHeader(e),this.size+=70,e.writeUint16(0),e.writeUint16(0),e.writeUint32(0),e.writeUint32(0),e.writeUint32(0),e.writeUint16(this.width),e.writeUint16(this.height),e.writeUint32(this.horizresolution),e.writeUint32(this.vertresolution),e.writeUint32(0),e.writeUint16(this.frame_count),e.writeUint8(Math.min(31,this.compressorname.length)),e.writeString(this.compressorname,null,31),e.writeUint16(this.depth),e.writeInt16(-1),this.writeFooter(e)},h.AudioSampleEntry.prototype.write=function(e){this.writeHeader(e),this.size+=20,e.writeUint32(0),e.writeUint32(0),e.writeUint16(this.channel_count),e.writeUint16(this.samplesize),e.writeUint16(0),e.writeUint16(0),e.writeUint32(this.samplerate<<16),this.writeFooter(e)},h.stppSampleEntry.prototype.write=function(e){this.writeHeader(e),this.size+=this.namespace.length+1+this.schema_location.length+1+this.auxiliary_mime_types.length+1,e.writeCString(this.namespace),e.writeCString(this.schema_location),e.writeCString(this.auxiliary_mime_types),this.writeFooter(e)},h.SampleGroupEntry.prototype.write=function(e){e.writeUint8Array(this.data)},h.sbgpBox.prototype.write=function(e){this.version=1,this.flags=0,this.size=12+8*this.entries.length,this.writeHeader(e),e.writeString(this.grouping_type,null,4),e.writeUint32(this.grouping_type_parameter),e.writeUint32(this.entries.length);for(var t=0;t<this.entries.length;t++){var i=this.entries[t];e.writeInt32(i.sample_count),e.writeInt32(i.group_description_index)}},h.sgpdBox.prototype.write=function(e){var t,i;for(this.flags=0,this.size=12,t=0;t<this.entries.length;t++)i=this.entries[t],1===this.version&&(0===this.default_length&&(this.size+=4),this.size+=i.data.length);for(this.writeHeader(e),e.writeString(this.grouping_type,null,4),1===this.version&&e.writeUint32(this.default_length),this.version>=2&&e.writeUint32(this.default_sample_description_index),e.writeUint32(this.entries.length),t=0;t<this.entries.length;t++)i=this.entries[t],1===this.version&&0===this.default_length&&e.writeUint32(i.description_length),i.write(e)},h.sidxBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=20+12*this.references.length,this.writeHeader(e),e.writeUint32(this.reference_ID),e.writeUint32(this.timescale),e.writeUint32(this.earliest_presentation_time),e.writeUint32(this.first_offset),e.writeUint16(0),e.writeUint16(this.references.length);for(var t=0;t<this.references.length;t++){var i=this.references[t];e.writeUint32(i.reference_type<<31|i.referenced_size),e.writeUint32(i.subsegment_duration),e.writeUint32(i.starts_with_SAP<<31|i.SAP_type<<28|i.SAP_delta_time)}},h.smhdBox.prototype.write=function(e){this.version=0,this.flags=1,this.size=4,this.writeHeader(e),e.writeUint16(this.balance),e.writeUint16(0)},h.stcoBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=4+4*this.chunk_offsets.length,this.writeHeader(e),e.writeUint32(this.chunk_offsets.length),e.writeUint32Array(this.chunk_offsets)},h.stscBox.prototype.write=function(e){var t;for(this.version=0,this.flags=0,this.size=4+12*this.first_chunk.length,this.writeHeader(e),e.writeUint32(this.first_chunk.length),t=0;t<this.first_chunk.length;t++)e.writeUint32(this.first_chunk[t]),e.writeUint32(this.samples_per_chunk[t]),e.writeUint32(this.sample_description_index[t])},h.stsdBox.prototype.write=function(e){var t;for(this.version=0,this.flags=0,this.size=0,this.writeHeader(e),e.writeUint32(this.entries.length),this.size+=4,t=0;t<this.entries.length;t++)this.entries[t].write(e),this.size+=this.entries[t].size;n.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),e.adjustUint32(this.sizePosition,this.size)},h.stshBox.prototype.write=function(e){var t;for(this.version=0,this.flags=0,this.size=4+8*this.shadowed_sample_numbers.length,this.writeHeader(e),e.writeUint32(this.shadowed_sample_numbers.length),t=0;t<this.shadowed_sample_numbers.length;t++)e.writeUint32(this.shadowed_sample_numbers[t]),e.writeUint32(this.sync_sample_numbers[t])},h.stssBox.prototype.write=function(e){this.version=0,this.flags=0,this.size=4+4*this.sample_numbers.length,this.writeHeader(e),e.writeUint32(this.sample_numbers.length),e.writeUint32Array(this.sample_numbers)},h.stszBox.prototype.write=function(e){var t,i=!0;if(this.version=0,this.flags=0,this.sample_sizes.length>0)for(t=0;t+1<this.sample_sizes.length;){if(this.sample_sizes[t+1]!==this.sample_sizes[0]){i=!1;break}t++}else i=!1;this.size=8,i||(this.size+=4*this.sample_sizes.length),this.writeHeader(e),i?e.writeUint32(this.sample_sizes[0]):e.writeUint32(0),e.writeUint32(this.sample_sizes.length),i||e.writeUint32Array(this.sample_sizes)},h.sttsBox.prototype.write=function(e){var t;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(e),e.writeUint32(this.sample_counts.length),t=0;t<this.sample_counts.length;t++)e.writeUint32(this.sample_counts[t]),e.writeUint32(this.sample_deltas[t])},h.tfdtBox.prototype.write=function(e){var t=Math.pow(2,32)-1;this.version=this.baseMediaDecodeTime>t?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<this.sample_count;t++)this.flags&h.TRUN_FLAGS_DURATION&&e.writeUint32(this.sample_duration[t]),this.flags&h.TRUN_FLAGS_SIZE&&e.writeUint32(this.sample_size[t]),this.flags&h.TRUN_FLAGS_FLAGS&&e.writeUint32(this.sample_flags[t]),this.flags&h.TRUN_FLAGS_CTS_OFFSET&&(0===this.version?e.writeUint32(this.sample_composition_time_offset[t]):e.writeInt32(this.sample_composition_time_offset[t]))},h["url Box"].prototype.write=function(e){this.version=0,this.location?(this.flags=0,this.size=this.location.length+1):(this.flags=1,this.size=0),this.writeHeader(e),this.location&&e.writeCString(this.location)},h["urn Box"].prototype.write=function(e){this.version=0,this.flags=0,this.size=this.name.length+1+(this.location?this.location.length+1:0),this.writeHeader(e),e.writeCString(this.name),this.location&&e.writeCString(this.location)},h.vmhdBox.prototype.write=function(e){this.version=0,this.flags=1,this.size=8,this.writeHeader(e),e.writeUint16(this.graphicsmode),e.writeUint16Array(this.opcolor)},h.cttsBox.prototype.unpack=function(e){var t,i,r;for(r=0,t=0;t<this.sample_counts.length;t++)for(i=0;i<this.sample_counts[t];i++)e[r].pts=e[r].dts+this.sample_offsets[t],r++},h.sttsBox.prototype.unpack=function(e){var t,i,r;for(r=0,t=0;t<this.sample_counts.length;t++)for(i=0;i<this.sample_counts[t];i++)e[r].dts=0===r?0:e[r-1].dts+this.sample_deltas[t],r++},h.stcoBox.prototype.unpack=function(e){var t;for(t=0;t<this.chunk_offsets.length;t++)e[t].offset=this.chunk_offsets[t]},h.stscBox.prototype.unpack=function(e){var t,i,r,s,a;for(s=0,a=0,t=0;t<this.first_chunk.length;t++)for(i=0;i<(t+1<this.first_chunk.length?this.first_chunk[t+1]:1/0);i++)for(a++,r=0;r<this.samples_per_chunk[t];r++){if(!e[s])return;e[s].description_index=this.sample_description_index[t],e[s].chunk_index=a,s++}},h.stszBox.prototype.unpack=function(e){var t;for(t=0;t<this.sample_sizes.length;t++)e[t].size=this.sample_sizes[t]},h.DIFF_BOXES_PROP_NAMES=["boxes","entries","references","subsamples","items","item_infos","extents","associations","subsegments","ranges","seekLists","seekPoints","esd","levels"],h.DIFF_PRIMITIVE_ARRAY_PROP_NAMES=["compatible_brands","matrix","opcolor","sample_counts","sample_counts","sample_deltas","first_chunk","samples_per_chunk","sample_sizes","chunk_offsets","sample_offsets","sample_description_index","sample_duration"],h.boxEqualFields=function(e,t){if(e&&!t)return!1;var i;for(i in e)if(!(h.DIFF_BOXES_PROP_NAMES.indexOf(i)>-1||e[i]instanceof h.Box||t[i]instanceof h.Box||void 0===e[i]||void 0===t[i]||"function"==typeof e[i]||"function"==typeof t[i]||e.subBoxNames&&e.subBoxNames.indexOf(i.slice(0,4))>-1||t.subBoxNames&&t.subBoxNames.indexOf(i.slice(0,4))>-1||"data"===i||"start"===i||"size"===i||"creation_time"===i||"modification_time"===i||h.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(i)>-1||e[i]===t[i]))return!1;return!0},h.boxEqual=function(e,t){if(!h.boxEqualFields(e,t))return!1;for(var i=0;i<h.DIFF_BOXES_PROP_NAMES.length;i++){var r=h.DIFF_BOXES_PROP_NAMES[i];if(e[r]&&t[r]&&!h.boxEqual(e[r],t[r]))return!1}return!0};var _=function(){};_.prototype.parseSample=function(e){var t,i={};i.resources=[];var r=new o(e.data.buffer);if(e.subsamples&&0!==e.subsamples.length){if(i.documentString=r.readString(e.subsamples[0].size),e.subsamples.length>1)for(t=1;t<e.subsamples.length;t++)i.resources[t]=r.readUint8Array(e.subsamples[t].size)}else i.documentString=r.readString(e.data.length);return"undefined"!=typeof DOMParser&&(i.document=(new DOMParser).parseFromString(i.documentString,"application/xml")),i};var m=function(){};m.prototype.parseSample=function(e){return new o(e.data.buffer).readString(e.data.length)},m.prototype.parseConfig=function(e){var t=new o(e.buffer);return t.readUint32(),t.readCString()},t.XMLSubtitlein4Parser=_,t.Textin4Parser=m;var g=function(e){this.stream=e||new c,this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.onMoovStart=null,this.moovStartSent=!1,this.onReady=null,this.readySent=!1,this.onSegment=null,this.onSamples=null,this.onError=null,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.onSidx=null,this.sidxSent=!1};g.prototype.destroy=function(){this.stream&&(this.stream.destroy(),this.stream=null),this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.onMoovStart=null,this.moovStartSent=!1,this.onReady=null,this.readySent=!1,this.onSegment=null,this.onSamples=null,this.onError=null,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.onSidx=null,this.sidxSent=!1},g.prototype.setSegmentOptions=function(e,t,i){var r=this.getTrackById(e);if(r){var s={};this.fragmentedTracks.push(s),s.id=e,s.user=t,s.trak=r,r.nextSample=0,s.segmentStream=null,s.nb_samples=1e3,s.rapAlignement=!0,i&&(i.nbSamples&&(s.nb_samples=i.nbSamples),i.rapAlignement&&(s.rapAlignement=i.rapAlignement))}},g.prototype.unsetSegmentOptions=function(e){for(var t=-1,i=0;i<this.fragmentedTracks.length;i++){this.fragmentedTracks[i].id==e&&(t=i)}t>-1&&this.fragmentedTracks.splice(t,1)},g.prototype.setExtractionOptions=function(e,t,i){var r=this.getTrackById(e);if(r){var s={};this.extractedTracks.push(s),s.id=e,s.user=t,s.trak=r,r.nextSample=0,s.nb_samples=1e3,s.samples=[],i&&i.nbSamples&&(s.nb_samples=i.nbSamples)}},g.prototype.unsetExtractionOptions=function(e){for(var t=-1,i=0;i<this.extractedTracks.length;i++){this.extractedTracks[i].id==e&&(t=i)}t>-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 i;switch(i="uuid"!==(t=e.box).type?t.type:t.uuid,this.boxes.push(t),i){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[i]&&n.warn("ISOFile","Duplicate Box of type: "+i+", overriding previous occurrence"),this[i]=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?(n.warn("ISOFile","Ignoring empty buffer (fileStart: "+e.fileStart+")"),this.stream.logBufferLevel(),!1):(n.info("ISOFile","Processing buffer (fileStart: "+e.fileStart+")"),e.usedBytes=0,this.stream.insertBuffer(e),this.stream.logBufferLevel(),!!this.stream.initialized()||(n.warn("ISOFile","Not ready to start parsing"),!1))},g.prototype.appendBuffer=function(e,t){var i;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?(i=this.nextSeekPosition,this.nextSeekPosition=void 0):i=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(i=this.stream.getEndFilePositionAfter(i))):i=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&&(n.info("ISOFile","Done processing buffer (fileStart: "+e.fileStart+") - next buffer to fetch should have a fileStart position of "+i),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),n.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),i},g.prototype.getInfo=function(){var e,t,i,r,s,a,n={},o=new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(n.hasMoov=!0,n.duration=this.moov.mvhd.duration,n.timescale=this.moov.mvhd.timescale,n.isFragmented=null!=this.moov.mvex,n.isFragmented&&this.moov.mvex.mehd&&(n.fragment_duration=this.moov.mvex.mehd.fragment_duration),n.isProgressive=this.isProgressive,n.hasIOD=null!=this.moov.iods,n.brands=[],n.brands.push(this.ftyp.major_brand),n.brands=n.brands.concat(this.ftyp.compatible_brands),n.created=new Date(o+1e3*this.moov.mvhd.creation_time),n.modified=new Date(o+1e3*this.moov.mvhd.modification_time),n.tracks=[],n.audioTracks=[],n.videoTracks=[],n.subtitleTracks=[],n.metadataTracks=[],n.hintTracks=[],n.otherTracks=[],e=0;e<this.moov.traks.length;e++){if(a=(i=this.moov.traks[e]).mdia.minf.stbl.stsd.entries[0],r={},n.tracks.push(r),r.id=i.tkhd.track_id,r.name=i.mdia.hdlr.name,r.references=[],i.tref)for(t=0;t<i.tref.boxes.length;t++)s={},r.references.push(s),s.type=i.tref.boxes[t].type,s.track_ids=i.tref.boxes[t].track_ids;i.edts&&(r.edits=i.edts.elst.entries),r.created=new Date(o+1e3*i.tkhd.creation_time),r.modified=new Date(o+1e3*i.tkhd.modification_time),r.movie_duration=i.tkhd.duration,r.movie_timescale=n.timescale,r.layer=i.tkhd.layer,r.alternate_group=i.tkhd.alternate_group,r.volume=i.tkhd.volume,r.matrix=i.tkhd.matrix,r.track_width=i.tkhd.width/65536,r.track_height=i.tkhd.height/65536,r.timescale=i.mdia.mdhd.timescale,r.cts_shift=i.mdia.minf.stbl.cslg,r.duration=i.mdia.mdhd.duration,r.samples_duration=i.samples_duration,r.codec=a.getCodec(),r.kind=i.udta&&i.udta.kinds.length?i.udta.kinds[0]:{schemeURI:"",value:""},r.language=i.mdia.elng?i.mdia.elng.extended_language:i.mdia.mdhd.languageString,r.nb_samples=i.samples.length,r.size=i.samples_size,r.bitrate=8*r.size*r.timescale/r.samples_duration,a.isAudio()?(r.type="audio",n.audioTracks.push(r),r.audio={},r.audio.sample_rate=a.getSampleRate(),r.audio.channel_count=a.getChannelCount(),r.audio.sample_size=a.getSampleSize()):a.isVideo()?(r.type="video",n.videoTracks.push(r),r.video={},r.video.width=a.getWidth(),r.video.height=a.getHeight()):a.isSubtitle()?(r.type="subtitles",n.subtitleTracks.push(r)):a.isHint()?(r.type="metadata",n.hintTracks.push(r)):a.isMetadata()?(r.type="metadata",n.metadataTracks.push(r)):(r.type="metadata",n.otherTracks.push(r))}else n.hasMoov=!1;if(n.mime="",n.hasMoov&&n.tracks){for(n.videoTracks&&n.videoTracks.length>0?n.mime+='video/mp4; codecs="':n.audioTracks&&n.audioTracks.length>0?n.mime+='audio/mp4; codecs="':n.mime+='application/mp4; codecs="',e=0;e<n.tracks.length;e++)0!==e&&(n.mime+=","),n.mime+=n.tracks[e].codec;n.mime+='"; profiles="',n.mime+=this.ftyp.compatible_brands.join(),n.mime+='"'}return n},g.prototype.setNextSeekPositionFromSample=function(e){e&&(this.nextSeekPosition?this.nextSeekPosition=Math.min(e.offset+e.alreadyRead,this.nextSeekPosition):this.nextSeekPosition=e.offset+e.alreadyRead)},g.prototype.processSamples=function(e){var t,i;if(this.sampleProcessingStarted){if(this.isFragmentationInitialized&&null!==this.onSegment)for(t=0;t<this.fragmentedTracks.length;t++){var r=this.fragmentedTracks[t];for(i=r.trak;i.nextSample<i.samples.length&&this.sampleProcessingStarted;){n.debug("ISOFile","Creating media fragment on track #"+r.id+" for sample "+i.nextSample);var s=this.createFragment(r.id,i.nextSample,r.segmentStream);if(!s)break;if(r.segmentStream=s,i.nextSample++,(i.nextSample%r.nb_samples==0||e||i.nextSample>=i.samples.length)&&(n.info("ISOFile","Sending fragmented data on track #"+r.id+" for samples ["+Math.max(0,i.nextSample-r.nb_samples)+","+(i.nextSample-1)+"]"),n.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(r.id,r.user,r.segmentStream.buffer,i.nextSample,e||i.nextSample>=i.samples.length),r.segmentStream=null,r!==this.fragmentedTracks[t]))break}}if(null!==this.onSamples)for(t=0;t<this.extractedTracks.length;t++){var a=this.extractedTracks[t];for(i=a.trak;i.nextSample<i.samples.length&&this.sampleProcessingStarted;){n.debug("ISOFile","Exporting on track #"+a.id+" sample #"+i.nextSample);var o=this.getSample(i,i.nextSample);if(!o){this.setNextSeekPositionFromSample(i.samples[i.nextSample]);break}if(i.nextSample++,a.samples.push(o),(i.nextSample%a.nb_samples==0||i.nextSample>=i.samples.length)&&(n.debug("ISOFile","Sending samples on track #"+a.id+" for sample "+i.nextSample),this.onSamples&&this.onSamples(a.id,a.user,a.samples),a.samples=[],a!==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 i=[];return g._sweep.call(this,e,i,t),i},g._sweep=function(e,t,i){for(var r in this.type&&this.type==e&&t.push(this),this.boxes){if(t.length&&i)return;g._sweep.call(this.boxes[r],e,t,i)}},g.prototype.getTrackSamplesInfo=function(e){var t=this.getTrackById(e);return t?t.samples:void 0},g.prototype.getTrackSample=function(e,t){var i=this.getTrackById(e);return this.getSample(i,t)},g.prototype.releaseUsedSamples=function(e,t){var i=0,r=this.getTrackById(e);r.lastValidSample||(r.lastValidSample=0);for(var s=r.lastValidSample;s<t;s++)i+=this.releaseSample(r,s);n.info("ISOFile","Track #"+e+" released samples up to "+t+" (released size: "+i+", remaining: "+this.samplesDataSize+")"),r.lastValidSample=t},g.prototype.start=function(){this.sampleProcessingStarted=!0,this.processSamples(!1)},g.prototype.stop=function(){this.sampleProcessingStarted=!1},g.prototype.flush=function(){n.info("ISOFile","Flushing remaining samples"),this.updateSampleLists(),this.processSamples(!0),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0)},g.prototype.seekTrack=function(e,t,i){var r,s,a,o,d=0,l=0;if(0===i.samples.length)return n.info("ISOFile","No sample in track, cannot seek! Using time "+n.getDurationString(0,1)+" and offset: 0"),{offset:0,time:0};for(r=0;r<i.samples.length;r++){if(s=i.samples[r],0===r)l=0,o=s.timescale;else if(s.cts>e*s.timescale){l=r-1;break}t&&s.is_sync&&(d=r)}for(t&&(l=d),e=i.samples[l].cts,i.nextSample=l;i.samples[l].alreadyRead===i.samples[l].size&&i.samples[l+1];)l++;return a=i.samples[l].offset+i.samples[l].alreadyRead,n.info("ISOFile","Seeking to "+(t?"RAP":"")+" sample #"+i.nextSample+" on track "+i.tkhd.track_id+", time "+n.getDurationString(e,o)+" and offset: "+a),{offset:a,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 i,r,s,a=this.moov,o={offset:1/0,time:1/0};if(this.moov){for(s=0;s<a.traks.length;s++)i=a.traks[s],e>this.getTrackDuration(i)||((r=this.seekTrack(e,t,i)).offset<o.offset&&(o.offset=r.offset),r.time<o.time&&(o.time=r.time));return n.info("ISOFile","Seeking at time "+n.getDurationString(o.time,1)+" needs a buffer with a fileStart position of "+o.offset),o.offset===1/0?o={offset:this.nextParsePosition,time:0}:o.offset=this.stream.getEndFilePositionAfter(o.offset),n.info("ISOFile","Adjusted seek position (after checking data already in buffer): "+o.offset),o}throw"Cannot seek: moov not received!"},g.prototype.equal=function(e){for(var t=0;t<this.boxes.length&&t<e.boxes.length;){var i=this.boxes[t],r=e.boxes[t];if(!h.boxEqual(i,r))return!1;t++}return!0},t.ISOFile=g,g.prototype.lastBoxStartPosition=0,g.prototype.parsingMdat=null,g.prototype.nextParsePosition=0,g.prototype.discardMdatData=!1,g.prototype.processIncompleteBox=function(e){var t;return"mdat"===e.type?(t=new h[e.type+"Box"](e.size),this.parsingMdat=t,this.boxes.push(t),this.mdats.push(t),t.start=e.start,t.hdr_size=e.hdr_size,this.stream.addUsedBytes(t.hdr_size),this.lastBoxStartPosition=t.start+t.size,this.stream.seek(t.start+t.size,!1,this.discardMdatData)?(this.parsingMdat=null,!0):(this.moovStartFound?this.nextParsePosition=this.stream.findEndContiguousBuf():this.nextParsePosition=t.start+t.size,!1)):("moov"===e.type&&(this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0)),!!this.stream.mergeNextBuffer&&this.stream.mergeNextBuffer()?(this.nextParsePosition=this.stream.getEndPosition(),!0):(e.type?this.moovStartFound?this.nextParsePosition=this.stream.getEndPosition():this.nextParsePosition=this.stream.getPosition()+e.size:this.nextParsePosition=this.stream.getEndPosition(),!1))},g.prototype.hasIncompleteMdat=function(){return null!==this.parsingMdat},g.prototype.processIncompleteMdat=function(){var e;return e=this.parsingMdat,this.stream.seek(e.start+e.size,!1,this.discardMdatData)?(n.debug("ISOFile","Found 'mdat' end in buffered data"),this.parsingMdat=null,!0):(this.nextParsePosition=this.stream.findEndContiguousBuf(),!1)},g.prototype.restoreParsePosition=function(){return this.stream.seek(this.lastBoxStartPosition,!0,this.discardMdatData)},g.prototype.saveParsePosition=function(){this.lastBoxStartPosition=this.stream.getPosition()},g.prototype.updateUsedBytes=function(e,t){this.stream.addUsedBytes&&("mdat"===e.type?(this.stream.addUsedBytes(e.hdr_size),this.discardMdatData&&this.stream.addUsedBytes(e.size-e.hdr_size)):this.stream.addUsedBytes(e.size))},g.prototype.add=h.Box.prototype.add,g.prototype.addBox=h.Box.prototype.addBox,g.prototype.init=function(e){var t=e||{};this.add("ftyp").set("major_brand",t.brands&&t.brands[0]||"iso4").set("minor_version",0).set("compatible_brands",t.brands||["iso4"]);var i=this.add("moov");return i.add("mvhd").set("timescale",t.timescale||600).set("rate",t.rate||65536).set("creation_time",0).set("modification_time",0).set("duration",t.duration||0).set("volume",t.width?0:256).set("matrix",[65536,0,0,0,65536,0,0,0,1073741824]).set("next_track_id",1),i.add("mvex"),this},g.prototype.addTrack=function(e){this.moov||this.init(e);var t=e||{};t.width=t.width||320,t.height=t.height||320,t.id=t.id||this.moov.mvhd.next_track_id,t.type=t.type||"avc1";var i=this.moov.add("trak");this.moov.mvhd.next_track_id=t.id+1,i.add("tkhd").set("flags",h.TKHD_FLAG_ENABLED|h.TKHD_FLAG_IN_MOVIE|h.TKHD_FLAG_IN_PREVIEW).set("creation_time",0).set("modification_time",0).set("track_id",t.id).set("duration",t.duration||0).set("layer",t.layer||0).set("alternate_group",0).set("volume",1).set("matrix",[0,0,0,0,0,0,0,0,0]).set("width",t.width<<16).set("height",t.height<<16);var r=i.add("mdia");r.add("mdhd").set("creation_time",0).set("modification_time",0).set("timescale",t.timescale||1).set("duration",t.media_duration||0).set("language",t.language||"und"),r.add("hdlr").set("handler",t.hdlr||"vide").set("name",t.name||"Track created with MP4Box.js"),r.add("elng").set("extended_language",t.language||"fr-FR");var s=r.add("minf");if(void 0!==h[t.type+"SampleEntry"]){var a=new h[t.type+"SampleEntry"];a.data_reference_index=1;var n="";for(var d in h.sampleEntryCodes)for(var l=h.sampleEntryCodes[d],c=0;c<l.length;c++)if(l.indexOf(t.type)>-1){n=d;break}switch(n){case"Visual":if(s.add("vmhd").set("graphicsmode",0).set("opcolor",[0,0,0]),a.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 u=new h.avcCBox;u.parse(new o(t.avcDecoderConfigRecord)),a.addBox(u)}else if(t.hevcDecoderConfigRecord){var f=new h.hvcCBox;f.parse(new o(t.hevcDecoderConfigRecord)),a.addBox(f)}break;case"Audio":s.add("smhd").set("balance",t.balance||0),a.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)a.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&&a.addBox(t.description),t.description_boxes&&t.description_boxes.forEach((function(e){a.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(a),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(i),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,i){var r=i||{},s={},a=this.getTrackById(e);if(null!==a){s.number=a.samples.length,s.track_id=a.tkhd.track_id,s.timescale=a.mdia.mdhd.timescale,s.description_index=r.sample_description_index?r.sample_description_index-1:0,s.description=a.mdia.minf.stbl.stsd.entries[s.description_index],s.data=t,s.size=t.byteLength,s.alreadyRead=s.size,s.duration=r.duration||1,s.cts=r.cts||0,s.dts=r.dts||0,s.is_sync=r.is_sync||!1,s.is_leading=r.is_leading||0,s.depends_on=r.depends_on||0,s.is_depended_on=r.is_depended_on||0,s.has_redundancy=r.has_redundancy||0,s.degradation_priority=r.degradation_priority||0,s.offset=0,s.subsamples=r.subsamples,a.samples.push(s),a.samples_size+=s.size,a.samples_duration+=s.duration,void 0===a.first_dts&&(a.first_dts=r.dts),this.processSamples();var n=this.createSingleSampleMoof(s);return this.addBox(n),n.computeSize(),n.trafs[0].truns[0].data_offset=n.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 i=new h.moofBox;i.add("mfhd").set("sequence_number",this.nextMoofNumber),this.nextMoofNumber++;var r=i.add("traf"),s=this.getTrackById(e.track_id);return r.add("tfhd").set("track_id",e.track_id).set("flags",h.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),r.add("tfdt").set("baseMediaDecodeTime",e.dts-(s.first_dts||0)),r.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]),i},g.prototype.lastMoofIndex=0,g.prototype.samplesDataSize=0,g.prototype.resetTables=function(){var e,t,i,r,s,a;for(this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0,e=0;e<this.moov.traks.length;e++){(t=this.moov.traks[e]).tkhd.duration=0,t.mdia.mdhd.duration=0,(t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64).chunk_offsets=[],(i=t.mdia.minf.stbl.stsc).first_chunk=[],i.samples_per_chunk=[],i.sample_description_index=[],(t.mdia.minf.stbl.stsz||t.mdia.minf.stbl.stz2).sample_sizes=[],(r=t.mdia.minf.stbl.stts).sample_counts=[],r.sample_deltas=[],(s=t.mdia.minf.stbl.ctts)&&(s.sample_counts=[],s.sample_offsets=[]),a=t.mdia.minf.stbl.stss;var n=t.mdia.minf.stbl.boxes.indexOf(a);-1!=n&&(t.mdia.minf.stbl.boxes[n]=null)}},g.initSampleGroups=function(e,t,i,r,s){var a,n,o,d;function l(e,t,i){this.grouping_type=e,this.grouping_type_parameter=t,this.sbgp=i,this.last_sample_in_run=-1,this.entry_index=-1}for(t&&(t.sample_groups_info=[]),e.sample_groups_info||(e.sample_groups_info=[]),n=0;n<i.length;n++){for(d=i[n].grouping_type+"/"+i[n].grouping_type_parameter,o=new l(i[n].grouping_type,i[n].grouping_type_parameter,i[n]),t&&(t.sample_groups_info[d]=o),e.sample_groups_info[d]||(e.sample_groups_info[d]=o),a=0;a<r.length;a++)r[a].grouping_type===i[n].grouping_type&&(o.description=r[a],o.description.used=!0);if(s)for(a=0;a<s.length;a++)s[a].grouping_type===i[n].grouping_type&&(o.fragment_description=s[a],o.fragment_description.used=!0,o.is_fragment=!0)}if(t){if(s)for(n=0;n<s.length;n++)!s[n].used&&s[n].version>=2&&(d=s[n].grouping_type+"/0",(o=new l(s[n].grouping_type,0)).is_fragment=!0,t.sample_groups_info[d]||(t.sample_groups_info[d]=o))}else for(n=0;n<r.length;n++)!r[n].used&&r[n].version>=2&&(d=r[n].grouping_type+"/0",o=new l(r[n].grouping_type,0),e.sample_groups_info[d]||(e.sample_groups_info[d]=o))},g.setSampleGroupProperties=function(e,t,i,r){var s,a;for(s in t.sample_groups=[],r){var n;if(t.sample_groups[s]={},t.sample_groups[s].grouping_type=r[s].grouping_type,t.sample_groups[s].grouping_type_parameter=r[s].grouping_type_parameter,i>=r[s].last_sample_in_run&&(r[s].last_sample_in_run<0&&(r[s].last_sample_in_run=0),r[s].entry_index++,r[s].entry_index<=r[s].sbgp.entries.length-1&&(r[s].last_sample_in_run+=r[s].sbgp.entries[r[s].entry_index].sample_count)),r[s].entry_index<=r[s].sbgp.entries.length-1?t.sample_groups[s].group_description_index=r[s].sbgp.entries[r[s].entry_index].group_description_index:t.sample_groups[s].group_description_index=-1,0!==t.sample_groups[s].group_description_index)n=r[s].fragment_description?r[s].fragment_description:r[s].description,t.sample_groups[s].group_description_index>0?(a=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,n&&a>=0&&(t.sample_groups[s].description=n.entries[a])):n&&n.version>=2&&n.default_group_description_index>0&&(t.sample_groups[s].description=n.entries[n.default_group_description_index-1])}},g.process_sdtp=function(e,t,i){t&&(e?(t.is_leading=e.is_leading[i],t.depends_on=e.sample_depends_on[i],t.is_depended_on=e.sample_is_depended_on[i],t.has_redundancy=e.sample_has_redundancy[i]):(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;e<this.moov.traks.length;e++)t=this.moov.traks[e],this.buildTrakSampleLists(t)},g.prototype.buildTrakSampleLists=function(e){var t,i,r,s,a,n,o,d,l,c,u,h,f,p,_,m,y,b,S,v,w,A,U,E;if(e.samples=[],e.samples_duration=0,e.samples_size=0,i=e.mdia.minf.stbl.stco||e.mdia.minf.stbl.co64,r=e.mdia.minf.stbl.stsc,s=e.mdia.minf.stbl.stsz||e.mdia.minf.stbl.stz2,a=e.mdia.minf.stbl.stts,n=e.mdia.minf.stbl.ctts,o=e.mdia.minf.stbl.stss,d=e.mdia.minf.stbl.stsd,l=e.mdia.minf.stbl.subs,h=e.mdia.minf.stbl.stdp,c=e.mdia.minf.stbl.sbgps,u=e.mdia.minf.stbl.sgpds,b=-1,S=-1,v=-1,w=-1,A=0,U=0,E=0,g.initSampleGroups(e,null,c,u),void 0!==s){for(t=0;t<s.sample_sizes.length;t++){var x={};x.number=t,x.track_id=e.tkhd.track_id,x.timescale=e.mdia.mdhd.timescale,x.alreadyRead=0,e.samples[t]=x,x.size=s.sample_sizes[t],e.samples_size+=x.size,0===t?(p=1,f=0,x.chunk_index=p,x.chunk_run_index=f,y=r.samples_per_chunk[f],m=0,_=f+1<r.first_chunk.length?r.first_chunk[f+1]-1:1/0):t<y?(x.chunk_index=p,x.chunk_run_index=f):(p++,x.chunk_index=p,m=0,p<=_||(_=++f+1<r.first_chunk.length?r.first_chunk[f+1]-1:1/0),x.chunk_run_index=f,y+=r.samples_per_chunk[f]),x.description_index=r.sample_description_index[x.chunk_run_index]-1,x.description=d.entries[x.description_index],x.offset=i.chunk_offsets[x.chunk_index-1]+m,m+=x.size,t>b&&(S++,b<0&&(b=0),b+=a.sample_counts[S]),t>0?(e.samples[t-1].duration=a.sample_deltas[S],e.samples_duration+=e.samples[t-1].duration,x.dts=e.samples[t-1].dts+e.samples[t-1].duration):x.dts=0,n?(t>=v&&(w++,v<0&&(v=0),v+=n.sample_counts[w]),x.cts=e.samples[t].dts+n.sample_offsets[w]):x.cts=x.dts,o?(t==o.sample_numbers[A]-1?(x.is_sync=!0,A++):(x.is_sync=!1,x.degradation_priority=0),l&&l.entries[U].sample_delta+E==t+1&&(x.subsamples=l.entries[U].subsamples,E+=l.entries[U].sample_delta,U++)):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[U].sample_delta+E==t&&(x.subsamples=l.entries[U].subsamples,E+=l.entries[U].sample_delta),(c.length>0||u.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,i,r,s,a,n,o,d,l,c,u,f,p,_;if(void 0!==this.moov)for(;this.lastMoofIndex<this.moofs.length;)if(d=this.moofs[this.lastMoofIndex],this.lastMoofIndex++,"moof"==d.type)for(l=d,e=0;e<l.trafs.length;e++){for(c=l.trafs[e],u=this.getTrackById(c.tfhd.track_id),f=this.getTrexById(c.tfhd.track_id),r=c.tfhd.flags&h.TFHD_FLAG_SAMPLE_DESC?c.tfhd.default_sample_description_index:f?f.default_sample_description_index:1,s=c.tfhd.flags&h.TFHD_FLAG_SAMPLE_DUR?c.tfhd.default_sample_duration:f?f.default_sample_duration:0,a=c.tfhd.flags&h.TFHD_FLAG_SAMPLE_SIZE?c.tfhd.default_sample_size:f?f.default_sample_size:0,n=c.tfhd.flags&h.TFHD_FLAG_SAMPLE_FLAGS?c.tfhd.default_sample_flags:f?f.default_sample_flags:0,c.sample_number=0,c.sbgps.length>0&&g.initSampleGroups(u,c,c.sbgps,u.mdia.minf.stbl.sgpds,c.sgpds),t=0;t<c.truns.length;t++){var m=c.truns[t];for(i=0;i<m.sample_count;i++){(p={}).moof_number=this.lastMoofIndex,p.number_in_traf=c.sample_number,c.sample_number++,p.number=u.samples.length,c.first_sample_index=u.samples.length,u.samples.push(p),p.track_id=u.tkhd.track_id,p.timescale=u.mdia.mdhd.timescale,p.description_index=r-1,p.description=u.mdia.minf.stbl.stsd.entries[p.description_index],p.size=a,m.flags&h.TRUN_FLAGS_SIZE&&(p.size=m.sample_size[i]),u.samples_size+=p.size,p.duration=s,m.flags&h.TRUN_FLAGS_DURATION&&(p.duration=m.sample_duration[i]),u.samples_duration+=p.duration,u.first_traf_merged||i>0?p.dts=u.samples[u.samples.length-2].dts+u.samples[u.samples.length-2].duration:(c.tfdt?p.dts=c.tfdt.baseMediaDecodeTime:p.dts=0,u.first_traf_merged=!0),p.cts=p.dts,m.flags&h.TRUN_FLAGS_CTS_OFFSET&&(p.cts=p.dts+m.sample_composition_time_offset[i]),_=n,m.flags&h.TRUN_FLAGS_FLAGS?_=m.sample_flags[i]:0===i&&m.flags&h.TRUN_FLAGS_FIRST_FLAG&&(_=m.first_sample_flags),p.is_sync=!(_>>16&1),p.is_leading=_>>26&3,p.depends_on=_>>24&3,p.is_depended_on=_>>22&3,p.has_redundancy=_>>20&3,p.degradation_priority=65535&_;var y=!!(c.tfhd.flags&h.TFHD_FLAG_BASE_DATA_OFFSET),b=!!(c.tfhd.flags&h.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),S=!!(m.flags&h.TRUN_FLAGS_DATA_OFFSET),v=0;v=y?c.tfhd.base_data_offset:b||0===t?l.start:o,p.offset=0===t&&0===i?S?v+m.data_offset:v:o,o=p.offset+p.size,(c.sbgps.length>0||c.sgpds.length>0||u.mdia.minf.stbl.sbgps.length>0||u.mdia.minf.stbl.sgpds.length>0)&&g.setSampleGroupProperties(u,p,p.number_in_traf,c.sample_groups_info)}}if(c.subs){u.has_fragment_subsamples=!0;var w=c.first_sample_index;for(t=0;t<c.subs.entries.length;t++)w+=c.subs.entries[t].sample_delta,(p=u.samples[w-1]).subsamples=c.subs.entries[t].subsamples}}},g.prototype.getSample=function(e,t){var i,r=e.samples[t];if(!this.moov)return null;if(r.data){if(r.alreadyRead==r.size)return r}else r.data=new Uint8Array(r.size),r.alreadyRead=0,this.samplesDataSize+=r.size,n.debug("ISOFile","Allocating sample #"+t+" on track #"+e.tkhd.track_id+" of size "+r.size+" (total: "+this.samplesDataSize+")");for(;;){var s=this.stream.findPosition(!0,r.offset+r.alreadyRead,!1);if(!(s>-1))return null;var a=(i=this.stream.buffers[s]).byteLength-(r.offset+r.alreadyRead-i.fileStart);if(r.size-r.alreadyRead<=a)return n.debug("ISOFile","Getting sample #"+t+" data (alreadyRead: "+r.alreadyRead+" offset: "+(r.offset+r.alreadyRead-i.fileStart)+" read size: "+(r.size-r.alreadyRead)+" full size: "+r.size+")"),d.memcpy(r.data.buffer,r.alreadyRead,i,r.offset+r.alreadyRead-i.fileStart,r.size-r.alreadyRead),i.usedBytes+=r.size-r.alreadyRead,this.stream.logBufferLevel(),r.alreadyRead=r.size,r;if(0===a)return null;n.debug("ISOFile","Getting sample #"+t+" partial data (alreadyRead: "+r.alreadyRead+" offset: "+(r.offset+r.alreadyRead-i.fileStart)+" read size: "+a+" full size: "+r.size+")"),d.memcpy(r.data.buffer,r.alreadyRead,i,r.offset+r.alreadyRead-i.fileStart,a),r.alreadyRead+=a,i.usedBytes+=a,this.stream.logBufferLevel()}},g.prototype.releaseSample=function(e,t){var i=e.samples[t];return i.data?(this.samplesDataSize-=i.size,i.data=null,i.alreadyRead=0,i.size):0},g.prototype.getAllocatedSampleDataSize=function(){return this.samplesDataSize},g.prototype.getCodecs=function(){var e,t="";for(e=0;e<this.moov.traks.length;e++){e>0&&(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;t<this.moov.mvex.trexs.length;t++){var i=this.moov.mvex.trexs[t];if(i.track_id==e)return i}return null},g.prototype.getTrackById=function(e){if(void 0===this.moov)return null;for(var t=0;t<this.moov.traks.length;t++){var i=this.moov.traks[t];if(i.tkhd.track_id==e)return i}return null},g.prototype.items=[],g.prototype.entity_groups=[],g.prototype.itemsDataSize=0,g.prototype.flattenItemInfo=function(){var e,t,i,r=this.items,s=this.entity_groups,a=this.meta;if(null!=a&&void 0!==a.hdlr&&void 0!==a.iinf){for(e=0;e<a.iinf.item_infos.length;e++)(i={}).id=a.iinf.item_infos[e].item_ID,r[i.id]=i,i.ref_to=[],i.name=a.iinf.item_infos[e].item_name,a.iinf.item_infos[e].protection_index>0&&(i.protection=a.ipro.protections[a.iinf.item_infos[e].protection_index-1]),a.iinf.item_infos[e].item_type?i.type=a.iinf.item_infos[e].item_type:i.type="mime",i.content_type=a.iinf.item_infos[e].content_type,i.content_encoding=a.iinf.item_infos[e].content_encoding;if(a.grpl)for(e=0;e<a.grpl.boxes.length;e++)entity_group={},entity_group.id=a.grpl.boxes[e].group_id,entity_group.entity_ids=a.grpl.boxes[e].entity_ids,entity_group.type=a.grpl.boxes[e].type,s[entity_group.id]=entity_group;if(a.iloc)for(e=0;e<a.iloc.items.length;e++){var o=a.iloc.items[e];switch(i=r[o.item_ID],0!==o.data_reference_index&&(n.warn("Item storage with reference to other files: not supported"),i.source=a.dinf.boxes[o.data_reference_index-1]),o.construction_method){case 0:break;case 1:case 2:n.warn("Item storage with construction_method : not supported")}for(i.extents=[],i.size=0,t=0;t<o.extents.length;t++)i.extents[t]={},i.extents[t].offset=o.extents[t].extent_offset+o.base_offset,i.extents[t].length=o.extents[t].extent_length,i.extents[t].alreadyRead=0,i.size+=i.extents[t].length}if(a.pitm&&(r[a.pitm.item_id].primary=!0),a.iref)for(e=0;e<a.iref.references.length;e++){var d=a.iref.references[e];for(t=0;t<d.references.length;t++)r[d.from_item_ID].ref_to.push({type:d.type,id:d.references[t]})}if(a.iprp)for(var l=0;l<a.iprp.ipmas.length;l++){var c=a.iprp.ipmas[l];for(e=0;e<c.associations.length;e++){var u=c.associations[e];if((i=r[u.id])||(i=s[u.id]),i)for(void 0===i.properties&&(i.properties={},i.properties.boxes=[]),t=0;t<u.props.length;t++){var h=u.props[t];if(h.property_index>0&&h.property_index-1<a.iprp.ipco.boxes.length){var f=a.iprp.ipco.boxes[h.property_index-1];i.properties[f.type]=f,i.properties.boxes.push(f)}}}}}},g.prototype.getItem=function(e){var t,i;if(!this.meta)return null;if(!(i=this.items[e]).data&&i.size)i.data=new Uint8Array(i.size),i.alreadyRead=0,this.itemsDataSize+=i.size,n.debug("ISOFile","Allocating item #"+e+" of size "+i.size+" (total: "+this.itemsDataSize+")");else if(i.alreadyRead===i.size)return i;for(var r=0;r<i.extents.length;r++){var s=i.extents[r];if(s.alreadyRead!==s.length){var a=this.stream.findPosition(!0,s.offset+s.alreadyRead,!1);if(!(a>-1))return null;var o=(t=this.stream.buffers[a]).byteLength-(s.offset+s.alreadyRead-t.fileStart);if(!(s.length-s.alreadyRead<=o))return n.debug("ISOFile","Getting item #"+e+" extent #"+r+" partial data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-t.fileStart)+" read size: "+o+" full extent size: "+s.length+" full item size: "+i.size+")"),d.memcpy(i.data.buffer,i.alreadyRead,t,s.offset+s.alreadyRead-t.fileStart,o),s.alreadyRead+=o,i.alreadyRead+=o,t.usedBytes+=o,this.stream.logBufferLevel(),null;n.debug("ISOFile","Getting item #"+e+" extent #"+r+" 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: "+i.size+")"),d.memcpy(i.data.buffer,i.alreadyRead,t,s.offset+s.alreadyRead-t.fileStart,s.length-s.alreadyRead),t.usedBytes+=s.length-s.alreadyRead,this.stream.logBufferLevel(),i.alreadyRead+=s.length-s.alreadyRead,s.alreadyRead=s.length}}return i.alreadyRead===i.size?i: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 i=0;i<t.extents.length;i++){t.extents[i].alreadyRead=0}return t.size}return 0},g.prototype.processItems=function(e){for(var t in this.items){var i=this.items[t];this.getItem(i.id),e&&!i.sent&&(e(i),i.sent=!0,i.data=null)}},g.prototype.hasItem=function(e){for(var t in this.items){var i=this.items[t];if(i.name===e)return i.id}return-1},g.prototype.getMetaHandler=function(){return this.meta?this.meta.hdlr.handler:null},g.prototype.getPrimaryItem=function(){return this.meta&&this.meta.pitm?this.getItem(this.meta.pitm.item_id):null},g.prototype.itemToFragmentedTrackFile=function(e){var t=e||{},i=null;if(null==(i=t.itemId?this.getItem(t.itemId):this.getPrimaryItem()))return null;var r=new g;r.discardMdatData=!1;var s={type:i.type,description_boxes:i.properties.boxes};i.properties.ispe&&(s.width=i.properties.ispe.image_width,s.height=i.properties.ispe.image_height);var a=r.addTrack(s);return a?(r.addSample(a,i.data),r):null},g.prototype.write=function(e){for(var t=0;t<this.boxes.length;t++)this.boxes[t].write(e)},g.prototype.createFragment=function(e,t,i){var r=this.getTrackById(e),s=this.getSample(r,t);if(null==s)return this.setNextSeekPositionFromSample(r.samples[t]),null;var a=i||new d;a.endianness=d.BIG_ENDIAN;var o=this.createSingleSampleMoof(s);o.write(a),o.trafs[0].truns[0].data_offset=o.size+8,n.debug("MP4Box","Adjusting data_offset with new value "+o.trafs[0].truns[0].data_offset),a.adjustUint32(o.trafs[0].truns[0].data_offset_position,o.trafs[0].truns[0].data_offset);var l=new h.mdatBox;return l.data=s.data,l.write(a),a},g.writeInitializationSegment=function(e,t,i,r){var s;n.debug("ISOFile","Generating initialization segment");var a=new d;a.endianness=d.BIG_ENDIAN,e.write(a);var o=t.add("mvex");for(i&&o.add("mehd").set("fragment_duration",i),s=0;s<t.traks.length;s++)o.add("trex").set("track_id",t.traks[s].tkhd.track_id).set("default_sample_description_index",1).set("default_sample_duration",r).set("default_sample_size",0).set("default_sample_flags",65536);return t.write(a),a.buffer},g.prototype.save=function(e){var t=new d;t.endianness=d.BIG_ENDIAN,this.write(t),t.save(e)},g.prototype.getBuffer=function(){var e=new d;return e.endianness=d.BIG_ENDIAN,this.write(e),e.buffer},g.prototype.initializeSegmentation=function(){var e,t,i,r;for(null===this.onSegment&&n.warn("MP4Box","No segmentation callback set!"),this.isFragmentationInitialized||(this.isFragmentationInitialized=!0,this.nextMoofNumber=0,this.resetTables()),t=[],e=0;e<this.fragmentedTracks.length;e++){var s=new h.moovBox;s.mvhd=this.moov.mvhd,s.boxes.push(s.mvhd),i=this.getTrackById(this.fragmentedTracks[e].id),s.boxes.push(i),s.traks.push(i),(r={}).id=i.tkhd.track_id,r.user=this.fragmentedTracks[e].user,r.buffer=g.writeInitializationSegment(this.ftyp,s,this.moov.mvex&&this.moov.mvex.mehd?this.moov.mvex.mehd.fragment_duration:void 0,this.moov.traks[e].samples.length>0?this.moov.traks[e].samples[0].duration:0),t.push(r)}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<this.boxes.length;t++)if(this.boxes[t]){var i=e.indent;e.indent+=" ",this.boxes[t].print(e),e.indent=i}},g.prototype.print=function(e){e.indent="";for(var t=0;t<this.boxes.length;t++)this.boxes[t]&&this.boxes[t].print(e)},h.mvhdBox.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+"timescale: "+this.timescale),e.log(e.indent+"duration: "+this.duration),e.log(e.indent+"rate: "+this.rate),e.log(e.indent+"volume: "+(this.volume>>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 i=void 0===e||e,r=new g(t);return r.discardMdatData=!i,r}};t.createFile=y.createFile}));function zr(e){return e.reduce(((e,t)=>256*e+t))}function Nr(e){const t=[101,103,119,99],i=e.length-28,r=e.slice(i,i+t.length);return t.every(((e,t)=>e===r[t]))}Rr.Log,Rr.MP4BoxStream,Rr.DataStream,Rr.MultiBufferStream,Rr.MPEG4DescriptorParser,Rr.BoxParser,Rr.XMLSubtitlein4Parser,Rr.Textin4Parser,Rr.ISOFile,Rr.createFile;class Gr{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<this.u))return this.a&&this.s?(this.a.set(t,this.r),this.s.parse(null,this.r,t.byteLength),this.a.slice(this.r,this.r+t.byteLength)):(console.error("video_error_2"),this.d=!0,e);Nr(t)&&this.c++}else{const i=function(e,t){const i=function(e,t){for(let i=0;i<e.byteLength-t.length;i++)for(let r=0;r<t.length&&e[i+r]===t[r];r++)if(r===t.length-1)return i;return null}(e,t);if(i){const t=zr(e.slice(i+16,i+16+8));return[t,zr(e.slice(i+24,i+24+8)),function(e){return e.map((e=>~e))}(e.slice(i+32,i+32+t))]}return null}(t,this.t);if(!i)return e;const r=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(r instanceof Error)return console.error(r.message),this.d=!0,e;this.A=!0,this.u=i[1],Nr(t)&&this.c++,WebAssembly.instantiate(i[2],r).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 Or=16,Hr=[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],Vr=[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 $r(e){const t=[];for(let i=0,r=e.length;i<r;i+=2)t.push(parseInt(e.substr(i,2),16));return t}function Wr(e){return e.map((e=>1===(e=e.toString(16)).length?"0"+e:e)).join("")}function Yr(e){const t=[];for(let i=0,r=e.length;i<r;i++){const r=e.codePointAt(i);if(r<=127)t.push(r);else if(r<=2047)t.push(192|r>>>6),t.push(128|63&r);else if(r<=55295||r>=57344&&r<=65535)t.push(224|r>>>12),t.push(128|r>>>6&63),t.push(128|63&r);else{if(!(r>=65536&&r<=1114111))throw t.push(r),new Error("input is not supported");i++,t.push(240|r>>>18&28),t.push(128|r>>>12&63),t.push(128|r>>>6&63),t.push(128|63&r)}}return t}function qr(e){const t=[];for(let i=0,r=e.length;i<r;i++)e[i]>=240&&e[i]<=247?(t.push(String.fromCodePoint(((7&e[i])<<18)+((63&e[i+1])<<12)+((63&e[i+2])<<6)+(63&e[i+3]))),i+=3):e[i]>=224&&e[i]<=239?(t.push(String.fromCodePoint(((15&e[i])<<12)+((63&e[i+1])<<6)+(63&e[i+2]))),i+=2):e[i]>=192&&e[i]<=223?(t.push(String.fromCodePoint(((31&e[i])<<6)+(63&e[i+1]))),i++):t.push(String.fromCodePoint(e[i]));return t.join("")}function jr(e,t){const i=31&t;return e<<i|e>>>32-i}function Kr(e){return(255&Hr[e>>>24&255])<<24|(255&Hr[e>>>16&255])<<16|(255&Hr[e>>>8&255])<<8|255&Hr[255&e]}function Xr(e){return e^jr(e,2)^jr(e,10)^jr(e,18)^jr(e,24)}function Zr(e){return e^jr(e,13)^jr(e,23)}function Jr(e,t,i){const r=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],r[t]=s[0]<<24|s[1]<<16|s[2]<<8|s[3];for(let e,t=0;t<32;t+=4)e=r[1]^r[2]^r[3]^i[t+0],r[0]^=Xr(Kr(e)),e=r[2]^r[3]^r[0]^i[t+1],r[1]^=Xr(Kr(e)),e=r[3]^r[0]^r[1]^i[t+2],r[2]^=Xr(Kr(e)),e=r[0]^r[1]^r[2]^i[t+3],r[3]^=Xr(Kr(e));for(let e=0;e<16;e+=4)t[e]=r[3-e/4]>>>24&255,t[e+1]=r[3-e/4]>>>16&255,t[e+2]=r[3-e/4]>>>8&255,t[e+3]=255&r[3-e/4]}function Qr(e,t,i){const r=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],r[t]=s[0]<<24|s[1]<<16|s[2]<<8|s[3];r[0]^=2746333894,r[1]^=1453994832,r[2]^=1736282519,r[3]^=2993693404;for(let e,i=0;i<32;i+=4)e=r[1]^r[2]^r[3]^Vr[i+0],t[i+0]=r[0]^=Zr(Kr(e)),e=r[2]^r[3]^r[0]^Vr[i+1],t[i+1]=r[1]^=Zr(Kr(e)),e=r[3]^r[0]^r[1]^Vr[i+2],t[i+2]=r[2]^=Zr(Kr(e)),e=r[0]^r[1]^r[2]^Vr[i+3],t[i+3]=r[3]^=Zr(Kr(e));if(0===i)for(let e,i=0;i<16;i++)e=t[i],t[i]=t[31-i],t[31-i]=e}function es(e,t,i){let{padding:r="pkcs#7",mode:s,iv:a=[],output:n="string"}=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("cbc"===s&&("string"==typeof a&&(a=$r(a)),16!==a.length))throw new Error("iv is invalid");if("string"==typeof t&&(t=$r(t)),16!==t.length)throw new Error("key is invalid");if(e="string"==typeof e?0!==i?Yr(e):$r(e):[...e],("pkcs#5"===r||"pkcs#7"===r)&&0!==i){const t=Or-e.length%Or;for(let i=0;i<t;i++)e.push(t)}const o=new Array(32);Qr(t,o,i);const d=[];let l=a,c=e.length,u=0;for(;c>=Or;){const t=e.slice(u,u+16),r=new Array(16);if("cbc"===s)for(let e=0;e<Or;e++)0!==i&&(t[e]^=l[e]);Jr(t,r,o);for(let e=0;e<Or;e++)"cbc"===s&&0===i&&(r[e]^=l[e]),d[u+e]=r[e];"cbc"===s&&(l=0!==i?r:t),c-=Or,u+=Or}if(("pkcs#5"===r||"pkcs#7"===r)&&0===i){const e=d.length,t=d[e-1];for(let i=1;i<=t;i++)if(d[e-i]!==t)throw new Error("padding is invalid");d.splice(e-t,t)}return"array"!==n?0!==i?Wr(d):qr(d):d}function ts(e){return e[3]|e[2]<<8|e[1]<<16|e[0]<<24}function is(e,t){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const r=e.byteLength;let s=5;for(;s<r;){let a=ts(e.slice(s,s+4));if(a>r)break;let n=e[s+4],o=!1;if(i?(n=n>>>1&63,o=[0,1,2,3,4,5,6,7,8,9,16,17,18,19,20,21].includes(n)):(n&=31,o=1===n||5===n),o){const i=es(e.slice(s+4+2,s+4+a),t,0,{padding:"none",output:"array"});e.set(i,s+4+2)}s=s+4+a}return e}const rs={init:0,findFirstStartCode:1,findSecondStartCode:2};class ss extends class{on(e,t,i){const r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:i}),this}once(e,t,i){const r=this;function s(){r.off(e,s);for(var a=arguments.length,n=new Array(a),o=0;o<a;o++)n[o]=arguments[o];t.apply(i,n)}return s._=t,this.on(e,s,i)}emit(e){const t=((this.e||(this.e={}))[e]||[]).slice();for(var i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];for(let e=0;e<t.length;e+=1)t[e].fn.apply(t[e].ctx,r);return this}off(e,t){const i=this.e||(this.e={});if(!e)return Object.keys(i).forEach((e=>{delete i[e]})),void delete this.e;const r=i[e],s=[];if(r&&t)for(let e=0,i=r.length;e<i;e+=1)r[e].fn!==t&&r[e].fn._!==t&&s.push(r[e]);return s.length?i[e]=s:delete i[e],this}}{constructor(e){super(),this.player=e,this.isDestroyed=!1,this.reset()}destroy(){this.isDestroyed=!1,this.off(),this.reset()}reset(){this.stats=rs.init,this.tempBuffer=new Uint8Array(0),this.parsedOffset=0,this.versionLayer=0}dispatch(e,t){let i=new Uint8Array(this.tempBuffer.length+e.length);for(i.set(this.tempBuffer,0),i.set(e,this.tempBuffer.length),this.tempBuffer=i;!this.isDestroyed;){if(this.state==rs.Init){let e=!1;for(;this.tempBuffer.length-this.parsedOffset>=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=rs.findFirstStartCode,this.fisrtStartCodeOffset=this.parsedOffset,this.parsedOffset+=2,e=!0;break}this.parsedOffset++}else this.parsedOffset++;if(e)continue;break}if(this.state==rs.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=rs.findSecondStartCode,this.secondStartCodeOffset=this.parsedOffset,this.parsedOffset+=2,e=!0;break}this.parsedOffset++}else this.parsedOffset++;if(e)continue;break}if(this.state==rs.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=rs.findFirstStartCode}}}}function as(e,t,i){for(let r=2;r<e.length;++r){const s=r-2,a=t[s%t.length],n=i[s%i.length];e[r]=e[r]^a^n}return e}function ns(e){return e[3]|e[2]<<8|e[1]<<16|e[0]<<24}function os(e,t,i){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const s=e.byteLength;let a=5;for(;a<s;){let n=ns(e.slice(a,a+4));if(n>s)break;let o=e[a+4],d=!1;if(r?(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 r=as(e.slice(a+4,a+4+n),t,i);e.set(r,a+4)}a=a+4+n}return e}function ds(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];if((t=t.filter(Boolean)).length<2)return t[0];const r=new Uint8Array(t.reduce(((e,t)=>e+t.byteLength),0));let s=0;return t.forEach((e=>{r.set(e,s),s+=e.byteLength})),r}class ls{constructor(e){this.destroys=[],this.proxy=this.proxy.bind(this),this.master=e}proxy(e,t,i){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(!e)return;if(Array.isArray(t))return t.map((t=>this.proxy(e,t,i,r)));e.addEventListener(t,i,r);const s=()=>{oi(e.removeEventListener)&&e.removeEventListener(t,i,r)};return this.destroys.push(s),s}destroy(){this.master.debug&&this.master.debug.log("Events","destroy"),this.destroys.forEach((e=>e())),this.destroys=[]}}class cs{static init(){cs.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 cs.types)cs.types.hasOwnProperty(e)&&(cs.types[e]=[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]);let e=cs.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,i=null,r=Array.prototype.slice.call(arguments,1),s=r.length;for(let e=0;e<s;e++)t+=r[e].byteLength;i=new Uint8Array(t),i[0]=t>>>24&255,i[1]=t>>>16&255,i[2]=t>>>8&255,i[3]=255&t,i.set(e,4);let a=8;for(let e=0;e<s;e++)i.set(r[e],a),a+=r[e].byteLength;return i}static generateInitSegment(e){let t=cs.box(cs.types.ftyp,cs.constants.FTYP),i=cs.moov(e),r=new Uint8Array(t.byteLength+i.byteLength);return r.set(t,0),r.set(i,t.byteLength),r}static moov(e){let t=cs.mvhd(e.timescale,e.duration),i=cs.trak(e),r=cs.mvex(e);return cs.box(cs.types.moov,t,i,r)}static mvhd(e,t){return cs.box(cs.types.mvhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,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 cs.box(cs.types.trak,cs.tkhd(e),cs.mdia(e))}static tkhd(e){let t=e.id,i=e.duration,r=e.presentWidth,s=e.presentHeight;return cs.box(cs.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,i>>>24&255,i>>>16&255,i>>>8&255,255&i,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,r>>>8&255,255&r,0,0,s>>>8&255,255&s,0,0]))}static mdia(e){return cs.box(cs.types.mdia,cs.mdhd(e),cs.hdlr(e),cs.minf(e))}static mdhd(e){let t=e.timescale,i=e.duration;return cs.box(cs.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,i>>>24&255,i>>>16&255,i>>>8&255,255&i,85,196,0,0]))}static hdlr(e){let t=null;return t="audio"===e.type?cs.constants.HDLR_AUDIO:cs.constants.HDLR_VIDEO,cs.box(cs.types.hdlr,t)}static minf(e){let t=null;return t="audio"===e.type?cs.box(cs.types.smhd,cs.constants.SMHD):cs.box(cs.types.vmhd,cs.constants.VMHD),cs.box(cs.types.minf,t,cs.dinf(),cs.stbl(e))}static dinf(){return cs.box(cs.types.dinf,cs.box(cs.types.dref,cs.constants.DREF))}static stbl(e){return cs.box(cs.types.stbl,cs.stsd(e),cs.box(cs.types.stts,cs.constants.STTS),cs.box(cs.types.stsc,cs.constants.STSC),cs.box(cs.types.stsz,cs.constants.STSZ),cs.box(cs.types.stco,cs.constants.STCO))}static stsd(e){return"audio"===e.type?"mp3"===e.audioType?cs.box(cs.types.stsd,cs.constants.STSD_PREFIX,cs.mp3(e)):cs.box(cs.types.stsd,cs.constants.STSD_PREFIX,cs.mp4a(e)):"avc"===e.videoType?cs.box(cs.types.stsd,cs.constants.STSD_PREFIX,cs.avc1(e)):cs.box(cs.types.stsd,cs.constants.STSD_PREFIX,cs.hvc1(e))}static mp3(e){let t=e.channelCount,i=e.audioSampleRate,r=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,i>>>8&255,255&i,0,0]);return cs.box(cs.types[".mp3"],r)}static mp4a(e){let t=e.channelCount,i=e.audioSampleRate,r=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,i>>>8&255,255&i,0,0]);return cs.box(cs.types.mp4a,r,cs.esds(e))}static esds(e){let t=e.config||[],i=t.length,r=new Uint8Array([0,0,0,0,3,23+i,0,1,0,4,15+i,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([i]).concat(t).concat([6,1,2]));return cs.box(cs.types.esds,r)}static avc1(e){let t=e.avcc;const i=e.codecWidth,r=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,i>>>8&255,255&i,r>>>8&255,255&r,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 cs.box(cs.types.avc1,s,cs.box(cs.types.avcC,t))}static hvc1(e){let t=e.avcc;const i=e.codecWidth,r=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,i>>>8&255,255&i,r>>>8&255,255&r,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 cs.box(cs.types.hvc1,s,cs.box(cs.types.hvcC,t))}static mvex(e){return cs.box(cs.types.mvex,cs.trex(e))}static trex(e){let t=e.id,i=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 cs.box(cs.types.trex,i)}static moof(e,t){return cs.box(cs.types.moof,cs.mfhd(e.sequenceNumber),cs.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 cs.box(cs.types.mfhd,t)}static traf(e,t){let i=e.id,r=cs.box(cs.types.tfhd,new Uint8Array([0,0,0,0,i>>>24&255,i>>>16&255,i>>>8&255,255&i])),s=cs.box(cs.types.tfdt,new Uint8Array([0,0,0,0,t>>>24&255,t>>>16&255,t>>>8&255,255&t])),a=cs.sdtp(e),n=cs.trun(e,a.byteLength+16+16+8+16+8+8);return cs.box(cs.types.traf,r,s,n,a)}static sdtp(e){let t=new Uint8Array(5),i=e.flags;return t[4]=i.isLeading<<6|i.dependsOn<<4|i.isDependedOn<<2|i.hasRedundancy,cs.box(cs.types.sdtp,t)}static trun(e,t){let i=new Uint8Array(28);t+=36,i.set([0,0,15,1,0,0,0,1,t>>>24&255,t>>>16&255,t>>>8&255,255&t],0);let r=e.duration,s=e.size,a=e.flags,n=e.cts;return i.set([r>>>24&255,r>>>16&255,r>>>8&255,255&r,s>>>24&255,s>>>16&255,s>>>8&255,255&s,a.isLeading<<2|a.dependsOn,a.isDependedOn<<6|a.hasRedundancy<<4|a.isNonSync,0,0,n>>>24&255,n>>>16&255,n>>>8&255,255&n],12),cs.box(cs.types.trun,i)}static mdat(e){return cs.box(cs.types.mdat,e)}}cs.init();var us,hs=Rt((function(e){e.exports=function(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e},e.exports.__esModule=!0,e.exports.default=e.exports}));(us=hs)&&us.__esModule&&Object.prototype.hasOwnProperty.call(us,"default")&&us.default;const fs=[44100,48e3,32e3,0],ps=[22050,24e3,16e3,0],_s=[11025,12e3,8e3,0],ms=[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1],gs=[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1],ys=[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1];function bs(e){if(e.length<4)return void console.error("Invalid MP3 packet, header missing!");let t=new Uint8Array(e.buffer),i=null;if(255!==t[0])return void console.error("Invalid MP3 packet, first byte != 0xFF ");let r=t[1]>>>3&3,s=(6&t[1])>>1,a=(240&t[2])>>>4,n=(12&t[2])>>>2,o=3!==(t[3]>>>6&3)?2:1,d=0,l=0;switch(r){case 0:d=_s[n];break;case 2:d=ps[n];break;case 3:d=fs[n]}switch(s){case 1:a<ys.length&&(l=ys[a]);break;case 2:a<gs.length&&(l=gs[a]);break;case 3:a<ms.length&&(l=ms[a])}return i={bitRate:l,samplingRate:d,channelCount:o,codec:"mp3",originalCodec:"mp3",audioType:"mp3"},i}const Ss=3,vs=4,ws=6,As=15,Us=17,Es=129,xs=135,Bs=21,Ts=134,Cs=27,ks=36;class Is{constructor(){this.slices=[],this.total_length=0,this.expected_length=0,this.random_access_indicator=0}}class Ds{constructor(){this.pid=null,this.data=null,this.stream_type=null,this.random_access_indicator=null}}class Ls{constructor(){this.pid=null,this.stream_id=null,this.len=null,this.data=null,this.pts=null,this.nearest_pts=null,this.dts=null}}const Fs=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];class Ps{constructor(){this.mimeType=null,this.duration=null,this.hasAudio=null,this.hasVideo=null,this.audioCodec=null,this.videoCodec=null,this.audioDataRate=null,this.videoDataRate=null,this.audioSampleRate=null,this.audioChannelCount=null,this.width=null,this.height=null,this.fps=null,this.profile=null,this.level=null,this.refFrames=null,this.chromaFormat=null,this.sarNum=null,this.sarDen=null,this.metadata=null,this.segments=null,this.segmentCount=null,this.hasKeyframesIndex=null,this.keyframesIndex=null}isComplete(){let e=!1===this.hasAudio||!0===this.hasAudio&&null!=this.audioCodec&&null!=this.audioSampleRate&&null!=this.audioChannelCount,t=!1===this.hasVideo||!0===this.hasVideo&&null!=this.videoCodec&&null!=this.width&&null!=this.height&&null!=this.fps&&null!=this.profile&&null!=this.level&&null!=this.refFrames&&null!=this.chromaFormat&&null!=this.sarNum&&null!=this.sarDen;return null!=this.mimeType&&e&&t}isSeekable(){return!0===this.hasKeyframesIndex}getNearestKeyframe(e){if(null==this.keyframesIndex)return null;let t=this.keyframesIndex,i=this._search(t.times,e);return{index:i,milliseconds:t.times[i],fileposition:t.filepositions[i]}}_search(e,t){let i=0,r=e.length-1,s=0,a=0,n=r;for(t<e[0]&&(i=0,a=n+1);a<=n;){if(s=a+Math.floor((n-a)/2),s===r||t>=e[s]&&t<e[s+1]){i=s;break}e[s]<t?a=s+1:n=s-1}return i}}class Ms{constructor(e){let t=null,i=e.audio_object_type,r=e.audio_object_type,s=e.sampling_freq_index,a=e.channel_config,n=0,o=navigator.userAgent.toLowerCase();-1!==o.indexOf("firefox")?s>=6?(r=5,t=new Array(4),n=s-3):(r=2,t=new Array(2),n=s):-1!==o.indexOf("android")?(r=2,t=new Array(2),n=s):(r=5,n=s,t=new Array(4),s>=6?n=s-3:1===a&&(r=2,t=new Array(2),n=s)),t[0]=r<<3,t[0]|=(15&s)>>>1,t[1]=(15&s)<<7,t[1]|=(15&a)<<3,5===r&&(t[1]|=(15&n)>>>1,t[2]=(1&n)<<7,t[2]|=8,t[3]=0),this.config=t,this.sampling_rate=Fs[s],this.sampling_index=s,this.channel_count=a,this.object_type=r,this.original_object_type=i,this.codec_mimetype="mp4a.40."+r,this.original_codec_mimetype="mp4a.40."+i}}Date.now||(Date.now=function(){return(new Date).getTime()}),function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=[],s=[],a={},n=new AbortController,o=null,m=null,g=null,v=null,_e=!1,me=null,Ne=null,We=!1,Ye=!1,je=!!_i(i),Xe=!1,st=null,ut=null,ht=null,ft=[],pt=null,vt=null,wt=0,Et=0,Rt=null,zt=null,Nt=0,Gt=0,Wt=!1,Kt=!1,ti=!1,bi=null,Si=null,vi=null,wi=!1,xi=!0,Ni=()=>{const e=fi();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&&(a={hasInit:!1,isEmitInfo:!1,offscreenCanvas:null,offscreenCanvasCtx:null,decoder:new VideoDecoder({output:function(e){if(a.isEmitInfo||(ar.debug.log("worker","Webcodecs Video Decoder initSize"),postMessage({cmd:A,w:e.codedWidth,h:e.codedHeight}),a.isEmitInfo=!0,a.offscreenCanvas=new OffscreenCanvas(e.codedWidth,e.codedHeight),a.offscreenCanvasCtx=a.offscreenCanvas.getContext("2d")),oi(e.createImageBitmap))e.createImageBitmap().then((t=>{a.offscreenCanvasCtx.drawImage(t,0,0,e.codedWidth,e.codedHeight);let i=a.offscreenCanvas.transferToImageBitmap();postMessage({cmd:U,buffer:i,delay:ar.delay,ts:0},[i]),ci(e)}));else{a.offscreenCanvasCtx.drawImage(e,0,0,e.codedWidth,e.codedHeight);let t=a.offscreenCanvas.transferToImageBitmap();postMessage({cmd:U,buffer:t,delay:ar.delay,ts:0},[t]),ci(e)}},error:function(e){ar.debug.error("worker","VideoDecoder error",e)}}),decode:function(e,t,i){const r=e[0]>>4==1;if(a.hasInit){const i=new EncodedVideoChunk({data:e.slice(5),timestamp:t,type:r?ot:dt});a.decoder.decode(i)}else if(r&&0===e[1]){const t=15&e[0];postMessage({cmd:k,code:t});const i=new Uint8Array(e);postMessage({cmd:I,buffer:i,codecId:t},[i.buffer]);let r=null,s=null;const n=e.slice(5);t===Te?(s=Bi(n),r={codec:s.codec,description:n}):t===Ce&&(s=Vi(n),r={codec:s.codec,description:n}),s&&s.codecWidth&&s.codecHeight&&(r.codedHeight=s.codecHeight,r.codedWidth=s.codecWidth);try{a.decoder.configure(r),a.hasInit=!0}catch(e){ar.debug.log("worker","VideoDecoder configure error",e.code,e)}}},reset(){a.hasInit=!1,a.isEmitInfo=!1,a.offscreenCanvas=null,a.offscreenCanvasCtx=null}});let Gi=function(){if(wi=!0,ar.fetchStatus!==Tt||mi(ar._opt.isChrome)){if(n)try{n.abort(),n=null}catch(e){ar.debug.log("worker","abort catch",e)}}else n=null,ar.debug.log("worker",`abort() and not abortController.abort() _status is ${ar.fetchStatus} and _isChrome is ${ar._opt.isChrome}`)},$i={init(){$i.lastBuf=null,$i.vps=null,$i.sps=null,$i.pps=null,$i.streamType=null,$i.localDts=0,$i.isSendSeqHeader=!1},destroy(){$i.lastBuf=null,$i.vps=null,$i.sps=null,$i.pps=null,$i.streamType=null,$i.localDts=0,$i.isSendSeqHeader=!1},dispatch(e){const t=new Uint8Array(e);$i.extractNALu$2(t)},getNaluDts(){let e=$i.localDts;return $i.localDts=$i.localDts+40,e},getNaluAudioDts(){const e=ar._opt.sampleRate,t=ar._opt.audioBufferSize;return $i.localDts+parseInt(t/e*1e3)},extractNALu(e){let t,i,r=0,s=e.byteLength,a=0,n=[];for(;r<s;)switch(t=e[r++],a){case 0:0===t&&(a=1);break;case 1:a=0===t?2:0;break;case 2:case 3:0===t?a=3:1===t&&r<s?(i&&n.push(e.subarray(i,r-a-1)),i=r,a=0):a=0}return i&&n.push(e.subarray(i,s)),n},extractNALu$2(e){let t=null;if(!e||e.byteLength<1)return;$i.lastBuf?(t=new Uint8Array(e.byteLength+$i.lastBuf.length),t.set($i.lastBuf),t.set(new Uint8Array(e),$i.lastBuf.length)):t=new Uint8Array(e);let i=0,r=-1,s=-2;const a=new Array;for(let e=0;e<t.length;e+=2){const i=t[e],n=t[e+1];0==r&&0==i&&0==n?a.push(e-1):1==n&&0==i&&0==r&&0==s&&a.push(e-2),s=i,r=n}if(a.length>1)for(let e=0;e<a.length-1;++e){const r=t.subarray(a[e],a[e+1]+1);$i.handleNALu(r),i=a[e+1]}else i=a[0];if(0!=i&&i<t.length)$i.lastBuf=t.subarray(i);else{$i.lastBuf||($i.lastBuf=t);const i=new Uint8Array($i.lastBuf.length+e.byteLength);i.set($i.lastBuf),i.set(new Uint8Array(e),$i.lastBuf.length),$i.lastBuf=i}},handleNALu(e){e.byteLength<=4||(e=e.slice(4),$i.handleVideoNalu(e))},handleVideoNalu(e){if($i.streamType||($i.streamType=di(e),bi=$i.streamType===De),$i.streamType===Ie){const t=$i.handleAddNaluStartCode(e),i=$i.extractNALu(t);if(0===i.length)return void ar.debug.warn("worker","handleVideoNalu","h264 naluList.length === 0");const r=[];if(i.forEach((e=>{const t=Di(e);t===ze||t===Re?$i.handleVideoH264Nalu(e):Fi(t)&&r.push(e)})),1===r.length)$i.handleVideoH264Nalu(r[0]);else{if(Mi(r)){const e=Di(r[0]),t=Pi(e);$i.handleVideoH264NaluList(r,t,e)}else r.forEach((e=>{$i.handleVideoH264Nalu(e)}))}}else if($i.streamType===De)if(ar._opt.nakedFlowH265DemuxUseNew){const t=$i.handleAddNaluStartCode(e),i=$i.extractNALu(t);if(0===i.length)return void ar.debug.warn("worker","handleVideoNalu","h265 naluList.length === 0");const r=[];if(i.forEach((e=>{const t=ji(e);t===it||t===et||t===Je?$i.handleVideoH265Nalu(e):Xi(t)&&r.push(e)})),1===r.length)$i.handleVideoH265Nalu(r[0]);else{if(Ji(r)){const e=ji(r[0]),t=Zi(e);$i.handleVideoH265NaluList(r,t,e)}else r.forEach((e=>{$i.handleVideoH265Nalu(e)}))}}else{ji(e)===it?$i.extractH265PPS(e):$i.handleVideoH265Nalu(e)}},extractH264PPS(e){const t=$i.handleAddNaluStartCode(e);$i.extractNALu(t).forEach((e=>{Li(Di(e))?$i.extractH264SEI(e):$i.handleVideoH264Nalu(e)}))},extractH265PPS(e){const t=$i.handleAddNaluStartCode(e);$i.extractNALu(t).forEach((e=>{Ki(ji(e))?$i.extractH265SEI(e):$i.handleVideoH265Nalu(e)}))},extractH264SEI(e){const t=$i.handleAddNaluStartCode(e);$i.extractNALu(t).forEach((e=>{$i.handleVideoH264Nalu(e)}))},extractH265SEI(e){const t=$i.handleAddNaluStartCode(e);$i.extractNALu(t).forEach((e=>{$i.handleVideoH265Nalu(e)}))},handleAddNaluStartCode(e){const t=[0,0,0,1],i=new Uint8Array(e.length+t.length);return i.set(t),i.set(e,t.length),i},handleVideoH264Nalu(e){const t=Di(e);switch(t){case Re:$i.sps=e;break;case ze:$i.pps=e}if($i.isSendSeqHeader){if($i.sps&&$i.pps){const e=Ti({sps:$i.sps,pps:$i.pps}),t=$i.getNaluDts();ar.decode(e,{type:te,ts:t,isIFrame:!0,cts:0}),$i.sps=null,$i.pps=null}if(Fi(t)){const i=Pi(t),r=$i.getNaluDts(),s=ki(e,i);$i.doDecode(s,{type:te,ts:r,isIFrame:i,cts:0})}else ar.debug.warn("worker",`handleVideoH264Nalu Avc Seq Head is ${t}`)}else if($i.sps&&$i.pps){$i.isSendSeqHeader=!0;const e=Ti({sps:$i.sps,pps:$i.pps});ar.decode(e,{type:te,ts:0,isIFrame:!0,cts:0}),$i.sps=null,$i.pps=null}},handleVideoH264NaluList(e,t,i){if($i.isSendSeqHeader){const r=$i.getNaluDts(),s=Ii(e.reduce(((e,t)=>{const i=Zt(e),r=Zt(t),s=new Uint8Array(i.byteLength+r.byteLength);return s.set(i,0),s.set(r,i.byteLength),s})),t);$i.doDecode(s,{type:te,ts:r,isIFrame:t,cts:0}),ar.debug.log("worker",`handleVideoH264NaluList list size is ${e.length} package length is ${s.byteLength} isIFrame is ${t},nalu type is ${i}, dts is ${r}`)}else ar.debug.warn("worker","handleVideoH264NaluList isSendSeqHeader is false")},handleVideoH265Nalu(e){const t=ji(e);switch(t){case Je:$i.vps=e;break;case et:$i.sps=e;break;case it:$i.pps=e}if($i.isSendSeqHeader){if($i.vps&&$i.sps&&$i.pps){const e=Wi({vps:$i.vps,sps:$i.sps,pps:$i.pps}),t=$i.getNaluDts();ar.decode(e,{type:te,ts:t,isIFrame:!0,cts:0}),$i.vps=null,$i.sps=null,$i.pps=null}if(Xi(t)){const i=Zi(t),r=$i.getNaluDts(),s=Yi(e,i);$i.doDecode(s,{type:te,ts:r,isIFrame:i,cts:0})}else ar.debug.warn("work",`handleVideoH265Nalu HevcSeqHead is ${t}`)}else if($i.vps&&$i.sps&&$i.pps){$i.isSendSeqHeader=!0;const e=Wi({vps:$i.vps,sps:$i.sps,pps:$i.pps});ar.decode(e,{type:te,ts:0,isIFrame:!0,cts:0}),$i.vps=null,$i.sps=null,$i.pps=null}},handleVideoH265NaluList(e,t,i){if($i.isSendSeqHeader){const r=$i.getNaluDts(),s=qi(e.reduce(((e,t)=>{const i=Zt(e),r=Zt(t),s=new Uint8Array(i.byteLength+r.byteLength);return s.set(i,0),s.set(r,i.byteLength),s})),t);$i.doDecode(s,{type:te,ts:r,isIFrame:t,cts:0}),ar.debug.log("worker",`handleVideoH265NaluList list size is ${e.length} package length is ${s.byteLength} isIFrame is ${t},nalu type is ${i}, dts is ${r}`)}else ar.debug.warn("worker","handleVideoH265NaluList isSendSeqHeader is false")},doDecode(e,t){ar.calcNetworkDelay(t.ts),t.isIFrame&&ar.calcIframeIntervalTimestamp(t.ts),ar.decode(e,t)}},tr={LOG_NAME:"worker fmp4Demuxer",mp4Box:null,offset:0,videoTrackId:null,audioTrackId:null,isHevc:!1,listenMp4Box(){tr.mp4Box=Rr.createFile(),tr.mp4Box.onReady=tr.onReady,tr.mp4Box.onError=tr.onError,tr.mp4Box.onSamples=tr.onSamples},initTransportDescarmber(){tr.transportDescarmber=new Gr},_getSeqHeader(e){const t=tr.mp4Box.getTrackById(e.id);for(const e of t.mdia.minf.stbl.stsd.entries)if(e.avcC||e.hvcC){const t=new Rr.DataStream(void 0,0,Rr.DataStream.BIG_ENDIAN);let i=[];e.avcC?(e.avcC.write(t),i=[23,0,0,0,0]):(tr.isHevc=!0,bi=!0,e.hvcC.write(t),i=[28,0,0,0,0]);const r=new Uint8Array(t.buffer,8),s=new Uint8Array(i.length+r.length);return s.set(i,0),s.set(r,i.length),s}return null},onReady(e){ar.debug.log(tr.LOG_NAME,"onReady()");const t=e.videoTracks[0],i=e.audioTracks[0];if(t){tr.videoTrackId=t.id;const e=tr._getSeqHeader(t);e&&(ar.debug.log(tr.LOG_NAME,"seqHeader"),ar.decodeVideo(e,0,!0,0)),tr.mp4Box.setExtractionOptions(t.id)}if(i&&ar._opt.hasAudio){tr.audioTrackId=i.id;const e=i.audio||{},t=Ot.indexOf(e.sample_rate),r=i.codec.replace("mp4a.40.","");tr.mp4Box.setExtractionOptions(i.id);const s=Ht({profile:parseInt(r,10),sampleRate:t,channel:e.channel_count});ar.debug.log(tr.LOG_NAME,"aacADTSHeader"),ar.decodeAudio(s,0)}tr.mp4Box.start()},onError(e){ar.debug.error(tr.LOG_NAME,"mp4Box onError",e)},onSamples(e,t,i){if(e===tr.videoTrackId)for(const t of i){const i=t.data,r=t.is_sync,s=1e3*t.cts/t.timescale;t.duration,t.timescale,r&&ar.calcIframeIntervalTimestamp(s);let a=null;a=tr.isHevc?qi(i,r):Ii(i,r),ar.decode(a,{type:te,ts:s,isIFrame:r,cts:0}),tr.mp4Box.releaseUsedSamples(e,t.number)}else if(e===tr.audioTrackId){if(ar._opt.hasAudio)for(const t of i){const i=t.data,r=1e3*t.cts/t.timescale;t.duration,t.timescale;const s=new Uint8Array(i.byteLength+2);s.set([175,1],0),s.set(i,2),ar.decode(s,{type:ee,ts:r,isIFrame:!1,cts:0}),tr.mp4Box.releaseUsedSamples(e,t.number)}}else ar.debug.warn(tr.LOG_NAME,"onSamples() trackId error",e)},dispatch(e){let t=new Uint8Array(e);tr.transportDescarmber&&(t=tr.transportDescarmber.transport(t)),t.buffer.fileStart=tr.offset,tr.offset+=t.byteLength,tr.mp4Box.appendBuffer(t.buffer)},destroy(){tr.mp4Box&&(tr.mp4Box.stop(),tr.mp4Box.flush(),tr.mp4Box.destroy(),tr.mp4Box=null),tr.transportDescarmber&&(tr.transportDescarmber.destroy(),tr.transportDescarmber=null),tr.offset=0,tr.videoTrackId=null,tr.audioTrackId=null,tr.isHevc=!1}},ir={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);ir.extractNALu(t)},destroy(){ir.lastBuffer=new Uint8Array(0),ir.parsedOffset=0,ir.firstStartCodeOffset=0,ir.secondStartCodeOffset=0,ir.state="init",ir.hasInitVideoCodec=!1,ir.localDts=0},extractNALu(e){if(!e||e.byteLength<1)return void ar.debug.warn(ir.LOG_NAME,"extractNALu() buffer error",e);const t=new Uint8Array(ir.lastBuffer.length+e.length);for(t.set(ir.lastBuffer,0),t.set(new Uint8Array(e),ir.lastBuffer.length),ir.lastBuffer=t;;){if("init"===ir.state){let e=!1;for(;ir.lastBuffer.length-ir.parsedOffset>=4;)if(0===ir.lastBuffer[ir.parsedOffset])if(0===ir.lastBuffer[ir.parsedOffset+1])if(1===ir.lastBuffer[ir.parsedOffset+2]){if(182===ir.lastBuffer[ir.parsedOffset+3]){ir.state="findFirstStartCode",ir.firstStartCodeOffset=ir.parsedOffset,ir.parsedOffset+=4,e=!0;break}ir.parsedOffset++}else ir.parsedOffset++;else ir.parsedOffset++;else ir.parsedOffset++;if(e)continue;break}if("findFirstStartCode"===ir.state){let e=!1;for(;ir.lastBuffer.length-ir.parsedOffset>=4;)if(0===ir.lastBuffer[ir.parsedOffset])if(0===ir.lastBuffer[ir.parsedOffset+1])if(1===ir.lastBuffer[ir.parsedOffset+2]){if(182===ir.lastBuffer[ir.parsedOffset+3]){ir.state="findSecondStartCode",ir.secondStartCodeOffset=ir.parsedOffset,ir.parsedOffset+=4,e=!0;break}ir.parsedOffset++}else ir.parsedOffset++;else ir.parsedOffset++;else ir.parsedOffset++;if(e)continue;break}if("findSecondStartCode"===ir.state){if(!(ir.lastBuffer.length-ir.parsedOffset>0))break;{let e,t,i=192&ir.lastBuffer[ir.parsedOffset];e=0==i?ir.secondStartCodeOffset-14:ir.secondStartCodeOffset;let r=0==(192&ir.lastBuffer[ir.firstStartCodeOffset+4]);if(r){if(ir.firstStartCodeOffset-14<0)return void ar.debug.warn(ir.LOG_NAME,"firstStartCodeOffset -14 is",ir.firstStartCodeOffset-14);ir.hasInitVideoCodec||(ir.hasInitVideoCodec=!0,ar.debug.log(ir.LOG_NAME,"setCodec"),or.setCodec(ke,"")),t=ir.lastBuffer.subarray(ir.firstStartCodeOffset-14,e)}else t=ir.lastBuffer.subarray(ir.firstStartCodeOffset,e);let s=ir.getNaluDts();ir.hasInitVideoCodec?(postMessage({cmd:P,type:Se,value:t.byteLength}),postMessage({cmd:P,type:ve,value:s}),or.decode(t,r?1:0,s)):ar.debug.warn(ir.LOG_NAME,"has not init video codec"),ir.lastBuffer=ir.lastBuffer.subarray(e),ir.firstStartCodeOffset=0==i?14:0,ir.parsedOffset=ir.firstStartCodeOffset+4,ir.state="findFirstStartCode"}}}},getNaluDts(){let e=ir.localDts;return ir.localDts=ir.localDts+40,e}},rr={TAG_NAME:"worker TsLoaderV2",first_parse_:!0,tsPacketSize:0,syncOffset:0,pmt_:null,config_:null,media_info_:new Ps,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(){rr.media_info_=null,rr.pes_slice_queues_=null,rr.section_slice_queues_=null,rr.video_metadata_=null,rr.audio_metadata_=null,rr.aac_last_incomplete_data_=null,rr.video_track_=null,rr.audio_track_=null,rr._remainingPacketData=null},probe(e){let t=new Uint8Array(e),i=-1,r=188;if(t.byteLength<=3*r)return{needMoreData:!0};for(;-1===i;){let e=Math.min(1e3,t.byteLength-3*r);for(let s=0;s<e;){if(71===t[s]&&71===t[s+r]&&71===t[s+2*r]){i=s;break}s++}if(-1===i)if(188===r)r=192;else{if(192!==r)break;r=204}}return-1===i?{match:!1}:(192===r&&i>=4&&(i-=4),{match:!0,consumed:0,ts_packet_size:r,sync_offset:i})},_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){rr._remainingPacketData&&(e=ds(rr._remainingPacketData,e),rr._remainingPacketData=null);let t=e.buffer;const i=rr.parseChunks(t);i?rr._remainingPacketData=e.subarray(i):e.length<this.tsPacketSize&&(rr._remainingPacketData=e)},parseChunks(e){let t=0;if(rr.first_parse_){rr.first_parse_=!1;const i=rr.probe(e);i.match&&(rr.tsPacketSize=i.ts_packet_size,rr.syncOffset=i.sync_offset),t=rr.syncOffset,ar.debug.log(rr.TAG_NAME,`isFirstDispatch and tsPacketSize = ${rr.tsPacketSize}, syncOffset = ${rr.syncOffset}`)}for(;t+rr.tsPacketSize<=e.byteLength;){192===rr.tsPacketSize&&(t+=4);const i=new Uint8Array(e,t,188);let r=i[0];if(71!==r){ar.debug.warn(rr.TAG_NAME,`sync_byte = ${r}, not 0x47`);break}let s=(64&i[1])>>>6;i[1];let a=(31&i[1])<<8|i[2],n=(48&i[3])>>>4,o=15&i[3],d=!(!rr.pmt_||rr.pmt_.pcr_pid!==a),l={},c=4;if(2==n||3==n){let e=i[4];if(e>0&&(d||3==n)){if(l.discontinuity_indicator=(128&i[5])>>>7,l.random_access_indicator=(64&i[5])>>>6,l.elementary_stream_priority_indicator=(32&i[5])>>>5,(16&i[5])>>>4){let e=300*(i[6]<<25|i[7]<<17|i[8]<<9|i[9]<<1|i[10]>>>7)+((1&i[10])<<8|i[11]);rr.last_pcr_=e}}if(2==n||5+e===188){t+=188,204===rr.tsPacketSize&&(t+=16);continue}c=5+e}if(1==n||3==n)if(0===a||a===rr.current_pmt_pid_||null!=rr.pmt_&&rr.pmt_.pid_stream_type[a]===Ts){let i=188-c;rr.handleSectionSlice(e,t+c,i,{pid:a,payload_unit_start_indicator:s,continuity_conunter:o,random_access_indicator:l.random_access_indicator})}else if(null!=rr.pmt_&&null!=rr.pmt_.pid_stream_type[a]){let i=188-c,r=rr.pmt_.pid_stream_type[a];a!==rr.pmt_.common_pids.h264&&a!==rr.pmt_.common_pids.h265&&a!==rr.pmt_.common_pids.adts_aac&&a!==rr.pmt_.common_pids.loas_aac&&a!==rr.pmt_.common_pids.ac3&&a!==rr.pmt_.common_pids.eac3&&a!==rr.pmt_.common_pids.opus&&a!==rr.pmt_.common_pids.mp3&&!0!==rr.pmt_.pes_private_data_pids[a]&&!0!==rr.pmt_.timed_id3_pids[a]&&!0!==rr.pmt_.synchronous_klv_pids[a]&&!0!==rr.pmt_.asynchronous_klv_pids[a]||rr.handlePESSlice(e,t+c,i,{pid:a,stream_type:r,payload_unit_start_indicator:s,continuity_conunter:o,random_access_indicator:l.random_access_indicator})}t+=188,204===rr.tsPacketSize&&(t+=16)}return rr.dispatchAudioVideoMediaSegment(),t},handleSectionSlice(e,t,i,r){let s=new Uint8Array(e,t,i),a=rr.section_slice_queues_[r.pid];if(r.payload_unit_start_indicator){let n=s[0];if(null!=a&&0!==a.total_length){let s=new Uint8Array(e,t+1,Math.min(i,n));a.slices.push(s),a.total_length+=s.byteLength,a.total_length===a.expected_length?rr.emitSectionSlices(a,r):rr.clearSlices(a,r)}for(let o=1+n;o<s.byteLength;){if(255===s[o+0])break;let n=(15&s[o+1])<<8|s[o+2];rr.section_slice_queues_[r.pid]=new Is,a=rr.section_slice_queues_[r.pid],a.expected_length=n+3,a.random_access_indicator=r.random_access_indicator;let d=new Uint8Array(e,t+o,Math.min(i-o,a.expected_length-a.total_length));a.slices.push(d),a.total_length+=d.byteLength,a.total_length===a.expected_length?rr.emitSectionSlices(a,r):a.total_length>=a.expected_length&&rr.clearSlices(a,r),o+=d.byteLength}}else if(null!=a&&0!==a.total_length){let s=new Uint8Array(e,t,Math.min(i,a.expected_length-a.total_length));a.slices.push(s),a.total_length+=s.byteLength,a.total_length===a.expected_length?rr.emitSectionSlices(a,r):a.total_length>=a.expected_length&&rr.clearSlices(a,r)}},handlePESSlice(e,t,i,r){let s=new Uint8Array(e,t,i),a=s[0]<<16|s[1]<<8|s[2];s[3];let n=s[4]<<8|s[5];if(r.payload_unit_start_indicator){if(1!==a)return void ar.debug.warn(rr.TAG_NAME,`handlePESSlice: packet_start_code_prefix should be 1 but with value ${a}`);let e=rr.pes_slice_queues_[r.pid];e&&(0===e.expected_length||e.expected_length===e.total_length?rr.emitPESSlices(e,r):rr.clearSlices(e,r)),rr.pes_slice_queues_[r.pid]=new Is,rr.pes_slice_queues_[r.pid].random_access_indicator=r.random_access_indicator}if(null==rr.pes_slice_queues_[r.pid])return;let o=rr.pes_slice_queues_[r.pid];o.slices.push(s),r.payload_unit_start_indicator&&(o.expected_length=0===n?0:n+6),o.total_length+=s.byteLength,o.expected_length>0&&o.expected_length===o.total_length?rr.emitPESSlices(o,r):o.expected_length>0&&o.expected_length<o.total_length&&rr.clearSlices(o,r)},emitSectionSlices(e,t){let i=new Uint8Array(e.total_length);for(let t=0,r=0;t<e.slices.length;t++){let s=e.slices[t];i.set(s,r),r+=s.byteLength}e.slices=[],e.expected_length=-1,e.total_length=0;let r={};r.pid=t.pid,r.data=i,r.file_position=e.file_position,r.random_access_indicator=e.random_access_indicator,rr.parseSection(r)},emitPESSlices(e,t){let i=new Uint8Array(e.total_length);for(let t=0,r=0;t<e.slices.length;t++){let s=e.slices[t];i.set(s,r),r+=s.byteLength}e.slices=[],e.expected_length=-1,e.total_length=0;let r=new Ds;r.pid=t.pid,r.data=i,r.stream_type=t.stream_type,r.random_access_indicator=e.random_access_indicator,rr.parsePES(r)},clearSlices(e){e.slices=[],e.expected_length=-1,e.total_length=0},parseSection(e){let t=e.data,i=e.pid;0===i?rr.parsePAT(t):i===rr.current_pmt_pid_?rr.parsePMT(t):null!=rr.pmt_&&rr.pmt_.scte_35_pids[i]},parsePES(e){let t=e.data,i=t[0]<<16|t[1]<<8|t[2],r=t[3],s=t[4]<<8|t[5];if(1===i){if(188!==r&&190!==r&&191!==r&&240!==r&&241!==r&&255!==r&&242!==r&&248!==r){t[6];let i,a,n=(192&t[7])>>>6,o=t[8];2!==n&&3!==n||(i=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,a=3===n?536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2:i);let d,l=9+o;if(0!==s){if(s<3+o)return void ar.debug.warn(rr.TAG_NAME,"Malformed PES: PES_packet_length < 3 + PES_header_data_length");d=s-3-o}else d=t.byteLength-l;let c=t.subarray(l,l+d);switch(e.stream_type){case Ss:case vs:rr.parseMP3Payload(c,i);break;case ws:rr.pmt_.common_pids.opus===e.pid||rr.pmt_.common_pids.ac3===e.pid||rr.pmt_.common_pids.eac3===e.pid||(rr.pmt_.asynchronous_klv_pids[e.pid]?rr.parseAsynchronousKLVMetadataPayload(c,e.pid,r):rr.pmt_.smpte2038_pids[e.pid]?rr.parseSMPTE2038MetadataPayload(c,i,a,e.pid,r):rr.parsePESPrivateDataPayload(c,i,a,e.pid,r));break;case As:rr.parseADTSAACPayload(c,i);break;case Us:rr.parseLOASAACPayload(c,i);break;case Es:case xs:break;case Bs:rr.pmt_.timed_id3_pids[e.pid]?rr.parseTimedID3MetadataPayload(c,i,a,e.pid,r):rr.pmt_.synchronous_klv_pids[e.pid]&&rr.parseSynchronousKLVMetadataPayload(c,i,a,e.pid,r);break;case Cs:rr.parseH264Payload(c,i,a,e.random_access_indicator);break;case ks:rr.parseH265Payload(c,i,a,e.random_access_indicator)}}else if((188===r||191===r||240===r||241===r||255===r||242===r||248===r)&&e.stream_type===ws){let i,a=6;i=0!==s?s:t.byteLength-a;let n=t.subarray(a,a+i);rr.parsePESPrivateDataPayload(n,void 0,void 0,e.pid,r)}}else ar.debug.error(rr.TAG_NAME,`parsePES: packet_start_code_prefix should be 1 but with value ${i}`)},parsePAT(e){let t=e[0];if(0!==t)return void Log.e(rr.TAG,`parsePAT: table_id ${t} is not corresponded to PAT!`);let i=(15&e[1])<<8|e[2];e[3],e[4];let r=(62&e[5])>>>1,s=1&e[5],a=e[6];e[7];let n=null;if(1===s&&0===a)n={version_number:0,network_pid:0,program_pmt_pid:{}},n.version_number=r;else if(n=rr.pat_,null==n)return;let o=i-5-4,d=-1,l=-1;for(let t=8;t<8+o;t+=4){let i=e[t]<<8|e[t+1],r=(31&e[t+2])<<8|e[t+3];0===i?n.network_pid=r:(n.program_pmt_pid[i]=r,-1===d&&(d=i),-1===l&&(l=r))}1===s&&0===a&&(null==rr.pat_&&ar.debug.log(rr.TAG_NAME,`Parsed first PAT: ${JSON.stringify(n)}`),rr.pat_=n,rr.current_program_=d,rr.current_pmt_pid_=l)},parsePMT(e){let t=e[0];if(2!==t)return void ar.debug.error(rr.TAG_NAME,`parsePMT: table_id ${t} is not corresponded to PMT!`);let i,r=(15&e[1])<<8|e[2],s=e[3]<<8|e[4],a=(62&e[5])>>>1,n=1&e[5],o=e[6];if(e[7],1===n&&0===o)i=rr._initPmt(),i.program_number=s,i.version_number=a,rr.program_pmt_map_[s]=i;else if(i=rr.program_pmt_map_[s],null==i)return;i.pcr_pid=(31&e[8])<<8|e[9];let d=(15&e[10])<<8|e[11],l=12+d,c=r-9-d-4;for(let t=l;t<l+c;){let r=e[t],s=(31&e[t+1])<<8|e[t+2],a=(15&e[t+3])<<8|e[t+4];i.pid_stream_type[s]=r;let n=i.common_pids.h264||i.common_pids.h265,o=i.common_pids.adts_aac||i.common_pids.loas_aac||i.common_pids.ac3||i.common_pids.eac3||i.common_pids.opus||i.common_pids.mp3;if(r!==Cs||n)if(r!==ks||n)if(r!==As||o)if(r!==Us||o)if(r!==Es||o)if(r!==xs||o)if(r!==Ss&&r!==vs||o)if(r===ws){if(i.pes_private_data_pids[s]=!0,a>0){for(let r=t+5;r<t+5+a;){let t=e[r+0],a=e[r+1];if(5===t){let t=String.fromCharCode(...Array.from(e.subarray(r+2,r+2+a)));"VANC"===t?i.smpte2038_pids[s]=!0:"Opus"===t?i.common_pids.opus=s:"KLVA"===t&&(i.asynchronous_klv_pids[s]=!0)}else if(127===t&&s===i.common_pids.opus){let t=null;if(128===e[r+2]&&(t=e[r+3]),null==t){Log.e(rr.TAG,"Not Supported Opus channel count.");continue}const i={codec:"opus",channel_count:0==(15&t)?2:15&t,channel_config_code:t,sample_rate:48e3},s={codec:"opus",meta:i};0==rr.audio_init_segment_dispatched_?(rr.audio_metadata_=i,rr.dispatchAudioInitSegment(s)):rr.detectAudioMetadataChange(s)&&(rr.dispatchAudioMediaSegment(),rr.dispatchAudioInitSegment(s))}r+=2+a}e.subarray(t+5,t+5+a)}}else if(r===Bs){if(a>0)for(let r=t+5;r<t+5+a;){let t=e[r+0],a=e[r+1];if(38===t){let t=e[r+2]<<8|e[r+3]<<0,a=null;65535===t&&(a=String.fromCharCode(...Array.from(e.subarray(r+4,r+4+4))));let n=null;if(255===e[r+4+(65535===t?4:0)]){let i=4+(65535===t?4:0)+1;n=String.fromCharCode(...Array.from(e.subarray(r+i,r+i+4)))}"ID3 "===a&&"ID3 "===n?i.timed_id3_pids[s]=!0:"KLVA"===n&&(i.synchronous_klv_pids[s]=!0)}r+=2+a}}else r===Ts&&(i.scte_35_pids[s]=!0);else i.common_pids.mp3=s;else i.common_pids.eac3=s;else i.common_pids.ac3=s;else i.common_pids.loas_aac=s;else i.common_pids.adts_aac=s;else i.common_pids.h265=s;else i.common_pids.h264=s;t+=5+a}s===rr.current_program_&&(null==rr.pmt_&&ar.debug.log(rr.TAG_NAME,`Parsed first PMT: ${JSON.stringify(i)}`),rr.pmt_=i,(i.common_pids.h264||i.common_pids.h265)&&(rr.has_video_=!0),(i.common_pids.adts_aac||i.common_pids.loas_aac||i.common_pids.ac3||i.common_pids.opus||i.common_pids.mp3)&&(rr.has_audio_=!0))},parseSCTE35(e){},parseH264Payload(e,t,i,r){let s=new Ri(e),a=null,n=null,o=[],d=0,l=!1;for(;null!=(a=s.readNextNaluPayload());){let e=new zi(a);if(e.type===Ve){let t=Ei.parseSPS$2(a.data);rr.video_init_segment_dispatched_?!0===rr.detectVideoMetadataChange(e,t)&&(ar.debug.log(rr.TAG_NAME,"H264: Critical h264 metadata has been changed, attempt to re-generate InitSegment"),rr.video_metadata_changed_=!0,rr.video_metadata_={vps:void 0,sps:e,pps:void 0,details:t}):(rr.video_metadata_.sps=e,rr.video_metadata_.details=t)}else e.type===$e?rr.video_init_segment_dispatched_&&!rr.video_metadata_changed_||(rr.video_metadata_.pps=e,rr.video_metadata_.sps&&rr.video_metadata_.pps&&(rr.video_metadata_changed_&&rr.dispatchVideoMediaSegment(),rr.dispatchVideoInitSegment())):(e.type===Oe||e.type===Ge&&1===r)&&(l=!0);rr.video_init_segment_dispatched_&&(o.push(e),d+=e.data.byteLength)}let c=Math.floor(t/rr.timescale_),u=Math.floor(i/rr.timescale_);if(o.length){let e=rr.video_track_;for(let e=0;e<o.length;e++){let t=o[e];if(null==n)n=t.data;else{let e=new Uint8Array(n.byteLength+t.data.byteLength);e.set(n,0),e.set(t.data,n.byteLength),n=e}}let t={length:d,isIFrame:l,dts:u,pts:c,cts:c-u,payload:n,type:te,isHevc:!1};e.samples.push(t),e.length=n.byteLength}},parseH265Payload(e,t,i,r){let s=new Qi(e),a=null,n=null,o=[],d=0,l=!1;for(;null!=(a=s.readNextNaluPayload());){let e=new er(a);if(e.type===Qe){if(!rr.video_init_segment_dispatched_){let t=Oi.parseVPS(a.data);rr.video_metadata_.vps=e,rr.video_metadata_.details={...rr.video_metadata_.details,...t}}}else if(e.type===tt){let t=Oi.parseSPS(a.data);rr.video_init_segment_dispatched_?!0===rr.detectVideoMetadataChange(e,t)&&(ar.debug.log(rr.TAG_NAME,"H265: Critical h265 metadata has been changed, attempt to re-generate InitSegment"),rr.video_metadata_changed_=!0,rr.video_metadata_={vps:void 0,sps:e,pps:void 0,details:t}):(rr.video_metadata_.sps=e,rr.video_metadata_.details={...rr.video_metadata_.details,...t})}else if(e.type===rt){if(!rr.video_init_segment_dispatched_||rr.video_metadata_changed_){let t=Oi.parsePPS(a.data);rr.video_metadata_.pps=e,rr.video_metadata_.details={...rr.video_metadata_.details,...t},rr.video_metadata_.vps&&rr.video_metadata_.sps&&rr.video_metadata_.pps&&(rr.video_metadata_changed_&&rr.dispatchVideoMediaSegment(),rr.dispatchVideoInitSegment())}}else e.type!==qe&&e.type!==Ke&&e.type!==Ze||(l=!0);rr.video_init_segment_dispatched_&&(o.push(e),d+=e.data.byteLength)}let c=Math.floor(t/rr.timescale_),u=Math.floor(i/rr.timescale_);if(o.length){let e=rr.video_track_;for(let e=0;e<o.length;e++){let t=o[e];if(null==n)n=t.data;else{let e=new Uint8Array(n.byteLength+t.data.byteLength);e.set(n,0),e.set(t.data,n.byteLength),n=e}}let t={type:te,length:d,isIFrame:l,dts:u,pts:c,cts:c-u,payload:n,isHevc:!0};e.samples.push(t),e.length=n.byteLength}},detectVideoMetadataChange(e,t){if(t.codec_mimetype!==rr.video_metadata_.details.codec_mimetype)return ar.debug.log(rr.TAG_NAME,`Video: Codec mimeType changed from ${rr.video_metadata_.details.codec_mimetype} to ${t.codec_mimetype}`),!0;if(t.codec_size.width!==rr.video_metadata_.details.codec_size.width||t.codec_size.height!==rr.video_metadata_.details.codec_size.height){let e=rr.video_metadata_.details.codec_size,i=t.codec_size;return ar.debug.log(rr.TAG_NAME,`Video: Coded Resolution changed from ${e.width}x${e.height} to ${i.width}x${i.height}`),!0}return t.present_size.width!==rr.video_metadata_.details.present_size.width&&(ar.debug.log(rr.TAG_NAME,`Video: Present resolution width changed from ${rr.video_metadata_.details.present_size.width} to ${t.present_size.width}`),!0)},isInitSegmentDispatched:()=>rr.has_video_&&rr.has_audio_?rr.video_init_segment_dispatched_&&rr.audio_init_segment_dispatched_:rr.has_video_&&!rr.has_audio_?rr.video_init_segment_dispatched_:!(rr.has_video_||!rr.has_audio_)&&rr.audio_init_segment_dispatched_,dispatchVideoInitSegment(){let e=rr.video_metadata_.details,t={type:"video"};t.id=rr.video_track_.id,t.timescale=1e3,t.duration=rr.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 i=t.frameRate.fps_den,r=t.frameRate.fps_num;if(t.refSampleDuration=i/r*1e3,t.codec=e.codec_mimetype,rr.video_metadata_.vps){let e=rr.video_metadata_.vps.data.subarray(4),i=rr.video_metadata_.sps.data.subarray(4),r=rr.video_metadata_.pps.data.subarray(4);t.hvcc=Wi({vps:e,sps:i,pps:r}),0==rr.video_init_segment_dispatched_&&ar.debug.log(rr.TAG_NAME,`Generated first HEVCDecoderConfigurationRecord for mimeType: ${t.codec}`),t.hvcc&&ar.decodeVideo(t.hvcc,0,!0,0)}else{let e=rr.video_metadata_.sps.data.subarray(4),i=rr.video_metadata_.pps.data.subarray(4);t.avcc=Ci({sps:e,pps:i}),0==rr.video_init_segment_dispatched_&&ar.debug.log(rr.TAG_NAME,`Generated first AVCDecoderConfigurationRecord for mimeType: ${t.codec}`),t.avcc&&ar.decodeVideo(t.avcc,0,!0,0)}rr.video_init_segment_dispatched_=!0,rr.video_metadata_changed_=!1;let s=rr.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(){rr.isInitSegmentDispatched()&&rr.video_track_.length&&rr._preDoDecode()},dispatchAudioMediaSegment(){rr.isInitSegmentDispatched()&&rr.audio_track_.length&&rr._preDoDecode()},dispatchAudioVideoMediaSegment(){rr.isInitSegmentDispatched()&&(rr.audio_track_.length||rr.video_track_.length)&&rr._preDoDecode()},parseADTSAACPayload(e,t){if(rr.has_video_&&!rr.video_init_segment_dispatched_)return;if(rr.aac_last_incomplete_data_){let t=new Uint8Array(e.byteLength+rr.aac_last_incomplete_data_.byteLength);t.set(rr.aac_last_incomplete_data_,0),t.set(e,rr.aac_last_incomplete_data_.byteLength),e=t}let i,r;if(null!=t&&(r=t/rr.timescale_),"aac"===rr.audio_metadata_.codec){if(null==t&&null!=rr.audio_last_sample_pts_)i=1024/rr.audio_metadata_.sampling_frequency*1e3,r=rr.audio_last_sample_pts_+i;else if(null==t)return void ar.debug.warn(rr.TAG_NAME,"AAC: Unknown pts");if(rr.aac_last_incomplete_data_&&rr.audio_last_sample_pts_){i=1024/rr.audio_metadata_.sampling_frequency*1e3;let e=rr.audio_last_sample_pts_+i;Math.abs(e-r)>1&&(ar.debug.warn(rr.TAG_NAME,`AAC: Detected pts overlapped, expected: ${e}ms, PES pts: ${r}ms`),r=e)}}let s,a=new qt(e),n=null,o=r;for(;null!=(n=a.readNextAACFrame());){i=1024/n.sampling_frequency*1e3;const e={codec:"aac",data:n};0==rr.audio_init_segment_dispatched_?(rr.audio_metadata_={codec:"aac",audio_object_type:n.audio_object_type,sampling_freq_index:n.sampling_freq_index,sampling_frequency:n.sampling_frequency,channel_config:n.channel_config},rr.dispatchAudioInitSegment(e)):rr.detectAudioMetadataChange(e)&&(rr.dispatchAudioMediaSegment(),rr.dispatchAudioInitSegment(e)),s=o;let t=Math.floor(o);const r=new Uint8Array(n.data.length+2);r.set([175,1],0),r.set(n.data,2);let a={payload:r,length:r.byteLength,pts:t,dts:t,type:ee};rr.audio_track_.samples.push(a),rr.audio_track_.length+=r.byteLength,o+=i}a.hasIncompleteData()&&(rr.aac_last_incomplete_data_=a.getIncompleteData()),s&&(rr.audio_last_sample_pts_=s)},parseLOASAACPayload(e,t){if(rr.has_video_&&!rr.video_init_segment_dispatched_)return;if(rr.aac_last_incomplete_data_){let t=new Uint8Array(e.byteLength+rr.aac_last_incomplete_data_.byteLength);t.set(rr.aac_last_incomplete_data_,0),t.set(e,rr.aac_last_incomplete_data_.byteLength),e=t}let i,r;if(null!=t&&(r=t/rr.timescale_),"aac"===rr.audio_metadata_.codec){if(null==t&&null!=rr.audio_last_sample_pts_)i=1024/rr.audio_metadata_.sampling_frequency*1e3,r=rr.audio_last_sample_pts_+i;else if(null==t)return void ar.debug.warn(rr.TAG_NAME,"AAC: Unknown pts");if(rr.aac_last_incomplete_data_&&rr.audio_last_sample_pts_){i=1024/rr.audio_metadata_.sampling_frequency*1e3;let e=rr.audio_last_sample_pts_+i;Math.abs(e-r)>1&&(ar.debug.warn(rr.TAG,`AAC: Detected pts overlapped, expected: ${e}ms, PES pts: ${r}ms`),r=e)}}let s,a=new jt(e),n=null,o=r;for(;null!=(n=a.readNextAACFrame(ai(this.loas_previous_frame)?void 0:this.loas_previous_frame));){rr.loas_previous_frame=n,i=1024/n.sampling_frequency*1e3;const e={codec:"aac",data:n};0==rr.audio_init_segment_dispatched_?(rr.audio_metadata_={codec:"aac",audio_object_type:n.audio_object_type,sampling_freq_index:n.sampling_freq_index,sampling_frequency:n.sampling_frequency,channel_config:n.channel_config},rr.dispatchAudioInitSegment(e)):rr.detectAudioMetadataChange(e)&&(rr.dispatchAudioMediaSegment(),rr.dispatchAudioInitSegment(e)),s=o;let t=Math.floor(o);const r=new Uint8Array(n.data.length+2);r.set([175,1],0),r.set(n.data,2);let a={payload:r,length:r.byteLength,pts:t,dts:t,type:ee};rr.audio_track_.samples.push(a),rr.audio_track_.length+=r.byteLength,o+=i}a.hasIncompleteData()&&(rr.aac_last_incomplete_data_=a.getIncompleteData()),s&&(rr.audio_last_sample_pts_=s)},parseAC3Payload(e,t){},parseEAC3Payload(e,t){},parseOpusPayload(e,t){},parseMP3Payload(e,t){if(rr.has_video_&&!rr.video_init_segment_dispatched_)return;let i=[44100,48e3,32e3,0],r=[22050,24e3,16e3,0],s=[11025,12e3,8e3,0],a=e[1]>>>3&3,n=(6&e[1])>>1;e[2];let o=(12&e[2])>>>2,d=3!==(e[3]>>>6&3)?2:1,l=0,c=34;switch(a){case 0:l=s[o];break;case 2:l=r[o];break;case 3:l=i[o]}switch(n){case 1:c=34;break;case 2:c=33;break;case 3:c=32}const u={};u.object_type=c,u.sample_rate=l,u.channel_count=d,u.data=e;const h={codec:"mp3",data:u};0==rr.audio_init_segment_dispatched_?(rr.audio_metadata_={codec:"mp3",object_type:c,sample_rate:l,channel_count:d},rr.dispatchAudioInitSegment(h)):rr.detectAudioMetadataChange(h)&&(rr.dispatchAudioMediaSegment(),rr.dispatchAudioInitSegment(h));let f={payload:e,length:e.byteLength,pts:t/rr.timescale_,dts:t/rr.timescale_,type:ee};rr.audio_track_.samples.push(f),rr.audio_track_.length+=e.byteLength},detectAudioMetadataChange(e){if(e.codec!==rr.audio_metadata_.codec)return ar.debug.log(rr.TAG_NAME,`Audio: Audio Codecs changed from ${rr.audio_metadata_.codec} to ${e.codec}`),!0;if("aac"===e.codec&&"aac"===rr.audio_metadata_.codec){const t=e.data;if(t.audio_object_type!==rr.audio_metadata_.audio_object_type)return ar.debug.log(rr.TAG_NAME,`AAC: AudioObjectType changed from ${rr.audio_metadata_.audio_object_type} to ${t.audio_object_type}`),!0;if(t.sampling_freq_index!==rr.audio_metadata_.sampling_freq_index)return ar.debug.log(rr.TAG_NAME,`AAC: SamplingFrequencyIndex changed from ${rr.audio_metadata_.sampling_freq_index} to ${t.sampling_freq_index}`),!0;if(t.channel_config!==rr.audio_metadata_.channel_config)return ar.debug.log(rr.TAG_NAME,`AAC: Channel configuration changed from ${rr.audio_metadata_.channel_config} to ${t.channel_config}`),!0}else if("ac-3"===e.codec&&"ac-3"===rr.audio_metadata_.codec){const t=e.data;if(t.sampling_frequency!==rr.audio_metadata_.sampling_frequency)return ar.debug.log(rr.TAG_NAME,`AC3: Sampling Frequency changed from ${rr.audio_metadata_.sampling_frequency} to ${t.sampling_frequency}`),!0;if(t.bit_stream_identification!==rr.audio_metadata_.bit_stream_identification)return ar.debug.log(rr.TAG_NAME,`AC3: Bit Stream Identification changed from ${rr.audio_metadata_.bit_stream_identification} to ${t.bit_stream_identification}`),!0;if(t.bit_stream_mode!==rr.audio_metadata_.bit_stream_mode)return ar.debug.log(rr.TAG_NAME,`AC3: BitStream Mode changed from ${rr.audio_metadata_.bit_stream_mode} to ${t.bit_stream_mode}`),!0;if(t.channel_mode!==rr.audio_metadata_.channel_mode)return ar.debug.log(rr.TAG_NAME,`AC3: Channel Mode changed from ${rr.audio_metadata_.channel_mode} to ${t.channel_mode}`),!0;if(t.low_frequency_effects_channel_on!==rr.audio_metadata_.low_frequency_effects_channel_on)return ar.debug.log(rr.TAG_NAME,`AC3: Low Frequency Effects Channel On changed from ${rr.audio_metadata_.low_frequency_effects_channel_on} to ${t.low_frequency_effects_channel_on}`),!0}else if("opus"===e.codec&&"opus"===rr.audio_metadata_.codec){const t=e.meta;if(t.sample_rate!==rr.audio_metadata_.sample_rate)return ar.debug.log(rr.TAG_NAME,`Opus: SamplingFrequencyIndex changed from ${rr.audio_metadata_.sample_rate} to ${t.sample_rate}`),!0;if(t.channel_count!==rr.audio_metadata_.channel_count)return ar.debug.log(rr.TAG_NAME,`Opus: Channel count changed from ${rr.audio_metadata_.channel_count} to ${t.channel_count}`),!0}else if("mp3"===e.codec&&"mp3"===rr.audio_metadata_.codec){const t=e.data;if(t.object_type!==rr.audio_metadata_.object_type)return ar.debug.log(rr.TAG_NAME,`MP3: AudioObjectType changed from ${rr.audio_metadata_.object_type} to ${t.object_type}`),!0;if(t.sample_rate!==rr.audio_metadata_.sample_rate)return ar.debug.log(rr.TAG_NAME,`MP3: SamplingFrequencyIndex changed from ${rr.audio_metadata_.sample_rate} to ${t.sample_rate}`),!0;if(t.channel_count!==rr.audio_metadata_.channel_count)return ar.debug.log(rr.TAG_NAME,`MP3: Channel count changed from ${rr.audio_metadata_.channel_count} to ${t.channel_count}`),!0}return!1},dispatchAudioInitSegment(e){let t={type:"audio"};if(t.id=rr.audio_track_.id,t.timescale=1e3,t.duration=rr.duration_,"aac"===rr.audio_metadata_.codec){let i="aac"===e.codec?e.data:null,r=new Ms(i);t.audioSampleRate=r.sampling_rate,t.audioSampleRateIndex=r.sampling_index,t.channelCount=r.channel_count,t.codec=r.codec_mimetype,t.originalCodec=r.original_codec_mimetype,t.config=r.config,t.refSampleDuration=1024/t.audioSampleRate*t.timescale;const s=Ht({profile:ar._opt.mseDecodeAudio?r.object_type:r.original_object_type,sampleRate:t.audioSampleRateIndex,channel:t.channelCount});ar.decodeAudio(s,0)}else"ac-3"===rr.audio_metadata_.codec||"ec-3"===rr.audio_metadata_.codec||"opus"===rr.audio_metadata_.codec||"mp3"===rr.audio_metadata_.codec&&(t.audioSampleRate=rr.audio_metadata_.sample_rate,t.channelCount=rr.audio_metadata_.channel_count,t.codec="mp3",t.originalCodec="mp3",t.config=void 0);0==rr.audio_init_segment_dispatched_&&ar.debug.log(rr.TAG_NAME,`Generated first AudioSpecificConfig for mimeType: ${t.codec}`),rr.audio_init_segment_dispatched_=!0,rr.video_metadata_changed_=!1;let i=rr.media_info_;i.hasAudio=!0,i.audioCodec=t.originalCodec,i.audioSampleRate=t.audioSampleRate,i.audioChannelCount=t.channelCount,i.hasVideo&&i.videoCodec?i.mimeType=`video/mp2t; codecs="${i.videoCodec},${i.audioCodec}"`:i.mimeType=`video/mp2t; codecs="${i.audioCodec}"`},dispatchPESPrivateDataDescriptor(e,t,i){},parsePESPrivateDataPayload(e,t,i,r,s){let a=new Ls;if(a.pid=r,a.stream_id=s,a.len=e.byteLength,a.data=e,null!=t){let e=Math.floor(t/rr.timescale_);a.pts=e}else a.nearest_pts=rr.getNearestTimestampMilliseconds();if(null!=i){let e=Math.floor(i/rr.timescale_);a.dts=e}},parseTimedID3MetadataPayload(e,t,i,r,s){ar.debug.log(rr.TAG_NAME,`Timed ID3 Metadata: pid=${r}, pts=${t}, dts=${i}, stream_id=${s}`)},parseSynchronousKLVMetadataPayload(e,t,i,r,s){ar.debug.log(rr.TAG_NAME,`Synchronous KLV Metadata: pid=${r}, pts=${t}, dts=${i}, stream_id=${s}`)},parseAsynchronousKLVMetadataPayload(e,t,i){ar.debug.log(rr.TAG_NAME,`Asynchronous KLV Metadata: pid=${t}, stream_id=${i}`)},parseSMPTE2038MetadataPayload(e,t,i,r,s){ar.debug.log(rr.TAG_NAME,`SMPTE 2038 Metadata: pid=${r}, pts=${t}, dts=${i}, stream_id=${s}`)},getNearestTimestampMilliseconds(){if(null!=rr.audio_last_sample_pts_)return Math.floor(rr.audio_last_sample_pts_);if(null!=rr.last_pcr_){return Math.floor(rr.last_pcr_/300/rr.timescale_)}},_preDoDecode(){const e=rr.video_track_,t=rr.audio_track_;let i=e.samples;t.samples.length>0&&(i=e.samples.concat(t.samples),i=i.sort(((e,t)=>e.dts-t.dts))),i.forEach((e=>{const t=new Uint8Array(e.payload);delete e.payload,e.type===te?rr._doDecodeVideo({...e,payload:t}):e.type===ee&&rr._doDecodeAudio({...e,payload:t})})),e.samples=[],e.length=0,t.samples=[],t.length=0},_doDecodeVideo(e){const t=new Uint8Array(e.payload);let i=null;i=e.isHevc?qi(t,e.isIFrame):Ii(t,e.isIFrame),e.isIFrame&&ar.calcIframeIntervalTimestamp(e.dts);let r=ar.cryptoPayload(i,e.isIFrame);ar.decode(r,{type:te,ts:e.dts,isIFrame:e.isIFrame,cts:e.cts})},_doDecodeAudio(e){const t=new Uint8Array(e.payload);let i=t;_i(ar._opt.m7sCryptoAudio)&&(i=ar.cryptoPayloadAudio(t)),ar.decode(i,{type:ee,ts:e.dts,isIFrame:!1,cts:0})}},sr=null;gi()&&(sr={TAG_NAME:"worker MediaSource",_resetInIt(){sr.isAvc=null,sr.isAAC=null,sr.videoInfo={},sr.videoMeta={},sr.audioMeta={},sr.sourceBuffer=null,sr.audioSourceBuffer=null,sr.hasInit=!1,sr.hasAudioInit=!1,sr.isAudioInitInfo=!1,sr.videoMimeType="",sr.audioMimeType="",sr.cacheTrack={},sr.cacheAudioTrack={},sr.timeInit=!1,sr.sequenceNumber=0,sr.audioSequenceNumber=0,sr.firstRenderTime=null,sr.firstAudioTime=null,sr.mediaSourceAppendBufferFull=!1,sr.mediaSourceAppendBufferError=!1,sr.mediaSourceAddSourceBufferError=!1,sr.mediaSourceBufferError=!1,sr.mediaSourceError=!1,sr.prevTimestamp=null,sr.decodeDiffTimestamp=null,sr.prevDts=null,sr.prevAudioDts=null,sr.prevPayloadBufferSize=0,sr.isWidthOrHeightChanged=!1,sr.prevTs=null,sr.prevAudioTs=null,sr.eventListenList=[],sr.pendingRemoveRanges=[],sr.pendingSegments=[],sr.pendingAudioRemoveRanges=[],sr.pendingAudioSegments=[],sr.supportVideoFrameCallbackHandle=null,sr.audioSourceBufferCheckTimeout=null,sr.audioSourceNoDataCheckTimeout=null,sr.hasPendingEos=!1,sr.$video={currentTime:0,readyState:0}},init(){sr.events=new ls,sr._resetInIt(),sr.mediaSource=new self.MediaSource,sr.isDecodeFirstIIframe=!!mi(ar._opt.checkFirstIFrame),sr._bindMediaSourceEvents()},destroy(){sr.stop(),sr._clearAudioSourceBufferCheckTimeout(),sr.eventListenList&&sr.eventListenList.length&&(sr.eventListenList.forEach((e=>e())),sr.eventListenList=[]),sr._resetInIt(),sr.mediaSource=null},getState:()=>sr.mediaSource&&sr.mediaSource.readyState,isStateOpen:()=>sr.getState()===mt,isStateClosed:()=>sr.getState()===gt,isStateEnded:()=>sr.getState()===_t,_bindMediaSourceEvents(){const{proxy:e}=sr.events,t=e(sr.mediaSource,bt,(()=>{ar.debug.log(sr.TAG_NAME,"sourceOpen"),sr._onMediaSourceSourceOpen()})),i=e(sr.mediaSource,yt,(()=>{ar.debug.log(sr.TAG_NAME,"sourceClose")})),r=e(sr.mediaSource,St,(()=>{ar.debug.log(sr.TAG_NAME,"sourceended")}));sr.eventListenList.push(t,i,r)},_onMediaSourceSourceOpen(){sr.sourceBuffer||(ar.debug.log(sr.TAG_NAME,"onMediaSourceSourceOpen() sourceBuffer is null and next init"),sr._initSourceBuffer()),sr.audioSourceBuffer||(ar.debug.log(sr.TAG_NAME,"onMediaSourceSourceOpen() audioSourceBuffer is null and next init"),sr._initAudioSourceBuffer()),sr._hasPendingSegments()&&sr._doAppendSegments()},decodeVideo(e,t,i,r){if(ar.isDestroyed)ar.debug.warn(sr.TAG_NAME,"decodeVideo() and decoder is destroyed");else if(mi(sr.hasInit))if(i&&e[1]===Ut){const r=15&e[0];if(r===Ce&&mi(si()))return void sr.emitError(xe.mediaSourceH265NotSupport);sr.videoInfo.codec=r,postMessage({cmd:k,code:r});const s=new Uint8Array(e);postMessage({cmd:I,buffer:s,codecId:r},[s.buffer]),sr.hasInit=sr._decodeConfigurationRecord(e,t,i,r)}else ar.debug.warn(sr.TAG_NAME,`decodeVideo has not init , isIframe is ${i} , payload is ${e[1]}`);else if(!sr.isDecodeFirstIIframe&&i&&(sr.isDecodeFirstIIframe=!0),sr.isDecodeFirstIIframe){if(i&&0===e[1]){const t=15&e[0];let i={};if(t===Te){i=Bi(e.slice(5))}else t===Ce&&(i=Hi(e));const r=sr.videoInfo;r&&r.codecWidth&&r.codecWidth&&i&&i.codecWidth&&i.codecHeight&&(i.codecWidth!==r.codecWidth||i.codecHeight!==r.codecWidth)&&(ar.debug.warn(sr.TAG_NAME,`\n decodeVideo: video width or height is changed,\n old width is ${r.codecWidth}, old height is ${r.codecWidth},\n new width is ${i.codecWidth}, new height is ${i.codecHeight},\n and emit change event`),sr.isWidthOrHeightChanged=!0,sr.emitError(xe.mseWidthOrHeightChange))}if(sr.isWidthOrHeightChanged)return void ar.debug.warn(sr.TAG_NAME,"decodeVideo: video width or height is changed, and return");if(pi(e))return void ar.debug.warn(sr.TAG_NAME,"decodeVideo and payload is video sequence header so drop this frame");if(e.byteLength<S)return void ar.debug.warn(sr.TAG_NAME,`decodeVideo and payload is too small , payload length is ${e.byteLength}`);let s=t;if(ar.isPlayer){if(null===sr.firstRenderTime&&(sr.firstRenderTime=t,postMessage({cmd:J,value:sr.firstRenderTime})),s=t-sr.firstRenderTime,s<0&&(ar.debug.warn(sr.TAG_NAME,`decodeVideo\n local dts is < 0 , ts is ${t} and prevTs is ${sr.prevTs},\n firstRenderTime is ${sr.firstRenderTime} and mseCorrectTimeDuration is ${ar._opt.mseCorrectTimeDuration}`),s=null===sr.prevDts?0:sr.prevDts+ar._opt.mseCorrectTimeDuration,sr._checkTsIsMaxDiff(t)))return ar.debug.warn(sr.TAG_NAME,`decodeVideo is max diff , ts is ${t} and prevTs is ${sr.prevTs}, diff is ${sr.prevTs-t}`),void sr.emitError(xe.mediaSourceTsIsMaxDiff);if(null!==sr.prevDts&&s<=sr.prevDts){if(ar.debug.warn(sr.TAG_NAME,`\n decodeVideo dts is less than(or equal) prev dts ,\n dts is ${s} and prev dts is ${sr.prevDts} ,\n and now ts is ${t} and prev ts is ${sr.prevTs} ,\n and diff is ${t-sr.prevTs} and firstRenderTime is ${sr.firstRenderTime} and isIframe is ${i},\n and mseCorrectTimeDuration is ${ar._opt.mseCorrectTimeDuration},\n and prevPayloadBufferSize is ${sr.prevPayloadBufferSize} and payload size is ${e.byteLength}`),s===sr.prevDts&&sr.prevPayloadBufferSize===e.byteLength)return void ar.debug.warn(sr.TAG_NAME,"decodeVideo dts is equal to prev dts and payload size is equal to prev payload size so drop this frame");if(s=sr.prevDts+ar._opt.mseCorrectTimeDuration,sr._checkTsIsMaxDiff(t))return ar.debug.warn(sr.TAG_NAME,`decodeVideo is max diff , ts is ${t} and prevTs is ${sr.prevTs}, diff is ${sr.prevTs-t} and emit replay`),void sr.emitError(xe.mediaSourceTsIsMaxDiff)}}ar.isPlayer?sr._decodeVideo(e,s,i,r,t):ar.isPlayback,sr.prevDts=s,sr.prevPayloadBufferSize=e.byteLength,sr.prevTs=t}else ar.debug.log(sr.TAG_NAME,"decodeVideo first frame is not iFrame")},decodeAudio(e,t){if(ar.isDestroyed)ar.debug.warn(sr.TAG_NAME,"decodeAudio() and decoder is destroyed");else if(mi(sr.hasAudioInit))sr.hasAudioInit=sr._decodeAudioConfigurationRecord(e,t);else{let i=t;if(Vt(e))return void ar.debug.log(sr.TAG_NAME,"decodeAudio and has already initialized and payload is aac codec packet so drop this frame");if(sr._clearAudioNoDataCheckTimeout(),sr.isDecodeFirstIIframe){if(ar.isPlayer){if(null===sr.firstAudioTime&&(sr.firstAudioTime=t,null!==sr.firstRenderTime&&null!==sr.prevTs)){const e=Math.abs(sr.firstRenderTime-sr.prevTs);e>300&&(sr.firstAudioTime-=e,ar.debug.warn(sr.TAG_NAME,`video\n firstAudioTime is ${sr.firstRenderTime} and current time is ${sr.prevTs}\n play time is ${e} and firstAudioTime ${t} - ${e} = ${sr.firstAudioTime}`))}i=t-sr.firstAudioTime,i<0&&(ar.debug.warn(sr.TAG_NAME,`decodeAudio\n local dts is < 0 , ts is ${t} and prevTs is ${sr.prevAudioTs},\n firstAudioTime is ${sr.firstAudioTime}`),i=null===sr.prevAudioDts?0:sr.prevAudioDts+ar._opt.mseCorrectAudioTimeDuration),null!==sr.prevAudioTs&&i<=sr.prevAudioDts&&(ar.debug.warn(sr.TAG_NAME,`\n decodeAudio dts is less than(or equal) prev dts ,\n dts is ${i} and prev dts is ${sr.prevAudioDts} ,\n and now ts is ${t} and prev ts is ${sr.prevAudioTs} ,\n and diff is ${t-sr.prevAudioTs}`),i=sr.prevAudioDts+ar._opt.mseCorrectAudioTimeDuration)}ar.isPlayer?sr._decodeAudio(e,i,t):ar.isPlayback,sr.prevAudioTs=t,sr.prevAudioDts=i}else ar.debug.log(sr.TAG_NAME,"decodeAudio first frame is not iFrame")}},_checkTsIsMaxDiff:e=>sr.prevTs>0&&e<sr.prevTs&&sr.prevTs-e>y,_decodeConfigurationRecord(e,t,i,r){let s=e.slice(5),a={};if(r===Te?a=Bi(s):r===Ce&&(a=Vi(s)),sr.videoInfo.width=a.codecWidth,sr.videoInfo.height=a.codecHeight,0===a.codecWidth&&0===a.codecHeight)return ar.debug.warn(sr.TAG_NAME,"_decodeConfigurationRecord error",JSON.stringify(a)),sr.emitError(xe.mediaSourceDecoderConfigurationError),!1;const n={id:kt,type:"video",timescale:1e3,duration:0,avcc:s,codecWidth:a.codecWidth,codecHeight:a.codecHeight,videoType:a.videoType},o=cs.generateInitSegment(n);sr.isAvc=r===Te;let d=a.codec;return sr.videoMimeType=d?`video/mp4; codecs="${a.codec}"`:sr.isAvc?lt:ct,postMessage({cmd:A,w:a.codecWidth,h:a.codecHeight}),sr._initSourceBuffer(),sr.appendBuffer(o.buffer),sr.sequenceNumber=0,sr.cacheTrack={},sr.timeInit=!1,!0},_decodeAudioConfigurationRecord(e,t){const i=e[0]>>4,r=e[0]>>1&1,s=i===Me,a=i===Le;if(mi(a||s))return ar.debug.warn(sr.TAG_NAME,`_decodeAudioConfigurationRecord audio codec is not support , codecId is ${i} ant auto wasm decode`),sr.emitError(xe.mediaSourceAudioG711NotSupport),!1;const n={id:It,type:"audio",timescale:1e3};let o={};if(Vt(e)){if(o=Yt(e.slice(2)),!o)return!1;n.audioSampleRate=o.sampleRate,n.channelCount=o.channelCount,n.config=o.config,n.refSampleDuration=1024/n.audioSampleRate*n.timescale}else{if(!s)return!1;if(o=bs(e),!o)return!1;n.audioSampleRate=o.samplingRate,n.channelCount=o.channelCount,n.refSampleDuration=1152/n.audioSampleRate*n.timescale}n.codec=o.codec,n.duration=0;let d="mp4",l=o.codec,c=null;s&&mi(ri())?(d="mpeg",l="",c=new Uint8Array):c=cs.generateInitSegment(n);let u=`${n.type}/${d}`;return l&&l.length>0&&(u+=`;codecs=${l}`),mi(sr.isAudioInitInfo)&&(vi=i===Le?r?16:8:0===r?8:16,postMessage({cmd:B,code:i}),postMessage({cmd:x,sampleRate:n.audioSampleRate,channels:n.channelCount,depth:vi}),sr.isAudioInitInfo=!0),sr.audioMimeType=u,sr.isAAC=a,sr._initAudioSourceBuffer(),sr.appendAudioBuffer(c.buffer),!0},_initSourceBuffer(){const{proxy:e}=sr.events;if(null===sr.sourceBuffer&&null!==sr.mediaSource&&sr.isStateOpen()&&sr.videoMimeType){try{sr.sourceBuffer=sr.mediaSource.addSourceBuffer(sr.videoMimeType),ar.debug.log(sr.TAG_NAME,"_initSourceBuffer() mseDecoder.mediaSource.addSourceBuffer()",sr.videoMimeType)}catch(e){return ar.debug.error(sr.TAG_NAME,"appendBuffer() mseDecoder.mediaSource.addSourceBuffer()",e.code,e),sr.emitError(xe.mseAddSourceBufferError,e.code),void(sr.mediaSourceAddSourceBufferError=!0)}if(sr.sourceBuffer){const t=e(sr.sourceBuffer,"error",(e=>{sr.mediaSourceBufferError=!0,ar.debug.error(sr.TAG_NAME,"mseSourceBufferError mseDecoder.sourceBuffer",e),sr.emitError(xe.mseSourceBufferError,e.code)})),i=e(sr.sourceBuffer,"updateend",(()=>{sr._hasPendingRemoveRanges()?sr._doRemoveRanges():sr._hasPendingSegments()?sr._doAppendSegments():sr.hasPendingEos&&(ar.debug.log(sr.TAG_NAME,"videoSourceBuffer updateend and hasPendingEos is true, next endOfStream()"),sr.endOfStream())}));sr.eventListenList.push(t,i)}}else ar.debug.log(sr.TAG_NAME,`_initSourceBuffer and mseDecoder.isStateOpen is ${sr.isStateOpen()} and mseDecoder.isAvc === null is ${null===sr.isAvc}`)},_initAudioSourceBuffer(){const{proxy:e}=sr.events;if(null===sr.audioSourceBuffer&&null!==sr.mediaSource&&sr.isStateOpen()&&sr.audioMimeType){try{sr.audioSourceBuffer=sr.mediaSource.addSourceBuffer(sr.audioMimeType),sr._clearAudioSourceBufferCheckTimeout(),ar.debug.log(sr.TAG_NAME,"_initAudioSourceBuffer() mseDecoder.mediaSource.addSourceBuffer()",sr.audioMimeType)}catch(e){return ar.debug.error(sr.TAG_NAME,"appendAudioBuffer() mseDecoder.mediaSource.addSourceBuffer()",e.code,e),sr.emitError(xe.mseAddSourceBufferError,e.code),void(sr.mediaSourceAddSourceBufferError=!0)}if(sr.audioSourceBuffer){const t=e(sr.audioSourceBuffer,"error",(e=>{sr.mediaSourceBufferError=!0,ar.debug.error(sr.TAG_NAME,"mseSourceBufferError mseDecoder.audioSourceBuffer",e),sr.emitError(xe.mseSourceBufferError,e.code)})),i=e(sr.audioSourceBuffer,"updateend",(()=>{sr._hasPendingRemoveRanges()?sr._doRemoveRanges():sr._hasPendingSegments()?sr._doAppendSegments():sr.hasPendingEos&&(ar.debug.log(sr.TAG_NAME,"audioSourceBuffer updateend and hasPendingEos is true, next endOfStream()"),sr.endOfStream())}));sr.eventListenList.push(t,i),null===sr.audioSourceNoDataCheckTimeout&&(sr.audioSourceNoDataCheckTimeout=setTimeout((()=>{sr._clearAudioNoDataCheckTimeout(),sr.emitError(xe.mediaSourceAudioNoDataTimeout)}),1e3))}}else ar.debug.log(sr.TAG_NAME,`_initAudioSourceBuffer and mseDecoder.isStateOpen is ${sr.isStateOpen()} and mseDecoder.audioMimeType is ${sr.audioMimeType}`)},_decodeVideo(e,t,i,r,s){let a=e.slice(5),n=a.byteLength;if(0===n)return void ar.debug.warn(sr.TAG_NAME,"_decodeVideo payload bytes is 0 and return");let o=(new Date).getTime(),d=!1;sr.prevTimestamp||(sr.prevTimestamp=o,d=!0);const l=o-sr.prevTimestamp;if(sr.decodeDiffTimestamp=l,l>500&&!d&&ar.isPlayer&&ar.debug.warn(sr.TAG_NAME,`_decodeVideo now time is ${o} and prev time is ${sr.prevTimestamp}, diff time is ${l} ms`),sr.cacheTrack.id&&t>=sr.cacheTrack.dts){let e=8+sr.cacheTrack.size,i=new Uint8Array(e);i[0]=e>>>24&255,i[1]=e>>>16&255,i[2]=e>>>8&255,i[3]=255&e,i.set(cs.types.mdat,4),i.set(sr.cacheTrack.data,8),sr.cacheTrack.duration=t-sr.cacheTrack.dts;let r=cs.moof(sr.cacheTrack,sr.cacheTrack.dts);sr.cacheTrack={};let s=new Uint8Array(r.byteLength+i.byteLength);s.set(r,0),s.set(i,r.byteLength),sr.appendBuffer(s.buffer)}else ar.debug.log(sr.TAG_NAME,`timeInit set false , cacheTrack = {} now dts is ${t}, and ts is ${s} cacheTrack dts is ${sr.cacheTrack&&sr.cacheTrack.dts}`),sr.timeInit=!1,sr.cacheTrack={};sr.cacheTrack||(sr.cacheTrack={}),sr.cacheTrack.id=kt,sr.cacheTrack.sequenceNumber=++sr.sequenceNumber,sr.cacheTrack.size=n,sr.cacheTrack.dts=t,sr.cacheTrack.cts=r,sr.cacheTrack.isKeyframe=i,sr.cacheTrack.data=a,sr.cacheTrack.flags={isLeading:0,dependsOn:i?2:1,isDependedOn:i?1:0,hasRedundancy:0,isNonSync:i?0:1},sr.prevTimestamp=(new Date).getTime()},_decodeAudio(e,t,i){let r=sr.isAAC?e.slice(2):e.slice(1),s=r.byteLength;if(sr.cacheAudioTrack.id&&t>=sr.cacheAudioTrack.dts){let e=8+sr.cacheAudioTrack.size,i=new Uint8Array(e);i[0]=e>>>24&255,i[1]=e>>>16&255,i[2]=e>>>8&255,i[3]=255&e,i.set(cs.types.mdat,4),i.set(sr.cacheAudioTrack.data,8),sr.cacheAudioTrack.duration=t-sr.cacheAudioTrack.dts;let r=cs.moof(sr.cacheAudioTrack,sr.cacheAudioTrack.dts);sr.cacheAudioTrack={};let s=new Uint8Array(r.byteLength+i.byteLength);s.set(r,0),s.set(i,r.byteLength),sr.appendAudioBuffer(s.buffer)}else sr.cacheAudioTrack={};sr.cacheAudioTrack||(sr.cacheAudioTrack={}),sr.cacheAudioTrack.id=It,sr.cacheAudioTrack.sequenceNumber=++sr.audioSequenceNumber,sr.cacheAudioTrack.size=s,sr.cacheAudioTrack.dts=t,sr.cacheAudioTrack.cts=0,sr.cacheAudioTrack.data=r,sr.cacheAudioTrack.flags={isLeading:0,dependsOn:1,isDependedOn:0,hasRedundancy:0}},appendBuffer(e){ar.isDestroyed?ar.debug.warn(sr.TAG_NAME,"appendBuffer() player is destroyed"):sr.mediaSourceAddSourceBufferError?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceAddSourceBufferError is true"):sr.mediaSourceAppendBufferFull?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceAppendBufferFull is true"):sr.mediaSourceAppendBufferError?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceAppendBufferError is true"):sr.mediaSourceBufferError?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceBufferError is true"):(sr.pendingSegments.push(e),sr.sourceBuffer&&(ar._opt.mseAutoCleanupSourceBuffer&&sr._needCleanupSourceBuffer()&&sr._doCleanUpSourceBuffer(),mi(sr.getSourceBufferUpdating())&&sr.isStateOpen()&&mi(sr._hasPendingRemoveRanges()))?sr._doAppendSegments():sr.isStateClosed()?(sr.mediaSourceBufferError=!0,sr.emitError(xe.mseSourceBufferError,"mediaSource is not attached to video or mediaSource is closed")):sr.isStateEnded()?(sr.mediaSourceBufferError=!0,sr.emitError(xe.mseSourceBufferError,"mediaSource is end")):sr._hasPendingRemoveRanges()&&ar.debug.log(sr.TAG_NAME,`video has pending remove ranges and video length is ${sr.pendingRemoveRanges.length}, audio length is ${sr.pendingAudioRemoveRanges.length}`))},appendAudioBuffer(e){ar.isDestroyed?ar.debug.warn(sr.TAG_NAME,"appendAudioBuffer() player is destroyed"):sr.mediaSourceAddSourceBufferError?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceAddSourceBufferError is true"):sr.mediaSourceAppendBufferFull?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceAppendBufferFull is true"):sr.mediaSourceAppendBufferError?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceAppendBufferError is true"):sr.mediaSourceBufferError?ar.debug.warn(sr.TAG_NAME,"mseDecoder.mediaSourceBufferError is true"):(sr.pendingAudioSegments.push(e),sr.audioSourceBuffer&&(ar._opt.mseAutoCleanupSourceBuffer&&sr._needCleanupSourceBuffer()&&sr._doCleanUpSourceBuffer(),mi(sr.getAudioSourceBufferUpdating())&&sr.isStateOpen()&&mi(sr._hasPendingRemoveRanges()))?sr._doAppendSegments():sr.isStateClosed()?(sr.mediaSourceBufferError=!0,sr.emitError(xe.mseSourceBufferError,"mediaSource is not attached to video or mediaSource is closed")):sr.isStateEnded()?(sr.mediaSourceBufferError=!0,sr.emitError(xe.mseSourceBufferError,"mediaSource is end")):sr._hasPendingRemoveRanges()&&ar.debug.log(sr.TAG_NAME,`audio has pending remove ranges and video length is ${sr.pendingRemoveRanges.length}, audio length is ${sr.pendingAudioRemoveRanges.length}`))},getSourceBufferUpdating:()=>sr.sourceBuffer&&sr.sourceBuffer.updating,getAudioSourceBufferUpdating:()=>sr.audioSourceBuffer&&sr.audioSourceBuffer.updating,stop(){sr.abortSourceBuffer(),sr.removeSourceBuffer(),sr.endOfStream()},clearUpAllSourceBuffer(){if(sr.sourceBuffer){const e=sr.sourceBuffer.buffered;for(let t=0;t<e.length;t++){let i=e.start(t),r=e.end(t);sr.pendingRemoveRanges.push({start:i,end:r})}mi(sr.getSourceBufferUpdating())&&sr._doRemoveRanges()}if(sr.audioSourceBuffer){const e=sr.audioSourceBuffer.buffered;for(let t=0;t<e.length;t++){let i=e.start(t),r=e.end(t);sr.pendingAudioRemoveRanges.push({start:i,end:r})}mi(sr.getAudioSourceBufferUpdating())&&sr._doRemoveRanges()}},endOfStream(){if(sr.isStateOpen()&&xi)if(sr.getSourceBufferUpdating()||sr.getAudioSourceBufferUpdating())ar.debug.log(sr.TAG_NAME,"endOfStream() has pending eos"),sr.hasPendingEos=!0;else{sr.hasPendingEos=!1;try{ar.debug.log(sr.TAG_NAME,"endOfStream()"),sr.mediaSource.endOfStream()}catch(e){ar.debug.warn(sr.TAG_NAME,"endOfStream() error",e)}}},abortSourceBuffer(){if(sr.isStateOpen){if(sr.sourceBuffer){try{ar.debug.log(sr.TAG_NAME,"abortSourceBuffer() abort sourceBuffer"),sr.sourceBuffer.abort()}catch(e){}mi(sr.getSourceBufferUpdating())&&sr._doRemoveRanges()}if(sr.audioSourceBuffer){try{ar.debug.log(sr.TAG_NAME,"abortSourceBuffer() abort audioSourceBuffer"),sr.audioSourceBuffer.abort()}catch(e){}mi(sr.getAudioSourceBufferUpdating())&&sr._doRemoveRanges()}}sr.sourceBuffer=null,sr.audioSourceBuffer=null},removeSourceBuffer(){if(!sr.isStateClosed()&&sr.mediaSource){if(sr.sourceBuffer)try{ar.debug.log(sr.TAG_NAME,"removeSourceBuffer() sourceBuffer"),sr.mediaSource.removeSourceBuffer(sr.sourceBuffer)}catch(e){ar.debug.warn(sr.TAG_NAME,"removeSourceBuffer() sourceBuffer error",e)}if(sr.audioSourceBuffer)try{ar.debug.log(sr.TAG_NAME,"removeSourceBuffer() audioSourceBuffer"),sr.mediaSource.removeSourceBuffer(sr.audioSourceBuffer)}catch(e){ar.debug.warn(sr.TAG_NAME,"removeSourceBuffer() audioSourceBuffer error",e)}}},_hasPendingSegments:()=>sr.pendingSegments.length>0||sr.pendingAudioSegments.length>0,getPendingSegmentsLength:()=>sr.pendingSegments.length,_handleUpdatePlaybackRate(){},_doAppendSegments(){if(sr.isStateClosed()||sr.isStateEnded())ar.debug.log(sr.TAG_NAME,"_doAppendSegments() mediaSource is closed or ended and return");else if(null!==sr.sourceBuffer){if(sr.needInitAudio()&&null===sr.audioSourceBuffer)return ar.debug.log(sr.TAG_NAME,"_doAppendSegments() audioSourceBuffer is null and need init audio source buffer"),void(null===sr.audioSourceBufferCheckTimeout&&(sr.audioSourceBufferCheckTimeout=setTimeout((()=>{sr._clearAudioSourceBufferCheckTimeout(),sr.emitError(xe.mediaSourceAudioInitTimeout)}),1e3)));if(mi(sr.getSourceBufferUpdating())&&sr.pendingSegments.length>0){const e=sr.pendingSegments.shift();try{sr.sourceBuffer.appendBuffer(e)}catch(e){ar.debug.error(sr.TAG_NAME,"mseDecoder.sourceBuffer.appendBuffer()",e.code,e),22===e.code?(sr.stop(),sr.mediaSourceAppendBufferFull=!0,sr.emitError(xe.mediaSourceFull)):11===e.code?(sr.stop(),sr.mediaSourceAppendBufferError=!0,sr.emitError(xe.mediaSourceAppendBufferError)):(sr.stop(),sr.mediaSourceBufferError=!0,sr.emitError(xe.mseSourceBufferError,e.code))}}if(mi(sr.getAudioSourceBufferUpdating())&&sr.pendingAudioSegments.length>0){const e=sr.pendingAudioSegments.shift();try{sr.audioSourceBuffer.appendBuffer(e)}catch(e){ar.debug.error(sr.TAG_NAME,"mseDecoder.audioSourceBuffer.appendBuffer()",e.code,e),22===e.code?(sr.stop(),sr.mediaSourceAppendBufferFull=!0,sr.emitError(xe.mediaSourceFull)):11===e.code?(sr.stop(),sr.mediaSourceAppendBufferError=!0,sr.emitError(xe.mediaSourceAppendBufferError)):(sr.stop(),sr.mediaSourceBufferError=!0,sr.emitError(xe.mseSourceBufferError,e.code))}}}else ar.debug.log(sr.TAG_NAME,"_doAppendSegments() sourceBuffer is null and wait init and return")},_doCleanUpSourceBuffer(){const e=sr.$video.currentTime;if(sr.sourceBuffer){const t=sr.sourceBuffer.buffered;let i=!1;for(let r=0;r<t.length;r++){let s=t.start(r),a=t.end(r);if(s<=e&&e<a+3){if(e-s>=ar._opt.mseAutoCleanupMaxBackwardDuration){i=!0;let t=e-ar._opt.mseAutoCleanupMinBackwardDuration;sr.pendingRemoveRanges.push({start:s,end:t})}}else a<e&&(i=!0,sr.pendingRemoveRanges.push({start:s,end:a}))}i&&mi(sr.getSourceBufferUpdating())&&sr._doRemoveRanges()}if(sr.audioSourceBuffer){const t=sr.audioSourceBuffer.buffered;let i=!1;for(let r=0;r<t.length;r++){let s=t.start(r),a=t.end(r);if(s<=e&&e<a+3){if(e-s>=ar._opt.mseAutoCleanupMaxBackwardDuration){i=!0;let t=e-ar._opt.mseAutoCleanupMinBackwardDuration;sr.pendingAudioRemoveRanges.push({start:s,end:t})}}else a<e&&(i=!0,sr.pendingAudioRemoveRanges.push({start:s,end:a}))}i&&mi(sr.getAudioSourceBufferUpdating())&&sr._doRemoveRanges()}},_hasPendingRemoveRanges:()=>sr.pendingRemoveRanges.length>0||sr.pendingAudioRemoveRanges.length>0,needInitAudio:()=>ar._opt.hasAudio&&ar._opt.mseDecodeAudio,_doRemoveRanges(){if(sr.sourceBuffer&&mi(sr.getSourceBufferUpdating())){let e=sr.pendingRemoveRanges;for(;e.length&&mi(sr.getSourceBufferUpdating());){let t=e.shift();try{sr.sourceBuffer.remove(t.start,t.end)}catch(e){ar.debug.warn(sr.TAG_NAME,"_doRemoveRanges() sourceBuffer error",e)}}}if(sr.audioSourceBuffer&&mi(sr.getAudioSourceBufferUpdating())){let e=sr.pendingAudioRemoveRanges;for(;e.length&&mi(sr.getAudioSourceBufferUpdating());){let t=e.shift();try{sr.audioSourceBuffer.remove(t.start,t.end)}catch(e){ar.debug.warn(sr.TAG_NAME,"_doRemoveRanges() audioSourceBuffer error",e)}}}},_getPlaybackRate(){},_needCleanupSourceBuffer(){if(mi(ar._opt.mseAutoCleanupSourceBuffer))return!1;const e=sr.$video.currentTime;if(sr.sourceBuffer){let t=sr.sourceBuffer.buffered;if(t.length>=1&&e-t.start(0)>=ar._opt.mseAutoCleanupMaxBackwardDuration)return!0}if(sr.audioSourceBuffer){let t=sr.audioSourceBuffer.buffered;if(t.length>=1&&e-t.start(0)>=ar._opt.mseAutoCleanupMaxBackwardDuration)return!0}return!1},_clearAudioSourceBufferCheckTimeout(){sr.audioSourceBufferCheckTimeout&&(clearTimeout(sr.audioSourceBufferCheckTimeout),sr.audioSourceBufferCheckTimeout=null)},_clearAudioNoDataCheckTimeout(){sr.audioSourceNoDataCheckTimeout&&(clearTimeout(sr.audioSourceNoDataCheckTimeout),sr.audioSourceNoDataCheckTimeout=null)},getHandle:()=>sr.mediaSource.handle,emitError(e){postMessage({cmd:Q,value:e,msg:arguments.length>1&&void 0!==arguments[1]?arguments[1]:""})}});let ar={isPlayer:!0,isPlayback:!1,dropping:!1,isPushDropping:!1,isWorkerFetch:!1,isDestroyed:!1,fetchStatus:Bt,_opt:Ni(),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(){ar.stopStreamRateAndStatsInterval(),g=setInterval((()=>{m&&m(0);const e=JSON.stringify({demuxBufferDelay:ar.getVideoBufferLength(),audioDemuxBufferDelay:ar.getAudioBufferLength(),streamBufferByteLength:ar.getStreamBufferLength(),netBuf:ar.networkDelay||0,pushLatestDelay:ar.pushLatestDelay||0,latestDelay:ar.delay,isStreamTsMoreThanLocal:Xe});postMessage({cmd:P,type:Ae,value:e})}),1e3)},stopStreamRateAndStatsInterval:function(){g&&(clearInterval(g),g=null)},useOffscreen:function(){return ar._opt.useOffscreen&&"undefined"!=typeof OffscreenCanvas},getDelay:function(e,t){if(!e||ar._opt.hasVideo&&!je)return-1;if(t===ee)return ar.delay;if(ar.preDelayTimestamp&&ar.preDelayTimestamp>e)return ar.preDelayTimestamp-e>1e3&&ar.debug.warn("worker",`getDelay() and preDelayTimestamp is ${ar.preDelayTimestamp} > timestamp is ${e} more than ${ar.preDelayTimestamp-e}ms and return ${ar.delay}`),ar.preDelayTimestamp=e,ar.delay;if(ar.firstTimestamp){if(e){const t=Date.now()-ar.startTimestamp,i=e-ar.firstTimestamp;t>=i?(Xe=!1,ar.delay=t-i):(Xe=!0,ar.delay=i-t)}}else ar.firstTimestamp=e,ar.startTimestamp=Date.now(),ar.delay=-1;return ar.preDelayTimestamp=e,ar.delay},getDelayNotUpdateDelay:function(e,t){if(!e||ar._opt.hasVideo&&!je)return-1;if(t===ee)return ar.pushLatestDelay;if(ar.preDelayTimestamp&&ar.preDelayTimestamp-e>1e3)return ar.debug.warn("worker",`getDelayNotUpdateDelay() and preDelayTimestamp is ${ar.preDelayTimestamp} > timestamp is ${e} more than ${ar.preDelayTimestamp-e}ms and return -1`),-1;if(ar.firstTimestamp){let t=-1;if(e){const i=Date.now()-ar.startTimestamp,r=e-ar.firstTimestamp;i>=r?(Xe=!1,t=i-r):(Xe=!0,t=r-i)}return t}return-1},resetDelay:function(){ar.firstTimestamp=null,ar.startTimestamp=null,ar.delay=-1,ar.dropping=!1},resetAllDelay:function(){ar.resetDelay(),ar.preDelayTimestamp=null},doDecode:function(e){ar._opt.isEmitSEI&&e.type===te&&ar.isWorkerFetch&&ar.findSei(e.payload,e.ts),ar.isPlayUseMSEAndDecoderInWorker()?e.type===ee?ar._opt.mseDecodeAudio?sr.decodeAudio(e.payload,e.ts):e.decoder.decode(e.payload,e.ts):e.type===te&&sr.decodeVideo(e.payload,e.ts,e.isIFrame,e.cts):ar._opt.useWCS&&ar.useOffscreen()&&e.type===te&&a.decode?a.decode(e.payload,e.ts,e.cts):e.decoder.decode(e.payload,e.ts,e.isIFrame,e.cts)},decodeNext(e){if(0===r.length)return;const t=e.ts,s=r[0],a=e.type===te&&pi(e.payload);if(mi(i))a&&(ar.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 ${a}`),r.shift(),ar.doDecode(s));else{const i=s.ts-t,n=s.type===ee&&e.type===te;(i<=20||n||a)&&(ar.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 ${i} and isVideoAndNextAudio is ${n} and isVideoSqeHeader is ${a}`),r.shift(),ar.doDecode(s))}},init:function(){ar.debug.log("worker","init and opt is",JSON.stringify(ar._opt));const e=ar._opt.playType===f,t=ar._opt.playType===p;if($i.init(),ar.isPlayer=e,ar.isPlayback=t,ar.isPlayUseMSEAndDecoderInWorker()&&sr&&sr.init(),ar.isPlaybackCacheBeforeDecodeForFpsRender())ar.debug.log("worker","playback and playbackIsCacheBeforeDecodeForFpsRender is true");else{ar.debug.log("worker","setInterval()");const t=ar._opt.videoBuffer+ar._opt.videoBufferDelay,i=()=>{let i=null;if(r.length){if(ar.isPushDropping)return void ar.debug.warn("worker",`loop() isPushDropping is true and bufferList length is ${r.length}`);if(ar.dropping){for(i=r.shift(),ar.debug.warn("worker",`loop() dropBuffer is dropping and isIFrame ${i.isIFrame} and delay is ${ar.delay} and bufferlist is ${r.length}`);!i.isIFrame&&r.length;)i=r.shift();const e=ar.getDelayNotUpdateDelay(i.ts,i.type);i.isIFrame&&e<=ar.getNotDroppingDelayTs()&&(ar.debug.log("worker","loop() is dropping = false, is iFrame"),ar.dropping=!1,ar.doDecode(i),ar.decodeNext(i))}else if(ar.isPlayback||ar.isPlayUseMSE()||0===ar._opt.videoBuffer)for(;r.length;)i=r.shift(),ar.doDecode(i);else if(i=r[0],-1===ar.getDelay(i.ts,i.type))ar.debug.log("worker","loop() common dumex delay is -1 ,data.ts is",i.ts),r.shift(),ar.doDecode(i),ar.decodeNext(i);else if(ar.delay>t&&e)ar.hasIframeInBufferList()?(ar.debug.log("worker",`delay is ${ar.delay} > maxDelay ${t}, set dropping is true`),ar.resetAllDelay(),ar.dropping=!0,postMessage({cmd:R})):(r.shift(),ar.doDecode(i),ar.decodeNext(i));else for(;r.length;){if(i=r[0],!(ar.getDelay(i.ts,i.type)>ar._opt.videoBuffer)){ar.delay<0&&ar.debug.warn("worker",`loop() do not decode and delay is ${ar.delay}, bufferList is ${r.length}`);break}r.shift(),ar.doDecode(i)}}else-1!==ar.delay&&ar.debug.log("worker","loop() bufferList is empty and reset delay"),ar.resetAllDelay()};ar.stopId=setInterval((()=>{let e=(new Date).getTime();st||(st=e);const t=e-st;t>100&&ar.debug.warn("worker",`loop demux diff time is ${t}`),i(),st=(new Date).getTime()}),20)}if(mi(ar._opt.checkFirstIFrame)&&(je=!0),ar.isPlayUseMSEAndDecoderInWorker()&&sr){const e=sr.getHandle();e&&postMessage({cmd:Z,mseHandle:e},[e])}},playbackCacheLoop:function(){ar.stopId&&(clearInterval(ar.stopId),ar.stopId=null);const e=()=>{let e=null;r.length&&(e=r.shift(),ar.doDecode(e))};e();const t=Math.ceil(1e3/(ar.streamFps*ar._opt.playbackRate));ar.debug.log("worker",`playbackCacheLoop fragDuration is ${t}, streamFps is ${ar.streamFps}, streamAudioFps is ${ar.streamAudioFps} ,streamVideoFps is ${ar.streamVideoFps} playbackRate is ${ar._opt.playbackRate}`),ar.stopId=setInterval(e,t)},close:function(){if(ar.debug.log("worker","close"),ar.isDestroyed=!0,Gi(),!o||1!==o.readyState&&2!==o.readyState?o&&ar.debug.log("worker",`close() and socket.readyState is ${o.readyState}`):(wi=!0,o.close(1e3,"Client disconnecting")),o=null,ar.stopStreamRateAndStatsInterval(),ar.stopId&&(clearInterval(ar.stopId),ar.stopId=null),ar.mp3Demuxer&&(ar.mp3Demuxer.destroy(),ar.mp3Demuxer=null),ar.writableStream&&mi(ar.writableStream.locked)&&ar.writableStream.close().catch((e=>{ar.debug.log("worker","close() and writableStream.close() error",e)})),ar.writableStream=null,nr)try{nr.clear&&nr.clear(),nr=null}catch(e){ar.debug.warn("worker","close() and audioDecoder.clear error",e)}if(or)try{or.clear&&or.clear(),or=null}catch(e){ar.debug.warn("worker","close() and videoDecoder.clear error",e)}m=null,st=null,Xe=!1,a&&(a.reset&&a.reset(),a=null),sr&&(sr.destroy(),sr=null),ar.firstTimestamp=null,ar.startTimestamp=null,ar.networkDelay=0,ar.streamFps=null,ar.streamAudioFps=null,ar.streamVideoFps=null,ar.delay=-1,ar.pushLatestDelay=-1,ar.preDelayTimestamp=null,ar.dropping=!1,ar.isPushDropping=!1,ar.isPlayer=!0,ar.isPlayback=!1,ar.isWorkerFetch=!1,ar._opt=Ni(),ar.webglObj&&(ar.webglObj.destroy(),ar.offscreenCanvas.removeEventListener("webglcontextlost",ar.onOffscreenCanvasWebglContextLost),ar.offscreenCanvas.removeEventListener("webglcontextrestored",ar.onOffscreenCanvasWebglContextRestored),ar.offscreenCanvas=null,ar.offscreenCanvasGL=null,ar.offscreenCanvasCtx=null),r=[],s=[],v&&(v.buffer=null,v=null),me=null,Ne=null,We=!1,Ye=!1,je=!1,Wt=!1,Kt=!1,ti=!1,bi=null,Si=null,ft=[],wt=0,Et=0,ut=null,ht=null,Rt=null,zt=null,vi=null,Nt=0,Gt=0,pt=null,vt=null,ar.fetchStatus=Bt,xi=!0,$i.destroy(),tr.destroy(),ir.destroy(),rr.destroy(),postMessage({cmd:V})},pushBuffer:function(e,t){if(t.type===ee&&Vt(e)){if(ar.debug.log("worker",`pushBuffer audio ts is ${t.ts}, isAacCodecPacket is true`),ar._opt.isRecordTypeFlv){const t=new Uint8Array(e);postMessage({cmd:q,buffer:t},[t.buffer])}ar.decodeAudio(e,t.ts)}else if(t.type===te&&t.isIFrame&&pi(e)){if(ar.debug.log("worker",`pushBuffer video ts is ${t.ts}, isVideoSequenceHeader is true`),ar._opt.isRecordTypeFlv){const t=new Uint8Array(e);postMessage({cmd:j,buffer:t},[t.buffer])}ar.decodeVideo(e,t.ts,t.isIFrame,t.cts)}else{if(ar._opt.isRecording)if(ar._opt.isRecordTypeFlv){const i=new Uint8Array(e);postMessage({cmd:K,type:t.type,buffer:i,ts:t.ts},[i.buffer])}else if(ar._opt.recordType===_)if(t.type===te){const i=new Uint8Array(e).slice(5);postMessage({cmd:D,buffer:i,isIFrame:t.isIFrame,ts:t.ts,cts:t.cts},[i.buffer])}else if(t.type===ee&&ar._opt.isWasmMp4){const i=new Uint8Array(e),r=$t(i)?i.slice(2):i.slice(1);postMessage({cmd:T,buffer:r,ts:t.ts},[r.buffer])}if(ar.isPlayer&&Nt>0&&zt>0&&t.type===te){const e=t.ts-zt,i=Nt+Nt/2;e>i&&ar.debug.log("worker",`pushBuffer video\n ts is ${t.ts}, preTimestamp is ${zt},\n diff is ${e} and preTimestampDuration is ${Nt} and maxDiff is ${i}\n maybe trigger black screen or flower screen\n `)}if(ar.isPlayer&&zt>0&&t.type===te&&t.ts<zt&&zt-t.ts>y&&(ar.debug.warn("worker",`pushBuffer,\n preTimestamp is ${zt}, options.ts is ${t.ts},\n diff is ${zt-t.ts} more than 3600000,\n and resetAllDelay`),ar.resetAllDelay(),zt=null,Nt=0),ar.isPlayer&&zt>0&&t.ts<=zt&&t.type===te&&(ar.debug.warn("worker",`pushBuffer() and isIFrame is ${t.isIFrame} and,\n options.ts is ${t.ts} less than (or equal) preTimestamp is ${zt} and\n payloadBufferSize is ${e.byteLength} and prevPayloadBufferSize is ${Gt}`),ar._opt.isDropSameTimestampGop&&mi(t.isIFrame)&&je)){const e=ar.hasIframeInBufferList(),t=mi(ar.isPushDropping);return ar.debug.log("worker",`pushBuffer, isDropSameTimestampGop is true and\n hasIframe is ${e} and isNotPushDropping is ${t} and next dropBuffer`),void(e&&t?ar.dropBuffer$2():(ar.clearBuffer(!0),_i(ar._opt.checkFirstIFrame)&&_i(i)&&(ar.isPlayUseMSEAndDecoderInWorker()?sr.isDecodeFirstIIframe=!1:postMessage({cmd:X}))))}if(ar.isPlayer&&je){const e=ar._opt.videoBuffer+ar._opt.videoBufferDelay,i=ar.getDelayNotUpdateDelay(t.ts,t.type);ar.pushLatestDelay=i,i>e&&ar.delay<e&&ar.delay>0&&ar.hasIframeInBufferList()&&!1===ar.isPushDropping&&(ar.debug.log("worker",`pushBuffer(), pushLatestDelay is ${i} more than ${e} and decoder.delay is ${ar.delay} and has iIframe and next decoder.dropBuffer$2()`),ar.dropBuffer$2())}if(ar.isPlayer&&t.type===te&&(zt>0&&(Nt=t.ts-zt),Gt=e.byteLength,zt=t.ts),t.type===ee?r.push({ts:t.ts,payload:e,decoder:{decode:ar.decodeAudio},type:ee,isIFrame:!1}):t.type===te&&r.push({ts:t.ts,cts:t.cts,payload:e,decoder:{decode:ar.decodeVideo},type:te,isIFrame:t.isIFrame}),ar.isPlaybackCacheBeforeDecodeForFpsRender()&&(ai(ar.streamVideoFps)||ai(ar.streamAudioFps))){let e=ar.streamVideoFps,t=ar.streamAudioFps;if(ai(ar.streamVideoFps)&&(e=ui(r,te),e&&(ar.streamVideoFps=e,postMessage({cmd:N,value:ar.streamVideoFps}),ar.streamFps=t?e+t:e,mi(ar._opt.hasAudio)&&(ar.debug.log("worker","playbackCacheBeforeDecodeForFpsRender, _opt.hasAudio is false and set streamAudioFps is 0"),ar.streamAudioFps=0),ar.playbackCacheLoop())),ai(ar.streamAudioFps)&&(t=ui(r,ee),t&&(ar.streamAudioFps=t,ar.streamFps=e?e+t:t,ar.playbackCacheLoop())),ai(ar.streamVideoFps)&&ai(ar.streamAudioFps)){const i=r.map((e=>({type:e.type,ts:e.ts})));ar.debug.log("worker",`playbackCacheBeforeDecodeForFpsRender, calc streamAudioFps is ${t}, streamVideoFps is ${e}, bufferListLength is ${r.length}, and ts list is ${JSON.stringify(i)}`)}const i=ar.getAudioBufferLength()>0,s=i?60:40;r.length>=s&&(ar.debug.warn("worker",`playbackCacheBeforeDecodeForFpsRender, bufferListLength is ${r.length} more than ${s}, and hasAudio is ${i} an set streamFps is 25`),ar.streamVideoFps=25,postMessage({cmd:N,value:ar.streamVideoFps}),i?(ar.streamAudioFps=25,ar.streamFps=ar.streamVideoFps+ar.streamAudioFps):ar.streamFps=ar.streamVideoFps,ar.playbackCacheLoop())}}},getVideoBufferLength(){let e=0;return r.forEach((t=>{t.type===te&&(e+=1)})),e},hasIframeInBufferList:()=>r.some((e=>e.type===te&&e.isIFrame)),isAllIframeInBufferList(){const e=ar.getVideoBufferLength();let t=0;return r.forEach((e=>{e.type===te&&e.isIFrame&&(t+=1)})),e===t},getNotDroppingDelayTs:()=>ar._opt.videoBuffer+ar._opt.videoBufferDelay/2,getAudioBufferLength(){let e=0;return r.forEach((t=>{t.type===ee&&(e+=1)})),e},getStreamBufferLength(){let e=0;return v&&v.buffer&&(e=v.buffer.byteLength),ar._opt.isNakedFlow?$i.lastBuf&&(e=$i.lastBuf.byteLength):ar._opt.isTs?rr._remainingPacketData&&(e=rr._remainingPacketData.byteLength):ar._opt.isFmp4&&tr.mp4Box&&(e=tr.mp4Box.getAllocatedSampleDataSize()),e},fetchStream:function(e,t){ar.debug.log("worker","fetchStream, url is "+e,"options:",JSON.stringify(t)),ar.isWorkerFetch=!0,t.isFlv?ar._opt.isFlv=!0:t.isFmp4?ar._opt.isFmp4=!0:t.isMpeg4?ar._opt.isMpeg4=!0:t.isNakedFlow?ar._opt.isNakedFlow=!0:t.isTs&&(ar._opt.isTs=!0),m=ii((e=>{postMessage({cmd:P,type:ye,value:e})})),ar.startStreamRateAndStatsInterval(),t.isFmp4&&(tr.listenMp4Box(),ar._opt.isFmp4Private&&tr.initTransportDescarmber()),t.protocol===c?(v=new Ai(ar.demuxFlv()),fetch(e,{signal:n.signal}).then((e=>{if(_i(wi))return ar.debug.log("worker","request abort and run res.body.cancel()"),ar.fetchStatus=Bt,void e.body.cancel();if(!hi(e))return ar.debug.warn("worker",`fetch response status is ${e.status} and ok is ${e.ok} and emit error and next abort()`),Gi(),void postMessage({cmd:P,type:xe.fetchError,value:`fetch response status is ${e.status} and ok is ${e.ok}`});if(postMessage({cmd:P,type:we}),li())ar.writableStream=new WritableStream({write:e=>n&&n.signal&&n.signal.aborted?(ar.debug.log("worker","writableStream write() and abortController.signal.aborted is true so return"),void(ar.fetchStatus=Ct)):_i(wi)?(ar.debug.log("worker","writableStream write() and requestAbort is true so return"),void(ar.fetchStatus=Ct)):void("string"!=typeof e?(ar.fetchStatus=Tt,m(e.byteLength),t.isFlv?v.write(e):t.isFmp4?ar.demuxFmp4(e):t.isMpeg4?ar.demuxMpeg4(e):t.isTs&&ar.demuxTs(e)):ar.debug.warn("worker",`writableStream write() and value is "${e}" string so return`)),close:()=>{ar.debug.log("worker","writableStream close()"),ar.fetchStatus=Ct,v=null,Gi(),postMessage({cmd:P,type:ge,value:u,msg:"fetch done"})},abort:e=>{if(n&&n.signal&&n.signal.aborted)return ar.debug.log("worker","writableStream abort() and abortController.signal.aborted is true so return"),void(ar.fetchStatus=Ct);v=null,e.name!==At?(ar.debug.log("worker",`writableStream abort() and e is ${e.toString()}`),Gi(),postMessage({cmd:P,type:xe.fetchError,value:e.toString()})):ar.debug.log("worker","writableStream abort() and e.name is AbortError so return")}}),e.body.pipeTo(ar.writableStream);else{const i=e.body.getReader(),r=()=>{i.read().then((e=>{let{done:i,value:s}=e;return i?(ar.debug.log("worker","fetchNext().then() and done is true"),ar.fetchStatus=Ct,v=null,Gi(),void postMessage({cmd:P,type:ge,value:u,msg:"fetch done"})):n&&n.signal&&n.signal.aborted?(ar.debug.log("worker","fetchNext().then() and abortController.signal.aborted is true so return"),void(ar.fetchStatus=Ct)):_i(wi)?(ar.debug.log("worker","fetchNext().then() and requestAbort is true so return"),void(ar.fetchStatus=Ct)):void("string"!=typeof s?(ar.fetchStatus=Tt,m(s.byteLength),t.isFlv?v.write(s):t.isFmp4?ar.demuxFmp4(s):t.isMpeg4?ar.demuxMpeg4(s):t.isTs&&ar.demuxTs(s),r()):ar.debug.warn("worker",`fetchNext().then() and value "${s}" is string so return`))})).catch((e=>{if(n&&n.signal&&n.signal.aborted)return ar.debug.log("worker","fetchNext().catch() and abortController.signal.aborted is true so return"),void(ar.fetchStatus=Ct);v=null,e.name!==At?(ar.debug.log("worker",`fetchNext().catch() and e is ${e.toString()}`),Gi(),postMessage({cmd:P,type:xe.fetchError,value:e.toString()})):ar.debug.log("worker","fetchNext().catch() and e.name is AbortError so return")}))};r()}})).catch((e=>{n&&n.signal&&n.signal.aborted?ar.debug.log("worker","fetch().catch() and abortController.signal.aborted is true so return"):e.name!==At?(ar.debug.log("worker",`fetch().catch() and e is ${e.toString()}`),Gi(),postMessage({cmd:P,type:xe.fetchError,value:e.toString()}),v=null):ar.debug.log("worker","fetch().catch() and e.name is AbortError so return")}))):t.protocol===l&&(t.isFlv&&(v=new Ai(ar.demuxFlv())),o=new WebSocket(e),o.binaryType="arraybuffer",o.onopen=()=>{ar.debug.log("worker","fetchStream, WebsocketStream socket open"),postMessage({cmd:P,type:we}),postMessage({cmd:P,type:Ee})},o.onclose=e=>{_e?ar.debug.log("worker","fetchStream, WebsocketStream socket close and isSocketError is true , so return"):(ar.debug.log("worker",`fetchStream, WebsocketStream socket close and code is ${e.code}`),1006===e.code&&ar.debug.error("worker",`fetchStream, WebsocketStream socket close abnormally and code is ${e.code}`),_i(wi)?ar.debug.log("worker","fetchStream, WebsocketStream socket close and requestAbort is true so return"):(v=null,postMessage({cmd:P,type:ge,value:h,msg:e.code})))},o.onerror=e=>{ar.debug.error("worker","fetchStream, WebsocketStream socket error",e),_e=!0,v=null,postMessage({cmd:P,type:xe.websocketError,value:e.isTrusted?"websocket user aborted":"websocket error"})},o.onmessage=e=>{"string"!=typeof e.data?(m(e.data.byteLength),t.isFlv?v.write(e.data):t.isFmp4?ar.demuxFmp4(e.data):t.isMpeg4?ar.demuxMpeg4(e.data):ar._opt.isNakedFlow?ar.demuxNakedFlow(e.data):ar.demuxM7s(e.data)):ar.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),i=new Uint32Array(e);for(;;){t[3]=0;const e=yield 15,r=e[4];t[0]=e[7],t[1]=e[6],t[2]=e[5];const s=i[0];t[0]=e[10],t[1]=e[9],t[2]=e[8],t[3]=e[11];let a=i[0];const n=(yield s).slice();switch(r){case ie:if(n.byteLength>0){let e=n;_i(ar._opt.m7sCryptoAudio)&&(e=ar.cryptoPayloadAudio(n)),ar.decode(e,{type:ee,ts:a})}else ar.debug.warn("worker",`demuxFlv() type is audio and payload.byteLength is ${n.byteLength} and return`);break;case re:if(n.byteLength>=6){const e=n[0];if(ar._isEnhancedH265Header(e))ar._decodeEnhancedH265Video(n,a);else{const e=15&n[0];let t=n[0]>>4===xt;const r=e===Ce;if(mi(t)&&_i(yi(n,r))&&(ar.debug.log("worker","demux() isIFrame is false and unit type is IDR and update to true"),t=!0),t&&pi(n)&&null===bi){const e=15&n[0];bi=e===Ce,Si=Jt(n,bi),ar.debug.log("worker",`demuxFlv() isVideoSequenceHeader is true and isHevc is ${bi} and nalUnitSize is ${Si}`)}t&&ar.calcIframeIntervalTimestamp(a),ar.isPlayer&&ar.calcNetworkDelay(a),i[0]=n[4],i[1]=n[3],i[2]=n[2],i[3]=0;let s=i[0],o=ar.cryptoPayload(n,t);ar.decode(o,{type:te,ts:a,isIFrame:t,cts:s})}}else ar.debug.warn("worker",`demuxFlv() type is video and payload.byteLength is ${n.byteLength} and return`);break;case se:postMessage({cmd:Y,buffer:n},[n.buffer]);break;default:ar.debug.log("worker",`demuxFlv() type is ${r}`)}}},decode:function(e,t){t.type===ee?ar._opt.hasAudio&&(postMessage({cmd:P,type:be,value:e.byteLength}),ar.isPlayer?ar.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts}):ar.isPlayback&&(ar.isPlaybackOnlyDecodeIFrame()||(ar.isPlaybackCacheBeforeDecodeForFpsRender(),ar.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts})))):t.type===te&&ar._opt.hasVideo&&(postMessage({cmd:P,type:Se,value:e.byteLength}),postMessage({cmd:P,type:ve,value:t.ts}),ar.isPlayer?ar.pushBuffer(e,{type:t.type,ts:t.ts,isIFrame:t.isIFrame,cts:t.cts}):ar.isPlayback&&(ar.isPlaybackOnlyDecodeIFrame()?t.isIFrame&&ar.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts,isIFrame:t.isIFrame}):(ar.isPlaybackCacheBeforeDecodeForFpsRender(),ar.pushBuffer(e,{type:t.type,ts:t.ts,cts:t.cts,isIFrame:t.isIFrame}))))},cryptoPayload:function(e,t){let i=e;return ar._opt.isM7sCrypto?ar._opt.cryptoIV&&ar._opt.cryptoIV.byteLength>0&&ar._opt.cryptoKey&&ar._opt.cryptoKey.byteLength>0?i=Pr(e,ar._opt.cryptoKey,ar._opt.cryptoIV,bi):ar.debug.error("worker",`isM7sCrypto cryptoKey.length is ${ar._opt.cryptoKey&&ar._opt.cryptoKey.byteLength} or cryptoIV.length is ${ar._opt.cryptoIV&&ar._opt.cryptoIV.byteLength} null`):ar._opt.isSm4Crypto?ar._opt.sm4CryptoKey&&t?i=is(e,ar._opt.sm4CryptoKey):ar._opt.sm4CryptoKey||ar.debug.error("worker","isSm4Crypto opt.sm4CryptoKey is null"):ar._opt.isXorCrypto&&(ar._opt.cryptoIV&&ar._opt.cryptoIV.byteLength>0&&ar._opt.cryptoKey&&ar._opt.cryptoKey.byteLength>0?i=os(e,ar._opt.cryptoKey,ar._opt.cryptoIV,bi):ar.debug.error("worker",`isXorCrypto cryptoKey.length is ${ar._opt.cryptoKey&&ar._opt.cryptoKey.byteLength} or cryptoIV.length is ${ar._opt.cryptoIV&&ar._opt.cryptoIV.byteLength} null`)),i},cryptoPayloadAudio:function(e){let t=e;if(ar._opt.isM7sCrypto)if(ar._opt.cryptoIV&&ar._opt.cryptoIV.byteLength>0&&ar._opt.cryptoKey&&ar._opt.cryptoKey.byteLength>0){e[0]>>4===Le&&(t=Mr(e,ar._opt.cryptoKey,ar._opt.cryptoIV))}else ar.debug.error("worker",`isM7sCrypto cryptoKey.length is ${ar._opt.cryptoKey&&ar._opt.cryptoKey.byteLength} or cryptoIV.length is ${ar._opt.cryptoIV&&ar._opt.cryptoIV.byteLength} null`);return t},setCodecAudio:function(e,t){const i=e[0]>>4,r=e[0]>>1&1;if(vi=i===Le?r?16:8:0===r?8:16,nr&&nr.setCodec)if(Vt(e)||i===Fe||i===Pe||i===Me){ar.debug.log("worker",`setCodecAudio: init audio codec, codeId is ${i}`);const r=i===Le?e.slice(2):new Uint8Array(0);nr.setCodec(i,ar._opt.sampleRate,r),i===Le&&postMessage({cmd:C,buffer:r},[r.buffer]),Ye=!0,i!==Le&&(i===Me?(ar.mp3Demuxer||(ar.mp3Demuxer=new ss(ar),ar.mp3Demuxer.on("data",((e,t)=>{nr.decode(e,t)}))),ar.mp3Demuxer.dispatch(e.slice(1),t)):nr.decode(e.slice(1),t));{const e=Number("1")||1;setTimeout((()=>{ar.debug.error("worker","Jb pro 体验结束,请刷新页面再次体验(wasm内部会暂停解码),如需要购买商业授权,可以联系微信:bosswancheng"),ar.close(),postMessage({cmd:z})}),60*e*60*1e3)}}else ar.debug.warn("worker","setCodecAudio: hasInitAudioCodec is false, codecId is ",i);else ar.debug.error("worker","setCodecAudio: audioDecoder or audioDecoder.setCodec is null")},decodeAudio:function(e,t){if(ar.isDestroyed)ar.debug.log("worker","decodeAudio, decoder is destroyed and return");else if(ar.isPlayUseMSEAndDecoderInWorkerAndMseDecodeAudio())sr.decodeAudio(e,t);else if(_i(i)&&_i(ar._opt.mseDecodeAudio))postMessage({cmd:F,payload:e,ts:t,cts:t},[e.buffer]);else{const i=e[0]>>4;if(Ye){if(Vt(e))return void ar.debug.log("worker","decodeAudio and has already initialized and payload is aac codec packet so drop this frame");i===Me?ar.mp3Demuxer.dispatch(e.slice(1),t):nr.decode(i===Le?e.slice(2):e.slice(1),t)}else ar.setCodecAudio(e,t)}},setCodecVideo:function(e){const t=15&e[0];if(or&&or.setCodec)if(pi(e))if(t===Te||t===Ce){ar.debug.log("worker",`setCodecVideo: init video codec , codecId is ${t}`);const i=e.slice(5);if(t===Te&&ar._opt.useSIMD){const e=Bi(i);if(e.codecWidth>b||e.codecHeight>b)return postMessage({cmd:H}),void ar.debug.warn("worker",`setCodecVideo: SIMD H264 decode video width is too large, width is ${e.codecWidth}, height is ${e.codecHeight}`)}const r=new Uint8Array(e);We=!0,or.setCodec(t,i),postMessage({cmd:k,code:t}),postMessage({cmd:I,buffer:r,codecId:t},[r.buffer])}else ar.debug.warn("worker",`setCodecVideo: hasInitVideoCodec is false, codecId is ${t} is not H264 or H265`);else ar.debug.warn("worker",`decodeVideo: hasInitVideoCodec is false, codecId is ${t} and frameType is ${e[0]>>4} and packetType is ${e[1]}`);else ar.debug.error("worker","setCodecVideo: videoDecoder or videoDecoder.setCodec is null")},decodeVideo:function(e,t,r){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;if(ar.isDestroyed)ar.debug.log("worker","decodeVideo, decoder is destroyed and return");else if(ar.isPlayUseMSEAndDecoderInWorker())sr.decodeVideo(e,t,r,s);else if(_i(i))postMessage({cmd:L,payload:e,isIFrame:r,ts:t,cts:s,delay:ar.delay},[e.buffer]);else if(We)if(!je&&r&&(je=!0),je){if(r&&pi(e)){const t=15&e[0];let i={};if(t===Te){i=Bi(e.slice(5))}else t===Ce&&(i=Hi(e));i.codecWidth&&i.codecHeight&&me&&Ne&&(i.codecWidth!==me||i.codecHeight!==Ne)&&(ar.debug.warn("worker",`\n decodeVideo: video width or height is changed,\n old width is ${me}, old height is ${Ne},\n new width is ${i.codecWidth}, new height is ${i.codecHeight},\n and emit change event`),Kt=!0,postMessage({cmd:G}))}if(Kt)return void ar.debug.warn("worker","decodeVideo: video width or height is changed, and return");if(ti)return void ar.debug.warn("worker","decodeVideo: simd decode error, and return");if(pi(e))return void ar.debug.warn("worker","decodeVideo and payload is video sequence header so drop this frame");if(e.byteLength<S)return void ar.debug.warn("worker",`decodeVideo and payload is too small , payload length is ${e.byteLength}`);const i=e.slice(5);or.decode(i,r?1:0,t)}else ar.debug.log("worker","decodeVideo first frame is not iFrame");else ar.setCodecVideo(e)},clearBuffer:function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];ar.debug.log("worker",`clearBuffer,bufferList length is ${r.length}, need clear is ${e}`),e&&(r=[]),ar.isPlayer&&(ar.resetAllDelay(),_i(ar._opt.checkFirstIFrame)&&(ar.dropping=!0,postMessage({cmd:R}))),_i(ar._opt.checkFirstIFrame)&&mi(i)&&(je=!1)},dropBuffer$2:function(){if(r.length>0){let e=r.findIndex((e=>_i(e.isIFrame)&&e.type===te));if(ar.isAllIframeInBufferList())for(let t=0;t<r.length;t++){const i=r[t],s=ar.getDelayNotUpdateDelay(i.ts,i.type);if(s>=ar.getNotDroppingDelayTs()){ar.debug.log("worker",`dropBuffer$2() isAllIframeInBufferList() is true, and index is ${t} and tempDelay is ${s} and notDroppingDelayTs is ${ar.getNotDroppingDelayTs()}`),e=t;break}}if(e>=0){ar.isPushDropping=!0,postMessage({cmd:R});const t=r.length;r=r.slice(e);const i=r.shift();ar.resetAllDelay(),ar.getDelay(i.ts,i.type),ar.doDecode(i),ar.isPushDropping=!1,ar.debug.log("worker",`dropBuffer$2() iFrameIndex is ${e},and old bufferList length is ${t} ,new bufferList is ${r.length} and new delay is ${ar.delay} `)}else ar.isPushDropping=!1}0===r.length&&(ar.isPushDropping=!1)},demuxM7s:function(e){const t=new DataView(e),i=t.getUint32(1,!1),r=t.getUint8(0),s=new ArrayBuffer(4),a=new Uint32Array(s);switch(r){case ee:ar.decode(new Uint8Array(e,5),{type:ee,ts:i});break;case te:if(t.byteLength>=11){const r=new Uint8Array(e,5),s=r[0];if(ar._isEnhancedH265Header(s))ar._decodeEnhancedH265Video(r,i);else{const e=t.getUint8(5)>>4==1;if(e&&(ar.calcIframeIntervalTimestamp(i),pi(r)&&null===bi)){const e=15&r[0];bi=e===Ce}ar.isPlayer&&ar.calcNetworkDelay(i),a[0]=r[4],a[1]=r[3],a[2]=r[2],a[3]=0;let s=a[0],n=ar.cryptoPayload(r,e);ar.decode(n,{type:te,ts:i,isIFrame:e,cts:s})}}else ar.debug.warn("worker",`demuxM7s() type is video and arrayBuffer length is ${e.byteLength} and return`)}},demuxNakedFlow:function(e){$i.dispatch(e)},demuxFmp4:function(e){tr.dispatch(e)},demuxMpeg4:function(e){ir.dispatch(e)},demuxTs:function(e){rr.dispatch(e)},_decodeEnhancedH265Video:function(e,t){const i=e[0],r=48&i,s=15&i,a=e.slice(1,5),n=new ArrayBuffer(4),o=new Uint32Array(n),d="a"==String.fromCharCode(a[0]);if(bi=mi(d),s===Lt){if(r===Mt){const i=e.slice(5);if(d);else{const r=new Uint8Array(5+i.length);r.set([28,0,0,0,0],0),r.set(i,5),Si=Jt(e,bi),ar.debug.log("worker",`demuxFlv() isVideoSequenceHeader(enhancedH265) is true and isHevc is ${bi} and nalUnitSize is ${Si}`),ar.decode(r,{type:te,ts:t,isIFrame:!0,cts:0})}}}else if(s===Ft){let i=e,s=0;const a=r===Mt;if(a&&ar.calcIframeIntervalTimestamp(t),d);else{o[0]=e[4],o[1]=e[3],o[2]=e[2],o[3]=0,s=o[0];i=qi(e.slice(8),a),i=ar.cryptoPayload(i,a),ar.decode(i,{type:te,ts:t,isIFrame:a,cts:s})}}else if(s===Pt){const i=r===Mt;i&&ar.calcIframeIntervalTimestamp(t);let s=qi(e.slice(5),i);s=ar.cryptoPayload(s,i),ar.decode(s,{type:te,ts:t,isIFrame:i,cts:0})}},_isEnhancedH265Header:function(e){return(e&Dt)===Dt},findSei:function(e,t){let i=4;ni(Si)&&(i=Si);Xt(e.slice(5),i).forEach((e=>{const i=bi?e[0]>>>1&63:31&e[0];(bi&&(i===nt||i===at)||mi(bi)&&i===He)&&postMessage({cmd:W,buffer:e,ts:t},[e.buffer])}))},calcNetworkDelay:function(e){if(!(je&&e>0))return;null===ut?(ut=e,ht=Qt()):e<ut&&(ar.debug.warn("worker",`calcNetworkDelay, dts is ${e} less than bufferStartDts is ${ut}`),ut=e,ht=Qt());const t=e-ut,i=Qt()-ht,r=i>t?i-t:0;ar.networkDelay=r,r>ar._opt.networkDelay&&ar._opt.playType===f&&(ar.debug.warn("worker",`calcNetworkDelay now dts:${e}, start dts is ${ut} vs start is ${t},local diff is ${i} ,delay is ${r}`),postMessage({cmd:P,type:Ue,value:r}))},calcIframeIntervalTimestamp:function(e){null===Rt?Rt=e:Rt<e&&(vt=e-Rt,postMessage({cmd:M,value:vt}),Rt=e)},canVisibilityDecodeNotDrop:function(){return ar._opt.visibility&&me*Ne<=2073600},isPlaybackCacheBeforeDecodeForFpsRender:function(){return ar.isPlayback&&ar._opt.playbackIsCacheBeforeDecodeForFpsRender},isPlaybackOnlyDecodeIFrame:function(){return ar._opt.playbackRate>=ar._opt.playbackForwardMaxRateDecodeIFrame},isPlayUseMSE:function(){return ar.isPlayer&&ar._opt.useMSE&&_i(i)},isPlayUseMSEAndDecoderInWorker:function(){return ar.isPlayUseMSE()&&ar._opt.mseDecoderUseWorker},isPlayUseMSEAndDecoderInWorkerAndMseDecodeAudio:function(){return ar.isPlayUseMSEAndDecoderInWorker()&&ar._opt.mseDecodeAudio},playbackUpdatePlaybackRate:function(){ar.clearBuffer(!0)},onOffscreenCanvasWebglContextLost:function(e){ar.debug.error("worker","handleOffscreenCanvasWebglContextLost and next try to create webgl"),e.preventDefault(),Wt=!0,ar.webglObj.destroy(),ar.webglObj=null,ar.offscreenCanvasGL=null,setTimeout((()=>{ar.offscreenCanvasGL=ar.offscreenCanvas.getContext("webgl"),ar.offscreenCanvasGL&&ar.offscreenCanvasGL.getContextAttributes().stencil?(ar.webglObj=d(ar.offscreenCanvasGL,ar._opt.openWebglAlignment),Wt=!1):ar.debug.error("worker","handleOffscreenCanvasWebglContextLost, stencil is false")}),500)},onOffscreenCanvasWebglContextRestored:function(e){ar.debug.log("worker","handleOffscreenCanvasWebglContextRestored"),e.preventDefault()},videoInfo:function(e,t,i){postMessage({cmd:k,code:e}),postMessage({cmd:A,w:t,h:i}),me=t,Ne=i,ar.useOffscreen()&&(ar.offscreenCanvas=new OffscreenCanvas(t,i),ar.offscreenCanvasGL=ar.offscreenCanvas.getContext("webgl"),ar.webglObj=d(ar.offscreenCanvasGL,ar._opt.openWebglAlignment),ar.offscreenCanvas.addEventListener("webglcontextlost",ar.onOffscreenCanvasWebglContextLost,!1),ar.offscreenCanvas.addEventListener("webglcontextrestored",ar.onOffscreenCanvasWebglContextRestored,!1))},audioInfo:function(e,t,i){postMessage({cmd:B,code:e}),postMessage({cmd:x,sampleRate:t,channels:i,depth:vi}),Et=i},yuvData:function(t,i){if(ar.isDestroyed)return void ar.debug.log("worker","yuvData, decoder is destroyed and return");const r=me*Ne*3/2;let s=e.HEAPU8.subarray(t,t+r),a=new Uint8Array(s);if(pt=null,ar.useOffscreen())try{if(Wt)return;ar.webglObj.renderYUV(me,Ne,a);let e=ar.offscreenCanvas.transferToImageBitmap();postMessage({cmd:U,buffer:e,delay:ar.delay,ts:i},[e])}catch(e){ar.debug.error("worker","yuvData, transferToImageBitmap error is",e)}else postMessage({cmd:U,output:a,delay:ar.delay,ts:i},[a.buffer])},pcmData:function(e,i,r){if(ar.isDestroyed)return void ar.debug.log("worker","pcmData, decoder is destroyed and return");let a=i,n=[],o=0,d=ar._opt.audioBufferSize;for(let i=0;i<2;i++){let r=t.HEAPU32[(e>>2)+i]>>2;n[i]=t.HEAPF32.subarray(r,r+a)}if(wt){if(!(a>=(i=d-wt)))return wt+=a,s[0]=Float32Array.of(...s[0],...n[0]),void(2==Et&&(s[1]=Float32Array.of(...s[1],...n[1])));ft[0]=Float32Array.of(...s[0],...n[0].subarray(0,i)),2==Et&&(ft[1]=Float32Array.of(...s[1],...n[1].subarray(0,i))),postMessage({cmd:E,buffer:ft,ts:r},ft.map((e=>e.buffer))),o=i,a-=i}for(wt=a;wt>=d;wt-=d)ft[0]=n[0].slice(o,o+=d),2==Et&&(ft[1]=n[1].slice(o-d,o)),postMessage({cmd:E,buffer:ft,ts:r},ft.map((e=>e.buffer)));wt&&(s[0]=n[0].slice(o),2==Et&&(s[1]=n[1].slice(o))),n=[]},errorInfo:function(e){null===pt&&(pt=Qt());const t=Qt(),i=ei(vt>0?2*vt:5e3,1e3,5e3),r=t-pt;r>i&&(ar.debug.warn("worker",`errorInfo() emit simdDecodeError and\n iframeIntervalTimestamp is ${vt} and diff is ${r} and maxDiff is ${i}\n and replay`),ti=!0,postMessage({cmd:O}))},sendWebsocketMessage:function(e){o?o.readyState===Be?o.send(e):ar.debug.error("worker","socket is not open"):ar.debug.error("worker","socket is null")},timeEnd:function(){ar.debug.error("worker","Jb pro 体验结束,请刷新页面再次体验(wasm内部会暂停解码),如需要购买商业授权,可以联系微信:bosswancheng"),ar.close(),postMessage({cmd:z})},postStreamToMain(e,t){postMessage({cmd:$,type:t,buffer:e},[e.buffer])}};ar.debug=new Ui(ar);let nr=null;t.AudioDecoder&&(nr=new t.AudioDecoder(ar));let or=null;e.VideoDecoder&&(or=new e.VideoDecoder(ar)),postMessage({cmd:w}),self.onmessage=function(e){let t=e.data;switch(t.cmd){case ae:try{ar._opt=Object.assign(ar._opt,JSON.parse(t.opt))}catch(e){}ar.init();break;case ne:ar.pushBuffer(t.buffer,t.options);break;case oe:ar.decodeAudio(t.buffer,t.ts);break;case de:ar.decodeVideo(t.buffer,t.ts,t.isIFrame);break;case ue:ar.clearBuffer(t.needClear);break;case he:ar.fetchStream(t.url,JSON.parse(t.opt));break;case le:ar.debug.log("worker","close",JSON.stringify(t.options)),t.options&&mi(t.options.isVideoInited)&&(xi=t.options.isVideoInited),ar.close();break;case ce:ar.debug.log("worker","updateConfig",t.key,t.value),ar._opt[t.key]=t.value,"playbackRate"===t.key&&(ar.playbackUpdatePlaybackRate(),ar.isPlaybackCacheBeforeDecodeForFpsRender()&&ar.playbackCacheLoop());break;case fe:ar.sendWebsocketMessage(t.message);break;case pe:sr.$video.currentTime=Number(t.message)}}}({},{},!0)}));