typeof window!="undefined"&&function(R,T){typeof exports=="object"&&typeof module=="object"?module.exports=T():typeof define=="function"&&define.amd?define([],T):typeof exports=="object"?exports.Hls=T():R.Hls=T()}(this,function(){return function(w){var R={};function T(_){if(R[_])return R[_].exports;var A=R[_]={i:_,l:!1,exports:{}};return w[_].call(A.exports,A,A.exports,T),A.l=!0,A.exports}return T.m=w,T.c=R,T.d=function(_,A,m){T.o(_,A)||Object.defineProperty(_,A,{enumerable:!0,get:m})},T.r=function(_){typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(_,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(_,"__esModule",{value:!0})},T.t=function(_,A){if(A&1&&(_=T(_)),A&8||A&4&&typeof _=="object"&&_&&_.__esModule)return _;var m=Object.create(null);if(T.r(m),Object.defineProperty(m,"default",{enumerable:!0,value:_}),A&2&&typeof _!="string")for(var y in _)T.d(m,y,function(f){return _[f]}.bind(null,y));return m},T.n=function(_){var A=_&&_.__esModule?function(){return _.default}:function(){return _};return T.d(A,"a",A),A},T.o=function(_,A){return Object.prototype.hasOwnProperty.call(_,A)},T.p="/dist/",T(T.s="./src/hls.js")}({"./node_modules/eventemitter3/index.js":function(w,R,T){"use strict";var _=Object.prototype.hasOwnProperty,A="~";function m(){}Object.create&&(m.prototype=Object.create(null),new m().__proto__||(A=!1));function y(c,a,o){this.fn=c,this.context=a,this.once=o||!1}function f(c,a,o,r,i){if(typeof o!="function")throw new TypeError("The listener must be a function");var t=new y(o,r||c,i),e=A?A+a:a;return c._events[e]?c._events[e].fn?c._events[e]=[c._events[e],t]:c._events[e].push(t):(c._events[e]=t,c._eventsCount++),c}function u(c,a){--c._eventsCount==0?c._events=new m:delete c._events[a]}function p(){this._events=new m,this._eventsCount=0}p.prototype.eventNames=function(){var a=[],o,r;if(this._eventsCount===0)return a;for(r in o=this._events)_.call(o,r)&&a.push(A?r.slice(1):r);return Object.getOwnPropertySymbols?a.concat(Object.getOwnPropertySymbols(o)):a},p.prototype.listeners=function(a){var o=A?A+a:a,r=this._events[o];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,t=r.length,e=new Array(t);i0&&this._events[f].length>p&&(this._events[f].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[f].length),typeof console.trace=="function"&&console.trace())),this},T.prototype.on=T.prototype.addListener,T.prototype.once=function(f,u){if(!_(u))throw TypeError("listener must be a function");var p=!1;function c(){this.removeListener(f,c),p||(p=!0,u.apply(this,arguments))}return c.listener=u,this.on(f,c),this},T.prototype.removeListener=function(f,u){var p,c,a,o;if(!_(u))throw TypeError("listener must be a function");if(!this._events||!this._events[f])return this;if(p=this._events[f],a=p.length,c=-1,p===u||_(p.listener)&&p.listener===u)delete this._events[f],this._events.removeListener&&this.emit("removeListener",f,u);else if(m(p)){for(o=a;o-- >0;)if(p[o]===u||p[o].listener&&p[o].listener===u){c=o;break}if(c<0)return this;p.length===1?(p.length=0,delete this._events[f]):p.splice(c,1),this._events.removeListener&&this.emit("removeListener",f,u)}return this},T.prototype.removeAllListeners=function(f){var u,p;if(!this._events)return this;if(!this._events.removeListener)return arguments.length===0?this._events={}:this._events[f]&&delete this._events[f],this;if(arguments.length===0){for(u in this._events)u!=="removeListener"&&this.removeAllListeners(u);return this.removeAllListeners("removeListener"),this._events={},this}if(p=this._events[f],_(p))this.removeListener(f,p);else if(p)for(;p.length;)this.removeListener(f,p[p.length-1]);return delete this._events[f],this},T.prototype.listeners=function(f){var u;return!this._events||!this._events[f]?u=[]:_(this._events[f])?u=[this._events[f]]:u=this._events[f].slice(),u},T.prototype.listenerCount=function(f){if(this._events){var u=this._events[f];if(_(u))return 1;if(u)return u.length}return 0},T.listenerCount=function(f,u){return f.listenerCount(u)};function _(f){return typeof f=="function"}function A(f){return typeof f=="number"}function m(f){return typeof f=="object"&&f!==null}function y(f){return f===void 0}},"./node_modules/url-toolkit/src/url-toolkit.js":function(w,R,T){(function(_){var A=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,m=/^([^\/?#]*)(.*)$/,y=/(?:\/|^)\.(?=\/)/g,f=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,u={buildAbsoluteURL:function(p,c,a){if(a=a||{},p=p.trim(),c=c.trim(),!c){if(!a.alwaysNormalize)return p;var o=u.parseURL(p);if(!o)throw new Error("Error trying to parse base URL.");return o.path=u.normalizePath(o.path),u.buildURLFromParts(o)}var r=u.parseURL(c);if(!r)throw new Error("Error trying to parse relative URL.");if(r.scheme)return a.alwaysNormalize?(r.path=u.normalizePath(r.path),u.buildURLFromParts(r)):c;var i=u.parseURL(p);if(!i)throw new Error("Error trying to parse base URL.");if(!i.netLoc&&i.path&&i.path[0]!=="/"){var t=m.exec(i.path);i.netLoc=t[1],i.path=t[2]}i.netLoc&&!i.path&&(i.path="/");var e={scheme:i.scheme,netLoc:r.netLoc,path:null,params:r.params,query:r.query,fragment:r.fragment};if(!r.netLoc&&(e.netLoc=i.netLoc,r.path[0]!=="/"))if(!r.path)e.path=i.path,r.params||(e.params=i.params,r.query||(e.query=i.query));else{var n=i.path,d=n.substring(0,n.lastIndexOf("/")+1)+r.path;e.path=u.normalizePath(d)}return e.path===null&&(e.path=a.alwaysNormalize?u.normalizePath(r.path):r.path),u.buildURLFromParts(e)},parseURL:function(p){var c=A.exec(p);return c?{scheme:c[1]||"",netLoc:c[2]||"",path:c[3]||"",params:c[4]||"",query:c[5]||"",fragment:c[6]||""}:null},normalizePath:function(p){for(p=p.split("").reverse().join("").replace(y,"");p.length!==(p=p.replace(f,"")).length;);return p.split("").reverse().join("")},buildURLFromParts:function(p){return p.scheme+p.netLoc+p.path+p.params+p.query+p.fragment}};w.exports=u})(this)},"./node_modules/webworkify-webpack/index.js":function(w,R,T){function _(a){var o={};function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return a[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}r.m=a,r.c=o,r.i=function(t){return t},r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},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="/",r.oe=function(t){throw console.error(t),t};var i=r(r.s=ENTRY_MODULE);return i.default||i}var A="[\\.|\\-|\\+|\\w|/|@]+",m="\\((/\\*.*?\\*/)?s?.*?("+A+").*?\\)";function y(a){return(a+"").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&")}function f(a){return!isNaN(1*a)}function u(a,o,r){var i={};i[r]=[];var t=o.toString(),e=t.match(/^function\s?\(\w+,\s*\w+,\s*(\w+)\)/);if(!e)return i;for(var n=e[1],d=new RegExp("(\\\\n|\\W)"+y(n)+m,"g"),g;g=d.exec(t);)g[3]!=="dll-reference"&&i[r].push(g[3]);for(d=new RegExp("\\("+y(n)+'\\("(dll-reference\\s('+A+'))"\\)\\)'+m,"g");g=d.exec(t);)a[g[2]]||(i[r].push(g[1]),a[g[2]]=T(g[1]).m),i[g[2]]=i[g[2]]||[],i[g[2]].push(g[4]);for(var v=Object.keys(i),s=0;s0},!1)}function c(a,o){for(var r={main:[o]},i={main:[]},t={main:{}};p(r);)for(var e=Object.keys(r),n=0;n500*n.duration/l){var x=t.levels,h=Math.max(1,v.bw?v.bw/8:v.loaded*1e3/s),E=x[n.level],S=E.realBitrate?Math.max(E.realBitrate,E.bitrate):E.bitrate,b=v.total?v.total:Math.max(v.loaded,Math.round(n.duration*S/8)),I=e.currentTime,L=(b-v.loaded)/h,D=(f.BufferHelper.bufferInfo(e,I,t.config.maxBufferHole).end-I)/l;if(D<2*n.duration/l&&L>D){var O=void 0,F=void 0;for(F=n.level-1;F>g;F--){var C=x[F].realBitrate?Math.max(x[F].realBitrate,x[F].bitrate):x[F].bitrate;if(O=n.duration*C/(8*.8*h),O=0)return b;p.logger.trace("rebuffering expected to happen, lets try to find a quality level minimizing the rebuffering");var I=l?Math.min(l,d.maxStarvationDelay):d.maxStarvationDelay,L=d.abrBandWidthFactor,D=d.abrBandWidthUpFactor;if(S===0){var O=this.bitrateTestDelay;if(O){var F=l?Math.min(l,d.maxLoadingDelay):d.maxLoadingDelay;I=F-O,p.logger.trace("bitrate test took "+Math.round(1e3*O)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*I)+" ms"),L=D=1}}return b=this._findBestLevel(s,l,E,g,e,S+I,L,D,n),Math.max(b,0)},enumerable:!0,configurable:!0}),i.prototype._findBestLevel=function(t,e,n,d,g,v,s,l,x){for(var h=g;h>=d;h--){var E=x[h];if(!!E){var S=E.details,b=S?S.totalduration/S.fragments.length:e,I=S?S.live:!1,L=void 0;h<=t?L=s*n:L=l*n;var D=x[h].realBitrate?Math.max(x[h].realBitrate,x[h].bitrate):x[h].bitrate,O=D*b/L;if(p.logger.trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: "+h+"/"+Math.round(L)+"/"+D+"/"+b+"/"+v+"/"+O),L>D&&(!O||I&&!this.bitrateTestDelay||O0&&l===-1?(o.logger.log("audio:override startPosition with lastCurrentTime @"+x.toFixed(3)),this.state=e.State.IDLE):(this.lastCurrentTime=this.startPosition?this.startPosition:l,this.state=e.State.STARTING),this.nextLoadPosition=this.startPosition=this.lastCurrentTime,this.tick()}else this.startPosition=l,this.state=e.State.STOPPED},Object.defineProperty(s.prototype,"state",{get:function(){return this._state},set:function(l){if(this.state!==l){var x=this.state;this._state=l,o.logger.log("audio stream:"+x+"->"+l)}},enumerable:!0,configurable:!0}),s.prototype.doTick=function(){var l,x,h,E=this.hls,S=E.config;switch(this.state){case e.State.ERROR:case e.State.PAUSED:case e.State.BUFFER_FLUSHING:break;case e.State.STARTING:this.state=e.State.WAITING_TRACK,this.loadedmetadata=!1;break;case e.State.IDLE:var b=this.tracks;if(!b||!this.media&&(this.startFragRequested||!S.startFragPrefetch))break;if(this.loadedmetadata)l=this.media.currentTime;else if(l=this.nextLoadPosition,l===void 0)break;var I=this.mediaBuffer?this.mediaBuffer:this.media,L=this.videoBuffer?this.videoBuffer:this.media,D=y.BufferHelper.bufferInfo(I,l,S.maxBufferHole),O=y.BufferHelper.bufferInfo(L,l,S.maxBufferHole),F=D.len,C=D.end,P=this.fragPrevious,k=Math.min(S.maxBufferLength,S.maxMaxBufferLength),B=Math.max(k,O.len),M=this.audioSwitch,N=this.trackId;if((FG||D.nextStart)o.logger.log("alt audio track ahead of main track, seek to start of alt audio track"),this.media.currentTime=G+.05;else return}if(h.initSegment&&!h.initSegment.data)U=h.initSegment;else if(C<=G){if(U=j[0],this.videoTrackCC!==null&&U.cc!==this.videoTrackCC&&(U=r.findFragWithCC(j,this.videoTrackCC)),h.live&&U.loadIdx&&U.loadIdx===this.fragLoadIdx){var V=D.nextStart?D.nextStart:G;o.logger.log("no alt audio available @currentTime:"+this.media.currentTime+", seeking @"+(V+.05)),this.media.currentTime=V+.05;return}}else{var H=void 0,Y=S.maxFragLookUpTolerance,z=P?j[P.sn-j[0].sn+1]:void 0,X=function(q){var Q=Math.min(Y,q.duration);return q.start+q.duration-Q<=C?1:q.start-Q>C&&q.start?-1:0};CW-Y&&(Y=0),z&&!X(z)?H=z:H=m.default.search(j,X)):H=j[K-1],H&&(U=H,G=H.start,P&&U.level===P.level&&U.sn===P.sn&&(U.sn=te||re)&&(o.logger.log("audioStreamController: retryDate reached, switch back to IDLE state"),this.state=e.State.IDLE);break;case e.State.WAITING_INIT_PTS:var $=this.videoTrackCC;if(this.initPTS[$]===void 0)break;var Z=this.waitingFragment;if(Z){var ie=Z.frag.cc;$!==ie?(x=this.tracks[this.trackId],x.details&&x.details.live&&(o.logger.warn("Waiting fragment CC ("+ie+") does not match video track CC ("+$+")"),this.waitingFragment=null,this.state=e.State.IDLE)):(this.state=e.State.FRAG_LOADING,this.onFragLoaded(this.waitingFragment),this.waitingFragment=null)}else this.state=e.State.IDLE;break;case e.State.STOPPED:case e.State.FRAG_LOADING:case e.State.PARSING:case e.State.PARSED:case e.State.ENDED:break;default:break}},s.prototype.onMediaAttached=function(l){var x=this.media=this.mediaBuffer=l.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),x.addEventListener("seeking",this.onvseeking),x.addEventListener("ended",this.onvended);var h=this.config;this.tracks&&h.autoStartLoad&&this.startLoad(h.startPosition)},s.prototype.onMediaDetaching=function(){var l=this.media;l&&l.ended&&(o.logger.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),l&&(l.removeEventListener("seeking",this.onvseeking),l.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvended=null),this.media=this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1,this.stopLoad()},s.prototype.onAudioTracksUpdated=function(l){o.logger.log("audio tracks updated"),this.tracks=l.audioTracks},s.prototype.onAudioTrackSwitching=function(l){var x=!!l.url;this.trackId=l.id,this.fragCurrent=null,this.state=e.State.PAUSED,this.waitingFragment=null,x?this.setInterval(d):this.demuxer&&(this.demuxer.destroy(),this.demuxer=null),x&&(this.audioSwitch=!0,this.state=e.State.IDLE),this.tick()},s.prototype.onAudioTrackLoaded=function(l){var x=l.details,h=l.id,E=this.tracks[h],S=x.totalduration,b=0;if(o.logger.log("track "+h+" loaded ["+x.startSN+","+x.endSN+"],duration:"+S),x.live){var I=E.details;I&&x.fragments.length>0?(p.mergeDetails(I,x),b=x.fragments[0].start,x.PTSKnown?o.logger.log("live audio playlist sliding:"+b.toFixed(3)):o.logger.log("live audio playlist - outdated PTS, unknown sliding")):(x.PTSKnown=!1,o.logger.log("live audio playlist - first load, unknown sliding"))}else x.PTSKnown=!1;if(E.details=x,!this.startFragRequested){if(this.startPosition===-1){var L=x.startTimeOffset;_.isFinite(L)?(o.logger.log("start time offset found in playlist, adjust startPosition to "+L),this.startPosition=L):this.startPosition=0}this.nextLoadPosition=this.startPosition}this.state===e.State.WAITING_TRACK&&(this.state=e.State.IDLE),this.tick()},s.prototype.onKeyLoaded=function(){this.state===e.State.KEY_LOADING&&(this.state=e.State.IDLE,this.tick())},s.prototype.onFragLoaded=function(l){var x=this.fragCurrent,h=l.frag;if(this.state===e.State.FRAG_LOADING&&x&&h.type==="audio"&&h.level===x.level&&h.sn===x.sn){var E=this.tracks[this.trackId],S=E.details,b=S.totalduration,I=x.level,L=x.sn,D=x.cc,O=this.config.defaultAudioCodec||E.audioCodec||"mp4a.40.2",F=this.stats=l.stats;if(L==="initSegment")this.state=e.State.IDLE,F.tparsed=F.tbuffered=n.now(),S.initSegment.data=l.payload,this.hls.trigger(u.default.FRAG_BUFFERED,{stats:F,frag:x,id:"audio"}),this.tick();else{this.state=e.State.PARSING,this.appended=!1,this.demuxer||(this.demuxer=new f.default(this.hls,"audio"));var C=this.initPTS[D],P=S.initSegment?S.initSegment.data:[];if(S.initSegment||C!==void 0){this.pendingBuffering=!0,o.logger.log("Demuxing "+L+" of ["+S.startSN+" ,"+S.endSN+"],track "+I);var k=!1;this.demuxer.push(l.payload,P,O,null,x,b,k,C)}else o.logger.log("unknown video PTS for continuity counter "+D+", waiting for video PTS before demuxing audio frag "+L+" of ["+S.startSN+" ,"+S.endSN+"],track "+I),this.waitingFragment=l,this.state=e.State.WAITING_INIT_PTS}}this.fragLoadError=0},s.prototype.onFragParsingInitSegment=function(l){var x=this.fragCurrent,h=l.frag;if(x&&l.id==="audio"&&h.sn===x.sn&&h.level===x.level&&this.state===e.State.PARSING){var E=l.tracks,S=void 0;if(E.video&&delete E.video,S=E.audio,S){S.levelCodec=S.codec,S.id=l.id,this.hls.trigger(u.default.BUFFER_CODECS,E),o.logger.log("audio track:audio,container:"+S.container+",codecs[level/parsed]=["+S.levelCodec+"/"+S.codec+"]");var b=S.initSegment;if(b){var I={type:"audio",data:b,parent:"audio",content:"initSegment"};this.audioSwitch?this.pendingData=[I]:(this.appended=!0,this.pendingBuffering=!0,this.hls.trigger(u.default.BUFFER_APPENDING,I))}this.tick()}}},s.prototype.onFragParsingData=function(l){var x=this,h=this.fragCurrent,E=l.frag;if(h&&l.id==="audio"&&l.type==="audio"&&E.sn===h.sn&&E.level===h.level&&this.state===e.State.PARSING){var S=this.trackId,b=this.tracks[S],I=this.hls;_.isFinite(l.endPTS)||(l.endPTS=l.startPTS+h.duration,l.endDTS=l.startDTS+h.duration),h.addElementaryStream(t.default.ElementaryStreamTypes.AUDIO),o.logger.log("parsed "+l.type+",PTS:["+l.startPTS.toFixed(3)+","+l.endPTS.toFixed(3)+"],DTS:["+l.startDTS.toFixed(3)+"/"+l.endDTS.toFixed(3)+"],nb:"+l.nb),p.updateFragPTSDTS(b.details,h,l.startPTS,l.endPTS);var L=this.audioSwitch,D=this.media,O=!1;if(L&&D)if(D.readyState){var F=D.currentTime;o.logger.log("switching audio track : currentTime:"+F),F>=l.startPTS&&(o.logger.log("switching audio track : flushing all audio"),this.state=e.State.BUFFER_FLUSHING,I.trigger(u.default.BUFFER_FLUSHING,{startOffset:0,endOffset:_.POSITIVE_INFINITY,type:"audio"}),O=!0,this.audioSwitch=!1,I.trigger(u.default.AUDIO_TRACK_SWITCHED,{id:S}))}else this.audioSwitch=!1,I.trigger(u.default.AUDIO_TRACK_SWITCHED,{id:S});var C=this.pendingData;if(!C){o.logger.warn("Apparently attempt to enqueue media payload without codec initialization data upfront"),I.trigger(u.default.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:null,fatal:!0});return}this.audioSwitch||([l.data1,l.data2].forEach(function(P){P&&P.length&&C.push({type:l.type,data:P,parent:"audio",content:"data"})}),!O&&C.length&&(C.forEach(function(P){x.state===e.State.PARSING&&(x.pendingBuffering=!0,x.hls.trigger(u.default.BUFFER_APPENDING,P))}),this.pendingData=[],this.appended=!0)),this.tick()}},s.prototype.onFragParsed=function(l){var x=this.fragCurrent,h=l.frag;x&&l.id==="audio"&&h.sn===x.sn&&h.level===x.level&&this.state===e.State.PARSING&&(this.stats.tparsed=n.now(),this.state=e.State.PARSED,this._checkAppendedParsed())},s.prototype.onBufferReset=function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1},s.prototype.onBufferCreated=function(l){var x=l.tracks.audio;x&&(this.mediaBuffer=x.buffer,this.loadedmetadata=!0),l.tracks.video&&(this.videoBuffer=l.tracks.video.buffer)},s.prototype.onBufferAppended=function(l){if(l.parent==="audio"){var x=this.state;(x===e.State.PARSING||x===e.State.PARSED)&&(this.pendingBuffering=l.pending>0,this._checkAppendedParsed())}},s.prototype._checkAppendedParsed=function(){if(this.state===e.State.PARSED&&(!this.appended||!this.pendingBuffering)){var l=this.fragCurrent,x=this.stats,h=this.hls;if(l){this.fragPrevious=l,x.tbuffered=n.now(),h.trigger(u.default.FRAG_BUFFERED,{stats:x,frag:l,id:"audio"});var E=this.mediaBuffer?this.mediaBuffer:this.media;o.logger.log("audio buffered : "+c.default.toString(E.buffered)),this.audioSwitch&&this.appended&&(this.audioSwitch=!1,h.trigger(u.default.AUDIO_TRACK_SWITCHED,{id:this.trackId})),this.state=e.State.IDLE}this.tick()}},s.prototype.onError=function(l){var x=l.frag;if(!(x&&x.type!=="audio"))switch(l.details){case a.ErrorDetails.FRAG_LOAD_ERROR:case a.ErrorDetails.FRAG_LOAD_TIMEOUT:var h=l.frag;if(h&&h.type!=="audio")break;if(!l.fatal){var E=this.fragLoadError;E?E++:E=1;var S=this.config;if(E<=S.fragLoadingMaxRetry){this.fragLoadError=E;var b=Math.min(Math.pow(2,E-1)*S.fragLoadingRetryDelay,S.fragLoadingMaxRetryTimeout);o.logger.warn("AudioStreamController: frag loading failed, retry in "+b+" ms"),this.retryDate=n.now()+b,this.state=e.State.FRAG_LOADING_WAITING_RETRY}else o.logger.error("AudioStreamController: "+l.details+" reaches max retry, redispatch as fatal ..."),l.fatal=!0,this.state=e.State.ERROR}break;case a.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:case a.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:case a.ErrorDetails.KEY_LOAD_ERROR:case a.ErrorDetails.KEY_LOAD_TIMEOUT:this.state!==e.State.ERROR&&(this.state=l.fatal?e.State.ERROR:e.State.IDLE,o.logger.warn("AudioStreamController: "+l.details+" while loading frag, now switching to "+this.state+" state ..."));break;case a.ErrorDetails.BUFFER_FULL_ERROR:if(l.parent==="audio"&&(this.state===e.State.PARSING||this.state===e.State.PARSED)){var I=this.mediaBuffer,L=this.media.currentTime,D=I&&y.BufferHelper.isBuffered(I,L)&&y.BufferHelper.isBuffered(I,L+.5);if(D){var S=this.config;S.maxMaxBufferLength>=S.maxBufferLength&&(S.maxMaxBufferLength/=2,o.logger.warn("AudioStreamController: reduce max buffer length to "+S.maxMaxBufferLength+"s")),this.state=e.State.IDLE}else o.logger.warn("AudioStreamController: buffer full error also media.currentTime is not buffered, flush audio buffer"),this.fragCurrent=null,this.state=e.State.BUFFER_FLUSHING,this.hls.trigger(u.default.BUFFER_FLUSHING,{startOffset:0,endOffset:_.POSITIVE_INFINITY,type:"audio"})}break;default:break}},s.prototype.onBufferFlushed=function(){var l=this,x=this.pendingData;x&&x.length?(o.logger.log("AudioStreamController: appending pending audio data after buffer flushed"),x.forEach(function(h){l.hls.trigger(u.default.BUFFER_APPENDING,h)}),this.appended=!0,this.pendingData=[],this.state=e.State.PARSED):(this.state=e.State.IDLE,this.fragPrevious=null,this.tick())},s}(e.default);R.default=g}).call(this,T("./src/polyfills/number.js").Number)},"./src/controller/audio-track-controller.js":function(w,R,T){"use strict";var _=this&&this.__extends||function(){var p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,a){c.__proto__=a}||function(c,a){for(var o in a)a.hasOwnProperty(o)&&(c[o]=a[o])};return function(c,a){p(c,a);function o(){this.constructor=c}c.prototype=a===null?Object.create(a):(o.prototype=a.prototype,new o)}}();Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/events.js"),m=T("./src/task-loop.js"),y=T("./src/utils/logger.js"),f=T("./src/errors.js"),u=function(p){_(c,p);function c(a){var o=p.call(this,a,A.default.MANIFEST_LOADING,A.default.MANIFEST_PARSED,A.default.AUDIO_TRACK_LOADED,A.default.AUDIO_TRACK_SWITCHED,A.default.LEVEL_LOADED,A.default.ERROR)||this;return o._trackId=-1,o._selectDefaultTrack=!0,o.tracks=[],o.trackIdBlacklist=Object.create(null),o.audioGroupId=null,o}return c.prototype.onManifestLoading=function(){this.tracks=[],this._trackId=-1,this._selectDefaultTrack=!0},c.prototype.onManifestParsed=function(a){var o=this.tracks=a.audioTracks||[];this.hls.trigger(A.default.AUDIO_TRACKS_UPDATED,{audioTracks:o})},c.prototype.onAudioTrackLoaded=function(a){if(a.id>=this.tracks.length){y.logger.warn("Invalid audio track id:",a.id);return}if(y.logger.log("audioTrack "+a.id+" loaded"),this.tracks[a.id].details=a.details,a.details.live&&!this.hasInterval()){var o=a.details.targetduration*1e3;this.setInterval(o)}!a.details.live&&this.hasInterval()&&this.clearInterval()},c.prototype.onAudioTrackSwitched=function(a){var o=this.tracks[a.id].groupId;o&&this.audioGroupId!==o&&(this.audioGroupId=o)},c.prototype.onLevelLoaded=function(a){var o=this.hls.levels[a.level];if(!!o.audioGroupIds){var r=o.audioGroupIds[o.urlId];this.audioGroupId!==r&&(this.audioGroupId=r,this._selectInitialAudioTrack())}},c.prototype.onError=function(a){a.type===f.ErrorTypes.NETWORK_ERROR&&(a.fatal&&this.clearInterval(),a.details===f.ErrorDetails.AUDIO_TRACK_LOAD_ERROR&&(y.logger.warn("Network failure on audio-track id:",a.context.id),this._handleLoadError()))},Object.defineProperty(c.prototype,"audioTracks",{get:function(){return this.tracks},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"audioTrack",{get:function(){return this._trackId},set:function(a){this._setAudioTrack(a),this._selectDefaultTrack=!1},enumerable:!0,configurable:!0}),c.prototype._setAudioTrack=function(a){if(this._trackId===a&&this.tracks[this._trackId].details){y.logger.debug("Same id as current audio-track passed, and track details available -> no-op");return}if(a<0||a>=this.tracks.length){y.logger.warn("Invalid id passed to audio-track controller");return}var o=this.tracks[a];y.logger.log("Now switching to audio-track index "+a),this.clearInterval(),this._trackId=a;var r=o.url,i=o.type,t=o.id;this.hls.trigger(A.default.AUDIO_TRACK_SWITCHING,{id:t,type:i,url:r}),this._loadTrackDetailsIfNeeded(o)},c.prototype.doTick=function(){this._updateTrack(this._trackId)},c.prototype._selectInitialAudioTrack=function(){var a=this,o=this.tracks;if(!!o.length){var r=this.tracks[this._trackId],i=null;if(r&&(i=r.name),this._selectDefaultTrack){var t=o.filter(function(d){return d.default});t.length?o=t:y.logger.warn("No default audio tracks defined")}var e=!1,n=function(){o.forEach(function(d){e||(!a.audioGroupId||d.groupId===a.audioGroupId)&&(!i||i===d.name)&&(a._setAudioTrack(d.id),e=!0)})};n(),e||(i=null,n()),e||(y.logger.error("No track found for running audio group-ID: "+this.audioGroupId),this.hls.trigger(A.default.ERROR,{type:f.ErrorTypes.MEDIA_ERROR,details:f.ErrorDetails.AUDIO_TRACK_LOAD_ERROR,fatal:!0}))}},c.prototype._needsTrackLoading=function(a){var o=a.details,r=a.url;return!o||o.live?!!r:!1},c.prototype._loadTrackDetailsIfNeeded=function(a){if(this._needsTrackLoading(a)){var o=a.url,r=a.id;y.logger.log("loading audio-track playlist for id: "+r),this.hls.trigger(A.default.AUDIO_TRACK_LOADING,{url:o,id:r})}},c.prototype._updateTrack=function(a){if(!(a<0||a>=this.tracks.length)){this.clearInterval(),this._trackId=a,y.logger.log("trying to update audio-track "+a);var o=this.tracks[a];this._loadTrackDetailsIfNeeded(o)}},c.prototype._handleLoadError=function(){this.trackIdBlacklist[this._trackId]=!0;var a=this._trackId,o=this.tracks[a],r=o.name,i=o.language,t=o.groupId;y.logger.warn("Loading failed on audio track id: "+a+", group-id: "+t+', name/language: "'+r+'" / "'+i+'"');for(var e=a,n=0;nl?(g.loader&&(u.logger.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),g.loader.abort()),this.fragCurrent=null,this.fragPrevious=null,this.state=R.State.IDLE):u.logger.log("seeking outside of buffer but within currently loaded fragment range")}}else e===R.State.ENDED&&(d.len===0&&(this.fragPrevious=null,this.fragCurrent=null),this.state=R.State.IDLE);i&&(this.lastCurrentTime=n),this.loadedmetadata||(this.nextLoadPosition=this.startPosition=n),this.tick()},a.prototype.onMediaEnded=function(){this.startPosition=this.lastCurrentTime=0},a.prototype.onHandlerDestroying=function(){this.stopLoad(),c.prototype.onHandlerDestroying.call(this)},a.prototype.onHandlerDestroyed=function(){this.state=R.State.STOPPED,this.fragmentTracker=null},a}(m.default);R.default=p}).call(this,T("./src/polyfills/number.js").Number)},"./src/controller/buffer-controller.js":function(w,R,T){"use strict";(function(_){var A=this&&this.__extends||function(){var o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var t in i)i.hasOwnProperty(t)&&(r[t]=i[t])};return function(r,i){o(r,i);function t(){this.constructor=r}r.prototype=i===null?Object.create(i):(t.prototype=i.prototype,new t)}}();Object.defineProperty(R,"__esModule",{value:!0});var m=T("./src/events.js"),y=T("./src/event-handler.js"),f=T("./src/utils/logger.js"),u=T("./src/errors.js"),p=T("./src/utils/mediasource-helper.js"),c=p.getMediaSource(),a=function(o){A(r,o);function r(i){var t=o.call(this,i,m.default.MEDIA_ATTACHING,m.default.MEDIA_DETACHING,m.default.MANIFEST_PARSED,m.default.BUFFER_RESET,m.default.BUFFER_APPENDING,m.default.BUFFER_CODECS,m.default.BUFFER_EOS,m.default.BUFFER_FLUSHING,m.default.LEVEL_PTS_UPDATED,m.default.LEVEL_UPDATED)||this;return t._msDuration=null,t._levelDuration=null,t._levelTargetDuration=10,t._live=null,t._objectUrl=null,t.bufferCodecEventsExpected=0,t.onsbue=t.onSBUpdateEnd.bind(t),t.onsbe=t.onSBUpdateError.bind(t),t.pendingTracks={},t.tracks={},t}return r.prototype.destroy=function(){y.default.prototype.destroy.call(this)},r.prototype.onLevelPtsUpdated=function(i){var t=i.type,e=this.tracks.audio;if(t==="audio"&&e&&e.container==="audio/mpeg"){var n=this.sourceBuffer.audio,d=Math.abs(n.timestampOffset-i.start);if(d>.1){var g=n.updating;try{n.abort()}catch(v){f.logger.warn("can not abort audio buffer: "+v)}g?this.audioTimestampOffset=i.start:(f.logger.warn("change mpeg audio timestamp offset from "+n.timestampOffset+" to "+i.start),n.timestampOffset=i.start)}}},r.prototype.onManifestParsed=function(i){this.bufferCodecEventsExpected=i.altAudio?2:1,f.logger.log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},r.prototype.onMediaAttaching=function(i){var t=this.media=i.media;if(t){var e=this.mediaSource=new c;this.onmso=this.onMediaSourceOpen.bind(this),this.onmse=this.onMediaSourceEnded.bind(this),this.onmsc=this.onMediaSourceClose.bind(this),e.addEventListener("sourceopen",this.onmso),e.addEventListener("sourceended",this.onmse),e.addEventListener("sourceclose",this.onmsc),t.src=window.URL.createObjectURL(e),this._objectUrl=t.src}},r.prototype.onMediaDetaching=function(){f.logger.log("media source detaching");var i=this.mediaSource;if(i){if(i.readyState==="open")try{i.endOfStream()}catch(t){f.logger.warn("onMediaDetaching:"+t.message+" while calling endOfStream")}i.removeEventListener("sourceopen",this.onmso),i.removeEventListener("sourceended",this.onmse),i.removeEventListener("sourceclose",this.onmsc),this.media&&(window.URL.revokeObjectURL(this._objectUrl),this.media.src===this._objectUrl?(this.media.removeAttribute("src"),this.media.load()):f.logger.warn("media.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.pendingTracks={},this.tracks={},this.sourceBuffer={},this.flushRange=[],this.segments=[],this.appended=0}this.onmso=this.onmse=this.onmsc=null,this.hls.trigger(m.default.MEDIA_DETACHED)},r.prototype.onMediaSourceOpen=function(){f.logger.log("media source opened"),this.hls.trigger(m.default.MEDIA_ATTACHED,{media:this.media});var i=this.mediaSource;i&&i.removeEventListener("sourceopen",this.onmso),this.checkPendingTracks()},r.prototype.checkPendingTracks=function(){var i=this,t=i.bufferCodecEventsExpected,e=i.pendingTracks,n=Object.keys(e).length;(n&&!t||n===2)&&(this.createSourceBuffers(e),this.pendingTracks={},this.doAppending())},r.prototype.onMediaSourceClose=function(){f.logger.log("media source closed")},r.prototype.onMediaSourceEnded=function(){f.logger.log("media source ended")},r.prototype.onSBUpdateEnd=function(){if(this.audioTimestampOffset){var i=this.sourceBuffer.audio;f.logger.warn("change mpeg audio timestamp offset from "+i.timestampOffset+" to "+this.audioTimestampOffset),i.timestampOffset=this.audioTimestampOffset,delete this.audioTimestampOffset}this._needsFlush&&this.doFlush(),this._needsEos&&this.checkEos(),this.appending=!1;var t=this.parent,e=this.segments.reduce(function(v,s){return s.parent===t?v+1:v},0),n={},d=this.sourceBuffer;for(var g in d)n[g]=d[g].buffered;this.hls.trigger(m.default.BUFFER_APPENDED,{parent:t,pending:e,timeRanges:n}),this._needsFlush||this.doAppending(),this.updateMediaElementDuration(),e===0&&this.flushLiveBackBuffer()},r.prototype.onSBUpdateError=function(i){f.logger.error("sourceBuffer error:",i),this.hls.trigger(m.default.ERROR,{type:u.ErrorTypes.MEDIA_ERROR,details:u.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1})},r.prototype.onBufferReset=function(){var i=this.sourceBuffer;for(var t in i){var e=i[t];try{this.mediaSource.removeSourceBuffer(e),e.removeEventListener("updateend",this.onsbue),e.removeEventListener("error",this.onsbe)}catch(n){}}this.sourceBuffer={},this.flushRange=[],this.segments=[],this.appended=0},r.prototype.onBufferCodecs=function(i){var t=this;if(!Object.keys(this.sourceBuffer).length){Object.keys(i).forEach(function(n){t.pendingTracks[n]=i[n]});var e=this.mediaSource;this.bufferCodecEventsExpected=Math.max(this.bufferCodecEventsExpected-1,0),e&&e.readyState==="open"&&this.checkPendingTracks()}},r.prototype.createSourceBuffers=function(i){var t=this.sourceBuffer,e=this.mediaSource;for(var n in i)if(!t[n]){var d=i[n],g=d.levelCodec||d.codec,v=d.container+";codecs="+g;f.logger.log("creating sourceBuffer("+v+")");try{var s=t[n]=e.addSourceBuffer(v);s.addEventListener("updateend",this.onsbue),s.addEventListener("error",this.onsbe),this.tracks[n]={codec:g,container:d.container},d.buffer=s}catch(l){f.logger.error("error while trying to add sourceBuffer:"+l.message),this.hls.trigger(m.default.ERROR,{type:u.ErrorTypes.MEDIA_ERROR,details:u.ErrorDetails.BUFFER_ADD_CODEC_ERROR,fatal:!1,err:l,mimeType:v})}}this.hls.trigger(m.default.BUFFER_CREATED,{tracks:i})},r.prototype.onBufferAppending=function(i){this._needsFlush||(this.segments?this.segments.push(i):this.segments=[i],this.doAppending())},r.prototype.onBufferAppendFail=function(i){f.logger.error("sourceBuffer error:",i.event),this.hls.trigger(m.default.ERROR,{type:u.ErrorTypes.MEDIA_ERROR,details:u.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1})},r.prototype.onBufferEos=function(i){var t=this.sourceBuffer,e=i.type;for(var n in t)(!e||n===e)&&(t[n].ended||(t[n].ended=!0,f.logger.log(n+" sourceBuffer now EOS")));this.checkEos()},r.prototype.checkEos=function(){var i=this.sourceBuffer,t=this.mediaSource;if(!t||t.readyState!=="open"){this._needsEos=!1;return}for(var e in i){var n=i[e];if(!n.ended)return;if(n.updating){this._needsEos=!0;return}}f.logger.log("all media data are available, signal endOfStream() to MediaSource and stop loading fragment");try{t.endOfStream()}catch(d){f.logger.warn("exception while calling mediaSource.endOfStream()")}this._needsEos=!1},r.prototype.onBufferFlushing=function(i){this.flushRange.push({start:i.startOffset,end:i.endOffset,type:i.type}),this.flushBufferCounter=0,this.doFlush()},r.prototype.flushLiveBackBuffer=function(){if(!!this._live){var i=this.hls.config.liveBackBufferLength;if(!(!isFinite(i)||i<0))for(var t=this.media.currentTime,e=this.sourceBuffer,n=Object.keys(e),d=t-Math.max(i,this._levelTargetDuration),g=n.length-1;g>=0;g--){var v=n[g],s=e[v].buffered;s.length>0&&d>s.start(0)&&this.removeBufferRange(v,e[v],0,d)}}},r.prototype.onLevelUpdated=function(i){var t=i.details;t.fragments.length>0&&(this._levelDuration=t.totalduration+t.fragments[0].start,this._levelTargetDuration=t.averagetargetduration||t.targetduration||10,this._live=t.live,this.updateMediaElementDuration())},r.prototype.updateMediaElementDuration=function(){var i=this.hls.config,t;if(!(this._levelDuration===null||!this.media||!this.mediaSource||!this.sourceBuffer||this.media.readyState===0||this.mediaSource.readyState!=="open")){for(var e in this.sourceBuffer)if(this.sourceBuffer[e].updating===!0)return;t=this.media.duration,this._msDuration===null&&(this._msDuration=this.mediaSource.duration),this._live===!0&&i.liveDurationInfinity===!0?(f.logger.log("Media Source duration is set to Infinity"),this._msDuration=this.mediaSource.duration=Infinity):(this._levelDuration>this._msDuration&&this._levelDuration>t||!_.isFinite(t))&&(f.logger.log("Updating Media Source duration to "+this._levelDuration.toFixed(3)),this._msDuration=this.mediaSource.duration=this._levelDuration)}},r.prototype.doFlush=function(){for(;this.flushRange.length;){var i=this.flushRange[0];if(this.flushBuffer(i.start,i.end,i.type))this.flushRange.shift(),this.flushBufferCounter=0;else{this._needsFlush=!0;return}}if(this.flushRange.length===0){this._needsFlush=!1;var t=0,e=this.sourceBuffer;try{for(var n in e)t+=e[n].buffered.length}catch(d){f.logger.error("error while accessing sourceBuffer.buffered")}this.appended=t,this.hls.trigger(m.default.BUFFER_FLUSHED)}},r.prototype.doAppending=function(){var i=this,t=i.hls,e=i.segments,n=i.sourceBuffer;if(Object.keys(n).length){if(this.media.error){this.segments=[],f.logger.error("trying to append although a media error occured, flush segment and abort");return}if(this.appending)return;if(e&&e.length){var d=e.shift();try{var g=d.type,v=n[g];v?v.updating?e.unshift(d):(v.ended=!1,this.parent=d.parent,v.appendBuffer(d.data),this.appendError=0,this.appended++,this.appending=!0):this.onSBUpdateEnd()}catch(l){f.logger.error("error while trying to append buffer:"+l.message),e.unshift(d);var s={type:u.ErrorTypes.MEDIA_ERROR,parent:d.parent};l.code!==22?(this.appendError?this.appendError++:this.appendError=1,s.details=u.ErrorDetails.BUFFER_APPEND_ERROR,this.appendError>t.config.appendErrorMaxRetry?(f.logger.log("fail "+t.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),this.segments=[],s.fatal=!0,t.trigger(m.default.ERROR,s)):(s.fatal=!1,t.trigger(m.default.ERROR,s))):(this.segments=[],s.details=u.ErrorDetails.BUFFER_FULL_ERROR,s.fatal=!1,t.trigger(m.default.ERROR,s))}}}},r.prototype.flushBuffer=function(i,t,e){var n,d=this.sourceBuffer;if(Object.keys(d).length){if(f.logger.log("flushBuffer,pos/start/end: "+this.media.currentTime.toFixed(3)+"/"+i+"/"+t),this.flushBufferCounter.5)return f.logger.log("sb remove "+i+" ["+s+","+l+"], of ["+g+","+v+"], pos:"+this.media.currentTime),t.remove(s,l),!0}}catch(x){f.logger.warn("removeBufferRange failed",x)}return!1},r}(y.default);R.default=a}).call(this,T("./src/polyfills/number.js").Number)},"./src/controller/cap-level-controller.js":function(w,R,T){"use strict";(function(_){var A=this&&this.__extends||function(){var u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(p,c){p.__proto__=c}||function(p,c){for(var a in c)c.hasOwnProperty(a)&&(p[a]=c[a])};return function(p,c){u(p,c);function a(){this.constructor=p}p.prototype=c===null?Object.create(c):(a.prototype=c.prototype,new a)}}();Object.defineProperty(R,"__esModule",{value:!0});var m=T("./src/events.js"),y=T("./src/event-handler.js"),f=function(u){A(p,u);function p(c){var a=u.call(this,c,m.default.FPS_DROP_LEVEL_CAPPING,m.default.MEDIA_ATTACHING,m.default.MANIFEST_PARSED,m.default.BUFFER_CODECS,m.default.MEDIA_DETACHING)||this;return a.autoLevelCapping=_.POSITIVE_INFINITY,a.firstLevel=null,a.levels=[],a.media=null,a.restrictedLevels=[],a.timer=null,a}return p.prototype.destroy=function(){this.hls.config.capLevelToPlayerSize&&(this.media=null,this._stopCapping())},p.prototype.onFpsDropLevelCapping=function(c){p.isLevelAllowed(c.droppedLevel,this.restrictedLevels)&&this.restrictedLevels.push(c.droppedLevel)},p.prototype.onMediaAttaching=function(c){this.media=c.media instanceof window.HTMLVideoElement?c.media:null},p.prototype.onManifestParsed=function(c){var a=this.hls;this.restrictedLevels=[],this.levels=c.levels,this.firstLevel=c.firstLevel,a.config.capLevelToPlayerSize&&c.video&&this._startCapping()},p.prototype.onBufferCodecs=function(c){var a=this.hls;a.config.capLevelToPlayerSize&&c.video&&this._startCapping()},p.prototype.onLevelsUpdated=function(c){this.levels=c.levels},p.prototype.onMediaDetaching=function(){this._stopCapping()},p.prototype.detectPlayerSize=function(){if(this.media){var c=this.levels?this.levels.length:0;if(c){var a=this.hls;a.autoLevelCapping=this.getMaxLevel(c-1),a.autoLevelCapping>this.autoLevelCapping&&a.streamController.nextLevelSwitch(),this.autoLevelCapping=a.autoLevelCapping}}},p.prototype.getMaxLevel=function(c){var a=this;if(!this.levels)return-1;var o=this.levels.filter(function(r,i){return p.isLevelAllowed(i,a.restrictedLevels)&&i<=c});return p.getMaxLevelByMediaSize(o,this.mediaWidth,this.mediaHeight)},p.prototype._startCapping=function(){this.timer||(this.autoLevelCapping=_.POSITIVE_INFINITY,this.hls.firstLevel=this.getMaxLevel(this.firstLevel),clearInterval(this.timer),this.timer=setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},p.prototype._stopCapping=function(){this.restrictedLevels=[],this.firstLevel=null,this.autoLevelCapping=_.POSITIVE_INFINITY,this.timer&&(this.timer=clearInterval(this.timer),this.timer=null)},Object.defineProperty(p.prototype,"mediaWidth",{get:function(){var c,a=this.media;return a&&(c=a.width||a.clientWidth||a.offsetWidth,c*=p.contentScaleFactor),c},enumerable:!0,configurable:!0}),Object.defineProperty(p.prototype,"mediaHeight",{get:function(){var c,a=this.media;return a&&(c=a.height||a.clientHeight||a.offsetHeight,c*=p.contentScaleFactor),c},enumerable:!0,configurable:!0}),Object.defineProperty(p,"contentScaleFactor",{get:function(){var c=1;try{c=window.devicePixelRatio}catch(a){}return c},enumerable:!0,configurable:!0}),p.isLevelAllowed=function(c,a){return a===void 0&&(a=[]),a.indexOf(c)===-1},p.getMaxLevelByMediaSize=function(c,a,o){if(!c||c&&!c.length)return-1;for(var r=function(n,d){return d?n.width!==d.width||n.height!==d.height:!0},i=c.length-1,t=0;t=a||e.height>=o)&&r(e,c[t+1])){i=t;break}}return i},p}(y.default);R.default=f}).call(this,T("./src/polyfills/number.js").Number)},"./src/controller/eme-controller.js":function(w,R,T){"use strict";var _=this&&this.__extends||function(){var i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(t,e){i(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/event-handler.js"),m=T("./src/events.js"),y=T("./src/errors.js"),f=T("./src/utils/logger.js"),u=window.XMLHttpRequest,p=3,c={WIDEVINE:"com.widevine.alpha",PLAYREADY:"com.microsoft.playready"},a=function(i,t,e){var n={videoCapabilities:[]};return t.forEach(function(d){n.videoCapabilities.push({contentType:'video/mp4; codecs="'+d+'"'})}),[n]},o=function(i,t,e){switch(i){case c.WIDEVINE:return a(t,e);default:throw Error("Unknown key-system: "+i)}},r=function(i){_(t,i);function t(e){var n=i.call(this,e,m.default.MEDIA_ATTACHED,m.default.MANIFEST_PARSED)||this;return n._widevineLicenseUrl=e.config.widevineLicenseUrl,n._licenseXhrSetup=e.config.licenseXhrSetup,n._emeEnabled=e.config.emeEnabled,n._requestMediaKeySystemAccess=e.config.requestMediaKeySystemAccessFunc,n._mediaKeysList=[],n._media=null,n._hasSetMediaKeys=!1,n._isMediaEncrypted=!1,n._requestLicenseFailureCount=0,n}return t.prototype.getLicenseServerUrl=function(e){var n;switch(e){case c.WIDEVINE:n=this._widevineLicenseUrl;break;default:n=null;break}return n||(f.logger.error('No license server URL configured for key-system "'+e+'"'),this.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0})),n},t.prototype._attemptKeySystemAccess=function(e,n,d){var g=this,v=o(e,n,d);if(!v){f.logger.warn("Can not create config for key-system (maybe because platform is not supported):",e);return}f.logger.log("Requesting encrypted media key-system access"),this.requestMediaKeySystemAccess(e,v).then(function(s){g._onMediaKeySystemAccessObtained(e,s)}).catch(function(s){f.logger.error('Failed to obtain key-system "'+e+'" access:',s)})},Object.defineProperty(t.prototype,"requestMediaKeySystemAccess",{get:function(){if(!this._requestMediaKeySystemAccess)throw new Error("No requestMediaKeySystemAccess function configured");return this._requestMediaKeySystemAccess},enumerable:!0,configurable:!0}),t.prototype._onMediaKeySystemAccessObtained=function(e,n){var d=this;f.logger.log('Access for key-system "'+e+'" obtained');var g={mediaKeys:null,mediaKeysSession:null,mediaKeysSessionInitialized:!1,mediaKeySystemAccess:n,mediaKeySystemDomain:e};this._mediaKeysList.push(g),n.createMediaKeys().then(function(v){g.mediaKeys=v,f.logger.log('Media-keys created for key-system "'+e+'"'),d._onMediaKeysCreated()}).catch(function(v){f.logger.error("Failed to create media-keys:",v)})},t.prototype._onMediaKeysCreated=function(){var e=this;this._mediaKeysList.forEach(function(n){n.mediaKeysSession||(n.mediaKeysSession=n.mediaKeys.createSession(),e._onNewMediaKeySession(n.mediaKeysSession))})},t.prototype._onNewMediaKeySession=function(e){var n=this;f.logger.log("New key-system session "+e.sessionId),e.addEventListener("message",function(d){n._onKeySessionMessage(e,d.message)},!1)},t.prototype._onKeySessionMessage=function(e,n){f.logger.log("Got EME message event, creating license request"),this._requestLicense(n,function(d){f.logger.log("Received license data, updating key-session"),e.update(d)})},t.prototype._onMediaEncrypted=function(e,n){f.logger.log('Media is encrypted using "'+e+'" init data type'),this._isMediaEncrypted=!0,this._mediaEncryptionInitDataType=e,this._mediaEncryptionInitData=n,this._attemptSetMediaKeys(),this._generateRequestWithPreferredKeySession()},t.prototype._attemptSetMediaKeys=function(){if(!this._hasSetMediaKeys){var e=this._mediaKeysList[0];if(!e||!e.mediaKeys){f.logger.error("Fatal: Media is encrypted but no CDM access or no keys have been obtained yet"),this.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_NO_KEYS,fatal:!0});return}f.logger.log("Setting keys for encrypted media"),this._media.setMediaKeys(e.mediaKeys),this._hasSetMediaKeys=!0}},t.prototype._generateRequestWithPreferredKeySession=function(){var e=this,n=this._mediaKeysList[0];if(!n){f.logger.error("Fatal: Media is encrypted but not any key-system access has been obtained yet"),this.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_NO_ACCESS,fatal:!0});return}if(n.mediaKeysSessionInitialized){f.logger.warn("Key-Session already initialized but requested again");return}var d=n.mediaKeysSession;d||(f.logger.error("Fatal: Media is encrypted but no key-session existing"),this.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_NO_SESSION,fatal:!0}));var g=this._mediaEncryptionInitDataType,v=this._mediaEncryptionInitData;f.logger.log('Generating key-session request for "'+g+'" init data type'),n.mediaKeysSessionInitialized=!0,d.generateRequest(g,v).then(function(){f.logger.debug("Key-session generation succeeded")}).catch(function(s){f.logger.error("Error generating key-session request:",s),e.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_NO_SESSION,fatal:!1})})},t.prototype._createLicenseXhr=function(e,n,d){var g=new u,v=this._licenseXhrSetup;try{if(v)try{v(g,e)}catch(s){g.open("POST",e,!0),v(g,e)}g.readyState||g.open("POST",e,!0)}catch(s){f.logger.error("Error setting up key-system license XHR",s),this.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0});return}return g.responseType="arraybuffer",g.onreadystatechange=this._onLicenseRequestReadyStageChange.bind(this,g,e,n,d),g},t.prototype._onLicenseRequestReadyStageChange=function(e,n,d,g){switch(e.readyState){case 4:if(e.status===200)this._requestLicenseFailureCount=0,f.logger.log("License request succeeded"),g(e.response);else{if(f.logger.error("License Request XHR failed ("+n+"). Status: "+e.status+" ("+e.statusText+")"),this._requestLicenseFailureCount++,this._requestLicenseFailureCount<=p){var v=p-this._requestLicenseFailureCount+1;f.logger.warn("Retrying license request, "+v+" attempts left"),this._requestLicense(d,g);return}this.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0})}break}},t.prototype._generateLicenseRequestChallenge=function(e,n){var d;return e.mediaKeySystemDomain===c.PLAYREADY?f.logger.error("PlayReady is not supported (yet)"):e.mediaKeySystemDomain===c.WIDEVINE?d=n:f.logger.error("Unsupported key-system:",e.mediaKeySystemDomain),d},t.prototype._requestLicense=function(e,n){f.logger.log("Requesting content license for key-system");var d=this._mediaKeysList[0];if(!d){f.logger.error("Fatal error: Media is encrypted but no key-system access has been obtained yet"),this.hls.trigger(m.default.ERROR,{type:y.ErrorTypes.KEY_SYSTEM_ERROR,details:y.ErrorDetails.KEY_SYSTEM_NO_ACCESS,fatal:!0});return}var g=this.getLicenseServerUrl(d.mediaKeySystemDomain),v=this._createLicenseXhr(g,e,n);f.logger.log("Sending license request to URL: "+g),v.send(this._generateLicenseRequestChallenge(d,e))},t.prototype.onMediaAttached=function(e){var n=this;if(!!this._emeEnabled){var d=e.media;this._media=d,d.addEventListener("encrypted",function(g){n._onMediaEncrypted(g.initDataType,g.initData)})}},t.prototype.onManifestParsed=function(e){if(!!this._emeEnabled){var n=e.levels.map(function(g){return g.audioCodec}),d=e.levels.map(function(g){return g.videoCodec});this._attemptKeySystemAccess(c.WIDEVINE,n,d)}},t}(A.default);R.default=r},"./src/controller/fps-controller.js":function(w,R,T){"use strict";var _=this&&this.__extends||function(){var p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,a){c.__proto__=a}||function(c,a){for(var o in a)a.hasOwnProperty(o)&&(c[o]=a[o])};return function(c,a){p(c,a);function o(){this.constructor=c}c.prototype=a===null?Object.create(a):(o.prototype=a.prototype,new o)}}();Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/events.js"),m=T("./src/event-handler.js"),y=T("./src/utils/logger.js"),f=window.performance,u=function(p){_(c,p);function c(a){return p.call(this,a,A.default.MEDIA_ATTACHING)||this}return c.prototype.destroy=function(){this.timer&&clearInterval(this.timer),this.isVideoPlaybackQualityAvailable=!1},c.prototype.onMediaAttaching=function(a){var o=this.hls.config;if(o.capLevelOnFPSDrop){var r=this.video=a.media instanceof window.HTMLVideoElement?a.media:null;typeof r.getVideoPlaybackQuality=="function"&&(this.isVideoPlaybackQualityAvailable=!0),clearInterval(this.timer),this.timer=setInterval(this.checkFPSInterval.bind(this),o.fpsDroppedMonitoringPeriod)}},c.prototype.checkFPS=function(a,o,r){var i=f.now();if(o){if(this.lastTime){var t=i-this.lastTime,e=r-this.lastDroppedFrames,n=o-this.lastDecodedFrames,d=1e3*e/t,g=this.hls;if(g.trigger(A.default.FPS_DROP,{currentDropped:e,currentDecoded:n,totalDroppedFrames:r}),d>0&&e>g.config.fpsDroppedMonitoringThreshold*n){var v=g.currentLevel;y.logger.warn("drop FPS ratio greater than max allowed value for currentLevel: "+v),v>0&&(g.autoLevelCapping===-1||g.autoLevelCapping>=v)&&(v=v-1,g.trigger(A.default.FPS_DROP_LEVEL_CAPPING,{level:v,droppedLevel:g.currentLevel}),g.autoLevelCapping=v,g.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=r,this.lastDecodedFrames=o}},c.prototype.checkFPSInterval=function(){var a=this.video;if(a)if(this.isVideoPlaybackQualityAvailable){var o=a.getVideoPlaybackQuality();this.checkFPS(a,o.totalVideoFrames,o.droppedVideoFrames)}else this.checkFPS(a,a.webkitDecodedFrameCount,a.webkitDroppedFrameCount)},c}(m.default);R.default=u},"./src/controller/fragment-finders.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/utils/binary-search.js");function m(p,c,a){if(!Array.isArray(p)||!p.length||!_.isFinite(c)||c=p[p.length-1].endProgramDateTime)return null;a=a||0;for(var o=0;op&&a.start?-1:0}R.fragmentWithinToleranceTest=f;function u(p,c,a){var o=Math.min(c,a.duration+(a.deltaPTS?a.deltaPTS:0))*1e3;return a.endProgramDateTime-o>p}R.pdtWithinToleranceTest=u}).call(this,T("./src/polyfills/number.js").Number)},"./src/controller/fragment-tracker.js":function(w,R,T){"use strict";(function(_){var A=this&&this.__extends||function(){var u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(p,c){p.__proto__=c}||function(p,c){for(var a in c)c.hasOwnProperty(a)&&(p[a]=c[a])};return function(p,c){u(p,c);function a(){this.constructor=p}p.prototype=c===null?Object.create(c):(a.prototype=c.prototype,new a)}}();Object.defineProperty(R,"__esModule",{value:!0});var m=T("./src/event-handler.js"),y=T("./src/events.js");R.FragmentState={NOT_LOADED:"NOT_LOADED",APPENDING:"APPENDING",PARTIAL:"PARTIAL",OK:"OK"};var f=function(u){A(p,u);function p(c){var a=u.call(this,c,y.default.BUFFER_APPENDED,y.default.FRAG_BUFFERED,y.default.FRAG_LOADED)||this;return a.bufferPadding=.2,a.fragments=Object.create(null),a.timeRanges=Object.create(null),a.config=c.config,a}return p.prototype.destroy=function(){this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.config=null,m.default.prototype.destroy.call(this),u.prototype.destroy.call(this)},p.prototype.getBufferedFrag=function(c,a){var o=this.fragments,r=Object.keys(o).filter(function(t){var e=o[t];if(e.body.type!==a||!e.buffered)return!1;var n=e.body;return n.startPTS<=c&&c<=n.endPTS});if(r.length===0)return null;var i=r.pop();return o[i].body},p.prototype.detectEvictedFragments=function(c,a){var o=this,r,i;Object.keys(this.fragments).forEach(function(t){var e=o.fragments[t];if(e.buffered===!0){var n=e.range[c];if(n){r=n.time;for(var d=0;d=i&&a<=t){r.push({startPTS:Math.max(c,o.start(n)),endPTS:Math.min(a,o.end(n))});break}else if(ci)r.push({startPTS:Math.max(c,o.start(n)),endPTS:Math.min(a,o.end(n))}),e=!0;else if(a<=i)break;return{time:r,partial:e}},p.prototype.getFragmentKey=function(c){return c.type+"_"+c.level+"_"+c.urlId+"_"+c.sn},p.prototype.getPartialFragment=function(c){var a=this,o,r,i,t=null,e=0;return Object.keys(this.fragments).forEach(function(n){var d=a.fragments[n];a.isPartial(d)&&(r=d.body.startPTS-a.bufferPadding,i=d.body.endPTS+a.bufferPadding,c>=r&&c<=i&&(o=Math.min(c-r,i-c),e<=o&&(t=d.body,e=o)))}),t},p.prototype.getState=function(c){var a=this.getFragmentKey(c),o=this.fragments[a],r=R.FragmentState.NOT_LOADED;return o!==void 0&&(o.buffered?this.isPartial(o)===!0?r=R.FragmentState.PARTIAL:r=R.FragmentState.OK:r=R.FragmentState.APPENDING),r},p.prototype.isPartial=function(c){return c.buffered===!0&&(c.range.video!==void 0&&c.range.video.partial===!0||c.range.audio!==void 0&&c.range.audio.partial===!0)},p.prototype.isTimeBuffered=function(c,a,o){for(var r,i,t=0;t=r&&a<=i)return!0;if(a<=r)return!1}return!1},p.prototype.onFragLoaded=function(c){var a=c.frag;!_.isFinite(a.sn)||a.bitrateTest||(this.fragments[this.getFragmentKey(a)]={body:a,range:Object.create(null),buffered:!1})},p.prototype.onBufferAppended=function(c){var a=this;this.timeRanges=c.timeRanges,Object.keys(this.timeRanges).forEach(function(o){var r=a.timeRanges[o];a.detectEvictedFragments(o,r)})},p.prototype.onFragBuffered=function(c){this.detectPartialFragments(c.frag)},p.prototype.hasFragment=function(c){var a=this.getFragmentKey(c);return this.fragments[a]!==void 0},p.prototype.removeFragment=function(c){var a=this.getFragmentKey(c);delete this.fragments[a]},p.prototype.removeAllFragments=function(){this.fragments=Object.create(null)},p}(m.default);R.FragmentTracker=f}).call(this,T("./src/polyfills/number.js").Number)},"./src/controller/gap-controller.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/utils/buffer-helper.js"),A=T("./src/errors.js"),m=T("./src/events.js"),y=T("./src/utils/logger.js"),f=1e3,u=.5,p=function(){function c(a,o,r,i){this.config=a,this.media=o,this.fragmentTracker=r,this.hls=i,this.stallReported=!1}return c.prototype.poll=function(a,o){var r=this,i=r.config,t=r.media,e=t.currentTime,n=window.performance.now();if(e!==a){this.stallReported&&(y.logger.warn("playback not stuck anymore @"+e+", after "+Math.round(n-this.stalled)+"ms"),this.stallReported=!1),this.stalled=null,this.nudgeRetry=0;return}if(!(t.ended||!t.buffered.length||t.readyState>2)&&!(t.seeking&&_.BufferHelper.isBuffered(t,e))){var d=n-this.stalled,g=_.BufferHelper.bufferInfo(t,e,i.maxBufferHole);if(this.stalled)d>=f&&this._reportStall(g.len);else{this.stalled=n;return}this._tryFixBufferStall(g,d)}},c.prototype._tryFixBufferStall=function(a,o){var r=this,i=r.config,t=r.fragmentTracker,e=r.media,n=e.currentTime,d=t.getPartialFragment(n);d&&this._trySkipBufferHole(d),a.len>u&&o>i.highBufferWatchdogPeriod*1e3&&(this.stalled=null,this._tryNudgeBuffer())},c.prototype._reportStall=function(a){var o=this,r=o.hls,i=o.media,t=o.stallReported;t||(this.stallReported=!0,y.logger.warn("Playback stalling at @"+i.currentTime+" due to low buffer"),r.trigger(m.default.ERROR,{type:A.ErrorTypes.MEDIA_ERROR,details:A.ErrorDetails.BUFFER_STALLED_ERROR,fatal:!1,buffer:a}))},c.prototype._trySkipBufferHole=function(a){for(var o=this,r=o.hls,i=o.media,t=i.currentTime,e=0,n=0;n=e&&t0){d=e[0].bitrate,e.sort(function(h,E){return h.bitrate-E.bitrate}),this._levels=e;for(var x=0;x=0&&t1&&l.loadError0){var e=this.currentLevelIndex,n=t.urlId,d=t.url[n];y.logger.log("Attempt loading level index "+e+" with URL-id "+n),this.hls.trigger(A.default.LEVEL_LOADING,{url:d,level:e,id:n})}}},Object.defineProperty(i.prototype,"nextLoadLevel",{get:function(){return this.manualLevelIndex!==-1?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(t){this.level=t,this.manualLevelIndex===-1&&(this.hls.nextAutoLevel=t)},enumerable:!0,configurable:!0}),i}(m.default);R.default=o},"./src/controller/level-helper.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/utils/logger.js");function m(r,i,t){switch(i){case"audio":r.audioGroupIds||(r.audioGroupIds=[]),r.audioGroupIds.push(t);break;case"text":r.textGroupIds||(r.textGroupIds=[]),r.textGroupIds.push(t);break}}R.addGroupId=m;function y(r,i,t){var e=r[i],n=r[t],d=n.startPTS;_.isFinite(d)?t>i?(e.duration=d-e.start,e.duration<0&&A.logger.warn("negative duration computed for frag "+e.sn+",level "+e.level+", there should be some duration drift between playlist and fragment!")):(n.duration=e.start-d,n.duration<0&&A.logger.warn("negative duration computed for frag "+n.sn+",level "+n.level+", there should be some duration drift between playlist and fragment!")):t>i?n.start=e.start+e.duration:n.start=Math.max(e.start-n.duration,0)}R.updatePTS=y;function f(r,i,t,e,n,d){var g=t;if(_.isFinite(i.startPTS)){var v=Math.abs(i.startPTS-t);_.isFinite(i.deltaPTS)?i.deltaPTS=Math.max(v,i.deltaPTS):i.deltaPTS=v,g=Math.max(t,i.startPTS),t=Math.min(t,i.startPTS),e=Math.max(e,i.endPTS),n=Math.min(n,i.startDTS),d=Math.max(d,i.endDTS)}var s=t-i.start;i.start=i.startPTS=t,i.maxStartPTS=g,i.endPTS=e,i.startDTS=n,i.endDTS=d,i.duration=e-t;var l=i.sn;if(!r||lr.endSN)return 0;var x,h,E;for(x=l-r.startSN,h=r.fragments,h[x]=i,E=x;E>0;E--)y(h,E,E-1);for(E=x;Ee.length))for(var d=0;d0&&h===-1&&(t.logger.log("override startPosition with lastCurrentTime @"+E.toFixed(3)),h=E),this.state=g.State.IDLE,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=h,this.tick()}else this.forceStartLoad=!0,this.state=g.State.STOPPED},x.prototype.stopLoad=function(){this.forceStartLoad=!1,l.prototype.stopLoad.call(this)},x.prototype.doTick=function(){switch(this.state){case g.State.BUFFER_FLUSHING:this.fragLoadError=0;break;case g.State.IDLE:this._doTickIdle();break;case g.State.WAITING_LEVEL:var h=this.levels[this.level];h&&h.details&&(this.state=g.State.IDLE);break;case g.State.FRAG_LOADING_WAITING_RETRY:var E=window.performance.now(),S=this.retryDate;(!S||E>=S||this.media&&this.media.seeking)&&(t.logger.log("mediaController: retryDate reached, switch back to IDLE state"),this.state=g.State.IDLE);break;case g.State.ERROR:case g.State.STOPPED:case g.State.FRAG_LOADING:case g.State.PARSING:case g.State.PARSED:case g.State.ENDED:break;default:break}this._checkBuffer(),this._checkFragmentChanged()},x.prototype._doTickIdle=function(){var h=this.hls,E=h.config,S=this.media;if(!(this.levelLastLoaded===void 0||!S&&(this.startFragRequested||!E.startFragPrefetch))){var b;this.loadedmetadata?b=S.currentTime:b=this.nextLoadPosition;var I=h.nextLoadLevel,L=this.levels[I];if(!!L){var D=L.bitrate,O;D?O=Math.max(8*E.maxBufferSize/D,E.maxBufferLength):O=E.maxBufferLength,O=Math.min(O,E.maxMaxBufferLength);var F=y.BufferHelper.bufferInfo(this.mediaBuffer?this.mediaBuffer:S,b,E.maxBufferHole),C=F.len;if(!(C>=O)){t.logger.trace("buffer length of "+C.toFixed(3)+" is below max of "+O.toFixed(3)+". checking for more payload ..."),this.level=h.nextLoadLevel=I;var P=L.details;if(!P||P.live&&this.levelLastLoaded!==I){this.state=g.State.WAITING_LEVEL;return}if(this._streamEnded(F,P)){var k={};this.altAudio&&(k.type="video"),this.hls.trigger(u.default.BUFFER_EOS,k),this.state=g.State.ENDED;return}this._fetchPayloadOrEos(b,F,P)}}}},x.prototype._fetchPayloadOrEos=function(h,E,S){var b=this.fragPrevious,I=this.level,L=S.fragments,D=L.length;if(D!==0){var O=L[0].start,F=L[D-1].start+L[D-1].duration,C=E.end,P;if(S.initSegment&&!S.initSegment.data)P=S.initSegment;else if(S.live){var k=this.config.initialLiveManifestSize;if(Dk&&(F.currentTime=k),this.nextLoadPosition=k}if(h.PTSKnown&&E>b&&F&&F.readyState)return null;if(this.startFragRequested&&!h.PTSKnown){if(I)if(h.hasProgramDateTime)t.logger.log("live playlist, switching playlist, load frag with same PDT: "+I.programDateTime),C=n.findFragmentByPDT(L,I.endProgramDateTime,O.maxFragLookUpTolerance);else{var B=I.sn+1;if(B>=h.startSN&&B<=h.endSN){var M=L[B-h.startSN];I.cc===M.cc&&(C=M,t.logger.log("live playlist, switching playlist, load frag with next SN: "+C.sn))}C||(C=m.default.search(L,function(N){return I.cc-N.cc}),C&&t.logger.log("live playlist, switching playlist, load frag with same CC: "+C.sn))}C||(C=L[Math.min(D-1,Math.round(D/2))],t.logger.log("live playlist, switching playlist, unknown, load middle frag : "+C.sn))}return C},x.prototype._findFragment=function(h,E,S,b,I,L,D){var O=this.hls.config,F;if(IL-O.maxFragLookUpTolerance?0:O.maxFragLookUpTolerance;F=n.findFragmentByPTS(E,b,I,C)}else F=b[S-1];if(F){var P=F.sn-D.startSN,k=E&&F.level===E.level,B=b[P-1],M=b[P+1];if(E&&F.sn===E.sn)if(k&&!F.backtracked)if(F.snO.maxBufferHole&&E.dropped&&P?(F=B,t.logger.warn("SN just loaded, with large PTS gap between audio and video, maybe frag is not starting with a keyframe ? load previous one to try to overcome this")):(F=M,t.logger.log("SN just loaded, load next one: "+F.sn,F))}else F=null;else F.backtracked&&(M&&M.backtracked?(t.logger.warn("Already backtracked from fragment "+M.sn+", will not backtrack to fragment "+F.sn+". Loading fragment "+M.sn),F=M):(t.logger.warn("Loaded fragment with dropped frames, backtracking 1 segment to find a keyframe"),F.dropped=0,B?(F=B,F.backtracked=!0):P&&(F=null)))}return F},x.prototype._loadKey=function(h){this.state=g.State.KEY_LOADING,this.hls.trigger(u.default.KEY_LOADING,{frag:h})},x.prototype._loadFragment=function(h){var E=this.fragmentTracker.getState(h);this.fragCurrent=h,this.startFragRequested=!0,_.isFinite(h.sn)&&!h.bitrateTest&&(this.nextLoadPosition=h.start+h.duration),h.backtracked||E===p.FragmentState.NOT_LOADED||E===p.FragmentState.PARTIAL?(h.autoLevel=this.hls.autoLevelEnabled,h.bitrateTest=this.bitrateTest,this.hls.trigger(u.default.FRAG_LOADING,{frag:h}),this.demuxer||(this.demuxer=new f.default(this.hls,"main")),this.state=g.State.FRAG_LOADING):E===p.FragmentState.APPENDING&&this._reduceMaxBufferLength(h.duration)&&this.fragmentTracker.removeFragment(h)},Object.defineProperty(x.prototype,"state",{get:function(){return this._state},set:function(h){if(this.state!==h){var E=this.state;this._state=h,t.logger.log("main stream:"+E+"->"+h),this.hls.trigger(u.default.STREAM_STATE_TRANSITION,{previousState:E,nextState:h})}},enumerable:!0,configurable:!0}),x.prototype.getBufferedFrag=function(h){return this.fragmentTracker.getBufferedFrag(h,a.default.LevelType.MAIN)},Object.defineProperty(x.prototype,"currentLevel",{get:function(){var h=this.media;if(h){var E=this.getBufferedFrag(h.currentTime);if(E)return E.level}return-1},enumerable:!0,configurable:!0}),Object.defineProperty(x.prototype,"nextBufferedFrag",{get:function(){var h=this.media;return h?this.followingBufferedFrag(this.getBufferedFrag(h.currentTime)):null},enumerable:!0,configurable:!0}),x.prototype.followingBufferedFrag=function(h){return h?this.getBufferedFrag(h.endPTS+.5):null},Object.defineProperty(x.prototype,"nextLevel",{get:function(){var h=this.nextBufferedFrag;return h?h.level:-1},enumerable:!0,configurable:!0}),x.prototype._checkFragmentChanged=function(){var h,E,S=this.media;if(S&&S.readyState&&S.seeking===!1&&(E=S.currentTime,E>this.lastCurrentTime&&(this.lastCurrentTime=E),y.BufferHelper.isBuffered(S,E)?h=this.getBufferedFrag(E):y.BufferHelper.isBuffered(S,E+.1)&&(h=this.getBufferedFrag(E+.1)),h)){var b=h;if(b!==this.fragPlaying){this.hls.trigger(u.default.FRAG_CHANGED,{frag:b});var I=b.level;(!this.fragPlaying||this.fragPlaying.level!==I)&&this.hls.trigger(u.default.LEVEL_SWITCHED,{level:I}),this.fragPlaying=b}}},x.prototype.immediateLevelSwitch=function(){if(t.logger.log("immediateLevelSwitch"),!this.immediateSwitch){this.immediateSwitch=!0;var h=this.media,E=void 0;h?(E=h.paused,h.pause()):E=!0,this.previouslyPaused=E}var S=this.fragCurrent;S&&S.loader&&S.loader.abort(),this.fragCurrent=null,this.flushMainBuffer(0,_.POSITIVE_INFINITY)},x.prototype.immediateLevelSwitchEnd=function(){var h=this.media;h&&h.buffered.length&&(this.immediateSwitch=!1,y.BufferHelper.isBuffered(h,h.currentTime)&&(h.currentTime-=1e-4),this.previouslyPaused||h.play())},x.prototype.nextLevelSwitch=function(){var h=this.media;if(h&&h.readyState){var E=void 0,S=void 0,b=void 0;if(S=this.getBufferedFrag(h.currentTime),S&&S.startPTS>1&&this.flushMainBuffer(0,S.startPTS-1),h.paused)E=0;else{var I=this.hls.nextLoadLevel,L=this.levels[I],D=this.fragLastKbps;D&&this.fragCurrent?E=this.fragCurrent.duration*L.bitrate/(1e3*D)+1:E=0}if(b=this.getBufferedFrag(h.currentTime+E),b&&(b=this.followingBufferedFrag(b),b)){var O=this.fragCurrent;O&&O.loader&&O.loader.abort(),this.fragCurrent=null,this.flushMainBuffer(b.maxStartPTS,_.POSITIVE_INFINITY)}}},x.prototype.flushMainBuffer=function(h,E){this.state=g.State.BUFFER_FLUSHING;var S={startOffset:h,endOffset:E};this.altAudio&&(S.type="video"),this.hls.trigger(u.default.BUFFER_FLUSHING,S)},x.prototype.onMediaAttached=function(h){var E=this.media=this.mediaBuffer=h.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),this.onvended=this.onMediaEnded.bind(this),E.addEventListener("seeking",this.onvseeking),E.addEventListener("seeked",this.onvseeked),E.addEventListener("ended",this.onvended);var S=this.config;this.levels&&S.autoStartLoad&&this.hls.startLoad(S.startPosition),this.gapController=new d.default(S,E,this.fragmentTracker,this.hls)},x.prototype.onMediaDetaching=function(){var h=this.media;h&&h.ended&&(t.logger.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0);var E=this.levels;E&&E.forEach(function(S){S.details&&S.details.fragments.forEach(function(b){b.backtracked=void 0})}),h&&(h.removeEventListener("seeking",this.onvseeking),h.removeEventListener("seeked",this.onvseeked),h.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvended=null),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.stopLoad()},x.prototype.onMediaSeeked=function(){var h=this.media,E=h?h.currentTime:void 0;_.isFinite(E)&&t.logger.log("media seeked to "+E.toFixed(3)),this.tick()},x.prototype.onManifestLoading=function(){t.logger.log("trigger BUFFER_RESET"),this.hls.trigger(u.default.BUFFER_RESET),this.fragmentTracker.removeAllFragments(),this.stalled=!1,this.startPosition=this.lastCurrentTime=0},x.prototype.onManifestParsed=function(h){var E=!1,S=!1,b;h.levels.forEach(function(L){b=L.audioCodec,b&&(b.indexOf("mp4a.40.2")!==-1&&(E=!0),b.indexOf("mp4a.40.5")!==-1&&(S=!0))}),this.audioCodecSwitch=E&&S,this.audioCodecSwitch&&t.logger.log("both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=h.levels,this.startFragRequested=!1;var I=this.config;(I.autoStartLoad||this.forceStartLoad)&&this.hls.startLoad(I.startPosition)},x.prototype.onLevelLoaded=function(h){var E=h.details,S=h.level,b=this.levels[this.levelLastLoaded],I=this.levels[S],L=E.totalduration,D=0;if(t.logger.log("level "+S+" loaded ["+E.startSN+","+E.endSN+"],duration:"+L),E.live){var O=I.details;O&&E.fragments.length>0?(o.mergeDetails(O,E),D=E.fragments[0].start,this.liveSyncPosition=this.computeLivePosition(D,O),E.PTSKnown&&_.isFinite(D)?t.logger.log("live playlist sliding:"+D.toFixed(3)):(t.logger.log("live playlist - outdated PTS, unknown sliding"),e.alignStream(this.fragPrevious,b,E))):(t.logger.log("live playlist - first load, unknown sliding"),E.PTSKnown=!1,e.alignStream(this.fragPrevious,b,E))}else E.PTSKnown=!1;if(I.details=E,this.levelLastLoaded=S,this.hls.trigger(u.default.LEVEL_UPDATED,{details:E,level:S}),this.startFragRequested===!1){if(this.startPosition===-1||this.lastCurrentTime===-1){var F=E.startTimeOffset;_.isFinite(F)?(F<0&&(t.logger.log("negative start time offset "+F+", count from end of last fragment"),F=D+L+F),t.logger.log("start time offset found in playlist, adjust startPosition to "+F),this.startPosition=F):E.live?(this.startPosition=this.computeLivePosition(D,E),t.logger.log("configure startPosition to "+this.startPosition)):this.startPosition=0,this.lastCurrentTime=this.startPosition}this.nextLoadPosition=this.startPosition}this.state===g.State.WAITING_LEVEL&&(this.state=g.State.IDLE),this.tick()},x.prototype.onKeyLoaded=function(){this.state===g.State.KEY_LOADING&&(this.state=g.State.IDLE,this.tick())},x.prototype.onFragLoaded=function(h){var E=this,S=E.fragCurrent,b=E.hls,I=E.levels,L=E.media,D=h.frag;if(this.state===g.State.FRAG_LOADING&&S&&D.type==="main"&&D.level===S.level&&D.sn===S.sn){var O=h.stats,F=I[S.level],C=F.details;if(this.bitrateTest=!1,this.stats=O,t.logger.log("Loaded "+S.sn+" of ["+C.startSN+" ,"+C.endSN+"],level "+S.level),D.bitrateTest&&b.nextLoadLevel)this.state=g.State.IDLE,this.startFragRequested=!1,O.tparsed=O.tbuffered=window.performance.now(),b.trigger(u.default.FRAG_BUFFERED,{stats:O,frag:S,id:"main"}),this.tick();else if(D.sn==="initSegment")this.state=g.State.IDLE,O.tparsed=O.tbuffered=window.performance.now(),C.initSegment.data=h.payload,b.trigger(u.default.FRAG_BUFFERED,{stats:O,frag:S,id:"main"}),this.tick();else{t.logger.log("Parsing "+S.sn+" of ["+C.startSN+" ,"+C.endSN+"],level "+S.level+", cc "+S.cc),this.state=g.State.PARSING,this.pendingBuffering=!0,this.appended=!1,D.bitrateTest&&(D.bitrateTest=!1,this.fragmentTracker.onFragLoaded({frag:D}));var P=!(L&&L.seeking)&&(C.PTSKnown||!C.live),k=C.initSegment?C.initSegment.data:[],B=this._getAudioCodec(F),M=this.demuxer=this.demuxer||new f.default(this.hls,"main");M.push(h.payload,k,B,F.videoCodec,S,C.totalduration,P)}}this.fragLoadError=0},x.prototype.onFragParsingInitSegment=function(h){var E=this.fragCurrent,S=h.frag;if(E&&h.id==="main"&&S.sn===E.sn&&S.level===E.level&&this.state===g.State.PARSING){var b=h.tracks,I=void 0,L=void 0;if(b.audio&&this.altAudio&&delete b.audio,L=b.audio,L){var D=this.levels[this.level].audioCodec,O=navigator.userAgent.toLowerCase();D&&this.audioCodecSwap&&(t.logger.log("swapping playlist audio codec"),D.indexOf("mp4a.40.5")!==-1?D="mp4a.40.2":D="mp4a.40.5"),this.audioCodecSwitch&&L.metadata.channelCount!==1&&O.indexOf("firefox")===-1&&(D="mp4a.40.5"),O.indexOf("android")!==-1&&L.container!=="audio/mpeg"&&(D="mp4a.40.2",t.logger.log("Android: force audio codec to "+D)),L.levelCodec=D,L.id=h.id}L=b.video,L&&(L.levelCodec=this.levels[this.level].videoCodec,L.id=h.id),this.hls.trigger(u.default.BUFFER_CODECS,b);for(I in b){L=b[I],t.logger.log("main track:"+I+",container:"+L.container+",codecs[level/parsed]=["+L.levelCodec+"/"+L.codec+"]");var F=L.initSegment;F&&(this.appended=!0,this.pendingBuffering=!0,this.hls.trigger(u.default.BUFFER_APPENDING,{type:I,data:F,parent:"main",content:"initSegment"}))}this.tick()}},x.prototype.onFragParsingData=function(h){var E=this,S=this.fragCurrent,b=h.frag;if(S&&h.id==="main"&&b.sn===S.sn&&b.level===S.level&&!(h.type==="audio"&&this.altAudio)&&this.state===g.State.PARSING){var I=this.levels[this.level],L=S;if(_.isFinite(h.endPTS)||(h.endPTS=h.startPTS+S.duration,h.endDTS=h.startDTS+S.duration),h.hasAudio===!0&&L.addElementaryStream(c.default.ElementaryStreamTypes.AUDIO),h.hasVideo===!0&&L.addElementaryStream(c.default.ElementaryStreamTypes.VIDEO),t.logger.log("Parsed "+h.type+",PTS:["+h.startPTS.toFixed(3)+","+h.endPTS.toFixed(3)+"],DTS:["+h.startDTS.toFixed(3)+"/"+h.endDTS.toFixed(3)+"],nb:"+h.nb+",dropped:"+(h.dropped||0)),h.type==="video")if(L.dropped=h.dropped,L.dropped)if(L.backtracked)t.logger.warn("Already backtracked on this fragment, appending with the gap",L.sn);else{var D=I.details;if(D&&L.sn===D.startSN)t.logger.warn("missing video frame(s) on first frag, appending with gap",L.sn);else{t.logger.warn("missing video frame(s), backtracking fragment",L.sn),this.fragmentTracker.removeFragment(L),L.backtracked=!0,this.nextLoadPosition=h.startPTS,this.state=g.State.IDLE,this.fragPrevious=L,this.tick();return}}else L.backtracked=!1;var O=o.updateFragPTSDTS(I.details,L,h.startPTS,h.endPTS,h.startDTS,h.endDTS),F=this.hls;F.trigger(u.default.LEVEL_PTS_UPDATED,{details:I.details,level:this.level,drift:O,type:h.type,start:h.startPTS,end:h.endPTS}),[h.data1,h.data2].forEach(function(C){C&&C.length&&E.state===g.State.PARSING&&(E.appended=!0,E.pendingBuffering=!0,F.trigger(u.default.BUFFER_APPENDING,{type:h.type,data:C,parent:"main",content:"data"}))}),this.tick()}},x.prototype.onFragParsed=function(h){var E=this.fragCurrent,S=h.frag;E&&h.id==="main"&&S.sn===E.sn&&S.level===E.level&&this.state===g.State.PARSING&&(this.stats.tparsed=window.performance.now(),this.state=g.State.PARSED,this._checkAppendedParsed())},x.prototype.onAudioTrackSwitching=function(h){var E=!!h.url,S=h.id;if(!E){if(this.mediaBuffer!==this.media){t.logger.log("switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var b=this.fragCurrent;b.loader&&(t.logger.log("switching to main audio track, cancel main fragment load"),b.loader.abort()),this.fragCurrent=null,this.fragPrevious=null,this.demuxer&&(this.demuxer.destroy(),this.demuxer=null),this.state=g.State.IDLE}var I=this.hls;I.trigger(u.default.BUFFER_FLUSHING,{startOffset:0,endOffset:_.POSITIVE_INFINITY,type:"audio"}),I.trigger(u.default.AUDIO_TRACK_SWITCHED,{id:S}),this.altAudio=!1}},x.prototype.onAudioTrackSwitched=function(h){var E=h.id,S=!!this.hls.audioTracks[E].url;if(S){var b=this.videoBuffer;b&&this.mediaBuffer!==b&&(t.logger.log("switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=b)}this.altAudio=S,this.tick()},x.prototype.onBufferCreated=function(h){var E=h.tracks,S,b,I=!1;for(var L in E){var D=E[L];D.id==="main"?(b=L,S=D,L==="video"&&(this.videoBuffer=E[L].buffer)):I=!0}I&&S?(t.logger.log("alternate track found, use "+b+".buffered to schedule main fragment loading"),this.mediaBuffer=S.buffer):this.mediaBuffer=this.media},x.prototype.onBufferAppended=function(h){if(h.parent==="main"){var E=this.state;(E===g.State.PARSING||E===g.State.PARSED)&&(this.pendingBuffering=h.pending>0,this._checkAppendedParsed())}},x.prototype._checkAppendedParsed=function(){if(this.state===g.State.PARSED&&(!this.appended||!this.pendingBuffering)){var h=this.fragCurrent;if(h){var E=this.mediaBuffer?this.mediaBuffer:this.media;t.logger.log("main buffered : "+r.default.toString(E.buffered)),this.fragPrevious=h;var S=this.stats;S.tbuffered=window.performance.now(),this.fragLastKbps=Math.round(8*S.total/(S.tbuffered-S.tfirst)),this.hls.trigger(u.default.FRAG_BUFFERED,{stats:S,frag:h,id:"main"}),this.state=g.State.IDLE}this.tick()}},x.prototype.onError=function(h){var E=h.frag||this.fragCurrent;if(!(E&&E.type!=="main")){var S=!!this.media&&y.BufferHelper.isBuffered(this.media,this.media.currentTime)&&y.BufferHelper.isBuffered(this.media,this.media.currentTime+.5);switch(h.details){case i.ErrorDetails.FRAG_LOAD_ERROR:case i.ErrorDetails.FRAG_LOAD_TIMEOUT:case i.ErrorDetails.KEY_LOAD_ERROR:case i.ErrorDetails.KEY_LOAD_TIMEOUT:if(!h.fatal)if(this.fragLoadError+1<=this.config.fragLoadingMaxRetry){var b=Math.min(Math.pow(2,this.fragLoadError)*this.config.fragLoadingRetryDelay,this.config.fragLoadingMaxRetryTimeout);t.logger.warn("mediaController: frag loading failed, retry in "+b+" ms"),this.retryDate=window.performance.now()+b,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.fragLoadError++,this.state=g.State.FRAG_LOADING_WAITING_RETRY}else t.logger.error("mediaController: "+h.details+" reaches max retry, redispatch as fatal ..."),h.fatal=!0,this.state=g.State.ERROR;break;case i.ErrorDetails.LEVEL_LOAD_ERROR:case i.ErrorDetails.LEVEL_LOAD_TIMEOUT:this.state!==g.State.ERROR&&(h.fatal?(this.state=g.State.ERROR,t.logger.warn("streamController: "+h.details+",switch to "+this.state+" state ...")):!h.levelRetry&&this.state===g.State.WAITING_LEVEL&&(this.state=g.State.IDLE));break;case i.ErrorDetails.BUFFER_FULL_ERROR:h.parent==="main"&&(this.state===g.State.PARSING||this.state===g.State.PARSED)&&(S?(this._reduceMaxBufferLength(this.config.maxBufferLength),this.state=g.State.IDLE):(t.logger.warn("buffer full error also media.currentTime is not buffered, flush everything"),this.fragCurrent=null,this.flushMainBuffer(0,_.POSITIVE_INFINITY)));break;default:break}}},x.prototype._reduceMaxBufferLength=function(h){var E=this.config;return E.maxMaxBufferLength>=h?(E.maxMaxBufferLength/=2,t.logger.warn("main:reduce max buffer length to "+E.maxMaxBufferLength+"s"),!0):!1},x.prototype._checkBuffer=function(){var h=this.media;if(!(!h||h.readyState===0)){var E=this.mediaBuffer?this.mediaBuffer:h,S=E.buffered;!this.loadedmetadata&&S.length?(this.loadedmetadata=!0,this._seekToStartPos()):this.immediateSwitch?this.immediateLevelSwitchEnd():this.gapController.poll(this.lastCurrentTime,S)}},x.prototype.onFragLoadEmergencyAborted=function(){this.state=g.State.IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tick()},x.prototype.onBufferFlushed=function(){var h=this.mediaBuffer?this.mediaBuffer:this.media;h&&this.fragmentTracker.detectEvictedFragments(c.default.ElementaryStreamTypes.VIDEO,h.buffered),this.state=g.State.IDLE,this.fragPrevious=null},x.prototype.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},x.prototype.computeLivePosition=function(h,E){var S=this.config.liveSyncDuration!==void 0?this.config.liveSyncDuration:this.config.liveSyncDurationCount*E.targetduration;return h+Math.max(0,E.totalduration-S)},x.prototype._seekToStartPos=function(){var h=this.media,E=h.currentTime,S=h.seeking?E:this.startPosition;E!==S&&(t.logger.log("target start position not buffered, seek to buffered.start(0) "+S+" from current time "+E+" "),h.currentTime=S)},x.prototype._getAudioCodec=function(h){var E=this.config.defaultAudioCodec||h.audioCodec;return this.audioCodecSwap&&(t.logger.log("swapping playlist audio codec"),E&&(E.indexOf("mp4a.40.5")!==-1?E="mp4a.40.2":E="mp4a.40.5")),E},Object.defineProperty(x.prototype,"liveSyncPosition",{get:function(){return this._liveSyncPosition},set:function(h){this._liveSyncPosition=h},enumerable:!0,configurable:!0}),x}(g.default);R.default=s}).call(this,T("./src/polyfills/number.js").Number)},"./src/controller/subtitle-stream-controller.js":function(w,R,T){"use strict";var _=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var d in n)n.hasOwnProperty(d)&&(e[d]=n[d])};return function(e,n){t(e,n);function d(){this.constructor=e}e.prototype=n===null?Object.create(n):(d.prototype=n.prototype,new d)}}();Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/events.js"),m=T("./src/utils/logger.js"),y=T("./src/crypt/decrypter.js"),f=T("./src/utils/buffer-helper.js"),u=T("./src/controller/fragment-finders.js"),p=T("./src/controller/fragment-tracker.js"),c=T("./src/controller/base-stream-controller.js"),a=T("./src/controller/level-helper.js"),o=window.performance,r=500,i=function(t){_(e,t);function e(n,d){var g=t.call(this,n,A.default.MEDIA_ATTACHED,A.default.MEDIA_DETACHING,A.default.ERROR,A.default.KEY_LOADED,A.default.FRAG_LOADED,A.default.SUBTITLE_TRACKS_UPDATED,A.default.SUBTITLE_TRACK_SWITCH,A.default.SUBTITLE_TRACK_LOADED,A.default.SUBTITLE_FRAG_PROCESSED,A.default.LEVEL_UPDATED)||this;return g.fragmentTracker=d,g.config=n.config,g.state=c.State.STOPPED,g.tracks=[],g.tracksBuffered=[],g.currentTrackId=-1,g.decrypter=new y.default(n,n.config),g.lastAVStart=0,g._onMediaSeeking=g.onMediaSeeking.bind(g),g}return e.prototype.onSubtitleFragProcessed=function(n){var d=n.frag,g=n.success;if(this.fragPrevious=d,this.state=c.State.IDLE,!!g){var v=this.tracksBuffered[this.currentTrackId];if(!!v){for(var s,l=d.start,x=0;x=v[x].start&&l<=v[x].end){s=v[x];break}var h=d.start+d.duration;s?s.end=h:(s={start:l,end:h},v.push(s))}}},e.prototype.onMediaAttached=function(n){var d=n.media;this.media=d,d.addEventListener("seeking",this._onMediaSeeking),this.state=c.State.IDLE},e.prototype.onMediaDetaching=function(){this.media.removeEventListener("seeking",this._onMediaSeeking),this.media=null,this.state=c.State.STOPPED},e.prototype.onError=function(n){var d=n.frag;!d||d.type!=="subtitle"||(this.state=c.State.IDLE)},e.prototype.onSubtitleTracksUpdated=function(n){var d=this;m.logger.log("subtitle tracks updated"),this.tracksBuffered=[],this.tracks=n.subtitleTracks,this.tracks.forEach(function(g){d.tracksBuffered[g.id]=[]})},e.prototype.onSubtitleTrackSwitch=function(n){if(this.currentTrackId=n.id,!this.tracks||this.currentTrackId===-1){this.clearInterval();return}var d=this.tracks[this.currentTrackId];d&&d.details&&this.setInterval(r)},e.prototype.onSubtitleTrackLoaded=function(n){var d=n.id,g=n.details,v=this,s=v.currentTrackId,l=v.tracks,x=l[s];d>=l.length||d!==s||!x||(g.live&&a.mergeSubtitlePlaylists(x.details,g,this.lastAVStart),x.details=g,this.setInterval(r))},e.prototype.onKeyLoaded=function(){this.state===c.State.KEY_LOADING&&(this.state=c.State.IDLE)},e.prototype.onFragLoaded=function(n){var d=this.fragCurrent,g=n.frag.decryptdata,v=n.frag,s=this.hls;if(this.state===c.State.FRAG_LOADING&&d&&n.frag.type==="subtitle"&&d.sn===n.frag.sn&&n.payload.byteLength>0&&g&&g.key&&g.method==="AES-128"){var l=o.now();this.decrypter.decrypt(n.payload,g.key.buffer,g.iv.buffer,function(x){var h=o.now();s.trigger(A.default.FRAG_DECRYPTED,{frag:v,payload:x,stats:{tstart:l,tdecrypt:h}})})}},e.prototype.onLevelUpdated=function(n){var d=n.details,g=d.fragments;this.lastAVStart=g.length?g[0].start:0},e.prototype.doTick=function(){if(!this.media){this.state=c.State.IDLE;return}switch(this.state){case c.State.IDLE:{var n=this,d=n.config,g=n.currentTrackId,v=n.fragmentTracker,s=n.media,l=n.tracks;if(!l||!l[g]||!l[g].details)break;var x=d.maxBufferHole,h=d.maxFragLookUpTolerance,E=Math.min(d.maxBufferLength,d.maxMaxBufferLength),S=f.BufferHelper.bufferedInfo(this._getBuffered(),s.currentTime,x),b=S.end,I=S.len,L=l[g].details,D=L.fragments,O=D.length,F=D[O-1].start+D[O-1].duration;if(I>E)return;var C=void 0,P=this.fragPrevious;b=g.length||t!==d||!v||this.stopped){this._clearReloadTimer();return}if(f.logger.log("subtitle track "+t+" loaded"),e.live){var s=u.computeReloadInterval(v.details,e,r.stats.trequest);f.logger.log("Reloading live subtitle playlist in "+s+"ms"),this.timer=setTimeout(function(){i._loadCurrentTrack()},s)}else this._clearReloadTimer()},o.prototype.startLoad=function(){this.stopped=!1,this._loadCurrentTrack()},o.prototype.stopLoad=function(){this.stopped=!0,this._clearReloadTimer()},Object.defineProperty(o.prototype,"subtitleTracks",{get:function(){return this.tracks},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"subtitleTrack",{get:function(){return this.trackId},set:function(r){this.trackId!==r&&(this._toggleTrackModes(r),this._setSubtitleTrackInternal(r))},enumerable:!0,configurable:!0}),o.prototype._clearReloadTimer=function(){this.timer&&(clearTimeout(this.timer),this.timer=null)},o.prototype._loadCurrentTrack=function(){var r=this,i=r.trackId,t=r.tracks,e=r.hls,n=t[i];i<0||!n||n.details&&!n.details.live||(f.logger.log("Loading subtitle track "+i),e.trigger(m.default.SUBTITLE_TRACK_LOADING,{url:n.url,id:i}))},o.prototype._toggleTrackModes=function(r){var i=this,t=i.media,e=i.subtitleDisplay,n=i.trackId;if(!!t){var d=c(t.textTracks);if(r===-1)[].slice.call(d).forEach(function(s){s.mode="disabled"});else{var g=d[n];g&&(g.mode="disabled")}var v=d[r];v&&(v.mode=e?"showing":"hidden")}},o.prototype._setSubtitleTrackInternal=function(r){var i=this,t=i.hls,e=i.tracks;!_.isFinite(r)||r<-1||r>=e.length||(this.trackId=r,f.logger.log("Switching to subtitle track "+r),t.trigger(m.default.SUBTITLE_TRACK_SWITCH,{id:r}),this._loadCurrentTrack())},o.prototype._onTextTracksChanged=function(){if(!!this.media){for(var r=-1,i=c(this.media.textTracks),t=0;t=0&&(h[0]=Math.min(h[0],d),h[1]=Math.max(h[1],g),l=!0,E/(g-d)>.5))return}l||s.push([d,g]),this.Cues.newCue(this.captionsTracks[n],d,g,v)},e.prototype.onInitPtsFound=function(n){var d=this;if(n.id==="main"&&(this.initPTS[n.frag.cc]=n.initPTS),this.unparsedVttFrags.length){var g=this.unparsedVttFrags;this.unparsedVttFrags=[],g.forEach(function(v){d.onFragLoaded(v)})}},e.prototype.getExistingTrack=function(n){var d=this.media;if(d)for(var g=0;g>>8^l&255^99,y[g]=l,f[l]=g;var x=d[g],h=d[x],E=d[h],S=d[l]*257^l*16843008;p[g]=S<<24|S>>>8,c[g]=S<<16|S>>>16,a[g]=S<<8|S>>>24,o[g]=S,S=E*16843009^h*65537^x*257^g*16843008,i[l]=S<<24|S>>>8,t[l]=S<<16|S>>>16,e[l]=S<<8|S>>>24,n[l]=S,g?(g=x^d[d[d[E^x]]],v^=d[d[v]]):g=v=1}},m.prototype.expandKey=function(y){for(var f=this.uint8ArrayToUint32Array_(y),u=!0,p=0;p>>6)+1,s=(n[d+2]&60)>>>2,s>b.length-1){e.trigger(m.default.ERROR,{type:A.ErrorTypes.MEDIA_ERROR,details:A.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+s});return}return x=(n[d+2]&1)<<2,x|=(n[d+3]&192)>>>6,_.logger.log("manifest codec:"+g+",ADTS data:type:"+v+",sampleingIndex:"+s+"["+b[s]+"Hz],channelConfig:"+x),/firefox/i.test(E)?s>=6?(v=5,h=new Array(4),l=s-3):(v=2,h=new Array(2),l=s):E.indexOf("android")!==-1?(v=2,h=new Array(2),l=s):(v=5,h=new Array(4),g&&(g.indexOf("mp4a.40.29")!==-1||g.indexOf("mp4a.40.5")!==-1)||!g&&s>=6?l=s-3:((g&&g.indexOf("mp4a.40.2")!==-1&&(s>=6&&x===1||/vivaldi/i.test(E))||!g&&x===1)&&(v=2,h=new Array(2)),l=s)),h[0]=v<<3,h[0]|=(s&14)>>1,h[1]|=(s&1)<<7,h[1]|=x<<3,v===5&&(h[1]|=(l&14)>>1,h[2]=(l&1)<<7,h[2]|=2<<2,h[3]=0),{config:h,samplerate:b[s],channelCount:x,codec:"mp4a.40."+v,manifestCodec:S}}R.getAudioConfig=y;function f(e,n){return e[n]===255&&(e[n+1]&246)==240}R.isHeaderPattern=f;function u(e,n){return e[n+1]&1?7:9}R.getHeaderLength=u;function p(e,n){return(e[n+3]&3)<<11|e[n+4]<<3|(e[n+5]&224)>>>5}R.getFullFrameLength=p;function c(e,n){return!!(n+10&&n+s+l<=h)return x=d+g*v,{headerLength:s,frameLength:l,stamp:x}}R.parseFrameHeader=i;function t(e,n,d,g,v){var s=r(e.samplerate),l=i(n,d,g,v,s);if(l){var x=l.stamp,h=l.headerLength,E=l.frameLength,S={unit:n.subarray(d+h,d+h+E),pts:x,dts:x};return e.samples.push(S),e.len+=E,{sample:S,length:E+h}}}R.appendFrame=t},"./src/demux/demuxer-inline.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/events.js"),A=T("./src/errors.js"),m=T("./src/crypt/decrypter.js"),y=T("./src/demux/aacdemuxer.js"),f=T("./src/demux/mp4demuxer.js"),u=T("./src/demux/tsdemuxer.js"),p=T("./src/demux/mp3demuxer.js"),c=T("./src/remux/mp4-remuxer.js"),a=T("./src/remux/passthrough-remuxer.js"),o=T("./src/utils/get-self-scope.js"),r=T("./src/utils/logger.js"),i=o.getSelfScope(),t;try{t=i.performance.now.bind(i.performance)}catch(n){r.logger.debug("Unable to use Performance API on this environment"),t=i.Date.now}var e=function(){function n(d,g,v,s){this.observer=d,this.typeSupported=g,this.config=v,this.vendor=s}return n.prototype.destroy=function(){var d=this.demuxer;d&&d.destroy()},n.prototype.push=function(d,g,v,s,l,x,h,E,S,b,I,L){var D=this;if(d.byteLength>0&&g!=null&&g.key!=null&&g.method==="AES-128"){var O=this.decrypter;O==null&&(O=this.decrypter=new m.default(this.observer,this.config));var F=t();O.decrypt(d,g.key.buffer,g.iv.buffer,function(C){var P=t();D.observer.trigger(_.default.FRAG_DECRYPTED,{stats:{tstart:F,tdecrypt:P}}),D.pushDecrypted(new Uint8Array(C),g,new Uint8Array(v),s,l,x,h,E,S,b,I,L)})}else this.pushDecrypted(new Uint8Array(d),g,new Uint8Array(v),s,l,x,h,E,S,b,I,L)},n.prototype.pushDecrypted=function(d,g,v,s,l,x,h,E,S,b,I,L){var D=this.demuxer;if(!D||(h||E)&&!this.probe(d)){for(var O=this.observer,F=this.typeSupported,C=this.config,P=[{demux:u.default,remux:c.default},{demux:f.default,remux:a.default},{demux:y.default,remux:c.default},{demux:p.default,remux:c.default}],k=0,B=P.length;ky?(this.word<<=y,this.bitsAvailable-=y):(y-=this.bitsAvailable,f=y>>3,y-=f>>3,this.bytesAvailable-=f,this.loadWord(),this.word<<=y,this.bitsAvailable-=y)},m.prototype.readBits=function(y){var f=Math.min(this.bitsAvailable,y),u=this.word>>>32-f;return y>32&&_.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=f,this.bitsAvailable>0?this.word<<=f:this.bytesAvailable>0&&this.loadWord(),f=y-f,f>0&&this.bitsAvailable?u<>>y)!=0)return this.word<<=y,this.bitsAvailable-=y,y;return this.loadWord(),y+this.skipLZ()},m.prototype.skipUEG=function(){this.skipBits(1+this.skipLZ())},m.prototype.skipEG=function(){this.skipBits(1+this.skipLZ())},m.prototype.readUEG=function(){var y=this.skipLZ();return this.readBits(y+1)-1},m.prototype.readEG=function(){var y=this.readUEG();return 1&y?1+y>>>1:-1*(y>>>1)},m.prototype.readBoolean=function(){return this.readBits(1)===1},m.prototype.readUByte=function(){return this.readBits(8)},m.prototype.readUShort=function(){return this.readBits(16)},m.prototype.readUInt=function(){return this.readBits(32)},m.prototype.skipScalingList=function(y){var f=8,u=8,p,c;for(p=0;p0)return y.subarray(u,u+p)},m._readSize=function(y,f){var u=0;return u=(y[f]&127)<<21,u|=(y[f+1]&127)<<14,u|=(y[f+2]&127)<<7,u|=y[f+3]&127,u},m.getTimeStamp=function(y){for(var f=m.getID3Frames(y),u=0;u>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:o+=String.fromCharCode(p);break;case 12:case 13:c=y[r++],o+=String.fromCharCode((p&31)<<6|c&63);break;case 14:c=y[r++],a=y[r++],o+=String.fromCharCode((p&15)<<12|(c&63)<<6|(a&63)<<0);break;default:}}return o},m}(),A=_._utf8ArrayToStr;R.utf8ArrayToStr=A,R.default=_},"./src/demux/mp3demuxer.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/demux/id3.js"),A=T("./src/utils/logger.js"),m=T("./src/demux/mpegaudio.js"),y=function(){function f(u,p,c){this.observer=u,this.config=c,this.remuxer=p}return f.prototype.resetInitSegment=function(u,p,c,a){this._audioTrack={container:"audio/mpeg",type:"audio",id:-1,sequenceNumber:0,isAAC:!1,samples:[],len:0,manifestCodec:p,duration:a,inputTimeScale:9e4}},f.prototype.resetTimeStamp=function(){},f.probe=function(u){var p,c,a=_.default.getID3Data(u,0);if(a&&_.default.getTimeStamp(a)!==void 0){for(p=a.length,c=Math.min(u.length-1,p+100);p0},f.bin2str=function(u){return String.fromCharCode.apply(null,u)},f.readUint16=function(u,p){u.data&&(p+=u.start,u=u.data);var c=u[p]<<8|u[p+1];return c<0?65536+c:c},f.readUint32=function(u,p){u.data&&(p+=u.start,u=u.data);var c=u[p]<<24|u[p+1]<<16|u[p+2]<<8|u[p+3];return c<0?4294967296+c:c},f.writeUint32=function(u,p,c){u.data&&(p+=u.start,u=u.data),u[p]=c>>24,u[p+1]=c>>16&255,u[p+2]=c>>8&255,u[p+3]=c&255},f.findBox=function(u,p){var c=[],a,o,r,i,t,e,n;if(u.data?(e=u.start,i=u.end,u=u.data):(e=0,i=u.byteLength),!p.length)return null;for(a=e;a1?a+o:i,r===p[0]&&(p.length===1?c.push({data:u,start:a+8,end:n}):(t=f.findBox({data:u,start:a+8,end:n},p.slice(1)),t.length&&(c=c.concat(t)))),a=n;return c},f.parseSegmentIndex=function(u){var p=f.findBox(u,["moov"])[0],c=p?p.end:null,a=0,o=f.findBox(u,["sidx"]),r;if(!o||!o[0])return null;r=[],o=o[0];var i=o.data[0];a=i===0?8:16;var t=f.readUint32(o,a);a+=4;var e=0,n=0;i===0?a+=8:a+=16,a+=2;var d=o.end+n,g=f.readUint16(o,a);a+=2;for(var v=0;v>>31;if(h===1){console.warn("SIDX has hierarchical references (not supported)");return}var E=f.readUint32(o,s);s+=4,r.push({referenceSize:x,subsegmentDuration:E,info:{duration:E/t,start:d,end:d+x-1}}),d+=x,s+=4,a=s}return{earliestPresentationTime:e,timescale:t,version:i,referencesCount:g,references:r,moovEndOffset:c}},f.parseInitSegment=function(u){var p=[],c=f.findBox(u,["moov","trak"]);return c.forEach(function(a){var o=f.findBox(a,["tkhd"])[0];if(o){var r=o.data[o.start],i=r===0?12:20,t=f.readUint32(o,i),e=f.findBox(a,["mdia","mdhd"])[0];if(e){r=e.data[e.start],i=r===0?12:20;var n=f.readUint32(e,i),d=f.findBox(a,["mdia","hdlr"])[0];if(d){var g=f.bin2str(d.data.subarray(d.start+8,d.start+12)),v={soun:"audio",vide:"video"}[g];if(v){var s=f.findBox(a,["mdia","minf","stbl","stsd"]);if(s.length){s=s[0];var l=f.bin2str(s.data.subarray(s.start+12,s.start+16));_.logger.log("MP4Demuxer:"+v+":"+l+" found")}p[t]={timescale:n,type:v},p[v]={timescale:n,id:t}}}}}}),p},f.getStartDTS=function(u,p){var c,a,o;return c=f.findBox(p,["moof","traf"]),a=[].concat.apply([],c.map(function(r){return f.findBox(r,["tfhd"]).map(function(i){var t,e,n;return t=f.readUint32(i,4),e=u[t].timescale||9e4,n=f.findBox(r,["tfdt"]).map(function(d){var g,v;return g=d.data[d.start],v=f.readUint32(d,4),g===1&&(v*=Math.pow(2,32),v+=f.readUint32(d,8)),v})[0],n/e})})),o=Math.min.apply(null,a),isFinite(o)?o:0},f.offsetStartDTS=function(u,p,c){f.findBox(p,["moof","traf"]).map(function(a){return f.findBox(a,["tfhd"]).map(function(o){var r=f.readUint32(o,4),i=u[r].timescale||9e4;f.findBox(a,["tfdt"]).map(function(t){var e=t.data[t.start],n=f.readUint32(t,4);if(e===0)f.writeUint32(t,4,n-c*i);else{n*=Math.pow(2,32),n+=f.readUint32(t,8),n-=c*i,n=Math.max(n,0);var d=Math.floor(n/(m+1)),g=Math.floor(n%(m+1));f.writeUint32(t,4,d),f.writeUint32(t,8,g)}})})})},f.prototype.append=function(u,p,c,a){var o=this.initData;o||(this.resetInitSegment(u,this.audioCodec,this.videoCodec,!1),o=this.initData);var r,i=this.initPTS;if(i===void 0){var t=f.getStartDTS(o,u);this.initPTS=i=t-p,this.observer.trigger(A.default.INIT_PTS_FOUND,{initPTS:i})}f.offsetStartDTS(o,u,i),r=f.getStartDTS(o,u),this.remuxer.remux(o.audio,o.video,null,null,r,c,a,u)},f.prototype.destroy=function(){},f}();R.default=y},"./src/demux/mpegaudio.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _={BitratesMap:[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],SamplingRateMap:[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],SamplesCoefficients:[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],BytesInSlot:[0,1,1,4],appendFrame:function(A,m,y,f,u){if(!(y+24>m.length)){var p=this.parseHeader(m,y);if(p&&y+p.frameLength<=m.length){var c=p.samplesPerFrame*9e4/p.sampleRate,a=f+u*c,o={unit:m.subarray(y,y+p.frameLength),pts:a,dts:a};return A.config=[],A.channelCount=p.channelCount,A.samplerate=p.sampleRate,A.samples.push(o),A.len+=p.frameLength,{sample:o,length:p.frameLength}}}},parseHeader:function(A,m){var y=A[m+1]>>3&3,f=A[m+1]>>1&3,u=A[m+2]>>4&15,p=A[m+2]>>2&3,c=A[m+2]>>1&1;if(y!==1&&u!==0&&u!==15&&p!==3){var a=y===3?3-f:f===3?3:4,o=_.BitratesMap[a*14+u-1]*1e3,r=y===3?0:y===2?1:2,i=_.SamplingRateMap[r*3+p],t=A[m+3]>>6==3?1:2,e=_.SamplesCoefficients[y][f],n=_.BytesInSlot[f],d=e*8*n,g=parseInt(e*o/i+c,10)*n;return{sampleRate:i,channelCount:t,frameLength:g,samplesPerFrame:d}}},isHeaderPattern:function(A,m){return A[m]===255&&(A[m+1]&224)==224&&(A[m+1]&6)!=0},isHeader:function(A,m){return!!(m+1=y.length){u();return}if(!(y[f].unit.length<32)){var p=this.decrypter.isSync();if(this.decryptAacSample(y,f,u,p),!p)return}}},m.prototype.getAvcEncryptedData=function(y){for(var f=Math.floor((y.length-48)/160)*16+16,u=new Int8Array(f),p=0,c=32;c<=y.length-16;c+=160,p+=16)u.set(y.subarray(c,c+16),p);return u},m.prototype.getAvcDecryptedUnit=function(y,f){f=new Uint8Array(f);for(var u=0,p=32;p<=y.length-16;p+=160,u+=16)y.set(f.subarray(u,u+16),p);return y},m.prototype.decryptAvcSample=function(y,f,u,p,c,a){var o=this.discardEPB(c.data),r=this.getAvcEncryptedData(o),i=this;this.decryptBuffer(r.buffer,function(t){c.data=i.getAvcDecryptedUnit(o,t),a||i.decryptAvcSamples(y,f,u+1,p)})},m.prototype.decryptAvcSamples=function(y,f,u,p){for(;;f++,u=0){if(f>=y.length){p();return}for(var c=y[f].units;!(u>=c.length);u++){var a=c[u];if(!(a.length<=48||a.type!==1&&a.type!==5)){var o=this.decrypter.isSync();if(this.decryptAvcSample(y,f,u,p,a,o),!o)return}}}},m}();R.default=A},"./src/demux/tsdemuxer.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/demux/adts.js"),A=T("./src/demux/mpegaudio.js"),m=T("./src/events.js"),y=T("./src/demux/exp-golomb.js"),f=T("./src/demux/sample-aes.js"),u=T("./src/utils/logger.js"),p=T("./src/errors.js"),c={video:1,audio:2,id3:3,text:4},a=function(){function o(r,i,t,e){this.observer=r,this.config=t,this.typeSupported=e,this.remuxer=i,this.sampleAes=null}return o.prototype.setDecryptData=function(r){r!=null&&r.key!=null&&r.method==="SAMPLE-AES"?this.sampleAes=new f.default(this.observer,this.config,r,this.discardEPB):this.sampleAes=null},o.probe=function(r){var i=o._syncOffset(r);return i<0?!1:(i&&u.logger.warn("MPEG2-TS detected but first sync word found @ offset "+i+", junk ahead ?"),!0)},o._syncOffset=function(r){for(var i=Math.min(1e3,r.length-3*188),t=0;t>4,s>1){if(l=n+5+r[n+4],l===n+188)continue}else l=n+4;switch(v){case L:g&&(C&&(x=N(C))&&x.pts!==void 0&&j(x,!1),C={data:[],size:0}),C&&(C.data.push(r.subarray(l,n+188)),C.size+=n+188-l);break;case D:g&&(P&&(x=N(P))&&x.pts!==void 0&&(b.isAAC?K(x):G(x)),P={data:[],size:0}),P&&(P.data.push(r.subarray(l,n+188)),P.size+=n+188-l);break;case O:g&&(k&&(x=N(k))&&x.pts!==void 0&&W(x),k={data:[],size:0}),k&&(k.data.push(r.subarray(l,n+188)),k.size+=n+188-l);break;case 0:g&&(l+=r[l]+1),F=this._pmtId=B(r,l);break;case F:g&&(l+=r[l]+1);var V=M(r,l,this.typeSupported.mpeg===!0||this.typeSupported.mp3===!0,this.sampleAes!=null);L=V.avc,L>0&&(S.pid=L),D=V.audio,D>0&&(b.pid=D,b.isAAC=V.isAAC),O=V.id3,O>0&&(I.pid=O),h&&!E&&(u.logger.log("reparse from beginning"),h=!1,n=U-188),E=this.pmtParsed=!0;break;case 17:case 8191:break;default:h=!0;break}}else this.observer.trigger(m.default.ERROR,{type:p.ErrorTypes.MEDIA_ERROR,details:p.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});C&&(x=N(C))&&x.pts!==void 0?(j(x,!0),S.pesData=null):S.pesData=C,P&&(x=N(P))&&x.pts!==void 0?(b.isAAC?K(x):G(x),b.pesData=null):(P&&P.size&&u.logger.log("last AAC PES packet truncated,might overlap between fragments"),b.pesData=P),k&&(x=N(k))&&x.pts!==void 0?(W(x),I.pesData=null):I.pesData=k,this.sampleAes==null?this.remuxer.remux(b,S,I,this._txtTrack,i,t,e):this.decryptAndRemux(b,S,I,this._txtTrack,i,t,e)},o.prototype.decryptAndRemux=function(r,i,t,e,n,d,g){if(r.samples&&r.isAAC){var v=this;this.sampleAes.decryptAacSamples(r.samples,0,function(){v.decryptAndRemuxAvc(r,i,t,e,n,d,g)})}else this.decryptAndRemuxAvc(r,i,t,e,n,d,g)},o.prototype.decryptAndRemuxAvc=function(r,i,t,e,n,d,g){if(i.samples){var v=this;this.sampleAes.decryptAvcSamples(i.samples,0,0,function(){v.remuxer.remux(r,i,t,e,n,d,g)})}else this.remuxer.remux(r,i,t,e,n,d,g)},o.prototype.destroy=function(){this._initPTS=this._initDTS=void 0,this._duration=0},o.prototype._parsePAT=function(r,i){return(r[i+10]&31)<<8|r[i+11]},o.prototype._parsePMT=function(r,i,t,e){var n,d,g,v,s={audio:-1,avc:-1,id3:-1,isAAC:!0};for(n=(r[i+1]&15)<<8|r[i+2],d=i+3+n-4,g=(r[i+10]&15)<<8|r[i+11],i+=12+g;i1;){var E=new Uint8Array(h[0].length+h[1].length);E.set(h[0]),E.set(h[1],h[0].length),h[0]=E,h.splice(1,1)}if(t=h[0],n=(t[0]<<16)+(t[1]<<8)+t[2],n===1){if(d=(t[4]<<8)+t[5],d&&d>r.size-6)return null;e=t[7],e&192&&(s=(t[9]&14)*536870912+(t[10]&255)*4194304+(t[11]&254)*16384+(t[12]&255)*128+(t[13]&254)/2,s>4294967295&&(s-=8589934592),e&64?(l=(t[14]&14)*536870912+(t[15]&255)*4194304+(t[16]&254)*16384+(t[17]&255)*128+(t[18]&254)/2,l>4294967295&&(l-=8589934592),s-l>60*9e4&&(u.logger.warn(Math.round((s-l)/9e4)+"s delta between PTS and DTS, align them"),s=l)):l=s),g=t[8],x=g+9,r.size-=x,v=new Uint8Array(r.size);for(var S=0,b=h.length;SI){x-=I;continue}else t=t.subarray(x),I-=x,x=0;v.set(t,i),i+=I}return d&&(d-=g+3),{data:v,pts:s,dts:l,len:d}}else return null},o.prototype.pushAccesUnit=function(r,i){if(r.units.length&&r.frame){var t=i.samples,e=t.length;!this.config.forceKeyFrameOnDiscontinuity||r.key===!0||i.sps&&(e||this.contiguous)?(r.id=e,t.push(r)):i.dropped++}r.debug.length&&u.logger.log(r.pts+"/"+r.dts+":"+r.debug)},o.prototype._parseAVCPES=function(r,i){var t=this,e=this._avcTrack,n=this._parseAVCNALu(r.data),d=!1,g,v=this.avcSample,s,l=!1,x,h=this.pushAccesUnit.bind(this),E=function(S,b,I,L){return{key:S,pts:b,dts:I,units:[],debug:L}};r.data=null,v&&n.length&&!e.audFound&&(h(v,e),v=this.avcSample=E(!1,r.pts,r.dts,"")),n.forEach(function(S){switch(S.type){case 1:s=!0,v||(v=t.avcSample=E(!0,r.pts,r.dts,"")),d&&(v.debug+="NDR "),v.frame=!0;var b=S.data;if(l&&b.length>4){var I=new y.default(b).readSliceType();(I===2||I===4||I===7||I===9)&&(v.key=!0)}break;case 5:s=!0,v||(v=t.avcSample=E(!0,r.pts,r.dts,"")),d&&(v.debug+="IDR "),v.key=!0,v.frame=!0;break;case 6:s=!0,d&&v&&(v.debug+="SEI "),g=new y.default(t.discardEPB(S.data)),g.readUByte();for(var L=0,D=0,O=!1,F=0;!O&&g.bytesAvailable>1;){L=0;do F=g.readUByte(),L+=F;while(F===255);D=0;do F=g.readUByte(),D+=F;while(F===255);if(L===4&&g.bytesAvailable!==0){O=!0;var C=g.readUByte();if(C===181){var P=g.readUShort();if(P===49){var k=g.readUInt();if(k===1195456820){var B=g.readUByte();if(B===3){var M=g.readUByte(),N=g.readUByte(),j=31&M,K=[M,N];for(x=0;x0){if(i.pts>=r[t-1].pts)r.push(i);else for(var e=t-1;e>=0;e--)if(i.pts=0)l={data:r.subarray(h,i-g-1),type:E},s.push(l);else{var S=this._getLastNalUnit();if(S&&(v&&i<=4-v&&S.state&&(S.data=S.data.subarray(0,S.data.byteLength-v)),n=i-g-1,n>0)){var b=new Uint8Array(S.data.byteLength+n);b.set(S.data,0),b.set(r.subarray(0,n),S.data.byteLength),S.data=b}}i=0&&g>=0&&(l={data:r.subarray(h,t),type:E,state:g},s.push(l)),s.length===0){var S=this._getLastNalUnit();if(S){var b=new Uint8Array(S.data.byteLength+r.byteLength);b.set(S.data,0),b.set(r,S.data.byteLength),S.data=b}}return d.naluState=g,s},o.prototype.discardEPB=function(r){for(var i=r.byteLength,t=[],e=1,n,d;e1&&(u.logger.log("AAC: align PTS for overlapping frames by "+Math.round((I-e)/90)),e=I)}for(;lx)return E}return 0},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"maxAutoLevel",{get:function(){var s=this,l=s.levels,x=s.autoLevelCapping,h;return x===-1&&l&&l.length?h=l.length-1:h=x,h},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"nextAutoLevel",{get:function(){var s=this;return Math.min(Math.max(s.abrController.nextAutoLevel,s.minAutoLevel),s.maxAutoLevel)},set:function(s){var l=this;l.abrController.nextAutoLevel=Math.max(l.minAutoLevel,s)},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"audioTracks",{get:function(){var s=this.audioTrackController;return s?s.audioTracks:[]},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"audioTrack",{get:function(){var s=this.audioTrackController;return s?s.audioTrack:-1},set:function(s){var l=this.audioTrackController;l&&(l.audioTrack=s)},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"liveSyncPosition",{get:function(){return this.streamController.liveSyncPosition},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"subtitleTracks",{get:function(){var s=this.subtitleTrackController;return s?s.subtitleTracks:[]},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"subtitleTrack",{get:function(){var s=this.subtitleTrackController;return s?s.subtitleTrack:-1},set:function(s){var l=this.subtitleTrackController;l&&(l.subtitleTrack=s)},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"subtitleDisplay",{get:function(){var s=this.subtitleTrackController;return s?s.subtitleDisplay:!1},set:function(s){var l=this.subtitleTrackController;l&&(l.subtitleDisplay=s)},enumerable:!0,configurable:!0}),v}(n.Observer);R.default=d},"./src/is-supported.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/utils/mediasource-helper.js");function A(){var m=_.getMediaSource(),y=window.SourceBuffer||window.WebKitSourceBuffer,f=m&&typeof m.isTypeSupported=="function"&&m.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'),u=!y||y.prototype&&typeof y.prototype.appendBuffer=="function"&&typeof y.prototype.remove=="function";return!!f&&!!u}R.isSupported=A},"./src/loader/fragment-loader.js":function(w,R,T){"use strict";(function(_){var A=this&&this.__extends||function(){var c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,o){a.__proto__=o}||function(a,o){for(var r in o)o.hasOwnProperty(r)&&(a[r]=o[r])};return function(a,o){c(a,o);function r(){this.constructor=a}a.prototype=o===null?Object.create(o):(r.prototype=o.prototype,new r)}}();Object.defineProperty(R,"__esModule",{value:!0});var m=T("./src/events.js"),y=T("./src/event-handler.js"),f=T("./src/errors.js"),u=T("./src/utils/logger.js"),p=function(c){A(a,c);function a(o){var r=c.call(this,o,m.default.FRAG_LOADING)||this;return r.loaders={},r}return a.prototype.destroy=function(){var o=this.loaders;for(var r in o){var i=o[r];i&&i.destroy()}this.loaders={},c.prototype.destroy.call(this)},a.prototype.onFragLoading=function(o){var r=o.frag,i=r.type,t=this.loaders,e=this.hls.config,n=e.fLoader,d=e.loader;r.loaded=0;var g=t[i];g&&(u.logger.warn("abort previous fragment loader for type: "+i),g.abort()),g=t[i]=r.loader=e.fLoader?new n(e):new d(e);var v,s,l;v={url:r.url,frag:r,responseType:"arraybuffer",progressData:!1};var x=r.byteRangeStartOffset,h=r.byteRangeEndOffset;_.isFinite(x)&&_.isFinite(h)&&(v.rangeStart=x,v.rangeEnd=h),s={timeout:e.fragLoadingTimeOut,maxRetry:0,retryDelay:0,maxRetryDelay:e.fragLoadingMaxRetryTimeout},l={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this),onProgress:this.loadprogress.bind(this)},g.load(v,s,l)},a.prototype.loadsuccess=function(o,r,i,t){t===void 0&&(t=null);var e=o.data,n=i.frag;n.loader=void 0,this.loaders[n.type]=void 0,this.hls.trigger(m.default.FRAG_LOADED,{payload:e,frag:n,stats:r,networkDetails:t})},a.prototype.loaderror=function(o,r,i){i===void 0&&(i=null);var t=r.frag,e=t.loader;e&&e.abort(),this.loaders[t.type]=void 0,this.hls.trigger(m.default.ERROR,{type:f.ErrorTypes.NETWORK_ERROR,details:f.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:r.frag,response:o,networkDetails:i})},a.prototype.loadtimeout=function(o,r,i){i===void 0&&(i=null);var t=r.frag,e=t.loader;e&&e.abort(),this.loaders[t.type]=void 0,this.hls.trigger(m.default.ERROR,{type:f.ErrorTypes.NETWORK_ERROR,details:f.ErrorDetails.FRAG_LOAD_TIMEOUT,fatal:!1,frag:r.frag,networkDetails:i})},a.prototype.loadprogress=function(o,r,i,t){t===void 0&&(t=null);var e=r.frag;e.loaded=o.loaded,this.hls.trigger(m.default.FRAG_LOAD_PROGRESS,{frag:e,stats:o,networkDetails:t})},a}(y.default);R.default=p}).call(this,T("./src/polyfills/number.js").Number)},"./src/loader/fragment.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=T("./node_modules/url-toolkit/src/url-toolkit.js"),m=T("./src/loader/level-key.js"),y=function(){function f(){var u;this._url=null,this._byteRange=null,this._decryptdata=null,this.tagList=[],this.programDateTime=null,this.rawProgramDateTime=null,this._elementaryStreams=(u={},u[f.ElementaryStreamTypes.AUDIO]=!1,u[f.ElementaryStreamTypes.VIDEO]=!1,u)}return Object.defineProperty(f,"ElementaryStreamTypes",{get:function(){return{AUDIO:"audio",VIDEO:"video"}},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"url",{get:function(){return!this._url&&this.relurl&&(this._url=A.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url},set:function(u){this._url=u},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"byteRange",{get:function(){if(!this._byteRange&&!this.rawByteRange)return[];if(this._byteRange)return this._byteRange;var u=[];if(this.rawByteRange){var p=this.rawByteRange.split("@",2);if(p.length===1){var c=this.lastByteRangeEndOffset;u[0]=c||0}else u[0]=parseInt(p[1]);u[1]=parseInt(p[0])+u[0],this._byteRange=u}return u},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"byteRangeStartOffset",{get:function(){return this.byteRange[0]},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"byteRangeEndOffset",{get:function(){return this.byteRange[1]},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"decryptdata",{get:function(){return this._decryptdata||(this._decryptdata=this.fragmentDecryptdataFromLevelkey(this.levelkey,this.sn)),this._decryptdata},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"endProgramDateTime",{get:function(){if(!_.isFinite(this.programDateTime))return null;var u=_.isFinite(this.duration)?this.duration:0;return this.programDateTime+u*1e3},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"encrypted",{get:function(){return!!(this.decryptdata&&this.decryptdata.uri!==null&&this.decryptdata.key===null)},enumerable:!0,configurable:!0}),f.prototype.addElementaryStream=function(u){this._elementaryStreams[u]=!0},f.prototype.hasElementaryStream=function(u){return this._elementaryStreams[u]===!0},f.prototype.createInitializationVector=function(u){for(var p=new Uint8Array(16),c=12;c<16;c++)p[c]=u>>8*(15-c)&255;return p},f.prototype.fragmentDecryptdataFromLevelkey=function(u,p){var c=u;return u&&u.method&&u.uri&&!u.iv&&(c=new m.default,c.method=u.method,c.baseuri=u.baseuri,c.reluri=u.reluri,c.iv=this.createInitializationVector(p)),c},f}();R.default=y}).call(this,T("./src/polyfills/number.js").Number)},"./src/loader/key-loader.js":function(w,R,T){"use strict";var _=this&&this.__extends||function(){var p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,a){c.__proto__=a}||function(c,a){for(var o in a)a.hasOwnProperty(o)&&(c[o]=a[o])};return function(c,a){p(c,a);function o(){this.constructor=c}c.prototype=a===null?Object.create(a):(o.prototype=a.prototype,new o)}}();Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/events.js"),m=T("./src/event-handler.js"),y=T("./src/errors.js"),f=T("./src/utils/logger.js"),u=function(p){_(c,p);function c(a){var o=p.call(this,a,A.default.KEY_LOADING)||this;return o.loaders={},o.decryptkey=null,o.decrypturl=null,o}return c.prototype.destroy=function(){for(var a in this.loaders){var o=this.loaders[a];o&&o.destroy()}this.loaders={},m.default.prototype.destroy.call(this)},c.prototype.onKeyLoading=function(a){var o=a.frag,r=o.type,i=this.loaders[r],t=o.decryptdata,e=t.uri;if(e!==this.decrypturl||this.decryptkey===null){var n=this.hls.config;i&&(f.logger.warn("abort previous key loader for type:"+r),i.abort()),o.loader=this.loaders[r]=new n.loader(n),this.decrypturl=e,this.decryptkey=null;var d=void 0,g=void 0,v=void 0;d={url:e,frag:o,responseType:"arraybuffer"},g={timeout:n.fragLoadingTimeOut,maxRetry:0,retryDelay:n.fragLoadingRetryDelay,maxRetryDelay:n.fragLoadingMaxRetryTimeout},v={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)},o.loader.load(d,g,v)}else this.decryptkey&&(t.key=this.decryptkey,this.hls.trigger(A.default.KEY_LOADED,{frag:o}))},c.prototype.loadsuccess=function(a,o,r){var i=r.frag;this.decryptkey=i.decryptdata.key=new Uint8Array(a.data),i.loader=void 0,this.loaders[i.type]=void 0,this.hls.trigger(A.default.KEY_LOADED,{frag:i})},c.prototype.loaderror=function(a,o){var r=o.frag,i=r.loader;i&&i.abort(),this.loaders[o.type]=void 0,this.hls.trigger(A.default.ERROR,{type:y.ErrorTypes.NETWORK_ERROR,details:y.ErrorDetails.KEY_LOAD_ERROR,fatal:!1,frag:r,response:a})},c.prototype.loadtimeout=function(a,o){var r=o.frag,i=r.loader;i&&i.abort(),this.loaders[o.type]=void 0,this.hls.trigger(A.default.ERROR,{type:y.ErrorTypes.NETWORK_ERROR,details:y.ErrorDetails.KEY_LOAD_TIMEOUT,fatal:!1,frag:r})},c}(m.default);R.default=u},"./src/loader/level-key.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./node_modules/url-toolkit/src/url-toolkit.js"),A=function(){function m(){this.method=null,this.key=null,this.iv=null,this._uri=null}return Object.defineProperty(m.prototype,"uri",{get:function(){return!this._uri&&this.reluri&&(this._uri=_.buildAbsoluteURL(this.baseuri,this.reluri,{alwaysNormalize:!0})),this._uri},enumerable:!0,configurable:!0}),m}();R.default=A},"./src/loader/level.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=function(){function m(y){this.endCC=0,this.endSN=0,this.fragments=[],this.initSegment=null,this.live=!0,this.needSidxRanges=!1,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=y,this.version=null}return Object.defineProperty(m.prototype,"hasProgramDateTime",{get:function(){return!!(this.fragments[0]&&_.isFinite(this.fragments[0].programDateTime))},enumerable:!0,configurable:!0}),m}();R.default=A}).call(this,T("./src/polyfills/number.js").Number)},"./src/loader/m3u8-parser.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=T("./node_modules/url-toolkit/src/url-toolkit.js"),m=T("./src/loader/fragment.js"),y=T("./src/loader/level.js"),f=T("./src/loader/level-key.js"),u=T("./src/utils/attr-list.js"),p=T("./src/utils/logger.js"),c=T("./src/utils/codecs.js"),a=/#EXT-X-STREAM-INF:([^\n\r]*)[\r\n]+([^\r\n]+)/g,o=/#EXT-X-MEDIA:(.*)/g,r=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/|(?!#)([\S+ ?]+)/.source,/|#EXT-X-BYTERANGE:*(.+)/.source,/|#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/|#.*/.source].join(""),"g"),i=/(?:(?:#(EXTM3U))|(?:#EXT-X-(PLAYLIST-TYPE):(.+))|(?:#EXT-X-(MEDIA-SEQUENCE): *(\d+))|(?:#EXT-X-(TARGETDURATION): *(\d+))|(?:#EXT-X-(KEY):(.+))|(?:#EXT-X-(START):(.+))|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DISCONTINUITY-SEQ)UENCE:(\d+))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(VERSION):(\d+))|(?:#EXT-X-(MAP):(.+))|(?:(#)([^:]*):(.*))|(?:(#)(.*))(?:.*)\r?\n?/,t=/\.(mp4|m4s|m4v|m4a)$/i,e=function(){function g(){}return g.findGroup=function(v,s){if(!v)return null;for(var l=null,x=0;x2?(s=l.shift()+".",s+=parseInt(l.shift()).toString(16),s+=("000"+parseInt(l.shift()).toString(16)).substr(-4)):s=v,s},g.resolve=function(v,s){return A.buildAbsoluteURL(s,v,{alwaysNormalize:!0})},g.parseMasterPlaylist=function(v,s){var l=[],x;a.lastIndex=0;function h(I,L){["video","audio"].forEach(function(D){var O=I.filter(function(C){return c.isCodecType(C,D)});if(O.length){var F=O.filter(function(C){return C.lastIndexOf("avc1",0)===0||C.lastIndexOf("mp4a",0)===0});L[D+"Codec"]=F.length>0?F[0]:O[0],I=I.filter(function(C){return O.indexOf(C)===-1})}}),L.unknownCodecs=I}for(;(x=a.exec(v))!=null;){var E={},S=E.attrs=new u.default(x[1]);E.url=g.resolve(x[2],s);var b=S.decimalResolution("RESOLUTION");b&&(E.width=b.width,E.height=b.height),E.bitrate=S.decimalInteger("AVERAGE-BANDWIDTH")||S.decimalInteger("BANDWIDTH"),E.name=S.NAME,h([].concat((S.CODECS||"").split(/[ ,]+/)),E),E.videoCodec&&E.videoCodec.indexOf("avc1")!==-1&&(E.videoCodec=g.convertAVC1ToAVCOTI(E.videoCodec)),l.push(E)}return l},g.parseMasterPlaylistMedia=function(v,s,l,x){x===void 0&&(x=[]);var h,E=[],S=0;for(o.lastIndex=0;(h=o.exec(v))!==null;){var b={},I=new u.default(h[1]);if(I.TYPE===l){if(b.groupId=I["GROUP-ID"],b.name=I.NAME,b.type=l,b.default=I.DEFAULT==="YES",b.autoselect=I.AUTOSELECT==="YES",b.forced=I.FORCED==="YES",I.URI&&(b.url=g.resolve(I.URI,s)),b.lang=I.LANGUAGE,b.name||(b.name=b.lang),x.length){var L=g.findGroup(x,b.groupId);b.audioCodec=L?L.codec:x[0].codec}b.id=S++,E.push(b)}}return E},g.parseLevelPlaylist=function(v,s,l,x,h){var E=0,S=0,b=new y.default(s),I=new f.default,L=0,D=null,O=new m.default,F,C,P=null;for(r.lastIndex=0;(F=r.exec(v))!==null;){var k=F[1];if(k){O.duration=parseFloat(k);var B=(" "+F[2]).slice(1);O.title=B||null,O.tagList.push(B?["INF",k,B]:["INF",k])}else if(F[3]){if(_.isFinite(O.duration)){var M=E++;O.type=x,O.start=S,O.levelkey=I,O.sn=M,O.level=l,O.cc=L,O.urlId=h,O.baseurl=s,O.relurl=(" "+F[3]).slice(1),d(O,D),b.fragments.push(O),D=O,S+=O.duration,O=new m.default}}else if(F[4]){if(O.rawByteRange=(" "+F[4]).slice(1),D){var N=D.byteRangeEndOffset;N&&(O.lastByteRangeEndOffset=N)}}else if(F[5])O.rawProgramDateTime=(" "+F[5]).slice(1),O.tagList.push(["PROGRAM-DATE-TIME",O.rawProgramDateTime]),P===null&&(P=b.fragments.length);else{for(F=F[0].match(i),C=1;C=0&&(I.method=U,I.baseuri=s,I.reluri=V,I.key=null,I.iv=H));break;case"START":var Y=j,z=new u.default(Y),X=z.decimalFloatingPoint("TIME-OFFSET");_.isFinite(X)&&(b.startTimeOffset=X);break;case"MAP":var ee=new u.default(j);O.relurl=ee.URI,O.rawByteRange=ee.BYTERANGE,O.baseurl=s,O.level=l,O.type=x,O.sn="initSegment",b.initSegment=O,O=new m.default,O.rawProgramDateTime=b.initSegment.rawProgramDateTime;break;default:p.logger.warn("line parsed but not handled: "+F);break}}}return O=D,O&&!O.relurl&&(b.fragments.pop(),S-=O.duration),b.totalduration=S,b.averagetargetduration=S/b.fragments.length,b.endSN=E-1,b.startCC=b.fragments[0]?b.fragments[0].cc:0,b.endCC=L,!b.initSegment&&b.fragments.length&&b.fragments.every(function(te){return t.test(te.relurl)})&&(p.logger.warn("MP4 fragments found but no init segment (probably no MAP, incomplete M3U8), trying to fetch SIDX"),O=new m.default,O.relurl=b.fragments[0].relurl,O.baseurl=s,O.level=l,O.type=x,O.sn="initSegment",b.initSegment=O,b.needSidxRanges=!0),P&&n(b.fragments,P),b},g}();R.default=e;function n(g,v){for(var s=g[v],l=v-1;l>=0;l--){var x=g[l];x.programDateTime=s.programDateTime-x.duration*1e3,s=x}}function d(g,v){g.rawProgramDateTime?g.programDateTime=Date.parse(g.rawProgramDateTime):v&&v.programDateTime&&(g.programDateTime=v.endProgramDateTime),_.isFinite(g.programDateTime)||(g.programDateTime=null,g.rawProgramDateTime=null)}}).call(this,T("./src/polyfills/number.js").Number)},"./src/loader/playlist-loader.js":function(w,R,T){"use strict";(function(_){var A=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var d in n)n.hasOwnProperty(d)&&(e[d]=n[d])};return function(e,n){t(e,n);function d(){this.constructor=e}e.prototype=n===null?Object.create(n):(d.prototype=n.prototype,new d)}}();Object.defineProperty(R,"__esModule",{value:!0});var m=T("./src/events.js"),y=T("./src/event-handler.js"),f=T("./src/errors.js"),u=T("./src/utils/logger.js"),p=T("./src/demux/mp4demuxer.js"),c=T("./src/loader/m3u8-parser.js"),a=window.performance,o={MANIFEST:"manifest",LEVEL:"level",AUDIO_TRACK:"audioTrack",SUBTITLE_TRACK:"subtitleTrack"},r={MAIN:"main",AUDIO:"audio",SUBTITLE:"subtitle"},i=function(t){A(e,t);function e(n){var d=t.call(this,n,m.default.MANIFEST_LOADING,m.default.LEVEL_LOADING,m.default.AUDIO_TRACK_LOADING,m.default.SUBTITLE_TRACK_LOADING)||this;return d.loaders={},d}return Object.defineProperty(e,"ContextType",{get:function(){return o},enumerable:!0,configurable:!0}),Object.defineProperty(e,"LevelType",{get:function(){return r},enumerable:!0,configurable:!0}),e.canHaveQualityLevels=function(n){return n!==o.AUDIO_TRACK&&n!==o.SUBTITLE_TRACK},e.mapContextToLevelType=function(n){var d=n.type;switch(d){case o.AUDIO_TRACK:return r.AUDIO;case o.SUBTITLE_TRACK:return r.SUBTITLE;default:return r.MAIN}},e.getResponseUrl=function(n,d){var g=n.url;return(g===void 0||g.indexOf("data:")===0)&&(g=d.url),g},e.prototype.createInternalLoader=function(n){var d=this.hls.config,g=d.pLoader,v=d.loader,s=g||v,l=new s(d);return n.loader=l,this.loaders[n.type]=l,l},e.prototype.getInternalLoader=function(n){return this.loaders[n.type]},e.prototype.resetInternalLoader=function(n){this.loaders[n]&&delete this.loaders[n]},e.prototype.destroyInternalLoaders=function(){for(var n in this.loaders){var d=this.loaders[n];d&&d.destroy(),this.resetInternalLoader(n)}},e.prototype.destroy=function(){this.destroyInternalLoaders(),t.prototype.destroy.call(this)},e.prototype.onManifestLoading=function(n){this.load(n.url,{type:o.MANIFEST,level:0,id:null})},e.prototype.onLevelLoading=function(n){this.load(n.url,{type:o.LEVEL,level:n.level,id:n.id})},e.prototype.onAudioTrackLoading=function(n){this.load(n.url,{type:o.AUDIO_TRACK,level:null,id:n.id})},e.prototype.onSubtitleTrackLoading=function(n){this.load(n.url,{type:o.SUBTITLE_TRACK,level:null,id:n.id})},e.prototype.load=function(n,d){var g=this.hls.config;u.logger.debug("Loading playlist of type "+d.type+", level: "+d.level+", id: "+d.id);var v=this.getInternalLoader(d);if(v){var s=v.context;if(s&&s.url===n)return u.logger.trace("playlist request ongoing"),!1;u.logger.warn("aborting previous loader for type: "+d.type),v.abort()}var l,x,h,E;switch(d.type){case o.MANIFEST:l=g.manifestLoadingMaxRetry,x=g.manifestLoadingTimeOut,h=g.manifestLoadingRetryDelay,E=g.manifestLoadingMaxRetryTimeout;break;case o.LEVEL:l=0,x=g.levelLoadingTimeOut;break;default:l=g.levelLoadingMaxRetry,x=g.levelLoadingTimeOut,h=g.levelLoadingRetryDelay,E=g.levelLoadingMaxRetryTimeout;break}v=this.createInternalLoader(d),d.url=n,d.responseType=d.responseType||"";var S={timeout:x,maxRetry:l,retryDelay:h,maxRetryDelay:E},b={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};return u.logger.debug("Calling internal loader delegate for URL: "+n),v.load(d,S,b),!0},e.prototype.loadsuccess=function(n,d,g,v){if(v===void 0&&(v=null),g.isSidxRequest){this._handleSidxRequest(n,g),this._handlePlaylistLoaded(n,d,g,v);return}this.resetInternalLoader(g.type);var s=n.data;if(d.tload=a.now(),s.indexOf("#EXTM3U")!==0){this._handleManifestParsingError(n,g,"no EXTM3U delimiter",v);return}s.indexOf("#EXTINF:")>0||s.indexOf("#EXT-X-TARGETDURATION:")>0?this._handleTrackOrLevelPlaylist(n,d,g,v):this._handleMasterPlaylist(n,d,g,v)},e.prototype.loaderror=function(n,d,g){g===void 0&&(g=null),this._handleNetworkError(d,g,!1,n)},e.prototype.loadtimeout=function(n,d,g){g===void 0&&(g=null),this._handleNetworkError(d,g,!0)},e.prototype._handleMasterPlaylist=function(n,d,g,v){var s=this.hls,l=n.data,x=e.getResponseUrl(n,g),h=c.default.parseMasterPlaylist(l,x);if(!h.length){this._handleManifestParsingError(n,g,"no level found in manifest",v);return}var E=h.map(function(L){return{id:L.attrs.AUDIO,codec:L.audioCodec}}),S=c.default.parseMasterPlaylistMedia(l,x,"AUDIO",E),b=c.default.parseMasterPlaylistMedia(l,x,"SUBTITLES");if(S.length){var I=!1;S.forEach(function(L){L.url||(I=!0)}),I===!1&&h[0].audioCodec&&!h[0].attrs.AUDIO&&(u.logger.log("audio codec signaled in quality level, but no embedded audio track signaled, create one"),S.unshift({type:"main",name:"main"}))}s.trigger(m.default.MANIFEST_LOADED,{levels:h,audioTracks:S,subtitles:b,url:x,stats:d,networkDetails:v})},e.prototype._handleTrackOrLevelPlaylist=function(n,d,g,v){var s=this.hls,l=g.id,x=g.level,h=g.type,E=e.getResponseUrl(n,g),S=_.isFinite(l)?l:0,b=_.isFinite(x)?x:S,I=e.mapContextToLevelType(g),L=c.default.parseLevelPlaylist(n.data,E,b,I,S);if(L.tload=d.tload,h===o.MANIFEST){var D={url:E,details:L};s.trigger(m.default.MANIFEST_LOADED,{levels:[D],audioTracks:[],url:E,stats:d,networkDetails:v})}if(d.tparsed=a.now(),L.needSidxRanges){var O=L.initSegment.url;this.load(O,{isSidxRequest:!0,type:h,level:x,levelDetails:L,id:l,rangeStart:0,rangeEnd:2048,responseType:"arraybuffer"});return}g.levelDetails=L,this._handlePlaylistLoaded(n,d,g,v)},e.prototype._handleSidxRequest=function(n,d){var g=p.default.parseSegmentIndex(new Uint8Array(n.data));if(!!g){var v=g.references,s=d.levelDetails;v.forEach(function(l,x){var h=l.info,E=s.fragments[x];E.byteRange.length===0&&(E.rawByteRange=String(1+h.end-h.start)+"@"+String(h.start))}),s.initSegment.rawByteRange=String(g.moovEndOffset)+"@0"}},e.prototype._handleManifestParsingError=function(n,d,g,v){this.hls.trigger(m.default.ERROR,{type:f.ErrorTypes.NETWORK_ERROR,details:f.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:n.url,reason:g,networkDetails:v})},e.prototype._handleNetworkError=function(n,d,g,v){g===void 0&&(g=!1),v===void 0&&(v=null),u.logger.info("A network error occured while loading a "+n.type+"-type playlist");var s,l,x=this.getInternalLoader(n);switch(n.type){case o.MANIFEST:s=g?f.ErrorDetails.MANIFEST_LOAD_TIMEOUT:f.ErrorDetails.MANIFEST_LOAD_ERROR,l=!0;break;case o.LEVEL:s=g?f.ErrorDetails.LEVEL_LOAD_TIMEOUT:f.ErrorDetails.LEVEL_LOAD_ERROR,l=!1;break;case o.AUDIO_TRACK:s=g?f.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:f.ErrorDetails.AUDIO_TRACK_LOAD_ERROR,l=!1;break;default:l=!1}x&&(x.abort(),this.resetInternalLoader(n.type));var h={type:f.ErrorTypes.NETWORK_ERROR,details:s,fatal:l,url:x.url,loader:x,context:n,networkDetails:d};v&&(h.response=v),this.hls.trigger(m.default.ERROR,h)},e.prototype._handlePlaylistLoaded=function(n,d,g,v){var s=g.type,l=g.level,x=g.id,h=g.levelDetails;if(!h.targetduration){this._handleManifestParsingError(n,g,"invalid target duration",v);return}var E=e.canHaveQualityLevels(g.type);if(E)this.hls.trigger(m.default.LEVEL_LOADED,{details:h,level:l||0,id:x||0,stats:d,networkDetails:v});else switch(s){case o.AUDIO_TRACK:this.hls.trigger(m.default.AUDIO_TRACK_LOADED,{details:h,id:x,stats:d,networkDetails:v});break;case o.SUBTITLE_TRACK:this.hls.trigger(m.default.SUBTITLE_TRACK_LOADED,{details:h,id:x,stats:d,networkDetails:v});break}},e}(y.default);R.default=i}).call(this,T("./src/polyfills/number.js").Number)},"./src/observer.js":function(w,R,T){"use strict";var _=this&&this.__extends||function(){var y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(f,u){f.__proto__=u}||function(f,u){for(var p in u)u.hasOwnProperty(p)&&(f[p]=u[p])};return function(f,u){y(f,u);function p(){this.constructor=f}f.prototype=u===null?Object.create(u):(p.prototype=u.prototype,new p)}}();Object.defineProperty(R,"__esModule",{value:!0});var A=T("./node_modules/eventemitter3/index.js"),m=function(y){_(f,y);function f(){return y!==null&&y.apply(this,arguments)||this}return f.prototype.trigger=function(u){for(var p=[],c=1;c>24&255,a[1]=u>>16&255,a[2]=u>>8&255,a[3]=u&255,a.set(y,4),p=0,u=8;p>24&255,y>>16&255,y>>8&255,y&255,u>>24,u>>16&255,u>>8&255,u&255,p>>24,p>>16&255,p>>8&255,p&255,85,196,0,0]))},m.mdia=function(y){return m.box(m.types.mdia,m.mdhd(y.timescale,y.duration),m.hdlr(y.type),m.minf(y))},m.mfhd=function(y){return m.box(m.types.mfhd,new Uint8Array([0,0,0,0,y>>24,y>>16&255,y>>8&255,y&255]))},m.minf=function(y){return y.type==="audio"?m.box(m.types.minf,m.box(m.types.smhd,m.SMHD),m.DINF,m.stbl(y)):m.box(m.types.minf,m.box(m.types.vmhd,m.VMHD),m.DINF,m.stbl(y))},m.moof=function(y,f,u){return m.box(m.types.moof,m.mfhd(y),m.traf(u,f))},m.moov=function(y){for(var f=y.length,u=[];f--;)u[f]=m.trak(y[f]);return m.box.apply(null,[m.types.moov,m.mvhd(y[0].timescale,y[0].duration)].concat(u).concat(m.mvex(y)))},m.mvex=function(y){for(var f=y.length,u=[];f--;)u[f]=m.trex(y[f]);return m.box.apply(null,[m.types.mvex].concat(u))},m.mvhd=function(y,f){f*=y;var u=Math.floor(f/(_+1)),p=Math.floor(f%(_+1)),c=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,y>>24&255,y>>16&255,y>>8&255,y&255,u>>24,u>>16&255,u>>8&255,u&255,p>>24,p>>16&255,p>>8&255,p&255,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 m.box(m.types.mvhd,c)},m.sdtp=function(y){var f=y.samples||[],u=new Uint8Array(4+f.length),p,c;for(c=0;c>>8&255),f.push(a&255),f=f.concat(Array.prototype.slice.call(c));for(p=0;p>>8&255),u.push(a&255),u=u.concat(Array.prototype.slice.call(c));var o=m.box(m.types.avcC,new Uint8Array([1,f[3],f[4],f[5],252|3,224|y.sps.length].concat(f).concat([y.pps.length]).concat(u))),r=y.width,i=y.height,t=y.pixelRatio[0],e=y.pixelRatio[1];return m.box(m.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,r>>8&255,r&255,i>>8&255,i&255,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,m.box(m.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),m.box(m.types.pasp,new Uint8Array([t>>24,t>>16&255,t>>8&255,t&255,e>>24,e>>16&255,e>>8&255,e&255])))},m.esds=function(y){var f=y.config.length;return new Uint8Array([0,0,0,0,3,23+f,0,1,0,4,15+f,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([f]).concat(y.config).concat([6,1,2]))},m.mp4a=function(y){var f=y.samplerate;return m.box(m.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,y.channelCount,0,16,0,0,0,0,f>>8&255,f&255,0,0]),m.box(m.types.esds,m.esds(y)))},m.mp3=function(y){var f=y.samplerate;return m.box(m.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,y.channelCount,0,16,0,0,0,0,f>>8&255,f&255,0,0]))},m.stsd=function(y){return y.type==="audio"?!y.isAAC&&y.codec==="mp3"?m.box(m.types.stsd,m.STSD,m.mp3(y)):m.box(m.types.stsd,m.STSD,m.mp4a(y)):m.box(m.types.stsd,m.STSD,m.avc1(y))},m.tkhd=function(y){var f=y.id,u=y.duration*y.timescale,p=y.width,c=y.height,a=Math.floor(u/(_+1)),o=Math.floor(u%(_+1));return m.box(m.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,f>>24&255,f>>16&255,f>>8&255,f&255,0,0,0,0,a>>24,a>>16&255,a>>8&255,a&255,o>>24,o>>16&255,o>>8&255,o&255,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,p>>8&255,p&255,0,0,c>>8&255,c&255,0,0]))},m.traf=function(y,f){var u=m.sdtp(y),p=y.id,c=Math.floor(f/(_+1)),a=Math.floor(f%(_+1));return m.box(m.types.traf,m.box(m.types.tfhd,new Uint8Array([0,0,0,0,p>>24,p>>16&255,p>>8&255,p&255])),m.box(m.types.tfdt,new Uint8Array([1,0,0,0,c>>24,c>>16&255,c>>8&255,c&255,a>>24,a>>16&255,a>>8&255,a&255])),m.trun(y,u.length+16+20+8+16+8+8),u)},m.trak=function(y){return y.duration=y.duration||4294967295,m.box(m.types.trak,m.tkhd(y),m.mdia(y))},m.trex=function(y){var f=y.id;return m.box(m.types.trex,new Uint8Array([0,0,0,0,f>>24,f>>16&255,f>>8&255,f&255,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},m.trun=function(y,f){var u=y.samples||[],p=u.length,c=12+16*p,a=new Uint8Array(c),o,r,i,t,e,n;for(f+=8+c,a.set([0,0,15,1,p>>>24&255,p>>>16&255,p>>>8&255,p&255,f>>>24&255,f>>>16&255,f>>>8&255,f&255],0),o=0;o>>24&255,i>>>16&255,i>>>8&255,i&255,t>>>24&255,t>>>16&255,t>>>8&255,t&255,e.isLeading<<2|e.dependsOn,e.isDependedOn<<6|e.hasRedundancy<<4|e.paddingValue<<1|e.isNonSync,e.degradPrio&240<<8,e.degradPrio&15,n>>>24&255,n>>>16&255,n>>>8&255,n&255],12+16*o);return m.box(m.types.trun,a)},m.initSegment=function(y){m.types||m.init();var f=m.moov(y),u;return u=new Uint8Array(m.FTYP.byteLength+f.byteLength),u.set(m.FTYP),u.set(f,m.FTYP.byteLength),u},m}();R.default=A},"./src/remux/mp4-remuxer.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/remux/aac-helper.js"),A=T("./src/remux/mp4-generator.js"),m=T("./src/events.js"),y=T("./src/errors.js"),f=T("./src/utils/logger.js"),u=10*1e3,p=function(){function c(a,o,r,i){this.observer=a,this.config=o,this.typeSupported=r;var t=navigator.userAgent;this.isSafari=i&&i.indexOf("Apple")>-1&&t&&!t.match("CriOS"),this.ISGenerated=!1}return c.prototype.destroy=function(){},c.prototype.resetTimeStamp=function(a){this._initPTS=this._initDTS=a},c.prototype.resetInitSegment=function(){this.ISGenerated=!1},c.prototype.remux=function(a,o,r,i,t,e,n){if(this.ISGenerated||this.generateIS(a,o,t),this.ISGenerated){var d=a.samples.length,g=o.samples.length,v=t,s=t;if(d&&g){var l=(a.samples[0].pts-o.samples[0].pts)/o.inputTimeScale;v+=Math.max(0,l),s+=Math.max(0,-l)}if(d){a.timescale||(f.logger.warn("regenerate InitSegment as audio detected"),this.generateIS(a,o,t));var x=this.remuxAudio(a,v,e,n);if(g){var h=void 0;x&&(h=x.endPTS-x.startPTS),o.timescale||(f.logger.warn("regenerate InitSegment as video detected"),this.generateIS(a,o,t)),this.remuxVideo(o,s,e,h,n)}}else if(g){var E=this.remuxVideo(o,s,e,0,n);E&&a.codec&&this.remuxEmptyAudio(a,v,e,E)}}r.samples.length&&this.remuxID3(r,t),i.samples.length&&this.remuxText(i,t),this.observer.trigger(m.default.FRAG_PARSED)},c.prototype.generateIS=function(a,o,r){var i=this.observer,t=a.samples,e=o.samples,n=this.typeSupported,d="audio/mp4",g={},v={tracks:g},s=this._initPTS===void 0,l,x;if(s&&(l=x=Infinity),a.config&&t.length&&(a.timescale=a.samplerate,f.logger.log("audio sampling rate : "+a.samplerate),a.isAAC||(n.mpeg?(d="audio/mpeg",a.codec=""):n.mp3&&(a.codec="mp3")),g.audio={container:d,codec:a.codec,initSegment:!a.isAAC&&n.mpeg?new Uint8Array:A.default.initSegment([a]),metadata:{channelCount:a.channelCount}},s&&(l=x=t[0].pts-a.inputTimeScale*r)),o.sps&&o.pps&&e.length){var h=o.inputTimeScale;o.timescale=h,g.video={container:"video/mp4",codec:o.codec,initSegment:A.default.initSegment([o]),metadata:{width:o.width,height:o.height}},s&&(l=Math.min(l,e[0].pts-h*r),x=Math.min(x,e[0].dts-h*r),this.observer.trigger(m.default.INIT_PTS_FOUND,{initPTS:l}))}Object.keys(g).length?(i.trigger(m.default.FRAG_PARSING_INIT_SEGMENT,v),this.ISGenerated=!0,s&&(this._initPTS=l,this._initDTS=x)):i.trigger(m.default.ERROR,{type:y.ErrorTypes.MEDIA_ERROR,details:y.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"})},c.prototype.remuxVideo=function(a,o,r,i,t){var e=8,n,d,g,v,s,l,x,h=a.timescale,E=a.samples,S=[],b=E.length,I=this._PTSNormalize,L=this._initPTS,D=this.nextAvcDts,O=this.isSafari;if(b!==0){O&&(r|=E.length&&D&&(t&&Math.abs(o-D/h)<.1||Math.abs(E[0].pts-D-L)1?f.logger.log("AVC:"+k+" ms hole between fragments detected,filling it"):k<-1&&f.logger.log("AVC:"+-k+" ms overlapping between fragments detected"),s=D,E[0].dts=s,v=Math.max(v-k,D),E[0].pts=v,f.logger.log("Video/PTS/DTS adjusted: "+Math.round(v/90)+"/"+Math.round(s/90)+",delta:"+k+" ms")),P=E[E.length-1],x=Math.max(P.dts,0),l=Math.max(P.pts,0,x),O&&(n=Math.round((x-s)/(E.length-1)));for(var B=0,M=0,C=0;C0?C-1:C].dts;if($.stretchShortVideoTrack){var ie=$.maxBufferHole,q=Math.floor(ie*h),Q=(i?v+i*h:this.nextAudioPts)-H.pts;Q>q?(n=Q-Z,n<0&&(n=Z),f.logger.log("It is approximately "+Q/90+" ms to the next segment; using duration "+n/90+" ms for the last video frame.")):n=Z}else n=Z}X=Math.round(H.pts-H.dts)}S.push({size:z,duration:n,cts:X,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:H.key?2:1,isNonSync:H.key?0:1}})}this.nextAvcDts=x+n;var oe=a.dropped;if(a.len=0,a.nbNalu=0,a.dropped=0,S.length&&navigator.userAgent.toLowerCase().indexOf("chrome")>-1){var ae=S[0].flags;ae.dependsOn=2,ae.isNonSync=0}a.samples=S,g=A.default.moof(a.sequenceNumber++,s,a),a.samples=[];var se={data1:g,data2:d,startPTS:v/h,endPTS:(l+n)/h,startDTS:s/h,endDTS:this.nextAvcDts/h,type:"video",hasAudio:!1,hasVideo:!0,nb:S.length,dropped:oe};return this.observer.trigger(m.default.FRAG_PARSING_DATA,se),se}},c.prototype.remuxAudio=function(a,o,r,i){var t=a.inputTimeScale,e=a.timescale,n=t/e,d=a.isAAC?1024:1152,g=d*n,v=this._PTSNormalize,s=this._initPTS,l=!a.isAAC&&this.typeSupported.mpeg,x,h,E,S,b,I,L,D=a.samples,O=[],F=this.nextAudioPts;if(r|=D.length&&F&&(i&&Math.abs(o-F/t)<.1||Math.abs(D[0].pts-F-s)<20*g),D.forEach(function(Q){Q.pts=Q.dts=v(Q.pts-s,o*t)}),D=D.filter(function(Q){return Q.pts>=0}),D.length!==0){if(r||(i?F=o*t:F=D[0].pts),a.isAAC)for(var C=this.config.maxAudioFramesDrift,P=0,k=F;P=C*g&&j.1*g,B.pts=B.dts=k,k+=g,P++}for(var G=0,U=D.length;G0&&Y0&&(E=_.default.getSilentFrame(a.manifestCodec||a.codec,a.channelCount),E||(E=H.subarray()),a.len+=z*E.length);else if(Y<-12){f.logger.log("drop overlapping AAC sample, expected/parsed/delta:"+(F/t).toFixed(3)+"s/"+(N/t).toFixed(3)+"s/"+-Y+"ms"),a.len-=H.byteLength;continue}N=F}if(I=N,a.len>0){var X=l?a.len:a.len+8;x=l?0:8;try{S=new Uint8Array(X)}catch(ae){this.observer.trigger(m.default.ERROR,{type:y.ErrorTypes.MUX_ERROR,details:y.ErrorDetails.REMUX_ALLOC_ERROR,fatal:!1,bytes:X,reason:"fail allocating audio mdat "+X});return}if(!l){var ee=new DataView(S.buffer);ee.setUint32(0,X),S.set(A.default.types.mdat,4)}}else return;for(var P=0;P=2&&(re=O[$-2].duration,h.duration=re),$){this.nextAudioPts=F=L+n*re,a.len=0,a.samples=O,l?b=new Uint8Array:b=A.default.moof(a.sequenceNumber++,I/n,a),a.samples=[];var Z=I/t,ie=F/t,q={data1:b,data2:S,startPTS:Z,endPTS:ie,startDTS:Z,endDTS:ie,type:"audio",hasAudio:!0,hasVideo:!1,nb:$};return this.observer.trigger(m.default.FRAG_PARSING_DATA,q),q}return null}},c.prototype.remuxEmptyAudio=function(a,o,r,i){var t=a.inputTimeScale,e=a.samplerate?a.samplerate:t,n=t/e,d=this.nextAudioPts,g=(d!==void 0?d:i.startDTS*t)+this._initDTS,v=i.endDTS*t+this._initDTS,s=1024,l=n*s,x=Math.ceil((v-g)/l),h=_.default.getSilentFrame(a.manifestCodec||a.codec,a.channelCount);if(f.logger.warn("remux empty Audio"),!h){f.logger.trace("Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec!");return}for(var E=[],S=0;S4294967296;)a+=r;return a},c}();R.default=p},"./src/remux/passthrough-remuxer.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/events.js"),A=function(){function m(y){this.observer=y}return m.prototype.destroy=function(){},m.prototype.resetTimeStamp=function(){},m.prototype.resetInitSegment=function(){},m.prototype.remux=function(y,f,u,p,c,a,o,r){var i=this.observer,t="";y&&(t+="audio"),f&&(t+="video"),i.trigger(_.default.FRAG_PARSING_DATA,{data1:r,startPTS:c,startDTS:c,type:t,hasAudio:!!y,hasVideo:!!f,nb:1,dropped:0}),i.trigger(_.default.FRAG_PARSED)},m}();R.default=A},"./src/task-loop.js":function(w,R,T){"use strict";var _=this&&this.__extends||function(){var y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(f,u){f.__proto__=u}||function(f,u){for(var p in u)u.hasOwnProperty(p)&&(f[p]=u[p])};return function(f,u){y(f,u);function p(){this.constructor=f}f.prototype=u===null?Object.create(u):(p.prototype=u.prototype,new p)}}();Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/event-handler.js"),m=function(y){_(f,y);function f(u){for(var p=[],c=1;c1&&(this.clearNextTick(),this._tickTimer=setTimeout(this._boundTick,0)),this._tickCallCount=0)},f.prototype.doTick=function(){},f}(A.default);R.default=m},"./src/utils/attr-list.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=/^(\d+)x(\d+)$/,m=/\s*(.+?)\s*=((?:\".*?\")|.*?)(?:,|$)/g,y=function(){function f(u){typeof u=="string"&&(u=f.parseAttrList(u));for(var p in u)u.hasOwnProperty(p)&&(this[p]=u[p])}return f.prototype.decimalInteger=function(u){var p=parseInt(this[u],10);return p>_.MAX_SAFE_INTEGER?Infinity:p},f.prototype.hexadecimalInteger=function(u){if(this[u]){var p=(this[u]||"0x").slice(2);p=(p.length&1?"0":"")+p;for(var c=new Uint8Array(p.length/2),a=0;a_.MAX_SAFE_INTEGER?Infinity:p},f.prototype.decimalFloatingPoint=function(u){return parseFloat(this[u])},f.prototype.enumeratedString=function(u){return this[u]},f.prototype.decimalResolution=function(u){var p=A.exec(this[u]);if(p!==null)return{width:parseInt(p[1],10),height:parseInt(p[2],10)}},f.parseAttrList=function(u){var p,c={};for(m.lastIndex=0;(p=m.exec(u))!==null;){var a=p[2],o='"';a.indexOf(o)===0&&a.lastIndexOf(o)===a.length-1&&(a=a.slice(1,-1)),c[p[1]]=a}return c},f}();R.default=y}).call(this,T("./src/polyfills/number.js").Number)},"./src/utils/binary-search.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _={search:function(A,m){for(var y=0,f=A.length-1,u=null,p=null;y<=f;){u=(y+f)/2|0,p=A[u];var c=m(p);if(c>0)y=u+1;else if(c<0)f=u-1;else return p}return null}};R.default=_},"./src/utils/buffer-helper.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=function(){function A(){}return A.isBuffered=function(m,y){try{if(m){for(var f=m.buffered,u=0;u=f.start(u)&&y<=f.end(u))return!0}}catch(p){}return!1},A.bufferInfo=function(m,y,f){try{if(m){var u=m.buffered,p=[],c=void 0;for(c=0;ct&&(u[i-1].end=m[r].end):u.push(m[r])}else u.push(m[r])}for(r=0,p=0,c=a=y;r=e&&y=l}},r=function(v){for(var s=[],l=0;ly&&(o.log("ERROR","Too large cursor position "+this.pos),this.pos=y)},v.prototype.moveCursor=function(s){var l=this.pos+s;if(s>1)for(var x=this.pos+1;x=144&&this.backSpace();var l=A(s);if(this.pos>=y){o.log("ERROR","Cannot insert "+s.toString(16)+" ("+l+") at position "+this.pos+". Skipping it!");return}this.chars[this.pos].setChar(l,this.currPenState),this.moveCursor(1)},v.prototype.clearFromPos=function(s){var l;for(l=s;l0&&(s?x="["+l.join(" | ")+"]":x=l.join(` `)),x},v.prototype.getTextAndFormat=function(){return this.rows},v}(),d=function(){function v(s,l){this.chNr=s,this.outputFilter=l,this.mode=null,this.verbose=0,this.displayedMemory=new n,this.nonDisplayedMemory=new n,this.lastOutputScreen=new n,this.currRollUpRow=this.displayedMemory.rows[m-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null}return v.prototype.reset=function(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.currRollUpRow=this.displayedMemory.rows[m-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.lastCueEndTime=null},v.prototype.getHandler=function(){return this.outputFilter},v.prototype.setHandler=function(s){this.outputFilter=s},v.prototype.setPAC=function(s){this.writeScreen.setPAC(s)},v.prototype.setBkgData=function(s){this.writeScreen.setBkgData(s)},v.prototype.setMode=function(s){s!==this.mode&&(this.mode=s,o.log("INFO","MODE="+s),this.mode==="MODE_POP-ON"?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),this.mode!=="MODE_ROLL-UP"&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=s)},v.prototype.insertChars=function(s){for(var l=0;l=46,l.italics)l.foreground="white";else{var x=Math.floor(s/2)-16,h=["white","green","blue","cyan","red","yellow","magenta"];l.foreground=h[x]}o.log("INFO","MIDROW: "+JSON.stringify(l)),this.writeScreen.setPen(l)},v.prototype.outputDataUpdate=function(s){s===void 0&&(s=!1);var l=o.time;l!==null&&this.outputFilter&&(this.cueStartTime===null&&!this.displayedMemory.isEmpty()?this.cueStartTime=l:this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue&&(this.outputFilter.newCue(this.cueStartTime,l,this.lastOutputScreen),s===!0&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue()),this.cueStartTime=this.displayedMemory.isEmpty()?null:l),this.lastOutputScreen.copy(this.displayedMemory))},v.prototype.cueSplitAtTime=function(s){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,s,this.displayedMemory),this.cueStartTime=s))},v}(),g=function(){function v(s,l,x){this.field=s||1,this.outputs=[l,x],this.channels=[new d(1,l),new d(2,x)],this.currChNr=-1,this.lastCmdA=null,this.lastCmdB=null,this.bufferedData=[],this.startTime=null,this.lastTime=null,this.dataCounters={padding:0,char:0,cmd:0,other:0}}return v.prototype.getHandler=function(s){return this.channels[s].getHandler()},v.prototype.setHandler=function(s,l){this.channels[s].setHandler(l)},v.prototype.addData=function(s,l){var x,h,E,S=!1;this.lastTime=s,o.setTime(s);for(var b=0;b ("+r([h,E])+")");if(x=this.parseCmd(h,E),x||(x=this.parseMidrow(h,E)),x||(x=this.parsePAC(h,E)),x||(x=this.parseBackgroundAttributes(h,E)),!x&&(S=this.parseChars(h,E),S))if(this.currChNr&&this.currChNr>=0){var I=this.channels[this.currChNr-1];I.insertChars(S)}else o.log("WARNING","No channel found yet. TEXT-MODE?");x?this.dataCounters.cmd+=2:S?this.dataCounters.char+=2:(this.dataCounters.other+=2,o.log("WARNING","Couldn't parse cleaned data "+r([h,E])+" orig: "+r([l[b],l[b+1]])))}},v.prototype.parseCmd=function(s,l){var x=null,h=(s===20||s===28)&&l>=32&&l<=47,E=(s===23||s===31)&&l>=33&&l<=35;if(!(h||E))return!1;if(s===this.lastCmdA&&l===this.lastCmdB)return this.lastCmdA=null,this.lastCmdB=null,o.log("DEBUG","Repeated command ("+r([s,l])+") is dropped"),!0;s===20||s===23?x=1:x=2;var S=this.channels[x-1];return s===20||s===28?l===32?S.ccRCL():l===33?S.ccBS():l===34?S.ccAOF():l===35?S.ccAON():l===36?S.ccDER():l===37?S.ccRU(2):l===38?S.ccRU(3):l===39?S.ccRU(4):l===40?S.ccFON():l===41?S.ccRDC():l===42?S.ccTR():l===43?S.ccRTD():l===44?S.ccEDM():l===45?S.ccCR():l===46?S.ccENM():l===47&&S.ccEOC():S.ccTO(l-32),this.lastCmdA=s,this.lastCmdB=l,this.currChNr=x,!0},v.prototype.parseMidrow=function(s,l){var x=null;if((s===17||s===25)&&l>=32&&l<=47){if(s===17?x=1:x=2,x!==this.currChNr)return o.log("ERROR","Mismatch channel in midrow parsing"),!1;var h=this.channels[x-1];return h.ccMIDROW(l),o.log("DEBUG","MIDROW ("+r([s,l])+")"),!0}return!1},v.prototype.parsePAC=function(s,l){var x=null,h=null,E=(s>=17&&s<=23||s>=25&&s<=31)&&l>=64&&l<=127,S=(s===16||s===24)&&l>=64&&l<=95;if(!(E||S))return!1;if(s===this.lastCmdA&&l===this.lastCmdB)return this.lastCmdA=null,this.lastCmdB=null,!0;x=s<=23?1:2,l>=64&&l<=95?h=x===1?f[s]:p[s]:h=x===1?u[s]:c[s];var b=this.interpretPAC(h,l),I=this.channels[x-1];return I.setPAC(b),this.lastCmdA=s,this.lastCmdB=l,this.currChNr=x,!0},v.prototype.interpretPAC=function(s,l){var x=l,h={color:null,italics:!1,indent:null,underline:!1,row:s};return l>95?x=l-96:x=l-64,h.underline=(x&1)==1,x<=13?h.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(x/2)]:x<=15?(h.italics=!0,h.color="white"):h.indent=Math.floor((x-16)/2)*4,h},v.prototype.parseChars=function(s,l){var x=null,h=null,E=null;if(s>=25?(x=2,E=s-8):(x=1,E=s),E>=17&&E<=19){var S=l;E===17?S=l+80:E===18?S=l+112:S=l+144,o.log("INFO","Special char '"+A(S)+"' in channel "+x),h=[S]}else s>=32&&s<=127&&(h=l===0?[s]:[s,l]);if(h){var b=r(h);o.log("DEBUG","Char codes = "+b.join(",")),this.lastCmdA=null,this.lastCmdB=null}return h},v.prototype.parseBackgroundAttributes=function(s,l){var x,h,E,S,b=(s===16||s===24)&&l>=32&&l<=47,I=(s===23||s===31)&&l>=45&&l<=47;return b||I?(x={},s===16||s===24?(h=Math.floor((l-32)/2),x.background=a[h],l%2==1&&(x.background=x.background+"_semi")):l===45?x.background="transparent":(x.foreground="black",l===47&&(x.underline=!0)),E=s<24?1:2,S=this.channels[E-1],S.setBkgData(x),this.lastCmdA=null,this.lastCmdB=null,!0):!1},v.prototype.reset=function(){for(var s=0;s=16?o--:o++,navigator.userAgent.match(/Firefox\//)?c.line=t+1:c.line=t>7?t-2:t+1,c.align="left",c.position=Math.max(0,Math.min(100,100*(o/32)+(navigator.userAgent.match(/Firefox\//)?50:0))),m.addCue(c)}}R.newCue=A},"./src/utils/discontinuities.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/utils/binary-search.js"),m=T("./src/utils/logger.js");function y(i,t){for(var e=null,n=0;nt?-1:0})}R.findFragWithCC=f;function u(i,t,e){var n=!1;return t&&t.details&&e&&(e.endCC>e.startCC||i&&i.cc=this.minWeight_},m.prototype.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},m.prototype.destroy=function(){},m}();R.default=A},"./src/utils/ewma.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=function(){function A(m){this.alpha_=m?Math.exp(Math.log(.5)/m):0,this.estimate_=0,this.totalWeight_=0}return A.prototype.sample=function(m,y){var f=Math.pow(this.alpha_,m);this.estimate_=y*(1-f)+f*this.estimate_,this.totalWeight_+=m},A.prototype.getTotalWeight=function(){return this.totalWeight_},A.prototype.getEstimate=function(){if(this.alpha_){var m=1-Math.pow(this.alpha_,this.totalWeight_);return this.estimate_/m}else return this.estimate_},A}();R.default=_},"./src/utils/get-self-scope.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});function _(){return typeof window=="undefined"?self:window}R.getSelfScope=_},"./src/utils/logger.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/utils/get-self-scope.js");function A(){}var m={trace:A,debug:A,log:A,warn:A,info:A,error:A},y=m;function f(a,o){return o="["+a+"] > "+o,o}var u=_.getSelfScope();function p(a){var o=u.console[a];return o?function(){for(var r=[],i=0;im)&&(this.startTime=m),this.endTime=y,this.screen=f,this.timelineController.createCaptionsTrack(this.trackName)},A}();R.default=_},"./src/utils/texttrack-utils.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});function _(m,y){var f=null;try{f=new window.Event("addtrack")}catch(u){f=document.createEvent("Event"),f.initEvent("addtrack",!1,!1)}f.track=m,y.dispatchEvent(f)}R.sendAddTrackEvent=_;function A(m){if(m&&m.cues)for(;m.cues.length>0;)m.removeCue(m.cues[0])}R.clearCurrentCues=A},"./src/utils/time-ranges.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _={toString:function(A){for(var m="",y=A.length,f=0;f100)throw new Error("Position must be between 0 and 100.");S=D,this.hasBeenReset=!0}})),Object.defineProperty(r,"positionAlign",u({},t,{get:function(){return b},set:function(D){var O=f(D);if(!O)throw new SyntaxError("An invalid or illegal string was specified.");b=O,this.hasBeenReset=!0}})),Object.defineProperty(r,"size",u({},t,{get:function(){return I},set:function(D){if(D<0||D>100)throw new Error("Size must be between 0 and 100.");I=D,this.hasBeenReset=!0}})),Object.defineProperty(r,"align",u({},t,{get:function(){return L},set:function(D){var O=f(D);if(!O)throw new SyntaxError("An invalid or illegal string was specified.");L=O,this.hasBeenReset=!0}})),r.displayState=void 0,i)return r}return p.prototype.getCueAsHTML=function(){var c=window.WebVTT;return c.convertCueToDOMTree(window,this.text)},p}()},"./src/utils/vttparser.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/utils/vttcue.js"),A=function(){return{decode:function(i){if(!i)return"";if(typeof i!="string")throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(i))}}};function m(){this.window=window,this.state="INITIAL",this.buffer="",this.decoder=new A,this.regionList=[]}function y(r){function i(e,n,d,g){return(e|0)*3600+(n|0)*60+(d|0)+(g|0)/1e3}var t=r.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);return t?t[3]?i(t[1],t[2],t[3].replace(":",""),t[4]):t[1]>59?i(t[1],t[2],0,t[4]):i(0,t[1],t[2],t[4]):null}function f(){this.values=Object.create(null)}f.prototype={set:function(r,i){!this.get(r)&&i!==""&&(this.values[r]=i)},get:function(r,i,t){return t?this.has(r)?this.values[r]:i[t]:this.has(r)?this.values[r]:i},has:function(r){return r in this.values},alt:function(r,i,t){for(var e=0;e=0&&i<=100)?(this.set(r,i),!0):!1}};function u(r,i,t,e){var n=e?r.split(e):[r];for(var d in n)if(typeof n[d]=="string"){var g=n[d].split(t);if(g.length===2){var v=g[0],s=g[1];i(v,s)}}}var p=new _.default(0,0,0),c=p.align==="middle"?"middle":"center";function a(r,i,t){var e=r;function n(){var v=y(r);if(v===null)throw new Error("Malformed timestamp: "+e);return r=r.replace(/^[^\sa-zA-Z-]+/,""),v}function d(v,s){var l=new f;u(v,function(E,S){switch(E){case"region":for(var b=t.length-1;b>=0;b--)if(t[b].id===S){l.set(E,t[b].region);break}break;case"vertical":l.alt(E,S,["rl","lr"]);break;case"line":var I=S.split(","),L=I[0];l.integer(E,L),l.percent(E,L)&&l.set("snapToLines",!1),l.alt(E,L,["auto"]),I.length===2&&l.alt("lineAlign",I[1],["start",c,"end"]);break;case"position":I=S.split(","),l.percent(E,I[0]),I.length===2&&l.alt("positionAlign",I[1],["start",c,"end","line-left","line-right","auto"]);break;case"size":l.percent(E,S);break;case"align":l.alt(E,S,["start",c,"end","left","right"]);break}},/:/,/\s/),s.region=l.get("region",null),s.vertical=l.get("vertical","");var x=l.get("line","auto");x==="auto"&&p.line===-1&&(x=-1),s.line=x,s.lineAlign=l.get("lineAlign","start"),s.snapToLines=l.get("snapToLines",!0),s.size=l.get("size",100),s.align=l.get("align",c);var h=l.get("position","auto");h==="auto"&&p.position===50&&(h=s.align==="start"||s.align==="left"?0:s.align==="end"||s.align==="right"?100:50),s.position=h}function g(){r=r.replace(/^\s+/,"")}if(g(),i.startTime=n(),g(),r.substr(0,3)!=="-->")throw new Error("Malformed time stamp (time stamps must be separated by '-->'): "+e);r=r.substr(3),g(),i.endTime=n(),g(),d(r,i)}function o(r){return r.replace(//gi,` `)}R.fixLineBreaks=o,m.prototype={parse:function(r){var i=this;r&&(i.buffer+=i.decoder.decode(r,{stream:!0}));function t(){var s=i.buffer,l=0;for(s=o(s);l")===-1){i.cue.id=n;continue}case"CUE":try{a(n,i.cue,i.regionList)}catch(s){i.cue=null,i.state="BADCUE";continue}i.state="CUETEXT";continue;case"CUETEXT":var v=n.indexOf("-->")!==-1;if(!n||v&&(g=!0)){i.oncue&&i.oncue(i.cue),i.cue=null,i.state="ID";continue}i.cue.text&&(i.cue.text+=` `),i.cue.text+=n;continue;case"BADCUE":n||(i.state="ID");continue}}}catch(s){i.state==="CUETEXT"&&i.cue&&i.oncue&&i.oncue(i.cue),i.cue=null,i.state=i.state==="INITIAL"?"BADWEBVTT":"BADCUE"}return this},flush:function(){var r=this;try{if(r.buffer+=r.decoder.decode(),(r.cue||r.state==="HEADER")&&(r.buffer+=` `,r.parse()),r.state==="INITIAL")throw new Error("Malformed WebVTT signature.")}catch(i){throw i}return r.onflush&&r.onflush(),this}},R.default=m},"./src/utils/webvtt-parser.js":function(w,R,T){"use strict";(function(_){Object.defineProperty(R,"__esModule",{value:!0});var A=T("./src/utils/vttparser.js"),m=T("./src/demux/id3.js"),y=function(a,o,r){return a.substr(r||0,o.length)===o},f=function(a){var o=parseInt(a.substr(-3)),r=parseInt(a.substr(-6,2)),i=parseInt(a.substr(-9,2)),t=a.length>9?parseInt(a.substr(0,a.indexOf(":"))):0;return!_.isFinite(o)||!_.isFinite(r)||!_.isFinite(i)||!_.isFinite(t)?-1:(o+=1e3*r,o+=60*1e3*i,o+=60*60*1e3*t,o)},u=function(a){for(var o=5381,r=a.length;r;)o=o*33^a.charCodeAt(--r);return(o>>>0).toString()},p=function(a,o,r){var i=a[o],t=a[i.prevCC];if(!t||!t.new&&i.new){a.ccOffset=a.presentationOffset=i.start,i.new=!1;return}for(;t&&t.new;)a.ccOffset+=i.start-t.start,i.new=!1,i=t,t=a[i.prevCC];a.presentationOffset=r},c={parse:function(a,o,r,i,t,e){var n=/\r\n|\n\r|\n|\r/g,d=m.utf8ArrayToStr(new Uint8Array(a)).trim().replace(n,` `).split(` `),g="00:00.000",v=0,s=0,l=0,x=[],h,E=!0,S=new A.default;S.oncue=function(b){var I=r[i],L=r.ccOffset;I&&I.new&&(s!==void 0?L=r.ccOffset=I.start:p(r,i,l)),l&&(L=l-r.presentationOffset),b.startTime+=L-s,b.endTime+=L-s,b.id=u(b.startTime.toString())+u(b.endTime.toString())+u(b.text),b.text=decodeURIComponent(encodeURIComponent(b.text)),b.endTime>0&&x.push(b)},S.onparsingerror=function(b){h=b},S.onflush=function(){if(h&&e){e(h);return}t(x)},d.forEach(function(b){if(E)if(y(b,"X-TIMESTAMP-MAP=")){E=!1,b.substr(16).split(",").forEach(function(I){y(I,"LOCAL:")?g=I.substr(6):y(I,"MPEGTS:")&&(v=parseInt(I.substr(7)))});try{o+(r[i].start*9e4||0)<0&&(o+=8589934592),v-=o,s=f(g)/1e3,l=v/9e4,s===-1&&(h=new Error("Malformed X-TIMESTAMP-MAP: "+b))}catch(I){h=new Error("Malformed X-TIMESTAMP-MAP: "+b)}return}else b===""&&(E=!1);S.parse(b+` `)}),S.flush()}};R.default=c}).call(this,T("./src/polyfills/number.js").Number)},"./src/utils/xhr-loader.js":function(w,R,T){"use strict";Object.defineProperty(R,"__esModule",{value:!0});var _=T("./src/utils/logger.js"),A=window.performance,m=window.XMLHttpRequest,y=function(){function f(u){u&&u.xhrSetup&&(this.xhrSetup=u.xhrSetup)}return f.prototype.destroy=function(){this.abort(),this.loader=null},f.prototype.abort=function(){var u=this.loader;u&&u.readyState!==4&&(this.stats.aborted=!0,u.abort()),window.clearTimeout(this.requestTimeout),this.requestTimeout=null,window.clearTimeout(this.retryTimeout),this.retryTimeout=null},f.prototype.load=function(u,p,c){this.context=u,this.config=p,this.callbacks=c,this.stats={trequest:A.now(),retry:0},this.retryDelay=p.retryDelay,this.loadInternal()},f.prototype.loadInternal=function(){var u,p=this.context;u=this.loader=new m;var c=this.stats;c.tfirst=0,c.loaded=0;var a=this.xhrSetup;try{if(a)try{a(u,p.url)}catch(o){u.open("GET",p.url,!0),a(u,p.url)}u.readyState||u.open("GET",p.url,!0)}catch(o){this.callbacks.onError({code:u.status,text:o.message},p,u);return}p.rangeEnd&&u.setRequestHeader("Range","bytes="+p.rangeStart+"-"+(p.rangeEnd-1)),u.onreadystatechange=this.readystatechange.bind(this),u.onprogress=this.loadprogress.bind(this),u.responseType=p.responseType,this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),this.config.timeout),u.send()},f.prototype.readystatechange=function(u){var p=u.currentTarget,c=p.readyState,a=this.stats,o=this.context,r=this.config;if(!a.aborted&&c>=2)if(window.clearTimeout(this.requestTimeout),a.tfirst===0&&(a.tfirst=Math.max(A.now(),a.trequest)),c===4){var i=p.status;if(i>=200&&i<300){a.tload=Math.max(a.tfirst,A.now());var t=void 0,e=void 0;o.responseType==="arraybuffer"?(t=p.response,e=t.byteLength):(t=p.responseText,e=t.length),a.loaded=a.total=e;var n={url:p.responseURL,data:t};this.callbacks.onSuccess(n,a,o,p)}else a.retry>=r.maxRetry||i>=400&&i<499?(_.logger.error(i+" while loading "+o.url),this.callbacks.onError({code:i,text:p.statusText},o,p)):(_.logger.warn(i+" while loading "+o.url+", retrying in "+this.retryDelay+"..."),this.destroy(),this.retryTimeout=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,r.maxRetryDelay),a.retry++)}else this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),r.timeout)},f.prototype.loadtimeout=function(){_.logger.warn("timeout while loading "+this.context.url),this.callbacks.onTimeout(this.stats,this.context,null)},f.prototype.loadprogress=function(u){var p=u.currentTarget,c=this.stats;c.loaded=u.loaded,u.lengthComputable&&(c.total=u.total);var a=this.callbacks.onProgress;a&&a(c,this.context,null,p)},f}();R.default=y}}).default});