@flowplayer/player 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/plugins/hls.js CHANGED
@@ -18,11 +18,11 @@
18
18
  /*!******************************************!*\
19
19
  !*** ./src/controller/abr-controller.ts ***!
20
20
  \******************************************/
21
- /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../utils/ewma-bandwidth-estimator */"./src/utils/ewma-bandwidth-estimator.ts"),a=r(/*! ../events */"./src/events.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),o=r(/*! ../errors */"./src/errors.ts"),l=r(/*! ../types/loader */"./src/types/loader.ts"),u=r(/*! ../utils/logger */"./src/utils/logger.ts");function d(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var c=function(){function t(t){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=t;var e=t.config;this.bwEstimator=new n.default(e.abrEwmaSlowVoD,e.abrEwmaFastVoD,e.abrEwmaDefaultEstimate),this.registerListeners()}var e,r,c,h=t.prototype;return h.registerListeners=function(){var t=this.hls;t.on(a.Events.FRAG_LOADING,this.onFragLoading,this),t.on(a.Events.FRAG_LOADED,this.onFragLoaded,this),t.on(a.Events.FRAG_BUFFERED,this.onFragBuffered,this),t.on(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(a.Events.ERROR,this.onError,this)},h.unregisterListeners=function(){var t=this.hls;t.off(a.Events.FRAG_LOADING,this.onFragLoading,this),t.off(a.Events.FRAG_LOADED,this.onFragLoaded,this),t.off(a.Events.FRAG_BUFFERED,this.onFragBuffered,this),t.off(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(a.Events.ERROR,this.onError,this)},h.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this.onCheck=null,this.fragCurrent=this.partCurrent=null},h.onFragLoading=function(t,e){var r,i=e.frag;i.type===l.PlaylistLevelType.MAIN&&(this.timer||(this.fragCurrent=i,this.partCurrent=null!=(r=e.part)?r:null,this.timer=self.setInterval(this.onCheck,100)))},h.onLevelLoaded=function(t,e){var r=this.hls.config;e.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD)},h._abandonRulesCheck=function(){var t=this.fragCurrent,e=this.partCurrent,r=this.hls,n=r.autoLevelEnabled,o=r.config,l=r.media;if(t&&l){var d=e?e.stats:t.stats,c=e?e.duration:t.duration;if(d.aborted)return u.logger.warn("frag loader destroy or aborted, disarm abandonRules"),this.clearTimer(),void(this._nextAutoLevel=-1);if(n&&!l.paused&&l.playbackRate&&l.readyState){var h=performance.now()-d.loading.start,f=Math.abs(l.playbackRate);if(!(h<=500*c/f)){var g=r.levels,v=r.minAutoLevel,p=g[t.level],m=d.total||Math.max(d.loaded,Math.round(c*p.maxBitrate/8)),y=Math.max(1,d.bwEstimate?d.bwEstimate/8:1e3*d.loaded/h),E=(m-d.loaded)/y,T=l.currentTime,S=(s.BufferHelper.bufferInfo(l,T,o.maxBufferHole).end-T)/f;if(!(S>=2*c/f||E<=S)){var b,L=Number.POSITIVE_INFINITY;for(b=t.level-1;b>v&&!((L=c*g[b].maxBitrate/(6.4*y))<S);b--);if(!(L>=E)){var D=this.bwEstimator.getEstimate();u.logger.warn("Fragment "+t.sn+(e?" part "+e.index:"")+" of level "+t.level+" is loading too slowly and will cause an underbuffer; aborting and switching to level "+b+"\n Current BW estimate: "+(Object(i.isFiniteNumber)(D)?(D/1024).toFixed(3):"Unknown")+" Kb/s\n Estimated load time for current fragment: "+E.toFixed(3)+" s\n Estimated load time for the next fragment: "+L.toFixed(3)+" s\n Time to underbuffer: "+S.toFixed(3)+" s"),r.nextLoadLevel=b,this.bwEstimator.sample(h,d.loaded),this.clearTimer(),t.loader&&(this.fragCurrent=this.partCurrent=null,t.loader.abort()),r.trigger(a.Events.FRAG_LOAD_EMERGENCY_ABORTED,{frag:t,part:e,stats:d})}}}}}},h.onFragLoaded=function(t,e){var r=e.frag,n=e.part;if(r.type===l.PlaylistLevelType.MAIN&&Object(i.isFiniteNumber)(r.sn)){var s=n?n.stats:r.stats,o=n?n.duration:r.duration;if(this.clearTimer(),this.lastLoadedFragLevel=r.level,this._nextAutoLevel=-1,this.hls.config.abrMaxWithRealBitrate){var u=this.hls.levels[r.level],d=(u.loaded?u.loaded.bytes:0)+s.loaded,c=(u.loaded?u.loaded.duration:0)+o;u.loaded={bytes:d,duration:c},u.realBitrate=Math.round(8*d/c)}if(r.bitrateTest){var h={stats:s,frag:r,part:n,id:r.type};this.onFragBuffered(a.Events.FRAG_BUFFERED,h),r.bitrateTest=!1}}},h.onFragBuffered=function(t,e){var r=e.frag,i=e.part,n=i?i.stats:r.stats;if(!n.aborted&&r.type===l.PlaylistLevelType.MAIN&&"initSegment"!==r.sn){var a=n.parsing.end-n.loading.start;this.bwEstimator.sample(a,n.loaded),n.bwEstimate=this.bwEstimator.getEstimate(),r.bitrateTest?this.bitrateTestDelay=a/1e3:this.bitrateTestDelay=0}},h.onError=function(t,e){switch(e.details){case o.ErrorDetails.FRAG_LOAD_ERROR:case o.ErrorDetails.FRAG_LOAD_TIMEOUT:this.clearTimer()}},h.clearTimer=function(){self.clearInterval(this.timer),this.timer=void 0},h.getNextABRAutoLevel=function(){var t=this.fragCurrent,e=this.partCurrent,r=this.hls,i=r.maxAutoLevel,n=r.config,a=r.minAutoLevel,o=r.media,l=e?e.duration:t?t.duration:0,d=o?o.currentTime:0,c=o&&0!==o.playbackRate?Math.abs(o.playbackRate):1,h=this.bwEstimator?this.bwEstimator.getEstimate():n.abrEwmaDefaultEstimate,f=(s.BufferHelper.bufferInfo(o,d,n.maxBufferHole).end-d)/c,g=this.findBestLevel(h,a,i,f,n.abrBandWidthFactor,n.abrBandWidthUpFactor);if(g>=0)return g;u.logger.trace((f?"rebuffering expected":"buffer is empty")+", finding optimal quality level");var v=l?Math.min(l,n.maxStarvationDelay):n.maxStarvationDelay,p=n.abrBandWidthFactor,m=n.abrBandWidthUpFactor;if(!f){var y=this.bitrateTestDelay;y&&(v=(l?Math.min(l,n.maxLoadingDelay):n.maxLoadingDelay)-y,u.logger.trace("bitrate test took "+Math.round(1e3*y)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*v)+" ms"),p=m=1)}return g=this.findBestLevel(h,a,i,f+v,p,m),Math.max(g,0)},h.findBestLevel=function(t,e,r,i,n,a){for(var s,o=this.fragCurrent,l=this.partCurrent,d=this.lastLoadedFragLevel,c=this.hls.levels,h=c[d],f=!(null==h||null===(s=h.details)||void 0===s||!s.live),g=null==h?void 0:h.codecSet,v=l?l.duration:o?o.duration:0,p=r;p>=e;p--){var m=c[p];if(m&&(!g||m.codecSet===g)){var y=m.details,E=(l?null==y?void 0:y.partTarget:null==y?void 0:y.averagetargetduration)||v,T=void 0;T=p<=d?n*t:a*t;var S=c[p].maxBitrate,b=S*E/T;if(u.logger.trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: "+p+"/"+Math.round(T)+"/"+S+"/"+E+"/"+i+"/"+b),T>S&&(!b||f&&!this.bitrateTestDelay||b<i))return p}}return-1},e=t,(r=[{key:"nextAutoLevel",get:function(){var t=this._nextAutoLevel,e=this.bwEstimator;if(!(-1===t||e&&e.canEstimate()))return t;var r=this.getNextABRAutoLevel();return-1!==t&&(r=Math.min(t,r)),r},set:function(t){this._nextAutoLevel=t}}])&&d(e.prototype,r),c&&d(e,c),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.default=c},"./src/controller/audio-stream-controller.ts":
21
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../utils/ewma-bandwidth-estimator */"./src/utils/ewma-bandwidth-estimator.ts"),a=r(/*! ../events */"./src/events.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),o=r(/*! ../errors */"./src/errors.ts"),l=r(/*! ../types/loader */"./src/types/loader.ts"),u=r(/*! ../utils/logger */"./src/utils/logger.ts");function d(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var c=function(){function t(t){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=t;var e=t.config;this.bwEstimator=new n.default(e.abrEwmaSlowVoD,e.abrEwmaFastVoD,e.abrEwmaDefaultEstimate),this.registerListeners()}var e,r,c,h=t.prototype;return h.registerListeners=function(){var t=this.hls;t.on(a.Events.FRAG_LOADING,this.onFragLoading,this),t.on(a.Events.FRAG_LOADED,this.onFragLoaded,this),t.on(a.Events.FRAG_BUFFERED,this.onFragBuffered,this),t.on(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(a.Events.ERROR,this.onError,this)},h.unregisterListeners=function(){var t=this.hls;t.off(a.Events.FRAG_LOADING,this.onFragLoading,this),t.off(a.Events.FRAG_LOADED,this.onFragLoaded,this),t.off(a.Events.FRAG_BUFFERED,this.onFragBuffered,this),t.off(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(a.Events.ERROR,this.onError,this)},h.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this.onCheck=null,this.fragCurrent=this.partCurrent=null},h.onFragLoading=function(t,e){var r,i=e.frag;i.type===l.PlaylistLevelType.MAIN&&(this.timer||(this.fragCurrent=i,this.partCurrent=null!=(r=e.part)?r:null,this.timer=self.setInterval(this.onCheck,100)))},h.onLevelLoaded=function(t,e){var r=this.hls.config;e.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD)},h._abandonRulesCheck=function(){var t=this.fragCurrent,e=this.partCurrent,r=this.hls,n=r.autoLevelEnabled,o=r.config,l=r.media;if(t&&l){var d=e?e.stats:t.stats,c=e?e.duration:t.duration;if(d.aborted)return u.logger.warn("frag loader destroy or aborted, disarm abandonRules"),this.clearTimer(),void(this._nextAutoLevel=-1);if(n&&!l.paused&&l.playbackRate&&l.readyState){var h=performance.now()-d.loading.start,f=Math.abs(l.playbackRate);if(!(h<=500*c/f)){var g=r.levels,v=r.minAutoLevel,p=g[t.level],m=d.total||Math.max(d.loaded,Math.round(c*p.maxBitrate/8)),y=Math.max(1,d.bwEstimate?d.bwEstimate/8:1e3*d.loaded/h),E=(m-d.loaded)/y,T=l.currentTime,S=(s.BufferHelper.bufferInfo(l,T,o.maxBufferHole).end-T)/f;if(!(S>=2*c/f||E<=S)){var b,L=Number.POSITIVE_INFINITY;for(b=t.level-1;b>v&&!((L=c*g[b].maxBitrate/(6.4*y))<S);b--);if(!(L>=E)){var D=this.bwEstimator.getEstimate();u.logger.warn("Fragment "+t.sn+(e?" part "+e.index:"")+" of level "+t.level+" is loading too slowly and will cause an underbuffer; aborting and switching to level "+b+"\n Current BW estimate: "+(Object(i.isFiniteNumber)(D)?(D/1024).toFixed(3):"Unknown")+" Kb/s\n Estimated load time for current fragment: "+E.toFixed(3)+" s\n Estimated load time for the next fragment: "+L.toFixed(3)+" s\n Time to underbuffer: "+S.toFixed(3)+" s"),r.nextLoadLevel=b,this.bwEstimator.sample(h,d.loaded),this.clearTimer(),t.loader&&(this.fragCurrent=this.partCurrent=null,t.loader.abort()),r.trigger(a.Events.FRAG_LOAD_EMERGENCY_ABORTED,{frag:t,part:e,stats:d})}}}}}},h.onFragLoaded=function(t,e){var r=e.frag,n=e.part;if(r.type===l.PlaylistLevelType.MAIN&&Object(i.isFiniteNumber)(r.sn)){var s=n?n.stats:r.stats,o=n?n.duration:r.duration;if(this.clearTimer(),this.lastLoadedFragLevel=r.level,this._nextAutoLevel=-1,this.hls.config.abrMaxWithRealBitrate){var u=this.hls.levels[r.level],d=(u.loaded?u.loaded.bytes:0)+s.loaded,c=(u.loaded?u.loaded.duration:0)+o;u.loaded={bytes:d,duration:c},u.realBitrate=Math.round(8*d/c)}if(r.bitrateTest){var h={stats:s,frag:r,part:n,id:r.type};this.onFragBuffered(a.Events.FRAG_BUFFERED,h)}}},h.onFragBuffered=function(t,e){var r=e.frag,i=e.part,n=i?i.stats:r.stats;if(!n.aborted&&r.type===l.PlaylistLevelType.MAIN&&"initSegment"!==r.sn){var a=n.parsing.end-n.loading.start;this.bwEstimator.sample(a,n.loaded),n.bwEstimate=this.bwEstimator.getEstimate(),r.bitrateTest?this.bitrateTestDelay=a/1e3:this.bitrateTestDelay=0}},h.onError=function(t,e){switch(e.details){case o.ErrorDetails.FRAG_LOAD_ERROR:case o.ErrorDetails.FRAG_LOAD_TIMEOUT:this.clearTimer()}},h.clearTimer=function(){self.clearInterval(this.timer),this.timer=void 0},h.getNextABRAutoLevel=function(){var t=this.fragCurrent,e=this.partCurrent,r=this.hls,i=r.maxAutoLevel,n=r.config,a=r.minAutoLevel,o=r.media,l=e?e.duration:t?t.duration:0,d=o?o.currentTime:0,c=o&&0!==o.playbackRate?Math.abs(o.playbackRate):1,h=this.bwEstimator?this.bwEstimator.getEstimate():n.abrEwmaDefaultEstimate,f=(s.BufferHelper.bufferInfo(o,d,n.maxBufferHole).end-d)/c,g=this.findBestLevel(h,a,i,f,n.abrBandWidthFactor,n.abrBandWidthUpFactor);if(g>=0)return g;u.logger.trace((f?"rebuffering expected":"buffer is empty")+", finding optimal quality level");var v=l?Math.min(l,n.maxStarvationDelay):n.maxStarvationDelay,p=n.abrBandWidthFactor,m=n.abrBandWidthUpFactor;if(!f){var y=this.bitrateTestDelay;y&&(v=(l?Math.min(l,n.maxLoadingDelay):n.maxLoadingDelay)-y,u.logger.trace("bitrate test took "+Math.round(1e3*y)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*v)+" ms"),p=m=1)}return g=this.findBestLevel(h,a,i,f+v,p,m),Math.max(g,0)},h.findBestLevel=function(t,e,r,i,n,a){for(var s,o=this.fragCurrent,l=this.partCurrent,d=this.lastLoadedFragLevel,c=this.hls.levels,h=c[d],f=!(null==h||null===(s=h.details)||void 0===s||!s.live),g=null==h?void 0:h.codecSet,v=l?l.duration:o?o.duration:0,p=r;p>=e;p--){var m=c[p];if(m&&(!g||m.codecSet===g)){var y=m.details,E=(l?null==y?void 0:y.partTarget:null==y?void 0:y.averagetargetduration)||v,T=void 0;T=p<=d?n*t:a*t;var S=c[p].maxBitrate,b=S*E/T;if(u.logger.trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: "+p+"/"+Math.round(T)+"/"+S+"/"+E+"/"+i+"/"+b),T>S&&(!b||f&&!this.bitrateTestDelay||b<i))return p}}return-1},e=t,(r=[{key:"nextAutoLevel",get:function(){var t=this._nextAutoLevel,e=this.bwEstimator;if(-1!==t&&!e.canEstimate())return t;var r=this.getNextABRAutoLevel();return-1!==t&&this.hls.levels[r].loadError?t:(-1!==t&&(r=Math.min(t,r)),r)},set:function(t){this._nextAutoLevel=t}}])&&d(e.prototype,r),c&&d(e,c),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.default=c},"./src/controller/audio-stream-controller.ts":
22
22
  /*!***************************************************!*\
23
23
  !*** ./src/controller/audio-stream-controller.ts ***!
24
24
  \***************************************************/
25
- /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./base-stream-controller */"./src/controller/base-stream-controller.ts"),a=r(/*! ../events */"./src/events.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),o=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),l=r(/*! ../types/level */"./src/types/level.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),c=r(/*! ../demux/chunk-cache */"./src/demux/chunk-cache.ts"),h=r(/*! ../demux/transmuxer-interface */"./src/demux/transmuxer-interface.ts"),f=r(/*! ../types/transmuxer */"./src/types/transmuxer.ts"),g=r(/*! ./fragment-finders */"./src/controller/fragment-finders.ts"),v=r(/*! ../utils/discontinuities */"./src/utils/discontinuities.ts"),p=r(/*! ../errors */"./src/errors.ts"),m=r(/*! ../utils/logger */"./src/utils/logger.ts");function y(){return(y=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function E(t,e){return(E=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var T=function(t){var e,r;function T(e,r){var i;return(i=t.call(this,e,r,"[audio-stream-controller]")||this).videoBuffer=null,i.videoTrackCC=-1,i.waitingVideoCC=-1,i.audioSwitch=!1,i.trackId=-1,i.waitingData=null,i.mainDetails=null,i.bufferFlushed=!1,i.cachedTrackLoadedData=null,i._registerListeners(),i}r=t,(e=T).prototype=Object.create(r.prototype),e.prototype.constructor=e,E(e,r);var S=T.prototype;return S.onHandlerDestroying=function(){this._unregisterListeners(),this.mainDetails=null},S._registerListeners=function(){var t=this.hls;t.on(a.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(a.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(a.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(a.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),t.on(a.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.on(a.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.on(a.Events.ERROR,this.onError,this),t.on(a.Events.BUFFER_RESET,this.onBufferReset,this),t.on(a.Events.BUFFER_CREATED,this.onBufferCreated,this),t.on(a.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.on(a.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(a.Events.FRAG_BUFFERED,this.onFragBuffered,this)},S._unregisterListeners=function(){var t=this.hls;t.off(a.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(a.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(a.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(a.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),t.off(a.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.off(a.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.off(a.Events.ERROR,this.onError,this),t.off(a.Events.BUFFER_RESET,this.onBufferReset,this),t.off(a.Events.BUFFER_CREATED,this.onBufferCreated,this),t.off(a.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.off(a.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(a.Events.FRAG_BUFFERED,this.onFragBuffered,this)},S.onInitPtsFound=function(t,e){var r=e.frag,i=e.id,a=e.initPTS;if("main"===i){var s=r.cc;this.initPTS[r.cc]=a,this.log("InitPTS for cc: "+s+" found from main: "+a),this.videoTrackCC=s,this.state===n.State.WAITING_INIT_PTS&&this.tick()}},S.startLoad=function(t){if(!this.levels)return this.startPosition=t,void(this.state=n.State.STOPPED);var e=this.lastCurrentTime;this.stopLoad(),this.setInterval(100),this.fragLoadError=0,e>0&&-1===t?(this.log("Override startPosition with lastCurrentTime @"+e.toFixed(3)),this.state=n.State.IDLE):(this.loadedmetadata=!1,this.state=n.State.WAITING_TRACK),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()},S.doTick=function(){switch(this.state){case n.State.IDLE:this.doTickIdle();break;case n.State.WAITING_TRACK:var e,r=this.levels,i=this.trackId,a=null==r||null===(e=r[i])||void 0===e?void 0:e.details;if(a){if(this.waitForCdnTuneIn(a))break;this.state=n.State.WAITING_INIT_PTS}break;case n.State.FRAG_LOADING_WAITING_RETRY:var o,l=performance.now(),u=this.retryDate;(!u||l>=u||null!==(o=this.media)&&void 0!==o&&o.seeking)&&(this.log("RetryDate reached, switch back to IDLE state"),this.state=n.State.IDLE);break;case n.State.WAITING_INIT_PTS:var d=this.waitingData;if(d){var c=d.frag,h=d.part,f=d.cache,v=d.complete;if(void 0!==this.initPTS[c.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=n.State.FRAG_LOADING;var p={frag:c,part:h,payload:f.flush(),networkDetails:null};this._handleFragmentLoadProgress(p),v&&t.prototype._handleFragmentLoadComplete.call(this,p)}else if(this.videoTrackCC!==this.waitingVideoCC)m.logger.log("Waiting fragment cc ("+c.cc+") cancelled because video is at cc "+this.videoTrackCC),this.clearWaitingFragment();else{var y=this.getLoadPosition(),E=s.BufferHelper.bufferInfo(this.mediaBuffer,y,this.config.maxBufferHole);Object(g.fragmentWithinToleranceTest)(E.end,this.config.maxFragLookUpTolerance,c)<0&&(m.logger.log("Waiting fragment cc ("+c.cc+") @ "+c.start+" cancelled because another fragment at "+E.end+" is needed"),this.clearWaitingFragment())}}else this.state=n.State.IDLE}this.onTickEnd()},S.clearWaitingFragment=function(){var t=this.waitingData;t&&(this.fragmentTracker.removeFragment(t.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=n.State.IDLE)},S.onTickEnd=function(){var t=this.media;if(t&&t.readyState){var e=(this.mediaBuffer?this.mediaBuffer:t).buffered;!this.loadedmetadata&&e.length&&(this.loadedmetadata=!0),this.lastCurrentTime=t.currentTime}},S.doTickIdle=function(){var t,e,r=this.hls,i=this.levels,s=this.media,o=this.trackId,l=r.config;if(i&&i[o]&&(s||!this.startFragRequested&&l.startFragPrefetch)){var c=i[o].details;if(!c||c.live&&this.levelLastLoaded!==o||this.waitForCdnTuneIn(c))this.state=n.State.WAITING_TRACK;else{this.bufferFlushed&&(this.bufferFlushed=!1,this.afterBufferFlushed(this.mediaBuffer?this.mediaBuffer:this.media,d.ElementaryStreamTypes.AUDIO,u.PlaylistLevelType.AUDIO));var h=this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,u.PlaylistLevelType.AUDIO);if(null!==h){var f=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,u.PlaylistLevelType.MAIN),g=h.len,v=this.getMaxBufferLength(null==f?void 0:f.len),p=this.audioSwitch;if(!(g>=v)||p){if(!p&&this._streamEnded(h,c))return r.trigger(a.Events.BUFFER_EOS,{type:"audio"}),void(this.state=n.State.ENDED);var m=c.fragments[0].start,y=h.end;if(p){var E=this.getLoadPosition();y=E,c.PTSKnown&&E<m&&(h.end>m||h.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),s.currentTime=m+.05)}if(!(f&&y>f.end+c.targetduration)&&(f&&f.len||!h.len)){var T=this.getNextFragment(y,c);T?"identity"!==(null===(t=T.decryptdata)||void 0===t?void 0:t.keyFormat)||null!==(e=T.decryptdata)&&void 0!==e&&e.key?this.loadFragment(T,c,y):this.loadKey(T,c):this.bufferFlushed=!0}}}}}},S.getMaxBufferLength=function(e){var r=t.prototype.getMaxBufferLength.call(this);return e?Math.max(r,e):r},S.onMediaDetaching=function(){this.videoBuffer=null,t.prototype.onMediaDetaching.call(this)},S.onAudioTracksUpdated=function(t,e){var r=e.audioTracks;this.resetTransmuxer(),this.levels=r.map((function(t){return new l.Level(t)}))},S.onAudioTrackSwitching=function(t,e){var r=!!e.url;this.trackId=e.id;var i=this.fragCurrent;null!=i&&i.loader&&i.loader.abort(),this.fragCurrent=null,this.clearWaitingFragment(),r?this.setInterval(100):this.resetTransmuxer(),r?(this.audioSwitch=!0,this.state=n.State.IDLE):this.state=n.State.STOPPED,this.tick()},S.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=!1},S.onLevelLoaded=function(t,e){this.mainDetails=e.details,null!==this.cachedTrackLoadedData&&(this.hls.trigger(a.Events.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)},S.onAudioTrackLoaded=function(t,e){var r;if(null!=this.mainDetails){var i=this.levels,a=e.details,s=e.id;if(i){this.log("Track "+s+" loaded ["+a.startSN+","+a.endSN+"],duration:"+a.totalduration);var o=i[s],l=0;if(a.live||null!==(r=o.details)&&void 0!==r&&r.live){var u=this.mainDetails;if(a.fragments[0]||(a.deltaUpdateFailed=!0),a.deltaUpdateFailed||!u)return;!o.details&&a.hasProgramDateTime&&u.hasProgramDateTime?(Object(v.alignMediaPlaylistByPDT)(a,u),l=a.fragments[0].start):l=this.alignPlaylists(a,o.details)}o.details=a,this.levelLastLoaded=s,this.startFragRequested||!this.mainDetails&&a.live||this.setStartPosition(o.details,l),this.state!==n.State.WAITING_TRACK||this.waitForCdnTuneIn(a)||(this.state=n.State.IDLE),this.tick()}else this.warn("Audio tracks were reset while loading level "+s)}else this.cachedTrackLoadedData=e},S._handleFragmentLoadProgress=function(t){var e,r=t.frag,i=t.part,a=t.payload,s=this.config,o=this.trackId,l=this.levels;if(l){var d=l[o];console.assert(d,"Audio track is defined on fragment load progress");var g=d.details;console.assert(g,"Audio track details are defined on fragment load progress");var v=s.defaultAudioCodec||d.audioCodec||"mp4a.40.2",p=this.transmuxer;p||(p=this.transmuxer=new h.default(this.hls,u.PlaylistLevelType.AUDIO,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));var y=this.initPTS[r.cc],E=null===(e=r.initSegment)||void 0===e?void 0:e.data;if(void 0!==y){var T=i?i.index:-1,S=-1!==T,b=new f.ChunkMetadata(r.level,r.sn,r.stats.chunkCount,a.byteLength,T,S);p.push(a,E,v,"",r,i,g.totalduration,!1,b,y)}else m.logger.log("Unknown video PTS for cc "+r.cc+", waiting for video PTS before demuxing audio frag "+r.sn+" of ["+g.startSN+" ,"+g.endSN+"],track "+o),(this.waitingData=this.waitingData||{frag:r,part:i,cache:new c.default,complete:!1}).cache.push(new Uint8Array(a)),this.waitingVideoCC=this.videoTrackCC,this.state=n.State.WAITING_INIT_PTS}else this.warn("Audio tracks were reset while fragment load was in progress. Fragment "+r.sn+" of level "+r.level+" will not be buffered")},S._handleFragmentLoadComplete=function(e){this.waitingData?this.waitingData.complete=!0:t.prototype._handleFragmentLoadComplete.call(this,e)},S.onBufferReset=function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1},S.onBufferCreated=function(t,e){var r=e.tracks.audio;r&&(this.mediaBuffer=r.buffer),e.tracks.video&&(this.videoBuffer=e.tracks.video.buffer)},S.onFragBuffered=function(t,e){var r=e.frag,i=e.part;r.type===u.PlaylistLevelType.AUDIO&&(this.fragContextChanged(r)?this.warn("Fragment "+r.sn+(i?" p: "+i.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state+", audioSwitch: "+this.audioSwitch):("initSegment"!==r.sn&&(this.fragPrevious=r,this.audioSwitch&&(this.audioSwitch=!1,this.hls.trigger(a.Events.AUDIO_TRACK_SWITCHED,{id:this.trackId}))),this.fragBufferedComplete(r,i)))},S.onError=function(e,r){switch(r.details){case p.ErrorDetails.FRAG_LOAD_ERROR:case p.ErrorDetails.FRAG_LOAD_TIMEOUT:case p.ErrorDetails.KEY_LOAD_ERROR:case p.ErrorDetails.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(u.PlaylistLevelType.AUDIO,r);break;case p.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:case p.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:this.state!==n.State.ERROR&&this.state!==n.State.STOPPED&&(this.state=r.fatal?n.State.ERROR:n.State.IDLE,this.warn(r.details+" while loading frag, switching to "+this.state+" state"));break;case p.ErrorDetails.BUFFER_FULL_ERROR:if("audio"===r.parent&&(this.state===n.State.PARSING||this.state===n.State.PARSED)){var i=!0,a=this.getFwdBufferInfo(this.mediaBuffer,u.PlaylistLevelType.AUDIO);a&&a.len>.5&&(i=!this.reduceMaxBufferLength(a.len)),i&&(this.warn("Buffer full error also media.currentTime is not buffered, flush audio buffer"),this.fragCurrent=null,t.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.resetLoadingState()}}},S.onBufferFlushed=function(t,e){e.type===d.ElementaryStreamTypes.AUDIO&&(this.bufferFlushed=!0)},S._handleTransmuxComplete=function(t){var e,r="audio",i=this.hls,s=t.remuxResult,o=t.chunkMeta,l=this.getCurrentContext(o);if(!l)return this.warn("The loading context changed while buffering fragment "+o.sn+" of level "+o.level+". This chunk will not be buffered."),void this.resetLiveStartWhenNotLoaded(o.level);var u=l.frag,c=l.part,h=l.level.details,f=s.audio,g=s.text,v=s.id3,p=s.initSegment;if(!this.fragContextChanged(u)&&h){if(this.state=n.State.PARSING,this.audioSwitch&&f&&this.completeAudioSwitch(),null!=p&&p.tracks&&(this._bufferInitSegment(p.tracks,u,o),i.trigger(a.Events.FRAG_PARSING_INIT_SEGMENT,{frag:u,id:r,tracks:p.tracks})),f){var m=f.startPTS,E=f.endPTS,T=f.startDTS,S=f.endDTS;c&&(c.elementaryStreams[d.ElementaryStreamTypes.AUDIO]={startPTS:m,endPTS:E,startDTS:T,endDTS:S}),u.setElementaryStreamInfo(d.ElementaryStreamTypes.AUDIO,m,E,T,S),this.bufferFragmentData(f,u,c,o)}if(null!=v&&null!==(e=v.samples)&&void 0!==e&&e.length){var b=y({id:r,frag:u,details:h},v);i.trigger(a.Events.FRAG_PARSING_METADATA,b)}if(g){var L=y({id:r,frag:u,details:h},g);i.trigger(a.Events.FRAG_PARSING_USERDATA,L)}}},S._bufferInitSegment=function(t,e,r){if(this.state===n.State.PARSING){t.video&&delete t.video;var i=t.audio;if(i){i.levelCodec=i.codec,i.id="audio",this.log("Init audio buffer, container:"+i.container+", codecs[parsed]=["+i.codec+"]"),this.hls.trigger(a.Events.BUFFER_CODECS,t);var s=i.initSegment;if(null!=s&&s.byteLength){var o={type:"audio",frag:e,part:null,chunkMeta:r,parent:e.type,data:s};this.hls.trigger(a.Events.BUFFER_APPENDING,o)}this.tick()}}},S.loadFragment=function(e,r,a){var s=this.fragmentTracker.getState(e);this.fragCurrent=e,(this.audioSwitch||s===o.FragmentState.NOT_LOADED||s===o.FragmentState.PARTIAL)&&("initSegment"===e.sn?this._loadInitSegment(e):r.live&&!Object(i.isFiniteNumber)(this.initPTS[e.cc])?(this.log("Waiting for video PTS in continuity counter "+e.cc+" of live stream before loading audio fragment "+e.sn+" of level "+this.trackId),this.state=n.State.WAITING_INIT_PTS):(this.startFragRequested=!0,t.prototype.loadFragment.call(this,e,r,a)))},S.completeAudioSwitch=function(){var e=this.hls,r=this.media,i=this.trackId;r&&(this.log("Switching audio track : flushing all audio"),t.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.audioSwitch=!1,e.trigger(a.Events.AUDIO_TRACK_SWITCHED,{id:i})},T}(n.default);e.default=T},"./src/controller/audio-track-controller.ts":
25
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./base-stream-controller */"./src/controller/base-stream-controller.ts"),a=r(/*! ../events */"./src/events.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),o=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),l=r(/*! ../types/level */"./src/types/level.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),c=r(/*! ../demux/chunk-cache */"./src/demux/chunk-cache.ts"),h=r(/*! ../demux/transmuxer-interface */"./src/demux/transmuxer-interface.ts"),f=r(/*! ../types/transmuxer */"./src/types/transmuxer.ts"),g=r(/*! ./fragment-finders */"./src/controller/fragment-finders.ts"),v=r(/*! ../utils/discontinuities */"./src/utils/discontinuities.ts"),p=r(/*! ../errors */"./src/errors.ts");function m(){return(m=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function y(t,e){return(y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var E=function(t){var e,r;function E(e,r){var i;return(i=t.call(this,e,r,"[audio-stream-controller]")||this).videoBuffer=null,i.videoTrackCC=-1,i.waitingVideoCC=-1,i.audioSwitch=!1,i.trackId=-1,i.waitingData=null,i.mainDetails=null,i.bufferFlushed=!1,i.cachedTrackLoadedData=null,i._registerListeners(),i}r=t,(e=E).prototype=Object.create(r.prototype),e.prototype.constructor=e,y(e,r);var T=E.prototype;return T.onHandlerDestroying=function(){this._unregisterListeners(),this.mainDetails=null},T._registerListeners=function(){var t=this.hls;t.on(a.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(a.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(a.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(a.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),t.on(a.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.on(a.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.on(a.Events.ERROR,this.onError,this),t.on(a.Events.BUFFER_RESET,this.onBufferReset,this),t.on(a.Events.BUFFER_CREATED,this.onBufferCreated,this),t.on(a.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.on(a.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(a.Events.FRAG_BUFFERED,this.onFragBuffered,this)},T._unregisterListeners=function(){var t=this.hls;t.off(a.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(a.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(a.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(a.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(a.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),t.off(a.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.off(a.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.off(a.Events.ERROR,this.onError,this),t.off(a.Events.BUFFER_RESET,this.onBufferReset,this),t.off(a.Events.BUFFER_CREATED,this.onBufferCreated,this),t.off(a.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.off(a.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(a.Events.FRAG_BUFFERED,this.onFragBuffered,this)},T.onInitPtsFound=function(t,e){var r=e.frag,i=e.id,a=e.initPTS;if("main"===i){var s=r.cc;this.initPTS[r.cc]=a,this.log("InitPTS for cc: "+s+" found from main: "+a),this.videoTrackCC=s,this.state===n.State.WAITING_INIT_PTS&&this.tick()}},T.startLoad=function(t){if(!this.levels)return this.startPosition=t,void(this.state=n.State.STOPPED);var e=this.lastCurrentTime;this.stopLoad(),this.setInterval(100),this.fragLoadError=0,e>0&&-1===t?(this.log("Override startPosition with lastCurrentTime @"+e.toFixed(3)),t=e,this.state=n.State.IDLE):(this.loadedmetadata=!1,this.state=n.State.WAITING_TRACK),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()},T.doTick=function(){switch(this.state){case n.State.IDLE:this.doTickIdle();break;case n.State.WAITING_TRACK:var e,r=this.levels,i=this.trackId,a=null==r||null===(e=r[i])||void 0===e?void 0:e.details;if(a){if(this.waitForCdnTuneIn(a))break;this.state=n.State.WAITING_INIT_PTS}break;case n.State.FRAG_LOADING_WAITING_RETRY:var o,l=performance.now(),u=this.retryDate;(!u||l>=u||null!==(o=this.media)&&void 0!==o&&o.seeking)&&(this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded(this.trackId),this.state=n.State.IDLE);break;case n.State.WAITING_INIT_PTS:var d=this.waitingData;if(d){var c=d.frag,h=d.part,f=d.cache,v=d.complete;if(void 0!==this.initPTS[c.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=n.State.FRAG_LOADING;var p={frag:c,part:h,payload:f.flush(),networkDetails:null};this._handleFragmentLoadProgress(p),v&&t.prototype._handleFragmentLoadComplete.call(this,p)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log("Waiting fragment cc ("+c.cc+") cancelled because video is at cc "+this.videoTrackCC),this.clearWaitingFragment();else{var m=this.getLoadPosition(),y=s.BufferHelper.bufferInfo(this.mediaBuffer,m,this.config.maxBufferHole);Object(g.fragmentWithinToleranceTest)(y.end,this.config.maxFragLookUpTolerance,c)<0&&(this.log("Waiting fragment cc ("+c.cc+") @ "+c.start+" cancelled because another fragment at "+y.end+" is needed"),this.clearWaitingFragment())}}else this.state=n.State.IDLE}this.onTickEnd()},T.clearWaitingFragment=function(){var t=this.waitingData;t&&(this.fragmentTracker.removeFragment(t.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=n.State.IDLE)},T.resetLoadingState=function(){this.clearWaitingFragment(),t.prototype.resetLoadingState.call(this)},T.onTickEnd=function(){var t=this.media;if(t&&t.readyState){var e=(this.mediaBuffer?this.mediaBuffer:t).buffered;!this.loadedmetadata&&e.length&&(this.loadedmetadata=!0),this.lastCurrentTime=t.currentTime}},T.doTickIdle=function(){var t,e,r=this.hls,i=this.levels,s=this.media,o=this.trackId,l=r.config;if(i&&i[o]&&(s||!this.startFragRequested&&l.startFragPrefetch)){var c=i[o].details;if(!c||c.live&&this.levelLastLoaded!==o||this.waitForCdnTuneIn(c))this.state=n.State.WAITING_TRACK;else{var h=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&h&&(this.bufferFlushed=!1,this.afterBufferFlushed(h,d.ElementaryStreamTypes.AUDIO,u.PlaylistLevelType.AUDIO));var f=this.getFwdBufferInfo(h,u.PlaylistLevelType.AUDIO);if(null!==f){var g=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,u.PlaylistLevelType.MAIN),v=f.len,p=this.getMaxBufferLength(null==g?void 0:g.len),m=this.audioSwitch;if(!(v>=p)||m){if(!m&&this._streamEnded(f,c))return r.trigger(a.Events.BUFFER_EOS,{type:"audio"}),void(this.state=n.State.ENDED);var y=c.fragments[0].start,E=f.end;if(m&&s){var T=this.getLoadPosition();E=T,c.PTSKnown&&T<y&&(f.end>y||f.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),s.currentTime=y+.05)}if(!(g&&E>g.end+c.targetduration)&&(g&&g.len||!f.len)){var S=this.getNextFragment(E,c);S?"identity"!==(null===(t=S.decryptdata)||void 0===t?void 0:t.keyFormat)||null!==(e=S.decryptdata)&&void 0!==e&&e.key?this.loadFragment(S,c,E):this.loadKey(S,c):this.bufferFlushed=!0}}}}}},T.getMaxBufferLength=function(e){var r=t.prototype.getMaxBufferLength.call(this);return e?Math.max(r,e):r},T.onMediaDetaching=function(){this.videoBuffer=null,t.prototype.onMediaDetaching.call(this)},T.onAudioTracksUpdated=function(t,e){var r=e.audioTracks;this.resetTransmuxer(),this.levels=r.map((function(t){return new l.Level(t)}))},T.onAudioTrackSwitching=function(t,e){var r=!!e.url;this.trackId=e.id;var i=this.fragCurrent;null!=i&&i.loader&&i.loader.abort(),this.fragCurrent=null,this.clearWaitingFragment(),r?this.setInterval(100):this.resetTransmuxer(),r?(this.audioSwitch=!0,this.state=n.State.IDLE):this.state=n.State.STOPPED,this.tick()},T.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=!1},T.onLevelLoaded=function(t,e){this.mainDetails=e.details,null!==this.cachedTrackLoadedData&&(this.hls.trigger(a.Events.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)},T.onAudioTrackLoaded=function(t,e){var r;if(null!=this.mainDetails){var i=this.levels,a=e.details,s=e.id;if(i){this.log("Track "+s+" loaded ["+a.startSN+","+a.endSN+"],duration:"+a.totalduration);var o=i[s],l=0;if(a.live||null!==(r=o.details)&&void 0!==r&&r.live){var u=this.mainDetails;if(a.fragments[0]||(a.deltaUpdateFailed=!0),a.deltaUpdateFailed||!u)return;!o.details&&a.hasProgramDateTime&&u.hasProgramDateTime?(Object(v.alignMediaPlaylistByPDT)(a,u),l=a.fragments[0].start):l=this.alignPlaylists(a,o.details)}o.details=a,this.levelLastLoaded=s,this.startFragRequested||!this.mainDetails&&a.live||this.setStartPosition(o.details,l),this.state!==n.State.WAITING_TRACK||this.waitForCdnTuneIn(a)||(this.state=n.State.IDLE),this.tick()}else this.warn("Audio tracks were reset while loading level "+s)}else this.cachedTrackLoadedData=e},T._handleFragmentLoadProgress=function(t){var e,r=t.frag,i=t.part,a=t.payload,s=this.config,o=this.trackId,l=this.levels;if(l){var d=l[o];console.assert(d,"Audio track is defined on fragment load progress");var g=d.details;console.assert(g,"Audio track details are defined on fragment load progress");var v=s.defaultAudioCodec||d.audioCodec||"mp4a.40.2",p=this.transmuxer;p||(p=this.transmuxer=new h.default(this.hls,u.PlaylistLevelType.AUDIO,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));var m=this.initPTS[r.cc],y=null===(e=r.initSegment)||void 0===e?void 0:e.data;if(void 0!==m){var E=i?i.index:-1,T=-1!==E,S=new f.ChunkMetadata(r.level,r.sn,r.stats.chunkCount,a.byteLength,E,T);p.push(a,y,v,"",r,i,g.totalduration,!1,S,m)}else this.log("Unknown video PTS for cc "+r.cc+", waiting for video PTS before demuxing audio frag "+r.sn+" of ["+g.startSN+" ,"+g.endSN+"],track "+o),(this.waitingData=this.waitingData||{frag:r,part:i,cache:new c.default,complete:!1}).cache.push(new Uint8Array(a)),this.waitingVideoCC=this.videoTrackCC,this.state=n.State.WAITING_INIT_PTS}else this.warn("Audio tracks were reset while fragment load was in progress. Fragment "+r.sn+" of level "+r.level+" will not be buffered")},T._handleFragmentLoadComplete=function(e){this.waitingData?this.waitingData.complete=!0:t.prototype._handleFragmentLoadComplete.call(this,e)},T.onBufferReset=function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1},T.onBufferCreated=function(t,e){var r=e.tracks.audio;r&&(this.mediaBuffer=r.buffer||null),e.tracks.video&&(this.videoBuffer=e.tracks.video.buffer||null)},T.onFragBuffered=function(t,e){var r=e.frag,i=e.part;r.type===u.PlaylistLevelType.AUDIO&&(this.fragContextChanged(r)?this.warn("Fragment "+r.sn+(i?" p: "+i.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state+", audioSwitch: "+this.audioSwitch):("initSegment"!==r.sn&&(this.fragPrevious=r,this.audioSwitch&&(this.audioSwitch=!1,this.hls.trigger(a.Events.AUDIO_TRACK_SWITCHED,{id:this.trackId}))),this.fragBufferedComplete(r,i)))},T.onError=function(e,r){switch(r.details){case p.ErrorDetails.FRAG_LOAD_ERROR:case p.ErrorDetails.FRAG_LOAD_TIMEOUT:case p.ErrorDetails.KEY_LOAD_ERROR:case p.ErrorDetails.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(u.PlaylistLevelType.AUDIO,r);break;case p.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:case p.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:this.state!==n.State.ERROR&&this.state!==n.State.STOPPED&&(this.state=r.fatal?n.State.ERROR:n.State.IDLE,this.warn(r.details+" while loading frag, switching to "+this.state+" state"));break;case p.ErrorDetails.BUFFER_FULL_ERROR:if("audio"===r.parent&&(this.state===n.State.PARSING||this.state===n.State.PARSED)){var i=!0,a=this.getFwdBufferInfo(this.mediaBuffer,u.PlaylistLevelType.AUDIO);a&&a.len>.5&&(i=!this.reduceMaxBufferLength(a.len)),i&&(this.warn("Buffer full error also media.currentTime is not buffered, flush audio buffer"),this.fragCurrent=null,t.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.resetLoadingState()}}},T.onBufferFlushed=function(t,e){e.type===d.ElementaryStreamTypes.AUDIO&&(this.bufferFlushed=!0)},T._handleTransmuxComplete=function(t){var e,r="audio",i=this.hls,s=t.remuxResult,o=t.chunkMeta,l=this.getCurrentContext(o);if(!l)return this.warn("The loading context changed while buffering fragment "+o.sn+" of level "+o.level+". This chunk will not be buffered."),void this.resetStartWhenNotLoaded(o.level);var u=l.frag,c=l.part,h=l.level.details,f=s.audio,g=s.text,v=s.id3,p=s.initSegment;if(!this.fragContextChanged(u)&&h){if(this.state=n.State.PARSING,this.audioSwitch&&f&&this.completeAudioSwitch(),null!=p&&p.tracks&&(this._bufferInitSegment(p.tracks,u,o),i.trigger(a.Events.FRAG_PARSING_INIT_SEGMENT,{frag:u,id:r,tracks:p.tracks})),f){var y=f.startPTS,E=f.endPTS,T=f.startDTS,S=f.endDTS;c&&(c.elementaryStreams[d.ElementaryStreamTypes.AUDIO]={startPTS:y,endPTS:E,startDTS:T,endDTS:S}),u.setElementaryStreamInfo(d.ElementaryStreamTypes.AUDIO,y,E,T,S),this.bufferFragmentData(f,u,c,o)}if(null!=v&&null!==(e=v.samples)&&void 0!==e&&e.length){var b=m({id:r,frag:u,details:h},v);i.trigger(a.Events.FRAG_PARSING_METADATA,b)}if(g){var L=m({id:r,frag:u,details:h},g);i.trigger(a.Events.FRAG_PARSING_USERDATA,L)}}},T._bufferInitSegment=function(t,e,r){if(this.state===n.State.PARSING){t.video&&delete t.video;var i=t.audio;if(i){i.levelCodec=i.codec,i.id="audio",this.log("Init audio buffer, container:"+i.container+", codecs[parsed]=["+i.codec+"]"),this.hls.trigger(a.Events.BUFFER_CODECS,t);var s=i.initSegment;if(null!=s&&s.byteLength){var o={type:"audio",frag:e,part:null,chunkMeta:r,parent:e.type,data:s};this.hls.trigger(a.Events.BUFFER_APPENDING,o)}this.tick()}}},T.loadFragment=function(e,r,a){var s=this.fragmentTracker.getState(e);this.fragCurrent=e,(this.audioSwitch||s===o.FragmentState.NOT_LOADED||s===o.FragmentState.PARTIAL)&&("initSegment"===e.sn?this._loadInitSegment(e):r.live&&!Object(i.isFiniteNumber)(this.initPTS[e.cc])?(this.log("Waiting for video PTS in continuity counter "+e.cc+" of live stream before loading audio fragment "+e.sn+" of level "+this.trackId),this.state=n.State.WAITING_INIT_PTS):(this.startFragRequested=!0,t.prototype.loadFragment.call(this,e,r,a)))},T.completeAudioSwitch=function(){var e=this.hls,r=this.media,i=this.trackId;r&&(this.log("Switching audio track : flushing all audio"),t.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.audioSwitch=!1,e.trigger(a.Events.AUDIO_TRACK_SWITCHED,{id:i})},E}(n.default);e.default=E},"./src/controller/audio-track-controller.ts":
26
26
  /*!**************************************************!*\
27
27
  !*** ./src/controller/audio-track-controller.ts ***!
28
28
  \**************************************************/
@@ -34,11 +34,11 @@
34
34
  /*!**************************************************!*\
35
35
  !*** ./src/controller/base-stream-controller.ts ***!
36
36
  \**************************************************/
37
- /*! exports provided: State, default */function(t,e,r){r.r(e),r.d(e,"State",(function(){return S})),r.d(e,"default",(function(){return b}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../task-loop */"./src/task-loop.ts"),a=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),o=r(/*! ../utils/logger */"./src/utils/logger.ts"),l=r(/*! ../events */"./src/events.ts"),u=r(/*! ../errors */"./src/errors.ts"),d=r(/*! ../types/transmuxer */"./src/types/transmuxer.ts"),c=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),h=r(/*! ../utils/discontinuities */"./src/utils/discontinuities.ts"),f=r(/*! ./fragment-finders */"./src/controller/fragment-finders.ts"),g=r(/*! ./level-helper */"./src/controller/level-helper.ts"),v=r(/*! ../loader/fragment-loader */"./src/loader/fragment-loader.ts"),p=r(/*! ../crypt/decrypter */"./src/crypt/decrypter.ts"),m=r(/*! ../utils/time-ranges */"./src/utils/time-ranges.ts"),y=r(/*! ../types/loader */"./src/types/loader.ts");function E(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function T(t,e){return(T=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var S={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"},b=function(t){var e,r;function n(e,r,i){var n;return(n=t.call(this)||this).hls=void 0,n.fragPrevious=null,n.fragCurrent=null,n.fragmentTracker=void 0,n.transmuxer=null,n._state=S.STOPPED,n.media=void 0,n.mediaBuffer=void 0,n.config=void 0,n.bitrateTest=!1,n.lastCurrentTime=0,n.nextLoadPosition=0,n.startPosition=0,n.loadedmetadata=!1,n.fragLoadError=0,n.retryDate=0,n.levels=null,n.fragmentLoader=void 0,n.levelLastLoaded=null,n.startFragRequested=!1,n.decrypter=void 0,n.initPTS=[],n.onvseeking=null,n.onvended=null,n.logPrefix="",n.log=void 0,n.warn=void 0,n.logPrefix=i,n.log=o.logger.log.bind(o.logger,i+":"),n.warn=o.logger.warn.bind(o.logger,i+":"),n.hls=e,n.fragmentLoader=new v.default(e.config),n.fragmentTracker=r,n.config=e.config,n.decrypter=new p.default(e,e.config),e.on(l.Events.KEY_LOADED,n.onKeyLoaded,function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n)),n}r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,T(e,r);var b,L,D,A=n.prototype;return A.doTick=function(){this.onTickEnd()},A.onTickEnd=function(){},A.startLoad=function(t){},A.stopLoad=function(){this.fragmentLoader.abort();var t=this.fragCurrent;t&&this.fragmentTracker.removeFragment(t),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=S.STOPPED},A._streamEnded=function(t,e){var r=this.fragCurrent,i=this.fragmentTracker;if(!e.live&&r&&r.sn>=e.endSN&&!t.nextStart){var n=e.partList;if(null!=n&&n.length){var o=n[n.length-1];return s.BufferHelper.isBuffered(this.media,o.start+o.duration/2)}var l=i.getState(r);return l===a.FragmentState.PARTIAL||l===a.FragmentState.OK}return!1},A.onMediaAttached=function(t,e){var r=this.media=this.mediaBuffer=e.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),r.addEventListener("seeking",this.onvseeking),r.addEventListener("ended",this.onvended);var i=this.config;this.levels&&i.autoStartLoad&&this.state===S.STOPPED&&this.startLoad(i.startPosition)},A.onMediaDetaching=function(){var t=this.media;null!=t&&t.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),t&&(t.removeEventListener("seeking",this.onvseeking),t.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()},A.onMediaSeeking=function(){var t=this.config,e=this.fragCurrent,r=this.media,n=this.mediaBuffer,a=this.state,o=r?r.currentTime:0,l=s.BufferHelper.bufferInfo(n||r,o,t.maxBufferHole);if(this.log("media seeking to "+(Object(i.isFiniteNumber)(o)?o.toFixed(3):o)+", state: "+a),a===S.ENDED)this.resetLoadingState();else if(e&&!l.len){var u=t.maxFragLookUpTolerance,d=e.start-u,c=o>e.start+e.duration+u;(o<d||c)&&(c&&e.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),e.loader.abort()),this.resetLoadingState())}r&&(this.lastCurrentTime=o),this.loadedmetadata||l.len||(this.nextLoadPosition=this.startPosition=o),this.tickImmediate()},A.onMediaEnded=function(){this.startPosition=this.lastCurrentTime=0},A.onKeyLoaded=function(t,e){if(this.state===S.KEY_LOADING&&e.frag===this.fragCurrent&&this.levels){this.state=S.IDLE;var r=this.levels[e.frag.level].details;r&&this.loadFragment(e.frag,r,e.frag.start)}},A.onHandlerDestroying=function(){this.stopLoad(),t.prototype.onHandlerDestroying.call(this)},A.onHandlerDestroyed=function(){this.state=S.STOPPED,this.hls.off(l.Events.KEY_LOADED,this.onKeyLoaded,this),this.fragmentLoader&&this.fragmentLoader.destroy(),this.decrypter&&this.decrypter.destroy(),this.hls=this.log=this.warn=this.decrypter=this.fragmentLoader=this.fragmentTracker=null,t.prototype.onHandlerDestroyed.call(this)},A.loadKey=function(t,e){this.log("Loading key for "+t.sn+" of ["+e.startSN+"-"+e.endSN+"], "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+t.level),this.state=S.KEY_LOADING,this.fragCurrent=t,this.hls.trigger(l.Events.KEY_LOADING,{frag:t})},A.loadFragment=function(t,e,r){this._loadFragForPlayback(t,e,r)},A._loadFragForPlayback=function(t,e,r){var i=this;this._doFragLoad(t,e,r,(function(e){if(i.fragContextChanged(t))return i.warn("Fragment "+t.sn+(e.part?" p: "+e.part.index:"")+" of level "+t.level+" was dropped during download."),void i.fragmentTracker.removeFragment(t);t.stats.chunkCount++,i._handleFragmentLoadProgress(e)})).then((function(e){if(e){i.fragLoadError=0;var r=i.state;i.fragContextChanged(t)?(r===S.FRAG_LOADING||!i.fragCurrent&&r===S.PARSING)&&(i.fragmentTracker.removeFragment(t),i.state=S.IDLE):("payload"in e&&(i.log("Loaded fragment "+t.sn+" of level "+t.level),i.hls.trigger(l.Events.FRAG_LOADED,e)),i._handleFragmentLoadComplete(e))}})).catch((function(e){i.state!==S.STOPPED&&(i.warn(e),i.resetFragmentLoading(t))}))},A.flushMainBuffer=function(t,e,r){if(void 0===r&&(r=null),t-e){var i={startOffset:t,endOffset:e,type:r};this.fragLoadError=0,this.hls.trigger(l.Events.BUFFER_FLUSHING,i)}},A._loadInitSegment=function(t){var e=this;this._doFragLoad(t).then((function(r){if(!r||e.fragContextChanged(t)||!e.levels)throw new Error("init load aborted");return r})).then((function(r){var i=e.hls,n=r.payload,a=t.decryptdata;if(n&&n.byteLength>0&&a&&a.key&&a.iv&&"AES-128"===a.method){var s=self.performance.now();return e.decrypter.webCryptoDecrypt(new Uint8Array(n),a.key.buffer,a.iv.buffer).then((function(e){var n=self.performance.now();return i.trigger(l.Events.FRAG_DECRYPTED,{frag:t,payload:e,stats:{tstart:s,tdecrypt:n}}),r.payload=e,r}))}return r})).then((function(r){var i=e.fragCurrent,n=e.hls,a=e.levels;if(!a)throw new Error("init load aborted, missing levels");var s=a[t.level].details;console.assert(s,"Level details are defined when init segment is loaded");var o=t.stats;e.state=S.IDLE,e.fragLoadError=0,t.data=new Uint8Array(r.payload),o.parsing.start=o.buffering.start=self.performance.now(),o.parsing.end=o.buffering.end=self.performance.now(),r.frag===i&&n.trigger(l.Events.FRAG_BUFFERED,{stats:o,frag:i,part:null,id:t.type}),e.tick()})).catch((function(r){e.warn(r),e.resetFragmentLoading(t)}))},A.fragContextChanged=function(t){var e=this.fragCurrent;return!t||!e||t.level!==e.level||t.sn!==e.sn||t.urlId!==e.urlId},A.fragBufferedComplete=function(t,e){var r=this.mediaBuffer?this.mediaBuffer:this.media;this.log("Buffered "+t.type+" sn: "+t.sn+(e?" part: "+e.index:"")+" of "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+t.level+" "+m.default.toString(s.BufferHelper.getBuffered(r))),this.state=S.IDLE,this.tick()},A._handleFragmentLoadComplete=function(t){var e=this.transmuxer;if(e){var r=t.frag,i=t.part,n=t.partsLoaded,a=!n||0===n.length||n.some((function(t){return!t})),s=new d.ChunkMetadata(r.level,r.sn,r.stats.chunkCount+1,0,i?i.index:-1,!a);e.flush(s)}},A._handleFragmentLoadProgress=function(t){},A._doFragLoad=function(t,e,r,n){var a=this;if(void 0===r&&(r=null),!this.levels)throw new Error("frag load aborted, missing levels");if(r=Math.max(t.start,r||0),this.config.lowLatencyMode&&e){var s=e.partList;if(s&&n){r>t.end&&e.fragmentHint&&(t=e.fragmentHint);var o=this.getNextPart(s,t,r);if(o>-1){var u=s[o];return this.log("Loading part sn: "+t.sn+" p: "+u.index+" cc: "+t.cc+" of playlist ["+e.startSN+"-"+e.endSN+"] parts [0-"+o+"-"+(s.length-1)+"] "+("[stream-controller]"===this.logPrefix?"level":"track")+": "+t.level+", target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=u.start+u.duration,this.state=S.FRAG_LOADING,this.hls.trigger(l.Events.FRAG_LOADING,{frag:t,part:s[o],targetBufferTime:r}),this.doFragPartsLoad(t,s,o,n).catch((function(t){return a.handleFragLoadError(t)}))}if(!t.url||this.loadedEndOfParts(s,r))return Promise.resolve(null)}}return this.log("Loading fragment "+t.sn+" cc: "+t.cc+" "+(e?"of ["+e.startSN+"-"+e.endSN+"] ":"")+("[stream-controller]"===this.logPrefix?"level":"track")+": "+t.level+", target: "+parseFloat(r.toFixed(3))),Object(i.isFiniteNumber)(t.sn)&&!this.bitrateTest&&(this.nextLoadPosition=t.start+t.duration),this.state=S.FRAG_LOADING,this.hls.trigger(l.Events.FRAG_LOADING,{frag:t,targetBufferTime:r}),this.fragmentLoader.load(t,n).catch((function(t){return a.handleFragLoadError(t)}))},A.doFragPartsLoad=function(t,e,r,i){var n=this;return new Promise((function(a,s){var o=[];!function r(u){var d=e[u];n.fragmentLoader.loadPart(t,d,i).then((function(i){o[d.index]=i;var s=i.part;n.hls.trigger(l.Events.FRAG_LOADED,i);var c=e[u+1];if(!c||c.fragment!==t)return a({frag:t,part:s,partsLoaded:o});r(u+1)})).catch(s)}(r)}))},A.handleFragLoadError=function(t){var e=t.data;return e&&e.details===u.ErrorDetails.INTERNAL_ABORTED?this.handleFragLoadAborted(e.frag,e.part):this.hls.trigger(l.Events.ERROR,e),null},A._handleTransmuxerFlush=function(t){var e=this.getCurrentContext(t);if(e&&this.state===S.PARSING){var r=e.frag,i=e.part,n=e.level,a=self.performance.now();r.stats.parsing.end=a,i&&(i.stats.parsing.end=a),this.updateLevelTiming(r,i,n,t.partial)}else this.fragCurrent||(this.state=S.IDLE)},A.getCurrentContext=function(t){var e=this.levels,r=t.level,i=t.sn,n=t.part;if(!e||!e[r])return this.warn("Levels object was unset while buffering fragment "+i+" of level "+r+". The current chunk will not be buffered."),null;var a=e[r],s=n>-1?Object(g.getPartWith)(a,i,n):null,o=s?s.fragment:Object(g.getFragmentWithSN)(a,i,this.fragCurrent);return o?{frag:o,part:s,level:a}:null},A.bufferFragmentData=function(t,e,r,i){if(t&&this.state===S.PARSING){var n=t.data1,a=t.data2,s=n;if(n&&a&&(s=Object(c.appendUint8Array)(n,a)),s&&s.length){var o={type:t.type,frag:e,part:r,chunkMeta:i,parent:e.type,data:s};this.hls.trigger(l.Events.BUFFER_APPENDING,o),t.dropped&&t.independent&&!r&&this.flushBufferGap(e)}}},A.flushBufferGap=function(t){var e=this.media;if(e)if(s.BufferHelper.isBuffered(e,e.currentTime)){var r=e.currentTime,i=s.BufferHelper.bufferInfo(e,r,0),n=t.duration,a=Math.min(2*this.config.maxFragLookUpTolerance,.25*n),o=Math.max(Math.min(t.start-a,i.end-a),r+a);t.start-o>a&&this.flushMainBuffer(o,t.start)}else this.flushMainBuffer(0,t.start)},A.getFwdBufferInfo=function(t,e){var r=this.config,n=this.getLoadPosition();if(!Object(i.isFiniteNumber)(n))return null;var a=s.BufferHelper.bufferInfo(t,n,r.maxBufferHole);if(0===a.len&&void 0!==a.nextStart){var o=this.fragmentTracker.getBufferedFrag(n,e);if(o&&a.nextStart<o.end)return s.BufferHelper.bufferInfo(t,n,Math.max(a.nextStart,r.maxBufferHole))}return a},A.getMaxBufferLength=function(t){var e,r=this.config;return e=t?Math.max(8*r.maxBufferSize/t,r.maxBufferLength):r.maxBufferLength,Math.min(e,r.maxMaxBufferLength)},A.reduceMaxBufferLength=function(t){var e=this.config,r=t||e.maxBufferLength;return e.maxMaxBufferLength>=r&&(e.maxMaxBufferLength/=2,this.warn("Reduce max buffer length to "+e.maxMaxBufferLength+"s"),!0)},A.getNextFragment=function(t,e){var r,i,n=e.fragments,a=n.length;if(!a)return null;var s,o=this.config,l=n[0].start;if(e.live){var u=o.initialLiveManifestSize;if(a<u)return this.warn("Not enough fragments to start playback (have: "+a+", need: "+u+")"),null;e.PTSKnown||this.startFragRequested||-1!==this.startPosition||(s=this.getInitialLiveFragment(e,n),this.startPosition=s?this.hls.liveSyncPosition||s.start:t)}else t<=l&&(s=n[0]);if(!s){var d=o.lowLatencyMode?e.partEnd:e.fragmentEnd;s=this.getFragmentAtPosition(t,d,e)}return null===(r=s)||void 0===r||!r.initSegment||null!==(i=s)&&void 0!==i&&i.initSegment.data||this.bitrateTest||(s=s.initSegment),s},A.getNextPart=function(t,e,r){for(var i=-1,n=!1,a=!0,s=0,o=t.length;s<o;s++){var l=t[s];if(a=a&&!l.independent,i>-1&&r<l.start)break;var u=l.loaded;!u&&(n||l.independent||a)&&l.fragment===e&&(i=s),n=u}return i},A.loadedEndOfParts=function(t,e){var r=t[t.length-1];return r&&e>r.start&&r.loaded},A.getInitialLiveFragment=function(t,e){var r=this.fragPrevious,i=null;if(r){if(t.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: "+r.programDateTime),i=Object(f.findFragmentByPDT)(e,r.endProgramDateTime,this.config.maxFragLookUpTolerance)),!i){var n=r.sn+1;if(n>=t.startSN&&n<=t.endSN){var a=e[n-t.startSN];r.cc===a.cc&&(i=a,this.log("Live playlist, switching playlist, load frag with next SN: "+i.sn))}i||(i=Object(f.findFragWithCC)(e,r.cc))&&this.log("Live playlist, switching playlist, load frag with same CC: "+i.sn)}}else{var s=this.hls.liveSyncPosition;null!==s&&(i=this.getFragmentAtPosition(s,this.bitrateTest?t.fragmentEnd:t.edge,t))}return i},A.getFragmentAtPosition=function(t,e,r){var i,n=this.config,s=this.fragPrevious,o=r.fragments,l=r.endSN,u=r.fragmentHint,d=n.maxFragLookUpTolerance,c=!!(n.lowLatencyMode&&r.partList&&u);if(c&&u&&!this.bitrateTest&&(o=o.concat(u),l=u.sn),t<e){var h=t>e-d?0:d;i=Object(f.findFragmentByPTS)(s,o,t,h)}else i=o[o.length-1];if(i){var g=i.sn-r.startSN,v=s&&i.level===s.level,p=o[g+1];s&&i.sn===s.sn&&!c&&v&&(i.sn<l&&this.fragmentTracker.getState(p)!==a.FragmentState.OK?(this.log("SN "+i.sn+" just loaded, load next one: "+p.sn),i=p):i=null)}return i},A.synchronizeToLiveEdge=function(t){var e=this.config,r=this.media;if(r){var i=this.hls.liveSyncPosition,n=r.currentTime,a=t.fragments[0].start,s=t.edge,o=n>=a-e.maxFragLookUpTolerance&&n<=s;if(null!==i&&r.duration>i&&(n<i||!o)){var l=void 0!==e.liveMaxLatencyDuration?e.liveMaxLatencyDuration:e.liveMaxLatencyDurationCount*t.targetduration;(!o&&r.readyState<4||n<s-l)&&(this.loadedmetadata||(this.nextLoadPosition=i),r.readyState&&(this.warn("Playback: "+n.toFixed(3)+" is located too far from the end of live sliding playlist: "+s+", reset currentTime to : "+i.toFixed(3)),r.currentTime=i))}}},A.alignPlaylists=function(t,e){var r=this.levels,n=this.levelLastLoaded,a=this.fragPrevious,s=null!==n?r[n]:null,o=t.fragments.length;if(!o)return this.warn("No fragments in live playlist"),0;var l=t.fragments[0].start,u=!e,d=t.alignedSliding&&Object(i.isFiniteNumber)(l);if(u||!d&&!l){Object(h.alignStream)(a,s,t);var c=t.fragments[0].start;return this.log("Live playlist sliding: "+c.toFixed(2)+" start-sn: "+(e?e.startSN:"na")+"->"+t.startSN+" prev-sn: "+(a?a.sn:"na")+" fragments: "+o),c}return l},A.waitForCdnTuneIn=function(t){return t.live&&t.canBlockReload&&t.partTarget&&t.tuneInGoal>Math.max(t.partHoldBack,3*t.partTarget)},A.setStartPosition=function(t,e){var r=this.startPosition;if(r<e&&(r=-1),-1===r||-1===this.lastCurrentTime){var n=t.startTimeOffset;Object(i.isFiniteNumber)(n)?(r=e+n,n<0&&(r+=t.totalduration),r=Math.min(Math.max(e,r),e+t.totalduration),this.log("Start time offset "+n+" found in playlist, adjust startPosition to "+r),this.startPosition=r):t.live?r=this.hls.liveSyncPosition||e:this.startPosition=r=0,this.lastCurrentTime=r}this.nextLoadPosition=r},A.getLoadPosition=function(){var t=this.media,e=0;return this.loadedmetadata&&t?e=t.currentTime:this.nextLoadPosition&&(e=this.nextLoadPosition),e},A.handleFragLoadAborted=function(t,e){this.transmuxer&&"initSegment"!==t.sn&&t.stats.aborted&&(this.warn("Fragment "+t.sn+(e?" part"+e.index:"")+" of level "+t.level+" was aborted"),this.resetFragmentLoading(t))},A.resetFragmentLoading=function(t){this.fragCurrent&&this.fragContextChanged(t)||(this.state=S.IDLE)},A.onFragmentOrKeyLoadError=function(t,e){if(!e.fatal){var r=e.frag;if(r&&r.type===t){var i=this.fragCurrent;console.assert(i&&r.sn===i.sn&&r.level===i.level&&r.urlId===i.urlId,"Frag load error must match current frag to retry");var n=this.config;if(this.fragLoadError+1<=n.fragLoadingMaxRetry){if(this.resetLiveStartWhenNotLoaded(r.level))return;var a=Math.min(Math.pow(2,this.fragLoadError)*n.fragLoadingRetryDelay,n.fragLoadingMaxRetryTimeout);this.warn("Fragment "+r.sn+" of "+t+" "+r.level+" failed to load, retrying in "+a+"ms"),this.retryDate=self.performance.now()+a,this.fragLoadError++,this.state=S.FRAG_LOADING_WAITING_RETRY}else e.levelRetry?(t===y.PlaylistLevelType.AUDIO&&(this.fragCurrent=null),this.fragLoadError=0,this.state=S.IDLE):(o.logger.error(e.details+" reaches max retry, redispatch as fatal ..."),e.fatal=!0,this.hls.stopLoad(),this.state=S.ERROR)}}},A.afterBufferFlushed=function(t,e,r){if(t){var i=s.BufferHelper.getBuffered(t);this.fragmentTracker.detectEvictedFragments(e,i,r),this.state===S.ENDED&&this.resetLoadingState()}},A.resetLoadingState=function(){this.fragCurrent=null,this.fragPrevious=null,this.state=S.IDLE},A.resetLiveStartWhenNotLoaded=function(t){if(!this.loadedmetadata){this.startFragRequested=!1;var e=this.levels?this.levels[t].details:null;if(null!=e&&e.live)return this.startPosition=-1,this.setStartPosition(e,0),this.resetLoadingState(),!0;this.nextLoadPosition=this.startPosition}return!1},A.updateLevelTiming=function(t,e,r,i){var n=this,a=r.details;console.assert(!!a,"level.details must be defined"),Object.keys(t.elementaryStreams).reduce((function(e,s){var o=t.elementaryStreams[s];if(o){var u=o.endPTS-o.startPTS;if(u<=0)return n.warn("Could not parse fragment "+t.sn+" "+s+" duration reliably ("+u+")"),e||!1;var d=i?0:Object(g.updateFragPTSDTS)(a,t,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return n.hls.trigger(l.Events.LEVEL_PTS_UPDATED,{details:a,level:r,drift:d,type:s,frag:t,start:o.startPTS,end:o.endPTS}),!0}return e}),!1)||(this.warn("Found no media in fragment "+t.sn+" of level "+r.id+" resetting transmuxer to fallback to playlist timing"),this.resetTransmuxer()),this.state=S.PARSED,this.hls.trigger(l.Events.FRAG_PARSED,{frag:t,part:e})},A.resetTransmuxer=function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)},b=n,(L=[{key:"state",get:function(){return this._state},set:function(t){var e=this._state;e!==t&&(this._state=t,this.log(e+"->"+t))}}])&&E(b.prototype,L),D&&E(b,D),Object.defineProperty(b,"prototype",{writable:!1}),n}(n.default)},"./src/controller/buffer-controller.ts":
37
+ /*! exports provided: State, default */function(t,e,r){r.r(e),r.d(e,"State",(function(){return b})),r.d(e,"default",(function(){return L}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../task-loop */"./src/task-loop.ts"),a=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),o=r(/*! ../utils/logger */"./src/utils/logger.ts"),l=r(/*! ../events */"./src/events.ts"),u=r(/*! ../errors */"./src/errors.ts"),d=r(/*! ../types/transmuxer */"./src/types/transmuxer.ts"),c=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),h=r(/*! ../utils/discontinuities */"./src/utils/discontinuities.ts"),f=r(/*! ./fragment-finders */"./src/controller/fragment-finders.ts"),g=r(/*! ./level-helper */"./src/controller/level-helper.ts"),v=r(/*! ../loader/fragment-loader */"./src/loader/fragment-loader.ts"),p=r(/*! ../crypt/decrypter */"./src/crypt/decrypter.ts"),m=r(/*! ../utils/time-ranges */"./src/utils/time-ranges.ts"),y=r(/*! ../types/loader */"./src/types/loader.ts");function E(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function T(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function S(t,e){return(S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var b={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"},L=function(t){var e,r;function n(e,r,i){var n;return(n=t.call(this)||this).hls=void 0,n.fragPrevious=null,n.fragCurrent=null,n.fragmentTracker=void 0,n.transmuxer=null,n._state=b.STOPPED,n.media=null,n.mediaBuffer=null,n.config=void 0,n.bitrateTest=!1,n.lastCurrentTime=0,n.nextLoadPosition=0,n.startPosition=0,n.loadedmetadata=!1,n.fragLoadError=0,n.retryDate=0,n.levels=null,n.fragmentLoader=void 0,n.levelLastLoaded=null,n.startFragRequested=!1,n.decrypter=void 0,n.initPTS=[],n.onvseeking=null,n.onvended=null,n.logPrefix="",n.log=void 0,n.warn=void 0,n.logPrefix=i,n.log=o.logger.log.bind(o.logger,i+":"),n.warn=o.logger.warn.bind(o.logger,i+":"),n.hls=e,n.fragmentLoader=new v.default(e.config),n.fragmentTracker=r,n.config=e.config,n.decrypter=new p.default(e,e.config),e.on(l.Events.KEY_LOADED,n.onKeyLoaded,T(n)),e.on(l.Events.LEVEL_SWITCHING,n.onLevelSwitching,T(n)),n}r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,S(e,r);var L,D,A,R=n.prototype;return R.doTick=function(){this.onTickEnd()},R.onTickEnd=function(){},R.startLoad=function(t){},R.stopLoad=function(){this.fragmentLoader.abort();var t=this.fragCurrent;t&&this.fragmentTracker.removeFragment(t),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=b.STOPPED},R._streamEnded=function(t,e){var r=this.fragCurrent,i=this.fragmentTracker;if(!e.live&&r&&this.media&&r.sn>=e.endSN&&!t.nextStart){var n=e.partList;if(null!=n&&n.length){var o=n[n.length-1];return s.BufferHelper.isBuffered(this.media,o.start+o.duration/2)}var l=i.getState(r);return l===a.FragmentState.PARTIAL||l===a.FragmentState.OK}return!1},R.onMediaAttached=function(t,e){var r=this.media=this.mediaBuffer=e.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),r.addEventListener("seeking",this.onvseeking),r.addEventListener("ended",this.onvended);var i=this.config;this.levels&&i.autoStartLoad&&this.state===b.STOPPED&&this.startLoad(i.startPosition)},R.onMediaDetaching=function(){var t=this.media;null!=t&&t.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),t&&this.onvseeking&&this.onvended&&(t.removeEventListener("seeking",this.onvseeking),t.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()},R.onMediaSeeking=function(){var t=this.config,e=this.fragCurrent,r=this.media,n=this.mediaBuffer,a=this.state,o=r?r.currentTime:0,l=s.BufferHelper.bufferInfo(n||r,o,t.maxBufferHole);if(this.log("media seeking to "+(Object(i.isFiniteNumber)(o)?o.toFixed(3):o)+", state: "+a),a===b.ENDED)this.resetLoadingState();else if(e&&!l.len){var u=t.maxFragLookUpTolerance,d=e.start-u,c=o>e.start+e.duration+u;(o<d||c)&&(c&&e.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),e.loader.abort()),this.resetLoadingState())}r&&(this.lastCurrentTime=o),this.loadedmetadata||l.len||(this.nextLoadPosition=this.startPosition=o),this.tickImmediate()},R.onMediaEnded=function(){this.startPosition=this.lastCurrentTime=0},R.onKeyLoaded=function(t,e){if(this.state===b.KEY_LOADING&&e.frag===this.fragCurrent&&this.levels){this.state=b.IDLE;var r=this.levels[e.frag.level].details;r&&this.loadFragment(e.frag,r,e.frag.start)}},R.onLevelSwitching=function(t,e){this.fragLoadError=0},R.onHandlerDestroying=function(){this.stopLoad(),t.prototype.onHandlerDestroying.call(this)},R.onHandlerDestroyed=function(){this.state=b.STOPPED,this.hls.off(l.Events.KEY_LOADED,this.onKeyLoaded,this),this.hls.off(l.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,t.prototype.onHandlerDestroyed.call(this)},R.loadKey=function(t,e){this.log("Loading key for "+t.sn+" of ["+e.startSN+"-"+e.endSN+"], "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+t.level),this.state=b.KEY_LOADING,this.fragCurrent=t,this.hls.trigger(l.Events.KEY_LOADING,{frag:t})},R.loadFragment=function(t,e,r){this._loadFragForPlayback(t,e,r)},R._loadFragForPlayback=function(t,e,r){var i=this;this._doFragLoad(t,e,r,(function(e){if(i.fragContextChanged(t))return i.warn("Fragment "+t.sn+(e.part?" p: "+e.part.index:"")+" of level "+t.level+" was dropped during download."),void i.fragmentTracker.removeFragment(t);t.stats.chunkCount++,i._handleFragmentLoadProgress(e)})).then((function(e){if(e){i.fragLoadError=0;var r=i.state;i.fragContextChanged(t)?(r===b.FRAG_LOADING||!i.fragCurrent&&r===b.PARSING)&&(i.fragmentTracker.removeFragment(t),i.state=b.IDLE):("payload"in e&&(i.log("Loaded fragment "+t.sn+" of level "+t.level),i.hls.trigger(l.Events.FRAG_LOADED,e)),i._handleFragmentLoadComplete(e))}})).catch((function(e){i.state!==b.STOPPED&&i.state!==b.ERROR&&(i.warn(e),i.resetFragmentLoading(t))}))},R.flushMainBuffer=function(t,e,r){if(void 0===r&&(r=null),t-e){var i={startOffset:t,endOffset:e,type:r};this.fragLoadError=0,this.hls.trigger(l.Events.BUFFER_FLUSHING,i)}},R._loadInitSegment=function(t){var e=this;this._doFragLoad(t).then((function(r){if(!r||e.fragContextChanged(t)||!e.levels)throw new Error("init load aborted");return r})).then((function(r){var i=e.hls,n=r.payload,a=t.decryptdata;if(n&&n.byteLength>0&&a&&a.key&&a.iv&&"AES-128"===a.method){var s=self.performance.now();return e.decrypter.webCryptoDecrypt(new Uint8Array(n),a.key.buffer,a.iv.buffer).then((function(e){var n=self.performance.now();return i.trigger(l.Events.FRAG_DECRYPTED,{frag:t,payload:e,stats:{tstart:s,tdecrypt:n}}),r.payload=e,r}))}return r})).then((function(r){var i=e.fragCurrent,n=e.hls,a=e.levels;if(!a)throw new Error("init load aborted, missing levels");var s=a[t.level].details;console.assert(s,"Level details are defined when init segment is loaded");var o=t.stats;e.state=b.IDLE,e.fragLoadError=0,t.data=new Uint8Array(r.payload),o.parsing.start=o.buffering.start=self.performance.now(),o.parsing.end=o.buffering.end=self.performance.now(),r.frag===i&&n.trigger(l.Events.FRAG_BUFFERED,{stats:o,frag:i,part:null,id:t.type}),e.tick()})).catch((function(r){e.state!==b.STOPPED&&e.state!==b.ERROR&&(e.warn(r),e.resetFragmentLoading(t))}))},R.fragContextChanged=function(t){var e=this.fragCurrent;return!t||!e||t.level!==e.level||t.sn!==e.sn||t.urlId!==e.urlId},R.fragBufferedComplete=function(t,e){var r=this.mediaBuffer?this.mediaBuffer:this.media;this.log("Buffered "+t.type+" sn: "+t.sn+(e?" part: "+e.index:"")+" of "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+t.level+" "+(r?m.default.toString(s.BufferHelper.getBuffered(r)):"(detached)")),this.state=b.IDLE,r&&(!this.loadedmetadata&&r.buffered.length&&this.fragCurrent===this.fragPrevious&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())},R.seekToStartPos=function(){},R._handleFragmentLoadComplete=function(t){var e=this.transmuxer;if(e){var r=t.frag,i=t.part,n=t.partsLoaded,a=!n||0===n.length||n.some((function(t){return!t})),s=new d.ChunkMetadata(r.level,r.sn,r.stats.chunkCount+1,0,i?i.index:-1,!a);e.flush(s)}},R._handleFragmentLoadProgress=function(t){},R._doFragLoad=function(t,e,r,n){var a=this;if(void 0===r&&(r=null),!this.levels)throw new Error("frag load aborted, missing levels");if(r=Math.max(t.start,r||0),this.config.lowLatencyMode&&e){var s=e.partList;if(s&&n){r>t.end&&e.fragmentHint&&(t=e.fragmentHint);var o=this.getNextPart(s,t,r);if(o>-1){var u=s[o];return this.log("Loading part sn: "+t.sn+" p: "+u.index+" cc: "+t.cc+" of playlist ["+e.startSN+"-"+e.endSN+"] parts [0-"+o+"-"+(s.length-1)+"] "+("[stream-controller]"===this.logPrefix?"level":"track")+": "+t.level+", target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=u.start+u.duration,this.state=b.FRAG_LOADING,this.hls.trigger(l.Events.FRAG_LOADING,{frag:t,part:s[o],targetBufferTime:r}),this.doFragPartsLoad(t,s,o,n).catch((function(t){return a.handleFragLoadError(t)}))}if(!t.url||this.loadedEndOfParts(s,r))return Promise.resolve(null)}}return this.log("Loading fragment "+t.sn+" cc: "+t.cc+" "+(e?"of ["+e.startSN+"-"+e.endSN+"] ":"")+("[stream-controller]"===this.logPrefix?"level":"track")+": "+t.level+", target: "+parseFloat(r.toFixed(3))),Object(i.isFiniteNumber)(t.sn)&&!this.bitrateTest&&(this.nextLoadPosition=t.start+t.duration),this.state=b.FRAG_LOADING,this.hls.trigger(l.Events.FRAG_LOADING,{frag:t,targetBufferTime:r}),this.fragmentLoader.load(t,n).catch((function(t){return a.handleFragLoadError(t)}))},R.doFragPartsLoad=function(t,e,r,i){var n=this;return new Promise((function(a,s){var o=[];!function r(u){var d=e[u];n.fragmentLoader.loadPart(t,d,i).then((function(i){o[d.index]=i;var s=i.part;n.hls.trigger(l.Events.FRAG_LOADED,i);var c=e[u+1];if(!c||c.fragment!==t)return a({frag:t,part:s,partsLoaded:o});r(u+1)})).catch(s)}(r)}))},R.handleFragLoadError=function(t){var e=t.data;return e&&e.details===u.ErrorDetails.INTERNAL_ABORTED?this.handleFragLoadAborted(e.frag,e.part):this.hls.trigger(l.Events.ERROR,e),null},R._handleTransmuxerFlush=function(t){var e=this.getCurrentContext(t);if(e&&this.state===b.PARSING){var r=e.frag,i=e.part,n=e.level,a=self.performance.now();r.stats.parsing.end=a,i&&(i.stats.parsing.end=a),this.updateLevelTiming(r,i,n,t.partial)}else this.fragCurrent||(this.state=b.IDLE)},R.getCurrentContext=function(t){var e=this.levels,r=t.level,i=t.sn,n=t.part;if(!e||!e[r])return this.warn("Levels object was unset while buffering fragment "+i+" of level "+r+". The current chunk will not be buffered."),null;var a=e[r],s=n>-1?Object(g.getPartWith)(a,i,n):null,o=s?s.fragment:Object(g.getFragmentWithSN)(a,i,this.fragCurrent);return o?{frag:o,part:s,level:a}:null},R.bufferFragmentData=function(t,e,r,i){if(t&&this.state===b.PARSING){var n=t.data1,a=t.data2,s=n;if(n&&a&&(s=Object(c.appendUint8Array)(n,a)),s&&s.length){var o={type:t.type,frag:e,part:r,chunkMeta:i,parent:e.type,data:s};this.hls.trigger(l.Events.BUFFER_APPENDING,o),t.dropped&&t.independent&&!r&&this.flushBufferGap(e)}}},R.flushBufferGap=function(t){var e=this.media;if(e)if(s.BufferHelper.isBuffered(e,e.currentTime)){var r=e.currentTime,i=s.BufferHelper.bufferInfo(e,r,0),n=t.duration,a=Math.min(2*this.config.maxFragLookUpTolerance,.25*n),o=Math.max(Math.min(t.start-a,i.end-a),r+a);t.start-o>a&&this.flushMainBuffer(o,t.start)}else this.flushMainBuffer(0,t.start)},R.getFwdBufferInfo=function(t,e){var r=this.config,n=this.getLoadPosition();if(!Object(i.isFiniteNumber)(n))return null;var a=s.BufferHelper.bufferInfo(t,n,r.maxBufferHole);if(0===a.len&&void 0!==a.nextStart){var o=this.fragmentTracker.getBufferedFrag(n,e);if(o&&a.nextStart<o.end)return s.BufferHelper.bufferInfo(t,n,Math.max(a.nextStart,r.maxBufferHole))}return a},R.getMaxBufferLength=function(t){var e,r=this.config;return e=t?Math.max(8*r.maxBufferSize/t,r.maxBufferLength):r.maxBufferLength,Math.min(e,r.maxMaxBufferLength)},R.reduceMaxBufferLength=function(t){var e=this.config,r=t||e.maxBufferLength;return e.maxMaxBufferLength>=r&&(e.maxMaxBufferLength/=2,this.warn("Reduce max buffer length to "+e.maxMaxBufferLength+"s"),!0)},R.getNextFragment=function(t,e){var r=e.fragments,i=r.length;if(!i)return null;var n,a=this.config,s=r[0].start;if(e.live){var o=a.initialLiveManifestSize;if(i<o)return this.warn("Not enough fragments to start playback (have: "+i+", need: "+o+")"),null;e.PTSKnown||this.startFragRequested||-1!==this.startPosition||(n=this.getInitialLiveFragment(e,r),this.startPosition=n?this.hls.liveSyncPosition||n.start:t)}else t<=s&&(n=r[0]);if(!n){var l=a.lowLatencyMode?e.partEnd:e.fragmentEnd;n=this.getFragmentAtPosition(t,l,e)}return this.mapToInitFragWhenRequired(n)},R.mapToInitFragWhenRequired=function(t){return null==t||!t.initSegment||null!=t&&t.initSegment.data||this.bitrateTest?t:t.initSegment},R.getNextPart=function(t,e,r){for(var i=-1,n=!1,a=!0,s=0,o=t.length;s<o;s++){var l=t[s];if(a=a&&!l.independent,i>-1&&r<l.start)break;var u=l.loaded;!u&&(n||l.independent||a)&&l.fragment===e&&(i=s),n=u}return i},R.loadedEndOfParts=function(t,e){var r=t[t.length-1];return r&&e>r.start&&r.loaded},R.getInitialLiveFragment=function(t,e){var r=this.fragPrevious,i=null;if(r){if(t.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: "+r.programDateTime),i=Object(f.findFragmentByPDT)(e,r.endProgramDateTime,this.config.maxFragLookUpTolerance)),!i){var n=r.sn+1;if(n>=t.startSN&&n<=t.endSN){var a=e[n-t.startSN];r.cc===a.cc&&(i=a,this.log("Live playlist, switching playlist, load frag with next SN: "+i.sn))}i||(i=Object(f.findFragWithCC)(e,r.cc))&&this.log("Live playlist, switching playlist, load frag with same CC: "+i.sn)}}else{var s=this.hls.liveSyncPosition;null!==s&&(i=this.getFragmentAtPosition(s,this.bitrateTest?t.fragmentEnd:t.edge,t))}return i},R.getFragmentAtPosition=function(t,e,r){var i,n=this.config,s=this.fragPrevious,o=r.fragments,l=r.endSN,u=r.fragmentHint,d=n.maxFragLookUpTolerance,c=!!(n.lowLatencyMode&&r.partList&&u);if(c&&u&&!this.bitrateTest&&(o=o.concat(u),l=u.sn),t<e){var h=t>e-d?0:d;i=Object(f.findFragmentByPTS)(s,o,t,h)}else i=o[o.length-1];if(i){var g=i.sn-r.startSN;if(s&&i.sn===s.sn&&!c&&s&&i.level===s.level){var v=o[g+1];i.sn<l&&this.fragmentTracker.getState(v)!==a.FragmentState.OK?(this.log("SN "+i.sn+" just loaded, load next one: "+v.sn),i=v):i=null}}return i},R.synchronizeToLiveEdge=function(t){var e=this.config,r=this.media;if(r){var i=this.hls.liveSyncPosition,n=r.currentTime,a=t.fragments[0].start,s=t.edge,o=n>=a-e.maxFragLookUpTolerance&&n<=s;if(null!==i&&r.duration>i&&(n<i||!o)){var l=void 0!==e.liveMaxLatencyDuration?e.liveMaxLatencyDuration:e.liveMaxLatencyDurationCount*t.targetduration;(!o&&r.readyState<4||n<s-l)&&(this.loadedmetadata||(this.nextLoadPosition=i),r.readyState&&(this.warn("Playback: "+n.toFixed(3)+" is located too far from the end of live sliding playlist: "+s+", reset currentTime to : "+i.toFixed(3)),r.currentTime=i))}}},R.alignPlaylists=function(t,e){var r=this.levels,n=this.levelLastLoaded,a=this.fragPrevious,s=null!==n?r[n]:null,o=t.fragments.length;if(!o)return this.warn("No fragments in live playlist"),0;var l=t.fragments[0].start,u=!e,d=t.alignedSliding&&Object(i.isFiniteNumber)(l);if(u||!d&&!l){Object(h.alignStream)(a,s,t);var c=t.fragments[0].start;return this.log("Live playlist sliding: "+c.toFixed(2)+" start-sn: "+(e?e.startSN:"na")+"->"+t.startSN+" prev-sn: "+(a?a.sn:"na")+" fragments: "+o),c}return l},R.waitForCdnTuneIn=function(t){return t.live&&t.canBlockReload&&t.partTarget&&t.tuneInGoal>Math.max(t.partHoldBack,3*t.partTarget)},R.setStartPosition=function(t,e){var r=this.startPosition;if(r<e&&(r=-1),-1===r||-1===this.lastCurrentTime){var n=t.startTimeOffset;Object(i.isFiniteNumber)(n)?(r=e+n,n<0&&(r+=t.totalduration),r=Math.min(Math.max(e,r),e+t.totalduration),this.log("Start time offset "+n+" found in playlist, adjust startPosition to "+r),this.startPosition=r):t.live?r=this.hls.liveSyncPosition||e:this.startPosition=r=0,this.lastCurrentTime=r}this.nextLoadPosition=r},R.getLoadPosition=function(){var t=this.media,e=0;return this.loadedmetadata&&t?e=t.currentTime:this.nextLoadPosition&&(e=this.nextLoadPosition),e},R.handleFragLoadAborted=function(t,e){this.transmuxer&&"initSegment"!==t.sn&&t.stats.aborted&&(this.warn("Fragment "+t.sn+(e?" part"+e.index:"")+" of level "+t.level+" was aborted"),this.resetFragmentLoading(t))},R.resetFragmentLoading=function(t){this.fragCurrent&&(this.fragContextChanged(t)||this.state===b.FRAG_LOADING_WAITING_RETRY)||(this.state=b.IDLE)},R.onFragmentOrKeyLoadError=function(t,e){if(!e.fatal){var r=e.frag;if(r&&r.type===t){var i=this.fragCurrent;console.assert(i&&r.sn===i.sn&&r.level===i.level&&r.urlId===i.urlId,"Frag load error must match current frag to retry");var n=this.config;if(this.fragLoadError+1<=n.fragLoadingMaxRetry){this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition);var a=Math.min(Math.pow(2,this.fragLoadError)*n.fragLoadingRetryDelay,n.fragLoadingMaxRetryTimeout);this.warn("Fragment "+r.sn+" of "+t+" "+r.level+" failed to load, retrying in "+a+"ms"),this.retryDate=self.performance.now()+a,this.fragLoadError++,this.state=b.FRAG_LOADING_WAITING_RETRY}else e.levelRetry?(t===y.PlaylistLevelType.AUDIO&&(this.fragCurrent=null),this.fragLoadError=0,this.state=b.IDLE):(o.logger.error(e.details+" reaches max retry, redispatch as fatal ..."),e.fatal=!0,this.hls.stopLoad(),this.state=b.ERROR)}}},R.afterBufferFlushed=function(t,e,r){if(t){var i=s.BufferHelper.getBuffered(t);this.fragmentTracker.detectEvictedFragments(e,i,r),this.state===b.ENDED&&this.resetLoadingState()}},R.resetLoadingState=function(){this.fragCurrent=null,this.fragPrevious=null,this.state=b.IDLE},R.resetStartWhenNotLoaded=function(t){if(!this.loadedmetadata){this.startFragRequested=!1;var e=this.levels?this.levels[t].details:null;null!=e&&e.live?(this.startPosition=-1,this.setStartPosition(e,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}},R.updateLevelTiming=function(t,e,r,i){var n=this,a=r.details;console.assert(!!a,"level.details must be defined"),Object.keys(t.elementaryStreams).reduce((function(e,s){var o=t.elementaryStreams[s];if(o){var u=o.endPTS-o.startPTS;if(u<=0)return n.warn("Could not parse fragment "+t.sn+" "+s+" duration reliably ("+u+")"),e||!1;var d=i?0:Object(g.updateFragPTSDTS)(a,t,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return n.hls.trigger(l.Events.LEVEL_PTS_UPDATED,{details:a,level:r,drift:d,type:s,frag:t,start:o.startPTS,end:o.endPTS}),!0}return e}),!1)||(this.warn("Found no media in fragment "+t.sn+" of level "+r.id+" resetting transmuxer to fallback to playlist timing"),this.resetTransmuxer()),this.state=b.PARSED,this.hls.trigger(l.Events.FRAG_PARSED,{frag:t,part:e})},R.resetTransmuxer=function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)},L=n,(D=[{key:"state",get:function(){return this._state},set:function(t){var e=this._state;e!==t&&(this._state=t,this.log(e+"->"+t))}}])&&E(L.prototype,D),A&&E(L,A),Object.defineProperty(L,"prototype",{writable:!1}),n}(n.default)},"./src/controller/buffer-controller.ts":
38
38
  /*!*********************************************!*\
39
39
  !*** ./src/controller/buffer-controller.ts ***!
40
40
  \*********************************************/
41
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return f}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! ../errors */"./src/errors.ts"),o=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),l=r(/*! ../utils/mediasource-helper */"./src/utils/mediasource-helper.ts"),u=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),d=r(/*! ./buffer-operation-queue */"./src/controller/buffer-operation-queue.ts"),c=Object(l.getMediaSource)(),h=/([ha]vc.)(?:\.[^.,]+)+/,f=function(){function t(t){var e=this;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.appendError=0,this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this._onMediaSourceOpen=function(){var t=e.hls,r=e.media,i=e.mediaSource;a.logger.log("[buffer-controller]: Media source opened"),r&&(e.updateMediaElementDuration(),t.trigger(n.Events.MEDIA_ATTACHED,{media:r})),i&&i.removeEventListener("sourceopen",e._onMediaSourceOpen),e.checkPendingTracks()},this._onMediaSourceClose=function(){a.logger.log("[buffer-controller]: Media source closed")},this._onMediaSourceEnded=function(){a.logger.log("[buffer-controller]: Media source ended")},this.hls=t,this._initSourceBuffer(),this.registerListeners()}var e=t.prototype;return e.hasSourceTypes=function(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0},e.destroy=function(){this.unregisterListeners(),this.details=null},e.registerListeners=function(){var t=this.hls;t.on(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(n.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.on(n.Events.BUFFER_RESET,this.onBufferReset,this),t.on(n.Events.BUFFER_APPENDING,this.onBufferAppending,this),t.on(n.Events.BUFFER_CODECS,this.onBufferCodecs,this),t.on(n.Events.BUFFER_EOS,this.onBufferEos,this),t.on(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(n.Events.LEVEL_UPDATED,this.onLevelUpdated,this),t.on(n.Events.FRAG_PARSED,this.onFragParsed,this),t.on(n.Events.FRAG_CHANGED,this.onFragChanged,this)},e.unregisterListeners=function(){var t=this.hls;t.off(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(n.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.off(n.Events.BUFFER_RESET,this.onBufferReset,this),t.off(n.Events.BUFFER_APPENDING,this.onBufferAppending,this),t.off(n.Events.BUFFER_CODECS,this.onBufferCodecs,this),t.off(n.Events.BUFFER_EOS,this.onBufferEos,this),t.off(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(n.Events.LEVEL_UPDATED,this.onLevelUpdated,this),t.off(n.Events.FRAG_PARSED,this.onFragParsed,this),t.off(n.Events.FRAG_CHANGED,this.onFragChanged,this)},e._initSourceBuffer=function(){this.sourceBuffer={},this.operationQueue=new d.default(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]}},e.onManifestParsed=function(t,e){var r=2;(e.audio&&!e.video||!e.altAudio)&&(r=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=r,this.details=null,a.logger.log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},e.onMediaAttaching=function(t,e){var r=this.media=e.media;if(r&&c){var i=this.mediaSource=new c;i.addEventListener("sourceopen",this._onMediaSourceOpen),i.addEventListener("sourceended",this._onMediaSourceEnded),i.addEventListener("sourceclose",this._onMediaSourceClose),r.src=self.URL.createObjectURL(i),this._objectUrl=r.src}},e.onMediaDetaching=function(){var t=this.media,e=this.mediaSource,r=this._objectUrl;if(e){if(a.logger.log("[buffer-controller]: media source detaching"),"open"===e.readyState)try{e.endOfStream()}catch(t){a.logger.warn("[buffer-controller]: onMediaDetaching: "+t.message+" while calling endOfStream")}this.onBufferReset(),e.removeEventListener("sourceopen",this._onMediaSourceOpen),e.removeEventListener("sourceended",this._onMediaSourceEnded),e.removeEventListener("sourceclose",this._onMediaSourceClose),t&&(r&&self.URL.revokeObjectURL(r),t.src===r?(t.removeAttribute("src"),t.load()):a.logger.warn("[buffer-controller]: media.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(n.Events.MEDIA_DETACHED,void 0)},e.onBufferReset=function(){var t=this;this.getSourceBufferTypes().forEach((function(e){var r=t.sourceBuffer[e];try{r&&(t.removeBufferListeners(e),t.mediaSource&&t.mediaSource.removeSourceBuffer(r),t.sourceBuffer[e]=void 0)}catch(t){a.logger.warn("[buffer-controller]: Failed to reset the "+e+" buffer",t)}})),this._initSourceBuffer()},e.onBufferCodecs=function(t,e){var r=this,i=this.getSourceBufferTypes().length;Object.keys(e).forEach((function(t){if(i){var n=r.tracks[t];if(n&&"function"==typeof n.buffer.changeType){var s=e[t],o=s.id,l=s.codec,u=s.levelCodec,d=s.container,c=s.metadata,f=(n.levelCodec||n.codec).replace(h,"$1"),g=(u||l).replace(h,"$1");if(f!==g){var v=d+";codecs="+(u||l);r.appendChangeType(t,v),a.logger.log("[buffer-controller]: switching codec "+f+" to "+g),r.tracks[t]={buffer:n.buffer,codec:l,container:d,levelCodec:u,metadata:c,id:o}}}}else r.pendingTracks[t]=e[t]})),i||(this.bufferCodecEventsExpected=Math.max(this.bufferCodecEventsExpected-1,0),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks())},e.appendChangeType=function(t,e){var r=this,i=this.operationQueue,n={execute:function(){var n=r.sourceBuffer[t];n&&(a.logger.log("[buffer-controller]: changing "+t+" sourceBuffer type to "+e),n.changeType(e)),i.shiftAndExecuteNext(t)},onStart:function(){},onComplete:function(){},onError:function(e){a.logger.warn("[buffer-controller]: Failed to change "+t+" SourceBuffer type",e)}};i.append(n,t)},e.onBufferAppending=function(t,e){var r=this,i=this.hls,l=this.operationQueue,u=this.tracks,d=e.data,c=e.type,h=e.frag,f=e.part,g=e.chunkMeta,v=g.buffering[c],p=self.performance.now();v.start=p;var m=h.stats.buffering,y=f?f.stats.buffering:null;0===m.start&&(m.start=p),y&&0===y.start&&(y.start=p);var E=u.audio,T="audio"===c&&1===g.id&&"audio/mpeg"===(null==E?void 0:E.container),S={execute:function(){if(v.executeStart=self.performance.now(),T){var t=r.sourceBuffer[c];if(t){var e=h.start-t.timestampOffset;Math.abs(e)>=.1&&(a.logger.log("[buffer-controller]: Updating audio SourceBuffer timestampOffset to "+h.start+" (delta: "+e+") sn: "+h.sn+")"),t.timestampOffset=h.start)}}r.appendExecutor(d,c)},onStart:function(){},onComplete:function(){var t=self.performance.now();v.executeEnd=v.end=t,0===m.first&&(m.first=t),y&&0===y.first&&(y.first=t);var e=r.sourceBuffer,i={};for(var a in e)i[a]=o.BufferHelper.getBuffered(e[a]);r.appendError=0,r.hls.trigger(n.Events.BUFFER_APPENDED,{type:c,frag:h,part:f,chunkMeta:g,parent:h.type,timeRanges:i})},onError:function(t){a.logger.error("[buffer-controller]: Error encountered while trying to append to the "+c+" SourceBuffer",t);var e={type:s.ErrorTypes.MEDIA_ERROR,parent:h.type,details:s.ErrorDetails.BUFFER_APPEND_ERROR,err:t,fatal:!1};t.code===DOMException.QUOTA_EXCEEDED_ERR?e.details=s.ErrorDetails.BUFFER_FULL_ERROR:(r.appendError++,e.details=s.ErrorDetails.BUFFER_APPEND_ERROR,r.appendError>i.config.appendErrorMaxRetry&&(a.logger.error("[buffer-controller]: Failed "+i.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),e.fatal=!0)),i.trigger(n.Events.ERROR,e)}};l.append(S,c)},e.onBufferFlushing=function(t,e){var r=this,i=this.operationQueue,s=function(t){return{execute:r.removeExecutor.bind(r,t,e.startOffset,e.endOffset),onStart:function(){},onComplete:function(){r.hls.trigger(n.Events.BUFFER_FLUSHED,{type:t})},onError:function(e){a.logger.warn("[buffer-controller]: Failed to remove from "+t+" SourceBuffer",e)}}};e.type?i.append(s(e.type),e.type):this.getSourceBufferTypes().forEach((function(t){i.append(s(t),t)}))},e.onFragParsed=function(t,e){var r=this,i=e.frag,s=e.part,o=[],l=s?s.elementaryStreams:i.elementaryStreams;l[u.ElementaryStreamTypes.AUDIOVIDEO]?o.push("audiovideo"):(l[u.ElementaryStreamTypes.AUDIO]&&o.push("audio"),l[u.ElementaryStreamTypes.VIDEO]&&o.push("video")),0===o.length&&a.logger.warn("Fragments must have at least one ElementaryStreamType set. type: "+i.type+" level: "+i.level+" sn: "+i.sn),this.blockBuffers((function(){var t=self.performance.now();i.stats.buffering.end=t,s&&(s.stats.buffering.end=t);var e=s?s.stats:i.stats;r.hls.trigger(n.Events.FRAG_BUFFERED,{frag:i,part:s,stats:e,id:i.type})}),o)},e.onFragChanged=function(t,e){this.flushBackBuffer()},e.onBufferEos=function(t,e){var r=this;this.getSourceBufferTypes().reduce((function(t,i){var n=r.sourceBuffer[i];return e.type&&e.type!==i||n&&!n.ended&&(n.ended=!0,a.logger.log("[buffer-controller]: "+i+" sourceBuffer now EOS")),t&&!(n&&!n.ended)}),!0)&&this.blockBuffers((function(){var t=r.mediaSource;t&&"open"===t.readyState&&t.endOfStream()}))},e.onLevelUpdated=function(t,e){var r=e.details;r.fragments.length&&(this.details=r,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())},e.flushBackBuffer=function(){var t=this.hls,e=this.details,r=this.media,a=this.sourceBuffer;if(r&&null!==e){var s=this.getSourceBufferTypes();if(s.length){var l=e.live&&null!==t.config.liveBackBufferLength?t.config.liveBackBufferLength:t.config.backBufferLength;if(Object(i.isFiniteNumber)(l)&&!(l<0)){var u=r.currentTime,d=e.levelTargetDuration,c=Math.max(l,d),h=Math.floor(u/d)*d-c;s.forEach((function(r){var i=a[r];if(i){var s=o.BufferHelper.getBuffered(i);s.length>0&&h>s.start(0)&&(t.trigger(n.Events.BACK_BUFFER_REACHED,{bufferEnd:h}),e.live&&t.trigger(n.Events.LIVE_BACK_BUFFER_REACHED,{bufferEnd:h}),t.trigger(n.Events.BUFFER_FLUSHING,{startOffset:0,endOffset:h,type:r}))}}))}}}},e.updateMediaElementDuration=function(){if(this.details&&this.media&&this.mediaSource&&"open"===this.mediaSource.readyState){var t=this.details,e=this.hls,r=this.media,n=this.mediaSource,s=t.fragments[0].start+t.totalduration,o=r.duration,l=Object(i.isFiniteNumber)(n.duration)?n.duration:0;t.live&&e.config.liveDurationInfinity?(a.logger.log("[buffer-controller]: Media Source duration is set to Infinity"),n.duration=1/0,this.updateSeekableRange(t)):(s>l&&s>o||!Object(i.isFiniteNumber)(o))&&(a.logger.log("[buffer-controller]: Updating Media Source duration to "+s.toFixed(3)),n.duration=s)}},e.updateSeekableRange=function(t){var e=this.mediaSource,r=t.fragments;if(r.length&&t.live&&null!=e&&e.setLiveSeekableRange){var i=Math.max(0,r[0].start),n=Math.max(i,i+t.totalduration);e.setLiveSeekableRange(i,n)}},e.checkPendingTracks=function(){var t=this.bufferCodecEventsExpected,e=this.operationQueue,r=this.pendingTracks,i=Object.keys(r).length;if(i&&!t||2===i){this.createSourceBuffers(r),this.pendingTracks={};var a=this.getSourceBufferTypes();if(0===a.length)return void this.hls.trigger(n.Events.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,reason:"could not create source buffer for media codec(s)"});a.forEach((function(t){e.executeNext(t)}))}},e.createSourceBuffers=function(t){var e=this.sourceBuffer,r=this.mediaSource;if(!r)throw Error("createSourceBuffers called when mediaSource was null");var i=0;for(var o in t)if(!e[o]){var l=t[o];if(!l)throw Error("source buffer exists for track "+o+", however track does not");var u=l.levelCodec||l.codec,d=l.container+";codecs="+u;a.logger.log("[buffer-controller]: creating sourceBuffer("+d+")");try{var c=e[o]=r.addSourceBuffer(d),h=o;this.addBufferListener(h,"updatestart",this._onSBUpdateStart),this.addBufferListener(h,"updateend",this._onSBUpdateEnd),this.addBufferListener(h,"error",this._onSBUpdateError),this.tracks[o]={buffer:c,codec:u,container:l.container,levelCodec:l.levelCodec,metadata:l.metadata,id:l.id},i++}catch(t){a.logger.error("[buffer-controller]: error while trying to add sourceBuffer: "+t.message),this.hls.trigger(n.Events.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:t,mimeType:d})}}i&&this.hls.trigger(n.Events.BUFFER_CREATED,{tracks:this.tracks})},e._onSBUpdateStart=function(t){this.operationQueue.current(t).onStart()},e._onSBUpdateEnd=function(t){var e=this.operationQueue;e.current(t).onComplete(),e.shiftAndExecuteNext(t)},e._onSBUpdateError=function(t,e){a.logger.error("[buffer-controller]: "+t+" SourceBuffer error",e),this.hls.trigger(n.Events.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1});var r=this.operationQueue.current(t);r&&r.onError(e)},e.removeExecutor=function(t,e,r){var n=this.media,s=this.mediaSource,o=this.operationQueue,l=this.sourceBuffer[t];if(!n||!s||!l)return a.logger.warn("[buffer-controller]: Attempting to remove from the "+t+" SourceBuffer, but it does not exist"),void o.shiftAndExecuteNext(t);var u=Object(i.isFiniteNumber)(n.duration)?n.duration:1/0,d=Object(i.isFiniteNumber)(s.duration)?s.duration:1/0,c=Math.max(0,e),h=Math.min(r,u,d);h>c?(a.logger.log("[buffer-controller]: Removing ["+c+","+h+"] from the "+t+" SourceBuffer"),console.assert(!l.updating,t+" sourceBuffer must not be updating"),l.remove(c,h)):o.shiftAndExecuteNext(t)},e.appendExecutor=function(t,e){var r=this.operationQueue,i=this.sourceBuffer[e];if(!i)return a.logger.warn("[buffer-controller]: Attempting to append to the "+e+" SourceBuffer, but it does not exist"),void r.shiftAndExecuteNext(e);i.ended=!1,console.assert(!i.updating,e+" sourceBuffer must not be updating"),i.appendBuffer(t)},e.blockBuffers=function(t,e){var r=this;if(void 0===e&&(e=this.getSourceBufferTypes()),!e.length)return a.logger.log("[buffer-controller]: Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(t);var i=this.operationQueue,n=e.map((function(t){return i.appendBlocker(t)}));Promise.all(n).then((function(){t(),e.forEach((function(t){var e=r.sourceBuffer[t];e&&e.updating||i.shiftAndExecuteNext(t)}))}))},e.getSourceBufferTypes=function(){return Object.keys(this.sourceBuffer)},e.addBufferListener=function(t,e,r){var i=this.sourceBuffer[t];if(i){var n=r.bind(this,t);this.listeners[t].push({event:e,listener:n}),i.addEventListener(e,n)}},e.removeBufferListeners=function(t){var e=this.sourceBuffer[t];e&&this.listeners[t].forEach((function(t){e.removeEventListener(t.event,t.listener)}))},t}()},"./src/controller/buffer-operation-queue.ts":
41
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return f}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! ../errors */"./src/errors.ts"),o=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),l=r(/*! ../utils/mediasource-helper */"./src/utils/mediasource-helper.ts"),u=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),d=r(/*! ./buffer-operation-queue */"./src/controller/buffer-operation-queue.ts"),c=Object(l.getMediaSource)(),h=/([ha]vc.)(?:\.[^.,]+)+/,f=function(){function t(t){var e=this;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.appendError=0,this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this._onMediaSourceOpen=function(){var t=e.hls,r=e.media,i=e.mediaSource;a.logger.log("[buffer-controller]: Media source opened"),r&&(e.updateMediaElementDuration(),t.trigger(n.Events.MEDIA_ATTACHED,{media:r})),i&&i.removeEventListener("sourceopen",e._onMediaSourceOpen),e.checkPendingTracks()},this._onMediaSourceClose=function(){a.logger.log("[buffer-controller]: Media source closed")},this._onMediaSourceEnded=function(){a.logger.log("[buffer-controller]: Media source ended")},this.hls=t,this._initSourceBuffer(),this.registerListeners()}var e=t.prototype;return e.hasSourceTypes=function(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0},e.destroy=function(){this.unregisterListeners(),this.details=null},e.registerListeners=function(){var t=this.hls;t.on(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(n.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.on(n.Events.BUFFER_RESET,this.onBufferReset,this),t.on(n.Events.BUFFER_APPENDING,this.onBufferAppending,this),t.on(n.Events.BUFFER_CODECS,this.onBufferCodecs,this),t.on(n.Events.BUFFER_EOS,this.onBufferEos,this),t.on(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(n.Events.LEVEL_UPDATED,this.onLevelUpdated,this),t.on(n.Events.FRAG_PARSED,this.onFragParsed,this),t.on(n.Events.FRAG_CHANGED,this.onFragChanged,this)},e.unregisterListeners=function(){var t=this.hls;t.off(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(n.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.off(n.Events.BUFFER_RESET,this.onBufferReset,this),t.off(n.Events.BUFFER_APPENDING,this.onBufferAppending,this),t.off(n.Events.BUFFER_CODECS,this.onBufferCodecs,this),t.off(n.Events.BUFFER_EOS,this.onBufferEos,this),t.off(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(n.Events.LEVEL_UPDATED,this.onLevelUpdated,this),t.off(n.Events.FRAG_PARSED,this.onFragParsed,this),t.off(n.Events.FRAG_CHANGED,this.onFragChanged,this)},e._initSourceBuffer=function(){this.sourceBuffer={},this.operationQueue=new d.default(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]}},e.onManifestParsed=function(t,e){var r=2;(e.audio&&!e.video||!e.altAudio)&&(r=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=r,this.details=null,a.logger.log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},e.onMediaAttaching=function(t,e){var r=this.media=e.media;if(r&&c){var i=this.mediaSource=new c;i.addEventListener("sourceopen",this._onMediaSourceOpen),i.addEventListener("sourceended",this._onMediaSourceEnded),i.addEventListener("sourceclose",this._onMediaSourceClose),r.src=self.URL.createObjectURL(i),this._objectUrl=r.src}},e.onMediaDetaching=function(){var t=this.media,e=this.mediaSource,r=this._objectUrl;if(e){if(a.logger.log("[buffer-controller]: media source detaching"),"open"===e.readyState)try{e.endOfStream()}catch(t){a.logger.warn("[buffer-controller]: onMediaDetaching: "+t.message+" while calling endOfStream")}this.onBufferReset(),e.removeEventListener("sourceopen",this._onMediaSourceOpen),e.removeEventListener("sourceended",this._onMediaSourceEnded),e.removeEventListener("sourceclose",this._onMediaSourceClose),t&&(r&&self.URL.revokeObjectURL(r),t.src===r?(t.removeAttribute("src"),t.load()):a.logger.warn("[buffer-controller]: media.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(n.Events.MEDIA_DETACHED,void 0)},e.onBufferReset=function(){var t=this;this.getSourceBufferTypes().forEach((function(e){var r=t.sourceBuffer[e];try{r&&(t.removeBufferListeners(e),t.mediaSource&&t.mediaSource.removeSourceBuffer(r),t.sourceBuffer[e]=void 0)}catch(t){a.logger.warn("[buffer-controller]: Failed to reset the "+e+" buffer",t)}})),this._initSourceBuffer()},e.onBufferCodecs=function(t,e){var r=this,i=this.getSourceBufferTypes().length;Object.keys(e).forEach((function(t){if(i){var n=r.tracks[t];if(n&&"function"==typeof n.buffer.changeType){var s=e[t],o=s.id,l=s.codec,u=s.levelCodec,d=s.container,c=s.metadata,f=(n.levelCodec||n.codec).replace(h,"$1"),g=(u||l).replace(h,"$1");if(f!==g){var v=d+";codecs="+(u||l);r.appendChangeType(t,v),a.logger.log("[buffer-controller]: switching codec "+f+" to "+g),r.tracks[t]={buffer:n.buffer,codec:l,container:d,levelCodec:u,metadata:c,id:o}}}}else r.pendingTracks[t]=e[t]})),i||(this.bufferCodecEventsExpected=Math.max(this.bufferCodecEventsExpected-1,0),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks())},e.appendChangeType=function(t,e){var r=this,i=this.operationQueue,n={execute:function(){var n=r.sourceBuffer[t];n&&(a.logger.log("[buffer-controller]: changing "+t+" sourceBuffer type to "+e),n.changeType(e)),i.shiftAndExecuteNext(t)},onStart:function(){},onComplete:function(){},onError:function(e){a.logger.warn("[buffer-controller]: Failed to change "+t+" SourceBuffer type",e)}};i.append(n,t)},e.onBufferAppending=function(t,e){var r=this,i=this.hls,l=this.operationQueue,u=this.tracks,d=e.data,c=e.type,h=e.frag,f=e.part,g=e.chunkMeta,v=g.buffering[c],p=self.performance.now();v.start=p;var m=h.stats.buffering,y=f?f.stats.buffering:null;0===m.start&&(m.start=p),y&&0===y.start&&(y.start=p);var E=u.audio,T="audio"===c&&1===g.id&&"audio/mpeg"===(null==E?void 0:E.container),S={execute:function(){if(v.executeStart=self.performance.now(),T){var t=r.sourceBuffer[c];if(t){var e=h.start-t.timestampOffset;Math.abs(e)>=.1&&(a.logger.log("[buffer-controller]: Updating audio SourceBuffer timestampOffset to "+h.start+" (delta: "+e+") sn: "+h.sn+")"),t.timestampOffset=h.start)}}r.appendExecutor(d,c)},onStart:function(){},onComplete:function(){var t=self.performance.now();v.executeEnd=v.end=t,0===m.first&&(m.first=t),y&&0===y.first&&(y.first=t);var e=r.sourceBuffer,i={};for(var a in e)i[a]=o.BufferHelper.getBuffered(e[a]);r.appendError=0,r.hls.trigger(n.Events.BUFFER_APPENDED,{type:c,frag:h,part:f,chunkMeta:g,parent:h.type,timeRanges:i})},onError:function(t){a.logger.error("[buffer-controller]: Error encountered while trying to append to the "+c+" SourceBuffer",t);var e={type:s.ErrorTypes.MEDIA_ERROR,parent:h.type,details:s.ErrorDetails.BUFFER_APPEND_ERROR,err:t,fatal:!1};t.code===DOMException.QUOTA_EXCEEDED_ERR?e.details=s.ErrorDetails.BUFFER_FULL_ERROR:(r.appendError++,e.details=s.ErrorDetails.BUFFER_APPEND_ERROR,r.appendError>i.config.appendErrorMaxRetry&&(a.logger.error("[buffer-controller]: Failed "+i.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),e.fatal=!0,i.stopLoad())),i.trigger(n.Events.ERROR,e)}};l.append(S,c)},e.onBufferFlushing=function(t,e){var r=this,i=this.operationQueue,s=function(t){return{execute:r.removeExecutor.bind(r,t,e.startOffset,e.endOffset),onStart:function(){},onComplete:function(){r.hls.trigger(n.Events.BUFFER_FLUSHED,{type:t})},onError:function(e){a.logger.warn("[buffer-controller]: Failed to remove from "+t+" SourceBuffer",e)}}};e.type?i.append(s(e.type),e.type):this.getSourceBufferTypes().forEach((function(t){i.append(s(t),t)}))},e.onFragParsed=function(t,e){var r=this,i=e.frag,s=e.part,o=[],l=s?s.elementaryStreams:i.elementaryStreams;l[u.ElementaryStreamTypes.AUDIOVIDEO]?o.push("audiovideo"):(l[u.ElementaryStreamTypes.AUDIO]&&o.push("audio"),l[u.ElementaryStreamTypes.VIDEO]&&o.push("video")),0===o.length&&a.logger.warn("Fragments must have at least one ElementaryStreamType set. type: "+i.type+" level: "+i.level+" sn: "+i.sn),this.blockBuffers((function(){var t=self.performance.now();i.stats.buffering.end=t,s&&(s.stats.buffering.end=t);var e=s?s.stats:i.stats;r.hls.trigger(n.Events.FRAG_BUFFERED,{frag:i,part:s,stats:e,id:i.type})}),o)},e.onFragChanged=function(t,e){this.flushBackBuffer()},e.onBufferEos=function(t,e){var r=this;this.getSourceBufferTypes().reduce((function(t,i){var n=r.sourceBuffer[i];return e.type&&e.type!==i||n&&!n.ended&&(n.ended=!0,a.logger.log("[buffer-controller]: "+i+" sourceBuffer now EOS")),t&&!(n&&!n.ended)}),!0)&&this.blockBuffers((function(){var t=r.mediaSource;t&&"open"===t.readyState&&t.endOfStream()}))},e.onLevelUpdated=function(t,e){var r=e.details;r.fragments.length&&(this.details=r,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())},e.flushBackBuffer=function(){var t=this.hls,e=this.details,r=this.media,a=this.sourceBuffer;if(r&&null!==e){var s=this.getSourceBufferTypes();if(s.length){var l=e.live&&null!==t.config.liveBackBufferLength?t.config.liveBackBufferLength:t.config.backBufferLength;if(Object(i.isFiniteNumber)(l)&&!(l<0)){var u=r.currentTime,d=e.levelTargetDuration,c=Math.max(l,d),h=Math.floor(u/d)*d-c;s.forEach((function(r){var i=a[r];if(i){var s=o.BufferHelper.getBuffered(i);s.length>0&&h>s.start(0)&&(t.trigger(n.Events.BACK_BUFFER_REACHED,{bufferEnd:h}),e.live&&t.trigger(n.Events.LIVE_BACK_BUFFER_REACHED,{bufferEnd:h}),t.trigger(n.Events.BUFFER_FLUSHING,{startOffset:0,endOffset:h,type:r}))}}))}}}},e.updateMediaElementDuration=function(){if(this.details&&this.media&&this.mediaSource&&"open"===this.mediaSource.readyState){var t=this.details,e=this.hls,r=this.media,n=this.mediaSource,s=t.fragments[0].start+t.totalduration,o=r.duration,l=Object(i.isFiniteNumber)(n.duration)?n.duration:0;t.live&&e.config.liveDurationInfinity?(a.logger.log("[buffer-controller]: Media Source duration is set to Infinity"),n.duration=1/0,this.updateSeekableRange(t)):(s>l&&s>o||!Object(i.isFiniteNumber)(o))&&(a.logger.log("[buffer-controller]: Updating Media Source duration to "+s.toFixed(3)),n.duration=s)}},e.updateSeekableRange=function(t){var e=this.mediaSource,r=t.fragments;if(r.length&&t.live&&null!=e&&e.setLiveSeekableRange){var i=Math.max(0,r[0].start),n=Math.max(i,i+t.totalduration);e.setLiveSeekableRange(i,n)}},e.checkPendingTracks=function(){var t=this.bufferCodecEventsExpected,e=this.operationQueue,r=this.pendingTracks,i=Object.keys(r).length;if(i&&!t||2===i){this.createSourceBuffers(r),this.pendingTracks={};var a=this.getSourceBufferTypes();if(0===a.length)return void this.hls.trigger(n.Events.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,reason:"could not create source buffer for media codec(s)"});a.forEach((function(t){e.executeNext(t)}))}},e.createSourceBuffers=function(t){var e=this.sourceBuffer,r=this.mediaSource;if(!r)throw Error("createSourceBuffers called when mediaSource was null");var i=0;for(var o in t)if(!e[o]){var l=t[o];if(!l)throw Error("source buffer exists for track "+o+", however track does not");var u=l.levelCodec||l.codec,d=l.container+";codecs="+u;a.logger.log("[buffer-controller]: creating sourceBuffer("+d+")");try{var c=e[o]=r.addSourceBuffer(d),h=o;this.addBufferListener(h,"updatestart",this._onSBUpdateStart),this.addBufferListener(h,"updateend",this._onSBUpdateEnd),this.addBufferListener(h,"error",this._onSBUpdateError),this.tracks[o]={buffer:c,codec:u,container:l.container,levelCodec:l.levelCodec,metadata:l.metadata,id:l.id},i++}catch(t){a.logger.error("[buffer-controller]: error while trying to add sourceBuffer: "+t.message),this.hls.trigger(n.Events.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:t,mimeType:d})}}i&&this.hls.trigger(n.Events.BUFFER_CREATED,{tracks:this.tracks})},e._onSBUpdateStart=function(t){this.operationQueue.current(t).onStart()},e._onSBUpdateEnd=function(t){var e=this.operationQueue;e.current(t).onComplete(),e.shiftAndExecuteNext(t)},e._onSBUpdateError=function(t,e){a.logger.error("[buffer-controller]: "+t+" SourceBuffer error",e),this.hls.trigger(n.Events.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1});var r=this.operationQueue.current(t);r&&r.onError(e)},e.removeExecutor=function(t,e,r){var n=this.media,s=this.mediaSource,o=this.operationQueue,l=this.sourceBuffer[t];if(!n||!s||!l)return a.logger.warn("[buffer-controller]: Attempting to remove from the "+t+" SourceBuffer, but it does not exist"),void o.shiftAndExecuteNext(t);var u=Object(i.isFiniteNumber)(n.duration)?n.duration:1/0,d=Object(i.isFiniteNumber)(s.duration)?s.duration:1/0,c=Math.max(0,e),h=Math.min(r,u,d);h>c?(a.logger.log("[buffer-controller]: Removing ["+c+","+h+"] from the "+t+" SourceBuffer"),console.assert(!l.updating,t+" sourceBuffer must not be updating"),l.remove(c,h)):o.shiftAndExecuteNext(t)},e.appendExecutor=function(t,e){var r=this.operationQueue,i=this.sourceBuffer[e];if(!i)return a.logger.warn("[buffer-controller]: Attempting to append to the "+e+" SourceBuffer, but it does not exist"),void r.shiftAndExecuteNext(e);i.ended=!1,console.assert(!i.updating,e+" sourceBuffer must not be updating"),i.appendBuffer(t)},e.blockBuffers=function(t,e){var r=this;if(void 0===e&&(e=this.getSourceBufferTypes()),!e.length)return a.logger.log("[buffer-controller]: Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(t);var i=this.operationQueue,n=e.map((function(t){return i.appendBlocker(t)}));Promise.all(n).then((function(){t(),e.forEach((function(t){var e=r.sourceBuffer[t];e&&e.updating||i.shiftAndExecuteNext(t)}))}))},e.getSourceBufferTypes=function(){return Object.keys(this.sourceBuffer)},e.addBufferListener=function(t,e,r){var i=this.sourceBuffer[t];if(i){var n=r.bind(this,t);this.listeners[t].push({event:e,listener:n}),i.addEventListener(e,n)}},e.removeBufferListeners=function(t){var e=this.sourceBuffer[t];e&&this.listeners[t].forEach((function(t){e.removeEventListener(t.event,t.listener)}))},t}()},"./src/controller/buffer-operation-queue.ts":
42
42
  /*!**************************************************!*\
43
43
  !*** ./src/controller/buffer-operation-queue.ts ***!
44
44
  \**************************************************/
@@ -82,7 +82,7 @@
82
82
  /*!********************************************!*\
83
83
  !*** ./src/controller/level-controller.ts ***!
84
84
  \********************************************/
85
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return g}));var i=r(/*! ../types/level */"./src/types/level.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../utils/codecs */"./src/utils/codecs.ts"),o=r(/*! ./level-helper */"./src/controller/level-helper.ts"),l=r(/*! ./base-playlist-controller */"./src/controller/base-playlist-controller.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts");function d(){return(d=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function c(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function h(t,e){return(h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var f=/chrome|firefox/.test(navigator.userAgent.toLowerCase()),g=function(t){var e,r;function l(e){var r;return(r=t.call(this,e,"[level-controller]")||this)._levels=[],r._firstLevel=-1,r._startLevel=void 0,r.currentLevelIndex=-1,r.manualLevelIndex=-1,r.onParsedComplete=void 0,r._registerListeners(),r}r=t,(e=l).prototype=Object.create(r.prototype),e.prototype.constructor=e,h(e,r);var g,v,p,m=l.prototype;return m._registerListeners=function(){var t=this.hls;t.on(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(n.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(n.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.on(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.on(n.Events.ERROR,this.onError,this)},m._unregisterListeners=function(){var t=this.hls;t.off(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(n.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(n.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.off(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.off(n.Events.ERROR,this.onError,this)},m.destroy=function(){this._unregisterListeners(),this.manualLevelIndex=-1,this._levels.length=0,t.prototype.destroy.call(this)},m.startLoad=function(){this._levels.forEach((function(t){t.loadError=0})),t.prototype.startLoad.call(this)},m.onManifestLoaded=function(t,e){var r,l,u=[],d=[],c=[],h={},g=!1,v=!1,p=!1;if(e.levels.forEach((function(t){var e=t.attrs;g=g||!(!t.width||!t.height),v=v||!!t.videoCodec,p=p||!!t.audioCodec,f&&t.audioCodec&&-1!==t.audioCodec.indexOf("mp4a.40.34")&&(t.audioCodec=void 0);var r=t.bitrate+"-"+t.attrs.RESOLUTION+"-"+t.attrs.CODECS;(l=h[r])?l.url.push(t.url):(l=new i.Level(t),h[r]=l,u.push(l)),e&&(e.AUDIO&&Object(o.addGroupId)(l,"audio",e.AUDIO),e.SUBTITLES&&Object(o.addGroupId)(l,"text",e.SUBTITLES))})),(g||v)&&p&&(u=u.filter((function(t){var e=t.videoCodec,r=t.width,i=t.height;return!!e||!(!r||!i)}))),u=u.filter((function(t){var e=t.audioCodec,r=t.videoCodec;return(!e||Object(s.isCodecSupportedInMp4)(e,"audio"))&&(!r||Object(s.isCodecSupportedInMp4)(r,"video"))})),e.audioTracks&&(d=e.audioTracks.filter((function(t){return!t.audioCodec||Object(s.isCodecSupportedInMp4)(t.audioCodec,"audio")})),Object(o.assignTrackIdsByGroup)(d)),e.subtitles&&(c=e.subtitles,Object(o.assignTrackIdsByGroup)(c)),u.length>0){r=u[0].bitrate,u.sort((function(t,e){return t.bitrate-e.bitrate})),this._levels=u;for(var m=0;m<u.length;m++)if(u[m].bitrate===r){this._firstLevel=m,this.log("manifest loaded, "+u.length+" level(s) found, first bitrate: "+r);break}var y=p&&!v,E={levels:u,audioTracks:d,subtitleTracks:c,firstLevel:this._firstLevel,stats:e.stats,audio:p,video:v,altAudio:!y&&d.some((function(t){return!!t.url}))};this.hls.trigger(n.Events.MANIFEST_PARSED,E),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}else this.hls.trigger(n.Events.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:e.url,reason:"no level with compatible codecs found in manifest"})},m.onError=function(e,r){if(t.prototype.onError.call(this,e,r),!r.fatal){var i=r.context,n=this._levels[this.currentLevelIndex];if(i&&(i.type===u.PlaylistContextType.AUDIO_TRACK&&n.audioGroupIds&&i.groupId===n.audioGroupIds[n.urlId]||i.type===u.PlaylistContextType.SUBTITLE_TRACK&&n.textGroupIds&&i.groupId===n.textGroupIds[n.urlId]))this.redundantFailover(this.currentLevelIndex);else{var s,o=!1,l=!0;switch(r.details){case a.ErrorDetails.FRAG_LOAD_ERROR:case a.ErrorDetails.FRAG_LOAD_TIMEOUT:case a.ErrorDetails.KEY_LOAD_ERROR:case a.ErrorDetails.KEY_LOAD_TIMEOUT:if(r.frag){var d=this._levels[r.frag.level];d?(d.fragmentError++,d.fragmentError>this.hls.config.fragLoadingMaxRetry&&(s=r.frag.level)):s=r.frag.level}break;case a.ErrorDetails.LEVEL_LOAD_ERROR:case a.ErrorDetails.LEVEL_LOAD_TIMEOUT:i&&(i.deliveryDirectives&&(l=!1),s=i.level),o=!0;break;case a.ErrorDetails.REMUX_ALLOC_ERROR:s=r.level,o=!0}void 0!==s&&this.recoverLevel(r,s,o,l)}}},m.recoverLevel=function(t,e,r,i){var n=t.details,a=this._levels[e];if(a.loadError++,r){if(!this.retryLoadingOrFail(t))return void(this.currentLevelIndex=-1);t.levelRetry=!0}if(i){var s=a.url.length;if(s>1&&a.loadError<s)t.levelRetry=!0,this.redundantFailover(e);else if(-1===this.manualLevelIndex){var o=0===e?this._levels.length-1:e-1;this.currentLevelIndex!==o&&0===this._levels[o].loadError&&(this.warn(n+": switch to "+o),t.levelRetry=!0,this.hls.nextAutoLevel=o)}}},m.redundantFailover=function(t){var e=this._levels[t],r=e.url.length;if(r>1){var i=(e.urlId+1)%r;this.warn("Switching to redundant URL-id "+i),this._levels.forEach((function(t){t.urlId=i})),this.level=t}},m.onFragLoaded=function(t,e){var r=e.frag;if(void 0!==r&&r.type===u.PlaylistLevelType.MAIN){var i=this._levels[r.level];void 0!==i&&(i.fragmentError=0,i.loadError=0)}},m.onLevelLoaded=function(t,e){var r,i,n=e.level,a=e.details,s=this._levels[n];if(!s)return this.warn("Invalid level index "+n),void(null!==(i=e.deliveryDirectives)&&void 0!==i&&i.skip&&(a.deltaUpdateFailed=!0));n===this.currentLevelIndex?(0===s.fragmentError&&(s.loadError=0,this.retryCount=0),this.playlistLoaded(n,e,s.details)):null!==(r=e.deliveryDirectives)&&void 0!==r&&r.skip&&(a.deltaUpdateFailed=!0)},m.onAudioTrackSwitched=function(t,e){var r=this.hls.levels[this.currentLevelIndex];if(r&&r.audioGroupIds){for(var i=-1,n=this.hls.audioTracks[e.id].groupId,a=0;a<r.audioGroupIds.length;a++)if(r.audioGroupIds[a]===n){i=a;break}i!==r.urlId&&(r.urlId=i,this.startLoad())}},m.loadPlaylist=function(t){var e=this.currentLevelIndex,r=this._levels[e];if(this.canLoad&&r&&r.url.length>0){var i=r.urlId,a=r.url[i];if(t)try{a=t.addDirectives(a)}catch(t){this.warn("Could not construct new URL with HLS Delivery Directives: "+t)}this.log("Attempt loading level index "+e+(t?" at sn "+t.msn+" part "+t.part:"")+" with URL-id "+i+" "+a),this.clearTimer(),this.hls.trigger(n.Events.LEVEL_LOADING,{url:a,level:e,id:i,deliveryDirectives:t||null})}},m.removeLevel=function(t,e){var r=function(t,r){return r!==e},i=this._levels.filter((function(i,n){return n!==t||i.url.length>1&&void 0!==e&&(i.url=i.url.filter(r),i.audioGroupIds&&(i.audioGroupIds=i.audioGroupIds.filter(r)),i.textGroupIds&&(i.textGroupIds=i.textGroupIds.filter(r)),i.urlId=0,!0)})).map((function(t,e){var r=t.details;return null!=r&&r.fragments&&r.fragments.forEach((function(t){t.level=e})),t}));this._levels=i,this.hls.trigger(n.Events.LEVELS_UPDATED,{levels:i})},g=l,(v=[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(t){var e,r=this._levels;if(0!==r.length&&(this.currentLevelIndex!==t||null===(e=r[t])||void 0===e||!e.details)){if(t<0||t>=r.length){var i=t<0;if(this.hls.trigger(n.Events.ERROR,{type:a.ErrorTypes.OTHER_ERROR,details:a.ErrorDetails.LEVEL_SWITCH_ERROR,level:t,fatal:i,reason:"invalid level idx"}),i)return;t=Math.min(t,r.length-1)}this.clearTimer();var s=this.currentLevelIndex,o=r[s],l=r[t];this.log("switching to level "+t+" from "+s),this.currentLevelIndex=t;var u=d({},l,{level:t,maxBitrate:l.maxBitrate,uri:l.uri,urlId:l.urlId});delete u._urlId,this.hls.trigger(n.Events.LEVEL_SWITCHING,u);var c=l.details;if(!c||c.live){var h=this.switchParams(l.uri,null==o?void 0:o.details);this.loadPlaylist(h)}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(t){this.manualLevelIndex=t,void 0===this._startLevel&&(this._startLevel=t),-1!==t&&(this.level=t)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(t){this._firstLevel=t}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var t=this.hls.config.startLevel;return void 0!==t?t:this._firstLevel}return this._startLevel},set:function(t){this._startLevel=t}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(t){this.level=t,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=t)}}])&&c(g.prototype,v),p&&c(g,p),Object.defineProperty(g,"prototype",{writable:!1}),l}(l.default)},"./src/controller/level-helper.ts":
85
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return g}));var i=r(/*! ../types/level */"./src/types/level.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../utils/codecs */"./src/utils/codecs.ts"),o=r(/*! ./level-helper */"./src/controller/level-helper.ts"),l=r(/*! ./base-playlist-controller */"./src/controller/base-playlist-controller.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts");function d(){return(d=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function c(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function h(t,e){return(h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var f=/chrome|firefox/.test(navigator.userAgent.toLowerCase()),g=function(t){var e,r;function l(e){var r;return(r=t.call(this,e,"[level-controller]")||this)._levels=[],r._firstLevel=-1,r._startLevel=void 0,r.currentLevelIndex=-1,r.manualLevelIndex=-1,r.onParsedComplete=void 0,r._registerListeners(),r}r=t,(e=l).prototype=Object.create(r.prototype),e.prototype.constructor=e,h(e,r);var g,v,p,m=l.prototype;return m._registerListeners=function(){var t=this.hls;t.on(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(n.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(n.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.on(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.on(n.Events.ERROR,this.onError,this)},m._unregisterListeners=function(){var t=this.hls;t.off(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(n.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(n.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.off(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.off(n.Events.ERROR,this.onError,this)},m.destroy=function(){this._unregisterListeners(),this.manualLevelIndex=-1,this._levels.length=0,t.prototype.destroy.call(this)},m.startLoad=function(){this._levels.forEach((function(t){t.loadError=0})),t.prototype.startLoad.call(this)},m.onManifestLoaded=function(t,e){var r,l,u=[],d=[],c=[],h={},g=!1,v=!1,p=!1;if(e.levels.forEach((function(t){var e=t.attrs;g=g||!(!t.width||!t.height),v=v||!!t.videoCodec,p=p||!!t.audioCodec,f&&t.audioCodec&&-1!==t.audioCodec.indexOf("mp4a.40.34")&&(t.audioCodec=void 0);var r=t.bitrate+"-"+t.attrs.RESOLUTION+"-"+t.attrs.CODECS;(l=h[r])?l.url.push(t.url):(l=new i.Level(t),h[r]=l,u.push(l)),e&&(e.AUDIO&&Object(o.addGroupId)(l,"audio",e.AUDIO),e.SUBTITLES&&Object(o.addGroupId)(l,"text",e.SUBTITLES))})),(g||v)&&p&&(u=u.filter((function(t){var e=t.videoCodec,r=t.width,i=t.height;return!!e||!(!r||!i)}))),u=u.filter((function(t){var e=t.audioCodec,r=t.videoCodec;return(!e||Object(s.isCodecSupportedInMp4)(e,"audio"))&&(!r||Object(s.isCodecSupportedInMp4)(r,"video"))})),e.audioTracks&&(d=e.audioTracks.filter((function(t){return!t.audioCodec||Object(s.isCodecSupportedInMp4)(t.audioCodec,"audio")})),Object(o.assignTrackIdsByGroup)(d)),e.subtitles&&(c=e.subtitles,Object(o.assignTrackIdsByGroup)(c)),u.length>0){r=u[0].bitrate,u.sort((function(t,e){return t.bitrate-e.bitrate})),this._levels=u;for(var m=0;m<u.length;m++)if(u[m].bitrate===r){this._firstLevel=m,this.log("manifest loaded, "+u.length+" level(s) found, first bitrate: "+r);break}var y=p&&!v,E={levels:u,audioTracks:d,subtitleTracks:c,firstLevel:this._firstLevel,stats:e.stats,audio:p,video:v,altAudio:!y&&d.some((function(t){return!!t.url}))};this.hls.trigger(n.Events.MANIFEST_PARSED,E),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}else this.hls.trigger(n.Events.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:e.url,reason:"no level with compatible codecs found in manifest"})},m.onError=function(e,r){var i;if(t.prototype.onError.call(this,e,r),!r.fatal){var n=r.context,s=this._levels[this.currentLevelIndex];if(n&&(n.type===u.PlaylistContextType.AUDIO_TRACK&&s.audioGroupIds&&n.groupId===s.audioGroupIds[s.urlId]||n.type===u.PlaylistContextType.SUBTITLE_TRACK&&s.textGroupIds&&n.groupId===s.textGroupIds[s.urlId]))this.redundantFailover(this.currentLevelIndex);else{var o,l=!1,d=!0;switch(r.details){case a.ErrorDetails.FRAG_LOAD_ERROR:case a.ErrorDetails.FRAG_LOAD_TIMEOUT:case a.ErrorDetails.KEY_LOAD_ERROR:case a.ErrorDetails.KEY_LOAD_TIMEOUT:if(r.frag){var c=r.frag.type===u.PlaylistLevelType.MAIN?r.frag.level:this.currentLevelIndex,h=this._levels[c];h?(h.fragmentError++,h.fragmentError>this.hls.config.fragLoadingMaxRetry&&(o=c)):o=c}break;case a.ErrorDetails.LEVEL_LOAD_ERROR:case a.ErrorDetails.LEVEL_LOAD_TIMEOUT:n&&(n.deliveryDirectives&&(d=!1),o=n.level),l=!0;break;case a.ErrorDetails.REMUX_ALLOC_ERROR:o=null!=(i=r.level)?i:this.currentLevelIndex,l=!0}void 0!==o&&this.recoverLevel(r,o,l,d)}}},m.recoverLevel=function(t,e,r,i){var n=t.details,a=this._levels[e];if(a.loadError++,r){if(!this.retryLoadingOrFail(t))return void(this.currentLevelIndex=-1);t.levelRetry=!0}if(i){var s=a.url.length;if(s>1&&a.loadError<s)t.levelRetry=!0,this.redundantFailover(e);else if(-1===this.manualLevelIndex){for(var o=-1,l=this._levels,u=l.length;u--;){var d=(u+this.currentLevelIndex)%l.length;if(d!==this.currentLevelIndex&&0===l[d].loadError){o=d;break}}o>-1&&this.currentLevelIndex!==o&&(this.warn(n+": switch to "+o),t.levelRetry=!0,this.hls.nextAutoLevel=o)}}},m.redundantFailover=function(t){var e=this._levels[t],r=e.url.length;if(r>1){var i=(e.urlId+1)%r;this.warn("Switching to redundant URL-id "+i),this._levels.forEach((function(t){t.urlId=i})),this.level=t}},m.onFragLoaded=function(t,e){var r=e.frag;if(void 0!==r&&r.type===u.PlaylistLevelType.MAIN){var i=this._levels[r.level];void 0!==i&&(i.fragmentError=0,i.loadError=0)}},m.onLevelLoaded=function(t,e){var r,i,n=e.level,a=e.details,s=this._levels[n];if(!s)return this.warn("Invalid level index "+n),void(null!==(i=e.deliveryDirectives)&&void 0!==i&&i.skip&&(a.deltaUpdateFailed=!0));n===this.currentLevelIndex?(0===s.fragmentError&&(s.loadError=0,this.retryCount=0),this.playlistLoaded(n,e,s.details)):null!==(r=e.deliveryDirectives)&&void 0!==r&&r.skip&&(a.deltaUpdateFailed=!0)},m.onAudioTrackSwitched=function(t,e){var r=this.hls.levels[this.currentLevelIndex];if(r&&r.audioGroupIds){for(var i=-1,n=this.hls.audioTracks[e.id].groupId,a=0;a<r.audioGroupIds.length;a++)if(r.audioGroupIds[a]===n){i=a;break}i!==r.urlId&&(r.urlId=i,this.startLoad())}},m.loadPlaylist=function(t){var e=this.currentLevelIndex,r=this._levels[e];if(this.canLoad&&r&&r.url.length>0){var i=r.urlId,a=r.url[i];if(t)try{a=t.addDirectives(a)}catch(t){this.warn("Could not construct new URL with HLS Delivery Directives: "+t)}this.log("Attempt loading level index "+e+(t?" at sn "+t.msn+" part "+t.part:"")+" with URL-id "+i+" "+a),this.clearTimer(),this.hls.trigger(n.Events.LEVEL_LOADING,{url:a,level:e,id:i,deliveryDirectives:t||null})}},m.removeLevel=function(t,e){var r=function(t,r){return r!==e},i=this._levels.filter((function(i,n){return n!==t||i.url.length>1&&void 0!==e&&(i.url=i.url.filter(r),i.audioGroupIds&&(i.audioGroupIds=i.audioGroupIds.filter(r)),i.textGroupIds&&(i.textGroupIds=i.textGroupIds.filter(r)),i.urlId=0,!0)})).map((function(t,e){var r=t.details;return null!=r&&r.fragments&&r.fragments.forEach((function(t){t.level=e})),t}));this._levels=i,this.hls.trigger(n.Events.LEVELS_UPDATED,{levels:i})},g=l,(v=[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(t){var e,r=this._levels;if(0!==r.length&&(this.currentLevelIndex!==t||null===(e=r[t])||void 0===e||!e.details)){if(t<0||t>=r.length){var i=t<0;if(this.hls.trigger(n.Events.ERROR,{type:a.ErrorTypes.OTHER_ERROR,details:a.ErrorDetails.LEVEL_SWITCH_ERROR,level:t,fatal:i,reason:"invalid level idx"}),i)return;t=Math.min(t,r.length-1)}this.clearTimer();var s=this.currentLevelIndex,o=r[s],l=r[t];this.log("switching to level "+t+" from "+s),this.currentLevelIndex=t;var u=d({},l,{level:t,maxBitrate:l.maxBitrate,uri:l.uri,urlId:l.urlId});delete u._urlId,this.hls.trigger(n.Events.LEVEL_SWITCHING,u);var c=l.details;if(!c||c.live){var h=this.switchParams(l.uri,null==o?void 0:o.details);this.loadPlaylist(h)}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(t){this.manualLevelIndex=t,void 0===this._startLevel&&(this._startLevel=t),-1!==t&&(this.level=t)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(t){this._firstLevel=t}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var t=this.hls.config.startLevel;return void 0!==t?t:this._firstLevel}return this._startLevel},set:function(t){this._startLevel=t}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(t){this.level=t,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=t)}}])&&c(g.prototype,v),p&&c(g,p),Object.defineProperty(g,"prototype",{writable:!1}),l}(l.default)},"./src/controller/level-helper.ts":
86
86
  /*!****************************************!*\
87
87
  !*** ./src/controller/level-helper.ts ***!
88
88
  \****************************************/
@@ -90,11 +90,11 @@
90
90
  /*!*********************************************!*\
91
91
  !*** ./src/controller/stream-controller.ts ***!
92
92
  \*********************************************/
93
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return y}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./base-stream-controller */"./src/controller/base-stream-controller.ts"),a=r(/*! ../is-supported */"./src/is-supported.ts"),s=r(/*! ../events */"./src/events.ts"),o=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),l=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),c=r(/*! ../demux/transmuxer-interface */"./src/demux/transmuxer-interface.ts"),h=r(/*! ../types/transmuxer */"./src/types/transmuxer.ts"),f=r(/*! ./gap-controller */"./src/controller/gap-controller.ts"),g=r(/*! ../errors */"./src/errors.ts"),v=r(/*! ../utils/logger */"./src/utils/logger.ts");function p(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function m(t,e){return(m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var y=function(t){var e,r;function y(e,r){var i;return(i=t.call(this,e,r,"[stream-controller]")||this).audioCodecSwap=!1,i.gapController=null,i.level=-1,i._forceStartLoad=!1,i.altAudio=!1,i.audioOnly=!1,i.fragPlaying=null,i.onvplaying=null,i.onvseeked=null,i.fragLastKbps=0,i.stalled=!1,i.couldBacktrack=!1,i.backtrackFragment=null,i.audioCodecSwitch=!1,i.videoBuffer=null,i._registerListeners(),i}r=t,(e=y).prototype=Object.create(r.prototype),e.prototype.constructor=e,m(e,r);var E,T,S,b=y.prototype;return b._registerListeners=function(){var t=this.hls;t.on(s.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(s.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(s.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(s.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.on(s.Events.LEVEL_LOADING,this.onLevelLoading,this),t.on(s.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(s.Events.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.on(s.Events.ERROR,this.onError,this),t.on(s.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.on(s.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.on(s.Events.BUFFER_CREATED,this.onBufferCreated,this),t.on(s.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.on(s.Events.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(s.Events.FRAG_BUFFERED,this.onFragBuffered,this)},b._unregisterListeners=function(){var t=this.hls;t.off(s.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(s.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(s.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(s.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.off(s.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(s.Events.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.off(s.Events.ERROR,this.onError,this),t.off(s.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.off(s.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.off(s.Events.BUFFER_CREATED,this.onBufferCreated,this),t.off(s.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.off(s.Events.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(s.Events.FRAG_BUFFERED,this.onFragBuffered,this)},b.onHandlerDestroying=function(){this._unregisterListeners(),this.onMediaDetaching()},b.startLoad=function(t){if(this.levels){var e=this.lastCurrentTime,r=this.hls;if(this.stopLoad(),this.setInterval(100),this.level=-1,this.fragLoadError=0,!this.startFragRequested){var i=r.startLevel;-1===i&&(r.config.testBandwidth?(i=0,this.bitrateTest=!0):i=r.nextAutoLevel),this.level=r.nextLoadLevel=i,this.loadedmetadata=!1}e>0&&-1===t&&(this.log("Override startPosition with lastCurrentTime @"+e.toFixed(3)),t=e),this.state=n.State.IDLE,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}else this._forceStartLoad=!0,this.state=n.State.STOPPED},b.stopLoad=function(){this._forceStartLoad=!1,t.prototype.stopLoad.call(this)},b.doTick=function(){switch(this.state){case n.State.IDLE:this.doTickIdle();break;case n.State.WAITING_LEVEL:var t,e=this.levels,r=this.level,i=null==e||null===(t=e[r])||void 0===t?void 0:t.details;if(i&&(!i.live||this.levelLastLoaded===this.level)){if(this.waitForCdnTuneIn(i))break;this.state=n.State.IDLE;break}break;case n.State.FRAG_LOADING_WAITING_RETRY:var a,s=self.performance.now(),o=this.retryDate;(!o||s>=o||null!==(a=this.media)&&void 0!==a&&a.seeking)&&(this.log("retryDate reached, switch back to IDLE state"),this.state=n.State.IDLE)}this.onTickEnd()},b.onTickEnd=function(){t.prototype.onTickEnd.call(this),this.checkBuffer(),this.checkFragmentChanged()},b.doTickIdle=function(){var t,e,r=this.hls,i=this.levelLastLoaded,a=this.levels,o=this.media,c=r.config,h=r.nextLoadLevel;if(null!==i&&(o||!this.startFragRequested&&c.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)&&a&&a[h]){var f=a[h];this.level=r.nextLoadLevel=h;var g=f.details;if(!g||this.state===n.State.WAITING_LEVEL||g.live&&this.levelLastLoaded!==h)this.state=n.State.WAITING_LEVEL;else{var v=this.getMainFwdBufferInfo();if(null!==v&&!(v.len>=this.getMaxBufferLength(f.maxBitrate))){if(this._streamEnded(v,g)){var p={};return this.altAudio&&(p.type="video"),this.hls.trigger(s.Events.BUFFER_EOS,p),void(this.state=n.State.ENDED)}this.backtrackFragment&&this.backtrackFragment.start>v.end&&(this.backtrackFragment=null);var m=this.backtrackFragment?this.backtrackFragment.start:v.end,y=this.getNextFragment(m,g);if(this.couldBacktrack&&!this.fragPrevious&&y&&"initSegment"!==y.sn&&this.fragmentTracker.getState(y)!==l.FragmentState.OK){var E,T=(null!=(E=this.backtrackFragment)?E:y).sn-g.startSN,S=g.fragments[T-1];S&&y.cc===S.cc&&(y=S,this.fragmentTracker.removeFragment(S))}else this.backtrackFragment&&v.len&&(this.backtrackFragment=null);if(y&&this.fragmentTracker.getState(y)===l.FragmentState.OK&&this.nextLoadPosition>m){var b=this.audioOnly&&!this.altAudio?d.ElementaryStreamTypes.AUDIO:d.ElementaryStreamTypes.VIDEO;this.afterBufferFlushed(o,b,u.PlaylistLevelType.MAIN),y=this.getNextFragment(this.nextLoadPosition,g)}y&&(!y.initSegment||y.initSegment.data||this.bitrateTest||(y=y.initSegment),"identity"!==(null===(t=y.decryptdata)||void 0===t?void 0:t.keyFormat)||null!==(e=y.decryptdata)&&void 0!==e&&e.key?this.loadFragment(y,g,m):this.loadKey(y,g))}}}},b.loadFragment=function(e,r,i){var n,a=this.fragmentTracker.getState(e);this.fragCurrent=e,a===l.FragmentState.NOT_LOADED||a===l.FragmentState.PARTIAL?"initSegment"===e.sn?this._loadInitSegment(e):this.bitrateTest?(e.bitrateTest=!0,this.log("Fragment "+e.sn+" of level "+e.level+" is being downloaded to test bitrate and will not be buffered"),this._loadBitrateTestFrag(e)):(this.startFragRequested=!0,t.prototype.loadFragment.call(this,e,r,i)):a===l.FragmentState.APPENDING?this.reduceMaxBufferLength(e.duration)&&this.fragmentTracker.removeFragment(e):0===(null===(n=this.media)||void 0===n?void 0:n.buffered.length)&&this.fragmentTracker.removeAllFragments()},b.getAppendedFrag=function(t){var e=this.fragmentTracker.getAppendedFrag(t,u.PlaylistLevelType.MAIN);return e&&"fragment"in e?e.fragment:e},b.getBufferedFrag=function(t){return this.fragmentTracker.getBufferedFrag(t,u.PlaylistLevelType.MAIN)},b.followingBufferedFrag=function(t){return t?this.getBufferedFrag(t.end+.5):null},b.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},b.nextLevelSwitch=function(){var t=this.levels,e=this.media;if(null!=e&&e.readyState){var r,i=this.getAppendedFrag(e.currentTime);if(i&&i.start>1&&this.flushMainBuffer(0,i.start-1),!e.paused&&t){var n=t[this.hls.nextLoadLevel],a=this.fragLastKbps;r=a&&this.fragCurrent?this.fragCurrent.duration*n.maxBitrate/(1e3*a)+1:0}else r=0;var s=this.getBufferedFrag(e.currentTime+r);if(s){var o=this.followingBufferedFrag(s);if(o){this.abortCurrentFrag();var l=o.maxStartPTS?o.maxStartPTS:o.start,u=o.duration,d=Math.max(s.end,l+Math.min(Math.max(u-this.config.maxFragLookUpTolerance,.5*u),.75*u));this.flushMainBuffer(d,Number.POSITIVE_INFINITY)}}}},b.abortCurrentFrag=function(){var t=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,null!=t&&t.loader&&t.loader.abort(),this.state){case n.State.KEY_LOADING:case n.State.FRAG_LOADING:case n.State.FRAG_LOADING_WAITING_RETRY:case n.State.PARSING:case n.State.PARSED:this.state=n.State.IDLE}this.nextLoadPosition=this.getLoadPosition()},b.flushMainBuffer=function(e,r){t.prototype.flushMainBuffer.call(this,e,r,this.altAudio?"video":null)},b.onMediaAttached=function(e,r){t.prototype.onMediaAttached.call(this,e,r);var i=r.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),i.addEventListener("playing",this.onvplaying),i.addEventListener("seeked",this.onvseeked),this.gapController=new f.default(this.config,i,this.fragmentTracker,this.hls)},b.onMediaDetaching=function(){var e=this.media;e&&(e.removeEventListener("playing",this.onvplaying),e.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),t.prototype.onMediaDetaching.call(this)},b.onMediaPlaying=function(){this.tick()},b.onMediaSeeked=function(){var t=this.media,e=t?t.currentTime:null;Object(i.isFiniteNumber)(e)&&this.log("Media seeked to "+e.toFixed(3)),this.tick()},b.onManifestLoading=function(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(s.Events.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=this.stalled=!1,this.startPosition=this.lastCurrentTime=0,this.fragPlaying=null,this.backtrackFragment=null},b.onManifestParsed=function(t,e){var r,i=!1,n=!1;e.levels.forEach((function(t){(r=t.audioCodec)&&(-1!==r.indexOf("mp4a.40.2")&&(i=!0),-1!==r.indexOf("mp4a.40.5")&&(n=!0))})),this.audioCodecSwitch=i&&n&&!Object(a.changeTypeSupported)(),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},b.onLevelLoading=function(t,e){var r=this.levels;if(r&&this.state===n.State.IDLE){var i=r[e.level];(!i.details||i.details.live&&this.levelLastLoaded!==e.level||this.waitForCdnTuneIn(i.details))&&(this.state=n.State.WAITING_LEVEL)}},b.onLevelLoaded=function(t,e){var r,i=this.levels,a=e.level,o=e.details,l=o.totalduration;if(i){this.log("Level "+a+" loaded ["+o.startSN+","+o.endSN+"], cc ["+o.startCC+", "+o.endCC+"] duration:"+l);var u=this.fragCurrent;!u||this.state!==n.State.FRAG_LOADING&&this.state!==n.State.FRAG_LOADING_WAITING_RETRY||u.level!==e.level&&u.loader&&(this.state=n.State.IDLE,this.backtrackFragment=null,u.loader.abort());var d=i[a],c=0;if(o.live||null!==(r=d.details)&&void 0!==r&&r.live){if(o.fragments[0]||(o.deltaUpdateFailed=!0),o.deltaUpdateFailed)return;c=this.alignPlaylists(o,d.details)}if(d.details=o,this.levelLastLoaded=a,this.hls.trigger(s.Events.LEVEL_UPDATED,{details:o,level:a}),this.state===n.State.WAITING_LEVEL){if(this.waitForCdnTuneIn(o))return;this.state=n.State.IDLE}this.startFragRequested?o.live&&this.synchronizeToLiveEdge(o):this.setStartPosition(o,c),this.tick()}else this.warn("Levels were reset while loading level "+a)},b._handleFragmentLoadProgress=function(t){var e,r=t.frag,i=t.part,n=t.payload,a=this.levels;if(a){var s=a[r.level],o=s.details;if(o){var l=s.videoCodec,d=o.PTSKnown||!o.live,f=null===(e=r.initSegment)||void 0===e?void 0:e.data,g=this._getAudioCodec(s),v=this.transmuxer=this.transmuxer||new c.default(this.hls,u.PlaylistLevelType.MAIN,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),p=i?i.index:-1,m=-1!==p,y=new h.ChunkMetadata(r.level,r.sn,r.stats.chunkCount,n.byteLength,p,m),E=this.initPTS[r.cc];v.push(n,f,g,l,r,i,o.totalduration,d,y,E)}else this.warn("Dropping fragment "+r.sn+" of level "+r.level+" after level details were reset")}else this.warn("Levels were reset while fragment load was in progress. Fragment "+r.sn+" of level "+r.level+" will not be buffered")},b.onAudioTrackSwitching=function(t,e){var r=this.altAudio,i=!!e.url,n=e.id;if(!i){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var a=this.fragCurrent;null!=a&&a.loader&&(this.log("Switching to main audio track, cancel main fragment load"),a.loader.abort()),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();var o=this.hls;r&&o.trigger(s.Events.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:"audio"}),o.trigger(s.Events.AUDIO_TRACK_SWITCHED,{id:n})}},b.onAudioTrackSwitched=function(t,e){var r=e.id,i=!!this.hls.audioTracks[r].url;if(i){var n=this.videoBuffer;n&&this.mediaBuffer!==n&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=n)}this.altAudio=i,this.tick()},b.onBufferCreated=function(t,e){var r,i,n=e.tracks,a=!1;for(var s in n){var o=n[s];if("main"===o.id){if(i=s,r=o,"video"===s){var l=n[s];l&&(this.videoBuffer=l.buffer)}}else a=!0}a&&r?(this.log("Alternate track found, use "+i+".buffered to schedule main fragment loading"),this.mediaBuffer=r.buffer):this.mediaBuffer=this.media},b.onFragBuffered=function(t,e){var r=e.frag,i=e.part;if(!r||r.type===u.PlaylistLevelType.MAIN){if(this.fragContextChanged(r))return this.warn("Fragment "+r.sn+(i?" p: "+i.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state),void(this.state===n.State.PARSED&&(this.state=n.State.IDLE));var a=i?i.stats:r.stats;this.fragLastKbps=Math.round(8*a.total/(a.buffering.end-a.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,i)}},b.onError=function(t,e){switch(e.details){case g.ErrorDetails.FRAG_LOAD_ERROR:case g.ErrorDetails.FRAG_LOAD_TIMEOUT:case g.ErrorDetails.KEY_LOAD_ERROR:case g.ErrorDetails.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(u.PlaylistLevelType.MAIN,e);break;case g.ErrorDetails.LEVEL_LOAD_ERROR:case g.ErrorDetails.LEVEL_LOAD_TIMEOUT:this.state!==n.State.ERROR&&(e.fatal?(this.warn(""+e.details),this.state=n.State.ERROR):e.levelRetry||this.state!==n.State.WAITING_LEVEL||(this.state=n.State.IDLE));break;case g.ErrorDetails.BUFFER_FULL_ERROR:if("main"===e.parent&&(this.state===n.State.PARSING||this.state===n.State.PARSED)){var r=!0,i=this.getFwdBufferInfo(this.media,u.PlaylistLevelType.MAIN);i&&i.len>.5&&(r=!this.reduceMaxBufferLength(i.len)),r&&(this.warn("buffer full error also media.currentTime is not buffered, flush main"),this.immediateLevelSwitch()),this.resetLoadingState()}}},b.checkBuffer=function(){var t=this.media,e=this.gapController;if(t&&e&&t.readyState){var r=o.BufferHelper.getBuffered(t);if(!this.loadedmetadata&&r.length)this.loadedmetadata=!0,this.seekToStartPos();else{var i=this.state!==n.State.IDLE?this.fragCurrent:null;e.poll(this.lastCurrentTime,i)}this.lastCurrentTime=t.currentTime}},b.onFragLoadEmergencyAborted=function(){this.state=n.State.IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()},b.onBufferFlushed=function(t,e){var r=e.type;if(r!==d.ElementaryStreamTypes.AUDIO||this.audioOnly&&!this.altAudio){var i=(r===d.ElementaryStreamTypes.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(i,r,u.PlaylistLevelType.MAIN)}},b.onLevelsUpdated=function(t,e){this.levels=e.levels},b.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},b.seekToStartPos=function(){var t=this.media,e=t.currentTime,r=this.startPosition;if(r>=0&&e<r){if(t.seeking)return void v.logger.log("could not seek to "+r+", already seeking at "+e);var i=o.BufferHelper.getBuffered(t),n=(i.length?i.start(0):0)-r;n>0&&(n<this.config.maxBufferHole||n<this.config.maxFragLookUpTolerance)&&(v.logger.log("adjusting start position by "+n+" to match buffer start"),r+=n,this.startPosition=r),this.log("seek to target start position "+r+" from current time "+e),t.currentTime=r}},b._getAudioCodec=function(t){var e=this.config.defaultAudioCodec||t.audioCodec;return this.audioCodecSwap&&e&&(this.log("Swapping audio codec"),e=-1!==e.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),e},b._loadBitrateTestFrag=function(t){var e=this;this._doFragLoad(t).then((function(r){var i=e.hls;if(r&&!i.nextLoadLevel&&!e.fragContextChanged(t)){e.fragLoadError=0,e.state=n.State.IDLE,e.startFragRequested=!1,e.bitrateTest=!1;var a=t.stats;a.parsing.start=a.parsing.end=a.buffering.start=a.buffering.end=self.performance.now(),i.trigger(s.Events.FRAG_LOADED,r)}}))},b._handleTransmuxComplete=function(t){var e,r="main",a=this.hls,o=t.remuxResult,l=t.chunkMeta,u=this.getCurrentContext(l);if(!u)return this.warn("The loading context changed while buffering fragment "+l.sn+" of level "+l.level+". This chunk will not be buffered."),void this.resetLiveStartWhenNotLoaded(l.level);var c=u.frag,h=u.part,f=u.level,g=o.video,v=o.text,p=o.id3,m=o.initSegment,y=f.details,E=this.altAudio?void 0:o.audio;if(!this.fragContextChanged(c)){if(this.state=n.State.PARSING,m){m.tracks&&(this._bufferInitSegment(f,m.tracks,c,l),a.trigger(s.Events.FRAG_PARSING_INIT_SEGMENT,{frag:c,id:r,tracks:m.tracks}));var T=m.initPTS,S=m.timescale;Object(i.isFiniteNumber)(T)&&(this.initPTS[c.cc]=T,a.trigger(s.Events.INIT_PTS_FOUND,{frag:c,id:r,initPTS:T,timescale:S}))}if(g&&!1!==o.independent){if(y){var b=g.startPTS,L=g.endPTS,D=g.startDTS,A=g.endDTS;if(h)h.elementaryStreams[g.type]={startPTS:b,endPTS:L,startDTS:D,endDTS:A};else if(g.firstKeyFrame&&g.independent&&(this.couldBacktrack=!0),g.dropped&&g.independent){var R=this.getMainFwdBufferInfo();if((R?R.end:this.getLoadPosition())+this.config.maxBufferHole<(g.firstKeyFramePTS?g.firstKeyFramePTS:b)-this.config.maxBufferHole)return void this.backtrack(c);c.setElementaryStreamInfo(g.type,c.start,L,c.start,A,!0)}c.setElementaryStreamInfo(g.type,b,L,D,A),this.backtrackFragment&&(this.backtrackFragment=c),this.bufferFragmentData(g,c,h,l)}}else if(!1===o.independent)return void this.backtrack(c);if(E){var k=E.startPTS,I=E.endPTS,_=E.startDTS,O=E.endDTS;h&&(h.elementaryStreams[d.ElementaryStreamTypes.AUDIO]={startPTS:k,endPTS:I,startDTS:_,endDTS:O}),c.setElementaryStreamInfo(d.ElementaryStreamTypes.AUDIO,k,I,_,O),this.bufferFragmentData(E,c,h,l)}if(y&&null!=p&&null!==(e=p.samples)&&void 0!==e&&e.length){var C={id:r,frag:c,details:y,samples:p.samples};a.trigger(s.Events.FRAG_PARSING_METADATA,C)}if(y&&v){var w={id:r,frag:c,details:y,samples:v.samples};a.trigger(s.Events.FRAG_PARSING_USERDATA,w)}}},b._bufferInitSegment=function(t,e,r,i){var a=this;if(this.state===n.State.PARSING){this.audioOnly=!!e.audio&&!e.video,this.altAudio&&!this.audioOnly&&delete e.audio;var o=e.audio,l=e.video,u=e.audiovideo;if(o){var d=t.audioCodec,c=navigator.userAgent.toLowerCase();this.audioCodecSwitch&&(d&&(d=-1!==d.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),1!==o.metadata.channelCount&&-1===c.indexOf("firefox")&&(d="mp4a.40.5")),-1!==c.indexOf("android")&&"audio/mpeg"!==o.container&&(d="mp4a.40.2",this.log("Android: force audio codec to "+d)),t.audioCodec&&t.audioCodec!==d&&this.log('Swapping manifest audio codec "'+t.audioCodec+'" for "'+d+'"'),o.levelCodec=d,o.id="main",this.log("Init audio buffer, container:"+o.container+", codecs[selected/level/parsed]=["+(d||"")+"/"+(t.audioCodec||"")+"/"+o.codec+"]")}l&&(l.levelCodec=t.videoCodec,l.id="main",this.log("Init video buffer, container:"+l.container+", codecs[level/parsed]=["+(t.videoCodec||"")+"/"+l.codec+"]")),u&&this.log("Init audiovideo buffer, container:"+u.container+", codecs[level/parsed]=["+(t.attrs.CODECS||"")+"/"+u.codec+"]"),this.hls.trigger(s.Events.BUFFER_CODECS,e),Object.keys(e).forEach((function(t){var n=e[t].initSegment;null!=n&&n.byteLength&&a.hls.trigger(s.Events.BUFFER_APPENDING,{type:t,data:n,frag:r,part:null,chunkMeta:i,parent:r.type})})),this.tick()}},b.getMainFwdBufferInfo=function(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,u.PlaylistLevelType.MAIN)},b.backtrack=function(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=n.State.IDLE},b.checkFragmentChanged=function(){var t=this.media,e=null;if(t&&t.readyState>1&&!1===t.seeking){var r=t.currentTime;if(o.BufferHelper.isBuffered(t,r)?e=this.getAppendedFrag(r):o.BufferHelper.isBuffered(t,r+.1)&&(e=this.getAppendedFrag(r+.1)),e){this.backtrackFragment=null;var i=this.fragPlaying,n=e.level;i&&e.sn===i.sn&&i.level===n&&e.urlId===i.urlId||(this.hls.trigger(s.Events.FRAG_CHANGED,{frag:e}),i&&i.level===n||this.hls.trigger(s.Events.LEVEL_SWITCHED,{level:n}),this.fragPlaying=e)}}},E=y,(T=[{key:"nextLevel",get:function(){var t=this.nextBufferedFrag;return t?t.level:-1}},{key:"currentFrag",get:function(){var t=this.media;return t?this.fragPlaying||this.getAppendedFrag(t.currentTime):null}},{key:"currentProgramDateTime",get:function(){var t=this.media;if(t){var e=t.currentTime,r=this.currentFrag;if(r&&Object(i.isFiniteNumber)(e)&&Object(i.isFiniteNumber)(r.programDateTime)){var n=r.programDateTime+1e3*(e-r.start);return new Date(n)}}return null}},{key:"currentLevel",get:function(){var t=this.currentFrag;return t?t.level:-1}},{key:"nextBufferedFrag",get:function(){var t=this.currentFrag;return t?this.followingBufferedFrag(t):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}])&&p(E.prototype,T),S&&p(E,S),Object.defineProperty(E,"prototype",{writable:!1}),y}(n.default)},"./src/controller/subtitle-stream-controller.ts":
93
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return m}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./base-stream-controller */"./src/controller/base-stream-controller.ts"),a=r(/*! ../is-supported */"./src/is-supported.ts"),s=r(/*! ../events */"./src/events.ts"),o=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),l=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),c=r(/*! ../demux/transmuxer-interface */"./src/demux/transmuxer-interface.ts"),h=r(/*! ../types/transmuxer */"./src/types/transmuxer.ts"),f=r(/*! ./gap-controller */"./src/controller/gap-controller.ts"),g=r(/*! ../errors */"./src/errors.ts");function v(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function p(t,e){return(p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var m=function(t){var e,r;function m(e,r){var i;return(i=t.call(this,e,r,"[stream-controller]")||this).audioCodecSwap=!1,i.gapController=null,i.level=-1,i._forceStartLoad=!1,i.altAudio=!1,i.audioOnly=!1,i.fragPlaying=null,i.onvplaying=null,i.onvseeked=null,i.fragLastKbps=0,i.couldBacktrack=!1,i.backtrackFragment=null,i.audioCodecSwitch=!1,i.videoBuffer=null,i._registerListeners(),i}r=t,(e=m).prototype=Object.create(r.prototype),e.prototype.constructor=e,p(e,r);var y,E,T,S=m.prototype;return S._registerListeners=function(){var t=this.hls;t.on(s.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(s.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(s.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(s.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.on(s.Events.LEVEL_LOADING,this.onLevelLoading,this),t.on(s.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(s.Events.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.on(s.Events.ERROR,this.onError,this),t.on(s.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.on(s.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.on(s.Events.BUFFER_CREATED,this.onBufferCreated,this),t.on(s.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.on(s.Events.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(s.Events.FRAG_BUFFERED,this.onFragBuffered,this)},S._unregisterListeners=function(){var t=this.hls;t.off(s.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(s.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(s.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(s.Events.MANIFEST_PARSED,this.onManifestParsed,this),t.off(s.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(s.Events.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.off(s.Events.ERROR,this.onError,this),t.off(s.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.off(s.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.off(s.Events.BUFFER_CREATED,this.onBufferCreated,this),t.off(s.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),t.off(s.Events.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(s.Events.FRAG_BUFFERED,this.onFragBuffered,this)},S.onHandlerDestroying=function(){this._unregisterListeners(),this.onMediaDetaching()},S.startLoad=function(t){if(this.levels){var e=this.lastCurrentTime,r=this.hls;if(this.stopLoad(),this.setInterval(100),this.level=-1,this.fragLoadError=0,!this.startFragRequested){var i=r.startLevel;-1===i&&(r.config.testBandwidth&&this.levels.length>1?(i=0,this.bitrateTest=!0):i=r.nextAutoLevel),this.level=r.nextLoadLevel=i,this.loadedmetadata=!1}e>0&&-1===t&&(this.log("Override startPosition with lastCurrentTime @"+e.toFixed(3)),t=e),this.state=n.State.IDLE,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}else this._forceStartLoad=!0,this.state=n.State.STOPPED},S.stopLoad=function(){this._forceStartLoad=!1,t.prototype.stopLoad.call(this)},S.doTick=function(){switch(this.state){case n.State.IDLE:this.doTickIdle();break;case n.State.WAITING_LEVEL:var t,e=this.levels,r=this.level,i=null==e||null===(t=e[r])||void 0===t?void 0:t.details;if(i&&(!i.live||this.levelLastLoaded===this.level)){if(this.waitForCdnTuneIn(i))break;this.state=n.State.IDLE;break}break;case n.State.FRAG_LOADING_WAITING_RETRY:var a,s=self.performance.now(),o=this.retryDate;(!o||s>=o||null!==(a=this.media)&&void 0!==a&&a.seeking)&&(this.log("retryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded(this.level),this.state=n.State.IDLE)}this.onTickEnd()},S.onTickEnd=function(){t.prototype.onTickEnd.call(this),this.checkBuffer(),this.checkFragmentChanged()},S.doTickIdle=function(){var t,e,r=this.hls,i=this.levelLastLoaded,a=this.levels,o=this.media,c=r.config,h=r.nextLoadLevel;if(null!==i&&(o||!this.startFragRequested&&c.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)&&a&&a[h]){var f=a[h];this.level=r.nextLoadLevel=h;var g=f.details;if(!g||this.state===n.State.WAITING_LEVEL||g.live&&this.levelLastLoaded!==h)this.state=n.State.WAITING_LEVEL;else{var v=this.getMainFwdBufferInfo();if(null!==v&&!(v.len>=this.getMaxBufferLength(f.maxBitrate))){if(this._streamEnded(v,g)){var p={};return this.altAudio&&(p.type="video"),this.hls.trigger(s.Events.BUFFER_EOS,p),void(this.state=n.State.ENDED)}this.backtrackFragment&&this.backtrackFragment.start>v.end&&(this.backtrackFragment=null);var m=this.backtrackFragment?this.backtrackFragment.start:v.end,y=this.getNextFragment(m,g);if(this.couldBacktrack&&!this.fragPrevious&&y&&"initSegment"!==y.sn&&this.fragmentTracker.getState(y)!==l.FragmentState.OK){var E,T=(null!=(E=this.backtrackFragment)?E:y).sn-g.startSN,S=g.fragments[T-1];S&&y.cc===S.cc&&(y=S,this.fragmentTracker.removeFragment(S))}else this.backtrackFragment&&v.len&&(this.backtrackFragment=null);if(y&&this.fragmentTracker.getState(y)===l.FragmentState.OK&&this.nextLoadPosition>m){var b=this.audioOnly&&!this.altAudio?d.ElementaryStreamTypes.AUDIO:d.ElementaryStreamTypes.VIDEO;o&&this.afterBufferFlushed(o,b,u.PlaylistLevelType.MAIN),y=this.getNextFragment(this.nextLoadPosition,g)}y&&(!y.initSegment||y.initSegment.data||this.bitrateTest||(y=y.initSegment),"identity"!==(null===(t=y.decryptdata)||void 0===t?void 0:t.keyFormat)||null!==(e=y.decryptdata)&&void 0!==e&&e.key?this.loadFragment(y,g,m):this.loadKey(y,g))}}}},S.loadFragment=function(e,r,i){var n,a=this.fragmentTracker.getState(e);this.fragCurrent=e,a===l.FragmentState.NOT_LOADED?"initSegment"===e.sn?this._loadInitSegment(e):this.bitrateTest?(this.log("Fragment "+e.sn+" of level "+e.level+" is being downloaded to test bitrate and will not be buffered"),this._loadBitrateTestFrag(e)):(this.startFragRequested=!0,t.prototype.loadFragment.call(this,e,r,i)):a===l.FragmentState.APPENDING?this.reduceMaxBufferLength(e.duration)&&this.fragmentTracker.removeFragment(e):0===(null===(n=this.media)||void 0===n?void 0:n.buffered.length)&&this.fragmentTracker.removeAllFragments()},S.getAppendedFrag=function(t){var e=this.fragmentTracker.getAppendedFrag(t,u.PlaylistLevelType.MAIN);return e&&"fragment"in e?e.fragment:e},S.getBufferedFrag=function(t){return this.fragmentTracker.getBufferedFrag(t,u.PlaylistLevelType.MAIN)},S.followingBufferedFrag=function(t){return t?this.getBufferedFrag(t.end+.5):null},S.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},S.nextLevelSwitch=function(){var t=this.levels,e=this.media;if(null!=e&&e.readyState){var r,i=this.getAppendedFrag(e.currentTime);if(i&&i.start>1&&this.flushMainBuffer(0,i.start-1),!e.paused&&t){var n=t[this.hls.nextLoadLevel],a=this.fragLastKbps;r=a&&this.fragCurrent?this.fragCurrent.duration*n.maxBitrate/(1e3*a)+1:0}else r=0;var s=this.getBufferedFrag(e.currentTime+r);if(s){var o=this.followingBufferedFrag(s);if(o){this.abortCurrentFrag();var l=o.maxStartPTS?o.maxStartPTS:o.start,u=o.duration,d=Math.max(s.end,l+Math.min(Math.max(u-this.config.maxFragLookUpTolerance,.5*u),.75*u));this.flushMainBuffer(d,Number.POSITIVE_INFINITY)}}}},S.abortCurrentFrag=function(){var t=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,null!=t&&t.loader&&t.loader.abort(),this.state){case n.State.KEY_LOADING:case n.State.FRAG_LOADING:case n.State.FRAG_LOADING_WAITING_RETRY:case n.State.PARSING:case n.State.PARSED:this.state=n.State.IDLE}this.nextLoadPosition=this.getLoadPosition()},S.flushMainBuffer=function(e,r){t.prototype.flushMainBuffer.call(this,e,r,this.altAudio?"video":null)},S.onMediaAttached=function(e,r){t.prototype.onMediaAttached.call(this,e,r);var i=r.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),i.addEventListener("playing",this.onvplaying),i.addEventListener("seeked",this.onvseeked),this.gapController=new f.default(this.config,i,this.fragmentTracker,this.hls)},S.onMediaDetaching=function(){var e=this.media;e&&this.onvplaying&&this.onvseeked&&(e.removeEventListener("playing",this.onvplaying),e.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),t.prototype.onMediaDetaching.call(this)},S.onMediaPlaying=function(){this.tick()},S.onMediaSeeked=function(){var t=this.media,e=t?t.currentTime:null;Object(i.isFiniteNumber)(e)&&this.log("Media seeked to "+e.toFixed(3)),this.tick()},S.onManifestLoading=function(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(s.Events.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=!1,this.startPosition=this.lastCurrentTime=0,this.fragPlaying=null,this.backtrackFragment=null},S.onManifestParsed=function(t,e){var r,i=!1,n=!1;e.levels.forEach((function(t){(r=t.audioCodec)&&(-1!==r.indexOf("mp4a.40.2")&&(i=!0),-1!==r.indexOf("mp4a.40.5")&&(n=!0))})),this.audioCodecSwitch=i&&n&&!Object(a.changeTypeSupported)(),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},S.onLevelLoading=function(t,e){var r=this.levels;if(r&&this.state===n.State.IDLE){var i=r[e.level];(!i.details||i.details.live&&this.levelLastLoaded!==e.level||this.waitForCdnTuneIn(i.details))&&(this.state=n.State.WAITING_LEVEL)}},S.onLevelLoaded=function(t,e){var r,i=this.levels,a=e.level,o=e.details,l=o.totalduration;if(i){this.log("Level "+a+" loaded ["+o.startSN+","+o.endSN+"], cc ["+o.startCC+", "+o.endCC+"] duration:"+l);var u=this.fragCurrent;!u||this.state!==n.State.FRAG_LOADING&&this.state!==n.State.FRAG_LOADING_WAITING_RETRY||u.level!==e.level&&u.loader&&(this.state=n.State.IDLE,this.backtrackFragment=null,u.loader.abort());var d=i[a],c=0;if(o.live||null!==(r=d.details)&&void 0!==r&&r.live){if(o.fragments[0]||(o.deltaUpdateFailed=!0),o.deltaUpdateFailed)return;c=this.alignPlaylists(o,d.details)}if(d.details=o,this.levelLastLoaded=a,this.hls.trigger(s.Events.LEVEL_UPDATED,{details:o,level:a}),this.state===n.State.WAITING_LEVEL){if(this.waitForCdnTuneIn(o))return;this.state=n.State.IDLE}this.startFragRequested?o.live&&this.synchronizeToLiveEdge(o):this.setStartPosition(o,c),this.tick()}else this.warn("Levels were reset while loading level "+a)},S._handleFragmentLoadProgress=function(t){var e,r=t.frag,i=t.part,n=t.payload,a=this.levels;if(a){var s=a[r.level],o=s.details;if(o){var l=s.videoCodec,d=o.PTSKnown||!o.live,f=null===(e=r.initSegment)||void 0===e?void 0:e.data,g=this._getAudioCodec(s),v=this.transmuxer=this.transmuxer||new c.default(this.hls,u.PlaylistLevelType.MAIN,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),p=i?i.index:-1,m=-1!==p,y=new h.ChunkMetadata(r.level,r.sn,r.stats.chunkCount,n.byteLength,p,m),E=this.initPTS[r.cc];v.push(n,f,g,l,r,i,o.totalduration,d,y,E)}else this.warn("Dropping fragment "+r.sn+" of level "+r.level+" after level details were reset")}else this.warn("Levels were reset while fragment load was in progress. Fragment "+r.sn+" of level "+r.level+" will not be buffered")},S.onAudioTrackSwitching=function(t,e){var r=this.altAudio,i=!!e.url,n=e.id;if(!i){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var a=this.fragCurrent;null!=a&&a.loader&&(this.log("Switching to main audio track, cancel main fragment load"),a.loader.abort()),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();var o=this.hls;r&&o.trigger(s.Events.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:"audio"}),o.trigger(s.Events.AUDIO_TRACK_SWITCHED,{id:n})}},S.onAudioTrackSwitched=function(t,e){var r=e.id,i=!!this.hls.audioTracks[r].url;if(i){var n=this.videoBuffer;n&&this.mediaBuffer!==n&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=n)}this.altAudio=i,this.tick()},S.onBufferCreated=function(t,e){var r,i,n=e.tracks,a=!1;for(var s in n){var o=n[s];if("main"===o.id){if(i=s,r=o,"video"===s){var l=n[s];l&&(this.videoBuffer=l.buffer)}}else a=!0}a&&r?(this.log("Alternate track found, use "+i+".buffered to schedule main fragment loading"),this.mediaBuffer=r.buffer):this.mediaBuffer=this.media},S.onFragBuffered=function(t,e){var r=e.frag,i=e.part;if(!r||r.type===u.PlaylistLevelType.MAIN){if(this.fragContextChanged(r))return this.warn("Fragment "+r.sn+(i?" p: "+i.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state),void(this.state===n.State.PARSED&&(this.state=n.State.IDLE));var a=i?i.stats:r.stats;this.fragLastKbps=Math.round(8*a.total/(a.buffering.end-a.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,i)}},S.onError=function(t,e){switch(e.details){case g.ErrorDetails.FRAG_LOAD_ERROR:case g.ErrorDetails.FRAG_LOAD_TIMEOUT:case g.ErrorDetails.KEY_LOAD_ERROR:case g.ErrorDetails.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(u.PlaylistLevelType.MAIN,e);break;case g.ErrorDetails.LEVEL_LOAD_ERROR:case g.ErrorDetails.LEVEL_LOAD_TIMEOUT:this.state!==n.State.ERROR&&(e.fatal?(this.warn(""+e.details),this.state=n.State.ERROR):e.levelRetry||this.state!==n.State.WAITING_LEVEL||(this.state=n.State.IDLE));break;case g.ErrorDetails.BUFFER_FULL_ERROR:if("main"===e.parent&&(this.state===n.State.PARSING||this.state===n.State.PARSED)){var r=!0,i=this.getFwdBufferInfo(this.media,u.PlaylistLevelType.MAIN);i&&i.len>.5&&(r=!this.reduceMaxBufferLength(i.len)),r&&(this.warn("buffer full error also media.currentTime is not buffered, flush main"),this.immediateLevelSwitch()),this.resetLoadingState()}}},S.checkBuffer=function(){var t=this.media,e=this.gapController;if(t&&e&&t.readyState){if(this.loadedmetadata||!o.BufferHelper.getBuffered(t).length){var r=this.state!==n.State.IDLE?this.fragCurrent:null;e.poll(this.lastCurrentTime,r)}this.lastCurrentTime=t.currentTime}},S.onFragLoadEmergencyAborted=function(){this.state=n.State.IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()},S.onBufferFlushed=function(t,e){var r=e.type;if(r!==d.ElementaryStreamTypes.AUDIO||this.audioOnly&&!this.altAudio){var i=(r===d.ElementaryStreamTypes.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(i,r,u.PlaylistLevelType.MAIN)}},S.onLevelsUpdated=function(t,e){this.levels=e.levels},S.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},S.seekToStartPos=function(){var t=this.media;if(t){var e=t.currentTime,r=this.startPosition;if(r>=0&&e<r){if(t.seeking)return void this.log("could not seek to "+r+", already seeking at "+e);var i=o.BufferHelper.getBuffered(t),n=(i.length?i.start(0):0)-r;n>0&&(n<this.config.maxBufferHole||n<this.config.maxFragLookUpTolerance)&&(this.log("adjusting start position by "+n+" to match buffer start"),r+=n,this.startPosition=r),this.log("seek to target start position "+r+" from current time "+e),t.currentTime=r}}},S._getAudioCodec=function(t){var e=this.config.defaultAudioCodec||t.audioCodec;return this.audioCodecSwap&&e&&(this.log("Swapping audio codec"),e=-1!==e.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),e},S._loadBitrateTestFrag=function(t){var e=this;t.bitrateTest=!0,this._doFragLoad(t).then((function(r){var i=e.hls;if(r&&!i.nextLoadLevel&&!e.fragContextChanged(t)){e.fragLoadError=0,e.state=n.State.IDLE,e.startFragRequested=!1,e.bitrateTest=!1;var a=t.stats;a.parsing.start=a.parsing.end=a.buffering.start=a.buffering.end=self.performance.now(),i.trigger(s.Events.FRAG_LOADED,r),t.bitrateTest=!1}}))},S._handleTransmuxComplete=function(t){var e,r="main",a=this.hls,o=t.remuxResult,l=t.chunkMeta,u=this.getCurrentContext(l);if(!u)return this.warn("The loading context changed while buffering fragment "+l.sn+" of level "+l.level+". This chunk will not be buffered."),void this.resetStartWhenNotLoaded(l.level);var c=u.frag,h=u.part,f=u.level,g=o.video,v=o.text,p=o.id3,m=o.initSegment,y=f.details,E=this.altAudio?void 0:o.audio;if(!this.fragContextChanged(c)){if(this.state=n.State.PARSING,m){m.tracks&&(this._bufferInitSegment(f,m.tracks,c,l),a.trigger(s.Events.FRAG_PARSING_INIT_SEGMENT,{frag:c,id:r,tracks:m.tracks}));var T=m.initPTS,S=m.timescale;Object(i.isFiniteNumber)(T)&&(this.initPTS[c.cc]=T,a.trigger(s.Events.INIT_PTS_FOUND,{frag:c,id:r,initPTS:T,timescale:S}))}if(g&&!1!==o.independent){if(y){var b=g.startPTS,L=g.endPTS,D=g.startDTS,A=g.endDTS;if(h)h.elementaryStreams[g.type]={startPTS:b,endPTS:L,startDTS:D,endDTS:A};else if(g.firstKeyFrame&&g.independent&&(this.couldBacktrack=!0),g.dropped&&g.independent){var R=this.getMainFwdBufferInfo();if((R?R.end:this.getLoadPosition())+this.config.maxBufferHole<(g.firstKeyFramePTS?g.firstKeyFramePTS:b)-this.config.maxBufferHole)return void this.backtrack(c);c.setElementaryStreamInfo(g.type,c.start,L,c.start,A,!0)}c.setElementaryStreamInfo(g.type,b,L,D,A),this.backtrackFragment&&(this.backtrackFragment=c),this.bufferFragmentData(g,c,h,l)}}else if(!1===o.independent)return void this.backtrack(c);if(E){var k=E.startPTS,I=E.endPTS,_=E.startDTS,C=E.endDTS;h&&(h.elementaryStreams[d.ElementaryStreamTypes.AUDIO]={startPTS:k,endPTS:I,startDTS:_,endDTS:C}),c.setElementaryStreamInfo(d.ElementaryStreamTypes.AUDIO,k,I,_,C),this.bufferFragmentData(E,c,h,l)}if(y&&null!=p&&null!==(e=p.samples)&&void 0!==e&&e.length){var O={id:r,frag:c,details:y,samples:p.samples};a.trigger(s.Events.FRAG_PARSING_METADATA,O)}if(y&&v){var w={id:r,frag:c,details:y,samples:v.samples};a.trigger(s.Events.FRAG_PARSING_USERDATA,w)}}},S._bufferInitSegment=function(t,e,r,i){var a=this;if(this.state===n.State.PARSING){this.audioOnly=!!e.audio&&!e.video,this.altAudio&&!this.audioOnly&&delete e.audio;var o=e.audio,l=e.video,u=e.audiovideo;if(o){var d=t.audioCodec,c=navigator.userAgent.toLowerCase();this.audioCodecSwitch&&(d&&(d=-1!==d.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),1!==o.metadata.channelCount&&-1===c.indexOf("firefox")&&(d="mp4a.40.5")),-1!==c.indexOf("android")&&"audio/mpeg"!==o.container&&(d="mp4a.40.2",this.log("Android: force audio codec to "+d)),t.audioCodec&&t.audioCodec!==d&&this.log('Swapping manifest audio codec "'+t.audioCodec+'" for "'+d+'"'),o.levelCodec=d,o.id="main",this.log("Init audio buffer, container:"+o.container+", codecs[selected/level/parsed]=["+(d||"")+"/"+(t.audioCodec||"")+"/"+o.codec+"]")}l&&(l.levelCodec=t.videoCodec,l.id="main",this.log("Init video buffer, container:"+l.container+", codecs[level/parsed]=["+(t.videoCodec||"")+"/"+l.codec+"]")),u&&this.log("Init audiovideo buffer, container:"+u.container+", codecs[level/parsed]=["+(t.attrs.CODECS||"")+"/"+u.codec+"]"),this.hls.trigger(s.Events.BUFFER_CODECS,e),Object.keys(e).forEach((function(t){var n=e[t].initSegment;null!=n&&n.byteLength&&a.hls.trigger(s.Events.BUFFER_APPENDING,{type:t,data:n,frag:r,part:null,chunkMeta:i,parent:r.type})})),this.tick()}},S.getMainFwdBufferInfo=function(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,u.PlaylistLevelType.MAIN)},S.backtrack=function(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=n.State.IDLE},S.checkFragmentChanged=function(){var t=this.media,e=null;if(t&&t.readyState>1&&!1===t.seeking){var r=t.currentTime;if(o.BufferHelper.isBuffered(t,r)?e=this.getAppendedFrag(r):o.BufferHelper.isBuffered(t,r+.1)&&(e=this.getAppendedFrag(r+.1)),e){this.backtrackFragment=null;var i=this.fragPlaying,n=e.level;i&&e.sn===i.sn&&i.level===n&&e.urlId===i.urlId||(this.hls.trigger(s.Events.FRAG_CHANGED,{frag:e}),i&&i.level===n||this.hls.trigger(s.Events.LEVEL_SWITCHED,{level:n}),this.fragPlaying=e)}}},y=m,(E=[{key:"nextLevel",get:function(){var t=this.nextBufferedFrag;return t?t.level:-1}},{key:"currentFrag",get:function(){var t=this.media;return t?this.fragPlaying||this.getAppendedFrag(t.currentTime):null}},{key:"currentProgramDateTime",get:function(){var t=this.media;if(t){var e=t.currentTime,r=this.currentFrag;if(r&&Object(i.isFiniteNumber)(e)&&Object(i.isFiniteNumber)(r.programDateTime)){var n=r.programDateTime+1e3*(e-r.start);return new Date(n)}}return null}},{key:"currentLevel",get:function(){var t=this.currentFrag;return t?t.level:-1}},{key:"nextBufferedFrag",get:function(){var t=this.currentFrag;return t?this.followingBufferedFrag(t):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}])&&v(y.prototype,E),T&&v(y,T),Object.defineProperty(y,"prototype",{writable:!1}),m}(n.default)},"./src/controller/subtitle-stream-controller.ts":
94
94
  /*!******************************************************!*\
95
95
  !*** ./src/controller/subtitle-stream-controller.ts ***!
96
96
  \******************************************************/
97
- /*! exports provided: SubtitleStreamController */function(t,e,r){r.r(e),r.d(e,"SubtitleStreamController",(function(){return g}));var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),a=r(/*! ./fragment-finders */"./src/controller/fragment-finders.ts"),s=r(/*! ../utils/discontinuities */"./src/utils/discontinuities.ts"),o=r(/*! ./level-helper */"./src/controller/level-helper.ts"),l=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),u=r(/*! ./base-stream-controller */"./src/controller/base-stream-controller.ts"),d=r(/*! ../types/loader */"./src/types/loader.ts"),c=r(/*! ../types/level */"./src/types/level.ts");function h(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function f(t,e){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var g=function(t){var e,r;function g(e,r){var i;return(i=t.call(this,e,r,"[subtitle-stream-controller]")||this).levels=[],i.currentTrackId=-1,i.tracksBuffered=[],i.mainDetails=null,i._registerListeners(),i}r=t,(e=g).prototype=Object.create(r.prototype),e.prototype.constructor=e,f(e,r);var v,p,m,y=g.prototype;return y.onHandlerDestroying=function(){this._unregisterListeners(),this.mainDetails=null},y._registerListeners=function(){var t=this.hls;t.on(i.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(i.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(i.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(i.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(i.Events.ERROR,this.onError,this),t.on(i.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(i.Events.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.on(i.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.on(i.Events.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.on(i.Events.BUFFER_FLUSHING,this.onBufferFlushing,this)},y._unregisterListeners=function(){var t=this.hls;t.off(i.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(i.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(i.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(i.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(i.Events.ERROR,this.onError,this),t.off(i.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(i.Events.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.off(i.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.off(i.Events.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.off(i.Events.BUFFER_FLUSHING,this.onBufferFlushing,this)},y.startLoad=function(){this.stopLoad(),this.state=u.State.IDLE,this.setInterval(500),this.tick()},y.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments()},y.onLevelLoaded=function(t,e){this.mainDetails=e.details},y.onSubtitleFragProcessed=function(t,e){var r=e.frag,i=e.success;if(this.fragPrevious=r,this.state=u.State.IDLE,i){var n=this.tracksBuffered[this.currentTrackId];if(n){for(var a,s=r.start,o=0;o<n.length;o++)if(s>=n[o].start&&s<=n[o].end){a=n[o];break}var l=r.start+r.duration;a?a.end=l:(a={start:s,end:l},n.push(a)),this.fragmentTracker.fragBuffered(r)}}},y.onBufferFlushing=function(t,e){var r=e.startOffset,i=e.endOffset;if(0===r&&i!==Number.POSITIVE_INFINITY){var n=this.currentTrackId,a=this.levels;if(!a.length||!a[n]||!a[n].details)return;var s=i-a[n].details.targetduration;if(s<=0)return;e.endOffsetSubtitles=Math.max(0,s),this.tracksBuffered.forEach((function(t){for(var e=0;e<t.length;)if(t[e].end<=s)t.shift();else{if(!(t[e].start<s))break;t[e].start=s,e++}})),this.fragmentTracker.removeFragmentsInRange(r,s,d.PlaylistLevelType.SUBTITLE)}},y.onError=function(t,e){var r,i=e.frag;i&&i.type===d.PlaylistLevelType.SUBTITLE&&(null!==(r=this.fragCurrent)&&void 0!==r&&r.loader&&this.fragCurrent.loader.abort(),this.state=u.State.IDLE)},y.onSubtitleTracksUpdated=function(t,e){var r=this,i=e.subtitleTracks;this.tracksBuffered=[],this.levels=i.map((function(t){return new c.Level(t)})),this.fragmentTracker.removeAllFragments(),this.fragPrevious=null,this.levels.forEach((function(t){r.tracksBuffered[t.id]=[]})),this.mediaBuffer=null},y.onSubtitleTrackSwitch=function(t,e){if(this.currentTrackId=e.id,this.levels.length&&-1!==this.currentTrackId){var r=this.levels[this.currentTrackId];null!=r&&r.details?this.mediaBuffer=this.mediaBufferTimeRanges:this.mediaBuffer=null,r&&this.setInterval(500)}else this.clearInterval()},y.onSubtitleTrackLoaded=function(t,e){var r,i=e.details,n=e.id,l=this.currentTrackId,d=this.levels;if(d.length){var c=d[l];if(!(n>=d.length||n!==l)&&c){if(this.mediaBuffer=this.mediaBufferTimeRanges,i.live||null!==(r=c.details)&&void 0!==r&&r.live){var h=this.mainDetails;if(i.deltaUpdateFailed||!h)return;var f=h.fragments[0];c.details?0===this.alignPlaylists(i,c.details)&&f&&Object(o.addSliding)(i,f.start):i.hasProgramDateTime&&h.hasProgramDateTime?Object(s.alignMediaPlaylistByPDT)(i,h):f&&Object(o.addSliding)(i,f.start)}c.details=i,this.levelLastLoaded=n,this.tick(),i.live&&!this.fragCurrent&&this.media&&this.state===u.State.IDLE&&(Object(a.findFragmentByPTS)(null,i.fragments,this.media.currentTime,0)||(this.warn("Subtitle playlist not aligned with playback"),c.details=void 0))}}},y._handleFragmentLoadComplete=function(t){var e=t.frag,r=t.payload,n=e.decryptdata,a=this.hls;if(!this.fragContextChanged(e)&&r&&r.byteLength>0&&n&&n.key&&n.iv&&"AES-128"===n.method){var s=performance.now();this.decrypter.webCryptoDecrypt(new Uint8Array(r),n.key.buffer,n.iv.buffer).then((function(t){var r=performance.now();a.trigger(i.Events.FRAG_DECRYPTED,{frag:e,payload:t,stats:{tstart:s,tdecrypt:r}})}))}},y.doTick=function(){if(this.media){if(this.state===u.State.IDLE){var t,e=this.currentTrackId,r=this.levels;if(!r.length||!r[e]||!r[e].details)return;var i=r[e].details,s=i.targetduration,o=this.config,d=this.media,c=n.BufferHelper.bufferedInfo(this.mediaBufferTimeRanges,d.currentTime-s,o.maxBufferHole),h=c.end;if(c.len>this.getMaxBufferLength()+s)return;console.assert(i,"Subtitle track details are defined on idle subtitle stream controller tick");var f,g=i.fragments,v=g.length,p=i.edge,m=this.fragPrevious;if(h<p){var y=o.maxFragLookUpTolerance;!(f=Object(a.findFragmentByPTS)(m,g,Math.max(g[0].start,h),y))&&m&&m.start<g[0].start&&(f=g[0])}else f=g[v-1];null!==(t=f)&&void 0!==t&&t.encrypted?this.loadKey(f,i):f&&this.fragmentTracker.getState(f)===l.FragmentState.NOT_LOADED&&this.loadFragment(f,i,h)}}else this.state=u.State.IDLE},y.loadFragment=function(e,r,i){this.fragCurrent=e,t.prototype.loadFragment.call(this,e,r,i)},v=g,(p=[{key:"mediaBufferTimeRanges",get:function(){return this.tracksBuffered[this.currentTrackId]||[]}}])&&h(v.prototype,p),m&&h(v,m),Object.defineProperty(v,"prototype",{writable:!1}),g}(u.default)},"./src/controller/subtitle-track-controller.ts":
97
+ /*! exports provided: SubtitleStreamController */function(t,e,r){r.r(e),r.d(e,"SubtitleStreamController",(function(){return g}));var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),a=r(/*! ./fragment-finders */"./src/controller/fragment-finders.ts"),s=r(/*! ../utils/discontinuities */"./src/utils/discontinuities.ts"),o=r(/*! ./level-helper */"./src/controller/level-helper.ts"),l=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),u=r(/*! ./base-stream-controller */"./src/controller/base-stream-controller.ts"),d=r(/*! ../types/loader */"./src/types/loader.ts"),c=r(/*! ../types/level */"./src/types/level.ts");function h(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function f(t,e){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var g=function(t){var e,r;function g(e,r){var i;return(i=t.call(this,e,r,"[subtitle-stream-controller]")||this).levels=[],i.currentTrackId=-1,i.tracksBuffered=[],i.mainDetails=null,i._registerListeners(),i}r=t,(e=g).prototype=Object.create(r.prototype),e.prototype.constructor=e,f(e,r);var p,m,y,E=g.prototype;return E.onHandlerDestroying=function(){this._unregisterListeners(),this.mainDetails=null},E._registerListeners=function(){var t=this.hls;t.on(i.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(i.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(i.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(i.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.on(i.Events.ERROR,this.onError,this),t.on(i.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(i.Events.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.on(i.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.on(i.Events.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.on(i.Events.BUFFER_FLUSHING,this.onBufferFlushing,this)},E._unregisterListeners=function(){var t=this.hls;t.off(i.Events.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(i.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(i.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(i.Events.LEVEL_LOADED,this.onLevelLoaded,this),t.off(i.Events.ERROR,this.onError,this),t.off(i.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(i.Events.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.off(i.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.off(i.Events.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.off(i.Events.BUFFER_FLUSHING,this.onBufferFlushing,this)},E.startLoad=function(){this.stopLoad(),this.state=u.State.IDLE,this.setInterval(500),this.tick()},E.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments()},E.onLevelLoaded=function(t,e){this.mainDetails=e.details},E.onSubtitleFragProcessed=function(t,e){var r=e.frag,i=e.success;if(this.fragPrevious=r,this.state=u.State.IDLE,i){var n=this.tracksBuffered[this.currentTrackId];if(n){for(var a,s=r.start,o=0;o<n.length;o++)if(s>=n[o].start&&s<=n[o].end){a=n[o];break}var l=r.start+r.duration;a?a.end=l:(a={start:s,end:l},n.push(a)),this.fragmentTracker.fragBuffered(r)}}},E.onBufferFlushing=function(t,e){var r=e.startOffset,i=e.endOffset;if(0===r&&i!==Number.POSITIVE_INFINITY){var n=this.currentTrackId,a=this.levels;if(!a.length||!a[n]||!a[n].details)return;var s=i-a[n].details.targetduration;if(s<=0)return;e.endOffsetSubtitles=Math.max(0,s),this.tracksBuffered.forEach((function(t){for(var e=0;e<t.length;)if(t[e].end<=s)t.shift();else{if(!(t[e].start<s))break;t[e].start=s,e++}})),this.fragmentTracker.removeFragmentsInRange(r,s,d.PlaylistLevelType.SUBTITLE)}},E.onError=function(t,e){var r,i=e.frag;i&&i.type===d.PlaylistLevelType.SUBTITLE&&(null!==(r=this.fragCurrent)&&void 0!==r&&r.loader&&this.fragCurrent.loader.abort(),this.state=u.State.IDLE)},E.onSubtitleTracksUpdated=function(t,e){var r=this,i=e.subtitleTracks;this.tracksBuffered=[],this.levels=i.map((function(t){return new c.Level(t)})),this.fragmentTracker.removeAllFragments(),this.fragPrevious=null,this.levels.forEach((function(t){r.tracksBuffered[t.id]=[]})),this.mediaBuffer=null},E.onSubtitleTrackSwitch=function(t,e){if(this.currentTrackId=e.id,this.levels.length&&-1!==this.currentTrackId){var r=this.levels[this.currentTrackId];null!=r&&r.details?this.mediaBuffer=this.mediaBufferTimeRanges:this.mediaBuffer=null,r&&this.setInterval(500)}else this.clearInterval()},E.onSubtitleTrackLoaded=function(t,e){var r,i=e.details,n=e.id,l=this.currentTrackId,d=this.levels;if(d.length){var c=d[l];if(!(n>=d.length||n!==l)&&c){if(this.mediaBuffer=this.mediaBufferTimeRanges,i.live||null!==(r=c.details)&&void 0!==r&&r.live){var h=this.mainDetails;if(i.deltaUpdateFailed||!h)return;var f=h.fragments[0];c.details?0===this.alignPlaylists(i,c.details)&&f&&Object(o.addSliding)(i,f.start):i.hasProgramDateTime&&h.hasProgramDateTime?Object(s.alignMediaPlaylistByPDT)(i,h):f&&Object(o.addSliding)(i,f.start)}c.details=i,this.levelLastLoaded=n,this.tick(),i.live&&!this.fragCurrent&&this.media&&this.state===u.State.IDLE&&(Object(a.findFragmentByPTS)(null,i.fragments,this.media.currentTime,0)||(this.warn("Subtitle playlist not aligned with playback"),c.details=void 0))}}},E._handleFragmentLoadComplete=function(t){var e=t.frag,r=t.payload,n=e.decryptdata,a=this.hls;if(!this.fragContextChanged(e)&&r&&r.byteLength>0&&n&&n.key&&n.iv&&"AES-128"===n.method){var s=performance.now();this.decrypter.webCryptoDecrypt(new Uint8Array(r),n.key.buffer,n.iv.buffer).then((function(t){var r=performance.now();a.trigger(i.Events.FRAG_DECRYPTED,{frag:e,payload:t,stats:{tstart:s,tdecrypt:r}})}))}},E.doTick=function(){if(this.media){if(this.state===u.State.IDLE){var t=this.currentTrackId,e=this.levels;if(!e.length||!e[t]||!e[t].details)return;var r=e[t].details,i=r.targetduration,s=this.config,o=this.media,d=n.BufferHelper.bufferedInfo(this.tracksBuffered[this.currentTrackId]||[],o.currentTime-i,s.maxBufferHole),c=d.end;if(d.len>this.getMaxBufferLength()+i)return;console.assert(r,"Subtitle track details are defined on idle subtitle stream controller tick");var h,f=r.fragments,g=f.length,v=r.edge,p=this.fragPrevious;if(c<v){var m=s.maxFragLookUpTolerance;!(h=Object(a.findFragmentByPTS)(p,f,Math.max(f[0].start,c),m))&&p&&p.start<f[0].start&&(h=f[0])}else h=f[g-1];if(!(h=this.mapToInitFragWhenRequired(h)))return;if(this.fragmentTracker.getState(h)!==l.FragmentState.NOT_LOADED)return;h.encrypted?this.loadKey(h,r):this.loadFragment(h,r,c)}}else this.state=u.State.IDLE},E.loadFragment=function(e,r,i){this.fragCurrent=e,"initSegment"===e.sn?this._loadInitSegment(e):t.prototype.loadFragment.call(this,e,r,i)},p=g,(m=[{key:"mediaBufferTimeRanges",get:function(){return new v(this.tracksBuffered[this.currentTrackId]||[])}}])&&h(p.prototype,m),y&&h(p,y),Object.defineProperty(p,"prototype",{writable:!1}),g}(u.default),v=function(t){this.buffered=void 0;var e=function(e,r,i){if((r>>>=0)>i-1)throw new DOMException("Failed to execute '"+e+"' on 'TimeRanges': The index provided ("+r+") is greater than the maximum bound ("+i+")");return t[r][e]};this.buffered={get length(){return t.length},end:function(r){return e("end",r,t.length)},start:function(r){return e("start",r,t.length)}}}},"./src/controller/subtitle-track-controller.ts":
98
98
  /*!*****************************************************!*\
99
99
  !*** ./src/controller/subtitle-track-controller.ts ***!
100
100
  \*****************************************************/
@@ -102,7 +102,7 @@
102
102
  /*!***********************************************!*\
103
103
  !*** ./src/controller/timeline-controller.ts ***!
104
104
  \***********************************************/
105
- /*! exports provided: TimelineController */function(t,e,r){r.r(e),r.d(e,"TimelineController",(function(){return h}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../utils/cea-608-parser */"./src/utils/cea-608-parser.ts"),s=r(/*! ../utils/output-filter */"./src/utils/output-filter.ts"),o=r(/*! ../utils/webvtt-parser */"./src/utils/webvtt-parser.ts"),l=r(/*! ../utils/texttrack-utils */"./src/utils/texttrack-utils.ts"),u=r(/*! ../utils/imsc1-ttml-parser */"./src/utils/imsc1-ttml-parser.ts"),d=r(/*! ../types/loader */"./src/types/loader.ts"),c=r(/*! ../utils/logger */"./src/utils/logger.ts"),h=function(){function t(t){if(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.timescale=[],this.unparsedVttFrags=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.cea608Parser1=void 0,this.cea608Parser2=void 0,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!1}},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}},this.config.enableCEA708Captions){var e=new s.default(this,"textTrack1"),r=new s.default(this,"textTrack2"),i=new s.default(this,"textTrack3"),o=new s.default(this,"textTrack4");this.cea608Parser1=new a.default(1,e,r),this.cea608Parser2=new a.default(3,i,o)}t.on(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(n.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(n.Events.FRAG_LOADING,this.onFragLoading,this),t.on(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.on(n.Events.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.on(n.Events.FRAG_DECRYPTED,this.onFragDecrypted,this),t.on(n.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(n.Events.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.on(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this)}var e=t.prototype;return e.destroy=function(){var t=this.hls;t.off(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(n.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(n.Events.FRAG_LOADING,this.onFragLoading,this),t.off(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.off(n.Events.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.off(n.Events.FRAG_DECRYPTED,this.onFragDecrypted,this),t.off(n.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(n.Events.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.off(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=this.cea608Parser1=this.cea608Parser2=null},e.addCues=function(t,e,r,i,a){for(var s,o,l,u,d=!1,c=a.length;c--;){var h=a[c],f=(s=h[0],o=h[1],l=e,u=r,Math.min(o,u)-Math.max(s,l));if(f>=0&&(h[0]=Math.min(h[0],e),h[1]=Math.max(h[1],r),d=!0,f/(r-e)>.5))return}if(d||a.push([e,r]),this.config.renderTextTracksNatively){var g=this.captionsTracks[t];this.Cues.newCue(g,e,r,i)}else{var v=this.Cues.newCue(null,e,r,i);this.hls.trigger(n.Events.CUES_PARSED,{type:"captions",cues:v,track:t})}},e.onInitPtsFound=function(t,e){var r=this,i=e.frag,a=e.id,s=e.initPTS,o=e.timescale,l=this.unparsedVttFrags;"main"===a&&(this.initPTS[i.cc]=s,this.timescale[i.cc]=o),l.length&&(this.unparsedVttFrags=[],l.forEach((function(t){r.onFragLoaded(n.Events.FRAG_LOADED,t)})))},e.getExistingTrack=function(t){var e=this.media;if(e)for(var r=0;r<e.textTracks.length;r++){var i=e.textTracks[r];if(i[t])return i}return null},e.createCaptionsTrack=function(t){this.config.renderTextTracksNatively?this.createNativeTrack(t):this.createNonNativeTrack(t)},e.createNativeTrack=function(t){if(!this.captionsTracks[t]){var e=this.captionsProperties,r=this.captionsTracks,i=this.media,n=e[t],a=n.label,s=n.languageCode,o=this.getExistingTrack(t);if(o)r[t]=o,Object(l.clearCurrentCues)(r[t]),Object(l.sendAddTrackEvent)(r[t],i);else{var u=this.createTextTrack("captions",a,s);u&&(u[t]=!0,r[t]=u)}}},e.createNonNativeTrack=function(t){if(!this.nonNativeCaptionsTracks[t]){var e=this.captionsProperties[t];if(e){var r={_id:t,label:e.label,kind:"captions",default:!!e.media&&!!e.media.default,closedCaptions:e.media};this.nonNativeCaptionsTracks[t]=r,this.hls.trigger(n.Events.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:[r]})}}},e.createTextTrack=function(t,e,r){var i=this.media;if(i)return i.addTextTrack(t,e,r)},e.onMediaAttaching=function(t,e){this.media=e.media,this._cleanTracks()},e.onMediaDetaching=function(){var t=this.captionsTracks;Object.keys(t).forEach((function(e){Object(l.clearCurrentCues)(t[e]),delete t[e]})),this.nonNativeCaptionsTracks={}},e.onManifestLoading=function(){this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!1}},this._cleanTracks(),this.tracks=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.textTracks=[],this.unparsedVttFrags=this.unparsedVttFrags||[],this.initPTS=[],this.timescale=[],this.cea608Parser1&&this.cea608Parser2&&(this.cea608Parser1.reset(),this.cea608Parser2.reset())},e._cleanTracks=function(){var t=this.media;if(t){var e=t.textTracks;if(e)for(var r=0;r<e.length;r++)Object(l.clearCurrentCues)(e[r])}},e.onSubtitleTracksUpdated=function(t,e){var r=this;this.textTracks=[];var i=e.subtitleTracks||[],a=i.some((function(t){return t.textCodec===u.IMSC1_CODEC}));if(this.config.enableWebVTT||a&&this.config.enableIMSC1){var s=this.tracks&&i&&this.tracks.length===i.length;if(this.tracks=i||[],this.config.renderTextTracksNatively){var o=this.media?this.media.textTracks:[];this.tracks.forEach((function(t,e){var i;if(e<o.length){for(var n=null,a=0;a<o.length;a++)if(f(o[a],t)){n=o[a];break}n&&(i=n)}i?Object(l.clearCurrentCues)(i):(i=r.createTextTrack("subtitles",t.name,t.lang))&&(i.mode="disabled"),i&&(i.groupId=t.groupId,r.textTracks.push(i))}))}else if(!s&&this.tracks&&this.tracks.length){var d=this.tracks.map((function(t){return{label:t.name,kind:t.type.toLowerCase(),default:t.default,subtitleTrack:t}}));this.hls.trigger(n.Events.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:d})}}},e.onManifestLoaded=function(t,e){var r=this;this.config.enableCEA708Captions&&e.captions&&e.captions.forEach((function(t){var e=/(?:CC|SERVICE)([1-4])/.exec(t.instreamId);if(e){var i="textTrack"+e[1],n=r.captionsProperties[i];n&&(n.label=t.name,t.lang&&(n.languageCode=t.lang),n.media=t)}}))},e.onFragLoading=function(t,e){var r=this.cea608Parser1,i=this.cea608Parser2,n=this.lastSn,a=this.lastPartIndex;if(this.enabled&&r&&i&&e.frag.type===d.PlaylistLevelType.MAIN){var s,o,l=e.frag.sn,u=null!=(s=null==e||null===(o=e.part)||void 0===o?void 0:o.index)?s:-1;l===n+1||l===n&&u===a+1||(r.reset(),i.reset()),this.lastSn=l,this.lastPartIndex=u}},e.onFragLoaded=function(t,e){var r=e.frag,a=e.payload,s=this.initPTS,o=this.unparsedVttFrags;if(r.type===d.PlaylistLevelType.SUBTITLE)if(a.byteLength){if(!Object(i.isFiniteNumber)(s[r.cc]))return o.push(e),void(s.length&&this.hls.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:r,error:new Error("Missing initial subtitle PTS")}));var l=r.decryptdata,c="stats"in e;if(null==l||null==l.key||"AES-128"!==l.method||c){var h=this.tracks[r.level],f=this.vttCCs;f[r.cc]||(f[r.cc]={start:r.start,prevCC:this.prevCC,new:!0},this.prevCC=r.cc),h&&h.textCodec===u.IMSC1_CODEC?this._parseIMSC1(r,a):this._parseVTTs(r,a,f)}}else this.hls.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:r,error:new Error("Empty subtitle payload")})},e._parseIMSC1=function(t,e){var r=this,i=this.hls;Object(u.parseIMSC1)(e,this.initPTS[t.cc],this.timescale[t.cc],(function(e){r._appendCues(e,t.level),i.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:t})}),(function(e){c.logger.log("Failed to parse IMSC1: "+e),i.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:t,error:e})}))},e._parseVTTs=function(t,e,r){var i=this,a=this.hls;Object(o.parseWebVTT)(e,this.initPTS[t.cc],this.timescale[t.cc],r,t.cc,t.start,(function(e){i._appendCues(e,t.level),a.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:t})}),(function(r){i._fallbackToIMSC1(t,e),c.logger.log("Failed to parse VTT cue: "+r),a.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:t,error:r})}))},e._fallbackToIMSC1=function(t,e){var r=this,i=this.tracks[t.level];i.textCodec||Object(u.parseIMSC1)(e,this.initPTS[t.cc],this.timescale[t.cc],(function(){i.textCodec=u.IMSC1_CODEC,r._parseIMSC1(t,e)}),(function(){i.textCodec="wvtt"}))},e._appendCues=function(t,e){var r=this.hls;if(this.config.renderTextTracksNatively){var i=this.textTracks[e];if(!i||"disabled"===i.mode)return;t.forEach((function(t){return Object(l.addCueToTrack)(i,t)}))}else{var a=this.tracks[e];if(!a)return;var s=a.default?"default":"subtitles"+e;r.trigger(n.Events.CUES_PARSED,{type:"subtitles",cues:t,track:s})}},e.onFragDecrypted=function(t,e){var r=e.frag;if(r.type===d.PlaylistLevelType.SUBTITLE){if(!Object(i.isFiniteNumber)(this.initPTS[r.cc]))return void this.unparsedVttFrags.push(e);this.onFragLoaded(n.Events.FRAG_LOADED,e)}},e.onSubtitleTracksCleared=function(){this.tracks=[],this.captionsTracks={}},e.onFragParsingUserdata=function(t,e){var r=this.cea608Parser1,i=this.cea608Parser2;if(this.enabled&&r&&i)for(var n=0;n<e.samples.length;n++){var a=e.samples[n].bytes;if(a){var s=this.extractCea608Data(a);r.addData(e.samples[n].pts,s[0]),i.addData(e.samples[n].pts,s[1])}}},e.onBufferFlushing=function(t,e){var r=e.startOffset,i=e.endOffset,n=e.endOffsetSubtitles,a=e.type,s=this.media;if(s&&!(s.currentTime<i)){if(!a||"video"===a){var o=this.captionsTracks;Object.keys(o).forEach((function(t){return Object(l.removeCuesInRange)(o[t],r,i)}))}if(this.config.renderTextTracksNatively&&0===r&&void 0!==n){var u=this.textTracks;Object.keys(u).forEach((function(t){return Object(l.removeCuesInRange)(u[t],r,n)}))}}},e.extractCea608Data=function(t){for(var e=[[],[]],r=31&t[0],i=2,n=0;n<r;n++){var a=t[i++],s=127&t[i++],o=127&t[i++];if((0!==s||0!==o)&&0!=(4&a)){var l=3&a;0!==l&&1!==l||(e[l].push(s),e[l].push(o))}}return e},t}();function f(t,e){return t&&t.label===e.name&&!(t.textTrack1||t.textTrack2)}},"./src/crypt/aes-crypto.ts":
105
+ /*! exports provided: TimelineController */function(t,e,r){r.r(e),r.d(e,"TimelineController",(function(){return f}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../utils/cea-608-parser */"./src/utils/cea-608-parser.ts"),s=r(/*! ../utils/output-filter */"./src/utils/output-filter.ts"),o=r(/*! ../utils/webvtt-parser */"./src/utils/webvtt-parser.ts"),l=r(/*! ../utils/texttrack-utils */"./src/utils/texttrack-utils.ts"),u=r(/*! ../utils/imsc1-ttml-parser */"./src/utils/imsc1-ttml-parser.ts"),d=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),c=r(/*! ../types/loader */"./src/types/loader.ts"),h=r(/*! ../utils/logger */"./src/utils/logger.ts"),f=function(){function t(t){if(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.timescale=[],this.unparsedVttFrags=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.cea608Parser1=void 0,this.cea608Parser2=void 0,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}},this.config.enableCEA708Captions){var e=new s.default(this,"textTrack1"),r=new s.default(this,"textTrack2"),i=new s.default(this,"textTrack3"),o=new s.default(this,"textTrack4");this.cea608Parser1=new a.default(1,e,r),this.cea608Parser2=new a.default(3,i,o)}t.on(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(n.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(n.Events.FRAG_LOADING,this.onFragLoading,this),t.on(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.on(n.Events.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.on(n.Events.FRAG_DECRYPTED,this.onFragDecrypted,this),t.on(n.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(n.Events.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.on(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this)}var e=t.prototype;return e.destroy=function(){var t=this.hls;t.off(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(n.Events.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(n.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(n.Events.FRAG_LOADING,this.onFragLoading,this),t.off(n.Events.FRAG_LOADED,this.onFragLoaded,this),t.off(n.Events.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.off(n.Events.FRAG_DECRYPTED,this.onFragDecrypted,this),t.off(n.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(n.Events.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.off(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=this.cea608Parser1=this.cea608Parser2=null},e.addCues=function(t,e,r,i,a){for(var s,o,l,u,d=!1,c=a.length;c--;){var h=a[c],f=(s=h[0],o=h[1],l=e,u=r,Math.min(o,u)-Math.max(s,l));if(f>=0&&(h[0]=Math.min(h[0],e),h[1]=Math.max(h[1],r),d=!0,f/(r-e)>.5))return}if(d||a.push([e,r]),this.config.renderTextTracksNatively){var g=this.captionsTracks[t];this.Cues.newCue(g,e,r,i)}else{var v=this.Cues.newCue(null,e,r,i);this.hls.trigger(n.Events.CUES_PARSED,{type:"captions",cues:v,track:t})}},e.onInitPtsFound=function(t,e){var r=this,i=e.frag,a=e.id,s=e.initPTS,o=e.timescale,l=this.unparsedVttFrags;"main"===a&&(this.initPTS[i.cc]=s,this.timescale[i.cc]=o),l.length&&(this.unparsedVttFrags=[],l.forEach((function(t){r.onFragLoaded(n.Events.FRAG_LOADED,t)})))},e.getExistingTrack=function(t){var e=this.media;if(e)for(var r=0;r<e.textTracks.length;r++){var i=e.textTracks[r];if(i[t])return i}return null},e.createCaptionsTrack=function(t){this.config.renderTextTracksNatively?this.createNativeTrack(t):this.createNonNativeTrack(t)},e.createNativeTrack=function(t){if(!this.captionsTracks[t]){var e=this.captionsProperties,r=this.captionsTracks,i=this.media,n=e[t],a=n.label,s=n.languageCode,o=this.getExistingTrack(t);if(o)r[t]=o,Object(l.clearCurrentCues)(r[t]),Object(l.sendAddTrackEvent)(r[t],i);else{var u=this.createTextTrack("captions",a,s);u&&(u[t]=!0,r[t]=u)}}},e.createNonNativeTrack=function(t){if(!this.nonNativeCaptionsTracks[t]){var e=this.captionsProperties[t];if(e){var r={_id:t,label:e.label,kind:"captions",default:!!e.media&&!!e.media.default,closedCaptions:e.media};this.nonNativeCaptionsTracks[t]=r,this.hls.trigger(n.Events.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:[r]})}}},e.createTextTrack=function(t,e,r){var i=this.media;if(i)return i.addTextTrack(t,e,r)},e.onMediaAttaching=function(t,e){this.media=e.media,this._cleanTracks()},e.onMediaDetaching=function(){var t=this.captionsTracks;Object.keys(t).forEach((function(e){Object(l.clearCurrentCues)(t[e]),delete t[e]})),this.nonNativeCaptionsTracks={}},e.onManifestLoading=function(){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.unparsedVttFrags||[],this.initPTS=[],this.timescale=[],this.cea608Parser1&&this.cea608Parser2&&(this.cea608Parser1.reset(),this.cea608Parser2.reset())},e._cleanTracks=function(){var t=this.media;if(t){var e=t.textTracks;if(e)for(var r=0;r<e.length;r++)Object(l.clearCurrentCues)(e[r])}},e.onSubtitleTracksUpdated=function(t,e){var r=this;this.textTracks=[];var i=e.subtitleTracks||[],a=i.some((function(t){return t.textCodec===u.IMSC1_CODEC}));if(this.config.enableWebVTT||a&&this.config.enableIMSC1){var s=this.tracks&&i&&this.tracks.length===i.length;if(this.tracks=i||[],this.config.renderTextTracksNatively){var o=this.media?this.media.textTracks:[];this.tracks.forEach((function(t,e){var i;if(e<o.length){for(var n=null,a=0;a<o.length;a++)if(g(o[a],t)){n=o[a];break}n&&(i=n)}if(i)Object(l.clearCurrentCues)(i);else{var s=r._captionsOrSubtitlesFromCharacteristics(t);(i=r.createTextTrack(s,t.name,t.lang))&&(i.mode="disabled")}i&&(i.groupId=t.groupId,r.textTracks.push(i))}))}else if(!s&&this.tracks&&this.tracks.length){var d=this.tracks.map((function(t){return{label:t.name,kind:t.type.toLowerCase(),default:t.default,subtitleTrack:t}}));this.hls.trigger(n.Events.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:d})}}},e._captionsOrSubtitlesFromCharacteristics=function(t){var e;if(null!==(e=t.attrs)&&void 0!==e&&e.CHARACTERISTICS){var r=/transcribes-spoken-dialog/gi.test(t.attrs.CHARACTERISTICS),i=/describes-music-and-sound/gi.test(t.attrs.CHARACTERISTICS);if(r&&i)return"captions"}return"subtitles"},e.onManifestLoaded=function(t,e){var r=this;this.config.enableCEA708Captions&&e.captions&&e.captions.forEach((function(t){var e=/(?:CC|SERVICE)([1-4])/.exec(t.instreamId);if(e){var i="textTrack"+e[1],n=r.captionsProperties[i];n&&(n.label=t.name,t.lang&&(n.languageCode=t.lang),n.media=t)}}))},e.onFragLoading=function(t,e){var r=this.cea608Parser1,i=this.cea608Parser2,n=this.lastSn,a=this.lastPartIndex;if(this.enabled&&r&&i&&e.frag.type===c.PlaylistLevelType.MAIN){var s,o,l=e.frag.sn,u=null!=(s=null==e||null===(o=e.part)||void 0===o?void 0:o.index)?s:-1;l===n+1||l===n&&u===a+1||(r.reset(),i.reset()),this.lastSn=l,this.lastPartIndex=u}},e.onFragLoaded=function(t,e){var r=e.frag,a=e.payload,s=this.initPTS,o=this.unparsedVttFrags;if(r.type===c.PlaylistLevelType.SUBTITLE)if(a.byteLength){if(!Object(i.isFiniteNumber)(s[r.cc]))return o.push(e),void(s.length&&this.hls.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:r,error:new Error("Missing initial subtitle PTS")}));var l=r.decryptdata,d="stats"in e;if(null==l||null==l.key||"AES-128"!==l.method||d){var h=this.tracks[r.level],f=this.vttCCs;f[r.cc]||(f[r.cc]={start:r.start,prevCC:this.prevCC,new:!0},this.prevCC=r.cc),h&&h.textCodec===u.IMSC1_CODEC?this._parseIMSC1(r,a):this._parseVTTs(r,a,f)}}else this.hls.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:r,error:new Error("Empty subtitle payload")})},e._parseIMSC1=function(t,e){var r=this,i=this.hls;Object(u.parseIMSC1)(e,this.initPTS[t.cc],this.timescale[t.cc],(function(e){r._appendCues(e,t.level),i.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:t})}),(function(e){h.logger.log("Failed to parse IMSC1: "+e),i.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:t,error:e})}))},e._parseVTTs=function(t,e,r){var i,a=this,s=this.hls,l=null!==(i=t.initSegment)&&void 0!==i&&i.data?Object(d.appendUint8Array)(t.initSegment.data,new Uint8Array(e)):e;Object(o.parseWebVTT)(l,this.initPTS[t.cc],this.timescale[t.cc],r,t.cc,t.start,(function(e){a._appendCues(e,t.level),s.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:t})}),(function(r){a._fallbackToIMSC1(t,e),h.logger.log("Failed to parse VTT cue: "+r),s.trigger(n.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:t,error:r})}))},e._fallbackToIMSC1=function(t,e){var r=this,i=this.tracks[t.level];i.textCodec||Object(u.parseIMSC1)(e,this.initPTS[t.cc],this.timescale[t.cc],(function(){i.textCodec=u.IMSC1_CODEC,r._parseIMSC1(t,e)}),(function(){i.textCodec="wvtt"}))},e._appendCues=function(t,e){var r=this.hls;if(this.config.renderTextTracksNatively){var i=this.textTracks[e];if(!i||"disabled"===i.mode)return;t.forEach((function(t){return Object(l.addCueToTrack)(i,t)}))}else{var a=this.tracks[e];if(!a)return;var s=a.default?"default":"subtitles"+e;r.trigger(n.Events.CUES_PARSED,{type:"subtitles",cues:t,track:s})}},e.onFragDecrypted=function(t,e){var r=e.frag;if(r.type===c.PlaylistLevelType.SUBTITLE){if(!Object(i.isFiniteNumber)(this.initPTS[r.cc]))return void this.unparsedVttFrags.push(e);this.onFragLoaded(n.Events.FRAG_LOADED,e)}},e.onSubtitleTracksCleared=function(){this.tracks=[],this.captionsTracks={}},e.onFragParsingUserdata=function(t,e){var r=this.cea608Parser1,i=this.cea608Parser2;if(this.enabled&&r&&i)for(var n=0;n<e.samples.length;n++){var a=e.samples[n].bytes;if(a){var s=this.extractCea608Data(a);r.addData(e.samples[n].pts,s[0]),i.addData(e.samples[n].pts,s[1])}}},e.onBufferFlushing=function(t,e){var r=e.startOffset,i=e.endOffset,n=e.endOffsetSubtitles,a=e.type,s=this.media;if(s&&!(s.currentTime<i)){if(!a||"video"===a){var o=this.captionsTracks;Object.keys(o).forEach((function(t){return Object(l.removeCuesInRange)(o[t],r,i)}))}if(this.config.renderTextTracksNatively&&0===r&&void 0!==n){var u=this.textTracks;Object.keys(u).forEach((function(t){return Object(l.removeCuesInRange)(u[t],r,n)}))}}},e.extractCea608Data=function(t){for(var e=[[],[]],r=31&t[0],i=2,n=0;n<r;n++){var a=t[i++],s=127&t[i++],o=127&t[i++];if((0!==s||0!==o)&&0!=(4&a)){var l=3&a;0!==l&&1!==l||(e[l].push(s),e[l].push(o))}}return e},t}();function g(t,e){return t&&t.label===e.name&&!(t.textTrack1||t.textTrack2)}},"./src/crypt/aes-crypto.ts":
106
106
  /*!*********************************!*\
107
107
  !*** ./src/crypt/aes-crypto.ts ***!
108
108
  \*********************************/
@@ -110,7 +110,7 @@
110
110
  /*!************************************!*\
111
111
  !*** ./src/crypt/aes-decryptor.ts ***!
112
112
  \************************************/
113
- /*! exports provided: removePadding, default */function(t,e,r){r.r(e),r.d(e,"removePadding",(function(){return n})),r.d(e,"default",(function(){return a}));var i=r(/*! ../utils/typed-array */"./src/utils/typed-array.ts");function n(t){var e=t.byteLength,r=e&&new DataView(t.buffer).getUint8(e-1);return r?Object(i.sliceUint8)(t,0,e-r):t}var a=function(){function t(){this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}var e=t.prototype;return e.uint8ArrayToUint32Array_=function(t){for(var e=new DataView(t),r=new Uint32Array(4),i=0;i<4;i++)r[i]=e.getUint32(4*i);return r},e.initTable=function(){var t=this.sBox,e=this.invSBox,r=this.subMix,i=r[0],n=r[1],a=r[2],s=r[3],o=this.invSubMix,l=o[0],u=o[1],d=o[2],c=o[3],h=new Uint32Array(256),f=0,g=0,v=0;for(v=0;v<256;v++)h[v]=v<128?v<<1:v<<1^283;for(v=0;v<256;v++){var p=g^g<<1^g<<2^g<<3^g<<4;p=p>>>8^255&p^99,t[f]=p,e[p]=f;var m=h[f],y=h[m],E=h[y],T=257*h[p]^16843008*p;i[f]=T<<24|T>>>8,n[f]=T<<16|T>>>16,a[f]=T<<8|T>>>24,s[f]=T,T=16843009*E^65537*y^257*m^16843008*f,l[p]=T<<24|T>>>8,u[p]=T<<16|T>>>16,d[p]=T<<8|T>>>24,c[p]=T,f?(f=m^h[h[h[E^m]]],g^=h[h[g]]):f=g=1}},e.expandKey=function(t){for(var e=this.uint8ArrayToUint32Array_(t),r=!0,i=0;i<e.length&&r;)r=e[i]===this.key[i],i++;if(!r){this.key=e;var n=this.keySize=e.length;if(4!==n&&6!==n&&8!==n)throw new Error("Invalid aes key size="+n);var a,s,o,l,u=this.ksRows=4*(n+6+1),d=this.keySchedule=new Uint32Array(u),c=this.invKeySchedule=new Uint32Array(u),h=this.sBox,f=this.rcon,g=this.invSubMix,v=g[0],p=g[1],m=g[2],y=g[3];for(a=0;a<u;a++)a<n?o=d[a]=e[a]:(l=o,a%n==0?(l=h[(l=l<<8|l>>>24)>>>24]<<24|h[l>>>16&255]<<16|h[l>>>8&255]<<8|h[255&l],l^=f[a/n|0]<<24):n>6&&a%n==4&&(l=h[l>>>24]<<24|h[l>>>16&255]<<16|h[l>>>8&255]<<8|h[255&l]),d[a]=o=(d[a-n]^l)>>>0);for(s=0;s<u;s++)a=u-s,l=3&s?d[a]:d[a-4],c[s]=s<4||a<=4?l:v[h[l>>>24]]^p[h[l>>>16&255]]^m[h[l>>>8&255]]^y[h[255&l]],c[s]=c[s]>>>0}},e.networkToHostOrderSwap=function(t){return t<<24|(65280&t)<<8|(16711680&t)>>8|t>>>24},e.decrypt=function(t,e,r){for(var i,n,a,s,o,l,u,d,c,h,f,g,v,p,m=this.keySize+6,y=this.invKeySchedule,E=this.invSBox,T=this.invSubMix,S=T[0],b=T[1],L=T[2],D=T[3],A=this.uint8ArrayToUint32Array_(r),R=A[0],k=A[1],I=A[2],_=A[3],O=new Int32Array(t),C=new Int32Array(O.length),w=this.networkToHostOrderSwap;e<O.length;){for(c=w(O[e]),h=w(O[e+1]),f=w(O[e+2]),g=w(O[e+3]),o=c^y[0],l=g^y[1],u=f^y[2],d=h^y[3],v=4,p=1;p<m;p++)i=S[o>>>24]^b[l>>16&255]^L[u>>8&255]^D[255&d]^y[v],n=S[l>>>24]^b[u>>16&255]^L[d>>8&255]^D[255&o]^y[v+1],a=S[u>>>24]^b[d>>16&255]^L[o>>8&255]^D[255&l]^y[v+2],s=S[d>>>24]^b[o>>16&255]^L[l>>8&255]^D[255&u]^y[v+3],o=i,l=n,u=a,d=s,v+=4;i=E[o>>>24]<<24^E[l>>16&255]<<16^E[u>>8&255]<<8^E[255&d]^y[v],n=E[l>>>24]<<24^E[u>>16&255]<<16^E[d>>8&255]<<8^E[255&o]^y[v+1],a=E[u>>>24]<<24^E[d>>16&255]<<16^E[o>>8&255]<<8^E[255&l]^y[v+2],s=E[d>>>24]<<24^E[o>>16&255]<<16^E[l>>8&255]<<8^E[255&u]^y[v+3],C[e]=w(i^R),C[e+1]=w(s^k),C[e+2]=w(a^I),C[e+3]=w(n^_),R=c,k=h,I=f,_=g,e+=4}return C.buffer},t}()},"./src/crypt/decrypter.ts":
113
+ /*! exports provided: removePadding, default */function(t,e,r){r.r(e),r.d(e,"removePadding",(function(){return n})),r.d(e,"default",(function(){return a}));var i=r(/*! ../utils/typed-array */"./src/utils/typed-array.ts");function n(t){var e=t.byteLength,r=e&&new DataView(t.buffer).getUint8(e-1);return r?Object(i.sliceUint8)(t,0,e-r):t}var a=function(){function t(){this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}var e=t.prototype;return e.uint8ArrayToUint32Array_=function(t){for(var e=new DataView(t),r=new Uint32Array(4),i=0;i<4;i++)r[i]=e.getUint32(4*i);return r},e.initTable=function(){var t=this.sBox,e=this.invSBox,r=this.subMix,i=r[0],n=r[1],a=r[2],s=r[3],o=this.invSubMix,l=o[0],u=o[1],d=o[2],c=o[3],h=new Uint32Array(256),f=0,g=0,v=0;for(v=0;v<256;v++)h[v]=v<128?v<<1:v<<1^283;for(v=0;v<256;v++){var p=g^g<<1^g<<2^g<<3^g<<4;p=p>>>8^255&p^99,t[f]=p,e[p]=f;var m=h[f],y=h[m],E=h[y],T=257*h[p]^16843008*p;i[f]=T<<24|T>>>8,n[f]=T<<16|T>>>16,a[f]=T<<8|T>>>24,s[f]=T,T=16843009*E^65537*y^257*m^16843008*f,l[p]=T<<24|T>>>8,u[p]=T<<16|T>>>16,d[p]=T<<8|T>>>24,c[p]=T,f?(f=m^h[h[h[E^m]]],g^=h[h[g]]):f=g=1}},e.expandKey=function(t){for(var e=this.uint8ArrayToUint32Array_(t),r=!0,i=0;i<e.length&&r;)r=e[i]===this.key[i],i++;if(!r){this.key=e;var n=this.keySize=e.length;if(4!==n&&6!==n&&8!==n)throw new Error("Invalid aes key size="+n);var a,s,o,l,u=this.ksRows=4*(n+6+1),d=this.keySchedule=new Uint32Array(u),c=this.invKeySchedule=new Uint32Array(u),h=this.sBox,f=this.rcon,g=this.invSubMix,v=g[0],p=g[1],m=g[2],y=g[3];for(a=0;a<u;a++)a<n?o=d[a]=e[a]:(l=o,a%n==0?(l=h[(l=l<<8|l>>>24)>>>24]<<24|h[l>>>16&255]<<16|h[l>>>8&255]<<8|h[255&l],l^=f[a/n|0]<<24):n>6&&a%n==4&&(l=h[l>>>24]<<24|h[l>>>16&255]<<16|h[l>>>8&255]<<8|h[255&l]),d[a]=o=(d[a-n]^l)>>>0);for(s=0;s<u;s++)a=u-s,l=3&s?d[a]:d[a-4],c[s]=s<4||a<=4?l:v[h[l>>>24]]^p[h[l>>>16&255]]^m[h[l>>>8&255]]^y[h[255&l]],c[s]=c[s]>>>0}},e.networkToHostOrderSwap=function(t){return t<<24|(65280&t)<<8|(16711680&t)>>8|t>>>24},e.decrypt=function(t,e,r){for(var i,n,a,s,o,l,u,d,c,h,f,g,v,p,m=this.keySize+6,y=this.invKeySchedule,E=this.invSBox,T=this.invSubMix,S=T[0],b=T[1],L=T[2],D=T[3],A=this.uint8ArrayToUint32Array_(r),R=A[0],k=A[1],I=A[2],_=A[3],C=new Int32Array(t),O=new Int32Array(C.length),w=this.networkToHostOrderSwap;e<C.length;){for(c=w(C[e]),h=w(C[e+1]),f=w(C[e+2]),g=w(C[e+3]),o=c^y[0],l=g^y[1],u=f^y[2],d=h^y[3],v=4,p=1;p<m;p++)i=S[o>>>24]^b[l>>16&255]^L[u>>8&255]^D[255&d]^y[v],n=S[l>>>24]^b[u>>16&255]^L[d>>8&255]^D[255&o]^y[v+1],a=S[u>>>24]^b[d>>16&255]^L[o>>8&255]^D[255&l]^y[v+2],s=S[d>>>24]^b[o>>16&255]^L[l>>8&255]^D[255&u]^y[v+3],o=i,l=n,u=a,d=s,v+=4;i=E[o>>>24]<<24^E[l>>16&255]<<16^E[u>>8&255]<<8^E[255&d]^y[v],n=E[l>>>24]<<24^E[u>>16&255]<<16^E[d>>8&255]<<8^E[255&o]^y[v+1],a=E[u>>>24]<<24^E[d>>16&255]<<16^E[o>>8&255]<<8^E[255&l]^y[v+2],s=E[d>>>24]<<24^E[o>>16&255]<<16^E[l>>8&255]<<8^E[255&u]^y[v+3],O[e]=w(i^R),O[e+1]=w(s^k),O[e+2]=w(a^I),O[e+3]=w(n^_),R=c,k=h,I=f,_=g,e+=4}return O.buffer},t}()},"./src/crypt/decrypter.ts":
114
114
  /*!********************************!*\
115
115
  !*** ./src/crypt/decrypter.ts ***!
116
116
  \********************************/
@@ -122,7 +122,7 @@
122
122
  /*!*********************************!*\
123
123
  !*** ./src/demux/aacdemuxer.ts ***!
124
124
  \*********************************/
125
- /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./base-audio-demuxer */"./src/demux/base-audio-demuxer.ts"),n=r(/*! ./adts */"./src/demux/adts.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! ../demux/id3 */"./src/demux/id3.ts");function o(t,e){return(o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var l=function(t){var e,r;function i(e,r){var i;return(i=t.call(this)||this).observer=void 0,i.config=void 0,i.observer=e,i.config=r,i}r=t,(e=i).prototype=Object.create(r.prototype),e.prototype.constructor=e,o(e,r);var l=i.prototype;return l.resetInitSegment=function(e,r,i,n){t.prototype.resetInitSegment.call(this,e,r,i,n),this._audioTrack={container:"audio/adts",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"aac",samples:[],manifestCodec:r,duration:n,inputTimeScale:9e4,dropped:0}},i.probe=function(t){if(!t)return!1;for(var e=(s.getID3Data(t,0)||[]).length,r=t.length;e<r;e++)if(n.probe(t,e))return a.logger.log("ADTS sync word found !"),!0;return!1},l.canParse=function(t,e){return n.canParse(t,e)},l.appendFrame=function(t,e,r){n.initTrackConfig(t,this.observer,e,r,t.manifestCodec);var i=n.appendFrame(t,e,r,this.initPTS,this.frameIndex);if(i&&0===i.missing)return i},i}(i.default);l.minProbeByteLength=9,e.default=l},"./src/demux/adts.ts":
125
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./base-audio-demuxer */"./src/demux/base-audio-demuxer.ts"),n=r(/*! ./adts */"./src/demux/adts.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! ../demux/id3 */"./src/demux/id3.ts");function o(t,e){return(o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var l=function(t){var e,r;function i(e,r){var i;return(i=t.call(this)||this).observer=void 0,i.config=void 0,i.observer=e,i.config=r,i}r=t,(e=i).prototype=Object.create(r.prototype),e.prototype.constructor=e,o(e,r);var l=i.prototype;return l.resetInitSegment=function(e,r,i,n){t.prototype.resetInitSegment.call(this,e,r,i,n),this._audioTrack={container:"audio/adts",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"aac",samples:[],manifestCodec:r,duration:n,inputTimeScale:9e4,dropped:0}},i.probe=function(t){if(!t)return!1;for(var e=(s.getID3Data(t,0)||[]).length,r=t.length;e<r;e++)if(n.probe(t,e))return a.logger.log("ADTS sync word found !"),!0;return!1},l.canParse=function(t,e){return n.canParse(t,e)},l.appendFrame=function(t,e,r){n.initTrackConfig(t,this.observer,e,r,t.manifestCodec);var i=n.appendFrame(t,e,r,this.basePTS,this.frameIndex);if(i&&0===i.missing)return i},i}(i.default);e.default=l},"./src/demux/adts.ts":
126
126
  /*!***************************!*\
127
127
  !*** ./src/demux/adts.ts ***!
128
128
  \***************************/
@@ -130,7 +130,7 @@
130
130
  /*!*****************************************!*\
131
131
  !*** ./src/demux/base-audio-demuxer.ts ***!
132
132
  \*****************************************/
133
- /*! exports provided: initPTSFn, default */function(t,e,r){r.r(e),r.d(e,"initPTSFn",(function(){return d}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../demux/id3 */"./src/demux/id3.ts"),a=r(/*! ../types/demuxer */"./src/types/demuxer.ts"),s=r(/*! ./dummy-demuxed-track */"./src/demux/dummy-demuxed-track.ts"),o=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),l=r(/*! ../utils/typed-array */"./src/utils/typed-array.ts"),u=function(){function t(){this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.initPTS=null}var e=t.prototype;return e.resetInitSegment=function(t,e,r,i){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}},e.resetTimeStamp=function(){},e.resetContiguity=function(){},e.canParse=function(t,e){return!1},e.appendFrame=function(t,e,r){},e.demux=function(t,e){this.cachedData&&(t=Object(o.appendUint8Array)(this.cachedData,t),this.cachedData=null);var r,i,u=n.getID3Data(t,0),c=u?u.length:0,h=this._audioTrack,f=this._id3Track,g=u?n.getTimeStamp(u):void 0,v=t.length;for(0!==this.frameIndex&&null!==this.initPTS||(this.initPTS=d(g,e)),u&&u.length>0&&f.samples.push({pts:this.initPTS,dts:this.initPTS,data:u,type:a.MetadataSchema.audioId3}),i=this.initPTS;c<v;){if(this.canParse(t,c)){var p=this.appendFrame(h,t,c);p?(this.frameIndex++,i=p.sample.pts,r=c+=p.length):c=v}else n.canParse(t,c)?(u=n.getID3Data(t,c),f.samples.push({pts:i,dts:i,data:u,type:a.MetadataSchema.audioId3}),r=c+=u.length):c++;if(c===v&&r!==v){var m=Object(l.sliceUint8)(t,r);this.cachedData?this.cachedData=Object(o.appendUint8Array)(this.cachedData,m):this.cachedData=m}}return{audioTrack:h,videoTrack:Object(s.dummyTrack)(),id3Track:f,textTrack:Object(s.dummyTrack)()}},e.demuxSampleAes=function(t,e,r){return Promise.reject(new Error("["+this+"] This demuxer does not support Sample-AES decryption"))},e.flush=function(t){var e=this.cachedData;return e&&(this.cachedData=null,this.demux(e,0)),this.frameIndex=0,{audioTrack:this._audioTrack,videoTrack:Object(s.dummyTrack)(),id3Track:this._id3Track,textTrack:Object(s.dummyTrack)()}},e.destroy=function(){},t}(),d=function(t,e){return Object(i.isFiniteNumber)(t)?90*t:9e4*e};e.default=u},"./src/demux/chunk-cache.ts":
133
+ /*! exports provided: initPTSFn, default */function(t,e,r){r.r(e),r.d(e,"initPTSFn",(function(){return d}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../demux/id3 */"./src/demux/id3.ts"),a=r(/*! ../types/demuxer */"./src/types/demuxer.ts"),s=r(/*! ./dummy-demuxed-track */"./src/demux/dummy-demuxed-track.ts"),o=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),l=r(/*! ../utils/typed-array */"./src/utils/typed-array.ts"),u=function(){function t(){this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null}var e=t.prototype;return e.resetInitSegment=function(t,e,r,i){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}},e.resetTimeStamp=function(t){this.initPTS=t,this.resetContiguity()},e.resetContiguity=function(){this.basePTS=null,this.frameIndex=0},e.canParse=function(t,e){return!1},e.appendFrame=function(t,e,r){},e.demux=function(t,e){this.cachedData&&(t=Object(o.appendUint8Array)(this.cachedData,t),this.cachedData=null);var r,u,c=n.getID3Data(t,0),h=c?c.length:0,f=this._audioTrack,g=this._id3Track,v=c?n.getTimeStamp(c):void 0,p=t.length;for((null===this.basePTS||0===this.frameIndex&&Object(i.isFiniteNumber)(v))&&(this.basePTS=d(v,e,this.initPTS)),c&&c.length>0&&g.samples.push({pts:this.basePTS,dts:this.basePTS,data:c,type:a.MetadataSchema.audioId3}),u=this.basePTS;h<p;){if(this.canParse(t,h)){var m=this.appendFrame(f,t,h);m?(this.frameIndex++,u=m.sample.pts,r=h+=m.length):h=p}else n.canParse(t,h)?(c=n.getID3Data(t,h),g.samples.push({pts:u,dts:u,data:c,type:a.MetadataSchema.audioId3}),r=h+=c.length):h++;if(h===p&&r!==p){var y=Object(l.sliceUint8)(t,r);this.cachedData?this.cachedData=Object(o.appendUint8Array)(this.cachedData,y):this.cachedData=y}}return{audioTrack:f,videoTrack:Object(s.dummyTrack)(),id3Track:g,textTrack:Object(s.dummyTrack)()}},e.demuxSampleAes=function(t,e,r){return Promise.reject(new Error("["+this+"] This demuxer does not support Sample-AES decryption"))},e.flush=function(t){var e=this.cachedData;return e&&(this.cachedData=null,this.demux(e,0)),{audioTrack:this._audioTrack,videoTrack:Object(s.dummyTrack)(),id3Track:this._id3Track,textTrack:Object(s.dummyTrack)()}},e.destroy=function(){},t}(),d=function(t,e,r){return Object(i.isFiniteNumber)(t)?90*t:9e4*e+(r||0)};e.default=u},"./src/demux/chunk-cache.ts":
134
134
  /*!**********************************!*\
135
135
  !*** ./src/demux/chunk-cache.ts ***!
136
136
  \**********************************/
@@ -150,11 +150,11 @@
150
150
  /*!*********************************!*\
151
151
  !*** ./src/demux/mp3demuxer.ts ***!
152
152
  \*********************************/
153
- /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./base-audio-demuxer */"./src/demux/base-audio-demuxer.ts"),n=r(/*! ../demux/id3 */"./src/demux/id3.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! ./mpegaudio */"./src/demux/mpegaudio.ts");function o(t,e){return(o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var l=function(t){var e,r;function i(){return t.apply(this,arguments)||this}r=t,(e=i).prototype=Object.create(r.prototype),e.prototype.constructor=e,o(e,r);var l=i.prototype;return l.resetInitSegment=function(e,r,i,n){t.prototype.resetInitSegment.call(this,e,r,i,n),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:r,duration:n,inputTimeScale:9e4,dropped:0}},i.probe=function(t){if(!t)return!1;for(var e=(n.getID3Data(t,0)||[]).length,r=t.length;e<r;e++)if(s.probe(t,e))return a.logger.log("MPEG Audio sync word found !"),!0;return!1},l.canParse=function(t,e){return s.canParse(t,e)},l.appendFrame=function(t,e,r){if(null!==this.initPTS)return s.appendFrame(t,e,r,this.initPTS,this.frameIndex)},i}(i.default);l.minProbeByteLength=4,e.default=l},"./src/demux/mp4demuxer.ts":
153
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./base-audio-demuxer */"./src/demux/base-audio-demuxer.ts"),n=r(/*! ../demux/id3 */"./src/demux/id3.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! ./mpegaudio */"./src/demux/mpegaudio.ts");function o(t,e){return(o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var l=function(t){var e,r;function i(){return t.apply(this,arguments)||this}r=t,(e=i).prototype=Object.create(r.prototype),e.prototype.constructor=e,o(e,r);var l=i.prototype;return l.resetInitSegment=function(e,r,i,n){t.prototype.resetInitSegment.call(this,e,r,i,n),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:r,duration:n,inputTimeScale:9e4,dropped:0}},i.probe=function(t){if(!t)return!1;for(var e=(n.getID3Data(t,0)||[]).length,r=t.length;e<r;e++)if(s.probe(t,e))return a.logger.log("MPEG Audio sync word found !"),!0;return!1},l.canParse=function(t,e){return s.canParse(t,e)},l.appendFrame=function(t,e,r){if(null!==this.basePTS)return s.appendFrame(t,e,r,this.basePTS,this.frameIndex)},i}(i.default);e.default=l},"./src/demux/mp4demuxer.ts":
154
154
  /*!*********************************!*\
155
155
  !*** ./src/demux/mp4demuxer.ts ***!
156
156
  \*********************************/
157
- /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../types/demuxer */"./src/types/demuxer.ts"),a=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),s=r(/*! ./dummy-demuxed-track */"./src/demux/dummy-demuxed-track.ts"),o=/\/emsg[-/]ID3/i,l=function(){function t(t,e){this.remainderData=null,this.timeOffset=0,this.config=void 0,this.videoTrack=void 0,this.audioTrack=void 0,this.id3Track=void 0,this.txtTrack=void 0,this.config=e}var e=t.prototype;return e.resetTimeStamp=function(){},e.resetInitSegment=function(t,e,r,i){var n=Object(a.parseInitSegment)(t),o=this.videoTrack=Object(s.dummyTrack)("video",1),l=this.audioTrack=Object(s.dummyTrack)("audio",1),u=this.txtTrack=Object(s.dummyTrack)("text",1);if(this.id3Track=Object(s.dummyTrack)("id3",1),this.timeOffset=0,n.video){var d=n.video,c=d.id,h=d.timescale,f=d.codec;o.id=c,o.timescale=u.timescale=h,o.codec=f}if(n.audio){var g=n.audio,v=g.id,p=g.timescale,m=g.codec;l.id=v,l.timescale=p,l.codec=m}u.id=a.RemuxerTrackIdConfig.text,o.sampleDuration=0,o.duration=l.duration=i},e.resetContiguity=function(){},t.probe=function(t){return t=t.length>16384?t.subarray(0,16384):t,Object(a.findBox)(t,["moof"]).length>0},e.demux=function(t,e){this.timeOffset=e;var r=t,i=this.videoTrack,n=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=Object(a.appendUint8Array)(this.remainderData,t));var s=Object(a.segmentValidRange)(r);this.remainderData=s.remainder,i.samples=s.valid||new Uint8Array}else i.samples=r;var o=this.extractID3Track(i,e);return n.samples=Object(a.parseSamples)(e,i),{videoTrack:i,audioTrack:this.audioTrack,id3Track:o,textTrack:this.txtTrack}},e.flush=function(){var t=this.timeOffset,e=this.videoTrack,r=this.txtTrack;e.samples=this.remainderData||new Uint8Array,this.remainderData=null;var i=this.extractID3Track(e,this.timeOffset);return r.samples=Object(a.parseSamples)(t,e),{videoTrack:e,audioTrack:Object(s.dummyTrack)(),id3Track:i,textTrack:Object(s.dummyTrack)()}},e.extractID3Track=function(t,e){var r=this.id3Track;if(t.samples.length){var s=Object(a.findBox)(t.samples,["emsg"]);s&&s.forEach((function(t){var s=Object(a.parseEmsg)(t);if(o.test(s.schemeIdUri)){var l=Object(i.isFiniteNumber)(s.presentationTime)?s.presentationTime/s.timeScale:e+s.presentationTimeDelta/s.timeScale,u=s.payload;r.samples.push({data:u,len:u.byteLength,dts:l,pts:l,type:n.MetadataSchema.emsg})}}))}return r},e.demuxSampleAes=function(t,e,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},e.destroy=function(){},t}();l.minProbeByteLength=1024,e.default=l},"./src/demux/mpegaudio.ts":
157
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../types/demuxer */"./src/types/demuxer.ts"),a=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),s=r(/*! ./dummy-demuxed-track */"./src/demux/dummy-demuxed-track.ts"),o=/\/emsg[-/]ID3/i,l=function(){function t(t,e){this.remainderData=null,this.timeOffset=0,this.config=void 0,this.videoTrack=void 0,this.audioTrack=void 0,this.id3Track=void 0,this.txtTrack=void 0,this.config=e}var e=t.prototype;return e.resetTimeStamp=function(){},e.resetInitSegment=function(t,e,r,i){var n=Object(a.parseInitSegment)(t),o=this.videoTrack=Object(s.dummyTrack)("video",1),l=this.audioTrack=Object(s.dummyTrack)("audio",1),u=this.txtTrack=Object(s.dummyTrack)("text",1);if(this.id3Track=Object(s.dummyTrack)("id3",1),this.timeOffset=0,n.video){var d=n.video,c=d.id,h=d.timescale,f=d.codec;o.id=c,o.timescale=u.timescale=h,o.codec=f}if(n.audio){var g=n.audio,v=g.id,p=g.timescale,m=g.codec;l.id=v,l.timescale=p,l.codec=m}u.id=a.RemuxerTrackIdConfig.text,o.sampleDuration=0,o.duration=l.duration=i},e.resetContiguity=function(){},t.probe=function(t){return t=t.length>16384?t.subarray(0,16384):t,Object(a.findBox)(t,["moof"]).length>0},e.demux=function(t,e){this.timeOffset=e;var r=t,i=this.videoTrack,n=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=Object(a.appendUint8Array)(this.remainderData,t));var s=Object(a.segmentValidRange)(r);this.remainderData=s.remainder,i.samples=s.valid||new Uint8Array}else i.samples=r;var o=this.extractID3Track(i,e);return n.samples=Object(a.parseSamples)(e,i),{videoTrack:i,audioTrack:this.audioTrack,id3Track:o,textTrack:this.txtTrack}},e.flush=function(){var t=this.timeOffset,e=this.videoTrack,r=this.txtTrack;e.samples=this.remainderData||new Uint8Array,this.remainderData=null;var i=this.extractID3Track(e,this.timeOffset);return r.samples=Object(a.parseSamples)(t,e),{videoTrack:e,audioTrack:Object(s.dummyTrack)(),id3Track:i,textTrack:Object(s.dummyTrack)()}},e.extractID3Track=function(t,e){var r=this.id3Track;if(t.samples.length){var s=Object(a.findBox)(t.samples,["emsg"]);s&&s.forEach((function(t){var s=Object(a.parseEmsg)(t);if(o.test(s.schemeIdUri)){var l=Object(i.isFiniteNumber)(s.presentationTime)?s.presentationTime/s.timeScale:e+s.presentationTimeDelta/s.timeScale,u=s.payload;r.samples.push({data:u,len:u.byteLength,dts:l,pts:l,type:n.MetadataSchema.emsg})}}))}return r},e.demuxSampleAes=function(t,e,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},e.destroy=function(){},t}();e.default=l},"./src/demux/mpegaudio.ts":
158
158
  /*!********************************!*\
159
159
  !*** ./src/demux/mpegaudio.ts ***!
160
160
  \********************************/
@@ -166,19 +166,19 @@
166
166
  /*!*******************************************!*\
167
167
  !*** ./src/demux/transmuxer-interface.ts ***!
168
168
  \*******************************************/
169
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return c}));var i=r(/*! webworkify-webpack */"./node_modules/webworkify-webpack/index.js"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../demux/transmuxer */"./src/demux/transmuxer.ts"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),o=r(/*! ../errors */"./src/errors.ts"),l=r(/*! ../utils/mediasource-helper */"./src/utils/mediasource-helper.ts"),u=r(/*! eventemitter3 */"./node_modules/eventemitter3/index.js"),d=Object(l.getMediaSource)()||{isTypeSupported:function(){return!1}},c=function(){function t(t,e,r,l){var c=this;this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.worker=void 0,this.onwmsg=void 0,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0,this.hls=t,this.id=e,this.onTransmuxComplete=r,this.onFlush=l;var h=t.config,f=function(e,r){(r=r||{}).frag=c.frag,r.id=c.id,t.trigger(e,r)};this.observer=new u.EventEmitter,this.observer.on(n.Events.FRAG_DECRYPTED,f),this.observer.on(n.Events.ERROR,f);var g={mp4:d.isTypeSupported("video/mp4"),mpeg:d.isTypeSupported("audio/mpeg"),mp3:d.isTypeSupported('audio/mp4; codecs="mp3"')},v=navigator.vendor;if(h.enableWorker&&"undefined"!=typeof Worker){var p;s.logger.log("demuxing in webworker");try{p=this.worker=i(/*! ../demux/transmuxer-worker.ts */"./src/demux/transmuxer-worker.ts"),this.onwmsg=this.onWorkerMessage.bind(this),p.addEventListener("message",this.onwmsg),p.onerror=function(e){t.trigger(n.Events.ERROR,{type:o.ErrorTypes.OTHER_ERROR,details:o.ErrorDetails.INTERNAL_EXCEPTION,fatal:!0,event:"demuxerWorker",error:new Error(e.message+" ("+e.filename+":"+e.lineno+")")})},p.postMessage({cmd:"init",typeSupported:g,vendor:v,id:e,config:JSON.stringify(h)})}catch(t){s.logger.warn("Error in worker:",t),s.logger.error("Error while initializing DemuxerWorker, fallback to inline"),p&&self.URL.revokeObjectURL(p.objectURL),this.transmuxer=new a.default(this.observer,g,h,v,e),this.worker=null}}else this.transmuxer=new a.default(this.observer,g,h,v,e)}var e=t.prototype;return e.destroy=function(){var t=this.worker;if(t)t.removeEventListener("message",this.onwmsg),t.terminate(),this.worker=null,this.onwmsg=void 0;else{var e=this.transmuxer;e&&(e.destroy(),this.transmuxer=null)}var r=this.observer;r&&r.removeAllListeners(),this.frag=null,this.observer=null,this.hls=null},e.push=function(t,e,r,i,n,o,l,u,d,c){var h,f,g=this;d.transmuxing.start=self.performance.now();var v=this.transmuxer,p=this.worker,m=o?o.start:n.start,y=n.decryptdata,E=this.frag,T=!(E&&n.cc===E.cc),S=!(E&&d.level===E.level),b=E?d.sn-E.sn:-1,L=this.part?d.part-this.part.index:-1,D=!S&&(1===b||0===b&&1===L),A=self.performance.now();(S||b||0===n.stats.parsing.start)&&(n.stats.parsing.start=A),!o||!L&&D||(o.stats.parsing.start=A);var R=!(E&&(null===(h=n.initSegment)||void 0===h?void 0:h.url)===(null===(f=E.initSegment)||void 0===f?void 0:f.url)),k=new a.TransmuxState(T,D,u,S,m,R);if(!D||T||R){s.logger.log("[transmuxer-interface, "+n.type+"]: Starting new transmux session for sn: "+d.sn+" p: "+d.part+" level: "+d.level+" id: "+d.id+"\n discontinuity: "+T+"\n trackSwitch: "+S+"\n contiguous: "+D+"\n accurateTimeOffset: "+u+"\n timeOffset: "+m+"\n initSegmentChange: "+R);var I=new a.TransmuxConfig(r,i,e,l,c);this.configureTransmuxer(I)}if(this.frag=n,this.part=o,p)p.postMessage({cmd:"demux",data:t,decryptdata:y,chunkMeta:d,state:k},t instanceof ArrayBuffer?[t]:[]);else if(v){var _=v.push(t,y,d,k);Object(a.isPromise)(_)?_.then((function(t){g.handleTransmuxComplete(t)})):this.handleTransmuxComplete(_)}},e.flush=function(t){var e=this;t.transmuxing.start=self.performance.now();var r=this.transmuxer,i=this.worker;if(i)i.postMessage({cmd:"flush",chunkMeta:t});else if(r){var n=r.flush(t);Object(a.isPromise)(n)?n.then((function(r){e.handleFlushResult(r,t)})):this.handleFlushResult(n,t)}},e.handleFlushResult=function(t,e){var r=this;t.forEach((function(t){r.handleTransmuxComplete(t)})),this.onFlush(e)},e.onWorkerMessage=function(t){var e=t.data,r=this.hls;switch(e.event){case"init":self.URL.revokeObjectURL(this.worker.objectURL);break;case"transmuxComplete":this.handleTransmuxComplete(e.data);break;case"flush":this.onFlush(e.data);break;default:e.data=e.data||{},e.data.frag=this.frag,e.data.id=this.id,r.trigger(e.event,e.data)}},e.configureTransmuxer=function(t){var e=this.worker,r=this.transmuxer;e?e.postMessage({cmd:"configure",config:t}):r&&r.configure(t)},e.handleTransmuxComplete=function(t){t.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(t)},t}()},"./src/demux/transmuxer-worker.ts":
169
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return c}));var i=r(/*! webworkify-webpack */"./node_modules/webworkify-webpack/index.js"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../demux/transmuxer */"./src/demux/transmuxer.ts"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),o=r(/*! ../errors */"./src/errors.ts"),l=r(/*! ../utils/mediasource-helper */"./src/utils/mediasource-helper.ts"),u=r(/*! eventemitter3 */"./node_modules/eventemitter3/index.js"),d=Object(l.getMediaSource)()||{isTypeSupported:function(){return!1}},c=function(){function t(t,e,r,l){var c=this;this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.worker=void 0,this.onwmsg=void 0,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0,this.hls=t,this.id=e,this.onTransmuxComplete=r,this.onFlush=l;var h=t.config,f=function(e,r){(r=r||{}).frag=c.frag,r.id=c.id,t.trigger(e,r)};this.observer=new u.EventEmitter,this.observer.on(n.Events.FRAG_DECRYPTED,f),this.observer.on(n.Events.ERROR,f);var g={mp4:d.isTypeSupported("video/mp4"),mpeg:d.isTypeSupported("audio/mpeg"),mp3:d.isTypeSupported('audio/mp4; codecs="mp3"')},v=navigator.vendor;if(h.enableWorker&&"undefined"!=typeof Worker){var p;s.logger.log("demuxing in webworker");try{p=this.worker=i(/*! ../demux/transmuxer-worker.ts */"./src/demux/transmuxer-worker.ts"),this.onwmsg=this.onWorkerMessage.bind(this),p.addEventListener("message",this.onwmsg),p.onerror=function(e){t.trigger(n.Events.ERROR,{type:o.ErrorTypes.OTHER_ERROR,details:o.ErrorDetails.INTERNAL_EXCEPTION,fatal:!0,event:"demuxerWorker",error:new Error(e.message+" ("+e.filename+":"+e.lineno+")")})},p.postMessage({cmd:"init",typeSupported:g,vendor:v,id:e,config:JSON.stringify(h)})}catch(t){s.logger.warn("Error in worker:",t),s.logger.error("Error while initializing DemuxerWorker, fallback to inline"),p&&self.URL.revokeObjectURL(p.objectURL),this.transmuxer=new a.default(this.observer,g,h,v,e),this.worker=null}}else this.transmuxer=new a.default(this.observer,g,h,v,e)}var e=t.prototype;return e.destroy=function(){var t=this.worker;if(t)t.removeEventListener("message",this.onwmsg),t.terminate(),this.worker=null,this.onwmsg=void 0;else{var e=this.transmuxer;e&&(e.destroy(),this.transmuxer=null)}var r=this.observer;r&&r.removeAllListeners(),this.frag=null,this.observer=null,this.hls=null},e.push=function(t,e,r,i,n,o,l,u,d,c){var h,f,g=this;d.transmuxing.start=self.performance.now();var v=this.transmuxer,p=this.worker,m=o?o.start:n.start,y=n.decryptdata,E=this.frag,T=!(E&&n.cc===E.cc),S=!(E&&d.level===E.level),b=E?d.sn-E.sn:-1,L=this.part?d.part-this.part.index:-1,D=0===b&&d.id>1&&d.id===(null==E?void 0:E.stats.chunkCount),A=!S&&(1===b||0===b&&(1===L||D&&L<=0)),R=self.performance.now();(S||b||0===n.stats.parsing.start)&&(n.stats.parsing.start=R),!o||!L&&A||(o.stats.parsing.start=R);var k=!(E&&(null===(h=n.initSegment)||void 0===h?void 0:h.url)===(null===(f=E.initSegment)||void 0===f?void 0:f.url)),I=new a.TransmuxState(T,A,u,S,m,k);if(!A||T||k){s.logger.log("[transmuxer-interface, "+n.type+"]: Starting new transmux session for sn: "+d.sn+" p: "+d.part+" level: "+d.level+" id: "+d.id+"\n discontinuity: "+T+"\n trackSwitch: "+S+"\n contiguous: "+A+"\n accurateTimeOffset: "+u+"\n timeOffset: "+m+"\n initSegmentChange: "+k);var _=new a.TransmuxConfig(r,i,e,l,c);this.configureTransmuxer(_)}if(this.frag=n,this.part=o,p)p.postMessage({cmd:"demux",data:t,decryptdata:y,chunkMeta:d,state:I},t instanceof ArrayBuffer?[t]:[]);else if(v){var C=v.push(t,y,d,I);Object(a.isPromise)(C)?C.then((function(t){g.handleTransmuxComplete(t)})):this.handleTransmuxComplete(C)}},e.flush=function(t){var e=this;t.transmuxing.start=self.performance.now();var r=this.transmuxer,i=this.worker;if(i)i.postMessage({cmd:"flush",chunkMeta:t});else if(r){var n=r.flush(t);Object(a.isPromise)(n)?n.then((function(r){e.handleFlushResult(r,t)})):this.handleFlushResult(n,t)}},e.handleFlushResult=function(t,e){var r=this;t.forEach((function(t){r.handleTransmuxComplete(t)})),this.onFlush(e)},e.onWorkerMessage=function(t){var e=t.data,r=this.hls;switch(e.event){case"init":self.URL.revokeObjectURL(this.worker.objectURL);break;case"transmuxComplete":this.handleTransmuxComplete(e.data);break;case"flush":this.onFlush(e.data);break;case"workerLog":s.logger[e.data.logType]&&s.logger[e.data.logType](e.data.message);break;default:e.data=e.data||{},e.data.frag=this.frag,e.data.id=this.id,r.trigger(e.event,e.data)}},e.configureTransmuxer=function(t){var e=this.worker,r=this.transmuxer;e?e.postMessage({cmd:"configure",config:t}):r&&r.configure(t)},e.handleTransmuxComplete=function(t){t.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(t)},t}()},"./src/demux/transmuxer-worker.ts":
170
170
  /*!****************************************!*\
171
171
  !*** ./src/demux/transmuxer-worker.ts ***!
172
172
  \****************************************/
173
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return o}));var i=r(/*! ../demux/transmuxer */"./src/demux/transmuxer.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! eventemitter3 */"./node_modules/eventemitter3/index.js");function o(t){var e=new s.EventEmitter,r=function(e,r){t.postMessage({event:e,data:r})};e.on(n.Events.FRAG_DECRYPTED,r),e.on(n.Events.ERROR,r),t.addEventListener("message",(function(n){var s=n.data;switch(s.cmd){case"init":var o=JSON.parse(s.config);t.transmuxer=new i.default(e,s.typeSupported,o,s.vendor,s.id),Object(a.enableLogs)(o.debug),r("init",null);break;case"configure":t.transmuxer.configure(s.config);break;case"demux":var u=t.transmuxer.push(s.data,s.decryptdata,s.chunkMeta,s.state);Object(i.isPromise)(u)?u.then((function(e){l(t,e)})):l(t,u);break;case"flush":var c=s.chunkMeta,h=t.transmuxer.flush(c);Object(i.isPromise)(h)?h.then((function(e){d(t,e,c)})):d(t,h,c)}}))}function l(t,e){if(!((r=e.remuxResult).audio||r.video||r.text||r.id3||r.initSegment))return!1;var r,i=[],n=e.remuxResult,a=n.audio,s=n.video;return a&&u(i,a),s&&u(i,s),t.postMessage({event:"transmuxComplete",data:e},i),!0}function u(t,e){e.data1&&t.push(e.data1.buffer),e.data2&&t.push(e.data2.buffer)}function d(t,e,r){e.reduce((function(e,r){return l(t,r)||e}),!1)||t.postMessage({event:"transmuxComplete",data:e[0]}),t.postMessage({event:"flush",data:r})}},"./src/demux/transmuxer.ts":
173
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return o}));var i=r(/*! ../demux/transmuxer */"./src/demux/transmuxer.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! eventemitter3 */"./node_modules/eventemitter3/index.js");function o(t){var e=new s.EventEmitter,r=function(e,r){t.postMessage({event:e,data:r})};e.on(n.Events.FRAG_DECRYPTED,r),e.on(n.Events.ERROR,r),t.addEventListener("message",(function(n){var s=n.data;switch(s.cmd){case"init":var o=JSON.parse(s.config);t.transmuxer=new i.default(e,s.typeSupported,o,s.vendor,s.id),Object(a.enableLogs)(o.debug),function(){var t=function(t){a.logger[t]=function(e){r("workerLog",{logType:t,message:e})}};for(var e in a.logger)t(e)}(),r("init",null);break;case"configure":t.transmuxer.configure(s.config);break;case"demux":var u=t.transmuxer.push(s.data,s.decryptdata,s.chunkMeta,s.state);Object(i.isPromise)(u)?u.then((function(e){l(t,e)})):l(t,u);break;case"flush":var c=s.chunkMeta,h=t.transmuxer.flush(c);Object(i.isPromise)(h)?h.then((function(e){d(t,e,c)})):d(t,h,c)}}))}function l(t,e){if(!((r=e.remuxResult).audio||r.video||r.text||r.id3||r.initSegment))return!1;var r,i=[],n=e.remuxResult,a=n.audio,s=n.video;return a&&u(i,a),s&&u(i,s),t.postMessage({event:"transmuxComplete",data:e},i),!0}function u(t,e){e.data1&&t.push(e.data1.buffer),e.data2&&t.push(e.data2.buffer)}function d(t,e,r){e.reduce((function(e,r){return l(t,r)||e}),!1)||t.postMessage({event:"transmuxComplete",data:e[0]}),t.postMessage({event:"flush",data:r})}},"./src/demux/transmuxer.ts":
174
174
  /*!*********************************!*\
175
175
  !*** ./src/demux/transmuxer.ts ***!
176
176
  \*********************************/
177
- /*! exports provided: default, isPromise, TransmuxConfig, TransmuxState */function(t,e,r){r.r(e),r.d(e,"default",(function(){return y})),r.d(e,"isPromise",(function(){return T})),r.d(e,"TransmuxConfig",(function(){return S})),r.d(e,"TransmuxState",(function(){return b}));var i,n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../crypt/decrypter */"./src/crypt/decrypter.ts"),o=r(/*! ../demux/aacdemuxer */"./src/demux/aacdemuxer.ts"),l=r(/*! ../demux/mp4demuxer */"./src/demux/mp4demuxer.ts"),u=r(/*! ../demux/tsdemuxer */"./src/demux/tsdemuxer.ts"),d=r(/*! ../demux/mp3demuxer */"./src/demux/mp3demuxer.ts"),c=r(/*! ../remux/mp4-remuxer */"./src/remux/mp4-remuxer.ts"),h=r(/*! ../remux/passthrough-remuxer */"./src/remux/passthrough-remuxer.ts"),f=r(/*! ./chunk-cache */"./src/demux/chunk-cache.ts"),g=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),v=r(/*! ../utils/logger */"./src/utils/logger.ts");try{i=self.performance.now.bind(self.performance)}catch(t){v.logger.debug("Unable to use Performance API on this environment"),i=self.Date.now}var p=[{demux:u.default,remux:c.default},{demux:l.default,remux:h.default},{demux:o.default,remux:c.default},{demux:d.default,remux:c.default}],m=1024;p.forEach((function(t){var e=t.demux;m=Math.max(m,e.minProbeByteLength)}));var y=function(){function t(t,e,r,i,n){this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.cache=new f.default,this.observer=t,this.typeSupported=e,this.config=r,this.vendor=i,this.id=n}var e=t.prototype;return e.configure=function(t){this.transmuxConfig=t,this.decrypter&&this.decrypter.reset()},e.push=function(t,e,r,n){var a=this,s=r.transmuxing;s.executeStart=i();var o=new Uint8Array(t),l=this.cache,u=this.config,d=this.currentTransmuxState,c=this.transmuxConfig;n&&(this.currentTransmuxState=n);var h=function(t,e){var r=null;return t.byteLength>0&&null!=e&&null!=e.key&&null!==e.iv&&null!=e.method&&(r=e),r}(o,e);if(h&&"AES-128"===h.method){var f=this.getDecrypter();if(!u.enableSoftwareAES)return this.decryptionPromise=f.webCryptoDecrypt(o,h.key.buffer,h.iv.buffer).then((function(t){var e=a.push(t,null,r);return a.decryptionPromise=null,e})),this.decryptionPromise;var v=f.softwareDecrypt(o,h.key.buffer,h.iv.buffer);if(!v)return s.executeEnd=i(),E(r);o=new Uint8Array(v)}var p=n||d,m=p.contiguous,y=p.discontinuity,T=p.trackSwitch,S=p.accurateTimeOffset,b=p.timeOffset,L=p.initSegmentChange,D=c.audioCodec,A=c.videoCodec,R=c.defaultInitPts,k=c.duration,I=c.initSegmentData;if((y||T||L)&&this.resetInitSegment(I,D,A,k),(y||L)&&this.resetInitialTimestamp(R),m||this.resetContiguity(),this.needsProbing(o,y,T)){if(l.dataLength){var _=l.flush();o=Object(g.appendUint8Array)(_,o)}this.configureTransmuxer(o,c)}var O=this.transmux(o,h,b,S,r),C=this.currentTransmuxState;return C.contiguous=!0,C.discontinuity=!1,C.trackSwitch=!1,s.executeEnd=i(),O},e.flush=function(t){var e=this,r=t.transmuxing;r.executeStart=i();var s=this.decrypter,o=this.cache,l=this.currentTransmuxState,u=this.decryptionPromise;if(u)return u.then((function(){return e.flush(t)}));var d=[],c=l.timeOffset;if(s){var h=s.flush();h&&d.push(this.push(h,null,t))}var f=o.dataLength;o.reset();var g=this.demuxer,v=this.remuxer;if(!g||!v)return f>=m&&this.observer.emit(n.Events.ERROR,n.Events.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"no demux matching with content found"}),r.executeEnd=i(),[E(t)];var p=g.flush(c);return T(p)?p.then((function(r){return e.flushRemux(d,r,t),d})):(this.flushRemux(d,p,t),d)},e.flushRemux=function(t,e,r){var n=e.audioTrack,a=e.videoTrack,s=e.id3Track,o=e.textTrack,l=this.currentTransmuxState,u=l.accurateTimeOffset,d=l.timeOffset;v.logger.log("[transmuxer.ts]: Flushed fragment "+r.sn+(r.part>-1?" p: "+r.part:"")+" of level "+r.level);var c=this.remuxer.remux(n,a,s,o,d,u,!0,this.id);t.push({remuxResult:c,chunkMeta:r}),r.transmuxing.executeEnd=i()},e.resetInitialTimestamp=function(t){var e=this.demuxer,r=this.remuxer;e&&r&&(e.resetTimeStamp(t),r.resetTimeStamp(t))},e.resetContiguity=function(){var t=this.demuxer,e=this.remuxer;t&&e&&(t.resetContiguity(),e.resetNextTimestamp())},e.resetInitSegment=function(t,e,r,i){var n=this.demuxer,a=this.remuxer;n&&a&&(n.resetInitSegment(t,e,r,i),a.resetInitSegment(t,e,r))},e.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},e.transmux=function(t,e,r,i,n){return e&&"SAMPLE-AES"===e.method?this.transmuxSampleAes(t,e,r,i,n):this.transmuxUnencrypted(t,r,i,n)},e.transmuxUnencrypted=function(t,e,r,i){var n=this.demuxer.demux(t,e,!1,!this.config.progressive),a=n.audioTrack,s=n.videoTrack,o=n.id3Track,l=n.textTrack;return{remuxResult:this.remuxer.remux(a,s,o,l,e,r,!1,this.id),chunkMeta:i}},e.transmuxSampleAes=function(t,e,r,i,n){var a=this;return this.demuxer.demuxSampleAes(t,e,r).then((function(t){return{remuxResult:a.remuxer.remux(t.audioTrack,t.videoTrack,t.id3Track,t.textTrack,r,i,!1,a.id),chunkMeta:n}}))},e.configureTransmuxer=function(t,e){for(var r,i=this.config,n=this.observer,a=this.typeSupported,s=this.vendor,o=e.audioCodec,u=e.defaultInitPts,d=e.duration,c=e.initSegmentData,f=e.videoCodec,g=0,m=p.length;g<m;g++)if(p[g].demux.probe(t)){r=p[g];break}r||(v.logger.warn("Failed to find demuxer by probing frag, treating as mp4 passthrough"),r={demux:l.default,remux:h.default});var y=this.demuxer,E=this.remuxer,T=r.remux,S=r.demux;E&&E instanceof T||(this.remuxer=new T(n,i,a,s)),y&&y instanceof S||(this.demuxer=new S(n,i,a),this.probe=S.probe),this.resetInitSegment(c,o,f,d),this.resetInitialTimestamp(u)},e.needsProbing=function(t,e,r){return!this.demuxer||!this.remuxer||e||r},e.getDecrypter=function(){var t=this.decrypter;return t||(t=this.decrypter=new s.default(this.observer,this.config)),t},t}(),E=function(t){return{remuxResult:{},chunkMeta:t}};function T(t){return"then"in t&&t.then instanceof Function}var S=function(t,e,r,i,n){this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=t,this.videoCodec=e,this.initSegmentData=r,this.duration=i,this.defaultInitPts=n},b=function(t,e,r,i,n,a){this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=t,this.contiguous=e,this.accurateTimeOffset=r,this.trackSwitch=i,this.timeOffset=n,this.initSegmentChange=a}},"./src/demux/tsdemuxer.ts":
177
+ /*! exports provided: default, isPromise, TransmuxConfig, TransmuxState */function(t,e,r){r.r(e),r.d(e,"default",(function(){return v})),r.d(e,"isPromise",(function(){return m})),r.d(e,"TransmuxConfig",(function(){return y})),r.d(e,"TransmuxState",(function(){return E}));var i,n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../crypt/decrypter */"./src/crypt/decrypter.ts"),o=r(/*! ../demux/aacdemuxer */"./src/demux/aacdemuxer.ts"),l=r(/*! ../demux/mp4demuxer */"./src/demux/mp4demuxer.ts"),u=r(/*! ../demux/tsdemuxer */"./src/demux/tsdemuxer.ts"),d=r(/*! ../demux/mp3demuxer */"./src/demux/mp3demuxer.ts"),c=r(/*! ../remux/mp4-remuxer */"./src/remux/mp4-remuxer.ts"),h=r(/*! ../remux/passthrough-remuxer */"./src/remux/passthrough-remuxer.ts"),f=r(/*! ../utils/logger */"./src/utils/logger.ts");try{i=self.performance.now.bind(self.performance)}catch(t){f.logger.debug("Unable to use Performance API on this environment"),i=self.Date.now}var g=[{demux:u.default,remux:c.default},{demux:l.default,remux:h.default},{demux:o.default,remux:c.default},{demux:d.default,remux:c.default}],v=function(){function t(t,e,r,i,n){this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.observer=t,this.typeSupported=e,this.config=r,this.vendor=i,this.id=n}var e=t.prototype;return e.configure=function(t){this.transmuxConfig=t,this.decrypter&&this.decrypter.reset()},e.push=function(t,e,r,n){var a=this,s=r.transmuxing;s.executeStart=i();var o=new Uint8Array(t),l=this.config,u=this.currentTransmuxState,d=this.transmuxConfig;n&&(this.currentTransmuxState=n);var c=n||u,h=c.contiguous,f=c.discontinuity,g=c.trackSwitch,v=c.accurateTimeOffset,m=c.timeOffset,y=c.initSegmentChange,E=d.audioCodec,T=d.videoCodec,S=d.defaultInitPts,b=d.duration,L=d.initSegmentData;(f||g||y)&&this.resetInitSegment(L,E,T,b),(f||y)&&this.resetInitialTimestamp(S),h||this.resetContiguity();var D=function(t,e){var r=null;return t.byteLength>0&&null!=e&&null!=e.key&&null!==e.iv&&null!=e.method&&(r=e),r}(o,e);if(D&&"AES-128"===D.method){var A=this.getDecrypter();if(!l.enableSoftwareAES)return this.decryptionPromise=A.webCryptoDecrypt(o,D.key.buffer,D.iv.buffer).then((function(t){var e=a.push(t,null,r);return a.decryptionPromise=null,e})),this.decryptionPromise;var R=A.softwareDecrypt(o,D.key.buffer,D.iv.buffer);if(!R)return s.executeEnd=i(),p(r);o=new Uint8Array(R)}this.needsProbing(o,f,g)&&this.configureTransmuxer(o,d);var k=this.transmux(o,D,m,v,r),I=this.currentTransmuxState;return I.contiguous=!0,I.discontinuity=!1,I.trackSwitch=!1,s.executeEnd=i(),k},e.flush=function(t){var e=this,r=t.transmuxing;r.executeStart=i();var s=this.decrypter,o=this.currentTransmuxState,l=this.decryptionPromise;if(l)return l.then((function(){return e.flush(t)}));var u=[],d=o.timeOffset;if(s){var c=s.flush();c&&u.push(this.push(c,null,t))}var h=this.demuxer,f=this.remuxer;if(!h||!f)return this.observer.emit(n.Events.ERROR,n.Events.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"no demux matching with content found"}),r.executeEnd=i(),[p(t)];var g=h.flush(d);return m(g)?g.then((function(r){return e.flushRemux(u,r,t),u})):(this.flushRemux(u,g,t),u)},e.flushRemux=function(t,e,r){var n=e.audioTrack,a=e.videoTrack,s=e.id3Track,o=e.textTrack,l=this.currentTransmuxState,u=l.accurateTimeOffset,d=l.timeOffset;f.logger.log("[transmuxer.ts]: Flushed fragment "+r.sn+(r.part>-1?" p: "+r.part:"")+" of level "+r.level);var c=this.remuxer.remux(n,a,s,o,d,u,!0,this.id);t.push({remuxResult:c,chunkMeta:r}),r.transmuxing.executeEnd=i()},e.resetInitialTimestamp=function(t){var e=this.demuxer,r=this.remuxer;e&&r&&(e.resetTimeStamp(t),r.resetTimeStamp(t))},e.resetContiguity=function(){var t=this.demuxer,e=this.remuxer;t&&e&&(t.resetContiguity(),e.resetNextTimestamp())},e.resetInitSegment=function(t,e,r,i){var n=this.demuxer,a=this.remuxer;n&&a&&(n.resetInitSegment(t,e,r,i),a.resetInitSegment(t,e,r))},e.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},e.transmux=function(t,e,r,i,n){return e&&"SAMPLE-AES"===e.method?this.transmuxSampleAes(t,e,r,i,n):this.transmuxUnencrypted(t,r,i,n)},e.transmuxUnencrypted=function(t,e,r,i){var n=this.demuxer.demux(t,e,!1,!this.config.progressive),a=n.audioTrack,s=n.videoTrack,o=n.id3Track,l=n.textTrack;return{remuxResult:this.remuxer.remux(a,s,o,l,e,r,!1,this.id),chunkMeta:i}},e.transmuxSampleAes=function(t,e,r,i,n){var a=this;return this.demuxer.demuxSampleAes(t,e,r).then((function(t){return{remuxResult:a.remuxer.remux(t.audioTrack,t.videoTrack,t.id3Track,t.textTrack,r,i,!1,a.id),chunkMeta:n}}))},e.configureTransmuxer=function(t,e){for(var r,i=this.config,n=this.observer,a=this.typeSupported,s=this.vendor,o=e.audioCodec,u=e.defaultInitPts,d=e.duration,c=e.initSegmentData,v=e.videoCodec,p=0,m=g.length;p<m;p++)if(g[p].demux.probe(t)){r=g[p];break}r||(f.logger.warn("Failed to find demuxer by probing frag, treating as mp4 passthrough"),r={demux:l.default,remux:h.default});var y=this.demuxer,E=this.remuxer,T=r.remux,S=r.demux;E&&E instanceof T||(this.remuxer=new T(n,i,a,s)),y&&y instanceof S||(this.demuxer=new S(n,i,a),this.probe=S.probe),this.resetInitSegment(c,o,v,d),this.resetInitialTimestamp(u)},e.needsProbing=function(t,e,r){return!this.demuxer||!this.remuxer||e||r},e.getDecrypter=function(){var t=this.decrypter;return t||(t=this.decrypter=new s.default(this.observer,this.config)),t},t}(),p=function(t){return{remuxResult:{},chunkMeta:t}};function m(t){return"then"in t&&t.then instanceof Function}var y=function(t,e,r,i,n){this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=t,this.videoCodec=e,this.initSegmentData=r,this.duration=i,this.defaultInitPts=n},E=function(t,e,r,i,n,a){this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=t,this.contiguous=e,this.accurateTimeOffset=r,this.trackSwitch=i,this.timeOffset=n,this.initSegmentChange=a}},"./src/demux/tsdemuxer.ts":
178
178
  /*!********************************!*\
179
179
  !*** ./src/demux/tsdemuxer.ts ***!
180
180
  \********************************/
181
- /*! exports provided: discardEPB, default */function(t,e,r){r.r(e),r.d(e,"discardEPB",(function(){return E}));var i=r(/*! ./adts */"./src/demux/adts.ts"),n=r(/*! ./mpegaudio */"./src/demux/mpegaudio.ts"),a=r(/*! ./exp-golomb */"./src/demux/exp-golomb.ts"),s=r(/*! ./sample-aes */"./src/demux/sample-aes.ts"),o=r(/*! ../events */"./src/events.ts"),l=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),u=r(/*! ../utils/logger */"./src/utils/logger.ts"),d=r(/*! ../errors */"./src/errors.ts"),c=r(/*! ../types/demuxer */"./src/types/demuxer.ts");function h(){return(h=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}var f=function(){function t(t,e,r){this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._avcTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.observer=t,this.config=e,this.typeSupported=r}t.probe=function(e){var r=t.syncOffset(e);return!(r<0||(r&&u.logger.warn("MPEG2-TS detected but first sync word found @ offset "+r+", junk ahead ?"),0))},t.syncOffset=function(t){for(var e=Math.min(1e3,t.length-564),r=0;r<e;){if(71===t[r]&&71===t[r+188]&&71===t[r+376])return r;r++}return-1},t.createTrack=function(t,e){return{container:"video"===t||"audio"===t?"video/mp2t":void 0,type:t,id:l.RemuxerTrackIdConfig[t],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===t?e:void 0}};var e=t.prototype;return e.resetInitSegment=function(e,r,i,n){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack=t.createTrack("video"),this._audioTrack=t.createTrack("audio",n),this._id3Track=t.createTrack("id3"),this._txtTrack=t.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.avcSample=null,this.audioCodec=r,this.videoCodec=i,this._duration=n},e.resetTimeStamp=function(){},e.resetContiguity=function(){var t=this._audioTrack,e=this._avcTrack,r=this._id3Track;t&&(t.pesData=null),e&&(e.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null},e.demux=function(e,r,i,n){var a;void 0===i&&(i=!1),void 0===n&&(n=!1),i||(this.sampleAes=null);var s=this._avcTrack,c=this._audioTrack,h=this._id3Track,f=this._txtTrack,g=s.pid,y=s.pesData,E=c.pid,T=h.pid,S=c.pesData,b=h.pesData,L=!1,D=this.pmtParsed,A=this._pmtId,R=e.length;if(this.remainderData&&(R=(e=Object(l.appendUint8Array)(this.remainderData,e)).length,this.remainderData=null),R<188&&!n)return this.remainderData=e,{audioTrack:c,videoTrack:s,id3Track:h,textTrack:f};var k=Math.max(0,t.syncOffset(e));(R-=(R+k)%188)<e.byteLength&&!n&&(this.remainderData=new Uint8Array(e.buffer,R,e.buffer.byteLength-R));for(var I=0,_=k;_<R;_+=188)if(71===e[_]){var O=!!(64&e[_+1]),C=((31&e[_+1])<<8)+e[_+2],w=void 0;if((48&e[_+3])>>4>1){if((w=_+5+e[_+4])===_+188)continue}else w=_+4;switch(C){case g:O&&(y&&(a=m(y))&&this.parseAVCPES(s,f,a,!1),y={data:[],size:0}),y&&(y.data.push(e.subarray(w,_+188)),y.size+=_+188-w);break;case E:if(O){if(S&&(a=m(S)))switch(c.segmentCodec){case"aac":this.parseAACPES(c,a);break;case"mp3":this.parseMPEGPES(c,a)}S={data:[],size:0}}S&&(S.data.push(e.subarray(w,_+188)),S.size+=_+188-w);break;case T:O&&(b&&(a=m(b))&&this.parseID3PES(h,a),b={data:[],size:0}),b&&(b.data.push(e.subarray(w,_+188)),b.size+=_+188-w);break;case 0:O&&(w+=e[w]+1),A=this._pmtId=v(e,w);break;case A:O&&(w+=e[w]+1);var x=p(e,w,this.typeSupported,i);(g=x.avc)>0&&(s.pid=g),(E=x.audio)>0&&(c.pid=E,c.segmentCodec=x.segmentCodec),(T=x.id3)>0&&(h.pid=T),L&&!D&&(u.logger.log("reparse from beginning"),L=!1,_=k-188),D=this.pmtParsed=!0;break;case 17:case 8191:break;default:L=!0}}else I++;I>0&&this.observer.emit(o.Events.ERROR,o.Events.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"Found "+I+" TS packet/s that do not start with 0x47"}),s.pesData=y,c.pesData=S,h.pesData=b;var P={audioTrack:c,videoTrack:s,id3Track:h,textTrack:f};return n&&this.extractRemainingSamples(P),P},e.flush=function(){var t,e=this.remainderData;return this.remainderData=null,t=e?this.demux(e,-1,!1,!0):{videoTrack:this._avcTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(t),this.sampleAes?this.decrypt(t,this.sampleAes):t},e.extractRemainingSamples=function(t){var e,r=t.audioTrack,i=t.videoTrack,n=t.id3Track,a=t.textTrack,s=i.pesData,o=r.pesData,l=n.pesData;if(s&&(e=m(s))?(this.parseAVCPES(i,a,e,!0),i.pesData=null):i.pesData=s,o&&(e=m(o))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,e);break;case"mp3":this.parseMPEGPES(r,e)}r.pesData=null}else null!=o&&o.size&&u.logger.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;l&&(e=m(l))?(this.parseID3PES(n,e),n.pesData=null):n.pesData=l},e.demuxSampleAes=function(t,e,r){var i=this.demux(t,r,!0,!this.config.progressive),n=this.sampleAes=new s.default(this.observer,this.config,e);return this.decrypt(i,n)},e.decrypt=function(t,e){return new Promise((function(r){var i=t.audioTrack,n=t.videoTrack;i.samples&&"aac"===i.segmentCodec?e.decryptAacSamples(i.samples,0,(function(){n.samples?e.decryptAvcSamples(n.samples,0,0,(function(){r(t)})):r(t)})):n.samples&&e.decryptAvcSamples(n.samples,0,0,(function(){r(t)}))}))},e.destroy=function(){this._duration=0},e.parseAVCPES=function(t,e,r,i){var n,s=this,o=this.parseAVCNALu(t,r.data),u=this.avcSample,d=!1;r.data=null,u&&o.length&&!t.audFound&&(y(u,t),u=this.avcSample=g(!1,r.pts,r.dts,"")),o.forEach((function(i){switch(i.type){case 1:n=!0,u||(u=s.avcSample=g(!0,r.pts,r.dts,"")),u.frame=!0;var o=i.data;if(d&&o.length>4){var c=new a.default(o).readSliceType();2!==c&&4!==c&&7!==c&&9!==c||(u.key=!0)}break;case 5:n=!0,u||(u=s.avcSample=g(!0,r.pts,r.dts,"")),u.key=!0,u.frame=!0;break;case 6:n=!0,Object(l.parseSEIMessageFromNALu)(E(i.data),r.pts,e.samples);break;case 7:if(n=!0,d=!0,!t.sps){var h=new a.default(i.data).readSPS();t.width=h.width,t.height=h.height,t.pixelRatio=h.pixelRatio,t.sps=[i.data],t.duration=s._duration;for(var f=i.data.subarray(1,4),v="avc1.",p=0;p<3;p++){var m=f[p].toString(16);m.length<2&&(m="0"+m),v+=m}t.codec=v}break;case 8:n=!0,t.pps||(t.pps=[i.data]);break;case 9:n=!1,t.audFound=!0,u&&y(u,t),u=s.avcSample=g(!1,r.pts,r.dts,"");break;case 12:n=!0;break;default:n=!1,u&&(u.debug+="unknown NAL "+i.type+" ")}u&&n&&u.units.push(i)})),i&&u&&(y(u,t),this.avcSample=null)},e.getLastNalUnit=function(t){var e,r,i=this.avcSample;if(i&&0!==i.units.length||(i=t[t.length-1]),null!==(e=i)&&void 0!==e&&e.units){var n=i.units;r=n[n.length-1]}return r},e.parseAVCNALu=function(t,e){var r,i,n=e.byteLength,a=t.naluState||0,s=a,o=[],l=0,u=-1,d=0;for(-1===a&&(u=0,d=31&e[0],a=0,l=1);l<n;)if(r=e[l++],a)if(1!==a)if(r)if(1===r){if(u>=0){var c={data:e.subarray(u,l-a-1),type:d};o.push(c)}else{var h=this.getLastNalUnit(t.samples);if(h&&(s&&l<=4-s&&h.state&&(h.data=h.data.subarray(0,h.data.byteLength-s)),(i=l-a-1)>0)){var f=new Uint8Array(h.data.byteLength+i);f.set(h.data,0),f.set(e.subarray(0,i),h.data.byteLength),h.data=f,h.state=0}}l<n?(u=l,d=31&e[l],a=0):a=-1}else a=0;else a=3;else a=r?0:2;else a=r?0:1;if(u>=0&&a>=0){var g={data:e.subarray(u,n),type:d,state:a};o.push(g)}if(0===o.length){var v=this.getLastNalUnit(t.samples);if(v){var p=new Uint8Array(v.data.byteLength+e.byteLength);p.set(v.data,0),p.set(e,v.data.byteLength),v.data=p}}return t.naluState=a,o},e.parseAACPES=function(t,e){var r,n,a,s,l,c=0,h=this.aacOverFlow,f=e.data;if(h){this.aacOverFlow=null;var g=h.missing,v=h.sample.unit.byteLength;if(-1===g){var p=new Uint8Array(v+f.byteLength);p.set(h.sample.unit,0),p.set(f,v),f=p}else{var m=v-g;h.sample.unit.set(f.subarray(0,g),m),t.samples.push(h.sample),c=h.missing}}for(r=c,n=f.length;r<n-1&&!i.isHeader(f,r);r++);if(r===c||(r<n-1?(a="AAC PES did not start with ADTS header,offset:"+r,s=!1):(a="no ADTS header found in AAC PES",s=!0),u.logger.warn("parsing error:"+a),this.observer.emit(o.Events.ERROR,o.Events.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.FRAG_PARSING_ERROR,fatal:s,reason:a}),!s)){if(i.initTrackConfig(t,this.observer,f,r,this.audioCodec),void 0!==e.pts)l=e.pts;else{if(!h)return void u.logger.warn("[tsdemuxer]: AAC PES unknown PTS");var y=i.getFrameDuration(t.samplerate);l=h.sample.pts+y}for(var E,T=0;r<n;){if(r+=(E=i.appendFrame(t,f,r,l,T)).length,E.missing){this.aacOverFlow=E;break}for(T++;r<n-1&&!i.isHeader(f,r);r++);}}},e.parseMPEGPES=function(t,e){var r=e.data,i=r.length,a=0,s=0,o=e.pts;if(void 0!==o)for(;s<i;)if(n.isHeader(r,s)){var l=n.appendFrame(t,r,s,o,a);if(!l)break;s+=l.length,a++}else s++;else u.logger.warn("[tsdemuxer]: MPEG PES unknown PTS")},e.parseID3PES=function(t,e){if(void 0!==e.pts){var r=h({},e,{type:this._avcTrack?c.MetadataSchema.emsg:c.MetadataSchema.audioId3});t.samples.push(r)}else u.logger.warn("[tsdemuxer]: ID3 PES unknown PTS")},t}();function g(t,e,r,i){return{key:t,frame:!1,pts:e,dts:r,units:[],debug:i,length:0}}function v(t,e){return(31&t[e+10])<<8|t[e+11]}function p(t,e,r,i){var n={audio:-1,avc:-1,id3:-1,segmentCodec:"aac"},a=e+3+((15&t[e+1])<<8|t[e+2])-4;for(e+=12+((15&t[e+10])<<8|t[e+11]);e<a;){var s=(31&t[e+1])<<8|t[e+2];switch(t[e]){case 207:if(!i){u.logger.log("ADTS AAC with AES-128-CBC frame encryption found in unencrypted stream");break}case 15:-1===n.audio&&(n.audio=s);break;case 21:-1===n.id3&&(n.id3=s);break;case 219:if(!i){u.logger.log("H.264 with AES-128-CBC slice encryption found in unencrypted stream");break}case 27:-1===n.avc&&(n.avc=s);break;case 3:case 4:!0!==r.mpeg&&!0!==r.mp3?u.logger.log("MPEG audio found, not supported in this browser"):-1===n.audio&&(n.audio=s,n.segmentCodec="mp3");break;case 36:u.logger.warn("Unsupported HEVC stream type found")}e+=5+((15&t[e+3])<<8|t[e+4])}return n}function m(t){var e,r,i,n,a,s=0,o=t.data;if(!t||0===t.size)return null;for(;o[0].length<19&&o.length>1;){var l=new Uint8Array(o[0].length+o[1].length);l.set(o[0]),l.set(o[1],o[0].length),o[0]=l,o.splice(1,1)}if(1===((e=o[0])[0]<<16)+(e[1]<<8)+e[2]){if((r=(e[4]<<8)+e[5])&&r>t.size-6)return null;var d=e[7];192&d&&(n=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&d?n-(a=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(u.logger.warn(Math.round((n-a)/9e4)+"s delta between PTS and DTS, align them"),n=a):a=n);var c=(i=e[8])+9;if(t.size<=c)return null;t.size-=c;for(var h=new Uint8Array(t.size),f=0,g=o.length;f<g;f++){var v=(e=o[f]).byteLength;if(c){if(c>v){c-=v;continue}e=e.subarray(c),v-=c,c=0}h.set(e,s),s+=v}return r&&(r-=i+3),{data:h,pts:n,dts:a,len:r}}return null}function y(t,e){if(t.units.length&&t.frame){if(void 0===t.pts){var r=e.samples,i=r.length;if(!i)return void e.dropped++;var n=r[i-1];t.pts=n.pts,t.dts=n.dts}e.samples.push(t)}t.debug.length&&u.logger.log(t.pts+"/"+t.dts+":"+t.debug)}function E(t){for(var e=t.byteLength,r=[],i=1;i<e-2;)0===t[i]&&0===t[i+1]&&3===t[i+2]?(r.push(i+2),i+=2):i++;if(0===r.length)return t;var n=e-r.length,a=new Uint8Array(n),s=0;for(i=0;i<n;s++,i++)s===r[0]&&(s++,r.shift()),a[i]=t[s];return a}f.minProbeByteLength=188,e.default=f},"./src/errors.ts":
181
+ /*! exports provided: discardEPB, default */function(t,e,r){r.r(e),r.d(e,"discardEPB",(function(){return E}));var i=r(/*! ./adts */"./src/demux/adts.ts"),n=r(/*! ./mpegaudio */"./src/demux/mpegaudio.ts"),a=r(/*! ./exp-golomb */"./src/demux/exp-golomb.ts"),s=r(/*! ./sample-aes */"./src/demux/sample-aes.ts"),o=r(/*! ../events */"./src/events.ts"),l=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),u=r(/*! ../utils/logger */"./src/utils/logger.ts"),d=r(/*! ../errors */"./src/errors.ts"),c=r(/*! ../types/demuxer */"./src/types/demuxer.ts");function h(){return(h=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}var f=function(){function t(t,e,r){this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._avcTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.observer=t,this.config=e,this.typeSupported=r}t.probe=function(t){return 71===t[0]&&71===t[188]},t.createTrack=function(t,e){return{container:"video"===t||"audio"===t?"video/mp2t":void 0,type:t,id:l.RemuxerTrackIdConfig[t],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===t?e:void 0}};var e=t.prototype;return e.resetInitSegment=function(e,r,i,n){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack=t.createTrack("video"),this._audioTrack=t.createTrack("audio",n),this._id3Track=t.createTrack("id3"),this._txtTrack=t.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=i,this._duration=n},e.resetTimeStamp=function(){},e.resetContiguity=function(){var t=this._audioTrack,e=this._avcTrack,r=this._id3Track;t&&(t.pesData=null),e&&(e.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null},e.demux=function(t,e,r,i){var n;void 0===r&&(r=!1),void 0===i&&(i=!1),r||(this.sampleAes=null);var a=this._avcTrack,s=this._audioTrack,c=this._id3Track,h=this._txtTrack,f=a.pid,g=a.pesData,y=s.pid,E=c.pid,T=s.pesData,S=c.pesData,b=null,L=this.pmtParsed,D=this._pmtId,A=t.length;if(this.remainderData&&(A=(t=Object(l.appendUint8Array)(this.remainderData,t)).length,this.remainderData=null),A<188&&!i)return this.remainderData=t,{audioTrack:s,videoTrack:a,id3Track:c,textTrack:h};(A-=A%188)<t.byteLength&&!i&&(this.remainderData=new Uint8Array(t.buffer,A,t.buffer.byteLength-A));for(var R=0,k=0;k<A;k+=188)if(71===t[k]){var I=!!(64&t[k+1]),_=((31&t[k+1])<<8)+t[k+2],C=void 0;if((48&t[k+3])>>4>1){if((C=k+5+t[k+4])===k+188)continue}else C=k+4;switch(_){case f:I&&(g&&(n=m(g))&&this.parseAVCPES(a,h,n,!1),g={data:[],size:0}),g&&(g.data.push(t.subarray(C,k+188)),g.size+=k+188-C);break;case y:if(I){if(T&&(n=m(T)))switch(s.segmentCodec){case"aac":this.parseAACPES(s,n);break;case"mp3":this.parseMPEGPES(s,n)}T={data:[],size:0}}T&&(T.data.push(t.subarray(C,k+188)),T.size+=k+188-C);break;case E:I&&(S&&(n=m(S))&&this.parseID3PES(c,n),S={data:[],size:0}),S&&(S.data.push(t.subarray(C,k+188)),S.size+=k+188-C);break;case 0:I&&(C+=t[C]+1),D=this._pmtId=v(t,C);break;case D:I&&(C+=t[C]+1);var O=p(t,C,this.typeSupported,r);(f=O.avc)>0&&(a.pid=f),(y=O.audio)>0&&(s.pid=y,s.segmentCodec=O.segmentCodec),(E=O.id3)>0&&(c.pid=E),null===b||L||(u.logger.log("unknown PID '"+b+"' in TS found"),b=null),L=this.pmtParsed=!0;break;case 17:case 8191:break;default:b=_}}else R++;R>0&&this.observer.emit(o.Events.ERROR,o.Events.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"Found "+R+" TS packet/s that do not start with 0x47"}),a.pesData=g,s.pesData=T,c.pesData=S;var w={audioTrack:s,videoTrack:a,id3Track:c,textTrack:h};return i&&this.extractRemainingSamples(w),w},e.flush=function(){var t,e=this.remainderData;return this.remainderData=null,t=e?this.demux(e,-1,!1,!0):{videoTrack:this._avcTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(t),this.sampleAes?this.decrypt(t,this.sampleAes):t},e.extractRemainingSamples=function(t){var e,r=t.audioTrack,i=t.videoTrack,n=t.id3Track,a=t.textTrack,s=i.pesData,o=r.pesData,l=n.pesData;if(s&&(e=m(s))?(this.parseAVCPES(i,a,e,!0),i.pesData=null):i.pesData=s,o&&(e=m(o))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,e);break;case"mp3":this.parseMPEGPES(r,e)}r.pesData=null}else null!=o&&o.size&&u.logger.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;l&&(e=m(l))?(this.parseID3PES(n,e),n.pesData=null):n.pesData=l},e.demuxSampleAes=function(t,e,r){var i=this.demux(t,r,!0,!this.config.progressive),n=this.sampleAes=new s.default(this.observer,this.config,e);return this.decrypt(i,n)},e.decrypt=function(t,e){return new Promise((function(r){var i=t.audioTrack,n=t.videoTrack;i.samples&&"aac"===i.segmentCodec?e.decryptAacSamples(i.samples,0,(function(){n.samples?e.decryptAvcSamples(n.samples,0,0,(function(){r(t)})):r(t)})):n.samples&&e.decryptAvcSamples(n.samples,0,0,(function(){r(t)}))}))},e.destroy=function(){this._duration=0},e.parseAVCPES=function(t,e,r,i){var n,s=this,o=this.parseAVCNALu(t,r.data),u=this.avcSample,d=!1;r.data=null,u&&o.length&&!t.audFound&&(y(u,t),u=this.avcSample=g(!1,r.pts,r.dts,"")),o.forEach((function(i){switch(i.type){case 1:n=!0,u||(u=s.avcSample=g(!0,r.pts,r.dts,"")),u.frame=!0;var o=i.data;if(d&&o.length>4){var c=new a.default(o).readSliceType();2!==c&&4!==c&&7!==c&&9!==c||(u.key=!0)}break;case 5:n=!0,u||(u=s.avcSample=g(!0,r.pts,r.dts,"")),u.key=!0,u.frame=!0;break;case 6:n=!0,Object(l.parseSEIMessageFromNALu)(E(i.data),r.pts,e.samples);break;case 7:if(n=!0,d=!0,!t.sps){var h=new a.default(i.data).readSPS();t.width=h.width,t.height=h.height,t.pixelRatio=h.pixelRatio,t.sps=[i.data],t.duration=s._duration;for(var f=i.data.subarray(1,4),v="avc1.",p=0;p<3;p++){var m=f[p].toString(16);m.length<2&&(m="0"+m),v+=m}t.codec=v}break;case 8:n=!0,t.pps||(t.pps=[i.data]);break;case 9:n=!1,t.audFound=!0,u&&y(u,t),u=s.avcSample=g(!1,r.pts,r.dts,"");break;case 12:n=!0;break;default:n=!1,u&&(u.debug+="unknown NAL "+i.type+" ")}u&&n&&u.units.push(i)})),i&&u&&(y(u,t),this.avcSample=null)},e.getLastNalUnit=function(t){var e,r,i=this.avcSample;if(i&&0!==i.units.length||(i=t[t.length-1]),null!==(e=i)&&void 0!==e&&e.units){var n=i.units;r=n[n.length-1]}return r},e.parseAVCNALu=function(t,e){var r,i,n=e.byteLength,a=t.naluState||0,s=a,o=[],l=0,u=-1,d=0;for(-1===a&&(u=0,d=31&e[0],a=0,l=1);l<n;)if(r=e[l++],a)if(1!==a)if(r)if(1===r){if(u>=0){var c={data:e.subarray(u,l-a-1),type:d};o.push(c)}else{var h=this.getLastNalUnit(t.samples);if(h&&(s&&l<=4-s&&h.state&&(h.data=h.data.subarray(0,h.data.byteLength-s)),(i=l-a-1)>0)){var f=new Uint8Array(h.data.byteLength+i);f.set(h.data,0),f.set(e.subarray(0,i),h.data.byteLength),h.data=f,h.state=0}}l<n?(u=l,d=31&e[l],a=0):a=-1}else a=0;else a=3;else a=r?0:2;else a=r?0:1;if(u>=0&&a>=0){var g={data:e.subarray(u,n),type:d,state:a};o.push(g)}if(0===o.length){var v=this.getLastNalUnit(t.samples);if(v){var p=new Uint8Array(v.data.byteLength+e.byteLength);p.set(v.data,0),p.set(e,v.data.byteLength),v.data=p}}return t.naluState=a,o},e.parseAACPES=function(t,e){var r,n,a,s,l,c=0,h=this.aacOverFlow,f=e.data;if(h){this.aacOverFlow=null;var g=h.missing,v=h.sample.unit.byteLength;if(-1===g){var p=new Uint8Array(v+f.byteLength);p.set(h.sample.unit,0),p.set(f,v),f=p}else{var m=v-g;h.sample.unit.set(f.subarray(0,g),m),t.samples.push(h.sample),c=h.missing}}for(r=c,n=f.length;r<n-1&&!i.isHeader(f,r);r++);if(r===c||(r<n-1?(a="AAC PES did not start with ADTS header,offset:"+r,s=!1):(a="no ADTS header found in AAC PES",s=!0),u.logger.warn("parsing error:"+a),this.observer.emit(o.Events.ERROR,o.Events.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.FRAG_PARSING_ERROR,fatal:s,reason:a}),!s)){if(i.initTrackConfig(t,this.observer,f,r,this.audioCodec),void 0!==e.pts)l=e.pts;else{if(!h)return void u.logger.warn("[tsdemuxer]: AAC PES unknown PTS");var y=i.getFrameDuration(t.samplerate);l=h.sample.pts+y}for(var E,T=0;r<n;){if(r+=(E=i.appendFrame(t,f,r,l,T)).length,E.missing){this.aacOverFlow=E;break}for(T++;r<n-1&&!i.isHeader(f,r);r++);}}},e.parseMPEGPES=function(t,e){var r=e.data,i=r.length,a=0,s=0,o=e.pts;if(void 0!==o)for(;s<i;)if(n.isHeader(r,s)){var l=n.appendFrame(t,r,s,o,a);if(!l)break;s+=l.length,a++}else s++;else u.logger.warn("[tsdemuxer]: MPEG PES unknown PTS")},e.parseID3PES=function(t,e){if(void 0!==e.pts){var r=h({},e,{type:this._avcTrack?c.MetadataSchema.emsg:c.MetadataSchema.audioId3});t.samples.push(r)}else u.logger.warn("[tsdemuxer]: ID3 PES unknown PTS")},t}();function g(t,e,r,i){return{key:t,frame:!1,pts:e,dts:r,units:[],debug:i,length:0}}function v(t,e){return(31&t[e+10])<<8|t[e+11]}function p(t,e,r,i){var n={audio:-1,avc:-1,id3:-1,segmentCodec:"aac"},a=e+3+((15&t[e+1])<<8|t[e+2])-4;for(e+=12+((15&t[e+10])<<8|t[e+11]);e<a;){var s=(31&t[e+1])<<8|t[e+2];switch(t[e]){case 207:if(!i){u.logger.log("ADTS AAC with AES-128-CBC frame encryption found in unencrypted stream");break}case 15:-1===n.audio&&(n.audio=s);break;case 21:-1===n.id3&&(n.id3=s);break;case 219:if(!i){u.logger.log("H.264 with AES-128-CBC slice encryption found in unencrypted stream");break}case 27:-1===n.avc&&(n.avc=s);break;case 3:case 4:!0!==r.mpeg&&!0!==r.mp3?u.logger.log("MPEG audio found, not supported in this browser"):-1===n.audio&&(n.audio=s,n.segmentCodec="mp3");break;case 36:u.logger.warn("Unsupported HEVC stream type found")}e+=5+((15&t[e+3])<<8|t[e+4])}return n}function m(t){var e,r,i,n,a,s=0,o=t.data;if(!t||0===t.size)return null;for(;o[0].length<19&&o.length>1;){var l=new Uint8Array(o[0].length+o[1].length);l.set(o[0]),l.set(o[1],o[0].length),o[0]=l,o.splice(1,1)}if(1===((e=o[0])[0]<<16)+(e[1]<<8)+e[2]){if((r=(e[4]<<8)+e[5])&&r>t.size-6)return null;var d=e[7];192&d&&(n=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&d?n-(a=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(u.logger.warn(Math.round((n-a)/9e4)+"s delta between PTS and DTS, align them"),n=a):a=n);var c=(i=e[8])+9;if(t.size<=c)return null;t.size-=c;for(var h=new Uint8Array(t.size),f=0,g=o.length;f<g;f++){var v=(e=o[f]).byteLength;if(c){if(c>v){c-=v;continue}e=e.subarray(c),v-=c,c=0}h.set(e,s),s+=v}return r&&(r-=i+3),{data:h,pts:n,dts:a,len:r}}return null}function y(t,e){if(t.units.length&&t.frame){if(void 0===t.pts){var r=e.samples,i=r.length;if(!i)return void e.dropped++;var n=r[i-1];t.pts=n.pts,t.dts=n.dts}e.samples.push(t)}t.debug.length&&u.logger.log(t.pts+"/"+t.dts+":"+t.debug)}function E(t){for(var e=t.byteLength,r=[],i=1;i<e-2;)0===t[i]&&0===t[i+1]&&3===t[i+2]?(r.push(i+2),i+=2):i++;if(0===r.length)return t;var n=e-r.length,a=new Uint8Array(n),s=0;for(i=0;i<n;s++,i++)s===r[0]&&(s++,r.shift()),a[i]=t[s];return a}e.default=f},"./src/errors.ts":
182
182
  /*!***********************!*\
183
183
  !*** ./src/errors.ts ***!
184
184
  \***********************/
@@ -190,7 +190,7 @@
190
190
  /*!********************!*\
191
191
  !*** ./src/hls.ts ***!
192
192
  \********************/
193
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return y}));var i=r(/*! url-toolkit */"./node_modules/url-toolkit/src/url-toolkit.js"),n=r(/*! ./loader/playlist-loader */"./src/loader/playlist-loader.ts"),a=r(/*! ./loader/key-loader */"./src/loader/key-loader.ts"),s=r(/*! ./controller/id3-track-controller */"./src/controller/id3-track-controller.ts"),o=r(/*! ./controller/latency-controller */"./src/controller/latency-controller.ts"),l=r(/*! ./controller/level-controller */"./src/controller/level-controller.ts"),u=r(/*! ./controller/fragment-tracker */"./src/controller/fragment-tracker.ts"),d=r(/*! ./controller/stream-controller */"./src/controller/stream-controller.ts"),c=r(/*! ./is-supported */"./src/is-supported.ts"),h=r(/*! ./utils/logger */"./src/utils/logger.ts"),f=r(/*! ./config */"./src/config.ts"),g=r(/*! eventemitter3 */"./node_modules/eventemitter3/index.js"),v=r(/*! ./events */"./src/events.ts"),p=r(/*! ./errors */"./src/errors.ts");function m(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var y=function(){function t(e){void 0===e&&(e={}),this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this._emitter=new g.EventEmitter,this._autoLevelCapping=void 0,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;var r=this.config=Object(f.mergeConfig)(t.DefaultConfig,e);this.userConfig=e,Object(h.enableLogs)(r.debug),this._autoLevelCapping=-1,r.progressive&&Object(f.enableStreamingMode)(r);var i=r.abrController,c=r.bufferController,v=r.capLevelController,p=r.fpsController,m=this.abrController=new i(this),y=this.bufferController=new c(this),E=this.capLevelController=new v(this),T=new p(this),S=new n.default(this),b=new a.default(this),L=new s.default(this),D=this.levelController=new l.default(this),A=new u.FragmentTracker(this),R=this.streamController=new d.default(this,A);E.setStreamController(R),T.setStreamController(R);var k=[D,R];this.networkControllers=k;var I=[S,b,m,y,E,T,L,A];this.audioTrackController=this.createController(r.audioTrackController,null,k),this.createController(r.audioStreamController,A,k),this.subtitleTrackController=this.createController(r.subtitleTrackController,null,k),this.createController(r.subtitleStreamController,A,k),this.createController(r.timelineController,null,I),this.emeController=this.createController(r.emeController,null,I),this.cmcdController=this.createController(r.cmcdController,null,I),this.latencyController=this.createController(o.default,null,I),this.coreComponents=I}t.isSupported=function(){return Object(c.isSupported)()};var e,r,y,E=t.prototype;return E.createController=function(t,e,r){if(t){var i=e?new t(this,e):new t(this);return r&&r.push(i),i}return null},E.on=function(t,e,r){void 0===r&&(r=this),this._emitter.on(t,e,r)},E.once=function(t,e,r){void 0===r&&(r=this),this._emitter.once(t,e,r)},E.removeAllListeners=function(t){this._emitter.removeAllListeners(t)},E.off=function(t,e,r,i){void 0===r&&(r=this),this._emitter.off(t,e,r,i)},E.listeners=function(t){return this._emitter.listeners(t)},E.emit=function(t,e,r){return this._emitter.emit(t,e,r)},E.trigger=function(t,e){if(this.config.debug)return this.emit(t,t,e);try{return this.emit(t,t,e)}catch(e){h.logger.error("An internal error happened while handling event "+t+'. Error message: "'+e.message+'". Here is a stacktrace:',e),this.trigger(v.Events.ERROR,{type:p.ErrorTypes.OTHER_ERROR,details:p.ErrorDetails.INTERNAL_EXCEPTION,fatal:!1,event:t,error:e})}return!1},E.listenerCount=function(t){return this._emitter.listenerCount(t)},E.destroy=function(){h.logger.log("destroy"),this.trigger(v.Events.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((function(t){return t.destroy()})),this.networkControllers.length=0,this.coreComponents.forEach((function(t){return t.destroy()})),this.coreComponents.length=0},E.attachMedia=function(t){h.logger.log("attachMedia"),this._media=t,this.trigger(v.Events.MEDIA_ATTACHING,{media:t})},E.detachMedia=function(){h.logger.log("detachMedia"),this.trigger(v.Events.MEDIA_DETACHING,void 0),this._media=null},E.loadSource=function(t){this.stopLoad();var e=this.media,r=this.url,n=this.url=i.buildAbsoluteURL(self.location.href,t,{alwaysNormalize:!0});h.logger.log("loadSource:"+n),e&&r&&r!==n&&this.bufferController.hasSourceTypes()&&(this.detachMedia(),this.attachMedia(e)),this.trigger(v.Events.MANIFEST_LOADING,{url:t})},E.startLoad=function(t){void 0===t&&(t=-1),h.logger.log("startLoad("+t+")"),this.networkControllers.forEach((function(e){e.startLoad(t)}))},E.stopLoad=function(){h.logger.log("stopLoad"),this.networkControllers.forEach((function(t){t.stopLoad()}))},E.swapAudioCodec=function(){h.logger.log("swapAudioCodec"),this.streamController.swapAudioCodec()},E.recoverMediaError=function(){h.logger.log("recoverMediaError");var t=this._media;this.detachMedia(),t&&this.attachMedia(t)},E.removeLevel=function(t,e){void 0===e&&(e=0),this.levelController.removeLevel(t,e)},e=t,y=[{key:"version",get:function(){return"1.2.0"}},{key:"Events",get:function(){return v.Events}},{key:"ErrorTypes",get:function(){return p.ErrorTypes}},{key:"ErrorDetails",get:function(){return p.ErrorDetails}},{key:"DefaultConfig",get:function(){return t.defaultConfig?t.defaultConfig:f.hlsDefaultConfig},set:function(e){t.defaultConfig=e}}],(r=[{key:"levels",get:function(){var t=this.levelController.levels;return t||[]}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(t){h.logger.log("set currentLevel:"+t),this.loadLevel=t,this.abrController.clearTimer(),this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(t){h.logger.log("set nextLevel:"+t),this.levelController.manualLevel=t,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(t){h.logger.log("set loadLevel:"+t),this.levelController.manualLevel=t}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(t){this.levelController.nextLoadLevel=t}},{key:"firstLevel",get:function(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)},set:function(t){h.logger.log("set firstLevel:"+t),this.levelController.firstLevel=t}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(t){h.logger.log("set startLevel:"+t),-1!==t&&(t=Math.max(t,this.minAutoLevel)),this.levelController.startLevel=t}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(t){var e=!!t;e!==this.config.capLevelToPlayerSize&&(e?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=e)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(t){this._autoLevelCapping!==t&&(h.logger.log("set autoLevelCapping:"+t),this._autoLevelCapping=t)}},{key:"bandwidthEstimate",get:function(){var t=this.abrController.bwEstimator;return t?t.getEstimate():NaN}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}},{key:"minAutoLevel",get:function(){var t=this.levels,e=this.config.minAutoBitrate;if(!t)return 0;for(var r=t.length,i=0;i<r;i++)if(t[i].maxBitrate>=e)return i;return 0}},{key:"maxAutoLevel",get:function(){var t=this.levels,e=this.autoLevelCapping;return-1===e&&t&&t.length?t.length-1:e}},{key:"nextAutoLevel",get:function(){return Math.min(Math.max(this.abrController.nextAutoLevel,this.minAutoLevel),this.maxAutoLevel)},set:function(t){this.abrController.nextAutoLevel=Math.max(this.minAutoLevel,t)}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"audioTracks",get:function(){var t=this.audioTrackController;return t?t.audioTracks:[]}},{key:"audioTrack",get:function(){var t=this.audioTrackController;return t?t.audioTrack:-1},set:function(t){var e=this.audioTrackController;e&&(e.audioTrack=t)}},{key:"subtitleTracks",get:function(){var t=this.subtitleTrackController;return t?t.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var t=this.subtitleTrackController;return t?t.subtitleTrack:-1},set:function(t){var e=this.subtitleTrackController;e&&(e.subtitleTrack=t)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var t=this.subtitleTrackController;return!!t&&t.subtitleDisplay},set:function(t){var e=this.subtitleTrackController;e&&(e.subtitleDisplay=t)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(t){this.config.lowLatencyMode=t}},{key:"liveSyncPosition",get:function(){return this.latencyController.liveSyncPosition}},{key:"latency",get:function(){return this.latencyController.latency}},{key:"maxLatency",get:function(){return this.latencyController.maxLatency}},{key:"targetLatency",get:function(){return this.latencyController.targetLatency}},{key:"drift",get:function(){return this.latencyController.drift}},{key:"forceStartLoad",get:function(){return this.streamController.forceStartLoad}}])&&m(e.prototype,r),y&&m(e,y),Object.defineProperty(e,"prototype",{writable:!1}),t}();y.defaultConfig=void 0},"./src/is-supported.ts":
193
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return y}));var i=r(/*! url-toolkit */"./node_modules/url-toolkit/src/url-toolkit.js"),n=r(/*! ./loader/playlist-loader */"./src/loader/playlist-loader.ts"),a=r(/*! ./loader/key-loader */"./src/loader/key-loader.ts"),s=r(/*! ./controller/id3-track-controller */"./src/controller/id3-track-controller.ts"),o=r(/*! ./controller/latency-controller */"./src/controller/latency-controller.ts"),l=r(/*! ./controller/level-controller */"./src/controller/level-controller.ts"),u=r(/*! ./controller/fragment-tracker */"./src/controller/fragment-tracker.ts"),d=r(/*! ./controller/stream-controller */"./src/controller/stream-controller.ts"),c=r(/*! ./is-supported */"./src/is-supported.ts"),h=r(/*! ./utils/logger */"./src/utils/logger.ts"),f=r(/*! ./config */"./src/config.ts"),g=r(/*! eventemitter3 */"./node_modules/eventemitter3/index.js"),v=r(/*! ./events */"./src/events.ts"),p=r(/*! ./errors */"./src/errors.ts");function m(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var y=function(){function t(e){void 0===e&&(e={}),this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this._emitter=new g.EventEmitter,this._autoLevelCapping=void 0,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;var r=this.config=Object(f.mergeConfig)(t.DefaultConfig,e);this.userConfig=e,Object(h.enableLogs)(r.debug),this._autoLevelCapping=-1,r.progressive&&Object(f.enableStreamingMode)(r);var i=r.abrController,c=r.bufferController,v=r.capLevelController,p=r.fpsController,m=this.abrController=new i(this),y=this.bufferController=new c(this),E=this.capLevelController=new v(this),T=new p(this),S=new n.default(this),b=new a.default(this),L=new s.default(this),D=this.levelController=new l.default(this),A=new u.FragmentTracker(this),R=this.streamController=new d.default(this,A);E.setStreamController(R),T.setStreamController(R);var k=[S,b,D,R];this.networkControllers=k;var I=[m,y,E,T,L,A];this.audioTrackController=this.createController(r.audioTrackController,null,k),this.createController(r.audioStreamController,A,k),this.subtitleTrackController=this.createController(r.subtitleTrackController,null,k),this.createController(r.subtitleStreamController,A,k),this.createController(r.timelineController,null,I),this.emeController=this.createController(r.emeController,null,I),this.cmcdController=this.createController(r.cmcdController,null,I),this.latencyController=this.createController(o.default,null,I),this.coreComponents=I}t.isSupported=function(){return Object(c.isSupported)()};var e,r,y,E=t.prototype;return E.createController=function(t,e,r){if(t){var i=e?new t(this,e):new t(this);return r&&r.push(i),i}return null},E.on=function(t,e,r){void 0===r&&(r=this),this._emitter.on(t,e,r)},E.once=function(t,e,r){void 0===r&&(r=this),this._emitter.once(t,e,r)},E.removeAllListeners=function(t){this._emitter.removeAllListeners(t)},E.off=function(t,e,r,i){void 0===r&&(r=this),this._emitter.off(t,e,r,i)},E.listeners=function(t){return this._emitter.listeners(t)},E.emit=function(t,e,r){return this._emitter.emit(t,e,r)},E.trigger=function(t,e){if(this.config.debug)return this.emit(t,t,e);try{return this.emit(t,t,e)}catch(e){h.logger.error("An internal error happened while handling event "+t+'. Error message: "'+e.message+'". Here is a stacktrace:',e),this.trigger(v.Events.ERROR,{type:p.ErrorTypes.OTHER_ERROR,details:p.ErrorDetails.INTERNAL_EXCEPTION,fatal:!1,event:t,error:e})}return!1},E.listenerCount=function(t){return this._emitter.listenerCount(t)},E.destroy=function(){h.logger.log("destroy"),this.trigger(v.Events.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((function(t){return t.destroy()})),this.networkControllers.length=0,this.coreComponents.forEach((function(t){return t.destroy()})),this.coreComponents.length=0},E.attachMedia=function(t){h.logger.log("attachMedia"),this._media=t,this.trigger(v.Events.MEDIA_ATTACHING,{media:t})},E.detachMedia=function(){h.logger.log("detachMedia"),this.trigger(v.Events.MEDIA_DETACHING,void 0),this._media=null},E.loadSource=function(t){this.stopLoad();var e=this.media,r=this.url,n=this.url=i.buildAbsoluteURL(self.location.href,t,{alwaysNormalize:!0});h.logger.log("loadSource:"+n),e&&r&&r!==n&&this.bufferController.hasSourceTypes()&&(this.detachMedia(),this.attachMedia(e)),this.trigger(v.Events.MANIFEST_LOADING,{url:t})},E.startLoad=function(t){void 0===t&&(t=-1),h.logger.log("startLoad("+t+")"),this.networkControllers.forEach((function(e){e.startLoad(t)}))},E.stopLoad=function(){h.logger.log("stopLoad"),this.networkControllers.forEach((function(t){t.stopLoad()}))},E.swapAudioCodec=function(){h.logger.log("swapAudioCodec"),this.streamController.swapAudioCodec()},E.recoverMediaError=function(){h.logger.log("recoverMediaError");var t=this._media;this.detachMedia(),t&&this.attachMedia(t)},E.removeLevel=function(t,e){void 0===e&&(e=0),this.levelController.removeLevel(t,e)},e=t,y=[{key:"version",get:function(){return"1.2.3"}},{key:"Events",get:function(){return v.Events}},{key:"ErrorTypes",get:function(){return p.ErrorTypes}},{key:"ErrorDetails",get:function(){return p.ErrorDetails}},{key:"DefaultConfig",get:function(){return t.defaultConfig?t.defaultConfig:f.hlsDefaultConfig},set:function(e){t.defaultConfig=e}}],(r=[{key:"levels",get:function(){var t=this.levelController.levels;return t||[]}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(t){h.logger.log("set currentLevel:"+t),this.loadLevel=t,this.abrController.clearTimer(),this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(t){h.logger.log("set nextLevel:"+t),this.levelController.manualLevel=t,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(t){h.logger.log("set loadLevel:"+t),this.levelController.manualLevel=t}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(t){this.levelController.nextLoadLevel=t}},{key:"firstLevel",get:function(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)},set:function(t){h.logger.log("set firstLevel:"+t),this.levelController.firstLevel=t}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(t){h.logger.log("set startLevel:"+t),-1!==t&&(t=Math.max(t,this.minAutoLevel)),this.levelController.startLevel=t}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(t){var e=!!t;e!==this.config.capLevelToPlayerSize&&(e?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=e)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(t){this._autoLevelCapping!==t&&(h.logger.log("set autoLevelCapping:"+t),this._autoLevelCapping=t)}},{key:"bandwidthEstimate",get:function(){var t=this.abrController.bwEstimator;return t?t.getEstimate():NaN}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}},{key:"minAutoLevel",get:function(){var t=this.levels,e=this.config.minAutoBitrate;if(!t)return 0;for(var r=t.length,i=0;i<r;i++)if(t[i].maxBitrate>=e)return i;return 0}},{key:"maxAutoLevel",get:function(){var t=this.levels,e=this.autoLevelCapping;return-1===e&&t&&t.length?t.length-1:e}},{key:"nextAutoLevel",get:function(){return Math.min(Math.max(this.abrController.nextAutoLevel,this.minAutoLevel),this.maxAutoLevel)},set:function(t){this.abrController.nextAutoLevel=Math.max(this.minAutoLevel,t)}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"audioTracks",get:function(){var t=this.audioTrackController;return t?t.audioTracks:[]}},{key:"audioTrack",get:function(){var t=this.audioTrackController;return t?t.audioTrack:-1},set:function(t){var e=this.audioTrackController;e&&(e.audioTrack=t)}},{key:"subtitleTracks",get:function(){var t=this.subtitleTrackController;return t?t.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var t=this.subtitleTrackController;return t?t.subtitleTrack:-1},set:function(t){var e=this.subtitleTrackController;e&&(e.subtitleTrack=t)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var t=this.subtitleTrackController;return!!t&&t.subtitleDisplay},set:function(t){var e=this.subtitleTrackController;e&&(e.subtitleDisplay=t)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(t){this.config.lowLatencyMode=t}},{key:"liveSyncPosition",get:function(){return this.latencyController.liveSyncPosition}},{key:"latency",get:function(){return this.latencyController.latency}},{key:"maxLatency",get:function(){return this.latencyController.maxLatency}},{key:"targetLatency",get:function(){return this.latencyController.targetLatency}},{key:"drift",get:function(){return this.latencyController.drift}},{key:"forceStartLoad",get:function(){return this.streamController.forceStartLoad}}])&&m(e.prototype,r),y&&m(e,y),Object.defineProperty(e,"prototype",{writable:!1}),t}();y.defaultConfig=void 0},"./src/is-supported.ts":
194
194
  /*!*****************************!*\
195
195
  !*** ./src/is-supported.ts ***!
196
196
  \*****************************/
@@ -210,7 +210,7 @@
210
210
  /*!**********************************!*\
211
211
  !*** ./src/loader/key-loader.ts ***!
212
212
  \**********************************/
213
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return s}));var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../errors */"./src/errors.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=function(){function t(t){this.hls=void 0,this.loaders={},this.decryptkey=null,this.decrypturl=null,this.hls=t,this._registerListeners()}var e=t.prototype;return e._registerListeners=function(){this.hls.on(i.Events.KEY_LOADING,this.onKeyLoading,this)},e._unregisterListeners=function(){this.hls.off(i.Events.KEY_LOADING,this.onKeyLoading)},e.destroy=function(){for(var t in this._unregisterListeners(),this.loaders){var e=this.loaders[t];e&&e.destroy()}this.loaders={}},e.onKeyLoading=function(t,e){var r=e.frag,n=r.type,s=this.loaders[n];if(r.decryptdata){var o=r.decryptdata.uri;if(o!==this.decrypturl||null===this.decryptkey){var l=this.hls.config;if(s&&(a.logger.warn("abort previous key loader for type:"+n),s.abort()),!o)return void a.logger.warn("key uri is falsy");var u=l.loader,d=r.loader=this.loaders[n]=new u(l);this.decrypturl=o,this.decryptkey=null;var c={url:o,frag:r,responseType:"arraybuffer"},h={timeout:l.fragLoadingTimeOut,maxRetry:0,retryDelay:l.fragLoadingRetryDelay,maxRetryDelay:l.fragLoadingMaxRetryTimeout,highWaterMark:0},f={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};d.load(c,h,f)}else this.decryptkey&&(r.decryptdata.key=this.decryptkey,this.hls.trigger(i.Events.KEY_LOADED,{frag:r}))}else a.logger.warn("Missing decryption data on fragment in onKeyLoading")},e.loadsuccess=function(t,e,r){var n=r.frag;n.decryptdata?(this.decryptkey=n.decryptdata.key=new Uint8Array(t.data),n.loader=null,delete this.loaders[n.type],this.hls.trigger(i.Events.KEY_LOADED,{frag:n})):a.logger.error("after key load, decryptdata unset")},e.loaderror=function(t,e){var r=e.frag,a=r.loader;a&&a.abort(),delete this.loaders[r.type],this.hls.trigger(i.Events.ERROR,{type:n.ErrorTypes.NETWORK_ERROR,details:n.ErrorDetails.KEY_LOAD_ERROR,fatal:!1,frag:r,response:t})},e.loadtimeout=function(t,e){var r=e.frag,a=r.loader;a&&a.abort(),delete this.loaders[r.type],this.hls.trigger(i.Events.ERROR,{type:n.ErrorTypes.NETWORK_ERROR,details:n.ErrorDetails.KEY_LOAD_TIMEOUT,fatal:!1,frag:r})},t}()},"./src/loader/level-details.ts":
213
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return s}));var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../errors */"./src/errors.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=function(){function t(t){this.hls=void 0,this.loaders={},this.decryptkey=null,this.decrypturl=null,this.hls=t,this.registerListeners()}var e=t.prototype;return e.startLoad=function(t){},e.stopLoad=function(){this.destroyInternalLoaders()},e.registerListeners=function(){this.hls.on(i.Events.KEY_LOADING,this.onKeyLoading,this)},e.unregisterListeners=function(){this.hls.off(i.Events.KEY_LOADING,this.onKeyLoading)},e.destroyInternalLoaders=function(){for(var t in this.loaders){var e=this.loaders[t];e&&e.destroy()}this.loaders={}},e.destroy=function(){this.unregisterListeners(),this.destroyInternalLoaders()},e.onKeyLoading=function(t,e){var r=e.frag,n=r.type,s=this.loaders[n];if(r.decryptdata){var o=r.decryptdata.uri;if(o!==this.decrypturl||null===this.decryptkey){var l=this.hls.config;if(s&&(a.logger.warn("abort previous key loader for type:"+n),s.abort()),!o)return void a.logger.warn("key uri is falsy");var u=l.loader,d=r.loader=this.loaders[n]=new u(l);this.decrypturl=o,this.decryptkey=null;var c={url:o,frag:r,responseType:"arraybuffer"},h={timeout:l.fragLoadingTimeOut,maxRetry:0,retryDelay:l.fragLoadingRetryDelay,maxRetryDelay:l.fragLoadingMaxRetryTimeout,highWaterMark:0},f={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};d.load(c,h,f)}else this.decryptkey&&(r.decryptdata.key=this.decryptkey,this.hls.trigger(i.Events.KEY_LOADED,{frag:r}))}else a.logger.warn("Missing decryption data on fragment in onKeyLoading")},e.loadsuccess=function(t,e,r){var n=r.frag;n.decryptdata?(this.decryptkey=n.decryptdata.key=new Uint8Array(t.data),n.loader=null,delete this.loaders[n.type],this.hls.trigger(i.Events.KEY_LOADED,{frag:n})):a.logger.error("after key load, decryptdata unset")},e.loaderror=function(t,e){var r=e.frag,a=r.loader;a&&a.abort(),delete this.loaders[r.type],this.hls.trigger(i.Events.ERROR,{type:n.ErrorTypes.NETWORK_ERROR,details:n.ErrorDetails.KEY_LOAD_ERROR,fatal:!1,frag:r,response:t})},e.loadtimeout=function(t,e){var r=e.frag,a=r.loader;a&&a.abort(),delete this.loaders[r.type],this.hls.trigger(i.Events.ERROR,{type:n.ErrorTypes.NETWORK_ERROR,details:n.ErrorDetails.KEY_LOAD_TIMEOUT,fatal:!1,frag:r})},t}()},"./src/loader/level-details.ts":
214
214
  /*!*************************************!*\
215
215
  !*** ./src/loader/level-details.ts ***!
216
216
  \*************************************/
@@ -226,11 +226,11 @@
226
226
  /*!***********************************!*\
227
227
  !*** ./src/loader/m3u8-parser.ts ***!
228
228
  \***********************************/
229
- /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return m}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! url-toolkit */"./node_modules/url-toolkit/src/url-toolkit.js"),a=r(/*! ./date-range */"./src/loader/date-range.ts"),s=r(/*! ./fragment */"./src/loader/fragment.ts"),o=r(/*! ./level-details */"./src/loader/level-details.ts"),l=r(/*! ./level-key */"./src/loader/level-key.ts"),u=r(/*! ../utils/attr-list */"./src/utils/attr-list.ts"),d=r(/*! ../utils/logger */"./src/utils/logger.ts"),c=r(/*! ../utils/codecs */"./src/utils/codecs.ts"),h=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-SESSION-DATA:([^\r\n]*)[\r\n]+/g,f=/#EXT-X-MEDIA:(.*)/g,g=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[\S ]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),v=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),p=/\.(mp4|m4s|m4v|m4a)$/i,m=function(){function t(){}return t.findGroup=function(t,e){for(var r=0;r<t.length;r++){var i=t[r];if(i.id===e)return i}},t.convertAVC1ToAVCOTI=function(t){var e=t.split(".");if(e.length>2){var r=e.shift()+".";return r+=parseInt(e.shift()).toString(16),r+=("000"+parseInt(e.shift()).toString(16)).slice(-4)}return t},t.resolve=function(t,e){return n.buildAbsoluteURL(e,t,{alwaysNormalize:!0})},t.parseMasterPlaylist=function(e,r){var i,n=[],a={},s=!1;for(h.lastIndex=0;null!=(i=h.exec(e));)if(i[1]){var o=new u.AttrList(i[1]),l={attrs:o,bitrate:o.decimalInteger("AVERAGE-BANDWIDTH")||o.decimalInteger("BANDWIDTH"),name:o.NAME,url:t.resolve(i[2],r)},d=o.decimalResolution("RESOLUTION");d&&(l.width=d.width,l.height=d.height),y((o.CODECS||"").split(/[ ,]+/).filter((function(t){return t})),l),l.videoCodec&&-1!==l.videoCodec.indexOf("avc1")&&(l.videoCodec=t.convertAVC1ToAVCOTI(l.videoCodec)),n.push(l)}else if(i[3]){var c=new u.AttrList(i[3]);c["DATA-ID"]&&(s=!0,a[c["DATA-ID"]]=c)}return{levels:n,sessionData:s?a:null}},t.parseMasterPlaylistMedia=function(e,r,i,n){var a;void 0===n&&(n=[]);var s=[],o=0;for(f.lastIndex=0;null!==(a=f.exec(e));){var l=new u.AttrList(a[1]);if(l.TYPE===i){var d={attrs:l,bitrate:0,id:o++,groupId:l["GROUP-ID"],instreamId:l["INSTREAM-ID"],name:l.NAME||l.LANGUAGE||"",type:i,default:l.bool("DEFAULT"),autoselect:l.bool("AUTOSELECT"),forced:l.bool("FORCED"),lang:l.LANGUAGE,url:l.URI?t.resolve(l.URI,r):""};if(n.length){var c=t.findGroup(n,d.groupId)||n[0];E(d,c,"audioCodec"),E(d,c,"textCodec")}s.push(d)}}return s},t.parseLevelPlaylist=function(t,e,r,c,h){var f,m,y,E=new o.LevelDetails(e),b=E.fragments,L=null,D=0,A=0,R=0,k=0,I=null,_=new s.Fragment(c,e),O=-1,C=!1;for(g.lastIndex=0,E.m3u8=t;null!==(f=g.exec(t));){C&&(C=!1,(_=new s.Fragment(c,e)).start=R,_.sn=D,_.cc=k,_.level=r,L&&(_.initSegment=L,_.rawProgramDateTime=L.rawProgramDateTime,L.rawProgramDateTime=null));var w=f[1];if(w){_.duration=parseFloat(w);var x=(" "+f[2]).slice(1);_.title=x||null,_.tagList.push(x?["INF",w,x]:["INF",w])}else if(f[3])Object(i.isFiniteNumber)(_.duration)&&(_.start=R,y&&(_.levelkey=y),_.sn=D,_.level=r,_.cc=k,_.urlId=h,b.push(_),_.relurl=(" "+f[3]).slice(1),T(_,I),I=_,R+=_.duration,D++,A=0,C=!0);else if(f[4]){var P=(" "+f[4]).slice(1);I?_.setByteRange(P,I):_.setByteRange(P)}else if(f[5])_.rawProgramDateTime=(" "+f[5]).slice(1),_.tagList.push(["PROGRAM-DATE-TIME",_.rawProgramDateTime]),-1===O&&(O=b.length);else{if(!(f=f[0].match(v))){d.logger.warn("No matches on slow regex match for level playlist!");continue}for(m=1;m<f.length&&void 0===f[m];m++);var F=(" "+f[m]).slice(1),M=(" "+f[m+1]).slice(1),N=f[m+2]?(" "+f[m+2]).slice(1):"";switch(F){case"PLAYLIST-TYPE":E.type=M.toUpperCase();break;case"MEDIA-SEQUENCE":D=E.startSN=parseInt(M);break;case"SKIP":var U=new u.AttrList(M),B=U.decimalInteger("SKIPPED-SEGMENTS");if(Object(i.isFiniteNumber)(B)){E.skippedSegments=B;for(var G=B;G--;)b.unshift(null);D+=B}var j=U.enumeratedString("RECENTLY-REMOVED-DATERANGES");j&&(E.recentlyRemovedDateranges=j.split("\t"));break;case"TARGETDURATION":E.targetduration=parseFloat(M);break;case"VERSION":E.version=parseInt(M);break;case"EXTM3U":break;case"ENDLIST":E.live=!1;break;case"#":(M||N)&&_.tagList.push(N?[M,N]:[M]);break;case"DISCONTINUITY":k++,_.tagList.push(["DIS"]);break;case"GAP":_.tagList.push([F]);break;case"BITRATE":_.tagList.push([F,M]);break;case"DATERANGE":var K=new u.AttrList(M),H=new a.DateRange(K,E.dateRanges[K.ID]);H.isValid||E.skippedSegments?E.dateRanges[H.id]=H:d.logger.warn('Ignoring invalid DATERANGE tag: "'+M+'"'),_.tagList.push(["EXT-X-DATERANGE",M]);break;case"DISCONTINUITY-SEQUENCE":k=parseInt(M);break;case"KEY":var V,W=new u.AttrList(M),Y=W.enumeratedString("METHOD"),q=W.URI,z=W.hexadecimalInteger("IV"),X=W.enumeratedString("KEYFORMATVERSIONS"),Q=W.enumeratedString("KEYID"),$=null!=(V=W.enumeratedString("KEYFORMAT"))?V:"identity";if(["com.apple.streamingkeydelivery","com.microsoft.playready","urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed","com.widevine"].indexOf($)>-1){d.logger.warn("Keyformat "+$+" is not supported from the manifest");continue}if("identity"!==$)continue;Y&&(y=l.LevelKey.fromURL(e,q),q&&["AES-128","SAMPLE-AES","SAMPLE-AES-CENC"].indexOf(Y)>=0&&(y.method=Y,y.keyFormat=$,Q&&(y.keyID=Q),X&&(y.keyFormatVersions=X),y.iv=z));break;case"START":var J=new u.AttrList(M).decimalFloatingPoint("TIME-OFFSET");Object(i.isFiniteNumber)(J)&&(E.startTimeOffset=J);break;case"MAP":var Z=new u.AttrList(M);if(_.duration){var tt=new s.Fragment(c,e);S(tt,Z,r,y),L=tt,_.initSegment=L,L.rawProgramDateTime&&!_.rawProgramDateTime&&(_.rawProgramDateTime=L.rawProgramDateTime)}else S(_,Z,r,y),L=_,C=!0;break;case"SERVER-CONTROL":var et=new u.AttrList(M);E.canBlockReload=et.bool("CAN-BLOCK-RELOAD"),E.canSkipUntil=et.optionalFloat("CAN-SKIP-UNTIL",0),E.canSkipDateRanges=E.canSkipUntil>0&&et.bool("CAN-SKIP-DATERANGES"),E.partHoldBack=et.optionalFloat("PART-HOLD-BACK",0),E.holdBack=et.optionalFloat("HOLD-BACK",0);break;case"PART-INF":var rt=new u.AttrList(M);E.partTarget=rt.decimalFloatingPoint("PART-TARGET");break;case"PART":var it=E.partList;it||(it=E.partList=[]);var nt=A>0?it[it.length-1]:void 0,at=A++,st=new s.Part(new u.AttrList(M),_,e,at,nt);it.push(st),_.duration+=st.duration;break;case"PRELOAD-HINT":var ot=new u.AttrList(M);E.preloadHint=ot;break;case"RENDITION-REPORT":var lt=new u.AttrList(M);E.renditionReports=E.renditionReports||[],E.renditionReports.push(lt);break;default:d.logger.warn("line parsed but not handled: "+f)}}}I&&!I.relurl?(b.pop(),R-=I.duration,E.partList&&(E.fragmentHint=I)):E.partList&&(T(_,I),_.cc=k,E.fragmentHint=_);var ut=b.length,dt=b[0],ct=b[ut-1];if((R+=E.skippedSegments*E.targetduration)>0&&ut&&ct){E.averagetargetduration=R/ut;var ht=ct.sn;E.endSN="initSegment"!==ht?ht:0,dt&&(E.startCC=dt.cc,dt.initSegment||E.fragments.every((function(t){return t.relurl&&(e=t.relurl,p.test(null!=(r=null===(i=n.parseURL(e))||void 0===i?void 0:i.path)?r:""));var e,r,i}))&&(d.logger.warn("MP4 fragments found but no init segment (probably no MAP, incomplete M3U8), trying to fetch SIDX"),(_=new s.Fragment(c,e)).relurl=ct.relurl,_.level=r,_.sn="initSegment",dt.initSegment=_,E.needSidxRanges=!0))}else E.endSN=0,E.startCC=0;return E.fragmentHint&&(R+=E.fragmentHint.duration),E.totalduration=R,E.endCC=k,O>0&&function(t,e){for(var r=t[e],i=e;i--;){var n=t[i];if(!n)return;n.programDateTime=r.programDateTime-1e3*n.duration,r=n}}(b,O),E},t}();function y(t,e){["video","audio","text"].forEach((function(r){var i=t.filter((function(t){return Object(c.isCodecType)(t,r)}));if(i.length){var n=i.filter((function(t){return 0===t.lastIndexOf("avc1",0)||0===t.lastIndexOf("mp4a",0)}));e[r+"Codec"]=n.length>0?n[0]:i[0],t=t.filter((function(t){return-1===i.indexOf(t)}))}})),e.unknownCodecs=t}function E(t,e,r){var i=e[r];i&&(t[r]=i)}function T(t,e){t.rawProgramDateTime?t.programDateTime=Date.parse(t.rawProgramDateTime):null!=e&&e.programDateTime&&(t.programDateTime=e.endProgramDateTime),Object(i.isFiniteNumber)(t.programDateTime)||(t.programDateTime=null,t.rawProgramDateTime=null)}function S(t,e,r,i){t.relurl=e.URI,e.BYTERANGE&&t.setByteRange(e.BYTERANGE),t.level=r,t.sn="initSegment",i&&(t.levelkey=i),t.initSegment=null}},"./src/loader/playlist-loader.ts":
229
+ /*! exports provided: default */function(t,e,r){r.r(e),r.d(e,"default",(function(){return m}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! url-toolkit */"./node_modules/url-toolkit/src/url-toolkit.js"),a=r(/*! ./date-range */"./src/loader/date-range.ts"),s=r(/*! ./fragment */"./src/loader/fragment.ts"),o=r(/*! ./level-details */"./src/loader/level-details.ts"),l=r(/*! ./level-key */"./src/loader/level-key.ts"),u=r(/*! ../utils/attr-list */"./src/utils/attr-list.ts"),d=r(/*! ../utils/logger */"./src/utils/logger.ts"),c=r(/*! ../utils/codecs */"./src/utils/codecs.ts"),h=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-SESSION-DATA:([^\r\n]*)[\r\n]+/g,f=/#EXT-X-MEDIA:(.*)/g,g=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[\S ]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),v=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),p=/\.(mp4|m4s|m4v|m4a)$/i,m=function(){function t(){}return t.findGroup=function(t,e){for(var r=0;r<t.length;r++){var i=t[r];if(i.id===e)return i}},t.convertAVC1ToAVCOTI=function(t){var e=t.split(".");if(e.length>2){var r=e.shift()+".";return r+=parseInt(e.shift()).toString(16),r+=("000"+parseInt(e.shift()).toString(16)).slice(-4)}return t},t.resolve=function(t,e){return n.buildAbsoluteURL(e,t,{alwaysNormalize:!0})},t.parseMasterPlaylist=function(e,r){var i,n=[],a={},s=!1;for(h.lastIndex=0;null!=(i=h.exec(e));)if(i[1]){var o=new u.AttrList(i[1]),l={attrs:o,bitrate:o.decimalInteger("AVERAGE-BANDWIDTH")||o.decimalInteger("BANDWIDTH"),name:o.NAME,url:t.resolve(i[2],r)},d=o.decimalResolution("RESOLUTION");d&&(l.width=d.width,l.height=d.height),y((o.CODECS||"").split(/[ ,]+/).filter((function(t){return t})),l),l.videoCodec&&-1!==l.videoCodec.indexOf("avc1")&&(l.videoCodec=t.convertAVC1ToAVCOTI(l.videoCodec)),n.push(l)}else if(i[3]){var c=new u.AttrList(i[3]);c["DATA-ID"]&&(s=!0,a[c["DATA-ID"]]=c)}return{levels:n,sessionData:s?a:null}},t.parseMasterPlaylistMedia=function(e,r,i,n){var a;void 0===n&&(n=[]);var s=[],o=0;for(f.lastIndex=0;null!==(a=f.exec(e));){var l=new u.AttrList(a[1]);if(l.TYPE===i){var d={attrs:l,bitrate:0,id:o++,groupId:l["GROUP-ID"],instreamId:l["INSTREAM-ID"],name:l.NAME||l.LANGUAGE||"",type:i,default:l.bool("DEFAULT"),autoselect:l.bool("AUTOSELECT"),forced:l.bool("FORCED"),lang:l.LANGUAGE,url:l.URI?t.resolve(l.URI,r):""};if(n.length){var c=t.findGroup(n,d.groupId)||n[0];E(d,c,"audioCodec"),E(d,c,"textCodec")}s.push(d)}}return s},t.parseLevelPlaylist=function(t,e,r,c,h){var f,m,y,E=new o.LevelDetails(e),b=E.fragments,L=null,D=0,A=0,R=0,k=0,I=null,_=new s.Fragment(c,e),C=-1,O=!1;for(g.lastIndex=0,E.m3u8=t;null!==(f=g.exec(t));){O&&(O=!1,(_=new s.Fragment(c,e)).start=R,_.sn=D,_.cc=k,_.level=r,L&&(_.initSegment=L,_.rawProgramDateTime=L.rawProgramDateTime,L.rawProgramDateTime=null));var w=f[1];if(w){_.duration=parseFloat(w);var x=(" "+f[2]).slice(1);_.title=x||null,_.tagList.push(x?["INF",w,x]:["INF",w])}else if(f[3])Object(i.isFiniteNumber)(_.duration)&&(_.start=R,y&&(_.levelkey=y),_.sn=D,_.level=r,_.cc=k,_.urlId=h,b.push(_),_.relurl=(" "+f[3]).slice(1),T(_,I),I=_,R+=_.duration,D++,A=0,O=!0);else if(f[4]){var P=(" "+f[4]).slice(1);I?_.setByteRange(P,I):_.setByteRange(P)}else if(f[5])_.rawProgramDateTime=(" "+f[5]).slice(1),_.tagList.push(["PROGRAM-DATE-TIME",_.rawProgramDateTime]),-1===C&&(C=b.length);else{if(!(f=f[0].match(v))){d.logger.warn("No matches on slow regex match for level playlist!");continue}for(m=1;m<f.length&&void 0===f[m];m++);var F=(" "+f[m]).slice(1),M=(" "+f[m+1]).slice(1),N=f[m+2]?(" "+f[m+2]).slice(1):"";switch(F){case"PLAYLIST-TYPE":E.type=M.toUpperCase();break;case"MEDIA-SEQUENCE":D=E.startSN=parseInt(M);break;case"SKIP":var U=new u.AttrList(M),B=U.decimalInteger("SKIPPED-SEGMENTS");if(Object(i.isFiniteNumber)(B)){E.skippedSegments=B;for(var G=B;G--;)b.unshift(null);D+=B}var j=U.enumeratedString("RECENTLY-REMOVED-DATERANGES");j&&(E.recentlyRemovedDateranges=j.split("\t"));break;case"TARGETDURATION":E.targetduration=parseFloat(M);break;case"VERSION":E.version=parseInt(M);break;case"EXTM3U":break;case"ENDLIST":E.live=!1;break;case"#":(M||N)&&_.tagList.push(N?[M,N]:[M]);break;case"DISCONTINUITY":k++,_.tagList.push(["DIS"]);break;case"GAP":_.tagList.push([F]);break;case"BITRATE":_.tagList.push([F,M]);break;case"DATERANGE":var H=new u.AttrList(M),K=new a.DateRange(H,E.dateRanges[H.ID]);K.isValid||E.skippedSegments?E.dateRanges[K.id]=K:d.logger.warn('Ignoring invalid DATERANGE tag: "'+M+'"'),_.tagList.push(["EXT-X-DATERANGE",M]);break;case"DISCONTINUITY-SEQUENCE":k=parseInt(M);break;case"KEY":var V,W=new u.AttrList(M),Y=W.enumeratedString("METHOD"),q=W.URI,z=W.hexadecimalInteger("IV"),X=W.enumeratedString("KEYFORMATVERSIONS"),Q=W.enumeratedString("KEYID"),$=null!=(V=W.enumeratedString("KEYFORMAT"))?V:"identity";if(["com.apple.streamingkeydelivery","com.microsoft.playready","urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed","com.widevine"].indexOf($)>-1){d.logger.warn("Keyformat "+$+" is not supported from the manifest");continue}if("identity"!==$)continue;Y&&(y=l.LevelKey.fromURL(e,q),q&&["AES-128","SAMPLE-AES","SAMPLE-AES-CENC"].indexOf(Y)>=0&&(y.method=Y,y.keyFormat=$,Q&&(y.keyID=Q),X&&(y.keyFormatVersions=X),y.iv=z));break;case"START":var J=new u.AttrList(M).decimalFloatingPoint("TIME-OFFSET");Object(i.isFiniteNumber)(J)&&(E.startTimeOffset=J);break;case"MAP":var Z=new u.AttrList(M);if(_.duration){var tt=new s.Fragment(c,e);S(tt,Z,r,y),L=tt,_.initSegment=L,L.rawProgramDateTime&&!_.rawProgramDateTime&&(_.rawProgramDateTime=L.rawProgramDateTime)}else S(_,Z,r,y),L=_,O=!0;break;case"SERVER-CONTROL":var et=new u.AttrList(M);E.canBlockReload=et.bool("CAN-BLOCK-RELOAD"),E.canSkipUntil=et.optionalFloat("CAN-SKIP-UNTIL",0),E.canSkipDateRanges=E.canSkipUntil>0&&et.bool("CAN-SKIP-DATERANGES"),E.partHoldBack=et.optionalFloat("PART-HOLD-BACK",0),E.holdBack=et.optionalFloat("HOLD-BACK",0);break;case"PART-INF":var rt=new u.AttrList(M);E.partTarget=rt.decimalFloatingPoint("PART-TARGET");break;case"PART":var it=E.partList;it||(it=E.partList=[]);var nt=A>0?it[it.length-1]:void 0,at=A++,st=new s.Part(new u.AttrList(M),_,e,at,nt);it.push(st),_.duration+=st.duration;break;case"PRELOAD-HINT":var ot=new u.AttrList(M);E.preloadHint=ot;break;case"RENDITION-REPORT":var lt=new u.AttrList(M);E.renditionReports=E.renditionReports||[],E.renditionReports.push(lt);break;default:d.logger.warn("line parsed but not handled: "+f)}}}I&&!I.relurl?(b.pop(),R-=I.duration,E.partList&&(E.fragmentHint=I)):E.partList&&(T(_,I),_.cc=k,E.fragmentHint=_);var ut=b.length,dt=b[0],ct=b[ut-1];if((R+=E.skippedSegments*E.targetduration)>0&&ut&&ct){E.averagetargetduration=R/ut;var ht=ct.sn;E.endSN="initSegment"!==ht?ht:0,dt&&(E.startCC=dt.cc,dt.initSegment||E.fragments.every((function(t){return t.relurl&&(e=t.relurl,p.test(null!=(r=null===(i=n.parseURL(e))||void 0===i?void 0:i.path)?r:""));var e,r,i}))&&(d.logger.warn("MP4 fragments found but no init segment (probably no MAP, incomplete M3U8), trying to fetch SIDX"),(_=new s.Fragment(c,e)).relurl=ct.relurl,_.level=r,_.sn="initSegment",dt.initSegment=_,E.needSidxRanges=!0))}else E.endSN=0,E.startCC=0;return E.fragmentHint&&(R+=E.fragmentHint.duration),E.totalduration=R,E.endCC=k,C>0&&function(t,e){for(var r=t[e],i=e;i--;){var n=t[i];if(!n)return;n.programDateTime=r.programDateTime-1e3*n.duration,r=n}}(b,C),E},t}();function y(t,e){["video","audio","text"].forEach((function(r){var i=t.filter((function(t){return Object(c.isCodecType)(t,r)}));if(i.length){var n=i.filter((function(t){return 0===t.lastIndexOf("avc1",0)||0===t.lastIndexOf("mp4a",0)}));e[r+"Codec"]=n.length>0?n[0]:i[0],t=t.filter((function(t){return-1===i.indexOf(t)}))}})),e.unknownCodecs=t}function E(t,e,r){var i=e[r];i&&(t[r]=i)}function T(t,e){t.rawProgramDateTime?t.programDateTime=Date.parse(t.rawProgramDateTime):null!=e&&e.programDateTime&&(t.programDateTime=e.endProgramDateTime),Object(i.isFiniteNumber)(t.programDateTime)||(t.programDateTime=null,t.rawProgramDateTime=null)}function S(t,e,r,i){t.relurl=e.URI,e.BYTERANGE&&t.setByteRange(e.BYTERANGE),t.level=r,t.sn="initSegment",i&&(t.levelkey=i),t.initSegment=null}},"./src/loader/playlist-loader.ts":
230
230
  /*!***************************************!*\
231
231
  !*** ./src/loader/playlist-loader.ts ***!
232
232
  \***************************************/
233
- /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),o=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),l=r(/*! ./m3u8-parser */"./src/loader/m3u8-parser.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../utils/attr-list */"./src/utils/attr-list.ts");function c(t,e){var r=t.url;return void 0!==r&&0!==r.indexOf("data:")||(r=e.url),r}var h=function(){function t(t){this.hls=void 0,this.loaders=Object.create(null),this.hls=t,this.registerListeners()}var e=t.prototype;return e.registerListeners=function(){var t=this.hls;t.on(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(n.Events.LEVEL_LOADING,this.onLevelLoading,this),t.on(n.Events.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.on(n.Events.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},e.unregisterListeners=function(){var t=this.hls;t.off(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(n.Events.LEVEL_LOADING,this.onLevelLoading,this),t.off(n.Events.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.off(n.Events.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},e.createInternalLoader=function(t){var e=this.hls.config,r=e.pLoader,i=e.loader,n=new(r||i)(e);return t.loader=n,this.loaders[t.type]=n,n},e.getInternalLoader=function(t){return this.loaders[t.type]},e.resetInternalLoader=function(t){this.loaders[t]&&delete this.loaders[t]},e.destroyInternalLoaders=function(){for(var t in this.loaders){var e=this.loaders[t];e&&e.destroy(),this.resetInternalLoader(t)}},e.destroy=function(){this.unregisterListeners(),this.destroyInternalLoaders()},e.onManifestLoading=function(t,e){var r=e.url;this.load({id:null,groupId:null,level:0,responseType:"text",type:u.PlaylistContextType.MANIFEST,url:r,deliveryDirectives:null})},e.onLevelLoading=function(t,e){var r=e.id,i=e.level,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:null,level:i,responseType:"text",type:u.PlaylistContextType.LEVEL,url:n,deliveryDirectives:a})},e.onAudioTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:u.PlaylistContextType.AUDIO_TRACK,url:n,deliveryDirectives:a})},e.onSubtitleTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:u.PlaylistContextType.SUBTITLE_TRACK,url:n,deliveryDirectives:a})},e.load=function(t){var e,r,i,n,a,o,l=this.hls.config,d=this.getInternalLoader(t);if(d){var c=d.context;if(c&&c.url===t.url)return void s.logger.trace("[playlist-loader]: playlist request ongoing");s.logger.log("[playlist-loader]: aborting previous loader for type: "+t.type),d.abort()}switch(t.type){case u.PlaylistContextType.MANIFEST:r=l.manifestLoadingMaxRetry,i=l.manifestLoadingTimeOut,n=l.manifestLoadingRetryDelay,a=l.manifestLoadingMaxRetryTimeout;break;case u.PlaylistContextType.LEVEL:case u.PlaylistContextType.AUDIO_TRACK:case u.PlaylistContextType.SUBTITLE_TRACK:r=0,i=l.levelLoadingTimeOut;break;default:r=l.levelLoadingMaxRetry,i=l.levelLoadingTimeOut,n=l.levelLoadingRetryDelay,a=l.levelLoadingMaxRetryTimeout}if(d=this.createInternalLoader(t),null!==(e=t.deliveryDirectives)&&void 0!==e&&e.part&&(t.type===u.PlaylistContextType.LEVEL&&null!==t.level?o=this.hls.levels[t.level].details:t.type===u.PlaylistContextType.AUDIO_TRACK&&null!==t.id?o=this.hls.audioTracks[t.id].details:t.type===u.PlaylistContextType.SUBTITLE_TRACK&&null!==t.id&&(o=this.hls.subtitleTracks[t.id].details),o)){var h=o.partTarget,f=o.targetduration;h&&f&&(i=Math.min(1e3*Math.max(3*h,.8*f),i))}var g={timeout:i,maxRetry:r,retryDelay:n,maxRetryDelay:a,highWaterMark:0},v={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};d.load(t,g,v)},e.loadsuccess=function(t,e,r,i){if(void 0===i&&(i=null),r.isSidxRequest)return this.handleSidxRequest(t,r),void this.handlePlaylistLoaded(t,e,r,i);this.resetInternalLoader(r.type);var n=t.data;0===n.indexOf("#EXTM3U")?(e.parsing.start=performance.now(),n.indexOf("#EXTINF:")>0||n.indexOf("#EXT-X-TARGETDURATION:")>0?this.handleTrackOrLevelPlaylist(t,e,r,i):this.handleMasterPlaylist(t,e,r,i)):this.handleManifestParsingError(t,r,"no EXTM3U delimiter",i)},e.loaderror=function(t,e,r){void 0===r&&(r=null),this.handleNetworkError(e,r,!1,t)},e.loadtimeout=function(t,e,r){void 0===r&&(r=null),this.handleNetworkError(e,r,!0)},e.handleMasterPlaylist=function(t,e,r,i){var a=this.hls,o=t.data,u=c(t,r),h=l.default.parseMasterPlaylist(o,u),f=h.levels,g=h.sessionData;if(f.length){var v=f.map((function(t){return{id:t.attrs.AUDIO,audioCodec:t.audioCodec}})),p=f.map((function(t){return{id:t.attrs.SUBTITLES,textCodec:t.textCodec}})),m=l.default.parseMasterPlaylistMedia(o,u,"AUDIO",v),y=l.default.parseMasterPlaylistMedia(o,u,"SUBTITLES",p),E=l.default.parseMasterPlaylistMedia(o,u,"CLOSED-CAPTIONS");m.length&&(m.some((function(t){return!t.url}))||!f[0].audioCodec||f[0].attrs.AUDIO||(s.logger.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),m.unshift({type:"main",name:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new d.AttrList({}),bitrate:0,url:""}))),a.trigger(n.Events.MANIFEST_LOADED,{levels:f,audioTracks:m,subtitles:y,captions:E,url:u,stats:e,networkDetails:i,sessionData:g})}else this.handleManifestParsingError(t,r,"no level found in manifest",i)},e.handleTrackOrLevelPlaylist=function(t,e,r,s){var o=this.hls,h=r.id,f=r.level,g=r.type,v=c(t,r),p=Object(i.isFiniteNumber)(h)?h:0,m=Object(i.isFiniteNumber)(f)?f:p,y=function(t){switch(t.type){case u.PlaylistContextType.AUDIO_TRACK:return u.PlaylistLevelType.AUDIO;case u.PlaylistContextType.SUBTITLE_TRACK:return u.PlaylistLevelType.SUBTITLE;default:return u.PlaylistLevelType.MAIN}}(r),E=l.default.parseLevelPlaylist(t.data,v,m,y,p);if(E.fragments.length){if(g===u.PlaylistContextType.MANIFEST){var T={attrs:new d.AttrList({}),bitrate:0,details:E,name:"",url:v};o.trigger(n.Events.MANIFEST_LOADED,{levels:[T],audioTracks:[],url:v,stats:e,networkDetails:s,sessionData:null})}if(e.parsing.end=performance.now(),E.needSidxRanges){var S,b=null===(S=E.fragments[0].initSegment)||void 0===S?void 0:S.url;this.load({url:b,isSidxRequest:!0,type:g,level:f,levelDetails:E,id:h,groupId:null,rangeStart:0,rangeEnd:2048,responseType:"arraybuffer",deliveryDirectives:null})}else r.levelDetails=E,this.handlePlaylistLoaded(t,e,r,s)}else o.trigger(n.Events.ERROR,{type:a.ErrorTypes.NETWORK_ERROR,details:a.ErrorDetails.LEVEL_EMPTY_ERROR,fatal:!1,url:v,reason:"no fragments found in level",level:"number"==typeof r.level?r.level:void 0})},e.handleSidxRequest=function(t,e){var r=Object(o.parseSegmentIndex)(new Uint8Array(t.data));if(r){var i=r.references,n=e.levelDetails;i.forEach((function(t,e){var i=t.info,a=n.fragments[e];0===a.byteRange.length&&a.setByteRange(String(1+i.end-i.start)+"@"+String(i.start)),a.initSegment&&a.initSegment.setByteRange(String(r.moovEndOffset)+"@0")}))}},e.handleManifestParsingError=function(t,e,r,i){this.hls.trigger(n.Events.ERROR,{type:a.ErrorTypes.NETWORK_ERROR,details:a.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:e.type===u.PlaylistContextType.MANIFEST,url:t.url,reason:r,response:t,context:e,networkDetails:i})},e.handleNetworkError=function(t,e,r,i){void 0===r&&(r=!1),s.logger.warn("[playlist-loader]: A network "+(r?"timeout":"error")+" occurred while loading "+t.type+" level: "+t.level+" id: "+t.id+' group-id: "'+t.groupId+'"');var o=a.ErrorDetails.UNKNOWN,l=!1,d=this.getInternalLoader(t);switch(t.type){case u.PlaylistContextType.MANIFEST:o=r?a.ErrorDetails.MANIFEST_LOAD_TIMEOUT:a.ErrorDetails.MANIFEST_LOAD_ERROR,l=!0;break;case u.PlaylistContextType.LEVEL:o=r?a.ErrorDetails.LEVEL_LOAD_TIMEOUT:a.ErrorDetails.LEVEL_LOAD_ERROR,l=!1;break;case u.PlaylistContextType.AUDIO_TRACK:o=r?a.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:a.ErrorDetails.AUDIO_TRACK_LOAD_ERROR,l=!1;break;case u.PlaylistContextType.SUBTITLE_TRACK:o=r?a.ErrorDetails.SUBTITLE_TRACK_LOAD_TIMEOUT:a.ErrorDetails.SUBTITLE_LOAD_ERROR,l=!1}d&&this.resetInternalLoader(t.type);var c={type:a.ErrorTypes.NETWORK_ERROR,details:o,fatal:l,url:t.url,loader:d,context:t,networkDetails:e};i&&(c.response=i),this.hls.trigger(n.Events.ERROR,c)},e.handlePlaylistLoaded=function(t,e,r,i){var a=r.type,s=r.level,o=r.id,l=r.groupId,d=r.loader,c=r.levelDetails,h=r.deliveryDirectives;if(null!=c&&c.targetduration){if(d)switch(c.live&&(d.getCacheAge&&(c.ageHeader=d.getCacheAge()||0),d.getCacheAge&&!isNaN(c.ageHeader)||(c.ageHeader=0)),a){case u.PlaylistContextType.MANIFEST:case u.PlaylistContextType.LEVEL:this.hls.trigger(n.Events.LEVEL_LOADED,{details:c,level:s||0,id:o||0,stats:e,networkDetails:i,deliveryDirectives:h});break;case u.PlaylistContextType.AUDIO_TRACK:this.hls.trigger(n.Events.AUDIO_TRACK_LOADED,{details:c,id:o||0,groupId:l||"",stats:e,networkDetails:i,deliveryDirectives:h});break;case u.PlaylistContextType.SUBTITLE_TRACK:this.hls.trigger(n.Events.SUBTITLE_TRACK_LOADED,{details:c,id:o||0,groupId:l||"",stats:e,networkDetails:i,deliveryDirectives:h})}}else this.handleManifestParsingError(t,r,"invalid target duration",i)},t}();e.default=h},"./src/polyfills/number.ts":
233
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../events */"./src/events.ts"),a=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),o=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),l=r(/*! ./m3u8-parser */"./src/loader/m3u8-parser.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../utils/attr-list */"./src/utils/attr-list.ts");function c(t,e){var r=t.url;return void 0!==r&&0!==r.indexOf("data:")||(r=e.url),r}var h=function(){function t(t){this.hls=void 0,this.loaders=Object.create(null),this.hls=t,this.registerListeners()}var e=t.prototype;return e.startLoad=function(t){},e.stopLoad=function(){this.destroyInternalLoaders()},e.registerListeners=function(){var t=this.hls;t.on(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.on(n.Events.LEVEL_LOADING,this.onLevelLoading,this),t.on(n.Events.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.on(n.Events.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},e.unregisterListeners=function(){var t=this.hls;t.off(n.Events.MANIFEST_LOADING,this.onManifestLoading,this),t.off(n.Events.LEVEL_LOADING,this.onLevelLoading,this),t.off(n.Events.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.off(n.Events.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},e.createInternalLoader=function(t){var e=this.hls.config,r=e.pLoader,i=e.loader,n=new(r||i)(e);return t.loader=n,this.loaders[t.type]=n,n},e.getInternalLoader=function(t){return this.loaders[t.type]},e.resetInternalLoader=function(t){this.loaders[t]&&delete this.loaders[t]},e.destroyInternalLoaders=function(){for(var t in this.loaders){var e=this.loaders[t];e&&e.destroy(),this.resetInternalLoader(t)}},e.destroy=function(){this.unregisterListeners(),this.destroyInternalLoaders()},e.onManifestLoading=function(t,e){var r=e.url;this.load({id:null,groupId:null,level:0,responseType:"text",type:u.PlaylistContextType.MANIFEST,url:r,deliveryDirectives:null})},e.onLevelLoading=function(t,e){var r=e.id,i=e.level,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:null,level:i,responseType:"text",type:u.PlaylistContextType.LEVEL,url:n,deliveryDirectives:a})},e.onAudioTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:u.PlaylistContextType.AUDIO_TRACK,url:n,deliveryDirectives:a})},e.onSubtitleTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:u.PlaylistContextType.SUBTITLE_TRACK,url:n,deliveryDirectives:a})},e.load=function(t){var e,r,i,n,a,o,l=this.hls.config,d=this.getInternalLoader(t);if(d){var c=d.context;if(c&&c.url===t.url)return void s.logger.trace("[playlist-loader]: playlist request ongoing");s.logger.log("[playlist-loader]: aborting previous loader for type: "+t.type),d.abort()}switch(t.type){case u.PlaylistContextType.MANIFEST:r=l.manifestLoadingMaxRetry,i=l.manifestLoadingTimeOut,n=l.manifestLoadingRetryDelay,a=l.manifestLoadingMaxRetryTimeout;break;case u.PlaylistContextType.LEVEL:case u.PlaylistContextType.AUDIO_TRACK:case u.PlaylistContextType.SUBTITLE_TRACK:r=0,i=l.levelLoadingTimeOut;break;default:r=l.levelLoadingMaxRetry,i=l.levelLoadingTimeOut,n=l.levelLoadingRetryDelay,a=l.levelLoadingMaxRetryTimeout}if(d=this.createInternalLoader(t),null!==(e=t.deliveryDirectives)&&void 0!==e&&e.part&&(t.type===u.PlaylistContextType.LEVEL&&null!==t.level?o=this.hls.levels[t.level].details:t.type===u.PlaylistContextType.AUDIO_TRACK&&null!==t.id?o=this.hls.audioTracks[t.id].details:t.type===u.PlaylistContextType.SUBTITLE_TRACK&&null!==t.id&&(o=this.hls.subtitleTracks[t.id].details),o)){var h=o.partTarget,f=o.targetduration;h&&f&&(i=Math.min(1e3*Math.max(3*h,.8*f),i))}var g={timeout:i,maxRetry:r,retryDelay:n,maxRetryDelay:a,highWaterMark:0},v={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};d.load(t,g,v)},e.loadsuccess=function(t,e,r,i){if(void 0===i&&(i=null),r.isSidxRequest)return this.handleSidxRequest(t,r),void this.handlePlaylistLoaded(t,e,r,i);this.resetInternalLoader(r.type);var n=t.data;0===n.indexOf("#EXTM3U")?(e.parsing.start=performance.now(),n.indexOf("#EXTINF:")>0||n.indexOf("#EXT-X-TARGETDURATION:")>0?this.handleTrackOrLevelPlaylist(t,e,r,i):this.handleMasterPlaylist(t,e,r,i)):this.handleManifestParsingError(t,r,"no EXTM3U delimiter",i)},e.loaderror=function(t,e,r){void 0===r&&(r=null),this.handleNetworkError(e,r,!1,t)},e.loadtimeout=function(t,e,r){void 0===r&&(r=null),this.handleNetworkError(e,r,!0)},e.handleMasterPlaylist=function(t,e,r,i){var a=this.hls,o=t.data,u=c(t,r),h=l.default.parseMasterPlaylist(o,u),f=h.levels,g=h.sessionData;if(f.length){var v=f.map((function(t){return{id:t.attrs.AUDIO,audioCodec:t.audioCodec}})),p=f.map((function(t){return{id:t.attrs.SUBTITLES,textCodec:t.textCodec}})),m=l.default.parseMasterPlaylistMedia(o,u,"AUDIO",v),y=l.default.parseMasterPlaylistMedia(o,u,"SUBTITLES",p),E=l.default.parseMasterPlaylistMedia(o,u,"CLOSED-CAPTIONS");m.length&&(m.some((function(t){return!t.url}))||!f[0].audioCodec||f[0].attrs.AUDIO||(s.logger.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),m.unshift({type:"main",name:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new d.AttrList({}),bitrate:0,url:""}))),a.trigger(n.Events.MANIFEST_LOADED,{levels:f,audioTracks:m,subtitles:y,captions:E,url:u,stats:e,networkDetails:i,sessionData:g})}else this.handleManifestParsingError(t,r,"no level found in manifest",i)},e.handleTrackOrLevelPlaylist=function(t,e,r,s){var o=this.hls,h=r.id,f=r.level,g=r.type,v=c(t,r),p=Object(i.isFiniteNumber)(h)?h:0,m=Object(i.isFiniteNumber)(f)?f:p,y=function(t){switch(t.type){case u.PlaylistContextType.AUDIO_TRACK:return u.PlaylistLevelType.AUDIO;case u.PlaylistContextType.SUBTITLE_TRACK:return u.PlaylistLevelType.SUBTITLE;default:return u.PlaylistLevelType.MAIN}}(r),E=l.default.parseLevelPlaylist(t.data,v,m,y,p);if(E.fragments.length){if(g===u.PlaylistContextType.MANIFEST){var T={attrs:new d.AttrList({}),bitrate:0,details:E,name:"",url:v};o.trigger(n.Events.MANIFEST_LOADED,{levels:[T],audioTracks:[],url:v,stats:e,networkDetails:s,sessionData:null})}if(e.parsing.end=performance.now(),E.needSidxRanges){var S,b=null===(S=E.fragments[0].initSegment)||void 0===S?void 0:S.url;this.load({url:b,isSidxRequest:!0,type:g,level:f,levelDetails:E,id:h,groupId:null,rangeStart:0,rangeEnd:2048,responseType:"arraybuffer",deliveryDirectives:null})}else r.levelDetails=E,this.handlePlaylistLoaded(t,e,r,s)}else o.trigger(n.Events.ERROR,{type:a.ErrorTypes.NETWORK_ERROR,details:a.ErrorDetails.LEVEL_EMPTY_ERROR,fatal:!1,url:v,reason:"no fragments found in level",level:"number"==typeof r.level?r.level:void 0})},e.handleSidxRequest=function(t,e){var r=new Uint8Array(t.data),i=Object(o.findBox)(r,["sidx"])[0];if(i){var n=Object(o.parseSegmentIndex)(i);if(n){var a=n.references,s=e.levelDetails;a.forEach((function(t,e){var i=t.info,n=s.fragments[e];if(0===n.byteRange.length&&n.setByteRange(String(1+i.end-i.start)+"@"+String(i.start)),n.initSegment){var a=Object(o.findBox)(r,["moov"])[0],l=a?a.length:null;n.initSegment.setByteRange(String(l)+"@0")}}))}}},e.handleManifestParsingError=function(t,e,r,i){this.hls.trigger(n.Events.ERROR,{type:a.ErrorTypes.NETWORK_ERROR,details:a.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:e.type===u.PlaylistContextType.MANIFEST,url:t.url,reason:r,response:t,context:e,networkDetails:i})},e.handleNetworkError=function(t,e,r,i){void 0===r&&(r=!1),s.logger.warn("[playlist-loader]: A network "+(r?"timeout":"error")+" occurred while loading "+t.type+" level: "+t.level+" id: "+t.id+' group-id: "'+t.groupId+'"');var o=a.ErrorDetails.UNKNOWN,l=!1,d=this.getInternalLoader(t);switch(t.type){case u.PlaylistContextType.MANIFEST:o=r?a.ErrorDetails.MANIFEST_LOAD_TIMEOUT:a.ErrorDetails.MANIFEST_LOAD_ERROR,l=!0;break;case u.PlaylistContextType.LEVEL:o=r?a.ErrorDetails.LEVEL_LOAD_TIMEOUT:a.ErrorDetails.LEVEL_LOAD_ERROR,l=!1;break;case u.PlaylistContextType.AUDIO_TRACK:o=r?a.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:a.ErrorDetails.AUDIO_TRACK_LOAD_ERROR,l=!1;break;case u.PlaylistContextType.SUBTITLE_TRACK:o=r?a.ErrorDetails.SUBTITLE_TRACK_LOAD_TIMEOUT:a.ErrorDetails.SUBTITLE_LOAD_ERROR,l=!1}d&&this.resetInternalLoader(t.type);var c={type:a.ErrorTypes.NETWORK_ERROR,details:o,fatal:l,url:t.url,loader:d,context:t,networkDetails:e};i&&(c.response=i),this.hls.trigger(n.Events.ERROR,c)},e.handlePlaylistLoaded=function(t,e,r,i){var a=r.type,s=r.level,o=r.id,l=r.groupId,d=r.loader,c=r.levelDetails,h=r.deliveryDirectives;if(null!=c&&c.targetduration){if(d)switch(c.live&&(d.getCacheAge&&(c.ageHeader=d.getCacheAge()||0),d.getCacheAge&&!isNaN(c.ageHeader)||(c.ageHeader=0)),a){case u.PlaylistContextType.MANIFEST:case u.PlaylistContextType.LEVEL:this.hls.trigger(n.Events.LEVEL_LOADED,{details:c,level:s||0,id:o||0,stats:e,networkDetails:i,deliveryDirectives:h});break;case u.PlaylistContextType.AUDIO_TRACK:this.hls.trigger(n.Events.AUDIO_TRACK_LOADED,{details:c,id:o||0,groupId:l||"",stats:e,networkDetails:i,deliveryDirectives:h});break;case u.PlaylistContextType.SUBTITLE_TRACK:this.hls.trigger(n.Events.SUBTITLE_TRACK_LOADED,{details:c,id:o||0,groupId:l||"",stats:e,networkDetails:i,deliveryDirectives:h})}}else this.handleManifestParsingError(t,r,"invalid target duration",i)},t}();e.default=h},"./src/polyfills/number.ts":
234
234
  /*!*********************************!*\
235
235
  !*** ./src/polyfills/number.ts ***!
236
236
  \*********************************/
@@ -242,15 +242,15 @@
242
242
  /*!************************************!*\
243
243
  !*** ./src/remux/mp4-generator.ts ***!
244
244
  \************************************/
245
- /*! exports provided: default */function(t,e,r){r.r(e);var i=Math.pow(2,32)-1,n=function(){function t(){}return t.init=function(){var e;for(e in t.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],mvex:[],mvhd:[],pasp:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},t.types)t.types.hasOwnProperty(e)&&(t.types[e]=[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]);var r=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),i=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);t.HDLR_TYPES={video:r,audio:i};var n=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),a=new Uint8Array([0,0,0,0,0,0,0,0]);t.STTS=t.STSC=t.STCO=a,t.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),t.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),t.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),t.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);var s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);t.FTYP=t.box(t.types.ftyp,s,l,s,o),t.DINF=t.box(t.types.dinf,t.box(t.types.dref,n))},t.box=function(t){for(var e=8,r=arguments.length,i=new Array(r>1?r-1:0),n=1;n<r;n++)i[n-1]=arguments[n];for(var a=i.length,s=a;a--;)e+=i[a].byteLength;var o=new Uint8Array(e);for(o[0]=e>>24&255,o[1]=e>>16&255,o[2]=e>>8&255,o[3]=255&e,o.set(t,4),a=0,e=8;a<s;a++)o.set(i[a],e),e+=i[a].byteLength;return o},t.hdlr=function(e){return t.box(t.types.hdlr,t.HDLR_TYPES[e])},t.mdat=function(e){return t.box(t.types.mdat,e)},t.mdhd=function(e,r){r*=e;var n=Math.floor(r/(i+1)),a=Math.floor(r%(i+1));return t.box(t.types.mdhd,new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,n>>24,n>>16&255,n>>8&255,255&n,a>>24,a>>16&255,a>>8&255,255&a,85,196,0,0]))},t.mdia=function(e){return t.box(t.types.mdia,t.mdhd(e.timescale,e.duration),t.hdlr(e.type),t.minf(e))},t.mfhd=function(e){return t.box(t.types.mfhd,new Uint8Array([0,0,0,0,e>>24,e>>16&255,e>>8&255,255&e]))},t.minf=function(e){return"audio"===e.type?t.box(t.types.minf,t.box(t.types.smhd,t.SMHD),t.DINF,t.stbl(e)):t.box(t.types.minf,t.box(t.types.vmhd,t.VMHD),t.DINF,t.stbl(e))},t.moof=function(e,r,i){return t.box(t.types.moof,t.mfhd(e),t.traf(i,r))},t.moov=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trak(e[r]);return t.box.apply(null,[t.types.moov,t.mvhd(e[0].timescale,e[0].duration)].concat(i).concat(t.mvex(e)))},t.mvex=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trex(e[r]);return t.box.apply(null,[t.types.mvex].concat(i))},t.mvhd=function(e,r){r*=e;var n=Math.floor(r/(i+1)),a=Math.floor(r%(i+1)),s=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,n>>24,n>>16&255,n>>8&255,255&n,a>>24,a>>16&255,a>>8&255,255&a,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return t.box(t.types.mvhd,s)},t.sdtp=function(e){var r,i,n=e.samples||[],a=new Uint8Array(4+n.length);for(r=0;r<n.length;r++)i=n[r].flags,a[r+4]=i.dependsOn<<4|i.isDependedOn<<2|i.hasRedundancy;return t.box(t.types.sdtp,a)},t.stbl=function(e){return t.box(t.types.stbl,t.stsd(e),t.box(t.types.stts,t.STTS),t.box(t.types.stsc,t.STSC),t.box(t.types.stsz,t.STSZ),t.box(t.types.stco,t.STCO))},t.avc1=function(e){var r,i,n,a=[],s=[];for(r=0;r<e.sps.length;r++)n=(i=e.sps[r]).byteLength,a.push(n>>>8&255),a.push(255&n),a=a.concat(Array.prototype.slice.call(i));for(r=0;r<e.pps.length;r++)n=(i=e.pps[r]).byteLength,s.push(n>>>8&255),s.push(255&n),s=s.concat(Array.prototype.slice.call(i));var o=t.box(t.types.avcC,new Uint8Array([1,a[3],a[4],a[5],255,224|e.sps.length].concat(a).concat([e.pps.length]).concat(s))),l=e.width,u=e.height,d=e.pixelRatio[0],c=e.pixelRatio[1];return t.box(t.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,l>>8&255,255&l,u>>8&255,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,t.box(t.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),t.box(t.types.pasp,new Uint8Array([d>>24,d>>16&255,d>>8&255,255&d,c>>24,c>>16&255,c>>8&255,255&c])))},t.esds=function(t){var e=t.config.length;return new Uint8Array([0,0,0,0,3,23+e,0,1,0,4,15+e,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([e]).concat(t.config).concat([6,1,2]))},t.mp4a=function(e){var r=e.samplerate;return t.box(t.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),t.box(t.types.esds,t.esds(e)))},t.mp3=function(e){var r=e.samplerate;return t.box(t.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]))},t.stsd=function(e){return"audio"===e.type?"mp3"===e.segmentCodec&&"mp3"===e.codec?t.box(t.types.stsd,t.STSD,t.mp3(e)):t.box(t.types.stsd,t.STSD,t.mp4a(e)):t.box(t.types.stsd,t.STSD,t.avc1(e))},t.tkhd=function(e){var r=e.id,n=e.duration*e.timescale,a=e.width,s=e.height,o=Math.floor(n/(i+1)),l=Math.floor(n%(i+1));return t.box(t.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,o>>24,o>>16&255,o>>8&255,255&o,l>>24,l>>16&255,l>>8&255,255&l,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,a>>8&255,255&a,0,0,s>>8&255,255&s,0,0]))},t.traf=function(e,r){var n=t.sdtp(e),a=e.id,s=Math.floor(r/(i+1)),o=Math.floor(r%(i+1));return t.box(t.types.traf,t.box(t.types.tfhd,new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a])),t.box(t.types.tfdt,new Uint8Array([1,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o])),t.trun(e,n.length+16+20+8+16+8+8),n)},t.trak=function(e){return e.duration=e.duration||4294967295,t.box(t.types.trak,t.tkhd(e),t.mdia(e))},t.trex=function(e){var r=e.id;return t.box(t.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},t.trun=function(e,r){var i,n,a,s,o,l,u=e.samples||[],d=u.length,c=12+16*d,h=new Uint8Array(c);for(r+=8+c,h.set([0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i<d;i++)a=(n=u[i]).duration,s=n.size,o=n.flags,l=n.cts,h.set([a>>>24&255,a>>>16&255,a>>>8&255,255&a,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return t.box(t.types.trun,h)},t.initSegment=function(e){t.types||t.init();var r=t.moov(e),i=new Uint8Array(t.FTYP.byteLength+r.byteLength);return i.set(t.FTYP),i.set(r,t.FTYP.byteLength),i},t}();n.types=void 0,n.HDLR_TYPES=void 0,n.STTS=void 0,n.STSC=void 0,n.STCO=void 0,n.STSZ=void 0,n.VMHD=void 0,n.SMHD=void 0,n.STSD=void 0,n.FTYP=void 0,n.DINF=void 0,e.default=n},"./src/remux/mp4-remuxer.ts":
245
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=Math.pow(2,32)-1,n=function(){function t(){}return t.init=function(){var e;for(e in t.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],mvex:[],mvhd:[],pasp:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},t.types)t.types.hasOwnProperty(e)&&(t.types[e]=[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]);var r=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),i=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);t.HDLR_TYPES={video:r,audio:i};var n=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),a=new Uint8Array([0,0,0,0,0,0,0,0]);t.STTS=t.STSC=t.STCO=a,t.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),t.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),t.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),t.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);var s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);t.FTYP=t.box(t.types.ftyp,s,l,s,o),t.DINF=t.box(t.types.dinf,t.box(t.types.dref,n))},t.box=function(t){for(var e=8,r=arguments.length,i=new Array(r>1?r-1:0),n=1;n<r;n++)i[n-1]=arguments[n];for(var a=i.length,s=a;a--;)e+=i[a].byteLength;var o=new Uint8Array(e);for(o[0]=e>>24&255,o[1]=e>>16&255,o[2]=e>>8&255,o[3]=255&e,o.set(t,4),a=0,e=8;a<s;a++)o.set(i[a],e),e+=i[a].byteLength;return o},t.hdlr=function(e){return t.box(t.types.hdlr,t.HDLR_TYPES[e])},t.mdat=function(e){return t.box(t.types.mdat,e)},t.mdhd=function(e,r){r*=e;var n=Math.floor(r/(i+1)),a=Math.floor(r%(i+1));return t.box(t.types.mdhd,new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,n>>24,n>>16&255,n>>8&255,255&n,a>>24,a>>16&255,a>>8&255,255&a,85,196,0,0]))},t.mdia=function(e){return t.box(t.types.mdia,t.mdhd(e.timescale,e.duration),t.hdlr(e.type),t.minf(e))},t.mfhd=function(e){return t.box(t.types.mfhd,new Uint8Array([0,0,0,0,e>>24,e>>16&255,e>>8&255,255&e]))},t.minf=function(e){return"audio"===e.type?t.box(t.types.minf,t.box(t.types.smhd,t.SMHD),t.DINF,t.stbl(e)):t.box(t.types.minf,t.box(t.types.vmhd,t.VMHD),t.DINF,t.stbl(e))},t.moof=function(e,r,i){return t.box(t.types.moof,t.mfhd(e),t.traf(i,r))},t.moov=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trak(e[r]);return t.box.apply(null,[t.types.moov,t.mvhd(e[0].timescale,e[0].duration)].concat(i).concat(t.mvex(e)))},t.mvex=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trex(e[r]);return t.box.apply(null,[t.types.mvex].concat(i))},t.mvhd=function(e,r){r*=e;var n=Math.floor(r/(i+1)),a=Math.floor(r%(i+1)),s=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,n>>24,n>>16&255,n>>8&255,255&n,a>>24,a>>16&255,a>>8&255,255&a,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return t.box(t.types.mvhd,s)},t.sdtp=function(e){var r,i,n=e.samples||[],a=new Uint8Array(4+n.length);for(r=0;r<n.length;r++)i=n[r].flags,a[r+4]=i.dependsOn<<4|i.isDependedOn<<2|i.hasRedundancy;return t.box(t.types.sdtp,a)},t.stbl=function(e){return t.box(t.types.stbl,t.stsd(e),t.box(t.types.stts,t.STTS),t.box(t.types.stsc,t.STSC),t.box(t.types.stsz,t.STSZ),t.box(t.types.stco,t.STCO))},t.avc1=function(e){var r,i,n,a=[],s=[];for(r=0;r<e.sps.length;r++)n=(i=e.sps[r]).byteLength,a.push(n>>>8&255),a.push(255&n),a=a.concat(Array.prototype.slice.call(i));for(r=0;r<e.pps.length;r++)n=(i=e.pps[r]).byteLength,s.push(n>>>8&255),s.push(255&n),s=s.concat(Array.prototype.slice.call(i));var o=t.box(t.types.avcC,new Uint8Array([1,a[3],a[4],a[5],255,224|e.sps.length].concat(a).concat([e.pps.length]).concat(s))),l=e.width,u=e.height,d=e.pixelRatio[0],c=e.pixelRatio[1];return t.box(t.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,l>>8&255,255&l,u>>8&255,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,t.box(t.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),t.box(t.types.pasp,new Uint8Array([d>>24,d>>16&255,d>>8&255,255&d,c>>24,c>>16&255,c>>8&255,255&c])))},t.esds=function(t){var e=t.config.length;return new Uint8Array([0,0,0,0,3,23+e,0,1,0,4,15+e,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([e]).concat(t.config).concat([6,1,2]))},t.mp4a=function(e){var r=e.samplerate;return t.box(t.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),t.box(t.types.esds,t.esds(e)))},t.mp3=function(e){var r=e.samplerate;return t.box(t.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]))},t.stsd=function(e){return"audio"===e.type?"mp3"===e.segmentCodec&&"mp3"===e.codec?t.box(t.types.stsd,t.STSD,t.mp3(e)):t.box(t.types.stsd,t.STSD,t.mp4a(e)):t.box(t.types.stsd,t.STSD,t.avc1(e))},t.tkhd=function(e){var r=e.id,n=e.duration*e.timescale,a=e.width,s=e.height,o=Math.floor(n/(i+1)),l=Math.floor(n%(i+1));return t.box(t.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,o>>24,o>>16&255,o>>8&255,255&o,l>>24,l>>16&255,l>>8&255,255&l,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,a>>8&255,255&a,0,0,s>>8&255,255&s,0,0]))},t.traf=function(e,r){var n=t.sdtp(e),a=e.id,s=Math.floor(r/(i+1)),o=Math.floor(r%(i+1));return t.box(t.types.traf,t.box(t.types.tfhd,new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a])),t.box(t.types.tfdt,new Uint8Array([1,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o])),t.trun(e,n.length+16+20+8+16+8+8),n)},t.trak=function(e){return e.duration=e.duration||4294967295,t.box(t.types.trak,t.tkhd(e),t.mdia(e))},t.trex=function(e){var r=e.id;return t.box(t.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},t.trun=function(e,r){var i,n,a,s,o,l,u=e.samples||[],d=u.length,c=12+16*d,h=new Uint8Array(c);for(r+=8+c,h.set(["video"===e.type?1:0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i<d;i++)a=(n=u[i]).duration,s=n.size,o=n.flags,l=n.cts,h.set([a>>>24&255,a>>>16&255,a>>>8&255,255&a,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return t.box(t.types.trun,h)},t.initSegment=function(e){t.types||t.init();var r=t.moov(e),i=new Uint8Array(t.FTYP.byteLength+r.byteLength);return i.set(t.FTYP),i.set(r,t.FTYP.byteLength),i},t}();n.types=void 0,n.HDLR_TYPES=void 0,n.STTS=void 0,n.STSC=void 0,n.STCO=void 0,n.STSZ=void 0,n.VMHD=void 0,n.SMHD=void 0,n.STSD=void 0,n.FTYP=void 0,n.DINF=void 0,e.default=n},"./src/remux/mp4-remuxer.ts":
246
246
  /*!**********************************!*\
247
247
  !*** ./src/remux/mp4-remuxer.ts ***!
248
248
  \**********************************/
249
- /*! exports provided: default, normalizePts, flushTextTrackMetadataCueSamples, flushTextTrackUserdataCueSamples */function(t,e,r){r.r(e),r.d(e,"default",(function(){return v})),r.d(e,"normalizePts",(function(){return p})),r.d(e,"flushTextTrackMetadataCueSamples",(function(){return m})),r.d(e,"flushTextTrackUserdataCueSamples",(function(){return y}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./aac-helper */"./src/remux/aac-helper.ts"),a=r(/*! ./mp4-generator */"./src/remux/mp4-generator.ts"),s=r(/*! ../events */"./src/events.ts"),o=r(/*! ../errors */"./src/errors.ts"),l=r(/*! ../utils/logger */"./src/utils/logger.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../utils/timescale-conversion */"./src/utils/timescale-conversion.ts");function c(){return(c=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}var h=null,f=null,g=!1,v=function(){function t(t,e,r,i){if(this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=void 0,this._initDTS=void 0,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.observer=t,this.config=e,this.typeSupported=r,this.ISGenerated=!1,null===h){var n=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);h=n?parseInt(n[1]):0}if(null===f){var a=navigator.userAgent.match(/Safari\/(\d+)/i);f=a?parseInt(a[1]):0}g=!(h&&h>=75||f&&f>=600)}var e=t.prototype;return e.destroy=function(){},e.resetTimeStamp=function(t){l.logger.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=t},e.resetNextTimestamp=function(){l.logger.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},e.resetInitSegment=function(){l.logger.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1},e.getVideoStartPts=function(t){var e=!1,r=t.reduce((function(t,r){var i=r.pts-t;return i<-4294967296?(e=!0,p(t,r.pts)):i>0?t:r.pts}),t[0].pts);return e&&l.logger.debug("PTS rollover detected"),r},e.remux=function(t,e,r,i,n,a,s,o){var d,c,h,f,g,v,E=n,T=n,S=t.pid>-1,b=e.pid>-1,L=e.samples.length,D=t.samples.length>0,A=s&&L>0||L>1;if((!S||D)&&(!b||A)||this.ISGenerated||s){this.ISGenerated||(h=this.generateIS(t,e,n));var R,k=this.isVideoContiguous,I=-1;if(A&&(I=function(t){for(var e=0;e<t.length;e++)if(t[e].key)return e;return-1}(e.samples),!k&&this.config.forceKeyFrameOnDiscontinuity))if(v=!0,I>0){l.logger.warn("[mp4-remuxer]: Dropped "+I+" out of "+L+" video samples due to a missing keyframe");var _=this.getVideoStartPts(e.samples);e.samples=e.samples.slice(I),e.dropped+=I,R=T+=(e.samples[0].pts-_)/e.inputTimeScale}else-1===I&&(l.logger.warn("[mp4-remuxer]: No keyframe found out of "+L+" video samples"),v=!1);if(this.ISGenerated){if(D&&A){var O=this.getVideoStartPts(e.samples),C=(p(t.samples[0].pts,O)-O)/e.inputTimeScale;E+=Math.max(0,C),T+=Math.max(0,-C)}if(D){if(t.samplerate||(l.logger.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),h=this.generateIS(t,e,n)),c=this.remuxAudio(t,E,this.isAudioContiguous,a,b||A||o===u.PlaylistLevelType.AUDIO?T:void 0),A){var w=c?c.endPTS-c.startPTS:0;e.inputTimeScale||(l.logger.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),h=this.generateIS(t,e,n)),d=this.remuxVideo(e,T,k,w)}}else A&&(d=this.remuxVideo(e,T,k,0));d&&(d.firstKeyFrame=I,d.independent=-1!==I,d.firstKeyFramePTS=R)}}return this.ISGenerated&&(r.samples.length&&(g=m(r,n,this._initPTS,this._initDTS)),i.samples.length&&(f=y(i,n,this._initPTS))),{audio:c,video:d,initSegment:h,independent:v,text:f,id3:g}},e.generateIS=function(t,e,r){var n,s,o,l=t.samples,u=e.samples,d=this.typeSupported,c={},h=!Object(i.isFiniteNumber)(this._initPTS),f="audio/mp4";if(h&&(n=s=1/0),t.config&&l.length){switch(t.timescale=t.samplerate,t.segmentCodec){case"mp3":d.mpeg?(f="audio/mpeg",t.codec=""):d.mp3&&(t.codec="mp3")}c.audio={id:"audio",container:f,codec:t.codec,initSegment:"mp3"===t.segmentCodec&&d.mpeg?new Uint8Array(0):a.default.initSegment([t]),metadata:{channelCount:t.channelCount}},h&&(o=t.inputTimeScale,n=s=l[0].pts-Math.round(o*r))}if(e.sps&&e.pps&&u.length&&(e.timescale=e.inputTimeScale,c.video={id:"main",container:"video/mp4",codec:e.codec,initSegment:a.default.initSegment([e]),metadata:{width:e.width,height:e.height}},h)){o=e.inputTimeScale;var g=this.getVideoStartPts(u),v=Math.round(o*r);s=Math.min(s,p(u[0].dts,g)-v),n=Math.min(n,g-v)}if(Object.keys(c).length)return this.ISGenerated=!0,h&&(this._initPTS=n,this._initDTS=s),{tracks:c,initPTS:n,timescale:o}},e.remuxVideo=function(t,e,r,i){var n,u,f=t.inputTimeScale,v=t.samples,m=[],y=v.length,T=this._initPTS,S=this.nextAvcDts,b=8,L=this.videoSampleDuration,D=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,R=0,k=!1;r&&null!==S||(S=e*f-(v[0].pts-p(v[0].dts,v[0].pts)));for(var I=0;I<y;I++){var _=v[I];_.pts=p(_.pts-T,S),_.dts=p(_.dts-T,S),_.dts>_.pts&&(R=Math.max(Math.min(R,_.pts-_.dts),-18e3)),_.dts<v[I>0?I-1:I].dts&&(k=!0)}k&&v.sort((function(t,e){var r=t.dts-e.dts,i=t.pts-e.pts;return r||i})),n=v[0].dts;var O=(u=v[v.length-1].dts)-n,C=O?Math.round(O/(y-1)):L||t.inputTimeScale/30;if(R<0){if(R<-2*C){l.logger.warn("PTS < DTS detected in video samples, offsetting DTS from PTS by "+Object(d.toMsFromMpegTsClock)(-C,!0)+" ms");for(var w=R,x=0;x<y;x++)v[x].dts=w=Math.max(w,v[x].pts-C),v[x].pts=Math.max(w,v[x].pts)}else{l.logger.warn("PTS < DTS detected in video samples, shifting DTS by "+Object(d.toMsFromMpegTsClock)(R,!0)+" ms to overcome this issue");for(var P=0;P<y;P++)v[P].dts=v[P].dts+R}n=v[0].dts}if(r){var F=n-S,M=F>C;if(M||F<-1){M?l.logger.warn("AVC: "+Object(d.toMsFromMpegTsClock)(F,!0)+" ms ("+F+"dts) hole between fragments detected, filling it"):l.logger.warn("AVC: "+Object(d.toMsFromMpegTsClock)(-F,!0)+" ms ("+F+"dts) overlapping between fragments detected"),n=S;var N=v[0].pts-F;v[0].dts=n,v[0].pts=N,l.logger.log("Video: First PTS/DTS adjusted: "+Object(d.toMsFromMpegTsClock)(N,!0)+"/"+Object(d.toMsFromMpegTsClock)(n,!0)+", delta: "+Object(d.toMsFromMpegTsClock)(F,!0)+" ms")}}g&&(n=Math.max(0,n));for(var U=0,B=0,G=0;G<y;G++){for(var j=v[G],K=j.units,H=K.length,V=0,W=0;W<H;W++)V+=K[W].data.length;B+=V,U+=H,j.length=V,j.dts=Math.max(j.dts,n),j.pts=Math.max(j.pts,j.dts,0),D=Math.min(j.pts,D),A=Math.max(j.pts,A)}u=v[y-1].dts;var Y,q=B+4*U+8;try{Y=new Uint8Array(q)}catch(t){return void this.observer.emit(s.Events.ERROR,s.Events.ERROR,{type:o.ErrorTypes.MUX_ERROR,details:o.ErrorDetails.REMUX_ALLOC_ERROR,fatal:!1,bytes:q,reason:"fail allocating video mdat "+q})}var z=new DataView(Y.buffer);z.setUint32(0,q),Y.set(a.default.types.mdat,4);for(var X=!1,Q=0;Q<y;Q++){for(var $=v[Q],J=$.units,Z=0,tt=0,et=J.length;tt<et;tt++){var rt=J[tt],it=rt.data,nt=rt.data.byteLength;z.setUint32(b,nt),b+=4,Y.set(it,b),b+=nt,Z+=4+nt}if(Q<y-1)L=v[Q+1].dts-$.dts;else{var at=this.config,st=Q>0?$.dts-v[Q-1].dts:C;if(at.stretchShortVideoTrack&&null!==this.nextAudioPts){var ot=Math.floor(at.maxBufferHole*f),lt=(i?D+i*f:this.nextAudioPts)-$.pts;lt>ot?((L=lt-st)<0?L=st:X=!0,l.logger.log("[mp4-remuxer]: It is approximately "+lt/90+" ms to the next segment; using duration "+L/90+" ms for the last video frame.")):L=st}else L=st}var ut=Math.round($.pts-$.dts);m.push(new E($.key,L,Z,ut))}if(m.length&&h&&h<70){var dt=m[0].flags;dt.dependsOn=2,dt.isNonSync=0}console.assert(null!==L,"mp4SampleDuration must be computed"),L=X||!L?C:L,this.nextAvcDts=S=u+L,this.videoSampleDuration=L,this.isVideoContiguous=!0;var ct={data1:a.default.moof(t.sequenceNumber++,n,c({},t,{samples:m})),data2:Y,startPTS:D/f,endPTS:(A+L)/f,startDTS:n/f,endDTS:S/f,type:"video",hasAudio:!1,hasVideo:!0,nb:m.length,dropped:t.dropped};return t.samples=[],t.dropped=0,console.assert(Y.length,"MDAT length must not be zero"),ct},e.remuxAudio=function(t,e,r,i,u){var d=t.inputTimeScale,h=d/(t.samplerate?t.samplerate:d),f="aac"===t.segmentCodec?1024:1152,g=f*h,v=this._initPTS,m="mp3"===t.segmentCodec&&this.typeSupported.mpeg,y=[],T=void 0!==u,S=t.samples,b=m?0:8,L=this.nextAudioPts||-1,D=e*d;if(this.isAudioContiguous=r=r||S.length&&L>0&&(i&&Math.abs(D-L)<9e3||Math.abs(p(S[0].pts-v,D)-L)<20*g),S.forEach((function(t){t.pts=p(t.pts-v,D)})),!r||L<0){if(!(S=S.filter((function(t){return t.pts>=0}))).length)return;L=0===u?0:i&&!T?Math.max(0,D):S[0].pts}if("aac"===t.segmentCodec)for(var A=this.config.maxAudioFramesDrift,R=0,k=L;R<S.length;R++){var I=S[R],_=I.pts,O=_-k,C=Math.abs(1e3*O/d);if(O<=-A*g&&T)0===R&&(l.logger.warn("Audio frame @ "+(_/d).toFixed(3)+"s overlaps nextAudioPts by "+Math.round(1e3*O/d)+" ms."),this.nextAudioPts=L=k=_);else if(O>=A*g&&C<1e4&&T){var w=Math.round(O/g);(k=_-w*g)<0&&(w--,k+=g),0===R&&(this.nextAudioPts=L=k),l.logger.warn("[mp4-remuxer]: Injecting "+w+" audio frame @ "+(k/d).toFixed(3)+"s due to "+Math.round(1e3*O/d)+" ms gap.");for(var x=0;x<w;x++){var P=Math.max(k,0),F=n.default.getSilentFrame(t.manifestCodec||t.codec,t.channelCount);F||(l.logger.log("[mp4-remuxer]: Unable to get silent frame for given audio codec; duplicating last frame instead."),F=I.unit.subarray()),S.splice(R,0,{unit:F,pts:P}),k+=g,R++}}I.pts=k,k+=g}for(var M,N=null,U=null,B=0,G=S.length;G--;)B+=S[G].unit.byteLength;for(var j=0,K=S.length;j<K;j++){var H=S[j],V=H.unit,W=H.pts;if(null!==U)y[j-1].duration=Math.round((W-U)/h);else{if(r&&"aac"===t.segmentCodec&&(W=L),N=W,!(B>0))return;B+=b;try{M=new Uint8Array(B)}catch(t){return void this.observer.emit(s.Events.ERROR,s.Events.ERROR,{type:o.ErrorTypes.MUX_ERROR,details:o.ErrorDetails.REMUX_ALLOC_ERROR,fatal:!1,bytes:B,reason:"fail allocating audio mdat "+B})}m||(new DataView(M.buffer).setUint32(0,B),M.set(a.default.types.mdat,4))}M.set(V,b);var Y=V.byteLength;b+=Y,y.push(new E(!0,f,Y,0)),U=W}var q=y.length;if(q){var z=y[y.length-1];this.nextAudioPts=L=U+h*z.duration;var X=m?new Uint8Array(0):a.default.moof(t.sequenceNumber++,N/h,c({},t,{samples:y}));t.samples=[];var Q=N/d,$=L/d,J={data1:X,data2:M,startPTS:Q,endPTS:$,startDTS:Q,endDTS:$,type:"audio",hasAudio:!0,hasVideo:!1,nb:q};return this.isAudioContiguous=!0,console.assert(M.length,"MDAT length must not be zero"),J}},e.remuxEmptyAudio=function(t,e,r,i){var a=t.inputTimeScale,s=a/(t.samplerate?t.samplerate:a),o=this.nextAudioPts,u=(null!==o?o:i.startDTS*a)+this._initDTS,d=i.endDTS*a+this._initDTS,c=1024*s,h=Math.ceil((d-u)/c),f=n.default.getSilentFrame(t.manifestCodec||t.codec,t.channelCount);if(l.logger.warn("[mp4-remuxer]: remux empty Audio"),f){for(var g=[],v=0;v<h;v++){var p=u+v*c;g.push({unit:f,pts:p,dts:p})}return t.samples=g,this.remuxAudio(t,e,r,!1)}l.logger.trace("[mp4-remuxer]: Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec")},t}();function p(t,e){var r;if(null===e)return t;for(r=e<t?-8589934592:8589934592;Math.abs(t-e)>4294967296;)t+=r;return t}function m(t,e,r,i){var n=t.samples.length;if(n){for(var a=t.inputTimeScale,s=0;s<n;s++){var o=t.samples[s];o.pts=p(o.pts-r,e*a)/a,o.dts=p(o.dts-i,e*a)/a}var l=t.samples;return t.samples=[],{samples:l}}}function y(t,e,r){var i=t.samples.length;if(i){for(var n=t.inputTimeScale,a=0;a<i;a++){var s=t.samples[a];s.pts=p(s.pts-r,e*n)/n}t.samples.sort((function(t,e){return t.pts-e.pts}));var o=t.samples;return t.samples=[],{samples:o}}}var E=function(t,e,r,i){this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=e,this.size=r,this.cts=i,this.flags=new T(t)},T=function(t){this.isLeading=0,this.isDependedOn=0,this.hasRedundancy=0,this.degradPrio=0,this.dependsOn=1,this.isNonSync=1,this.dependsOn=t?2:1,this.isNonSync=t?0:1}},"./src/remux/passthrough-remuxer.ts":
249
+ /*! exports provided: default, normalizePts, flushTextTrackMetadataCueSamples, flushTextTrackUserdataCueSamples */function(t,e,r){r.r(e),r.d(e,"default",(function(){return g})),r.d(e,"normalizePts",(function(){return v})),r.d(e,"flushTextTrackMetadataCueSamples",(function(){return p})),r.d(e,"flushTextTrackUserdataCueSamples",(function(){return m}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./aac-helper */"./src/remux/aac-helper.ts"),a=r(/*! ./mp4-generator */"./src/remux/mp4-generator.ts"),s=r(/*! ../events */"./src/events.ts"),o=r(/*! ../errors */"./src/errors.ts"),l=r(/*! ../utils/logger */"./src/utils/logger.ts"),u=r(/*! ../types/loader */"./src/types/loader.ts"),d=r(/*! ../utils/timescale-conversion */"./src/utils/timescale-conversion.ts");function c(){return(c=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}var h=null,f=null,g=function(){function t(t,e,r,i){if(this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=void 0,this._initDTS=void 0,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.observer=t,this.config=e,this.typeSupported=r,this.ISGenerated=!1,null===h){var n=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);h=n?parseInt(n[1]):0}if(null===f){var a=navigator.userAgent.match(/Safari\/(\d+)/i);f=a?parseInt(a[1]):0}}var e=t.prototype;return e.destroy=function(){},e.resetTimeStamp=function(t){l.logger.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=t},e.resetNextTimestamp=function(){l.logger.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},e.resetInitSegment=function(){l.logger.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1},e.getVideoStartPts=function(t){var e=!1,r=t.reduce((function(t,r){var i=r.pts-t;return i<-4294967296?(e=!0,v(t,r.pts)):i>0?t:r.pts}),t[0].pts);return e&&l.logger.debug("PTS rollover detected"),r},e.remux=function(t,e,r,i,n,a,s,o){var d,c,h,f,g,y,E=n,T=n,S=t.pid>-1,b=e.pid>-1,L=e.samples.length,D=t.samples.length>0,A=s&&L>0||L>1;if((!S||D)&&(!b||A)||this.ISGenerated||s){this.ISGenerated||(h=this.generateIS(t,e,n));var R,k=this.isVideoContiguous,I=-1;if(A&&(I=function(t){for(var e=0;e<t.length;e++)if(t[e].key)return e;return-1}(e.samples),!k&&this.config.forceKeyFrameOnDiscontinuity))if(y=!0,I>0){l.logger.warn("[mp4-remuxer]: Dropped "+I+" out of "+L+" video samples due to a missing keyframe");var _=this.getVideoStartPts(e.samples);e.samples=e.samples.slice(I),e.dropped+=I,R=T+=(e.samples[0].pts-_)/e.inputTimeScale}else-1===I&&(l.logger.warn("[mp4-remuxer]: No keyframe found out of "+L+" video samples"),y=!1);if(this.ISGenerated){if(D&&A){var C=this.getVideoStartPts(e.samples),O=(v(t.samples[0].pts,C)-C)/e.inputTimeScale;E+=Math.max(0,O),T+=Math.max(0,-O)}if(D){if(t.samplerate||(l.logger.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),h=this.generateIS(t,e,n)),c=this.remuxAudio(t,E,this.isAudioContiguous,a,b||A||o===u.PlaylistLevelType.AUDIO?T:void 0),A){var w=c?c.endPTS-c.startPTS:0;e.inputTimeScale||(l.logger.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),h=this.generateIS(t,e,n)),d=this.remuxVideo(e,T,k,w)}}else A&&(d=this.remuxVideo(e,T,k,0));d&&(d.firstKeyFrame=I,d.independent=-1!==I,d.firstKeyFramePTS=R)}}return this.ISGenerated&&(r.samples.length&&(g=p(r,n,this._initPTS,this._initDTS)),i.samples.length&&(f=m(i,n,this._initPTS))),{audio:c,video:d,initSegment:h,independent:y,text:f,id3:g}},e.generateIS=function(t,e,r){var n,s,o,l=t.samples,u=e.samples,d=this.typeSupported,c={},h=!Object(i.isFiniteNumber)(this._initPTS),f="audio/mp4";if(h&&(n=s=1/0),t.config&&l.length){switch(t.timescale=t.samplerate,t.segmentCodec){case"mp3":d.mpeg?(f="audio/mpeg",t.codec=""):d.mp3&&(t.codec="mp3")}c.audio={id:"audio",container:f,codec:t.codec,initSegment:"mp3"===t.segmentCodec&&d.mpeg?new Uint8Array(0):a.default.initSegment([t]),metadata:{channelCount:t.channelCount}},h&&(o=t.inputTimeScale,n=s=l[0].pts-Math.round(o*r))}if(e.sps&&e.pps&&u.length&&(e.timescale=e.inputTimeScale,c.video={id:"main",container:"video/mp4",codec:e.codec,initSegment:a.default.initSegment([e]),metadata:{width:e.width,height:e.height}},h)){o=e.inputTimeScale;var g=this.getVideoStartPts(u),p=Math.round(o*r);s=Math.min(s,v(u[0].dts,g)-p),n=Math.min(n,g-p)}if(Object.keys(c).length)return this.ISGenerated=!0,h&&(this._initPTS=n,this._initDTS=s),{tracks:c,initPTS:n,timescale:o}},e.remuxVideo=function(t,e,r,i){var n,u,g=t.inputTimeScale,p=t.samples,m=[],E=p.length,T=this._initPTS,S=this.nextAvcDts,b=8,L=this.videoSampleDuration,D=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,R=!1;r&&null!==S||(S=e*g-(p[0].pts-v(p[0].dts,p[0].pts)));for(var k=0;k<E;k++){var I=p[k];I.pts=v(I.pts-T,S),I.dts=v(I.dts-T,S),I.dts<p[k>0?k-1:k].dts&&(R=!0)}R&&p.sort((function(t,e){var r=t.dts-e.dts,i=t.pts-e.pts;return r||i})),n=p[0].dts;var _=(u=p[p.length-1].dts)-n,C=_?Math.round(_/(E-1)):L||t.inputTimeScale/30;if(r){var O=n-S,w=O>C;if(w||O<-1){w?l.logger.warn("AVC: "+Object(d.toMsFromMpegTsClock)(O,!0)+" ms ("+O+"dts) hole between fragments detected, filling it"):l.logger.warn("AVC: "+Object(d.toMsFromMpegTsClock)(-O,!0)+" ms ("+O+"dts) overlapping between fragments detected"),n=S;var x=p[0].pts-O;p[0].dts=n,p[0].pts=x,l.logger.log("Video: First PTS/DTS adjusted: "+Object(d.toMsFromMpegTsClock)(x,!0)+"/"+Object(d.toMsFromMpegTsClock)(n,!0)+", delta: "+Object(d.toMsFromMpegTsClock)(O,!0)+" ms")}}n=Math.max(0,n);for(var P=0,F=0,M=0;M<E;M++){for(var N=p[M],U=N.units,B=U.length,G=0,j=0;j<B;j++)G+=U[j].data.length;F+=G,P+=B,N.length=G,N.dts=Math.max(N.dts,n),D=Math.min(N.pts,D),A=Math.max(N.pts,A)}u=p[E-1].dts;var H,K=F+4*P+8;try{H=new Uint8Array(K)}catch(t){return void this.observer.emit(s.Events.ERROR,s.Events.ERROR,{type:o.ErrorTypes.MUX_ERROR,details:o.ErrorDetails.REMUX_ALLOC_ERROR,fatal:!1,bytes:K,reason:"fail allocating video mdat "+K})}var V=new DataView(H.buffer);V.setUint32(0,K),H.set(a.default.types.mdat,4);for(var W=!1,Y=Number.POSITIVE_INFINITY,q=Number.POSITIVE_INFINITY,z=Number.NEGATIVE_INFINITY,X=Number.NEGATIVE_INFINITY,Q=0;Q<E;Q++){for(var $=p[Q],J=$.units,Z=0,tt=0,et=J.length;tt<et;tt++){var rt=J[tt],it=rt.data,nt=rt.data.byteLength;V.setUint32(b,nt),b+=4,H.set(it,b),b+=nt,Z+=4+nt}var at=void 0;if(Q<E-1)L=p[Q+1].dts-$.dts,at=p[Q+1].pts-$.pts;else{var st=this.config,ot=Q>0?$.dts-p[Q-1].dts:C;if(at=Q>0?$.pts-p[Q-1].pts:C,st.stretchShortVideoTrack&&null!==this.nextAudioPts){var lt=Math.floor(st.maxBufferHole*g),ut=(i?D+i*g:this.nextAudioPts)-$.pts;ut>lt?((L=ut-ot)<0?L=ot:W=!0,l.logger.log("[mp4-remuxer]: It is approximately "+ut/90+" ms to the next segment; using duration "+L/90+" ms for the last video frame.")):L=ot}else L=ot}var dt=Math.round($.pts-$.dts);Y=Math.min(Y,L),z=Math.max(z,L),q=Math.min(q,at),X=Math.max(X,at),m.push(new y($.key,L,Z,dt))}if(m.length)if(h){if(h<70){var ct=m[0].flags;ct.dependsOn=2,ct.isNonSync=0}}else if(f&&X-q<z-Y&&C/z<.025&&0===m[0].cts){l.logger.warn("Found irregular gaps in sample duration. Using PTS instead of DTS to determine MP4 sample duration.");for(var ht=n,ft=0,gt=m.length;ft<gt;ft++){var vt=ht+m[ft].duration,pt=ht+m[ft].cts;if(ft<gt-1){var mt=vt+m[ft+1].cts;m[ft].duration=mt-pt}else m[ft].duration=ft?m[ft-1].duration:C;m[ft].cts=0,ht=vt}}console.assert(null!==L,"mp4SampleDuration must be computed"),L=W||!L?C:L,this.nextAvcDts=S=u+L,this.videoSampleDuration=L,this.isVideoContiguous=!0;var yt={data1:a.default.moof(t.sequenceNumber++,n,c({},t,{samples:m})),data2:H,startPTS:D/g,endPTS:(A+L)/g,startDTS:n/g,endDTS:S/g,type:"video",hasAudio:!1,hasVideo:!0,nb:m.length,dropped:t.dropped};return t.samples=[],t.dropped=0,console.assert(H.length,"MDAT length must not be zero"),yt},e.remuxAudio=function(t,e,r,i,u){var d=t.inputTimeScale,h=d/(t.samplerate?t.samplerate:d),f="aac"===t.segmentCodec?1024:1152,g=f*h,p=this._initPTS,m="mp3"===t.segmentCodec&&this.typeSupported.mpeg,E=[],T=void 0!==u,S=t.samples,b=m?0:8,L=this.nextAudioPts||-1,D=e*d;if(this.isAudioContiguous=r=r||S.length&&L>0&&(i&&Math.abs(D-L)<9e3||Math.abs(v(S[0].pts-p,D)-L)<20*g),S.forEach((function(t){t.pts=v(t.pts-p,D)})),!r||L<0){if(!(S=S.filter((function(t){return t.pts>=0}))).length)return;L=0===u?0:i&&!T?Math.max(0,D):S[0].pts}if("aac"===t.segmentCodec)for(var A=this.config.maxAudioFramesDrift,R=0,k=L;R<S.length;R++){var I=S[R],_=I.pts,C=_-k,O=Math.abs(1e3*C/d);if(C<=-A*g&&T)0===R&&(l.logger.warn("Audio frame @ "+(_/d).toFixed(3)+"s overlaps nextAudioPts by "+Math.round(1e3*C/d)+" ms."),this.nextAudioPts=L=k=_);else if(C>=A*g&&O<1e4&&T){var w=Math.round(C/g);(k=_-w*g)<0&&(w--,k+=g),0===R&&(this.nextAudioPts=L=k),l.logger.warn("[mp4-remuxer]: Injecting "+w+" audio frame @ "+(k/d).toFixed(3)+"s due to "+Math.round(1e3*C/d)+" ms gap.");for(var x=0;x<w;x++){var P=Math.max(k,0),F=n.default.getSilentFrame(t.manifestCodec||t.codec,t.channelCount);F||(l.logger.log("[mp4-remuxer]: Unable to get silent frame for given audio codec; duplicating last frame instead."),F=I.unit.subarray()),S.splice(R,0,{unit:F,pts:P}),k+=g,R++}}I.pts=k,k+=g}for(var M,N=null,U=null,B=0,G=S.length;G--;)B+=S[G].unit.byteLength;for(var j=0,H=S.length;j<H;j++){var K=S[j],V=K.unit,W=K.pts;if(null!==U)E[j-1].duration=Math.round((W-U)/h);else{if(r&&"aac"===t.segmentCodec&&(W=L),N=W,!(B>0))return;B+=b;try{M=new Uint8Array(B)}catch(t){return void this.observer.emit(s.Events.ERROR,s.Events.ERROR,{type:o.ErrorTypes.MUX_ERROR,details:o.ErrorDetails.REMUX_ALLOC_ERROR,fatal:!1,bytes:B,reason:"fail allocating audio mdat "+B})}m||(new DataView(M.buffer).setUint32(0,B),M.set(a.default.types.mdat,4))}M.set(V,b);var Y=V.byteLength;b+=Y,E.push(new y(!0,f,Y,0)),U=W}var q=E.length;if(q){var z=E[E.length-1];this.nextAudioPts=L=U+h*z.duration;var X=m?new Uint8Array(0):a.default.moof(t.sequenceNumber++,N/h,c({},t,{samples:E}));t.samples=[];var Q=N/d,$=L/d,J={data1:X,data2:M,startPTS:Q,endPTS:$,startDTS:Q,endDTS:$,type:"audio",hasAudio:!0,hasVideo:!1,nb:q};return this.isAudioContiguous=!0,console.assert(M.length,"MDAT length must not be zero"),J}},e.remuxEmptyAudio=function(t,e,r,i){var a=t.inputTimeScale,s=a/(t.samplerate?t.samplerate:a),o=this.nextAudioPts,u=(null!==o?o:i.startDTS*a)+this._initDTS,d=i.endDTS*a+this._initDTS,c=1024*s,h=Math.ceil((d-u)/c),f=n.default.getSilentFrame(t.manifestCodec||t.codec,t.channelCount);if(l.logger.warn("[mp4-remuxer]: remux empty Audio"),f){for(var g=[],v=0;v<h;v++){var p=u+v*c;g.push({unit:f,pts:p,dts:p})}return t.samples=g,this.remuxAudio(t,e,r,!1)}l.logger.trace("[mp4-remuxer]: Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec")},t}();function v(t,e){var r;if(null===e)return t;for(r=e<t?-8589934592:8589934592;Math.abs(t-e)>4294967296;)t+=r;return t}function p(t,e,r,i){var n=t.samples.length;if(n){for(var a=t.inputTimeScale,s=0;s<n;s++){var o=t.samples[s];o.pts=v(o.pts-r,e*a)/a,o.dts=v(o.dts-i,e*a)/a}var l=t.samples;return t.samples=[],{samples:l}}}function m(t,e,r){var i=t.samples.length;if(i){for(var n=t.inputTimeScale,a=0;a<i;a++){var s=t.samples[a];s.pts=v(s.pts-r,e*n)/n}t.samples.sort((function(t,e){return t.pts-e.pts}));var o=t.samples;return t.samples=[],{samples:o}}}var y=function(t,e,r,i){this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=e,this.size=r,this.cts=i,this.flags=new E(t)},E=function(t){this.isLeading=0,this.isDependedOn=0,this.hasRedundancy=0,this.degradPrio=0,this.dependsOn=1,this.isNonSync=1,this.dependsOn=t?2:1,this.isNonSync=t?0:1}},"./src/remux/passthrough-remuxer.ts":
250
250
  /*!******************************************!*\
251
251
  !*** ./src/remux/passthrough-remuxer.ts ***!
252
252
  \******************************************/
253
- /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./mp4-remuxer */"./src/remux/mp4-remuxer.ts"),a=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),s=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),o=r(/*! ../utils/logger */"./src/utils/logger.ts"),l=function(){function t(){this.emitInitSegment=!1,this.audioCodec=void 0,this.videoCodec=void 0,this.initData=void 0,this.initPTS=void 0,this.initTracks=void 0,this.lastEndDTS=null}var e=t.prototype;return e.destroy=function(){},e.resetTimeStamp=function(t){this.initPTS=t,this.lastEndDTS=null},e.resetNextTimestamp=function(){this.lastEndDTS=null},e.resetInitSegment=function(t,e,r){this.audioCodec=e,this.videoCodec=r,this.generateInitSegment(t),this.emitInitSegment=!0},e.generateInitSegment=function(t){var e=this.audioCodec,r=this.videoCodec;if(!t||!t.byteLength)return this.initTracks=void 0,void(this.initData=void 0);var i=this.initData=Object(a.parseInitSegment)(t);e||(e=d(i.audio,s.ElementaryStreamTypes.AUDIO)),r||(r=d(i.video,s.ElementaryStreamTypes.VIDEO));var n={};i.audio&&i.video?n.audiovideo={container:"video/mp4",codec:e+","+r,initSegment:t,id:"main"}:i.audio?n.audio={container:"audio/mp4",codec:e,initSegment:t,id:"audio"}:i.video?n.video={container:"video/mp4",codec:r,initSegment:t,id:"main"}:o.logger.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=n},e.remux=function(t,e,r,s,l){var d,c=this.initPTS,h=this.lastEndDTS,f={audio:void 0,video:void 0,text:s,id3:r,initSegment:void 0};Object(i.isFiniteNumber)(h)||(h=this.lastEndDTS=l||0);var g=e.samples;if(!g||!g.length)return f;var v={initPTS:void 0,timescale:1},p=this.initData;if(p&&p.length||(this.generateInitSegment(g),p=this.initData),!p||!p.length)return o.logger.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),f;this.emitInitSegment&&(v.tracks=this.initTracks,this.emitInitSegment=!1),Object(i.isFiniteNumber)(c)||(this.initPTS=v.initPTS=c=u(p,g,h));var m=Object(a.getDuration)(g,p),y=h,E=m+y;Object(a.offsetStartDTS)(p,g,c),m>0?this.lastEndDTS=E:(o.logger.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var T=!!p.audio,S=!!p.video,b="";T&&(b+="audio"),S&&(b+="video");var L={data1:g,startPTS:y,startDTS:y,endPTS:E,endDTS:E,type:b,hasAudio:T,hasVideo:S,nb:1,dropped:0};f.audio="audio"===L.type?L:void 0,f.video="audio"!==L.type?L:void 0,f.initSegment=v;var D=null!=(d=this.initPTS)?d:0;return f.id3=Object(n.flushTextTrackMetadataCueSamples)(r,l,D,D),s.samples.length&&(f.text=Object(n.flushTextTrackUserdataCueSamples)(s,l,D)),f},t}(),u=function(t,e,r){return Object(a.getStartDTS)(t,e)-r};function d(t,e){var r=null==t?void 0:t.codec;return r&&r.length>4?r:"hvc1"===r||"hev1"===r?"hvc1.1.c.L120.90":"av01"===r?"av01.0.04M.08":"avc1"===r||e===s.ElementaryStreamTypes.VIDEO?"avc1.42e01e":"mp4a.40.5"}e.default=l},"./src/task-loop.ts":
253
+ /*! exports provided: default */function(t,e,r){r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./mp4-remuxer */"./src/remux/mp4-remuxer.ts"),a=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),s=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),o=r(/*! ../utils/logger */"./src/utils/logger.ts"),l=function(){function t(){this.emitInitSegment=!1,this.audioCodec=void 0,this.videoCodec=void 0,this.initData=void 0,this.initPTS=void 0,this.initTracks=void 0,this.lastEndTime=null}var e=t.prototype;return e.destroy=function(){},e.resetTimeStamp=function(t){this.initPTS=t,this.lastEndTime=null},e.resetNextTimestamp=function(){this.lastEndTime=null},e.resetInitSegment=function(t,e,r){this.audioCodec=e,this.videoCodec=r,this.generateInitSegment(t),this.emitInitSegment=!0},e.generateInitSegment=function(t){var e=this.audioCodec,r=this.videoCodec;if(!t||!t.byteLength)return this.initTracks=void 0,void(this.initData=void 0);var i=this.initData=Object(a.parseInitSegment)(t);e||(e=u(i.audio,s.ElementaryStreamTypes.AUDIO)),r||(r=u(i.video,s.ElementaryStreamTypes.VIDEO));var n={};i.audio&&i.video?n.audiovideo={container:"video/mp4",codec:e+","+r,initSegment:t,id:"main"}:i.audio?n.audio={container:"audio/mp4",codec:e,initSegment:t,id:"audio"}:i.video?n.video={container:"video/mp4",codec:r,initSegment:t,id:"main"}:o.logger.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=n},e.remux=function(t,e,r,s,l){var u,d=this.initPTS,c=this.lastEndTime,h={audio:void 0,video:void 0,text:s,id3:r,initSegment:void 0};Object(i.isFiniteNumber)(c)||(c=this.lastEndTime=l||0);var f=e.samples;if(!f||!f.length)return h;var g={initPTS:void 0,timescale:1},v=this.initData;if(v&&v.length||(this.generateInitSegment(f),v=this.initData),!v||!v.length)return o.logger.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),h;this.emitInitSegment&&(g.tracks=this.initTracks,this.emitInitSegment=!1);var p=Object(a.getStartDTS)(v,f);Object(i.isFiniteNumber)(d)||(this.initPTS=g.initPTS=d=p-l);var m=Object(a.getDuration)(f,v),y=t?p-d:c,E=y+m;Object(a.offsetStartDTS)(v,f,d),m>0?this.lastEndTime=E:(o.logger.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var T=!!v.audio,S=!!v.video,b="";T&&(b+="audio"),S&&(b+="video");var L={data1:f,startPTS:y,startDTS:y,endPTS:E,endDTS:E,type:b,hasAudio:T,hasVideo:S,nb:1,dropped:0};h.audio="audio"===L.type?L:void 0,h.video="audio"!==L.type?L:void 0,h.initSegment=g;var D=null!=(u=this.initPTS)?u:0;return h.id3=Object(n.flushTextTrackMetadataCueSamples)(r,l,D,D),s.samples.length&&(h.text=Object(n.flushTextTrackUserdataCueSamples)(s,l,D)),h},t}();function u(t,e){var r=null==t?void 0:t.codec;return r&&r.length>4?r:"hvc1"===r||"hev1"===r?"hvc1.1.c.L120.90":"av01"===r?"av01.0.04M.08":"avc1"===r||e===s.ElementaryStreamTypes.VIDEO?"avc1.42e01e":"mp4a.40.5"}e.default=l},"./src/task-loop.ts":
254
254
  /*!**************************!*\
255
255
  !*** ./src/task-loop.ts ***!
256
256
  \**************************/
@@ -334,7 +334,7 @@
334
334
  /*!********************************!*\
335
335
  !*** ./src/utils/mp4-tools.ts ***!
336
336
  \********************************/
337
- /*! exports provided: RemuxerTrackIdConfig, bin2str, readUint16, readUint32, readSint32, writeUint32, findBox, parseSegmentIndex, parseInitSegment, getStartDTS, getDuration, computeRawDurationFromSamples, offsetStartDTS, segmentValidRange, appendUint8Array, parseSamples, parseSEIMessageFromNALu, parseEmsg */function(t,e,r){r.r(e),r.d(e,"RemuxerTrackIdConfig",(function(){return l})),r.d(e,"bin2str",(function(){return u})),r.d(e,"readUint16",(function(){return d})),r.d(e,"readUint32",(function(){return c})),r.d(e,"readSint32",(function(){return h})),r.d(e,"writeUint32",(function(){return f})),r.d(e,"findBox",(function(){return g})),r.d(e,"parseSegmentIndex",(function(){return v})),r.d(e,"parseInitSegment",(function(){return p})),r.d(e,"getStartDTS",(function(){return m})),r.d(e,"getDuration",(function(){return y})),r.d(e,"computeRawDurationFromSamples",(function(){return E})),r.d(e,"offsetStartDTS",(function(){return T})),r.d(e,"segmentValidRange",(function(){return S})),r.d(e,"appendUint8Array",(function(){return b})),r.d(e,"parseSamples",(function(){return L})),r.d(e,"parseSEIMessageFromNALu",(function(){return A})),r.d(e,"parseEmsg",(function(){return R}));var i=r(/*! ./typed-array */"./src/utils/typed-array.ts"),n=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),a=r(/*! ../demux/id3 */"./src/demux/id3.ts"),s=Math.pow(2,32)-1,o=[].push,l={video:1,audio:2,id3:3,text:4};function u(t){return String.fromCharCode.apply(null,t)}function d(t,e){var r=t[e]<<8|t[e+1];return r<0?65536+r:r}function c(t,e){var r=h(t,e);return r<0?4294967296+r:r}function h(t,e){return t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3]}function f(t,e,r){t[e]=r>>24,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r}function g(t,e){var r=[];if(!e.length)return r;for(var i=t.byteLength,n=0;n<i;){var a=c(t,n),s=a>1?n+a:i;if(u(t.subarray(n+4,n+8))===e[0])if(1===e.length)r.push(t.subarray(n+8,s));else{var l=g(t.subarray(n+8,s),e.slice(1));l.length&&o.apply(r,l)}n=s}return r}function v(t){var e=g(t,["moov"])[0],r=e?e.length:null,i=g(t,["sidx"]);if(!i||!i[0])return null;var n=[],a=i[0],s=a[0],o=8,l=c(a,o);o+=4,o+=0===s?8:16,o+=2;var u=a.length+0,h=d(a,o);o+=2;for(var f=0;f<h;f++){var v=o,p=c(a,v);v+=4;var m=2147483647&p;if(1==(2147483648&p)>>>31)return console.warn("SIDX has hierarchical references (not supported)"),null;var y=c(a,v);v+=4,n.push({referenceSize:m,subsegmentDuration:y,info:{duration:y/l,start:u,end:u+m-1}}),u+=m,o=v+=4}return{earliestPresentationTime:0,timescale:l,version:s,referencesCount:h,references:n,moovEndOffset:r}}function p(t){for(var e=[],r=g(t,["moov","trak"]),i=0;i<r.length;i++){var a=r[i],s=g(a,["tkhd"])[0];if(s){var o=s[0],l=0===o?12:20,d=c(s,l),h=g(a,["mdia","mdhd"])[0];if(h){var f=c(h,l=0===(o=h[0])?12:20),v=g(a,["mdia","hdlr"])[0];if(v){var p=u(v.subarray(8,12)),m={soun:n.ElementaryStreamTypes.AUDIO,vide:n.ElementaryStreamTypes.VIDEO}[p];if(m){var y=g(a,["mdia","minf","stbl","stsd"])[0],E=void 0;y&&(E=u(y.subarray(12,16))),e[d]={timescale:f,type:m},e[m]={timescale:f,id:d,codec:E}}}}}}return g(t,["moov","mvex","trex"]).forEach((function(t){var r=c(t,4),i=e[r];i&&(i.default={duration:c(t,12),flags:c(t,20)})})),e}function m(t,e){return g(e,["moof","traf"]).reduce((function(e,r){var i=g(r,["tfdt"])[0],n=i[0],a=g(r,["tfhd"]).reduce((function(e,r){var a=c(r,4),s=t[a];if(s){var o=c(i,4);1===n&&(o*=Math.pow(2,32),o+=c(i,8));var l=o/(s.timescale||9e4);if(isFinite(l)&&(null===e||l<e))return l}return e}),null);return null!==a&&isFinite(a)&&(null===e||a<e)?a:e}),null)||0}function y(t,e){for(var r=0,i=0,a=0,s=g(t,["moof","traf"]),o=0;o<s.length;o++){var l=s[o],u=g(l,["tfhd"])[0],d=e[c(u,4)];if(d){var h=d.default,f=c(u,0)|(null==h?void 0:h.flags),p=null==h?void 0:h.duration;8&f&&(p=c(u,2&f?12:8));for(var m=d.timescale||9e4,y=g(l,["trun"]),T=0;T<y.length;T++)!(r=E(y[T]))&&p&&(r=p*c(y[T],4)),d.type===n.ElementaryStreamTypes.VIDEO?i+=r/m:d.type===n.ElementaryStreamTypes.AUDIO&&(a+=r/m)}}if(0===i&&0===a){var S=v(t);if(null!=S&&S.references)return S.references.reduce((function(t,e){return t+e.info.duration||0}),0)}return i||a}function E(t){var e=c(t,0),r=8;1&e&&(r+=4),4&e&&(r+=4);for(var i=0,n=c(t,4),a=0;a<n;a++)256&e&&(i+=c(t,r),r+=4),512&e&&(r+=4),1024&e&&(r+=4),2048&e&&(r+=4);return i}function T(t,e,r){g(e,["moof","traf"]).forEach((function(e){g(e,["tfhd"]).forEach((function(i){var n=c(i,4),a=t[n];if(a){var o=a.timescale||9e4;g(e,["tfdt"]).forEach((function(t){var e=t[0],i=c(t,4);if(0===e)i-=r*o,f(t,4,i=Math.max(i,0));else{i*=Math.pow(2,32),i+=c(t,8),i-=r*o,i=Math.max(i,0);var n=Math.floor(i/(s+1)),a=Math.floor(i%(s+1));f(t,4,n),f(t,8,a)}}))}}))}))}function S(t){var e={valid:null,remainder:null},r=g(t,["moof"]);if(!r)return e;if(r.length<2)return e.remainder=t,e;var n=r[r.length-1];return e.valid=Object(i.sliceUint8)(t,0,n.byteOffset-8),e.remainder=Object(i.sliceUint8)(t,n.byteOffset-8),e}function b(t,e){var r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),r}function L(t,e){var r=[],i=e.samples,a=e.timescale,s=e.id,o=!1;return g(i,["moof"]).map((function(l){var u=l.byteOffset-8;g(l,["traf"]).map((function(l){var d=g(l,["tfdt"]).map((function(t){var e=t[0],r=c(t,4);return 1===e&&(r*=Math.pow(2,32),r+=c(t,8)),r/a}))[0];return void 0!==d&&(t=d),g(l,["tfhd"]).map((function(d){var f=c(d,4),v=16777215&c(d,0),p=0,m=0!=(16&v),y=0,E=0!=(32&v),T=8;f===s&&(0!=(1&v)&&(T+=8),0!=(2&v)&&(T+=4),0!=(8&v)&&(p=c(d,T),T+=4),m&&(y=c(d,T),T+=4),E&&(T+=4),"video"===e.type&&(o=function(t){if(!t)return!1;var e=t.indexOf("."),r=e<0?t:t.substring(0,e);return"hvc1"===r||"hev1"===r||"dvh1"===r||"dvhe"===r}(e.codec)),g(l,["trun"]).map((function(s){var l=s[0],d=16777215&c(s,0),f=0!=(1&d),g=0,v=0!=(4&d),m=0!=(256&d),E=0,T=0!=(512&d),S=0,b=0!=(1024&d),L=0!=(2048&d),R=0,k=c(s,4),I=8;f&&(g=c(s,I),I+=4),v&&(I+=4);for(var _=g+u,O=0;O<k;O++){if(m?(E=c(s,I),I+=4):E=p,T?(S=c(s,I),I+=4):S=y,b&&(I+=4),L&&(R=0===l?c(s,I):h(s,I),I+=4),e.type===n.ElementaryStreamTypes.VIDEO)for(var C=0;C<S;){var w=c(i,_),x=31&i[_+=4];D(o,x)&&A(i.subarray(_,_+w),t+R/a,r),_+=w,C+=w+4}t+=E/a}})))}))}))})),r}function D(t,e){return t?39===e||40===e:6===e}function A(t,e,r){var i=function(t){for(var e=t.byteLength,r=[],i=1;i<e-2;)0===t[i]&&0===t[i+1]&&3===t[i+2]?(r.push(i+2),i+=2):i++;if(0===r.length)return t;var n=e-r.length,a=new Uint8Array(n),s=0;for(i=0;i<n;s++,i++)s===r[0]&&(s++,r.shift()),a[i]=t[s];return a}(t),n=0;n++;for(var s=0,o=0,l=!1,u=0;n<i.length;){s=0;do{if(n>=i.length)break;s+=u=i[n++]}while(255===u);o=0;do{if(n>=i.length)break;o+=u=i[n++]}while(255===u);var h=i.length-n;if(!l&&4===s&&n<i.length){if(l=!0,181===i[n++]){var f=d(i,n);if(n+=2,49===f){var g=c(i,n);if(n+=4,1195456820===g){var v=i[n++];if(3===v){var p=i[n++],m=64&p,y=m?2+3*(31&p):0,E=new Uint8Array(y);if(m){E[0]=p;for(var T=1;T<y;T++)E[T]=i[n++]}r.push({type:v,payloadType:s,pts:e,bytes:E})}}}}}else if(5===s&&o<h){if(l=!0,o>16){for(var S=[],b=0;b<16;b++){var L=i[n++].toString(16);S.push(1==L.length?"0"+L:L),3!==b&&5!==b&&7!==b&&9!==b||S.push("-")}for(var D=o-16,A=new Uint8Array(D),R=0;R<D;R++)A[R]=i[n++];r.push({payloadType:s,pts:e,uuid:S.join(""),userData:Object(a.utf8ArrayToStr)(A),userDataBytes:A})}}else if(o<h)n+=o;else if(o>h)break}}function R(t){var e=t[0],r="",i="",n=0,a=0,s=0,o=0,l=0,d=0;if(0===e){for(;"\0"!==u(t.subarray(d,d+1));)r+=u(t.subarray(d,d+1)),d+=1;for(r+=u(t.subarray(d,d+1)),d+=1;"\0"!==u(t.subarray(d,d+1));)i+=u(t.subarray(d,d+1)),d+=1;i+=u(t.subarray(d,d+1)),d+=1,n=c(t,12),a=c(t,16),o=c(t,20),l=c(t,24),d=28}else if(1===e){n=c(t,d+=4);var h=c(t,d+=4),f=c(t,d+=4);for(d+=4,s=Math.pow(2,32)*h+f,Number.isSafeInteger(s)||(s=Number.MAX_SAFE_INTEGER,console.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=c(t,d),l=c(t,d+=4),d+=4;"\0"!==u(t.subarray(d,d+1));)r+=u(t.subarray(d,d+1)),d+=1;for(r+=u(t.subarray(d,d+1)),d+=1;"\0"!==u(t.subarray(d,d+1));)i+=u(t.subarray(d,d+1)),d+=1;i+=u(t.subarray(d,d+1)),d+=1}return{schemeIdUri:r,value:i,timeScale:n,presentationTime:s,presentationTimeDelta:a,eventDuration:o,id:l,payload:t.subarray(d,t.byteLength)}}},"./src/utils/output-filter.ts":
337
+ /*! exports provided: RemuxerTrackIdConfig, bin2str, readUint16, readUint32, readSint32, writeUint32, findBox, parseSegmentIndex, parseInitSegment, getStartDTS, getDuration, computeRawDurationFromSamples, offsetStartDTS, segmentValidRange, appendUint8Array, parseSamples, parseSEIMessageFromNALu, parseEmsg */function(t,e,r){r.r(e),r.d(e,"RemuxerTrackIdConfig",(function(){return l})),r.d(e,"bin2str",(function(){return u})),r.d(e,"readUint16",(function(){return d})),r.d(e,"readUint32",(function(){return c})),r.d(e,"readSint32",(function(){return h})),r.d(e,"writeUint32",(function(){return f})),r.d(e,"findBox",(function(){return g})),r.d(e,"parseSegmentIndex",(function(){return v})),r.d(e,"parseInitSegment",(function(){return p})),r.d(e,"getStartDTS",(function(){return m})),r.d(e,"getDuration",(function(){return y})),r.d(e,"computeRawDurationFromSamples",(function(){return E})),r.d(e,"offsetStartDTS",(function(){return T})),r.d(e,"segmentValidRange",(function(){return S})),r.d(e,"appendUint8Array",(function(){return b})),r.d(e,"parseSamples",(function(){return L})),r.d(e,"parseSEIMessageFromNALu",(function(){return A})),r.d(e,"parseEmsg",(function(){return R}));var i=r(/*! ./typed-array */"./src/utils/typed-array.ts"),n=r(/*! ../loader/fragment */"./src/loader/fragment.ts"),a=r(/*! ../demux/id3 */"./src/demux/id3.ts"),s=Math.pow(2,32)-1,o=[].push,l={video:1,audio:2,id3:3,text:4};function u(t){return String.fromCharCode.apply(null,t)}function d(t,e){var r=t[e]<<8|t[e+1];return r<0?65536+r:r}function c(t,e){var r=h(t,e);return r<0?4294967296+r:r}function h(t,e){return t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3]}function f(t,e,r){t[e]=r>>24,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r}function g(t,e){var r=[];if(!e.length)return r;for(var i=t.byteLength,n=0;n<i;){var a=c(t,n),s=a>1?n+a:i;if(u(t.subarray(n+4,n+8))===e[0])if(1===e.length)r.push(t.subarray(n+8,s));else{var l=g(t.subarray(n+8,s),e.slice(1));l.length&&o.apply(r,l)}n=s}return r}function v(t){var e=[],r=t[0],i=8,n=c(t,i);i+=4,i+=0===r?8:16,i+=2;var a=t.length+0,s=d(t,i);i+=2;for(var o=0;o<s;o++){var l=i,u=c(t,l);l+=4;var h=2147483647&u;if(1==(2147483648&u)>>>31)return console.warn("SIDX has hierarchical references (not supported)"),null;var f=c(t,l);l+=4,e.push({referenceSize:h,subsegmentDuration:f,info:{duration:f/n,start:a,end:a+h-1}}),a+=h,i=l+=4}return{earliestPresentationTime:0,timescale:n,version:r,referencesCount:s,references:e}}function p(t){for(var e=[],r=g(t,["moov","trak"]),i=0;i<r.length;i++){var a=r[i],s=g(a,["tkhd"])[0];if(s){var o=s[0],l=0===o?12:20,d=c(s,l),h=g(a,["mdia","mdhd"])[0];if(h){var f=c(h,l=0===(o=h[0])?12:20),v=g(a,["mdia","hdlr"])[0];if(v){var p=u(v.subarray(8,12)),m={soun:n.ElementaryStreamTypes.AUDIO,vide:n.ElementaryStreamTypes.VIDEO}[p];if(m){var y=g(a,["mdia","minf","stbl","stsd"])[0],E=void 0;y&&(E=u(y.subarray(12,16))),e[d]={timescale:f,type:m},e[m]={timescale:f,id:d,codec:E}}}}}}return g(t,["moov","mvex","trex"]).forEach((function(t){var r=c(t,4),i=e[r];i&&(i.default={duration:c(t,12),flags:c(t,20)})})),e}function m(t,e){return g(e,["moof","traf"]).reduce((function(e,r){var i=g(r,["tfdt"])[0],n=i[0],a=g(r,["tfhd"]).reduce((function(e,r){var a=c(r,4),s=t[a];if(s){var o=c(i,4);1===n&&(o*=Math.pow(2,32),o+=c(i,8));var l=o/(s.timescale||9e4);if(isFinite(l)&&(null===e||l<e))return l}return e}),null);return null!==a&&isFinite(a)&&(null===e||a<e)?a:e}),null)||0}function y(t,e){for(var r=0,i=0,a=0,s=g(t,["moof","traf"]),o=0;o<s.length;o++){var l=s[o],u=g(l,["tfhd"])[0],d=e[c(u,4)];if(d){var h=d.default,f=c(u,0)|(null==h?void 0:h.flags),p=null==h?void 0:h.duration;8&f&&(p=c(u,2&f?12:8));for(var m=d.timescale||9e4,y=g(l,["trun"]),T=0;T<y.length;T++)!(r=E(y[T]))&&p&&(r=p*c(y[T],4)),d.type===n.ElementaryStreamTypes.VIDEO?i+=r/m:d.type===n.ElementaryStreamTypes.AUDIO&&(a+=r/m)}}if(0===i&&0===a){for(var S=0,b=g(t,["sidx"]),L=0;L<b.length;L++){var D=v(b[L]);null!=D&&D.references&&(S+=D.references.reduce((function(t,e){return t+e.info.duration||0}),0))}return S}return i||a}function E(t){var e=c(t,0),r=8;1&e&&(r+=4),4&e&&(r+=4);for(var i=0,n=c(t,4),a=0;a<n;a++)256&e&&(i+=c(t,r),r+=4),512&e&&(r+=4),1024&e&&(r+=4),2048&e&&(r+=4);return i}function T(t,e,r){g(e,["moof","traf"]).forEach((function(e){g(e,["tfhd"]).forEach((function(i){var n=c(i,4),a=t[n];if(a){var o=a.timescale||9e4;g(e,["tfdt"]).forEach((function(t){var e=t[0],i=c(t,4);if(0===e)i-=r*o,f(t,4,i=Math.max(i,0));else{i*=Math.pow(2,32),i+=c(t,8),i-=r*o,i=Math.max(i,0);var n=Math.floor(i/(s+1)),a=Math.floor(i%(s+1));f(t,4,n),f(t,8,a)}}))}}))}))}function S(t){var e={valid:null,remainder:null},r=g(t,["moof"]);if(!r)return e;if(r.length<2)return e.remainder=t,e;var n=r[r.length-1];return e.valid=Object(i.sliceUint8)(t,0,n.byteOffset-8),e.remainder=Object(i.sliceUint8)(t,n.byteOffset-8),e}function b(t,e){var r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),r}function L(t,e){var r=[],i=e.samples,a=e.timescale,s=e.id,o=!1;return g(i,["moof"]).map((function(l){var u=l.byteOffset-8;g(l,["traf"]).map((function(l){var d=g(l,["tfdt"]).map((function(t){var e=t[0],r=c(t,4);return 1===e&&(r*=Math.pow(2,32),r+=c(t,8)),r/a}))[0];return void 0!==d&&(t=d),g(l,["tfhd"]).map((function(d){var f=c(d,4),v=16777215&c(d,0),p=0,m=0!=(16&v),y=0,E=0!=(32&v),T=8;f===s&&(0!=(1&v)&&(T+=8),0!=(2&v)&&(T+=4),0!=(8&v)&&(p=c(d,T),T+=4),m&&(y=c(d,T),T+=4),E&&(T+=4),"video"===e.type&&(o=function(t){if(!t)return!1;var e=t.indexOf("."),r=e<0?t:t.substring(0,e);return"hvc1"===r||"hev1"===r||"dvh1"===r||"dvhe"===r}(e.codec)),g(l,["trun"]).map((function(s){var l=s[0],d=16777215&c(s,0),f=0!=(1&d),g=0,v=0!=(4&d),m=0!=(256&d),E=0,T=0!=(512&d),S=0,b=0!=(1024&d),L=0!=(2048&d),R=0,k=c(s,4),I=8;f&&(g=c(s,I),I+=4),v&&(I+=4);for(var _=g+u,C=0;C<k;C++){if(m?(E=c(s,I),I+=4):E=p,T?(S=c(s,I),I+=4):S=y,b&&(I+=4),L&&(R=0===l?c(s,I):h(s,I),I+=4),e.type===n.ElementaryStreamTypes.VIDEO)for(var O=0;O<S;){var w=c(i,_),x=31&i[_+=4];D(o,x)&&A(i.subarray(_,_+w),t+R/a,r),_+=w,O+=w+4}t+=E/a}})))}))}))})),r}function D(t,e){return t?39===e||40===e:6===e}function A(t,e,r){var i=function(t){for(var e=t.byteLength,r=[],i=1;i<e-2;)0===t[i]&&0===t[i+1]&&3===t[i+2]?(r.push(i+2),i+=2):i++;if(0===r.length)return t;var n=e-r.length,a=new Uint8Array(n),s=0;for(i=0;i<n;s++,i++)s===r[0]&&(s++,r.shift()),a[i]=t[s];return a}(t),n=0;n++;for(var s=0,o=0,l=!1,u=0;n<i.length;){s=0;do{if(n>=i.length)break;s+=u=i[n++]}while(255===u);o=0;do{if(n>=i.length)break;o+=u=i[n++]}while(255===u);var h=i.length-n;if(!l&&4===s&&n<i.length){if(l=!0,181===i[n++]){var f=d(i,n);if(n+=2,49===f){var g=c(i,n);if(n+=4,1195456820===g){var v=i[n++];if(3===v){var p=i[n++],m=64&p,y=m?2+3*(31&p):0,E=new Uint8Array(y);if(m){E[0]=p;for(var T=1;T<y;T++)E[T]=i[n++]}r.push({type:v,payloadType:s,pts:e,bytes:E})}}}}}else if(5===s&&o<h){if(l=!0,o>16){for(var S=[],b=0;b<16;b++){var L=i[n++].toString(16);S.push(1==L.length?"0"+L:L),3!==b&&5!==b&&7!==b&&9!==b||S.push("-")}for(var D=o-16,A=new Uint8Array(D),R=0;R<D;R++)A[R]=i[n++];r.push({payloadType:s,pts:e,uuid:S.join(""),userData:Object(a.utf8ArrayToStr)(A),userDataBytes:A})}}else if(o<h)n+=o;else if(o>h)break}}function R(t){var e=t[0],r="",i="",n=0,a=0,s=0,o=0,l=0,d=0;if(0===e){for(;"\0"!==u(t.subarray(d,d+1));)r+=u(t.subarray(d,d+1)),d+=1;for(r+=u(t.subarray(d,d+1)),d+=1;"\0"!==u(t.subarray(d,d+1));)i+=u(t.subarray(d,d+1)),d+=1;i+=u(t.subarray(d,d+1)),d+=1,n=c(t,12),a=c(t,16),o=c(t,20),l=c(t,24),d=28}else if(1===e){n=c(t,d+=4);var h=c(t,d+=4),f=c(t,d+=4);for(d+=4,s=Math.pow(2,32)*h+f,Number.isSafeInteger(s)||(s=Number.MAX_SAFE_INTEGER,console.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=c(t,d),l=c(t,d+=4),d+=4;"\0"!==u(t.subarray(d,d+1));)r+=u(t.subarray(d,d+1)),d+=1;for(r+=u(t.subarray(d,d+1)),d+=1;"\0"!==u(t.subarray(d,d+1));)i+=u(t.subarray(d,d+1)),d+=1;i+=u(t.subarray(d,d+1)),d+=1}return{schemeIdUri:r,value:i,timeScale:n,presentationTime:s,presentationTimeDelta:a,eventDuration:o,id:l,payload:t.subarray(d,t.byteLength)}}},"./src/utils/output-filter.ts":
338
338
  /*!************************************!*\
339
339
  !*** ./src/utils/output-filter.ts ***!
340
340
  \************************************/