=h&&t3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:-1,o=arguments.length>5&&void 0!==arguments[5]&&arguments[5];S(this,e),this.level=void 0,this.sn=void 0,this.part=void 0,this.id=void 0,this.size=void 0,this.partial=void 0,this.transmuxing={start:0,executeStart:0,executeEnd:0,end:0},this.buffering={audio:{start:0,executeStart:0,executeEnd:0,end:0},video:{start:0,executeStart:0,executeEnd:0,end:0},audiovideo:{start:0,executeStart:0,executeEnd:0,end:0}},this.level=t,this.sn=r,this.id=i,this.size=a,this.part=n,this.partial=o}));function $f(e,t){for(var r=0,i=e.length;rr.startCC||e&&e.cc1&&void 0!==arguments[1]?arguments[1]:null,r=t||e,i={frag:e,part:t,responseType:"arraybuffer",url:r.url,headers:{},rangeStart:0,rangeEnd:0},a=r.byteRangeStartOffset,n=r.byteRangeEndOffset;if(bd(a)&&bd(n)){var o,s=a,l=n;if("initSegment"===e.sn&&"AES-128"===(null==(o=e.decryptdata)?void 0:o.method)){var c=n-a;c%16&&(l=n+(16-c%16)),0!==a&&(i.resetIV=!0,s=a-16)}i.rangeStart=s,i.rangeEnd=l}return i}function sm(e,t){var r=new Error("GAP ".concat(e.gap?"tag":"attribute"," found")),i={type:Sd.MEDIA_ERROR,details:Ed.FRAG_GAP,fatal:!1,frag:e,error:r,networkDetails:null};return t&&(i.part=t),(t||e).stats.aborted=!0,new lm(i)}var lm=function(e){function t(e){var r;return S(this,t),r=_(this,t,[e.error.message]),r.data=void 0,r.data=e,r}return k(t,e),w(t)}(y(Error)),cm=function(){function e(t,r){S(this,e),this.subtle=void 0,this.aesIV=void 0,this.subtle=t,this.aesIV=r}return w(e,[{key:"decrypt",value:function(e,t){return this.subtle.decrypt({name:"AES-CBC",iv:this.aesIV},t,e)}}])}(),um=function(){function e(t,r){S(this,e),this.subtle=void 0,this.key=void 0,this.subtle=t,this.key=r}return w(e,[{key:"expandKey",value:function(){return this.subtle.importKey("raw",this.key,{name:"AES-CBC"},!1,["encrypt","decrypt"])}}])}(),dm=function(){function e(){S(this,e),this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}return w(e,[{key:"uint8ArrayToUint32Array_",value:function(e){for(var t=new DataView(e),r=new Uint32Array(4),i=0;i<4;i++)r[i]=t.getUint32(4*i);return r}},{key:"initTable",value:function(){var e=this.sBox,t=this.invSBox,r=this.subMix,i=r[0],a=r[1],n=r[2],o=r[3],s=this.invSubMix,l=s[0],c=s[1],u=s[2],d=s[3],h=new Uint32Array(256),p=0,f=0,m=0;for(m=0;m<256;m++)h[m]=m<128?m<<1:m<<1^283;for(m=0;m<256;m++){var g=f^f<<1^f<<2^f<<3^f<<4;g=g>>>8^255&g^99,e[p]=g,t[g]=p;var y=h[p],v=h[y],A=h[v],b=257*h[g]^16843008*g;i[p]=b<<24|b>>>8,a[p]=b<<16|b>>>16,n[p]=b<<8|b>>>24,o[p]=b,b=16843009*A^65537*v^257*y^16843008*p,l[g]=b<<24|b>>>8,c[g]=b<<16|b>>>16,u[g]=b<<8|b>>>24,d[g]=b,p?(p=y^h[h[h[A^y]]],f^=h[h[f]]):p=f=1}}},{key:"expandKey",value:function(e){for(var t=this.uint8ArrayToUint32Array_(e),r=!0,i=0;i>8|e>>>24}},{key:"decrypt",value:function(e,t,r){for(var i,a,n,o,s,l,c,u,d,h,p,f,m,g,y=this.keySize+6,v=this.invKeySchedule,A=this.invSBox,b=this.invSubMix,_=b[0],k=b[1],w=b[2],S=b[3],E=this.uint8ArrayToUint32Array_(r),T=E[0],C=E[1],x=E[2],R=E[3],D=new Int32Array(e),L=new Int32Array(D.length),P=this.networkToHostOrderSwap;t>>24]^k[l>>16&255]^w[c>>8&255]^S[255&u]^v[m],a=_[l>>>24]^k[c>>16&255]^w[u>>8&255]^S[255&s]^v[m+1],n=_[c>>>24]^k[u>>16&255]^w[s>>8&255]^S[255&l]^v[m+2],o=_[u>>>24]^k[s>>16&255]^w[l>>8&255]^S[255&c]^v[m+3],s=i,l=a,c=n,u=o,m+=4;i=A[s>>>24]<<24^A[l>>16&255]<<16^A[c>>8&255]<<8^A[255&u]^v[m],a=A[l>>>24]<<24^A[c>>16&255]<<16^A[u>>8&255]<<8^A[255&s]^v[m+1],n=A[c>>>24]<<24^A[u>>16&255]<<16^A[s>>8&255]<<8^A[255&l]^v[m+2],o=A[u>>>24]<<24^A[s>>16&255]<<16^A[l>>8&255]<<8^A[255&c]^v[m+3],L[t]=P(i^T),L[t+1]=P(o^C),L[t+2]=P(n^x),L[t+3]=P(a^R),T=d,C=h,x=p,R=f,t+=4}return L.buffer}}])}(),hm=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.removePKCS7Padding,a=void 0===i||i;if(S(this,e),this.logEnabled=!0,this.removePKCS7Padding=void 0,this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null,this.useSoftware=void 0,this.useSoftware=t.enableSoftwareAES,this.removePKCS7Padding=a,a)try{var n=self.crypto;n&&(this.subtle=n.subtle||n.webkitSubtle)}catch(t){}null===this.subtle&&(this.useSoftware=!0)}return w(e,[{key:"destroy",value:function(){this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null}},{key:"isSync",value:function(){return this.useSoftware}},{key:"flush",value:function(){var e=this.currentResult,t=this.remainderData;if(!e||t)return this.reset(),null;var r=new Uint8Array(e);return this.reset(),this.removePKCS7Padding?function(e){var t=e.byteLength,r=t&&new DataView(e.buffer).getUint8(t-1);return r?nh(e,0,t-r):e}(r):r}},{key:"reset",value:function(){this.currentResult=null,this.currentIV=null,this.remainderData=null,this.softwareDecrypter&&(this.softwareDecrypter=null)}},{key:"decrypt",value:function(e,t,r){var i=this;return this.useSoftware?new Promise((function(a,n){i.softwareDecrypt(new Uint8Array(e),t,r);var o=i.flush();o?a(o.buffer):n(new Error("[softwareDecrypt] Failed to decrypt data"))})):this.webCryptoDecrypt(new Uint8Array(e),t,r)}},{key:"softwareDecrypt",value:function(e,t,r){var i=this.currentIV,a=this.currentResult,n=this.remainderData;this.logOnce("JS AES decrypt"),n&&(e=Gh(n,e),this.remainderData=null);var o=this.getValidChunk(e);if(!o.length)return null;i&&(r=i);var s=this.softwareDecrypter;s||(s=this.softwareDecrypter=new dm),s.expandKey(t);var l=a;return this.currentResult=s.decrypt(o.buffer,0,r),this.currentIV=nh(o,-16).buffer,l||null}},{key:"webCryptoDecrypt",value:function(e,t,r){var i=this,a=this.subtle;return this.key===t&&this.fastAesKey||(this.key=t,this.fastAesKey=new um(a,t)),this.fastAesKey.expandKey().then((function(t){return a?(i.logOnce("WebCrypto AES decrypt"),new cm(a,new Uint8Array(r)).decrypt(e.buffer,t)):Promise.reject(new Error("web crypto not initialized"))})).catch((function(a){return Dd.warn("[decrypter]: WebCrypto Error, disable WebCrypto API, ".concat(a.name,": ").concat(a.message)),i.onWebCryptoError(e,t,r)}))}},{key:"onWebCryptoError",value:function(e,t,r){this.useSoftware=!0,this.logEnabled=!0,this.softwareDecrypt(e,t,r);var i=this.flush();if(i)return i.buffer;throw new Error("WebCrypto and softwareDecrypt: failed to decrypt data")}},{key:"getValidChunk",value:function(e){var t=e,r=e.length-e.length%16;return r!==e.length&&(t=nh(e,0,r),this.remainderData=nh(e,r)),t}},{key:"logOnce",value:function(e){this.logEnabled&&(Dd.log("[decrypter]: ".concat(e)),this.logEnabled=!1)}}])}(),pm=function(e){for(var t="",r=e.length,i=0;io.end){var u=n>c;(n2&&void 0!==arguments[2]?arguments[2]:null;if(e-t){var i={startOffset:e,endOffset:t,type:r};this.hls.trigger(wd.BUFFER_FLUSHING,i)}}},{key:"_loadInitSegment",value:function(e,t){var r=this;this._doFragLoad(e,t).then((function(t){if(!t||r.fragContextChanged(e)||!r.levels)throw new Error("init load aborted");return t})).then((function(t){var i=r.hls,a=t.payload,n=e.decryptdata;if(a&&a.byteLength>0&&null!=n&&n.key&&n.iv&&"AES-128"===n.method){var o=self.performance.now();return r.decrypter.decrypt(new Uint8Array(a),n.key.buffer,n.iv.buffer).catch((function(t){throw i.trigger(wd.ERROR,{type:Sd.MEDIA_ERROR,details:Ed.FRAG_DECRYPT_ERROR,fatal:!1,error:t,reason:t.message,frag:e}),t})).then((function(a){var n=self.performance.now();return i.trigger(wd.FRAG_DECRYPTED,{frag:e,payload:a,stats:{tstart:o,tdecrypt:n}}),t.payload=a,r.completeInitSegmentLoad(t)}))}return r.completeInitSegmentLoad(t)})).catch((function(t){r.state!==fm&&r.state!==wm&&(r.warn(t),r.resetFragmentLoading(e))}))}},{key:"completeInitSegmentLoad",value:function(e){var t=this.levels;if(!t)throw new Error("init load aborted, missing levels");var r=e.frag.stats;this.state=mm,e.frag.data=new Uint8Array(e.payload),r.parsing.start=r.buffering.start=self.performance.now(),r.parsing.end=r.buffering.end=self.performance.now(),this.tick()}},{key:"fragContextChanged",value:function(e){var t=this.fragCurrent;return!e||!t||e.sn!==t.sn||e.level!==t.level}},{key:"fragBufferedComplete",value:function(e,t){var r,i,a,n,o=this.mediaBuffer?this.mediaBuffer:this.media;if(this.log("Buffered ".concat(e.type," sn: ").concat(e.sn).concat(t?" part: "+t.index:""," of ").concat(this.playlistType===Dp?"level":"track"," ").concat(e.level," (frag:[").concat((null!=(r=e.startPTS)?r:NaN).toFixed(3),"-").concat((null!=(i=e.endPTS)?i:NaN).toFixed(3),"] > buffer:").concat(o?pm(Xf.getBuffered(o)):"(detached)",")")),"initSegment"!==e.sn){var s;if(e.type!==Pp){var l=e.elementaryStreams;if(!Object.keys(l).some((function(e){return!!l[e]})))return void(this.state=mm)}var c=null==(s=this.levels)?void 0:s[e.level];null!=c&&c.fragmentError&&(this.log("Resetting level fragment error count of ".concat(c.fragmentError," on frag buffered")),c.fragmentError=0)}this.state=mm,o&&(!this.loadedmetadata&&e.type==Dp&&o.buffered.length&&(null==(a=this.fragCurrent)?void 0:a.sn)===(null==(n=this.fragPrevious)?void 0:n.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())}},{key:"seekToStartPos",value:function(){}},{key:"_handleFragmentLoadComplete",value:function(e){var t=this.transmuxer;if(t){var r=e.frag,i=e.part,a=e.partsLoaded,n=!a||0===a.length||a.some((function(e){return!e})),o=new Zf(r.level,r.sn,r.stats.chunkCount+1,0,i?i.index:-1,!n);t.flush(o)}}},{key:"_handleFragmentLoadProgress",value:function(e){}},{key:"_doFragLoad",value:function(e,t){var r,i=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3?arguments[3]:void 0,o=null==t?void 0:t.details;if(!this.levels||!o)throw new Error("frag load aborted, missing level".concat(o?"":" detail","s"));var s=null;if(!e.encrypted||null!=(r=e.decryptdata)&&r.key?!e.encrypted&&o.encryptedFragments.length&&this.keyLoader.loadClear(e,o.encryptedFragments):(this.log("Loading key for ".concat(e.sn," of [").concat(o.startSN,"-").concat(o.endSN,"], ").concat("[stream-controller]"===this.logPrefix?"level":"track"," ").concat(e.level)),this.state=gm,this.fragCurrent=e,s=this.keyLoader.load(e).then((function(e){if(!i.fragContextChanged(e.frag))return i.hls.trigger(wd.KEY_LOADED,e),i.state===gm&&(i.state=mm),e})),this.hls.trigger(wd.KEY_LOADING,{frag:e}),null===this.fragCurrent&&(s=Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING")))),a=Math.max(e.start,a||0),this.config.lowLatencyMode&&"initSegment"!==e.sn){var l=o.partList;if(l&&n){a>e.end&&o.fragmentHint&&(e=o.fragmentHint);var c=this.getNextPart(l,e,a);if(c>-1){var u,d=l[c];return this.log("Loading part sn: ".concat(e.sn," p: ").concat(d.index," cc: ").concat(e.cc," of playlist [").concat(o.startSN,"-").concat(o.endSN,"] parts [0-").concat(c,"-").concat(l.length-1,"] ").concat("[stream-controller]"===this.logPrefix?"level":"track",": ").concat(e.level,", target: ").concat(parseFloat(a.toFixed(3)))),this.nextLoadPosition=d.start+d.duration,this.state=ym,u=s?s.then((function(r){return!r||i.fragContextChanged(r.frag)?null:i.doFragPartsLoad(e,d,t,n)})).catch((function(e){return i.handleFragLoadError(e)})):this.doFragPartsLoad(e,d,t,n).catch((function(e){return i.handleFragLoadError(e)})),this.hls.trigger(wd.FRAG_LOADING,{frag:e,part:d,targetBufferTime:a}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):u}if(!e.url||this.loadedEndOfParts(l,a))return Promise.resolve(null)}}this.log("Loading fragment ".concat(e.sn," cc: ").concat(e.cc," ").concat(o?"of ["+o.startSN+"-"+o.endSN+"] ":"").concat("[stream-controller]"===this.logPrefix?"level":"track",": ").concat(e.level,", target: ").concat(parseFloat(a.toFixed(3)))),bd(e.sn)&&!this.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),this.state=ym;var p,f=this.config.progressive;return p=f&&s?s.then((function(t){return!t||i.fragContextChanged(null==t?void 0:t.frag)?null:i.fragmentLoader.load(e,n)})).catch((function(e){return i.handleFragLoadError(e)})):Promise.all([this.fragmentLoader.load(e,f?n:void 0),s]).then((function(e){var t=h(e,1),r=t[0];return!f&&r&&n&&n(r),r})).catch((function(e){return i.handleFragLoadError(e)})),this.hls.trigger(wd.FRAG_LOADING,{frag:e,targetBufferTime:a}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):p}},{key:"doFragPartsLoad",value:function(e,t,r,i){var a=this;return new Promise((function(n,o){var s,l=[],c=null==(s=r.details)?void 0:s.partList,u=function(t){a.fragmentLoader.loadPart(e,t,i).then((function(i){l[t.index]=i;var o=i.part;a.hls.trigger(wd.FRAG_LOADED,i);var s=uf(r,e.sn,t.index+1)||df(c,e.sn,t.index+1);if(!s)return n({frag:e,part:o,partsLoaded:l});u(s)})).catch(o)};u(t)}))}},{key:"handleFragLoadError",value:function(e){if("data"in e){var t=e.data;e.data&&t.details===Ed.INTERNAL_ABORTED?this.handleFragLoadAborted(t.frag,t.part):this.hls.trigger(wd.ERROR,t)}else this.hls.trigger(wd.ERROR,{type:Sd.OTHER_ERROR,details:Ed.INTERNAL_EXCEPTION,err:e,error:e,fatal:!0});return null}},{key:"_handleTransmuxerFlush",value:function(e){var t=this.getCurrentContext(e);if(t&&this.state===bm){var r=t.frag,i=t.part,a=t.level,n=self.performance.now();r.stats.parsing.end=n,i&&(i.stats.parsing.end=n),this.updateLevelTiming(r,i,a,e.partial)}else this.fragCurrent||this.state===fm||this.state===wm||(this.state=mm)}},{key:"getCurrentContext",value:function(e){var t=this.levels,r=this.fragCurrent,i=e.level,a=e.sn,n=e.part;if(null==t||!t[i])return this.warn("Levels object was unset while buffering fragment ".concat(a," of level ").concat(i,". The current chunk will not be buffered.")),null;var o=t[i],s=n>-1?uf(o,a,n):null,l=s?s.fragment:function(e,t,r){if(null==e||!e.details)return null;var i=e.details,a=i.fragments[t-i.startSN];return a||(a=i.fragmentHint,a&&a.sn===t?a:tn&&this.flushMainBuffer(o,e.start)}else this.flushMainBuffer(0,e.start)}},{key:"getFwdBufferInfo",value:function(e,t){var r=this.getLoadPosition();return bd(r)?this.getFwdBufferInfoAtPos(e,r,t):null}},{key:"getFwdBufferInfoAtPos",value:function(e,t,r){var i=this.config.maxBufferHole,a=Xf.bufferInfo(e,t,i);if(0===a.len&&void 0!==a.nextStart){var n=this.fragmentTracker.getBufferedFrag(t,r);if(n&&a.nextStart=r&&(t.maxMaxBufferLength/=2,this.warn("Reduce max buffer length to ".concat(t.maxMaxBufferLength,"s")),!0)}},{key:"getAppendedFrag",value:function(e){var t=this.fragmentTracker.getAppendedFrag(e,Dp);return t&&"fragment"in t?t.fragment:t}},{key:"getNextFragment",value:function(e,t){var r=t.fragments,i=r.length;if(!i)return null;var a,n=this.config,o=r[0].start;if(t.live){var s=n.initialLiveManifestSize;if(it}},{key:"getNextFragmentLoopLoading",value:function(e,t,r,i,a){var n=e.gap,o=this.getNextFragment(this.nextLoadPosition,t);if(null===o)return o;if(e=o,n&&e&&!e.gap&&r.nextStart){var s=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,r.nextStart,i);if(null!==s&&r.len+s.len>=a)return this.log('buffer full after gaps in "'.concat(i,'" playlist starting at sn: ').concat(e.sn)),null}return e}},{key:"mapToInitFragWhenRequired",value:function(e){return null==e||!e.initSegment||null!=e&&e.initSegment.data||this.bitrateTest?e:e.initSegment}},{key:"getNextPart",value:function(e,t,r){for(var i=-1,a=!1,n=!0,o=0,s=e.length;o-1&&rr.start&&r.loaded}},{key:"getInitialLiveFragment",value:function(e,t){var r=this.fragPrevious,i=null;if(r){if(e.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: ".concat(r.programDateTime)),i=function(e,t,r){if(null===t||!Array.isArray(e)||!e.length||!bd(t))return null;if(t<(e[0].programDateTime||0))return null;if(t>=(e[e.length-1].endProgramDateTime||0))return null;r=r||0;for(var i=0;i=e.startSN&&a<=e.endSN){var n=t[a-e.startSN];r.cc===n.cc&&(i=n,this.log("Live playlist, switching playlist, load frag with next SN: ".concat(i.sn)))}i||(i=function(e,t){return vf(e,(function(e){return e.cct?-1:0}))}(t,r.cc),i&&this.log("Live playlist, switching playlist, load frag with same CC: ".concat(i.sn)))}}else{var o=this.hls.liveSyncPosition;null!==o&&(i=this.getFragmentAtPosition(o,this.bitrateTest?e.fragmentEnd:e.edge,e))}return i}},{key:"getFragmentAtPosition",value:function(e,t,r){var i,a=this.config,n=this.fragPrevious,o=r.fragments,s=r.endSN,l=r.fragmentHint,c=a.maxFragLookUpTolerance,u=r.partList,d=!!(a.lowLatencyMode&&null!=u&&u.length&&l);if(d&&l&&!this.bitrateTest&&(o=o.concat(l),s=l.sn),i=et-c?0:c):o[o.length-1],i){var h=i.sn-r.startSN,p=this.fragmentTracker.getState(i);if((p===Jf||p===Wf&&i.gap)&&(n=i),n&&i.sn===n.sn&&(!d||u[0].fragment.sn>i.sn)&&n&&i.level===n.level){var f=o[h+1];i=i.sn=n-t.maxFragLookUpTolerance&&a<=o;if(null!==i&&r.duration>i&&(a").concat(e.startSN," prev-sn: ").concat(s?s.sn:"na"," fragments: ").concat(i)),l}return a}},{key:"waitForCdnTuneIn",value:function(e){return e.live&&e.canBlockReload&&e.partTarget&&e.tuneInGoal>Math.max(e.partHoldBack,3*e.partTarget)}},{key:"setStartPosition",value:function(e,t){var r=this.startPosition;if(r ").concat(null==(i=this.fragCurrent)?void 0:i.url));else{var n=t.details===Ed.FRAG_GAP;n&&this.fragmentTracker.fragBuffered(a,!0);var o=t.errorAction,s=o||{},l=s.action,c=s.retryCount,u=void 0===c?0:c,d=s.retryConfig;if(o&&l===Ef&&d){this.resetStartWhenNotLoaded(this.levelLastLoaded);var h=mf(d,u);this.warn("Fragment ".concat(a.sn," of ").concat(e," ").concat(a.level," errored with ").concat(t.details,", retrying loading ").concat(u+1,"/").concat(d.maxNumRetry," in ").concat(h,"ms")),o.resolved=!0,this.retryDate=self.performance.now()+h,this.state=vm}else if(d&&o){if(this.resetFragmentErrors(e),!(u.5;i&&this.reduceMaxBufferLength(r.len);var a=!i;return a&&this.warn("Buffer full error while media.currentTime is not buffered, flush ".concat(t," buffer")),e.frag&&(this.fragmentTracker.removeFragment(e.frag),this.nextLoadPosition=e.frag.start),this.resetLoadingState(),a}return!1}},{key:"resetFragmentErrors",value:function(e){e===Lp&&(this.fragCurrent=null),this.loadedmetadata||(this.startFragRequested=!1),this.state!==fm&&(this.state=mm)}},{key:"afterBufferFlushed",value:function(e,t,r){if(e){var i=Xf.getBuffered(e);this.fragmentTracker.detectEvictedFragments(t,i,r),this.state===km&&this.resetLoadingState()}}},{key:"resetLoadingState",value:function(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=mm}},{key:"resetStartWhenNotLoaded",value:function(e){if(!this.loadedmetadata){this.startFragRequested=!1;var t=e?e.details:null;null!=t&&t.live?(this.startPosition=-1,this.setStartPosition(t,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}}},{key:"resetWhenMissingContext",value:function(e){this.warn("The loading context changed while buffering fragment ".concat(e.sn," of level ").concat(e.level,". This chunk will not be buffered.")),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState()}},{key:"removeUnbufferedFrags",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.fragmentTracker.removeFragmentsInRange(e,1/0,this.playlistType,!1,!0)}},{key:"updateLevelTiming",value:function(e,t,r,i){var a,n=this,o=r.details;if(o){if(!Object.keys(e.elementaryStreams).reduce((function(t,a){var s=e.elementaryStreams[a];if(s){var l=s.endPTS-s.startPTS;if(l<=0)return n.warn("Could not parse fragment ".concat(e.sn," ").concat(a," duration reliably (").concat(l,")")),t||!1;var c=i?0:of(o,e,s.startPTS,s.endPTS,s.startDTS,s.endDTS);return n.hls.trigger(wd.LEVEL_PTS_UPDATED,{details:o,level:r,drift:c,type:a,frag:e,start:s.startPTS,end:s.endPTS}),!0}return t}),!1)&&null===(null==(a=this.transmuxer)?void 0:a.error)){var s=new Error("Found no media in fragment ".concat(e.sn," of level ").concat(e.level," resetting transmuxer to fallback to playlist timing"));if(0===r.fragmentError&&(r.fragmentError++,e.gap=!0,this.fragmentTracker.removeFragment(e),this.fragmentTracker.fragBuffered(e,!0)),this.warn(s.message),this.hls.trigger(wd.ERROR,{type:Sd.MEDIA_ERROR,details:Ed.FRAG_PARSING_ERROR,fatal:!1,error:s,frag:e,reason:"Found no media in msn ".concat(e.sn,' of level "').concat(r.url,'"')}),!this.hls)return;this.resetTransmuxer()}this.state=_m,this.hls.trigger(wd.FRAG_PARSED,{frag:e,part:t})}else this.warn("level.details undefined")}},{key:"resetTransmuxer",value:function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)}},{key:"recoverWorkerError",value:function(e){"demuxerWorker"===e.event&&(this.fragmentTracker.removeAllFragments(),this.resetTransmuxer(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState())}},{key:"state",get:function(){return this._state},set:function(e){var t=this._state;t!==e&&(this._state=e,this.log("".concat(t,"->").concat(e)))}}])}(Gf),Cm=function(){function e(){S(this,e),this.chunks=[],this.dataLength=0}return w(e,[{key:"push",value:function(e){this.chunks.push(e),this.dataLength+=e.length}},{key:"flush",value:function(){var e,t=this.chunks,r=this.dataLength;return t.length?(e=1===t.length?t[0]:function(e,t){for(var r=new Uint8Array(t),i=0,a=0;a0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return{type:e,id:-1,pid:-1,inputTimeScale:t,sequenceNumber:-1,samples:[],dropped:0}}var Rm=function(){function e(){S(this,e),this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null,this.lastPTS=null}return w(e,[{key:"resetInitSegment",value:function(e,t,r,i){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}}},{key:"resetTimeStamp",value:function(e){this.initPTS=e,this.resetContiguity()}},{key:"resetContiguity",value:function(){this.basePTS=null,this.lastPTS=null,this.frameIndex=0}},{key:"canParse",value:function(e,t){return!1}},{key:"appendFrame",value:function(e,t,r){}},{key:"demux",value:function(e,t){this.cachedData&&(e=Gh(this.cachedData,e),this.cachedData=null);var r,i=ch(e,0),a=i?i.length:0,n=this._audioTrack,o=this._id3Track,s=i?hh(i):void 0,l=e.length;for((null===this.basePTS||0===this.frameIndex&&bd(s))&&(this.basePTS=Dm(s,t,this.initPTS),this.lastPTS=this.basePTS),null===this.lastPTS&&(this.lastPTS=this.basePTS),i&&i.length>0&&o.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:i,type:zp,duration:Number.POSITIVE_INFINITY});a>>5}function Im(e,t){return t+1=e.length)return!1;var i=Bm(e,t);if(i<=r)return!1;var a=t+i;return a===e.length||Im(e,a)}return!1}function Um(e,t,r,i,a){if(!e.samplerate){var n=function(e,t,r,i){var a,n,o,s,l=navigator.userAgent.toLowerCase(),c=i,u=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];a=1+((192&t[r+2])>>>6);var d=(60&t[r+2])>>>2;if(!(d>u.length-1))return o=(1&t[r+2])<<2,o|=(192&t[r+3])>>>6,Dd.log("manifest codec:".concat(i,", ADTS type:").concat(a,", samplingIndex:").concat(d)),/firefox/i.test(l)?d>=6?(a=5,s=new Array(4),n=d-3):(a=2,s=new Array(2),n=d):-1!==l.indexOf("android")?(a=2,s=new Array(2),n=d):(a=5,s=new Array(4),i&&(-1!==i.indexOf("mp4a.40.29")||-1!==i.indexOf("mp4a.40.5"))||!i&&d>=6?n=d-3:((i&&-1!==i.indexOf("mp4a.40.2")&&(d>=6&&1===o||/vivaldi/i.test(l))||!i&&1===o)&&(a=2,s=new Array(2)),n=d)),s[0]=a<<3,s[0]|=(14&d)>>1,s[1]|=(1&d)<<7,s[1]|=o<<3,5===a&&(s[1]|=(14&n)>>1,s[2]=(1&n)<<7,s[2]|=8,s[3]=0),{config:s,samplerate:u[d],channelCount:o,codec:"mp4a.40."+a,manifestCodec:c};var h=new Error("invalid ADTS sampling index:".concat(d));e.emit(wd.ERROR,wd.ERROR,{type:Sd.MEDIA_ERROR,details:Ed.FRAG_PARSING_ERROR,fatal:!0,error:h,reason:h.message})}(t,r,i,a);if(!n)return;e.config=n.config,e.samplerate=n.samplerate,e.channelCount=n.channelCount,e.codec=n.codec,e.manifestCodec=n.manifestCodec,Dd.log("parsed codec:".concat(e.codec,", rate:").concat(n.samplerate,", channels:").concat(n.channelCount))}}function Fm(e){return 9216e4/e}function Om(e,t,r,i,a){var n,o=i+a*Fm(e.samplerate),s=function(e,t){var r=Pm(e,t);if(t+r<=e.length){var i=Bm(e,t)-r;if(i>0)return{headerLength:r,frameLength:i}}}(t,r);if(s){var l=s.frameLength,c=s.headerLength,u=c+l,d=Math.max(0,r+u-t.length);d?(n=new Uint8Array(u-c),n.set(t.subarray(r+c,t.length),0)):n=t.subarray(r+c,r+u);var h={unit:n,pts:o};return d||e.samples.push(h),{sample:h,length:u,missing:d}}var p=t.length-r;return n=new Uint8Array(p),n.set(t.subarray(r,t.length),0),{sample:{unit:n,pts:o},length:p,missing:-1}}var Nm=null,jm=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],zm=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],Gm=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],Hm=[0,1,1,4];function Vm(e,t,r,i,a){if(!(r+24>t.length)){var n=Wm(t,r);if(n&&r+n.frameLength<=t.length){var o=i+a*(9e4*n.samplesPerFrame/n.sampleRate),s={unit:t.subarray(r,r+n.frameLength),pts:o,dts:o};return e.config=[],e.channelCount=n.channelCount,e.samplerate=n.sampleRate,e.samples.push(s),{sample:s,length:n.frameLength,missing:0}}}}function Wm(e,t){var r=e[t+1]>>3&3,i=e[t+1]>>1&3,a=e[t+2]>>4&15,n=e[t+2]>>2&3;if(1!==r&&0!==a&&15!==a&&3!==n){var o=e[t+2]>>1&1,s=e[t+3]>>6,l=1e3*jm[14*(3===r?3-i:3===i?3:4)+a-1],c=zm[3*(3===r?0:2===r?1:2)+n],u=3===s?1:2,d=Gm[r][i],h=Hm[i],p=8*d*h,f=Math.floor(d*l/c+o)*h;if(null===Nm){var m=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Nm=m?parseInt(m[1]):0}return!!Nm&&Nm<=87&&2===i&&l>=224e3&&0===s&&(e[t+3]=128|e[t+3]),{sampleRate:c,channelCount:u,frameLength:f,samplesPerFrame:p}}}function Jm(e,t){return 255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}function qm(e,t){return t+10;){o[0]=e[t];var s=Math.min(i,8),l=8-s;n[0]=4278190080>>>24+l<>l,r=r?r<t.length)return-1;if(11!==t[r]||119!==t[r+1])return-1;var n=t[r+4]>>6;if(n>=3)return-1;var o=[48e3,44100,32e3][n],s=63&t[r+4],l=2*[64,69,96,64,70,96,80,87,120,80,88,120,96,104,144,96,105,144,112,121,168,112,122,168,128,139,192,128,140,192,160,174,240,160,175,240,192,208,288,192,209,288,224,243,336,224,244,336,256,278,384,256,279,384,320,348,480,320,349,480,384,417,576,384,418,576,448,487,672,448,488,672,512,557,768,512,558,768,640,696,960,640,697,960,768,835,1152,768,836,1152,896,975,1344,896,976,1344,1024,1114,1536,1024,1115,1536,1152,1253,1728,1152,1254,1728,1280,1393,1920,1280,1394,1920][3*s+n];if(r+l>t.length)return-1;var c=t[r+6]>>5,u=0;2===c?u+=2:(1&c&&1!==c&&(u+=2),4&c&&(u+=2));var d=(t[r+6]<<8|t[r+7])>>12-u&1,h=[2,1,2,3,3,4,4,5][c]+d,p=t[r+5]>>3,f=7&t[r+5],m=new Uint8Array([n<<6|p<<1|f>>2,(3&f)<<6|c<<3|d<<2|s>>4,s<<4&224]),g=i+a*(1536/o*9e4),y=t.subarray(r,r+l);return e.config=m,e.channelCount=h,e.samplerate=o,e.samples.push({unit:y,pts:g}),l}var $m=function(){function e(){S(this,e),this.VideoSample=null}return w(e,[{key:"createVideoSample",value:function(e,t,r,i){return{key:e,frame:!1,pts:t,dts:r,units:[],debug:i,length:0}}},{key:"getLastNalUnit",value:function(e){var t,r,i=this.VideoSample;if(i&&0!==i.units.length||(i=e[e.length-1]),null!=(t=i)&&t.units){var a=i.units;r=a[a.length-1]}return r}},{key:"pushAccessUnit",value:function(e,t){if(e.units.length&&e.frame){if(void 0===e.pts){var r=t.samples,i=r.length;if(!i)return void t.dropped++;var a=r[i-1];e.pts=a.pts,e.dts=a.dts}t.samples.push(e)}e.debug.length&&Dd.log(e.pts+"/"+e.dts+":"+e.debug)}}])}(),eg=function(){function e(t){S(this,e),this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=t,this.bytesAvailable=t.byteLength,this.word=0,this.bitsAvailable=0}return w(e,[{key:"loadWord",value:function(){var e=this.data,t=this.bytesAvailable,r=e.byteLength-t,i=new Uint8Array(4),a=Math.min(4,t);if(0===a)throw new Error("no bytes available");i.set(e.subarray(r,r+a)),this.word=new DataView(i.buffer).getUint32(0),this.bitsAvailable=8*a,this.bytesAvailable-=a}},{key:"skipBits",value:function(e){var t;e=Math.min(e,8*this.bytesAvailable+this.bitsAvailable),this.bitsAvailable>e?(this.word<<=e,this.bitsAvailable-=e):(t=(e-=this.bitsAvailable)>>3,e-=t<<3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)}},{key:"readBits",value:function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;if(e>32&&Dd.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0)this.word<<=t;else{if(!(this.bytesAvailable>0))throw new Error("no bits available");this.loadWord()}return t=e-t,t>0&&this.bitsAvailable?r<>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"readUShort",value:function(){return this.readBits(16)}},{key:"readUInt",value:function(){return this.readBits(32)}},{key:"skipScalingList",value:function(e){for(var t,r=8,i=8,a=0;a4){var p=new eg(h).readSliceType();2!==p&&4!==p&&7!==p&&9!==p||(u=!0)}u&&null!=(d=l)&&d.frame&&!l.key&&(o.pushAccessUnit(l,e),l=o.VideoSample=null),l||(l=o.VideoSample=o.createVideoSample(!0,r.pts,r.dts,"")),l.frame=!0,l.key=u;break;case 5:n=!0,null!=(s=l)&&s.frame&&!l.key&&(o.pushAccessUnit(l,e),l=o.VideoSample=null),l||(l=o.VideoSample=o.createVideoSample(!0,r.pts,r.dts,"")),l.key=!0,l.frame=!0;break;case 6:n=!0,Wh(i.data,1,r.pts,t.samples);break;case 7:var f,m;n=!0,c=!0;var g=i.data,y=new eg(g).readSPS();if(!e.sps||e.width!==y.width||e.height!==y.height||(null==(f=e.pixelRatio)?void 0:f[0])!==y.pixelRatio[0]||(null==(m=e.pixelRatio)?void 0:m[1])!==y.pixelRatio[1]){e.width=y.width,e.height=y.height,e.pixelRatio=y.pixelRatio,e.sps=[g],e.duration=a;for(var v=g.subarray(1,4),A="avc1.",b=0;b<3;b++){var _=v[b].toString(16);_.length<2&&(_="0"+_),A+=_}e.codec=A}break;case 8:n=!0,e.pps=[i.data];break;case 9:n=!0,e.audFound=!0,l&&o.pushAccessUnit(l,e),l=o.VideoSample=o.createVideoSample(!1,r.pts,r.dts,"");break;case 12:n=!0;break;default:n=!1,l&&(l.debug+="unknown NAL "+i.type+" ")}l&&n&&l.units.push(i)})),i&&l&&(this.pushAccessUnit(l,e),this.VideoSample=null)}},{key:"parseAVCNALu",value:function(e,t){var r,i,a,n=t.byteLength,o=e.naluState||0,s=o,l=[],c=0,u=-1,d=0;for(-1===o&&(u=0,d=31&t[0],o=0,c=1);c=0){var h={data:t.subarray(u,i),type:d};l.push(h)}else{var p=this.getLastNalUnit(e.samples);p&&(s&&c<=4-s&&p.state&&(p.data=p.data.subarray(0,p.data.byteLength-s)),i>0&&(p.data=Gh(p.data,t.subarray(0,i)),p.state=0))}c=0&&o>=0){var f={data:t.subarray(u,n),type:d,state:o};l.push(f)}if(0===l.length){var m=this.getLastNalUnit(e.samples);m&&(m.data=Gh(m.data,t))}return e.naluState=o,l}}])}($m),rg=function(){function e(t,r,i){S(this,e),this.keyData=void 0,this.decrypter=void 0,this.keyData=i,this.decrypter=new hm(r,{removePKCS7Padding:!1})}return w(e,[{key:"decryptBuffer",value:function(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer)}},{key:"decryptAacSample",value:function(e,t,r){var i=this,a=e[t].unit;if(!(a.length<=16)){var n=a.subarray(16,a.length-a.length%16),o=n.buffer.slice(n.byteOffset,n.byteOffset+n.length);this.decryptBuffer(o).then((function(n){var o=new Uint8Array(n);a.set(o,16),i.decrypter.isSync()||i.decryptAacSamples(e,t+1,r)}))}}},{key:"decryptAacSamples",value:function(e,t,r){for(;;t++){if(t>=e.length)return void r();if(!(e[t].unit.length<32)&&(this.decryptAacSample(e,t,r),!this.decrypter.isSync()))return}}},{key:"getAvcEncryptedData",value:function(e){for(var t=16*Math.floor((e.length-48)/160)+16,r=new Int8Array(t),i=0,a=32;a=e.length)return void i();for(var a=e[t].units;!(r>=a.length);r++){var n=a[r];if(!(n.data.length<=48||1!==n.type&&5!==n.type||(this.decryptAvcSample(e,t,r,i,n),this.decrypter.isSync())))return}}}}])}(),ig=188,ag=function(){function e(t,r,i){S(this,e),this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._videoTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.remainderData=null,this.videoParser=void 0,this.observer=t,this.config=r,this.typeSupported=i,this.videoParser=new tg}return w(e,[{key:"resetInitSegment",value:function(t,r,i,a){this.pmtParsed=!1,this._pmtId=-1,this._videoTrack=e.createTrack("video"),this._audioTrack=e.createTrack("audio",a),this._id3Track=e.createTrack("id3"),this._txtTrack=e.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=i,this._duration=a}},{key:"resetTimeStamp",value:function(){}},{key:"resetContiguity",value:function(){var e=this._audioTrack,t=this._videoTrack,r=this._id3Track;e&&(e.pesData=null),t&&(t.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null,this.remainderData=null}},{key:"demux",value:function(t,r){var i,a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];a||(this.sampleAes=null);var o=this._videoTrack,s=this._audioTrack,l=this._id3Track,c=this._txtTrack,u=o.pid,d=o.pesData,h=s.pid,p=l.pid,f=s.pesData,m=l.pesData,g=null,y=this.pmtParsed,v=this._pmtId,A=t.length;if(this.remainderData&&(A=(t=Gh(this.remainderData,t)).length,this.remainderData=null),A>4>1){if(E=k+5+t[k+4],E===k+ig)continue}else E=k+4;switch(S){case u:w&&(d&&(i=cg(d))&&this.videoParser.parseAVCPES(o,c,i,!1,this._duration),d={data:[],size:0}),d&&(d.data.push(t.subarray(E,k+ig)),d.size+=k+ig-E);break;case h:if(w){if(f&&(i=cg(f)))switch(s.segmentCodec){case"aac":this.parseAACPES(s,i);break;case"mp3":this.parseMPEGPES(s,i);break;case"ac3":this.parseAC3PES(s,i)}f={data:[],size:0}}f&&(f.data.push(t.subarray(E,k+ig)),f.size+=k+ig-E);break;case p:w&&(m&&(i=cg(m))&&this.parseID3PES(l,i),m={data:[],size:0}),m&&(m.data.push(t.subarray(E,k+ig)),m.size+=k+ig-E);break;case 0:w&&(E+=t[E]+1),v=this._pmtId=og(t,E);break;case v:w&&(E+=t[E]+1);var T=sg(t,E,this.typeSupported,a);u=T.videoPid,u>0&&(o.pid=u,o.segmentCodec=T.segmentVideoCodec),h=T.audioPid,h>0&&(s.pid=h,s.segmentCodec=T.segmentAudioCodec),p=T.id3Pid,p>0&&(l.pid=p),null===g||y||(Dd.warn("MPEG-TS PMT found at ".concat(k," after unknown PID '").concat(g,"'. Backtracking to sync byte @").concat(b," to parse all TS packets.")),g=null,k=b-188),y=this.pmtParsed=!0;break;case 17:case 8191:break;default:g=S}}else _++;if(_>0){var C=new Error("Found ".concat(_," TS packet/s that do not start with 0x47"));this.observer.emit(wd.ERROR,wd.ERROR,{type:Sd.MEDIA_ERROR,details:Ed.FRAG_PARSING_ERROR,fatal:!1,error:C,reason:C.message})}o.pesData=d,s.pesData=f,l.pesData=m;var x={audioTrack:s,videoTrack:o,id3Track:l,textTrack:c};return n&&this.extractRemainingSamples(x),x}},{key:"flush",value:function(){var e,t=this.remainderData;return this.remainderData=null,e=t?this.demux(t,-1,!1,!0):{videoTrack:this._videoTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(e),this.sampleAes?this.decrypt(e,this.sampleAes):e}},{key:"extractRemainingSamples",value:function(e){var t,r=e.audioTrack,i=e.videoTrack,a=e.id3Track,n=e.textTrack,o=i.pesData,s=r.pesData,l=a.pesData;if(o&&(t=cg(o))?(this.videoParser.parseAVCPES(i,n,t,!0,this._duration),i.pesData=null):i.pesData=o,s&&(t=cg(s))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,t);break;case"mp3":this.parseMPEGPES(r,t);break;case"ac3":this.parseAC3PES(r,t)}r.pesData=null}else null!=s&&s.size&&Dd.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=s;l&&(t=cg(l))?(this.parseID3PES(a,t),a.pesData=null):a.pesData=l}},{key:"demuxSampleAes",value:function(e,t,r){var i=this.demux(e,r,!0,!this.config.progressive),a=this.sampleAes=new rg(this.observer,this.config,t);return this.decrypt(i,a)}},{key:"decrypt",value:function(e,t){return new Promise((function(r){var i=e.audioTrack,a=e.videoTrack;i.samples&&"aac"===i.segmentCodec?t.decryptAacSamples(i.samples,0,(function(){a.samples?t.decryptAvcSamples(a.samples,0,0,(function(){r(e)})):r(e)})):a.samples&&t.decryptAvcSamples(a.samples,0,0,(function(){r(e)}))}))}},{key:"destroy",value:function(){this._duration=0}},{key:"parseAACPES",value:function(e,t){var r,i,a,n=0,o=this.aacOverFlow,s=t.data;if(o){this.aacOverFlow=null;var l=o.missing,c=o.sample.unit.byteLength;if(-1===l)s=Gh(o.sample.unit,s);else{var u=c-l;o.sample.unit.set(s.subarray(0,l),u),e.samples.push(o.sample),n=o.missing}}for(r=n,i=s.length;r0;)s+=a;else Dd.warn("[tsdemuxer]: AC3 PES unknown PTS")}},{key:"parseID3PES",value:function(e,t){if(void 0!==t.pts){var r=Ad({},t,{type:this._videoTrack?Hp:zp,duration:Number.POSITIVE_INFINITY});e.samples.push(r)}else Dd.warn("[tsdemuxer]: ID3 PES unknown PTS")}}],[{key:"probe",value:function(t){var r=e.syncOffset(t);return r>0&&Dd.warn("MPEG2-TS detected but first sync word found @ offset ".concat(r)),-1!==r}},{key:"syncOffset",value:function(e){for(var t=e.length,r=Math.min(940,t-ig)+1,i=0;i1&&(0===n&&o>2||s+ig>r))return n}i++}return-1}},{key:"createTrack",value:function(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:Th[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===e?t:void 0}}}])}();function ng(e,t){return((31&e[t+1])<<8)+e[t+2]}function og(e,t){return(31&e[t+10])<<8|e[t+11]}function sg(e,t,r,i){var a={audioPid:-1,videoPid:-1,id3Pid:-1,segmentVideoCodec:"avc",segmentAudioCodec:"aac"},n=t+3+((15&e[t+1])<<8|e[t+2])-4;for(t+=12+((15&e[t+10])<<8|e[t+11]);t0)for(var l=t+5,c=s;c>2;){106===e[l]&&(!0!==r.ac3?Dd.log("AC-3 audio found, not supported in this browser for now"):(a.audioPid=o,a.segmentAudioCodec="ac3"));var u=e[l+1]+2;l+=u,c-=u}break;case 194:case 135:Dd.warn("Unsupported EC-3 in M2TS found");break;case 36:Dd.warn("Unsupported HEVC in M2TS found")}t+=s+5}return a}function lg(e){Dd.log("".concat(e," with AES-128-CBC encryption found in unencrypted stream"))}function cg(e){var t,r,i,a,n,o=0,s=e.data;if(!e||0===e.size)return null;for(;s[0].length<19&&s.length>1;)s[0]=Gh(s[0],s[1]),s.splice(1,1);if(t=s[0],1===(t[0]<<16)+(t[1]<<8)+t[2]){if(r=(t[4]<<8)+t[5],r&&r>e.size-6)return null;var l=t[7];192&l&&(a=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,64&l?(n=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2,a-n>54e5&&(Dd.warn("".concat(Math.round((a-n)/9e4),"s delta between PTS and DTS, align them")),a=n)):n=a),i=t[8];var c=i+9;if(e.size<=c)return null;e.size-=c;for(var u=new Uint8Array(e.size),d=0,h=s.length;dp){c-=p;continue}t=t.subarray(c),p-=c,c=0}u.set(t,o),o+=p}return r&&(r-=i+3),{data:u,pts:a,dts:n,len:r}}return null}var ug=function(){function e(){S(this,e)}return w(e,null,[{key:"getSilentFrame",value:function(e,t){if("mp4a.40.2"===e){if(1===t)return new Uint8Array([0,200,0,128,35,128]);if(2===t)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224])}else{if(1===t)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94])}}}])}(),dg=Math.pow(2,32)-1,hg=function(){function e(){S(this,e)}return w(e,null,[{key:"init",value:function(){var t;for(t in e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],dac3:[],"ac-3":[],mvex:[],mvhd:[],pasp:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);var r=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]),i=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.HDLR_TYPES={video:r,audio:i};var a=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),n=new Uint8Array([0,0,0,0,0,0,0,0]);e.STTS=e.STSC=e.STCO=n,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);var o=new Uint8Array([105,115,111,109]),s=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,o,l,o,s),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,a))}},{key:"box",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i>24&255,s[1]=a>>16&255,s[2]=a>>8&255,s[3]=255&a,s.set(e,4),n=0,a=8;n>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,85,196,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value:function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))}},{key:"moof",value:function(t,r,i){return e.box(e.types.moof,e.mfhd(t),e.traf(i,r))}},{key:"moov",value:function(t){for(var r=t.length,i=[];r--;)i[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(e.mvex(t)))}},{key:"mvex",value:function(t){for(var r=t.length,i=[];r--;)i[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(i))}},{key:"mvhd",value:function(t,r){r*=t;var i=Math.floor(r/(dg+1)),a=Math.floor(r%(dg+1)),n=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,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]);return e.box(e.types.mvhd,n)}},{key:"sdtp",value:function(t){var r,i,a=t.samples||[],n=new Uint8Array(4+a.length);for(r=0;r>>8&255),n.push(255&a),n=n.concat(Array.prototype.slice.call(i));for(r=0;r>>8&255),o.push(255&a),o=o.concat(Array.prototype.slice.call(i));var s=e.box(e.types.avcC,new Uint8Array([1,n[3],n[4],n[5],255,224|t.sps.length].concat(n).concat([t.pps.length]).concat(o))),l=t.width,c=t.height,u=t.pixelRatio[0],d=t.pixelRatio[1];return e.box(e.types.avc1,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,l>>8&255,255&l,c>>8&255,255&c,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),s,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),e.box(e.types.pasp,new Uint8Array([u>>24,u>>16&255,u>>8&255,255&u,d>>24,d>>16&255,d>>8&255,255&d])))}},{key:"esds",value:function(e){var t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))}},{key:"audioStsd",value:function(e){var t=e.samplerate;return new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,t>>8&255,255&t,0,0])}},{key:"mp4a",value:function(t){return e.box(e.types.mp4a,e.audioStsd(t),e.box(e.types.esds,e.esds(t)))}},{key:"mp3",value:function(t){return e.box(e.types[".mp3"],e.audioStsd(t))}},{key:"ac3",value:function(t){return e.box(e.types["ac-3"],e.audioStsd(t),e.box(e.types.dac3,t.config))}},{key:"stsd",value:function(t){return"audio"===t.type?"mp3"===t.segmentCodec&&"mp3"===t.codec?e.box(e.types.stsd,e.STSD,e.mp3(t)):"ac3"===t.segmentCodec?e.box(e.types.stsd,e.STSD,e.ac3(t)):e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){var r=t.id,i=t.duration*t.timescale,a=t.width,n=t.height,o=Math.floor(i/(dg+1)),s=Math.floor(i%(dg+1));return e.box(e.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,o>>24,o>>16&255,o>>8&255,255&o,s>>24,s>>16&255,s>>8&255,255&s,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,a>>8&255,255&a,0,0,n>>8&255,255&n,0,0]))}},{key:"traf",value:function(t,r){var i=e.sdtp(t),a=t.id,n=Math.floor(r/(dg+1)),o=Math.floor(r%(dg+1));return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a])),e.box(e.types.tfdt,new Uint8Array([1,0,0,0,n>>24,n>>16&255,n>>8&255,255&n,o>>24,o>>16&255,o>>8&255,255&o])),e.trun(t,i.length+16+20+8+16+8+8),i)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(t,r){var i,a,n,o,s,l,c=t.samples||[],u=c.length,d=12+16*u,h=new Uint8Array(d);for(r+=8+d,h.set(["video"===t.type?1:0,0,15,1,u>>>24&255,u>>>16&255,u>>>8&255,255&u,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i>>24&255,n>>>16&255,n>>>8&255,255&n,o>>>24&255,o>>>16&255,o>>>8&255,255&o,s.isLeading<<2|s.dependsOn,s.isDependedOn<<6|s.hasRedundancy<<4|s.paddingValue<<1|s.isNonSync,61440&s.degradPrio,15&s.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return e.box(e.types.trun,h)}},{key:"initSegment",value:function(t){e.types||e.init();var r=e.moov(t);return Gh(e.FTYP,r)}}])}();function pg(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=e*t*r;return i?Math.round(a):a}function fg(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return pg(e,1e3,1/9e4,t)}hg.types=void 0,hg.HDLR_TYPES=void 0,hg.STTS=void 0,hg.STSC=void 0,hg.STCO=void 0,hg.STSZ=void 0,hg.VMHD=void 0,hg.SMHD=void 0,hg.STSD=void 0,hg.FTYP=void 0,hg.DINF=void 0;var mg,gg=null,yg=null,vg=function(){function e(t,r,i){if(S(this,e),this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=null,this._initDTS=null,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.videoTrackConfig=void 0,this.observer=t,this.config=r,this.typeSupported=i,this.ISGenerated=!1,null===gg){var a=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);gg=a?parseInt(a[1]):0}if(null===yg){var n=navigator.userAgent.match(/Safari\/(\d+)/i);yg=n?parseInt(n[1]):0}}return w(e,[{key:"destroy",value:function(){this.config=this.videoTrackConfig=this._initPTS=this._initDTS=null}},{key:"resetTimeStamp",value:function(e){Dd.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=e}},{key:"resetNextTimestamp",value:function(){Dd.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1}},{key:"resetInitSegment",value:function(){Dd.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1,this.videoTrackConfig=void 0}},{key:"getVideoStartPts",value:function(e){var t=!1,r=e.reduce((function(e,r){var i=r.pts-e;return i<-4294967296?(t=!0,Ag(e,r.pts)):i>0?e:r.pts}),e[0].pts);return t&&Dd.debug("PTS rollover detected"),r}},{key:"remux",value:function(e,t,r,i,a,n,o,s){var l,c,u,d,h,p,f=a,m=a,g=e.pid>-1,y=t.pid>-1,v=t.samples.length,A=e.samples.length>0,b=o&&v>0||v>1;if((!g||A)&&(!y||b)||this.ISGenerated||o){if(this.ISGenerated){var _,k,w,S,E=this.videoTrackConfig;!E||t.width===E.width&&t.height===E.height&&(null==(_=t.pixelRatio)?void 0:_[0])===(null==(k=E.pixelRatio)?void 0:k[0])&&(null==(w=t.pixelRatio)?void 0:w[1])===(null==(S=E.pixelRatio)?void 0:S[1])||this.resetInitSegment()}else u=this.generateIS(e,t,a,n);var T,C=this.isVideoContiguous,x=-1;if(b&&(x=function(e){for(var t=0;t0){Dd.warn("[mp4-remuxer]: Dropped ".concat(x," out of ").concat(v," video samples due to a missing keyframe"));var R=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(x),t.dropped+=x,m+=(t.samples[0].pts-R)/t.inputTimeScale,T=m}else-1===x&&(Dd.warn("[mp4-remuxer]: No keyframe found out of ".concat(v," video samples")),p=!1);if(this.ISGenerated){if(A&&b){var D=this.getVideoStartPts(t.samples),L=(Ag(e.samples[0].pts,D)-D)/t.inputTimeScale;f+=Math.max(0,L),m+=Math.max(0,-L)}if(A){if(e.samplerate||(Dd.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),u=this.generateIS(e,t,a,n)),c=this.remuxAudio(e,f,this.isAudioContiguous,n,y||b||s===Lp?m:void 0),b){var P=c?c.endPTS-c.startPTS:0;t.inputTimeScale||(Dd.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),u=this.generateIS(e,t,a,n)),l=this.remuxVideo(t,m,C,P)}}else b&&(l=this.remuxVideo(t,m,C,0));l&&(l.firstKeyFrame=x,l.independent=-1!==x,l.firstKeyFramePTS=T)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(r.samples.length&&(h=bg(r,a,this._initPTS,this._initDTS)),i.samples.length&&(d=_g(i,a,this._initPTS))),{audio:c,video:l,initSegment:u,independent:p,text:d,id3:h}}},{key:"generateIS",value:function(e,t,r,i){var a,n,o,s=e.samples,l=t.samples,c=this.typeSupported,u={},d=this._initPTS,h=!d||i,p="audio/mp4";if(h&&(a=n=1/0),e.config&&s.length){switch(e.timescale=e.samplerate,e.segmentCodec){case"mp3":c.mpeg?(p="audio/mpeg",e.codec=""):c.mp3&&(e.codec="mp3");break;case"ac3":e.codec="ac-3"}u.audio={id:"audio",container:p,codec:e.codec,initSegment:"mp3"===e.segmentCodec&&c.mpeg?new Uint8Array(0):hg.initSegment([e]),metadata:{channelCount:e.channelCount}},h&&(o=e.inputTimeScale,d&&o===d.timescale?h=!1:a=n=s[0].pts-Math.round(o*r))}if(t.sps&&t.pps&&l.length){if(t.timescale=t.inputTimeScale,u.video={id:"main",container:"video/mp4",codec:t.codec,initSegment:hg.initSegment([t]),metadata:{width:t.width,height:t.height}},h)if(o=t.inputTimeScale,d&&o===d.timescale)h=!1;else{var f=this.getVideoStartPts(l),m=Math.round(o*r);n=Math.min(n,Ag(l[0].dts,f)-m),a=Math.min(a,f-m)}this.videoTrackConfig={width:t.width,height:t.height,pixelRatio:t.pixelRatio}}if(Object.keys(u).length)return this.ISGenerated=!0,h?(this._initPTS={baseTime:a,timescale:o},this._initDTS={baseTime:n,timescale:o}):a=o=void 0,{tracks:u,initPTS:a,timescale:o}}},{key:"remuxVideo",value:function(e,t,r,i){var a,n,o=e.inputTimeScale,s=e.samples,l=[],c=s.length,u=this._initPTS,d=this.nextAvcDts,h=8,p=this.videoSampleDuration,f=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,g=!1;if(!r||null===d){var y=t*o,v=s[0].pts-Ag(s[0].dts,s[0].pts);gg&&null!==d&&Math.abs(y-v-d)<15e3?r=!0:d=y-v}for(var A=u.baseTime*o/u.timescale,b=0;b