!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Hls=t()}}(function(){return function s(e,t,r){function i(a,d){if(!t[a]){if(!e[a]){var l="function"==typeof require&&require;if(!d&&l)return l(a,!0);if(n)return n(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var o=t[a]={exports:{}};e[a][0].call(o.exports,function(t){var r=e[a][1][t];return i(r?r:t)},o,o.exports,s,e,t,r)}return t[a].exports}for(var n="function"==typeof require&&require,a=0;ae||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},e.prototype.emit=function(u){var o,a,n,s,e,l;if(this._events||(this._events={}),"error"===u&&(!this._events.error||r(this._events.error)&&!this._events.error.length)){if(o=arguments[1],o instanceof Error)throw o;throw TypeError('Uncaught, unspecified "error" event.')}if(a=this._events[u],i(a))return!1;if(t(a))switch(arguments.length){case 1:a.call(this);break;case 2:a.call(this,arguments[1]);break;case 3:a.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,s=new Array(n-1),e=1;n>e;e++)s[e-1]=arguments[e];a.apply(this,s)}else if(r(a)){for(n=arguments.length,s=new Array(n-1),e=1;n>e;e++)s[e-1]=arguments[e];for(l=a.slice(),n=l.length,e=0;n>e;e++)l[e].apply(this,s)}return!0},e.prototype.addListener=function(a,n){var s;if(!t(n))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,t(n.listener)?n.listener:n),this._events[a]?r(this._events[a])?this._events[a].push(n):this._events[a]=[this._events[a],n]:this._events[a]=n,r(this._events[a])&&!this._events[a].warned){var s;s=i(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,s&&s>0&&this._events[a].length>s&&(this._events[a].warned=!0,"function"==typeof console.trace)}return this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(i,e){function r(){this.removeListener(i,r),a||(a=!0,e.apply(this,arguments))}if(!t(e))throw TypeError("listener must be a function");var a=!1;return r.listener=e,this.on(i,r),this},e.prototype.removeListener=function(a,i){var e,s,o,n;if(!t(i))throw TypeError("listener must be a function");if(!this._events||!this._events[a])return this;if(e=this._events[a],o=e.length,s=-1,e===i||t(e.listener)&&e.listener===i)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,i);else if(r(e)){for(n=o;n-->0;)if(e[n]===i||e[n].listener&&e[n].listener===i){s=n;break}if(0>s)return this;1===e.length?(e.length=0,delete this._events[a]):e.splice(s,1),this._events.removeListener&&this.emit("removeListener",a,i)}return this},e.prototype.removeAllListeners=function(e){var i,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(i in this._events)"removeListener"!==i&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],t(r))this.removeListener(e,r);else for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},e.prototype.listeners=function(e){var r;return r=this._events&&this._events[e]?t(this._events[e])?[this._events[e]]:this._events[e].slice():[]},e.listenerCount=function(e,r){var i;return i=e._events&&e._events[r]?t(e._events[r])?1:e._events[r].length:0}},{}],2:[function(n,i,s){var a=arguments[3],e=arguments[4],r=arguments[5],t=JSON.stringify;i.exports=function(u){for(var i,o=Object.keys(r),n=0,l=o.length;l>n;n++){var s=o[n];if(r[s].exports===u){i=s;break}}if(!i){i=Math.floor(Math.pow(16,8)*Math.random()).toString(16);for(var d={},n=0,l=o.length;l>n;n++){var s=o[n];d[s]=s}e[i]=[Function(["require","module","exports"],"("+u+")(self)"),d]}var h=Math.floor(Math.pow(16,8)*Math.random()).toString(16),f={};f[i]=i,e[h]=[Function(["require"],"require("+t(i)+")(self)"),f];var c="("+a+")({"+Object.keys(e).map(function(r){return t(r)+":["+e[r][0]+","+t(e[r][1])+"]"}).join(",")+"},{},["+t(h)+"])",g=window.URL||window.webkitURL||window.mozURL||window.msURL;return new Worker(g.createObjectURL(new Blob([c],{type:"text/javascript"})))}},{}],3:[function(r,i,e){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function e(i,r){for(var t=0;t=e;e++)if(r=e<=this.lastfetchlevel?.8*i:.7*i,r=0&&iP){if(o.nextLoadLevel=l,this.level=l,n=this.levels[l].details,"undefined"==typeof n){this.state=e.WAITING_LEVEL;break}var u=n.fragments,g=u.length,p=u[0].start,w=u[g-1].start+u[g-1].duration,a=void 0;if(n.live){if(d=n.startSN&&S<=n.endSN&&(a=u[S-n.startSN],t.logger.log("live playlist, switching playlist, load frag with next SN: "+a.sn))}a||(a=u[Math.min(g-1,Math.round(g/2))],t.logger.log("live playlist, switching playlist, unknown, load middle frag : "+a.sn))}}else p>d&&(a=u[0]);if(!a){var m;if(m=w>d?f.default.search(u,function(e){return e.start+e.duration<=d?1:e.start>d?-1:0}):u[g-1],m&&(a=m,p=m.start,c&&a.level===c.level&&a.sn===c.sn))if(a.sn1&&(a.expectedLen=Math.round(a.duration*this.levels[l].bitrate/8),a.trequest=performance.now()),void 0!==this.fragLoadIdx?this.fragLoadIdx++:this.fragLoadIdx=0,a.loadCounter){a.loadCounter++;var D=this.config.fragLoadingLoopThreshold;if(a.loadCounter>D&&Math.abs(this.fragLoadIdx-a.loadIdx)1){var T=performance.now()-s.trequest;if(T>500*s.duration){var k=1e3*s.loaded/T;s.expectedLenb&&R>O&&(t.logger.warn("loading too slow, abort fragment loading"),t.logger.log("fragLoadedDelay/bufferStarvationDelay/fragLevelNextLoadedDelay :"+R.toFixed(1)+"/"+b.toFixed(1)+"/"+O.toFixed(1)),s.loader.abort(),o.trigger(r.default.FRAG_LOAD_EMERGENCY_ABORTED,{frag:s}),this.state=e.IDLE)}}break;case e.PARSING:break;case e.PARSED:case e.APPENDING:if(this.sourceBuffer){if(this.media.error)return t.logger.error("trying to append although a media error occured, switch to ERROR state"),void(this.state=e.ERROR);if(this.sourceBuffer.audio&&this.sourceBuffer.audio.updating||this.sourceBuffer.video&&this.sourceBuffer.video.updating);else if(this.mp4segments.length){var A=this.mp4segments.shift();try{this.sourceBuffer[A.type].appendBuffer(A.data),this.appendError=0}catch(a){this.mp4segments.unshift(A),this.appendError?this.appendError++:this.appendError=1;var y={type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.BUFFER_APPEND_ERROR,frag:this.fragCurrent};if(this.appendError>this.config.appendErrorMaxRetry)return t.logger.log("fail "+this.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),y.fatal=!0,o.trigger(r.default.ERROR,y),void(this.state=e.ERROR);y.fatal=!1,o.trigger(r.default.ERROR,y)}this.state=e.APPENDING}}else this.state=e.IDLE;break;case e.BUFFER_FLUSHING:for(;this.flushRange.length;){var x=this.flushRange[0];if(!this.flushBuffer(x.start,x.end))break;this.flushRange.shift()}0===this.flushRange.length&&(this.immediateSwitch&&this.immediateLevelSwitchEnd(),this.state=e.IDLE,this.fragPrevious=null)}this._checkFragmentChanged(),this._checkBuffer()}},{key:"bufferInfo",value:function(i,a){var e,n=this.media,t=n.buffered,r=[];for(e=0;ed&&(t[u-1].end=r[e].end):t.push(r[e])}else t.push(r[e])}for(e=0,o=0,l=n=i;e=s&&h>i?(l=s,n=h+a,o=n-i):s>i+a&&(f=s)}return{len:o,start:l,end:n,nextStart:f}}},{key:"getBufferRange",value:function(r){var e,t;for(e=this.bufferRange.length-1;e>=0;e--)if(t=this.bufferRange[e],r>=t.start&&r<=t.end)return t;return null}},{key:"followingBufferRange",value:function(e){return e?this.getBufferRange(e.end+.5):null}},{key:"isBuffered",value:function(r){for(var i=this.media,t=i.buffered,e=0;e=t.start(e)&&r<=t.end(e))return!0;return!1}},{key:"_checkFragmentChanged",value:function(){var t,e,i=this.media;if(i&&i.seeking===!1&&(e=i.currentTime,e>i.playbackRate*this.lastCurrentTime&&(this.lastCurrentTime=e),this.isBuffered(e)?t=this.getBufferRange(e):this.isBuffered(e+.1)&&(t=this.getBufferRange(e+.1)),t)){var a=t.frag;a!==this.fragPlaying&&(this.fragPlaying=a,this.hls.trigger(r.default.FRAG_CHANGED,{frag:a}))}}},{key:"flushBuffer",value:function(d,l){var r,e,o,s,i,a;if(this.flushBufferCounter++<2*this.bufferRange.length&&this.sourceBuffer)for(var u in this.sourceBuffer){if(r=this.sourceBuffer[u],r.updating)return!1;for(e=0;e.5)return t.logger.log("flush "+u+" ["+i+","+a+"], of ["+o+","+s+"], pos:"+this.media.currentTime),r.remove(i,a),!1}var n,h=[];for(e=0;e=a&&(e.currentTime=a,this.seekAfterBuffered=void 0);else if(3>i){var n=e.currentTime,s=this.bufferInfo(n,0);if(0===s.len){var r=s.nextStart;r&&.3>r-n&&(t.logger.log("adjust currentTime from "+n+" to "+r),e.currentTime=r)}}}}}},{key:"recoverMediaError",value:function(){this.lastReadyState<2&&(this.audioCodecSwap=!this.audioCodecSwap)}},{key:"onSBUpdateError",value:function(a){t.logger.error("sourceBuffer error:"+a),this.state=e.ERROR,this.hls.trigger(r.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!0,frag:this.fragCurrent})}},{key:"timeRangesToString",value:function(t){for(var r="",i=t.length,e=0;i>e;e++)r+="["+t.start(e)+","+t.end(e)+"]";return r}},{key:"onMediaSourceOpen",value:function(){t.logger.log("media source opened"),this.hls.trigger(r.default.MEDIA_ATTACHED),this.onvseeking=this.onMediaSeeking.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),this.onvmetadata=this.onMediaMetadata.bind(this),this.onvended=this.onMediaEnded.bind(this);var e=this.media;e.addEventListener("seeking",this.onvseeking),e.addEventListener("seeked",this.onvseeked),e.addEventListener("loadedmetadata",this.onvmetadata),e.addEventListener("ended",this.onvended),this.levels&&this.config.autoStartLoad&&this.startLoad(),this.mediaSource.removeEventListener("sourceopen",this.onmso)}},{key:"onMediaSourceClose",value:function(){t.logger.log("media source closed")}},{key:"onMediaSourceEnded",value:function(){t.logger.log("media source ended")}},{key:"currentLevel",get:function(){if(this.media){var e=this.getBufferRange(this.media.currentTime);if(e)return e.frag.level}return-1}},{key:"nextBufferRange",get:function(){return this.media?this.followingBufferRange(this.getBufferRange(this.media.currentTime)):null; }},{key:"nextLevel",get:function(){var e=this.nextBufferRange;return e?e.frag.level:-1}}]),a}();s.default=y,u.exports=s.default},{"../demux/demuxer":12,"../errors":16,"../events":17,"../helper/level-helper":18,"../utils/binary-search":25,"../utils/logger":26}],6:[function(n,t,e){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function e(i,r){for(var t=0;te;e++)c[(a[e]=e<<1^283*(e>>7))^e]=e;for(i=r=0;!f[i];i^=u||1,r=c[r]||1)for(t=r^r<<1^r<<2^r<<3^r<<4,t=t>>8^255&t^99,f[i]=t,g[t]=i,d=a[h=a[u=a[i]]],l=16843009*d^65537*h^257*u^16843008*i,s=257*a[t]^16843008*t,e=0;4>e;e++)n[e][i]=s=s<<24^s>>>8,o[e][t]=l=l<<24^l>>>8;for(e=0;5>e;e++)n[e]=n[e].slice(0),o[e]=o[e].slice(0)}},{key:"decrypt",value:function(A,p,_,b,E,m){var f,v,g,n,e=this._key[1],t=A^e[0],i=b^e[1],a=_^e[2],r=p^e[3],y=e.length/4-2,s=4,o=this._tables[1],h=o[0],d=o[1],u=o[2],l=o[3],c=o[4];for(n=0;y>n;n++)f=h[t>>>24]^d[i>>16&255]^u[a>>8&255]^l[255&r]^e[s],v=h[i>>>24]^d[a>>16&255]^u[r>>8&255]^l[255&t]^e[s+1],g=h[a>>>24]^d[r>>16&255]^u[t>>8&255]^l[255&i]^e[s+2],r=h[r>>>24]^d[t>>16&255]^u[i>>8&255]^l[255&a]^e[s+3],s+=4,t=f,i=v,a=g;for(n=0;4>n;n++)E[(3&-n)+m]=c[t>>>24]<<24^c[i>>16&255]<<16^c[a>>8&255]<<8^c[255&r]^e[s++],f=t,t=i,i=a,a=r,r=f}}]),e}();e.default=a,t.exports=e.default},{}],7:[function(t,r,e){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(i,r){for(var t=0;t>8|e>>>24}},{key:"doDecrypt",value:function(i,v,a){var u,f,s,h,l,c,d,n,e,r=new Int32Array(i.buffer,i.byteOffset,i.byteLength>>2),p=new o.default(Array.prototype.slice.call(v)),g=new Uint8Array(i.byteLength),t=new Int32Array(g.buffer);for(u=~~a[0],f=~~a[1],s=~~a[2],h=~~a[3],e=0;ee&&(255!==t[e]||240!==(240&t[e+1]));e++);for(a.audiosamplerate||(s=this._ADTStoAudioConfig(t,e,v),a.config=s.config,a.audiosamplerate=s.samplerate,a.channelCount=s.channelCount,a.codec=s.codec,a.timescale=this.remuxer.timescale,a.duration=this.remuxer.timescale*g,r.logger.log("parsed codec:"+a.codec+",rate:"+s.samplerate+",nb channel:"+s.channelCount)),u=0;l>e+5&&(n=(3&t[e+3])<<11,n|=t[e+4]<<3,n|=(224&t[e+5])>>>5,o=1&t[e+1]?7:9,n-=o,d=Math.round(90*p+1024*u*9e4/a.audiosamplerate),n>0&&l>=e+o+n);)for(f={unit:t.subarray(e+o,e+o+n),pts:d,dts:d},a.samples.push(f),a.len+=n,e+=n+o,u++;l-1>e&&(255!==t[e]||240!==(240&t[e+1]));e++);this.remuxer.remux(this._aacTrack,{samples:[]},{samples:[]},c)}},{key:"_ADTStoAudioConfig",value:function(l,u,s){var i,e,n,o,t,h=navigator.userAgent.toLowerCase(),d=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];return i=((192&l[u+2])>>>6)+1,e=(60&l[u+2])>>>2,e>d.length-1?void this.observer.trigger(Event.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+e}):(o=(1&l[u+2])<<2,o|=(192&l[u+3])>>>6,r.logger.log("manifest codec:"+s+",ADTS data:type:"+i+",sampleingIndex:"+e+"["+d[e]+"kHz],channelConfig:"+o),-1!==h.indexOf("firefox")?e>=6?(i=5,t=new Array(4),n=e-3):(i=2,t=new Array(2),n=e):-1!==h.indexOf("android")?(i=2,t=new Array(2),n=e):(i=5,t=new Array(4),s&&-1!==s.indexOf("mp4a.40.5")||!s&&e>=6?n=e-3:(s&&-1!==s.indexOf("mp4a.40.2")&&(e>=6||1===o)&&(i=2,t=new Array(2)),n=e)),t[0]=i<<3,t[0]|=(14&e)>>1,t[1]|=(1&e)<<7,t[1]|=o<<3,5===i&&(t[1]|=(14&n)>>1,t[2]=(1&n)<<7,t[2]|=8,t[3]=0),{config:t,samplerate:d[e],channelCount:o,codec:"mp4a.40."+i})}},{key:"destroy",value:function(){}}],[{key:"probe",value:function(t){var e,r,a=new i.default(t);if(a.hasTimeStamp)for(e=a.length,r=t.length;r-1>e;e++)if(255===t[e]&&240===(240&t[e+1]))return!0;return!1}}]),e}();t.default=s,n.exports=t.default},{"../demux/id3":14,"../errors":16,"../utils/logger":26}],10:[function(e,o,t){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function d(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var f=function(){function e(i,r){for(var t=0;t1?r-1:0),e=1;r>e;e++)a[e-1]=arguments[e];t.emit.apply(t,[i,i].concat(a))},t.off=function(a){for(var r=arguments.length,i=Array(r>1?r-1:0),e=1;r>e;e++)i[e-1]=arguments[e];t.removeListener.apply(t,[a].concat(i))},r.addEventListener("message",function(i){switch(i.data.cmd){case"init":r.demuxer=new n.default(t,h.default);break;case"demux":var e=i.data;r.demuxer.push(new Uint8Array(e.data),e.audioCodec,e.videoCodec,e.timeOffset,e.cc,e.level,e.sn,e.duration)}}),t.on(e.default.FRAG_PARSING_INIT_SEGMENT,function(a,t){var e={event:a},i=[];t.audioCodec&&(e.audioCodec=t.audioCodec,e.audioMoov=t.audioMoov.buffer,e.audioChannelCount=t.audioChannelCount,i.push(e.audioMoov)),t.videoCodec&&(e.videoCodec=t.videoCodec,e.videoMoov=t.videoMoov.buffer,e.videoWidth=t.videoWidth,e.videoHeight=t.videoHeight,i.push(e.videoMoov)),r.postMessage(e,i)}),t.on(e.default.FRAG_PARSING_DATA,function(i,e){var t={event:i,type:e.type,startPTS:e.startPTS,endPTS:e.endPTS,startDTS:e.startDTS,endDTS:e.endDTS,moof:e.moof.buffer,mdat:e.mdat.buffer,nb:e.nb};r.postMessage(t,[t.moof,t.mdat])}),t.on(e.default.FRAG_PARSED,function(e){r.postMessage({event:e})}),t.on(e.default.ERROR,function(e,t){r.postMessage({event:e,data:t})}),t.on(e.default.FRAG_PARSING_METADATA,function(e,t){var i={event:e,samples:t.samples};r.postMessage(i)})};i.default=o,s.exports=i.default},{"../demux/demuxer-inline":10,"../events":17,"../remux/mp4-remuxer":24,events:1}],12:[function(e,u,i){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function g(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function e(i,r){for(var t=0;t0&&null!=e&&null!=e.key&&"AES-128"===e.method){null==this.decrypter&&(this.decrypter=new p.default(this.hls));var u=this;this.decrypter.decrypt(t,e.key,e.iv,function(e){u.pushDecrypted(e,r,i,a,n,s,o,l)})}else this.pushDecrypted(t,r,i,a,n,s,o,l)}},{key:"onWorkerMessage",value:function(e){switch(e.data.event){case t.default.FRAG_PARSING_INIT_SEGMENT:var r={};e.data.audioMoov&&(r.audioMoov=new Uint8Array(e.data.audioMoov),r.audioCodec=e.data.audioCodec,r.audioChannelCount=e.data.audioChannelCount),e.data.videoMoov&&(r.videoMoov=new Uint8Array(e.data.videoMoov),r.videoCodec=e.data.videoCodec,r.videoWidth=e.data.videoWidth,r.videoHeight=e.data.videoHeight),this.hls.trigger(t.default.FRAG_PARSING_INIT_SEGMENT,r);break;case t.default.FRAG_PARSING_DATA:this.hls.trigger(t.default.FRAG_PARSING_DATA,{moof:new Uint8Array(e.data.moof),mdat:new Uint8Array(e.data.mdat),startPTS:e.data.startPTS,endPTS:e.data.endPTS,startDTS:e.data.startDTS,endDTS:e.data.endDTS,type:e.data.type,nb:e.data.nb});break;case t.default.FRAG_PARSING_METADATA:this.hls.trigger(t.default.FRAG_PARSING_METADATA,{samples:e.data.samples});break;default:this.hls.trigger(e.data.event,e.data.data)}}}]),r}();i.default=y,u.exports=i.default},{"../crypt/decrypter":8,"../demux/demuxer-inline":10,"../demux/demuxer-worker":11,"../events":17,"../remux/mp4-remuxer":24,"../utils/logger":26,webworkify:2}],13:[function(t,r,e){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function e(i,r){for(var t=0;te?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,t=e>>3,e-=t>>3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)}},{key:"readBits",value:function(t){var e=Math.min(this.bitsAvailable,t),r=this.word>>>32-e;return t>32&&n.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=e,this.bitsAvailable>0?this.word<<=e:this.bytesAvailable>0&&this.loadWord(),e=t-e,e>0?r<>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"skipScalingList",value:function(a){var t,i,r=8,e=8;for(t=0;a>t;t++)0!==e&&(i=this.readEG(),e=(r+i+256)%256),r=0===e?r:e}},{key:"readSPS",value:function(){var r,v,p,l,a,n,i,o,t,s=0,d=0,h=0,f=0,c=1;if(this.readUByte(),r=this.readUByte(),v=this.readBits(5),this.skipBits(3),p=this.readUByte(),this.skipUEG(),100===r||110===r||122===r||144===r){var g=this.readUEG();if(3===g&&this.skipBits(1),this.skipUEG(),this.skipUEG(),this.skipBits(1),this.readBoolean())for(o=3!==g?8:12,t=0;o>t;t++)this.readBoolean()&&(6>t?this.skipScalingList(16):this.skipScalingList(64))}this.skipUEG();var u=this.readUEG();if(0===u)this.readUEG();else if(1===u)for(this.skipBits(1),this.skipEG(),this.skipEG(),l=this.readUEG(),t=0;l>t;t++)this.skipEG();if(this.skipUEG(),this.skipBits(1),a=this.readUEG(),n=this.readUEG(),i=this.readBits(1),0===i&&this.skipBits(1),this.skipBits(1),this.readBoolean()&&(s=this.readUEG(),d=this.readUEG(),h=this.readUEG(),f=this.readUEG()),this.readBoolean()&&this.readBoolean()){var e=void 0,y=this.readUByte();switch(y){case 2:e=[12,11];break;case 3:e=[10,11];break;case 4:e=[16,11];break;case 5:e=[40,33];break;case 6:e=[24,11];break;case 7:e=[20,11];break;case 8:e=[32,11];break;case 9:e=[80,33];break;case 10:e=[18,11];break;case 11:e=[15,11];break;case 12:e=[64,33];break;case 13:e=[160,99];break;case 14:e=[4,3];break;case 15:e=[3,2];break;case 16:e=[2,1];break;case 255:e=[this.readUByte()<<8|this.readUByte(),this.readUByte()<<8|this.readUByte()]}e&&(c=e[0]/e[1])}return{width:(16*(a+1)-2*s-2*d)*c,height:(2-i)*(n+1)*16-(i?2:4)*(h+f)}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}();e.default=s,r.exports=e.default},{"../utils/logger":26}],14:[function(r,i,e){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(i,r){for(var t=0;tr);return t}},{key:"_parseID3Frames",value:function(r,e,n){for(var a,s,o,l,i;n>=e+8;)switch(a=this.readUTF(r,e,4),e+=4,s=r[e++]<<24+r[e++]<<16+r[e++]<<8+r[e++],l=r[e++]<<8+r[e++],o=e,a){case"PRIV":if("com.apple.streaming.transportStreamTimestamp"===this.readUTF(r,e,44)){e+=44,e+=4;var u=1&r[e++];this._hasTimeStamp=!0,i=((r[e++]<<23)+(r[e++]<<15)+(r[e++]<<7)+r[e++])/45,u&&(i+=47721858.84),i=Math.round(i),t.logger.trace("ID3 timestamp found: "+i),this._timeStamp=i}}}},{key:"hasTimeStamp",get:function(){return this._hasTimeStamp}},{key:"timeStamp",get:function(){return this._timeStamp}},{key:"length",get:function(){return this._length}}]),e}();e.default=s,i.exports=e.default},{"../utils/logger":26}],15:[function(r,s,i){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function d(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(i,"__esModule",{value:!0});var h=function(){function e(i,r){for(var t=0;tr;r+=188)if(71===i[r]){if(d=!!(64&i[r+1]),u=((31&i[r+1])<<8)+i[r+2],y=(48&i[r+3])>>4,y>1){if(n=r+5+i[r+4],n===r+188)continue}else n=r+4;p?u===g?(d&&(l&&this._parseAVCPES(this._parsePES(l)),l={data:[],size:0}),l&&(l.data.push(i.subarray(n,r+188)),l.size+=r+188-n)):u===c?(d&&(o&&this._parseAACPES(this._parsePES(o)),o={data:[],size:0}),o&&(o.data.push(i.subarray(n,r+188)),o.size+=r+188-n)):u===m&&(d&&(s&&this._parseID3PES(this._parsePES(s)),s={data:[],size:0}),s&&(s.data.push(i.subarray(n,r+188)),s.size+=r+188-n)):(d&&(n+=i[n]+1),0===u?this._parsePAT(i,n):u===this._pmtId&&(this._parsePMT(i,n),p=this.pmtParsed=!0,g=this._avcTrack.id,c=this._aacTrack.id,m=this._id3Track.id))}else this.observer.trigger(a.default.ERROR,{type:t.ErrorTypes.MEDIA_ERROR,details:t.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});l&&this._parseAVCPES(this._parsePES(l)),o&&this._parseAACPES(this._parsePES(o)),s&&this._parseID3PES(this._parsePES(s)),this.remux()}},{key:"remux",value:function(){this.remuxer.remux(this._aacTrack,this._avcTrack,this._id3Track,this.timeOffset,this.contiguous)}},{key:"destroy",value:function(){this.switchLevel(),this._initPTS=this._initDTS=void 0,this._duration=0}},{key:"_parsePAT",value:function(e,t){this._pmtId=(31&e[t+10])<<8|e[t+11]}},{key:"_parsePMT",value:function(r,t){var a,n,s,i;for(a=(15&r[t+1])<<8|r[t+2],n=t+3+a-4,s=(15&r[t+10])<<8|r[t+11],t+=12+s;n>t;){switch(i=(31&r[t+1])<<8|r[t+2],r[t]){case 15:this._aacTrack.id=i;break;case 21:this._id3Track.id=i;break;case 27:this._avcTrack.id=i;break;default:e.logger.log("unkown stream type:"+r[t])}t+=((15&r[t+3])<<8|r[t+4])+5}}},{key:"_parsePES",value:function(t){var e,a,u,o,d,n,r,i,s,l=0;if(e=t.data[0],u=(e[0]<<16)+(e[1]<<8)+e[2],1===u){for(o=(e[4]<<8)+e[5],a=e[7],192&a&&(r=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,r>4294967295&&(r-=8589934592),64&a?(i=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2,i>4294967295&&(i-=8589934592)):i=r),d=e[8],s=d+9,t.data[0]=t.data[0].subarray(s),t.size-=s,n=new Uint8Array(t.size);t.data.length;)e=t.data.shift(),n.set(e,l),l+=e.byteLength;return{data:n,pts:r,dts:i,len:o}}return null}},{key:"_parseAVCPES",value:function(a){var v,i,h=this,t=this._avcTrack,l=t.samples,p=this._parseAVCNALu(a.data),s=[],n=!1,g=!1,f=0;if(0===p.length&&l.length>0){var c=l[l.length-1],o=c.units.units[c.units.units.length-1],d=new Uint8Array(o.data.byteLength+a.data.byteLength);d.set(o.data,0),d.set(a.data,o.data.byteLength),o.data=d,c.units.length+=a.data.byteLength,t.len+=a.data.byteLength}a.data=null;var r="";p.forEach(function(e){switch(e.type){case 1:i=!0,n&&(r+="NDR ");break;case 5:i=!0,n&&(r+="IDR "),g=!0;break;case 6:i=!0,n&&(r+="SEI ");break;case 7:if(i=!0,n&&(r+="SPS "),!t.sps){var c=new u.default(e.data),l=c.readSPS();t.width=l.width,t.height=l.height,t.sps=[e.data],t.timescale=h.remuxer.timescale,t.duration=h.remuxer.timescale*h._duration;for(var v=e.data.subarray(1,4),d="avc1.",o=0;3>o;o++){var a=v[o].toString(16);a.length<2&&(a="0"+a),d+=a}t.codec=d}break;case 8:i=!0,n&&(r+="PPS "),t.pps||(t.pps=[e.data]);break;case 9:i=!0,n&&(r+="AUD ");break;default:i=!1,r+="unknown NAL "+e.type+" "}i&&(s.push(e),f+=e.data.byteLength)}),(n||r.length)&&e.logger.log(r),s.length&&(g===!0||t.sps)&&(v={units:{units:s,length:f},pts:a.pts,dts:a.dts,key:g},l.push(v),t.len+=f,t.nbNalu+=s.length)}},{key:"_parseAVCNALu",value:function(i){for(var n,r,o,s,a,u,t=0,d=i.byteLength,e=0,h=[];d>t;)switch(n=i[t++],e){case 0:0===n&&(e=1);break;case 1:e=0===n?2:0;break;case 2:case 3:if(0===n)e=3;else if(1===n){if(s=31&i[t],a)o={data:i.subarray(a,t-e-1),type:u},h.push(o);else if(r=t-e-1,r&&this._avcTrack.samples.length){var f=this._avcTrack.samples[this._avcTrack.samples.length-1],l=f.units.units[f.units.units.length-1],c=new Uint8Array(l.data.byteLength+r);c.set(l.data,0),c.set(i.subarray(0,r),l.data.byteLength),l.data=c,f.units.length+=r,this._avcTrack.len+=r}a=t,u=s,(1===s||5===s)&&(t=d),e=0}else e=0}return a&&(o={data:i.subarray(a,d),type:u},h.push(o)),h}},{key:"_parseAACPES",value:function(p){var v,l,n,r,u,f,h,o,s=this._aacTrack,i=p.data;if(this.aacOverFlow){var g=new Uint8Array(this.aacOverFlow.byteLength+i.byteLength);g.set(this.aacOverFlow,0),g.set(i,this.aacOverFlow.byteLength),i=g}for(r=0,o=i.length;o-1>r&&(255!==i[r]||240!==(240&i[r+1]));r++);if(r){var c,d;if(o-1>r?(c="AAC PES did not start with ADTS header,offset:"+r,d=!1):(c="no ADTS header found in AAC PES",d=!0),this.observer.trigger(a.default.ERROR,{type:t.ErrorTypes.MEDIA_ERROR,details:t.ErrorDetails.FRAG_PARSING_ERROR,fatal:d,reason:c}),d)return}for(s.audiosamplerate||(l=this._ADTStoAudioConfig(i,r,this.audioCodec),s.config=l.config,s.audiosamplerate=l.samplerate,s.channelCount=l.channelCount,s.codec=l.codec,s.timescale=this.remuxer.timescale,s.duration=this.remuxer.timescale*this._duration,e.logger.log("parsed codec:"+s.codec+",rate:"+l.samplerate+",nb channel:"+l.channelCount)),h=0;o>r+5&&(n=(3&i[r+3])<<11,n|=i[r+4]<<3,n|=(224&i[r+5])>>>5,u=1&i[r+1]?7:9,n-=u,f=Math.round(p.pts+1024*h*this.PES_TIMESCALE/s.audiosamplerate),n>0&&o>=r+u+n);)for(v={unit:i.subarray(r+u,r+u+n),pts:f,dts:f},this._aacTrack.samples.push(v),this._aacTrack.len+=n,r+=n+u,h++;o-1>r&&(255!==i[r]||240!==(240&i[r+1]));r++);o>r?this.aacOverFlow=i.subarray(r,o):this.aacOverFlow=null}},{key:"_ADTStoAudioConfig",value:function(u,d,s){var n,r,o,l,i,f=navigator.userAgent.toLowerCase(),h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];return n=((192&u[d+2])>>>6)+1,r=(60&u[d+2])>>>2,r>h.length-1?void this.observer.trigger(a.default.ERROR,{type:t.ErrorTypes.MEDIA_ERROR,details:t.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+r}):(l=(1&u[d+2])<<2,l|=(192&u[d+3])>>>6,e.logger.log("manifest codec:"+s+",ADTS data:type:"+n+",sampleingIndex:"+r+"["+h[r]+"kHz],channelConfig:"+l),-1!==f.indexOf("firefox")?r>=6?(n=5,i=new Array(4),o=r-3):(n=2,i=new Array(2),o=r):-1!==f.indexOf("android")?(n=2,i=new Array(2),o=r):(n=5,i=new Array(4),s&&(-1!==s.indexOf("mp4a.40.29")||-1!==s.indexOf("mp4a.40.5"))||!s&&r>=6?o=r-3:(s&&-1!==s.indexOf("mp4a.40.2")&&(r>=6||1===l)&&(n=2,i=new Array(2)),o=r)),i[0]=n<<3,i[0]|=(14&r)>>1,i[1]|=(1&r)<<7,i[1]|=l<<3,5===n&&(i[1]|=(14&o)>>1,i[2]=(1&o)<<7,i[2]|=8,i[3]=0),{config:i,samplerate:h[r],channelCount:l,codec:"mp4a.40."+n})}},{key:"_parseID3PES",value:function(e){this._id3Track.samples.push(e)}}],[{key:"probe",value:function(e){return e.length>=564&&71===e[0]&&71===e[188]&&71===e[376]?!0:!1}}]),r}();i.default=o,s.exports=i.default},{"../errors":16,"../events":17,"../utils/logger":26,"./exp-golomb":13}],16:[function(i,a,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t={NETWORK_ERROR:"hlsNetworkError",MEDIA_ERROR:"hlsMediaError",OTHER_ERROR:"hlsOtherError"};e.ErrorTypes=t;var r={MANIFEST_LOAD_ERROR:"manifestLoadError",MANIFEST_LOAD_TIMEOUT:"manifestLoadTimeOut",MANIFEST_PARSING_ERROR:"manifestParsingError",LEVEL_LOAD_ERROR:"levelLoadError",LEVEL_LOAD_TIMEOUT:"levelLoadTimeOut",LEVEL_SWITCH_ERROR:"levelSwitchError",FRAG_LOAD_ERROR:"fragLoadError",FRAG_LOOP_LOADING_ERROR:"fragLoopLoadingError",FRAG_LOAD_TIMEOUT:"fragLoadTimeOut",FRAG_DECRYPT_ERROR:"fragDecryptError",FRAG_PARSING_ERROR:"fragParsingError",KEY_LOAD_ERROR:"keyLoadError",KEY_LOAD_TIMEOUT:"keyLoadTimeOut",BUFFER_APPEND_ERROR:"bufferAppendError",BUFFER_APPENDING_ERROR:"bufferAppendingError"};e.ErrorDetails=r},{}],17:[function(r,t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsPTSUpdated",LEVEL_SWITCH:"hlsLevelSwitch",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_PROGRESS:"hlsFragLoadProgress",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_METADATA:"hlsFraParsingMetadata",FRAG_PARSING_DATA:"hlsFragParsingData",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFPSDrop",ERROR:"hlsError",DESTROYING:"hlsDestroying",KEY_LOADING:"hlsKeyLoading",KEY_LOADED:"hlsKeyLoaded"},t.exports=e.default},{}],18:[function(r,i,e){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(i,r){for(var t=0;td)return void(i.PTSKnown=!1);for(var r=c;d>=r;r++){var l=f[h+r],a=o[r];u=l.cc-a.cc,isNaN(l.startPTS)||(a.start=a.startPTS=l.startPTS,a.endPTS=l.endPTS,a.duration=l.duration,s=a)}if(u)for(t.logger.log("discontinuity sliding from playlist, take drift into account"),r=0;ri.endSN)return 0;o=l-i.startSN,n=i.fragments,r=n[o],isNaN(r.startPTS)||(a=Math.max(a,r.startPTS),s=Math.min(s,r.endPTS)); var u=a-r.start;for(r.start=r.startPTS=a,r.endPTS=s,r.duration=s-a,t=o;t>0;t--)e.updatePTS(n,t,t-1);for(t=o;ti?r.start=e.start+e.duration:r.start=e.start-r.duration:a>i?(e.duration=n-e.start,e.duration<0&&t.logger.error("negative duration computed for "+e+", there should be some duration drift between playlist and fragment!")):(r.duration=e.start-n,r.duration<0&&t.logger.error("negative duration computed for "+r+", there should be some duration drift between playlist and fragment!"))}}]),e}();e.default=s,i.exports=e.default},{"../utils/logger":26}],19:[function(t,c,a){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(a,"__esModule",{value:!0});var n=function(){function e(i,r){for(var t=0;t1?t-1:0),e=1;t>e;e++)a[e-1]=arguments[e];r.emit.apply(r,[i,i].concat(a))},r.off=function(a){for(var t=arguments.length,i=Array(t>1?t-1:0),e=1;t>e;e++)i[e-1]=arguments[e];r.removeListener.apply(r,[a].concat(i))},this.on=r.on.bind(r),this.off=r.off.bind(r),this.trigger=r.trigger.bind(r),this.playlistLoader=new d.default(this),this.fragmentLoader=new f.default(this),this.levelController=new m.default(this),this.abrController=new i.abrController(this),this.mediaController=new i.mediaController(this),this.keyLoader=new S.default(this)}return n(t,null,[{key:"isSupported",value:function(){return window.MediaSource&&window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')}},{key:"Events",get:function(){return i.default}},{key:"ErrorTypes",get:function(){return s.ErrorTypes}},{key:"ErrorDetails",get:function(){return s.ErrorDetails}}]),n(t,[{key:"destroy",value:function(){e.logger.log("destroy"),this.trigger(i.default.DESTROYING),this.detachMedia(),this.playlistLoader.destroy(),this.fragmentLoader.destroy(),this.levelController.destroy(),this.mediaController.destroy(),this.keyLoader.destroy(),this.url=null,this.observer.removeAllListeners()}},{key:"attachMedia",value:function(t){e.logger.log("attachMedia"),this.media=t,this.trigger(i.default.MEDIA_ATTACHING,{media:t})}},{key:"detachMedia",value:function(){e.logger.log("detachMedia"),this.trigger(i.default.MEDIA_DETACHING),this.media=null}},{key:"loadSource",value:function(t){e.logger.log("loadSource:"+t),this.url=t,this.trigger(i.default.MANIFEST_LOADING,{url:t})}},{key:"startLoad",value:function(){e.logger.log("startLoad"),this.mediaController.startLoad()}},{key:"recoverMediaError",value:function(){e.logger.log("recoverMediaError");var t=this.media;this.detachMedia(),this.attachMedia(t),this.mediaController.recoverMediaError()}},{key:"levels",get:function(){return this.levelController.levels}},{key:"currentLevel",get:function(){return this.mediaController.currentLevel},set:function(t){e.logger.log("set currentLevel:"+t),this.loadLevel=t,this.mediaController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.mediaController.nextLevel},set:function(t){e.logger.log("set nextLevel:"+t),this.levelController.manualLevel=t,this.mediaController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(t){e.logger.log("set loadLevel:"+t),this.levelController.manualLevel=t}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel()},set:function(e){this.levelController.level=e}},{key:"firstLevel",get:function(){return this.levelController.firstLevel},set:function(t){e.logger.log("set firstLevel:"+t),this.levelController.firstLevel=t}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(t){e.logger.log("set startLevel:"+t),this.levelController.startLevel=t}},{key:"autoLevelCapping",get:function(){return this.abrController.autoLevelCapping},set:function(t){e.logger.log("set autoLevelCapping:"+t),this.abrController.autoLevelCapping=t}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}}]),t}();a.default=l,c.exports=a.default},{"./controller/abr-controller":3,"./controller/level-controller":4,"./controller/mse-media-controller":5,"./errors":16,"./events":17,"./loader/fragment-loader":20,"./loader/key-loader":21,"./loader/playlist-loader":22,"./utils/logger":26,"./utils/xhr-loader":28,events:1}],20:[function(i,a,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(i,r){for(var t=0;t0;)switch(e.shift()){case"RES":t.width=parseInt(e.shift()),t.height=parseInt(e.shift());break;case"BAND":t.bitrate=parseInt(e.shift());break;case"NAME":t.name=e.shift();break;case"CODECS":for(i=e.shift().split(",");i.length>0;)r=i.shift(),-1!==r.indexOf("avc1")?t.videoCodec=this.avc1toavcoti(r):t.audioCodec=r}a.push(t),t={}}return a}},{key:"avc1toavcoti",value:function(r){var e,t=r.split(".");return t.length>2?(e=t.shift()+".",e+=parseInt(t.shift()).toString(16),e+=("00"+parseInt(t.shift()).toString(16)).substr(-4)):e=r,e}},{key:"parseKeyParamsByRegex",value:function(t,r){var e=r.exec(t);return e&&(e.shift(),e=e.filter(function(e){return void 0!==e}),2===e.length)?e[1]:null}},{key:"cloneObj",value:function(e){return JSON.parse(JSON.stringify(e))}},{key:"parseLevelPlaylist",value:function(A,n,_){var t,m,i,s,a,c=0,u=0,r={url:n,fragments:[],live:!0,startSN:0},v=0,e={method:null,key:null,iv:null,uri:null};for(m=/(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT-X-(KEY):(.*))|(?:#EXT(INF):([\d\.]+)[^\r\n]*([\r\n]+[^#|\r\n]+)?)|(?:#EXT-X-(BYTERANGE):([\d]+[@[\d]*)]*[\r\n]+([^#|\r\n]+)?|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))/g;null!==(t=m.exec(A));)switch(t.shift(),t=t.filter(function(e){return void 0!==e}),t[0]){case"MEDIA-SEQUENCE":c=r.startSN=parseInt(t[1]);break;case"TARGETDURATION":r.targetduration=parseFloat(t[1]);break;case"ENDLIST":r.live=!1;break;case"DIS":v++;break;case"BYTERANGE":var d=t[1].split("@");a=1===d.length?s:parseInt(d[1]),s=parseInt(d[0])+a,i=r.fragments.length?r.fragments[r.fragments.length-1]:null,i&&!i.url&&(i.byteRangeStartOffset=a,i.byteRangeEndOffset=s,i.url=this.resolve(t[2],n));break;case"INF":var h=parseFloat(t[1]);if(!isNaN(h)){var o,p=c++;if(e.method&&e.uri&&!e.iv){o=this.cloneObj(e);for(var y=new Uint8Array(16),l=12;16>l;l++)y[l]=p>>8*(15-l)&255;o.iv=y}else o=e;r.fragments.push({url:t[2]?this.resolve(t[2],n):null,duration:h,start:u,sn:p,level:_,cc:v,byteRangeStartOffset:a,byteRangeEndOffset:s,decryptdata:o}),u+=h,a=null}break;case"KEY":var g=t[1],f=this.parseKeyParamsByRegex(g,/(METHOD)=([^,]*)/),E=this.parseKeyParamsByRegex(g,/(URI)=["]([^,]*)["]/),b=this.parseKeyParamsByRegex(g,/(IV)=([^,]*)/);f&&(e={method:null,key:null,iv:null,uri:null},E&&"AES-128"===f&&(e.method=f,e.uri=this.resolve(E,n),e.key=null,b&&(e.iv=b,"0x"===e.iv.substring(0,2)&&(e.iv=e.iv.substring(2)),e.iv=e.iv.match(/.{8}/g),e.iv[0]=parseInt(e.iv[0],16),e.iv[1]=parseInt(e.iv[1],16),e.iv[2]=parseInt(e.iv[2],16),e.iv[3]=parseInt(e.iv[3],16),e.iv=new Uint32Array(e.iv))))}return r.totalduration=u,r.endSN=c-1,r}},{key:"loadsuccess",value:function(s,i){var o,n=s.currentTarget.responseText,r=s.currentTarget.responseURL,l=this.id,u=this.id2,a=this.hls;if(void 0===r&&(r=this.url),i.tload=performance.now(),i.mtime=new Date(s.currentTarget.getResponseHeader("Last-Modified")),0===n.indexOf("#EXTM3U"))if(n.indexOf("#EXTINF:")>0)if(null===this.id)a.trigger(e.default.MANIFEST_LOADED,{levels:[{url:r}],url:r,stats:i});else{var d=this.parseLevelPlaylist(n,r,l);i.tparsed=performance.now(),a.trigger(e.default.LEVEL_LOADED,{details:d,level:l,id:u,stats:i})}else o=this.parseMasterPlaylist(n,r),o.length?a.trigger(e.default.MANIFEST_LOADED,{levels:o,url:r,stats:i}):a.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:r,reason:"no level found in manifest"});else a.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:r,reason:"no EXTM3U delimiter"})}},{key:"loaderror",value:function(a){var r,i;null===this.id?(r=t.ErrorDetails.MANIFEST_LOAD_ERROR,i=!0):(r=t.ErrorDetails.LEVEL_LOAD_ERROR,i=!1),this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:r,fatal:i,url:this.url,loader:this.loader,response:a.currentTarget,level:this.id,id:this.id2})}},{key:"loadtimeout",value:function(){var r,i;null===this.id?(r=t.ErrorDetails.MANIFEST_LOAD_TIMEOUT,i=!0):(r=t.ErrorDetails.LEVEL_LOAD_TIMEOUT,i=!1),this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:r,fatal:i,url:this.url,loader:this.loader,level:this.id,id:this.id2})}}]),r}();i.default=o,s.exports=i.default},{"../errors":16,"../events":17,"../utils/url":27}],23:[function(n,t,e){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function e(i,r){for(var t=0;t>24&255,t>>16&255,t>>8&255,255&t,r>>24,r>>16&255,r>>8&255,255&r,85,196,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value:function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))}},{key:"moof",value:function(t,r,i){return e.box(e.types.moof,e.mfhd(t),e.traf(i,r))}},{key:"moov",value:function(t){for(var r=t.length,i=[];r--;)i[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(e.mvex(t)))}},{key:"mvex",value:function(r){for(var t=r.length,i=[];t--;)i[t]=e.trex(r[t]);return e.box.apply(null,[e.types.mvex].concat(i))}},{key:"mvhd",value:function(t,r){var i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,t>>24&255,t>>16&255,t>>8&255,255&t,r>>24&255,r>>16&255,r>>8&255,255&r,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 e.box(e.types.mvhd,i)}},{key:"sdtp",value:function(n){var r,t,i=n.samples||[],a=new Uint8Array(4+i.length);for(t=0;t>>8&255),i.push(255&n),i=i.concat(Array.prototype.slice.call(a));for(r=0;r>>8&255),s.push(255&n),s=s.concat(Array.prototype.slice.call(a));var o=e.box(e.types.avcC,new Uint8Array([1,i[3],i[4],i[5],255,224|t.sps.length].concat(i).concat([t.pps.length]).concat(s)));return e.box(e.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,t.width>>8&255,255&t.width,t.height>>8&255,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,19,118,105,100,101,111,106,115,45,99,111,110,116,114,105,98,45,104,108,115,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value:function(e){return new Uint8Array([0,0,0,0,3,23+e.config.length,0,1,0,4,15+e.config.length,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([e.config.length]).concat(e.config).concat([6,1,2]))}},{key:"mp4a",value:function(t){return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,t.audiosamplerate>>8&255,255&t.audiosamplerate,0,0]),e.box(e.types.esds,e.esds(t)))}},{key:"stsd",value:function(t){return"audio"===t.type?e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,t.id>>24&255,t.id>>16&255,t.id>>8&255,255&t.id,0,0,0,0,t.duration>>24,t.duration>>16&255,t.duration>>8&255,255&t.duration,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,t.width>>8&255,255&t.width,0,0,t.height>>8&255,255&t.height,0,0]))}},{key:"traf",value:function(t,r){var i=e.sdtp(t);return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,t.id>>24,t.id>>16&255,t.id>>8&255,255&t.id])),e.box(e.types.tfdt,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])),e.trun(t,i.length+16+16+8+16+8+8),i)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t.id>>24,t.id>>16&255,t.id>>8&255,255&t.id,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(s,i){var r,t,a,n;for(r=s.samples||[],n=new Uint8Array(12+16*r.length),i+=8+n.byteLength,n.set([0,0,15,1,r.length>>>24&255,r.length>>>16&255,r.length>>>8&255,255&r.length,i>>>24&255,i>>>16&255,i>>>8&255,255&i],0),a=0;a>>24&255,t.duration>>>16&255,t.duration>>>8&255,255&t.duration,t.size>>>24&255,t.size>>>16&255,t.size>>>8&255,255&t.size,t.flags.isLeading<<2|t.flags.dependsOn,t.flags.isDependedOn<<6|t.flags.hasRedundancy<<4|t.flags.paddingValue<<1|t.flags.isNonSync,61440&t.flags.degradPrio,15&t.flags.degradPrio,t.cts>>>24&255,t.cts>>>16&255,t.cts>>>8&255,255&t.cts],12+16*a);return e.box(e.types.trun,n)}},{key:"initSegment",value:function(i){e.types||e.init();var t,r=e.moov(i);return t=new Uint8Array(e.FTYP.byteLength+r.byteLength),t.set(e.FTYP),t.set(r,e.FTYP.byteLength),t}}]),e}();e.default=a,t.exports=e.default},{}],24:[function(i,h,a){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(a,"__esModule",{value:!0});var d=function(){function e(i,r){for(var t=0;t1?r.logger.log("AVC:"+l+" ms hole between fragments detected,filling it"):-1>l&&r.logger.log("AVC:"+-l+" ms overlapping between fragments detected"),a=g,s=Math.max(s-l,a),r.logger.log("Video/PTS/DTS adjusted:"+s+"/"+a)),A=Math.max(0,s),_=Math.max(0,a)}i={size:E,duration:0,cts:(s-a)/h,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0}},d.key===!0?(i.flags.dependsOn=2,i.flags.isNonSync=0):(i.flags.dependsOn=1,i.flags.isNonSync=1),o.push(i),c=a}o.length>=2&&(i.duration=o[o.length-2].duration),this.nextAvcDts=a+i.duration*h,n.len=0,n.nbNalu=0,navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&(o[0].flags.dependsOn=2,o[0].flags.isNonSync=0),n.samples=o,R=t.default.moof(n.sequenceNumber++,_/h,n),n.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:R,mdat:u,startPTS:A/v,endPTS:(s+h*i.duration)/v,startDTS:_/v,endDTS:(a+h*i.duration)/v,type:"video",nb:o.length})}},{key:"remuxAudio",value:function(a,L,R){var _,d,i,v,l,E,b,y,h,m,p,u,s,A=8,f=this.PES_TIMESCALE,g=this.PES2MP4SCALEFACTOR,o=[];for(l=new Uint8Array(a.len+8),_=new DataView(l.buffer),_.setUint32(0,l.byteLength),l.set(t.default.types.mdat,4);a.samples.length;){if(d=a.samples.shift(),v=d.unit,l.set(v,A),A+=v.byteLength,m=d.pts-this._initDTS,p=d.dts-this._initDTS,void 0!==h)u=this._PTSNormalize(m,h),s=this._PTSNormalize(p,h),i.duration=(s-h)/g,i.duration<0&&(r.logger.log("invalid AAC sample duration at PTS:"+d.pts+":"+i.duration),i.duration=0);else{var n,c=this.nextAacPts;u=this._PTSNormalize(m,c),s=this._PTSNormalize(p,c),n=Math.round(1e3*(u-c)/f),(R||Math.abs(n)<600)&&n&&(n>1?r.logger.log(n+" ms hole between AAC samples detected,filling it"):-1>n&&r.logger.log(-n+" ms overlapping between AAC samples detected"),u=s=c),b=Math.max(0,u),y=Math.max(0,s)}i={size:v.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},o.push(i),h=s}o.length>=2&&(i.duration=o[o.length-2].duration),this.nextAacPts=u+g*i.duration,a.len=0,a.samples=o,E=t.default.moof(a.sequenceNumber++,y/g,a),a.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:E,mdat:l,startPTS:b/f,endPTS:this.nextAacPts/f,startDTS:y/f,endDTS:(s+g*i.duration)/f,type:"audio",nb:o.length})}},{key:"remuxID3",value:function(r,a){var t,n=r.samples.length;if(n){for(var i=0;n>i;i++)t=r.samples[i],t.pts=(t.pts-this._initPTS)/this.PES_TIMESCALE,t.dts=(t.dts-this._initDTS)/this.PES_TIMESCALE;this.observer.trigger(e.default.FRAG_PARSING_METADATA,{samples:r.samples})}r.samples=[],a=a}},{key:"_PTSNormalize",value:function(e,t){var r;if(void 0===t)return e;for(r=e>t?-8589934592:8589934592;Math.abs(e-t)>4294967296;)e+=r;return e}},{key:"timescale",get:function(){return this.MP4_TIMESCALE}}]),i}();a.default=o,h.exports=a.default},{"../errors":16,"../events":17,"../remux/mp4-generator":23,"../utils/logger":26}],25:[function(r,e,i){"use strict";var t={search:function(a,s){for(var t=0,r=a.length-1,e=null,i=null;r>=t;){e=(t+r)/2|0,i=a[e];var n=s(i);if(n>0)t=e+1;else{if(!(0>n))return i;r=e-1}}return null}};e.exports=t},{}],26:[function(d,u,r){"use strict";function e(){}function l(t,e){return e="["+t+"] > "+e}function a(t){var r=window.console[t];return r?function(){for(var a=arguments.length,e=Array(a),i=0;a>i;i++)e[i]=arguments[i];e[0]&&(e[0]=l(t,e[0])),r.apply(window.console,e)}:e}function s(r){for(var i=arguments.length,n=Array(i>1?i-1:0),e=1;i>e;e++)n[e-1]=arguments[e];n.forEach(function(e){t[e]=r[e]?r[e].bind(r):a(e)})}Object.defineProperty(r,"__esModule",{value:!0});var i={trace:e,debug:e,log:e,warn:e,info:e,error:e},t=i,n=function(e){if(e===!0||"object"==typeof e){s(e,"debug","log","info","warn","error");try{t.log()}catch(e){t=i}}else t=i};r.enableLogs=n;var o=t;r.logger=o},{}],27:[function(r,t,i){"use strict";var e={buildAbsoluteURL:function(i,t){if(t=t.trim(),/^[a-z]+:/i.test(t))return t;var a=null,n=null,s=/^([^#]*)(.*)$/.exec(t);s&&(n=s[2],t=s[1]);var o=/^([^\?]*)(.*)$/.exec(t);o&&(a=o[2],t=o[1]);var u=/^([^#]*)(.*)$/.exec(i);u&&(i=u[1]);var d=/^([^\?]*)(.*)$/.exec(i);d&&(i=d[1]);var l=/^((([a-z]+):)?\/\/[a-z0-9\.-]+(:[0-9]+)?\/)(.*)$/i.exec(i),c=l[3],h=l[1],f=l[5],r=null;if(/^\/\//.test(t))r=c+"://"+e.buildAbsolutePath("",t.substring(2));else if(/^\//.test(t))r=h+e.buildAbsolutePath("",t.substring(1));else{var g=e.buildAbsolutePath(f,t);r=h+g}return a&&(r+=a),n&&(r+=n),r},buildAbsolutePath:function(n,s){for(var i,e,o=s,a="",t=n.replace(/[^\/]*$/,o.replace(/(\/|^)(?:\.?\/+)+/g,"$1")),r=0;e=t.indexOf("/../",r),e>-1;r=e+i)i=/^\/(?:\.\.\/)*/.exec(t.slice(e))[0].length,a=(a+t.substring(r,e)).replace(new RegExp("(?:\\/+[^\\/]*){0,"+(i-1)/3+"}$"),"/");return a+t.substr(r)}};t.exports=e},{}],28:[function(r,i,e){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(i,r){for(var t=0;t