UNPKG

ft-component-set

Version:

简单组件集

5 lines 607 kB
(function($t,be){typeof exports=="object"&&typeof module<"u"?be(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],be):($t=typeof globalThis<"u"?globalThis:$t||self,be($t["ft-component-set"]={},$t.Vue))})(this,function($t,be){"use strict";var wr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ra(We){return We&&We.__esModule&&Object.prototype.hasOwnProperty.call(We,"default")?We.default:We}var Ia={exports:{}};(function(We,Xe){typeof window<"u"&&function(Ee,Re){We.exports=Re()}(wr,()=>(()=>{var V={"./src/config.ts":(H,U,I)=>{I.r(U),I.d(U,{enableStreamingMode:()=>A,hlsDefaultConfig:()=>o,mergeConfig:()=>_});var w=I("./src/controller/abr-controller.ts"),R=I("./src/controller/audio-stream-controller.ts"),C=I("./src/controller/audio-track-controller.ts"),S=I("./src/controller/subtitle-stream-controller.ts"),P=I("./src/controller/subtitle-track-controller.ts"),E=I("./src/controller/buffer-controller.ts"),v=I("./src/controller/timeline-controller.ts"),m=I("./src/controller/cap-level-controller.ts"),u=I("./src/controller/fps-controller.ts"),f=I("./src/controller/eme-controller.ts"),h=I("./src/controller/cmcd-controller.ts"),d=I("./src/utils/xhr-loader.ts"),s=I("./src/utils/fetch-loader.ts"),r=I("./src/utils/cues.ts"),i=I("./src/utils/mediakeys-helper.ts"),n=I("./src/utils/logger.ts");function c(){return c=Object.assign?Object.assign.bind():function(x){for(var D=1;D<arguments.length;D++){var L=arguments[D];for(var y in L)Object.prototype.hasOwnProperty.call(L,y)&&(x[y]=L[y])}return x},c.apply(this,arguments)}function p(x,D){var L=Object.keys(x);if(Object.getOwnPropertySymbols){var y=Object.getOwnPropertySymbols(x);D&&(y=y.filter(function(O){return Object.getOwnPropertyDescriptor(x,O).enumerable})),L.push.apply(L,y)}return L}function l(x){for(var D=1;D<arguments.length;D++){var L=arguments[D]!=null?arguments[D]:{};D%2?p(Object(L),!0).forEach(function(y){a(x,y,L[y])}):Object.getOwnPropertyDescriptors?Object.defineProperties(x,Object.getOwnPropertyDescriptors(L)):p(Object(L)).forEach(function(y){Object.defineProperty(x,y,Object.getOwnPropertyDescriptor(L,y))})}return x}function a(x,D,L){return D in x?Object.defineProperty(x,D,{value:L,enumerable:!0,configurable:!0,writable:!0}):x[D]=L,x}var o=l(l({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,maxBufferSize:60*1e3*1e3,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,enableSoftwareAES:!0,manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,manifestLoadingMaxRetryTimeout:64e3,startLevel:void 0,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,levelLoadingMaxRetryTimeout:64e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3,startFragPrefetch:!1,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:3,loader:d.default,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:w.default,bufferController:E.default,capLevelController:m.default,fpsController:u.default,stretchShortVideoTrack:!1,maxAudioFramesDrift:1,forceKeyFrameOnDiscontinuity:!0,abrEwmaFastLive:3,abrEwmaSlowLive:9,abrEwmaFastVoD:3,abrEwmaSlowVoD:9,abrEwmaDefaultEstimate:5e5,abrBandWidthFactor:.95,abrBandWidthUpFactor:.7,abrMaxWithRealBitrate:!1,maxStarvationDelay:4,maxLoadingDelay:4,minAutoBitrate:0,emeEnabled:!1,widevineLicenseUrl:void 0,drmSystemOptions:{},requestMediaKeySystemAccessFunc:i.requestMediaKeySystemAccess,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0},g()),{},{subtitleStreamController:S.SubtitleStreamController,subtitleTrackController:P.default,timelineController:v.TimelineController,audioStreamController:R.default,audioTrackController:C.default,emeController:f.default,cmcdController:h.default});function g(){return{cueHandler:r.default,enableWebVTT:!0,enableIMSC1:!0,enableCEA708Captions:!0,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}}function _(x,D){if((D.liveSyncDurationCount||D.liveMaxLatencyDurationCount)&&(D.liveSyncDuration||D.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(D.liveMaxLatencyDurationCount!==void 0&&(D.liveSyncDurationCount===void 0||D.liveMaxLatencyDurationCount<=D.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(D.liveMaxLatencyDuration!==void 0&&(D.liveSyncDuration===void 0||D.liveMaxLatencyDuration<=D.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');return c({},x,D)}function A(x){var D=x.loader;if(D!==s.default&&D!==d.default)n.logger.log("[config]: Custom loader detected, cannot enable progressive streaming"),x.progressive=!1;else{var L=(0,s.fetchSupported)();L&&(x.loader=s.default,x.progressive=!0,x.enableSoftwareAES=!0,n.logger.log("[config]: Progressive streaming enabled, using FetchLoader"))}}},"./src/controller/abr-controller.ts":(H,U,I)=>{I.r(U),I.d(U,{default:()=>f});var w=I("./src/polyfills/number.ts"),R=I("./src/utils/ewma-bandwidth-estimator.ts"),C=I("./src/events.ts"),S=I("./src/errors.ts"),P=I("./src/types/loader.ts"),E=I("./src/utils/logger.ts");function v(h,d){for(var s=0;s<d.length;s++){var r=d[s];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(h,r.key,r)}}function m(h,d,s){return d&&v(h.prototype,d),s&&v(h,s),Object.defineProperty(h,"prototype",{writable:!1}),h}var u=function(){function h(s){this.hls=void 0,this.lastLoadedFragLevel=0,this._nextAutoLevel=-1,this.timer=void 0,this.onCheck=this._abandonRulesCheck.bind(this),this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this.hls=s;var r=s.config;this.bwEstimator=new R.default(r.abrEwmaSlowVoD,r.abrEwmaFastVoD,r.abrEwmaDefaultEstimate),this.registerListeners()}var d=h.prototype;return d.registerListeners=function(){var r=this.hls;r.on(C.Events.FRAG_LOADING,this.onFragLoading,this),r.on(C.Events.FRAG_LOADED,this.onFragLoaded,this),r.on(C.Events.FRAG_BUFFERED,this.onFragBuffered,this),r.on(C.Events.LEVEL_LOADED,this.onLevelLoaded,this),r.on(C.Events.ERROR,this.onError,this)},d.unregisterListeners=function(){var r=this.hls;r.off(C.Events.FRAG_LOADING,this.onFragLoading,this),r.off(C.Events.FRAG_LOADED,this.onFragLoaded,this),r.off(C.Events.FRAG_BUFFERED,this.onFragBuffered,this),r.off(C.Events.LEVEL_LOADED,this.onLevelLoaded,this),r.off(C.Events.ERROR,this.onError,this)},d.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this.onCheck=null,this.fragCurrent=this.partCurrent=null},d.onFragLoading=function(r,i){var n=i.frag;if(n.type===P.PlaylistLevelType.MAIN&&!this.timer){var c;this.fragCurrent=n,this.partCurrent=(c=i.part)!=null?c:null,this.timer=self.setInterval(this.onCheck,100)}},d.onLevelLoaded=function(r,i){var n=this.hls.config;i.details.live?this.bwEstimator.update(n.abrEwmaSlowLive,n.abrEwmaFastLive):this.bwEstimator.update(n.abrEwmaSlowVoD,n.abrEwmaFastVoD)},d._abandonRulesCheck=function(){var r=this.fragCurrent,i=this.partCurrent,n=this.hls,c=n.autoLevelEnabled;n.config;var p=n.media;if(!(!r||!p)){var l=i?i.stats:r.stats,a=i?i.duration:r.duration;if(l.aborted||l.loaded&&l.loaded===l.total||r.level===0){this.clearTimer(),this._nextAutoLevel=-1;return}if(!(!c||p.paused||!p.playbackRate||!p.readyState)){var o=n.mainForwardBufferInfo;if(o!==null){var g=performance.now()-l.loading.start,_=Math.abs(p.playbackRate);if(!(g<=500*a/_)){var A=l.loaded&&l.loading.first,x=this.bwEstimator.getEstimate(),D=n.levels,L=n.minAutoLevel,y=D[r.level],O=l.total||Math.max(l.loaded,Math.round(a*y.maxBitrate/8)),b=A?l.loaded*1e3/g:0,F=b?(O-l.loaded)/b:O*8/x,k=o.len/_;if(!(F<=k)){var B=Number.POSITIVE_INFINITY,K;for(K=r.level-1;K>L;K--){var j=D[K].maxBitrate;if(B=b?a*j/(8*.8*b):a*j/x,B<k)break}B>=F||(E.logger.warn("Fragment "+r.sn+(i?" part "+i.index:"")+" of level "+r.level+" is loading too slowly and will cause an underbuffer; aborting and switching to level "+K+` Current BW estimate: `+((0,w.isFiniteNumber)(x)?(x/1024).toFixed(3):"Unknown")+` Kb/s Estimated load time for current fragment: `+F.toFixed(3)+` s Estimated load time for the next fragment: `+B.toFixed(3)+` s Time to underbuffer: `+k.toFixed(3)+" s"),n.nextLoadLevel=K,A&&this.bwEstimator.sample(g,l.loaded),this.clearTimer(),r.loader&&(this.fragCurrent=this.partCurrent=null,r.loader.abort()),n.trigger(C.Events.FRAG_LOAD_EMERGENCY_ABORTED,{frag:r,part:i,stats:l}))}}}}}},d.onFragLoaded=function(r,i){var n=i.frag,c=i.part;if(n.type===P.PlaylistLevelType.MAIN&&(0,w.isFiniteNumber)(n.sn)){var p=c?c.stats:n.stats,l=c?c.duration:n.duration;if(this.clearTimer(),this.lastLoadedFragLevel=n.level,this._nextAutoLevel=-1,this.hls.config.abrMaxWithRealBitrate){var a=this.hls.levels[n.level],o=(a.loaded?a.loaded.bytes:0)+p.loaded,g=(a.loaded?a.loaded.duration:0)+l;a.loaded={bytes:o,duration:g},a.realBitrate=Math.round(8*o/g)}if(n.bitrateTest){var _={stats:p,frag:n,part:c,id:n.type};this.onFragBuffered(C.Events.FRAG_BUFFERED,_)}}},d.onFragBuffered=function(r,i){var n=i.frag,c=i.part,p=c?c.stats:n.stats;if(!p.aborted&&!(n.type!==P.PlaylistLevelType.MAIN||n.sn==="initSegment")){var l=p.parsing.end-p.loading.start;this.bwEstimator.sample(l,p.loaded),p.bwEstimate=this.bwEstimator.getEstimate(),n.bitrateTest?this.bitrateTestDelay=l/1e3:this.bitrateTestDelay=0}},d.onError=function(r,i){switch(i.details){case S.ErrorDetails.FRAG_LOAD_ERROR:case S.ErrorDetails.FRAG_LOAD_TIMEOUT:this.clearTimer();break}},d.clearTimer=function(){self.clearInterval(this.timer),this.timer=void 0},d.getNextABRAutoLevel=function(){var r=this.fragCurrent,i=this.partCurrent,n=this.hls,c=n.maxAutoLevel,p=n.config,l=n.minAutoLevel,a=n.media,o=i?i.duration:r?r.duration:0;a&&a.currentTime;var g=a&&a.playbackRate!==0?Math.abs(a.playbackRate):1,_=this.bwEstimator?this.bwEstimator.getEstimate():p.abrEwmaDefaultEstimate,A=n.mainForwardBufferInfo,x=(A?A.len:0)/g,D=this.findBestLevel(_,l,c,x,p.abrBandWidthFactor,p.abrBandWidthUpFactor);if(D>=0)return D;E.logger.trace((x?"rebuffering expected":"buffer is empty")+", finding optimal quality level");var L=o?Math.min(o,p.maxStarvationDelay):p.maxStarvationDelay,y=p.abrBandWidthFactor,O=p.abrBandWidthUpFactor;if(!x){var b=this.bitrateTestDelay;if(b){var F=o?Math.min(o,p.maxLoadingDelay):p.maxLoadingDelay;L=F-b,E.logger.trace("bitrate test took "+Math.round(1e3*b)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*L)+" ms"),y=O=1}}return D=this.findBestLevel(_,l,c,x+L,y,O),Math.max(D,0)},d.findBestLevel=function(r,i,n,c,p,l){for(var a,o=this.fragCurrent,g=this.partCurrent,_=this.lastLoadedFragLevel,A=this.hls.levels,x=A[_],D=!!(x!=null&&(a=x.details)!==null&&a!==void 0&&a.live),L=x==null?void 0:x.codecSet,y=g?g.duration:o?o.duration:0,O=n;O>=i;O--){var b=A[O];if(!(!b||L&&b.codecSet!==L)){var F=b.details,k=(g?F==null?void 0:F.partTarget:F==null?void 0:F.averagetargetduration)||y,B=void 0;O<=_?B=p*r:B=l*r;var K=A[O].maxBitrate,j=K*k/B;if(E.logger.trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: "+O+"/"+Math.round(B)+"/"+K+"/"+k+"/"+c+"/"+j),B>K&&(j===0||!(0,w.isFiniteNumber)(j)||D&&!this.bitrateTestDelay||j<c))return O}}return-1},m(h,[{key:"nextAutoLevel",get:function(){var r=this._nextAutoLevel,i=this.bwEstimator;if(r!==-1&&!i.canEstimate())return r;var n=this.getNextABRAutoLevel();return r!==-1&&this.hls.levels[n].loadError?r:(r!==-1&&(n=Math.min(r,n)),n)},set:function(r){this._nextAutoLevel=r}}]),h}();const f=u},"./src/controller/audio-stream-controller.ts":(H,U,I)=>{I.r(U),I.d(U,{default:()=>a});var w=I("./src/polyfills/number.ts"),R=I("./src/controller/base-stream-controller.ts"),C=I("./src/events.ts"),S=I("./src/utils/buffer-helper.ts"),P=I("./src/controller/fragment-tracker.ts"),E=I("./src/types/level.ts"),v=I("./src/types/loader.ts"),m=I("./src/loader/fragment.ts"),u=I("./src/demux/chunk-cache.ts"),f=I("./src/demux/transmuxer-interface.ts"),h=I("./src/types/transmuxer.ts"),d=I("./src/controller/fragment-finders.ts"),s=I("./src/utils/discontinuities.ts"),r=I("./src/errors.ts");function i(){return i=Object.assign?Object.assign.bind():function(o){for(var g=1;g<arguments.length;g++){var _=arguments[g];for(var A in _)Object.prototype.hasOwnProperty.call(_,A)&&(o[A]=_[A])}return o},i.apply(this,arguments)}function n(o,g){o.prototype=Object.create(g.prototype),o.prototype.constructor=o,c(o,g)}function c(o,g){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(A,x){return A.__proto__=x,A},c(o,g)}var p=100,l=function(o){n(g,o);function g(A,x){var D;return D=o.call(this,A,x,"[audio-stream-controller]")||this,D.videoBuffer=null,D.videoTrackCC=-1,D.waitingVideoCC=-1,D.audioSwitch=!1,D.trackId=-1,D.waitingData=null,D.mainDetails=null,D.bufferFlushed=!1,D.cachedTrackLoadedData=null,D._registerListeners(),D}var _=g.prototype;return _.onHandlerDestroying=function(){this._unregisterListeners(),this.mainDetails=null},_._registerListeners=function(){var x=this.hls;x.on(C.Events.MEDIA_ATTACHED,this.onMediaAttached,this),x.on(C.Events.MEDIA_DETACHING,this.onMediaDetaching,this),x.on(C.Events.MANIFEST_LOADING,this.onManifestLoading,this),x.on(C.Events.LEVEL_LOADED,this.onLevelLoaded,this),x.on(C.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),x.on(C.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),x.on(C.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),x.on(C.Events.ERROR,this.onError,this),x.on(C.Events.BUFFER_RESET,this.onBufferReset,this),x.on(C.Events.BUFFER_CREATED,this.onBufferCreated,this),x.on(C.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),x.on(C.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),x.on(C.Events.FRAG_BUFFERED,this.onFragBuffered,this)},_._unregisterListeners=function(){var x=this.hls;x.off(C.Events.MEDIA_ATTACHED,this.onMediaAttached,this),x.off(C.Events.MEDIA_DETACHING,this.onMediaDetaching,this),x.off(C.Events.MANIFEST_LOADING,this.onManifestLoading,this),x.off(C.Events.LEVEL_LOADED,this.onLevelLoaded,this),x.off(C.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),x.off(C.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),x.off(C.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),x.off(C.Events.ERROR,this.onError,this),x.off(C.Events.BUFFER_RESET,this.onBufferReset,this),x.off(C.Events.BUFFER_CREATED,this.onBufferCreated,this),x.off(C.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),x.off(C.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),x.off(C.Events.FRAG_BUFFERED,this.onFragBuffered,this)},_.onInitPtsFound=function(x,D){var L=D.frag,y=D.id,O=D.initPTS;if(y==="main"){var b=L.cc;this.initPTS[L.cc]=O,this.log("InitPTS for cc: "+b+" found from main: "+O),this.videoTrackCC=b,this.state===R.State.WAITING_INIT_PTS&&this.tick()}},_.startLoad=function(x){if(!this.levels){this.startPosition=x,this.state=R.State.STOPPED;return}var D=this.lastCurrentTime;this.stopLoad(),this.setInterval(p),this.fragLoadError=0,D>0&&x===-1?(this.log("Override startPosition with lastCurrentTime @"+D.toFixed(3)),x=D,this.state=R.State.IDLE):(this.loadedmetadata=!1,this.state=R.State.WAITING_TRACK),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=x,this.tick()},_.doTick=function(){switch(this.state){case R.State.IDLE:this.doTickIdle();break;case R.State.WAITING_TRACK:{var x,D=this.levels,L=this.trackId,y=D==null||(x=D[L])===null||x===void 0?void 0:x.details;if(y){if(this.waitForCdnTuneIn(y))break;this.state=R.State.WAITING_INIT_PTS}break}case R.State.FRAG_LOADING_WAITING_RETRY:{var O,b=performance.now(),F=this.retryDate;(!F||b>=F||(O=this.media)!==null&&O!==void 0&&O.seeking)&&(this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded(this.trackId),this.state=R.State.IDLE);break}case R.State.WAITING_INIT_PTS:{var k=this.waitingData;if(k){var B=k.frag,K=k.part,j=k.cache,Y=k.complete;if(this.initPTS[B.cc]!==void 0){this.waitingData=null,this.waitingVideoCC=-1,this.state=R.State.FRAG_LOADING;var z=j.flush(),Q={frag:B,part:K,payload:z,networkDetails:null};this._handleFragmentLoadProgress(Q),Y&&o.prototype._handleFragmentLoadComplete.call(this,Q)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log("Waiting fragment cc ("+B.cc+") cancelled because video is at cc "+this.videoTrackCC),this.clearWaitingFragment();else{var q=this.getLoadPosition(),ne=S.BufferHelper.bufferInfo(this.mediaBuffer,q,this.config.maxBufferHole),re=(0,d.fragmentWithinToleranceTest)(ne.end,this.config.maxFragLookUpTolerance,B);re<0&&(this.log("Waiting fragment cc ("+B.cc+") @ "+B.start+" cancelled because another fragment at "+ne.end+" is needed"),this.clearWaitingFragment())}}else this.state=R.State.IDLE}}this.onTickEnd()},_.clearWaitingFragment=function(){var x=this.waitingData;x&&(this.fragmentTracker.removeFragment(x.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=R.State.IDLE)},_.resetLoadingState=function(){this.clearWaitingFragment(),o.prototype.resetLoadingState.call(this)},_.onTickEnd=function(){var x=this.media;if(!(!x||!x.readyState)){var D=this.mediaBuffer?this.mediaBuffer:x,L=D.buffered;!this.loadedmetadata&&L.length&&(this.loadedmetadata=!0),this.lastCurrentTime=x.currentTime}},_.doTickIdle=function(){var x,D,L=this.hls,y=this.levels,O=this.media,b=this.trackId,F=L.config;if(!(!y||!y[b])&&!(!O&&(this.startFragRequested||!F.startFragPrefetch))){var k=y[b],B=k.details;if(!B||B.live&&this.levelLastLoaded!==b||this.waitForCdnTuneIn(B)){this.state=R.State.WAITING_TRACK;return}var K=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&K&&(this.bufferFlushed=!1,this.afterBufferFlushed(K,m.ElementaryStreamTypes.AUDIO,v.PlaylistLevelType.AUDIO));var j=this.getFwdBufferInfo(K,v.PlaylistLevelType.AUDIO);if(j!==null){var Y=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,v.PlaylistLevelType.MAIN),z=j.len,Q=this.getMaxBufferLength(Y==null?void 0:Y.len),q=this.audioSwitch;if(!(z>=Q&&!q)){if(!q&&this._streamEnded(j,B)){L.trigger(C.Events.BUFFER_EOS,{type:"audio"}),this.state=R.State.ENDED;return}var ne=B.fragments,re=ne[0].start,le=j.end;if(q&&O){var he=this.getLoadPosition();le=he,B.PTSKnown&&he<re&&(j.end>re||j.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),O.currentTime=re+.05)}if(!(Y&&le>Y.end+B.targetduration)&&!((!Y||!Y.len)&&j.len)){var ce=this.getNextFragment(le,B);if(!ce){this.bufferFlushed=!0;return}((x=ce.decryptdata)===null||x===void 0?void 0:x.keyFormat)==="identity"&&!((D=ce.decryptdata)!==null&&D!==void 0&&D.key)?this.loadKey(ce,B):this.loadFragment(ce,B,le)}}}}},_.getMaxBufferLength=function(x){var D=o.prototype.getMaxBufferLength.call(this);return x?Math.max(D,x):D},_.onMediaDetaching=function(){this.videoBuffer=null,o.prototype.onMediaDetaching.call(this)},_.onAudioTracksUpdated=function(x,D){var L=D.audioTracks;this.resetTransmuxer(),this.levels=L.map(function(y){return new E.Level(y)})},_.onAudioTrackSwitching=function(x,D){var L=!!D.url;this.trackId=D.id;var y=this.fragCurrent;y!=null&&y.loader&&y.loader.abort(),this.fragCurrent=null,this.clearWaitingFragment(),L?this.setInterval(p):this.resetTransmuxer(),L?(this.audioSwitch=!0,this.state=R.State.IDLE):this.state=R.State.STOPPED,this.tick()},_.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=!1},_.onLevelLoaded=function(x,D){this.mainDetails=D.details,this.cachedTrackLoadedData!==null&&(this.hls.trigger(C.Events.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)},_.onAudioTrackLoaded=function(x,D){var L;if(this.mainDetails==null){this.cachedTrackLoadedData=D;return}var y=this.levels,O=D.details,b=D.id;if(!y){this.warn("Audio tracks were reset while loading level "+b);return}this.log("Track "+b+" loaded ["+O.startSN+","+O.endSN+"],duration:"+O.totalduration);var F=y[b],k=0;if(O.live||(L=F.details)!==null&&L!==void 0&&L.live){var B=this.mainDetails;if(O.fragments[0]||(O.deltaUpdateFailed=!0),O.deltaUpdateFailed||!B)return;!F.details&&O.hasProgramDateTime&&B.hasProgramDateTime?((0,s.alignMediaPlaylistByPDT)(O,B),k=O.fragments[0].start):k=this.alignPlaylists(O,F.details)}F.details=O,this.levelLastLoaded=b,!this.startFragRequested&&(this.mainDetails||!O.live)&&this.setStartPosition(F.details,k),this.state===R.State.WAITING_TRACK&&!this.waitForCdnTuneIn(O)&&(this.state=R.State.IDLE),this.tick()},_._handleFragmentLoadProgress=function(x){var D,L=x.frag,y=x.part,O=x.payload,b=this.config,F=this.trackId,k=this.levels;if(!k){this.warn("Audio tracks were reset while fragment load was in progress. Fragment "+L.sn+" of level "+L.level+" will not be buffered");return}var B=k[F];console.assert(B,"Audio track is defined on fragment load progress");var K=B.details;console.assert(K,"Audio track details are defined on fragment load progress");var j=b.defaultAudioCodec||B.audioCodec||"mp4a.40.2",Y=this.transmuxer;Y||(Y=this.transmuxer=new f.default(this.hls,v.PlaylistLevelType.AUDIO,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));var z=this.initPTS[L.cc],Q=(D=L.initSegment)===null||D===void 0?void 0:D.data;if(z!==void 0){var q=!1,ne=y?y.index:-1,re=ne!==-1,le=new h.ChunkMetadata(L.level,L.sn,L.stats.chunkCount,O.byteLength,ne,re);Y.push(O,Q,j,"",L,y,K.totalduration,q,le,z)}else{this.log("Unknown video PTS for cc "+L.cc+", waiting for video PTS before demuxing audio frag "+L.sn+" of ["+K.startSN+" ,"+K.endSN+"],track "+F);var he=this.waitingData=this.waitingData||{frag:L,part:y,cache:new u.default,complete:!1},ce=he.cache;ce.push(new Uint8Array(O)),this.waitingVideoCC=this.videoTrackCC,this.state=R.State.WAITING_INIT_PTS}},_._handleFragmentLoadComplete=function(x){if(this.waitingData){this.waitingData.complete=!0;return}o.prototype._handleFragmentLoadComplete.call(this,x)},_.onBufferReset=function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1},_.onBufferCreated=function(x,D){var L=D.tracks.audio;L&&(this.mediaBuffer=L.buffer||null),D.tracks.video&&(this.videoBuffer=D.tracks.video.buffer||null)},_.onFragBuffered=function(x,D){var L=D.frag,y=D.part;if(L.type===v.PlaylistLevelType.AUDIO){if(this.fragContextChanged(L)){this.warn("Fragment "+L.sn+(y?" p: "+y.index:"")+" of level "+L.level+" finished buffering, but was aborted. state: "+this.state+", audioSwitch: "+this.audioSwitch);return}L.sn!=="initSegment"&&(this.fragPrevious=L,this.audioSwitch&&(this.audioSwitch=!1,this.hls.trigger(C.Events.AUDIO_TRACK_SWITCHED,{id:this.trackId}))),this.fragBufferedComplete(L,y)}},_.onError=function(x,D){switch(D.details){case r.ErrorDetails.FRAG_LOAD_ERROR:case r.ErrorDetails.FRAG_LOAD_TIMEOUT:case r.ErrorDetails.KEY_LOAD_ERROR:case r.ErrorDetails.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(v.PlaylistLevelType.AUDIO,D);break;case r.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:case r.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:this.state!==R.State.ERROR&&this.state!==R.State.STOPPED&&(this.state=D.fatal?R.State.ERROR:R.State.IDLE,this.warn(D.details+" while loading frag, switching to "+this.state+" state"));break;case r.ErrorDetails.BUFFER_FULL_ERROR:if(D.parent==="audio"&&(this.state===R.State.PARSING||this.state===R.State.PARSED)){var L=!0,y=this.getFwdBufferInfo(this.mediaBuffer,v.PlaylistLevelType.AUDIO);y&&y.len>.5&&(L=!this.reduceMaxBufferLength(y.len)),L&&(this.warn("Buffer full error also media.currentTime is not buffered, flush audio buffer"),this.fragCurrent=null,o.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.resetLoadingState()}break}},_.onBufferFlushed=function(x,D){var L=D.type;L===m.ElementaryStreamTypes.AUDIO&&(this.bufferFlushed=!0)},_._handleTransmuxComplete=function(x){var D,L="audio",y=this.hls,O=x.remuxResult,b=x.chunkMeta,F=this.getCurrentContext(b);if(!F){this.warn("The loading context changed while buffering fragment "+b.sn+" of level "+b.level+". This chunk will not be buffered."),this.resetStartWhenNotLoaded(b.level);return}var k=F.frag,B=F.part,K=F.level.details,j=O.audio,Y=O.text,z=O.id3,Q=O.initSegment;if(!(this.fragContextChanged(k)||!K)){if(this.state=R.State.PARSING,this.audioSwitch&&j&&this.completeAudioSwitch(),Q!=null&&Q.tracks&&(this._bufferInitSegment(Q.tracks,k,b),y.trigger(C.Events.FRAG_PARSING_INIT_SEGMENT,{frag:k,id:L,tracks:Q.tracks})),j){var q=j.startPTS,ne=j.endPTS,re=j.startDTS,le=j.endDTS;B&&(B.elementaryStreams[m.ElementaryStreamTypes.AUDIO]={startPTS:q,endPTS:ne,startDTS:re,endDTS:le}),k.setElementaryStreamInfo(m.ElementaryStreamTypes.AUDIO,q,ne,re,le),this.bufferFragmentData(j,k,B,b)}if(z!=null&&(D=z.samples)!==null&&D!==void 0&&D.length){var he=i({id:L,frag:k,details:K},z);y.trigger(C.Events.FRAG_PARSING_METADATA,he)}if(Y){var ce=i({id:L,frag:k,details:K},Y);y.trigger(C.Events.FRAG_PARSING_USERDATA,ce)}}},_._bufferInitSegment=function(x,D,L){if(this.state===R.State.PARSING){x.video&&delete x.video;var y=x.audio;if(!!y){y.levelCodec=y.codec,y.id="audio",this.log("Init audio buffer, container:"+y.container+", codecs[parsed]=["+y.codec+"]"),this.hls.trigger(C.Events.BUFFER_CODECS,x);var O=y.initSegment;if(O!=null&&O.byteLength){var b={type:"audio",frag:D,part:null,chunkMeta:L,parent:D.type,data:O};this.hls.trigger(C.Events.BUFFER_APPENDING,b)}this.tick()}}},_.loadFragment=function(x,D,L){var y=this.fragmentTracker.getState(x);this.fragCurrent=x,(this.audioSwitch||y===P.FragmentState.NOT_LOADED||y===P.FragmentState.PARTIAL)&&(x.sn==="initSegment"?this._loadInitSegment(x):D.live&&!(0,w.isFiniteNumber)(this.initPTS[x.cc])?(this.log("Waiting for video PTS in continuity counter "+x.cc+" of live stream before loading audio fragment "+x.sn+" of level "+this.trackId),this.state=R.State.WAITING_INIT_PTS):(this.startFragRequested=!0,o.prototype.loadFragment.call(this,x,D,L)))},_.completeAudioSwitch=function(){var x=this.hls,D=this.media,L=this.trackId;D&&(this.log("Switching audio track : flushing all audio"),o.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.audioSwitch=!1,x.trigger(C.Events.AUDIO_TRACK_SWITCHED,{id:L})},g}(R.default);const a=l},"./src/controller/audio-track-controller.ts":(H,U,I)=>{I.r(U),I.d(U,{default:()=>f});var w=I("./src/events.ts"),R=I("./src/errors.ts"),C=I("./src/controller/base-playlist-controller.ts"),S=I("./src/types/loader.ts");function P(h,d){for(var s=0;s<d.length;s++){var r=d[s];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(h,r.key,r)}}function E(h,d,s){return d&&P(h.prototype,d),s&&P(h,s),Object.defineProperty(h,"prototype",{writable:!1}),h}function v(h,d){h.prototype=Object.create(d.prototype),h.prototype.constructor=h,m(h,d)}function m(h,d){return m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,i){return r.__proto__=i,r},m(h,d)}var u=function(h){v(d,h);function d(r){var i;return i=h.call(this,r,"[audio-track-controller]")||this,i.tracks=[],i.groupId=null,i.tracksInGroup=[],i.trackId=-1,i.trackName="",i.selectDefaultTrack=!0,i.registerListeners(),i}var s=d.prototype;return s.registerListeners=function(){var i=this.hls;i.on(w.Events.MANIFEST_LOADING,this.onManifestLoading,this),i.on(w.Events.MANIFEST_PARSED,this.onManifestParsed,this),i.on(w.Events.LEVEL_LOADING,this.onLevelLoading,this),i.on(w.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),i.on(w.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),i.on(w.Events.ERROR,this.onError,this)},s.unregisterListeners=function(){var i=this.hls;i.off(w.Events.MANIFEST_LOADING,this.onManifestLoading,this),i.off(w.Events.MANIFEST_PARSED,this.onManifestParsed,this),i.off(w.Events.LEVEL_LOADING,this.onLevelLoading,this),i.off(w.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),i.off(w.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),i.off(w.Events.ERROR,this.onError,this)},s.destroy=function(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,h.prototype.destroy.call(this)},s.onManifestLoading=function(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.trackName="",this.selectDefaultTrack=!0},s.onManifestParsed=function(i,n){this.tracks=n.audioTracks||[]},s.onAudioTrackLoaded=function(i,n){var c=n.id,p=n.details,l=this.tracksInGroup[c];if(!l){this.warn("Invalid audio track id "+c);return}var a=l.details;l.details=n.details,this.log("audioTrack "+c+" loaded ["+p.startSN+"-"+p.endSN+"]"),c===this.trackId&&(this.retryCount=0,this.playlistLoaded(c,n,a))},s.onLevelLoading=function(i,n){this.switchLevel(n.level)},s.onLevelSwitching=function(i,n){this.switchLevel(n.level)},s.switchLevel=function(i){var n=this.hls.levels[i];if(!!(n!=null&&n.audioGroupIds)){var c=n.audioGroupIds[n.urlId];if(this.groupId!==c){this.groupId=c;var p=this.tracks.filter(function(a){return!c||a.groupId===c});this.selectDefaultTrack&&!p.some(function(a){return a.default})&&(this.selectDefaultTrack=!1),this.tracksInGroup=p;var l={audioTracks:p};this.log("Updating audio tracks, "+p.length+' track(s) found in "'+c+'" group-id'),this.hls.trigger(w.Events.AUDIO_TRACKS_UPDATED,l),this.selectInitialTrack()}}},s.onError=function(i,n){h.prototype.onError.call(this,i,n),!(n.fatal||!n.context)&&n.context.type===S.PlaylistContextType.AUDIO_TRACK&&n.context.id===this.trackId&&n.context.groupId===this.groupId&&this.retryLoadingOrFail(n)},s.setAudioTrack=function(i){var n=this.tracksInGroup;if(i<0||i>=n.length){this.warn("Invalid id passed to audio-track controller");return}this.clearTimer();var c=n[this.trackId];this.log("Now switching to audio-track index "+i);var p=n[i],l=p.id,a=p.groupId,o=a===void 0?"":a,g=p.name,_=p.type,A=p.url;if(this.trackId=i,this.trackName=g,this.selectDefaultTrack=!1,this.hls.trigger(w.Events.AUDIO_TRACK_SWITCHING,{id:l,groupId:o,name:g,type:_,url:A}),!(p.details&&!p.details.live)){var x=this.switchParams(p.url,c==null?void 0:c.details);this.loadPlaylist(x)}},s.selectInitialTrack=function(){var i=this.tracksInGroup;console.assert(i.length,"Initial audio track should be selected when tracks are known");var n=this.trackName,c=this.findTrackId(n)||this.findTrackId();c!==-1?this.setAudioTrack(c):(this.warn("No track found for running audio group-ID: "+this.groupId),this.hls.trigger(w.Events.ERROR,{type:R.ErrorTypes.MEDIA_ERROR,details:R.ErrorDetails.AUDIO_TRACK_LOAD_ERROR,fatal:!0}))},s.findTrackId=function(i){for(var n=this.tracksInGroup,c=0;c<n.length;c++){var p=n[c];if((!this.selectDefaultTrack||p.default)&&(!i||i===p.name))return p.id}return-1},s.loadPlaylist=function(i){var n=this.tracksInGroup[this.trackId];if(this.shouldLoadTrack(n)){var c=n.id,p=n.groupId,l=n.url;if(i)try{l=i.addDirectives(l)}catch(a){this.warn("Could not construct new URL with HLS Delivery Directives: "+a)}this.log("loading audio-track playlist for id: "+c),this.clearTimer(),this.hls.trigger(w.Events.AUDIO_TRACK_LOADING,{url:l,id:c,groupId:p,deliveryDirectives:i||null})}},E(d,[{key:"audioTracks",get:function(){return this.tracksInGroup}},{key:"audioTrack",get:function(){return this.trackId},set:function(i){this.selectDefaultTrack=!1,this.setAudioTrack(i)}}]),d}(C.default);const f=u},"./src/controller/base-playlist-controller.ts":(H,U,I)=>{I.r(U),I.d(U,{default:()=>E});var w=I("./src/polyfills/number.ts"),R=I("./src/types/level.ts"),C=I("./src/controller/level-helper.ts"),S=I("./src/utils/logger.ts"),P=I("./src/errors.ts"),E=function(){function v(u,f){this.hls=void 0,this.timer=-1,this.canLoad=!1,this.retryCount=0,this.log=void 0,this.warn=void 0,this.log=S.logger.log.bind(S.logger,f+":"),this.warn=S.logger.warn.bind(S.logger,f+":"),this.hls=u}var m=v.prototype;return m.destroy=function(){this.clearTimer(),this.hls=this.log=this.warn=null},m.onError=function(f,h){h.fatal&&h.type===P.ErrorTypes.NETWORK_ERROR&&this.clearTimer()},m.clearTimer=function(){clearTimeout(this.timer),this.timer=-1},m.startLoad=function(){this.canLoad=!0,this.retryCount=0,this.loadPlaylist()},m.stopLoad=function(){this.canLoad=!1,this.clearTimer()},m.switchParams=function(f,h){var d=h==null?void 0:h.renditionReports;if(d)for(var s=0;s<d.length;s++){var r=d[s],i=""+r.URI;if(i===f.slice(-i.length)){var n=parseInt(r["LAST-MSN"]),c=parseInt(r["LAST-PART"]);if(h&&this.hls.config.lowLatencyMode){var p=Math.min(h.age-h.partTarget,h.targetduration);c!==void 0&&p>h.partTarget&&(c+=1)}if((0,w.isFiniteNumber)(n))return new R.HlsUrlParameters(n,(0,w.isFiniteNumber)(c)?c:void 0,R.HlsSkip.No)}}},m.loadPlaylist=function(f){},m.shouldLoadTrack=function(f){return this.canLoad&&f&&!!f.url&&(!f.details||f.details.live)},m.playlistLoaded=function(f,h,d){var s=this,r=h.details,i=h.stats,n=i.loading.end?Math.max(0,self.performance.now()-i.loading.end):0;if(r.advancedDateTime=Date.now()-n,r.live||d!=null&&d.live){if(r.reloaded(d),d&&this.log("live playlist "+f+" "+(r.advanced?"REFRESHED "+r.lastPartSn+"-"+r.lastPartIndex:"MISSED")),d&&r.fragments.length>0&&(0,C.mergeDetails)(d,r),!this.canLoad||!r.live)return;var c,p=void 0,l=void 0;if(r.canBlockReload&&r.endSN&&r.advanced){var a=this.hls.config.lowLatencyMode,o=r.lastPartSn,g=r.endSN,_=r.lastPartIndex,A=_!==-1,x=o===g,D=a?0:_;A?(p=x?g+1:o,l=x?D:_+1):p=g+1;var L=r.age,y=L+r.ageHeader,O=Math.min(y-r.partTarget,r.targetduration*1.5);if(O>0){if(d&&O>d.tuneInGoal)this.warn("CDN Tune-in goal increased from: "+d.tuneInGoal+" to: "+O+" with playlist age: "+r.age),O=0;else{var b=Math.floor(O/r.targetduration);if(p+=b,l!==void 0){var F=Math.round(O%r.targetduration/r.partTarget);l+=F}this.log("CDN Tune-in age: "+r.ageHeader+"s last advanced "+L.toFixed(2)+"s goal: "+O+" skip sn "+b+" to part "+l)}r.tuneInGoal=O}if(c=this.getDeliveryDirectives(r,h.deliveryDirectives,p,l),a||!x){this.loadPlaylist(c);return}}else c=this.getDeliveryDirectives(r,h.deliveryDirectives,p,l);var k=(0,C.computeReloadInterval)(r,i);p!==void 0&&r.canBlockReload&&(k-=r.partTarget||1),this.log("reload live playlist "+f+" in "+Math.round(k)+" ms"),this.timer=self.setTimeout(function(){return s.loadPlaylist(c)},k)}else this.clearTimer()},m.getDeliveryDirectives=function(f,h,d,s){var r=(0,R.getSkipValue)(f,d);return h!=null&&h.skip&&f.deltaUpdateFailed&&(d=h.msn,s=h.part,r=R.HlsSkip.No),new R.HlsUrlParameters(d,s,r)},m.retryLoadingOrFail=function(f){var h=this,d=this.hls.config,s=this.retryCount<d.levelLoadingMaxRetry;if(s){var r;if(this.retryCount++,f.details.indexOf("LoadTimeOut")>-1&&(r=f.context)!==null&&r!==void 0&&r.deliveryDirectives)this.warn("retry playlist loading #"+this.retryCount+' after "'+f.details+'"'),this.loadPlaylist();else{var i=Math.min(Math.pow(2,this.retryCount)*d.levelLoadingRetryDelay,d.levelLoadingMaxRetryTimeout);this.timer=self.setTimeout(function(){return h.loadPlaylist()},i),this.warn("retry playlist loading #"+this.retryCount+" in "+i+' ms after "'+f.details+'"')}}else this.warn('cannot recover from error "'+f.details+'"'),this.clearTimer(),f.fatal=!0;return s},v}()},"./src/controller/base-stream-controller.ts":(H,U,I)=>{I.r(U),I.d(U,{State:()=>g,default:()=>_});var w=I("./src/polyfills/number.ts"),R=I("./src/task-loop.ts"),C=I("./src/controller/fragment-tracker.ts"),S=I("./src/utils/buffer-helper.ts"),P=I("./src/utils/logger.ts"),E=I("./src/events.ts"),v=I("./src/errors.ts"),m=I("./src/types/transmuxer.ts"),u=I("./src/utils/mp4-tools.ts"),f=I("./src/utils/discontinuities.ts"),h=I("./src/controller/fragment-finders.ts"),d=I("./src/controller/level-helper.ts"),s=I("./src/loader/fragment-loader.ts"),r=I("./src/crypt/decrypter.ts"),i=I("./src/utils/time-ranges.ts"),n=I("./src/types/loader.ts");function c(A,x){for(var D=0;D<x.length;D++){var L=x[D];L.enumerable=L.enumerable||!1,L.configurable=!0,"value"in L&&(L.writable=!0),Object.defineProperty(A,L.key,L)}}function p(A,x,D){return x&&c(A.prototype,x),D&&c(A,D),Object.defineProperty(A,"prototype",{writable:!1}),A}function l(A){if(A===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return A}function a(A,x){A.prototype=Object.create(x.prototype),A.prototype.constructor=A,o(A,x)}function o(A,x){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(L,y){return L.__proto__=y,L},o(A,x)}var g={STOPPED:"STOPPED",IDLE:"IDLE",KEY_LOADING:"KEY_LOADING",FRAG_LOADING:"FRAG_LOADING",FRAG_LOADING_WAITING_RETRY:"FRAG_LOADING_WAITING_RETRY",WAITING_TRACK:"WAITING_TRACK",PARSING:"PARSING",PARSED:"PARSED",ENDED:"ENDED",ERROR:"ERROR",WAITING_INIT_PTS:"WAITING_INIT_PTS",WAITING_LEVEL:"WAITING_LEVEL"},_=function(A){a(x,A);function x(L,y,O){var b;return b=A.call(this)||this,b.hls=void 0,b.fragPrevious=null,b.fragCurrent=null,b.fragmentTracker=void 0,b.transmuxer=null,b._state=g.STOPPED,b.media=null,b.mediaBuffer=null,b.config=void 0,b.bitrateTest=!1,b.lastCurrentTime=0,b.nextLoadPosition=0,b.startPosition=0,b.loadedmetadata=!1,b.fragLoadError=0,b.retryDate=0,b.levels=null,b.fragmentLoader=void 0,b.levelLastLoaded=null,b.startFragRequested=!1,b.decrypter=void 0,b.initPTS=[],b.onvseeking=null,b.onvended=null,b.logPrefix="",b.log=void 0,b.warn=void 0,b.logPrefix=O,b.log=P.logger.log.bind(P.logger,O+":"),b.warn=P.logger.warn.bind(P.logger,O+":"),b.hls=L,b.fragmentLoader=new s.default(L.config),b.fragmentTracker=y,b.config=L.config,b.decrypter=new r.default(L,L.config),L.on(E.Events.KEY_LOADED,b.onKeyLoaded,l(b)),L.on(E.Events.LEVEL_SWITCHING,b.onLevelSwitching,l(b)),b}var D=x.prototype;return D.doTick=function(){this.onTickEnd()},D.onTickEnd=function(){},D.startLoad=function(y){},D.stopLoad=function(){this.fragmentLoader.abort();var y=this.fragCurrent;y&&this.fragmentTracker.removeFragment(y),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=g.STOPPED},D._streamEnded=function(y,O){var b=this.fragCurrent,F=this.fragmentTracker;if(!O.live&&b&&this.media&&b.sn>=O.endSN&&!y.nextStart){var k=O.partList;if(k!=null&&k.length){var B=k[k.length-1],K=S.BufferHelper.isBuffered(this.media,B.start+B.duration/2);return K}var j=F.getState(b);return j===C.FragmentState.PARTIAL||j===C.FragmentState.OK}return!1},D.onMediaAttached=function(y,O){var b=this.media=this.mediaBuffer=O.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),b.addEventListener("seeking",this.onvseeking),b.addEventListener("ended",this.onvended);var F=this.config;this.levels&&F.autoStartLoad&&this.state===g.STOPPED&&this.startLoad(F.startPosition)},D.onMediaDetaching=function(){var y=this.media;y!=null&&y.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),y&&this.onvseeking&&this.onvended&&(y.removeEventListener("seeking",this.onvseeking),y.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()},D.onMediaSeeking=function(){var y=this.config,O=this.fragCurrent,b=this.media,F=this.mediaBuffer,k=this.state,B=b?b.currentTime:0,K=S.BufferHelper.bufferInfo(F||b,B,y.maxBufferHole);if(this.log("media seeking to "+((0,w.isFiniteNumber)(B)?B.toFixed(3):B)+", state: "+k),k===g.ENDED)this.resetLoadingState();else if(O&&!K.len){var j=y.maxFragLookUpTolerance,Y=O.start-j,z=O.start+O.duration+j,Q=B>z;(B<Y||Q)&&(Q&&O.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),O.loader.abort()),this.resetLoadingState())}b&&(this.lastCurrentTime=B),!this.loadedmetadata&&!K.len&&(this.nextLoadPosition=this.startPosition=B),this.tickImmediate()},D.onMediaEnded=function(){this.startPosition=this.lastCurrentTime=0},D.onKeyLoaded=function(y,O){if(!(this.state!==g.KEY_LOADING||O.frag!==this.fragCurrent||!this.levels)){this.state=g.IDLE;var b=this.levels[O.frag.level].details;b&&this.loadFragment(O.frag,b,O.frag.start)}},D.onLevelSwitching=function(y,O){this.fragLoadError=0},D.onHandlerDestroying=function(){this.stopLoad(),A.prototype.onHandlerDestroying.call(this)},D.onHandlerDestroyed=function(){this.state=g.STOPPED,this.hls.off(E.Events.KEY_LOADED,this.onKeyLoaded,this),this.hls.off(E.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),this.fragmentLoader&&this.fragmentLoader.destroy(),this.decrypter&&this.decrypter.destroy(),this.hls=this.log=this.warn=this.decrypter=this.fragmentLoader=this.fragmentTracker=null,A.prototype.onHandlerDestroyed.call(this)},D.loadKey=function(y,O){this.log("Loading key for "+y.sn+" of ["+O.startSN+"-"+O.endSN+"], "+(this.logPrefix==="[stream-controller]"?"level":"track")+" "+y.level),this.state=g.KEY_LOADING,this.fragCurrent=y,this.hls.trigger(E.Events.KEY_LOADING,{frag:y})},D.loadFragment=function(y,O,b){this._loadFragForPlayback(y,O,b)},D._loadFragForPlayback=function(y,O,b){var F=this,k=function(K){if(F.fragContextChanged(y)){F.warn("Fragment "+y.sn+(K.part?" p: "+K.part.index:"")+" of level "+y.level+" was dropped during download."),F.fragmentTracker.removeFragment(y);return}y.stats.chunkCount++,F._handleFragmentLoadProgress(K)};this._doFragLoad(y,O,b,k).then(function(B){if(!!B){F.fragLoadError=0;var K=F.state;if(F.fragContextChanged(y)){(K===g.FRAG_LOADING||!F.fragCurrent&&K===g.PARSING)&&(F.fragmentTracker.removeFragment(y),F.state=g.IDLE);return}"payload"in B&&(F.log("Loaded fragment "+y.sn+" of level "+y.level),F.hls.trigger(E.Events.FRAG_LOADED,B)),F._handleFragmentLoadComplete(B)}}).catch(function(B){F.state===g.STOPPED||F.state===g.ERROR||(F.warn(B),F.resetFragmentLoading(y))})},D.flushMainBuffer=function(y,O,b){if(b===void 0&&(b=null),!!(y-O)){var F={startOffset:y,endOffset:O,type:b};this.fragLoadError=0,this.hls.trigger(E.Events.BUFFER_FLUSHING,F)}},D._loadInitSegment=function(y){var O=this;this._doFragLoad(y).then(function(b){if(!b||O.fragContextChanged(y)||!O.levels)throw new Error("init load aborted");return b}).then(function(b){var F=O.hls,k=b.payload,B=y.decryptdata;if(k&&k.byteLength>0&&B&&B.key&&B.iv&&B.method==="AES-128"){var K=self.performance.now();return O.decrypter.webCryptoDecrypt(new Uint8Array(k),B.key.buffer,B.iv.buffer).then(function(j){var Y=self.performance.now();return F.trigger(E.Events.FRAG_DECRYPTED,{frag:y,payload:j,stats:{tstart:K,tdecrypt:Y}}),b.payload=j,b})}return b}).then(function(b){var F=O.fragCurrent,k=O.hls,B=O.levels;if(!B)throw new Error("init load aborted, missing levels");var K=B[y.level].details;console.assert(K,"Level details are defined when init segment is loaded");var j=y.stats;O.state=g.IDLE,O.fragLoadError=0,y.data=new Uint8Array(b.payload),j.parsing.start=j.buffering.start=self.performance.now(),j.parsing.end=j.buffering.end=self.performance.now(),b.frag===F&&k.trigger(E.Events.FRAG_BUFFERED,{stats:j,frag:F,part:null,id:y.type}),O.tick()}).catch(function(b){O.state===g.STOPPED||O.state===g.ERROR||(O.warn(b),O.resetFragmentLoading(y))})},D.fragContextChanged=function(y){var O=this.fragCurrent;return!y||!O||y.level!==O.level||y.sn!==O.sn||y.urlId!==O.urlId},D.fragBufferedComplete=function(y,O){var b,F,k=this.mediaBuffer?this.mediaBuffer:this.media;this.log("Buffered "+y.type+" sn: "+y.sn+(O?" part: "+O.index:"")+" of "+(this.logPrefix==="[stream-controller]"?"level":"track")+" "+y.level+" "+(k?i.default.toString(S.BufferHelper.getBuffered(k)):"(detached)")),this.state=g.IDLE,k&&(!this.loadedmetadata&&k.buffered.length&&((b=this.fragCurrent)===null||b===void 0?void 0:b.sn)===((F=this.fragPrevious)===null||F===void 0?void 0:F.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())},D.seekToStartPos=function(){},D._handleFragmentLoadComplete=function(y){var O=this.transmuxer;if(!!O){var b=y.frag,F=y.part,k=y.partsLoaded,B=!k||k.length===0||k.some(function(j){return!j}),K=new m.ChunkMetadata(b.level,b.sn,b.stats.chunkCount+1,0,F?F.index:-1,!B);O.flush(K)}},D._handleFragmentLoadProgress=function(y){},D._doFragLoad=function(y,O,b,F){var k=this;if(b===void 0&&(b=null),!this.levels)throw new Error("frag load aborted, missing levels");if(b=Math.max(y.start,b||0),this.config.lowLatencyMode&&O){var B=O.partList;if(B&&F){b>y.end&&O.fragmentHint&&(y=O.fragmentHint);var K=this.getNextPart(B,y,b);if(K>-1){var j=B[K];return this.log("Loading part sn: "+y.sn+" p: "+j.index+" cc: "+y.cc+" of playlist ["+O.startSN+"-"+O.endSN+"] parts [0-"+K+"-"+(B.length-1)+"] "+(this.logPrefix==="[stream-controller]"?"level":"track")+": "+y.level+", target: "+parseFloat(b.toFixed(3))),this.nextLoadPosition=j.start+j.duration,this.state=g.FRAG_LOADING,this.hls.trigger(E.Events.FRAG_LOADING,{frag:y,part:B[K],targetBufferTime:b}),this.doFragPartsLoad(y,B,K,F).catch(function(Y){return k.handleFragLoadError(Y)})}else if(!y.url||this.loadedEndOfParts(B,b))return Promise.resolve(null)}}return this.log("Loading fragment "+y.sn+" cc: "+y.cc+" "+(O?"of ["+O.startSN+"-"+O.endSN+"] ":"")+(this.logPrefix==="[stream-controller]"?"level":"track")+": "+y.level+", target: "+parseFloat(b.toFixed(3))),(0,w.isFiniteNumber)(y.sn)&&!this.bitrateTest&&(this.nextLoadPosition=y.start+y.duration),this.state=g.FRAG_LOADING,this.hls.trigger(E.Events.FRAG_LOADING,{frag:y,targetBufferTime:b}),this.fragmentLoader.load(y,F).catch(function(Y){return k.handleFragLoadError(Y)})},D.doFragPartsLoad=function(y,O,b,F){var k=this;return new Promise(function(B,K){var j=[],Y=function z(Q){var q=O[Q];k.fragmentLoader.loadPart(y,q,F).then(function(ne){j[q.index]=ne;var re=ne.part;k.hls.trigger(E.Events.FRAG_LOADED,ne);var le=O[Q+1];if(le&&le.fragment===y)z(Q+1);else return B({frag:y,part:re,partsLoaded:j})}).catch(K)};Y(b)})},D.handleFragLoadError=function(y){var O=y.data;return O&&O.details===v.ErrorDetails.INTERNAL_ABORTED?this.handleFragLoadAborted(O.frag,O.part):this.hls.trigger(E.Events.ERROR,O),null},D._handleTransmuxerFlush=function(y){var O=this.getCurrentContext(y);if(!O||this.state!==g.PARSING){this.fragCurrent||(this.state=g.IDLE);return}var b=O.frag,F=O.part,k=O.level,B=self.performance.now();b.stats.parsing.end=B,F&&(F.stats.parsing.end=B),this.updateLevelTiming(b,F,k,y.partial)},D.getCurrentContext=function(y){var O=this.levels,b=y.level,F=y.sn,k=y.part;if(!O||!O[b])return this.warn("Levels object was unset while buffering fragment "+F+" of level "+b+". The current chunk will not be buffered."),null;var B=O[b],K=k>-1?(0,d.getPartWith)(B,F,k):null,j=K?K.fragment:(0,d.getFragmentWithSN)(B,F,this.fragCurrent);return j?{frag:j,part:K,level:B}:null},D.bufferFragmentData=function(y,O,b,F){if(!(!y||this.state!==g.PARSING)){var k=y.data1,B=y.data2,K=k;if(k&&B&&(K=(0,u.appendUint8Array)(k,B)),!(!K||!K.length)){var j={type:y.type,frag:O,part:b,chunkMeta:F,parent:O.type,data:K};this.hls.trigger(E.Events.BUFFER_APPENDING,j),y.dropped&&y.independent&&!b&&this.flushBufferGap(O)}}},D.flushBufferGap=function(y){var O=this.media;if(!!O){if(!S.BufferHelper.isBuffered(O,O.currentTime)){this.flushMainBuffer(0,y.start);return}var b=O.currentTime,F=S.BufferHelper.bufferInfo(O,b,0),k=y.duration,B=Math.min(this.config.maxFragLookUpTolerance*2,k*.25),K=Math.max(Math.min(y.start-B,F.end-B),b+B);y.start-K>B&&this.flushMainBuffer(K,y.start)}},D.getFwdBufferInfo=function(y,O){var b=this.config,F=this.getLoadPosition();if(!(0,w.isFiniteNumber)(F))return null;var k=S.BufferHelper.bufferInfo(y,F,b.maxBufferHole);if(k.len===0&&k.nextStart!==void 0){var B=this.fragmentTracker.getBufferedFrag(F,O);if(B&&k.nextStart<B.end)return S.BufferHelper.bufferInfo(y,F,Math.max(k.nextStart,b.maxBufferHole))}return k},D.getMaxBufferLength=function(y){var O=this.config,b;return y?b=Math.max(8*O.maxBufferSize/y,O.maxBufferLength):b=O.maxBufferLength,Math.min(b,O.maxMaxBufferLength)},D.reduceMaxBufferLength=function(y){var O=this.config,b=y||O.maxBufferLength;return O.maxMaxBufferLength>=b?(O.maxMaxBufferLength/=2,this.warn("Reduce max buffer length to "+O.maxMaxBufferLength+"s"),!0):!1},D.getNextFragment=function(y,O){var b=O.fragments,F=b.length;if(!F)return null;var k=this.config,B=b[0].start,K;if(O.live){var j=k.initialLiveManifestSize;if(F<j)return this.warn("Not enough fragments to start playback (have: "+F+", need: "+j+")"),null;!O.PTSKnown&&!this.startFragRequested&&this.startPosition===-1&&(K=this.getInitialLiveFragment(O,b),this.startPosition=K?this.hls.liveSyncPosition||K.start:y)}else y<=B&&(K=b[0]);if(!K){var Y=k.lowLatencyMode?O.partEnd:O.fragmentEnd;K=this.getFragmentAtPosition(y,Y,O)}return this.mapToInitFragWhenRequired(K)},D.mapToInitFragWhenRequired=function(y){return y!=null&&y.initSegment&&!(y!=null&&y.initSegment.data)&&!this.bitrateTest?y.initSegment:y},D.getNextPart=function(y,O,b){for(var F=-1,k=!1,B=!0,K=0,j=y.length;K<j;K++){var Y=y[K];if(B=B&&!Y.independent,F>-1&&b<Y.start)break;var z=Y.loaded;!z&&(k||Y.independent||B)&&Y.fragment===O&&(F=K),k=z}return F},D.loadedEndOfParts=function(y,O){var b=y[y.length-1];return b&&O>b.start&&b.loaded},D.getInitialLiveFragment=function(y,O){var b=this.fragPrevious,F=null;if(b){if(y.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: "+b.programDateTime),F=(0,h.findFragmentByPDT)(O,b.endProgramDateTime,this.config.maxFragLookUpTolerance)),!F){var k=b.sn+1;if(k>=y.startSN&&k<=y.endSN){var B=O[k-y.startSN];b.cc===B.cc&&(