(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-771262e0"],{ba566:function(t,e,r){"undefined"!==typeof window&&function(e,r){t.exports=r()}(0,(function(){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(i,n,function(e){return t[e]}.bind(null,n));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="/dist/",r(r.s="./src/hls.ts")}({"./node_modules/eventemitter3/index.js": /*!*********************************************!*\ !*** ./node_modules/eventemitter3/index.js ***! \*********************************************/ /*! no static exports found */function(t,e,r){"use strict";var i=Object.prototype.hasOwnProperty,n="~";function s(){}function a(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function o(t,e,r,i,s){if("function"!==typeof r)throw new TypeError("The listener must be a function");var o=new a(r,i||t,s),l=n?n+e:e;return t._events[l]?t._events[l].fn?t._events[l]=[t._events[l],o]:t._events[l].push(o):(t._events[l]=o,t._eventsCount++),t}function l(t,e){0===--t._eventsCount?t._events=new s:delete t._events[e]}function u(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(n=!1)),u.prototype.eventNames=function(){var t,e,r=[];if(0===this._eventsCount)return r;for(e in t=this._events)i.call(t,e)&&r.push(n?e.slice(1):e);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},u.prototype.listeners=function(t){var e=n?n+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,s=r.length,a=new Array(s);i0}),!1)}function c(t,e){var r={main:[e]},i={main:[]},n={main:{}};while(u(r))for(var s=Object.keys(r),a=0;a=2*d/f||E<=S)){var b,L=Number.POSITIVE_INFINITY;for(b=t.level-1;b>v;b--){var A=g[b].maxBitrate;if(L=d*A/(6.4*y),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,c.loaded),this.clearTimer(),t.loader&&(this.fragCurrent=this.partCurrent=null,t.loader.abort()),r.trigger(s["Events"].FRAG_LOAD_EMERGENCY_ABORTED,{frag:t,part:e,stats:c})}}}}}},e.onFragLoaded=function(t,e){var r=e.frag,n=e.part;if(r.type===l["PlaylistLevelType"].MAIN&&Object(i["isFiniteNumber"])(r.sn)){var a=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],c=(u.loaded?u.loaded.bytes:0)+a.loaded,d=(u.loaded?u.loaded.duration:0)+o;u.loaded={bytes:c,duration:d},u.realBitrate=Math.round(8*c/d)}if(r.bitrateTest){var h={stats:a,frag:r,part:n,id:r.type};this.onFragBuffered(s["Events"].FRAG_BUFFERED,h),r.bitrateTest=!1}}},e.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 s=n.parsing.end-n.loading.start;this.bwEstimator.sample(s,n.loaded),n.bwEstimate=this.bwEstimator.getEstimate(),r.bitrateTest?this.bitrateTestDelay=s/1e3:this.bitrateTestDelay=0}},e.onError=function(t,e){switch(e.details){case o["ErrorDetails"].FRAG_LOAD_ERROR:case o["ErrorDetails"].FRAG_LOAD_TIMEOUT:this.clearTimer();break;default:break}},e.clearTimer=function(){self.clearInterval(this.timer),this.timer=void 0},e.getNextABRAutoLevel=function(){var t=this.fragCurrent,e=this.partCurrent,r=this.hls,i=r.maxAutoLevel,n=r.config,s=r.minAutoLevel,o=r.media,l=e?e.duration:t?t.duration:0,c=o?o.currentTime:0,d=o&&0!==o.playbackRate?Math.abs(o.playbackRate):1,h=this.bwEstimator?this.bwEstimator.getEstimate():n.abrEwmaDefaultEstimate,f=(a["BufferHelper"].bufferInfo(o,c,n.maxBufferHole).end-c)/d,g=this.findBestLevel(h,s,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;if(y){var E=l?Math.min(l,n.maxLoadingDelay):n.maxLoadingDelay;v=E-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,s,i,f+v,p,m),Math.max(g,0)},e.findBestLevel=function(t,e,r,i,n,s){for(var a,o=this.fragCurrent,l=this.partCurrent,c=this.lastLoadedFragLevel,d=this.hls.levels,h=d[c],f=!(null===h||void 0===h||null===(a=h.details)||void 0===a||!a.live),g=null===h||void 0===h?void 0:h.codecSet,v=l?l.duration:o?o.duration:0,p=r;p>=e;p--){var m=d[p];if(m&&(!g||m.codecSet===g)){var y=m.details,E=(l?null===y||void 0===y?void 0:y.partTarget:null===y||void 0===y?void 0:y.averagetargetduration)||v,T=void 0;T=p<=c?n*t:s*t;var S=d[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||b0&&-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()},r.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,s=null===r||void 0===r||null===(e=r[i])||void 0===e?void 0:e.details;if(s){if(this.waitForCdnTuneIn(s))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 c=this.waitingData;if(c){var d=c.frag,h=c.part,f=c.cache,v=c.complete;if(void 0!==this.initPTS[d.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=n["State"].FRAG_LOADING;var p=f.flush(),y={frag:d,part:h,payload:p,networkDetails:null};this._handleFragmentLoadProgress(y),v&&t.prototype._handleFragmentLoadComplete.call(this,y)}else if(this.videoTrackCC!==this.waitingVideoCC)m["logger"].log("Waiting fragment cc ("+d.cc+") cancelled because video is at cc "+this.videoTrackCC),this.clearWaitingFragment();else{var E=this.getLoadPosition(),T=a["BufferHelper"].bufferInfo(this.mediaBuffer,E,this.config.maxBufferHole),S=Object(g["fragmentWithinToleranceTest"])(T.end,this.config.maxFragLookUpTolerance,d);S<0&&(m["logger"].log("Waiting fragment cc ("+d.cc+") @ "+d.start+" cancelled because another fragment at "+T.end+" is needed"),this.clearWaitingFragment())}}else this.state=n["State"].IDLE}this.onTickEnd()},r.clearWaitingFragment=function(){var t=this.waitingData;t&&(this.fragmentTracker.removeFragment(t.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=n["State"].IDLE)},r.onTickEnd=function(){var t=this.media;if(t&&t.readyState){var e=this.mediaBuffer?this.mediaBuffer:t,r=e.buffered;!this.loadedmetadata&&r.length&&(this.loadedmetadata=!0),this.lastCurrentTime=t.currentTime}},r.doTickIdle=function(){var t,e,r=this.hls,i=this.levels,a=this.media,o=this.trackId,l=r.config;if(i&&i[o]&&(a||!this.startFragRequested&&l.startFragPrefetch)){var d=i[o],h=d.details;if(!h||h.live&&this.levelLastLoaded!==o||this.waitForCdnTuneIn(h))this.state=n["State"].WAITING_TRACK;else{this.bufferFlushed&&(this.bufferFlushed=!1,this.afterBufferFlushed(this.mediaBuffer?this.mediaBuffer:this.media,c["ElementaryStreamTypes"].AUDIO,u["PlaylistLevelType"].AUDIO));var f=this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,u["PlaylistLevelType"].AUDIO);if(null!==f){var g=f.len,v=this.getMaxBufferLength(),p=this.audioSwitch;if(!(g>=v)||p){if(!p&&this._streamEnded(f,h))return r.trigger(s["Events"].BUFFER_EOS,{type:"audio"}),void(this.state=n["State"].ENDED);var m=h.fragments,y=m[0].start,E=f.end;if(p){var T=this.getLoadPosition();E=T,h.PTSKnown&&Ty||f.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),a.currentTime=y+.05)}var S=this.getNextFragment(E,h);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,h,E):this.loadKey(S,h):this.bufferFlushed=!0}}}}},r.getMaxBufferLength=function(){var e=t.prototype.getMaxBufferLength.call(this),r=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,u["PlaylistLevelType"].MAIN);return null===r?e:Math.max(e,r.len)},r.onMediaDetaching=function(){this.videoBuffer=null,t.prototype.onMediaDetaching.call(this)},r.onAudioTracksUpdated=function(t,e){var r=e.audioTracks;this.resetTransmuxer(),this.levels=r.map((function(t){return new l["Level"](t)}))},r.onAudioTrackSwitching=function(t,e){var r=!!e.url;this.trackId=e.id;var i=this.fragCurrent;null!==i&&void 0!==i&&i.loader&&i.loader.abort(),this.fragCurrent=null,this.clearWaitingFragment(),r?this.setInterval(S):this.resetTransmuxer(),r?(this.audioSwitch=!0,this.state=n["State"].IDLE):this.state=n["State"].STOPPED,this.tick()},r.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=!1},r.onLevelLoaded=function(t,e){this.mainDetails=e.details},r.onAudioTrackLoaded=function(t,e){var r,i=this.levels,s=e.details,a=e.id;if(i){this.log("Track "+a+" loaded ["+s.startSN+","+s.endSN+"],duration:"+s.totalduration);var o=i[a],l=0;if(s.live||null!==(r=o.details)&&void 0!==r&&r.live){var u=this.mainDetails;if(s.fragments[0]||(s.deltaUpdateFailed=!0),s.deltaUpdateFailed||!u)return;!o.details&&s.hasProgramDateTime&&u.hasProgramDateTime?(Object(v["alignMediaPlaylistByPDT"])(s,u),l=s.fragments[0].start):l=this.alignPlaylists(s,o.details)}o.details=s,this.levelLastLoaded=a,this.startFragRequested||!this.mainDetails&&s.live||this.setStartPosition(o.details,l),this.state!==n["State"].WAITING_TRACK||this.waitForCdnTuneIn(s)||(this.state=n["State"].IDLE),this.tick()}else this.warn("Audio tracks were reset while loading level "+a)},r._handleFragmentLoadProgress=function(t){var e,r=t.frag,i=t.part,s=t.payload,a=this.config,o=this.trackId,l=this.levels;if(l){var c=l[o];console.assert(c,"Audio track is defined on fragment load progress");var g=c.details;console.assert(g,"Audio track details are defined on fragment load progress");var v=a.defaultAudioCodec||c.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=!1,S=i?i.index:-1,b=-1!==S,L=new f["ChunkMetadata"](r.level,r.sn,r.stats.chunkCount,s.byteLength,S,b);p.push(s,E,v,"",r,i,g.totalduration,T,L,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);var A=this.waitingData=this.waitingData||{frag:r,part:i,cache:new d["default"],complete:!1},D=A.cache;D.push(new Uint8Array(s)),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")},r._handleFragmentLoadComplete=function(e){this.waitingData?this.waitingData.complete=!0:t.prototype._handleFragmentLoadComplete.call(this,e)},r.onBufferReset=function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1},r.onBufferCreated=function(t,e){var r=e.tracks.audio;r&&(this.mediaBuffer=r.buffer),e.tracks.video&&(this.videoBuffer=e.tracks.video.buffer)},r.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(s["Events"].AUDIO_TRACK_SWITCHED,{id:this.trackId}))),this.fragBufferedComplete(r,i)))},r.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,s=this.getFwdBufferInfo(this.mediaBuffer,u["PlaylistLevelType"].AUDIO);s&&s.len>.5&&(i=!this.reduceMaxBufferLength(s.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()}break;default:break}},r.onBufferFlushed=function(t,e){var r=e.type;r===c["ElementaryStreamTypes"].AUDIO&&(this.bufferFlushed=!0)},r._handleTransmuxComplete=function(t){var e,r="audio",i=this.hls,a=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,d=l.part,h=a.audio,f=a.text,g=a.id3,v=a.initSegment;if(!this.fragContextChanged(u)){if(this.state=n["State"].PARSING,this.audioSwitch&&h&&this.completeAudioSwitch(),null!==v&&void 0!==v&&v.tracks&&(this._bufferInitSegment(v.tracks,u,o),i.trigger(s["Events"].FRAG_PARSING_INIT_SEGMENT,{frag:u,id:r,tracks:v.tracks})),h){var p=h.startPTS,m=h.endPTS,E=h.startDTS,T=h.endDTS;d&&(d.elementaryStreams[c["ElementaryStreamTypes"].AUDIO]={startPTS:p,endPTS:m,startDTS:E,endDTS:T}),u.setElementaryStreamInfo(c["ElementaryStreamTypes"].AUDIO,p,m,E,T),this.bufferFragmentData(h,u,d,o)}if(null!==g&&void 0!==g&&null!==(e=g.samples)&&void 0!==e&&e.length){var S=y({frag:u,id:r},g);i.trigger(s["Events"].FRAG_PARSING_METADATA,S)}if(f){var b=y({frag:u,id:r},f);i.trigger(s["Events"].FRAG_PARSING_USERDATA,b)}}},r._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(s["Events"].BUFFER_CODECS,t);var a=i.initSegment;if(null!==a&&void 0!==a&&a.byteLength){var o={type:"audio",frag:e,part:null,chunkMeta:r,parent:e.type,data:a};this.hls.trigger(s["Events"].BUFFER_APPENDING,o)}this.tick()}}},r.loadFragment=function(e,r,s){var a=this.fragmentTracker.getState(e);this.fragCurrent=e,(this.audioSwitch||a===o["FragmentState"].NOT_LOADED||a===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,s)))},r.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(s["Events"].AUDIO_TRACK_SWITCHED,{id:i})},e}(n["default"]);e["default"]=b},"./src/controller/audio-track-controller.ts": /*!**************************************************!*\ !*** ./src/controller/audio-track-controller.ts ***! \**************************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ./base-playlist-controller */"./src/controller/base-playlist-controller.ts"),a=r(/*! ../types/loader */"./src/types/loader.ts");function o(t,e){for(var r=0;r=e.length)this.warn("Invalid id passed to audio-track controller");else{this.clearTimer();var r=e[this.trackId];this.log("Now switching to audio-track index "+t);var n=e[t],s=n.id,a=n.groupId,o=void 0===a?"":a,l=n.name,u=n.type,c=n.url;if(this.trackId=t,this.trackName=l,this.selectDefaultTrack=!1,this.hls.trigger(i["Events"].AUDIO_TRACK_SWITCHING,{id:s,groupId:o,name:l,type:u,url:c}),!n.details||n.details.live){var d=this.switchParams(n.url,null===r||void 0===r?void 0:r.details);this.loadPlaylist(d)}}},r.selectInitialTrack=function(){var t=this.tracksInGroup;console.assert(t.length,"Initial audio track should be selected when tracks are known");var e=this.trackName,r=this.findTrackId(e)||this.findTrackId();-1!==r?this.setAudioTrack(r):(this.warn("No track found for running audio group-ID: "+this.groupId),this.hls.trigger(i["Events"].ERROR,{type:n["ErrorTypes"].MEDIA_ERROR,details:n["ErrorDetails"].AUDIO_TRACK_LOAD_ERROR,fatal:!0}))},r.findTrackId=function(t){for(var e=this.tracksInGroup,r=0;re.partTarget&&(u+=1)}if(Object(i["isFiniteNumber"])(l))return new n["HlsUrlParameters"](l,Object(i["isFiniteNumber"])(u)?u:void 0,n["HlsSkip"].No)}}},e.loadPlaylist=function(t){},e.shouldLoadTrack=function(t){return this.canLoad&&t&&!!t.url&&(!t.details||t.details.live)},e.playlistLoaded=function(t,e,r){var i=this,n=e.details,a=e.stats,o=a.loading.end?Math.max(0,self.performance.now()-a.loading.end):0;if(n.advancedDateTime=Date.now()-o,n.live||null!==r&&void 0!==r&&r.live){if(n.reloaded(r),r&&this.log("live playlist "+t+" "+(n.advanced?"REFRESHED "+n.lastPartSn+"-"+n.lastPartIndex:"MISSED")),r&&n.fragments.length>0&&Object(s["mergeDetails"])(r,n),!this.canLoad||!n.live)return;var l,u=void 0,c=void 0;if(n.canBlockReload&&n.endSN&&n.advanced){var d=this.hls.config.lowLatencyMode,h=n.lastPartSn,f=n.endSN,g=n.lastPartIndex,v=-1!==g,p=h===f,m=d?0:g;v?(u=p?f+1:h,c=p?m:g+1):u=f+1;var y=n.age,E=y+n.ageHeader,T=Math.min(E-n.partTarget,1.5*n.targetduration);if(T>0){if(r&&T>r.tuneInGoal)this.warn("CDN Tune-in goal increased from: "+r.tuneInGoal+" to: "+T+" with playlist age: "+n.age),T=0;else{var S=Math.floor(T/n.targetduration);if(u+=S,void 0!==c){var b=Math.round(T%n.targetduration/n.partTarget);c+=b}this.log("CDN Tune-in age: "+n.ageHeader+"s last advanced "+y.toFixed(2)+"s goal: "+T+" skip sn "+S+" to part "+c)}n.tuneInGoal=T}if(l=this.getDeliveryDirectives(n,e.deliveryDirectives,u,c),d||!p)return void this.loadPlaylist(l)}else l=this.getDeliveryDirectives(n,e.deliveryDirectives,u,c);var L=Object(s["computeReloadInterval"])(n,a);void 0!==u&&n.canBlockReload&&(L-=n.partTarget||1),this.log("reload live playlist "+t+" in "+Math.round(L)+" ms"),this.timer=self.setTimeout((function(){return i.loadPlaylist(l)}),L)}else this.clearTimer()},e.getDeliveryDirectives=function(t,e,r,i){var s=Object(n["getSkipValue"])(t,r);return null!==e&&void 0!==e&&e.skip&&t.deltaUpdateFailed&&(r=e.msn,i=e.part,s=n["HlsSkip"].No),new n["HlsUrlParameters"](r,i,s)},e.retryLoadingOrFail=function(t){var e,r=this,i=this.hls.config,n=this.retryCount-1&&null!==(e=t.context)&&void 0!==e&&e.deliveryDirectives)this.warn("retry playlist loading #"+this.retryCount+' after "'+t.details+'"'),this.loadPlaylist();else{var s=Math.min(Math.pow(2,this.retryCount)*i.levelLoadingRetryDelay,i.levelLoadingMaxRetryTimeout);this.timer=self.setTimeout((function(){return r.loadPlaylist()}),s),this.warn("retry playlist loading #"+this.retryCount+" in "+s+' ms after "'+t.details+'"')}else this.warn('cannot recover from error "'+t.details+'"'),this.clearTimer(),t.fatal=!0;return n},t}()},"./src/controller/base-stream-controller.ts": /*!**************************************************!*\ !*** ./src/controller/base-stream-controller.ts ***! \**************************************************/ /*! exports provided: State, default */function(t,e,r){"use strict";r.r(e),r.d(e,"State",(function(){return A})),r.d(e,"default",(function(){return D}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../task-loop */"./src/task-loop.ts"),s=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),a=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"),c=r(/*! ../types/transmuxer */"./src/types/transmuxer.ts"),d=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;rd;(o0&&s&&s.key&&s.iv&&"AES-128"===s.method){var a=self.performance.now();return e.decrypter.webCryptoDecrypt(new Uint8Array(n),s.key.buffer,s.iv.buffer).then((function(e){var n=self.performance.now();return i.trigger(l["Events"].FRAG_DECRYPTED,{frag:t,payload:e,stats:{tstart:a,tdecrypt:n}}),r.payload=e,r}))}return r})).then((function(r){var i=e.fragCurrent,n=e.hls,s=e.levels;if(!s)throw new Error("init load aborted, missing levels");var a=s[t.level].details;console.assert(a,"Level details are defined when init segment is loaded");var o=t.stats;e.state=A.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)}))},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+" "+m["default"].toString(a["BufferHelper"].getBuffered(r))),this.state=A.IDLE,this.tick()},r._handleFragmentLoadComplete=function(t){var e=this.transmuxer;if(e){var r=t.frag,i=t.part,n=t.partsLoaded,s=!n||0===n.length||n.some((function(t){return!t})),a=new c["ChunkMetadata"](r.level,r.sn,r.stats.chunkCount+1,0,i?i.index:-1,!s);e.flush(a)}},r._handleFragmentLoadProgress=function(t){},r._doFragLoad=function(t,e,r,n){var s=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 a=e.partList;if(a&&n){r>t.end&&e.fragmentHint&&(t=e.fragmentHint);var o=this.getNextPart(a,t,r);if(o>-1){var u=a[o];return this.log("Loading part sn: "+t.sn+" p: "+u.index+" cc: "+t.cc+" of playlist ["+e.startSN+"-"+e.endSN+"] parts [0-"+o+"-"+(a.length-1)+"] "+("[stream-controller]"===this.logPrefix?"level":"track")+": "+t.level+", target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=u.start+u.duration,this.state=A.FRAG_LOADING,this.hls.trigger(l["Events"].FRAG_LOADING,{frag:t,part:a[o],targetBufferTime:r}),this.doFragPartsLoad(t,a,o,n).catch((function(t){return s.handleFragLoadError(t)}))}if(!t.url||this.loadedEndOfParts(a,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=A.FRAG_LOADING,this.hls.trigger(l["Events"].FRAG_LOADING,{frag:t,targetBufferTime:r}),this.fragmentLoader.load(t,n).catch((function(t){return s.handleFragLoadError(t)}))},r.doFragPartsLoad=function(t,e,r,i){var n=this;return new Promise((function(s,a){var o=[],u=function r(u){var c=e[u];n.fragmentLoader.loadPart(t,c,i).then((function(i){o[c.index]=i;var a=i.part;n.hls.trigger(l["Events"].FRAG_LOADED,i);var d=e[u+1];if(!d||d.fragment!==t)return s({frag:t,part:a,partsLoaded:o});r(u+1)})).catch(a)};u(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===A.PARSING){var r=e.frag,i=e.part,n=e.level,s=self.performance.now();r.stats.parsing.end=s,i&&(i.stats.parsing.end=s),this.updateLevelTiming(r,i,n,t.partial)}else this.fragCurrent||(this.state=A.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 s=e[r],a=n>-1?Object(g["getPartWith"])(s,i,n):null,o=a?a.fragment:Object(g["getFragmentWithSN"])(s,i,this.fragCurrent);return o?{frag:o,part:a,level:s}:null},r.bufferFragmentData=function(t,e,r,i){if(t&&this.state===A.PARSING){var n=t.data1,s=t.data2,a=n;if(n&&s&&(a=Object(d["appendUint8Array"])(n,s)),a&&a.length){var o={type:t.type,frag:e,part:r,chunkMeta:i,parent:e.type,data:a};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(a["BufferHelper"].isBuffered(e,e.currentTime)){var r=e.currentTime,i=a["BufferHelper"].bufferInfo(e,r,0),n=t.duration,s=Math.min(2*this.config.maxFragLookUpTolerance,.25*n),o=Math.max(Math.min(t.start-s,i.end-s),r+s);t.start-o>s&&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 s=a["BufferHelper"].bufferInfo(t,n,r.maxBufferHole);if(0===s.len&&void 0!==s.nextStart){var o=this.fragmentTracker.getBufferedFrag(n,e);if(o&&s.nextStart=r&&(e.maxMaxBufferLength/=2,this.warn("Reduce max buffer length to "+e.maxMaxBufferLength+"s"),!0)},r.getNextFragment=function(t,e){var r,i,n=e.fragments,s=n.length;if(!s)return null;var a,o=this.config,l=n[0].start;if(e.live){var u=o.initialLiveManifestSize;if(s-1&&rr.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 s=e[n-t.startSN];r.cc===s.cc&&(i=s,this.log("Live playlist, switching playlist, load frag with next SN: "+i.sn))}i||(i=Object(f["findFragWithCC"])(e,r.cc),i&&this.log("Live playlist, switching playlist, load frag with same CC: "+i.sn))}}else{var a=this.hls.liveSyncPosition;null!==a&&(i=this.getFragmentAtPosition(a,this.bitrateTest?t.fragmentEnd:t.edge,t))}return i},r.getFragmentAtPosition=function(t,e,r){var i,n=this.config,a=this.fragPrevious,o=r.fragments,l=r.endSN,u=r.fragmentHint,c=n.maxFragLookUpTolerance,d=!!(n.lowLatencyMode&&r.partList&&u);if(d&&u&&!this.bitrateTest&&(o=o.concat(u),l=u.sn),te-c?0:c;i=Object(f["findFragmentByPTS"])(a,o,t,h)}else i=o[o.length-1];if(i){var g=i.sn-r.startSN,v=a&&i.level===a.level,p=o[g+1],m=this.fragmentTracker.getState(i);if(m===s["FragmentState"].BACKTRACKED){i=null;var y=g;while(o[y]&&this.fragmentTracker.getState(o[y])===s["FragmentState"].BACKTRACKED)i=a?o[y--]:o[--y];i||(i=p)}else a&&i.sn===a.sn&&!d&&v&&(i.sn=s-e.maxFragLookUpTolerance&&n<=a;if(null!==i&&r.duration>i&&(n"+t.startSN+" prev-sn: "+(s?s.sn:"na")+" fragments: "+o),d}return l},r.waitForCdnTuneIn=function(t){var e=3;return t.live&&t.canBlockReload&&t.tuneInGoal>Math.max(t.partHoldBack,t.partTarget*e)},r.setStartPosition=function(t,e){var r=this.startPosition;if(r"+t))}}]),e}(n["default"])},"./src/controller/buffer-controller.ts": /*!*********************************************!*\ !*** ./src/controller/buffer-controller.ts ***! \*********************************************/ /*! exports provided: default */function(t,e,r){"use strict";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"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),a=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"),c=r(/*! ./buffer-operation-queue */"./src/controller/buffer-operation-queue.ts"),d=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;s["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(){s["logger"].log("[buffer-controller]: Media source closed")},this._onMediaSourceEnded=function(){s["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 c["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,s["logger"].log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},e.onMediaAttaching=function(t,e){var r=this.media=e.media;if(r&&d){var i=this.mediaSource=new d;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(s["logger"].log("[buffer-controller]: media source detaching"),"open"===e.readyState)try{e.endOfStream()}catch(i){s["logger"].warn("[buffer-controller]: onMediaDetaching: "+i.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()):s["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(i){s["logger"].warn("[buffer-controller]: Failed to reset the "+e+" buffer",i)}})),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],a=s.codec,o=s.levelCodec,l=s.container,u=(n.levelCodec||n.codec).replace(h,"$1"),c=(o||a).replace(h,"$1");if(u!==c){var d=l+";codecs="+(o||a);r.appendChangeType(t,d)}}}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&&(s["logger"].log("[buffer-controller]: changing "+t+" sourceBuffer type to "+e),n.changeType(e)),i.shiftAndExecuteNext(t)},onStart:function(){},onComplete:function(){},onError:function(e){s["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,c=e.data,d=e.type,h=e.frag,f=e.part,g=e.chunkMeta,v=g.buffering[d],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"===d&&1===g.id&&"audio/mpeg"===(null===E||void 0===E?void 0:E.container),S={execute:function(){if(v.executeStart=self.performance.now(),T){var t=r.sourceBuffer[d];if(t){var e=h.start-t.timestampOffset;Math.abs(e)>=.1&&(s["logger"].log("[buffer-controller]: Updating audio SourceBuffer timestampOffset to "+h.start+" (delta: "+e+") sn: "+h.sn+")"),t.timestampOffset=h.start)}}r.appendExecutor(c,d)},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 s in e)i[s]=o["BufferHelper"].getBuffered(e[s]);r.appendError=0,r.hls.trigger(n["Events"].BUFFER_APPENDED,{type:d,frag:h,part:f,chunkMeta:g,parent:h.type,timeRanges:i})},onError:function(t){s["logger"].error("[buffer-controller]: Error encountered while trying to append to the "+d+" SourceBuffer",t);var e={type:a["ErrorTypes"].MEDIA_ERROR,parent:h.type,details:a["ErrorDetails"].BUFFER_APPEND_ERROR,err:t,fatal:!1};t.code===DOMException.QUOTA_EXCEEDED_ERR?e.details=a["ErrorDetails"].BUFFER_FULL_ERROR:(r.appendError++,e.details=a["ErrorDetails"].BUFFER_APPEND_ERROR,r.appendError>i.config.appendErrorMaxRetry&&(s["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,d)},e.onBufferFlushing=function(t,e){var r=this,i=this.operationQueue,a=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){s["logger"].warn("[buffer-controller]: Failed to remove from "+t+" SourceBuffer",e)}}};e.type?i.append(a(e.type),e.type):this.getSourceBufferTypes().forEach((function(t){i.append(a(t),t)}))},e.onFragParsed=function(t,e){var r=this,i=e.frag,a=e.part,o=[],l=a?a.elementaryStreams:i.elementaryStreams;l[u["ElementaryStreamTypes"].AUDIOVIDEO]?o.push("audiovideo"):(l[u["ElementaryStreamTypes"].AUDIO]&&o.push("audio"),l[u["ElementaryStreamTypes"].VIDEO]&&o.push("video"));var c=function(){var t=self.performance.now();i.stats.buffering.end=t,a&&(a.stats.buffering.end=t);var e=a?a.stats:i.stats;r.hls.trigger(n["Events"].FRAG_BUFFERED,{frag:i,part:a,stats:e,id:i.type})};0===o.length&&s["logger"].warn("Fragments must have at least one ElementaryStreamType set. type: "+i.type+" level: "+i.level+" sn: "+i.sn),this.blockBuffers(c,o)},e.onFragChanged=function(t,e){this.flushBackBuffer()},e.onBufferEos=function(t,e){var r=this,i=this.getSourceBufferTypes().reduce((function(t,i){var n=r.sourceBuffer[i];return e.type&&e.type!==i||n&&!n.ended&&(n.ended=!0,s["logger"].log("[buffer-controller]: "+i+" sourceBuffer now EOS")),t&&!(n&&!n.ended)}),!0);i&&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,s=this.sourceBuffer;if(r&&null!==e){var a=this.getSourceBufferTypes();if(a.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,c=e.levelTargetDuration,d=Math.max(l,c),h=Math.floor(u/c)*c-d;a.forEach((function(r){var i=s[r];if(i){var a=o["BufferHelper"].getBuffered(i);a.length>0&&h>a.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,a=t.fragments[0].start+t.totalduration,o=r.duration,l=Object(i["isFiniteNumber"])(n.duration)?n.duration:0;t.live&&e.config.liveDurationInfinity?(s["logger"].log("[buffer-controller]: Media Source duration is set to Infinity"),n.duration=1/0,this.updateSeekableRange(t)):(a>l&&a>o||!Object(i["isFiniteNumber"])(o))&&(s["logger"].log("[buffer-controller]: Updating Media Source duration to "+a.toFixed(3)),n.duration=a)}},e.updateSeekableRange=function(t){var e=this.mediaSource,r=t.fragments,i=r.length;if(i&&t.live&&null!==e&&void 0!==e&&e.setLiveSeekableRange){var n=Math.max(0,r[0].start),s=Math.max(n,n+t.totalduration);e.setLiveSeekableRange(n,s)}},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 s=this.getSourceBufferTypes();if(0===s.length)return void this.hls.trigger(n["Events"].ERROR,{type:a["ErrorTypes"].MEDIA_ERROR,details:a["ErrorDetails"].BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,reason:"could not create source buffer for media codec(s)"});s.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,c=l.container+";codecs="+u;s["logger"].log("[buffer-controller]: creating sourceBuffer("+c+")");try{var d=e[o]=r.addSourceBuffer(c),h=o;this.addBufferListener(h,"updatestart",this._onSBUpdateStart),this.addBufferListener(h,"updateend",this._onSBUpdateEnd),this.addBufferListener(h,"error",this._onSBUpdateError),this.tracks[o]={buffer:d,codec:u,container:l.container,levelCodec:l.levelCodec,id:l.id},i++}catch(f){s["logger"].error("[buffer-controller]: error while trying to add sourceBuffer: "+f.message),this.hls.trigger(n["Events"].ERROR,{type:a["ErrorTypes"].MEDIA_ERROR,details:a["ErrorDetails"].BUFFER_ADD_CODEC_ERROR,fatal:!1,error:f,mimeType:c})}}i&&this.hls.trigger(n["Events"].BUFFER_CREATED,{tracks:this.tracks})},e._onSBUpdateStart=function(t){var e=this.operationQueue,r=e.current(t);r.onStart()},e._onSBUpdateEnd=function(t){var e=this.operationQueue,r=e.current(t);r.onComplete(),e.shiftAndExecuteNext(t)},e._onSBUpdateError=function(t,e){s["logger"].error("[buffer-controller]: "+t+" SourceBuffer error",e),this.hls.trigger(n["Events"].ERROR,{type:a["ErrorTypes"].MEDIA_ERROR,details:a["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,a=this.mediaSource,o=this.operationQueue,l=this.sourceBuffer,u=l[t];if(!n||!a||!u)return s["logger"].warn("[buffer-controller]: Attempting to remove from the "+t+" SourceBuffer, but it does not exist"),void o.shiftAndExecuteNext(t);var c=Object(i["isFiniteNumber"])(n.duration)?n.duration:1/0,d=Object(i["isFiniteNumber"])(a.duration)?a.duration:1/0,h=Math.max(0,e),f=Math.min(r,c,d);f>h?(s["logger"].log("[buffer-controller]: Removing ["+h+","+f+"] from the "+t+" SourceBuffer"),console.assert(!u.updating,t+" sourceBuffer must not be updating"),u.remove(h,f)):o.shiftAndExecuteNext(t)},e.appendExecutor=function(t,e){var r=this.operationQueue,i=this.sourceBuffer,n=i[e];if(!n)return s["logger"].warn("[buffer-controller]: Attempting to append to the "+e+" SourceBuffer, but it does not exist"),void r.shiftAndExecuteNext(e);n.ended=!1,console.assert(!n.updating,e+" sourceBuffer must not be updating"),n.appendBuffer(t)},e.blockBuffers=function(t,e){var r=this;if(void 0===e&&(e=this.getSourceBufferTypes()),!e.length)return s["logger"].log("[buffer-controller]: Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve(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": /*!**************************************************!*\ !*** ./src/controller/buffer-operation-queue.ts ***! \**************************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return n}));var i=r(/*! ../utils/logger */"./src/utils/logger.ts"),n=function(){function t(t){this.buffers=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.buffers=t}var e=t.prototype;return e.append=function(t,e){var r=this.queues[e];r.push(t),1===r.length&&this.buffers[e]&&this.executeNext(e)},e.insertAbort=function(t,e){var r=this.queues[e];r.unshift(t),this.executeNext(e)},e.appendBlocker=function(t){var e,r=new Promise((function(t){e=t})),i={execute:e,onStart:function(){},onComplete:function(){},onError:function(){}};return this.append(i,t),r},e.executeNext=function(t){var e=this.buffers,r=this.queues,n=e[t],s=r[t];if(s.length){var a=s[0];try{a.execute()}catch(o){i["logger"].warn("[buffer-operation-queue]: Unhandled exception executing the current operation"),a.onError(o),n&&n.updating||(s.shift(),this.executeNext(t))}}},e.shiftAndExecuteNext=function(t){this.queues[t].shift(),this.executeNext(t)},e.current=function(t){return this.queues[t][0]},t}()},"./src/controller/cap-level-controller.ts": /*!************************************************!*\ !*** ./src/controller/cap-level-controller.ts ***! \************************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=r(/*! ../events */"./src/events.ts");function n(t,e){for(var r=0;r0&&this.mediaWidth>0){var t=this.hls.levels;if(t.length){var e=this.hls;e.autoLevelCapping=this.getMaxLevel(t.length-1),e.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=e.autoLevelCapping}}},e.getMaxLevel=function(e){var r=this,i=this.hls.levels;if(!i.length)return-1;var n=i.filter((function(i,n){return t.isLevelAllowed(n,r.restrictedLevels)&&n<=e}));return this.clientRect=null,t.getMaxLevelByMediaSize(n,this.mediaWidth,this.mediaHeight)},e.startCapping=function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,this.hls.firstLevel=this.getMaxLevel(this.firstLevel),self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},e.stopCapping=function(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)},e.getDimensions=function(){if(this.clientRect)return this.clientRect;var t=this.media,e={width:0,height:0};if(t){var r=t.getBoundingClientRect();e.width=r.width,e.height=r.height,e.width||e.height||(e.width=r.right-r.left||t.width||0,e.height=r.bottom-r.top||t.height||0)}return this.clientRect=e,e},t.isLevelAllowed=function(t,e){return void 0===e&&(e=[]),-1===e.indexOf(t)},t.getMaxLevelByMediaSize=function(t,e,r){if(!t||!t.length)return-1;for(var i=function(t,e){return!e||(t.width!==e.width||t.height!==e.height)},n=t.length-1,s=0;s=e||a.height>=r)&&i(a,t[s+1])){n=s;break}}return n},s(t,[{key:"mediaWidth",get:function(){return this.getDimensions().width*t.contentScaleFactor}},{key:"mediaHeight",get:function(){return this.getDimensions().height*t.contentScaleFactor}}],[{key:"contentScaleFactor",get:function(){var t=1;try{t=self.devicePixelRatio}catch(e){}return t}}]),t}();e["default"]=a},"./src/controller/cmcd-controller.ts": /*!*******************************************!*\ !*** ./src/controller/cmcd-controller.ts ***! \*******************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return f}));var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../types/cmcd */"./src/types/cmcd.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts");function o(t,e){for(var r=0;r=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(t,e){if(t){if("string"===typeof t)return d(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(t,e):void 0}}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r-1?s+1:i.levels.length;e=i.levels.slice(0,a)}for(var o,l=u(e);!(o=l()).done;){var c=o.value;c.bitrate>r&&(r=c.bitrate)}return r>0?r:NaN},e.getBufferLength=function(t){var e=this.hls.media,r=t===n["CMCDObjectType"].AUDIO?this.audioBuffer:this.videoBuffer;if(!r||!e)return NaN;var i=s["BufferHelper"].bufferInfo(r,e.currentTime,this.config.maxBufferHole);return 1e3*i.len},e.createPlaylistLoader=function(){var t=this.config.pLoader,e=this.applyPlaylistData,r=t||this.config.loader;return function(){function t(t){this.loader=void 0,this.loader=new r(t)}var i=t.prototype;return i.destroy=function(){this.loader.destroy()},i.abort=function(){this.loader.abort()},i.load=function(t,r,i){e(t),this.loader.load(t,r,i)},l(t,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),t}()},e.createFragmentLoader=function(){var t=this.config.fLoader,e=this.applyFragmentData,r=t||this.config.loader;return function(){function t(t){this.loader=void 0,this.loader=new r(t)}var i=t.prototype;return i.destroy=function(){this.loader.destroy()},i.abort=function(){this.loader.abort()},i.load=function(t,r,i){e(t),this.loader.load(t,r,i)},l(t,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),t}()},t.uuid=function(){var t=URL.createObjectURL(new Blob),e=t.toString();return URL.revokeObjectURL(t),e.substr(e.lastIndexOf("/")+1)},t.serialize=function(t){for(var e,r=[],i=function(t){return!Number.isNaN(t)&&null!=t&&""!==t&&!1!==t},n=function(t){return Math.round(t)},s=function(t){return 100*n(t/100)},a=function(t){return encodeURIComponent(t)},o={br:n,d:n,bl:s,dl:s,mtp:s,nor:a,rtp:s,tb:n},l=Object.keys(t||{}).sort(),c=u(l);!(e=c()).done;){var d=e.value,h=t[d];if(i(h)&&(("v"!==d||1!==h)&&("pr"!=d||1!==h))){var f=o[d];f&&(h=f(h));var g=typeof h,v=void 0;v="ot"===d||"sf"===d||"st"===d?d+"="+h:"boolean"===g?d:"number"===g?d+"="+h:d+"="+JSON.stringify(h),r.push(v)}}return r.join(",")},t.toHeaders=function(e){for(var r=Object.keys(e),i={},n=["Object","Request","Session","Status"],s=[{},{},{},{}],a={br:0,d:0,ot:0,tb:0,bl:1,dl:1,mtp:1,nor:1,nrr:1,su:1,cid:2,pr:2,sf:2,sid:2,st:2,v:2,bs:3,rtp:3},o=0,l=r;ou)return void this.hls.trigger(i["Events"].ERROR,{type:n["ErrorTypes"].KEY_SYSTEM_ERROR,details:n["ErrorDetails"].KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0});var c=u-this._requestLicenseFailureCount+1;s["logger"].warn("Retrying license request, "+c+" attempts left"),this._requestLicense(r,a)}break}},e._generateLicenseRequestChallenge=function(t,e){switch(t.mediaKeySystemDomain){case a["KeySystems"].WIDEVINE:return e}throw new Error("unsupported key-system: "+t.mediaKeySystemDomain)},e._requestLicense=function(t,e){s["logger"].log("Requesting content license for key-system");var r=this._mediaKeysList[0];if(!r)return s["logger"].error("Fatal error: Media is encrypted but no key-system access has been obtained yet"),void this.hls.trigger(i["Events"].ERROR,{type:n["ErrorTypes"].KEY_SYSTEM_ERROR,details:n["ErrorDetails"].KEY_SYSTEM_NO_ACCESS,fatal:!0});try{var a=this.getLicenseServerUrl(r.mediaKeySystemDomain),o=this._createLicenseXhr(a,t,e);s["logger"].log("Sending license request to URL: "+a);var l=this._generateLicenseRequestChallenge(r,t);o.send(l)}catch(u){s["logger"].error("Failure requesting DRM license: "+u),this.hls.trigger(i["Events"].ERROR,{type:n["ErrorTypes"].KEY_SYSTEM_ERROR,details:n["ErrorDetails"].KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0})}},e.onMediaAttached=function(t,e){if(this._emeEnabled){var r=e.media;this._media=r,r.addEventListener("encrypted",this._onMediaEncrypted)}},e.onMediaDetached=function(){var t=this._media,e=this._mediaKeysList;t&&(t.removeEventListener("encrypted",this._onMediaEncrypted),this._media=null,this._mediaKeysList=[],Promise.all(e.map((function(t){if(t.mediaKeysSession)return t.mediaKeysSession.close().catch((function(){}))}))).then((function(){return t.setMediaKeys(null)})).catch((function(){})))},e.onManifestParsed=function(t,e){if(this._emeEnabled){var r=e.levels.map((function(t){return t.audioCodec})).filter((function(t){return!!t})),i=e.levels.map((function(t){return t.videoCodec})).filter((function(t){return!!t}));this._attemptKeySystemAccess(a["KeySystems"].WIDEVINE,r,i)}},l(t,[{key:"requestMediaKeySystemAccess",get:function(){if(!this._requestMediaKeySystemAccess)throw new Error("No requestMediaKeySystemAccess function configured");return this._requestMediaKeySystemAccess}}]),t}();e["default"]=h},"./src/controller/fps-controller.ts": /*!******************************************!*\ !*** ./src/controller/fps-controller.ts ***! \******************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=function(){function t(t){this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=t,this.registerListeners()}var e=t.prototype;return e.setStreamController=function(t){this.streamController=t},e.registerListeners=function(){this.hls.on(i["Events"].MEDIA_ATTACHING,this.onMediaAttaching,this)},e.unregisterListeners=function(){this.hls.off(i["Events"].MEDIA_ATTACHING,this.onMediaAttaching)},e.destroy=function(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null},e.onMediaAttaching=function(t,e){var r=this.hls.config;if(r.capLevelOnFPSDrop){var i=e.media instanceof self.HTMLVideoElement?e.media:null;this.media=i,i&&"function"===typeof i.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),r.fpsDroppedMonitoringPeriod)}},e.checkFPS=function(t,e,r){var s=performance.now();if(e){if(this.lastTime){var a=s-this.lastTime,o=r-this.lastDroppedFrames,l=e-this.lastDecodedFrames,u=1e3*o/a,c=this.hls;if(c.trigger(i["Events"].FPS_DROP,{currentDropped:o,currentDecoded:l,totalDroppedFrames:r}),u>0&&o>c.config.fpsDroppedMonitoringThreshold*l){var d=c.currentLevel;n["logger"].warn("drop FPS ratio greater than max allowed value for currentLevel: "+d),d>0&&(-1===c.autoLevelCapping||c.autoLevelCapping>=d)&&(d-=1,c.trigger(i["Events"].FPS_DROP_LEVEL_CAPPING,{level:d,droppedLevel:c.currentLevel}),c.autoLevelCapping=d,this.streamController.nextLevelSwitch())}}this.lastTime=s,this.lastDroppedFrames=r,this.lastDecodedFrames=e}},e.checkFPSInterval=function(){var t=this.media;if(t)if(this.isVideoPlaybackQualityAvailable){var e=t.getVideoPlaybackQuality();this.checkFPS(t,e.totalVideoFrames,e.droppedVideoFrames)}else this.checkFPS(t,t.webkitDecodedFrameCount,t.webkitDroppedFrameCount)},t}();e["default"]=s},"./src/controller/fragment-finders.ts": /*!********************************************!*\ !*** ./src/controller/fragment-finders.ts ***! \********************************************/ /*! exports provided: findFragmentByPDT, findFragmentByPTS, fragmentWithinToleranceTest, pdtWithinToleranceTest, findFragWithCC */function(t,e,r){"use strict";r.r(e),r.d(e,"findFragmentByPDT",(function(){return s})),r.d(e,"findFragmentByPTS",(function(){return a})),r.d(e,"fragmentWithinToleranceTest",(function(){return o})),r.d(e,"pdtWithinToleranceTest",(function(){return l})),r.d(e,"findFragWithCC",(function(){return u}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../utils/binary-search */"./src/utils/binary-search.ts");function s(t,e,r){if(null===e||!Array.isArray(t)||!t.length||!Object(i["isFiniteNumber"])(e))return null;var n=t[0].programDateTime;if(e<(n||0))return null;var s=t[t.length-1].endProgramDateTime;if(e>=(s||0))return null;r=r||0;for(var a=0;at&&r.start?-1:0}function l(t,e,r){var i=1e3*Math.min(e,r.duration+(r.deltaPTS?r.deltaPTS:0)),n=r.endProgramDateTime||0;return n-i>t}function u(t,e){return n["default"].search(t,(function(t){return t.cce?-1:0}))}},"./src/controller/fragment-tracker.ts": /*!********************************************!*\ !*** ./src/controller/fragment-tracker.ts ***! \********************************************/ /*! exports provided: FragmentState, FragmentTracker */function(t,e,r){"use strict";r.r(e),r.d(e,"FragmentState",(function(){return i})),r.d(e,"FragmentTracker",(function(){return a}));var i,n=r(/*! ../events */"./src/events.ts"),s=r(/*! ../types/loader */"./src/types/loader.ts");(function(t){t["NOT_LOADED"]="NOT_LOADED",t["BACKTRACKED"]="BACKTRACKED",t["APPENDING"]="APPENDING",t["PARTIAL"]="PARTIAL",t["OK"]="OK"})(i||(i={}));var a=function(){function t(t){this.activeFragment=null,this.activeParts=null,this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hls=t,this._registerListeners()}var e=t.prototype;return e._registerListeners=function(){var t=this.hls;t.on(n["Events"].BUFFER_APPENDED,this.onBufferAppended,this),t.on(n["Events"].FRAG_BUFFERED,this.onFragBuffered,this),t.on(n["Events"].FRAG_LOADED,this.onFragLoaded,this)},e._unregisterListeners=function(){var t=this.hls;t.off(n["Events"].BUFFER_APPENDED,this.onBufferAppended,this),t.off(n["Events"].FRAG_BUFFERED,this.onFragBuffered,this),t.off(n["Events"].FRAG_LOADED,this.onFragLoaded,this)},e.destroy=function(){this._unregisterListeners(),this.fragments=this.timeRanges=null},e.getAppendedFrag=function(t,e){if(e===s["PlaylistLevelType"].MAIN){var r=this.activeFragment,i=this.activeParts;if(!r)return null;if(i)for(var n=i.length;n--;){var a=i[n],o=a?a.end:r.appendedPTS;if(a.start<=t&&void 0!==o&&t<=o)return n>9&&(this.activeParts=i.slice(n-9)),a}else if(r.start<=t&&void 0!==r.appendedPTS&&t<=r.appendedPTS)return r}return this.getBufferedFrag(t,e)},e.getBufferedFrag=function(t,e){for(var r=this.fragments,i=Object.keys(r),n=i.length;n--;){var s=r[i[n]];if((null===s||void 0===s?void 0:s.body.type)===e&&s.buffered){var a=s.body;if(a.start<=t&&t<=a.end)return a}}return null},e.detectEvictedFragments=function(t,e,r){var i=this;Object.keys(this.fragments).forEach((function(n){var s=i.fragments[n];if(s)if(s.buffered){var a=s.range[t];a&&a.time.some((function(t){var r=!i.isTimeBuffered(t.startPTS,t.endPTS,e);return r&&i.removeFragment(s.body),r}))}else s.body.type===r&&i.removeFragment(s.body)}))},e.detectPartialFragments=function(t){var e=this,r=this.timeRanges,i=t.frag,n=t.part;if(r&&"initSegment"!==i.sn){var s=l(i),a=this.fragments[s];a&&(Object.keys(r).forEach((function(t){var s=i.elementaryStreams[t];if(s){var o=r[t],l=null!==n||!0===s.partial;a.range[t]=e.getBufferedTimes(i,n,l,o)}})),a.backtrack=a.loaded=null,Object.keys(a.range).length?a.buffered=!0:this.removeFragment(a.body))}},e.fragBuffered=function(t){var e=l(t),r=this.fragments[e];r&&(r.backtrack=r.loaded=null,r.buffered=!0)},e.getBufferedTimes=function(t,e,r,i){for(var n={time:[],partial:r},s=e?e.start:t.start,a=e?e.end:t.end,o=t.minEndPTS||a,l=t.maxStartPTS||s,u=0;u=c&&o<=d){n.time.push({startPTS:Math.max(s,i.start(u)),endPTS:Math.min(a,i.end(u))});break}if(sc)n.partial=!0,n.time.push({startPTS:Math.max(s,i.start(u)),endPTS:Math.min(a,i.end(u))});else if(a<=c)break}return n},e.getPartialFragment=function(t){var e,r,i,n=null,s=0,a=this.bufferPadding,l=this.fragments;return Object.keys(l).forEach((function(u){var c=l[u];c&&o(c)&&(r=c.body.start-a,i=c.body.end+a,t>=r&&t<=i&&(e=Math.min(t-r,i-t),s<=e&&(n=c.body,s=e)))})),n},e.getState=function(t){var e=l(t),r=this.fragments[e];return r?r.buffered?o(r)?i.PARTIAL:i.OK:r.backtrack?i.BACKTRACKED:i.APPENDING:i.NOT_LOADED},e.backtrack=function(t,e){var r=l(t),i=this.fragments[r];if(!i||i.backtrack)return null;var n=i.backtrack=e||i.loaded;return i.loaded=null,n},e.getBacktrackData=function(t){var e=l(t),r=this.fragments[e];if(r){var i,n=r.backtrack;if(null!==n&&void 0!==n&&null!==(i=n.payload)&&void 0!==i&&i.byteLength)return n;this.removeFragment(t)}return null},e.isTimeBuffered=function(t,e,r){for(var i,n,s=0;s=i&&e<=n)return!0;if(e<=i)return!1}return!1},e.onFragLoaded=function(t,e){var r=e.frag,i=e.part;if("initSegment"!==r.sn&&!r.bitrateTest&&!i){var n=l(r);this.fragments[n]={body:r,loaded:e,backtrack:null,buffered:!1,range:Object.create(null)}}},e.onBufferAppended=function(t,e){var r=this,i=e.frag,n=e.part,a=e.timeRanges;if(i.type===s["PlaylistLevelType"].MAIN)if(this.activeFragment=i,n){var o=this.activeParts;o||(this.activeParts=o=[]),o.push(n)}else this.activeParts=null;this.timeRanges=a,Object.keys(a).forEach((function(t){var e=a[t];if(r.detectEvictedFragments(t,e),!n)for(var s=0;st&&i.removeFragment(a)}}))},e.removeFragment=function(t){var e=l(t);t.stats.loaded=0,t.clearElementaryStreamInfo(),delete this.fragments[e]},e.removeAllFragments=function(){this.fragments=Object.create(null),this.activeFragment=null,this.activeParts=null},t}();function o(t){var e,r;return t.buffered&&((null===(e=t.range.video)||void 0===e?void 0:e.partial)||(null===(r=t.range.audio)||void 0===r?void 0:r.partial))}function l(t){return t.type+"_"+t.level+"_"+t.urlId+"_"+t.sn}},"./src/controller/gap-controller.ts": /*!******************************************!*\ !*** ./src/controller/gap-controller.ts ***! \******************************************/ /*! exports provided: STALL_MINIMUM_DURATION_MS, MAX_START_GAP_JUMP, SKIP_BUFFER_HOLE_STEP_SECONDS, SKIP_BUFFER_RANGE_START, default */function(t,e,r){"use strict";r.r(e),r.d(e,"STALL_MINIMUM_DURATION_MS",(function(){return o})),r.d(e,"MAX_START_GAP_JUMP",(function(){return l})),r.d(e,"SKIP_BUFFER_HOLE_STEP_SECONDS",(function(){return u})),r.d(e,"SKIP_BUFFER_RANGE_START",(function(){return c})),r.d(e,"default",(function(){return d}));var i=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),n=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../events */"./src/events.ts"),a=r(/*! ../utils/logger */"./src/utils/logger.ts"),o=250,l=2,u=.1,c=.05,d=function(){function t(t,e,r,i){this.config=void 0,this.media=void 0,this.fragmentTracker=void 0,this.hls=void 0,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=t,this.media=e,this.fragmentTracker=r,this.hls=i}var e=t.prototype;return e.destroy=function(){this.hls=this.fragmentTracker=this.media=null},e.poll=function(t){var e=this.config,r=this.media,n=this.stalled,s=r.currentTime,u=r.seeking,c=this.seeking&&!u,d=!this.seeking&&u;if(this.seeking=u,s===t){if((d||c)&&(this.stalled=null),!r.paused&&!r.ended&&0!==r.playbackRate&&i["BufferHelper"].getBuffered(r).length){var h=i["BufferHelper"].bufferInfo(r,s,0),f=h.len>0,g=h.nextStart||0;if(f||g){if(u){var v=h.len>l,p=!g||g-s>l&&!this.fragmentTracker.getPartialFragment(s);if(v||p)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var m,y=Math.max(g,h.start||0)-s,E=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,T=null===E||void 0===E||null===(m=E.details)||void 0===m?void 0:m.live,S=T?2*E.details.targetduration:l;if(y>0&&y<=S)return void this._trySkipBufferHole(null)}var b=self.performance.now();if(null!==n){var L=b-n;!u&&L>=o&&this._reportStall(h.len);var A=i["BufferHelper"].bufferInfo(r,s,e.maxBufferHole);this._tryFixBufferStall(A,L)}else this.stalled=b}}}else if(this.moved=!0,null!==n){if(this.stallReported){var D=self.performance.now()-n;a["logger"].warn("playback not stuck anymore @"+s+", after "+Math.round(D)+"ms"),this.stallReported=!1}this.stalled=null,this.nudgeRetry=0}},e._tryFixBufferStall=function(t,e){var r=this.config,i=this.fragmentTracker,n=this.media,s=n.currentTime,o=i.getPartialFragment(s);if(o){var l=this._trySkipBufferHole(o);if(l)return}t.len>r.maxBufferHole&&e>1e3*r.highBufferWatchdogPeriod&&(a["logger"].warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())},e._reportStall=function(t){var e=this.hls,r=this.media,i=this.stallReported;i||(this.stallReported=!0,a["logger"].warn("Playback stalling at @"+r.currentTime+" due to low buffer (buffer="+t+")"),e.trigger(s["Events"].ERROR,{type:n["ErrorTypes"].MEDIA_ERROR,details:n["ErrorDetails"].BUFFER_STALLED_ERROR,fatal:!1,buffer:t}))},e._trySkipBufferHole=function(t){for(var e=this.config,r=this.hls,o=this.media,l=o.currentTime,d=0,h=i["BufferHelper"].getBuffered(o),f=0;f=d&&l.05&&this.forwardBufferLength>1){var c=Math.min(2,Math.max(1,s)),d=Math.round(2/(1+Math.exp(-.75*o-this.edgeStalled))*20)/20;t.playbackRate=Math.min(c,Math.max(1,d))}else 1!==t.playbackRate&&0!==t.playbackRate&&(t.playbackRate=1)}}}}},e.estimateLiveEdge=function(){var t=this.levelDetails;return null===t?null:t.edge+t.age},e.computeLatency=function(){var t=this.estimateLiveEdge();return null===t?null:t-this.currentTime},o(t,[{key:"latency",get:function(){return this._latency||0}},{key:"maxLatency",get:function(){var t=this.config,e=this.levelDetails;return void 0!==t.liveMaxLatencyDuration?t.liveMaxLatencyDuration:e?t.liveMaxLatencyDurationCount*e.targetduration:0}},{key:"targetLatency",get:function(){var t=this.levelDetails;if(null===t)return null;var e=t.holdBack,r=t.partHoldBack,i=t.targetduration,n=this.config,s=n.liveSyncDuration,a=n.liveSyncDurationCount,o=n.lowLatencyMode,l=this.hls.userConfig,u=o&&r||e;(l.liveSyncDuration||l.liveSyncDurationCount||0===u)&&(u=void 0!==s?s:a*i);var c=i,d=1;return u+Math.min(this.stallCount*d,c)}},{key:"liveSyncPosition",get:function(){var t=this.estimateLiveEdge(),e=this.targetLatency,r=this.levelDetails;if(null===t||null===e||null===r)return null;var i=r.edge,n=t-e-this.edgeStalled,s=i-r.totalduration,a=i-(this.config.lowLatencyMode&&r.partTarget||r.targetduration);return Math.min(Math.max(s,n),a)}},{key:"drift",get:function(){var t=this.levelDetails;return null===t?1:t.drift}},{key:"edgeStalled",get:function(){var t=this.levelDetails;if(null===t)return 0;var e=3*(this.config.lowLatencyMode&&t.partTarget||t.targetduration);return Math.max(t.age-e,0)}},{key:"forwardBufferLength",get:function(){var t=this.media,e=this.levelDetails;if(!t||!e)return 0;var r=t.buffered.length;return r?t.buffered.end(r-1):e.edge-this.currentTime}}]),t}()},"./src/controller/level-controller.ts": /*!********************************************!*\ !*** ./src/controller/level-controller.ts ***! \********************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return p}));var i=r(/*! ../types/level */"./src/types/level.ts"),n=r(/*! ../events */"./src/events.ts"),s=r(/*! ../errors */"./src/errors.ts"),a=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 c(){return c=Object.assign||function(t){for(var e=1;e0){r=u[0].bitrate,u.sort((function(t,e){return t.bitrate-e.bitrate})),this._levels=u;for(var m=0;mthis.hls.config.fragLoadingMaxRetry&&(a=r.frag.level)):a=r.frag.level}break;case s["ErrorDetails"].LEVEL_LOAD_ERROR:case s["ErrorDetails"].LEVEL_LOAD_TIMEOUT:i&&(i.deliveryDirectives&&(l=!1),a=i.level),o=!0;break;case s["ErrorDetails"].REMUX_ALLOC_ERROR:a=r.level,o=!0;break}void 0!==a&&this.recoverLevel(r,a,o,l)}}},r.recoverLevel=function(t,e,r,i){var n=t.details,s=this._levels[e];if(s.loadError++,r){var a=this.retryLoadingOrFail(t);if(!a)return void(this.currentLevelIndex=-1);t.levelRetry=!0}if(i){var o=s.url.length;if(o>1&&s.loadError1){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}},r.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)}},r.onLevelLoaded=function(t,e){var r,i,n=e.level,s=e.details,a=this._levels[n];if(!a)return this.warn("Invalid level index "+n),void(null!==(i=e.deliveryDirectives)&&void 0!==i&&i.skip&&(s.deltaUpdateFailed=!0));n===this.currentLevelIndex?(0===a.fragmentError&&(a.loadError=0,this.retryCount=0),this.playlistLoaded(n,e,a.details)):null!==(r=e.deliveryDirectives)&&void 0!==r&&r.skip&&(s.deltaUpdateFailed=!0)},r.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,s=0;s0){var i=r.urlId,s=r.url[i];if(t)try{s=t.addDirectives(s)}catch(a){this.warn("Could not construct new URL with HLS Delivery Directives: "+a)}this.log("Attempt loading level index "+e+(t?" at sn "+t.msn+" part "+t.part:"")+" with URL-id "+i+" "+s),this.clearTimer(),this.hls.trigger(n["Events"].LEVEL_LOADING,{url:s,level:e,id:i,deliveryDirectives:t||null})}},r.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&&void 0!==r&&r.fragments&&r.fragments.forEach((function(t){t.level=e})),t}));this._levels=i,this.hls.trigger(n["Events"].LEVELS_UPDATED,{levels:i})},h(e,[{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:s["ErrorTypes"].OTHER_ERROR,details:s["ErrorDetails"].LEVEL_SWITCH_ERROR,level:t,fatal:i,reason:"invalid level idx"}),i)return;t=Math.min(t,r.length-1)}this.clearTimer();var a=this.currentLevelIndex,o=r[a],l=r[t];this.log("switching to level "+t+" from "+a),this.currentLevelIndex=t;var u=c({},l,{level:t,maxBitrate:l.maxBitrate,uri:l.uri,urlId:l.urlId});delete u._urlId,this.hls.trigger(n["Events"].LEVEL_SWITCHING,u);var d=l.details;if(!d||d.live){var h=this.switchParams(l.uri,null===o||void 0===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)}}]),e}(l["default"])},"./src/controller/level-helper.ts": /*!****************************************!*\ !*** ./src/controller/level-helper.ts ***! \****************************************/ /*! exports provided: addGroupId, assignTrackIdsByGroup, updatePTS, updateFragPTSDTS, mergeDetails, mapPartIntersection, mapFragmentIntersection, adjustSliding, addSliding, computeReloadInterval, getFragmentWithSN, getPartWith */function(t,e,r){"use strict";r.r(e),r.d(e,"addGroupId",(function(){return s})),r.d(e,"assignTrackIdsByGroup",(function(){return a})),r.d(e,"updatePTS",(function(){return o})),r.d(e,"updateFragPTSDTS",(function(){return u})),r.d(e,"mergeDetails",(function(){return c})),r.d(e,"mapPartIntersection",(function(){return d})),r.d(e,"mapFragmentIntersection",(function(){return h})),r.d(e,"adjustSliding",(function(){return f})),r.d(e,"addSliding",(function(){return g})),r.d(e,"computeReloadInterval",(function(){return v})),r.d(e,"getFragmentWithSN",(function(){return p})),r.d(e,"getPartWith",(function(){return m}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../utils/logger */"./src/utils/logger.ts");function s(t,e,r){switch(e){case"audio":t.audioGroupIds||(t.audioGroupIds=[]),t.audioGroupIds.push(r);break;case"text":t.textGroupIds||(t.textGroupIds=[]),t.textGroupIds.push(r);break}}function a(t){var e={};t.forEach((function(t){var r=t.groupId||"";t.id=e[r]=e[r]||0,e[r]++}))}function o(t,e,r){var i=t[e],n=t[r];l(i,n)}function l(t,e){var r=e.startPTS;if(Object(i["isFiniteNumber"])(r)){var n,s=0;e.sn>t.sn?(s=r-t.start,n=t):(s=t.start-r,n=e),n.duration!==s&&(n.duration=s)}else if(e.sn>t.sn){var a=t.cc===e.cc;a&&t.minEndPTS?e.start=t.start+(t.minEndPTS-t.start):e.start=t.start+t.duration}else e.start=Math.max(t.start-e.duration,0)}function u(t,e,r,s,a,o){var u=s-r;u<=0&&(n["logger"].warn("Fragment should have a positive duration",e),s=r+e.duration,o=a+e.duration);var c=r,d=s,h=e.startPTS,f=e.endPTS;if(Object(i["isFiniteNumber"])(h)){var g=Math.abs(h-r);Object(i["isFiniteNumber"])(e.deltaPTS)?e.deltaPTS=Math.max(g,e.deltaPTS):e.deltaPTS=g,c=Math.max(r,h),r=Math.min(r,h),a=Math.min(a,e.startDTS),d=Math.min(s,f),s=Math.max(s,f),o=Math.max(o,e.endDTS)}e.duration=s-r;var v=r-e.start;e.appendedPTS=s,e.start=e.startPTS=r,e.maxStartPTS=c,e.startDTS=a,e.endPTS=s,e.minEndPTS=d,e.endDTS=o;var p,m=e.sn;if(!t||mt.endSN)return 0;var y=m-t.startSN,E=t.fragments;for(E[y]=e,p=y;p>0;p--)l(E[p],E[p-1]);for(p=y;p=0;a--){var o=s[a].initSegment;if(o){r=o;break}}t.fragmentHint&&delete t.fragmentHint.endPTS;var l,c=0;if(h(t,e,(function(t,n){t.relurl&&(c=t.cc-n.cc),Object(i["isFiniteNumber"])(t.startPTS)&&Object(i["isFiniteNumber"])(t.endPTS)&&(n.start=n.startPTS=t.startPTS,n.startDTS=t.startDTS,n.appendedPTS=t.appendedPTS,n.maxStartPTS=t.maxStartPTS,n.endPTS=t.endPTS,n.endDTS=t.endDTS,n.minEndPTS=t.minEndPTS,n.duration=t.endPTS-t.startPTS,n.duration&&(l=n),e.PTSKnown=e.alignedSliding=!0),n.elementaryStreams=t.elementaryStreams,n.loader=t.loader,n.stats=t.stats,n.urlId=t.urlId,t.initSegment&&(n.initSegment=t.initSegment,r=t.initSegment)})),r){var g=e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments;g.forEach((function(t){var e;t.initSegment&&t.initSegment.relurl!==(null===(e=r)||void 0===e?void 0:e.relurl)||(t.initSegment=r)}))}if(e.skippedSegments&&(e.deltaUpdateFailed=e.fragments.some((function(t){return!t})),e.deltaUpdateFailed)){n["logger"].warn("[level-helper] Previous playlist missing segments skipped in delta playlist");for(var v=e.skippedSegments;v--;)e.fragments.shift();e.startSN=e.fragments[0].sn,e.startCC=e.fragments[0].cc}var p=e.fragments;if(c){n["logger"].warn("discontinuity sliding from playlist, take drift into account");for(var m=0;m=i.length||g(e,i[r].start)}function g(t,e){if(e){for(var r=t.fragments,i=t.skippedSegments;i0&&s<3*i,o=e.loading.end-e.loading.start,l=t.availabilityDelay;if(!1===t.updated)if(a){var u=333*t.misses;r=Math.max(Math.min(n,2*o),u),t.availabilityDelay=(t.availabilityDelay||0)+r}else r=n;else a?(l=Math.min(l||i/2,s),t.availabilityDelay=l,r=l+i-s):r=i-o;return Math.round(r)}function p(t,e,r){if(!t||!t.details)return null;var i=t.details,n=i.fragments[e-i.startSN];return n||(n=i.fragmentHint,n&&n.sn===e?n:e0&&-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},r.stopLoad=function(){this._forceStartLoad=!1,t.prototype.stopLoad.call(this)},r.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||void 0===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 s,a=self.performance.now(),o=this.retryDate;(!o||a>=o||null!==(s=this.media)&&void 0!==s&&s.seeking)&&(this.log("retryDate reached, switch back to IDLE state"),this.state=n["State"].IDLE);break;default:break}this.onTickEnd()},r.onTickEnd=function(){t.prototype.onTickEnd.call(this),this.checkBuffer(),this.checkFragmentChanged()},r.doTickIdle=function(){var t,e,r=this.hls,i=this.levelLastLoaded,s=this.levels,o=this.media,d=r.config,h=r.nextLoadLevel;if(null!==i&&(o||!this.startFragRequested&&d.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)&&s&&s[h]){var f=s[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.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:o,u["PlaylistLevelType"].MAIN);if(null!==v){var p=v.len,m=this.getMaxBufferLength(f.maxBitrate);if(!(p>=m)){if(this._streamEnded(v,g)){var y={};return this.altAudio&&(y.type="video"),this.hls.trigger(a["Events"].BUFFER_EOS,y),void(this.state=n["State"].ENDED)}var E=v.end,T=this.getNextFragment(E,g);if(this.couldBacktrack&&!this.fragPrevious&&T&&"initSegment"!==T.sn){var S=T.sn-g.startSN;S>1&&(T=g.fragments[S-1],this.fragmentTracker.removeFragment(T))}if(T&&this.fragmentTracker.getState(T)===l["FragmentState"].OK&&this.nextLoadPosition>E){var b=this.audioOnly&&!this.altAudio?c["ElementaryStreamTypes"].AUDIO:c["ElementaryStreamTypes"].VIDEO;this.afterBufferFlushed(o,b,u["PlaylistLevelType"].MAIN),T=this.getNextFragment(this.nextLoadPosition,g)}T&&(!T.initSegment||T.initSegment.data||this.bitrateTest||(T=T.initSegment),"identity"!==(null===(t=T.decryptdata)||void 0===t?void 0:t.keyFormat)||null!==(e=T.decryptdata)&&void 0!==e&&e.key?this.loadFragment(T,g,E):this.loadKey(T,g))}}}}},r.loadFragment=function(e,r,i){var n,s=this.fragmentTracker.getState(e);if(this.fragCurrent=e,s===l["FragmentState"].BACKTRACKED){var a=this.fragmentTracker.getBacktrackData(e);if(a)return this._handleFragmentLoadProgress(a),void this._handleFragmentLoadComplete(a);s=l["FragmentState"].NOT_LOADED}s===l["FragmentState"].NOT_LOADED||s===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)):s===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()},r.getAppendedFrag=function(t){var e=this.fragmentTracker.getAppendedFrag(t,u["PlaylistLevelType"].MAIN);return e&&"fragment"in e?e.fragment:e},r.getBufferedFrag=function(t){return this.fragmentTracker.getBufferedFrag(t,u["PlaylistLevelType"].MAIN)},r.followingBufferedFrag=function(t){return t?this.getBufferedFrag(t.end+.5):null},r.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},r.nextLevelSwitch=function(){var t=this.levels,e=this.media;if(null!==e&&void 0!==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=this.hls.nextLoadLevel,s=t[n],a=this.fragLastKbps;r=a&&this.fragCurrent?this.fragCurrent.duration*s.maxBitrate/(1e3*a)+1:0}else r=0;var o=this.getBufferedFrag(e.currentTime+r);if(o){var l=this.followingBufferedFrag(o);if(l){this.abortCurrentFrag();var u=l.maxStartPTS?l.maxStartPTS:l.start,c=l.duration,d=Math.max(o.end,u+Math.min(Math.max(c-this.config.maxFragLookUpTolerance,.5*c),.75*c));this.flushMainBuffer(d,Number.POSITIVE_INFINITY)}}}},r.abortCurrentFrag=function(){var t=this.fragCurrent;this.fragCurrent=null,null!==t&&void 0!==t&&t.loader&&t.loader.abort(),this.state===n["State"].KEY_LOADING&&(this.state=n["State"].IDLE),this.nextLoadPosition=this.getLoadPosition()},r.flushMainBuffer=function(e,r){t.prototype.flushMainBuffer.call(this,e,r,this.altAudio?"video":null)},r.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)},r.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)},r.onMediaPlaying=function(){this.tick()},r.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()},r.onManifestLoading=function(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(a["Events"].BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=this.stalled=!1,this.startPosition=this.lastCurrentTime=0,this.fragPlaying=null},r.onManifestParsed=function(t,e){var r,i=!1,n=!1;e.levels.forEach((function(t){r=t.audioCodec,r&&(-1!==r.indexOf("mp4a.40.2")&&(i=!0),-1!==r.indexOf("mp4a.40.5")&&(n=!0))})),this.audioCodecSwitch=i&&n&&!Object(s["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},r.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)}},r.onLevelLoaded=function(t,e){var r,i=this.levels,s=e.level,o=e.details,l=o.totalduration;if(i){this.log("Level "+s+" 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,u.loader.abort());var c=i[s],d=0;if(o.live||null!==(r=c.details)&&void 0!==r&&r.live){if(o.fragments[0]||(o.deltaUpdateFailed=!0),o.deltaUpdateFailed)return;d=this.alignPlaylists(o,c.details)}if(c.details=o,this.levelLastLoaded=s,this.hls.trigger(a["Events"].LEVEL_UPDATED,{details:o,level:s}),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,d),this.tick()}else this.warn("Levels were reset while loading level "+s)},r._handleFragmentLoadProgress=function(t){var e,r=t.frag,i=t.part,n=t.payload,s=this.levels;if(s){var a=s[r.level],o=a.details;if(o){var l=a.videoCodec,c=o.PTSKnown||!o.live,f=null===(e=r.initSegment)||void 0===e?void 0:e.data,g=this._getAudioCodec(a),v=this.transmuxer=this.transmuxer||new d["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,c,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")},r.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 s=this.fragCurrent;null!==s&&void 0!==s&&s.loader&&(this.log("Switching to main audio track, cancel main fragment load"),s.loader.abort()),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();var o=this.hls;r&&o.trigger(a["Events"].BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:"audio"}),o.trigger(a["Events"].AUDIO_TRACK_SWITCHED,{id:n})}},r.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()},r.onBufferCreated=function(t,e){var r,i,n=e.tracks,s=!1;for(var a in n){var o=n[a];if("main"===o.id){if(i=a,r=o,"video"===a){var l=n[a];l&&(this.videoBuffer=l.buffer)}}else s=!0}s&&r?(this.log("Alternate track found, use "+i+".buffered to schedule main fragment loading"),this.mediaBuffer=r.buffer):this.mediaBuffer=this.media},r.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 s=i?i.stats:r.stats;this.fragLastKbps=Math.round(8*s.total/(s.buffering.end-s.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,i)}},r.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()}break;default:break}},r.checkBuffer=function(){var t=this.media,e=this.gapController;if(t&&e&&t.readyState){var r=o["BufferHelper"].getBuffered(t);!this.loadedmetadata&&r.length?(this.loadedmetadata=!0,this.seekToStartPos()):e.poll(this.lastCurrentTime),this.lastCurrentTime=t.currentTime}},r.onFragLoadEmergencyAborted=function(){this.state=n["State"].IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()},r.onBufferFlushed=function(t,e){var r=e.type;if(r!==c["ElementaryStreamTypes"].AUDIO||this.audioOnly&&!this.altAudio){var i=(r===c["ElementaryStreamTypes"].VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(i,r,u["PlaylistLevelType"].MAIN)}},r.onLevelsUpdated=function(t,e){this.levels=e.levels},r.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},r.seekToStartPos=function(){var t=this.media,e=t.currentTime,r=this.startPosition;if(r>=0&&e0&&(s1&&!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){var i=this.fragPlaying,n=e.level;i&&e.sn===i.sn&&i.level===n&&e.urlId===i.urlId||(this.hls.trigger(a["Events"].FRAG_CHANGED,{frag:e}),i&&i.level===n||this.hls.trigger(a["Events"].LEVEL_SWITCHED,{level:n}),this.fragPlaying=e)}}},m(e,[{key:"nextLevel",get:function(){var t=this.nextBufferedFrag;return t?t.level:-1}},{key:"currentLevel",get:function(){var t=this.media;if(t){var e=this.getAppendedFrag(t.currentTime);if(e)return e.level}return-1}},{key:"nextBufferedFrag",get:function(){var t=this.media;if(t){var e=this.getAppendedFrag(t.currentTime);return this.followingBufferedFrag(e)}return null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}]),e}(n["default"])},"./src/controller/subtitle-stream-controller.ts": /*!******************************************************!*\ !*** ./src/controller/subtitle-stream-controller.ts ***! \******************************************************/ /*! exports provided: SubtitleStreamController */function(t,e,r){"use strict";r.r(e),r.d(e,"SubtitleStreamController",(function(){return y}));var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../utils/logger */"./src/utils/logger.ts"),s=r(/*! ../utils/buffer-helper */"./src/utils/buffer-helper.ts"),a=r(/*! ./fragment-finders */"./src/controller/fragment-finders.ts"),o=r(/*! ../utils/discontinuities */"./src/utils/discontinuities.ts"),l=r(/*! ./level-helper */"./src/controller/level-helper.ts"),u=r(/*! ./fragment-tracker */"./src/controller/fragment-tracker.ts"),c=r(/*! ./base-stream-controller */"./src/controller/base-stream-controller.ts"),d=r(/*! ../types/loader */"./src/types/loader.ts"),h=r(/*! ../types/level */"./src/types/level.ts");function f(t,e){for(var r=0;r=n[o].start&&a<=n[o].end){s=n[o];break}var l=r.start+r.duration;s?s.end=l:(s={start:a,end:l},n.push(s)),this.fragmentTracker.fragBuffered(r)}}},r.onBufferFlushing=function(t,e){var r=e.startOffset,i=e.endOffset;if(0===r&&i!==Number.POSITIVE_INFINITY){var n=this.currentTrackId,s=this.levels;if(!s.length||!s[n]||!s[n].details)return;var a=s[n].details,o=a.targetduration,l=i-o;if(l<=0)return;e.endOffsetSubtitles=Math.max(0,l),this.tracksBuffered.forEach((function(t){for(var e=0;e=u.length||n!==s)&&d){if(this.mediaBuffer=this.mediaBufferTimeRanges,i.live||null!==(r=d.details)&&void 0!==r&&r.live){var h=this.mainDetails;if(i.deltaUpdateFailed||!h)return;var f=h.fragments[0];if(d.details){var g=this.alignPlaylists(i,d.details);0===g&&f&&Object(l["addSliding"])(i,f.start)}else i.hasProgramDateTime&&h.hasProgramDateTime?Object(o["alignMediaPlaylistByPDT"])(i,h):f&&Object(l["addSliding"])(i,f.start)}if(d.details=i,this.levelLastLoaded=n,this.tick(),i.live&&!this.fragCurrent&&this.media&&this.state===c["State"].IDLE){var v=Object(a["findFragmentByPTS"])(null,i.fragments,this.media.currentTime,0);v||(this.warn("Subtitle playlist not aligned with playback"),d.details=void 0)}}}},r._handleFragmentLoadComplete=function(t){var e=t.frag,r=t.payload,n=e.decryptdata,s=this.hls;if(!this.fragContextChanged(e)&&r&&r.byteLength>0&&n&&n.key&&n.iv&&"AES-128"===n.method){var a=performance.now();this.decrypter.webCryptoDecrypt(new Uint8Array(r),n.key.buffer,n.iv.buffer).then((function(t){var r=performance.now();s.trigger(i["Events"].FRAG_DECRYPTED,{frag:e,payload:t,stats:{tstart:a,tdecrypt:r}})}))}},r.doTick=function(){if(this.media){if(this.state===c["State"].IDLE){var t,e=this.currentTrackId,r=this.levels;if(!r.length||!r[e]||!r[e].details)return;var o=r[e].details,l=o.targetduration,d=this.config,h=this.media,f=s["BufferHelper"].bufferedInfo(this.mediaBufferTimeRanges,h.currentTime-l,d.maxBufferHole),g=f.end,v=f.len,p=this.getMaxBufferLength()+l;if(v>p)return;console.assert(o,"Subtitle track details are defined on idle subtitle stream controller tick");var m,y=o.fragments,E=y.length,T=o.edge,S=this.fragPrevious;if(g-1&&(this.subtitleTrack=this.queuedDefaultTrack,this.queuedDefaultTrack=-1),this.useTextTrackPolling=!(this.media.textTracks&&"onchange"in this.media.textTracks),this.useTextTrackPolling?this.pollTrackChange(500):this.media.textTracks.addEventListener("change",this.asyncPollTrackChange))},r.pollTrackChange=function(t){self.clearInterval(this.subtitlePollingInterval),this.subtitlePollingInterval=self.setInterval(this.trackChangeListener,t)},r.onMediaDetaching=function(){if(this.media){self.clearInterval(this.subtitlePollingInterval),this.useTextTrackPolling||this.media.textTracks.removeEventListener("change",this.asyncPollTrackChange),this.trackId>-1&&(this.queuedDefaultTrack=this.trackId);var t=h(this.media.textTracks);t.forEach((function(t){Object(n["clearCurrentCues"])(t)})),this.subtitleTrack=-1,this.media=null}},r.onManifestLoading=function(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.selectDefaultTrack=!0},r.onManifestParsed=function(t,e){this.tracks=e.subtitleTracks},r.onSubtitleTrackLoaded=function(t,e){var r=e.id,i=e.details,n=this.trackId,s=this.tracksInGroup[n];if(s){var a=s.details;s.details=e.details,this.log("subtitle track "+r+" loaded ["+i.startSN+"-"+i.endSN+"]"),r===this.trackId&&(this.retryCount=0,this.playlistLoaded(r,e,a))}else this.warn("Invalid subtitle track id "+r)},r.onLevelLoading=function(t,e){this.switchLevel(e.level)},r.onLevelSwitching=function(t,e){this.switchLevel(e.level)},r.switchLevel=function(t){var e=this.hls.levels[t];if(null!==e&&void 0!==e&&e.textGroupIds){var r=e.textGroupIds[e.urlId];if(this.groupId!==r){var n=this.tracksInGroup?this.tracksInGroup[this.trackId]:void 0,s=this.tracks.filter((function(t){return!r||t.groupId===r}));this.tracksInGroup=s;var a=this.findTrackId(null===n||void 0===n?void 0:n.name)||this.findTrackId();this.groupId=r;var o={subtitleTracks:s};this.log("Updating subtitle tracks, "+s.length+' track(s) found in "'+r+'" group-id'),this.hls.trigger(i["Events"].SUBTITLE_TRACKS_UPDATED,o),-1!==a&&this.setSubtitleTrack(a,n)}}},r.findTrackId=function(t){for(var e=this.tracksInGroup,r=0;r=n.length)){this.clearTimer();var s=n[t];if(this.log("Switching to subtitle track "+t),this.trackId=t,s){var a=s.id,o=s.groupId,l=void 0===o?"":o,u=s.name,c=s.type,d=s.url;this.hls.trigger(i["Events"].SUBTITLE_TRACK_SWITCH,{id:a,groupId:l,name:u,type:c,url:d});var h=this.switchParams(s.url,null===e||void 0===e?void 0:e.details);this.loadPlaylist(h)}else this.hls.trigger(i["Events"].SUBTITLE_TRACK_SWITCH,{id:t})}}else this.queuedDefaultTrack=t},r.onTextTracksChanged=function(){if(this.useTextTrackPolling||self.clearInterval(this.subtitlePollingInterval),this.media&&this.hls.config.renderTextTracksNatively){for(var t=-1,e=h(this.media.textTracks),r=0;r=0&&(l[0]=Math.min(l[0],e),l[1]=Math.max(l[1],r),a=!0,u/(r-e)>.5))return}if(a||s.push([e,r]),this.config.renderTextTracksNatively){var c=this.captionsTracks[t];this.Cues.newCue(c,e,r,i)}else{var d=this.Cues.newCue(null,e,r,i);this.hls.trigger(n["Events"].CUES_PARSED,{type:"captions",cues:d,track:t})}},e.onInitPtsFound=function(t,e){var r=this,i=e.frag,s=e.id,a=e.initPTS,o=e.timescale,l=this.unparsedVttFrags;"main"===s&&(this.initPTS[i.cc]=a,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>>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,s[f]=T<<8|T>>>24,a[f]=T,T=16843009*E^65537*y^257*m^16843008*f,l[p]=T<<24|T>>>8,u[p]=T<<16|T>>>16,c[p]=T<<8|T>>>24,d[p]=T,f?(f=m^h[h[h[E^m]]],g^=h[h[g]]):f=g=1}},e.expandKey=function(t){var e=this.uint8ArrayToUint32Array_(t),r=!0,i=0;while(i>>6);var g=(60&e[r+2])>>>2;if(!(g>f.length-1))return u=(1&e[r+2])<<2,u|=(192&e[r+3])>>>6,i["logger"].log("manifest codec:"+a+", ADTS type:"+o+", samplingIndex:"+g),/firefox/i.test(d)?g>=6?(o=5,c=new Array(4),l=g-3):(o=2,c=new Array(2),l=g):-1!==d.indexOf("android")?(o=2,c=new Array(2),l=g):(o=5,c=new Array(4),a&&(-1!==a.indexOf("mp4a.40.29")||-1!==a.indexOf("mp4a.40.5"))||!a&&g>=6?l=g-3:((a&&-1!==a.indexOf("mp4a.40.2")&&(g>=6&&1===u||/vivaldi/i.test(d))||!a&&1===u)&&(o=2,c=new Array(2)),l=g)),c[0]=o<<3,c[0]|=(14&g)>>1,c[1]|=(1&g)<<7,c[1]|=u<<3,5===o&&(c[1]|=(14&l)>>1,c[2]=(1&l)<<7,c[2]|=8,c[3]=0),{config:c,samplerate:f[g],channelCount:u,codec:"mp4a.40."+o,manifestCodec:h};t.trigger(s["Events"].ERROR,{type:n["ErrorTypes"].MEDIA_ERROR,details:n["ErrorDetails"].FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+g})}function o(t,e){return 255===t[e]&&240===(246&t[e+1])}function l(t,e){return 1&t[e+1]?7:9}function u(t,e){return(3&t[e+3])<<11|t[e+4]<<3|(224&t[e+5])>>>5}function c(t,e){return e+5=t.length)return!1;var i=u(t,e);if(i<=r)return!1;var n=e+i;return n===t.length||d(t,n)}return!1}function g(t,e,r,n,s){if(!t.samplerate){var o=a(e,r,n,s);if(!o)return;t.config=o.config,t.samplerate=o.samplerate,t.channelCount=o.channelCount,t.codec=o.codec,t.manifestCodec=o.manifestCodec,i["logger"].log("parsed codec:"+t.codec+", rate:"+o.samplerate+", channels:"+o.channelCount)}}function v(t){return 9216e4/t}function p(t,e,r,i,n){var s=l(t,e),a=u(t,e);if(a-=s,a>0){var o=r+i*n;return{headerLength:s,frameLength:a,stamp:o}}}function m(t,e,r,i,n){var s=v(t.samplerate),a=p(e,r,i,n,s);if(a){var o,l=a.frameLength,u=a.headerLength,c=a.stamp,d=u+l,h=Math.max(0,r+d-e.length);h?(o=new Uint8Array(d-u),o.set(e.subarray(r+u,e.length),0)):o=e.subarray(r+u,r+d);var f={unit:o,pts:c};return h||t.samples.push(f),{sample:f,length:d,missing:h}}}},"./src/demux/base-audio-demuxer.ts": /*!*****************************************!*\ !*** ./src/demux/base-audio-demuxer.ts ***! \*****************************************/ /*! exports provided: initPTSFn, default */function(t,e,r){"use strict";r.r(e),r.d(e,"initPTSFn",(function(){return u}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../demux/id3 */"./src/demux/id3.ts"),s=r(/*! ./dummy-demuxed-track */"./src/demux/dummy-demuxed-track.ts"),a=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),o=r(/*! ../utils/typed-array */"./src/utils/typed-array.ts"),l=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){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(a["appendUint8Array"])(this.cachedData,t),this.cachedData=null);var r,i,l=n["getID3Data"](t,0),c=l?l.length:0,d=this._audioTrack,h=this._id3Track,f=l?n["getTimeStamp"](l):void 0,g=t.length;0!==this.frameIndex&&null!==this.initPTS||(this.initPTS=u(f,e)),l&&l.length>0&&h.samples.push({pts:this.initPTS,dts:this.initPTS,data:l}),i=this.initPTS;while(ct?(this.word<<=t,this.bitsAvailable-=t):(t-=this.bitsAvailable,e=t>>3,t-=e>>3,this.bytesAvailable-=e,this.loadWord(),this.word<<=t,this.bitsAvailable-=t)},e.readBits=function(t){var e=Math.min(this.bitsAvailable,t),r=this.word>>>32-e;return t>32&&i["logger"].error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=e,this.bitsAvailable>0?this.word<<=e:this.bytesAvailable>0&&this.loadWord(),e=t-e,e>0&&this.bitsAvailable?r<>>t))return this.word<<=t,this.bitsAvailable-=t,t;return this.loadWord(),t+this.skipLZ()},e.skipUEG=function(){this.skipBits(1+this.skipLZ())},e.skipEG=function(){this.skipBits(1+this.skipLZ())},e.readUEG=function(){var t=this.skipLZ();return this.readBits(t+1)-1},e.readEG=function(){var t=this.readUEG();return 1&t?1+t>>>1:-1*(t>>>1)},e.readBoolean=function(){return 1===this.readBits(1)},e.readUByte=function(){return this.readBits(8)},e.readUShort=function(){return this.readBits(16)},e.readUInt=function(){return this.readBits(32)},e.skipScalingList=function(t){for(var e,r=8,i=8,n=0;n0)return t.subarray(r,r+i)},o=function(t,e){var r=0;return r=(127&t[e])<<21,r|=(127&t[e+1])<<14,r|=(127&t[e+2])<<7,r|=127&t[e+3],r},l=function(t,e){return n(t,e)&&o(t,e+6)+10<=t.length-e},u=function(t){for(var e=h(t),r=0;r>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:u+=String.fromCharCode(s);break;case 12:case 13:a=t[c++],u+=String.fromCharCode((31&s)<<6|63&a);break;case 14:a=t[c++],o=t[c++],u+=String.fromCharCode((15&s)<<12|(63&a)<<6|(63&o)<<0);break;default:}}return u},E={decodeTextFrame:v};function T(){return i||"undefined"===typeof self.TextDecoder||(i=new self.TextDecoder("utf-8")),i}},"./src/demux/mp3demuxer.ts": /*!*********************************!*\ !*** ./src/demux/mp3demuxer.ts ***! \*********************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=r(/*! ./base-audio-demuxer */"./src/demux/base-audio-demuxer.ts"),n=r(/*! ../demux/id3 */"./src/demux/id3.ts"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),a=r(/*! ./mpegaudio */"./src/demux/mpegaudio.ts");function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,l(t,e)}function l(t,e){return l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},l(t,e)}var u=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var r=e.prototype;return r.resetInitSegment=function(e,r,i){t.prototype.resetInitSegment.call(this,e,r,i),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,isAAC:!1,samples:[],manifestCodec:e,duration:i,inputTimeScale:9e4,dropped:0}},e.probe=function(t){if(!t)return!1;for(var e=n["getID3Data"](t,0)||[],r=e.length,i=t.length;r0},e.demux=function(t){var e=t,r=Object(n["dummyTrack"])();if(this.config.progressive){this.remainderData&&(e=Object(i["appendUint8Array"])(this.remainderData,t));var s=Object(i["segmentValidRange"])(e);this.remainderData=s.remainder,r.samples=s.valid||new Uint8Array}else r.samples=e;return{audioTrack:Object(n["dummyTrack"])(),avcTrack:r,id3Track:Object(n["dummyTrack"])(),textTrack:Object(n["dummyTrack"])()}},e.flush=function(){var t=Object(n["dummyTrack"])();return t.samples=this.remainderData||new Uint8Array,this.remainderData=null,{audioTrack:Object(n["dummyTrack"])(),avcTrack:t,id3Track:Object(n["dummyTrack"])(),textTrack:Object(n["dummyTrack"])()}},e.demuxSampleAes=function(t,e,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},e.destroy=function(){},t}();s.minProbeByteLength=1024,e["default"]=s},"./src/demux/mpegaudio.ts": /*!********************************!*\ !*** ./src/demux/mpegaudio.ts ***! \********************************/ /*! exports provided: appendFrame, parseHeader, isHeaderPattern, isHeader, canParse, probe */function(t,e,r){"use strict";r.r(e),r.d(e,"appendFrame",(function(){return l})),r.d(e,"parseHeader",(function(){return u})),r.d(e,"isHeaderPattern",(function(){return c})),r.d(e,"isHeader",(function(){return d})),r.d(e,"canParse",(function(){return h})),r.d(e,"probe",(function(){return f}));var i=null,n=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],s=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],a=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],o=[0,1,1,4];function l(t,e,r,i,n){if(!(r+24>e.length)){var s=u(e,r);if(s&&r+s.frameLength<=e.length){var a=9e4*s.samplesPerFrame/s.sampleRate,o=i+n*a,l={unit:e.subarray(r,r+s.frameLength),pts:o,dts:o};return t.config=[],t.channelCount=s.channelCount,t.samplerate=s.sampleRate,t.samples.push(l),{sample:l,length:s.frameLength,missing:0}}}}function u(t,e){var r=t[e+1]>>3&3,l=t[e+1]>>1&3,u=t[e+2]>>4&15,c=t[e+2]>>2&3;if(1!==r&&0!==u&&15!==u&&3!==c){var d=t[e+2]>>1&1,h=t[e+3]>>6,f=3===r?3-l:3===l?3:4,g=1e3*n[14*f+u-1],v=3===r?0:2===r?1:2,p=s[3*v+c],m=3===h?1:2,y=a[r][l],E=o[l],T=8*y*E,S=Math.floor(y*g/p+d)*E;if(null===i){var b=navigator.userAgent||"",L=b.match(/Chrome\/(\d+)/i);i=L?parseInt(L[1]):0}var A=!!i&&i<=87;return A&&2===l&&g>=224e3&&0===h&&(t[e+3]=128|t[e+3]),{sampleRate:p,channelCount:m,frameLength:S,samplesPerFrame:T}}}function c(t,e){return 255===t[e]&&224===(224&t[e+1])&&0!==(6&t[e+1])}function d(t,e){return e+1=t.length)return void r();if(!(t[e].unit.length<32)){var i=this.decrypter.isSync();if(this.decryptAacSample(t,e,r,i),!i)return}}},e.getAvcEncryptedData=function(t){for(var e=16*Math.floor((t.length-48)/160)+16,r=new Int8Array(e),i=0,n=32;n=t.length)return void i();for(var n=t[e].units;;r++){if(r>=n.length)break;var s=n[r];if(!(s.data.length<=48||1!==s.type&&5!==s.type)){var a=this.decrypter.isSync();if(this.decryptAvcSample(t,e,r,i,s,a),!a)return}}}},t}();e["default"]=s},"./src/demux/transmuxer-interface.ts": /*!*******************************************!*\ !*** ./src/demux/transmuxer-interface.ts ***! \*******************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return d}));var i=r(/*! webworkify-webpack */"./node_modules/webworkify-webpack/index.js"),n=r(/*! ../events */"./src/events.ts"),s=r(/*! ../demux/transmuxer */"./src/demux/transmuxer.ts"),a=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"),c=Object(l["getMediaSource"])()||{isTypeSupported:function(){return!1}},d=function(){function t(t,e,r,l){var d=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||{},r.frag=d.frag,r.id=d.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:c.isTypeSupported("video/mp4"),mpeg:c.isTypeSupported("audio/mpeg"),mp3:c.isTypeSupported('audio/mp4; codecs="mp3"')},v=navigator.vendor;if(h.enableWorker&&"undefined"!==typeof Worker){var p;a["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(m){a["logger"].warn("Error in worker:",m),a["logger"].error("Error while initializing DemuxerWorker, fallback to inline"),p&&self.URL.revokeObjectURL(p.objectURL),this.transmuxer=new s["default"](this.observer,g,h,v,e),this.worker=null}}else this.transmuxer=new s["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;else{var e=this.transmuxer;e&&(e.destroy(),this.transmuxer=null)}var r=this.observer;r&&r.removeAllListeners(),this.observer=null},e.push=function(t,e,r,i,n,o,l,u,c,d){var h,f,g=this;c.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&&c.level===E.level),b=E?c.sn-E.sn:-1,L=this.part?c.part-this.part.index:1,A=!S&&(1===b||0===b&&1===L),D=self.performance.now();(S||b||0===n.stats.parsing.start)&&(n.stats.parsing.start=D),!o||!L&&A||(o.stats.parsing.start=D);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)),R=new s["TransmuxState"](T,A,u,S,m,k);if(!A||T||k){a["logger"].log("[transmuxer-interface, "+n.type+"]: Starting new transmux session for sn: "+c.sn+" p: "+c.part+" level: "+c.level+" id: "+c.id+"\n discontinuity: "+T+"\n trackSwitch: "+S+"\n contiguous: "+A+"\n accurateTimeOffset: "+u+"\n timeOffset: "+m+"\n initSegmentChange: "+k);var I=new s["TransmuxConfig"](r,i,e,l,d);this.configureTransmuxer(I)}if(this.frag=n,this.part=o,p)p.postMessage({cmd:"demux",data:t,decryptdata:y,chunkMeta:c,state:R},t instanceof ArrayBuffer?[t]:[]);else if(v){var _=v.push(t,y,c,R);Object(s["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(s["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);break}},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": /*!****************************************!*\ !*** ./src/demux/transmuxer-worker.ts ***! \****************************************/ /*! exports provided: default */function(t,e,r){"use strict";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"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),a=r(/*! eventemitter3 */"./node_modules/eventemitter3/index.js");function o(t){var e=new a["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 a=n.data;switch(a.cmd){case"init":var o=JSON.parse(a.config);t.transmuxer=new i["default"](e,a.typeSupported,o,a.vendor,a.id),Object(s["enableLogs"])(o.debug),r("init",null);break;case"configure":t.transmuxer.configure(a.config);break;case"demux":var u=t.transmuxer.push(a.data,a.decryptdata,a.chunkMeta,a.state);Object(i["isPromise"])(u)?u.then((function(e){l(t,e)})):l(t,u);break;case"flush":var d=a.chunkMeta,h=t.transmuxer.flush(d);Object(i["isPromise"])(h)?h.then((function(e){c(t,e,d)})):c(t,h,d);break;default:break}}))}function l(t,e){if(!d(e.remuxResult)){var r=[],i=e.remuxResult,n=i.audio,s=i.video;n&&u(r,n),s&&u(r,s),t.postMessage({event:"transmuxComplete",data:e},r)}}function u(t,e){e.data1&&t.push(e.data1.buffer),e.data2&&t.push(e.data2.buffer)}function c(t,e,r){e.forEach((function(e){l(t,e)})),t.postMessage({event:"flush",data:r})}function d(t){return!t.audio&&!t.video&&!t.text&&!t.id3&&!t.initSegment}},"./src/demux/transmuxer.ts": /*!*********************************!*\ !*** ./src/demux/transmuxer.ts ***! \*********************************/ /*! exports provided: default, isPromise, TransmuxConfig, TransmuxState */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return y})),r.d(e,"isPromise",(function(){return S})),r.d(e,"TransmuxConfig",(function(){return b})),r.d(e,"TransmuxState",(function(){return L}));var i,n=r(/*! ../events */"./src/events.ts"),s=r(/*! ../errors */"./src/errors.ts"),a=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"),c=r(/*! ../demux/mp3demuxer */"./src/demux/mp3demuxer.ts"),d=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(A){v["logger"].debug("Unable to use Performance API on this environment"),i=self.Date.now}var p=[{demux:u["default"],remux:d["default"]},{demux:l["default"],remux:h["default"]},{demux:o["default"],remux:d["default"]},{demux:c["default"],remux:d["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 s=this,a=r.transmuxing;a.executeStart=i();var o=new Uint8Array(t),l=this.cache,u=this.config,c=this.currentTransmuxState,d=this.transmuxConfig;n&&(this.currentTransmuxState=n);var h=E(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=s.push(t,null,r);return s.decryptionPromise=null,e})),this.decryptionPromise;var v=f.softwareDecrypt(o,h.key.buffer,h.iv.buffer);if(!v)return a.executeEnd=i(),T(r);o=new Uint8Array(v)}var p=n||c,m=p.contiguous,y=p.discontinuity,S=p.trackSwitch,b=p.accurateTimeOffset,L=p.timeOffset,A=p.initSegmentChange,D=d.audioCodec,k=d.videoCodec,R=d.defaultInitPts,I=d.duration,_=d.initSegmentData;if((y||S||A)&&this.resetInitSegment(_,D,k,I),(y||A)&&this.resetInitialTimestamp(R),m||this.resetContiguity(),this.needsProbing(o,y,S)){if(l.dataLength){var C=l.flush();o=Object(g["appendUint8Array"])(C,o)}this.configureTransmuxer(o,d)}var O=this.transmux(o,h,L,b,r),w=this.currentTransmuxState;return w.contiguous=!0,w.discontinuity=!1,w.trackSwitch=!1,a.executeEnd=i(),O},e.flush=function(t){var e=this,r=t.transmuxing;r.executeStart=i();var a=this.decrypter,o=this.cache,l=this.currentTransmuxState,u=this.decryptionPromise;if(u)return u.then((function(){return e.flush(t)}));var c=[],d=l.timeOffset;if(a){var h=a.flush();h&&c.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:s["ErrorTypes"].MEDIA_ERROR,details:s["ErrorDetails"].FRAG_PARSING_ERROR,fatal:!0,reason:"no demux matching with content found"}),r.executeEnd=i(),[T(t)];var p=g.flush(d);return S(p)?p.then((function(r){return e.flushRemux(c,r,t),c})):(this.flushRemux(c,p,t),c)},e.flushRemux=function(t,e,r){var n=e.audioTrack,s=e.avcTrack,a=e.id3Track,o=e.textTrack,l=this.currentTransmuxState,u=l.accurateTimeOffset,c=l.timeOffset;v["logger"].log("[transmuxer.ts]: Flushed fragment "+r.sn+(r.part>-1?" p: "+r.part:"")+" of level "+r.level);var d=this.remuxer.remux(n,s,a,o,c,u,!0,this.id);t.push({remuxResult:d,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,s=this.remuxer;n&&s&&(n.resetInitSegment(e,r,i),s.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){var s;return s=e&&"SAMPLE-AES"===e.method?this.transmuxSampleAes(t,e,r,i,n):this.transmuxUnencrypted(t,r,i,n),s},e.transmuxUnencrypted=function(t,e,r,i){var n=this.demuxer.demux(t,e,!1,!this.config.progressive),s=n.audioTrack,a=n.avcTrack,o=n.id3Track,l=n.textTrack,u=this.remuxer.remux(s,a,o,l,e,r,!1,this.id);return{remuxResult:u,chunkMeta:i}},e.transmuxSampleAes=function(t,e,r,i,n){var s=this;return this.demuxer.demuxSampleAes(t,e,r).then((function(t){var e=s.remuxer.remux(t.audioTrack,t.avcTrack,t.id3Track,t.textTrack,r,i,!1,s.id);return{remuxResult:e,chunkMeta:n}}))},e.configureTransmuxer=function(t,e){for(var r,i=this.config,n=this.observer,s=this.typeSupported,a=this.vendor,o=e.audioCodec,u=e.defaultInitPts,c=e.duration,d=e.initSegmentData,f=e.videoCodec,g=0,m=p.length;g0&&null!=e&&null!=e.key&&null!==e.iv&&null!=e.method&&(r=e),r}var T=function(t){return{remuxResult:{},chunkMeta:t}};function S(t){return"then"in t&&t.then instanceof Function}var b=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},L=function(t,e,r,i,n,s){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=s}},"./src/demux/tsdemuxer.ts": /*!********************************!*\ !*** ./src/demux/tsdemuxer.ts ***! \********************************/ /*! exports provided: discardEPB, default */function(t,e,r){"use strict";r.r(e),r.d(e,"discardEPB",(function(){return T}));var i=r(/*! ./adts */"./src/demux/adts.ts"),n=r(/*! ./mpegaudio */"./src/demux/mpegaudio.ts"),s=r(/*! ./exp-golomb */"./src/demux/exp-golomb.ts"),a=r(/*! ./id3 */"./src/demux/id3.ts"),o=r(/*! ./sample-aes */"./src/demux/sample-aes.ts"),l=r(/*! ../events */"./src/events.ts"),u=r(/*! ../utils/mp4-tools */"./src/utils/mp4-tools.ts"),c=r(/*! ../utils/logger */"./src/utils/logger.ts"),d=r(/*! ../errors */"./src/errors.ts"),h={video:1,audio:2,id3:3,text:4},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.aacLastPTS=null,this._initPTS=null,this._initDTS=null,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&&c["logger"].warn("MPEG2-TS detected but first sync word found @ offset "+r+", junk ahead ?"),!0)},t.syncOffset=function(t){var e=Math.min(1e3,t.length-564),r=0;while(r>4,w=void 0;if(O>1){if(w=I+5+e[I+4],w===I+188)continue}else w=I+4;switch(C){case f:_&&(g&&(s=m(g))&&this.parseAVCPES(s,!1),g={data:[],size:0}),g&&(g.data.push(e.subarray(w,I+188)),g.size+=I+188-w);break;case y:_&&(T&&(s=m(T))&&(o.isAAC?this.parseAACPES(s):this.parseMPEGPES(s)),T={data:[],size:0}),T&&(T.data.push(e.subarray(w,I+188)),T.size+=I+188-w);break;case E:_&&(S&&(s=m(S))&&this.parseID3PES(s),S={data:[],size:0}),S&&(S.data.push(e.subarray(w,I+188)),S.size+=I+188-w);break;case 0:_&&(w+=e[w]+1),A=this._pmtId=v(e,w);break;case A:_&&(w+=e[w]+1);var x=p(e,w,!0===this.typeSupported.mpeg||!0===this.typeSupported.mp3,i);f=x.avc,f>0&&(a.pid=f),y=x.audio,y>0&&(o.pid=y,o.isAAC=x.isAAC),E=x.id3,E>0&&(h.pid=E),b&&!L&&(c["logger"].log("reparse from beginning"),b=!1,I=k-188),L=this.pmtParsed=!0;break;case 17:case 8191:break;default:b=!0;break}}else R++;R>0&&this.observer.emit(l["Events"].ERROR,l["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,o.pesData=T,h.pesData=S;var P={audioTrack:o,avcTrack:a,id3Track:h,textTrack:this._txtTrack};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):{audioTrack:this._audioTrack,avcTrack:this._avcTrack,textTrack:this._txtTrack,id3Track:this._id3Track},this.extractRemainingSamples(t),this.sampleAes?this.decrypt(t,this.sampleAes):t},e.extractRemainingSamples=function(t){var e,r=t.audioTrack,i=t.avcTrack,n=t.id3Track,s=i.pesData,a=r.pesData,o=n.pesData;s&&(e=m(s))?(this.parseAVCPES(e,!0),i.pesData=null):i.pesData=s,a&&(e=m(a))?(r.isAAC?this.parseAACPES(e):this.parseMPEGPES(e),r.pesData=null):(null!==a&&void 0!==a&&a.size&&c["logger"].log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=a),o&&(e=m(o))?(this.parseID3PES(e),n.pesData=null):n.pesData=o},e.demuxSampleAes=function(t,e,r){var i=this.demux(t,r,!0,!this.config.progressive),n=this.sampleAes=new o["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.avcTrack;i.samples&&i.isAAC?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._initPTS=this._initDTS=null,this._duration=0},e.parseAVCPES=function(t,e){var r,i=this,n=this._avcTrack,o=this.parseAVCNALu(t.data),l=!1,u=this.avcSample,c=!1;t.data=null,u&&o.length&&!n.audFound&&(y(u,n),u=this.avcSample=g(!1,t.pts,t.dts,"")),o.forEach((function(e){switch(e.type){case 1:r=!0,u||(u=i.avcSample=g(!0,t.pts,t.dts,"")),l&&(u.debug+="NDR "),u.frame=!0;var o=e.data;if(c&&o.length>4){var d=new s["default"](o).readSliceType();2!==d&&4!==d&&7!==d&&9!==d||(u.key=!0)}break;case 5:r=!0,u||(u=i.avcSample=g(!0,t.pts,t.dts,"")),l&&(u.debug+="IDR "),u.key=!0,u.frame=!0;break;case 6:r=!0,l&&u&&(u.debug+="SEI ");var h=new s["default"](T(e.data));h.readUByte();var f=0,v=0,p=!1,m=0;while(!p&&h.bytesAvailable>1){f=0;do{m=h.readUByte(),f+=m}while(255===m);v=0;do{m=h.readUByte(),v+=m}while(255===m);if(4===f&&0!==h.bytesAvailable){p=!0;var S=h.readUByte();if(181===S){var b=h.readUShort();if(49===b){var L=h.readUInt();if(1195456820===L){var A=h.readUByte();if(3===A){for(var D=h.readUByte(),k=h.readUByte(),R=31&D,I=[D,k],_=0;_16){for(var C=[],O=0;O<16;O++)C.push(h.readUByte().toString(16)),3!==O&&5!==O&&7!==O&&9!==O||C.push("-");for(var w=v-16,x=new Uint8Array(w),P=0;P=0){var h={data:t.subarray(c,u-a-1),type:d};l.push(h)}else{var f=this.getLastNalUnit();if(f&&(o&&u<=4-o&&f.state&&(f.data=f.data.subarray(0,f.data.byteLength-o)),r=u-a-1,r>0)){var g=new Uint8Array(f.data.byteLength+r);g.set(f.data,0),g.set(t.subarray(0,r),f.data.byteLength),f.data=g,f.state=0}}u=0&&a>=0){var v={data:t.subarray(c,n),type:d,state:a};l.push(v)}if(0===l.length){var p=this.getLastNalUnit();if(p){var m=new Uint8Array(p.data.byteLength+t.byteLength);m.set(p.data,0),m.set(t,p.data.byteLength),p.data=m}}return s.naluState=a,l},e.parseAACPES=function(t){var e,r,n,s,a,o=0,u=this._audioTrack,h=this.aacOverFlow,f=t.data;if(h){this.aacOverFlow=null;var g=h.sample.unit.byteLength,v=Math.min(h.missing,g),p=g-v;h.sample.unit.set(f.subarray(0,v),p),u.samples.push(h.sample),o=h.missing}for(e=o,r=f.length;e1){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)}e=o[0];var u=(e[0]<<16)+(e[1]<<8)+e[2];if(1===u){if(r=(e[4]<<8)+e[5],r&&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?(s=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2,n-s>54e5&&(c["logger"].warn(Math.round((n-s)/9e4)+"s delta between PTS and DTS, align them"),n=s)):s=n),i=e[8];var h=i+9;if(t.size<=h)return null;t.size-=h;for(var f=new Uint8Array(t.size),g=0,v=o.length;gp){h-=p;continue}e=e.subarray(h),p-=h,h=0}f.set(e,a),a+=p}return r&&(r-=i+3),{data:f,pts:n,dts:s,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&&c["logger"].log(t.pts+"/"+t.dts+":"+t.debug)}function E(t,e){var r=t.length;if(r>0){if(e.pts>=t[r-1].pts)t.push(e);else for(var i=r-1;i>=0;i--)if(e.ptse)return i;return 0}},{key:"maxAutoLevel",get:function(){var t,e=this.levels,r=this.autoLevelCapping;return t=-1===r&&e&&e.length?e.length-1:r,t}},{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:"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}}],[{key:"version",get:function(){return"1.1.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}}]),t}();E.defaultConfig=void 0},"./src/is-supported.ts": /*!*****************************!*\ !*** ./src/is-supported.ts ***! \*****************************/ /*! exports provided: isSupported, changeTypeSupported */function(t,e,r){"use strict";r.r(e),r.d(e,"isSupported",(function(){return s})),r.d(e,"changeTypeSupported",(function(){return a}));var i=r(/*! ./utils/mediasource-helper */"./src/utils/mediasource-helper.ts");function n(){return self.SourceBuffer||self.WebKitSourceBuffer}function s(){var t=Object(i["getMediaSource"])();if(!t)return!1;var e=n(),r=t&&"function"===typeof t.isTypeSupported&&t.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'),s=!e||e.prototype&&"function"===typeof e.prototype.appendBuffer&&"function"===typeof e.prototype.remove;return!!r&&!!s}function a(){var t,e=n();return"function"===typeof(null===e||void 0===e||null===(t=e.prototype)||void 0===t?void 0:t.changeType)}},"./src/loader/fragment-loader.ts": /*!***************************************!*\ !*** ./src/loader/fragment-loader.ts ***! \***************************************/ /*! exports provided: default, LoadError */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return f})),r.d(e,"LoadError",(function(){return v}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../errors */"./src/errors.ts");function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,c(t,e)}function a(t){var e="function"===typeof Map?new Map:void 0;return a=function(t){if(null===t||!u(t))return t;if("function"!==typeof t)throw new TypeError("Super expression must either be null or a function");if("undefined"!==typeof e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return o(t,arguments,d(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,t)},a(t)}function o(t,e,r){return o=l()?Reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var n=Function.bind.apply(t,i),s=new n;return r&&c(s,r.prototype),s},o.apply(null,arguments)}function l(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function u(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function c(t,e){return c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},c(t,e)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}var h=Math.pow(2,17),f=function(){function t(t){this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=t}var e=t.prototype;return e.destroy=function(){this.loader&&(this.loader.destroy(),this.loader=null)},e.abort=function(){this.loader&&this.loader.abort()},e.load=function(t,e){var r=this,i=t.url;if(!i)return Promise.reject(new v({type:n["ErrorTypes"].NETWORK_ERROR,details:n["ErrorDetails"].FRAG_LOAD_ERROR,fatal:!1,frag:t,networkDetails:null},"Fragment does not have a "+(i?"part list":"url")));this.abort();var s=this.config,a=s.fLoader,o=s.loader;return new Promise((function(i,l){r.loader&&r.loader.destroy();var u=r.loader=t.loader=a?new a(s):new o(s),c=g(t),d={timeout:s.fragLoadingTimeOut,maxRetry:0,retryDelay:0,maxRetryDelay:s.fragLoadingMaxRetryTimeout,highWaterMark:h};t.stats=u.stats,u.load(c,d,{onSuccess:function(e,n,s,a){r.resetLoader(t,u),i({frag:t,part:null,payload:e.data,networkDetails:a})},onError:function(e,i,s){r.resetLoader(t,u),l(new v({type:n["ErrorTypes"].NETWORK_ERROR,details:n["ErrorDetails"].FRAG_LOAD_ERROR,fatal:!1,frag:t,response:e,networkDetails:s}))},onAbort:function(e,i,s){r.resetLoader(t,u),l(new v({type:n["ErrorTypes"].NETWORK_ERROR,details:n["ErrorDetails"].INTERNAL_ABORTED,fatal:!1,frag:t,networkDetails:s}))},onTimeout:function(e,i,s){r.resetLoader(t,u),l(new v({type:n["ErrorTypes"].NETWORK_ERROR,details:n["ErrorDetails"].FRAG_LOAD_TIMEOUT,fatal:!1,frag:t,networkDetails:s}))},onProgress:function(r,i,n,s){e&&e({frag:t,part:null,payload:n,networkDetails:s})}})}))},e.loadPart=function(t,e,r){var i=this;this.abort();var s=this.config,a=s.fLoader,o=s.loader;return new Promise((function(l,u){i.loader&&i.loader.destroy();var c=i.loader=t.loader=a?new a(s):new o(s),d=g(t,e),f={timeout:s.fragLoadingTimeOut,maxRetry:0,retryDelay:0,maxRetryDelay:s.fragLoadingMaxRetryTimeout,highWaterMark:h};e.stats=c.stats,c.load(d,f,{onSuccess:function(n,s,a,o){i.resetLoader(t,c),i.updateStatsFromPart(t,e);var u={frag:t,part:e,payload:n.data,networkDetails:o};r(u),l(u)},onError:function(r,s,a){i.resetLoader(t,c),u(new v({type:n["ErrorTypes"].NETWORK_ERROR,details:n["ErrorDetails"].FRAG_LOAD_ERROR,fatal:!1,frag:t,part:e,response:r,networkDetails:a}))},onAbort:function(r,s,a){t.stats.aborted=e.stats.aborted,i.resetLoader(t,c),u(new v({type:n["ErrorTypes"].NETWORK_ERROR,details:n["ErrorDetails"].INTERNAL_ABORTED,fatal:!1,frag:t,part:e,networkDetails:a}))},onTimeout:function(r,s,a){i.resetLoader(t,c),u(new v({type:n["ErrorTypes"].NETWORK_ERROR,details:n["ErrorDetails"].FRAG_LOAD_TIMEOUT,fatal:!1,frag:t,part:e,networkDetails:a}))}})}))},e.updateStatsFromPart=function(t,e){var r=t.stats,i=e.stats,n=i.total;if(r.loaded+=i.loaded,n){var s=Math.round(t.duration/e.duration),a=Math.min(Math.round(r.loaded/n),s),o=s-a,l=o*Math.round(r.loaded/a);r.total=r.loaded+l}else r.total=Math.max(r.loaded,r.total);var u=r.loading,c=i.loading;u.start?u.first+=c.first-c.start:(u.start=c.start,u.first=c.first),u.end=c.end},e.resetLoader=function(t,e){t.loader=null,this.loader===e&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),e.destroy()},t}();function g(t,e){void 0===e&&(e=null);var r=e||t,n={frag:t,part:e,responseType:"arraybuffer",url:r.url,headers:{},rangeStart:0,rangeEnd:0},s=r.byteRangeStartOffset,a=r.byteRangeEndOffset;return Object(i["isFiniteNumber"])(s)&&Object(i["isFiniteNumber"])(a)&&(n.rangeStart=s,n.rangeEnd=a),n}var v=function(t){function e(e){for(var r,i=arguments.length,n=new Array(i>1?i-1:0),s=1;s>8*(15-r)&255;return e},r.setDecryptDataFromLevelKey=function(t,e){var r=t;return"AES-128"===(null===t||void 0===t?void 0:t.method)&&t.uri&&!t.iv&&(r=o["LevelKey"].fromURI(t.uri),r.method=t.method,r.iv=this.createInitializationVector(e),r.keyFormat="identity"),r},r.setElementaryStreamInfo=function(t,e,r,i,n,s){void 0===s&&(s=!1);var a=this.elementaryStreams,o=a[t];o?(o.startPTS=Math.min(o.startPTS,e),o.endPTS=Math.max(o.endPTS,r),o.startDTS=Math.min(o.startDTS,i),o.endDTS=Math.max(o.endDTS,n)):a[t]={startPTS:e,endPTS:r,startDTS:i,endDTS:n,partial:s}},r.clearElementaryStreamInfo=function(){var t=this.elementaryStreams;t[i.AUDIO]=null,t[i.VIDEO]=null,t[i.AUDIOVIDEO]=null},h(e,[{key:"decryptdata",get:function(){if(!this.levelkey&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkey){var t=this.sn;"number"!==typeof t&&(this.levelkey&&"AES-128"===this.levelkey.method&&!this.levelkey.iv&&a["logger"].warn('missing IV for initialization segment with method="'+this.levelkey.method+'" - compliance issue'),t=0),this._decryptdata=this.setDecryptDataFromLevelKey(this.levelkey,t)}return this._decryptdata}},{key:"end",get:function(){return this.start+this.duration}},{key:"endProgramDateTime",get:function(){if(null===this.programDateTime)return null;if(!Object(n["isFiniteNumber"])(this.programDateTime))return null;var t=Object(n["isFiniteNumber"])(this.duration)?this.duration:0;return this.programDateTime+1e3*t}},{key:"encrypted",get:function(){var t;return!(null===(t=this.decryptdata)||void 0===t||!t.keyFormat||!this.decryptdata.uri)}}]),e}(f),v=function(t){function e(e,r,i,n,s){var a;a=t.call(this,i)||this,a.fragOffset=0,a.duration=0,a.gap=!1,a.independent=!1,a.relurl=void 0,a.fragment=void 0,a.index=void 0,a.stats=new l["LoadStats"],a.duration=e.decimalFloatingPoint("DURATION"),a.gap=e.bool("GAP"),a.independent=e.bool("INDEPENDENT"),a.relurl=e.enumeratedString("URI"),a.fragment=r,a.index=n;var o=e.enumeratedString("BYTERANGE");return o&&a.setByteRange(o,s),s&&(a.fragOffset=s.fragOffset+s.duration),a}return u(e,t),h(e,[{key:"start",get:function(){return this.fragment.start+this.fragOffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var t=this.elementaryStreams;return!!(t.audio||t.video||t.audiovideo)}}]),e}(f)},"./src/loader/key-loader.ts": /*!**********************************!*\ !*** ./src/loader/key-loader.ts ***! \**********************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return a}));var i=r(/*! ../events */"./src/events.ts"),n=r(/*! ../errors */"./src/errors.ts"),s=r(/*! ../utils/logger */"./src/utils/logger.ts"),a=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,a=this.loaders[n];if(r.decryptdata){var o=r.decryptdata.uri;if(o!==this.decrypturl||null===this.decryptkey){var l=this.hls.config;if(a&&(s["logger"].warn("abort previous key loader for type:"+n),a.abort()),!o)return void s["logger"].warn("key uri is falsy");var u=l.loader,c=r.loader=this.loaders[n]=new u(l);this.decrypturl=o,this.decryptkey=null;var d={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)};c.load(d,h,f)}else this.decryptkey&&(r.decryptdata.key=this.decryptkey,this.hls.trigger(i["Events"].KEY_LOADED,{frag:r}))}else s["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})):s["logger"].error("after key load, decryptdata unset")},e.loaderror=function(t,e){var r=e.frag,s=r.loader;s&&s.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,s=r.loader;s&&s.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": /*!*************************************!*\ !*** ./src/loader/level-details.ts ***! \*************************************/ /*! exports provided: LevelDetails */function(t,e,r){"use strict";r.r(e),r.d(e,"LevelDetails",(function(){return o}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts");function n(t,e){for(var r=0;rt.endSN||e>0||0===e&&r>0,this.updated||this.advanced?this.misses=Math.floor(.6*t.misses):this.misses=t.misses+1,this.availabilityDelay=t.availabilityDelay},s(t,[{key:"hasProgramDateTime",get:function(){return!!this.fragments.length&&Object(i["isFiniteNumber"])(this.fragments[this.fragments.length-1].programDateTime)}},{key:"levelTargetDuration",get:function(){return this.averagetargetduration||this.targetduration||a}},{key:"drift",get:function(){var t=this.driftEndTime-this.driftStartTime;if(t>0){var e=this.driftEnd-this.driftStart;return 1e3*e/t}return 1}},{key:"edge",get:function(){return this.partEnd||this.fragmentEnd}},{key:"partEnd",get:function(){var t;return null!==(t=this.partList)&&void 0!==t&&t.length?this.partList[this.partList.length-1].end:this.fragmentEnd}},{key:"fragmentEnd",get:function(){var t;return null!==(t=this.fragments)&&void 0!==t&&t.length?this.fragments[this.fragments.length-1].end:0}},{key:"age",get:function(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}},{key:"lastPartIndex",get:function(){var t;return null!==(t=this.partList)&&void 0!==t&&t.length?this.partList[this.partList.length-1].index:-1}},{key:"lastPartSn",get:function(){var t;return null!==(t=this.partList)&&void 0!==t&&t.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}]),t}()},"./src/loader/level-key.ts": /*!*********************************!*\ !*** ./src/loader/level-key.ts ***! \*********************************/ /*! exports provided: LevelKey */function(t,e,r){"use strict";r.r(e),r.d(e,"LevelKey",(function(){return a}));var i=r(/*! url-toolkit */"./node_modules/url-toolkit/src/url-toolkit.js");function n(t,e){for(var r=0;r2){var r=e.shift()+".";return r+=parseInt(e.shift()).toString(16),r+=("000"+parseInt(e.shift()).toString(16)).substr(-4),r}return t},t.resolve=function(t,e){return n["buildAbsoluteURL"](e,t,{alwaysNormalize:!0})},t.parseMasterPlaylist=function(e,r){var i,n=[],s={},a=!1;d.lastIndex=0;while(null!=(i=d.exec(e)))if(i[1]){var o=new l["AttrList"](i[1]),u={attrs:o,bitrate:o.decimalInteger("AVERAGE-BANDWIDTH")||o.decimalInteger("BANDWIDTH"),name:o.NAME,url:t.resolve(i[2],r)},c=o.decimalResolution("RESOLUTION");c&&(u.width=c.width,u.height=c.height),y((o.CODECS||"").split(/[ ,]+/).filter((function(t){return t})),u),u.videoCodec&&-1!==u.videoCodec.indexOf("avc1")&&(u.videoCodec=t.convertAVC1ToAVCOTI(u.videoCodec)),n.push(u)}else if(i[3]){var h=new l["AttrList"](i[3]);h["DATA-ID"]&&(a=!0,s[h["DATA-ID"]]=h)}return{levels:n,sessionData:a?s:null}},t.parseMasterPlaylistMedia=function(e,r,i,n){var s;void 0===n&&(n=[]);var a=[],o=0;h.lastIndex=0;while(null!==(s=h.exec(e))){var u=new l["AttrList"](s[1]);if(u.TYPE===i){var c={attrs:u,bitrate:0,id:o++,groupId:u["GROUP-ID"],instreamId:u["INSTREAM-ID"],name:u.NAME||u.LANGUAGE||"",type:i,default:u.bool("DEFAULT"),autoselect:u.bool("AUTOSELECT"),forced:u.bool("FORCED"),lang:u.LANGUAGE,url:u.URI?t.resolve(u.URI,r):""};if(n.length){var d=t.findGroup(n,c.groupId)||n[0];E(c,d,"audioCodec"),E(c,d,"textCodec")}a.push(c)}}return a},t.parseLevelPlaylist=function(t,e,r,n,c){var d,h,v,m=new a["LevelDetails"](e),y=m.fragments,E=null,b=0,L=0,A=0,D=0,k=null,R=new s["Fragment"](n,e),I=-1,_=!1;f.lastIndex=0,m.m3u8=t;while(null!==(d=f.exec(t))){_&&(_=!1,R=new s["Fragment"](n,e),R.start=A,R.sn=b,R.cc=D,R.level=r,E&&(R.initSegment=E,R.rawProgramDateTime=E.rawProgramDateTime));var C=d[1];if(C){R.duration=parseFloat(C);var O=(" "+d[2]).slice(1);R.title=O||null,R.tagList.push(O?["INF",C,O]:["INF",C])}else if(d[3])Object(i["isFiniteNumber"])(R.duration)&&(R.start=A,v&&(R.levelkey=v),R.sn=b,R.level=r,R.cc=D,R.urlId=c,y.push(R),R.relurl=(" "+d[3]).slice(1),S(R,k),k=R,A+=R.duration,b++,L=0,_=!0);else if(d[4]){var w=(" "+d[4]).slice(1);k?R.setByteRange(w,k):R.setByteRange(w)}else if(d[5])R.rawProgramDateTime=(" "+d[5]).slice(1),R.tagList.push(["PROGRAM-DATE-TIME",R.rawProgramDateTime]),-1===I&&(I=y.length);else{if(d=d[0].match(g),!d){u["logger"].warn("No matches on slow regex match for level playlist!");continue}for(h=1;h-1){u["logger"].warn("Keyformat "+q+" is not supported from the manifest");continue}if("identity"!==q)continue;K&&(v=o["LevelKey"].fromURL(e,H),H&&["AES-128","SAMPLE-AES","SAMPLE-AES-CENC"].indexOf(K)>=0&&(v.method=K,v.keyFormat=q,Y&&(v.keyID=Y),W&&(v.keyFormatVersions=W),v.iv=V));break;case"START":var z=new l["AttrList"](P),Q=z.decimalFloatingPoint("TIME-OFFSET");Object(i["isFiniteNumber"])(Q)&&(m.startTimeOffset=Q);break;case"MAP":var $=new l["AttrList"](P);R.relurl=$.URI,$.BYTERANGE&&R.setByteRange($.BYTERANGE),R.level=r,R.sn="initSegment",v&&(R.levelkey=v),R.initSegment=null,E=R,_=!0;break;case"SERVER-CONTROL":var J=new l["AttrList"](P);m.canBlockReload=J.bool("CAN-BLOCK-RELOAD"),m.canSkipUntil=J.optionalFloat("CAN-SKIP-UNTIL",0),m.canSkipDateRanges=m.canSkipUntil>0&&J.bool("CAN-SKIP-DATERANGES"),m.partHoldBack=J.optionalFloat("PART-HOLD-BACK",0),m.holdBack=J.optionalFloat("HOLD-BACK",0);break;case"PART-INF":var Z=new l["AttrList"](P);m.partTarget=Z.decimalFloatingPoint("PART-TARGET");break;case"PART":var tt=m.partList;tt||(tt=m.partList=[]);var et=L>0?tt[tt.length-1]:void 0,rt=L++,it=new s["Part"](new l["AttrList"](P),R,e,rt,et);tt.push(it),R.duration+=it.duration;break;case"PRELOAD-HINT":var nt=new l["AttrList"](P);m.preloadHint=nt;break;case"RENDITION-REPORT":var st=new l["AttrList"](P);m.renditionReports=m.renditionReports||[],m.renditionReports.push(st);break;default:u["logger"].warn("line parsed but not handled: "+d);break}}}k&&!k.relurl?(y.pop(),A-=k.duration,m.partList&&(m.fragmentHint=k)):m.partList&&(S(R,k),R.cc=D,m.fragmentHint=R);var at=y.length,ot=y[0],lt=y[at-1];if(A+=m.skippedSegments*m.targetduration,A>0&&at&<){m.averagetargetduration=A/at;var ut=lt.sn;m.endSN="initSegment"!==ut?ut:0,ot&&(m.startCC=ot.cc,ot.initSegment||m.fragments.every((function(t){return t.relurl&&p(t.relurl)}))&&(u["logger"].warn("MP4 fragments found but no init segment (probably no MAP, incomplete M3U8), trying to fetch SIDX"),R=new s["Fragment"](n,e),R.relurl=lt.relurl,R.level=r,R.sn="initSegment",ot.initSegment=R,m.needSidxRanges=!0))}else m.endSN=0,m.startCC=0;return m.fragmentHint&&(A+=m.fragmentHint.duration),m.totalduration=A,m.endCC=D,I>0&&T(y,I),m},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){for(var r=t[e],i=e;i--;){var n=t[i];if(!n)return;n.programDateTime=r.programDateTime-1e3*n.duration,r=n}}function S(t,e){t.rawProgramDateTime?t.programDateTime=Date.parse(t.rawProgramDateTime):null!==e&&void 0!==e&&e.programDateTime&&(t.programDateTime=e.endProgramDateTime),Object(i["isFiniteNumber"])(t.programDateTime)||(t.programDateTime=null,t.rawProgramDateTime=null)}},"./src/loader/playlist-loader.ts": /*!***************************************!*\ !*** ./src/loader/playlist-loader.ts ***! \***************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../events */"./src/events.ts"),s=r(/*! ../errors */"./src/errors.ts"),a=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"),c=r(/*! ../utils/attr-list */"./src/utils/attr-list.ts");function d(t){var e=t.type;switch(e){case u["PlaylistContextType"].AUDIO_TRACK:return u["PlaylistLevelType"].AUDIO;case u["PlaylistContextType"].SUBTITLE_TRACK:return u["PlaylistLevelType"].SUBTITLE;default:return u["PlaylistLevelType"].MAIN}}function h(t,e){var r=t.url;return void 0!==r&&0!==r.indexOf("data:")||(r=e.url),r}var f=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=r||i,s=new n(e);return t.loader=s,this.loaders[t.type]=s,s},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,s=e.deliveryDirectives;this.load({id:r,groupId:null,level:i,responseType:"text",type:u["PlaylistContextType"].LEVEL,url:n,deliveryDirectives:s})},e.onAudioTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,s=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:u["PlaylistContextType"].AUDIO_TRACK,url:n,deliveryDirectives:s})},e.onSubtitleTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,s=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:u["PlaylistContextType"].SUBTITLE_TRACK,url:n,deliveryDirectives:s})},e.load=function(t){var e,r,i,n,s,o,l=this.hls.config,c=this.getInternalLoader(t);if(c){var d=c.context;if(d&&d.url===t.url)return void a["logger"].trace("[playlist-loader]: playlist request ongoing");a["logger"].log("[playlist-loader]: aborting previous loader for type: "+t.type),c.abort()}switch(t.type){case u["PlaylistContextType"].MANIFEST:r=l.manifestLoadingMaxRetry,i=l.manifestLoadingTimeOut,n=l.manifestLoadingRetryDelay,s=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,s=l.levelLoadingMaxRetryTimeout;break}if((c=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:s,highWaterMark:0},v={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};c.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 s=this.hls,o=t.data,u=h(t,r),d=l["default"].parseMasterPlaylist(o,u),f=d.levels,g=d.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");if(m.length){var T=m.some((function(t){return!t.url}));T||!f[0].audioCodec||f[0].attrs.AUDIO||(a["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 c["AttrList"]({}),bitrate:0,url:""}))}s.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,a){var o=this.hls,f=r.id,g=r.level,v=r.type,p=h(t,r),m=Object(i["isFiniteNumber"])(f)?f:0,y=Object(i["isFiniteNumber"])(g)?g:m,E=d(r),T=l["default"].parseLevelPlaylist(t.data,p,y,E,m);if(T.fragments.length){if(v===u["PlaylistContextType"].MANIFEST){var S={attrs:new c["AttrList"]({}),bitrate:0,details:T,name:"",url:p};o.trigger(n["Events"].MANIFEST_LOADED,{levels:[S],audioTracks:[],url:p,stats:e,networkDetails:a,sessionData:null})}if(e.parsing.end=performance.now(),T.needSidxRanges){var b,L=null===(b=T.fragments[0].initSegment)||void 0===b?void 0:b.url;this.load({url:L,isSidxRequest:!0,type:v,level:g,levelDetails:T,id:f,groupId:null,rangeStart:0,rangeEnd:2048,responseType:"arraybuffer",deliveryDirectives:null})}else r.levelDetails=T,this.handlePlaylistLoaded(t,e,r,a)}else o.trigger(n["Events"].ERROR,{type:s["ErrorTypes"].NETWORK_ERROR,details:s["ErrorDetails"].LEVEL_EMPTY_ERROR,fatal:!1,url:p,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,s=n.fragments[e];0===s.byteRange.length&&s.setByteRange(String(1+i.end-i.start)+"@"+String(i.start)),s.initSegment&&s.initSegment.setByteRange(String(r.moovEndOffset)+"@0")}))}},e.handleManifestParsingError=function(t,e,r,i){this.hls.trigger(n["Events"].ERROR,{type:s["ErrorTypes"].NETWORK_ERROR,details:s["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),a["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=s["ErrorDetails"].UNKNOWN,l=!1,c=this.getInternalLoader(t);switch(t.type){case u["PlaylistContextType"].MANIFEST:o=r?s["ErrorDetails"].MANIFEST_LOAD_TIMEOUT:s["ErrorDetails"].MANIFEST_LOAD_ERROR,l=!0;break;case u["PlaylistContextType"].LEVEL:o=r?s["ErrorDetails"].LEVEL_LOAD_TIMEOUT:s["ErrorDetails"].LEVEL_LOAD_ERROR,l=!1;break;case u["PlaylistContextType"].AUDIO_TRACK:o=r?s["ErrorDetails"].AUDIO_TRACK_LOAD_TIMEOUT:s["ErrorDetails"].AUDIO_TRACK_LOAD_ERROR,l=!1;break;case u["PlaylistContextType"].SUBTITLE_TRACK:o=r?s["ErrorDetails"].SUBTITLE_TRACK_LOAD_TIMEOUT:s["ErrorDetails"].SUBTITLE_LOAD_ERROR,l=!1;break}c&&this.resetInternalLoader(t.type);var d={type:s["ErrorTypes"].NETWORK_ERROR,details:o,fatal:l,url:t.url,loader:c,context:t,networkDetails:e};i&&(d.response=i),this.hls.trigger(n["Events"].ERROR,d)},e.handlePlaylistLoaded=function(t,e,r,i){var s=r.type,a=r.level,o=r.id,l=r.groupId,c=r.loader,d=r.levelDetails,h=r.deliveryDirectives;if(null!==d&&void 0!==d&&d.targetduration){if(c)switch(d.live&&(c.getCacheAge&&(d.ageHeader=c.getCacheAge()||0),c.getCacheAge&&!isNaN(d.ageHeader)||(d.ageHeader=0)),s){case u["PlaylistContextType"].MANIFEST:case u["PlaylistContextType"].LEVEL:this.hls.trigger(n["Events"].LEVEL_LOADED,{details:d,level:a||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:d,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:d,id:o||0,groupId:l||"",stats:e,networkDetails:i,deliveryDirectives:h});break}}else this.handleManifestParsingError(t,r,"invalid target duration",i)},t}();e["default"]=f},"./src/polyfills/number.ts": /*!*********************************!*\ !*** ./src/polyfills/number.ts ***! \*********************************/ /*! exports provided: isFiniteNumber, MAX_SAFE_INTEGER */function(t,e,r){"use strict";r.r(e),r.d(e,"isFiniteNumber",(function(){return i})),r.d(e,"MAX_SAFE_INTEGER",(function(){return n}));var i=Number.isFinite||function(t){return"number"===typeof t&&isFinite(t)},n=Number.MAX_SAFE_INTEGER||9007199254740991},"./src/remux/aac-helper.ts": /*!*********************************!*\ !*** ./src/remux/aac-helper.ts ***! \*********************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=function(){function t(){}return t.getSilentFrame=function(t,e){switch(t){case"mp4a.40.2":if(1===e)return new Uint8Array([0,200,0,128,35,128]);if(2===e)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===e)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===e)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===e)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===e)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224]);break;default:if(1===e)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===e)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===e)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);break}},t}();e["default"]=i},"./src/remux/mp4-generator.ts": /*!************************************!*\ !*** ./src/remux/mp4-generator.ts ***! \************************************/ /*! exports provided: default */function(t,e,r){"use strict";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]),s=new Uint8Array([0,0,0,0,0,0,0,0]);t.STTS=t.STSC=t.STCO=s,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 a=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,a,l,a,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>24&255,o[1]=e>>16&255,o[2]=e>>8&255,o[3]=255&e,o.set(t,4),s=0,e=8;s>24&255,e>>16&255,e>>8&255,255&e,n>>24,n>>16&255,n>>8&255,255&n,s>>24,s>>16&255,s>>8&255,255&s,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){var r=e.length,i=[];while(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){var r=e.length,i=[];while(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)),s=Math.floor(r%(i+1)),a=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,s>>24,s>>16&255,s>>8&255,255&s,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,a)},t.sdtp=function(e){var r,i,n=e.samples||[],s=new Uint8Array(4+n.length);for(r=0;r>>8&255),s.push(255&n),s=s.concat(Array.prototype.slice.call(i));for(r=0;r>>8&255),a.push(255&n),a=a.concat(Array.prototype.slice.call(i));var o=t.box(t.types.avcC,new Uint8Array([1,s[3],s[4],s[5],255,224|e.sps.length].concat(s).concat([e.pps.length]).concat(a))),l=e.width,u=e.height,c=e.pixelRatio[0],d=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([c>>24,c>>16&255,c>>8&255,255&c,d>>24,d>>16&255,d>>8&255,255&d])))},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?e.isAAC||"mp3"!==e.codec?t.box(t.types.stsd,t.STSD,t.mp4a(e)):t.box(t.types.stsd,t.STSD,t.mp3(e)):t.box(t.types.stsd,t.STSD,t.avc1(e))},t.tkhd=function(e){var r=e.id,n=e.duration*e.timescale,s=e.width,a=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,s>>8&255,255&s,0,0,a>>8&255,255&a,0,0]))},t.traf=function(e,r){var n=t.sdtp(e),s=e.id,a=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,s>>24,s>>16&255,s>>8&255,255&s])),t.box(t.types.tfdt,new Uint8Array([1,0,0,0,a>>24,a>>16&255,a>>8&255,255&a,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,s,a,o,l,u=e.samples||[],c=u.length,d=12+16*c,h=new Uint8Array(d);for(r+=8+d,h.set([0,0,15,1,c>>>24&255,c>>>16&255,c>>>8&255,255&c,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i>>24&255,s>>>16&255,s>>>8&255,255&s,a>>>24&255,a>>>16&255,a>>>8&255,255&a,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": /*!**********************************!*\ !*** ./src/remux/mp4-remuxer.ts ***! \**********************************/ /*! exports provided: default, normalizePts */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return y})),r.d(e,"normalizePts",(function(){return E}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./aac-helper */"./src/remux/aac-helper.ts"),s=r(/*! ./mp4-generator */"./src/remux/mp4-generator.ts"),a=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"),c=r(/*! ../utils/timescale-conversion */"./src/utils/timescale-conversion.ts");function d(){return d=Object.assign||function(t){for(var e=1;e0?t:r.pts}),t[0].pts);return e&&l["logger"].debug("PTS rollover detected"),r},e.remux=function(t,e,r,i,n,s,a,o){var c,d,h,f,g,v,p=n,m=n,y=t.pid>-1,S=e.pid>-1,b=e.samples.length,L=t.samples.length>0,A=b>1,D=(!y||L)&&(!S||A)||this.ISGenerated||a;if(D){this.ISGenerated||(h=this.generateIS(t,e,n));var k=this.isVideoContiguous,R=-1;if(A&&(R=T(e.samples),!k&&this.config.forceKeyFrameOnDiscontinuity))if(v=!0,R>0){l["logger"].warn("[mp4-remuxer]: Dropped "+R+" out of "+b+" video samples due to a missing keyframe");var I=this.getVideoStartPts(e.samples);e.samples=e.samples.slice(R),e.dropped+=R,m+=(e.samples[0].pts-I)/(e.timescale||9e4)}else-1===R&&(l["logger"].warn("[mp4-remuxer]: No keyframe found out of "+b+" video samples"),v=!1);if(this.ISGenerated){if(L&&A){var _=this.getVideoStartPts(e.samples),C=E(t.samples[0].pts,_)-_,O=C/e.inputTimeScale;p+=Math.max(0,O),m+=Math.max(0,-O)}if(L){if(t.samplerate||(l["logger"].warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),h=this.generateIS(t,e,n)),d=this.remuxAudio(t,p,this.isAudioContiguous,s,S||A||o===u["PlaylistLevelType"].AUDIO?m:void 0),A){var w=d?d.endPTS-d.startPTS:0;e.inputTimeScale||(l["logger"].warn("[mp4-remuxer]: regenerate InitSegment as video detected"),h=this.generateIS(t,e,n)),c=this.remuxVideo(e,m,k,w)}}else A&&(c=this.remuxVideo(e,m,k,0));c&&(c.firstKeyFrame=R,c.independent=-1!==R)}}return this.ISGenerated&&(r.samples.length&&(g=this.remuxID3(r,n)),i.samples.length&&(f=this.remuxText(i,n))),{audio:d,video:c,initSegment:h,independent:v,text:f,id3:g}},e.generateIS=function(t,e,r){var n,a,o,l=t.samples,u=e.samples,c=this.typeSupported,d={},h=!Object(i["isFiniteNumber"])(this._initPTS),f="audio/mp4";if(h&&(n=a=1/0),t.config&&l.length&&(t.timescale=t.samplerate,t.isAAC||(c.mpeg?(f="audio/mpeg",t.codec=""):c.mp3&&(t.codec="mp3")),d.audio={id:"audio",container:f,codec:t.codec,initSegment:!t.isAAC&&c.mpeg?new Uint8Array(0):s["default"].initSegment([t]),metadata:{channelCount:t.channelCount}},h&&(o=t.inputTimeScale,n=a=l[0].pts-Math.round(o*r))),e.sps&&e.pps&&u.length&&(e.timescale=e.inputTimeScale,d.video={id:"main",container:"video/mp4",codec:e.codec,initSegment:s["default"].initSegment([e]),metadata:{width:e.width,height:e.height}},h)){o=e.inputTimeScale;var g=this.getVideoStartPts(u),v=Math.round(o*r);a=Math.min(a,E(u[0].dts,g)-v),n=Math.min(n,g-v)}if(Object.keys(d).length)return this.ISGenerated=!0,h&&(this._initPTS=n,this._initDTS=a),{tracks:d,initPTS:n,timescale:o}},e.remuxVideo=function(t,e,r,i){var n,u,h,f=t.inputTimeScale,g=t.samples,p=[],y=g.length,T=this._initPTS,b=this.nextAvcDts,L=8,A=Number.POSITIVE_INFINITY,D=Number.NEGATIVE_INFINITY,k=0,R=!1;if(!r||null===b){var I=e*f,_=g[0].pts-E(g[0].dts,g[0].pts);b=I-_}for(var C=0;CO.pts){var w=18e3;k=Math.max(Math.min(k,O.pts-O.dts),-1*w)}O.dts0?C-1:C].dts&&(R=!0)}R&&g.sort((function(t,e){var r=t.dts-e.dts,i=t.pts-e.pts;return r||i})),u=g[0].dts,h=g[g.length-1].dts;var x=Math.round((h-u)/(y-1));if(k<0){if(k<-2*x){l["logger"].warn("PTS < DTS detected in video samples, offsetting DTS from PTS by "+Object(c["toMsFromMpegTsClock"])(-x,!0)+" ms");for(var P=k,F=0;Fx,B=N<-1;if(U||B){U?l["logger"].warn("AVC: "+Object(c["toMsFromMpegTsClock"])(N,!0)+" ms ("+N+"dts) hole between fragments detected, filling it"):l["logger"].warn("AVC: "+Object(c["toMsFromMpegTsClock"])(-N,!0)+" ms ("+N+"dts) overlapping between fragments detected"),u=b;var G=g[0].pts-N;g[0].dts=u,g[0].pts=G,l["logger"].log("Video: First PTS/DTS adjusted: "+Object(c["toMsFromMpegTsClock"])(G,!0)+"/"+Object(c["toMsFromMpegTsClock"])(u,!0)+", delta: "+Object(c["toMsFromMpegTsClock"])(N,!0)+" ms")}}m&&(u=Math.max(0,u));for(var j=0,K=0,H=0;H0?J-1:J].dts;if(ot.stretchShortVideoTrack&&null!==this.nextAudioPts){var ut=Math.floor(ot.maxBufferHole*f),ct=(i?A+i*f:this.nextAudioPts)-Z.pts;ct>ut?(n=ct-lt,n<0&&(n=lt),l["logger"].log("[mp4-remuxer]: It is approximately "+ct/90+" ms to the next segment; using duration "+n/90+" ms for the last video frame.")):n=lt}else n=lt}var dt=Math.round(Z.pts-Z.dts);p.push(new S(Z.key,n,et,dt))}if(p.length&&v&&v<70){var ht=p[0].flags;ht.dependsOn=2,ht.isNonSync=0}console.assert(void 0!==n,"mp4SampleDuration must be computed"),this.nextAvcDts=b=h+n,this.isVideoContiguous=!0;var ft=s["default"].moof(t.sequenceNumber++,u,d({},t,{samples:p})),gt="video",vt={data1:ft,data2:z,startPTS:A/f,endPTS:(D+n)/f,startDTS:u/f,endDTS:b/f,type:gt,hasAudio:!1,hasVideo:!0,nb:p.length,dropped:t.dropped};return t.samples=[],t.dropped=0,console.assert(z.length,"MDAT length must not be zero"),vt},e.remuxAudio=function(t,e,r,i,u){var c=t.inputTimeScale,v=t.samplerate?t.samplerate:c,p=c/v,m=t.isAAC?f:g,y=m*p,T=this._initPTS,b=!t.isAAC&&this.typeSupported.mpeg,L=[],A=t.samples,D=b?0:8,k=this.nextAudioPts||-1,R=e*c;if(this.isAudioContiguous=r=r||A.length&&k>0&&(i&&Math.abs(R-k)<9e3||Math.abs(E(A[0].pts-T,R)-k)<20*y),A.forEach((function(t){t.pts=E(t.pts-T,R)})),!r||k<0){if(A=A.filter((function(t){return t.pts>=0})),!A.length)return;k=0===u?0:i?Math.max(0,R):A[0].pts}if(t.isAAC)for(var I=void 0!==u,_=this.config.maxAudioFramesDrift,C=0,O=k;C=_*y&&F0))return;H+=D;try{G=new Uint8Array(H)}catch(at){return void this.observer.emit(a["Events"].ERROR,a["Events"].ERROR,{type:o["ErrorTypes"].MUX_ERROR,details:o["ErrorDetails"].REMUX_ALLOC_ERROR,fatal:!1,bytes:H,reason:"fail allocating audio mdat "+H})}if(!b){var $=new DataView(G.buffer);$.setUint32(0,H),G.set(s["default"].types.mdat,4)}}G.set(X,D);var J=X.byteLength;D+=J,L.push(new S(!0,m,J,0)),K=z}var Z=L.length;if(Z){var tt=L[L.length-1];this.nextAudioPts=k=K+p*tt.duration;var et=b?new Uint8Array(0):s["default"].moof(t.sequenceNumber++,j/p,d({},t,{samples:L}));t.samples=[];var rt=j/c,it=k/c,nt="audio",st={data1:et,data2:G,startPTS:rt,endPTS:it,startDTS:rt,endDTS:it,type:nt,hasAudio:!0,hasVideo:!1,nb:Z};return this.isAudioContiguous=!0,console.assert(G.length,"MDAT length must not be zero"),st}},e.remuxEmptyAudio=function(t,e,r,i){var s=t.inputTimeScale,a=t.samplerate?t.samplerate:s,o=s/a,u=this.nextAudioPts,c=(null!==u?u:i.startDTS*s)+this._initDTS,d=i.endDTS*s+this._initDTS,h=o*f,g=Math.ceil((d-c)/h),v=n["default"].getSilentFrame(t.manifestCodec||t.codec,t.channelCount);if(l["logger"].warn("[mp4-remuxer]: remux empty Audio"),v){for(var p=[],m=0;m4294967296)t+=r;return t}function T(t){for(var e=0;e0?this.lastEndDTS=m:(a["logger"].warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var y=!!g.audio,E=!!g.video,T="";y&&(T+="audio"),E&&(T+="video");var S={data1:h,startPTS:p,startDTS:p,endPTS:m,endDTS:m,type:T,hasAudio:y,hasVideo:E,nb:1,dropped:0};return d.audio="audio"===S.type?S:void 0,d.video="audio"!==S.type?S:void 0,d.text=s,d.id3=r,d.initSegment=f,d},t}(),l=function(t,e,r){return Object(n["getStartDTS"])(t,e)-r};function u(t,e){var r=null===t||void 0===t?void 0:t.codec;return r&&r.length>4?r:"hvc1"===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"]=o},"./src/task-loop.ts": /*!**************************!*\ !*** ./src/task-loop.ts ***! \**************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return i}));var i=function(){function t(){this._boundTick=void 0,this._tickTimer=null,this._tickInterval=null,this._tickCallCount=0,this._boundTick=this.tick.bind(this)}var e=t.prototype;return e.destroy=function(){this.onHandlerDestroying(),this.onHandlerDestroyed()},e.onHandlerDestroying=function(){this.clearNextTick(),this.clearInterval()},e.onHandlerDestroyed=function(){},e.hasInterval=function(){return!!this._tickInterval},e.hasNextTick=function(){return!!this._tickTimer},e.setInterval=function(t){return!this._tickInterval&&(this._tickInterval=self.setInterval(this._boundTick,t),!0)},e.clearInterval=function(){return!!this._tickInterval&&(self.clearInterval(this._tickInterval),this._tickInterval=null,!0)},e.clearNextTick=function(){return!!this._tickTimer&&(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0)},e.tick=function(){this._tickCallCount++,1===this._tickCallCount&&(this.doTick(),this._tickCallCount>1&&this.tickImmediate(),this._tickCallCount=0)},e.tickImmediate=function(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)},e.doTick=function(){},t}()},"./src/types/cmcd.ts": /*!***************************!*\ !*** ./src/types/cmcd.ts ***! \***************************/ /*! exports provided: CMCDVersion, CMCDObjectType, CMCDStreamingFormat, CMCDStreamType */function(t,e,r){"use strict";r.r(e),r.d(e,"CMCDVersion",(function(){return a})),r.d(e,"CMCDObjectType",(function(){return i})),r.d(e,"CMCDStreamingFormat",(function(){return n})),r.d(e,"CMCDStreamType",(function(){return s}));var i,n,s,a=1;(function(t){t["MANIFEST"]="m",t["AUDIO"]="a",t["VIDEO"]="v",t["MUXED"]="av",t["INIT"]="i",t["CAPTION"]="c",t["TIMED_TEXT"]="tt",t["KEY"]="k",t["OTHER"]="o"})(i||(i={})),function(t){t["DASH"]="d",t["HLS"]="h",t["SMOOTH"]="s",t["OTHER"]="o"}(n||(n={})),function(t){t["VOD"]="v",t["LIVE"]="l"}(s||(s={}))},"./src/types/level.ts": /*!****************************!*\ !*** ./src/types/level.ts ***! \****************************/ /*! exports provided: HlsSkip, getSkipValue, HlsUrlParameters, Level */function(t,e,r){"use strict";function i(t,e){for(var r=0;rNumber.MAX_SAFE_INTEGER?1/0:e},e.hexadecimalInteger=function(t){if(this[t]){var e=(this[t]||"0x").slice(2);e=(1&e.length?"0":"")+e;for(var r=new Uint8Array(e.length/2),i=0;iNumber.MAX_SAFE_INTEGER?1/0:e},e.decimalFloatingPoint=function(t){return parseFloat(this[t])},e.optionalFloat=function(t,e){var r=this[t];return r?parseFloat(r):e},e.enumeratedString=function(t){return this[t]},e.bool=function(t){return"YES"===this[t]},e.decimalResolution=function(t){var e=i.exec(this[t]);if(null!==e)return{width:parseInt(e[1],10),height:parseInt(e[2],10)}},t.parseAttrList=function(t){var e,r={},i='"';n.lastIndex=0;while(null!==(e=n.exec(t))){var s=e[2];0===s.indexOf(i)&&s.lastIndexOf(i)===s.length-1&&(s=s.slice(1,-1)),r[e[1]]=s}return r},t}()},"./src/utils/binary-search.ts": /*!************************************!*\ !*** ./src/utils/binary-search.ts ***! \************************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i={search:function(t,e){var r=0,i=t.length-1,n=null,s=null;while(r<=i){n=(r+i)/2|0,s=t[n];var a=e(s);if(a>0)r=n+1;else{if(!(a<0))return s;i=n-1}}return null}};e["default"]=i},"./src/utils/buffer-helper.ts": /*!************************************!*\ !*** ./src/utils/buffer-helper.ts ***! \************************************/ /*! exports provided: BufferHelper */function(t,e,r){"use strict";r.r(e),r.d(e,"BufferHelper",(function(){return s}));var i=r(/*! ./logger */"./src/utils/logger.ts"),n={length:0,start:function(){return 0},end:function(){return 0}},s=function(){function t(){}return t.isBuffered=function(e,r){try{if(e)for(var i=t.getBuffered(e),n=0;n=i.start(n)&&r<=i.end(n))return!0}catch(s){}return!1},t.bufferInfo=function(e,r,i){try{if(e){var n,s=t.getBuffered(e),a=[];for(n=0;na&&(i[s-1].end=t[n].end):i.push(t[n])}else i.push(t[n])}else i=t;for(var o,l=0,u=e,c=e,d=0;d=h&&e=t&&n["logger"].log(this.time+" ["+t+"] "+e)},t}(),v=function(t){for(var e=[],r=0;rl&&(this.logger.log(i.DEBUG,"Too large cursor position "+this.pos),this.pos=l)},e.moveCursor=function(t){var e=this.pos+t;if(t>1)for(var r=this.pos+1;r=144&&this.backSpace();var e=a(t);this.pos>=l?this.logger.log(i.ERROR,"Cannot insert "+t.toString(16)+" ("+e+") at position "+this.pos+". Skipping it!"):(this.chars[this.pos].setChar(e,this.currPenState),this.moveCursor(1))},e.clearFromPos=function(t){var e;for(e=t;e0&&(r=t?"["+e.join(" | ")+"]":e.join("\n")),r},e.getTextAndFormat=function(){return this.rows},t}(),T=function(){function t(t,e,r){this.chNr=void 0,this.outputFilter=void 0,this.mode=void 0,this.verbose=void 0,this.displayedMemory=void 0,this.nonDisplayedMemory=void 0,this.lastOutputScreen=void 0,this.currRollUpRow=void 0,this.writeScreen=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chNr=t,this.outputFilter=e,this.mode=null,this.verbose=0,this.displayedMemory=new E(r),this.nonDisplayedMemory=new E(r),this.lastOutputScreen=new E(r),this.currRollUpRow=this.displayedMemory.rows[o-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.logger=r}var e=t.prototype;return e.reset=function(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.outputFilter.reset(),this.currRollUpRow=this.displayedMemory.rows[o-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null},e.getHandler=function(){return this.outputFilter},e.setHandler=function(t){this.outputFilter=t},e.setPAC=function(t){this.writeScreen.setPAC(t)},e.setBkgData=function(t){this.writeScreen.setBkgData(t)},e.setMode=function(t){t!==this.mode&&(this.mode=t,this.logger.log(i.INFO,"MODE="+t),"MODE_POP-ON"===this.mode?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),"MODE_ROLL-UP"!==this.mode&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=t)},e.insertChars=function(t){for(var e=0;e=46,e.italics)e.foreground="white";else{var r=Math.floor(t/2)-16,n=["white","green","blue","cyan","red","yellow","magenta"];e.foreground=n[r]}this.logger.log(i.INFO,"MIDROW: "+JSON.stringify(e)),this.writeScreen.setPen(e)},e.outputDataUpdate=function(t){void 0===t&&(t=!1);var e=this.logger.time;null!==e&&this.outputFilter&&(null!==this.cueStartTime||this.displayedMemory.isEmpty()?this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue(this.cueStartTime,e,this.lastOutputScreen),t&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:e):this.cueStartTime=e,this.lastOutputScreen.copy(this.displayedMemory))},e.cueSplitAtTime=function(t){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,t,this.displayedMemory),this.cueStartTime=t))},t}(),S=function(){function t(t,e,r){this.channels=void 0,this.currentChannel=0,this.cmdHistory=void 0,this.logger=void 0;var i=new g;this.channels=[null,new T(t,e,i),new T(t+1,r,i)],this.cmdHistory=A(),this.logger=i}var e=t.prototype;return e.getHandler=function(t){return this.channels[t].getHandler()},e.setHandler=function(t,e){this.channels[t].setHandler(e)},e.addData=function(t,e){var r,n,s,a=!1;this.logger.time=t;for(var o=0;o ("+v([n,s])+")"),r=this.parseCmd(n,s),r||(r=this.parseMidrow(n,s)),r||(r=this.parsePAC(n,s)),r||(r=this.parseBackgroundAttributes(n,s)),!r&&(a=this.parseChars(n,s),a)){var l=this.currentChannel;if(l&&l>0){var u=this.channels[l];u.insertChars(a)}else this.logger.log(i.WARNING,"No channel found yet. TEXT-MODE?")}r||a||this.logger.log(i.WARNING,"Couldn't parse cleaned data "+v([n,s])+" orig: "+v([e[o],e[o+1]]))}},e.parseCmd=function(t,e){var r=this.cmdHistory,n=(20===t||28===t||21===t||29===t)&&e>=32&&e<=47,s=(23===t||31===t)&&e>=33&&e<=35;if(!n&&!s)return!1;if(L(t,e,r))return b(null,null,r),this.logger.log(i.DEBUG,"Repeated command ("+v([t,e])+") is dropped"),!0;var a=20===t||21===t||23===t?1:2,o=this.channels[a];return 20===t||21===t||28===t||29===t?32===e?o.ccRCL():33===e?o.ccBS():34===e?o.ccAOF():35===e?o.ccAON():36===e?o.ccDER():37===e?o.ccRU(2):38===e?o.ccRU(3):39===e?o.ccRU(4):40===e?o.ccFON():41===e?o.ccRDC():42===e?o.ccTR():43===e?o.ccRTD():44===e?o.ccEDM():45===e?o.ccCR():46===e?o.ccENM():47===e&&o.ccEOC():o.ccTO(e-32),b(t,e,r),this.currentChannel=a,!0},e.parseMidrow=function(t,e){var r=0;if((17===t||25===t)&&e>=32&&e<=47){if(r=17===t?1:2,r!==this.currentChannel)return this.logger.log(i.ERROR,"Mismatch channel in midrow parsing"),!1;var n=this.channels[r];return!!n&&(n.ccMIDROW(e),this.logger.log(i.DEBUG,"MIDROW ("+v([t,e])+")"),!0)}return!1},e.parsePAC=function(t,e){var r,i=this.cmdHistory,n=(t>=17&&t<=23||t>=25&&t<=31)&&e>=64&&e<=127,s=(16===t||24===t)&&e>=64&&e<=95;if(!n&&!s)return!1;if(L(t,e,i))return b(null,null,i),!0;var a=t<=23?1:2;r=e>=64&&e<=95?1===a?u[t]:d[t]:1===a?c[t]:h[t];var o=this.channels[a];return!!o&&(o.setPAC(this.interpretPAC(r,e)),b(t,e,i),this.currentChannel=a,!0)},e.interpretPAC=function(t,e){var r,i={color:null,italics:!1,indent:null,underline:!1,row:t};return r=e>95?e-96:e-64,i.underline=1===(1&r),r<=13?i.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(r/2)]:r<=15?(i.italics=!0,i.color="white"):i.indent=4*Math.floor((r-16)/2),i},e.parseChars=function(t,e){var r,n,s=null,o=null;(t>=25?(r=2,o=t-8):(r=1,o=t),o>=17&&o<=19)?(n=17===o?e+80:18===o?e+112:e+144,this.logger.log(i.INFO,"Special char '"+a(n)+"' in channel "+r),s=[n]):t>=32&&t<=127&&(s=0===e?[t]:[t,e]);if(s){var l=v(s);this.logger.log(i.DEBUG,"Char codes = "+l.join(",")),b(t,e,this.cmdHistory)}return s},e.parseBackgroundAttributes=function(t,e){var r,i=(16===t||24===t)&&e>=32&&e<=47,n=(23===t||31===t)&&e>=45&&e<=47;if(!i&&!n)return!1;var s={};16===t||24===t?(r=Math.floor((e-32)/2),s.background=f[r],e%2===1&&(s.background=s.background+"_semi")):45===e?s.background="transparent":(s.foreground="black",47===e&&(s.underline=!0));var a=t<=23?1:2,o=this.channels[a];return o.setBkgData(s),b(t,e,this.cmdHistory),!0},e.reset=function(){for(var t=0;t=16?d--:d++;var m=Object(i["fixLineBreaks"])(h.trim()),y=Object(n["generateCueId"])(e,r,m);t&&t.cues&&t.cues.getCueById(y)||(u=new g(e,r,m),u.id=y,u.line=v+1,u.align="left",u.position=10+Math.min(80,10*Math.floor(8*d/32)),f.push(u))}return t&&f.length&&(f.sort((function(t,e){return"auto"===t.line||"auto"===e.line?0:t.line>8&&e.line>8?e.line-t.line:t.line-e.line})),f.forEach((function(e){return Object(s["addCueToTrack"])(t,e)}))),f}};e["default"]=o},"./src/utils/discontinuities.ts": /*!**************************************!*\ !*** ./src/utils/discontinuities.ts ***! \**************************************/ /*! exports provided: findFirstFragWithCC, shouldAlignOnDiscontinuities, findDiscontinuousReferenceFrag, adjustSlidingStart, alignStream, alignPDT, alignFragmentByPDTDelta, alignMediaPlaylistByPDT */function(t,e,r){"use strict";r.r(e),r.d(e,"findFirstFragWithCC",(function(){return a})),r.d(e,"shouldAlignOnDiscontinuities",(function(){return o})),r.d(e,"findDiscontinuousReferenceFrag",(function(){return l})),r.d(e,"adjustSlidingStart",(function(){return c})),r.d(e,"alignStream",(function(){return d})),r.d(e,"alignPDT",(function(){return f})),r.d(e,"alignFragmentByPDTDelta",(function(){return g})),r.d(e,"alignMediaPlaylistByPDT",(function(){return v}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ./logger */"./src/utils/logger.ts"),s=r(/*! ../controller/level-helper */"./src/controller/level-helper.ts");function a(t,e){for(var r=null,i=0,n=t.length;ir.startCC||t&&t.cc=this.minWeight_},e.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},e.destroy=function(){},t}();e["default"]=n},"./src/utils/ewma.ts": /*!***************************!*\ !*** ./src/utils/ewma.ts ***! \***************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=function(){function t(t,e,r){void 0===e&&(e=0),void 0===r&&(r=0),this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=t,this.alpha_=t?Math.exp(Math.log(.5)/t):0,this.estimate_=e,this.totalWeight_=r}var e=t.prototype;return e.sample=function(t,e){var r=Math.pow(this.alpha_,t);this.estimate_=e*(1-r)+r*this.estimate_,this.totalWeight_+=t},e.getTotalWeight=function(){return this.totalWeight_},e.getEstimate=function(){if(this.alpha_){var t=1-Math.pow(this.alpha_,this.totalWeight_);if(t)return this.estimate_/t}return this.estimate_},t}();e["default"]=i},"./src/utils/fetch-loader.ts": /*!***********************************!*\ !*** ./src/utils/fetch-loader.ts ***! \***********************************/ /*! exports provided: fetchSupported, default */function(t,e,r){"use strict";r.r(e),r.d(e,"fetchSupported",(function(){return g}));var i=r(/*! ./src/polyfills/number */"./src/polyfills/number.ts"),n=r(/*! ../loader/load-stats */"./src/loader/load-stats.ts"),s=r(/*! ../demux/chunk-cache */"./src/demux/chunk-cache.ts");function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,d(t,e)}function o(t){var e="function"===typeof Map?new Map:void 0;return o=function(t){if(null===t||!c(t))return t;if("function"!==typeof t)throw new TypeError("Super expression must either be null or a function");if("undefined"!==typeof e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return l(t,arguments,h(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,t)},o(t)}function l(t,e,r){return l=u()?Reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var n=Function.bind.apply(t,i),s=new n;return r&&d(s,r.prototype),s},l.apply(null,arguments)}function u(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function c(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function d(t,e){return d=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},d(t,e)}function h(t){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},h(t)}function f(){return f=Object.assign||function(t){for(var e=1;e=i&&n(e,r,a.flush(),t)):n(e,r,l,t),s()})).catch((function(){return Promise.reject()}))};return l()},t}();function p(t,e){var r={method:"GET",mode:"cors",credentials:"same-origin",signal:e,headers:new self.Headers(f({},t.headers))};return t.rangeEnd&&r.headers.set("Range","bytes="+t.rangeStart+"-"+String(t.rangeEnd-1)),r}function m(t,e){return new self.Request(t.url,e)}var y=function(t){function e(e,r,i){var n;return n=t.call(this,e)||this,n.code=void 0,n.details=void 0,n.code=r,n.details=i,n}return a(e,t),e}(o(Error));e["default"]=v},"./src/utils/imsc1-ttml-parser.ts": /*!****************************************!*\ !*** ./src/utils/imsc1-ttml-parser.ts ***! \****************************************/ /*! exports provided: IMSC1_CODEC, parseIMSC1 */function(t,e,r){"use strict";r.r(e),r.d(e,"IMSC1_CODEC",(function(){return c})),r.d(e,"parseIMSC1",(function(){return g}));var i=r(/*! ./mp4-tools */"./src/utils/mp4-tools.ts"),n=r(/*! ./vttparser */"./src/utils/vttparser.ts"),s=r(/*! ./vttcue */"./src/utils/vttcue.ts"),a=r(/*! ../demux/id3 */"./src/demux/id3.ts"),o=r(/*! ./timescale-conversion */"./src/utils/timescale-conversion.ts"),l=r(/*! ./webvtt-parser */"./src/utils/webvtt-parser.ts");function u(){return u=Object.assign||function(t){for(var e=1;e"):i}function o(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i>24,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r}function d(t,e){var r,i,n,s=[];if(!e.length)return s;"data"in t?(r=t.data,i=t.start,n=t.end):(r=t,i=0,n=r.byteLength);for(var l=i;l1?l+c:n;if(h===e[0])if(1===e.length)s.push({data:r,start:l+8,end:f});else{var g=d({data:r,start:l+8,end:f},e.slice(1));g.length&&a.apply(s,g)}l=f}return s}function h(t){var e=d(t,["moov"]),r=e[0],i=r?r.end:null,n=d(t,["sidx"]);if(!n||!n[0])return null;var s=[],a=n[0],o=a.data[0],c=0===o?8:16,h=u(a,c);c+=4;var f=0,g=0;c+=0===o?8:16,c+=2;var v=a.end+g,p=l(a,c);c+=2;for(var m=0;m>>31;if(1===S)return console.warn("SIDX has hierarchical references (not supported)"),null;var b=u(a,y);y+=4,s.push({referenceSize:T,subsegmentDuration:b,info:{duration:b/h,start:v,end:v+T-1}}),v+=T,y+=4,c=y}return{earliestPresentationTime:f,timescale:h,version:o,referencesCount:p,references:s,moovEndOffset:i}}function f(t){for(var e=[],r=d(t,["moov","trak"]),i=0;it)&&(this.startTime=t),this.endTime=e,this.screen=r,this.timelineController.createCaptionsTrack(this.trackName)},e.reset=function(){this.cueRanges=[],this.startTime=null},t}()},"./src/utils/texttrack-utils.ts": /*!**************************************!*\ !*** ./src/utils/texttrack-utils.ts ***! \**************************************/ /*! exports provided: sendAddTrackEvent, addCueToTrack, clearCurrentCues, removeCuesInRange, getCuesInRange */function(t,e,r){"use strict";r.r(e),r.d(e,"sendAddTrackEvent",(function(){return n})),r.d(e,"addCueToTrack",(function(){return s})),r.d(e,"clearCurrentCues",(function(){return a})),r.d(e,"removeCuesInRange",(function(){return o})),r.d(e,"getCuesInRange",(function(){return u}));var i=r(/*! ./logger */"./src/utils/logger.ts");function n(t,e){var r;try{r=new Event("addtrack")}catch(i){r=document.createEvent("Event"),r.initEvent("addtrack",!1,!1)}r.track=t,e.dispatchEvent(r)}function s(t,e){var r=t.mode;if("disabled"===r&&(t.mode="hidden"),t.cues&&!t.cues.getCueById(e.id))try{if(t.addCue(e),!t.cues.getCueById(e.id))throw new Error("addCue is failed for: "+e)}catch(s){i["logger"].debug("[texttrack-utils]: "+s);var n=new self.TextTrackCue(e.startTime,e.endTime,e.text);n.id=e.id,t.addCue(n)}"disabled"===r&&(t.mode=r)}function a(t){var e=t.mode;if("disabled"===e&&(t.mode="hidden"),t.cues)for(var r=t.cues.length;r--;)t.removeCue(t.cues[r]);"disabled"===e&&(t.mode=e)}function o(t,e,r){var i=t.mode;if("disabled"===i&&(t.mode="hidden"),t.cues&&t.cues.length>0)for(var n=u(t.cues,e,r),s=0;st[r].endTime)return-1;var i=0,n=r;while(i<=n){var s=Math.floor((n+i)/2);if(et[s].startTime&&i-1)for(var s=n,a=t.length;s=e&&o.endTime<=r)i.push(o);else if(o.startTime>r)return i}return i}},"./src/utils/time-ranges.ts": /*!**********************************!*\ !*** ./src/utils/time-ranges.ts ***! \**********************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i={toString:function(t){for(var e="",r=t.length,i=0;i1?e-1:0),i=1;i100)throw new Error("Position must be between 0 and 100.");y=t,this.hasBeenReset=!0}})),Object.defineProperty(a,"positionAlign",s({},o,{get:function(){return E},set:function(t){var e=n(t);if(!e)throw new SyntaxError("An invalid or illegal string was specified.");E=e,this.hasBeenReset=!0}})),Object.defineProperty(a,"size",s({},o,{get:function(){return T},set:function(t){if(t<0||t>100)throw new Error("Size must be between 0 and 100.");T=t,this.hasBeenReset=!0}})),Object.defineProperty(a,"align",s({},o,{get:function(){return S},set:function(t){var e=n(t);if(!e)throw new SyntaxError("An invalid or illegal string was specified.");S=e,this.hasBeenReset=!0}})),a.displayState=void 0}return a.prototype.getCueAsHTML=function(){var t=self.WebVTT;return t.convertCueToDOMTree(self,this.text)},a}()},"./src/utils/vttparser.ts": /*!********************************!*\ !*** ./src/utils/vttparser.ts ***! \********************************/ /*! exports provided: parseTimeStamp, fixLineBreaks, VTTParser */function(t,e,r){"use strict";r.r(e),r.d(e,"parseTimeStamp",(function(){return s})),r.d(e,"fixLineBreaks",(function(){return d})),r.d(e,"VTTParser",(function(){return h}));var i=r(/*! ./vttcue */"./src/utils/vttcue.ts"),n=function(){function t(){}var e=t.prototype;return e.decode=function(t,e){if(!t)return"";if("string"!==typeof t)throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(t))},t}();function s(t){function e(t,e,r,i){return 3600*(0|t)+60*(0|e)+(0|r)+parseFloat(i||0)}var r=t.match(/^(?:(\d+):)?(\d{2}):(\d{2})(\.\d+)?/);return r?parseFloat(r[2])>59?e(r[2],r[3],0,r[4]):e(r[1],r[2],r[3],r[4]):null}var a=function(){function t(){this.values=Object.create(null)}var e=t.prototype;return e.set=function(t,e){this.get(t)||""===e||(this.values[t]=e)},e.get=function(t,e,r){return r?this.has(t)?this.values[t]:e[r]:this.has(t)?this.values[t]:e},e.has=function(t){return t in this.values},e.alt=function(t,e,r){for(var i=0;i=0&&r<=100)return this.set(t,r),!0}return!1},t}();function o(t,e,r,i){var n=i?t.split(i):[t];for(var s in n)if("string"===typeof n[s]){var a=n[s].split(r);if(2===a.length){var o=a[0],l=a[1];e(o,l)}}}var l=new i["default"](0,0,""),u="middle"===l.align?"middle":"center";function c(t,e,r){var i=t;function n(){var e=s(t);if(null===e)throw new Error("Malformed timestamp: "+i);return t=t.replace(/^[^\sa-zA-Z-]+/,""),e}function c(t,e){var i=new a;o(t,(function(t,e){var n;switch(t){case"region":for(var s=r.length-1;s>=0;s--)if(r[s].id===e){i.set(t,r[s].region);break}break;case"vertical":i.alt(t,e,["rl","lr"]);break;case"line":n=e.split(","),i.integer(t,n[0]),i.percent(t,n[0])&&i.set("snapToLines",!1),i.alt(t,n[0],["auto"]),2===n.length&&i.alt("lineAlign",n[1],["start",u,"end"]);break;case"position":n=e.split(","),i.percent(t,n[0]),2===n.length&&i.alt("positionAlign",n[1],["start",u,"end","line-left","line-right","auto"]);break;case"size":i.percent(t,e);break;case"align":i.alt(t,e,["start",u,"end","left","right"]);break}}),/:/,/\s/),e.region=i.get("region",null),e.vertical=i.get("vertical","");var n=i.get("line","auto");"auto"===n&&-1===l.line&&(n=-1),e.line=n,e.lineAlign=i.get("lineAlign","start"),e.snapToLines=i.get("snapToLines",!0),e.size=i.get("size",100),e.align=i.get("align",u);var s=i.get("position","auto");"auto"===s&&50===l.position&&(s="start"===e.align||"left"===e.align?0:"end"===e.align||"right"===e.align?100:50),e.position=s}function d(){t=t.replace(/^\s+/,"")}if(d(),e.startTime=n(),d(),"--\x3e"!==t.substr(0,3))throw new Error("Malformed time stamp (time stamps must be separated by '--\x3e'): "+i);t=t.substr(3),d(),e.endTime=n(),d(),c(t,e)}function d(t){return t.replace(//gi,"\n")}var h=function(){function t(){this.state="INITIAL",this.buffer="",this.decoder=new n,this.regionList=[],this.cue=null,this.oncue=void 0,this.onparsingerror=void 0,this.onflush=void 0}var e=t.prototype;return e.parse=function(t){var e=this;function r(){var t=e.buffer,r=0;t=d(t);while(r9?parseInt(t.substr(0,t.indexOf(":"))):0;if(!Object(i["isFiniteNumber"])(e)||!Object(i["isFiniteNumber"])(r)||!Object(i["isFiniteNumber"])(n)||!Object(i["isFiniteNumber"])(s))throw Error("Malformed X-TIMESTAMP-MAP: Local:"+t);return e+=1e3*r,e+=6e4*n,e+=36e5*s,e},d=function(t){var e=5381,r=t.length;while(r)e=33*e^t.charCodeAt(--r);return(e>>>0).toString()};function h(t,e,r){return d(t.toString())+d(e.toString())+d(r)}var f=function(t,e,r){var i=t[e],n=t[i.prevCC];if(!n||!n.new&&i.new)return t.ccOffset=t.presentationOffset=i.start,void(i.new=!1);while(null!==(s=n)&&void 0!==s&&s.new){var s;t.ccOffset+=i.start-n.start,i.new=!1,i=n,n=t[i.prevCC]}t.presentationOffset=r};function g(t,e,r,i,d,g,v,p){var m,y=new n["VTTParser"],E=Object(s["utf8ArrayToStr"])(new Uint8Array(t)).trim().replace(l,"\n").split("\n"),T=[],S=Object(a["toMpegTsClockFromTimescale"])(e,r),b="00:00.000",L=0,A=0,D=!0,k=!1;y.oncue=function(t){var e=i[d],r=i.ccOffset,n=(L-S)/9e4;if(null!==e&&void 0!==e&&e.new&&(void 0!==A?r=i.ccOffset=e.start:f(i,d,n)),n&&(r=n-i.presentationOffset),k){var s=t.endTime-t.startTime,a=Object(o["normalizePts"])(9e4*(t.startTime+r-A),9e4*g)/9e4;t.startTime=a,t.endTime=a+s}var l=t.text.trim();t.text=decodeURIComponent(encodeURIComponent(l)),t.id||(t.id=h(t.startTime,t.endTime,l)),t.endTime>0&&T.push(t)},y.onparsingerror=function(t){m=t},y.onflush=function(){m?p(m):v(T)},E.forEach((function(t){if(D){if(u(t,"X-TIMESTAMP-MAP=")){D=!1,k=!0,t.substr(16).split(",").forEach((function(t){u(t,"LOCAL:")?b=t.substr(6):u(t,"MPEGTS:")&&(L=parseInt(t.substr(7)))}));try{A=c(b)/1e3}catch(e){k=!1,m=e}return}""===t&&(D=!1)}y.parse(t+"\n")})),y.flush()}},"./src/utils/xhr-loader.ts": /*!*********************************!*\ !*** ./src/utils/xhr-loader.ts ***! \*********************************/ /*! exports provided: default */function(t,e,r){"use strict";r.r(e);var i=r(/*! ../utils/logger */"./src/utils/logger.ts"),n=r(/*! ../loader/load-stats */"./src/loader/load-stats.ts"),s=/^age:\s*[\d.]+\s*$/m,a=function(){function t(t){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=void 0,this.loader=null,this.stats=void 0,this.xhrSetup=t?t.xhrSetup:null,this.stats=new n["LoadStats"],this.retryDelay=0}var e=t.prototype;return e.destroy=function(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null},e.abortInternal=function(){var t=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),t&&(t.onreadystatechange=null,t.onprogress=null,4!==t.readyState&&(this.stats.aborted=!0,t.abort()))},e.abort=function(){var t;this.abortInternal(),null!==(t=this.callbacks)&&void 0!==t&&t.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)},e.load=function(t,e,r){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=t,this.config=e,this.callbacks=r,this.retryDelay=e.retryDelay,this.loadInternal()},e.loadInternal=function(){var t=this.config,e=this.context;if(t){var r=this.loader=new self.XMLHttpRequest,i=this.stats;i.loading.first=0,i.loaded=0;var n=this.xhrSetup;try{if(n)try{n(r,e.url)}catch(o){r.open("GET",e.url,!0),n(r,e.url)}r.readyState||r.open("GET",e.url,!0);var s=this.context.headers;if(s)for(var a in s)r.setRequestHeader(a,s[a])}catch(o){return void this.callbacks.onError({code:r.status,text:o.message},e,r)}e.rangeEnd&&r.setRequestHeader("Range","bytes="+e.rangeStart+"-"+(e.rangeEnd-1)),r.onreadystatechange=this.readystatechange.bind(this),r.onprogress=this.loadprogress.bind(this),r.responseType=e.responseType,self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),t.timeout),r.send()}},e.readystatechange=function(){var t=this.context,e=this.loader,r=this.stats;if(t&&e){var n=e.readyState,s=this.config;if(!r.aborted&&n>=2)if(self.clearTimeout(this.requestTimeout),0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start)),4===n){e.onreadystatechange=null,e.onprogress=null;var a=e.status;if(a>=200&&a<300){var o,l;if(r.loading.end=Math.max(self.performance.now(),r.loading.first),"arraybuffer"===t.responseType?(o=e.response,l=o.byteLength):(o=e.responseText,l=o.length),r.loaded=r.total=l,!this.callbacks)return;var u=this.callbacks.onProgress;if(u&&u(r,t,o,e),!this.callbacks)return;var c={url:e.responseURL,data:o};this.callbacks.onSuccess(c,r,t,e)}else r.retry>=s.maxRetry||a>=400&&a<499?(i["logger"].error(a+" while loading "+t.url),this.callbacks.onError({code:a,text:e.statusText},t,e)):(i["logger"].warn(a+" while loading "+t.url+", retrying in "+this.retryDelay+"..."),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,s.maxRetryDelay),r.retry++)}else self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),s.timeout)}},e.loadtimeout=function(){i["logger"].warn("timeout while loading "+this.context.url);var t=this.callbacks;t&&(this.abortInternal(),t.onTimeout(this.stats,this.context,this.loader))},e.loadprogress=function(t){var e=this.stats;e.loaded=t.loaded,t.lengthComputable&&(e.total=t.total)},e.getCacheAge=function(){var t=null;if(this.loader&&s.test(this.loader.getAllResponseHeaders())){var e=this.loader.getResponseHeader("age");t=e?parseFloat(e):null}return t},t}();e["default"]=a}})["default"]}))}}]);