!function e(t){var r,i;r=this,i=function(){"use strict";function r(e,t){for(var r=0;r=this.minWeight_},t.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},t.getEstimateTTFB=function(){return this.ttfb_.getTotalWeight()>=this.minWeight_?this.ttfb_.getEstimate():this.defaultTTFB_},t.destroy=function(){},i(e,[{key:"defaultEstimate",get:function(){return this.defaultEstimate_}}])}(),N=function(e,t){this.trace=void 0,this.debug=void 0,this.log=void 0,this.warn=void 0,this.info=void 0,this.error=void 0;var r="["+e+"]:";this.trace=B,this.debug=t.debug.bind(null,r),this.log=t.log.bind(null,r),this.warn=t.warn.bind(null,r),this.info=t.info.bind(null,r),this.error=t.error.bind(null,r)},B=function(){},U={trace:B,debug:B,log:B,warn:B,info:B,error:B};function G(){return n({},U)}function V(e,t,r){return t[e]?t[e].bind(t):function(e,t){var r=self.console[e];return r?r.bind(self.console,(t?"["+t+"] ":"")+"["+e+"] >"):B}(e,r)}var H=G();function K(e,t,r){var i=G();if("object"==typeof console&&!0===e||"object"==typeof e){var a=["debug","log","info","warn","error"];a.forEach((function(t){i[t]=V(t,e,r)}));try{i.log('Debug logs enabled for "'+t+'" in hls.js version 1.6.2')}catch(e){return G()}a.forEach((function(t){H[t]=V(t,e)}))}else n(H,i);return i}var W,Y,j=H,q=Y?W:(Y=1,W=void 0),X=v(q);function z(e,t){if(void 0===t&&(t=!1),"undefined"!=typeof TextDecoder){var r=new TextDecoder("utf-8").decode(e);if(t){var i=r.indexOf("\0");return-1!==i?r.substring(0,i):r}return r.replace(/\0/g,"")}for(var a,n,s,o=e.length,l="",u=0;u>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:l+=String.fromCharCode(a);break;case 12:case 13:n=e[u++],l+=String.fromCharCode((31&a)<<6|63&n);break;case 14:n=e[u++],s=e[u++],l+=String.fromCharCode((15&a)<<12|(63&n)<<6|(63&s)<<0)}}return l}var Q=function(e){for(var t="",r=0;r1||1===r&&this.levelkeys[t[0]].encrypted)return!0}return!1}},{key:"programDateTime",get:function(){return null===this._programDateTime&&this.rawProgramDateTime&&(this.programDateTime=Date.parse(this.rawProgramDateTime)),this._programDateTime},set:function(e){L(e)?this._programDateTime=e:this._programDateTime=this.rawProgramDateTime=null}},{key:"ref",get:function(){return re(this)?(this._ref||(this._ref={base:this.base,start:this.start,duration:this.duration,sn:this.sn,programDateTime:this.programDateTime}),this._ref):null}}])}(te),ae=function(e){function t(t,r,i,a,n){var s;(s=e.call(this,i)||this).fragOffset=0,s.duration=0,s.gap=!1,s.independent=!1,s.relurl=void 0,s.fragment=void 0,s.index=void 0,s.duration=t.decimalFloatingPoint("DURATION"),s.gap=t.bool("GAP"),s.independent=t.bool("INDEPENDENT"),s.relurl=t.enumeratedString("URI"),s.fragment=r,s.index=a;var o=t.enumeratedString("BYTERANGE");return o&&s.setByteRange(o,n),n&&(s.fragOffset=n.fragOffset+n.duration),s}return o(t,e),i(t,[{key:"start",get:function(){return this.fragment.start+this.fragOffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var e=this.elementaryStreams;return!!(e.audio||e.video||e.audiovideo)}}])}(te);function ne(e,t){var r=Object.getPrototypeOf(e);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i||ne(r,t)}}var se=Math.pow(2,32)-1,oe=[].push,le={video:1,audio:2,id3:3,text:4};function ue(e){return String.fromCharCode.apply(null,e)}function de(e,t){var r=e[t]<<8|e[t+1];return r<0?65536+r:r}function he(e,t){var r=ce(e,t);return r<0?4294967296+r:r}function fe(e,t){var r=he(e,t);return r*=Math.pow(2,32),r+=he(e,t+4)}function ce(e,t){return e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function ve(e,t,r){e[t]=r>>24,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r}function ge(e,t){var r=[];if(!t.length)return r;for(var i=e.byteLength,a=0;a1?a+n:i;if(ue(e.subarray(a+4,a+8))===t[0])if(1===t.length)r.push(e.subarray(a+8,s));else{var o=ge(e.subarray(a+8,s),t.slice(1));o.length&&oe.apply(r,o)}a=s}return r}function me(e){var t=[],r=e[0],i=8,a=he(e,i);i+=4;var n=0,s=0;0===r?(n=he(e,i),s=he(e,i+4),i+=8):(n=fe(e,i),s=fe(e,i+8),i+=16),i+=2;var o=e.length+s,l=de(e,i);i+=2;for(var u=0;u>>31)return j.warn("SIDX has hierarchical references (not supported)"),null;var c=he(e,d);d+=4,t.push({referenceSize:f,subsegmentDuration:c,info:{duration:c/a,start:o,end:o+f-1}}),o+=f,i=d+=4}return{earliestPresentationTime:n,timescale:a,version:r,referencesCount:l,references:t}}function pe(e){for(var t=[],r=ge(e,["moov","trak"]),i=0;i3&&(n+="."+Se(u[1])+Se(u[2])+Se(u[3]),t=Ee("avc1"===l?"dva1":"dvav",i));break;case"mp4a":var d=ge(r,[a])[0],h=ge(d.subarray(28),["esds"])[0];if(h&&h.length>7){var f=4;if(3!==h[f++])break;f=Te(h,f),f+=2;var c=h[f++];if(128&c&&(f+=2),64&c&&(f+=h[f++]),4!==h[f++])break;f=Te(h,f);var v=h[f++];if(64!==v)break;if(n+="."+Se(v),f+=12,5!==h[f++])break;f=Te(h,f);var g=h[f++],m=(248&g)>>3;31===m&&(m+=1+((7&g)<<3)+((224&h[f])>>5)),n+="."+m}break;case"hvc1":case"hev1":var p=ge(i,["hvcC"])[0];if(p&&p.length>12){var y=p[1],E=["","A","B","C"][y>>6],T=31&y,S=he(p,2),L=(32&y)>>5?"H":"L",R=p[12],A=p.subarray(6,12);n+="."+E+T,n+="."+S.toString(16).toUpperCase(),n+="."+L+R;for(var b="",D=A.length;D--;){var k=A[D];(k||b)&&(b="."+k.toString(16).toUpperCase()+b)}n+=b}t=Ee("hev1"==l?"dvhe":"dvh1",i);break;case"dvh1":case"dvhe":case"dvav":case"dva1":case"dav1":n=Ee(n,i)||n;break;case"vp09":var _=ge(i,["vpcC"])[0];if(_&&_.length>6){var I=_[4],C=_[5],x=_[6]>>4&15;n+="."+Le(I)+"."+Le(C)+"."+Le(x)}break;case"av01":var P=ge(i,["av1C"])[0];if(P&&P.length>2){var w=P[1]>>>5,O=31&P[1],M=P[2]>>>7?"H":"M",F=(64&P[2])>>6,N=(32&P[2])>>5,B=2===w&&F?N?12:10:F?10:8,U=(16&P[2])>>4,G=(8&P[2])>>3,V=(4&P[2])>>2,H=3&P[2];n+="."+w+"."+Le(O)+M+"."+Le(B)+"."+U+"."+G+V+H+"."+Le(1)+"."+Le(1)+"."+Le(1)+".0",t=Ee("dav1",i)}}return{codec:n,encrypted:s,supplemental:t}}function Ee(e,t){var r=ge(t,["dvvC"]),i=r.length?r[0]:ge(t,["dvcC"])[0];if(i){var a=i[2]>>1&127,n=i[2]<<5&32|i[3]>>3&31;return e+"."+Le(a)+"."+Le(n)}}function Te(e,t){for(var r=t+5;128&e[t++]&&t0;a||(i=ge(t,["encv"])),i.forEach((function(e){ge(a?e.subarray(28):e.subarray(78),["sinf"]).forEach((function(e){var t=function(e){var t=ge(e,["schm"])[0];if(t){var r=ue(t.subarray(4,8));if("cbcs"===r||"cenc"===r)return ge(e,["schi","tenc"])[0]}return null}(e);if(t){var i=t.subarray(8,24);i.some((function(e){return 0!==e}))||(j.log("[eme] Patching keyId in 'enc"+(a?"a":"v")+">sinf>>tenc' box: "+Q(i)+" -> "+Q(r)),t.set(r,8))}}))}))})),e}function Ae(e){var t=he(e,0),r=8;1&t&&(r+=4),4&t&&(r+=4);for(var i=0,a=he(e,4),n=0;n>1&63;return 39===r||40===r}return 6==(31&t)}function Ie(e,t,r,i){var a=Ce(e),n=0;n+=t;for(var s=0,o=0,l=0;n=a.length)break;s+=l=a[n++]}while(255===l);o=0;do{if(n>=a.length)break;o+=l=a[n++]}while(255===l);var u=a.length-n,d=n;if(ou){j.error("Malformed SEI payload. "+o+" is too small, only "+u+" bytes left to parse.");break}if(4===s){if(181===a[d++]){var h=de(a,d);if(d+=2,49===h){var f=he(a,d);if(d+=4,1195456820===f){var c=a[d++];if(3===c){var v=a[d++],g=64&v,m=g?2+3*(31&v):0,p=new Uint8Array(m);if(g){p[0]=v;for(var y=1;y16){for(var E=[],T=0;T<16;T++){var S=a[d++].toString(16);E.push(1==S.length?"0"+S:S),3!==T&&5!==T&&7!==T&&9!==T||E.push("-")}for(var L=o-16,R=new Uint8Array(L),A=0;A4||-1!==["ac-3","ec-3","alac","fLaC","Opus"].indexOf(e)))return e;if(t){var r=t.split(",");if(r.length>1){if(e)for(var i=r.length;i--;)if(r[i].substring(0,4)===e.substring(0,4))return r[i];return r[0]}}return t||e}function We(e){if(e.startsWith("av01.")){for(var t=e.split("."),r=["0","111","01","01","01","0"],i=t.length;i>4&&i<10;i++)t[i]=r[i-4];return t.join(".")}return e}function Ye(e){var t=xe(e)||{isTypeSupported:function(){return!1}};return{mpeg:t.isTypeSupported("audio/mpeg"),mp3:t.isTypeSupported('audio/mp4; codecs="mp3"'),ac3:!1}}function je(e){return e.replace(/^.+codecs=["']?([^"']+).*$/,"$1")}var qe=["NONE","TYPE-0","TYPE-1",null],Xe=["SDR","PQ","HLG"],ze="",Qe="YES",$e="v2";function Ze(e){var t=e.canSkipUntil,r=e.canSkipDateRanges,i=e.age;return t&&i-1&&g!==v,p=!!e||m;if(p||!l.paused&&l.playbackRate&&l.readyState){var y=s.mainForwardBufferInfo;if(p||null!==y){var E=r.bwEstimator.getEstimateTTFB(),T=Math.abs(l.playbackRate);if(!(f<=Math.max(E,h/(2*T)*1e3))){var S=y?y.len/T:0,R=d.loading.first?d.loading.first-d.loading.start:-1,A=d.loaded&&R>-1,b=r.getBwEstimate(),D=s.levels,_=D[v],I=Math.max(d.loaded,Math.round(h*(a.bitrate||_.averageBitrate)/8)),C=A?f-R:f;C<1&&A&&(C=Math.min(f,8*d.loaded/b));var x=A?1e3*d.loaded/C:0,P=E/1e3,w=x?(I-d.loaded)/x:8*I/b+P;if(!(w<=S)){var O,M=x?8*x:b,F=!0===(null==(t=(null==e?void 0:e.details)||r.hls.latestLevelDetails)?void 0:t.live),N=r.hls.config.abrBandWidthUpFactor,B=Number.POSITIVE_INFINITY;for(O=v-1;O>c;O--){var U=D[O].maxBitrate,G=!D[O].details||F;if((B=r.getTimeToLoadFrag(P,M,h*U,G))=w||B>10*h)){A?r.bwEstimator.sample(f-Math.min(E,R),d.loaded):r.bwEstimator.sampleTTFB(f);var V=D[O].maxBitrate;r.getBwEstimate()*N>V&&r.resetEstimator(V);var H=r.findBestLevel(V,c,O,0,S,1,1);H>-1&&(O=H),r.warn("Fragment "+a.sn+(n?" part "+n.index:"")+" of level "+v+" is loading too slowly;\n Fragment duration: "+a.duration.toFixed(3)+"\n Time to underbuffer: "+S.toFixed(3)+" s\n Estimated load time for current fragment: "+w.toFixed(3)+" s\n Estimated load time for down switch fragment: "+B.toFixed(3)+" s\n TTFB estimate: "+(0|R)+" ms\n Current BW estimate: "+(L(b)?0|b:"Unknown")+" bps\n New BW estimate: "+(0|r.getBwEstimate())+" bps\n Switching to level "+O+" @ "+(0|V)+" bps"),s.nextLoadLevel=s.nextAutoLevel=O,r.clearTimer();var K=function(){if(r.clearTimer(),r.fragCurrent===a&&r.hls.loadLevel===O&&O>0){var e=r.getStarvationDelay();if(r.warn("Aborting inflight request "+(O>0?"and switching down":"")+"\n Fragment duration: "+a.duration.toFixed(3)+" s\n Time to underbuffer: "+e.toFixed(3)+" s"),a.abortRequests(),r.fragCurrent=r.partCurrent=null,O>c){var t=r.findBestLevel(r.hls.levels[c].bitrate,c,O,0,e,1,1);-1===t&&(t=c),r.hls.nextLoadLevel=r.hls.nextAutoLevel=t,r.resetEstimator(r.hls.levels[t].bitrate)}}};m||w>2*B?K():r.timer=self.setInterval(K,1e3*B),s.trigger(k.FRAG_LOAD_EMERGENCY_ABORTED,{frag:a,part:n,stats:d})}}}}}}}},r.hls=t,r.bwEstimator=r.initEstimator(),r.registerListeners(),r}o(t,e);var r=t.prototype;return r.resetEstimator=function(e){e&&(this.log("setting initial bwe to "+e),this.hls.config.abrEwmaDefaultEstimate=e),this.firstSelection=-1,this.bwEstimator=this.initEstimator()},r.initEstimator=function(){var e=this.hls.config;return new F(e.abrEwmaSlowVoD,e.abrEwmaFastVoD,e.abrEwmaDefaultEstimate)},r.registerListeners=function(){var e=this.hls;e.on(k.MANIFEST_LOADING,this.onManifestLoading,this),e.on(k.FRAG_LOADING,this.onFragLoading,this),e.on(k.FRAG_LOADED,this.onFragLoaded,this),e.on(k.FRAG_BUFFERED,this.onFragBuffered,this),e.on(k.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(k.LEVEL_LOADED,this.onLevelLoaded,this),e.on(k.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(k.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.on(k.ERROR,this.onError,this)},r.unregisterListeners=function(){var e=this.hls;e&&(e.off(k.MANIFEST_LOADING,this.onManifestLoading,this),e.off(k.FRAG_LOADING,this.onFragLoading,this),e.off(k.FRAG_LOADED,this.onFragLoaded,this),e.off(k.FRAG_BUFFERED,this.onFragBuffered,this),e.off(k.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(k.LEVEL_LOADED,this.onLevelLoaded,this),e.off(k.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(k.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.off(k.ERROR,this.onError,this))},r.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this._abandonRulesCheck=null,this.fragCurrent=this.partCurrent=null},r.onManifestLoading=function(e,t){this.lastLoadedFragLevel=-1,this.firstSelection=-1,this.lastLevelLoadSec=0,this.fragCurrent=this.partCurrent=null,this.onLevelsUpdated(),this.clearTimer()},r.onLevelsUpdated=function(){this.lastLoadedFragLevel>-1&&this.fragCurrent&&(this.lastLoadedFragLevel=this.fragCurrent.level),this._nextAutoLevel=-1,this.onMaxAutoLevelUpdated(),this.codecTiers=null,this.audioTracksByGroup=null},r.onMaxAutoLevelUpdated=function(){this.firstSelection=-1,this.nextAutoLevelKey=""},r.onFragLoading=function(e,t){var r,i=t.frag;this.ignoreFragment(i)||(i.bitrateTest||(this.fragCurrent=i,this.partCurrent=null!=(r=t.part)?r:null),this.clearTimer(),this.timer=self.setInterval(this._abandonRulesCheck,100))},r.onLevelSwitching=function(e,t){this.clearTimer()},r.onError=function(e,t){if(!t.fatal)switch(t.details){case D.BUFFER_ADD_CODEC_ERROR:case D.BUFFER_APPEND_ERROR:this.lastLoadedFragLevel=-1,this.firstSelection=-1;break;case D.FRAG_LOAD_TIMEOUT:var r=t.frag,i=this.fragCurrent,a=this.partCurrent;if(r&&i&&r.sn===i.sn&&r.level===i.level){var n=performance.now(),s=a?a.stats:r.stats,o=n-s.loading.start,l=s.loading.first?s.loading.first-s.loading.start:-1;if(s.loaded&&l>-1){var u=this.bwEstimator.getEstimateTTFB();this.bwEstimator.sample(o-Math.min(u,l),s.loaded)}else this.bwEstimator.sampleTTFB(o)}}},r.getTimeToLoadFrag=function(e,t,r,i){return e+r/t+(i?e+this.lastLevelLoadSec:0)},r.onLevelLoaded=function(e,t){var r=this.hls.config,i=t.stats.loading,a=i.end-i.first;L(a)&&(this.lastLevelLoadSec=a/1e3),t.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD),this.timer>-1&&this._abandonRulesCheck(t.levelInfo)},r.onFragLoaded=function(e,t){var r=t.frag,i=t.part,a=i?i.stats:r.stats;if(r.type===P&&this.bwEstimator.sampleTTFB(a.loading.first-a.loading.start),!this.ignoreFragment(r)){if(this.clearTimer(),r.level===this._nextAutoLevel&&(this._nextAutoLevel=-1),this.firstSelection=-1,this.hls.config.abrMaxWithRealBitrate){var n=i?i.duration:r.duration,s=this.hls.levels[r.level],o=(s.loaded?s.loaded.bytes:0)+a.loaded,l=(s.loaded?s.loaded.duration:0)+n;s.loaded={bytes:o,duration:l},s.realBitrate=Math.round(8*o/l)}if(r.bitrateTest){var u={stats:a,frag:r,part:i,id:r.type};this.onFragBuffered(k.FRAG_BUFFERED,u),r.bitrateTest=!1}else this.lastLoadedFragLevel=r.level}},r.onFragBuffered=function(e,t){var r=t.frag,i=t.part,a=null!=i&&i.stats.loaded?i.stats:r.stats;if(!a.aborted&&!this.ignoreFragment(r)){var n=a.parsing.end-a.loading.start-Math.min(a.loading.first-a.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(n,a.loaded),a.bwEstimate=this.getBwEstimate(),r.bitrateTest?this.bitrateTestDelay=n/1e3:this.bitrateTestDelay=0}},r.ignoreFragment=function(e){return e.type!==P||"initSegment"===e.sn},r.clearTimer=function(){this.timer>-1&&(self.clearInterval(this.timer),this.timer=-1)},r.getAutoLevelKey=function(){return this.getBwEstimate()+"_"+this.getStarvationDelay().toFixed(2)},r.getNextABRAutoLevel=function(){var e=this.fragCurrent,t=this.partCurrent,r=this.hls;if(r.levels.length<=1)return r.loadLevel;var i=r.maxAutoLevel,a=r.config,n=r.minAutoLevel,s=t?t.duration:e?e.duration:0,o=this.getBwEstimate(),l=this.getStarvationDelay(),u=a.abrBandWidthFactor,d=a.abrBandWidthUpFactor;if(l){var h=this.findBestLevel(o,n,i,l,0,u,d);if(h>=0)return this.rebufferNotice=-1,h}var f=s?Math.min(s,a.maxStarvationDelay):a.maxStarvationDelay;if(!l){var c=this.bitrateTestDelay;c&&(f=(s?Math.min(s,a.maxLoadingDelay):a.maxLoadingDelay)-c,this.info("bitrate test took "+Math.round(1e3*c)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*f)+" ms"),u=d=1)}var v=this.findBestLevel(o,n,i,l,f,u,d);if(this.rebufferNotice!==v&&(this.rebufferNotice=v,this.info((l?"rebuffering expected":"buffer is empty")+", optimal quality level "+v)),v>-1)return v;var g=r.levels[n],m=r.loadLevelObj;return m&&(null==g?void 0:g.bitrate)0),f=Math.min(f,t.minHeight),c=Math.min(c,t.minFramerate),v=Math.min(v,t.minBitrate),T.filter((function(e){return t.videoRanges[e]>0})).length>0&&(h=!0)},R=n.length;R--;)S();f=L(f)?f:0,c=L(c)?c:0;var A=Math.max(1080,f),b=Math.max(30,c);v=L(v)?v:r,r=Math.max(v,r),h||(t=void 0);var D=n.length>1;return{codecSet:n.reduce((function(t,i){var a=e[i];if(i===t)return t;if(p=h?T.filter((function(e){return a.videoRanges[e]>0})):[],D){if(a.minBitrate>r)return at(i,"min bitrate of "+a.minBitrate+" > current estimate of "+r),t;if(!a.hasDefaultAudio)return at(i,"no renditions with default or auto-select sound found"),t;if(o&&i.indexOf(o.substring(0,4))%5!=0)return at(i,'audio codec preference "'+o+'" not found'),t;if(s&&!u){if(!a.channels[s])return at(i,"no renditions with "+s+" channel sound found (channels options: "+Object.keys(a.channels)+")"),t}else if((!o||u)&&d&&0===a.channels[2])return at(i,"no renditions with stereo sound found"),t;if(a.minHeight>A)return at(i,"min resolution of "+a.minHeight+" > maximum of "+A),t;if(a.minFramerate>b)return at(i,"min framerate of "+a.minFramerate+" > maximum of "+b),t;if(!p.some((function(e){return a.videoRanges[e]>0})))return at(i,"no variants with VIDEO-RANGE of "+it(p)+" found"),t;if(l&&i.indexOf(l.substring(0,4))%5!=0)return at(i,'video codec preference "'+l+'" not found'),t;if(a.maxScore=Ue(t)||a.fragmentError>e[t].fragmentError)?t:(g=a.minIndex,m=a.maxScore,i)}),void 0),videoRanges:p,preferHDR:E,minFramerate:c,minBitrate:v,minIndex:g}}(I,A,e,D,k),x=C.codecSet,P=C.videoRanges,w=C.minFramerate,O=C.minBitrate,M=C.minIndex,F=C.preferHDR;_=M,E=x,A=F?P[P.length-1]:P[0],b=w,e=Math.max(e,O),this.log("picked start tier "+it(C))}else E=null==T?void 0:T.codecSet,A=null==T?void 0:T.videoRange;for(var N,B=c?c.duration:f?f.duration:0,U=this.bwEstimator.getEstimateTTFB()/1e3,G=[],V=function(){var t,o=g[H],f=H>h;if(!o)return 0;if((E&&o.codecSet!==E||A&&o.videoRange!==A||f&&b>o.frameRate||!f&&b>0&&b=2*B&&0===a?o.averageBitrate:o.maxBitrate,D=l.getTimeToLoadFrag(U,v,T*y,void 0===m);if(v>=T&&(H===d||0===o.loadError&&0===o.fragmentError)&&(D<=U||!L(D)||S&&!l.bitrateTestDelay||D"+H+" adjustedbw("+Math.round(v)+")-bitrate="+Math.round(v-T)+" ttfb:"+U.toFixed(1)+" avgDuration:"+y.toFixed(1)+" maxFetchDuration:"+u.toFixed(1)+" fetchDuration:"+D.toFixed(1)+" firstSelection:"+R+" codecSet:"+o.codecSet+" videoRange:"+o.videoRange+" hls.loadLevel:"+p)),R&&(l.firstSelection=H),{v:H}}},H=r;H>=t;H--)if(0!==(N=V())&&N)return N.v;return-1},r.deriveNextAutoLevel=function(e){var t=this.hls,r=t.maxAutoLevel,i=t.minAutoLevel;return Math.min(Math.max(e,i),r)},i(t,[{key:"firstAutoLevel",get:function(){var e=this.hls,t=e.maxAutoLevel,r=e.minAutoLevel,i=this.getBwEstimate(),a=this.hls.config.maxStarvationDelay,n=this.findBestLevel(i,r,t,0,a,1,1);if(n>-1)return n;var s=this.hls.firstLevel,o=Math.min(Math.max(s,r),t);return this.warn("Could not find best starting auto level. Defaulting to first in playlist "+s+" clamped to "+o),o}},{key:"forcedAutoLevel",get:function(){return this.nextAutoLevelKey?-1:this._nextAutoLevel}},{key:"nextAutoLevel",get:function(){var e=this.forcedAutoLevel,t=this.bwEstimator.canEstimate(),r=this.lastLoadedFragLevel>-1;if(!(-1===e||t&&r&&this.nextAutoLevelKey!==this.getAutoLevelKey()))return e;var i=t&&r?this.getNextABRAutoLevel():this.firstAutoLevel;if(-1!==e){var a=this.hls.levels;if(a.length>Math.max(e,i)&&a[e].loadError<=a[i].loadError)return e}return this._nextAutoLevel=i,this.nextAutoLevelKey=this.getAutoLevelKey(),i},set:function(e){var t=this.deriveNextAutoLevel(e);this._nextAutoLevel!==t&&(this.nextAutoLevelKey="",this._nextAutoLevel=t)}}])}(N),lt=function(){function e(e){this.tracks=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.tracks=e}var t=e.prototype;return t.destroy=function(){this.tracks=this.queues=null},t.append=function(e,t,r){if(null!==this.queues&&null!==this.tracks){var i=this.queues[t];i.push(e),1!==i.length||r||this.executeNext(t)}},t.appendBlocker=function(e){var t=this;return new Promise((function(r){var i={label:"async-blocker",execute:r,onStart:function(){},onComplete:function(){},onError:function(){}};t.append(i,e)}))},t.prependBlocker=function(e){var t=this;return new Promise((function(r){if(t.queues){var i={label:"async-blocker-prepend",execute:r,onStart:function(){},onComplete:function(){},onError:function(){}};t.queues[e].unshift(i)}}))},t.removeBlockers=function(){null!==this.queues&&[this.queues.video,this.queues.audio,this.queues.audiovideo].forEach((function(e){var t,r=null==(t=e[0])?void 0:t.label;"async-blocker"!==r&&"async-blocker-prepend"!==r||(e[0].execute(),e.splice(0,1))}))},t.unblockAudio=function(e){null!==this.queues&&this.queues.audio[0]===e&&this.shiftAndExecuteNext("audio")},t.executeNext=function(e){if(null!==this.queues&&null!==this.tracks){var t=this.queues[e];if(t.length){var r=t[0];try{r.execute()}catch(t){var i;if(r.onError(t),null===this.queues||null===this.tracks)return;var a=null==(i=this.tracks[e])?void 0:i.buffer;null!=a&&a.updating||this.shiftAndExecuteNext(e)}}}},t.shiftAndExecuteNext=function(e){null!==this.queues&&(this.queues[e].shift(),this.executeNext(e))},t.current=function(e){var t;return(null==(t=this.queues)?void 0:t[e][0])||null},t.toString=function(){var e=this.queues,t=this.tracks;return null===e||null===t?"":"\n"+this.list("video")+"\n"+this.list("audio")+"\n"+this.list("audiovideo")+"}"},t.list=function(e){var t,r;return null!=(t=this.queues)&&t[e]||null!=(r=this.tracks)&&r[e]?e+": ("+this.listSbInfo(e)+") "+this.listOps(e):""},t.listSbInfo=function(e){var t,r=null==(t=this.tracks)?void 0:t[e],i=null==r?void 0:r.buffer;return i?"SourceBuffer"+(i.updating?" updating":"")+(r.ended?" ended":"")+(r.ending?" ending":""):"none"},t.listOps=function(e){var t;return(null==(t=this.queues)?void 0:t[e].map((function(e){return e.label})).join(", "))||""},e}(),ut=function(e,t){for(var r=0,i=e.length-1,a=null,n=null;r<=i;){var s=t(n=e[a=(r+i)/2|0]);if(s>0)r=a+1;else{if(!(s<0))return n;i=a-1}}return null};function dt(e,t,r,i,a){void 0===r&&(r=0),void 0===i&&(i=0),void 0===a&&(a=.005);var n=null;if(e){n=t[1+e.sn-t[0].sn]||null;var s=e.endDTS-r;s>0&&s<15e-7&&(r+=15e-7),n&&e.level!==n.level&&n.end<=e.end&&(n=t[2+e.sn-t[0].sn]||null)}else 0===r&&0===t[0].start&&(n=t[0]);if(n&&((!e||e.level===n.level)&&0===ht(r,i,n)||function(e,t,r){if(t&&0===t.start&&t.level0){var i=t.tagList.reduce((function(e,t){return"INF"===t[0]&&(e+=parseFloat(t[1])),e}),r);return e.start<=i}return!1}(n,e,Math.min(a,i))))return n;var o=ut(t,ht.bind(null,r,i));return!o||o===e&&n?n:o}function ht(e,t,r){if(void 0===e&&(e=0),void 0===t&&(t=0),r.start<=e&&r.start+r.duration>e)return 0;var i=Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return r.start+r.duration-i<=e?1:r.start-i>e&&r.start?-1:0}function ft(e,t,r){var i=1e3*Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return(r.endProgramDateTime||0)-i>e}function ct(e){switch(e.details){case D.FRAG_LOAD_TIMEOUT:case D.KEY_LOAD_TIMEOUT:case D.LEVEL_LOAD_TIMEOUT:case D.MANIFEST_LOAD_TIMEOUT:return!0}return!1}function vt(e,t){var r=ct(t);return e.default[(r?"timeout":"error")+"Retry"]}function gt(e,t){var r="linear"===e.backoff?1:Math.pow(2,t);return Math.min(r*e.retryDelayMs,e.maxRetryDelayMs)}function mt(e){return d(d({},e),{errorRetry:null,timeoutRetry:null})}function pt(e,t,r,i){if(!e)return!1;var a=null==i?void 0:i.code,n=t499)}(a)||!!r);return e.shouldRetry?e.shouldRetry(e,t,r,i,n):n}var yt=0,Et=2,Tt=3,St=5,Lt=0,Rt=1,At=2,bt=function(e){function t(t){var r;return(r=e.call(this,"error-controller",t.logger)||this).hls=void 0,r.playlistError=0,r.penalizedRenditions={},r.hls=t,r.registerListeners(),r}o(t,e);var r=t.prototype;return r.registerListeners=function(){var e=this.hls;e.on(k.ERROR,this.onError,this),e.on(k.MANIFEST_LOADING,this.onManifestLoading,this),e.on(k.LEVEL_UPDATED,this.onLevelUpdated,this)},r.unregisterListeners=function(){var e=this.hls;e&&(e.off(k.ERROR,this.onError,this),e.off(k.ERROR,this.onErrorOut,this),e.off(k.MANIFEST_LOADING,this.onManifestLoading,this),e.off(k.LEVEL_UPDATED,this.onLevelUpdated,this))},r.destroy=function(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}},r.startLoad=function(e){},r.stopLoad=function(){this.playlistError=0},r.getVariantLevelIndex=function(e){return(null==e?void 0:e.type)===P?e.level:this.hls.loadLevel},r.onManifestLoading=function(){this.playlistError=0,this.penalizedRenditions={}},r.onLevelUpdated=function(){this.playlistError=0},r.onError=function(e,t){var r;if(!t.fatal){var i=this.hls,a=t.context;switch(t.details){case D.FRAG_LOAD_ERROR:case D.FRAG_LOAD_TIMEOUT:case D.KEY_LOAD_ERROR:case D.KEY_LOAD_TIMEOUT:return void(t.errorAction=this.getFragRetryOrSwitchAction(t));case D.FRAG_PARSING_ERROR:if(null!=(r=t.frag)&&r.gap)return void(t.errorAction=Dt());case D.FRAG_GAP:case D.FRAG_DECRYPT_ERROR:return t.errorAction=this.getFragRetryOrSwitchAction(t),void(t.errorAction.action=Et);case D.LEVEL_EMPTY_ERROR:case D.LEVEL_PARSING_ERROR:var n,s,o=t.parent===P?t.level:i.loadLevel;return void(t.details===D.LEVEL_EMPTY_ERROR&&null!=(n=t.context)&&null!=(s=n.levelDetails)&&s.live?t.errorAction=this.getPlaylistRetryOrSwitchAction(t,o):(t.levelRetry=!1,t.errorAction=this.getLevelSwitchAction(t,o)));case D.LEVEL_LOAD_ERROR:case D.LEVEL_LOAD_TIMEOUT:return void("number"==typeof(null==a?void 0:a.level)&&(t.errorAction=this.getPlaylistRetryOrSwitchAction(t,a.level)));case D.AUDIO_TRACK_LOAD_ERROR:case D.AUDIO_TRACK_LOAD_TIMEOUT:case D.SUBTITLE_LOAD_ERROR:case D.SUBTITLE_TRACK_LOAD_TIMEOUT:if(a){var l=i.loadLevelObj;if(l&&(a.type===C&&l.hasAudioGroup(a.groupId)||a.type===x&&l.hasSubtitleGroup(a.groupId)))return t.errorAction=this.getPlaylistRetryOrSwitchAction(t,i.loadLevel),t.errorAction.action=Et,void(t.errorAction.flags=Rt)}return;case D.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:var u=i.loadLevelObj,d=null==u?void 0:u.attrs["HDCP-LEVEL"];return void(d?t.errorAction={action:Et,flags:At,hdcpLevel:d}:this.keySystemError(t));case D.BUFFER_ADD_CODEC_ERROR:case D.REMUX_ALLOC_ERROR:case D.BUFFER_APPEND_ERROR:var h;return void(t.errorAction||(t.errorAction=this.getLevelSwitchAction(t,null!=(h=t.level)?h:i.loadLevel)));case D.INTERNAL_EXCEPTION:case D.BUFFER_APPENDING_ERROR:case D.BUFFER_FULL_ERROR:case D.LEVEL_SWITCH_ERROR:case D.BUFFER_STALLED_ERROR:case D.BUFFER_SEEK_OVER_HOLE:case D.BUFFER_NUDGE_ON_STALL:return void(t.errorAction=Dt())}t.type===b.KEY_SYSTEM_ERROR&&this.keySystemError(t)}},r.keySystemError=function(e){var t=this.getVariantLevelIndex(e.frag);e.levelRetry=!1,e.errorAction=this.getLevelSwitchAction(e,t)},r.getPlaylistRetryOrSwitchAction=function(e,t){var r=vt(this.hls.config.playlistLoadPolicy,e),i=this.playlistError++;if(pt(r,i,ct(e),e.response))return{action:St,flags:Lt,retryConfig:r,retryCount:i};var a=this.getLevelSwitchAction(e,t);return r&&(a.retryConfig=r,a.retryCount=i),a},r.getFragRetryOrSwitchAction=function(e){var t=this.hls,r=this.getVariantLevelIndex(e.frag),i=t.levels[r],a=t.config,n=a.fragLoadPolicy,s=a.keyLoadPolicy,o=vt(e.details.startsWith("key")?s:n,e),l=t.levels.reduce((function(e,t){return e+t.fragmentError}),0);if(i&&(e.details!==D.FRAG_GAP&&i.fragmentError++,pt(o,l,ct(e),e.response)))return{action:St,flags:Lt,retryConfig:o,retryCount:l};var u=this.getLevelSwitchAction(e,r);return o&&(u.retryConfig=o,u.retryCount=l),u},r.getLevelSwitchAction=function(e,t){var r=this.hls;null==t&&(t=r.loadLevel);var i=this.hls.levels[t];if(i){var a,n,s=e.details;i.loadError++,s===D.BUFFER_APPEND_ERROR&&i.fragmentError++;var o=-1,l=r.levels,u=r.loadLevel,d=r.minAutoLevel,h=r.maxAutoLevel;r.autoLevelEnabled||(r.loadLevel=-1);for(var f,c=null==(a=e.frag)?void 0:a.type,v=(c===w&&s===D.FRAG_PARSING_ERROR||"audio"===e.sourceBufferName&&(s===D.BUFFER_ADD_CODEC_ERROR||s===D.BUFFER_APPEND_ERROR))&&l.some((function(e){var t=e.audioCodec;return i.audioCodec!==t})),g="video"===e.sourceBufferName&&(s===D.BUFFER_ADD_CODEC_ERROR||s===D.BUFFER_APPEND_ERROR)&&l.some((function(e){var t=e.codecSet,r=e.audioCodec;return i.codecSet!==t&&i.audioCodec===r})),m=null!=(n=e.context)?n:{},p=m.type,y=m.groupId,E=function(){var t=(T+u)%l.length;if(t!==u&&t>=d&&t<=h&&0===l[t].loadError){var r,a,n=l[t];if(s===D.FRAG_GAP&&c===P&&e.frag){var f=l[t].details;if(f){var m=dt(e.frag,f.fragments,e.frag.start);if(null!=m&&m.gap)return 0}}else{if(p===C&&n.hasAudioGroup(y)||p===x&&n.hasSubtitleGroup(y))return 0;if(c===w&&null!=(r=i.audioGroups)&&r.some((function(e){return n.hasAudioGroup(e)}))||c===O&&null!=(a=i.subtitleGroups)&&a.some((function(e){return n.hasSubtitleGroup(e)}))||v&&i.audioCodec===n.audioCodec||!v&&i.audioCodec!==n.audioCodec||g&&i.codecSet===n.codecSet)return 0}return o=t,1}},T=l.length;T--&&(0===(f=E())||1!==f););if(o>-1&&r.loadLevel!==o)return e.levelRetry=!0,this.playlistError=0,{action:Et,flags:Lt,nextAutoLevel:o}}return{action:Et,flags:Rt}},r.onErrorOut=function(e,t){var r;switch(null==(r=t.errorAction)?void 0:r.action){case yt:break;case Et:this.sendAlternateToPenaltyBox(t),t.errorAction.resolved||t.details===D.FRAG_GAP?/MediaSource readyState: ended/.test(t.error.message)&&(this.warn('MediaSource ended after "'+t.sourceBufferName+'" sourceBuffer append error. Attempting to recover from media error.'),this.hls.recoverMediaError()):t.fatal=!0}t.fatal&&this.hls.stopLoad()},r.sendAlternateToPenaltyBox=function(e){var t=this.hls,r=e.errorAction;if(r){var i=r.flags,a=r.hdcpLevel,n=r.nextAutoLevel;switch(i){case Lt:this.switchLevel(e,n);break;case At:a&&(t.maxHdcpLevel=qe[qe.indexOf(a)-1],r.resolved=!0),this.warn('Restricting playback to HDCP-LEVEL of "'+t.maxHdcpLevel+'" or lower')}r.resolved||this.switchLevel(e,n)}},r.switchLevel=function(e,t){if(void 0!==t&&e.errorAction&&(this.warn("switching to level "+t+" after "+e.details),this.hls.nextAutoLevel=t,e.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel,e.details===D.BUFFER_ADD_CODEC_ERROR&&e.mimeType&&"audiovideo"!==e.sourceBufferName))for(var r=je(e.mimeType),i=this.hls.levels,a=i.length;a--;)i[a][e.sourceBufferName+"Codec"]===r&&this.hls.removeLevel(a)},t}(N);function Dt(e){var t={action:yt,flags:Lt};return e&&(t.resolved=!0),t}var kt={length:0,start:function(){return 0},end:function(){return 0}},_t=function(){function e(){}return e.isBuffered=function(t,r){if(t)for(var i=e.getBuffered(t),a=i.length;a--;)if(r>=i.start(a)&&r<=i.end(a))return!0;return!1},e.bufferedRanges=function(t){if(t){var r=e.getBuffered(t);return e.timeRangesToArray(r)}return[]},e.timeRangesToArray=function(e){for(var t=[],r=0;r1&&e.sort((function(e,t){return e.start-t.start||t.end-e.end}));var i=-1,a=[];if(r)for(var n=0;n=e[n].start&&t<=e[n].end&&(i=n);var s=a.length;if(s){var o=a[s-1].end;e[n].start-oo&&(a[s-1].end=e[n].end):a.push(e[n])}else a.push(e[n])}else a=e;for(var l,u=0,d=t,h=t,f=0;f=c&&t<=v&&(i=f),t+r>=c&&t "+t+")")},i.hls=t,i.fragmentTracker=r,i.appendSource=(a=xe(t.config.preferManagedMediaSource),"undefined"!=typeof self&&a===self.ManagedMediaSource),i.initTracks(),i.registerListeners(),i}o(t,e);var r=t.prototype;return r.hasSourceTypes=function(){return Object.keys(this.tracks).length>0},r.destroy=function(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=this.blockedAudioAppend=null,this.transferData=this.overrides=void 0,this.operationQueue&&(this.operationQueue.destroy(),this.operationQueue=null),this.hls=this.fragmentTracker=null,this._onMediaSourceOpen=this._onMediaSourceClose=null,this._onMediaSourceEnded=null,this._onStartStreaming=this._onEndStreaming=null},r.registerListeners=function(){var e=this.hls;e.on(k.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(k.MANIFEST_LOADING,this.onManifestLoading,this),e.on(k.MANIFEST_PARSED,this.onManifestParsed,this),e.on(k.BUFFER_RESET,this.onBufferReset,this),e.on(k.BUFFER_APPENDING,this.onBufferAppending,this),e.on(k.BUFFER_CODECS,this.onBufferCodecs,this),e.on(k.BUFFER_EOS,this.onBufferEos,this),e.on(k.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(k.LEVEL_UPDATED,this.onLevelUpdated,this),e.on(k.FRAG_PARSED,this.onFragParsed,this),e.on(k.FRAG_CHANGED,this.onFragChanged,this),e.on(k.ERROR,this.onError,this)},r.unregisterListeners=function(){var e=this.hls;e.off(k.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(k.MANIFEST_LOADING,this.onManifestLoading,this),e.off(k.MANIFEST_PARSED,this.onManifestParsed,this),e.off(k.BUFFER_RESET,this.onBufferReset,this),e.off(k.BUFFER_APPENDING,this.onBufferAppending,this),e.off(k.BUFFER_CODECS,this.onBufferCodecs,this),e.off(k.BUFFER_EOS,this.onBufferEos,this),e.off(k.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(k.LEVEL_UPDATED,this.onLevelUpdated,this),e.off(k.FRAG_PARSED,this.onFragParsed,this),e.off(k.FRAG_CHANGED,this.onFragChanged,this),e.off(k.ERROR,this.onError,this)},r.transferMedia=function(){var e=this,t=this.media,r=this.mediaSource;if(!t)return null;var i={};if(this.operationQueue){var a=this.isUpdating();a||this.operationQueue.removeBlockers();var s=this.isQueued();(a||s)&&this.warn("Transfering MediaSource with"+(s?" operations in queue":"")+(a?" updating SourceBuffer(s)":"")+" "+this.operationQueue),this.operationQueue.destroy()}var o=this.transferData;return!this.sourceBufferCount&&o&&o.mediaSource===r?n(i,o.tracks):this.sourceBuffers.forEach((function(t){var r=t[0];r&&(i[r]=n({},e.tracks[r]),e.removeBuffer(r)),t[0]=t[1]=null})),{media:t,mediaSource:r,tracks:i}},r.initTracks=function(){this.sourceBuffers=[[null,null],[null,null]],this.tracks={},this.resetQueue(),this.resetAppendErrors(),this.lastMpegAudioChunk=this.blockedAudioAppend=null,this.lastVideoAppendEnd=0},r.onManifestLoading=function(){this.bufferCodecEventsTotal=0,this.details=null},r.onManifestParsed=function(e,t){var r,i=2;(t.audio&&!t.video||!t.altAudio)&&(i=1),this.bufferCodecEventsTotal=i,this.log(i+" bufferCodec event(s) expected."),null!=(r=this.transferData)&&r.mediaSource&&this.sourceBufferCount&&i&&this.bufferCreated()},r.onMediaAttaching=function(e,t){var r=this.media=t.media,i=xe(this.appendSource);if(this.transferData=this.overrides=void 0,r&&i){var a=!!t.mediaSource;(a||t.overrides)&&(this.transferData=t,this.overrides=t.overrides);var n=this.mediaSource=t.mediaSource||new i;if(this.assignMediaSource(n),a)this._objectUrl=r.src,this.attachTransferred();else{var s=this._objectUrl=self.URL.createObjectURL(n);if(this.appendSource)try{r.removeAttribute("src");var o=self.ManagedMediaSource;r.disableRemotePlayback=r.disableRemotePlayback||o&&n instanceof o,wt(r),function(e,t){var r=self.document.createElement("source");r.type="video/mp4",r.src=t,e.appendChild(r)}(r,s),r.load()}catch(e){r.src=s}else r.src=s}r.addEventListener("emptied",this._onMediaEmptied)}},r.assignMediaSource=function(e){var t,r;this.log(((null==(t=this.transferData)?void 0:t.mediaSource)===e?"transferred":"created")+" media source: "+(null==(r=e.constructor)?void 0:r.name)),e.addEventListener("sourceopen",this._onMediaSourceOpen),e.addEventListener("sourceended",this._onMediaSourceEnded),e.addEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(e.addEventListener("startstreaming",this._onStartStreaming),e.addEventListener("endstreaming",this._onEndStreaming))},r.attachTransferred=function(){var e=this,t=this.media,r=this.transferData;if(r&&t){var i=this.tracks,a=r.tracks,n=a?Object.keys(a):null,s=n?n.length:0,o=function(){e.media&&e.mediaSourceOpenOrEnded&&e._onMediaSourceOpen()};if(a&&n&&s){if(!this.tracksReady)return this.hls.config.startFragPrefetch=!0,void this.log("attachTransferred: waiting for SourceBuffer track info");if(this.log("attachTransferred: (bufferCodecEventsTotal "+this.bufferCodecEventsTotal+")\nrequired tracks: "+it(i,(function(e,t){return"initSegment"===e?void 0:t}))+";\ntransfer tracks: "+it(a,(function(e,t){return"initSegment"===e?void 0:t}))+"}"),!function(e,t){var r=Object.keys(e),i=Object.keys(t),a=r.length,n=i.length;return!a||!n||a===n&&!r.some((function(e){return-1===i.indexOf(e)}))}(a,i)){r.mediaSource=null,r.tracks=void 0;var l=t.currentTime,u=this.details,d=Math.max(l,(null==u?void 0:u.fragments[0].start)||0);return d-l>1?void this.log("attachTransferred: waiting for playback to reach new tracks start time "+l+" -> "+d):(this.warn('attachTransferred: resetting MediaSource for incompatible tracks ("'+Object.keys(a)+'"->"'+Object.keys(i)+'") start time: '+d+" currentTime: "+l),this.onMediaDetaching(k.MEDIA_DETACHING,{}),this.onMediaAttaching(k.MEDIA_ATTACHING,r),void(t.currentTime=d))}this.transferData=void 0,n.forEach((function(t){var r=t,i=a[r];if(i){var n=i.buffer;if(n){var s=e.fragmentTracker,o=i.id;if(s.hasFragments(o)||s.hasParts(o)){var l=_t.getBuffered(n);s.detectEvictedFragments(r,l,o,null,!0)}var u=Ot(r),d=[r,n];e.sourceBuffers[u]=d,n.updating&&e.operationQueue&&e.operationQueue.prependBlocker(r),e.trackSourceBuffer(r,i)}}})),o(),this.bufferCreated()}else this.log("attachTransferred: MediaSource w/o SourceBuffers"),o()}},r.onMediaDetaching=function(e,t){var r=this,i=!!t.transferMedia;this.transferData=this.overrides=void 0;var a=this.media,n=this.mediaSource,s=this._objectUrl;if(n){if(this.log("media source "+(i?"transferring":"detaching")),i)this.sourceBuffers.forEach((function(e){var t=e[0];t&&r.removeBuffer(t)})),this.resetQueue();else{if(this.mediaSourceOpenOrEnded){var o="open"===n.readyState;try{for(var l=n.sourceBuffers,u=l.length;u--;)o&&l[u].abort(),n.removeSourceBuffer(l[u]);o&&n.endOfStream()}catch(e){this.warn("onMediaDetaching: "+e.message+" while calling endOfStream")}}this.sourceBufferCount&&this.onBufferReset()}n.removeEventListener("sourceopen",this._onMediaSourceOpen),n.removeEventListener("sourceended",this._onMediaSourceEnded),n.removeEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(n.removeEventListener("startstreaming",this._onStartStreaming),n.removeEventListener("endstreaming",this._onEndStreaming)),this.mediaSource=null,this._objectUrl=null}a&&(a.removeEventListener("emptied",this._onMediaEmptied),i||(s&&self.URL.revokeObjectURL(s),this.mediaSrc===s?(a.removeAttribute("src"),this.appendSource&&wt(a),a.load()):this.warn("media|source.src was changed by a third party - skip cleanup")),this.media=null),this.hls.trigger(k.MEDIA_DETACHED,t)},r.onBufferReset=function(){var e=this;this.sourceBuffers.forEach((function(t){var r=t[0];r&&e.resetBuffer(r)})),this.initTracks()},r.resetBuffer=function(e){var t,r=null==(t=this.tracks[e])?void 0:t.buffer;if(this.removeBuffer(e),r)try{var i;null!=(i=this.mediaSource)&&i.sourceBuffers.length&&this.mediaSource.removeSourceBuffer(r)}catch(t){this.warn("onBufferReset "+e,t)}delete this.tracks[e]},r.removeBuffer=function(e){this.removeBufferListeners(e),this.sourceBuffers[Ot(e)]=[null,null];var t=this.tracks[e];t&&(t.buffer=void 0)},r.resetQueue=function(){this.operationQueue&&this.operationQueue.destroy(),this.operationQueue=new lt(this.tracks)},r.onBufferCodecs=function(e,t){var r=this,i=this.tracks,a=Object.keys(t);this.log('BUFFER_CODECS: "'+a+'" (current SB count '+this.sourceBufferCount+")");var n="audiovideo"in t&&(i.audio||i.video)||i.audiovideo&&("audio"in t||"video"in t),s=!n&&this.sourceBufferCount&&this.media&&a.some((function(e){return!i[e]}));n||s?this.warn('Unsupported transition between "'+Object.keys(i)+'" and "'+a+'" SourceBuffers'):(a.forEach((function(e){var a,n,s,o=t[e],l=o.id,u=o.codec,d=o.levelCodec,h=o.container,f=o.metadata,c=o.supplemental,v=i[e],g=null==(a=r.transferData)||null==(n=a.tracks)?void 0:n[e],m=null!=g&&g.buffer?g:v,p=(null==m?void 0:m.pendingCodec)||(null==m?void 0:m.codec),y=null==m?void 0:m.levelCodec;v||(v=i[e]={buffer:void 0,listeners:[],codec:u,supplemental:c,container:h,levelCodec:d,metadata:f,id:l});var E=Ke(p,y),T=null==E?void 0:E.replace(It,"$1"),S=Ke(u,d),L=null==(s=S)?void 0:s.replace(It,"$1");S&&E&&T!==L&&("audio"===e.slice(0,5)&&(S=He(S,r.appendSource)),r.log("switching codec "+p+" to "+S),S!==(v.pendingCodec||v.codec)&&(v.pendingCodec=S),v.container=h,r.appendChangeType(e,h,S))})),(this.tracksReady||this.sourceBufferCount)&&(t.tracks=this.sourceBufferTracks),this.sourceBufferCount||this.mediaSourceOpenOrEnded&&this.checkPendingTracks())},r.appendChangeType=function(e,t,r){var i=this,a=t+";codecs="+r,n={label:"change-type="+a,execute:function(){var n=i.tracks[e];if(n){var s=n.buffer;null!=s&&s.changeType&&(i.log("changing "+e+" sourceBuffer type to "+a),s.changeType(a),n.codec=r,n.container=t)}i.shiftAndExecuteNext(e)},onStart:function(){},onComplete:function(){},onError:function(t){i.warn("Failed to change "+e+" SourceBuffer type",t)}};this.append(n,e,this.isPending(this.tracks[e]))},r.blockAudio=function(e){var t,r=this,i=e.start,a=i+.05*e.duration;if(!0!==(null==(t=this.fragmentTracker.getAppendedFrag(i,P))?void 0:t.gap)){var n={label:"block-audio",execute:function(){var e,t=r.tracks.video;(r.lastVideoAppendEnd>a||null!=t&&t.buffer&&_t.isBuffered(t.buffer,a)||!0===(null==(e=r.fragmentTracker.getAppendedFrag(a,P))?void 0:e.gap))&&(r.blockedAudioAppend=null,r.shiftAndExecuteNext("audio"))},onStart:function(){},onComplete:function(){},onError:function(e){r.warn("Error executing block-audio operation",e)}};this.blockedAudioAppend={op:n,frag:e},this.append(n,"audio",!0)}},r.unblockAudio=function(){var e=this.blockedAudioAppend,t=this.operationQueue;e&&t&&(this.blockedAudioAppend=null,t.unblockAudio(e.op))},r.onBufferAppending=function(e,t){var r=this,i=this.tracks,a=t.data,n=t.type,s=t.parent,o=t.frag,l=t.part,u=t.chunkMeta,d=u.buffering[n],h=o.sn,f=self.performance.now();d.start=f;var c=o.stats.buffering,v=l?l.stats.buffering:null;0===c.start&&(c.start=f),v&&0===v.start&&(v.start=f);var g=i.audio,m=!1;"audio"===n&&"audio/mpeg"===(null==g?void 0:g.container)&&(m=!this.lastMpegAudioChunk||1===u.id||this.lastMpegAudioChunk.sn!==u.sn,this.lastMpegAudioChunk=u);var p=this.tracks.video,y=null==p?void 0:p.buffer;if(y&&"initSegment"!==h){var E=l||o,T=this.blockedAudioAppend;if("audio"!==n||"main"===s||this.blockedAudioAppend){if("video"===n){var S=E.end;if(T){var L=T.frag.start;(S>L||S=.1&&(r.log("Updating audio SourceBuffer timestampOffset to "+I+" (delta: "+i+") sn: "+h+")"),t.timestampOffset=I)}}}r.appendExecutor(a,n)},onStart:function(){},onComplete:function(){var e=self.performance.now();d.executeEnd=d.end=e,0===c.first&&(c.first=e),v&&0===v.first&&(v.first=e);var t={};r.sourceBuffers.forEach((function(e){var r=e[0],i=e[1];r&&(t[r]=_t.getBuffered(i))})),r.appendErrors[n]=0,"audio"===n||"video"===n?r.appendErrors.audiovideo=0:(r.appendErrors.audio=0,r.appendErrors.video=0),r.hls.trigger(k.BUFFER_APPENDED,{type:n,frag:o,part:l,chunkMeta:u,parent:o.type,timeRanges:t})},onError:function(e){var t,i={type:b.MEDIA_ERROR,parent:o.type,details:D.BUFFER_APPEND_ERROR,sourceBufferName:n,frag:o,part:l,chunkMeta:u,error:e,err:e,fatal:!1},a=null==(t=r.media)?void 0:t.error;if(e.code===DOMException.QUOTA_EXCEEDED_ERR)i.details=D.BUFFER_FULL_ERROR;else if(e.code===DOMException.INVALID_STATE_ERR&&r.mediaSourceOpenOrEnded&&!a)i.errorAction=Dt(!0);else if(e.name===Ct&&0===r.sourceBufferCount)i.errorAction=Dt(!0);else{var s=++r.appendErrors[n];r.warn("Failed "+s+"/"+r.hls.config.appendErrorMaxRetry+' times to append segment in "'+n+'" sourceBuffer ('+(a||"no media error")+")"),(s>=r.hls.config.appendErrorMaxRetry||a)&&(i.fatal=!0)}r.hls.trigger(k.ERROR,i)}};this.append(C,n,this.isPending(this.tracks[n]))},r.getFlushOp=function(e,t,r){var i=this;return this.log('queuing "'+e+'" remove '+t+"-"+r),{label:"remove",execute:function(){i.removeExecutor(e,t,r)},onStart:function(){},onComplete:function(){i.hls.trigger(k.BUFFER_FLUSHED,{type:e})},onError:function(a){i.warn("Failed to remove "+t+"-"+r+' from "'+e+'" SourceBuffer',a)}}},r.onBufferFlushing=function(e,t){var r=this,i=t.type,a=t.startOffset,n=t.endOffset;i?this.append(this.getFlushOp(i,a,n),i):this.sourceBuffers.forEach((function(e){var t=e[0];t&&r.append(r.getFlushOp(t,a,n),t)}))},r.onFragParsed=function(e,t){var r=this,i=t.frag,a=t.part,n=[],s=a?a.elementaryStreams:i.elementaryStreams;s[ee]?n.push("audiovideo"):(s[Z]&&n.push("audio"),s[J]&&n.push("video")),0===n.length&&this.warn("Fragments must have at least one ElementaryStreamType set. type: "+i.type+" level: "+i.level+" sn: "+i.sn),this.blockBuffers((function(){var e=self.performance.now();i.stats.buffering.end=e,a&&(a.stats.buffering.end=e);var t=a?a.stats:i.stats;r.hls.trigger(k.FRAG_BUFFERED,{frag:i,part:a,stats:t,id:i.type})}),n).catch((function(e){r.warn("Fragment buffered callback "+e),r.stepOperationQueue(r.sourceBufferTypes)}))},r.onFragChanged=function(e,t){this.trimBuffers()},r.onBufferEos=function(e,t){var r,i=this;this.sourceBuffers.forEach((function(e){var r=e[0];if(r){var a=i.tracks[r];t.type&&t.type!==r||(a.ending=!0,a.ended||(a.ended=!0,i.log(r+" buffer reached EOS")))}}));var a=!1!==(null==(r=this.overrides)?void 0:r.endOfStream);this.sourceBufferCount>0&&!this.sourceBuffers.some((function(e){var t,r=e[0];return r&&!(null!=(t=i.tracks[r])&&t.ended)}))&&(a?(this.log("Queueing EOS"),this.blockUntilOpen((function(){i.tracksEnded();var e=i.mediaSource;e&&"open"===e.readyState?(i.log("Calling mediaSource.endOfStream()"),e.endOfStream(),i.hls.trigger(k.BUFFERED_TO_END,void 0)):e&&i.log("Could not call mediaSource.endOfStream(). mediaSource.readyState: "+e.readyState)}))):(this.tracksEnded(),this.hls.trigger(k.BUFFERED_TO_END,void 0)))},r.tracksEnded=function(){var e=this;this.sourceBuffers.forEach((function(t){var r=t[0];if(null!==r){var i=e.tracks[r];i&&(i.ending=!1)}}))},r.onLevelUpdated=function(e,t){var r=t.details;r.fragments.length&&(this.details=r,this.updateDuration())},r.updateDuration=function(){var e=this,t=this.getDurationAndRange();t&&this.blockUntilOpen((function(){return e.updateMediaSource(t)}))},r.onError=function(e,t){if(t.details===D.BUFFER_APPEND_ERROR&&t.frag){var r,i=null==(r=t.errorAction)?void 0:r.nextAutoLevel;L(i)&&i!==t.frag.level&&this.resetAppendErrors()}},r.resetAppendErrors=function(){this.appendErrors={audio:0,video:0,audiovideo:0}},r.trimBuffers=function(){var e=this.hls,t=this.details,r=this.media;if(r&&null!==t&&this.sourceBufferCount){var i=e.config,a=r.currentTime,n=t.levelTargetDuration,s=t.live&&null!==i.liveBackBufferLength?i.liveBackBufferLength:i.backBufferLength;if(L(s)&&s>=0){var o=Math.max(s,n),l=Math.floor(a/n)*n-o;this.flushBackBuffer(a,n,l)}if(L(i.frontBufferFlushThreshold)&&i.frontBufferFlushThreshold>0){var u=Math.max(i.maxBufferLength,i.frontBufferFlushThreshold),d=Math.max(u,n),h=Math.floor(a/n)*n+d;this.flushFrontBuffer(a,n,h)}}},r.flushBackBuffer=function(e,t,r){var i=this;this.sourceBuffers.forEach((function(e){var t=e[0],a=e[1];if(a){var n=_t.getBuffered(a);if(n.length>0&&r>n.start(0)){var s;i.hls.trigger(k.BACK_BUFFER_REACHED,{bufferEnd:r});var o=i.tracks[t];if(null!=(s=i.details)&&s.live)i.hls.trigger(k.LIVE_BACK_BUFFER_REACHED,{bufferEnd:r});else if(null!=o&&o.ended)return void i.log("Cannot flush "+t+" back buffer while SourceBuffer is in ended state");i.hls.trigger(k.BUFFER_FLUSHING,{startOffset:0,endOffset:r,type:t})}}}))},r.flushFrontBuffer=function(e,t,r){var i=this;this.sourceBuffers.forEach((function(t){var a=t[0],n=t[1];if(n){var s=_t.getBuffered(n),o=s.length;if(o<2)return;var l=s.start(o-1),u=s.end(o-1);if(r>l||e>=l&&e<=u)return;i.hls.trigger(k.BUFFER_FLUSHING,{startOffset:l,endOffset:1/0,type:a})}}))},r.getDurationAndRange=function(){var e,t=this.details,r=this.mediaSource;if(!t||!this.media||"open"!==(null==r?void 0:r.readyState))return null;var i=t.edge;if(t.live&&this.hls.config.liveDurationInfinity){if(t.fragments.length&&t.live&&r.setLiveSeekableRange){var a=Math.max(0,t.fragmentStart);return{duration:1/0,start:a,end:Math.max(a,i)}}return{duration:1/0}}var n=null==(e=this.overrides)?void 0:e.duration;if(n)return L(n)?{duration:n}:null;var s=this.media.duration;return i>(L(r.duration)?r.duration:0)&&i>s||!L(s)?{duration:i}:null},r.updateMediaSource=function(e){var t=e.duration,r=e.start,i=e.end,a=this.mediaSource;this.media&&a&&"open"===a.readyState&&(a.duration!==t&&(L(t)&&this.log("Updating MediaSource duration to "+t.toFixed(3)),a.duration=t),void 0!==r&&void 0!==i&&(this.log("MediaSource duration is set to "+a.duration+". Setting seekable range to "+r+"-"+i+"."),a.setLiveSeekableRange(r,i)))},r.checkPendingTracks=function(){var e=this.bufferCodecEventsTotal,t=this.pendingTrackCount,r=this.tracks;if(this.log("checkPendingTracks (pending: "+t+" codec events expected: "+e+") "+it(r)),this.tracksReady){var i,a=null==(i=this.transferData)?void 0:i.tracks;a&&Object.keys(a).length?this.attachTransferred():this.createSourceBuffers()}},r.bufferCreated=function(){var e=this;if(this.sourceBufferCount){var t={};this.sourceBuffers.forEach((function(r){var i=r[0],a=r[1];if(i){var n=e.tracks[i];t[i]={buffer:a,container:n.container,codec:n.codec,supplemental:n.supplemental,levelCodec:n.levelCodec,id:n.id,metadata:n.metadata}}})),this.hls.trigger(k.BUFFER_CREATED,{tracks:t}),this.log("SourceBuffers created. Running queue: "+this.operationQueue),this.sourceBuffers.forEach((function(t){var r=t[0];e.executeNext(r)}))}else{var r=new Error("could not create source buffer for media codec(s)");this.hls.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:r,reason:r.message})}},r.createSourceBuffers=function(){var e=this.tracks,t=this.sourceBuffers,r=this.mediaSource;if(!r)throw new Error("createSourceBuffers called when mediaSource was null");for(var i in e){var a=i,n=e[a];if(this.isPending(n)){var s=this.getTrackCodec(n,a),o=n.container+";codecs="+s;n.codec=s,this.log("creating sourceBuffer("+o+")"+(this.currentOp(a)?" Queued":"")+" "+it(n));try{var l=r.addSourceBuffer(o),u=Ot(a),d=[a,l];t[u]=d,n.buffer=l}catch(e){var h;return this.error("error while trying to add sourceBuffer: "+e.message),this.shiftAndExecuteNext(a),null==(h=this.operationQueue)||h.removeBlockers(),delete this.tracks[a],void this.hls.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:e,sourceBufferName:a,mimeType:o,parent:n.id})}this.trackSourceBuffer(a,n)}}this.bufferCreated()},r.getTrackCodec=function(e,t){var r=e.supplemental,i=e.codec;r&&("video"===t||"audiovideo"===t)&&Me(r,"video")&&(i=function(e,t){var r=[];if(e)for(var i=e.split(","),a=0;au&&(!n.ending||n.ended)?(n.ended=!1,this.log("Removing ["+u+","+d+"] from the "+e+" SourceBuffer"),s.remove(u,d)):this.shiftAndExecuteNext(e)},r.appendExecutor=function(e,t){var r=this.tracks[t],i=null==r?void 0:r.buffer;if(!i)throw new xt("Attempting to append to the "+t+" SourceBuffer, but it does not exist");r.ending=!1,r.ended=!1,i.appendBuffer(e)},r.blockUntilOpen=function(e){var t=this;if(this.isUpdating()||this.isQueued())this.blockBuffers(e).catch((function(e){t.warn("SourceBuffer blocked callback "+e),t.stepOperationQueue(t.sourceBufferTypes)}));else try{e()}catch(e){this.warn("Callback run without blocking "+this.operationQueue+" "+e)}},r.isUpdating=function(){return this.sourceBuffers.some((function(e){var t=e[0],r=e[1];return t&&r.updating}))},r.isQueued=function(){var e=this;return this.sourceBuffers.some((function(t){var r=t[0];return r&&!!e.currentOp(r)}))},r.isPending=function(e){return!!e&&!e.buffer},r.blockBuffers=function(e,t){var r=this;if(void 0===t&&(t=this.sourceBufferTypes),!t.length)return this.log("Blocking operation requested, but no SourceBuffers exist"),Promise.resolve().then(e);var i=this.operationQueue,a=t.map((function(e){return r.appendBlocker(e)}));return t.length>1&&!!this.blockedAudioAppend&&this.unblockAudio(),Promise.all(a).then((function(t){i===r.operationQueue&&(e(),r.stepOperationQueue(r.sourceBufferTypes))}))},r.stepOperationQueue=function(e){var t=this;e.forEach((function(e){var r,i=null==(r=t.tracks[e])?void 0:r.buffer;i&&!i.updating&&t.shiftAndExecuteNext(e)}))},r.append=function(e,t,r){this.operationQueue&&this.operationQueue.append(e,t,r)},r.appendBlocker=function(e){if(this.operationQueue)return this.operationQueue.appendBlocker(e)},r.currentOp=function(e){return this.operationQueue?this.operationQueue.current(e):null},r.executeNext=function(e){e&&this.operationQueue&&this.operationQueue.executeNext(e)},r.shiftAndExecuteNext=function(e){this.operationQueue&&this.operationQueue.shiftAndExecuteNext(e)},r.addBufferListener=function(e,t,r){var i=this.tracks[e];if(i){var a=i.buffer;if(a){var n=r.bind(this,e);i.listeners.push({event:t,listener:n}),a.addEventListener(t,n)}}},r.removeBufferListeners=function(e){var t=this.tracks[e];if(t){var r=t.buffer;r&&(t.listeners.forEach((function(e){r.removeEventListener(e.event,e.listener)})),t.listeners.length=0)}},i(t,[{key:"mediaSourceOpenOrEnded",get:function(){var e,t=null==(e=this.mediaSource)?void 0:e.readyState;return"open"===t||"ended"===t}},{key:"sourceBufferTracks",get:function(){var e=this;return Object.keys(this.tracks).reduce((function(t,r){var i=e.tracks[r];return t[r]={id:i.id,container:i.container,codec:i.codec,levelCodec:i.levelCodec},t}),{})}},{key:"bufferedToEnd",get:function(){var e=this;return this.sourceBufferCount>0&&!this.sourceBuffers.some((function(t){var r,i,a=t[0];return a&&(!(null!=(r=e.tracks[a])&&r.ended)||(null==(i=e.tracks[a])?void 0:i.ending))}))}},{key:"tracksReady",get:function(){var e=this.pendingTrackCount;return e>0&&(e>=this.bufferCodecEventsTotal||this.isPending(this.tracks.audiovideo))}},{key:"mediaSrc",get:function(){var e,t,r=(null==(e=this.media)||null==(t=e.querySelector)?void 0:t.call(e,"source"))||this.media;return null==r?void 0:r.src}},{key:"pendingTrackCount",get:function(){var e=this;return Object.keys(this.tracks).reduce((function(t,r){return t+(e.isPending(e.tracks[r])?1:0)}),0)}},{key:"sourceBufferCount",get:function(){return this.sourceBuffers.reduce((function(e,t){return e+(t[0]?1:0)}),0)}},{key:"sourceBufferTypes",get:function(){return this.sourceBuffers.map((function(e){return e[0]})).filter((function(e){return!!e}))}}])}(N);function wt(e){var t=e.querySelectorAll("source");[].slice.call(t).forEach((function(t){e.removeChild(t)}))}function Ot(e){return"audio"===e?1:0}var Mt=function(){function e(e){this.hls=void 0,this.autoLevelCapping=void 0,this.firstLevel=void 0,this.media=void 0,this.restrictedLevels=void 0,this.timer=void 0,this.clientRect=void 0,this.streamController=void 0,this.hls=e,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.firstLevel=-1,this.media=null,this.restrictedLevels=[],this.timer=void 0,this.clientRect=null,this.registerListeners()}var t=e.prototype;return t.setStreamController=function(e){this.streamController=e},t.destroy=function(){this.hls&&this.unregisterListener(),this.timer&&this.stopCapping(),this.media=null,this.clientRect=null,this.hls=this.streamController=null},t.registerListeners=function(){var e=this.hls;e.on(k.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.on(k.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(k.MANIFEST_PARSED,this.onManifestParsed,this),e.on(k.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(k.BUFFER_CODECS,this.onBufferCodecs,this),e.on(k.MEDIA_DETACHING,this.onMediaDetaching,this)},t.unregisterListener=function(){var e=this.hls;e.off(k.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.off(k.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(k.MANIFEST_PARSED,this.onManifestParsed,this),e.off(k.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(k.BUFFER_CODECS,this.onBufferCodecs,this),e.off(k.MEDIA_DETACHING,this.onMediaDetaching,this)},t.onFpsDropLevelCapping=function(e,t){var r=this.hls.levels[t.droppedLevel];this.isLevelAllowed(r)&&this.restrictedLevels.push({bitrate:r.bitrate,height:r.height,width:r.width})},t.onMediaAttaching=function(e,t){this.media=t.media instanceof HTMLVideoElement?t.media:null,this.clientRect=null,this.timer&&this.hls.levels.length&&this.detectPlayerSize()},t.onManifestParsed=function(e,t){var r=this.hls;this.restrictedLevels=[],this.firstLevel=t.firstLevel,r.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onLevelsUpdated=function(e,t){this.timer&&L(this.autoLevelCapping)&&this.detectPlayerSize()},t.onBufferCodecs=function(e,t){this.hls.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onMediaDetaching=function(){this.stopCapping(),this.media=null},t.detectPlayerSize=function(){if(this.media){if(this.mediaHeight<=0||this.mediaWidth<=0)return void(this.clientRect=null);var e=this.hls.levels;if(e.length){var t=this.hls,r=this.getMaxLevel(e.length-1);r!==this.autoLevelCapping&&t.logger.log("Setting autoLevelCapping to "+r+": "+e[r].height+"p@"+e[r].bitrate+" for media "+this.mediaWidth+"x"+this.mediaHeight),t.autoLevelCapping=r,t.autoLevelEnabled&&t.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=t.autoLevelCapping}}},t.getMaxLevel=function(t){var r=this,i=this.hls.levels;if(!i.length)return-1;var a=i.filter((function(e,i){return r.isLevelAllowed(e)&&i<=t}));return this.clientRect=null,e.getMaxLevelByMediaSize(a,this.mediaWidth,this.mediaHeight)},t.startCapping=function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},t.stopCapping=function(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)},t.getDimensions=function(){if(this.clientRect)return this.clientRect;var e=this.media,t={width:0,height:0};if(e){var r=e.getBoundingClientRect();t.width=r.width,t.height=r.height,t.width||t.height||(t.width=r.right-r.left||e.width||0,t.height=r.bottom-r.top||e.height||0)}return this.clientRect=t,t},t.isLevelAllowed=function(e){return!this.restrictedLevels.some((function(t){return e.bitrate===t.bitrate&&e.width===t.width&&e.height===t.height}))},e.getMaxLevelByMediaSize=function(e,t,r){if(null==e||!e.length)return-1;for(var i,a,n=e.length-1,s=Math.max(t,r),o=0;o=s||l.height>=s)&&(i=l,!(a=e[o+1])||i.width!==a.width||i.height!==a.height)){n=o;break}}return n},i(e,[{key:"mediaWidth",get:function(){return this.getDimensions().width*this.contentScaleFactor}},{key:"mediaHeight",get:function(){return this.getDimensions().height*this.contentScaleFactor}},{key:"contentScaleFactor",get:function(){var e=1;if(!this.hls.config.ignoreDevicePixelRatio)try{e=self.devicePixelRatio}catch(e){}return Math.min(e,this.hls.config.maxDevicePixelRatio)}}])}(),Ft=/^(\d+)x(\d+)$/,Nt=/(.+?)=(".*?"|.*?)(?:,|$)/g,Bt=function(){function e(t,r){"string"==typeof t&&(t=e.parseAttrList(t,r)),n(this,t)}var t=e.prototype;return t.decimalInteger=function(e){var t=parseInt(this[e],10);return t>Number.MAX_SAFE_INTEGER?1/0:t},t.hexadecimalInteger=function(e){if(this[e]){var t=(this[e]||"0x").slice(2);t=(1&t.length?"0":"")+t;for(var r=new Uint8Array(t.length/2),i=0;iNumber.MAX_SAFE_INTEGER?1/0:t},t.decimalFloatingPoint=function(e){return parseFloat(this[e])},t.optionalFloat=function(e,t){var r=this[e];return r?parseFloat(r):t},t.enumeratedString=function(e){return this[e]},t.enumeratedStringList=function(e,t){var r=this[e];return(r?r.split(/[ ,]+/):[]).reduce((function(e,t){return e[t.toLowerCase()]=!0,e}),t)},t.bool=function(e){return"YES"===this[e]},t.decimalResolution=function(e){var t=Ft.exec(this[e]);if(null!==t)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}},e.parseAttrList=function(e,t){var r,i={};for(Nt.lastIndex=0;null!==(r=Nt.exec(e));){var a=r[1].trim(),n=r[2],s=0===n.indexOf('"')&&n.lastIndexOf('"')===n.length-1,o=!1;if(s)n=n.slice(1,-1);else switch(a){case"IV":case"SCTE35-CMD":case"SCTE35-IN":case"SCTE35-OUT":o=!0}if(t&&(s||o));else if(!o&&!s)switch(a){case"CLOSED-CAPTIONS":if("NONE"===n)break;case"ALLOWED-CPC":case"CLASS":case"ASSOC-LANGUAGE":case"AUDIO":case"BYTERANGE":case"CHANNELS":case"CHARACTERISTICS":case"CODECS":case"DATA-ID":case"END-DATE":case"GROUP-ID":case"ID":case"IMPORT":case"INSTREAM-ID":case"KEYFORMAT":case"KEYFORMATVERSIONS":case"LANGUAGE":case"NAME":case"PATHWAY-ID":case"QUERYPARAM":case"RECENTLY-REMOVED-DATERANGES":case"SERVER-URI":case"STABLE-RENDITION-ID":case"STABLE-VARIANT-ID":case"START-DATE":case"SUBTITLES":case"SUPPLEMENTAL-CODECS":case"URI":case"VALUE":case"VIDEO":case"X-ASSET-LIST":case"X-ASSET-URI":j.warn(e+": attribute "+a+" is missing quotes")}i[a]=n}return i},i(e,[{key:"clientAttrs",get:function(){return Object.keys(this).filter((function(e){return"X-"===e.substring(0,2)}))}}])}();function Ut(e){return"SCTE35-OUT"===e||"SCTE35-IN"===e||"SCTE35-CMD"===e}var Gt=function(){return i((function(e,t,r){var i;if(void 0===r&&(r=0),this.attr=void 0,this.tagAnchor=void 0,this.tagOrder=void 0,this._startDate=void 0,this._endDate=void 0,this._dateAtEnd=void 0,this._cue=void 0,this._badValueForSameId=void 0,this.tagAnchor=(null==t?void 0:t.tagAnchor)||null,this.tagOrder=null!=(i=null==t?void 0:t.tagOrder)?i:r,t){var a=t.attr;for(var s in a)if(Object.prototype.hasOwnProperty.call(e,s)&&e[s]!==a[s]){j.warn('DATERANGE tag attribute: "'+s+'" does not match for tags with ID: "'+e.ID+'"'),this._badValueForSameId=s;break}e=n(new Bt({}),a,e)}if(this.attr=e,t?(this._startDate=t._startDate,this._cue=t._cue,this._endDate=t._endDate,this._dateAtEnd=t._dateAtEnd):this._startDate=new Date(e["START-DATE"]),"END-DATE"in this.attr){var o=(null==t?void 0:t.endDate)||new Date(this.attr["END-DATE"]);L(o.getTime())&&(this._endDate=o)}}),[{key:"id",get:function(){return this.attr.ID}},{key:"class",get:function(){return this.attr.CLASS}},{key:"cue",get:function(){var e=this._cue;return void 0===e?this._cue=this.attr.enumeratedStringList(this.attr.CUE?"CUE":"X-CUE",{pre:!1,post:!1,once:!1}):e}},{key:"startTime",get:function(){var e=this.tagAnchor;return null===e||null===e.programDateTime?(j.warn('Expected tagAnchor Fragment with PDT set for DateRange "'+this.id+'": '+e),NaN):e.start+(this.startDate.getTime()-e.programDateTime)/1e3}},{key:"startDate",get:function(){return this._startDate}},{key:"endDate",get:function(){var e=this._endDate||this._dateAtEnd;if(e)return e;var t=this.duration;return null!==t?this._dateAtEnd=new Date(this._startDate.getTime()+1e3*t):null}},{key:"duration",get:function(){if("DURATION"in this.attr){var e=this.attr.decimalFloatingPoint("DURATION");if(L(e))return e}else if(this._endDate)return(this._endDate.getTime()-this._startDate.getTime())/1e3;return null}},{key:"plannedDuration",get:function(){return"PLANNED-DURATION"in this.attr?this.attr.decimalFloatingPoint("PLANNED-DURATION"):null}},{key:"endOnNext",get:function(){return this.attr.bool("END-ON-NEXT")}},{key:"isInterstitial",get:function(){return"com.apple.hls.interstitial"===this.class}},{key:"isValid",get:function(){return!!this.id&&!this._badValueForSameId&&L(this.startDate.getTime())&&(null===this.duration||this.duration>=0)&&(!this.endOnNext||!!this.class)&&(!this.attr.CUE||!this.cue.pre&&!this.cue.post||this.cue.pre!==this.cue.post)&&(!this.isInterstitial||"X-ASSET-URI"in this.attr||"X-ASSET-LIST"in this.attr)}}])}(),Vt=function(){function e(e){this.PTSKnown=!1,this.alignedSliding=!1,this.averagetargetduration=void 0,this.endCC=0,this.endSN=0,this.fragments=void 0,this.fragmentHint=void 0,this.partList=null,this.dateRanges=void 0,this.dateRangeTagCount=0,this.live=!0,this.requestScheduled=-1,this.ageHeader=0,this.advancedDateTime=void 0,this.updated=!0,this.advanced=!0,this.misses=0,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=void 0,this.m3u8="",this.version=null,this.canBlockReload=!1,this.canSkipUntil=0,this.canSkipDateRanges=!1,this.skippedSegments=0,this.recentlyRemovedDateranges=void 0,this.partHoldBack=0,this.holdBack=0,this.partTarget=0,this.preloadHint=void 0,this.renditionReports=void 0,this.tuneInGoal=0,this.deltaUpdateFailed=void 0,this.driftStartTime=0,this.driftEndTime=0,this.driftStart=0,this.driftEnd=0,this.encryptedFragments=void 0,this.playlistParsingError=null,this.variableList=null,this.hasVariableRefs=!1,this.appliedTimelineOffset=void 0,this.fragments=[],this.encryptedFragments=[],this.dateRanges={},this.url=e}return e.prototype.reloaded=function(e){if(!e)return this.advanced=!0,void(this.updated=!0);var t=this.lastPartSn-e.lastPartSn,r=this.lastPartIndex-e.lastPartIndex;this.updated=this.endSN!==e.endSN||!!r||!!t||!this.live,this.advanced=this.endSN>e.endSN||t>0||0===t&&r>0,this.updated||this.advanced?this.misses=Math.floor(.6*e.misses):this.misses=e.misses+1},i(e,[{key:"hasProgramDateTime",get:function(){return!!this.fragments.length&&L(this.fragments[this.fragments.length-1].programDateTime)}},{key:"levelTargetDuration",get:function(){return this.averagetargetduration||this.targetduration||10}},{key:"drift",get:function(){var e=this.driftEndTime-this.driftStartTime;return e>0?1e3*(this.driftEnd-this.driftStart)/e:1}},{key:"edge",get:function(){return this.partEnd||this.fragmentEnd}},{key:"partEnd",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].end:this.fragmentEnd}},{key:"fragmentEnd",get:function(){var e;return null!=(e=this.fragments)&&e.length?this.fragments[this.fragments.length-1].end:0}},{key:"fragmentStart",get:function(){var e;return null!=(e=this.fragments)&&e.length?this.fragments[0].start:0}},{key:"age",get:function(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}},{key:"lastPartIndex",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].index:-1}},{key:"maxPartIndex",get:function(){var e=this.partList;if(e){var t=this.lastPartIndex;if(-1!==t){for(var r=e.length;r--;)if(e[r].index>t)return e[r].index;return t}}return 0}},{key:"lastPartSn",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}},{key:"expired",get:function(){if(this.live&&this.age&&this.misses<3){var e=this.partEnd-this.fragmentStart;return this.age>Math.max(e,this.totalduration)+this.levelTargetDuration}return!1}}])}(),Ht=0,Kt=1;function Wt(e){return"AES-128"===e||"AES-256"===e||"AES-256-CTR"===e}function Yt(e){switch(e){case"AES-128":case"AES-256":return Ht;case"AES-256-CTR":return Kt;default:throw new Error("invalid full segment method "+e)}}var jt=function(){function e(e,t,r,i,a){void 0===i&&(i=[1]),void 0===a&&(a=null),this.uri=void 0,this.method=void 0,this.keyFormat=void 0,this.keyFormatVersions=void 0,this.encrypted=void 0,this.isCommonEncryption=void 0,this.iv=null,this.key=null,this.keyId=null,this.pssh=null,this.method=e,this.uri=t,this.keyFormat=r,this.keyFormatVersions=i,this.iv=a,this.encrypted=!!e&&"NONE"!==e,this.isCommonEncryption=this.encrypted&&!Wt(e)}e.clearKeyUriToKeyIdMap=function(){};var t=e.prototype;return t.isSupported=function(){if(this.method){if(Wt(this.method)||"NONE"===this.method)return!0;if("identity"===this.keyFormat)return"SAMPLE-AES"===this.method}return!1},t.getDecryptData=function(t){if(!this.encrypted||!this.uri)return null;if(Wt(this.method)&&this.uri&&!this.iv){"number"!=typeof t&&(j.warn('missing IV for initialization segment with method="'+this.method+'" - compliance issue'),t=0);var r=function(e){for(var t=new Uint8Array(16),r=12;r<16;r++)t[r]=e>>8*(15-r)&255;return t}(t);return new e(this.method,this.uri,"identity",this.keyFormatVersions,r)}return this},e}(),qt=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-(SESSION-DATA|SESSION-KEY|DEFINE|CONTENT-STEERING|START):([^\r\n]*)[\r\n]+/g,Xt=/#EXT-X-MEDIA:(.*)/g,zt=/^#EXT(?:INF|-X-TARGETDURATION):/m,Qt=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[^\r\n]*)/.source,/#.*/.source].join("|"),"g"),$t=new RegExp([/#EXT-X-(PROGRAM-DATE-TIME|BYTERANGE|DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP|INDEPENDENT-SEGMENTS)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),Zt=function(){function e(){}return e.findGroup=function(e,t){for(var r=0;r0&&n.length0&&ur(c,x,l),p=c.startSN=parseInt(P);break;case"SKIP":c.skippedSegments&&lr(c,x,l);var O=new Bt(P,c),M=O.decimalInteger("SKIPPED-SEGMENTS");if(L(M)){c.skippedSegments+=M;for(var F=M;F--;)v.push(null);p+=M}var N=O.enumeratedString("RECENTLY-REMOVED-DATERANGES");N&&(c.recentlyRemovedDateranges=(c.recentlyRemovedDateranges||[]).concat(N.split("\t")));break;case"TARGETDURATION":0!==c.targetduration&&lr(c,x,l),c.targetduration=Math.max(parseInt(P),1);break;case"VERSION":null!==c.version&&lr(c,x,l),c.version=parseInt(P);break;case"INDEPENDENT-SEGMENTS":case"DEFINE":break;case"ENDLIST":c.live||lr(c,x,l),c.live=!1;break;case"#":(P||w)&&A.tagList.push(w?[P,w]:[P]);break;case"DISCONTINUITY":T++,A.tagList.push(["DIS"]);break;case"GAP":A.gap=!0,A.tagList.push([x]);break;case"BITRATE":A.tagList.push([x,P]),S=1e3*parseInt(P),L(S)?A.bitrate=S:S=0;break;case"DATERANGE":var B=new Bt(P,c),U=new Gt(B,c.dateRanges[B.ID],c.dateRangeTagCount);c.dateRangeTagCount++,U.isValid||c.skippedSegments?c.dateRanges[U.id]=U:j.warn('Ignoring invalid DATERANGE tag: "'+P+'"'),A.tagList.push(["EXT-X-DATERANGE",P]);break;case"DISCONTINUITY-SEQUENCE":0!==c.startCC?lr(c,x,l):v.length>0&&ur(c,x,l),c.startCC=T=parseInt(P);break;case"KEY":var G=tr(P,t,c);if(G.isSupported()){if("NONE"===G.method){d=void 0;break}d||(d={}),d[G.keyFormat]&&(d=n({},d)),d[G.keyFormat]=G}else j.warn('[Keys] Ignoring invalid EXT-X-KEY tag: "'+P+'"');break;case"START":c.startTimeOffset=rr(P);break;case"MAP":var V=new Bt(P,c);if(A.duration){var H=new ie(i,f);sr(H,V,r,d),m=H,A.initSegment=m,m.rawProgramDateTime&&!A.rawProgramDateTime&&(A.rawProgramDateTime=m.rawProgramDateTime)}else{var K=A.byteRangeEndOffset;if(K){var W=A.byteRangeStartOffset;k=K-W+"@"+W}else k=null;sr(A,V,r,d),m=A,D=!0}m.cc=T;break;case"SERVER-CONTROL":h&&lr(c,x,l),h=new Bt(P),c.canBlockReload=h.bool("CAN-BLOCK-RELOAD"),c.canSkipUntil=h.optionalFloat("CAN-SKIP-UNTIL",0),c.canSkipDateRanges=c.canSkipUntil>0&&h.bool("CAN-SKIP-DATERANGES"),c.partHoldBack=h.optionalFloat("PART-HOLD-BACK",0),c.holdBack=h.optionalFloat("HOLD-BACK",0);break;case"PART-INF":c.partTarget&&lr(c,x,l);var Y=new Bt(P);c.partTarget=Y.decimalFloatingPoint("PART-TARGET");break;case"PART":var q=c.partList;q||(q=c.partList=[]);var X=y>0?q[q.length-1]:void 0,z=y++,Q=new Bt(P,c),$=new ae(Q,A,f,z,X);q.push($),A.duration+=$.duration;break;case"PRELOAD-HINT":var Z=new Bt(P,c);c.preloadHint=Z;break;case"RENDITION-REPORT":var J=new Bt(P,c);c.renditionReports=c.renditionReports||[],c.renditionReports.push(J);break;default:j.warn("line parsed but not handled: "+l)}}}R&&!R.relurl?(v.pop(),E-=R.duration,c.partList&&(c.fragmentHint=R)):c.partList&&(nr(A,R,g),A.cc=T,c.fragmentHint=A,d&&or(A,d,c)),c.targetduration||(c.playlistParsingError=new Error("#EXT-X-TARGETDURATION is required"));var ee=v.length,te=v[0],re=v[ee-1];if((E+=c.skippedSegments*c.targetduration)>0&&ee&&re){c.averagetargetduration=E/ee;var ne=re.sn;c.endSN="initSegment"!==ne?ne:0,c.live||(re.endList=!0),te&&void 0===c.startCC&&(c.startCC=te.cc),b>0&&(function(e,t){for(var r=e[t],i=t;i--;){var a=e[i];if(!a)return;a.programDateTime=r.programDateTime-1e3*a.duration,r=a}}(v,b),te&&g.unshift(te))}else c.endSN=0,c.startCC=0;return c.fragmentHint&&(E+=c.fragmentHint.duration),c.totalduration=E,g.length&&c.dateRangeTagCount&&te&&Jt(g,c),c.endCC=T,c},e}();function Jt(e,t){for(var r=e.length,i=e[r-1],a=t.live?1/0:t.totalduration,n=Object.keys(t.dateRanges),s=n.length;s--;){var o=t.dateRanges[n[s]],l=o.startDate.getTime();o.tagAnchor=i.ref;for(var u=r;u--;){var d=er(t,l,e,u,a);if(-1!==d){o.tagAnchor=t.fragments[d].ref;break}}}}function er(e,t,r,i,a){var n=r[i];if(n){var s,o=n.programDateTime;if((t>=o||0===i)&&t<=o+1e3*(((null==(s=r[i+1])?void 0:s.start)||a)-n.start)){var l=r[i].sn-e.startSN,u=e.fragments;if(u.length>r.length)for(var d=(r[i+1]||u[u.length-1]).sn-e.startSN;d>l;d--){var h=u[d].programDateTime;if(t>=h&&te.sn?(a=r-e.start,i=e):(a=e.start-r,i=t),i.duration!==a&&i.setDuration(a)}else t.sn>e.sn?e.cc===t.cc&&e.minEndPTS?t.setStart(e.start+(e.minEndPTS-e.start)):t.setStart(e.start+e.duration):t.setStart(Math.max(e.start-t.duration,0))}function hr(e,t,r,i,a,n){i-r<=0&&(j.warn("Fragment should have a positive duration",t),i=r+t.duration,n=a+t.duration);var s=r,o=i,l=t.startPTS,u=t.endPTS;if(L(l)){var d=Math.abs(l-r);L(t.deltaPTS)?t.deltaPTS=Math.max(d,t.deltaPTS):t.deltaPTS=d,s=Math.max(r,l),r=Math.min(r,l),a=Math.min(a,t.startDTS),o=Math.min(i,u),i=Math.max(i,u),n=Math.max(n,t.endDTS)}var h=r-t.start;0!==t.start&&t.setStart(r),t.setDuration(i-t.start),t.startPTS=r,t.maxStartPTS=s,t.startDTS=a,t.endPTS=i,t.minEndPTS=o,t.endDTS=n;var f,c=t.sn;if(!e||ce.endSN)return 0;var v=c-e.startSN,g=e.fragments;for(g[v]=t,f=v;f>0;f--)dr(g[f],g[f-1]);for(f=v;f=0;s--){var o=a[s].initSegment;if(o){i=o;break}}e.fragmentHint&&delete e.fragmentHint.endPTS,function(e,t,r){for(var i=t.skippedSegments,a=Math.max(e.startSN,t.startSN)-t.startSN,n=(e.fragmentHint?1:0)+(i?t.endSN:Math.min(e.endSN,t.endSN))-t.startSN,s=t.startSN-e.startSN,o=t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments,l=e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments,u=a;u<=n;u++){var d=l[s+u],h=o[u];if(i&&!h&&d&&(h=t.fragments[u]=d),d&&h){if(r(d,h,u,o),d.url&&d.url!==h.url)return void(t.playlistParsingError=cr("media sequence mismatch "+h.sn+":",e,t,0,h));if(d.cc!==h.cc)return void(t.playlistParsingError=cr("discontinuity sequence mismatch ("+d.cc+"!="+h.cc+")",e,t,0,h))}}}(e,t,(function(a,n,s,o){if(!t.startCC&&n.cc!==a.cc){for(var l,u,d=a.cc-n.cc,h=s;h=0,s=0;if(n&&it){var a=1e3*i[i.length-1].duration;a0)return void this.scheduleRefresh(this.uri,e)}this.loadSteeringManifest(this.uri)}},r.stopLoad=function(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),this.clearTimeout()},r.clearTimeout=function(){-1!==this.reloadTimer&&(self.clearTimeout(this.reloadTimer),this.reloadTimer=-1)},r.destroy=function(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null},r.removeLevel=function(e){var t=this.levels;t&&(this.levels=t.filter((function(t){return t!==e})))},r.onManifestLoading=function(){this.stopLoad(),this.enabled=!0,this.timeToLoad=300,this.updated=0,this.uri=null,this.pathwayId=".",this.levels=this.audioTracks=this.subtitleTracks=null},r.onManifestLoaded=function(e,t){var r=t.contentSteering;null!==r&&(this.pathwayId=r.pathwayId,this.uri=r.uri,this.started&&this.startLoad())},r.onManifestParsed=function(e,t){this.audioTracks=t.audioTracks,this.subtitleTracks=t.subtitleTracks},r.onError=function(e,t){var r=t.errorAction;if((null==r?void 0:r.action)===Et&&r.flags===Rt){var i=this.levels,a=this._pathwayPriority,n=this.pathwayId;if(t.context){var s=t.context,o=s.groupId,l=s.pathwayId,u=s.type;o&&i?n=this.getPathwayForGroupId(o,u,n):l&&(n=l)}n in this.penalizedPathways||(this.penalizedPathways[n]=performance.now()),!a&&i&&(a=this.pathways()),a&&a.length>1&&(this.updatePathwayPriority(a),r.resolved=this.pathwayId!==n),r.resolved||this.warn("Could not resolve "+t.details+' ("'+t.error.message+'") with content-steering for Pathway: '+n+" levels: "+(i?i.length:i)+" priorities: "+it(a)+" penalized: "+it(this.penalizedPathways))}},r.filterParsedLevels=function(e){this.levels=e;var t=this.getLevelsForPathway(this.pathwayId);if(0===t.length){var r=e[0].pathwayId;this.log("No levels found in Pathway "+this.pathwayId+'. Setting initial Pathway to "'+r+'"'),t=this.getLevelsForPathway(r),this.pathwayId=r}return t.length!==e.length&&this.log("Found "+t.length+"/"+e.length+' levels in Pathway "'+this.pathwayId+'"'),t},r.getLevelsForPathway=function(e){return null===this.levels?[]:this.levels.filter((function(t){return e===t.pathwayId}))},r.updatePathwayPriority=function(e){var t;this._pathwayPriority=e;var r=this.penalizedPathways,i=performance.now();Object.keys(r).forEach((function(e){i-r[e]>3e5&&delete r[e]}));for(var a=0;a0){this.log('Setting Pathway to "'+n+'"'),this.pathwayId=n,Er(t),this.hls.trigger(k.LEVELS_UPDATED,{levels:t});var l=this.hls.levels[s];o&&l&&this.levels&&(l.attrs["STABLE-VARIANT-ID"]!==o.attrs["STABLE-VARIANT-ID"]&&l.bitrate!==o.bitrate&&this.log("Unstable Pathways change from bitrate "+o.bitrate+" to "+l.bitrate),this.hls.nextLoadLevel=s);break}}}},r.getPathwayForGroupId=function(e,t,r){for(var i=this.getLevelsForPathway(r).concat(this.levels||[]),a=0;a0&&n>l.config.fpsDroppedMonitoringThreshold*s){var u=l.currentLevel;l.logger.warn("drop FPS ratio greater than max allowed value for currentLevel: "+u),u>0&&(-1===l.autoLevelCapping||l.autoLevelCapping>=u)&&(u-=1,l.trigger(k.FPS_DROP_LEVEL_CAPPING,{level:u,droppedLevel:l.currentLevel}),l.autoLevelCapping=u,this.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=r,this.lastDecodedFrames=t}},t.checkFPSInterval=function(){var e=this.media;if(e)if(this.isVideoPlaybackQualityAvailable){var t=e.getVideoPlaybackQuality();this.checkFPS(e,t.totalVideoFrames,t.droppedVideoFrames)}else this.checkFPS(e,e.webkitDecodedFrameCount,e.webkitDroppedFrameCount)},e}(),Ar=function(){function e(){this.chunks=[],this.dataLength=0}var t=e.prototype;return t.push=function(e){this.chunks.push(e),this.dataLength+=e.length},t.flush=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)return e.subarray(r,r+i)}function Ir(e,t){return 255===e[t]&&240==(246&e[t+1])}function Cr(e,t){return 1&e[t+1]?7:9}function xr(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function Pr(e,t){return t+1=e.length)return!1;var i=xr(e,t);if(i<=r)return!1;var a=t+i;return a===e.length||Pr(e,a)}return!1}function Or(e,t,r,i,a){if(!e.samplerate){var s=function(e,t,r,i){var a=t[r+2],n=a>>2&15;if(!(n>12)){var s=1+(a>>6&3),o=t[r+3]>>6&3|(1&a)<<2,l="mp4a.40."+s,u=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][n],d=n;5!==s&&29!==s||(d-=3);var h=[s<<3|(14&d)>>1,(1&d)<<7|o<<3];return j.log("manifest codec:"+i+", parsed codec:"+l+", channels:"+o+", rate:"+u+" (ADTS object type:"+s+" sampling index:"+n+")"),{config:h,samplerate:u,channelCount:o,codec:l,parsedCodec:l,manifestCodec:i}}var f=new Error("invalid ADTS sampling index:"+n);e.emit(k.ERROR,k.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!0,error:f,reason:f.message})}(t,r,i,a);if(!s)return;n(e,s)}}function Mr(e){return 9216e4/e}function Fr(e,t,r,i,a){var n,s=i+a*Mr(e.samplerate),o=function(e,t){var r=Cr(e,t);if(t+r<=e.length){var i=xr(e,t)-r;if(i>0)return{headerLength:r,frameLength:i}}}(t,r);if(o){var l=o.frameLength,u=o.headerLength,d=u+l,h=Math.max(0,r+d-t.length);h?(n=new Uint8Array(d-u)).set(t.subarray(r+u,t.length),0):n=t.subarray(r+u,r+d);var f={unit:n,pts:s};return h||e.samples.push(f),{sample:f,length:d,missing:h}}var c=t.length-r;return(n=new Uint8Array(c)).set(t.subarray(r,t.length),0),{sample:{unit:n,pts:s},length:c,missing:-1}}function Nr(e,t){return Dr(e,t)&&kr(e,t+6)+10<=e.length-t}function Br(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=1/0),function(e,t,r,i){var a=function(e){return e instanceof ArrayBuffer?e:e.buffer}(e),n=1;"BYTES_PER_ELEMENT"in i&&(n=i.BYTES_PER_ELEMENT);var s,o=(s=e)&&s.buffer instanceof ArrayBuffer&&void 0!==s.byteLength&&void 0!==s.byteOffset?e.byteOffset:0,l=(o+e.byteLength)/n,u=(o+t)/n,d=Math.floor(Math.max(0,Math.min(u,l))),h=Math.floor(Math.min(d+Math.max(r,0),l));return new i(a,d,h-d)}(e,t,r,Uint8Array)}function Ur(e){var t={key:e.type,description:"",data:"",mimeType:null,pictureType:null};if(!(e.size<2))if(3===e.data[0]){var r=e.data.subarray(1).indexOf(0);if(-1!==r){var i=z(Br(e.data,1,r)),a=e.data[2+r],n=e.data.subarray(3+r).indexOf(0);if(-1!==n){var s,o=z(Br(e.data,3+r,n));return s="--\x3e"===i?z(Br(e.data,4+r+n)):function(e){return e instanceof ArrayBuffer?e:0==e.byteOffset&&e.byteLength==e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer}(e.data.subarray(4+r+n)),t.mimeType=i,t.pictureType=a,t.description=o,t.data=s,t}}}else console.log("Ignore frame with unrecognized character encoding")}function Gr(e){return"PRIV"===e.type?function(e){if(!(e.size<2)){var t=z(e.data,!0),r=new Uint8Array(e.data.subarray(t.length+1));return{key:e.type,info:t,data:r.buffer}}}(e):"W"===e.type[0]?function(e){if("WXXX"===e.type){if(e.size<2)return;var t=1,r=z(e.data.subarray(t),!0);t+=r.length+1;var i=z(e.data.subarray(t));return{key:e.type,info:r,data:i}}var a=z(e.data);return{key:e.type,info:"",data:a}}(e):"APIC"===e.type?Ur(e):function(e){if(!(e.size<2)){if("TXXX"===e.type){var t=1,r=z(e.data.subarray(t),!0);t+=r.length+1;var i=z(e.data.subarray(t));return{key:e.type,info:r,data:i}}var a=z(e.data.subarray(1));return{key:e.type,info:"",data:a}}}(e)}function Vr(e){var t=String.fromCharCode(e[0],e[1],e[2],e[3]),r=kr(e,4);return{type:t,size:r,data:e.subarray(10,10+r)}}var Hr=10,Kr=10;function Wr(e){for(var t=0,r=[];Dr(e,t);){var i=kr(e,t+6);e[t+5]>>6&1&&(t+=Hr);for(var a=(t+=Hr)+i;t+Kr0&&s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:i,type:Xr.audioId3,duration:Number.POSITIVE_INFINITY});at.length)){var n=ai(t,r);if(n&&r+n.frameLength<=t.length){var s=i+a*(9e4*n.samplesPerFrame/n.sampleRate),o={unit:t.subarray(r,r+n.frameLength),pts:s,dts:s};return e.config=[],e.channelCount=n.channelCount,e.samplerate=n.sampleRate,e.samples.push(o),{sample:o,length:n.frameLength,missing:0}}}}function ai(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 s=e[t+2]>>1&1,o=e[t+3]>>6,l=1e3*Jr[14*(3===r?3-i:3===i?3:4)+a-1],u=ei[3*(3===r?0:2===r?1:2)+n],d=3===o?1:2,h=ti[r][i],f=ri[i],c=8*h*f,v=Math.floor(h*l/u+s)*f;if(null===Zr){var g=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Zr=g?parseInt(g[1]):0}return!!Zr&&Zr<=87&&2===i&&l>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:u,channelCount:d,frameLength:v,samplesPerFrame:c}}}function ni(e,t){return 255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}function si(e,t){return t+10;){s[0]=e[t];var o=Math.min(i,8),l=8-o;n[0]=4278190080>>>24+l<>l,r=r?r<>>8^255&m^99,e[c]=m,t[m]=c;var p=f[c],y=f[p],E=f[y],T=257*f[m]^16843008*m;i[c]=T<<24|T>>>8,a[c]=T<<16|T>>>16,n[c]=T<<8|T>>>24,s[c]=T,T=16843009*E^65537*y^257*p^16843008*c,l[m]=T<<24|T>>>8,u[m]=T<<16|T>>>16,d[m]=T<<8|T>>>24,h[m]=T,c?(c=p^f[f[f[E^p]]],v^=f[f[v]]):c=v=1}},t.expandKey=function(e){for(var t=this.uint8ArrayToUint32Array_(e),r=!0,i=0;i8&&109===e[r+4]&&111===e[r+5]&&111===e[r+6]&&102===e[r+7])return!0;r=i>1?r+i:t}return!1}(e)},t.demux=function(e,t){this.timeOffset=t;var r=e,i=this.videoTrack,a=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=be(this.remainderData,e));var n=function(e){var t={valid:null,remainder:null},r=ge(e,["moof"]);if(r.length<2)return t.remainder=e,t;var i=r[r.length-1];return t.valid=e.slice(0,i.byteOffset-8),t.remainder=e.slice(i.byteOffset-8),t}(r);this.remainderData=n.remainder,i.samples=n.valid||new Uint8Array}else i.samples=r;var s=this.extractID3Track(i,t);return a.samples=De(t,i),{videoTrack:i,audioTrack:this.audioTrack,id3Track:s,textTrack:this.txtTrack}},t.flush=function(){var e=this.timeOffset,t=this.videoTrack,r=this.txtTrack;t.samples=this.remainderData||new Uint8Array,this.remainderData=null;var i=this.extractID3Track(t,this.timeOffset);return r.samples=De(e,t),{videoTrack:t,audioTrack:zr(),id3Track:i,textTrack:zr()}},t.extractID3Track=function(e,t){var r=this,i=this.id3Track;if(e.samples.length){var a=ge(e.samples,["emsg"]);a&&a.forEach((function(e){var a=function(e){var t=e[0],r="",i="",a=0,n=0,s=0,o=0,l=0,u=0;if(0===t){for(;"\0"!==ue(e.subarray(u,u+1));)r+=ue(e.subarray(u,u+1)),u+=1;for(r+=ue(e.subarray(u,u+1)),u+=1;"\0"!==ue(e.subarray(u,u+1));)i+=ue(e.subarray(u,u+1)),u+=1;i+=ue(e.subarray(u,u+1)),u+=1,a=he(e,12),n=he(e,16),o=he(e,20),l=he(e,24),u=28}else if(1===t){a=he(e,u+=4);var d=he(e,u+=4),h=he(e,u+=4);for(u+=4,s=Math.pow(2,32)*d+h,R(s)||(s=Number.MAX_SAFE_INTEGER,j.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=he(e,u),l=he(e,u+=4),u+=4;"\0"!==ue(e.subarray(u,u+1));)r+=ue(e.subarray(u,u+1)),u+=1;for(r+=ue(e.subarray(u,u+1)),u+=1;"\0"!==ue(e.subarray(u,u+1));)i+=ue(e.subarray(u,u+1)),u+=1;i+=ue(e.subarray(u,u+1)),u+=1}return{schemeIdUri:r,value:i,timeScale:a,presentationTime:s,presentationTimeDelta:n,eventDuration:o,id:l,payload:e.subarray(u,e.byteLength)}}(e);if(vi.test(a.schemeIdUri)){var n=mi(a,t),s=4294967295===a.eventDuration?Number.POSITIVE_INFINITY:a.eventDuration/a.timeScale;s<=.001&&(s=Number.POSITIVE_INFINITY);var o=a.payload;i.samples.push({data:o,len:o.byteLength,dts:n,pts:n,type:Xr.emsg,duration:s})}else if(r.config.enableEmsgKLVMetadata&&a.schemeIdUri.startsWith("urn:misb:KLV:bin:1910.1")){var l=mi(a,t);i.samples.push({data:a.payload,len:a.payload.byteLength,dts:l,pts:l,type:Xr.misbklv,duration:Number.POSITIVE_INFINITY})}}))}return i},t.demuxSampleAes=function(e,t,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},t.destroy=function(){this.config=null,this.remainderData=null,this.videoTrack=this.audioTrack=this.id3Track=this.txtTrack=void 0},e}();function mi(e,t){return L(e.presentationTime)?e.presentationTime/e.timeScale:t+e.presentationTimeDelta/e.timeScale}var pi=function(){function e(e,t,r){this.keyData=void 0,this.decrypter=void 0,this.keyData=r,this.decrypter=new ci(t,{removePKCS7Padding:!1})}var t=e.prototype;return t.decryptBuffer=function(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer,Ht)},t.decryptAacSample=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),s=n.buffer.slice(n.byteOffset,n.byteOffset+n.length);this.decryptBuffer(s).then((function(n){var s=new Uint8Array(n);a.set(s,16),i.decrypter.isSync()||i.decryptAacSamples(e,t+1,r)}))}},t.decryptAacSamples=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}},t.getAvcEncryptedData=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}}},e}(),yi=function(){function e(){this.VideoSample=null}var t=e.prototype;return t.createVideoSample=function(e,t,r){return{key:e,frame:!1,pts:t,dts:r,units:[],length:0}},t.getLastNalUnit=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},t.pushAccessUnit=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)}},t.parseNALu=function(e,t,r){var i,a,n=t.byteLength,s=e.naluState||0,o=s,l=[],u=0,d=-1,h=0;for(-1===s&&(d=0,h=this.getNALuType(t,0),s=0,u=1);u=0){var f={data:t.subarray(d,a),type:h};l.push(f)}else{var c=this.getLastNalUnit(e.samples);c&&(o&&u<=4-o&&c.state&&(c.data=c.data.subarray(0,c.data.byteLength-o)),a>0&&(c.data=be(c.data,t.subarray(0,a)),c.state=0))}u=0&&s>=0){var v={data:t.subarray(d,n),type:h,state:s};l.push(v)}if(0===l.length){var g=this.getLastNalUnit(e.samples);g&&(g.data=be(g.data,t))}return e.naluState=s,l},e}(),Ei=function(){function e(e){this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=e,this.bytesAvailable=e.byteLength,this.word=0,this.bitsAvailable=0}var t=e.prototype;return t.loadWord=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},t.skipBits=function(e){var t;e=Math.min(e,8*this.bytesAvailable+this.bitsAvailable),this.bitsAvailable>e?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,e-=(t=e>>3)<<3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)},t.readBits=function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;if(e>32&&j.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)>0&&this.bitsAvailable?r<>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()},t.skipUEG=function(){this.skipBits(1+this.skipLZ())},t.skipEG=function(){this.skipBits(1+this.skipLZ())},t.readUEG=function(){var e=this.skipLZ();return this.readBits(e+1)-1},t.readEG=function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)},t.readBoolean=function(){return 1===this.readBits(1)},t.readUByte=function(){return this.readBits(8)},t.readUShort=function(){return this.readBits(16)},t.readUInt=function(){return this.readBits(32)},e}(),Ti=function(e){function t(){return e.apply(this,arguments)||this}o(t,e);var r=t.prototype;return r.parsePES=function(e,t,r,i){var a,n=this,s=this.parseNALu(e,r.data,i),o=this.VideoSample,l=!1;r.data=null,o&&s.length&&!e.audFound&&(this.pushAccessUnit(o,e),o=this.VideoSample=this.createVideoSample(!1,r.pts,r.dts)),s.forEach((function(i){var s,u;switch(i.type){case 1:var d=!1;a=!0;var h,f=i.data;if(l&&f.length>4){var c=n.readSliceType(f);2!==c&&4!==c&&7!==c&&9!==c||(d=!0)}d&&null!=(h=o)&&h.frame&&!o.key&&(n.pushAccessUnit(o,e),o=n.VideoSample=null),o||(o=n.VideoSample=n.createVideoSample(!0,r.pts,r.dts)),o.frame=!0,o.key=d;break;case 5:a=!0,null!=(s=o)&&s.frame&&!o.key&&(n.pushAccessUnit(o,e),o=n.VideoSample=null),o||(o=n.VideoSample=n.createVideoSample(!0,r.pts,r.dts)),o.key=!0,o.frame=!0;break;case 6:a=!0,Ie(i.data,1,r.pts,t.samples);break;case 7:var v,g;a=!0,l=!0;var m=i.data,p=n.readSPS(m);if(!e.sps||e.width!==p.width||e.height!==p.height||(null==(v=e.pixelRatio)?void 0:v[0])!==p.pixelRatio[0]||(null==(g=e.pixelRatio)?void 0:g[1])!==p.pixelRatio[1]){e.width=p.width,e.height=p.height,e.pixelRatio=p.pixelRatio,e.sps=[m];for(var y=m.subarray(1,4),E="avc1.",T=0;T<3;T++){var S=y[T].toString(16);S.length<2&&(S="0"+S),E+=S}e.codec=E}break;case 8:a=!0,e.pps=[i.data];break;case 9:a=!0,e.audFound=!0,null!=(u=o)&&u.frame&&(n.pushAccessUnit(o,e),o=null),o||(o=n.VideoSample=n.createVideoSample(!1,r.pts,r.dts));break;case 12:a=!0;break;default:a=!1}o&&a&&o.units.push(i)})),i&&o&&(this.pushAccessUnit(o,e),this.VideoSample=null)},r.getNALuType=function(e,t){return 31&e[t]},r.readSliceType=function(e){var t=new Ei(e);return t.readUByte(),t.readUEG(),t.readUEG()},r.skipScalingList=function(e,t){for(var r=8,i=8,a=0;a0&&r.warn("MPEG2-TS detected but first sync word found @ offset "+i),-1!==i},e.syncOffset=function(e){for(var t=e.length,r=Math.min(940,t-Si)+1,i=0;i1&&(0===n&&s>2||o+Si>r))return n}i++}return-1},e.createTrack=function(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:le[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===e?t:void 0}};var t=e.prototype;return t.resetInitSegment=function(t,r,i,a){this.pmtParsed=!1,this._pmtId=-1,this._videoTrack=e.createTrack("video"),this._videoTrack.duration=a,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},t.resetTimeStamp=function(){},t.resetContiguity=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},t.demux=function(t,r,i,a){var n;void 0===i&&(i=!1),void 0===a&&(a=!1),i||(this.sampleAes=null);var s=this._videoTrack,o=this._audioTrack,l=this._id3Track,u=this._txtTrack,d=s.pid,h=s.pesData,f=o.pid,c=l.pid,v=o.pesData,g=l.pesData,m=null,p=this.pmtParsed,y=this._pmtId,E=t.length;if(this.remainderData&&(E=(t=be(this.remainderData,t)).length,this.remainderData=null),E>4>1){if((b=L+5+t[L+4])===L+Si)continue}else b=L+4;switch(A){case d:R&&(h&&(n=_i(h,this.logger))&&(null===this.videoParser&&"avc"===s.segmentCodec&&(this.videoParser=new Ti),null!==this.videoParser&&this.videoParser.parsePES(s,u,n,!1)),h={data:[],size:0}),h&&(h.data.push(t.subarray(b,L+Si)),h.size+=L+Si-b);break;case f:if(R){if(v&&(n=_i(v,this.logger)))switch(o.segmentCodec){case"aac":this.parseAACPES(o,n);break;case"mp3":this.parseMPEGPES(o,n)}v={data:[],size:0}}v&&(v.data.push(t.subarray(b,L+Si)),v.size+=L+Si-b);break;case c:R&&(g&&(n=_i(g,this.logger))&&this.parseID3PES(l,n),g={data:[],size:0}),g&&(g.data.push(t.subarray(b,L+Si)),g.size+=L+Si-b);break;case 0:R&&(b+=t[b]+1),y=this._pmtId=Ai(t,b);break;case y:R&&(b+=t[b]+1);var D=bi(t,b,this.typeSupported,i,this.observer,this.logger);(d=D.videoPid)>0&&(s.pid=d,s.segmentCodec=D.segmentVideoCodec),(f=D.audioPid)>0&&(o.pid=f,o.segmentCodec=D.segmentAudioCodec),(c=D.id3Pid)>0&&(l.pid=c),null===m||p||(this.logger.warn("MPEG-TS PMT found at "+L+" after unknown PID '"+m+"'. Backtracking to sync byte @"+T+" to parse all TS packets."),m=null,L=T-188),p=this.pmtParsed=!0;break;case 17:case 8191:break;default:m=A}}else S++;S>0&&Di(this.observer,new Error("Found "+S+" TS packet/s that do not start with 0x47"),void 0,this.logger),s.pesData=h,o.pesData=v,l.pesData=g;var k={audioTrack:o,videoTrack:s,id3Track:l,textTrack:u};return a&&this.extractRemainingSamples(k),k},t.flush=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},t.extractRemainingSamples=function(e){var t,r=e.audioTrack,i=e.videoTrack,a=e.id3Track,n=e.textTrack,s=i.pesData,o=r.pesData,l=a.pesData;if(s&&(t=_i(s,this.logger))?(null===this.videoParser&&"avc"===i.segmentCodec&&(this.videoParser=new Ti),null!==this.videoParser&&(this.videoParser.parsePES(i,n,t,!0),i.pesData=null)):i.pesData=s,o&&(t=_i(o,this.logger))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,t);break;case"mp3":this.parseMPEGPES(r,t)}r.pesData=null}else null!=o&&o.size&&this.logger.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;l&&(t=_i(l,this.logger))?(this.parseID3PES(a,t),a.pesData=null):a.pesData=l},t.demuxSampleAes=function(e,t,r){var i=this.demux(e,r,!0,!this.config.progressive),a=this.sampleAes=new pi(this.observer,this.config,t);return this.decrypt(i,a)},t.decrypt=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)}))}))},t.destroy=function(){this.observer&&this.observer.removeAllListeners(),this.config=this.logger=this.observer=null,this.aacOverFlow=this.videoParser=this.remainderData=this.sampleAes=null,this._videoTrack=this._audioTrack=this._id3Track=this._txtTrack=void 0},t.parseAACPES=function(e,t){var r,i,a,n=0,s=this.aacOverFlow,o=t.data;if(s){this.aacOverFlow=null;var l=s.missing,u=s.sample.unit.byteLength;if(-1===l)o=be(s.sample.unit,o);else{var d=u-l;s.sample.unit.set(o.subarray(0,l),d),e.samples.push(s.sample),n=s.missing}}for(r=n,i=o.length;r0)for(var d=t+5,h=u;h>2;){106===e[d]&&n.warn("AC-3 in M2TS support not included in build");var f=e[d+1]+2;d+=f,h-=f}break;case 194:case 135:return Di(a,new Error("Unsupported EC-3 in M2TS found"),void 0,n),s;case 36:return Di(a,new Error("Unsupported HEVC in M2TS found"),void 0,n),s}t+=u+5}return s}function Di(e,t,r,i){i.warn("parsing error: "+t.message),e.emit(k.ERROR,k.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!1,levelRetry:r,error:t,reason:t.message})}function ki(e,t){t.log(e+" with AES-128-CBC encryption found in unencrypted stream")}function _i(e,t){var r,i,a,n,s,o=0,l=e.data;if(!e||0===e.size)return null;for(;l[0].length<19&&l.length>1;)l[0]=be(l[0],l[1]),l.splice(1,1);if(1===((r=l[0])[0]<<16)+(r[1]<<8)+r[2]){if((i=(r[4]<<8)+r[5])&&i>e.size-6)return null;var u=r[7];192&u&&(n=536870912*(14&r[9])+4194304*(255&r[10])+16384*(254&r[11])+128*(255&r[12])+(254&r[13])/2,64&u?n-(s=536870912*(14&r[14])+4194304*(255&r[15])+16384*(254&r[16])+128*(255&r[17])+(254&r[18])/2)>54e5&&(t.warn(Math.round((n-s)/9e4)+"s delta between PTS and DTS, align them"),n=s):s=n);var d=(a=r[8])+9;if(e.size<=d)return null;e.size-=d;for(var h=new Uint8Array(e.size),f=0,c=l.length;fv){d-=v;continue}r=r.subarray(d),v-=d,d=0}h.set(r,o),o+=v}return i&&(i-=a+3),{data:h,pts:n,dts:s,len:i}}return null}var Ii=function(){function e(){}return e.getSilentFrame=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])}},e}(),Ci=Math.pow(2,32)-1,xi=function(){function e(){}return e.init=function(){var t;for(t in e.types={avc1:[],avcC:[],hvc1:[],hvcC:[],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 s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,s,l,s,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,a))},e.box=function(e){for(var t=8,r=arguments.length,i=new Array(r>1?r-1:0),a=1;a>24&255,o[1]=t>>16&255,o[2]=t>>8&255,o[3]=255&t,o.set(e,4),n=0,t=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]))},e.mdia=function(t){return e.box(e.types.mdia,e.mdhd(t.timescale||0,t.duration||0),e.hdlr(t.type),e.minf(t))},e.mfhd=function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))},e.minf=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))},e.moof=function(t,r,i){return e.box(e.types.moof,e.mfhd(t),e.traf(i,r))},e.moov=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||0,t[0].duration||0)].concat(i).concat(e.mvex(t)))},e.mvex=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))},e.mvhd=function(t,r){r*=t;var i=Math.floor(r/(Ci+1)),a=Math.floor(r%(Ci+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)},e.sdtp=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),s.push(255&a),s=s.concat(Array.prototype.slice.call(i));var o=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(s))),l=t.width,u=t.height,d=t.pixelRatio[0],h=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,u>>8&255,255&u,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]),o,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([d>>24,d>>16&255,d>>8&255,255&d,h>>24,h>>16&255,h>>8&255,255&h])))},e.esds=function(e){var t=e.config;return new Uint8Array([0,0,0,0,3,25,0,1,0,4,17,64,21,0,0,0,0,0,0,0,0,0,0,0,5,2].concat(t,[6,1,2]))},e.audioStsd=function(e){var t=e.samplerate||0;return new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount||0,0,16,0,0,0,0,t>>8&255,255&t,0,0])},e.mp4a=function(t){return e.box(e.types.mp4a,e.audioStsd(t),e.box(e.types.esds,e.esds(t)))},e.mp3=function(t){return e.box(e.types[".mp3"],e.audioStsd(t))},e.ac3=function(t){return e.box(e.types["ac-3"],e.audioStsd(t),e.box(e.types.dac3,t.config))},e.stsd=function(t){var r=t.segmentCodec;if("audio"===t.type){if("aac"===r)return e.box(e.types.stsd,e.STSD,e.mp4a(t));if("mp3"===r&&"mp3"===t.codec)return e.box(e.types.stsd,e.STSD,e.mp3(t))}else{if(!t.pps||!t.sps)throw new Error("video track missing pps or sps");if("avc"===r)return e.box(e.types.stsd,e.STSD,e.avc1(t))}throw new Error("unsupported "+t.type+" segment codec ("+r+"/"+t.codec+")")},e.tkhd=function(t){var r=t.id,i=(t.duration||0)*(t.timescale||0),a=t.width||0,n=t.height||0,s=Math.floor(i/(Ci+1)),o=Math.floor(i%(Ci+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,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o,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]))},e.traf=function(t,r){var i=e.sdtp(t),a=t.id,n=Math.floor(r/(Ci+1)),s=Math.floor(r%(Ci+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,s>>24,s>>16&255,s>>8&255,255&s])),e.trun(t,i.length+16+20+8+16+8+8),i)},e.trak=function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))},e.trex=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]))},e.trun=function(t,r){var i,a,n,s,o,l,u=t.samples||[],d=u.length,h=12+16*d,f=new Uint8Array(h);for(r+=8+h,f.set(["video"===t.type?1:0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,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,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return e.box(e.types.trun,f)},e.initSegment=function(t){e.types||e.init();var r=e.moov(t);return be(e.FTYP,r)},e.hvc1=function(e){return new Uint8Array},e}();function Pi(e,t){return function(e,t,r,i){var a=e*t*r;return Math.round(a)}(e,1e3,1/9e4)}xi.types=void 0,xi.HDLR_TYPES=void 0,xi.STTS=void 0,xi.STSC=void 0,xi.STCO=void 0,xi.STSZ=void 0,xi.VMHD=void 0,xi.SMHD=void 0,xi.STSD=void 0,xi.FTYP=void 0,xi.DINF=void 0;var wi=null,Oi=null;function Mi(e,t,r,i){return{duration:t,size:r,cts:i,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:e?2:1,isNonSync:e?0:1}}}var Fi=function(){function e(e,t,r,i){if(this.logger=void 0,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=e,this.config=t,this.typeSupported=r,this.logger=i,this.ISGenerated=!1,null===wi){var a=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);wi=a?parseInt(a[1]):0}if(null===Oi){var n=navigator.userAgent.match(/Safari\/(\d+)/i);Oi=n?parseInt(n[1]):0}}var t=e.prototype;return t.destroy=function(){this.config=this.videoTrackConfig=this._initPTS=this._initDTS=null},t.resetTimeStamp=function(e){this.logger.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=e},t.resetNextTimestamp=function(){this.logger.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},t.resetInitSegment=function(){this.logger.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1,this.videoTrackConfig=void 0},t.getVideoStartPts=function(e){var t=!1,r=e[0].pts,i=e.reduce((function(e,i){var a=i.pts,n=a-e;return n<-4294967296&&(t=!0,n=(a=Ni(a,r))-e),n>0?e:a}),r);return t&&this.logger.debug("PTS rollover detected"),i},t.remux=function(e,t,r,i,a,n,s,o){var l,u,d,h,f,c,v=a,g=a,m=e.pid>-1,p=t.pid>-1,y=t.samples.length,E=e.samples.length>0,T=s&&y>0||y>1;if((!m||E)&&(!p||T)||this.ISGenerated||s){if(this.ISGenerated){var S,L,R,A,b=this.videoTrackConfig;(b&&(t.width!==b.width||t.height!==b.height||(null==(S=t.pixelRatio)?void 0:S[0])!==(null==(L=b.pixelRatio)?void 0:L[0])||(null==(R=t.pixelRatio)?void 0:R[1])!==(null==(A=b.pixelRatio)?void 0:A[1]))||!b&&T||null===this.nextAudioPts&&E)&&this.resetInitSegment()}this.ISGenerated||(d=this.generateIS(e,t,a,n));var D,k=this.isVideoContiguous,_=-1;if(T&&(_=function(e){for(var t=0;t0){this.logger.warn("[mp4-remuxer]: Dropped "+_+" out of "+y+" video samples due to a missing keyframe");var I=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(_),t.dropped+=_,D=g+=(t.samples[0].pts-I)/t.inputTimeScale}else-1===_&&(this.logger.warn("[mp4-remuxer]: No keyframe found out of "+y+" video samples"),c=!1);if(this.ISGenerated){if(E&&T){var C=this.getVideoStartPts(t.samples),x=(Ni(e.samples[0].pts,C)-C)/t.inputTimeScale;v+=Math.max(0,x),g+=Math.max(0,-x)}if(E){if(e.samplerate||(this.logger.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),d=this.generateIS(e,t,a,n)),u=this.remuxAudio(e,v,this.isAudioContiguous,n,p||T||o===w?g:void 0),T){var P=u?u.endPTS-u.startPTS:0;t.inputTimeScale||(this.logger.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),d=this.generateIS(e,t,a,n)),l=this.remuxVideo(t,g,k,P)}}else T&&(l=this.remuxVideo(t,g,k,0));l&&(l.firstKeyFrame=_,l.independent=-1!==_,l.firstKeyFramePTS=D)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(r.samples.length&&(f=Bi(r,a,this._initPTS,this._initDTS)),i.samples.length&&(h=Ui(i,a,this._initPTS))),{audio:u,video:l,initSegment:d,independent:c,text:h,id3:f}},t.generateIS=function(e,t,r,i){var a,n,s,o=e.samples,l=t.samples,u=this.typeSupported,d={},h=this._initPTS,f=!h||i,c="audio/mp4";if(f&&(a=n=1/0),e.config&&o.length){switch(e.timescale=e.samplerate,e.segmentCodec){case"mp3":u.mpeg?(c="audio/mpeg",e.codec=""):u.mp3&&(e.codec="mp3");break;case"ac3":e.codec="ac-3"}d.audio={id:"audio",container:c,codec:e.codec,initSegment:"mp3"===e.segmentCodec&&u.mpeg?new Uint8Array(0):xi.initSegment([e]),metadata:{channelCount:e.channelCount}},f&&(s=e.inputTimeScale,h&&s===h.timescale?f=!1:a=n=o[0].pts-Math.round(s*r))}if(t.sps&&t.pps&&l.length){if(t.timescale=t.inputTimeScale,d.video={id:"main",container:"video/mp4",codec:t.codec,initSegment:xi.initSegment([t]),metadata:{width:t.width,height:t.height}},f)if(s=t.inputTimeScale,h&&s===h.timescale)f=!1;else{var v=this.getVideoStartPts(l),g=Math.round(s*r);n=Math.min(n,Ni(l[0].dts,v)-g),a=Math.min(a,v-g)}this.videoTrackConfig={width:t.width,height:t.height,pixelRatio:t.pixelRatio}}if(Object.keys(d).length)return this.ISGenerated=!0,f?(this._initPTS={baseTime:a,timescale:s},this._initDTS={baseTime:n,timescale:s}):a=s=void 0,{tracks:d,initPTS:a,timescale:s}},t.remuxVideo=function(e,t,r,i){var a,s,o=e.inputTimeScale,l=e.samples,u=[],d=l.length,h=this._initPTS,f=this.nextAvcDts,c=8,v=this.videoSampleDuration,g=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,p=!1;if(!r||null===f){var y=t*o,E=l[0].pts-Ni(l[0].dts,l[0].pts);wi&&null!==f&&Math.abs(y-E-f)<15e3?r=!0:f=y-E}for(var T=h.baseTime*o/h.timescale,S=0;S0?S-1:S].dts&&(p=!0)}p&&l.sort((function(e,t){var r=e.dts-t.dts,i=e.pts-t.pts;return r||i})),a=l[0].dts;var R=(s=l[l.length-1].dts)-a,A=R?Math.round(R/(d-1)):v||e.inputTimeScale/30;if(r){var _=a-f,I=_>A,C=_<-1;if((I||C)&&(I?this.logger.warn((e.segmentCodec||"").toUpperCase()+": "+Pi(_)+" ms ("+_+"dts) hole between fragments detected at "+t.toFixed(3)):this.logger.warn((e.segmentCodec||"").toUpperCase()+": "+Pi(-_)+" ms ("+_+"dts) overlapping between fragments detected at "+t.toFixed(3)),!C||f>=l[0].pts||wi)){a=f;var x=l[0].pts-_;if(I)l[0].dts=a,l[0].pts=x;else for(var P=!0,w=0;wx&&P);w++){var O=l[w].pts;if(l[w].dts-=_,l[w].pts-=_,w0?ee.dts-l[J-1].dts:A;if(le=J>0?ee.pts-l[J-1].pts:A,ue.stretchShortVideoTrack&&null!==this.nextAudioPts){var he=Math.floor(ue.maxBufferHole*o),fe=(i?g+i*o:this.nextAudioPts)-ee.pts;fe>he?((v=fe-de)<0?v=de:X=!0,this.logger.log("[mp4-remuxer]: It is approximately "+fe/90+" ms to the next segment; using duration "+v/90+" ms for the last video frame.")):v=de}else v=de}var ce=Math.round(ee.pts-ee.dts);z=Math.min(z,v),$=Math.max($,v),Q=Math.min(Q,le),Z=Math.max(Z,le),u.push(Mi(ee.key,v,re,ce))}if(u.length)if(wi){if(wi<70){var ve=u[0].flags;ve.dependsOn=2,ve.isNonSync=0}}else if(Oi&&Z-Q<$-z&&A/$<.025&&0===u[0].cts){this.logger.warn("Found irregular gaps in sample duration. Using PTS instead of DTS to determine MP4 sample duration.");for(var ge=a,me=0,pe=u.length;me0&&(i&&Math.abs(p-m)<9e3||Math.abs(Ni(v[0].pts-y,p)-m)<20*u),v.forEach((function(e){e.pts=Ni(e.pts-y,p)})),!r||m<0){if(v=v.filter((function(e){return e.pts>=0})),!v.length)return;m=0===a?0:i&&!c?Math.max(0,p):v[0].pts}if("aac"===e.segmentCodec)for(var E=this.config.maxAudioFramesDrift,T=0,S=m;T=E*u&&_<1e4&&c){var I=Math.round(A/u);(S=R-I*u)<0&&(I--,S+=u),0===T&&(this.nextAudioPts=m=S),this.logger.warn("[mp4-remuxer]: Injecting "+I+" audio frame @ "+(S/s).toFixed(3)+"s due to "+Math.round(1e3*A/s)+" ms gap.");for(var C=0;C0))return;F+=g;try{w=new Uint8Array(F)}catch(e){return void this.observer.emit(k.ERROR,k.ERROR,{type:b.MUX_ERROR,details:D.REMUX_ALLOC_ERROR,fatal:!1,error:e,bytes:F,reason:"fail allocating audio mdat "+F})}h||(new DataView(w.buffer).setUint32(0,F),w.set(xi.types.mdat,4))}w.set(V,g);var K=V.byteLength;g+=K,f.push(Mi(!0,l,K,0)),M=H}var W=f.length;if(W){var Y=f[f.length-1];this.nextAudioPts=m=M+o*Y.duration;var j=h?new Uint8Array(0):xi.moof(e.sequenceNumber++,O/o,n({},e,{samples:f}));e.samples=[];var q=O/s,X=m/s,z={data1:j,data2:w,startPTS:q,endPTS:X,startDTS:q,endDTS:X,type:"audio",hasAudio:!0,hasVideo:!1,nb:W};return this.isAudioContiguous=!0,z}},e}();function Ni(e,t){var r;if(null===t)return e;for(r=t4294967296;)e+=r;return e}function Bi(e,t,r,i){var a=e.samples.length;if(a){for(var n=e.inputTimeScale,s=0;sa}(l,m,a,v)&&f.timescale===l.timescale||(f.initPTS=m-a,l&&1===l.timescale&&this.logger.warn("Adjusting initPTS @"+a+" from "+l.baseTime/l.timescale+" to "+f.initPTS),this.initPTS=l={baseTime:f.initPTS,timescale:1});var p=e?m-l.baseTime/l.timescale:u,y=p+v;!function(e,t,r){ge(t,["moof","traf"]).forEach((function(t){ge(t,["tfhd"]).forEach((function(i){var a=he(i,4),n=e[a];if(n){var s=n.timescale||9e4;ge(t,["tfdt"]).forEach((function(e){var t=e[0],i=r*s;if(i){var a=he(e,4);if(0===t)a-=i,ve(e,4,a=Math.max(a,0));else{a*=Math.pow(2,32),a+=he(e,8),a-=i,a=Math.max(a,0);var n=Math.floor(a/(se+1)),o=Math.floor(a%(se+1));ve(e,4,n),ve(e,8,o)}}}))}}))}))}(c,h,l.baseTime/l.timescale),v>0?this.lastEndTime=y:(this.logger.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var E=!!c.audio,T=!!c.video,S="";E&&(S+="audio"),T&&(S+="video");var R={data1:h,startPTS:p,startDTS:p,endPTS:y,endDTS:y,type:S,hasAudio:E,hasVideo:T,nb:1,dropped:0};return d.audio="audio"===R.type?R:void 0,d.video="audio"!==R.type?R:void 0,d.initSegment=f,d.id3=Bi(r,a,l,l),i.samples.length&&(d.text=Ui(i,a,l)),d},e}();function Hi(e,t){var r=null==e?void 0:e.codec;return r&&r.length>4?r:t===Z?"ec-3"===r||"ac-3"===r||"alac"===r?r:"fLaC"===r||"Opus"===r?He(r,!1):(j.warn('Unhandled audio codec "'+r+'" in mp4 MAP'),r||"mp4a"):(j.warn('Unhandled video codec "'+r+'" in mp4 MAP'),r||"avc1")}try{Gi=self.performance.now.bind(self.performance)}catch(e){Gi=Date.now}var Ki=[{demux:gi,remux:Vi},{demux:Li,remux:Fi},{demux:li,remux:Fi},{demux:ui,remux:Fi}],Wi=function(){function e(e,t,r,i,a,n){this.asyncResult=!1,this.logger=void 0,this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.observer=e,this.typeSupported=t,this.config=r,this.id=a,this.logger=n}var t=e.prototype;return t.configure=function(e){this.transmuxConfig=e,this.decrypter&&this.decrypter.reset()},t.push=function(e,t,r,i){var a=this,n=r.transmuxing;n.executeStart=Gi();var s=new Uint8Array(e),o=this.currentTransmuxState,l=this.transmuxConfig;i&&(this.currentTransmuxState=i);var u=i||o,d=u.contiguous,h=u.discontinuity,f=u.trackSwitch,c=u.accurateTimeOffset,v=u.timeOffset,g=u.initSegmentChange,m=l.audioCodec,p=l.videoCodec,y=l.defaultInitPts,E=l.duration,T=l.initSegmentData,S=function(e,t){var r=null;return e.byteLength>0&&null!=(null==t?void 0:t.key)&&null!==t.iv&&null!=t.method&&(r=t),r}(s,t);if(S&&Wt(S.method)){var L=this.getDecrypter(),R=Yt(S.method);if(!L.isSync())return this.asyncResult=!0,this.decryptionPromise=L.webCryptoDecrypt(s,S.key.buffer,S.iv.buffer,R).then((function(e){var t=a.push(e,null,r);return a.decryptionPromise=null,t})),this.decryptionPromise;var A=L.softwareDecrypt(s,S.key.buffer,S.iv.buffer,R);if(r.part>-1){var _=L.flush();A=_?_.buffer:_}if(!A)return n.executeEnd=Gi(),Yi(r);s=new Uint8Array(A)}var I=this.needsProbing(h,f);if(I){var C=this.configureTransmuxer(s);if(C)return this.logger.warn("[transmuxer] "+C.message),this.observer.emit(k.ERROR,k.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!1,error:C,reason:C.message}),n.executeEnd=Gi(),Yi(r)}(h||f||g||I)&&this.resetInitSegment(T,m,p,E,t),(h||g||I)&&this.resetInitialTimestamp(y),d||this.resetContiguity();var x=this.transmux(s,S,v,c,r);this.asyncResult=ji(x);var P=this.currentTransmuxState;return P.contiguous=!0,P.discontinuity=!1,P.trackSwitch=!1,n.executeEnd=Gi(),x},t.flush=function(e){var t=this,r=e.transmuxing;r.executeStart=Gi();var i=this.decrypter,a=this.currentTransmuxState,n=this.decryptionPromise;if(n)return this.asyncResult=!0,n.then((function(){return t.flush(e)}));var s=[],o=a.timeOffset;if(i){var l=i.flush();l&&s.push(this.push(l.buffer,null,e))}var u=this.demuxer,d=this.remuxer;if(!u||!d){r.executeEnd=Gi();var h=[Yi(e)];return this.asyncResult?Promise.resolve(h):h}var f=u.flush(o);return ji(f)?(this.asyncResult=!0,f.then((function(r){return t.flushRemux(s,r,e),s}))):(this.flushRemux(s,f,e),this.asyncResult?Promise.resolve(s):s)},t.flushRemux=function(e,t,r){var i=t.audioTrack,a=t.videoTrack,n=t.id3Track,s=t.textTrack,o=this.currentTransmuxState,l=o.accurateTimeOffset,u=o.timeOffset;this.logger.log("[transmuxer.ts]: Flushed "+this.id+" sn: "+r.sn+(r.part>-1?" part: "+r.part:"")+" of "+(this.id===P?"level":"track")+" "+r.level);var d=this.remuxer.remux(i,a,n,s,u,l,!0,this.id);e.push({remuxResult:d,chunkMeta:r}),r.transmuxing.executeEnd=Gi()},t.resetInitialTimestamp=function(e){var t=this.demuxer,r=this.remuxer;t&&r&&(t.resetTimeStamp(e),r.resetTimeStamp(e))},t.resetContiguity=function(){var e=this.demuxer,t=this.remuxer;e&&t&&(e.resetContiguity(),t.resetNextTimestamp())},t.resetInitSegment=function(e,t,r,i,a){var n=this.demuxer,s=this.remuxer;n&&s&&(n.resetInitSegment(e,t,r,i),s.resetInitSegment(e,t,r,a))},t.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},t.transmux=function(e,t,r,i,a){return t&&"SAMPLE-AES"===t.method?this.transmuxSampleAes(e,t,r,i,a):this.transmuxUnencrypted(e,r,i,a)},t.transmuxUnencrypted=function(e,t,r,i){var a=this.demuxer.demux(e,t,!1,!this.config.progressive),n=a.audioTrack,s=a.videoTrack,o=a.id3Track,l=a.textTrack;return{remuxResult:this.remuxer.remux(n,s,o,l,t,r,!1,this.id),chunkMeta:i}},t.transmuxSampleAes=function(e,t,r,i,a){var n=this;return this.demuxer.demuxSampleAes(e,t,r).then((function(e){return{remuxResult:n.remuxer.remux(e.audioTrack,e.videoTrack,e.id3Track,e.textTrack,r,i,!1,n.id),chunkMeta:a}}))},t.configureTransmuxer=function(e){for(var t,r=this.config,i=this.observer,a=this.typeSupported,n=0,s=Ki.length;n=i&&a(t,r,n.flush().buffer,e)):a(t,r,l.buffer,e),o()})).catch((function(){return Promise.reject()}))};return o()},e}();function $i(e,t){return new self.Request(e.url,t)}var Zi=function(e){function t(t,r,i){var a;return(a=e.call(this,t)||this).code=void 0,a.details=void 0,a.code=r,a.details=i,a}return o(t,e),t}(c(Error)),Ji=/^age:\s*[\d.]+\s*$/im,ea=function(){function e(e){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=null,this.loader=null,this.stats=void 0,this.xhrSetup=e&&e.xhrSetup||null,this.stats=new $,this.retryDelay=0}var t=e.prototype;return t.destroy=function(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null,this.context=null,this.xhrSetup=null},t.abortInternal=function(){var e=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),e&&(e.onreadystatechange=null,e.onprogress=null,4!==e.readyState&&(this.stats.aborted=!0,e.abort()))},t.abort=function(){var e;this.abortInternal(),null!=(e=this.callbacks)&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)},t.load=function(e,t,r){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=e,this.config=t,this.callbacks=r,this.loadInternal()},t.loadInternal=function(){var e=this,t=this.config,r=this.context;if(t&&r){var i=this.loader=new self.XMLHttpRequest,a=this.stats;a.loading.first=0,a.loaded=0,a.aborted=!1;var n=this.xhrSetup;n?Promise.resolve().then((function(){if(e.loader===i&&!e.stats.aborted)return n(i,r.url)})).catch((function(t){if(e.loader===i&&!e.stats.aborted)return i.open("GET",r.url,!0),n(i,r.url)})).then((function(){e.loader!==i||e.stats.aborted||e.openAndSendXhr(i,r,t)})).catch((function(t){var n;null==(n=e.callbacks)||n.onError({code:i.status,text:t.message},r,i,a)})):this.openAndSendXhr(i,r,t)}},t.openAndSendXhr=function(e,t,r){e.readyState||e.open("GET",t.url,!0);var i=t.headers,a=r.loadPolicy,n=a.maxTimeToFirstByteMs,s=a.maxLoadTimeMs;if(i)for(var o in i)e.setRequestHeader(o,i[o]);t.rangeEnd&&e.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),e.onreadystatechange=this.readystatechange.bind(this),e.onprogress=this.loadprogress.bind(this),e.responseType=t.responseType,self.clearTimeout(this.requestTimeout),r.timeout=n&&L(n)?n:s,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),r.timeout),e.send()},t.readystatechange=function(){var e=this.context,t=this.loader,r=this.stats;if(e&&t){var i=t.readyState,a=this.config;if(!r.aborted&&i>=2&&(0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start),a.timeout!==a.loadPolicy.maxLoadTimeMs&&(self.clearTimeout(this.requestTimeout),a.timeout=a.loadPolicy.maxLoadTimeMs,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),a.loadPolicy.maxLoadTimeMs-(r.loading.first-r.loading.start)))),4===i)){self.clearTimeout(this.requestTimeout),t.onreadystatechange=null,t.onprogress=null;var n=t.status,s="text"===t.responseType?t.responseText:null;if(n>=200&&n<300){var o=null!=s?s:t.response;if(null!=o){var l,u;r.loading.end=Math.max(self.performance.now(),r.loading.first);var d="arraybuffer"===t.responseType?o.byteLength:o.length;r.loaded=r.total=d,r.bwEstimate=8e3*r.total/(r.loading.end-r.loading.first);var h=null==(l=this.callbacks)?void 0:l.onProgress;h&&h(r,e,o,t);var f={url:t.responseURL,data:o,code:n};return void(null==(u=this.callbacks)||u.onSuccess(f,r,e,t))}}var c,v=a.loadPolicy.errorRetry;pt(v,r.retry,!1,{url:e.url,data:void 0,code:n})?this.retry(v):(j.error(n+" while loading "+e.url),null==(c=this.callbacks)||c.onError({code:n,text:t.statusText},e,t,r))}}},t.loadtimeout=function(){if(this.config){var e=this.config.loadPolicy.timeoutRetry;if(pt(e,this.stats.retry,!0))this.retry(e);else{var t;j.warn("timeout while loading "+(null==(t=this.context)?void 0:t.url));var r=this.callbacks;r&&(this.abortInternal(),r.onTimeout(this.stats,this.context,this.loader))}}},t.retry=function(e){var t=this.context,r=this.stats;this.retryDelay=gt(e,r.retry),r.retry++,j.warn((status?"HTTP Status "+status:"Timeout")+" while loading "+(null==t?void 0:t.url)+", retrying "+r.retry+"/"+e.maxNumRetry+" in "+this.retryDelay+"ms"),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay)},t.loadprogress=function(e){var t=this.stats;t.loaded=e.loaded,e.lengthComputable&&(t.total=e.total)},t.getCacheAge=function(){var e=null;if(this.loader&&Ji.test(this.loader.getAllResponseHeaders())){var t=this.loader.getResponseHeader("age");e=t?parseFloat(t):null}return e},t.getResponseHeader=function(e){return this.loader&&new RegExp("^"+e+":\\s*[\\d.]+\\s*$","im").test(this.loader.getAllResponseHeaders())?this.loader.getResponseHeader(e):null},e}(),ta={maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:null,errorRetry:null},ra=d(d({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,maxDevicePixelRatio:Number.POSITIVE_INFINITY,preferManagedMediaSource:!0,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,frontBufferFlushThreshold:1/0,maxBufferSize:6e7,maxFragLookUpTolerance:.25,maxBufferHole:.1,detectStallWithCurrentTimeMs:1250,highBufferWatchdogPeriod:2,nudgeOffset:.1,nudgeMaxRetry:3,nudgeOnVideoHole:!0,liveSyncDurationCount:3,liveSyncOnStallIncrease:1,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxLiveSyncPlaybackRate:1,liveDurationInfinity:!1,liveBackBufferLength:null,maxMaxBufferLength:600,enableWorker:!0,workerPath:null,enableSoftwareAES:!0,startLevel:void 0,startFragPrefetch:!1,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:3,ignorePlaylistParsingErrors:!1,loader:ea,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:ot,bufferController:Pt,capLevelController:Mt,errorController:bt,fpsController:Rr,stretchShortVideoTrack:!1,maxAudioFramesDrift:1,forceKeyFrameOnDiscontinuity:!0,abrEwmaFastLive:3,abrEwmaSlowLive:9,abrEwmaFastVoD:3,abrEwmaSlowVoD:9,abrEwmaDefaultEstimate:5e5,abrEwmaDefaultEstimateMax:5e6,abrBandWidthFactor:.95,abrBandWidthUpFactor:.7,abrMaxWithRealBitrate:!1,maxStarvationDelay:4,maxLoadingDelay:4,minAutoBitrate:0,emeEnabled:!1,widevineLicenseUrl:void 0,drmSystems:{},drmSystemOptions:{},requestMediaKeySystemAccessFunc:null,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableEmsgKLVMetadata:!1,enableID3MetadataCues:!0,enableInterstitialPlayback:!1,interstitialAppendInPlace:!0,interstitialLiveLookAhead:10,useMediaCapabilities:!1,certLoadPolicy:{default:ta},keyLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"},errorRetry:{maxNumRetry:8,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"}}},manifestLoadPolicy:{default:{maxTimeToFirstByteMs:1/0,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},playlistLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:2,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},fragLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:12e4,timeoutRetry:{maxNumRetry:4,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:6,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},steeringManifestLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},interstitialAssetListLoadPolicy:{default:ta},manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,manifestLoadingMaxRetryTimeout:64e3,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,levelLoadingMaxRetryTimeout:64e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3},{cueHandler:X,enableWebVTT:!1,enableIMSC1:!1,enableCEA708Captions:!1,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}),{},{subtitleStreamController:void 0,subtitleTrackController:void 0,timelineController:void 0,audioStreamController:void 0,audioTrackController:void 0,emeController:void 0,cmcdController:void 0,contentSteeringController:Tr,interstitialsController:void 0});function ia(e){return e&&"object"==typeof e?Array.isArray(e)?e.map(ia):Object.keys(e).reduce((function(t,r){return t[r]=ia(e[r]),t}),{}):e}function aa(e,t){var r=e.loader;r!==Qi&&r!==ea?(t.log("[config]: Custom loader detected, cannot enable progressive streaming"),e.progressive=!1):function(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch(e){}return!1}()&&(e.loader=Qi,e.progressive=!0,e.enableSoftwareAES=!0,t.log("[config]: Progressive streaming enabled, using FetchLoader"))}var na="NOT_LOADED",sa="APPENDING",oa="PARTIAL",la="OK",ua=function(){function e(e){this.activePartLists=Object.create(null),this.endListFragments=Object.create(null),this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hasGaps=!1,this.hls=e,this._registerListeners()}var t=e.prototype;return t._registerListeners=function(){var e=this.hls;e.on(k.MANIFEST_LOADING,this.onManifestLoading,this),e.on(k.BUFFER_APPENDED,this.onBufferAppended,this),e.on(k.FRAG_BUFFERED,this.onFragBuffered,this),e.on(k.FRAG_LOADED,this.onFragLoaded,this)},t._unregisterListeners=function(){var e=this.hls;e.off(k.MANIFEST_LOADING,this.onManifestLoading,this),e.off(k.BUFFER_APPENDED,this.onBufferAppended,this),e.off(k.FRAG_BUFFERED,this.onFragBuffered,this),e.off(k.FRAG_LOADED,this.onFragLoaded,this)},t.destroy=function(){this._unregisterListeners(),this.fragments=this.activePartLists=this.endListFragments=this.timeRanges=null},t.getAppendedFrag=function(e,t){var r=this.activePartLists[t];if(r)for(var i=r.length;i--;){var a=r[i];if(!a)break;var n=a.end;if(a.start<=e&&null!==n&&e<=n)return a}return this.getBufferedFrag(e,t)},t.getBufferedFrag=function(e,t){return this.getFragAtPos(e,t,!0)},t.getFragAtPos=function(e,t,r){for(var i=this.fragments,a=Object.keys(i),n=a.length;n--;){var s=i[a[n]];if((null==s?void 0:s.body.type)===t&&(!r||s.buffered)){var o=s.body;if(o.start<=e&&e<=o.end)return o}}return null},t.detectEvictedFragments=function(e,t,r,i,a){var n=this;this.timeRanges&&(this.timeRanges[e]=t);var s=(null==i?void 0:i.fragment.sn)||-1;Object.keys(this.fragments).forEach((function(i){var o=n.fragments[i];if(o&&!(s>=o.body.sn))if(o.buffered||o.loaded&&!a){var l=o.range[e];l&&(0!==l.time.length?l.time.some((function(e){var r=!n.isTimeBuffered(e.startPTS,e.endPTS,t);return r&&n.removeFragment(o.body),r})):n.removeFragment(o.body))}else o.body.type===r&&n.removeFragment(o.body)}))},t.detectPartialFragments=function(e){var t=this,r=this.timeRanges;if(r&&"initSegment"!==e.frag.sn){var i=e.frag,a=ha(i),n=this.fragments[a];if(!(!n||n.buffered&&i.gap)){var s=!i.relurl;Object.keys(r).forEach((function(a){var o=i.elementaryStreams[a];if(o){var l=r[a],u=s||!0===o.partial;n.range[a]=t.getBufferedTimes(i,e.part,u,l)}})),n.loaded=null,Object.keys(n.range).length?(n.buffered=!0,(n.body.endList=i.endList||n.body.endList)&&(this.endListFragments[n.body.type]=n),da(n)||this.removeParts(i.sn-1,i.type)):this.removeFragment(n.body)}}},t.removeParts=function(e,t){var r=this.activePartLists[t];r&&(this.activePartLists[t]=fa(r,(function(t){return t.fragment.sn>=e})))},t.fragBuffered=function(e,t){var r=ha(e),i=this.fragments[r];!i&&t&&(i=this.fragments[r]={body:e,appendedPTS:null,loaded:null,buffered:!1,range:Object.create(null)},e.gap&&(this.hasGaps=!0)),i&&(i.loaded=null,i.buffered=!0)},t.getBufferedTimes=function(e,t,r,i){for(var a={time:[],partial:r},n=e.start,s=e.end,o=e.minEndPTS||s,l=e.maxStartPTS||n,u=0;u=d&&o<=h){a.time.push({startPTS:Math.max(n,i.start(u)),endPTS:Math.min(s,i.end(u))});break}if(nd){var f=Math.max(n,i.start(u)),c=Math.min(s,i.end(u));c>f&&(a.partial=!0,a.time.push({startPTS:f,endPTS:c}))}else if(s<=d)break}return a},t.getPartialFragment=function(e){var t,r,i,a=null,n=0,s=this.bufferPadding,o=this.fragments;return Object.keys(o).forEach((function(l){var u=o[l];u&&da(u)&&(r=u.body.start-s,i=u.body.end+s,e>=r&&e<=i&&(t=Math.min(e-r,i-e),n<=t&&(a=u.body,n=t)))})),a},t.isEndListAppended=function(e){var t=this.endListFragments[e];return void 0!==t&&(t.buffered||da(t))},t.getState=function(e){var t=ha(e),r=this.fragments[t];return r?r.buffered?da(r)?oa:la:sa:na},t.isTimeBuffered=function(e,t,r){for(var i,a,n=0;n=i&&t<=a)return!0;if(t<=i)return!1}return!1},t.onManifestLoading=function(){this.removeAllFragments()},t.onFragLoaded=function(e,t){if("initSegment"!==t.frag.sn&&!t.frag.bitrateTest){var r=t.frag,i=t.part?null:t,a=ha(r);this.fragments[a]={body:r,appendedPTS:null,loaded:i,buffered:!1,range:Object.create(null)}}},t.onBufferAppended=function(e,t){var r=t.frag,i=t.part,a=t.timeRanges,n=t.type;if("initSegment"!==r.sn){var s=r.type;if(i){var o=this.activePartLists[s];o||(this.activePartLists[s]=o=[]),o.push(i)}this.timeRanges=a;var l=a[n];this.detectEvictedFragments(n,l,s,i)}},t.onFragBuffered=function(e,t){this.detectPartialFragments(t)},t.hasFragment=function(e){var t=ha(e);return!!this.fragments[t]},t.hasFragments=function(e){var t=this.fragments,r=Object.keys(t);if(!e)return r.length>0;for(var i=r.length;i--;){var a=t[r[i]];if((null==a?void 0:a.body.type)===e)return!0}return!1},t.hasParts=function(e){var t;return!(null==(t=this.activePartLists[e])||!t.length)},t.removeFragmentsInRange=function(e,t,r,i,a){var n=this;i&&!this.hasGaps||Object.keys(this.fragments).forEach((function(s){var o=n.fragments[s];if(o){var l=o.body;l.type!==r||i&&!l.gap||l.starte&&(o.buffered||a)&&n.removeFragment(l)}}))},t.removeFragment=function(e){var t=ha(e);e.clearElementaryStreamInfo();var r=this.activePartLists[e.type];if(r){var i=e.sn;this.activePartLists[e.type]=fa(r,(function(e){return e.fragment.sn!==i}))}delete this.fragments[t],e.endList&&delete this.endListFragments[e.type]},t.removeAllFragments=function(){var e,t;this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activePartLists=Object.create(null),this.hasGaps=!1;var r=null==(e=this.hls)||null==(t=e.latestLevelDetails)?void 0:t.partList;r&&r.forEach((function(e){return e.clearElementaryStreamInfo()}))},e}();function da(e){var t,r,i;return e.buffered&&(e.body.gap||(null==(t=e.range.video)?void 0:t.partial)||(null==(r=e.range.audio)?void 0:r.partial)||(null==(i=e.range.audiovideo)?void 0:i.partial))}function ha(e){return e.type+"_"+e.level+"_"+e.sn}function fa(e,t){return e.filter((function(e){var r=t(e);return r||e.clearElementaryStreamInfo(),r}))}var ca=Math.pow(2,17),va=function(){function e(e){this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=e}var t=e.prototype;return t.destroy=function(){this.loader&&(this.loader.destroy(),this.loader=null)},t.abort=function(){this.loader&&this.loader.abort()},t.load=function(e,t){var r=this,i=e.url;if(!i)return Promise.reject(new pa({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_ERROR,fatal:!1,frag:e,error:new Error("Fragment does not have a "+(i?"part list":"url")),networkDetails:null}));this.abort();var a=this.config,n=a.fLoader,s=a.loader;return new Promise((function(o,l){if(r.loader&&r.loader.destroy(),e.gap){if(e.tagList.some((function(e){return"GAP"===e[0]})))return void l(ma(e));e.gap=!1}var u=r.loader=n?new n(a):new s(a),h=ga(e);e.loader=u;var f=mt(a.fragLoadPolicy.default),c={loadPolicy:f,timeout:f.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:"initSegment"===e.sn?1/0:ca};e.stats=u.stats;var v={onSuccess:function(t,i,a,n){r.resetLoader(e,u);var s=t.data;a.resetIV&&e.decryptdata&&(e.decryptdata.iv=new Uint8Array(s.slice(0,16)),s=s.slice(16)),o({frag:e,part:null,payload:s,networkDetails:n})},onError:function(t,a,n,s){r.resetLoader(e,u),l(new pa({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_ERROR,fatal:!1,frag:e,response:d({url:i,data:void 0},t),error:new Error("HTTP Error "+t.code+" "+t.text),networkDetails:n,stats:s}))},onAbort:function(t,i,a){r.resetLoader(e,u),l(new pa({type:b.NETWORK_ERROR,details:D.INTERNAL_ABORTED,fatal:!1,frag:e,error:new Error("Aborted"),networkDetails:a,stats:t}))},onTimeout:function(t,i,a){r.resetLoader(e,u),l(new pa({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,error:new Error("Timeout after "+c.timeout+"ms"),networkDetails:a,stats:t}))}};t&&(v.onProgress=function(r,i,a,n){return t({frag:e,part:null,payload:a,networkDetails:n})}),u.load(h,c,v)}))},t.loadPart=function(e,t,r){var i=this;this.abort();var a=this.config,n=a.fLoader,s=a.loader;return new Promise((function(o,l){if(i.loader&&i.loader.destroy(),e.gap||t.gap)l(ma(e,t));else{var u=i.loader=n?new n(a):new s(a),h=ga(e,t);e.loader=u;var f=mt(a.fragLoadPolicy.default),c={loadPolicy:f,timeout:f.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:ca};t.stats=u.stats,u.load(h,c,{onSuccess:function(a,n,s,l){i.resetLoader(e,u),i.updateStatsFromPart(e,t);var d={frag:e,part:t,payload:a.data,networkDetails:l};r(d),o(d)},onError:function(r,a,n,s){i.resetLoader(e,u),l(new pa({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_ERROR,fatal:!1,frag:e,part:t,response:d({url:h.url,data:void 0},r),error:new Error("HTTP Error "+r.code+" "+r.text),networkDetails:n,stats:s}))},onAbort:function(r,a,n){e.stats.aborted=t.stats.aborted,i.resetLoader(e,u),l(new pa({type:b.NETWORK_ERROR,details:D.INTERNAL_ABORTED,fatal:!1,frag:e,part:t,error:new Error("Aborted"),networkDetails:n,stats:r}))},onTimeout:function(r,a,n){i.resetLoader(e,u),l(new pa({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,part:t,error:new Error("Timeout after "+c.timeout+"ms"),networkDetails:n,stats:r}))}})}}))},t.updateStatsFromPart=function(e,t){var r=e.stats,i=t.stats,a=i.total;if(r.loaded+=i.loaded,a){var n=Math.round(e.duration/t.duration),s=Math.min(Math.round(r.loaded/a),n),o=(n-s)*Math.round(r.loaded/s);r.total=r.loaded+o}else r.total=Math.max(r.loaded,r.total);var l=r.loading,u=i.loading;l.start?l.first+=u.first-u.start:(l.start=u.start,l.first=u.first),l.end=u.end},t.resetLoader=function(e,t){e.loader=null,this.loader===t&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),t.destroy()},e}();function ga(e,t){void 0===t&&(t=null);var r,i=t||e,a={frag:e,part:t,responseType:"arraybuffer",url:i.url,headers:{},rangeStart:0,rangeEnd:0},n=i.byteRangeStartOffset,s=i.byteRangeEndOffset;if(L(n)&&L(s)){var o,l=n,u=s;if("initSegment"===e.sn&&("AES-128"===(r=null==(o=e.decryptdata)?void 0:o.method)||"AES-256"===r)){var d=s-n;d%16&&(u=s+(16-d%16)),0!==n&&(a.resetIV=!0,l=n-16)}a.rangeStart=l,a.rangeEnd=u}return a}function ma(e,t){var r=new Error("GAP "+(e.gap?"tag":"attribute")+" found"),i={type:b.MEDIA_ERROR,details:D.FRAG_GAP,fatal:!1,frag:e,error:r,networkDetails:null};return t&&(i.part=t),(t||e).stats.aborted=!0,new pa(i)}var pa=function(e){function t(t){var r;return(r=e.call(this,t.error.message)||this).data=void 0,r.data=t,r}return o(t,e),t}(c(Error)),ya=function(e){function t(t,r){var i;return(i=e.call(this,t,r)||this)._boundTick=void 0,i._tickTimer=null,i._tickInterval=null,i._tickCallCount=0,i._boundTick=i.tick.bind(i),i}o(t,e);var r=t.prototype;return r.destroy=function(){this.onHandlerDestroying(),this.onHandlerDestroyed()},r.onHandlerDestroying=function(){this.clearNextTick(),this.clearInterval()},r.onHandlerDestroyed=function(){},r.hasInterval=function(){return!!this._tickInterval},r.hasNextTick=function(){return!!this._tickTimer},r.setInterval=function(e){return!this._tickInterval&&(this._tickCallCount=0,this._tickInterval=self.setInterval(this._boundTick,e),!0)},r.clearInterval=function(){return!!this._tickInterval&&(self.clearInterval(this._tickInterval),this._tickInterval=null,!0)},r.clearNextTick=function(){return!!this._tickTimer&&(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0)},r.tick=function(){this._tickCallCount++,1===this._tickCallCount&&(this.doTick(),this._tickCallCount>1&&this.tickImmediate(),this._tickCallCount=0)},r.tickImmediate=function(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)},r.doTick=function(){},t}(N),Ea=function(e,t,r,i,a,n){void 0===i&&(i=0),void 0===a&&(a=-1),void 0===n&&(n=!1),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=e,this.sn=t,this.id=r,this.size=i,this.part=a,this.partial=n};function Ta(e,t){for(var r=0,i=e.length;re.startCC)}(t,e)){var r=Math.min(t.endCC,e.endCC),i=Ta(t.fragments,r),a=Ta(e.fragments,r);i&&a&&(j.log("Aligning playlist at start of dicontinuity sequence "+r),La(i.start-a.start,e))}}(t,e),!t.alignedSliding&&e&&function(e,t){if(e.hasProgramDateTime&&t.hasProgramDateTime){var r,i,a=e.fragments,n=t.fragments;if(a.length&&n.length){var s=Math.min(t.endCC,e.endCC);t.startCCl.end){var f=o>h;(os.lastCurrentTime&&(s.lastCurrentTime=o),!s.loadingParts)){var c=Math.max(l.end,o),v=s.shouldLoadParts(s.getLevelDetails(),c);v&&(s.log("LL-Part loading ON after seeking to "+o.toFixed(2)+" with buffer @"+c.toFixed(2)),s.loadingParts=v)}s.hls.hasEnoughToStart||l.len||(s.log("setting startPosition to "+o+" because of seek before start"),s.nextLoadPosition=s.startPosition=o),s.tickImmediate()},s.onMediaEnded=function(){s.log("setting startPosition to 0 because media ended"),s.startPosition=s.lastCurrentTime=0},s.playlistType=n,s.hls=t,s.fragmentLoader=new va(t.config),s.keyLoader=i,s.fragmentTracker=r,s.config=t.config,s.decrypter=new ci(t.config),s}o(t,e);var r=t.prototype;return r.registerListeners=function(){var e=this.hls;e.on(k.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(k.MANIFEST_LOADING,this.onManifestLoading,this),e.on(k.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(k.ERROR,this.onError,this)},r.unregisterListeners=function(){var e=this.hls;e.off(k.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(k.MANIFEST_LOADING,this.onManifestLoading,this),e.off(k.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(k.ERROR,this.onError,this)},r.doTick=function(){this.onTickEnd()},r.onTickEnd=function(){},r.startLoad=function(e){},r.stopLoad=function(){if(this.state!==ba.STOPPED){this.fragmentLoader.abort(),this.keyLoader.abort(this.playlistType);var e=this.fragCurrent;null!=e&&e.loader&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=ba.STOPPED}},r.pauseBuffering=function(){this.buffering=!1},r.resumeBuffering=function(){this.buffering=!0},r._streamEnded=function(e,t){if(t.live||!this.media)return!1;var r=e.end||0,i=this.config.timelineOffset||0;if(r<=i)return!1;var a=e.nextStart;if(a&&a>i&&a0&&null!=n&&n.key&&n.iv&&Wt(n.method)){var s=self.performance.now();return r.decrypter.decrypt(new Uint8Array(a),n.key.buffer,n.iv.buffer,Yt(n.method)).catch((function(e){throw t.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_DECRYPT_ERROR,fatal:!1,error:e,reason:e.message,frag:i}),e})).then((function(a){var n=self.performance.now();return t.trigger(k.FRAG_DECRYPTED,{frag:i,payload:a,stats:{tstart:s,tdecrypt:n}}),e.payload=a,r.completeInitSegmentLoad(e)}))}return r.completeInitSegmentLoad(e)})).catch((function(t){r.state!==ba.STOPPED&&r.state!==ba.ERROR&&(r.warn(t),r.resetFragmentLoading(e))}))},r.completeInitSegmentLoad=function(e){if(!this.levels)throw new Error("init load aborted, missing levels");var t=e.frag.stats;this.state!==ba.STOPPED&&(this.state=ba.IDLE),e.frag.data=new Uint8Array(e.payload),t.parsing.start=t.buffering.start=self.performance.now(),t.parsing.end=t.buffering.end=self.performance.now(),this.tick()},r.fragContextChanged=function(e){var t=this.fragCurrent;return!e||!t||e.sn!==t.sn||e.level!==t.level},r.fragBufferedComplete=function(e,t){var r=this.mediaBuffer?this.mediaBuffer:this.media;if(this.log("Buffered "+e.type+" sn: "+e.sn+(t?" part: "+t.index:"")+" of "+this.fragInfo(e,!1,t)+" > buffer:"+(r?Aa(_t.getBuffered(r)):"(detached)")+")"),re(e)){var i;if(e.type!==O){var a=e.elementaryStreams;if(!Object.keys(a).some((function(e){return!!a[e]})))return void(this.state=ba.IDLE)}var n=null==(i=this.levels)?void 0:i[e.level];null!=n&&n.fragmentError&&(this.log("Resetting level fragment error count of "+n.fragmentError+" on frag buffered"),n.fragmentError=0)}this.state=ba.IDLE},r._handleFragmentLoadComplete=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})),s=new Ea(r.level,r.sn,r.stats.chunkCount+1,0,i?i.index:-1,!n);t.flush(s)}},r._handleFragmentLoadProgress=function(e){},r._doFragLoad=function(e,t,r,i){var a,n=this;void 0===r&&(r=null),this.fragCurrent=e;var s=null==t?void 0:t.details;if(!this.levels||!s)throw new Error("frag load aborted, missing level"+(s?"":" detail")+"s");var o=null;!e.encrypted||null!=(a=e.decryptdata)&&a.key?!e.encrypted&&s.encryptedFragments.length&&this.keyLoader.loadClear(e,s.encryptedFragments):(this.log("Loading key for "+e.sn+" of ["+s.startSN+"-"+s.endSN+"], "+this.playlistLabel()+" "+e.level),this.state=ba.KEY_LOADING,this.fragCurrent=e,o=this.keyLoader.load(e).then((function(e){if(!n.fragContextChanged(e.frag))return n.hls.trigger(k.KEY_LOADED,e),n.state===ba.KEY_LOADING&&(n.state=ba.IDLE),e})),this.hls.trigger(k.KEY_LOADING,{frag:e}),null===this.fragCurrent&&(o=Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING"))));var l=this.fragPrevious;if(re(e)&&(!l||e.sn!==l.sn)){var u=this.shouldLoadParts(t.details,e.end);u!==this.loadingParts&&(this.log("LL-Part loading "+(u?"ON":"OFF")+" loading sn "+(null==l?void 0:l.sn)+"->"+e.sn),this.loadingParts=u)}if(r=Math.max(e.start,r||0),this.loadingParts&&re(e)){var d=s.partList;if(d&&i){r>e.end&&s.fragmentHint&&(e=s.fragmentHint);var h=this.getNextPart(d,e,r);if(h>-1){var f,c=d[h];return e=this.fragCurrent=c.fragment,this.log("Loading "+e.type+" sn: "+e.sn+" part: "+c.index+" ("+h+"/"+(d.length-1)+") of "+this.fragInfo(e,!1,c)+") cc: "+e.cc+" ["+s.startSN+"-"+s.endSN+"], target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=c.start+c.duration,this.state=ba.FRAG_LOADING,f=o?o.then((function(r){return!r||n.fragContextChanged(r.frag)?null:n.doFragPartsLoad(e,c,t,i)})).catch((function(e){return n.handleFragLoadError(e)})):this.doFragPartsLoad(e,c,t,i).catch((function(e){return n.handleFragLoadError(e)})),this.hls.trigger(k.FRAG_LOADING,{frag:e,part:c,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):f}if(!e.url||this.loadedEndOfParts(d,r))return Promise.resolve(null)}}if(re(e)&&this.loadingParts)this.log("LL-Part loading OFF after next part miss @"+r.toFixed(2)),this.loadingParts=!1;else if(!e.url)return Promise.resolve(null);this.log("Loading "+e.type+" sn: "+e.sn+" of "+this.fragInfo(e,!1)+") cc: "+e.cc+" "+(s?"["+s.startSN+"-"+s.endSN+"]":"")+", target: "+parseFloat(r.toFixed(3))),L(e.sn)&&!this.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),this.state=ba.FRAG_LOADING;var v,g=this.config.progressive;return v=g&&o?o.then((function(t){return!t||n.fragContextChanged(null==t?void 0:t.frag)?null:n.fragmentLoader.load(e,i)})).catch((function(e){return n.handleFragLoadError(e)})):Promise.all([this.fragmentLoader.load(e,g?i:void 0),o]).then((function(e){var t=e[0];return!g&&t&&i&&i(t),t})).catch((function(e){return n.handleFragLoadError(e)})),this.hls.trigger(k.FRAG_LOADING,{frag:e,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):v},r.doFragPartsLoad=function(e,t,r,i){var a=this;return new Promise((function(n,s){var o,l=[],u=null==(o=r.details)?void 0:o.partList,d=function(t){a.fragmentLoader.loadPart(e,t,i).then((function(i){l[t.index]=i;var s=i.part;a.hls.trigger(k.FRAG_LOADED,i);var o=pr(r.details,e.sn,t.index+1)||yr(u,e.sn,t.index+1);if(!o)return n({frag:e,part:s,partsLoaded:l});d(o)})).catch(s)};d(t)}))},r.handleFragLoadError=function(e){if("data"in e){var t=e.data;e.data&&t.details===D.INTERNAL_ABORTED?this.handleFragLoadAborted(t.frag,t.part):this.hls.trigger(k.ERROR,t)}else this.hls.trigger(k.ERROR,{type:b.OTHER_ERROR,details:D.INTERNAL_EXCEPTION,err:e,error:e,fatal:!0});return null},r._handleTransmuxerFlush=function(e){var t=this.getCurrentContext(e);if(t&&this.state===ba.PARSING){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);var s=this.getLevelDetails(),o=s&&r.sn>s.endSN||this.shouldLoadParts(s,r.end);o!==this.loadingParts&&(this.log("LL-Part loading "+(o?"ON":"OFF")+" after parsing segment ending @"+r.end.toFixed(2)),this.loadingParts=o),this.updateLevelTiming(r,i,a,e.partial)}else this.fragCurrent||this.state===ba.STOPPED||this.state===ba.ERROR||(this.state=ba.IDLE)},r.shouldLoadParts=function(e,t){if(this.config.lowLatencyMode){if(!e)return this.loadingParts;if(null!=e&&e.partList){var r,i,a=e.partList[0];if(t>=a.end+((null==(r=e.fragmentHint)?void 0:r.duration)||0)&&(this.hls.hasEnoughToStart?(null==(i=this.media)?void 0:i.currentTime)||this.lastCurrentTime:this.getLoadPosition())>a.start-a.fragment.duration)return!0}}return!1},r.getCurrentContext=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 "+a+" of "+this.playlistLabel()+" "+i+". The current chunk will not be buffered."),null;var s=t[i],o=s.details,l=n>-1?pr(o,a,n):null,u=l?l.fragment:mr(o,a,r);return u?(r&&r!==u&&(u.stats=r.stats),{frag:u,part:l,level:s}):null},r.bufferFragmentData=function(e,t,r,i,a){var n;if(e&&this.state===ba.PARSING){var s=e.data1,o=e.data2,l=s;if(s&&o&&(l=be(s,o)),null!=(n=l)&&n.length){var u={type:e.type,frag:t,part:r,chunkMeta:i,parent:t.type,data:l};if(this.hls.trigger(k.BUFFER_APPENDING,u),e.dropped&&e.independent&&!r){if(a)return;this.flushBufferGap(t)}}}},r.flushBufferGap=function(e){var t=this.media;if(t)if(_t.isBuffered(t,t.currentTime)){var r=t.currentTime,i=_t.bufferInfo(t,r,0),a=e.duration,n=Math.min(2*this.config.maxFragLookUpTolerance,.25*a),s=Math.max(Math.min(e.start-n,i.end-n),r+n);e.start-s>n&&this.flushMainBuffer(s,e.start)}else this.flushMainBuffer(0,e.start)},r.getFwdBufferInfo=function(e,t){var r,i=this.getLoadPosition();if(!L(i))return null;var a=this.lastCurrentTime>i||null!=(r=this.media)&&r.paused?0:this.config.maxBufferHole;return this.getFwdBufferInfoAtPos(e,i,t,a)},r.getFwdBufferInfoAtPos=function(e,t,r,i){var a=_t.bufferInfo(e,t,i);if(0===a.len&&void 0!==a.nextStart){var n=this.fragmentTracker.getBufferedFrag(t,r);if(n&&(a.nextStart<=n.end||n.gap)){var s=Math.max(Math.min(a.nextStart,n.end)-t,i);return _t.bufferInfo(e,t,s)}}return a},r.getMaxBufferLength=function(e){var t,r=this.config;return t=e?Math.max(8*r.maxBufferSize/e,r.maxBufferLength):r.maxBufferLength,Math.min(t,r.maxMaxBufferLength)},r.reduceMaxBufferLength=function(e,t){var r=this.config,i=Math.max(Math.min(e-t,r.maxBufferLength),t),a=Math.max(e-3*t,r.maxMaxBufferLength/2,i);return a>=i&&(r.maxMaxBufferLength=a,this.warn("Reduce max buffer length to "+a+"s"),!0)},r.getAppendedFrag=function(e,t){var r;void 0===t&&(t=P);var i=null==(r=this.fragmentTracker)?void 0:r.getAppendedFrag(e,t);return i&&"fragment"in i?i.fragment:i},r.getNextFragment=function(e,t){var r=t.fragments,i=r.length;if(!i)return null;var a=this.config,n=r[0].start,s=a.lowLatencyMode&&!!t.partList,o=null;if(t.live){var l=a.initialLiveManifestSize;if(i=n?d:h)||o.start:e;this.log("Setting startPosition to "+f+" to match start frag at live edge. mainStart: "+d+" liveSyncPosition: "+h+" frag.start: "+(null==(u=o)?void 0:u.start)),this.startPosition=this.nextLoadPosition=f}}else e<=n&&(o=r[0]);if(!o){var c=this.loadingParts?t.partEnd:t.fragmentEnd;o=this.getFragmentAtPosition(e,c,t)}var v=this.filterReplacedPrimary(o,t);if(!v&&o){var g=o.sn-t.startSN;v=this.filterReplacedPrimary(r[g+1]||null,t)}return this.mapToInitFragWhenRequired(v)},r.isLoopLoading=function(e,t){var r=this.fragmentTracker.getState(e);return(r===la||r===oa&&!!e.gap)&&this.nextLoadPosition>t},r.getNextFragmentLoopLoading=function(e,t,r,i,a){var n=null;if(e.gap&&(n=this.getNextFragment(this.nextLoadPosition,t))&&!n.gap&&r.nextStart){var s=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,r.nextStart,i,0);if(null!==s&&r.len+s.len>=a){var o=n.sn;return this.loopSn!==o&&(this.log('buffer full after gaps in "'+i+'" playlist starting at sn: '+o),this.loopSn=o),null}}return this.loopSn=void 0,n},r.filterReplacedPrimary=function(e,t){return e?(this.hls.config,e):e},r.mapToInitFragWhenRequired=function(e){return null==e||!e.initSegment||null!=e&&e.initSegment.data||this.bitrateTest?e:e.initSegment},r.getNextPart=function(e,t,r){for(var i=-1,a=!1,n=!0,s=0,o=e.length;s-1&&rr.start&&r.loaded},r.getInitialLiveFragment=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: "+r.programDateTime),i=function(e,t,r){if(null===t||!Array.isArray(e)||!e.length||!L(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: "+i.sn))}i||(i=function(e,t){return ut(e,(function(e){return e.cct?-1:0}))}(t,r.cc),i&&this.log("Live playlist, switching playlist, load frag with same CC: "+i.sn))}}else{var s=this.hls.liveSyncPosition;null!==s&&(i=this.getFragmentAtPosition(s,this.bitrateTest?e.fragmentEnd:e.edge,e))}return i},r.getFragmentAtPosition=function(e,t,r){var i,a,n=this.config,s=this.fragPrevious,o=r.fragments,l=r.endSN,u=r.fragmentHint,d=n.maxFragLookUpTolerance,h=r.partList,f=!!(this.loadingParts&&null!=h&&h.length&&u);if(f&&u&&!this.bitrateTest&&h[h.length-1].fragment.sn===u.sn&&(o=o.concat(u),l=u.sn),i=et-d||null!=(a=this.media)&&a.paused||!this.startFragRequested?0:d):o[o.length-1]){var c=i.sn-r.startSN,v=this.fragmentTracker.getState(i);if((v===la||v===oa&&i.gap)&&(s=i),s&&i.sn===s.sn&&(!f||h[0].fragment.sn>i.sn||!r.live&&!f)&&s&&i.level===s.level){var g=o[c+1];i=i.sn"+e.startSN+" fragments: "+i),o}return a},r.waitForCdnTuneIn=function(e){return e.live&&e.canBlockReload&&e.partTarget&&e.tuneInGoal>Math.max(e.partHoldBack,3*e.partTarget)},r.setStartPosition=function(e,t){var r=this.startPosition;r=0&&(r=this.nextLoadPosition),r},r.handleFragLoadAborted=function(e,t){this.transmuxer&&e.type===this.playlistType&&re(e)&&e.stats.aborted&&(this.warn("Fragment "+e.sn+(t?" part "+t.index:"")+" of "+this.playlistLabel()+" "+e.level+" was aborted"),this.resetFragmentLoading(e))},r.resetFragmentLoading=function(e){this.fragCurrent&&(this.fragContextChanged(e)||this.state===ba.FRAG_LOADING_WAITING_RETRY)||(this.state=ba.IDLE)},r.onFragmentOrKeyLoadError=function(e,t){if(t.chunkMeta&&!t.frag){var r=this.getCurrentContext(t.chunkMeta);r&&(t.frag=r.frag)}var i=t.frag;if(i&&i.type===e&&this.levels)if(this.fragContextChanged(i)){var a;this.warn("Frag load error must match current frag to retry "+i.url+" > "+(null==(a=this.fragCurrent)?void 0:a.url))}else{var n=t.details===D.FRAG_GAP;n&&this.fragmentTracker.fragBuffered(i,!0);var s=t.errorAction,o=s||{},l=o.action,u=o.flags,d=o.retryCount,h=void 0===d?0:d,f=o.retryConfig,c=!!s&&!!f,v=c&&l===St,g=c&&!s.resolved&&u===Rt;if(!v&&g&&re(i)&&!i.endList)this.resetFragmentErrors(e),this.treatAsGap(i),s.resolved=!0;else if((v||g)&&h.5;a&&this.reduceMaxBufferLength(i.len,(null==t?void 0:t.duration)||10);var n=!a;return n&&this.warn("Buffer full error while media.currentTime is not buffered, flush "+r+" buffer"),t&&(this.fragmentTracker.removeFragment(t),this.nextLoadPosition=t.start),this.resetLoadingState(),n}return!1},r.resetFragmentErrors=function(e){e===w&&(this.fragCurrent=null),this.hls.hasEnoughToStart||(this.startFragRequested=!1),this.state!==ba.STOPPED&&(this.state=ba.IDLE)},r.afterBufferFlushed=function(e,t,r){if(e){var i=_t.getBuffered(e);this.fragmentTracker.detectEvictedFragments(t,i,r),this.state===ba.ENDED&&this.resetLoadingState()}},r.resetLoadingState=function(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state!==ba.STOPPED&&(this.state=ba.IDLE)},r.resetStartWhenNotLoaded=function(e){if(!this.hls.hasEnoughToStart){this.startFragRequested=!1;var t=e?e.details:null;null!=t&&t.live?(this.log("resetting startPosition for live start"),this.startPosition=-1,this.setStartPosition(t,t.fragmentStart),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}},r.resetWhenMissingContext=function(e){this.warn("The loading context changed while buffering fragment "+e.sn+" of "+this.playlistLabel()+" "+e.level+". This chunk will not be buffered."),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState()},r.removeUnbufferedFrags=function(e){void 0===e&&(e=0),this.fragmentTracker.removeFragmentsInRange(e,1/0,this.playlistType,!1,!0)},r.updateLevelTiming=function(e,t,r,i){var a=this,n=r.details;if(n){var s;if(!Object.keys(e.elementaryStreams).reduce((function(t,s){var o=e.elementaryStreams[s];if(o){var l=o.endPTS-o.startPTS;if(l<=0)return a.warn("Could not parse fragment "+e.sn+" "+s+" duration reliably ("+l+")"),t||!1;var u=i?0:hr(n,e,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return a.hls.trigger(k.LEVEL_PTS_UPDATED,{details:n,level:r,drift:u,type:s,frag:e,start:o.startPTS,end:o.endPTS}),!0}return t}),!1)&&(0===r.fragmentError&&this.treatAsGap(e,r),null===(null==(s=this.transmuxer)?void 0:s.error))){var o=new Error("Found no media in fragment "+e.sn+" of "+this.playlistLabel()+" "+e.level+" resetting transmuxer to fallback to playlist timing");if(this.warn(o.message),this.hls.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!1,error:o,frag:e,reason:"Found no media in msn "+e.sn+" of "+this.playlistLabel()+' "'+r.url+'"'}),!this.hls)return;this.resetTransmuxer()}this.state=ba.PARSED,this.log("Parsed "+e.type+" sn: "+e.sn+(t?" part: "+t.index:"")+" of "+this.fragInfo(e,!1,t)+")"),this.hls.trigger(k.FRAG_PARSED,{frag:e,part:t})}else this.warn("level.details undefined")},r.playlistLabel=function(){return this.playlistType===P?"level":"track"},r.fragInfo=function(e,t,r){var i,a;return void 0===t&&(t=!0),this.playlistLabel()+" "+e.level+" ("+(r?"part":"frag")+":["+(null!=(i=t&&!r?e.startPTS:(r||e).start)?i:NaN).toFixed(3)+"-"+(null!=(a=t&&!r?e.endPTS:(r||e).end)?a:NaN).toFixed(3)+"]"+(r&&"main"===e.type?"INDEPENDENT="+(r.independent?"YES":"NO"):"")},r.treatAsGap=function(e,t){t&&t.fragmentError++,e.gap=!0,this.fragmentTracker.removeFragment(e),this.fragmentTracker.fragBuffered(e,!0)},r.resetTransmuxer=function(){var e;null==(e=this.transmuxer)||e.reset()},r.recoverWorkerError=function(e){"demuxerWorker"===e.event&&(this.fragmentTracker.removeAllFragments(),this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState())},i(t,[{key:"startPositionValue",get:function(){var e=this.nextLoadPosition,t=this.startPosition;return-1===t&&e?e:t}},{key:"bufferingEnabled",get:function(){return this.buffering}},{key:"inFlightFrag",get:function(){return{frag:this.fragCurrent,state:this.state}}},{key:"timelineOffset",get:function(){var e,t=this.config.timelineOffset;return t?(null==(e=this.getLevelDetails())?void 0:e.appliedTimelineOffset)||t:0}},{key:"primaryPrefetch",get:function(){return this.hls.config,!1}},{key:"state",get:function(){return this._state},set:function(e){var t=this._state;t!==e&&(this._state=e,this.log(t+"->"+e))}}])}(ya);function ka(e,t,r){_a(e,t,r),e.addEventListener(t,r)}function _a(e,t,r){e.removeEventListener(t,r)}var Ia=function(e){function t(t,r){var i;return(i=e.call(this,"gap-controller",t.logger)||this).hls=null,i.fragmentTracker=null,i.media=null,i.mediaSource=void 0,i.nudgeRetry=0,i.stallReported=!1,i.stalled=null,i.moved=!1,i.seeking=!1,i.buffered={},i.lastCurrentTime=0,i.ended=0,i.waiting=0,i.onMediaPlaying=function(){i.ended=0,i.waiting=0},i.onMediaWaiting=function(){var e;null!=(e=i.media)&&e.seeking||(i.waiting=self.performance.now(),i.tick())},i.onMediaEnded=function(){var e;i.hls&&(i.ended=(null==(e=i.media)?void 0:e.currentTime)||1,i.hls.trigger(k.MEDIA_ENDED,{stalled:!1}))},i.hls=t,i.fragmentTracker=r,i.registerListeners(),i}o(t,e);var r=t.prototype;return r.registerListeners=function(){var e=this.hls;e&&(e.on(k.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(k.BUFFER_APPENDED,this.onBufferAppended,this))},r.unregisterListeners=function(){var e=this.hls;e&&(e.off(k.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(k.BUFFER_APPENDED,this.onBufferAppended,this))},r.destroy=function(){e.prototype.destroy.call(this),this.unregisterListeners(),this.media=this.hls=this.fragmentTracker=null,this.mediaSource=void 0},r.onMediaAttached=function(e,t){this.setInterval(100),this.mediaSource=t.mediaSource;var r=this.media=t.media;ka(r,"playing",this.onMediaPlaying),ka(r,"waiting",this.onMediaWaiting),ka(r,"ended",this.onMediaEnded)},r.onMediaDetaching=function(e,t){this.clearInterval();var r=this.media;r&&(_a(r,"playing",this.onMediaPlaying),_a(r,"waiting",this.onMediaWaiting),_a(r,"ended",this.onMediaEnded),this.media=null),this.mediaSource=void 0},r.onBufferAppended=function(e,t){this.buffered=t.timeRanges},r.tick=function(){var e;if(null!=(e=this.media)&&e.readyState&&this.hasBuffered){var t=this.media.currentTime;this.poll(t,this.lastCurrentTime),this.lastCurrentTime=t}},r.poll=function(e,t){var r,i,a=null==(r=this.hls)?void 0:r.config;if(a){var n=this.media,s=this.stalled;if(n){var o=n.seeking,l=this.seeking&&!o,u=!this.seeking&&o,d=n.paused&&!o||n.ended||0===n.playbackRate;if(this.seeking=o,e!==t)return t&&(this.ended=0),this.moved=!0,o||(this.nudgeRetry=0,a.nudgeOnVideoHole&&!d&&e>t&&this.nudgeOnVideoHole(e,t)),void(0===this.waiting&&this.stallResolved(e));if(u||l)l&&this.stallResolved(e);else{if(d)return this.nudgeRetry=0,this.stallResolved(e),void(!this.ended&&n.ended&&this.hls&&(this.ended=e||1,this.hls.trigger(k.MEDIA_ENDED,{stalled:!1})));if(_t.getBuffered(n).length){var h=_t.bufferInfo(n,e,0),f=h.nextStart||0,c=this.fragmentTracker;if(o&&c&&this.hls){var v=Ca(this.hls.inFlightFragments,e),g=h.len>2,m=!f||v||f-e>2&&!c.getPartialFragment(e);if(g||m)return;this.moved=!1}var p=null==(i=this.hls)?void 0:i.latestLevelDetails;if(!this.moved&&null!==this.stalled&&c){if(!(h.len>0||f))return;var y=Math.max(f,h.start||0)-e,E=null!=p&&p.live?2*p.targetduration:2,T=c.getPartialFragment(e);if(y>0&&(y<=E||T))return void(n.paused||this._trySkipBufferHole(T))}var S=a.detectStallWithCurrentTimeMs,L=self.performance.now(),R=this.waiting;if(null!==s){var A=L-s;if(!o&&(A>=S||R)&&this.hls){var b;if("ended"===(null==(b=this.mediaSource)?void 0:b.readyState)&&(null==p||!p.live)&&Math.abs(e-((null==p?void 0:p.edge)||0))<1){if(this.ended)return;return this.ended=e||1,void this.hls.trigger(k.MEDIA_ENDED,{stalled:!0})}if(this._reportStall(h),!this.media||!this.hls)return}var D=_t.bufferInfo(n,e,a.maxBufferHole);this._tryFixBufferStall(D,A)}else this.stalled=R>0&&L-R1&&e>i.end(0)){var a=_t.bufferedInfo(_t.timeRangesToArray(this.buffered.audio),e,0);if(a.len>1&&t>=a.start){var n=_t.timeRangesToArray(i),s=_t.bufferedInfo(n,t,0).bufferedIndex;if(s>-1&&ss)&&u-l<1&&e-l<2){var d=new Error("nudging playhead to flush pipeline after video hole. currentTime: "+e+" hole: "+l+" -> "+u+" buffered index: "+o);this.warn(d.message),this.media.currentTime+=1e-6;var h=this.fragmentTracker.getPartialFragment(e)||void 0,f=_t.bufferInfo(this.media,e,0);this.hls.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_SEEK_OVER_HOLE,fatal:!1,error:d,reason:d.message,frag:h,buffer:f.len,bufferInfo:f})}}}}},r._tryFixBufferStall=function(e,t){var r,i,a=this.fragmentTracker,n=this.media,s=null==(r=this.hls)?void 0:r.config;if(n&&a&&s){var o=n.currentTime,l=null==(i=this.hls)?void 0:i.latestLevelDetails,u=a.getPartialFragment(o);if((u||null!=l&&l.live&&o1&&e.len>s.maxBufferHole||e.nextStart&&e.nextStart-o1e3*s.highBufferWatchdogPeriod||this.waiting)&&(this.warn("Trying to nudge playhead over buffer-hole"),this._tryNudgeBuffer(e))}},r._reportStall=function(e){var t=this.hls,r=this.media,i=this.stallReported,a=this.stalled;if(!i&&null!==a&&r&&t){this.stallReported=!0;var n=new Error("Playback stalling at @"+r.currentTime+" due to low buffer ("+it(e)+")");this.warn(n.message),t.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_STALLED_ERROR,fatal:!1,error:n,buffer:e.len,bufferInfo:e,stalled:{start:a}})}},r._trySkipBufferHole=function(e){var t,r=this.fragmentTracker,i=this.media,a=null==(t=this.hls)?void 0:t.config;if(!i||!r||!a)return 0;var n=i.currentTime,s=_t.bufferInfo(i,n,0),o=n0&&s.len<1&&i.readyState<3,d=o-n;if(d>0&&(l||u)){if(d>a.maxBufferHole){var h=!1;if(0===n){var f=r.getAppendedFrag(0,P);f&&o0}}])}(ya);function Ca(e,t){var r=xa(e.main);if(r&&r.start<=t)return r;var i=xa(e.audio);return i&&i.start<=t?i:null}function xa(e){if(!e)return null;switch(e.state){case ba.IDLE:case ba.STOPPED:case ba.ENDED:case ba.ERROR:return null}return e.frag}function Pa(e,t){var r;try{r=new Event("addtrack")}catch(e){(r=document.createEvent("Event")).initEvent("addtrack",!1,!1)}r.track=e,t.dispatchEvent(r)}function wa(e,t,r,i){var a=e.mode;if("disabled"===a&&(e.mode="hidden"),e.cues&&e.cues.length>0)for(var n=function(e,t,r){var i=[],a=function(e,t){if(t<=e[0].startTime)return 0;var r=e.length-1;if(t>e[r].endTime)return-1;for(var i,a=0,n=r;a<=n;)if(te[i].startTime&&a-1)for(var n=a,s=e.length;n=t&&o.endTime<=r)i.push(o);else if(o.startTime>r)return i}return i}(e.cues,t,r),s=0;sFa&&(h=Fa),h-d<=0&&(h=d+.25);for(var f=0;f.01&&this.updateDateRangeCues(t.details)},t.updateDateRangeCues=function(e,t){var r=this;if(this.media&&e.hasProgramDateTime&&this.hls.config.enableDateRangeMetadataCues){var i,a=this.id3Track,n=e.dateRanges,s=Object.keys(n),o=this.dateRangeCuesAppended;if(a&&t)if(null!=(i=a.cues)&&i.length)for(var l=Object.keys(o).filter((function(e){return!s.includes(e)})),u=function(){var e=l[d],t=o[e].cues;delete o[e],Object.keys(t).forEach((function(e){try{var i=t[e];i.removeEventListener("enter",r.onEventCueEnter),a.removeCue(i)}catch(e){}}))},d=l.length;d--;)u();else o=this.dateRangeCuesAppended={};var h=e.fragments[e.fragments.length-1];if(0!==s.length&&L(null==h?void 0:h.programDateTime)){this.id3Track||(this.id3Track=this.createTrack(this.media));for(var f=Oa(),c=function(){var e=s[v],t=n[e],i=t.startTime,a=o[e],l=(null==a?void 0:a.cues)||{},u=(null==a?void 0:a.durationKnown)||!1,d=Fa,h=t.duration;if(t.endDate&&null!==h)d=i+h,u=!0;else if(t.endOnNext&&!u){var c=s.reduce((function(e,r){if(r!==t.id){var i=n[r];if(i.class===t.class&&i.startDate>t.startDate&&(!e||t.startDate.01&&(T.startTime=i,T.endTime=d);else if(f){var S=t.attr[E];Ut(E)&&(g=S,S=Uint8Array.from(g.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer);var L=Ma(f,i,d,{key:E,data:S},Xr.dateRange);L&&(L.id=e,r.id3Track.addCue(L),l[E]=L)}}}o[e]={cues:l,dateRange:t,durationKnown:u}},v=0;v.05&&t.forwardBufferLength>1){var u=Math.min(2,Math.max(1,s)),d=Math.round(2/(1+Math.exp(-.75*l-t.edgeStalled))*20)/20,h=Math.min(u,Math.max(1,d));t.changeMediaPlaybackRate(e,h)}else 1!==e.playbackRate&&0!==e.playbackRate&&t.changeMediaPlaybackRate(e,1)}}}}},this.hls=e,this.config=e.config,this.registerListeners()}var t=e.prototype;return t.destroy=function(){this.unregisterListeners(),this.onMediaDetaching(),this.hls=null},t.registerListeners=function(){var e=this.hls;e&&(e.on(k.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(k.MANIFEST_LOADING,this.onManifestLoading,this),e.on(k.LEVEL_UPDATED,this.onLevelUpdated,this),e.on(k.ERROR,this.onError,this))},t.unregisterListeners=function(){var e=this.hls;e&&(e.off(k.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(k.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(k.MANIFEST_LOADING,this.onManifestLoading,this),e.off(k.LEVEL_UPDATED,this.onLevelUpdated,this),e.off(k.ERROR,this.onError,this))},t.onMediaAttached=function(e,t){this.media=t.media,this.media.addEventListener("timeupdate",this.onTimeupdate)},t.onMediaDetaching=function(){this.media&&(this.media.removeEventListener("timeupdate",this.onTimeupdate),this.media=null)},t.onManifestLoading=function(){this._latency=null,this.stallCount=0},t.onLevelUpdated=function(e,t){var r=t.details;r.advanced&&this.onTimeupdate(),!r.live&&this.media&&this.media.removeEventListener("timeupdate",this.onTimeupdate)},t.onError=function(e,t){var r;t.details===D.BUFFER_STALLED_ERROR&&(this.stallCount++,this.hls&&null!=(r=this.levelDetails)&&r.live&&this.hls.logger.warn("[latency-controller]: Stall detected, adjusting target latency"))},t.changeMediaPlaybackRate=function(e,t){var r,i;e.playbackRate!==t&&(null==(r=this.hls)||r.logger.debug("[latency-controller]: latency="+this.latency.toFixed(3)+", targetLatency="+(null==(i=this.targetLatency)?void 0:i.toFixed(3))+", forwardBufferLength="+this.forwardBufferLength.toFixed(3)+": adjusting playback rate from "+e.playbackRate+" to "+t),e.playbackRate=t)},t.estimateLiveEdge=function(){var e=this.levelDetails;return null===e?null:e.edge+e.age},t.computeLatency=function(){var e=this.estimateLiveEdge();return null===e?null:e-this.currentTime},i(e,[{key:"levelDetails",get:function(){var e;return(null==(e=this.hls)?void 0:e.latestLevelDetails)||null}},{key:"latency",get:function(){return this._latency||0}},{key:"maxLatency",get:function(){var e=this.config;if(void 0!==e.liveMaxLatencyDuration)return e.liveMaxLatencyDuration;var t=this.levelDetails;return t?e.liveMaxLatencyDurationCount*t.targetduration:0}},{key:"targetLatency",get:function(){var e=this.levelDetails;if(null===e||null===this.hls)return null;var t=e.holdBack,r=e.partHoldBack,i=e.targetduration,a=this.config,n=a.liveSyncDuration,s=a.liveSyncDurationCount,o=a.lowLatencyMode,l=this.hls.userConfig,u=o&&r||t;(this._targetLatencyUpdated||l.liveSyncDuration||l.liveSyncDurationCount||0===u)&&(u=void 0!==n?n:s*i);var d=i;return u+Math.min(this.stallCount*this.config.liveSyncOnStallIncrease,d)},set:function(e){this.stallCount=0,this.config.liveSyncDuration=e,this._targetLatencyUpdated=!0}},{key:"liveSyncPosition",get:function(){var e=this.estimateLiveEdge(),t=this.targetLatency;if(null===e||null===t)return null;var r=this.levelDetails;if(null===r)return null;var i=r.edge,a=e-t-this.edgeStalled,n=i-r.totalduration,s=i-(this.config.lowLatencyMode&&r.partTarget||r.targetduration);return Math.min(Math.max(n,a),s)}},{key:"drift",get:function(){var e=this.levelDetails;return null===e?1:e.drift}},{key:"edgeStalled",get:function(){var e=this.levelDetails;if(null===e)return 0;var t=3*(this.config.lowLatencyMode&&e.partTarget||e.targetduration);return Math.max(e.age-t,0)}},{key:"forwardBufferLength",get:function(){var e=this.media,t=this.levelDetails;if(!e||!t)return 0;var r=e.buffered.length;return(r?e.buffered.end(r-1):t.edge)-this.currentTime}}])}(),Ua=function(e){function t(t,r){var i;return(i=e.call(this,r,t.logger)||this).hls=void 0,i.canLoad=!1,i.timer=-1,i.hls=t,i}o(t,e);var r=t.prototype;return r.destroy=function(){this.clearTimer(),this.hls=this.log=this.warn=null},r.clearTimer=function(){-1!==this.timer&&(self.clearTimeout(this.timer),this.timer=-1)},r.startLoad=function(){this.canLoad=!0,this.loadPlaylist()},r.stopLoad=function(){this.canLoad=!1,this.clearTimer()},r.switchParams=function(e,t,r){var i=null==t?void 0:t.renditionReports;if(i){for(var a=-1,n=0;n=0&&h>t.partTarget&&(d+=1)}var f=r&&Ze(r);return new Je(u,d>=0?d:void 0,f)}}},r.loadPlaylist=function(e){this.clearTimer()},r.loadingPlaylist=function(e,t){this.clearTimer()},r.shouldLoadPlaylist=function(e){return this.canLoad&&!!e&&!!e.url&&(!e.details||e.details.live)},r.getUrlWithDirectives=function(e,t){if(t)try{return t.addDirectives(e)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: "+e)}return e},r.playlistLoaded=function(e,t,r){var i=t.details,a=t.stats,n=self.performance.now(),s=a.loading.first?Math.max(0,n-a.loading.first):0;i.advancedDateTime=Date.now()-s;var o=this.hls.config.timelineOffset;if(o!==i.appliedTimelineOffset){var l=Math.max(o||0,0);i.appliedTimelineOffset=l,i.fragments.forEach((function(e){e.start=e.playlistOffset+l}))}if(i.live||null!=r&&r.live){var u="levelInfo"in t?t.levelInfo:t.track;if(i.reloaded(r),r&&i.fragments.length>0){fr(r,i);var d=i.playlistParsingError;if(d){this.warn(d);var h=this.hls;if(!h.config.ignorePlaylistParsingErrors){var f,c=t.networkDetails;return void h.trigger(k.ERROR,{type:b.NETWORK_ERROR,details:D.LEVEL_PARSING_ERROR,fatal:!1,url:i.url,error:d,reason:d.message,level:t.level||void 0,parent:null==(f=i.fragments[0])?void 0:f.type,networkDetails:c,stats:a})}i.playlistParsingError=null}}-1===i.requestScheduled&&(i.requestScheduled=a.loading.start);var v,g=this.hls.mainForwardBufferInfo,m=g?g.end-g.len:0,p=gr(i,1e3*(i.edge-m));if(i.requestScheduled+p0){if(I>3*i.targetduration)this.log("Playlist last advanced "+_.toFixed(2)+"s ago. Omitting segment and part directives."),y=void 0,E=void 0;else if(null!=r&&r.tuneInGoal&&I-i.partTarget>r.tuneInGoal)this.warn("CDN Tune-in goal increased from: "+r.tuneInGoal+" to: "+C+" with playlist age: "+i.age),C=0;else{var x=Math.floor(C/i.targetduration);y+=x,void 0!==E&&(E+=Math.round(C%i.targetduration/i.partTarget)),this.log("CDN Tune-in age: "+i.ageHeader+"s last advanced "+_.toFixed(2)+"s goal: "+C+" skip sn "+x+" to part "+E)}i.tuneInGoal=C}if(v=this.getDeliveryDirectives(i,t.deliveryDirectives,y,E),T||!A)return i.requestScheduled=n,void this.loadingPlaylist(u,v)}else(i.canBlockReload||i.canSkipUntil)&&(v=this.getDeliveryDirectives(i,t.deliveryDirectives,y,E));v&&void 0!==y&&i.canBlockReload&&(i.requestScheduled=a.loading.first+Math.max(p-2*s,p/2)),this.scheduleLoading(u,v,i)}else this.clearTimer()},r.scheduleLoading=function(e,t,r){var i=this,a=r||e.details;if(a){var n=self.performance.now(),s=a.requestScheduled;if(n>=s)this.loadingPlaylist(e,t);else{var o=s-n;this.log("reload live playlist "+(e.name||e.bitrate+"bps")+" in "+Math.round(o)+" ms"),this.clearTimer(),this.timer=self.setTimeout((function(){return i.loadingPlaylist(e,t)}),o)}}else this.loadingPlaylist(e,t)},r.getDeliveryDirectives=function(e,t,r,i){var a=Ze(e);return null!=t&&t.skip&&e.deltaUpdateFailed&&(r=t.msn,i=t.part,a=ze),new Je(r,i,a)},r.checkRetry=function(e){var t=this,r=e.details,i=ct(e),a=e.errorAction,n=a||{},s=n.action,o=n.retryCount,l=void 0===o?0:o,u=n.retryConfig,d=!!a&&!!u&&(s===St||!a.resolved&&s===Et);if(d){var h;if(l>=u.maxNumRetry)return!1;if(i&&null!=(h=e.context)&&h.deliveryDirectives)this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" without delivery-directives'),this.loadPlaylist();else{var f=gt(u,l);this.clearTimer(),this.timer=self.setTimeout((function(){return t.loadPlaylist()}),f),this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" in '+f+"ms")}e.levelRetry=!0,a.resolved=!0}return d},t}(N),Ga=function(e){function t(t,r){var i;return(i=e.call(this,t,"level-controller")||this)._levels=[],i._firstLevel=-1,i._maxAutoLevel=-1,i._startLevel=void 0,i.currentLevel=null,i.currentLevelIndex=-1,i.manualLevelIndex=-1,i.steering=void 0,i.onParsedComplete=void 0,i.steering=r,i._registerListeners(),i}o(t,e);var r=t.prototype;return r._registerListeners=function(){var e=this.hls;e.on(k.MANIFEST_LOADING,this.onManifestLoading,this),e.on(k.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(k.LEVEL_LOADED,this.onLevelLoaded,this),e.on(k.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(k.FRAG_BUFFERED,this.onFragBuffered,this),e.on(k.ERROR,this.onError,this)},r._unregisterListeners=function(){var e=this.hls;e.off(k.MANIFEST_LOADING,this.onManifestLoading,this),e.off(k.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(k.LEVEL_LOADED,this.onLevelLoaded,this),e.off(k.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(k.FRAG_BUFFERED,this.onFragBuffered,this),e.off(k.ERROR,this.onError,this)},r.destroy=function(){this._unregisterListeners(),this.steering=null,this.resetLevels(),e.prototype.destroy.call(this)},r.stopLoad=function(){this._levels.forEach((function(e){e.loadError=0,e.fragmentError=0})),e.prototype.stopLoad.call(this)},r.resetLevels=function(){this._startLevel=void 0,this.manualLevelIndex=-1,this.currentLevelIndex=-1,this.currentLevel=null,this._levels=[],this._maxAutoLevel=-1},r.onManifestLoading=function(e,t){this.resetLevels()},r.onManifestLoaded=function(e,t){var r=this,i=this.hls.config.preferManagedMediaSource,a=[],n={},s={},o=!1,l=!1,u=!1;t.levels.forEach((function(e){var t,d=e.attrs,h=e.audioCodec,f=e.videoCodec;h&&(e.audioCodec=h=He(h,i)||void 0),0===(null==(t=f)?void 0:t.indexOf("avc1"))&&(f=e.videoCodec=function(e){for(var t=e.split(","),r=0;r2){var a=i.shift()+".";a+=parseInt(i.shift()).toString(16),a+=("000"+parseInt(i.shift()).toString(16)).slice(-4),t[r]=a}}return t.join(",")}(f));var c=e.width,v=e.height,g=e.unknownCodecs,m=g?g.length:0;if(g)for(var p=m;p--;){var y=g[p];r.isAudioSupported(y)?(e.audioCodec=h=h?h+","+y:y,m--,we.audio[h.substring(0,4)]=2):r.isVideoSupported(y)&&(e.videoCodec=f=f?f+","+y:y,m--,we.video[f.substring(0,4)]=2)}if(o||(o=!(!c||!v)),l||(l=!!f),u||(u=!!h),m||h&&!r.isAudioSupported(h)||f&&!r.isVideoSupported(f))r.log('Some or all CODECS not supported "'+d.CODECS+'"');else{var E=d.CODECS,T=d["FRAME-RATE"],S=d["HDCP-LEVEL"],L=d["PATHWAY-ID"],R=d.RESOLUTION,A=d["VIDEO-RANGE"],b=(L||".")+"-"+e.bitrate+"-"+R+"-"+T+"-"+E+"-"+A+"-"+S;if(n[b])if(n[b].uri===e.url||e.attrs["PATHWAY-ID"])n[b].addGroupId("audio",d.AUDIO),n[b].addGroupId("text",d.SUBTITLES);else{var D=s[b]+=1;e.attrs["PATHWAY-ID"]=new Array(D+1).join(".");var k=r.createLevel(e);n[b]=k,a.push(k)}else{var _=r.createLevel(e);n[b]=_,s[b]=1,a.push(_)}}})),this.filterAndSortMediaOptions(a,t,o,l,u)},r.createLevel=function(e){var t=new et(e),r=e.supplemental;if(null!=r&&r.videoCodec&&!this.isVideoSupported(r.videoCodec)){var i=new Error('SUPPLEMENTAL-CODECS not supported "'+r.videoCodec+'"');this.log(i.message),t.supportedResult=q.getUnsupportedResult(i,[])}return t},r.isAudioSupported=function(e){return Me(e,"audio",this.hls.config.preferManagedMediaSource)},r.isVideoSupported=function(e){return Me(e,"video",this.hls.config.preferManagedMediaSource)},r.filterAndSortMediaOptions=function(e,t,r,i,a){var n=this,s=[],o=[],l=e;if((r||i)&&a&&(l=l.filter((function(e){var t,r=e.videoCodec,i=e.videoRange,a=e.width,n=e.height;return(!!r||!(!a||!n))&&!!(t=i)&&Xe.indexOf(t)>-1}))),0!==l.length){t.audioTracks&&Va(s=t.audioTracks.filter((function(e){return!e.audioCodec||n.isAudioSupported(e.audioCodec)}))),t.subtitles&&Va(o=t.subtitles);var u=l.slice(0);l.sort((function(e,t){if(e.attrs["HDCP-LEVEL"]!==t.attrs["HDCP-LEVEL"])return(e.attrs["HDCP-LEVEL"]||"")>(t.attrs["HDCP-LEVEL"]||"")?1:-1;if(r&&e.height!==t.height)return e.height-t.height;if(e.frameRate!==t.frameRate)return e.frameRate-t.frameRate;if(e.videoRange!==t.videoRange)return Xe.indexOf(e.videoRange)-Xe.indexOf(t.videoRange);if(e.videoCodec!==t.videoCodec){var i=Be(e.videoCodec),a=Be(t.videoCodec);if(i!==a)return a-i}if(e.uri===t.uri&&e.codecSet!==t.codecSet){var n=Ue(e.codecSet),s=Ue(t.codecSet);if(n!==s)return s-n}return e.averageBitrate!==t.averageBitrate?e.averageBitrate-t.averageBitrate:0}));var d=u[0];if(this.steering&&(l=this.steering.filterParsedLevels(l)).length!==u.length)for(var h=0;hg&&g===this.hls.abrEwmaDefaultEstimate&&(this.hls.bandwidthEstimate=m)}break}var p=a&&!i,y=this.hls.config,E=!(!y.audioStreamController||!y.audioTrackController),T={levels:l,audioTracks:s,subtitleTracks:o,sessionData:t.sessionData,sessionKeys:t.sessionKeys,firstLevel:this._firstLevel,stats:t.stats,audio:a,video:i,altAudio:E&&!p&&s.some((function(e){return!!e.url}))};this.hls.trigger(k.MANIFEST_PARSED,T)}else Promise.resolve().then((function(){if(n.hls){var e="no level with compatible codecs found in manifest",r=e;t.levels.length&&(r="one or more CODECS in variant not supported: "+it(t.levels.map((function(e){return e.attrs.CODECS})).filter((function(e,t,r){return r.indexOf(e)===t}))),n.warn(r),e+=" ("+r+")");var i=new Error(e);n.hls.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:t.url,error:i,reason:r})}}))},r.onError=function(e,t){!t.fatal&&t.context&&t.context.type===I&&t.context.level===this.level&&this.checkRetry(t)},r.onFragBuffered=function(e,t){var r=t.frag;if(void 0!==r&&r.type===P){var i=r.elementaryStreams;if(!Object.keys(i).some((function(e){return!!i[e]})))return;var a=this._levels[r.level];null!=a&&a.loadError&&(this.log("Resetting level error count of "+a.loadError+" on frag buffered"),a.loadError=0)}},r.onLevelLoaded=function(e,t){var r,i,a=t.level,n=t.details,s=t.levelInfo;if(!s)return this.warn("Invalid level index "+a),void(null!=(i=t.deliveryDirectives)&&i.skip&&(n.deltaUpdateFailed=!0));if(s===this.currentLevel||t.withoutMultiVariant){0===s.fragmentError&&(s.loadError=0);var o=s.details;o===t.details&&o.advanced&&(o=void 0),this.playlistLoaded(a,t,o)}else null!=(r=t.deliveryDirectives)&&r.skip&&(n.deltaUpdateFailed=!0)},r.loadPlaylist=function(t){e.prototype.loadPlaylist.call(this),this.shouldLoadPlaylist(this.currentLevel)&&this.scheduleLoading(this.currentLevel,t)},r.loadingPlaylist=function(t,r){e.prototype.loadingPlaylist.call(this,t,r);var i=this.getUrlWithDirectives(t.uri,r),a=this.currentLevelIndex,n=t.attrs["PATHWAY-ID"],s=t.details,o=null==s?void 0:s.age;this.log("Loading level index "+a+(void 0!==(null==r?void 0:r.msn)?" at sn "+r.msn+" part "+r.part:"")+(n?" Pathway "+n:"")+(o&&s.live?" age "+o.toFixed(1)+(s.type&&" "+s.type||""):"")+" "+i),this.hls.trigger(k.LEVEL_LOADING,{url:i,level:a,levelInfo:t,pathwayId:t.attrs["PATHWAY-ID"],id:0,deliveryDirectives:r||null})},r.removeLevel=function(e){var t,r=this;if(1!==this._levels.length){var i=this._levels.filter((function(t,i){return i!==e||(r.steering&&r.steering.removeLevel(t),t===r.currentLevel&&(r.currentLevel=null,r.currentLevelIndex=-1,t.details&&t.details.fragments.forEach((function(e){return e.level=-1}))),!1)}));Er(i),this._levels=i,this.currentLevelIndex>-1&&null!=(t=this.currentLevel)&&t.details&&(this.currentLevelIndex=this.currentLevel.details.fragments[0].level),this.manualLevelIndex>-1&&(this.manualLevelIndex=this.currentLevelIndex);var a=i.length-1;this._firstLevel=Math.min(this._firstLevel,a),this._startLevel&&(this._startLevel=Math.min(this._startLevel,a)),this.hls.trigger(k.LEVELS_UPDATED,{levels:i})}},r.onLevelsUpdated=function(e,t){var r=t.levels;this._levels=r},r.checkMaxAutoUpdated=function(){var e=this.hls,t=e.autoLevelCapping,r=e.maxAutoLevel,i=e.maxHdcpLevel;this._maxAutoLevel!==r&&(this._maxAutoLevel=r,this.hls.trigger(k.MAX_AUTO_LEVEL_UPDATED,{autoLevelCapping:t,levels:this.levels,maxAutoLevel:r,minAutoLevel:this.hls.minAutoLevel,maxHdcpLevel:i}))},i(t,[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"loadLevelObj",get:function(){return this.currentLevel}},{key:"level",get:function(){return this.currentLevelIndex},set:function(e){var t=this._levels;if(0!==t.length){if(e<0||e>=t.length){var r=new Error("invalid level idx"),i=e<0;if(this.hls.trigger(k.ERROR,{type:b.OTHER_ERROR,details:D.LEVEL_SWITCH_ERROR,level:e,fatal:i,error:r,reason:r.message}),i)return;e=Math.min(e,t.length-1)}var a=this.currentLevelIndex,n=this.currentLevel,s=n?n.attrs["PATHWAY-ID"]:void 0,o=t[e],l=o.attrs["PATHWAY-ID"];if(this.currentLevelIndex=e,this.currentLevel=o,a!==e||!n||s!==l){this.log("Switching to level "+e+" ("+(o.height?o.height+"p ":"")+(o.videoRange?o.videoRange+" ":"")+(o.codecSet?o.codecSet+" ":"")+"@"+o.bitrate+")"+(l?" with Pathway "+l:"")+" from level "+a+(s?" with Pathway "+s:""));var u={level:e,attrs:o.attrs,details:o.details,bitrate:o.bitrate,averageBitrate:o.averageBitrate,maxBitrate:o.maxBitrate,realBitrate:o.realBitrate,width:o.width,height:o.height,codecSet:o.codecSet,audioCodec:o.audioCodec,videoCodec:o.videoCodec,audioGroups:o.audioGroups,subtitleGroups:o.subtitleGroups,loaded:o.loaded,loadError:o.loadError,fragmentError:o.fragmentError,name:o.name,id:o.id,uri:o.uri,url:o.url,urlId:0,audioGroupIds:o.audioGroupIds,textGroupIds:o.textGroupIds};this.hls.trigger(k.LEVEL_SWITCHING,u);var d=o.details;if(!d||d.live){var h=this.switchParams(o.uri,null==n?void 0:n.details,d);this.loadPlaylist(h)}}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(e){this.manualLevelIndex=e,void 0===this._startLevel&&(this._startLevel=e),-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var e=this.hls.config.startLevel;return void 0!==e?e:this.hls.firstAutoLevel}return this._startLevel},set:function(e){this._startLevel=e}},{key:"pathways",get:function(){return this.steering?this.steering.pathways():[]}},{key:"pathwayPriority",get:function(){return this.steering?this.steering.pathwayPriority:null},set:function(e){if(this.steering){var t=this.steering.pathways(),r=e.filter((function(e){return-1!==t.indexOf(e)}));if(e.length<1)return void this.warn("pathwayPriority "+e+" should contain at least one pathway from list: "+t);this.steering.pathwayPriority=r}}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(e){this.level=e,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=e)}}])}(Ua);function Va(e){var t={};e.forEach((function(e){var r=e.groupId||"";e.id=t[r]=t[r]||0,t[r]++}))}var Ha=[];function Ka(e,t,r){if(!((i=t.remuxResult).audio||i.video||i.text||i.id3||i.initSegment))return!1;var i,a=[],n=t.remuxResult,s=n.audio,o=n.video;return s&&Wa(a,s),o&&Wa(a,o),e.postMessage({event:"transmuxComplete",data:t,instanceNo:r},a),!0}function Wa(e,t){t.data1&&e.push(t.data1.buffer),t.data2&&e.push(t.data2.buffer)}function Ya(e,t,r,i){t.reduce((function(t,r){return Ka(e,r,i)||t}),!1)||e.postMessage({event:"transmuxComplete",data:t[0],instanceNo:i}),e.postMessage({event:"flush",data:r,instanceNo:i})}function ja(e,t,r){self.postMessage({event:e,data:t,instanceNo:r})}void 0!==t&&t&&self.addEventListener("message",(function(e){var t=e.data,r=t.instanceNo;if(void 0!==r){var i=Ha[r];if("reset"===t.cmd&&(delete Ha[t.resetNo],i&&i.destroy(),t.cmd="init"),"init"===t.cmd){var a=JSON.parse(t.config),n=new E;n.on(k.FRAG_DECRYPTED,ja),n.on(k.ERROR,ja);var s=K(a.debug,t.id);return function(e,t){var r=function(r){var i=function(e){ja("workerLog",{logType:r,message:e},t)};e[r]=i};for(var i in e)r(i)}(s,r),Ha[r]=new Wi(n,t.typeSupported,a,"",t.id,s),void ja("init",null,r)}if(i)switch(t.cmd){case"configure":i.configure(t.config);break;case"demux":var o=i.push(t.data,t.decryptdata,t.chunkMeta,t.state);ji(o)?o.then((function(e){Ka(self,e,r)})).catch((function(e){ja(k.ERROR,{instanceNo:r,type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,chunkMeta:t.chunkMeta,fatal:!1,error:e,err:e,reason:"transmuxer-worker push error"},r)})):Ka(self,o,r);break;case"flush":var l=t.chunkMeta,u=i.flush(l);ji(u)?u.then((function(e){Ya(self,e,l,r)})).catch((function(e){ja(k.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,chunkMeta:t.chunkMeta,fatal:!1,error:e,err:e,reason:"transmuxer-worker flush error"},r)})):Ya(self,u,l,r)}}}));var qa="1.6.2",Xa={},za=0,Qa=function(){function t(t,r,i,a){var n=this;this.error=null,this.hls=void 0,this.id=void 0,this.instanceNo=za++,this.observer=void 0,this.frag=null,this.part=null,this.useWorker=void 0,this.workerContext=null,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0,this.onWorkerMessage=function(e){var t=e.data,r=n.hls;if(r&&null!=t&&t.event&&t.instanceNo===n.instanceNo)switch(t.event){case"init":var i,a=null==(i=n.workerContext)?void 0:i.objectURL;a&&self.URL.revokeObjectURL(a);break;case"transmuxComplete":n.handleTransmuxComplete(t.data);break;case"flush":n.onFlush(t.data);break;case"workerLog":r.logger[t.data.logType]&&r.logger[t.data.logType](t.data.message);break;default:t.data=t.data||{},t.data.frag=n.frag,t.data.part=n.part,t.data.id=n.id,r.trigger(t.event,t.data)}},this.onWorkerError=function(e){if(n.hls){var t=new Error(e.message+" ("+e.filename+":"+e.lineno+")");n.hls.config.enableWorker=!1,n.hls.logger.warn('Error in "'+n.id+'" Web Worker, fallback to inline'),n.hls.trigger(k.ERROR,{type:b.OTHER_ERROR,details:D.INTERNAL_EXCEPTION,fatal:!1,event:"demuxerWorker",error:t})}};var s=t.config;this.hls=t,this.id=r,this.useWorker=!!s.enableWorker,this.onTransmuxComplete=i,this.onFlush=a;var o=function(e,t){(t=t||{}).frag=n.frag||void 0,e===k.ERROR&&(t.parent=n.id,t.part=n.part,n.error=t.error),n.hls.trigger(e,t)};this.observer=new E,this.observer.on(k.FRAG_DECRYPTED,o),this.observer.on(k.ERROR,o);var l=Ye(s.preferManagedMediaSource);if(this.useWorker&&"undefined"!=typeof Worker){var u=this.hls.logger;s.workerPath;try{s.workerPath?(u.log("loading Web Worker "+s.workerPath+' for "'+r+'"'),this.workerContext=function(e){var t=Xa[e];if(t)return t.clientCount++,t;var r=new self.URL(e,self.location.href).href,i={worker:new self.Worker(r),scriptURL:r,clientCount:1};return Xa[e]=i,i}(s.workerPath)):(u.log('injecting Web Worker for "'+r+'"'),this.workerContext=function(){var t=Xa[qa];if(t)return t.clientCount++,t;var r=new self.Blob(["var exports={};var module={exports:exports};function define(f){f()};define.amd=true;("+e.toString()+")(true);"],{type:"text/javascript"}),i=self.URL.createObjectURL(r),a={worker:new self.Worker(i),objectURL:i,clientCount:1};return Xa[qa]=a,a}());var d=this.workerContext.worker;d.addEventListener("message",this.onWorkerMessage),d.addEventListener("error",this.onWorkerError),d.postMessage({instanceNo:this.instanceNo,cmd:"init",typeSupported:l,id:r,config:it(s)})}catch(e){u.warn('Error setting up "'+r+'" Web Worker, fallback to inline',e),this.terminateWorker(),this.error=null,this.transmuxer=new Wi(this.observer,l,s,"",r,t.logger)}}else this.transmuxer=new Wi(this.observer,l,s,"",r,t.logger)}var r=t.prototype;return r.reset=function(){if(this.frag=null,this.part=null,this.workerContext){var e=this.instanceNo;this.instanceNo=za++;var t=this.hls.config,r=Ye(t.preferManagedMediaSource);this.workerContext.worker.postMessage({instanceNo:this.instanceNo,cmd:"reset",resetNo:e,typeSupported:r,id:this.id,config:it(t)})}},r.terminateWorker=function(){if(this.workerContext){var e=this.workerContext.worker;this.workerContext=null,e.removeEventListener("message",this.onWorkerMessage),e.removeEventListener("error",this.onWorkerError),function(e){var t=Xa[e||qa];if(t&&1==t.clientCount--){var r=t.worker,i=t.objectURL;delete Xa[e||qa],i&&self.URL.revokeObjectURL(i),r.terminate()}}(this.hls.config.workerPath)}},r.destroy=function(){if(this.workerContext)this.terminateWorker(),this.onWorkerMessage=this.onWorkerError=null;else{var e=this.transmuxer;e&&(e.destroy(),this.transmuxer=null)}var t=this.observer;t&&t.removeAllListeners(),this.frag=null,this.part=null,this.observer=null,this.hls=null},r.push=function(e,t,r,i,a,n,s,o,l,u){var d,h,f=this;l.transmuxing.start=self.performance.now();var c=this.instanceNo,v=this.transmuxer,g=n?n.start:a.start,m=a.decryptdata,p=this.frag,y=!(p&&a.cc===p.cc),E=!(p&&l.level===p.level),T=p?l.sn-p.sn:-1,S=this.part?l.part-this.part.index:-1,L=0===T&&l.id>1&&l.id===(null==p?void 0:p.stats.chunkCount),R=!E&&(1===T||0===T&&(1===S||L&&S<=0)),A=self.performance.now();(E||T||0===a.stats.parsing.start)&&(a.stats.parsing.start=A),!n||!S&&R||(n.stats.parsing.start=A);var b=!(p&&(null==(d=a.initSegment)?void 0:d.url)===(null==(h=p.initSegment)?void 0:h.url)),D=new Xi(y,R,o,E,g,b);if(!R||y||b){this.hls.logger.log("[transmuxer-interface]: Starting new transmux session for "+a.type+" sn: "+l.sn+(l.part>-1?" part: "+l.part:"")+" "+(this.id===P?"level":"track")+": "+l.level+" id: "+l.id+"\n discontinuity: "+y+"\n trackSwitch: "+E+"\n contiguous: "+R+"\n accurateTimeOffset: "+o+"\n timeOffset: "+g+"\n initSegmentChange: "+b);var k=new qi(r,i,t,s,u);this.configureTransmuxer(k)}if(this.frag=a,this.part=n,this.workerContext)this.workerContext.worker.postMessage({instanceNo:c,cmd:"demux",data:e,decryptdata:m,chunkMeta:l,state:D},e instanceof ArrayBuffer?[e]:[]);else if(v){var _=v.push(e,m,l,D);ji(_)?_.then((function(e){f.handleTransmuxComplete(e)})).catch((function(e){f.transmuxerError(e,l,"transmuxer-interface push error")})):this.handleTransmuxComplete(_)}},r.flush=function(e){var t=this;e.transmuxing.start=self.performance.now();var r=this.instanceNo,i=this.transmuxer;if(this.workerContext)this.workerContext.worker.postMessage({instanceNo:r,cmd:"flush",chunkMeta:e});else if(i){var a=i.flush(e);ji(a)?a.then((function(r){t.handleFlushResult(r,e)})).catch((function(r){t.transmuxerError(r,e,"transmuxer-interface flush error")})):this.handleFlushResult(a,e)}},r.transmuxerError=function(e,t,r){this.hls&&(this.error=e,this.hls.trigger(k.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,chunkMeta:t,frag:this.frag||void 0,part:this.part||void 0,fatal:!1,error:e,err:e,reason:r}))},r.handleFlushResult=function(e,t){var r=this;e.forEach((function(e){r.handleTransmuxComplete(e)})),this.onFlush(t)},r.configureTransmuxer=function(e){var t=this.instanceNo,r=this.transmuxer;this.workerContext?this.workerContext.worker.postMessage({instanceNo:t,cmd:"configure",config:e}):r&&r.configure(e)},r.handleTransmuxComplete=function(e){e.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(e)},t}();function $a(){return self.SourceBuffer||self.WebKitSourceBuffer}function Za(){if(!xe())return!1;var e=$a();return!e||e.prototype&&"function"==typeof e.prototype.appendBuffer&&"function"==typeof e.prototype.remove}var Ja=function(e){function t(t,r,i){var a;return(a=e.call(this,t,r,i,"stream-controller",P)||this).audioCodecSwap=!1,a.level=-1,a._forceStartLoad=!1,a._hasEnoughToStart=!1,a.altAudio=0,a.audioOnly=!1,a.fragPlaying=null,a.fragLastKbps=0,a.couldBacktrack=!1,a.backtrackFragment=null,a.audioCodecSwitch=!1,a.videoBuffer=null,a.onMediaPlaying=function(){a.tick()},a.onMediaSeeked=function(){var e=a.media,t=e?e.currentTime:null;if(null!==t&&L(t)&&(a.log("Media seeked to "+t.toFixed(3)),a.getBufferedFrag(t))){var r=a.getFwdBufferInfoAtPos(e,t,P,0);null!==r&&0!==r.len?a.tick():a.warn("Main forward buffer length at "+t+' on "seeked" event '+(r?r.len:"empty")+")")}},a.registerListeners(),a}o(t,e);var r=t.prototype;return r.registerListeners=function(){e.prototype.registerListeners.call(this);var t=this.hls;t.on(k.MANIFEST_PARSED,this.onManifestParsed,this),t.on(k.LEVEL_LOADING,this.onLevelLoading,this),t.on(k.LEVEL_LOADED,this.onLevelLoaded,this),t.on(k.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.on(k.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.on(k.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.on(k.BUFFER_CREATED,this.onBufferCreated,this),t.on(k.BUFFER_FLUSHED,this.onBufferFlushed,this),t.on(k.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(k.FRAG_BUFFERED,this.onFragBuffered,this)},r.unregisterListeners=function(){e.prototype.unregisterListeners.call(this);var t=this.hls;t.off(k.MANIFEST_PARSED,this.onManifestParsed,this),t.off(k.LEVEL_LOADED,this.onLevelLoaded,this),t.off(k.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.off(k.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.off(k.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.off(k.BUFFER_CREATED,this.onBufferCreated,this),t.off(k.BUFFER_FLUSHED,this.onBufferFlushed,this),t.off(k.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(k.FRAG_BUFFERED,this.onFragBuffered,this)},r.onHandlerDestroying=function(){this.onMediaPlaying=this.onMediaSeeked=null,this.unregisterListeners(),e.prototype.onHandlerDestroying.call(this)},r.startLoad=function(e,t){if(this.levels){var r=this.lastCurrentTime,i=this.hls;if(this.stopLoad(),this.setInterval(100),this.level=-1,!this.startFragRequested){var a=i.startLevel;-1===a&&(i.config.testBandwidth&&this.levels.length>1?(a=0,this.bitrateTest=!0):a=i.firstAutoLevel),i.nextLoadLevel=a,this.level=i.loadLevel,this._hasEnoughToStart=!!t}r>0&&-1===e&&!t&&(this.log("Override startPosition with lastCurrentTime @"+r.toFixed(3)),e=r),this.state=ba.IDLE,this.nextLoadPosition=this.lastCurrentTime=e+this.timelineOffset,this.startPosition=t?-1:e,this.tick()}else this._forceStartLoad=!0,this.state=ba.STOPPED},r.stopLoad=function(){this._forceStartLoad=!1,e.prototype.stopLoad.call(this)},r.doTick=function(){switch(this.state){case ba.WAITING_LEVEL:var e=this.levels,t=this.level,r=null==e?void 0:e[t],i=null==r?void 0:r.details;if(i&&(!i.live||this.levelLastLoaded===r&&!this.waitForLive(r))){if(this.waitForCdnTuneIn(i))break;this.state=ba.IDLE;break}if(this.hls.nextLoadLevel!==this.level){this.state=ba.IDLE;break}break;case ba.FRAG_LOADING_WAITING_RETRY:var a,n=self.performance.now(),s=this.retryDate;if(!s||n>=s||null!=(a=this.media)&&a.seeking){var o=this.levels,l=this.level,u=null==o?void 0:o[l];this.resetStartWhenNotLoaded(u||null),this.state=ba.IDLE}}this.state===ba.IDLE&&this.doTickIdle(),this.onTickEnd()},r.onTickEnd=function(){var t;e.prototype.onTickEnd.call(this),null!=(t=this.media)&&t.readyState&&!1===this.media.seeking&&(this.lastCurrentTime=this.media.currentTime),this.checkFragmentChanged()},r.doTickIdle=function(){var e=this.hls,t=this.levelLastLoaded,r=this.levels,i=this.media;if(null!==t&&(i||this.primaryPrefetch||!this.startFragRequested&&e.config.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)){var a=this.buffering?e.nextLoadLevel:e.loadLevel;if(null!=r&&r[a]){var n=r[a],s=this.getMainFwdBufferInfo();if(null!==s){var o=this.getLevelDetails();if(o&&this._streamEnded(s,o)){var l={};return 2===this.altAudio&&(l.type="video"),this.hls.trigger(k.BUFFER_EOS,l),void(this.state=ba.ENDED)}if(this.buffering){e.loadLevel!==a&&-1===e.manualLevel&&this.log("Adapting to level "+a+" from level "+this.level),this.level=e.nextLoadLevel=a;var u=n.details;if(!u||this.state===ba.WAITING_LEVEL||this.waitForLive(n))return this.level=a,this.state=ba.WAITING_LEVEL,void(this.startFragRequested=!1);var d=s.len,h=this.getMaxBufferLength(n.maxBitrate);if(!(d>=h)){this.backtrackFragment&&this.backtrackFragment.start>s.end&&(this.backtrackFragment=null);var f=this.backtrackFragment?this.backtrackFragment.start:s.end,c=this.getNextFragment(f,u);if(this.couldBacktrack&&!this.fragPrevious&&c&&re(c)&&this.fragmentTracker.getState(c)!==la){var v,g=(null!=(v=this.backtrackFragment)?v:c).sn-u.startSN,m=u.fragments[g-1];m&&c.cc===m.cc&&(c=m,this.fragmentTracker.removeFragment(m))}else this.backtrackFragment&&s.len&&(this.backtrackFragment=null);if(c&&this.isLoopLoading(c,f)){if(!c.gap){var p=this.audioOnly&&!this.altAudio?Z:J,y=(p===J?this.videoBuffer:this.mediaBuffer)||this.media;y&&this.afterBufferFlushed(y,p,P)}c=this.getNextFragmentLoopLoading(c,u,s,P,h)}c&&(!c.initSegment||c.initSegment.data||this.bitrateTest||(c=c.initSegment),this.loadFragment(c,n,f))}}}}}},r.loadFragment=function(t,r,i){var a=this.fragmentTracker.getState(t);a===na||a===oa?re(t)?this.bitrateTest?(this.log("Fragment "+t.sn+" of level "+t.level+" is being downloaded to test bitrate and will not be buffered"),this._loadBitrateTestFrag(t,r)):e.prototype.loadFragment.call(this,t,r,i):this._loadInitSegment(t,r):this.clearTrackerIfNeeded(t)},r.getBufferedFrag=function(e){return this.fragmentTracker.getBufferedFrag(e,P)},r.followingBufferedFrag=function(e){return e?this.getBufferedFrag(e.end+.5):null},r.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},r.nextLevelSwitch=function(){var e=this.levels,t=this.media;if(null!=t&&t.readyState){var r,i=this.getAppendedFrag(t.currentTime);i&&i.start>1&&this.flushMainBuffer(0,i.start-1);var a=this.getLevelDetails();if(null!=a&&a.live){var n=this.getMainFwdBufferInfo();if(!n||n.len<2*a.targetduration)return}if(!t.paused&&e){var s=e[this.hls.nextLoadLevel],o=this.fragLastKbps;r=o&&this.fragCurrent?this.fragCurrent.duration*s.maxBitrate/(1e3*o)+1:0}else r=0;var l=this.getBufferedFrag(t.currentTime+r);if(l){var u=this.followingBufferedFrag(l);if(u){this.abortCurrentFrag();var d=u.maxStartPTS?u.maxStartPTS:u.start,h=u.duration,f=Math.max(l.end,d+Math.min(Math.max(h-this.config.maxFragLookUpTolerance,h*(this.couldBacktrack?.5:.125)),h*(this.couldBacktrack?.75:.25)));this.flushMainBuffer(f,Number.POSITIVE_INFINITY)}}}},r.abortCurrentFrag=function(){var e=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,e&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.state){case ba.KEY_LOADING:case ba.FRAG_LOADING:case ba.FRAG_LOADING_WAITING_RETRY:case ba.PARSING:case ba.PARSED:this.state=ba.IDLE}this.nextLoadPosition=this.getLoadPosition()},r.flushMainBuffer=function(t,r){e.prototype.flushMainBuffer.call(this,t,r,2===this.altAudio?"video":null)},r.onMediaAttached=function(t,r){e.prototype.onMediaAttached.call(this,t,r);var i=r.media;ka(i,"playing",this.onMediaPlaying),ka(i,"seeked",this.onMediaSeeked)},r.onMediaDetaching=function(t,r){var i=this.media;i&&(_a(i,"playing",this.onMediaPlaying),_a(i,"seeked",this.onMediaSeeked)),this.videoBuffer=null,this.fragPlaying=null,e.prototype.onMediaDetaching.call(this,t,r),r.transferMedia||(this._hasEnoughToStart=!1)},r.onManifestLoading=function(){e.prototype.onManifestLoading.call(this),this.log("Trigger BUFFER_RESET"),this.hls.trigger(k.BUFFER_RESET,void 0),this.couldBacktrack=!1,this.fragLastKbps=0,this.fragPlaying=this.backtrackFragment=null,this.altAudio=0,this.audioOnly=!1},r.onManifestParsed=function(e,t){var r,i,a=!1,n=!1;t.levels.forEach((function(e){var t=e.audioCodec;t&&(a=a||-1!==t.indexOf("mp4a.40.2"),n=n||-1!==t.indexOf("mp4a.40.5"))})),this.audioCodecSwitch=a&&n&&!("function"==typeof(null==(i=$a())||null==(r=i.prototype)?void 0:r.changeType)),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=t.levels,this.startFragRequested=!1},r.onLevelLoading=function(e,t){if(this.levels&&this.state===ba.IDLE){var r=t.levelInfo;(!r.details||r.details.live&&(this.levelLastLoaded!==r||r.details.expired)||this.waitForCdnTuneIn(r.details))&&(this.state=ba.WAITING_LEVEL)}},r.onLevelLoaded=function(e,t){var r,i=this.levels,a=this.startFragRequested,n=t.level,s=t.details,o=s.totalduration;if(i){this.log("Level "+n+" loaded ["+s.startSN+","+s.endSN+"]"+(s.lastPartSn?"[part-"+s.lastPartSn+"-"+s.lastPartIndex+"]":"")+", cc ["+s.startCC+", "+s.endCC+"] duration:"+o);var l=t.levelInfo,u=this.fragCurrent;!u||this.state!==ba.FRAG_LOADING&&this.state!==ba.FRAG_LOADING_WAITING_RETRY||u.level!==t.level&&u.loader&&this.abortCurrentFrag();var d=0;if(s.live||null!=(r=l.details)&&r.live){var h;if(this.checkLiveUpdate(s),s.deltaUpdateFailed)return;d=this.alignPlaylists(s,l.details,null==(h=this.levelLastLoaded)?void 0:h.details)}if(l.details=s,this.levelLastLoaded=l,a||this.setStartPosition(s,d),this.hls.trigger(k.LEVEL_UPDATED,{details:s,level:n}),this.state===ba.WAITING_LEVEL){if(this.waitForCdnTuneIn(s))return;this.state=ba.IDLE}a&&s.live&&this.synchronizeToLiveEdge(s),this.tick()}else this.warn("Levels were reset while loading level "+n)},r.synchronizeToLiveEdge=function(e){var t=this.config,r=this.media;if(r){var i=this.hls.liveSyncPosition,a=this.getLoadPosition(),n=e.fragmentStart,s=e.edge,o=a>=n-t.maxFragLookUpTolerance&&a<=s;if(null!==i&&r.duration>i&&(a-1&&this.fragCurrent&&(this.level=this.fragCurrent.level,-1===this.level&&this.resetWhenMissingContext(this.fragCurrent)),this.levels=t.levels},r.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},r.seekToStartPos=function(){var e=this.media;if(e){var t=e.currentTime,r=this.startPosition;if(r>=0&&t0&&(oE.cc;if(!1!==a.independent){var R=d.startPTS,A=d.endPTS,b=d.startDTS,D=d.endDTS;if(l)l.elementaryStreams[d.type]={startPTS:R,endPTS:A,startDTS:b,endDTS:D};else if(d.firstKeyFrame&&d.independent&&1===n.id&&!S&&(this.couldBacktrack=!0),d.dropped&&d.independent){var _=this.getMainFwdBufferInfo(),I=(_?_.end:this.getLoadPosition())+this.config.maxBufferHole,C=d.firstKeyFramePTS?d.firstKeyFramePTS:R;if(!T&&I2&&(o.gap=!0);o.setElementaryStreamInfo(d.type,R,A,b,D),this.backtrackFragment&&(this.backtrackFragment=o),this.bufferFragmentData(d,o,l,n,T||S)}else{if(!T&&!S)return void this.backtrack(o);o.gap=!0}}if(g){var x=g.startPTS,P=g.endPTS,w=g.startDTS,O=g.endDTS;l&&(l.elementaryStreams[Z]={startPTS:x,endPTS:P,startDTS:w,endDTS:O}),o.setElementaryStreamInfo(Z,x,P,w,O),this.bufferFragmentData(g,o,l,n)}if(v&&null!=f&&null!=(t=f.samples)&&t.length){var M={id:r,frag:o,details:v,samples:f.samples};i.trigger(k.FRAG_PARSING_METADATA,M)}if(v&&h){var F={id:r,frag:o,details:v,samples:h.samples};i.trigger(k.FRAG_PARSING_USERDATA,F)}}}else this.resetWhenMissingContext(n)},r.logMuxedErr=function(e){this.warn((re(e)?"Media":"Init")+" segment with muxed audiovideo where only video expected: "+e.url)},r._bufferInitSegment=function(e,t,r,i){var a=this;if(this.state===ba.PARSING){this.audioOnly=!!t.audio&&!t.video,this.altAudio&&!this.audioOnly&&(delete t.audio,t.audiovideo&&this.logMuxedErr(r));var n=t.audio,s=t.video,o=t.audiovideo;if(n){var l=Ke(n.codec,e.audioCodec);"mp4a"===l&&(l="mp4a.40.5");var u=navigator.userAgent.toLowerCase();if(this.audioCodecSwitch){l&&(l=-1!==l.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5");var d=n.metadata;d&&"channelCount"in d&&1!==(d.channelCount||1)&&-1===u.indexOf("firefox")&&(l="mp4a.40.5")}l&&-1!==l.indexOf("mp4a.40.5")&&-1!==u.indexOf("android")&&"audio/mpeg"!==n.container&&(l="mp4a.40.2",this.log("Android: force audio codec to "+l)),e.audioCodec&&e.audioCodec!==l&&this.log('Swapping manifest audio codec "'+e.audioCodec+'" for "'+l+'"'),n.levelCodec=l,n.id=P,this.log("Init audio buffer, container:"+n.container+", codecs[selected/level/parsed]=["+(l||"")+"/"+(e.audioCodec||"")+"/"+n.codec+"]"),delete t.audiovideo}if(s){s.levelCodec=e.videoCodec,s.id=P;var h=s.codec;if(4===(null==h?void 0:h.length))switch(h){case"hvc1":case"hev1":s.codec="hvc1.1.6.L120.90";break;case"av01":s.codec="av01.0.04M.08";break;case"avc1":s.codec="avc1.42e01e"}this.log("Init video buffer, container:"+s.container+", codecs[level/parsed]=["+(e.videoCodec||"")+"/"+h+"]"+(s.codec!==h?" parsed-corrected="+s.codec:"")+(s.supplemental?" supplemental="+s.supplemental:"")),delete t.audiovideo}o&&(this.log("Init audiovideo buffer, container:"+o.container+", codecs[level/parsed]=["+e.codecs+"/"+o.codec+"]"),delete t.video,delete t.audio);var f=Object.keys(t);if(f.length){if(this.hls.trigger(k.BUFFER_CODECS,t),!this.hls)return;f.forEach((function(e){var n=t[e].initSegment;null!=n&&n.byteLength&&a.hls.trigger(k.BUFFER_APPENDING,{type:e,data:n,frag:r,part:null,chunkMeta:i,parent:r.type})}))}this.tickImmediate()}},r.getMainFwdBufferInfo=function(){var e=this.mediaBuffer&&2===this.altAudio?this.mediaBuffer:this.media;return this.getFwdBufferInfo(e,P)},r.backtrack=function(e){this.couldBacktrack=!0,this.backtrackFragment=e,this.resetTransmuxer(),this.flushBufferGap(e),this.fragmentTracker.removeFragment(e),this.fragPrevious=null,this.nextLoadPosition=e.start,this.state=ba.IDLE},r.checkFragmentChanged=function(){var e=this.media,t=null;if(e&&e.readyState>1&&!1===e.seeking){var r=e.currentTime;if(_t.isBuffered(e,r)?t=this.getAppendedFrag(r):_t.isBuffered(e,r+.1)&&(t=this.getAppendedFrag(r+.1)),t){this.backtrackFragment=null;var i=this.fragPlaying,a=t.level;i&&t.sn===i.sn&&i.level===a||(this.fragPlaying=t,this.hls.trigger(k.FRAG_CHANGED,{frag:t}),i&&i.level===a||this.hls.trigger(k.LEVEL_SWITCHED,{level:a}))}}},i(t,[{key:"hasEnoughToStart",get:function(){return this._hasEnoughToStart}},{key:"maxBufferLength",get:function(){var e=this.levels,t=this.level,r=null==e?void 0:e[t];return r?this.getMaxBufferLength(r.maxBitrate):this.config.maxBufferLength}},{key:"nextLevel",get:function(){var e=this.nextBufferedFrag;return e?e.level:-1}},{key:"currentFrag",get:function(){var e;if(this.fragPlaying)return this.fragPlaying;var t=(null==(e=this.media)?void 0:e.currentTime)||this.lastCurrentTime;return L(t)?this.getAppendedFrag(t):null}},{key:"currentProgramDateTime",get:function(){var e,t=(null==(e=this.media)?void 0:e.currentTime)||this.lastCurrentTime;if(L(t)){var r=this.getLevelDetails(),i=this.currentFrag||(r?dt(null,r.fragments,t):null);if(i){var a=i.programDateTime;if(null!==a){var n=a+1e3*(t-i.start);return new Date(n)}}}return null}},{key:"currentLevel",get:function(){var e=this.currentFrag;return e?e.level:-1}},{key:"nextBufferedFrag",get:function(){var e=this.currentFrag;return e?this.followingBufferedFrag(e):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}])}(Da),en=function(){function e(e){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=e}var t=e.prototype;return t.abort=function(e){for(var t in this.keyUriToKeyInfo){var r=this.keyUriToKeyInfo[t].loader;if(r){var i;if(e&&e!==(null==(i=r.context)?void 0:i.frag.type))return;r.abort()}}},t.detach=function(){for(var e in this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e];(t.mediaKeySessionContext||t.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[e]}},t.destroy=function(){for(var e in this.detach(),this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e].loader;t&&t.destroy()}this.keyUriToKeyInfo={}},t.createKeyLoadError=function(e,t,r,i,a){return void 0===t&&(t=D.KEY_LOAD_ERROR),new pa({type:b.NETWORK_ERROR,details:t,fatal:!1,frag:e,response:a,error:r,networkDetails:i})},t.loadClear=function(e,t){var r=this;if(this.emeController&&this.config.emeEnabled)for(var i=e.sn,a=e.cc,n=function(){var e=t[s];if(a<=e.cc&&("initSegment"===i||"initSegment"===e.sn||i2&&n.push.apply(n,a.split(",").map((function(e){return{type:"media-source",audio:{contentType:Ne(e,"audio"),channels:""+i}}})))}})))})),Promise.all(n.map((function(e){var t=function(e){var t=e.audio,r=e.video,i=r||t;if(i){var a=je(i.contentType);if(r)return"r"+r.height+"x"+r.width+"f"+Math.ceil(r.framerate)+(r.transferFunction||"sd")+"_"+a+"_"+Math.ceil(r.bitrate/1e5);if(t)return"c"+t.channels+(t.spatialRendering?"s":"n")+"_"+a}return""}(e);return sn[t]||(sn[t]=r.decodingInfo(e))}))).then((function(e){return{supported:!e.some((function(e){return!e.supported})),configurations:n,decodingInfoResults:e}})).catch((function(e){return{supported:!1,configurations:n,decodingInfoResults:[],error:e}}))}var ln=function(){function e(t){void 0===t&&(t={}),this.config=void 0,this.userConfig=void 0,this.logger=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this._emitter=new E,this._autoLevelCapping=-1,this._maxHdcpLevel=null,this.abrController=void 0,this.bufferController=void 0,this.capLevelController=void 0,this.latencyController=void 0,this.levelController=void 0,this.streamController=void 0,this.audioStreamController=void 0,this.subtititleStreamController=void 0,this.audioTrackController=void 0,this.subtitleTrackController=void 0,this.interstitialsController=void 0,this.gapController=void 0,this.emeController=void 0,this.cmcdController=void 0,this._media=null,this._url=null,this._sessionId=void 0,this.triggeringException=void 0,this.started=!1;var r=this.logger=K(t.debug||!1,"Hls instance",t.assetPlayerId),i=this.config=function(e,t,r){if((t.liveSyncDurationCount||t.liveMaxLatencyDurationCount)&&(t.liveSyncDuration||t.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==t.liveMaxLatencyDurationCount&&(void 0===t.liveSyncDurationCount||t.liveMaxLatencyDurationCount<=t.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(void 0!==t.liveMaxLatencyDuration&&(void 0===t.liveSyncDuration||t.liveMaxLatencyDuration<=t.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');var i=ia(e),a=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];return["manifest","level","frag"].forEach((function(e){var n=("level"===e?"playlist":e)+"LoadPolicy",s=void 0===t[n],o=[];a.forEach((function(r){var a=e+"Loading"+r,l=t[a];if(void 0!==l&&s){o.push(a);var u=i[n].default;switch(t[n]={default:u},r){case"TimeOut":u.maxLoadTimeMs=l,u.maxTimeToFirstByteMs=l;break;case"MaxRetry":u.errorRetry.maxNumRetry=l,u.timeoutRetry.maxNumRetry=l;break;case"RetryDelay":u.errorRetry.retryDelayMs=l,u.timeoutRetry.retryDelayMs=l;break;case"MaxRetryTimeout":u.errorRetry.maxRetryDelayMs=l,u.timeoutRetry.maxRetryDelayMs=l}}})),o.length&&r.warn('hls.js config: "'+o.join('", "')+'" setting(s) are deprecated, use "'+n+'": '+it(t[n]))})),d(d({},i),t)}(e.DefaultConfig,t,r);this.userConfig=t,i.progressive&&aa(i,r);var a=i.abrController,n=i.bufferController,s=i.capLevelController,o=i.errorController,l=i.fpsController,u=new o(this),h=this.abrController=new a(this),f=new ua(this),c=i.interstitialsController,v=c?this.interstitialsController=new c(this,e):null,g=this.bufferController=new n(this,f),m=this.capLevelController=new s(this),p=new l(this),y=new an(this),T=i.contentSteeringController,S=T?new T(this):null,L=this.levelController=new Ga(this,S),R=new Na(this),A=new en(this.config),b=this.streamController=new Ja(this,f,A),D=this.gapController=new Ia(this,f);m.setStreamController(b),p.setStreamController(b);var _=[y,L,b];v&&_.splice(1,0,v),S&&_.splice(1,0,S),this.networkControllers=_;var I=[h,g,D,m,p,R,f];this.audioTrackController=this.createController(i.audioTrackController,_);var C=i.audioStreamController;C&&_.push(this.audioStreamController=new C(this,f,A)),this.subtitleTrackController=this.createController(i.subtitleTrackController,_);var x=i.subtitleStreamController;x&&_.push(this.subtititleStreamController=new x(this,f,A)),this.createController(i.timelineController,I),A.emeController=this.emeController=this.createController(i.emeController,I),this.cmcdController=this.createController(i.cmcdController,I),this.latencyController=this.createController(Ba,I),this.coreComponents=I,_.push(u);var P=u.onErrorOut;"function"==typeof P&&this.on(k.ERROR,P,u),this.on(k.MANIFEST_LOADED,y.onManifestLoaded,y)}e.isMSESupported=function(){return Za()},e.isSupported=function(){return function(){if(!Za())return!1;var e=xe();return"function"==typeof(null==e?void 0:e.isTypeSupported)&&(["avc1.42E01E,mp4a.40.2","av01.0.01M.08","vp09.00.50.08"].some((function(t){return e.isTypeSupported(Ne(t,"video"))}))||["mp4a.40.2","fLaC"].some((function(t){return e.isTypeSupported(Ne(t,"audio"))})))}()},e.getMediaSource=function(){return xe()};var t=e.prototype;return t.createController=function(e,t){if(e){var r=new e(this);return t&&t.push(r),r}return null},t.on=function(e,t,r){void 0===r&&(r=this),this._emitter.on(e,t,r)},t.once=function(e,t,r){void 0===r&&(r=this),this._emitter.once(e,t,r)},t.removeAllListeners=function(e){this._emitter.removeAllListeners(e)},t.off=function(e,t,r,i){void 0===r&&(r=this),this._emitter.off(e,t,r,i)},t.listeners=function(e){return this._emitter.listeners(e)},t.emit=function(e,t,r){return this._emitter.emit(e,t,r)},t.trigger=function(e,t){if(this.config.debug)return this.emit(e,e,t);try{return this.emit(e,e,t)}catch(t){if(this.logger.error("An internal error happened while handling event "+e+'. Error message: "'+t.message+'". Here is a stacktrace:',t),!this.triggeringException){this.triggeringException=!0;var r=e===k.ERROR;this.trigger(k.ERROR,{type:b.OTHER_ERROR,details:D.INTERNAL_EXCEPTION,fatal:r,event:e,error:t}),this.triggeringException=!1}}return!1},t.listenerCount=function(e){return this._emitter.listenerCount(e)},t.destroy=function(){this.logger.log("destroy"),this.trigger(k.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this._url=null,this.networkControllers.forEach((function(e){return e.destroy()})),this.networkControllers.length=0,this.coreComponents.forEach((function(e){return e.destroy()})),this.coreComponents.length=0;var e=this.config;e.xhrSetup=e.fetchSetup=void 0,this.userConfig=null},t.attachMedia=function(e){if(!e||"media"in e&&!e.media){var t=new Error("attachMedia failed: invalid argument ("+e+")");this.trigger(k.ERROR,{type:b.OTHER_ERROR,details:D.ATTACH_MEDIA_ERROR,fatal:!0,error:t})}else{this.logger.log("attachMedia"),this._media&&(this.logger.warn("media must be detached before attaching"),this.detachMedia());var r="media"in e,i=r?e.media:e,a=r?e:{media:i};this._media=i,this.trigger(k.MEDIA_ATTACHING,a)}},t.detachMedia=function(){this.logger.log("detachMedia"),this.trigger(k.MEDIA_DETACHING,{}),this._media=null},t.transferMedia=function(){this._media=null;var e=this.bufferController.transferMedia();return this.trigger(k.MEDIA_DETACHING,{transferMedia:e}),e},t.loadSource=function(e){this.stopLoad();var t=this.media,r=this._url,i=this._url=S.buildAbsoluteURL(self.location.href,e,{alwaysNormalize:!0});this._autoLevelCapping=-1,this._maxHdcpLevel=null,this.logger.log("loadSource:"+i),t&&r&&(r!==i||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(t)),this.trigger(k.MANIFEST_LOADING,{url:e})},t.startLoad=function(e,t){void 0===e&&(e=-1),this.logger.log("startLoad("+e+(t?", ":"")+")"),this.started=!0,this.resumeBuffering();for(var r=0;r-1?this.abrController.forcedAutoLevel:e},set:function(e){this.logger.log("set startLevel:"+e),-1!==e&&(e=Math.max(e,this.minAutoLevel)),this.levelController.startLevel=e}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(e){var t=!!e;t!==this.config.capLevelToPlayerSize&&(t?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=t)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping!==e&&(this.logger.log("set autoLevelCapping:"+e),this._autoLevelCapping=e,this.levelController.checkMaxAutoUpdated())}},{key:"bandwidthEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimate():NaN},set:function(e){this.abrController.resetEstimator(e)}},{key:"abrEwmaDefaultEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.defaultEstimate:NaN}},{key:"ttfbEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimateTTFB():NaN}},{key:"maxHdcpLevel",get:function(){return this._maxHdcpLevel},set:function(e){(function(e){return qe.indexOf(e)>-1})(e)&&this._maxHdcpLevel!==e&&(this._maxHdcpLevel=e,this.levelController.checkMaxAutoUpdated())}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}},{key:"minAutoLevel",get:function(){var e=this.levels,t=this.config.minAutoBitrate;if(!e)return 0;for(var r=e.length,i=0;i=t)return i;return 0}},{key:"maxAutoLevel",get:function(){var e,t=this.levels,r=this.autoLevelCapping,i=this.maxHdcpLevel;if(e=-1===r&&null!=t&&t.length?t.length-1:r,i)for(var a=e;a--;){var n=t[a].attrs["HDCP-LEVEL"];if(n&&n<=i)return a}return e}},{key:"firstAutoLevel",get:function(){return this.abrController.firstAutoLevel}},{key:"nextAutoLevel",get:function(){return this.abrController.nextAutoLevel},set:function(e){this.abrController.nextAutoLevel=e}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"mainForwardBufferInfo",get:function(){return this.streamController.getMainFwdBufferInfo()}},{key:"maxBufferLength",get:function(){return this.streamController.maxBufferLength}},{key:"allAudioTracks",get:function(){var e=this.audioTrackController;return e?e.allAudioTracks:[]}},{key:"audioTracks",get:function(){var e=this.audioTrackController;return e?e.audioTracks:[]}},{key:"audioTrack",get:function(){var e=this.audioTrackController;return e?e.audioTrack:-1},set:function(e){var t=this.audioTrackController;t&&(t.audioTrack=e)}},{key:"allSubtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.allSubtitleTracks:[]}},{key:"subtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTrack:-1},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleTrack=e)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var e=this.subtitleTrackController;return!!e&&e.subtitleDisplay},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleDisplay=e)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(e){this.config.lowLatencyMode=e}},{key:"liveSyncPosition",get:function(){return this.latencyController.liveSyncPosition}},{key:"latency",get:function(){return this.latencyController.latency}},{key:"maxLatency",get:function(){return this.latencyController.maxLatency}},{key:"targetLatency",get:function(){return this.latencyController.targetLatency},set:function(e){this.latencyController.targetLatency=e}},{key:"drift",get:function(){return this.latencyController.drift}},{key:"forceStartLoad",get:function(){return this.streamController.forceStartLoad}},{key:"pathways",get:function(){return this.levelController.pathways}},{key:"pathwayPriority",get:function(){return this.levelController.pathwayPriority},set:function(e){this.levelController.pathwayPriority=e}},{key:"bufferedToEnd",get:function(){var e;return!(null==(e=this.bufferController)||!e.bufferedToEnd)}},{key:"interstitialsManager",get:function(){var e;return(null==(e=this.interstitialsController)?void 0:e.interstitialsManager)||null}}],[{key:"version",get:function(){return qa}},{key:"Events",get:function(){return k}},{key:"MetadataSchema",get:function(){return Xr}},{key:"ErrorTypes",get:function(){return b}},{key:"ErrorDetails",get:function(){return D}},{key:"DefaultConfig",get:function(){return e.defaultConfig?e.defaultConfig:ra},set:function(t){e.defaultConfig=t}}])}();return ln.defaultConfig=void 0,ln},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(r="undefined"!=typeof globalThis?globalThis:r||self).Hls=i()}(!1); //# sourceMappingURL=hls.light.min.js.map