=16?l--:l++;const i=qa(d.trim()),p=Ja(e,n,i);null!=t&&null!=(u=t.cues)&&u.getCueById(p)||(s=new c(e,n,i),s.id=p,s.line=h+1,s.align="left",s.position=10+Math.min(80,10*Math.floor(8*l/32)),r.push(s))}return t&&r.length&&(r.sort(((t,e)=>"auto"===t.line||"auto"===e.line?0:t.line>8&&e.line>8?e.line-t.line:t.line-e.line)),r.forEach((e=>mn(t,e)))),r}},ho=q(q({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,preferManagedMediaSource:!0,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,frontBufferFlushThreshold:1/0,maxBufferSize:6e7,maxBufferHole:.1,highBufferWatchdogPeriod:2,nudgeOffset:.1,nudgeMaxRetry:3,maxFragLookUpTolerance:.25,liveSyncDurationCount:3,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,loader:ro,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:class{constructor(t){this.hls=void 0,this.lastLevelLoadSec=0,this.lastLoadedFragLevel=-1,this.firstSelection=-1,this._nextAutoLevel=-1,this.nextAutoLevelKey="",this.audioTracksByGroup=null,this.codecTiers=null,this.timer=-1,this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this._abandonRulesCheck=()=>{const{fragCurrent:t,partCurrent:e,hls:n}=this,{autoLevelEnabled:i,media:r}=n;if(!t||!r)return;const a=performance.now(),s=e?e.stats:t.stats,o=e?e.duration:t.duration,l=a-s.loading.start,d=n.minAutoLevel;if(s.aborted||s.loaded&&s.loaded===s.total||t.level<=d)return this.clearTimer(),void(this._nextAutoLevel=-1);if(!i||r.paused||!r.playbackRate||!r.readyState)return;const c=n.mainForwardBufferInfo;if(null===c)return;const u=this.bwEstimator.getEstimateTTFB(),h=Math.abs(r.playbackRate);if(l<=Math.max(u,o/(2*h)*1e3))return;const p=c.len/h,f=s.loading.first?s.loading.first-s.loading.start:-1,m=s.loaded&&f>-1,g=this.getBwEstimate(),y=n.levels,A=y[t.level],v=s.total||Math.max(s.loaded,Math.round(o*A.averageBitrate/8));let b=m?l-f:l;b<1&&m&&(b=Math.min(l,8*s.loaded/g));const E=m?1e3*s.loaded/b:0,w=E?(v-s.loaded)/E:8*v/g+u/1e3;if(w<=p)return;const x=E?8*E:g;let S,_=Number.POSITIVE_INFINITY;for(S=t.level-1;S>d;S--){const t=y[S].maxBitrate;if(_=this.getTimeToLoadFrag(u/1e3,x,o*t,!y[S].details),_=w)return;if(_>10*o)return;n.nextLoadLevel=n.nextAutoLevel=S,m?this.bwEstimator.sample(l-Math.min(u,f),s.loaded):this.bwEstimator.sampleTTFB(l);const T=y[S].maxBitrate;this.getBwEstimate()*this.hls.config.abrBandWidthUpFactor>T&&this.resetEstimator(T),this.clearTimer(),ot.warn(`[abr] Fragment ${t.sn}${e?" part "+e.index:""} of level ${t.level} is loading too slowly;\n Time to underbuffer: ${p.toFixed(3)} s\n Estimated load time for current fragment: ${w.toFixed(3)} s\n Estimated load time for down switch fragment: ${_.toFixed(3)} s\n TTFB estimate: ${0|f} ms\n Current BW estimate: ${X(g)?0|g:"Unknown"} bps\n New BW estimate: ${0|this.getBwEstimate()} bps\n Switching to level ${S} @ ${0|T} bps`),n.trigger(tt.FRAG_LOAD_EMERGENCY_ABORTED,{frag:t,part:e,stats:s})},this.hls=t,this.bwEstimator=this.initEstimator(),this.registerListeners()}resetEstimator(t){t&&(ot.log(`setting initial bwe to ${t}`),this.hls.config.abrEwmaDefaultEstimate=t),this.firstSelection=-1,this.bwEstimator=this.initEstimator()}initEstimator(){const t=this.hls.config;return new di(t.abrEwmaSlowVoD,t.abrEwmaFastVoD,t.abrEwmaDefaultEstimate)}registerListeners(){const{hls:t}=this;t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.FRAG_LOADING,this.onFragLoading,this),t.on(tt.FRAG_LOADED,this.onFragLoaded,this),t.on(tt.FRAG_BUFFERED,this.onFragBuffered,this),t.on(tt.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(tt.LEVEL_LOADED,this.onLevelLoaded,this),t.on(tt.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(tt.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),t.on(tt.ERROR,this.onError,this)}unregisterListeners(){const{hls:t}=this;t&&(t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.FRAG_LOADING,this.onFragLoading,this),t.off(tt.FRAG_LOADED,this.onFragLoaded,this),t.off(tt.FRAG_BUFFERED,this.onFragBuffered,this),t.off(tt.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(tt.LEVEL_LOADED,this.onLevelLoaded,this),t.off(tt.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(tt.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),t.off(tt.ERROR,this.onError,this))}destroy(){this.unregisterListeners(),this.clearTimer(),this.hls=this._abandonRulesCheck=null,this.fragCurrent=this.partCurrent=null}onManifestLoading(t,e){this.lastLoadedFragLevel=-1,this.firstSelection=-1,this.lastLevelLoadSec=0,this.fragCurrent=this.partCurrent=null,this.onLevelsUpdated(),this.clearTimer()}onLevelsUpdated(){this.lastLoadedFragLevel>-1&&this.fragCurrent&&(this.lastLoadedFragLevel=this.fragCurrent.level),this._nextAutoLevel=-1,this.onMaxAutoLevelUpdated(),this.codecTiers=null,this.audioTracksByGroup=null}onMaxAutoLevelUpdated(){this.firstSelection=-1,this.nextAutoLevelKey=""}onFragLoading(t,e){const n=e.frag;if(!this.ignoreFragment(n)){var i;if(!n.bitrateTest)this.fragCurrent=n,this.partCurrent=null!=(i=e.part)?i:null;this.clearTimer(),this.timer=self.setInterval(this._abandonRulesCheck,100)}}onLevelSwitching(t,e){this.clearTimer()}onError(t,e){if(!e.fatal)switch(e.details){case nt.BUFFER_ADD_CODEC_ERROR:case nt.BUFFER_APPEND_ERROR:this.lastLoadedFragLevel=-1,this.firstSelection=-1;break;case nt.FRAG_LOAD_TIMEOUT:{const t=e.frag,{fragCurrent:n,partCurrent:i}=this;if(t&&n&&t.sn===n.sn&&t.level===n.level){const e=performance.now(),n=i?i.stats:t.stats,r=e-n.loading.start,a=n.loading.first?n.loading.first-n.loading.start:-1;if(n.loaded&&a>-1){const t=this.bwEstimator.getEstimateTTFB();this.bwEstimator.sample(r-Math.min(t,a),n.loaded)}else this.bwEstimator.sampleTTFB(r)}break}}}getTimeToLoadFrag(t,e,n,i){return t+n/e+(i?this.lastLevelLoadSec:0)}onLevelLoaded(t,e){const n=this.hls.config,{loading:i}=e.stats,r=i.end-i.start;X(r)&&(this.lastLevelLoadSec=r/1e3),e.details.live?this.bwEstimator.update(n.abrEwmaSlowLive,n.abrEwmaFastLive):this.bwEstimator.update(n.abrEwmaSlowVoD,n.abrEwmaFastVoD)}onFragLoaded(t,{frag:e,part:n}){const i=n?n.stats:e.stats;if(e.type===ln&&this.bwEstimator.sampleTTFB(i.loading.first-i.loading.start),!this.ignoreFragment(e)){if(this.clearTimer(),e.level===this._nextAutoLevel&&(this._nextAutoLevel=-1),this.firstSelection=-1,this.hls.config.abrMaxWithRealBitrate){const t=n?n.duration:e.duration,r=this.hls.levels[e.level],a=(r.loaded?r.loaded.bytes:0)+i.loaded,s=(r.loaded?r.loaded.duration:0)+t;r.loaded={bytes:a,duration:s},r.realBitrate=Math.round(8*a/s)}if(e.bitrateTest){const t={stats:i,frag:e,part:n,id:e.type};this.onFragBuffered(tt.FRAG_BUFFERED,t),e.bitrateTest=!1}else this.lastLoadedFragLevel=e.level}}onFragBuffered(t,e){const{frag:n,part:i}=e,r=null!=i&&i.stats.loaded?i.stats:n.stats;if(r.aborted)return;if(this.ignoreFragment(n))return;const a=r.parsing.end-r.loading.start-Math.min(r.loading.first-r.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(a,r.loaded),r.bwEstimate=this.getBwEstimate(),n.bitrateTest?this.bitrateTestDelay=a/1e3:this.bitrateTestDelay=0}ignoreFragment(t){return t.type!==ln||"initSegment"===t.sn}clearTimer(){this.timer>-1&&(self.clearInterval(this.timer),this.timer=-1)}get firstAutoLevel(){const{maxAutoLevel:t,minAutoLevel:e}=this.hls,n=this.getBwEstimate(),i=this.hls.config.maxStarvationDelay,r=this.findBestLevel(n,e,t,0,i,1,1);if(r>-1)return r;const a=this.hls.firstLevel,s=Math.min(Math.max(a,e),t);return ot.warn(`[abr] Could not find best starting auto level. Defaulting to first in playlist ${a} clamped to ${s}`),s}get forcedAutoLevel(){return this.nextAutoLevelKey?-1:this._nextAutoLevel}get nextAutoLevel(){const t=this.forcedAutoLevel,e=this.bwEstimator.canEstimate(),n=this.lastLoadedFragLevel>-1;if(!(-1===t||e&&n&&this.nextAutoLevelKey!==this.getAutoLevelKey()))return t;const i=e&&n?this.getNextABRAutoLevel():this.firstAutoLevel;if(-1!==t){const e=this.hls.levels;if(e.length>Math.max(t,i)&&e[t].loadError<=e[i].loadError)return t}return this._nextAutoLevel=i,this.nextAutoLevelKey=this.getAutoLevelKey(),i}getAutoLevelKey(){return`${this.getBwEstimate()}_${this.getStarvationDelay().toFixed(2)}`}getNextABRAutoLevel(){const{fragCurrent:t,partCurrent:e,hls:n}=this,{maxAutoLevel:i,config:r,minAutoLevel:a}=n,s=e?e.duration:t?t.duration:0,o=this.getBwEstimate(),l=this.getStarvationDelay();let d=r.abrBandWidthFactor,c=r.abrBandWidthUpFactor;if(l){const t=this.findBestLevel(o,a,i,l,0,d,c);if(t>=0)return t}let u=s?Math.min(s,r.maxStarvationDelay):r.maxStarvationDelay;if(!l){const t=this.bitrateTestDelay;if(t){u=(s?Math.min(s,r.maxLoadingDelay):r.maxLoadingDelay)-t,ot.info(`[abr] bitrate test took ${Math.round(1e3*t)}ms, set first fragment max fetchDuration to ${Math.round(1e3*u)} ms`),d=c=1}}const h=this.findBestLevel(o,a,i,l,u,d,c);if(ot.info(`[abr] ${l?"rebuffering expected":"buffer is empty"}, optimal quality level ${h}`),h>-1)return h;const p=n.levels[a],f=n.levels[n.loadLevel];return(null==p?void 0:p.bitrate)<(null==f?void 0:f.bitrate)?a:n.loadLevel}getStarvationDelay(){const t=this.hls,e=t.media;if(!e)return 1/0;const n=e&&0!==e.playbackRate?Math.abs(e.playbackRate):1,i=t.mainForwardBufferInfo;return(i?i.len:0)/n}getBwEstimate(){return this.bwEstimator.canEstimate()?this.bwEstimator.getEstimate():this.hls.config.abrEwmaDefaultEstimate}findBestLevel(t,e,n,i,r,a,s){var o;const l=i+r,d=this.lastLoadedFragLevel,c=-1===d?this.hls.firstLevel:d,{fragCurrent:u,partCurrent:h}=this,{levels:p,allAudioTracks:f,loadLevel:m,config:g}=this.hls;if(1===p.length)return 0;const y=p[c],A=!(null==y||null==(o=y.details)||!o.live),v=-1===m||-1===d;let b,E="SDR",w=(null==y?void 0:y.frameRate)||0;const{audioPreference:x,videoPreference:S}=g,_=this.audioTracksByGroup||(this.audioTracksByGroup=function(t){return t.reduce(((t,e)=>{let n=t.groups[e.groupId];n||(n=t.groups[e.groupId]={tracks:[],channels:{2:0},hasDefault:!1,hasAutoSelect:!1}),n.tracks.push(e);const i=e.channels||"2";return n.channels[i]=(n.channels[i]||0)+1,n.hasDefault=n.hasDefault||e.default,n.hasAutoSelect=n.hasAutoSelect||e.autoselect,n.hasDefault&&(t.hasDefaultAudio=!0),n.hasAutoSelect&&(t.hasAutoSelectAudio=!0),t}),{hasDefaultAudio:!1,hasAutoSelectAudio:!1,groups:{}})}(f));if(v){if(-1!==this.firstSelection)return this.firstSelection;const i=this.codecTiers||(this.codecTiers=function(t,e,n,i){return t.slice(n,i+1).reduce(((t,n)=>{if(!n.codecSet)return t;const i=n.audioGroups;let r=t[n.codecSet];r||(t[n.codecSet]=r={minBitrate:1/0,minHeight:1/0,minFramerate:1/0,maxScore:0,videoRanges:{SDR:0},channels:{2:0},hasDefaultAudio:!i,fragmentError:0}),r.minBitrate=Math.min(r.minBitrate,n.bitrate);const a=Math.min(n.height,n.width);return r.minHeight=Math.min(r.minHeight,a),r.minFramerate=Math.min(r.minFramerate,n.frameRate),r.maxScore=Math.max(r.maxScore,n.score),r.fragmentError+=n.fragmentError,r.videoRanges[n.videoRange]=(r.videoRanges[n.videoRange]||0)+1,i&&i.forEach((t=>{if(!t)return;const n=e.groups[t];n&&(r.hasDefaultAudio=r.hasDefaultAudio||e.hasDefaultAudio?n.hasDefault:n.hasAutoSelect||!e.hasDefaultAudio&&!e.hasAutoSelectAudio,Object.keys(n.channels).forEach((t=>{r.channels[t]=(r.channels[t]||0)+n.channels[t]})))})),t}),{})}(p,_,e,n)),r=function(t,e,n,i,r){const a=Object.keys(t),s=null==i?void 0:i.channels,o=null==i?void 0:i.audioCodec,l=s&&2===parseInt(s);let d=!0,c=!1,u=1/0,h=1/0,p=1/0,f=0,m=[];const{preferHDR:g,allowedVideoRanges:y}=fi(e,r);for(let e=a.length;e--;){const n=t[a[e]];d=n.channels[2]>0,u=Math.min(u,n.minHeight),h=Math.min(h,n.minFramerate),p=Math.min(p,n.minBitrate);const i=y.filter((t=>n.videoRanges[t]>0));i.length>0&&(c=!0,m=i)}u=X(u)?u:0,h=X(h)?h:0;const A=Math.max(1080,u),v=Math.max(30,h);return p=X(p)?p:n,n=Math.max(p,n),c||(e=void 0,m=[]),{codecSet:a.reduce(((e,i)=>{const r=t[i];if(i===e)return e;if(r.minBitrate>n)return mi(i,`min bitrate of ${r.minBitrate} > current estimate of ${n}`),e;if(!r.hasDefaultAudio)return mi(i,"no renditions with default or auto-select sound found"),e;if(o&&i.indexOf(o.substring(0,4))%5!=0)return mi(i,`audio codec preference "${o}" not found`),e;if(s&&!l){if(!r.channels[s])return mi(i,`no renditions with ${s} channel sound found (channels options: ${Object.keys(r.channels)})`),e}else if((!o||l)&&d&&0===r.channels[2])return mi(i,"no renditions with stereo sound found"),e;return r.minHeight>A?(mi(i,`min resolution of ${r.minHeight} > maximum of ${A}`),e):r.minFramerate>v?(mi(i,`min framerate of ${r.minFramerate} > maximum of ${v}`),e):m.some((t=>r.videoRanges[t]>0))?r.maxScore=Ne(e)||r.fragmentError>t[e].fragmentError)?e:(f=r.maxScore,i):(mi(i,`no variants with VIDEO-RANGE of ${JSON.stringify(m)} found`),e)}),void 0),videoRanges:m,preferHDR:g,minFramerate:h,minBitrate:p}}(i,E,t,x,S),{codecSet:a,videoRanges:s,minFramerate:o,minBitrate:l,preferHDR:d}=r;b=a,E=d?s[s.length-1]:s[0],w=o,t=Math.max(t,l),ot.log(`[abr] picked start tier ${JSON.stringify(r)}`)}else b=null==y?void 0:y.codecSet,E=null==y?void 0:y.videoRange;const T=h?h.duration:u?u.duration:0,k=this.bwEstimator.getEstimateTTFB()/1e3,C=[];for(let o=n;o>=e;o--){var L;const e=p[o],u=o>c;if(!e)continue;if(g.useMediaCapabilities&&!e.supportedResult&&!e.supportedPromise){const n=navigator.mediaCapabilities;"function"==typeof(null==n?void 0:n.decodingInfo)&&hi(e,_,E,w,t,x)?(e.supportedPromise=pi(e,_,n),e.supportedPromise.then((t=>{if(!this.hls)return;e.supportedResult=t;const n=this.hls.levels,i=n.indexOf(e);t.error?ot.warn(`[abr] MediaCapabilities decodingInfo error: "${t.error}" for level ${i} ${JSON.stringify(t)}`):t.supported||(ot.warn(`[abr] Unsupported MediaCapabilities decodingInfo result for level ${i} ${JSON.stringify(t)}`),i>-1&&n.length>1&&(ot.log(`[abr] Removing unsupported level ${i}`),this.hls.removeLevel(i)))}))):e.supportedResult=ci}if(b&&e.codecSet!==b||E&&e.videoRange!==E||u&&w>e.frameRate||!u&&w>0&&w=2*T&&0===r?p[o].averageBitrate:p[o].maxBitrate,D=this.getTimeToLoadFrag(k,I,R*S,void 0===f);if(I>=R&&(o===d||0===e.loadError&&0===e.fragmentError)&&(D<=k||!X(D)||A&&!this.bitrateTestDelay||D${o} adjustedbw(${Math.round(I)})-bitrate=${Math.round(I-R)} ttfb:${k.toFixed(1)} avgDuration:${S.toFixed(1)} maxFetchDuration:${l.toFixed(1)} fetchDuration:${D.toFixed(1)} firstSelection:${v} codecSet:${b} videoRange:${E} hls.loadLevel:${m}`)),v&&(this.firstSelection=o),o}}return-1}set nextAutoLevel(t){const{maxAutoLevel:e,minAutoLevel:n}=this.hls,i=Math.min(Math.max(t,n),e);this._nextAutoLevel!==i&&(this.nextAutoLevelKey="",this._nextAutoLevel=i)}},bufferController:class{constructor(t){this.details=null,this._objectUrl=null,this.operationQueue=void 0,this.listeners=void 0,this.hls=void 0,this.bufferCodecEventsExpected=0,this._bufferCodecEventsTotal=0,this.media=null,this.mediaSource=null,this.lastMpegAudioChunk=null,this.appendSource=void 0,this.appendErrors={audio:0,video:0,audiovideo:0},this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this.log=void 0,this.warn=void 0,this.error=void 0,this._onEndStreaming=t=>{this.hls&&this.hls.pauseBuffering()},this._onStartStreaming=t=>{this.hls&&this.hls.resumeBuffering()},this._onMediaSourceOpen=()=>{const{media:t,mediaSource:e}=this;this.log("Media source opened"),t&&(t.removeEventListener("emptied",this._onMediaEmptied),this.updateMediaElementDuration(),this.hls.trigger(tt.MEDIA_ATTACHED,{media:t,mediaSource:e})),e&&e.removeEventListener("sourceopen",this._onMediaSourceOpen),this.checkPendingTracks()},this._onMediaSourceClose=()=>{this.log("Media source closed")},this._onMediaSourceEnded=()=>{this.log("Media source ended")},this._onMediaEmptied=()=>{const{mediaSrc:t,_objectUrl:e}=this;t!==e&&ot.error(`Media element src was set while attaching MediaSource (${e} > ${t})`)},this.hls=t;const e="[buffer-controller]";var n;this.appendSource=(n=Be(t.config.preferManagedMediaSource),"undefined"!=typeof self&&n===self.ManagedMediaSource),this.log=ot.log.bind(ot,e),this.warn=ot.warn.bind(ot,e),this.error=ot.error.bind(ot,e),this._initSourceBuffer(),this.registerListeners()}hasSourceTypes(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0}destroy(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null,this.hls=null}registerListeners(){const{hls:t}=this;t.on(tt.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.on(tt.BUFFER_RESET,this.onBufferReset,this),t.on(tt.BUFFER_APPENDING,this.onBufferAppending,this),t.on(tt.BUFFER_CODECS,this.onBufferCodecs,this),t.on(tt.BUFFER_EOS,this.onBufferEos,this),t.on(tt.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(tt.LEVEL_UPDATED,this.onLevelUpdated,this),t.on(tt.FRAG_PARSED,this.onFragParsed,this),t.on(tt.FRAG_CHANGED,this.onFragChanged,this)}unregisterListeners(){const{hls:t}=this;t.off(tt.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.off(tt.BUFFER_RESET,this.onBufferReset,this),t.off(tt.BUFFER_APPENDING,this.onBufferAppending,this),t.off(tt.BUFFER_CODECS,this.onBufferCodecs,this),t.off(tt.BUFFER_EOS,this.onBufferEos,this),t.off(tt.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(tt.LEVEL_UPDATED,this.onLevelUpdated,this),t.off(tt.FRAG_PARSED,this.onFragParsed,this),t.off(tt.FRAG_CHANGED,this.onFragChanged,this)}_initSourceBuffer(){this.sourceBuffer={},this.operationQueue=new ga(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.appendErrors={audio:0,video:0,audiovideo:0},this.lastMpegAudioChunk=null}onManifestLoading(){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=0,this.details=null}onManifestParsed(t,e){let n=2;(e.audio&&!e.video||!e.altAudio)&&(n=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=n,this.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`)}onMediaAttaching(t,e){const n=this.media=e.media,i=Be(this.appendSource);if(n&&i){var r;const t=this.mediaSource=new i;this.log(`created media source: ${null==(r=t.constructor)?void 0:r.name}`),t.addEventListener("sourceopen",this._onMediaSourceOpen),t.addEventListener("sourceended",this._onMediaSourceEnded),t.addEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(t.addEventListener("startstreaming",this._onStartStreaming),t.addEventListener("endstreaming",this._onEndStreaming));const e=this._objectUrl=self.URL.createObjectURL(t);if(this.appendSource)try{n.removeAttribute("src");const i=self.ManagedMediaSource;n.disableRemotePlayback=n.disableRemotePlayback||i&&t instanceof i,Aa(n),function(t,e){const n=self.document.createElement("source");n.type="video/mp4",n.src=e,t.appendChild(n)}(n,e),n.load()}catch(t){n.src=e}else n.src=e;n.addEventListener("emptied",this._onMediaEmptied)}}onMediaDetaching(){const{media:t,mediaSource:e,_objectUrl:n}=this;if(e){if(this.log("media source detaching"),"open"===e.readyState)try{e.endOfStream()}catch(t){this.warn(`onMediaDetaching: ${t.message} while calling endOfStream`)}this.onBufferReset(),e.removeEventListener("sourceopen",this._onMediaSourceOpen),e.removeEventListener("sourceended",this._onMediaSourceEnded),e.removeEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(e.removeEventListener("startstreaming",this._onStartStreaming),e.removeEventListener("endstreaming",this._onEndStreaming)),t&&(t.removeEventListener("emptied",this._onMediaEmptied),n&&self.URL.revokeObjectURL(n),this.mediaSrc===n?(t.removeAttribute("src"),this.appendSource&&Aa(t),t.load()):this.warn("media|source.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal,this.pendingTracks={},this.tracks={}}this.hls.trigger(tt.MEDIA_DETACHED,void 0)}onBufferReset(){this.getSourceBufferTypes().forEach((t=>{this.resetBuffer(t)})),this._initSourceBuffer()}resetBuffer(t){const e=this.sourceBuffer[t];try{var n;if(e)this.removeBufferListeners(t),this.sourceBuffer[t]=void 0,null!=(n=this.mediaSource)&&n.sourceBuffers.length&&this.mediaSource.removeSourceBuffer(e)}catch(e){this.warn(`onBufferReset ${t}`,e)}}onBufferCodecs(t,e){const n=this.getSourceBufferTypes().length,i=Object.keys(e);if(i.forEach((t=>{if(n){const n=this.tracks[t];if(n&&"function"==typeof n.buffer.changeType){var i;const{id:r,codec:a,levelCodec:s,container:o,metadata:l}=e[t],d=He(n.codec,n.levelCodec),c=null==d?void 0:d.replace(ya,"$1");let u=He(a,s);const h=null==(i=u)?void 0:i.replace(ya,"$1");if(u&&c!==h){"audio"===t.slice(0,5)&&(u=je(u,this.appendSource));const e=`${o};codecs=${u}`;this.appendChangeType(t,e),this.log(`switching codec ${d} to ${u}`),this.tracks[t]={buffer:n.buffer,codec:a,container:o,levelCodec:s,metadata:l,id:r}}}}else this.pendingTracks[t]=e[t]})),n)return;const r=Math.max(this.bufferCodecEventsExpected-1,0);this.bufferCodecEventsExpected!==r&&(this.log(`${r} bufferCodec event(s) expected ${i.join(",")}`),this.bufferCodecEventsExpected=r),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks()}appendChangeType(t,e){const{operationQueue:n}=this,i={execute:()=>{const i=this.sourceBuffer[t];i&&(this.log(`changing ${t} sourceBuffer type to ${e}`),i.changeType(e)),n.shiftAndExecuteNext(t)},onStart:()=>{},onComplete:()=>{},onError:e=>{this.warn(`Failed to change ${t} SourceBuffer type`,e)}};n.append(i,t,!!this.pendingTracks[t])}onBufferAppending(t,e){const{hls:n,operationQueue:i,tracks:r}=this,{data:a,type:s,frag:o,part:l,chunkMeta:d}=e,c=d.buffering[s],u=self.performance.now();c.start=u;const h=o.stats.buffering,p=l?l.stats.buffering:null;0===h.start&&(h.start=u),p&&0===p.start&&(p.start=u);const f=r.audio;let m=!1;"audio"===s&&"audio/mpeg"===(null==f?void 0:f.container)&&(m=!this.lastMpegAudioChunk||1===d.id||this.lastMpegAudioChunk.sn!==d.sn,this.lastMpegAudioChunk=d);const g=o.start,y={execute:()=>{if(c.executeStart=self.performance.now(),m){const t=this.sourceBuffer[s];if(t){const e=g-t.timestampOffset;Math.abs(e)>=.1&&(this.log(`Updating audio SourceBuffer timestampOffset to ${g} (delta: ${e}) sn: ${o.sn})`),t.timestampOffset=g)}}this.appendExecutor(a,s)},onStart:()=>{},onComplete:()=>{const t=self.performance.now();c.executeEnd=c.end=t,0===h.first&&(h.first=t),p&&0===p.first&&(p.first=t);const{sourceBuffer:e}=this,n={};for(const t in e)n[t]=Li.getBuffered(e[t]);this.appendErrors[s]=0,"audio"===s||"video"===s?this.appendErrors.audiovideo=0:(this.appendErrors.audio=0,this.appendErrors.video=0),this.hls.trigger(tt.BUFFER_APPENDED,{type:s,frag:o,part:l,chunkMeta:d,parent:o.type,timeRanges:n})},onError:t=>{const e={type:et.MEDIA_ERROR,parent:o.type,details:nt.BUFFER_APPEND_ERROR,sourceBufferName:s,frag:o,part:l,chunkMeta:d,error:t,err:t,fatal:!1};if(t.code===DOMException.QUOTA_EXCEEDED_ERR)e.details=nt.BUFFER_FULL_ERROR;else{const t=++this.appendErrors[s];e.details=nt.BUFFER_APPEND_ERROR,this.warn(`Failed ${t}/${n.config.appendErrorMaxRetry} times to append segment in "${s}" sourceBuffer`),t>=n.config.appendErrorMaxRetry&&(e.fatal=!0)}n.trigger(tt.ERROR,e)}};i.append(y,s,!!this.pendingTracks[s])}onBufferFlushing(t,e){const{operationQueue:n}=this,i=t=>({execute:this.removeExecutor.bind(this,t,e.startOffset,e.endOffset),onStart:()=>{},onComplete:()=>{this.hls.trigger(tt.BUFFER_FLUSHED,{type:t})},onError:e=>{this.warn(`Failed to remove from ${t} SourceBuffer`,e)}});e.type?n.append(i(e.type),e.type):this.getSourceBufferTypes().forEach((t=>{n.append(i(t),t)}))}onFragParsed(t,e){const{frag:n,part:i}=e,r=[],a=i?i.elementaryStreams:n.elementaryStreams;a[gt]?r.push("audiovideo"):(a[ft]&&r.push("audio"),a[mt]&&r.push("video"));0===r.length&&this.warn(`Fragments must have at least one ElementaryStreamType set. type: ${n.type} level: ${n.level} sn: ${n.sn}`),this.blockBuffers((()=>{const t=self.performance.now();n.stats.buffering.end=t,i&&(i.stats.buffering.end=t);const e=i?i.stats:n.stats;this.hls.trigger(tt.FRAG_BUFFERED,{frag:n,part:i,stats:e,id:n.type})}),r)}onFragChanged(t,e){this.trimBuffers()}onBufferEos(t,e){this.getSourceBufferTypes().reduce(((t,n)=>{const i=this.sourceBuffer[n];return!i||e.type&&e.type!==n||(i.ending=!0,i.ended||(i.ended=!0,this.log(`${n} sourceBuffer now EOS`))),t&&!(i&&!i.ended)}),!0)&&(this.log("Queueing mediaSource.endOfStream()"),this.blockBuffers((()=>{this.getSourceBufferTypes().forEach((t=>{const e=this.sourceBuffer[t];e&&(e.ending=!1)}));const{mediaSource:t}=this;t&&"open"===t.readyState?(this.log("Calling mediaSource.endOfStream()"),t.endOfStream()):t&&this.log(`Could not call mediaSource.endOfStream(). mediaSource.readyState: ${t.readyState}`)})))}onLevelUpdated(t,{details:e}){e.fragments.length&&(this.details=e,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())}trimBuffers(){const{hls:t,details:e,media:n}=this;if(!n||null===e)return;if(!this.getSourceBufferTypes().length)return;const i=t.config,r=n.currentTime,a=e.levelTargetDuration,s=e.live&&null!==i.liveBackBufferLength?i.liveBackBufferLength:i.backBufferLength;if(X(s)&&s>0){const t=Math.max(s,a),e=Math.floor(r/a)*a-t;this.flushBackBuffer(r,a,e)}if(X(i.frontBufferFlushThreshold)&&i.frontBufferFlushThreshold>0){const t=Math.max(i.maxBufferLength,i.frontBufferFlushThreshold),e=Math.max(t,a),n=Math.floor(r/a)*a+e;this.flushFrontBuffer(r,a,n)}}flushBackBuffer(t,e,n){const{details:i,sourceBuffer:r}=this;this.getSourceBufferTypes().forEach((a=>{const s=r[a];if(s){const r=Li.getBuffered(s);if(r.length>0&&n>r.start(0)){if(this.hls.trigger(tt.BACK_BUFFER_REACHED,{bufferEnd:n}),null!=i&&i.live)this.hls.trigger(tt.LIVE_BACK_BUFFER_REACHED,{bufferEnd:n});else if(s.ended&&r.end(r.length-1)-t<2*e)return void this.log(`Cannot flush ${a} back buffer while SourceBuffer is in ended state`);this.hls.trigger(tt.BUFFER_FLUSHING,{startOffset:0,endOffset:n,type:a})}}}))}flushFrontBuffer(t,e,n){const{sourceBuffer:i}=this;this.getSourceBufferTypes().forEach((r=>{const a=i[r];if(a){const i=Li.getBuffered(a),s=i.length;if(s<2)return;const o=i.start(s-1),l=i.end(s-1);if(n>o||t>=o&&t<=l)return;if(a.ended&&t-l<2*e)return void this.log(`Cannot flush ${r} front buffer while SourceBuffer is in ended state`);this.hls.trigger(tt.BUFFER_FLUSHING,{startOffset:o,endOffset:1/0,type:r})}}))}updateMediaElementDuration(){if(!this.details||!this.media||!this.mediaSource||"open"!==this.mediaSource.readyState)return;const{details:t,hls:e,media:n,mediaSource:i}=this,r=t.fragments[0].start+t.totalduration,a=n.duration,s=X(i.duration)?i.duration:0;t.live&&e.config.liveDurationInfinity?(i.duration=1/0,this.updateSeekableRange(t)):(r>s&&r>a||!X(a))&&(this.log(`Updating Media Source duration to ${r.toFixed(3)}`),i.duration=r)}updateSeekableRange(t){const e=this.mediaSource,n=t.fragments;if(n.length&&t.live&&null!=e&&e.setLiveSeekableRange){const i=Math.max(0,n[0].start),r=Math.max(i,i+t.totalduration);this.log(`Media Source duration is set to ${e.duration}. Setting seekable range to ${i}-${r}.`),e.setLiveSeekableRange(i,r)}}checkPendingTracks(){const{bufferCodecEventsExpected:t,operationQueue:e,pendingTracks:n}=this,i=Object.keys(n).length;if(i&&(!t||2===i||"audiovideo"in n)){this.createSourceBuffers(n),this.pendingTracks={};const t=this.getSourceBufferTypes();if(t.length)this.hls.trigger(tt.BUFFER_CREATED,{tracks:this.tracks}),t.forEach((t=>{e.executeNext(t)}));else{const t=new Error("could not create source buffer for media codec(s)");this.hls.trigger(tt.ERROR,{type:et.MEDIA_ERROR,details:nt.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:t,reason:t.message})}}}createSourceBuffers(t){const{sourceBuffer:e,mediaSource:n}=this;if(!n)throw Error("createSourceBuffers called when mediaSource was null");for(const r in t)if(!e[r]){var i;const a=t[r];if(!a)throw Error(`source buffer exists for track ${r}, however track does not`);let s=-1===(null==(i=a.levelCodec)?void 0:i.indexOf(","))?a.levelCodec:a.codec;s&&"audio"===r.slice(0,5)&&(s=je(s,this.appendSource));const o=`${a.container};codecs=${s}`;this.log(`creating sourceBuffer(${o})`);try{const t=e[r]=n.addSourceBuffer(o),i=r;this.addBufferListener(i,"updatestart",this._onSBUpdateStart),this.addBufferListener(i,"updateend",this._onSBUpdateEnd),this.addBufferListener(i,"error",this._onSBUpdateError),this.appendSource&&this.addBufferListener(i,"bufferedchange",((t,e)=>{const n=e.removedRanges;null!=n&&n.length&&this.hls.trigger(tt.BUFFER_FLUSHED,{type:r})})),this.tracks[r]={buffer:t,codec:s,container:a.container,levelCodec:a.levelCodec,metadata:a.metadata,id:a.id}}catch(t){this.error(`error while trying to add sourceBuffer: ${t.message}`),this.hls.trigger(tt.ERROR,{type:et.MEDIA_ERROR,details:nt.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:t,sourceBufferName:r,mimeType:o})}}}get mediaSrc(){var t;const e=(null==(t=this.media)?void 0:t.firstChild)||this.media;return null==e?void 0:e.src}_onSBUpdateStart(t){const{operationQueue:e}=this;e.current(t).onStart()}_onSBUpdateEnd(t){var e;if("closed"===(null==(e=this.mediaSource)?void 0:e.readyState))return void this.resetBuffer(t);const{operationQueue:n}=this;n.current(t).onComplete(),n.shiftAndExecuteNext(t)}_onSBUpdateError(t,e){var n;const i=new Error(`${t} SourceBuffer error. MediaSource readyState: ${null==(n=this.mediaSource)?void 0:n.readyState}`);this.error(`${i}`,e),this.hls.trigger(tt.ERROR,{type:et.MEDIA_ERROR,details:nt.BUFFER_APPENDING_ERROR,sourceBufferName:t,error:i,fatal:!1});const r=this.operationQueue.current(t);r&&r.onError(i)}removeExecutor(t,e,n){const{media:i,mediaSource:r,operationQueue:a,sourceBuffer:s}=this,o=s[t];if(!i||!r||!o)return this.warn(`Attempting to remove from the ${t} SourceBuffer, but it does not exist`),void a.shiftAndExecuteNext(t);const l=X(i.duration)?i.duration:1/0,d=X(r.duration)?r.duration:1/0,c=Math.max(0,e),u=Math.min(n,l,d);u>c&&(!o.ending||o.ended)?(o.ended=!1,this.log(`Removing [${c},${u}] from the ${t} SourceBuffer`),o.remove(c,u)):a.shiftAndExecuteNext(t)}appendExecutor(t,e){const n=this.sourceBuffer[e];if(n)n.ended=!1,n.appendBuffer(t);else if(!this.pendingTracks[e])throw new Error(`Attempting to append to the ${e} SourceBuffer, but it does not exist`)}blockBuffers(t,e=this.getSourceBufferTypes()){if(!e.length)return this.log("Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(t);const{operationQueue:n}=this,i=e.map((t=>n.appendBlocker(t)));Promise.all(i).then((()=>{t(),e.forEach((t=>{const e=this.sourceBuffer[t];null!=e&&e.updating||n.shiftAndExecuteNext(t)}))}))}getSourceBufferTypes(){return Object.keys(this.sourceBuffer)}addBufferListener(t,e,n){const i=this.sourceBuffer[t];if(!i)return;const r=n.bind(this,t);this.listeners[t].push({event:e,listener:r}),i.addEventListener(e,r)}removeBufferListeners(t){const e=this.sourceBuffer[t];e&&this.listeners[t].forEach((t=>{e.removeEventListener(t.event,t.listener)}))}},capLevelController:ps,errorController:class{constructor(t){this.hls=void 0,this.playlistError=0,this.penalizedRenditions={},this.log=void 0,this.warn=void 0,this.error=void 0,this.hls=t,this.log=ot.log.bind(ot,"[info]:"),this.warn=ot.warn.bind(ot,"[warning]:"),this.error=ot.error.bind(ot,"[error]:"),this.registerListeners()}registerListeners(){const t=this.hls;t.on(tt.ERROR,this.onError,this),t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.LEVEL_UPDATED,this.onLevelUpdated,this)}unregisterListeners(){const t=this.hls;t&&(t.off(tt.ERROR,this.onError,this),t.off(tt.ERROR,this.onErrorOut,this),t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.LEVEL_UPDATED,this.onLevelUpdated,this))}destroy(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}}startLoad(t){}stopLoad(){this.playlistError=0}getVariantLevelIndex(t){return(null==t?void 0:t.type)===ln?t.level:this.hls.loadLevel}onManifestLoading(){this.playlistError=0,this.penalizedRenditions={}}onLevelUpdated(){this.playlistError=0}onError(t,e){var n,i;if(e.fatal)return;const r=this.hls,a=e.context;switch(e.details){case nt.FRAG_LOAD_ERROR:case nt.FRAG_LOAD_TIMEOUT:case nt.KEY_LOAD_ERROR:case nt.KEY_LOAD_TIMEOUT:return void(e.errorAction=this.getFragRetryOrSwitchAction(e));case nt.FRAG_PARSING_ERROR:if(null!=(n=e.frag)&&n.gap)return void(e.errorAction={action:ti,flags:ri});case nt.FRAG_GAP:case nt.FRAG_DECRYPT_ERROR:return e.errorAction=this.getFragRetryOrSwitchAction(e),void(e.errorAction.action=ei);case nt.LEVEL_EMPTY_ERROR:case nt.LEVEL_PARSING_ERROR:{var s,o;const t=e.parent===ln?e.level:r.loadLevel;e.details===nt.LEVEL_EMPTY_ERROR&&null!=(s=e.context)&&null!=(o=s.levelDetails)&&o.live?e.errorAction=this.getPlaylistRetryOrSwitchAction(e,t):(e.levelRetry=!1,e.errorAction=this.getLevelSwitchAction(e,t))}return;case nt.LEVEL_LOAD_ERROR:case nt.LEVEL_LOAD_TIMEOUT:return void("number"==typeof(null==a?void 0:a.level)&&(e.errorAction=this.getPlaylistRetryOrSwitchAction(e,a.level)));case nt.AUDIO_TRACK_LOAD_ERROR:case nt.AUDIO_TRACK_LOAD_TIMEOUT:case nt.SUBTITLE_LOAD_ERROR:case nt.SUBTITLE_TRACK_LOAD_TIMEOUT:if(a){const t=r.levels[r.loadLevel];if(t&&(a.type===sn&&t.hasAudioGroup(a.groupId)||a.type===on&&t.hasSubtitleGroup(a.groupId)))return e.errorAction=this.getPlaylistRetryOrSwitchAction(e,r.loadLevel),e.errorAction.action=ei,void(e.errorAction.flags=ai)}return;case nt.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:{const t=r.levels[r.loadLevel],n=null==t?void 0:t.attrs["HDCP-LEVEL"];n?e.errorAction={action:ei,flags:si,hdcpLevel:n}:this.keySystemError(e)}return;case nt.BUFFER_ADD_CODEC_ERROR:case nt.REMUX_ALLOC_ERROR:case nt.BUFFER_APPEND_ERROR:return void(e.errorAction=this.getLevelSwitchAction(e,null!=(i=e.level)?i:r.loadLevel));case nt.INTERNAL_EXCEPTION:case nt.BUFFER_APPENDING_ERROR:case nt.BUFFER_FULL_ERROR:case nt.LEVEL_SWITCH_ERROR:case nt.BUFFER_STALLED_ERROR:case nt.BUFFER_SEEK_OVER_HOLE:case nt.BUFFER_NUDGE_ON_STALL:return void(e.errorAction={action:ti,flags:ri})}e.type===et.KEY_SYSTEM_ERROR&&this.keySystemError(e)}keySystemError(t){const e=this.getVariantLevelIndex(t.frag);t.levelRetry=!1,t.errorAction=this.getLevelSwitchAction(t,e)}getPlaylistRetryOrSwitchAction(t,e){const n=Kn(this.hls.config.playlistLoadPolicy,t),i=this.playlistError++;if(Wn(n,i,$n(t),t.response))return{action:ii,flags:ri,retryConfig:n,retryCount:i};const r=this.getLevelSwitchAction(t,e);return n&&(r.retryConfig=n,r.retryCount=i),r}getFragRetryOrSwitchAction(t){const e=this.hls,n=this.getVariantLevelIndex(t.frag),i=e.levels[n],{fragLoadPolicy:r,keyLoadPolicy:a}=e.config,s=Kn(t.details.startsWith("key")?a:r,t),o=e.levels.reduce(((t,e)=>t+e.fragmentError),0);if(i){t.details!==nt.FRAG_GAP&&i.fragmentError++;if(Wn(s,o,$n(t),t.response))return{action:ii,flags:ri,retryConfig:s,retryCount:o}}const l=this.getLevelSwitchAction(t,n);return s&&(l.retryConfig=s,l.retryCount=o),l}getLevelSwitchAction(t,e){const n=this.hls;null==e&&(e=n.loadLevel);const i=this.hls.levels[e];if(i){var r,a;const e=t.details;i.loadError++,e===nt.BUFFER_APPEND_ERROR&&i.fragmentError++;let l=-1;const{levels:d,loadLevel:c,minAutoLevel:u,maxAutoLevel:h}=n;n.autoLevelEnabled||(n.loadLevel=-1);const p=null==(r=t.frag)?void 0:r.type,f=(p===dn&&e===nt.FRAG_PARSING_ERROR||"audio"===t.sourceBufferName&&(e===nt.BUFFER_ADD_CODEC_ERROR||e===nt.BUFFER_APPEND_ERROR))&&d.some((({audioCodec:t})=>i.audioCodec!==t)),m="video"===t.sourceBufferName&&(e===nt.BUFFER_ADD_CODEC_ERROR||e===nt.BUFFER_APPEND_ERROR)&&d.some((({codecSet:t,audioCodec:e})=>i.codecSet!==t&&i.audioCodec===e)),{type:g,groupId:y}=null!=(a=t.context)?a:{};for(let n=d.length;n--;){const r=(n+c)%d.length;if(r!==c&&r>=u&&r<=h&&0===d[r].loadError){var s,o;const n=d[r];if(e===nt.FRAG_GAP&&t.frag){const e=d[r].details;if(e){const n=Xn(t.frag,e.fragments,t.frag.start);if(null!=n&&n.gap)continue}}else{if(g===sn&&n.hasAudioGroup(y)||g===on&&n.hasSubtitleGroup(y))continue;if(p===dn&&null!=(s=i.audioGroups)&&s.some((t=>n.hasAudioGroup(t)))||p===cn&&null!=(o=i.subtitleGroups)&&o.some((t=>n.hasSubtitleGroup(t)))||f&&i.audioCodec===n.audioCodec||!f&&i.audioCodec!==n.audioCodec||m&&i.codecSet===n.codecSet)continue}l=r;break}}if(l>-1&&n.loadLevel!==l)return t.levelRetry=!0,this.playlistError=0,{action:ei,flags:ri,nextAutoLevel:l}}return{action:ei,flags:ai}}onErrorOut(t,e){var n;switch(null==(n=e.errorAction)?void 0:n.action){case ti:break;case ei:this.sendAlternateToPenaltyBox(e),e.errorAction.resolved||e.details===nt.FRAG_GAP?/MediaSource readyState: ended/.test(e.error.message)&&(this.warn(`MediaSource ended after "${e.sourceBufferName}" sourceBuffer append error. Attempting to recover from media error.`),this.hls.recoverMediaError()):e.fatal=!0}e.fatal&&this.hls.stopLoad()}sendAlternateToPenaltyBox(t){const e=this.hls,n=t.errorAction;if(!n)return;const{flags:i,hdcpLevel:r,nextAutoLevel:a}=n;switch(i){case ri:this.switchLevel(t,a);break;case si:r&&(e.maxHdcpLevel=Cn[Cn.indexOf(r)-1],n.resolved=!0),this.warn(`Restricting playback to HDCP-LEVEL of "${e.maxHdcpLevel}" or lower`)}n.resolved||this.switchLevel(t,a)}switchLevel(t,e){void 0!==e&&t.errorAction&&(this.warn(`switching to level ${e} after ${t.details}`),this.hls.nextAutoLevel=e,t.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel)}},fpsController:class{constructor(t){this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=t,this.registerListeners()}setStreamController(t){this.streamController=t}registerListeners(){this.hls.on(tt.MEDIA_ATTACHING,this.onMediaAttaching,this)}unregisterListeners(){this.hls.off(tt.MEDIA_ATTACHING,this.onMediaAttaching,this)}destroy(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null}onMediaAttaching(t,e){const n=this.hls.config;if(n.capLevelOnFPSDrop){const t=e.media instanceof self.HTMLVideoElement?e.media:null;this.media=t,t&&"function"==typeof t.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),n.fpsDroppedMonitoringPeriod)}}checkFPS(t,e,n){const i=performance.now();if(e){if(this.lastTime){const t=i-this.lastTime,r=n-this.lastDroppedFrames,a=e-this.lastDecodedFrames,s=1e3*r/t,o=this.hls;if(o.trigger(tt.FPS_DROP,{currentDropped:r,currentDecoded:a,totalDroppedFrames:n}),s>0&&r>o.config.fpsDroppedMonitoringThreshold*a){let t=o.currentLevel;ot.warn("drop FPS ratio greater than max allowed value for currentLevel: "+t),t>0&&(-1===o.autoLevelCapping||o.autoLevelCapping>=t)&&(t-=1,o.trigger(tt.FPS_DROP_LEVEL_CAPPING,{level:t,droppedLevel:o.currentLevel}),o.autoLevelCapping=t,this.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=n,this.lastDecodedFrames=e}}checkFPSInterval(){const t=this.media;if(t)if(this.isVideoPlaybackQualityAvailable){const e=t.getVideoPlaybackQuality();this.checkFPS(t,e.totalVideoFrames,e.droppedVideoFrames)}else this.checkFPS(t,t.webkitDecodedFrameCount,t.webkitDroppedFrameCount)}},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:Pt,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0,useMediaCapabilities:!0,certLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:null,errorRetry:null}},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}}},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:uo,enableWebVTT:!0,enableIMSC1:!0,enableCEA708Captions:!0,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}),{},{subtitleStreamController:class extends rr{constructor(t,e,n){super(t,e,n,"[subtitle-stream-controller]",cn),this.currentTrackId=-1,this.tracksBuffered=[],this.mainDetails=null,this._registerListeners()}onHandlerDestroying(){this._unregisterListeners(),super.onHandlerDestroying(),this.mainDetails=null}_registerListeners(){const{hls:t}=this;t.on(tt.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.LEVEL_LOADED,this.onLevelLoaded,this),t.on(tt.ERROR,this.onError,this),t.on(tt.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(tt.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.on(tt.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.on(tt.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.on(tt.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(tt.FRAG_BUFFERED,this.onFragBuffered,this)}_unregisterListeners(){const{hls:t}=this;t.off(tt.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.LEVEL_LOADED,this.onLevelLoaded,this),t.off(tt.ERROR,this.onError,this),t.off(tt.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(tt.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.off(tt.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.off(tt.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.off(tt.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(tt.FRAG_BUFFERED,this.onFragBuffered,this)}startLoad(t){this.stopLoad(),this.state=qi,this.setInterval(500),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}onManifestLoading(){this.mainDetails=null,this.fragmentTracker.removeAllFragments()}onMediaDetaching(){this.tracksBuffered=[],super.onMediaDetaching()}onLevelLoaded(t,e){this.mainDetails=e.details}onSubtitleFragProcessed(t,e){const{frag:n,success:i}=e;if(this.fragPrevious=n,this.state=qi,!i)return;const r=this.tracksBuffered[this.currentTrackId];if(!r)return;let a;const s=n.start;for(let t=0;t=r[t].start&&s<=r[t].end){a=r[t];break}const o=n.start+n.duration;a?a.end=o:(a={start:s,end:o},r.push(a)),this.fragmentTracker.fragBuffered(n),this.fragBufferedComplete(n,null)}onBufferFlushing(t,e){const{startOffset:n,endOffset:i}=e;if(0===n&&i!==Number.POSITIVE_INFINITY){const t=i-1;if(t<=0)return;e.endOffsetSubtitles=Math.max(0,t),this.tracksBuffered.forEach((e=>{for(let n=0;nnew Un(t))):(this.tracksBuffered=[],this.levels=e.map((t=>{const e=new Un(t);return this.tracksBuffered[e.id]=[],e})),this.fragmentTracker.removeFragmentsInRange(0,Number.POSITIVE_INFINITY,cn),this.fragPrevious=null,this.mediaBuffer=null)}onSubtitleTrackSwitch(t,e){var n;if(this.currentTrackId=e.id,null==(n=this.levels)||!n.length||-1===this.currentTrackId)return void this.clearInterval();const i=this.levels[this.currentTrackId];null!=i&&i.details?this.mediaBuffer=this.mediaBufferTimeRanges:this.mediaBuffer=null,i&&this.setInterval(500)}onSubtitleTrackLoaded(t,e){var n;const{currentTrackId:i,levels:r}=this,{details:a,id:s}=e;if(!r)return void this.warn(`Subtitle tracks were reset while loading level ${s}`);const o=r[i];if(s>=r.length||s!==i||!o)return;this.log(`Subtitle track ${s} loaded [${a.startSN},${a.endSN}]${a.lastPartSn?`[part-${a.lastPartSn}-${a.lastPartIndex}]`:""},duration:${a.totalduration}`),this.mediaBuffer=this.mediaBufferTimeRanges;let l=0;if(a.live||null!=(n=o.details)&&n.live){const t=this.mainDetails;if(a.deltaUpdateFailed||!t)return;const e=t.fragments[0];var d;if(o.details)l=this.alignPlaylists(a,o.details,null==(d=this.levelLastLoaded)?void 0:d.details),0===l&&e&&(l=e.start,Gn(a,l));else a.hasProgramDateTime&&t.hasProgramDateTime?(Ui(a,t),l=a.fragments[0].start):e&&(l=e.start,Gn(a,l))}if(o.details=a,this.levelLastLoaded=o,this.startFragRequested||!this.mainDetails&&a.live||this.setStartPosition(this.mainDetails||a,l),this.tick(),a.live&&!this.fragCurrent&&this.media&&this.state===qi){Xn(null,a.fragments,this.media.currentTime,0)||(this.warn("Subtitle playlist not aligned with playback"),o.details=void 0)}}_handleFragmentLoadComplete(t){const{frag:e,payload:n}=t,i=e.decryptdata,r=this.hls;if(!this.fragContextChanged(e)&&n&&n.byteLength>0&&null!=i&&i.key&&i.iv&&"AES-128"===i.method){const t=performance.now();this.decrypter.decrypt(new Uint8Array(n),i.key.buffer,i.iv.buffer).catch((t=>{throw r.trigger(tt.ERROR,{type:et.MEDIA_ERROR,details:nt.FRAG_DECRYPT_ERROR,fatal:!1,error:t,reason:t.message,frag:e}),t})).then((n=>{const i=performance.now();r.trigger(tt.FRAG_DECRYPTED,{frag:e,payload:n,stats:{tstart:t,tdecrypt:i}})})).catch((t=>{this.warn(`${t.name}: ${t.message}`),this.state=qi}))}}doTick(){if(this.media){if(this.state===qi){const{currentTrackId:t,levels:e}=this,n=null==e?void 0:e[t];if(!n||!e.length||!n.details)return;const{config:i}=this,r=this.getLoadPosition(),a=Li.bufferedInfo(this.tracksBuffered[this.currentTrackId]||[],r,i.maxBufferHole),{end:s,len:o}=a,l=this.getFwdBufferInfo(this.media,ln),d=n.details;if(o>this.getMaxBufferLength(null==l?void 0:l.len)+d.levelTargetDuration)return;const c=d.fragments,u=c.length,h=d.edge;let p=null;const f=this.fragPrevious;if(sh-t?0:t;p=Xn(f,c,Math.max(c[0].start,s),e),!p&&f&&f.startthis.pollTrackChange(0),this.useTextTrackPolling=!1,this.subtitlePollingInterval=-1,this._subtitleDisplay=!0,this.onTextTracksChanged=()=>{if(this.useTextTrackPolling||self.clearInterval(this.subtitlePollingInterval),!this.media||!this.hls.config.renderTextTracksNatively)return;let t=null;const e=An(this.media.textTracks);for(let n=0;n-1&&this.toggleTrackModes()}registerListeners(){const{hls:t}=this;t.on(tt.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.on(tt.LEVEL_LOADING,this.onLevelLoading,this),t.on(tt.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(tt.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.on(tt.ERROR,this.onError,this)}unregisterListeners(){const{hls:t}=this;t.off(tt.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.off(tt.LEVEL_LOADING,this.onLevelLoading,this),t.off(tt.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(tt.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.off(tt.ERROR,this.onError,this)}onMediaAttached(t,e){this.media=e.media,this.media&&(this.queuedDefaultTrack>-1&&(this.subtitleTrack=this.queuedDefaultTrack,this.queuedDefaultTrack=-1),this.useTextTrackPolling=!(this.media.textTracks&&"onchange"in this.media.textTracks),this.useTextTrackPolling?this.pollTrackChange(500):this.media.textTracks.addEventListener("change",this.asyncPollTrackChange))}pollTrackChange(t){self.clearInterval(this.subtitlePollingInterval),this.subtitlePollingInterval=self.setInterval(this.onTextTracksChanged,t)}onMediaDetaching(){if(!this.media)return;self.clearInterval(this.subtitlePollingInterval),this.useTextTrackPolling||this.media.textTracks.removeEventListener("change",this.asyncPollTrackChange),this.trackId>-1&&(this.queuedDefaultTrack=this.trackId);An(this.media.textTracks).forEach((t=>{gn(t)})),this.subtitleTrack=-1,this.media=null}onManifestLoading(){this.tracks=[],this.groupIds=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0}onManifestParsed(t,e){this.tracks=e.subtitleTracks}onSubtitleTrackLoaded(t,e){const{id:n,groupId:i,details:r}=e,a=this.tracksInGroup[n];if(!a||a.groupId!==i)return void this.warn(`Subtitle track with id:${n} and group:${i} not found in active group ${null==a?void 0:a.groupId}`);const s=a.details;a.details=e.details,this.log(`Subtitle track ${n} "${a.name}" lang:${a.lang} group:${i} loaded [${r.startSN}-${r.endSN}]`),n===this.trackId&&this.playlistLoaded(n,e,s)}onLevelLoading(t,e){this.switchLevel(e.level)}onLevelSwitching(t,e){this.switchLevel(e.level)}switchLevel(t){const e=this.hls.levels[t];if(!e)return;const n=e.subtitleGroups||null,i=this.groupIds;let r=this.currentTrack;if(!n||(null==i?void 0:i.length)!==(null==n?void 0:n.length)||null!=n&&n.some((t=>-1===(null==i?void 0:i.indexOf(t))))){this.groupIds=n,this.trackId=-1,this.currentTrack=null;const t=this.tracks.filter((t=>!n||-1!==n.indexOf(t.groupId)));if(t.length)this.selectDefaultTrack&&!t.some((t=>t.default))&&(this.selectDefaultTrack=!1),t.forEach(((t,e)=>{t.id=e}));else if(!r&&!this.tracksInGroup.length)return;this.tracksInGroup=t;const e=this.hls.config.subtitlePreference;if(!r&&e){this.selectDefaultTrack=!1;const n=gi(e,t);if(n>-1)r=t[n];else{const t=gi(e,this.tracks);r=this.tracks[t]}}let i=this.findTrackId(r);-1===i&&r&&(i=this.findTrackId(null));const a={subtitleTracks:t};this.log(`Updating subtitle tracks, ${t.length} track(s) found in "${null==n?void 0:n.join(",")}" group-id`),this.hls.trigger(tt.SUBTITLE_TRACKS_UPDATED,a),-1!==i&&-1===this.trackId&&this.setSubtitleTrack(i)}else this.shouldReloadPlaylist(r)&&this.setSubtitleTrack(this.trackId)}findTrackId(t){const e=this.tracksInGroup,n=this.selectDefaultTrack;for(let i=0;i-1){const t=this.tracksInGroup[i];return this.setSubtitleTrack(i),t}if(n)return null;{const n=gi(t,e);if(n>-1)return e[n]}}}return null}loadPlaylist(t){super.loadPlaylist();const e=this.currentTrack;if(this.shouldLoadPlaylist(e)&&e){const n=e.id,i=e.groupId;let r=e.url;if(t)try{r=t.addDirectives(r)}catch(t){this.warn(`Could not construct new URL with HLS Delivery Directives: ${t}`)}this.log(`Loading subtitle playlist for id ${n}`),this.hls.trigger(tt.SUBTITLE_TRACK_LOADING,{url:r,id:n,groupId:i,deliveryDirectives:t||null})}}toggleTrackModes(){const{media:t}=this;if(!t)return;const e=An(t.textTracks),n=this.currentTrack;let i;if(n&&(i=e.filter((t=>fa(n,t)))[0],i||this.warn(`Unable to find subtitle TextTrack with name "${n.name}" and language "${n.lang}"`)),[].slice.call(e).forEach((t=>{"disabled"!==t.mode&&t!==i&&(t.mode="disabled")})),i){const t=this.subtitleDisplay?"showing":"hidden";i.mode!==t&&(i.mode=t)}}setSubtitleTrack(t){const e=this.tracksInGroup;if(!this.media)return void(this.queuedDefaultTrack=t);if(t<-1||t>=e.length||!X(t))return void this.warn(`Invalid subtitle track id: ${t}`);this.clearTimer(),this.selectDefaultTrack=!1;const n=this.currentTrack,i=e[t]||null;if(this.trackId=t,this.currentTrack=i,this.toggleTrackModes(),!i)return void this.hls.trigger(tt.SUBTITLE_TRACK_SWITCH,{id:t});const r=!!i.details&&!i.details.live;if(t===this.trackId&&i===n&&r)return;this.log(`Switching to subtitle-track ${t}`+(i?` "${i.name}" lang:${i.lang} group:${i.groupId}`:""));const{id:a,groupId:s="",name:o,type:l,url:d}=i;this.hls.trigger(tt.SUBTITLE_TRACK_SWITCH,{id:a,groupId:s,name:o,type:l,url:d});const c=this.switchParams(i.url,null==n?void 0:n.details,i.details);this.loadPlaylist(c)}},timelineController:class{constructor(t){this.hls=void 0,this.media=null,this.config=void 0,this.enabled=!0,this.Cues=void 0,this.textTracks=[],this.tracks=[],this.initPTS=[],this.unparsedVttFrags=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.cea608Parser1=void 0,this.cea608Parser2=void 0,this.lastCc=-1,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}},this.captionsProperties=void 0,this.hls=t,this.config=t.config,this.Cues=t.config.cueHandler,this.captionsProperties={textTrack1:{label:this.config.captionsTextTrack1Label,languageCode:this.config.captionsTextTrack1LanguageCode},textTrack2:{label:this.config.captionsTextTrack2Label,languageCode:this.config.captionsTextTrack2LanguageCode},textTrack3:{label:this.config.captionsTextTrack3Label,languageCode:this.config.captionsTextTrack3LanguageCode},textTrack4:{label:this.config.captionsTextTrack4Label,languageCode:this.config.captionsTextTrack4LanguageCode}},t.on(tt.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(tt.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(tt.FRAG_LOADING,this.onFragLoading,this),t.on(tt.FRAG_LOADED,this.onFragLoaded,this),t.on(tt.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.on(tt.FRAG_DECRYPTED,this.onFragDecrypted,this),t.on(tt.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(tt.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.on(tt.BUFFER_FLUSHING,this.onBufferFlushing,this)}destroy(){const{hls:t}=this;t.off(tt.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(tt.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(tt.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(tt.FRAG_LOADING,this.onFragLoading,this),t.off(tt.FRAG_LOADED,this.onFragLoaded,this),t.off(tt.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.off(tt.FRAG_DECRYPTED,this.onFragDecrypted,this),t.off(tt.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(tt.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.off(tt.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=null,this.cea608Parser1=this.cea608Parser2=void 0}initCea608Parsers(){if(this.config.enableCEA708Captions&&(!this.cea608Parser1||!this.cea608Parser2)){const t=new Ma(this,"textTrack1"),e=new Ma(this,"textTrack2"),n=new Ma(this,"textTrack3"),i=new Ma(this,"textTrack4");this.cea608Parser1=new Ua(1,t,e),this.cea608Parser2=new Ua(3,n,i)}}addCues(t,e,n,i,r){let a=!1;for(let t=r.length;t--;){const i=r[t],c=(s=i[0],o=i[1],l=e,d=n,Math.min(o,d)-Math.max(s,l));if(c>=0&&(i[0]=Math.min(i[0],e),i[1]=Math.max(i[1],n),a=!0,c/(n-e)>.5))return}var s,o,l,d;if(a||r.push([e,n]),this.config.renderTextTracksNatively){const r=this.captionsTracks[t];this.Cues.newCue(r,e,n,i)}else{const r=this.Cues.newCue(null,e,n,i);this.hls.trigger(tt.CUES_PARSED,{type:"captions",cues:r,track:t})}}onInitPtsFound(t,{frag:e,id:n,initPTS:i,timescale:r}){const{unparsedVttFrags:a}=this;"main"===n&&(this.initPTS[e.cc]={baseTime:i,timescale:r}),a.length&&(this.unparsedVttFrags=[],a.forEach((t=>{this.onFragLoaded(tt.FRAG_LOADED,t)})))}getExistingTrack(t,e){const{media:n}=this;if(n)for(let i=0;i{gn(t[e]),delete t[e]})),this.nonNativeCaptionsTracks={}}onManifestLoading(){this.lastCc=-1,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}},this._cleanTracks(),this.tracks=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.textTracks=[],this.unparsedVttFrags=[],this.initPTS=[],this.cea608Parser1&&this.cea608Parser2&&(this.cea608Parser1.reset(),this.cea608Parser2.reset())}_cleanTracks(){const{media:t}=this;if(!t)return;const e=t.textTracks;if(e)for(let t=0;tt.textCodec===ts));if(this.config.enableWebVTT||i&&this.config.enableIMSC1){if(ha(this.tracks,n))return void(this.tracks=n);if(this.textTracks=[],this.tracks=n,this.config.renderTextTracksNatively){const t=this.media,e=t?An(t.textTracks):null;if(this.tracks.forEach(((t,n)=>{let i;if(e){let n=null;for(let i=0;inull!==t)).map((t=>t.label));t.length&&ot.warn(`Media element contains unused subtitle tracks: ${t.join(", ")}. Replace media element for each source to clear TextTracks and captions menu.`)}}else if(this.tracks.length){const t=this.tracks.map((t=>({label:t.name,kind:t.type.toLowerCase(),default:t.default,subtitleTrack:t})));this.hls.trigger(tt.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:t})}}}onManifestLoaded(t,e){this.config.enableCEA708Captions&&e.captions&&e.captions.forEach((t=>{const e=/(?:CC|SERVICE)([1-4])/.exec(t.instreamId);if(!e)return;const n=`textTrack${e[1]}`,i=this.captionsProperties[n];i&&(i.label=t.name,t.lang&&(i.languageCode=t.lang),i.media=t)}))}closedCaptionsForLevel(t){const e=this.hls.levels[t.level];return null==e?void 0:e.attrs["CLOSED-CAPTIONS"]}onFragLoading(t,e){this.initCea608Parsers();const{cea608Parser1:n,cea608Parser2:i,lastCc:r,lastSn:a,lastPartIndex:s}=this;if(this.enabled&&n&&i&&e.frag.type===ln){var o,l;const{cc:t,sn:d}=e.frag,c=null!=(o=null==e||null==(l=e.part)?void 0:l.index)?o:-1;d===a+1||d===a&&c===s+1||t===r||(n.reset(),i.reset()),this.lastCc=t,this.lastSn=d,this.lastPartIndex=c}}onFragLoaded(t,e){const{frag:n,payload:i}=e;if(n.type===cn)if(i.byteLength){const t=n.decryptdata,r="stats"in e;if(null==t||!t.encrypted||r){const t=this.tracks[n.level],r=this.vttCCs;r[n.cc]||(r[n.cc]={start:n.start,prevCC:this.prevCC,new:!0},this.prevCC=n.cc),t&&t.textCodec===ts?this._parseIMSC1(n,i):this._parseVTTs(e)}}else this.hls.trigger(tt.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:n,error:new Error("Empty subtitle payload")})}_parseIMSC1(t,e){const n=this.hls;rs(e,this.initPTS[t.cc],(e=>{this._appendCues(e,t.level),n.trigger(tt.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:t})}),(e=>{ot.log(`Failed to parse IMSC1: ${e}`),n.trigger(tt.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:t,error:e})}))}_parseVTTs(t){var e;const{frag:n,payload:i}=t,{initPTS:r,unparsedVttFrags:a}=this,s=r.length-1;if(!r[n.cc]&&-1===s)return void a.push(t);const o=this.hls;Za(null!=(e=n.initSegment)&&e.data?ve(n.initSegment.data,new Uint8Array(i)):i,this.initPTS[n.cc],this.vttCCs,n.cc,n.start,(t=>{this._appendCues(t,n.level),o.trigger(tt.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:n})}),(e=>{const r="Missing initPTS for VTT MPEGTS"===e.message;r?a.push(t):this._fallbackToIMSC1(n,i),ot.log(`Failed to parse VTT cue: ${e}`),r&&s>n.cc||o.trigger(tt.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:n,error:e})}))}_fallbackToIMSC1(t,e){const n=this.tracks[t.level];n.textCodec||rs(e,this.initPTS[t.cc],(()=>{n.textCodec=ts,this._parseIMSC1(t,e)}),(()=>{n.textCodec="wvtt"}))}_appendCues(t,e){const n=this.hls;if(this.config.renderTextTracksNatively){const n=this.textTracks[e];if(!n||"disabled"===n.mode)return;t.forEach((t=>mn(n,t)))}else{const i=this.tracks[e];if(!i)return;const r=i.default?"default":"subtitles"+e;n.trigger(tt.CUES_PARSED,{type:"subtitles",cues:t,track:r})}}onFragDecrypted(t,e){const{frag:n}=e;n.type===cn&&this.onFragLoaded(tt.FRAG_LOADED,e)}onSubtitleTracksCleared(){this.tracks=[],this.captionsTracks={}}onFragParsingUserdata(t,e){this.initCea608Parsers();const{cea608Parser1:n,cea608Parser2:i}=this;if(!this.enabled||!n||!i)return;const{frag:r,samples:a}=e;if(r.type!==ln||"NONE"!==this.closedCaptionsForLevel(r))for(let t=0;tyn(t[i],e,n)))}if(this.config.renderTextTracksNatively&&0===e&&void 0!==i){const{textTracks:t}=this;Object.keys(t).forEach((n=>yn(t[n],e,i)))}}}extractCea608Data(t){const e=[[],[]],n=31&t[0];let i=2;for(let r=0;r0&&-1===t?(this.log(`Override startPosition with lastCurrentTime @${e.toFixed(3)}`),t=e,this.state=qi):(this.loadedmetadata=!1,this.state=Xi),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}doTick(){switch(this.state){case qi:this.doTickIdle();break;case Xi:{var t;const{levels:e,trackId:n}=this,i=null==e||null==(t=e[n])?void 0:t.details;if(i){if(this.waitForCdnTuneIn(i))break;this.state=nr}break}case Qi:{var e;const t=performance.now(),n=this.retryDate;if(!n||t>=n||null!=(e=this.media)&&e.seeking){const{levels:t,trackId:e}=this;this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded((null==t?void 0:t[e])||null),this.state=qi}break}case nr:{const t=this.waitingData;if(t){const{frag:e,part:n,cache:i,complete:r}=t;if(void 0!==this.initPTS[e.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=Wi;const t={frag:e,part:n,payload:i.flush(),networkDetails:null};this._handleFragmentLoadProgress(t),r&&super._handleFragmentLoadComplete(t)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log(`Waiting fragment cc (${e.cc}) cancelled because video is at cc ${this.videoTrackCC}`),this.clearWaitingFragment();else{const t=this.getLoadPosition(),n=Li.bufferInfo(this.mediaBuffer,t,this.config.maxBufferHole);Jn(n.end,this.config.maxFragLookUpTolerance,e)<0&&(this.log(`Waiting fragment cc (${e.cc}) @ ${e.start} cancelled because another fragment at ${n.end} is needed`),this.clearWaitingFragment())}}else this.state=qi}}this.onTickEnd()}clearWaitingFragment(){const t=this.waitingData;t&&(this.fragmentTracker.removeFragment(t.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=qi)}resetLoadingState(){this.clearWaitingFragment(),super.resetLoadingState()}onTickEnd(){const{media:t}=this;null!=t&&t.readyState&&(this.lastCurrentTime=t.currentTime)}doTickIdle(){const{hls:t,levels:e,media:n,trackId:i}=this,r=t.config;if(!n&&(this.startFragRequested||!r.startFragPrefetch)||null==e||!e[i])return;const a=e[i],s=a.details;if(!s||s.live&&this.levelLastLoaded!==a||this.waitForCdnTuneIn(s))return void(this.state=Xi);const o=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&o&&(this.bufferFlushed=!1,this.afterBufferFlushed(o,ft,dn));const l=this.getFwdBufferInfo(o,dn);if(null===l)return;const{bufferedTrack:d,switchingTrack:c}=this;if(!c&&this._streamEnded(l,s))return t.trigger(tt.BUFFER_EOS,{type:"audio"}),void(this.state=tr);const u=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,ln),h=l.len,p=this.getMaxBufferLength(null==u?void 0:u.len),f=s.fragments,m=f[0].start;let g=this.flushing?this.getLoadPosition():l.end;if(c&&n){const t=this.getLoadPosition();d&&!pa(c.attrs,d.attrs)&&(g=t),s.PTSKnown&&tm||l.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),n.currentTime=m+.05)}if(h>=p&&!c&&gu.end+s.targetduration;if(v||(null==u||!u.len)&&l.len){const t=this.getAppendedFrag(y.start,ln);if(null===t)return;if(A||(A=!!t.gap||!!v&&0===u.len),v&&!A||A&&l.nextStart&&l.nextStartnew Un(t)))}onAudioTrackSwitching(t,e){const n=!!e.url;this.trackId=e.id;const{fragCurrent:i}=this;i&&(i.abortRequests(),this.removeUnbufferedFrags(i.start)),this.resetLoadingState(),n?this.setInterval(100):this.resetTransmuxer(),n?(this.switchingTrack=e,this.state=qi,this.flushAudioIfNeeded(e)):(this.switchingTrack=null,this.bufferedTrack=e,this.state=Ki),this.tick()}onManifestLoading(){this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=this.flushing=!1,this.levels=this.mainDetails=this.waitingData=this.bufferedTrack=this.cachedTrackLoadedData=this.switchingTrack=null,this.startFragRequested=!1,this.trackId=this.videoTrackCC=this.waitingVideoCC=-1}onLevelLoaded(t,e){this.mainDetails=e.details,null!==this.cachedTrackLoadedData&&(this.hls.trigger(tt.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)}onAudioTrackLoaded(t,e){var n;if(null==this.mainDetails)return void(this.cachedTrackLoadedData=e);const{levels:i}=this,{details:r,id:a}=e;if(!i)return void this.warn(`Audio tracks were reset while loading level ${a}`);this.log(`Audio track ${a} loaded [${r.startSN},${r.endSN}]${r.lastPartSn?`[part-${r.lastPartSn}-${r.lastPartIndex}]`:""},duration:${r.totalduration}`);const s=i[a];let o=0;if(r.live||null!=(n=s.details)&&n.live){this.checkLiveUpdate(r);const t=this.mainDetails;if(r.deltaUpdateFailed||!t)return;var l;if(!s.details&&r.hasProgramDateTime&&t.hasProgramDateTime)Ui(r,t),o=r.fragments[0].start;else o=this.alignPlaylists(r,s.details,null==(l=this.levelLastLoaded)?void 0:l.details)}s.details=r,this.levelLastLoaded=s,this.startFragRequested||!this.mainDetails&&r.live||this.setStartPosition(this.mainDetails||r,o),this.state!==Xi||this.waitForCdnTuneIn(r)||(this.state=qi),this.tick()}_handleFragmentLoadProgress(t){var e;const{frag:n,part:i,payload:r}=t,{config:a,trackId:s,levels:o}=this;if(!o)return void this.warn(`Audio tracks were reset while fragment load was in progress. Fragment ${n.sn} of level ${n.level} will not be buffered`);const l=o[s];if(!l)return void this.warn("Audio track is undefined on fragment load progress");const d=l.details;if(!d)return this.warn("Audio track details undefined on fragment load progress"),void this.removeUnbufferedFrags(n.start);const c=a.defaultAudioCodec||l.audioCodec||"mp4a.40.2";let u=this.transmuxer;u||(u=this.transmuxer=new ua(this.hls,dn,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));const h=this.initPTS[n.cc],p=null==(e=n.initSegment)?void 0:e.data;if(void 0!==h){const t=!1,e=i?i.index:-1,a=-1!==e,s=new Ii(n.level,n.sn,n.stats.chunkCount,r.byteLength,e,a);u.push(r,p,c,"",n,i,d.totalduration,t,s,h)}else{this.log(`Unknown video PTS for cc ${n.cc}, waiting for video PTS before demuxing audio frag ${n.sn} of [${d.startSN} ,${d.endSN}],track ${s}`);const{cache:t}=this.waitingData=this.waitingData||{frag:n,part:i,cache:new ar,complete:!1};t.push(new Uint8Array(r)),this.waitingVideoCC=this.videoTrackCC,this.state=nr}}_handleFragmentLoadComplete(t){this.waitingData?this.waitingData.complete=!0:super._handleFragmentLoadComplete(t)}onBufferReset(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1}onBufferCreated(t,e){const n=e.tracks.audio;n&&(this.mediaBuffer=n.buffer||null),e.tracks.video&&(this.videoBuffer=e.tracks.video.buffer||null)}onFragBuffered(t,e){const{frag:n,part:i}=e;if(n.type===dn)if(this.fragContextChanged(n))this.warn(`Fragment ${n.sn}${i?" p: "+i.index:""} of level ${n.level} finished buffering, but was aborted. state: ${this.state}, audioSwitch: ${this.switchingTrack?this.switchingTrack.name:"false"}`);else{if("initSegment"!==n.sn){this.fragPrevious=n;const t=this.switchingTrack;t&&(this.bufferedTrack=t,this.switchingTrack=null,this.hls.trigger(tt.AUDIO_TRACK_SWITCHED,q({},t)))}this.fragBufferedComplete(n,i)}else if(!this.loadedmetadata&&n.type===ln){const t=this.videoBuffer||this.media;if(t){Li.getBuffered(t).length&&(this.loadedmetadata=!0)}}}onError(t,e){var n;if(e.fatal)this.state=er;else switch(e.details){case nt.FRAG_GAP:case nt.FRAG_PARSING_ERROR:case nt.FRAG_DECRYPT_ERROR:case nt.FRAG_LOAD_ERROR:case nt.FRAG_LOAD_TIMEOUT:case nt.KEY_LOAD_ERROR:case nt.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(dn,e);break;case nt.AUDIO_TRACK_LOAD_ERROR:case nt.AUDIO_TRACK_LOAD_TIMEOUT:case nt.LEVEL_PARSING_ERROR:e.levelRetry||this.state!==Xi||(null==(n=e.context)?void 0:n.type)!==sn||(this.state=qi);break;case nt.BUFFER_APPEND_ERROR:case nt.BUFFER_FULL_ERROR:if(!e.parent||"audio"!==e.parent)return;if(e.details===nt.BUFFER_APPEND_ERROR)return void this.resetLoadingState();this.reduceLengthAndFlushBuffer(e)&&(this.bufferedTrack=null,super.flushMainBuffer(0,Number.POSITIVE_INFINITY,"audio"));break;case nt.INTERNAL_EXCEPTION:this.recoverWorkerError(e)}}onBufferFlushing(t,{type:e}){e!==mt&&(this.flushing=!0)}onBufferFlushed(t,{type:e}){if(e!==mt){this.flushing=!1,this.bufferFlushed=!0,this.state===tr&&(this.state=qi);const t=this.mediaBuffer||this.media;t&&(this.afterBufferFlushed(t,e,dn),this.tick())}}_handleTransmuxComplete(t){var e;const n="audio",{hls:i}=this,{remuxResult:r,chunkMeta:a}=t,s=this.getCurrentContext(a);if(!s)return void this.resetWhenMissingContext(a);const{frag:o,part:l,level:d}=s,{details:c}=d,{audio:u,text:h,id3:p,initSegment:f}=r;if(!this.fragContextChanged(o)&&c){if(this.state=Ji,this.switchingTrack&&u&&this.completeAudioSwitch(this.switchingTrack),null!=f&&f.tracks){const t=o.initSegment||o;this._bufferInitSegment(d,f.tracks,t,a),i.trigger(tt.FRAG_PARSING_INIT_SEGMENT,{frag:t,id:n,tracks:f.tracks})}if(u){const{startPTS:t,endPTS:e,startDTS:n,endDTS:i}=u;l&&(l.elementaryStreams[ft]={startPTS:t,endPTS:e,startDTS:n,endDTS:i}),o.setElementaryStreamInfo(ft,t,e,n,i),this.bufferFragmentData(u,o,l,a)}if(null!=p&&null!=(e=p.samples)&&e.length){const t=Q({id:n,frag:o,details:c},p);i.trigger(tt.FRAG_PARSING_METADATA,t)}if(h){const t=Q({id:n,frag:o,details:c},h);i.trigger(tt.FRAG_PARSING_USERDATA,t)}}else this.fragmentTracker.removeFragment(o)}_bufferInitSegment(t,e,n,i){if(this.state!==Ji)return;e.video&&delete e.video;const r=e.audio;if(!r)return;r.id="audio";const a=t.audioCodec;this.log(`Init audio buffer, container:${r.container}, codecs[level/parsed]=[${a}/${r.codec}]`),a&&1===a.split(",").length&&(r.levelCodec=a),this.hls.trigger(tt.BUFFER_CODECS,e);const s=r.initSegment;if(null!=s&&s.byteLength){const t={type:"audio",frag:n,part:null,chunkMeta:i,parent:n.type,data:s};this.hls.trigger(tt.BUFFER_APPENDING,t)}this.tickImmediate()}loadFragment(t,e,n){const i=this.fragmentTracker.getState(t);var r;if(this.fragCurrent=t,this.switchingTrack||i===Ei||i===xi)if("initSegment"===t.sn)this._loadInitSegment(t,e);else if(null!=(r=e.details)&&r.live&&!this.initPTS[t.cc]){this.log(`Waiting for video PTS in continuity counter ${t.cc} of live stream before loading audio fragment ${t.sn} of level ${this.trackId}`),this.state=nr;const n=this.mainDetails;n&&n.fragments[0].start!==e.details.fragments[0].start&&Ui(e.details,n)}else this.startFragRequested=!0,super.loadFragment(t,e,n);else this.clearTrackerIfNeeded(t)}flushAudioIfNeeded(t){const{media:e,bufferedTrack:n}=this,i=null==n?void 0:n.attrs,r=t.attrs;e&&i&&(i.CHANNELS!==r.CHANNELS||n.name!==t.name||n.lang!==t.lang)&&(this.log("Switching audio track : flushing all audio"),super.flushMainBuffer(0,Number.POSITIVE_INFINITY,"audio"),this.bufferedTrack=null)}completeAudioSwitch(t){const{hls:e}=this;this.flushAudioIfNeeded(t),this.bufferedTrack=t,this.switchingTrack=null,e.trigger(tt.AUDIO_TRACK_SWITCHED,q({},t))}},audioTrackController:class extends oi{constructor(t){super(t,"[audio-track-controller]"),this.tracks=[],this.groupIds=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0,this.registerListeners()}registerListeners(){const{hls:t}=this;t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.on(tt.LEVEL_LOADING,this.onLevelLoading,this),t.on(tt.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(tt.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.on(tt.ERROR,this.onError,this)}unregisterListeners(){const{hls:t}=this;t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.off(tt.LEVEL_LOADING,this.onLevelLoading,this),t.off(tt.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(tt.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.off(tt.ERROR,this.onError,this)}destroy(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.currentTrack=null,super.destroy()}onManifestLoading(){this.tracks=[],this.tracksInGroup=[],this.groupIds=null,this.currentTrack=null,this.trackId=-1,this.selectDefaultTrack=!0}onManifestParsed(t,e){this.tracks=e.audioTracks||[]}onAudioTrackLoaded(t,e){const{id:n,groupId:i,details:r}=e,a=this.tracksInGroup[n];if(!a||a.groupId!==i)return void this.warn(`Audio track with id:${n} and group:${i} not found in active group ${null==a?void 0:a.groupId}`);const s=a.details;a.details=e.details,this.log(`Audio track ${n} "${a.name}" lang:${a.lang} group:${i} loaded [${r.startSN}-${r.endSN}]`),n===this.trackId&&this.playlistLoaded(n,e,s)}onLevelLoading(t,e){this.switchLevel(e.level)}onLevelSwitching(t,e){this.switchLevel(e.level)}switchLevel(t){const e=this.hls.levels[t];if(!e)return;const n=e.audioGroups||null,i=this.groupIds;let r=this.currentTrack;if(!n||(null==i?void 0:i.length)!==(null==n?void 0:n.length)||null!=n&&n.some((t=>-1===(null==i?void 0:i.indexOf(t))))){this.groupIds=n,this.trackId=-1,this.currentTrack=null;const t=this.tracks.filter((t=>!n||-1!==n.indexOf(t.groupId)));if(t.length)this.selectDefaultTrack&&!t.some((t=>t.default))&&(this.selectDefaultTrack=!1),t.forEach(((t,e)=>{t.id=e}));else if(!r&&!this.tracksInGroup.length)return;this.tracksInGroup=t;const e=this.hls.config.audioPreference;if(!r&&e){const n=gi(e,t,Ai);if(n>-1)r=t[n];else{const t=gi(e,this.tracks);r=this.tracks[t]}}let i=this.findTrackId(r);-1===i&&r&&(i=this.findTrackId(null));const s={audioTracks:t};this.log(`Updating audio tracks, ${t.length} track(s) found in group(s): ${null==n?void 0:n.join(",")}`),this.hls.trigger(tt.AUDIO_TRACKS_UPDATED,s);const o=this.trackId;if(-1!==i&&-1===o)this.setAudioTrack(i);else if(t.length&&-1===o){var a;const e=new Error(`No audio track selected for current audio group-ID(s): ${null==(a=this.groupIds)?void 0:a.join(",")} track count: ${t.length}`);this.warn(e.message),this.hls.trigger(tt.ERROR,{type:et.MEDIA_ERROR,details:nt.AUDIO_TRACK_LOAD_ERROR,fatal:!0,error:e})}}else this.shouldReloadPlaylist(r)&&this.setAudioTrack(this.trackId)}onError(t,e){!e.fatal&&e.context&&(e.context.type!==sn||e.context.id!==this.trackId||this.groupIds&&-1===this.groupIds.indexOf(e.context.groupId)||(this.requestScheduled=-1,this.checkRetry(e)))}get allAudioTracks(){return this.tracks}get audioTracks(){return this.tracksInGroup}get audioTrack(){return this.trackId}set audioTrack(t){this.selectDefaultTrack=!1,this.setAudioTrack(t)}setAudioOption(t){const e=this.hls;if(e.config.audioPreference=t,t){const n=this.allAudioTracks;if(this.selectDefaultTrack=!1,n.length){const i=this.currentTrack;if(i&&yi(t,i,Ai))return i;const r=gi(t,this.tracksInGroup,Ai);if(r>-1){const t=this.tracksInGroup[r];return this.setAudioTrack(r),t}if(i){let i=e.loadLevel;-1===i&&(i=e.firstAutoLevel);const r=function(t,e,n,i,r){const a=e[i],s=e.reduce(((t,e,n)=>{const i=e.uri;return(t[i]||(t[i]=[])).push(n),t}),{})[a.uri];s.length>1&&(i=Math.max.apply(Math,s));const o=a.videoRange,l=a.frameRate,d=a.codecSet.substring(0,4),c=vi(e,i,(e=>{if(e.videoRange!==o||e.frameRate!==l||e.codecSet.substring(0,4)!==d)return!1;const i=e.audioGroups,a=n.filter((t=>!i||-1!==i.indexOf(t.groupId)));return gi(t,a,r)>-1}));return c>-1?c:vi(e,i,(e=>{const i=e.audioGroups,a=n.filter((t=>!i||-1!==i.indexOf(t.groupId)));return gi(t,a,r)>-1}))}(t,e.levels,n,i,Ai);if(-1===r)return null;e.nextLoadLevel=r}if(t.channels||t.audioCodec){const e=gi(t,n);if(e>-1)return n[e]}}}return null}setAudioTrack(t){const e=this.tracksInGroup;if(t<0||t>=e.length)return void this.warn(`Invalid audio track id: ${t}`);this.clearTimer(),this.selectDefaultTrack=!1;const n=this.currentTrack,i=e[t],r=i.details&&!i.details.live;if(t===this.trackId&&i===n&&r)return;if(this.log(`Switching to audio-track ${t} "${i.name}" lang:${i.lang} group:${i.groupId} channels:${i.channels}`),this.trackId=t,this.currentTrack=i,this.hls.trigger(tt.AUDIO_TRACK_SWITCHING,q({},i)),r)return;const a=this.switchParams(i.url,null==n?void 0:n.details,i.details);this.loadPlaylist(a)}findTrackId(t){const e=this.tracksInGroup;for(let n=0;n{this.initialized&&(this.starved=!0),this.buffering=!0},this.onPlaying=()=>{this.initialized||(this.initialized=!0),this.buffering=!1},this.applyPlaylistData=t=>{try{this.apply(t,{ot:ys.MANIFEST,su:!this.initialized})}catch(t){ot.warn("Could not generate manifest CMCD data.",t)}},this.applyFragmentData=t=>{try{const e=t.frag,n=this.hls.levels[e.level],i=this.getObjectType(e),r={d:1e3*e.duration,ot:i};i!==ys.VIDEO&&i!==ys.AUDIO&&i!=ys.MUXED||(r.br=n.bitrate/1e3,r.tb=this.getTopBandwidth(i)/1e3,r.bl=this.getBufferLength(i)),this.apply(t,r)}catch(t){ot.warn("Could not generate segment CMCD data.",t)}},this.hls=t;const e=this.config=t.config,{cmcd:n}=e;null!=n&&(e.pLoader=this.createPlaylistLoader(),e.fLoader=this.createFragmentLoader(),this.sid=n.sessionId||function(){try{return crypto.randomUUID()}catch(t){try{const t=URL.createObjectURL(new Blob),e=t.toString();return URL.revokeObjectURL(t),e.slice(e.lastIndexOf("/")+1)}catch(t){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:3&n|8).toString(16)}))}}}(),this.cid=n.contentId,this.useHeaders=!0===n.useHeaders,this.includeKeys=n.includeKeys,this.registerListeners())}registerListeners(){const t=this.hls;t.on(tt.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(tt.MEDIA_DETACHED,this.onMediaDetached,this),t.on(tt.BUFFER_CREATED,this.onBufferCreated,this)}unregisterListeners(){const t=this.hls;t.off(tt.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(tt.MEDIA_DETACHED,this.onMediaDetached,this),t.off(tt.BUFFER_CREATED,this.onBufferCreated,this)}destroy(){this.unregisterListeners(),this.onMediaDetached(),this.hls=this.config=this.audioBuffer=this.videoBuffer=null,this.onWaiting=this.onPlaying=null}onMediaAttached(t,e){this.media=e.media,this.media.addEventListener("waiting",this.onWaiting),this.media.addEventListener("playing",this.onPlaying)}onMediaDetached(){this.media&&(this.media.removeEventListener("waiting",this.onWaiting),this.media.removeEventListener("playing",this.onPlaying),this.media=null)}onBufferCreated(t,e){var n,i;this.audioBuffer=null==(n=e.tracks.audio)?void 0:n.buffer,this.videoBuffer=null==(i=e.tracks.video)?void 0:i.buffer}createData(){var t;return{v:1,sf:As.HLS,sid:this.sid,cid:this.cid,pr:null==(t=this.media)?void 0:t.playbackRate,mtp:this.hls.bandwidthEstimate/1e3}}apply(t,e={}){Q(e,this.createData());const n=e.ot===ys.INIT||e.ot===ys.VIDEO||e.ot===ys.MUXED;this.starved&&n&&(e.bs=!0,e.su=!0,this.starved=!1),null==e.su&&(e.su=this.buffering);const{includeKeys:i}=this;i&&(e=Object.keys(e).reduce(((t,n)=>(i.includes(n)&&(t[n]=e[n]),t)),{})),this.useHeaders?(t.headers||(t.headers={}),Xs(t.headers,e)):t.url=to(t.url,e)}getObjectType(t){const{type:e}=t;return"subtitle"===e?ys.TIMED_TEXT:"initSegment"===t.sn?ys.INIT:"audio"===e?ys.AUDIO:"main"===e?this.hls.audioTracks.length?ys.VIDEO:ys.MUXED:void 0}getTopBandwidth(t){let e,n=0;const i=this.hls;if(t===ys.AUDIO)e=i.audioTracks;else{const t=i.maxAutoLevel,n=t>-1?t+1:i.levels.length;e=i.levels.slice(0,n)}for(const t of e)t.bitrate>n&&(n=t.bitrate);return n>0?n:NaN}getBufferLength(t){const e=this.hls.media,n=t===ys.AUDIO?this.audioBuffer:this.videoBuffer;if(!n||!e)return NaN;return 1e3*Li.bufferInfo(n,e.currentTime,this.config.maxBufferHole).len}createPlaylistLoader(){const{pLoader:t}=this.config,e=this.applyPlaylistData,n=t||this.config.loader;return class{constructor(t){this.loader=void 0,this.loader=new n(t)}get stats(){return this.loader.stats}get context(){return this.loader.context}destroy(){this.loader.destroy()}abort(){this.loader.abort()}load(t,n,i){e(t),this.loader.load(t,n,i)}}}createFragmentLoader(){const{fLoader:t}=this.config,e=this.applyFragmentData,n=t||this.config.loader;return class{constructor(t){this.loader=void 0,this.loader=new n(t)}get stats(){return this.loader.stats}get context(){return this.loader.context}destroy(){this.loader.destroy()}abort(){this.loader.abort()}load(t,n,i){e(t),this.loader.load(t,n,i)}}}},contentSteeringController:class{constructor(t){this.hls=void 0,this.log=void 0,this.loader=null,this.uri=null,this.pathwayId=".",this.pathwayPriority=null,this.timeToLoad=300,this.reloadTimer=-1,this.updated=0,this.started=!1,this.enabled=!0,this.levels=null,this.audioTracks=null,this.subtitleTracks=null,this.penalizedPathways={},this.hls=t,this.log=ot.log.bind(ot,"[content-steering]:"),this.registerListeners()}registerListeners(){const t=this.hls;t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.on(tt.ERROR,this.onError,this)}unregisterListeners(){const t=this.hls;t&&(t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(tt.MANIFEST_PARSED,this.onManifestParsed,this),t.off(tt.ERROR,this.onError,this))}startLoad(){if(this.started=!0,this.clearTimeout(),this.enabled&&this.uri){if(this.updated){const t=1e3*this.timeToLoad-(performance.now()-this.updated);if(t>0)return void this.scheduleRefresh(this.uri,t)}this.loadSteeringManifest(this.uri)}}stopLoad(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),this.clearTimeout()}clearTimeout(){-1!==this.reloadTimer&&(self.clearTimeout(this.reloadTimer),this.reloadTimer=-1)}destroy(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null}removeLevel(t){const e=this.levels;e&&(this.levels=e.filter((e=>e!==t)))}onManifestLoading(){this.stopLoad(),this.enabled=!0,this.timeToLoad=300,this.updated=0,this.uri=null,this.pathwayId=".",this.levels=this.audioTracks=this.subtitleTracks=null}onManifestLoaded(t,e){const{contentSteering:n}=e;null!==n&&(this.pathwayId=n.pathwayId,this.uri=n.uri,this.started&&this.startLoad())}onManifestParsed(t,e){this.audioTracks=e.audioTracks,this.subtitleTracks=e.subtitleTracks}onError(t,e){const{errorAction:n}=e;if((null==n?void 0:n.action)===ei&&n.flags===ai){const t=this.levels;let i=this.pathwayPriority,r=this.pathwayId;if(e.context){const{groupId:n,pathwayId:i,type:a}=e.context;n&&t?r=this.getPathwayForGroupId(n,a,r):i&&(r=i)}r in this.penalizedPathways||(this.penalizedPathways[r]=performance.now()),!i&&t&&(i=t.reduce(((t,e)=>(-1===t.indexOf(e.pathwayId)&&t.push(e.pathwayId),t)),[])),i&&i.length>1&&(this.updatePathwayPriority(i),n.resolved=this.pathwayId!==r),n.resolved||ot.warn(`Could not resolve ${e.details} ("${e.error.message}") with content-steering for Pathway: ${r} levels: ${t?t.length:t} priorities: ${JSON.stringify(i)} penalized: ${JSON.stringify(this.penalizedPathways)}`)}}filterParsedLevels(t){this.levels=t;let e=this.getLevelsForPathway(this.pathwayId);if(0===e.length){const n=t[0].pathwayId;this.log(`No levels found in Pathway ${this.pathwayId}. Setting initial Pathway to "${n}"`),e=this.getLevelsForPathway(n),this.pathwayId=n}return e.length!==t.length?(this.log(`Found ${e.length}/${t.length} levels in Pathway "${this.pathwayId}"`),e):t}getLevelsForPathway(t){return null===this.levels?[]:this.levels.filter((e=>t===e.pathwayId))}updatePathwayPriority(t){let e;this.pathwayPriority=t;const n=this.penalizedPathways,i=performance.now();Object.keys(n).forEach((t=>{i-n[t]>3e5&&delete n[t]}));for(let i=0;i0){this.log(`Setting Pathway to "${r}"`),this.pathwayId=r,Yn(e),this.hls.trigger(tt.LEVELS_UPDATED,{levels:e});const t=this.hls.levels[a];s&&t&&this.levels&&(t.attrs["STABLE-VARIANT-ID"]!==s.attrs["STABLE-VARIANT-ID"]&&t.bitrate!==s.bitrate&&this.log(`Unstable Pathways change from bitrate ${s.bitrate} to ${t.bitrate}`),this.hls.nextLoadLevel=a);break}}}getPathwayForGroupId(t,e,n){const i=this.getLevelsForPathway(n).concat(this.levels||[]);for(let n=0;n{const{ID:r,"BASE-ID":a,"URI-REPLACEMENT":s}=t;if(e.some((t=>t.pathwayId===r)))return;const o=this.getLevelsForPathway(a).map((t=>{const e=new ct(t.attrs);e["PATHWAY-ID"]=r;const a=e.AUDIO&&`${e.AUDIO}_clone_${r}`,o=e.SUBTITLES&&`${e.SUBTITLES}_clone_${r}`;a&&(n[e.AUDIO]=a,e.AUDIO=a),o&&(i[e.SUBTITLES]=o,e.SUBTITLES=o);const l=no(t.uri,e["STABLE-VARIANT-ID"],"PER-VARIANT-URIS",s),d=new Un({attrs:e,audioCodec:t.audioCodec,bitrate:t.bitrate,height:t.height,name:t.name,url:l,videoCodec:t.videoCodec,width:t.width});if(t.audioGroups)for(let e=1;e{this.log(`Loaded steering manifest: "${i}"`);const a=t.data;if(1!==a.VERSION)return void this.log(`Steering VERSION ${a.VERSION} not supported!`);this.updated=performance.now(),this.timeToLoad=a.TTL;const{"RELOAD-URI":s,"PATHWAY-CLONES":o,"PATHWAY-PRIORITY":l}=a;if(s)try{this.uri=new self.URL(s,i).href}catch(t){return this.enabled=!1,void this.log(`Failed to parse Steering Manifest RELOAD-URI: ${s}`)}this.scheduleRefresh(this.uri||n.url),o&&this.clonePathways(o);const d={steeringManifest:a,url:i.toString()};this.hls.trigger(tt.STEERING_MANIFEST_LOADED,d),l&&this.updatePathwayPriority(l)},onError:(t,e,n,i)=>{if(this.log(`Error loading steering manifest: ${t.code} ${t.text} (${e.url})`),this.stopLoad(),410===t.code)return this.enabled=!1,void this.log(`Steering manifest ${e.url} no longer available`);let r=1e3*this.timeToLoad;if(429!==t.code)this.scheduleRefresh(this.uri||e.url,r);else{const t=this.loader;if("function"==typeof(null==t?void 0:t.getResponseHeader)){const e=t.getResponseHeader("Retry-After");e&&(r=1e3*parseFloat(e))}this.log(`Steering manifest ${e.url} rate limited`)}},onTimeout:(t,e,n)=>{this.log(`Timeout loading steering manifest (${e.url})`),this.scheduleRefresh(this.uri||e.url)}};this.log(`Requesting steering manifest: ${i}`),this.loader.load(r,o,l)}scheduleRefresh(t,e=1e3*this.timeToLoad){this.clearTimeout(),this.reloadTimer=self.setTimeout((()=>{var e;const n=null==(e=this.hls)?void 0:e.media;!n||n.ended?this.scheduleRefresh(t,1e3*this.timeToLoad):this.loadSteeringManifest(t)}),e)}}});function po(t){return t&&"object"==typeof t?Array.isArray(t)?t.map(po):Object.keys(t).reduce(((e,n)=>(e[n]=po(t[n]),e)),{}):t}function fo(t){const e=t.loader;if(e!==so&&e!==ro)ot.log("[config]: Custom loader detected, cannot enable progressive streaming"),t.progressive=!1;else{(function(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch(t){}return!1})()&&(t.loader=so,t.progressive=!0,t.enableSoftwareAES=!0,ot.log("[config]: Progressive streaming enabled, using FetchLoader"))}}let mo;class go extends oi{constructor(t,e){super(t,"[level-controller]"),this._levels=[],this._firstLevel=-1,this._maxAutoLevel=-1,this._startLevel=void 0,this.currentLevel=null,this.currentLevelIndex=-1,this.manualLevelIndex=-1,this.steering=void 0,this.onParsedComplete=void 0,this.steering=e,this._registerListeners()}_registerListeners(){const{hls:t}=this;t.on(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.on(tt.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(tt.LEVEL_LOADED,this.onLevelLoaded,this),t.on(tt.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(tt.FRAG_BUFFERED,this.onFragBuffered,this),t.on(tt.ERROR,this.onError,this)}_unregisterListeners(){const{hls:t}=this;t.off(tt.MANIFEST_LOADING,this.onManifestLoading,this),t.off(tt.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(tt.LEVEL_LOADED,this.onLevelLoaded,this),t.off(tt.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(tt.FRAG_BUFFERED,this.onFragBuffered,this),t.off(tt.ERROR,this.onError,this)}destroy(){this._unregisterListeners(),this.steering=null,this.resetLevels(),super.destroy()}stopLoad(){this._levels.forEach((t=>{t.loadError=0,t.fragmentError=0})),super.stopLoad()}resetLevels(){this._startLevel=void 0,this.manualLevelIndex=-1,this.currentLevelIndex=-1,this.currentLevel=null,this._levels=[],this._maxAutoLevel=-1}onManifestLoading(t,e){this.resetLevels()}onManifestLoaded(t,e){const n=this.hls.config.preferManagedMediaSource,i=[],r={},a={};let s=!1,o=!1,l=!1;e.levels.forEach((t=>{var e,d;const c=t.attrs;let{audioCodec:u,videoCodec:h}=t;-1!==(null==(e=u)?void 0:e.indexOf("mp4a.40.34"))&&(mo||(mo=/chrome|firefox/i.test(navigator.userAgent)),mo&&(t.audioCodec=u=void 0)),u&&(t.audioCodec=u=je(u,n)),0===(null==(d=h)?void 0:d.indexOf("avc1"))&&(h=t.videoCodec=function(t){const e=t.split(".");if(e.length>2){let t=e.shift()+".";return t+=parseInt(e.shift()).toString(16),t+=("000"+parseInt(e.shift()).toString(16)).slice(-4),t}return t}(h));const{width:p,height:f,unknownCodecs:m}=t;if(s||(s=!(!p||!f)),o||(o=!!h),l||(l=!!u),null!=m&&m.length||u&&!Ue(u,"audio",n)||h&&!Ue(h,"video",n))return;const{CODECS:g,"FRAME-RATE":y,"HDCP-LEVEL":A,"PATHWAY-ID":v,RESOLUTION:b,"VIDEO-RANGE":E}=c,w=`${`${v||"."}-`}${t.bitrate}-${b}-${y}-${g}-${E}-${A}`;if(r[w])if(r[w].uri===t.url||t.attrs["PATHWAY-ID"])r[w].addGroupId("audio",c.AUDIO),r[w].addGroupId("text",c.SUBTITLES);else{const e=a[w]+=1;t.attrs["PATHWAY-ID"]=new Array(e+1).join(".");const n=new Un(t);r[w]=n,i.push(n)}else{const e=new Un(t);r[w]=e,a[w]=1,i.push(e)}})),this.filterAndSortMediaOptions(i,e,s,o,l)}filterAndSortMediaOptions(t,e,n,i,r){let a=[],s=[],o=t;if((n||i)&&r&&(o=o.filter((({videoCodec:t,videoRange:e,width:n,height:i})=>{return(!!t||!(!n||!i))&&(!!(r=e)&&Ln.indexOf(r)>-1);var r}))),0===o.length)return void Promise.resolve().then((()=>{if(this.hls){e.levels.length&&this.warn(`One or more CODECS in variant not supported: ${JSON.stringify(e.levels[0].attrs)}`);const t=new Error("no level with compatible codecs found in manifest");this.hls.trigger(tt.ERROR,{type:et.MEDIA_ERROR,details:nt.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:e.url,error:t,reason:t.message})}}));if(e.audioTracks){const{preferManagedMediaSource:t}=this.hls.config;a=e.audioTracks.filter((e=>!e.audioCodec||Ue(e.audioCodec,"audio",t))),yo(a)}e.subtitles&&(s=e.subtitles,yo(s));const l=o.slice(0);o.sort(((t,e)=>{if(t.attrs["HDCP-LEVEL"]!==e.attrs["HDCP-LEVEL"])return(t.attrs["HDCP-LEVEL"]||"")>(e.attrs["HDCP-LEVEL"]||"")?1:-1;if(n&&t.height!==e.height)return t.height-e.height;if(t.frameRate!==e.frameRate)return t.frameRate-e.frameRate;if(t.videoRange!==e.videoRange)return Ln.indexOf(t.videoRange)-Ln.indexOf(e.videoRange);if(t.videoCodec!==e.videoCodec){const n=Me(t.videoCodec),i=Me(e.videoCodec);if(n!==i)return i-n}if(t.uri===e.uri&&t.codecSet!==e.codecSet){const n=Ne(t.codecSet),i=Ne(e.codecSet);if(n!==i)return i-n}return t.averageBitrate!==e.averageBitrate?t.averageBitrate-e.averageBitrate:0}));let d=l[0];if(this.steering&&(o=this.steering.filterParsedLevels(o),o.length!==l.length))for(let t=0;tn&&n===ho.abrEwmaDefaultEstimate&&(this.hls.bandwidthEstimate=t)}break}const u=r&&!i,h={levels:o,audioTracks:a,subtitleTracks:s,sessionData:e.sessionData,sessionKeys:e.sessionKeys,firstLevel:this._firstLevel,stats:e.stats,audio:r,video:i,altAudio:!u&&a.some((t=>!!t.url))};this.hls.trigger(tt.MANIFEST_PARSED,h),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}get levels(){return 0===this._levels.length?null:this._levels}get level(){return this.currentLevelIndex}set level(t){const e=this._levels;if(0===e.length)return;if(t<0||t>=e.length){const n=new Error("invalid level idx"),i=t<0;if(this.hls.trigger(tt.ERROR,{type:et.OTHER_ERROR,details:nt.LEVEL_SWITCH_ERROR,level:t,fatal:i,error:n,reason:n.message}),i)return;t=Math.min(t,e.length-1)}const n=this.currentLevelIndex,i=this.currentLevel,r=i?i.attrs["PATHWAY-ID"]:void 0,a=e[t],s=a.attrs["PATHWAY-ID"];if(this.currentLevelIndex=t,this.currentLevel=a,n===t&&a.details&&i&&r===s)return;this.log(`Switching to level ${t} (${a.height?a.height+"p ":""}${a.videoRange?a.videoRange+" ":""}${a.codecSet?a.codecSet+" ":""}@${a.bitrate})${s?" with Pathway "+s:""} from level ${n}${r?" with Pathway "+r:""}`);const o={level:t,attrs:a.attrs,details:a.details,bitrate:a.bitrate,averageBitrate:a.averageBitrate,maxBitrate:a.maxBitrate,realBitrate:a.realBitrate,width:a.width,height:a.height,codecSet:a.codecSet,audioCodec:a.audioCodec,videoCodec:a.videoCodec,audioGroups:a.audioGroups,subtitleGroups:a.subtitleGroups,loaded:a.loaded,loadError:a.loadError,fragmentError:a.fragmentError,name:a.name,id:a.id,uri:a.uri,url:a.url,urlId:0,audioGroupIds:a.audioGroupIds,textGroupIds:a.textGroupIds};this.hls.trigger(tt.LEVEL_SWITCHING,o);const l=a.details;if(!l||l.live){const t=this.switchParams(a.uri,null==i?void 0:i.details,l);this.loadPlaylist(t)}}get manualLevel(){return this.manualLevelIndex}set manualLevel(t){this.manualLevelIndex=t,void 0===this._startLevel&&(this._startLevel=t),-1!==t&&(this.level=t)}get firstLevel(){return this._firstLevel}set firstLevel(t){this._firstLevel=t}get startLevel(){if(void 0===this._startLevel){const t=this.hls.config.startLevel;return void 0!==t?t:this.hls.firstAutoLevel}return this._startLevel}set startLevel(t){this._startLevel=t}onError(t,e){!e.fatal&&e.context&&e.context.type===an&&e.context.level===this.level&&this.checkRetry(e)}onFragBuffered(t,{frag:e}){if(void 0!==e&&e.type===ln){const t=e.elementaryStreams;if(!Object.keys(t).some((e=>!!t[e])))return;const n=this._levels[e.level];null!=n&&n.loadError&&(this.log(`Resetting level error count of ${n.loadError} on frag buffered`),n.loadError=0)}}onLevelLoaded(t,e){var n;const{level:i,details:r}=e,a=this._levels[i];var s;if(!a)return this.warn(`Invalid level index ${i}`),void(null!=(s=e.deliveryDirectives)&&s.skip&&(r.deltaUpdateFailed=!0));i===this.currentLevelIndex?(0===a.fragmentError&&(a.loadError=0),this.playlistLoaded(i,e,a.details)):null!=(n=e.deliveryDirectives)&&n.skip&&(r.deltaUpdateFailed=!0)}loadPlaylist(t){super.loadPlaylist();const e=this.currentLevelIndex,n=this.currentLevel;if(n&&this.shouldLoadPlaylist(n)){let i=n.uri;if(t)try{i=t.addDirectives(i)}catch(t){this.warn(`Could not construct new URL with HLS Delivery Directives: ${t}`)}const r=n.attrs["PATHWAY-ID"];this.log(`Loading level index ${e}${void 0!==(null==t?void 0:t.msn)?" at sn "+t.msn+" part "+t.part:""} with${r?" Pathway "+r:""} ${i}`),this.clearTimer(),this.hls.trigger(tt.LEVEL_LOADING,{url:i,level:e,pathwayId:n.attrs["PATHWAY-ID"],id:0,deliveryDirectives:t||null})}}get nextLoadLevel(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel}set nextLoadLevel(t){this.level=t,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=t)}removeLevel(t){var e;const n=this._levels.filter(((e,n)=>n!==t||(this.steering&&this.steering.removeLevel(e),e===this.currentLevel&&(this.currentLevel=null,this.currentLevelIndex=-1,e.details&&e.details.fragments.forEach((t=>t.level=-1))),!1)));Yn(n),this._levels=n,this.currentLevelIndex>-1&&null!=(e=this.currentLevel)&&e.details&&(this.currentLevelIndex=this.currentLevel.details.fragments[0].level),this.hls.trigger(tt.LEVELS_UPDATED,{levels:n})}onLevelsUpdated(t,{levels:e}){this._levels=e}checkMaxAutoUpdated(){const{autoLevelCapping:t,maxAutoLevel:e,maxHdcpLevel:n}=this.hls;this._maxAutoLevel!==e&&(this._maxAutoLevel=e,this.hls.trigger(tt.MAX_AUTO_LEVEL_UPDATED,{autoLevelCapping:t,levels:this.levels,maxAutoLevel:e,minAutoLevel:this.hls.minAutoLevel,maxHdcpLevel:n}))}}function yo(t){const e={};t.forEach((t=>{const n=t.groupId||"";t.id=e[n]=e[n]||0,e[n]++}))}class Ao{constructor(t){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=t}abort(t){for(const n in this.keyUriToKeyInfo){const i=this.keyUriToKeyInfo[n].loader;if(i){var e;if(t&&t!==(null==(e=i.context)?void 0:e.frag.type))return;i.abort()}}}detach(){for(const t in this.keyUriToKeyInfo){const e=this.keyUriToKeyInfo[t];(e.mediaKeySessionContext||e.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[t]}}destroy(){this.detach();for(const t in this.keyUriToKeyInfo){const e=this.keyUriToKeyInfo[t].loader;e&&e.destroy()}this.keyUriToKeyInfo={}}createKeyLoadError(t,e=nt.KEY_LOAD_ERROR,n,i,r){return new zi({type:et.NETWORK_ERROR,details:e,fatal:!1,frag:t,response:r,error:n,networkDetails:i})}loadClear(t,e){if(this.emeController&&this.config.emeEnabled){const{sn:n,cc:i}=t;for(let t=0;t{r.setKeyFormat(t)}));break}}}}load(t){return!t.decryptdata&&t.encrypted&&this.emeController?this.emeController.selectKeySystemFormat(t).then((e=>this.loadInternal(t,e))):this.loadInternal(t)}loadInternal(t,e){var n,i;e&&t.setKeyFormat(e);const r=t.decryptdata;if(!r){const n=new Error(e?`Expected frag.decryptdata to be defined after setting format ${e}`:"Missing decryption data on fragment in onKeyLoading");return Promise.reject(this.createKeyLoadError(t,nt.KEY_LOAD_ERROR,n))}const a=r.uri;if(!a)return Promise.reject(this.createKeyLoadError(t,nt.KEY_LOAD_ERROR,new Error(`Invalid key URI: "${a}"`)));let s=this.keyUriToKeyInfo[a];if(null!=(n=s)&&n.decryptdata.key)return r.key=s.decryptdata.key,Promise.resolve({frag:t,keyInfo:s});var o;if(null!=(i=s)&&i.keyLoadPromise)switch(null==(o=s.mediaKeySessionContext)?void 0:o.keyStatus){case void 0:case"status-pending":case"usable":case"usable-in-future":return s.keyLoadPromise.then((e=>(r.key=e.keyInfo.decryptdata.key,{frag:t,keyInfo:s})))}switch(s=this.keyUriToKeyInfo[a]={decryptdata:r,keyLoadPromise:null,loader:null,mediaKeySessionContext:null},r.method){case"ISO-23001-7":case"SAMPLE-AES":case"SAMPLE-AES-CENC":case"SAMPLE-AES-CTR":return"identity"===r.keyFormat?this.loadKeyHTTP(s,t):this.loadKeyEME(s,t);case"AES-128":return this.loadKeyHTTP(s,t);default:return Promise.reject(this.createKeyLoadError(t,nt.KEY_LOAD_ERROR,new Error(`Key supplied with unsupported METHOD: "${r.method}"`)))}}loadKeyEME(t,e){const n={frag:e,keyInfo:t};if(this.emeController&&this.config.emeEnabled){const e=this.emeController.loadKey(n);if(e)return(t.keyLoadPromise=e.then((e=>(t.mediaKeySessionContext=e,n)))).catch((e=>{throw t.keyLoadPromise=null,e}))}return Promise.resolve(n)}loadKeyHTTP(t,e){const n=this.config,i=new(0,n.loader)(n);return e.keyLoader=t.loader=i,t.keyLoadPromise=new Promise(((r,a)=>{const s={keyInfo:t,frag:e,responseType:"arraybuffer",url:t.decryptdata.uri},o=n.keyLoadPolicy.default,l={loadPolicy:o,timeout:o.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},d={onSuccess:(t,e,n,i)=>{const{frag:s,keyInfo:o,url:l}=n;if(!s.decryptdata||o!==this.keyUriToKeyInfo[l])return a(this.createKeyLoadError(s,nt.KEY_LOAD_ERROR,new Error("after key load, decryptdata unset or changed"),i));o.decryptdata.key=s.decryptdata.key=new Uint8Array(t.data),s.keyLoader=null,o.loader=null,r({frag:s,keyInfo:o})},onError:(t,n,i,r)=>{this.resetLoader(n),a(this.createKeyLoadError(e,nt.KEY_LOAD_ERROR,new Error(`HTTP Error ${t.code} loading key ${t.text}`),i,q({url:s.url,data:void 0},t)))},onTimeout:(t,n,i)=>{this.resetLoader(n),a(this.createKeyLoadError(e,nt.KEY_LOAD_TIMEOUT,new Error("key loading timed out"),i))},onAbort:(t,n,i)=>{this.resetLoader(n),a(this.createKeyLoadError(e,nt.INTERNAL_ABORTED,new Error("key loading aborted"),i))}};i.load(s,l,d)}))}resetLoader(t){const{frag:e,keyInfo:n,url:i}=t,r=n.loader;e.keyLoader===r&&(e.keyLoader=null,n.loader=null),delete this.keyUriToKeyInfo[i],r&&r.destroy()}}function vo(){return self.SourceBuffer||self.WebKitSourceBuffer}function bo(){if(!Be())return!1;const t=vo();return!t||t.prototype&&"function"==typeof t.prototype.appendBuffer&&"function"==typeof t.prototype.remove}class Eo{constructor(t,e,n,i){this.config=void 0,this.media=null,this.fragmentTracker=void 0,this.hls=void 0,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=t,this.media=e,this.fragmentTracker=n,this.hls=i}destroy(){this.media=null,this.hls=this.fragmentTracker=null}poll(t,e){const{config:n,media:i,stalled:r}=this;if(null===i)return;const{currentTime:a,seeking:s}=i,o=this.seeking&&!s,l=!this.seeking&&s;if(this.seeking=s,a!==t){if(this.moved=!0,s||(this.nudgeRetry=0),null!==r){if(this.stallReported){const t=self.performance.now()-r;ot.warn(`playback not stuck anymore @${a}, after ${Math.round(t)}ms`),this.stallReported=!1}this.stalled=null}return}if(l||o)return void(this.stalled=null);if(i.paused&&!s||i.ended||0===i.playbackRate||!Li.getBuffered(i).length)return void(this.nudgeRetry=0);const d=Li.bufferInfo(i,a,0),c=d.nextStart||0;if(s){const t=d.len>2,n=!c||e&&e.start<=a||c-a>2&&!this.fragmentTracker.getPartialFragment(a);if(t||n)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var u;if(!(d.len>0)&&!c)return;const t=Math.max(c,d.start||0)-a,e=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,n=(null==e||null==(u=e.details)?void 0:u.live)?2*e.details.targetduration:2,r=this.fragmentTracker.getPartialFragment(a);if(t>0&&(t<=n||r))return void(i.paused||this._trySkipBufferHole(r))}const h=self.performance.now();if(null===r)return void(this.stalled=h);const p=h-r;if(!s&&p>=250&&(this._reportStall(d),!this.media))return;const f=Li.bufferInfo(i,a,n.maxBufferHole);this._tryFixBufferStall(f,p)}_tryFixBufferStall(t,e){const{config:n,fragmentTracker:i,media:r}=this;if(null===r)return;const a=r.currentTime,s=i.getPartialFragment(a);if(s){if(this._trySkipBufferHole(s)||!this.media)return}(t.len>n.maxBufferHole||t.nextStart&&t.nextStart-a1e3*n.highBufferWatchdogPeriod&&(ot.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}_reportStall(t){const{hls:e,media:n,stallReported:i}=this;if(!i&&n){this.stallReported=!0;const i=new Error(`Playback stalling at @${n.currentTime} due to low buffer (${JSON.stringify(t)})`);ot.warn(i.message),e.trigger(tt.ERROR,{type:et.MEDIA_ERROR,details:nt.BUFFER_STALLED_ERROR,fatal:!1,error:i,buffer:t.len})}}_trySkipBufferHole(t){const{config:e,hls:n,media:i}=this;if(null===i)return 0;const r=i.currentTime,a=Li.bufferInfo(i,r,0),s=r0&&a.len<1&&i.readyState<3,d=s-r;if(d>0&&(o||l)){if(d>e.maxBufferHole){const{fragmentTracker:e}=this;let n=!1;if(0===r){const t=e.getAppendedFrag(0,ln);t&&s1?(t=0,this.bitrateTest=!0):t=n.firstAutoLevel),n.nextLoadLevel=t,this.level=n.loadLevel,this.loadedmetadata=!1}e>0&&-1===t&&(this.log(`Override startPosition with lastCurrentTime @${e.toFixed(3)}`),t=e),this.state=qi,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}else this._forceStartLoad=!0,this.state=Ki}stopLoad(){this._forceStartLoad=!1,super.stopLoad()}doTick(){switch(this.state){case ir:{const{levels:t,level:e}=this,n=null==t?void 0:t[e],i=null==n?void 0:n.details;if(i&&(!i.live||this.levelLastLoaded===n)){if(this.waitForCdnTuneIn(i))break;this.state=qi;break}if(this.hls.nextLoadLevel!==this.level){this.state=qi;break}break}case Qi:{var t;const e=self.performance.now(),n=this.retryDate;if(!n||e>=n||null!=(t=this.media)&&t.seeking){const{levels:t,level:e}=this,n=null==t?void 0:t[e];this.resetStartWhenNotLoaded(n||null),this.state=qi}}}this.state===qi&&this.doTickIdle(),this.onTickEnd()}onTickEnd(){super.onTickEnd(),this.checkBuffer(),this.checkFragmentChanged()}doTickIdle(){const{hls:t,levelLastLoaded:e,levels:n,media:i}=this;if(null===e||!i&&(this.startFragRequested||!t.config.startFragPrefetch))return;if(this.altAudio&&this.audioOnly)return;const r=t.nextLoadLevel;if(null==n||!n[r])return;const a=n[r],s=this.getMainFwdBufferInfo();if(null===s)return;const o=this.getLevelDetails();if(o&&this._streamEnded(s,o)){const t={};return this.altAudio&&(t.type="video"),this.hls.trigger(tt.BUFFER_EOS,t),void(this.state=tr)}t.loadLevel!==r&&-1===t.manualLevel&&this.log(`Adapting to level ${r} from level ${this.level}`),this.level=t.nextLoadLevel=r;const l=a.details;if(!l||this.state===ir||l.live&&this.levelLastLoaded!==a)return this.level=r,void(this.state=ir);const d=s.len,c=this.getMaxBufferLength(a.maxBitrate);if(d>=c)return;this.backtrackFragment&&this.backtrackFragment.start>s.end&&(this.backtrackFragment=null);const u=this.backtrackFragment?this.backtrackFragment.start:s.end;let h=this.getNextFragment(u,l);if(this.couldBacktrack&&!this.fragPrevious&&h&&"initSegment"!==h.sn&&this.fragmentTracker.getState(h)!==Si){var p;const t=(null!=(p=this.backtrackFragment)?p:h).sn-l.startSN,e=l.fragments[t-1];e&&h.cc===e.cc&&(h=e,this.fragmentTracker.removeFragment(e))}else this.backtrackFragment&&s.len&&(this.backtrackFragment=null);if(h&&this.isLoopLoading(h,u)){if(!h.gap){const t=this.audioOnly&&!this.altAudio?ft:mt,e=(t===mt?this.videoBuffer:this.mediaBuffer)||this.media;e&&this.afterBufferFlushed(e,t,ln)}h=this.getNextFragmentLoopLoading(h,l,s,ln,c)}h&&(!h.initSegment||h.initSegment.data||this.bitrateTest||(h=h.initSegment),this.loadFragment(h,a,u))}loadFragment(t,e,n){const i=this.fragmentTracker.getState(t);this.fragCurrent=t,i===Ei||i===xi?"initSegment"===t.sn?this._loadInitSegment(t,e):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,e)):(this.startFragRequested=!0,super.loadFragment(t,e,n)):this.clearTrackerIfNeeded(t)}getBufferedFrag(t){return this.fragmentTracker.getBufferedFrag(t,ln)}followingBufferedFrag(t){return t?this.getBufferedFrag(t.end+.5):null}immediateLevelSwitch(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)}nextLevelSwitch(){const{levels:t,media:e}=this;if(null!=e&&e.readyState){let n;const i=this.getAppendedFrag(e.currentTime);i&&i.start>1&&this.flushMainBuffer(0,i.start-1);const r=this.getLevelDetails();if(null!=r&&r.live){const t=this.getMainFwdBufferInfo();if(!t||t.len<2*r.targetduration)return}if(!e.paused&&t){const e=t[this.hls.nextLoadLevel],i=this.fragLastKbps;n=i&&this.fragCurrent?this.fragCurrent.duration*e.maxBitrate/(1e3*i)+1:0}else n=0;const a=this.getBufferedFrag(e.currentTime+n);if(a){const t=this.followingBufferedFrag(a);if(t){this.abortCurrentFrag();const e=t.maxStartPTS?t.maxStartPTS:t.start,n=t.duration,i=Math.max(a.end,e+Math.min(Math.max(n-this.config.maxFragLookUpTolerance,n*(this.couldBacktrack?.5:.125)),n*(this.couldBacktrack?.75:.25)));this.flushMainBuffer(i,Number.POSITIVE_INFINITY)}}}}abortCurrentFrag(){const t=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,t&&(t.abortRequests(),this.fragmentTracker.removeFragment(t)),this.state){case Vi:case Wi:case Qi:case Ji:case Zi:this.state=qi}this.nextLoadPosition=this.getLoadPosition()}flushMainBuffer(t,e){super.flushMainBuffer(t,e,this.altAudio?"video":null)}onMediaAttached(t,e){super.onMediaAttached(t,e);const n=e.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),n.addEventListener("playing",this.onvplaying),n.addEventListener("seeked",this.onvseeked),this.gapController=new Eo(this.config,n,this.fragmentTracker,this.hls)}onMediaDetaching(){const{media:t}=this;t&&this.onvplaying&&this.onvseeked&&(t.removeEventListener("playing",this.onvplaying),t.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),super.onMediaDetaching()}onMediaPlaying(){this.tick()}onMediaSeeked(){const t=this.media,e=t?t.currentTime:null;X(e)&&this.log(`Media seeked to ${e.toFixed(3)}`);const n=this.getMainFwdBufferInfo();null!==n&&0!==n.len?this.tick():this.warn(`Main forward buffer length on "seeked" event ${n?n.len:"empty"})`)}onManifestLoading(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(tt.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=!1,this.startPosition=this.lastCurrentTime=this.fragLastKbps=0,this.levels=this.fragPlaying=this.backtrackFragment=this.levelLastLoaded=null,this.altAudio=this.audioOnly=this.startFragRequested=!1}onManifestParsed(t,e){let n=!1,i=!1;e.levels.forEach((t=>{const e=t.audioCodec;e&&(n=n||-1!==e.indexOf("mp4a.40.2"),i=i||-1!==e.indexOf("mp4a.40.5"))})),this.audioCodecSwitch=n&&i&&!function(){var t;const e=vo();return"function"==typeof(null==e||null==(t=e.prototype)?void 0:t.changeType)}(),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=e.levels,this.startFragRequested=!1}onLevelLoading(t,e){const{levels:n}=this;if(!n||this.state!==qi)return;const i=n[e.level];(!i.details||i.details.live&&this.levelLastLoaded!==i||this.waitForCdnTuneIn(i.details))&&(this.state=ir)}onLevelLoaded(t,e){var n;const{levels:i}=this,r=e.level,a=e.details,s=a.totalduration;if(!i)return void this.warn(`Levels were reset while loading level ${r}`);this.log(`Level ${r} loaded [${a.startSN},${a.endSN}]${a.lastPartSn?`[part-${a.lastPartSn}-${a.lastPartIndex}]`:""}, cc [${a.startCC}, ${a.endCC}] duration:${s}`);const o=i[r],l=this.fragCurrent;!l||this.state!==Wi&&this.state!==Qi||l.level!==e.level&&l.loader&&this.abortCurrentFrag();let d=0;if(a.live||null!=(n=o.details)&&n.live){var c;if(this.checkLiveUpdate(a),a.deltaUpdateFailed)return;d=this.alignPlaylists(a,o.details,null==(c=this.levelLastLoaded)?void 0:c.details)}if(o.details=a,this.levelLastLoaded=o,this.hls.trigger(tt.LEVEL_UPDATED,{details:a,level:r}),this.state===ir){if(this.waitForCdnTuneIn(a))return;this.state=qi}this.startFragRequested?a.live&&this.synchronizeToLiveEdge(a):this.setStartPosition(a,d),this.tick()}_handleFragmentLoadProgress(t){var e;const{frag:n,part:i,payload:r}=t,{levels:a}=this;if(!a)return void this.warn(`Levels were reset while fragment load was in progress. Fragment ${n.sn} of level ${n.level} will not be buffered`);const s=a[n.level],o=s.details;if(!o)return this.warn(`Dropping fragment ${n.sn} of level ${n.level} after level details were reset`),void this.fragmentTracker.removeFragment(n);const l=s.videoCodec,d=o.PTSKnown||!o.live,c=null==(e=n.initSegment)?void 0:e.data,u=this._getAudioCodec(s),h=this.transmuxer=this.transmuxer||new ua(this.hls,ln,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),p=i?i.index:-1,f=-1!==p,m=new Ii(n.level,n.sn,n.stats.chunkCount,r.byteLength,p,f),g=this.initPTS[n.cc];h.push(r,c,u,l,n,i,o.totalduration,d,m,g)}onAudioTrackSwitching(t,e){const n=this.altAudio;if(!!!e.url){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;const t=this.fragCurrent;t&&(this.log("Switching to main audio track, cancel main fragment load"),t.abortRequests(),this.fragmentTracker.removeFragment(t)),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();const t=this.hls;n&&(t.trigger(tt.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:null}),this.fragmentTracker.removeAllFragments()),t.trigger(tt.AUDIO_TRACK_SWITCHED,e)}}onAudioTrackSwitched(t,e){const n=e.id,i=!!this.hls.audioTracks[n].url;if(i){const t=this.videoBuffer;t&&this.mediaBuffer!==t&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=t)}this.altAudio=i,this.tick()}onBufferCreated(t,e){const n=e.tracks;let i,r,a=!1;for(const t in n){const e=n[t];if("main"===e.id){if(r=t,i=e,"video"===t){const e=n[t];e&&(this.videoBuffer=e.buffer)}}else a=!0}a&&i?(this.log(`Alternate track found, use ${r}.buffered to schedule main fragment loading`),this.mediaBuffer=i.buffer):this.mediaBuffer=this.media}onFragBuffered(t,e){const{frag:n,part:i}=e;if(n&&n.type!==ln)return;if(this.fragContextChanged(n))return this.warn(`Fragment ${n.sn}${i?" p: "+i.index:""} of level ${n.level} finished buffering, but was aborted. state: ${this.state}`),void(this.state===Zi&&(this.state=qi));const r=i?i.stats:n.stats;this.fragLastKbps=Math.round(8*r.total/(r.buffering.end-r.loading.first)),"initSegment"!==n.sn&&(this.fragPrevious=n),this.fragBufferedComplete(n,i)}onError(t,e){var n;if(e.fatal)this.state=er;else switch(e.details){case nt.FRAG_GAP:case nt.FRAG_PARSING_ERROR:case nt.FRAG_DECRYPT_ERROR:case nt.FRAG_LOAD_ERROR:case nt.FRAG_LOAD_TIMEOUT:case nt.KEY_LOAD_ERROR:case nt.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(ln,e);break;case nt.LEVEL_LOAD_ERROR:case nt.LEVEL_LOAD_TIMEOUT:case nt.LEVEL_PARSING_ERROR:e.levelRetry||this.state!==ir||(null==(n=e.context)?void 0:n.type)!==an||(this.state=qi);break;case nt.BUFFER_APPEND_ERROR:case nt.BUFFER_FULL_ERROR:if(!e.parent||"main"!==e.parent)return;if(e.details===nt.BUFFER_APPEND_ERROR)return void this.resetLoadingState();this.reduceLengthAndFlushBuffer(e)&&this.flushMainBuffer(0,Number.POSITIVE_INFINITY);break;case nt.INTERNAL_EXCEPTION:this.recoverWorkerError(e)}}checkBuffer(){const{media:t,gapController:e}=this;if(t&&e&&t.readyState){if(this.loadedmetadata||!Li.getBuffered(t).length){const t=this.state!==qi?this.fragCurrent:null;e.poll(this.lastCurrentTime,t)}this.lastCurrentTime=t.currentTime}}onFragLoadEmergencyAborted(){this.state=qi,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()}onBufferFlushed(t,{type:e}){if(e!==ft||this.audioOnly&&!this.altAudio){const t=(e===mt?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(t,e,ln),this.tick()}}onLevelsUpdated(t,e){this.level>-1&&this.fragCurrent&&(this.level=this.fragCurrent.level),this.levels=e.levels}swapAudioCodec(){this.audioCodecSwap=!this.audioCodecSwap}seekToStartPos(){const{media:t}=this;if(!t)return;const e=t.currentTime;let n=this.startPosition;if(n>=0&&e0&&(r{const{hls:i}=this;if(!n||this.fragContextChanged(t))return;e.fragmentError=0,this.state=qi,this.startFragRequested=!1,this.bitrateTest=!1;const r=t.stats;r.parsing.start=r.parsing.end=r.buffering.start=r.buffering.end=self.performance.now(),i.trigger(tt.FRAG_LOADED,n),t.bitrateTest=!1}))}_handleTransmuxComplete(t){var e;const n="main",{hls:i}=this,{remuxResult:r,chunkMeta:a}=t,s=this.getCurrentContext(a);if(!s)return void this.resetWhenMissingContext(a);const{frag:o,part:l,level:d}=s,{video:c,text:u,id3:h,initSegment:p}=r,{details:f}=d,m=this.altAudio?void 0:r.audio;if(this.fragContextChanged(o))this.fragmentTracker.removeFragment(o);else{if(this.state=Ji,p){if(null!=p&&p.tracks){const t=o.initSegment||o;this._bufferInitSegment(d,p.tracks,t,a),i.trigger(tt.FRAG_PARSING_INIT_SEGMENT,{frag:t,id:n,tracks:p.tracks})}const t=p.initPTS,e=p.timescale;X(t)&&(this.initPTS[o.cc]={baseTime:t,timescale:e},i.trigger(tt.INIT_PTS_FOUND,{frag:o,id:n,initPTS:t,timescale:e}))}if(c&&f&&"initSegment"!==o.sn){const t=f.fragments[o.sn-1-f.startSN],e=o.sn===f.startSN,n=!t||o.cc>t.cc;if(!1!==r.independent){const{startPTS:t,endPTS:i,startDTS:r,endDTS:s}=c;if(l)l.elementaryStreams[c.type]={startPTS:t,endPTS:i,startDTS:r,endDTS:s};else if(c.firstKeyFrame&&c.independent&&1===a.id&&!n&&(this.couldBacktrack=!0),c.dropped&&c.independent){const r=this.getMainFwdBufferInfo(),a=(r?r.end:this.getLoadPosition())+this.config.maxBufferHole,l=c.firstKeyFramePTS?c.firstKeyFramePTS:t;if(!e&&a2&&(o.gap=!0);o.setElementaryStreamInfo(c.type,t,i,r,s),this.backtrackFragment&&(this.backtrackFragment=o),this.bufferFragmentData(c,o,l,a,e||n)}else{if(!e&&!n)return void this.backtrack(o);o.gap=!0}}if(m){const{startPTS:t,endPTS:e,startDTS:n,endDTS:i}=m;l&&(l.elementaryStreams[ft]={startPTS:t,endPTS:e,startDTS:n,endDTS:i}),o.setElementaryStreamInfo(ft,t,e,n,i),this.bufferFragmentData(m,o,l,a)}if(f&&null!=h&&null!=(e=h.samples)&&e.length){const t={id:n,frag:o,details:f,samples:h.samples};i.trigger(tt.FRAG_PARSING_METADATA,t)}if(f&&u){const t={id:n,frag:o,details:f,samples:u.samples};i.trigger(tt.FRAG_PARSING_USERDATA,t)}}}_bufferInitSegment(t,e,n,i){if(this.state!==Ji)return;this.audioOnly=!!e.audio&&!e.video,this.altAudio&&!this.audioOnly&&delete e.audio;const{audio:r,video:a,audiovideo:s}=e;if(r){let e=t.audioCodec;const n=navigator.userAgent.toLowerCase();this.audioCodecSwitch&&(e&&(e=-1!==e.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),1!==r.metadata.channelCount&&-1===n.indexOf("firefox")&&(e="mp4a.40.5")),e&&-1!==e.indexOf("mp4a.40.5")&&-1!==n.indexOf("android")&&"audio/mpeg"!==r.container&&(e="mp4a.40.2",this.log(`Android: force audio codec to ${e}`)),t.audioCodec&&t.audioCodec!==e&&this.log(`Swapping manifest audio codec "${t.audioCodec}" for "${e}"`),r.levelCodec=e,r.id="main",this.log(`Init audio buffer, container:${r.container}, codecs[selected/level/parsed]=[${e||""}/${t.audioCodec||""}/${r.codec}]`)}a&&(a.levelCodec=t.videoCodec,a.id="main",this.log(`Init video buffer, container:${a.container}, codecs[level/parsed]=[${t.videoCodec||""}/${a.codec}]`)),s&&this.log(`Init audiovideo buffer, container:${s.container}, codecs[level/parsed]=[${t.codecs}/${s.codec}]`),this.hls.trigger(tt.BUFFER_CODECS,e),Object.keys(e).forEach((t=>{const r=e[t].initSegment;null!=r&&r.byteLength&&this.hls.trigger(tt.BUFFER_APPENDING,{type:t,data:r,frag:n,part:null,chunkMeta:i,parent:n.type})})),this.tickImmediate()}getMainFwdBufferInfo(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,ln)}backtrack(t){this.couldBacktrack=!0,this.backtrackFragment=t,this.resetTransmuxer(),this.flushBufferGap(t),this.fragmentTracker.removeFragment(t),this.fragPrevious=null,this.nextLoadPosition=t.start,this.state=qi}checkFragmentChanged(){const t=this.media;let e=null;if(t&&t.readyState>1&&!1===t.seeking){const n=t.currentTime;if(Li.isBuffered(t,n)?e=this.getAppendedFrag(n):Li.isBuffered(t,n+.1)&&(e=this.getAppendedFrag(n+.1)),e){this.backtrackFragment=null;const t=this.fragPlaying,n=e.level;t&&e.sn===t.sn&&t.level===n||(this.fragPlaying=e,this.hls.trigger(tt.FRAG_CHANGED,{frag:e}),t&&t.level===n||this.hls.trigger(tt.LEVEL_SWITCHED,{level:n}))}}}get nextLevel(){const t=this.nextBufferedFrag;return t?t.level:-1}get currentFrag(){const t=this.media;return t?this.fragPlaying||this.getAppendedFrag(t.currentTime):null}get currentProgramDateTime(){const t=this.media;if(t){const e=t.currentTime,n=this.currentFrag;if(n&&X(e)&&X(n.programDateTime)){const t=n.programDateTime+1e3*(e-n.start);return new Date(t)}}return null}get currentLevel(){const t=this.currentFrag;return t?t.level:-1}get nextBufferedFrag(){const t=this.currentFrag;return t?this.followingBufferedFrag(t):null}get forceStartLoad(){return this._forceStartLoad}}class xo{static get version(){return"1.5.8"}static isMSESupported(){return bo()}static isSupported(){return function(){if(!bo())return!1;const t=Be();return"function"==typeof(null==t?void 0:t.isTypeSupported)&&(["avc1.42E01E,mp4a.40.2","av01.0.01M.08","vp09.00.50.08"].some((e=>t.isTypeSupported(Oe(e,"video"))))||["mp4a.40.2","fLaC"].some((e=>t.isTypeSupported(Oe(e,"audio")))))}()}static getMediaSource(){return Be()}static get Events(){return tt}static get ErrorTypes(){return et}static get ErrorDetails(){return nt}static get DefaultConfig(){return xo.defaultConfig?xo.defaultConfig:ho}static set DefaultConfig(t){xo.defaultConfig=t}constructor(t={}){this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this.started=!1,this._emitter=new ca,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.audioTrackController=void 0,this.subtitleTrackController=void 0,this.emeController=void 0,this.cmcdController=void 0,this._media=null,this.url=null,this.triggeringException=void 0,function(t,e){if("object"==typeof console&&!0===t||"object"==typeof t){st(t,"debug","log","info","warn","error");try{at.log(`Debug logs enabled for "${e}" in hls.js version 1.5.8`)}catch(t){at=rt}}else at=rt}(t.debug||!1,"Hls instance");const e=this.config=function(t,e){if((e.liveSyncDurationCount||e.liveMaxLatencyDurationCount)&&(e.liveSyncDuration||e.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==e.liveMaxLatencyDurationCount&&(void 0===e.liveSyncDurationCount||e.liveMaxLatencyDurationCount<=e.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(void 0!==e.liveMaxLatencyDuration&&(void 0===e.liveSyncDuration||e.liveMaxLatencyDuration<=e.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');const n=po(t),i=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];return["manifest","level","frag"].forEach((t=>{const r=`${"level"===t?"playlist":t}LoadPolicy`,a=void 0===e[r],s=[];i.forEach((i=>{const o=`${t}Loading${i}`,l=e[o];if(void 0!==l&&a){s.push(o);const t=n[r].default;switch(e[r]={default:t},i){case"TimeOut":t.maxLoadTimeMs=l,t.maxTimeToFirstByteMs=l;break;case"MaxRetry":t.errorRetry.maxNumRetry=l,t.timeoutRetry.maxNumRetry=l;break;case"RetryDelay":t.errorRetry.retryDelayMs=l,t.timeoutRetry.retryDelayMs=l;break;case"MaxRetryTimeout":t.errorRetry.maxRetryDelayMs=l,t.timeoutRetry.maxRetryDelayMs=l}}})),s.length&&ot.warn(`hls.js config: "${s.join('", "')}" setting(s) are deprecated, use "${r}": ${JSON.stringify(e[r])}`)})),q(q({},n),e)}(xo.DefaultConfig,t);this.userConfig=t,e.progressive&&fo(e);const{abrController:n,bufferController:i,capLevelController:r,errorController:a,fpsController:s}=e,o=new a(this),l=this.abrController=new n(this),d=this.bufferController=new i(this),c=this.capLevelController=new r(this),u=new s(this),h=new pn(this),p=new Tn(this),f=e.contentSteeringController,m=f?new f(this):null,g=this.levelController=new go(this,m),y=new _i(this),A=new Ao(this.config),v=this.streamController=new wo(this,y,A);c.setStreamController(v),u.setStreamController(v);const b=[h,g,v];m&&b.splice(1,0,m),this.networkControllers=b;const E=[l,d,c,u,p,y];this.audioTrackController=this.createController(e.audioTrackController,b);const w=e.audioStreamController;w&&b.push(new w(this,y,A)),this.subtitleTrackController=this.createController(e.subtitleTrackController,b);const x=e.subtitleStreamController;x&&b.push(new x(this,y,A)),this.createController(e.timelineController,E),A.emeController=this.emeController=this.createController(e.emeController,E),this.cmcdController=this.createController(e.cmcdController,E),this.latencyController=this.createController(kn,E),this.coreComponents=E,b.push(o);const S=o.onErrorOut;"function"==typeof S&&this.on(tt.ERROR,S,o)}createController(t,e){if(t){const n=new t(this);return e&&e.push(n),n}return null}on(t,e,n=this){this._emitter.on(t,e,n)}once(t,e,n=this){this._emitter.once(t,e,n)}removeAllListeners(t){this._emitter.removeAllListeners(t)}off(t,e,n=this,i){this._emitter.off(t,e,n,i)}listeners(t){return this._emitter.listeners(t)}emit(t,e,n){return this._emitter.emit(t,e,n)}trigger(t,e){if(this.config.debug)return this.emit(t,t,e);try{return this.emit(t,t,e)}catch(e){if(ot.error("An internal error happened while handling event "+t+'. Error message: "'+e.message+'". Here is a stacktrace:',e),!this.triggeringException){this.triggeringException=!0;const n=t===tt.ERROR;this.trigger(tt.ERROR,{type:et.OTHER_ERROR,details:nt.INTERNAL_EXCEPTION,fatal:n,event:t,error:e}),this.triggeringException=!1}}return!1}listenerCount(t){return this._emitter.listenerCount(t)}destroy(){ot.log("destroy"),this.trigger(tt.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((t=>t.destroy())),this.networkControllers.length=0,this.coreComponents.forEach((t=>t.destroy())),this.coreComponents.length=0;const t=this.config;t.xhrSetup=t.fetchSetup=void 0,this.userConfig=null}attachMedia(t){ot.log("attachMedia"),this._media=t,this.trigger(tt.MEDIA_ATTACHING,{media:t})}detachMedia(){ot.log("detachMedia"),this.trigger(tt.MEDIA_DETACHING,void 0),this._media=null}loadSource(t){this.stopLoad();const e=this.media,n=this.url,i=this.url=$.buildAbsoluteURL(self.location.href,t,{alwaysNormalize:!0});this._autoLevelCapping=-1,this._maxHdcpLevel=null,ot.log(`loadSource:${i}`),e&&n&&(n!==i||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(e)),this.trigger(tt.MANIFEST_LOADING,{url:t})}startLoad(t=-1){ot.log(`startLoad(${t})`),this.started=!0,this.networkControllers.forEach((e=>{e.startLoad(t)}))}stopLoad(){ot.log("stopLoad"),this.started=!1,this.networkControllers.forEach((t=>{t.stopLoad()}))}resumeBuffering(){this.started&&this.networkControllers.forEach((t=>{"fragmentLoader"in t&&t.startLoad(-1)}))}pauseBuffering(){this.networkControllers.forEach((t=>{"fragmentLoader"in t&&t.stopLoad()}))}swapAudioCodec(){ot.log("swapAudioCodec"),this.streamController.swapAudioCodec()}recoverMediaError(){ot.log("recoverMediaError");const t=this._media;this.detachMedia(),t&&this.attachMedia(t)}removeLevel(t){this.levelController.removeLevel(t)}get levels(){const t=this.levelController.levels;return t||[]}get currentLevel(){return this.streamController.currentLevel}set currentLevel(t){ot.log(`set currentLevel:${t}`),this.levelController.manualLevel=t,this.streamController.immediateLevelSwitch()}get nextLevel(){return this.streamController.nextLevel}set nextLevel(t){ot.log(`set nextLevel:${t}`),this.levelController.manualLevel=t,this.streamController.nextLevelSwitch()}get loadLevel(){return this.levelController.level}set loadLevel(t){ot.log(`set loadLevel:${t}`),this.levelController.manualLevel=t}get nextLoadLevel(){return this.levelController.nextLoadLevel}set nextLoadLevel(t){this.levelController.nextLoadLevel=t}get firstLevel(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)}set firstLevel(t){ot.log(`set firstLevel:${t}`),this.levelController.firstLevel=t}get startLevel(){const t=this.levelController.startLevel;return-1===t&&this.abrController.forcedAutoLevel>-1?this.abrController.forcedAutoLevel:t}set startLevel(t){ot.log(`set startLevel:${t}`),-1!==t&&(t=Math.max(t,this.minAutoLevel)),this.levelController.startLevel=t}get capLevelToPlayerSize(){return this.config.capLevelToPlayerSize}set capLevelToPlayerSize(t){const e=!!t;e!==this.config.capLevelToPlayerSize&&(e?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=e)}get autoLevelCapping(){return this._autoLevelCapping}get bandwidthEstimate(){const{bwEstimator:t}=this.abrController;return t?t.getEstimate():NaN}set bandwidthEstimate(t){this.abrController.resetEstimator(t)}get ttfbEstimate(){const{bwEstimator:t}=this.abrController;return t?t.getEstimateTTFB():NaN}set autoLevelCapping(t){this._autoLevelCapping!==t&&(ot.log(`set autoLevelCapping:${t}`),this._autoLevelCapping=t,this.levelController.checkMaxAutoUpdated())}get maxHdcpLevel(){return this._maxHdcpLevel}set maxHdcpLevel(t){(function(t){return Cn.indexOf(t)>-1})(t)&&this._maxHdcpLevel!==t&&(this._maxHdcpLevel=t,this.levelController.checkMaxAutoUpdated())}get autoLevelEnabled(){return-1===this.levelController.manualLevel}get manualLevel(){return this.levelController.manualLevel}get minAutoLevel(){const{levels:t,config:{minAutoBitrate:e}}=this;if(!t)return 0;const n=t.length;for(let i=0;i=e)return i;return 0}get maxAutoLevel(){const{levels:t,autoLevelCapping:e,maxHdcpLevel:n}=this;let i;if(i=-1===e&&null!=t&&t.length?t.length-1:e,n)for(let e=i;e--;){const i=t[e].attrs["HDCP-LEVEL"];if(i&&i<=n)return e}return i}get firstAutoLevel(){return this.abrController.firstAutoLevel}get nextAutoLevel(){return this.abrController.nextAutoLevel}set nextAutoLevel(t){this.abrController.nextAutoLevel=t}get playingDate(){return this.streamController.currentProgramDateTime}get mainForwardBufferInfo(){return this.streamController.getMainFwdBufferInfo()}setAudioOption(t){var e;return null==(e=this.audioTrackController)?void 0:e.setAudioOption(t)}setSubtitleOption(t){var e;return null==(e=this.subtitleTrackController)||e.setSubtitleOption(t),null}get allAudioTracks(){const t=this.audioTrackController;return t?t.allAudioTracks:[]}get audioTracks(){const t=this.audioTrackController;return t?t.audioTracks:[]}get audioTrack(){const t=this.audioTrackController;return t?t.audioTrack:-1}set audioTrack(t){const e=this.audioTrackController;e&&(e.audioTrack=t)}get allSubtitleTracks(){const t=this.subtitleTrackController;return t?t.allSubtitleTracks:[]}get subtitleTracks(){const t=this.subtitleTrackController;return t?t.subtitleTracks:[]}get subtitleTrack(){const t=this.subtitleTrackController;return t?t.subtitleTrack:-1}get media(){return this._media}set subtitleTrack(t){const e=this.subtitleTrackController;e&&(e.subtitleTrack=t)}get subtitleDisplay(){const t=this.subtitleTrackController;return!!t&&t.subtitleDisplay}set subtitleDisplay(t){const e=this.subtitleTrackController;e&&(e.subtitleDisplay=t)}get lowLatencyMode(){return this.config.lowLatencyMode}set lowLatencyMode(t){this.config.lowLatencyMode=t}get liveSyncPosition(){return this.latencyController.liveSyncPosition}get latency(){return this.latencyController.latency}get maxLatency(){return this.latencyController.maxLatency}get targetLatency(){return this.latencyController.targetLatency}get drift(){return this.latencyController.drift}get forceStartLoad(){return this.streamController.forceStartLoad}}function So(t){return{all:t=t||new Map,on:function(e,n){var i=t.get(e);i?i.push(n):t.set(e,[n])},off:function(e,n){var i=t.get(e);i&&(n?i.splice(i.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var i=t.get(e);i&&i.slice().map((function(t){t(n)})),(i=t.get("*"))&&i.slice().map((function(t){t(e,n)}))}}}xo.defaultConfig=void 0;var _o=function(){},To=function(){return m((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};f(this,t),this.config(e),this.init()}),[{key:"init",value:function(){var t=this;["debug","log","info","warn","error"].forEach((function(e){t[e]=t.enable?self.console[e].bind(self.console,t.prefix):_o}))}},{key:"config",value:function(t){var e=t.prefix,n=void 0===e?"[video-player]::":e,i=t.debug,r=void 0!==i&&i;this.prefix=n,this.enable=r,this.init()}}])}(),ko="object"==("undefined"==typeof global?"undefined":u(global))&&global&&global.Object===Object&&global,Co="object"==("undefined"==typeof self?"undefined":u(self))&&self&&self.Object===Object&&self,Lo=ko||Co||Function("return this")(),Io=Lo.Symbol,Ro=Object.prototype,Do=Ro.hasOwnProperty,Bo=Ro.toString,Po=Io?Io.toStringTag:void 0;var Uo=Object.prototype.toString;var Fo="[object Null]",Oo="[object Undefined]",Mo=Io?Io.toStringTag:void 0;function No(t){return null==t?void 0===t?Oo:Fo:Mo&&Mo in Object(t)?function(t){var e=Do.call(t,Po),n=t[Po];try{t[Po]=void 0;var i=!0}catch(t){}var r=Bo.call(t);return i&&(e?t[Po]=n:delete t[Po]),r}(t):function(t){return Uo.call(t)}(t)}function zo(t){return null!=t&&"object"==u(t)}var Go="[object Symbol]";function jo(t){return"symbol"==u(t)||zo(t)&&No(t)==Go}var Ho=Array.isArray,Yo=1/0,$o=Io?Io.prototype:void 0,Ko=$o?$o.toString:void 0;function qo(t){if("string"==typeof t)return t;if(Ho(t))return function(t,e){for(var n=-1,i=null==t?0:t.length,r=Array(i);++n-1&&t%1==0&&t-1&&t%1==0&&t<=Tl}function Cl(t){return null!=t&&kl(t.length)&&!tl(t)}var Ll=Object.prototype;function Il(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Ll)}function Rl(t){return zo(t)&&"[object Arguments]"==No(t)}var Dl=Object.prototype,Bl=Dl.hasOwnProperty,Pl=Dl.propertyIsEnumerable,Ul=Rl(function(){return arguments}())?Rl:function(t){return zo(t)&&Bl.call(t,"callee")&&!Pl.call(t,"callee")};var Fl="object"==("undefined"==typeof exports?"undefined":u(exports))&&exports&&!exports.nodeType&&exports,Ol=Fl&&"object"==("undefined"==typeof module?"undefined":u(module))&&module&&!module.nodeType&&module,Ml=Ol&&Ol.exports===Fl?Lo.Buffer:void 0,Nl=(Ml?Ml.isBuffer:void 0)||function(){return!1},zl={};function Gl(t){return function(e){return t(e)}}zl["[object Float32Array]"]=zl["[object Float64Array]"]=zl["[object Int8Array]"]=zl["[object Int16Array]"]=zl["[object Int32Array]"]=zl["[object Uint8Array]"]=zl["[object Uint8ClampedArray]"]=zl["[object Uint16Array]"]=zl["[object Uint32Array]"]=!0,zl["[object Arguments]"]=zl["[object Array]"]=zl["[object ArrayBuffer]"]=zl["[object Boolean]"]=zl["[object DataView]"]=zl["[object Date]"]=zl["[object Error]"]=zl["[object Function]"]=zl["[object Map]"]=zl["[object Number]"]=zl["[object Object]"]=zl["[object RegExp]"]=zl["[object Set]"]=zl["[object String]"]=zl["[object WeakMap]"]=!1;var jl="object"==("undefined"==typeof exports?"undefined":u(exports))&&exports&&!exports.nodeType&&exports,Hl=jl&&"object"==("undefined"==typeof module?"undefined":u(module))&&module&&!module.nodeType&&module,Yl=Hl&&Hl.exports===jl&&ko.process,$l=function(){try{var t=Hl&&Hl.require&&Hl.require("util").types;return t||Yl&&Yl.binding&&Yl.binding("util")}catch(t){}}(),Kl=$l&&$l.isTypedArray,ql=Kl?Gl(Kl):function(t){return zo(t)&&kl(t.length)&&!!zl[No(t)]},Vl=Object.prototype.hasOwnProperty;function Wl(t,e){var n=Ho(t),i=!n&&Ul(t),r=!n&&!i&&Nl(t),a=!n&&!i&&!r&&ql(t),s=n||i||r||a,o=s?function(t,e){for(var n=-1,i=Array(t);++n-1},pd.prototype.set=function(t,e){var n=this.__data__,i=ud(n,t);return i<0?(++this.size,n.push([t,e])):n[i][1]=e,this};var fd=pl(Lo,"Map");function md(t,e){var n,i,r=t.__data__;return("string"==(i=u(n=e))||"number"==i||"symbol"==i||"boolean"==i?"__proto__"!==n:null===n)?r["string"==typeof e?"string":"hash"]:r.map}function gd(t){var e=-1,n=null==t?0:t.length;for(this.clear();++eo))return!1;var d=a.get(t),c=a.get(e);if(d&&c)return d==e&&c==t;var u=-1,h=!0,p=n&qc?new Hc:void 0;for(a.set(t,e),a.set(e,t);++u0&&void 0!==arguments[0]?arguments[0]:{};t.time=(new Date).toLocaleString(),this.reports.push(t)}},{key:"uploadReports",value:function(){this.reports.length}},{key:"destroy",value:function(){this.uploadReports(),this.reports=[],clearInterval(this.timer)}}])}(),Hu=function(){function t(){this.listeners={}}var e=t.prototype;return e.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},e.off=function(t,e){if(!this.listeners[t])return!1;var n=this.listeners[t].indexOf(e);return this.listeners[t]=this.listeners[t].slice(0),this.listeners[t].splice(n,1),n>-1},e.trigger=function(t){var e=this.listeners[t];if(e)if(2===arguments.length)for(var n=e.length,i=0;i-1;e=this.buffer.indexOf("\n"))this.trigger("data",this.buffer.substring(0,e)),this.buffer=this.buffer.substring(e+1)}}])}(Hu),Vu=String.fromCharCode(9),Wu=function(t){var e=/([0-9.]*)?@?([0-9.]*)?/.exec(t||""),n={};return e[1]&&(n.length=parseInt(e[1],10)),e[2]&&(n.offset=parseInt(e[2],10)),n},Qu=function(t){var e={};if(!t)return e;for(var n,i=t.split(new RegExp('(?:^|,)((?:[^=]*)=(?:"[^"]*"|[^,]*))')),r=i.length;r--;)""!==i[r]&&((n=/([^=]*)=(.*)/.exec(i[r]).slice(1))[0]=n[0].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^['"](.*)['"]$/g,"$1"),e[n[0]]=n[1]);return e},Xu=function(t){function e(){var t;return f(this,e),(t=n(this,e)).customParsers=[],t.tagMappers=[],t}return y(e,t),m(e,[{key:"push",value:function(t){var e,n,i=this;0!==(t=t.trim()).length&&("#"===t[0]?this.tagMappers.reduce((function(e,n){var i=n(t);return i===t?e:e.concat([i])}),[t]).forEach((function(t){for(var r=0;r0&&(o.duration=t.duration),0===t.duration&&(o.duration=.01,this.trigger("info",{message:"updating zero segment duration to a small value"})),this.manifest.segments=s},key:function(){if(t.attributes)if("NONE"!==t.attributes.METHOD)if(t.attributes.URI){if("com.apple.streamingkeydelivery"===t.attributes.KEYFORMAT)return this.manifest.contentProtection=this.manifest.contentProtection||{},void(this.manifest.contentProtection["com.apple.fps.1_0"]={attributes:t.attributes});if("com.microsoft.playready"===t.attributes.KEYFORMAT)return this.manifest.contentProtection=this.manifest.contentProtection||{},void(this.manifest.contentProtection["com.microsoft.playready"]={uri:t.attributes.URI});if("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"===t.attributes.KEYFORMAT){return-1===["SAMPLE-AES","SAMPLE-AES-CTR","SAMPLE-AES-CENC"].indexOf(t.attributes.METHOD)?void this.trigger("warn",{message:"invalid key method provided for Widevine"}):("SAMPLE-AES-CENC"===t.attributes.METHOD&&this.trigger("warn",{message:"SAMPLE-AES-CENC is deprecated, please use SAMPLE-AES-CTR instead"}),"data:text/plain;base64,"!==t.attributes.URI.substring(0,23)?void this.trigger("warn",{message:"invalid key URI provided for Widevine"}):t.attributes.KEYID&&"0x"===t.attributes.KEYID.substring(0,2)?(this.manifest.contentProtection=this.manifest.contentProtection||{},void(this.manifest.contentProtection["com.widevine.alpha"]={attributes:{schemeIdUri:t.attributes.KEYFORMAT,keyId:t.attributes.KEYID.substring(2)},pssh:Ku(t.attributes.URI.split(",")[1])})):void this.trigger("warn",{message:"invalid key ID provided for Widevine"}))}t.attributes.METHOD||this.trigger("warn",{message:"defaulting key method to AES-128"}),r={method:t.attributes.METHOD||"AES-128",uri:t.attributes.URI},void 0!==t.attributes.IV&&(r.iv=t.attributes.IV)}else this.trigger("warn",{message:"ignoring key declaration without URI"});else r=null;else this.trigger("warn",{message:"ignoring key declaration without attribute list"})},"media-sequence":function(){isFinite(t.number)?this.manifest.mediaSequence=t.number:this.trigger("warn",{message:"ignoring invalid media sequence: "+t.number})},"discontinuity-sequence":function(){isFinite(t.number)?(this.manifest.discontinuitySequence=t.number,u=t.number):this.trigger("warn",{message:"ignoring invalid discontinuity sequence: "+t.number})},"playlist-type":function(){/VOD|EVENT/.test(t.playlistType)?this.manifest.playlistType=t.playlistType:this.trigger("warn",{message:"ignoring unknown playlist type: "+t.playlist})},map:function(){i={},t.uri&&(i.uri=t.uri),t.byterange&&(i.byterange=t.byterange),r&&(i.key=r)},"stream-inf":function(){this.manifest.playlists=s,this.manifest.mediaGroups=this.manifest.mediaGroups||c,t.attributes?(o.attributes||(o.attributes={}),Yu(o.attributes,t.attributes)):this.trigger("warn",{message:"ignoring empty stream-inf attributes"})},media:function(){if(this.manifest.mediaGroups=this.manifest.mediaGroups||c,t.attributes&&t.attributes.TYPE&&t.attributes["GROUP-ID"]&&t.attributes.NAME){var i=this.manifest.mediaGroups[t.attributes.TYPE];i[t.attributes["GROUP-ID"]]=i[t.attributes["GROUP-ID"]]||{},e=i[t.attributes["GROUP-ID"]],(n={default:/yes/i.test(t.attributes.DEFAULT)}).default?n.autoselect=!0:n.autoselect=/yes/i.test(t.attributes.AUTOSELECT),t.attributes.LANGUAGE&&(n.language=t.attributes.LANGUAGE),t.attributes.URI&&(n.uri=t.attributes.URI),t.attributes["INSTREAM-ID"]&&(n.instreamId=t.attributes["INSTREAM-ID"]),t.attributes.CHARACTERISTICS&&(n.characteristics=t.attributes.CHARACTERISTICS),t.attributes.FORCED&&(n.forced=/yes/i.test(t.attributes.FORCED)),e[t.attributes.NAME]=n}else this.trigger("warn",{message:"ignoring incomplete or missing media group"})},discontinuity:function(){u+=1,o.discontinuity=!0,this.manifest.discontinuityStarts.push(s.length)},"program-date-time":function(){void 0===this.manifest.dateTimeString&&(this.manifest.dateTimeString=t.dateTimeString,this.manifest.dateTimeObject=t.dateTimeObject),o.dateTimeString=t.dateTimeString,o.dateTimeObject=t.dateTimeObject;var e=this.lastProgramDateTime;this.lastProgramDateTime=new Date(t.dateTimeString).getTime(),null===e&&this.manifest.segments.reduceRight((function(t,e){return e.programDateTime=t-1e3*e.duration,e.programDateTime}),this.lastProgramDateTime)},targetduration:function(){!isFinite(t.duration)||t.duration<0?this.trigger("warn",{message:"ignoring invalid target duration: "+t.duration}):(this.manifest.targetDuration=t.duration,Zu.call(this,this.manifest))},start:function(){t.attributes&&!isNaN(t.attributes["TIME-OFFSET"])?this.manifest.start={timeOffset:t.attributes["TIME-OFFSET"],precise:t.attributes.PRECISE}:this.trigger("warn",{message:"ignoring start declaration without appropriate attribute list"})},"cue-out":function(){o.cueOut=t.data},"cue-out-cont":function(){o.cueOutCont=t.data},"cue-in":function(){o.cueIn=t.data},skip:function(){this.manifest.skip=Ju(t.attributes),this.warnOnMissingAttributes_("#EXT-X-SKIP",t.attributes,["SKIPPED-SEGMENTS"])},part:function(){var e=this;l=!0;var n=this.manifest.segments.length,i=Ju(t.attributes);o.parts=o.parts||[],o.parts.push(i),i.byterange&&(i.byterange.hasOwnProperty("offset")||(i.byterange.offset=p),p=i.byterange.offset+i.byterange.length);var r=o.parts.length-1;this.warnOnMissingAttributes_("#EXT-X-PART #".concat(r," for segment #").concat(n),t.attributes,["URI","DURATION"]),this.manifest.renditionReports&&this.manifest.renditionReports.forEach((function(t,n){t.hasOwnProperty("lastPart")||e.trigger("warn",{message:"#EXT-X-RENDITION-REPORT #".concat(n," lacks required attribute(s): LAST-PART")})}))},"server-control":function(){var e=this.manifest.serverControl=Ju(t.attributes);e.hasOwnProperty("canBlockReload")||(e.canBlockReload=!1,this.trigger("info",{message:"#EXT-X-SERVER-CONTROL defaulting CAN-BLOCK-RELOAD to false"})),Zu.call(this,this.manifest),e.canSkipDateranges&&!e.hasOwnProperty("canSkipUntil")&&this.trigger("warn",{message:"#EXT-X-SERVER-CONTROL lacks required attribute CAN-SKIP-UNTIL which is required when CAN-SKIP-DATERANGES is set"})},"preload-hint":function(){var e=this.manifest.segments.length,n=Ju(t.attributes),i=n.type&&"PART"===n.type;o.preloadHints=o.preloadHints||[],o.preloadHints.push(n),n.byterange&&(n.byterange.hasOwnProperty("offset")||(n.byterange.offset=i?p:0,i&&(p=n.byterange.offset+n.byterange.length)));var r=o.preloadHints.length-1;if(this.warnOnMissingAttributes_("#EXT-X-PRELOAD-HINT #".concat(r," for segment #").concat(e),t.attributes,["TYPE","URI"]),n.type)for(var a=0;a255)return!1;return!0}function r(t,e){if(t.buffer&&"Uint8Array"===t.name)return e&&(t=t.slice?t.slice():Array.prototype.slice.call(t)),t;if(Array.isArray(t)){if(!i(t))throw new Error("Array contains invalid value: "+t);return new Uint8Array(t)}if(n(t.length)&&i(t))return new Uint8Array(t);throw new Error("unsupported array-like object")}function a(t){return new Uint8Array(t)}function s(t,e,n,i,r){null==i&&null==r||(t=t.slice?t.slice(i,r):Array.prototype.slice.call(t,i,r)),e.set(t,n)}var o={toBytes:function(t){var e=[],n=0;for(t=encodeURI(t);n191&&i<224?(e.push(String.fromCharCode((31&i)<<6|63&t[n+1])),n+=2):(e.push(String.fromCharCode((15&i)<<12|(63&t[n+1])<<6|63&t[n+2])),n+=3)}return e.join("")}},l=function(){var t="0123456789abcdef";return{toBytes:function(t){for(var e=[],n=0;n>4]+t[15&r])}return n.join("")}}}(),d={16:10,24:12,32:14},c=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],u=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],h=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],p=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],f=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],m=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],g=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],y=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],A=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],v=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239e3,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],b=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998e3,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],E=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],w=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],x=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239e3,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],S=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998e3,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function _(t){for(var e=[],n=0;n>2,this._Ke[n][e%4]=a[e],this._Kd[t-n][e%4]=a[e];for(var s,o=0,l=r;l>16&255]<<24^u[s>>8&255]<<16^u[255&s]<<8^u[s>>24&255]^c[o]<<24,o+=1,8!=r)for(e=1;e>8&255]<<8^u[s>>16&255]<<16^u[s>>24&255]<<24;for(e=r/2+1;e>2,p=l%4,this._Ke[h][p]=a[e],this._Kd[t-h][p]=a[e++],l++}for(var h=1;h>24&255]^w[s>>16&255]^x[s>>8&255]^S[255&s]},T.prototype.encrypt=function(t){if(16!=t.length)throw new Error("invalid plaintext size (must be 16 bytes)");for(var e=this._Ke.length-1,n=[0,0,0,0],i=_(t),r=0;r<4;r++)i[r]^=this._Ke[0][r];for(var s=1;s>24&255]^f[i[(r+1)%4]>>16&255]^m[i[(r+2)%4]>>8&255]^g[255&i[(r+3)%4]]^this._Ke[s][r];i=n.slice()}var o,l=a(16);for(r=0;r<4;r++)o=this._Ke[e][r],l[4*r]=255&(u[i[r]>>24&255]^o>>24),l[4*r+1]=255&(u[i[(r+1)%4]>>16&255]^o>>16),l[4*r+2]=255&(u[i[(r+2)%4]>>8&255]^o>>8),l[4*r+3]=255&(u[255&i[(r+3)%4]]^o);return l},T.prototype.decrypt=function(t){if(16!=t.length)throw new Error("invalid ciphertext size (must be 16 bytes)");for(var e=this._Kd.length-1,n=[0,0,0,0],i=_(t),r=0;r<4;r++)i[r]^=this._Kd[0][r];for(var s=1;s>24&255]^A[i[(r+3)%4]>>16&255]^v[i[(r+2)%4]>>8&255]^b[255&i[(r+1)%4]]^this._Kd[s][r];i=n.slice()}var o,l=a(16);for(r=0;r<4;r++)o=this._Kd[e][r],l[4*r]=255&(h[i[r]>>24&255]^o>>24),l[4*r+1]=255&(h[i[(r+3)%4]>>16&255]^o>>16),l[4*r+2]=255&(h[i[(r+2)%4]>>8&255]^o>>8),l[4*r+3]=255&(h[255&i[(r+1)%4]]^o);return l};var k=function t(e){if(!(this instanceof t))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new T(e)};k.prototype.encrypt=function(t){if((t=r(t)).length%16!=0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var e=a(t.length),n=a(16),i=0;iNumber.MAX_SAFE_INTEGER)throw new Error("integer value out of safe range");for(var e=15;e>=0;--e)this._counter[e]=t%256,t=parseInt(t/256)},R.prototype.setBytes=function(t){if(16!=(t=r(t,!0)).length)throw new Error("invalid counter bytes size (must be 16 bytes)");this._counter=t},R.prototype.increment=function(){for(var t=15;t>=0;t--){if(255!==this._counter[t]){this._counter[t]++;break}this._counter[t]=0}};var D=function t(e,n){if(!(this instanceof t))throw Error("AES must be instanitated with `new`");this.description="Counter",this.name="ctr",n instanceof R||(n=new R(n)),this._counter=n,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new T(e)};D.prototype.encrypt=function(t){for(var e=r(t,!0),n=0;n16)throw new Error("PKCS#7 padding byte out of range");for(var n=t.length-e,i=0;i>".concat(n)),t.abrupt("return");case 5:if(i=e.VERSION,r=e.TARGETDURATION,a=e.SEQUENCE,s=e.TYPE,o=e.EXTINF,l=e.PREFIX_PATH,c=e.TS_START,u=e.TS_END,h=e.TS_NAME,p=e.TS_LIST,f=e.TS_LAST_TIME,m=e.IV,g=e.KEY,y="#EXTM3U\n#EXT-X-VERSION:".concat(i,"\n#EXT-X-TARGETDURATION:").concat(r,"\n#EXT-X-MEDIA-SEQUENCE:").concat(a,"\n#EXT-X-PLAYLIST-TYPE:").concat(s,"\n"),g?y+=m?'#EXT-X-KEY:METHOD=AES-128,URI="data:application/octet-stream;base64,'.concat(g,'",IV=').concat(m,"\n"):'#EXT-X-KEY:METHOD=AES-128,URI="data:application/octet-stream;base64,'.concat(g,'"\n'):this.key&&this.iv&&(y+='#EXT-X-KEY:METHOD=AES-128,URI="data:application/octet-stream;base64,'.concat(this.key,'",IV=').concat(this.iv,"\n")),A=[],null!=p&&p.length)for(v=0;v>".concat(n))),y+=A.join("\n"),y+="\n",y+="#EXT-X-ENDLIST",this.logger.log("m3u8Text",y),t.abrupt("return",y);case 16:case"end":return t.stop()}}),t,this)}))),function(t){return r.apply(this,arguments)})},{key:"getPlaylist",value:(i=p(d().mark((function t(e){var n,i,r,a;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=e.src){t.next=3;break}return t.abrupt("return");case 3:if(!Pu(n)||!n.startsWith("http")){t.next=16;break}return this.url=n,t.next=7,this.fetchMediaSrc(n);case 7:if(i=t.sent){t.next=10;break}return t.abrupt("return");case 10:if(r=i.type,a=i.data,"M3U8"!==r){t.next=15;break}return t.next=14,this.getPlaylistByM3u8(a);case 14:return t.abrupt("return",t.sent);case 15:return t.abrupt("return",this.getPlaylistByJson(a));case 16:if(!wh(n)){t.next=22;break}return t.next=19,this.getPlaylistByM3u8(n);case 19:return t.abrupt("return",t.sent);case 22:if(!Vo(n)){t.next=28;break}return t.next=25,this.getPlaylistByJson(n);case 25:return t.abrupt("return",t.sent);case 28:return t.prev=28,t.next=31,this.getPlaylistByJson(JSON.parse(n));case 31:return t.abrupt("return",t.sent);case 34:t.prev=34,t.t0=t.catch(28),this.logger.error("src数据有误",t.t0),this.emitter.emit("error",{fatal:!0});case 38:case"end":return t.stop()}}),t,this,[[28,34]])}))),function(t){return i.apply(this,arguments)})},{key:"getPlaylistByJson",value:(n=p(d().mark((function t(e){var n,i,r,a,s,o,l,c,u,h,p,f,m,g,y,A,v,b,E,w,x,S,_,T,k,C;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n={playlist:[],duration:0},e){t.next=5;break}return this.emitter.emit("error",{fatal:!0,src:this.url,type:"networkError",response:e,error:{message:"视频资源不存在"}}),this.logger.error("视频资源不存在>>".concat(this.url)),t.abrupt("return",n);case 5:if(e.VERSION,e.TARGETDURATION,e.SEQUENCE,e.TYPE,i=e.EXTINF,r=e.PREFIX_PATH,a=e.TS_START,s=e.TS_END,o=e.TS_NAME,l=e.TS_LAST_TIME,c=e.IV,u=e.KEY,h=e.TS_LIST,p=xh(u||this.key),f=nh(c||this.iv),null!=h&&h.length)for(m=0;m>".concat(this.url))),this.logger.log("getPlaylist",n),t.abrupt("return",n);case 12:case"end":return t.stop()}}),t,this)}))),function(t){return n.apply(this,arguments)})},{key:"getPlaylistByM3u8",value:(e=p(d().mark((function t(e){var n,i,r,a,s,o,l,c,u,h,p,f,m,g=this;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=2;break}return t.abrupt("return");case 2:if((s=new th).push(e),s.end(),o=s.manifest,this.logger.log("getPlaylistByM3u8",o),null==o||null===(n=o.playlists)||void 0===n||!n.length){t.next=10;break}return l=o.playlists.sort((function(t,e){return e.attributes.RESOLUTION.height-t.attributes.RESOLUTION.height})).map((function(t){var e=t.uri,n=t.attributes.RESOLUTION;return{url:e,name:"".concat(n.height,"P")}})),t.abrupt("return",{levels:l});case 10:if(null!=o&&null!==(i=o.segments)&&void 0!==i&&i.length){t.next=12;break}return t.abrupt("return");case 12:if(!(h=null===(r=o.segments[0].key)||void 0===r?void 0:r.uri)){t.next=26;break}if(!h.startsWith("data:application/octet-stream;")){t.next=18;break}c=xh(h),t.next=23;break;case 18:return!h.startsWith("http")&&h.endsWith(".key")&&(p=Eh(this.url),h="".concat(p).concat(h)),t.next=21,fetch(h).then((function(t){return t.arrayBuffer()})).catch((function(t){g.logger.error("获取视频加密key数据失败",h),g.emitter.emit("error",{fatal:!0,error:{message:"获取视频加密key数据失败"}})}));case 21:f=t.sent,c=h.includes("http")?new Uint8Array(f):xh(h);case 23:u=new Uint8Array(o.segments[0].key.iv.buffer),t.next=27;break;case 26:this.key&&this.iv&&(c="data:application/octet-stream;base64,".concat(this.key),u=nh(this.iv));case 27:return m={duration:0,playlist:[]},null==o||null===(a=o.segments)||void 0===a||a.forEach((function(t){var e=t.uri,n=t.duration;t.key;var i={key:c,iv:u,duration:n,url:e,startTime:m.duration};m.playlist.push(i),m.duration+=n})),t.abrupt("return",m);case 30:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"getResolution",value:(t=p(d().mark((function t(e){var n,i,r,a,s,o=this;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,fetch(e).then(function(){var t=p(d().mark((function t(e){return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.text());case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()).catch((function(t){o.logger.error("fetchMediaSrc",t),o.emitter.emit("error",{fatal:!0})}));case 3:if(n=t.sent,console.log("getResolution",n),n){t.next=7;break}return t.abrupt("return");case 7:if((i=new th).push(n),i.end(),r=i.manifest,this.logger.log("getResolution",r),r.playlists){t.next=14;break}return t.abrupt("return");case 14:return a=Eh(e),s=r.playlists.sort((function(t,e){return e.attributes.RESOLUTION.height-t.attributes.RESOLUTION.height})).map((function(t){var e=t.uri,n=t.attributes.RESOLUTION;return{url:e.startsWith("http")?e:"".concat(a).concat(e),name:"".concat(n.height,"P")}})),t.abrupt("return",s);case 19:t.prev=19,t.t0=t.catch(0),console.warn("getResolution::",t.t0);case 22:case"end":return t.stop()}}),t,this,[[0,19]])}))),function(e){return t.apply(this,arguments)})}]);var t,e,n,i,r,a,s,o}();function Eh(t){var e=t.lastIndexOf("/");return t.slice(0,e+1)}function wh(t){return Pu(t)&&t.startsWith("#EXTM3U")}function xh(t){if(t){for(var e=t.replace(/^data:application\/octet-stream;base64,/,""),n=window.atob(e),i=new Uint8Array(n.length),r=0;r\n ').concat(t.image&&"rolling"!==t.adType?'\n
'):"","\n \n ").concat(t.text?'').concat(t.text||"","
"):"","\n