diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2015-11-30 20:14:16 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2016-01-08 20:38:18 +0100 |
commit | 2a5bc9636647c1beeb58f3f0b3f2bcecb3509d16 (patch) | |
tree | cb1abc4fc90e9341b614114136e8be3d98c33e97 /mediabrowser/assets/hls.min.js | |
download | flask-mediabrowser-2a5bc9636647c1beeb58f3f0b3f2bcecb3509d16.tar.gz flask-mediabrowser-2a5bc9636647c1beeb58f3f0b3f2bcecb3509d16.zip |
poc
Diffstat (limited to 'mediabrowser/assets/hls.min.js')
-rw-r--r-- | mediabrowser/assets/hls.min.js | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/mediabrowser/assets/hls.min.js b/mediabrowser/assets/hls.min.js new file mode 100644 index 0000000..d49bd4c --- /dev/null +++ b/mediabrowser/assets/hls.min.js @@ -0,0 +1,3 @@ +!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 n(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(s)return s(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,n,e,t,r)}return t[a].exports}for(var s="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(n,a,o){function e(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function t(e){return"function"==typeof e}function s(e){return"number"==typeof e}function r(e){return"object"==typeof e&&null!==e}function i(e){return void 0===e}a.exports=e,e.EventEmitter=e,e.prototype._events=void 0,e.prototype._maxListeners=void 0,e.defaultMaxListeners=10,e.prototype.setMaxListeners=function(e){if(!s(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},e.prototype.emit=function(u){var o,a,s,n,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(s=arguments.length,n=new Array(s-1),e=1;s>e;e++)n[e-1]=arguments[e];a.apply(this,n)}else if(r(a)){for(s=arguments.length,n=new Array(s-1),e=1;s>e;e++)n[e-1]=arguments[e];for(l=a.slice(),s=l.length,e=0;s>e;e++)l[e].apply(this,n)}return!0},e.prototype.addListener=function(a,s){var n;if(!t(s))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,t(s.listener)?s.listener:s),this._events[a]?r(this._events[a])?this._events[a].push(s):this._events[a]=[this._events[a],s]:this._events[a]=s,r(this._events[a])&&!this._events[a].warned){var n;n=i(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[a].length>n&&(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,n,o,s;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,n=-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(s=o;s-->0;)if(e[s]===i||e[s].listener&&e[s].listener===i){n=s;break}if(0>n)return this;1===e.length?(e.length=0,delete this._events[a]):e.splice(n,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(s,i,n){var a=arguments[3],e=arguments[4],r=arguments[5],t=JSON.stringify;i.exports=function(u){for(var i,o=Object.keys(r),s=0,l=o.length;l>s;s++){var n=o[s];if(r[n].exports===u){i=n;break}}if(!i){i=Math.floor(Math.pow(16,8)*Math.random()).toString(16);for(var d={},s=0,l=o.length;l>s;s++){var n=o[s];d[n]=n}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 s(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<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),o=r("../events"),t=a(o),l=function(){function e(r){s(this,e),this.hls=r,this.lastfetchlevel=0,this._autoLevelCapping=-1,this._nextAutoLevel=-1,this.onflp=this.onFragmentLoadProgress.bind(this),r.on(t.default.FRAG_LOAD_PROGRESS,this.onflp)}return n(e,[{key:"destroy",value:function(){this.hls.off(t.default.FRAG_LOAD_PROGRESS,this.onflp)}},{key:"onFragmentLoadProgress",value:function(r,t){var e=t.stats;void 0===e.aborted&&(this.lastfetchduration=(performance.now()-e.trequest)/1e3,this.lastfetchlevel=t.frag.level,this.lastbw=8*e.loaded/this.lastfetchduration)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping=e}},{key:"nextAutoLevel",get:function(){var r,e,t,i=this.lastbw,a=this.hls;if(t=-1===this._autoLevelCapping?a.levels.length-1:this._autoLevelCapping,-1!==this._nextAutoLevel){var s=Math.min(this._nextAutoLevel,t);if(s!==this.lastfetchlevel)return s;this._nextAutoLevel=-1}for(e=0;t>=e;e++)if(r=e<=this.lastfetchlevel?.8*i:.7*i,r<a.levels[e].bitrate)return Math.max(0,e-1);return e-1},set:function(e){this._nextAutoLevel=e}}]),e}();e.default=l,i.exports=e.default},{"../events":12}],4:[function(i,s,a){"use strict";function l(e){return e&&e.__esModule?e:{default:e}}function u(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;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),n=i("../events"),e=l(n),r=i("../utils/logger"),t=i("../errors"),o=function(){function i(t){u(this,i),this.hls=t,this.onml=this.onManifestLoaded.bind(this),this.onll=this.onLevelLoaded.bind(this),this.onerr=this.onError.bind(this),this.ontick=this.tick.bind(this),t.on(e.default.MANIFEST_LOADED,this.onml),t.on(e.default.LEVEL_LOADED,this.onll),t.on(e.default.ERROR,this.onerr),this._manualLevel=this._autoLevelCapping=-1}return d(i,[{key:"destroy",value:function(){var t=this.hls;t.off(e.default.MANIFEST_LOADED,this.onml),t.off(e.default.LEVEL_LOADED,this.onll),t.off(e.default.ERROR,this.onerr),this.timer&&clearInterval(this.timer),this._manualLevel=-1}},{key:"onManifestLoaded",value:function(d,n){var s,i,a=[],t=[],o={},l=!1,u=!1;for(n.levels.forEach(function(e){e.videoCodec&&(l=!0),e.audioCodec&&(u=!0);var r=o[e.bitrate];void 0===r?(o[e.bitrate]=t.length,e.url=[e.url],e.urlId=0,a.push(e)):a[r].url.push(e.url)}),l&&u?a.forEach(function(e){e.videoCodec&&t.push(e)}):t=a,s=t[0].bitrate,t.sort(function(e,t){return e.bitrate-t.bitrate}),this._levels=t,i=0;i<t.length;i++)if(t[i].bitrate===s){this._firstLevel=i,r.logger.log("manifest loaded,"+t.length+" level(s) found, first bitrate:"+s);break}this.hls.trigger(e.default.MANIFEST_PARSED,{levels:this._levels,firstLevel:this._firstLevel,stats:n.stats})}},{key:"setLevelInternal",value:function(i){if(i>=0&&i<this._levels.length){this.timer&&(clearInterval(this.timer),this.timer=null),this._level=i,r.logger.log("switching to level "+i),this.hls.trigger(e.default.LEVEL_SWITCH,{level:i});var a=this._levels[i];if(void 0===a.details||a.details.live===!0){r.logger.log("(re)loading playlist for level "+i);var s=a.urlId;this.hls.trigger(e.default.LEVEL_LOADING,{url:a.url[s],level:i,id:s})}}else this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.OTHER_ERROR,details:t.ErrorDetails.LEVEL_SWITCH_ERROR,level:i,fatal:!1,reason:"invalid level idx"})}},{key:"onError",value:function(o,i){if(!i.fatal){var a,e,s=i.details,n=this.hls;switch(s){case t.ErrorDetails.FRAG_LOAD_ERROR:case t.ErrorDetails.FRAG_LOAD_TIMEOUT:case t.ErrorDetails.FRAG_LOOP_LOADING_ERROR:case t.ErrorDetails.KEY_LOAD_ERROR:case t.ErrorDetails.KEY_LOAD_TIMEOUT:a=i.frag.level;break;case t.ErrorDetails.LEVEL_LOAD_ERROR:case t.ErrorDetails.LEVEL_LOAD_TIMEOUT:a=i.level}if(void 0!==a)if(e=this._levels[a],e.urlId<e.url.length-1)e.urlId++,e.details=void 0,r.logger.warn("level controller,"+s+" for level "+a+": switching to redundant stream id "+e.urlId);else{var l=-1===this._manualLevel&&a;l?(r.logger.warn("level controller,"+s+": emergency switch-down for next fragment"),n.abrController.nextAutoLevel=0):e&&e.details&&e.details.live?r.logger.warn("level controller,"+s+" on live stream, discard"):(r.logger.error("cannot recover "+s+" error"),this._level=void 0,this.timer&&(clearInterval(this.timer),this.timer=null),i.fatal=!0,n.trigger(o,i))}}}},{key:"onLevelLoaded",value:function(t,e){e.details.live&&!this.timer&&(this.timer=setInterval(this.ontick,1e3*e.details.targetduration)),!e.details.live&&this.timer&&(clearInterval(this.timer),this.timer=null)}},{key:"tick",value:function(){var t=this._level;if(void 0!==t){var r=this._levels[t],i=r.urlId;this.hls.trigger(e.default.LEVEL_LOADING,{url:r.url[i],level:t,id:i})}}},{key:"nextLoadLevel",value:function(){return-1!==this._manualLevel?this._manualLevel:this.hls.abrController.nextAutoLevel}},{key:"levels",get:function(){return this._levels}},{key:"level",get:function(){return this._level},set:function(e){(this._level!==e||void 0===this._levels[e].details)&&this.setLevelInternal(e)}},{key:"manualLevel",get:function(){return this._manualLevel},set:function(e){this._manualLevel=e,-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){return void 0===this._startLevel?this._firstLevel:this._startLevel},set:function(e){this._startLevel=e}}]),i}();a.default=o,s.exports=a.default},{"../errors":11,"../events":12,"../utils/logger":21}],5:[function(a,u,n){"use strict";function s(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(n,"__esModule",{value:!0});var g=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),h=a("../demux/demuxer"),v=s(h),p=a("../events"),r=s(p),t=a("../utils/logger"),l=a("../utils/binary-search"),f=s(l),c=a("../helper/level-helper"),o=s(c),i=a("../errors"),e={ERROR:-2,STARTING:-1,IDLE:0,KEY_LOADING:1,FRAG_LOADING:2,WAITING_LEVEL:3,PARSING:4,PARSED:5,APPENDING:6,BUFFER_FLUSHING:7},y=function(){function a(e){d(this,a),this.config=e.config,this.hls=e,this.onsbue=this.onSBUpdateEnd.bind(this),this.onsbe=this.onSBUpdateError.bind(this),this.onmediaatt0=this.onMediaAttaching.bind(this),this.onmediadet0=this.onMediaDetaching.bind(this),this.onmp=this.onManifestParsed.bind(this),this.onll=this.onLevelLoaded.bind(this),this.onfl=this.onFragLoaded.bind(this),this.onkl=this.onKeyLoaded.bind(this),this.onis=this.onInitSegment.bind(this),this.onfpg=this.onFragParsing.bind(this),this.onfp=this.onFragParsed.bind(this),this.onerr=this.onError.bind(this),this.ontick=this.tick.bind(this),e.on(r.default.MEDIA_ATTACHING,this.onmediaatt0),e.on(r.default.MEDIA_DETACHING,this.onmediadet0),e.on(r.default.MANIFEST_PARSED,this.onmp)}return g(a,[{key:"destroy",value:function(){this.stop();var t=this.hls;t.off(r.default.MEDIA_ATTACHING,this.onmediaatt0),t.off(r.default.MEDIA_DETACHING,this.onmediadet0),t.off(r.default.MANIFEST_PARSED,this.onmp),this.state=e.IDLE}},{key:"startLoad",value:function(){this.levels&&this.media?(this.startInternal(),this.lastCurrentTime?(t.logger.log("seeking @ "+this.lastCurrentTime),this.lastPaused||(t.logger.log("resuming video"),this.media.play()),this.state=e.IDLE):(this.lastCurrentTime=0,this.state=e.STARTING),this.nextLoadPosition=this.startPosition=this.lastCurrentTime,this.tick()):t.logger.warn("cannot start loading as either manifest not parsed or video not attached")}},{key:"startInternal",value:function(){var e=this.hls;this.stop(),this.demuxer=new v.default(e),this.timer=setInterval(this.ontick,100),this.level=-1,e.on(r.default.FRAG_LOADED,this.onfl),e.on(r.default.FRAG_PARSING_INIT_SEGMENT,this.onis),e.on(r.default.FRAG_PARSING_DATA,this.onfpg),e.on(r.default.FRAG_PARSED,this.onfp),e.on(r.default.ERROR,this.onerr),e.on(r.default.LEVEL_LOADED,this.onll),e.on(r.default.KEY_LOADED,this.onkl)}},{key:"stop",value:function(){this.mp4segments=[],this.flushRange=[],this.bufferRange=[];var t=this.fragCurrent;if(t&&(t.loader&&t.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.sourceBuffer){for(var a in this.sourceBuffer){var i=this.sourceBuffer[a];try{this.mediaSource.removeSourceBuffer(i),i.removeEventListener("updateend",this.onsbue),i.removeEventListener("error",this.onsbe)}catch(e){}}this.sourceBuffer=null}this.timer&&(clearInterval(this.timer),this.timer=null),this.demuxer&&(this.demuxer.destroy(),this.demuxer=null);var e=this.hls;e.off(r.default.FRAG_LOADED,this.onfl),e.off(r.default.FRAG_PARSED,this.onfp),e.off(r.default.FRAG_PARSING_DATA,this.onfpg),e.off(r.default.LEVEL_LOADED,this.onll),e.off(r.default.KEY_LOADED,this.onkl),e.off(r.default.FRAG_PARSING_INIT_SEGMENT,this.onis),e.off(r.default.ERROR,this.onerr)}},{key:"tick",value:function(){var h,l,s,o=this.hls;switch(this.state){case e.ERROR:break;case e.STARTING:this.startLevel=o.startLevel,-1===this.startLevel&&(this.startLevel=0,this.fragBitrateTest=!0),this.level=o.nextLoadLevel=this.startLevel,this.state=e.WAITING_LEVEL,this.loadedmetadata=!1;break;case e.IDLE:if(!this.media)break;h=this.loadedmetadata?this.media.currentTime:this.nextLoadPosition,l=this.startFragmentRequested===!1?this.startLevel:o.nextLoadLevel;var g,D=this.bufferInfo(h,.3),I=D.len,d=D.end,c=this.fragPrevious;if(this.levels[l].hasOwnProperty("bitrate")?(g=Math.max(8*this.config.maxBufferSize/this.levels[l].bitrate,this.config.maxBufferLength),g=Math.min(g,this.config.maxMaxBufferLength)):g=this.config.maxBufferLength,g>I){if(o.nextLoadLevel=l,this.level=l,s=this.levels[l].details,"undefined"==typeof s){this.state=e.WAITING_LEVEL;break}var u=s.fragments,y=u.length,v=u[0].start,O=u[y-1].start+u[y-1].duration,a=void 0;if(s.live){if(d<Math.max(v,O-this.config.liveMaxLatencyDurationCount*s.targetduration)&&(this.seekAfterBuffered=v+Math.max(0,s.totalduration-this.config.liveSyncDurationCount*s.targetduration),t.logger.log("buffer end: "+d+" is located too far from the end of live sliding playlist, media position will be reseted to: "+this.seekAfterBuffered.toFixed(3)),d=this.seekAfterBuffered),this.startFragmentRequested&&!s.PTSKnown){if(c){var E=c.sn+1;E>=s.startSN&&E<=s.endSN&&(a=u[E-s.startSN],t.logger.log("live playlist, switching playlist, load frag with next SN: "+a.sn))}a||(a=u[Math.round(y/2)],t.logger.log("live playlist, switching playlist, unknown, load middle frag : "+a.sn))}}else v>d&&(a=u[0]);if(!a){if(d>O)break;var R=f.default.search(u,function(e){return e.start+e.duration<=d?1:e.start>d?-1:0});R&&(a=R,v=R.start,c&&a.level===c.level&&a.sn===c.sn&&(a.sn<s.endSN?(a=u[a.sn+1-s.startSN],t.logger.log("SN just loaded, load next one: "+a.sn)):a=null))}if(a)if(null!=a.decryptdata.uri&&null==a.decryptdata.key)t.logger.log("Loading key for "+a.sn+" of ["+s.startSN+" ,"+s.endSN+"],level "+l),this.state=e.KEY_LOADING,o.trigger(r.default.KEY_LOADING,{frag:a});else{if(t.logger.log("Loading "+a.sn+" of ["+s.startSN+" ,"+s.endSN+"],level "+l+", currentTime:"+h+",bufferEnd:"+d.toFixed(3)),a.autoLevel=o.autoLevelEnabled,this.levels.length>1&&(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 T=this.config.fragLoadingLoopThreshold;if(a.loadCounter>T&&Math.abs(this.fragLoadIdx-a.loadIdx)<T)return void o.trigger(r.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_LOOP_LOADING_ERROR,fatal:!1,frag:a})}else a.loadCounter=1;a.loadIdx=this.fragLoadIdx,this.fragCurrent=a,this.startFragmentRequested=!0,o.trigger(r.default.FRAG_LOADING,{frag:a}),this.state=e.FRAG_LOADING}}break;case e.WAITING_LEVEL:l=this.levels[this.level],l&&l.details&&(this.state=e.IDLE);break;case e.FRAG_LOADING:var A=this.media,n=this.fragCurrent;if(A&&(!A.paused||this.loadedmetadata===!1)&&n.autoLevel&&this.level&&this.levels.length>1){var b=performance.now()-n.trequest;if(b>500*n.duration){var S=1e3*n.loaded/b;n.expectedLen<n.loaded&&(n.expectedLen=n.loaded),h=A.currentTime;var _=(n.expectedLen-n.loaded)/S,L=this.bufferInfo(h,.3).end-h,k=n.duration*this.levels[o.nextLoadLevel].bitrate/(8*S);L<2*n.duration&&_>L&&_>k&&(t.logger.warn("loading too slow, abort fragment loading"),t.logger.log("fragLoadedDelay/bufferStarvationDelay/fragLevelNextLoadedDelay :"+_.toFixed(1)+"/"+L.toFixed(1)+"/"+k.toFixed(1)),n.loader.abort(),o.trigger(r.default.FRAG_LOAD_EMERGENCY_ABORTED,{frag:n}),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 m=this.mp4segments.shift();try{this.sourceBuffer[m.type].appendBuffer(m.data),this.appendError=0}catch(a){this.mp4segments.unshift(m),this.appendError?this.appendError++:this.appendError=1;var p={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"),p.fatal=!0,o.trigger(r.default.ERROR,p),void(this.state=e.ERROR);p.fatal=!1,o.trigger(r.default.ERROR,p)}this.state=e.APPENDING}}else this.state=e.IDLE;break;case e.BUFFER_FLUSHING:for(;this.flushRange.length;){var w=this.flushRange[0];if(!this.flushBuffer(w.start,w.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,s=this.media,t=s.buffered,r=[];for(e=0;e<t.length;e++)r.push({start:t.start(e),end:t.end(e)});return this.bufferedInfo(r,i,a)}},{key:"bufferedInfo",value:function(r,i,n){var o,l,a,f,e,t=[];for(r.sort(function(e,t){var r=e.start-t.start;return r?r:t.end-e.end}),e=0;e<r.length;e++){var u=t.length;if(u){var d=t[u-1].end;r[e].start-d<n?r[e].end>d&&(t[u-1].end=r[e].end):t.push(r[e])}else t.push(r[e])}for(e=0,o=0,l=a=i;e<t.length;e++){var s=t[e].start,h=t[e].end;i+n>=s&&h>i?(l=s,a=h,o=a-i):s>i+n&&(f=s)}return{len:o,start:l,end:a,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.length;e++)if(r>=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,n,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<r.buffered.length;e++)if(o=r.buffered.start(e),n=r.buffered.end(e),-1!==navigator.userAgent.toLowerCase().indexOf("firefox")&&l===Number.POSITIVE_INFINITY?(i=d,a=l):(i=Math.max(o,d),a=Math.min(n,l)),a-i>.5)return t.logger.log("flush "+u+" ["+i+","+a+"], of ["+o+","+n+"], pos:"+this.media.currentTime),r.remove(i,a),!1}var s,h=[];for(e=0;e<this.bufferRange.length;e++)s=this.bufferRange[e],this.isBuffered((s.start+s.end)/2)&&h.push(s);return this.bufferRange=h,t.logger.log("buffer flushed"),!0}},{key:"immediateLevelSwitch",value:function(){t.logger.log("immediateLevelSwitch"),this.immediateSwitch||(this.immediateSwitch=!0,this.previouslyPaused=this.media.paused,this.media.pause());var r=this.fragCurrent;r&&r.loader&&r.loader.abort(),this.fragCurrent=null,this.flushBufferCounter=0,this.flushRange.push({start:0,end:Number.POSITIVE_INFINITY}),this.state=e.BUFFER_FLUSHING,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold,this.tick()}},{key:"immediateLevelSwitchEnd",value:function(){this.immediateSwitch=!1,this.media.currentTime-=1e-4,this.previouslyPaused||this.media.play()}},{key:"nextLevelSwitch",value:function(){var r,i,t;if(i=this.getBufferRange(this.media.currentTime),i&&this.flushRange.push({start:0,end:i.start-1}),this.media.paused)r=0;else{var n=this.hls.nextLoadLevel,o=this.levels[n],s=this.fragLastKbps;r=s&&this.fragCurrent?this.fragCurrent.duration*o.bitrate/(1e3*s)+1:0}if(t=this.getBufferRange(this.media.currentTime+r),t&&(t=this.followingBufferRange(t))){this.flushRange.push({start:t.start,end:Number.POSITIVE_INFINITY});var a=this.fragCurrent;a&&a.loader&&a.loader.abort(),this.fragCurrent=null}this.flushRange.length&&(this.flushBufferCounter=0,this.state=e.BUFFER_FLUSHING,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold,this.tick())}},{key:"onMediaAttaching",value:function(i,t){var r=this.media=t.media,e=this.mediaSource=new MediaSource;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),r.src=URL.createObjectURL(e)}},{key:"onMediaDetaching",value:function(){var e=this.media;e&&e.ended&&(t.logger.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0);var a=this.levels;a&&a.forEach(function(e){e.details&&e.details.fragments.forEach(function(e){e.loadCounter=void 0})});var i=this.mediaSource;i&&("open"===i.readyState&&i.endOfStream(),i.removeEventListener("sourceopen",this.onmso),i.removeEventListener("sourceended",this.onmse),i.removeEventListener("sourceclose",this.onmsc),this.media.src="",this.mediaSource=null,e&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("seeked",this.onvseeked),e.removeEventListener("loadedmetadata",this.onvmetadata),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvmetadata=null),this.media=null,this.loadedmetadata=!1,this.stop()),this.onmso=this.onmse=this.onmsc=null,this.hls.trigger(r.default.MEDIA_DETACHED)}},{key:"onMediaSeeking",value:function(){if(this.state===e.FRAG_LOADING&&0===this.bufferInfo(this.media.currentTime,.3).len){t.logger.log("seeking outside of buffer while fragment load in progress, cancel fragment load");var r=this.fragCurrent;r&&(r.loader&&r.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.state=e.IDLE}this.media&&(this.lastCurrentTime=this.media.currentTime),void 0!==this.fragLoadIdx&&(this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold),this.tick()}},{key:"onMediaSeeked",value:function(){this.tick()}},{key:"onMediaMetadata",value:function(){this.media.currentTime!==this.startPosition&&(this.media.currentTime=this.startPosition),this.loadedmetadata=!0,this.tick()}},{key:"onMediaEnded",value:function(){t.logger.log("media ended"),this.startPosition=this.lastCurrentTime=0}},{key:"onManifestParsed",value:function(s,r){var e,i=!1,a=!1;r.levels.forEach(function(t){e=t.codecs,e&&(-1!==e.indexOf("mp4a.40.2")&&(i=!0),-1!==e.indexOf("mp4a.40.5")&&(a=!0))}),this.audiocodecswitch=i&&a,this.audiocodecswitch&&t.logger.log("both AAC/HE-AAC audio found in levels; declaring audio codec as HE-AAC"),this.levels=r.levels,this.startLevelLoaded=!1,this.startFragmentRequested=!1,this.media&&this.config.autoStartLoad&&this.startLoad()}},{key:"onLevelLoaded",value:function(d,s){var i=s.details,a=s.level,n=this.levels[a],l=i.totalduration;if(t.logger.log("level "+a+" loaded ["+i.startSN+","+i.endSN+"],duration:"+l),i.live){var u=n.details;u?(o.default.mergeDetails(u,i),i.PTSKnown?t.logger.log("live playlist sliding:"+i.fragments[0].start.toFixed(3)):t.logger.log("live playlist - outdated PTS, unknown sliding")):(i.PTSKnown=!1,t.logger.log("live playlist - first load, unknown sliding"))}else i.PTSKnown=!1;n.details=i,this.hls.trigger(r.default.LEVEL_UPDATED,{details:i,level:a}),this.startLevelLoaded===!1&&(i.live&&(this.startPosition=Math.max(0,l-this.config.liveSyncDurationCount*i.targetduration)),this.nextLoadPosition=this.startPosition,this.startLevelLoaded=!0),this.state===e.WAITING_LEVEL&&(this.state=e.IDLE),this.tick()}},{key:"onKeyLoaded",value:function(){this.state===e.KEY_LOADING&&(this.state=e.IDLE,this.tick())}},{key:"onFragLoaded",value:function(h,a){var i=this.fragCurrent;if(this.state===e.FRAG_LOADING&&i&&a.frag.level===i.level&&a.frag.sn===i.sn)if(this.fragBitrateTest===!0)this.state=e.IDLE,this.fragBitrateTest=!1,a.stats.tparsed=a.stats.tbuffered=performance.now(),this.hls.trigger(r.default.FRAG_BUFFERED,{stats:a.stats,frag:i});else{this.state=e.PARSING,this.stats=a.stats;var s=this.levels[this.level],n=s.details,u=n.totalduration,d=i.start,o=i.level,l=i.sn;t.logger.log("Demuxing "+l+" of ["+n.startSN+" ,"+n.endSN+"],level "+o),this.demuxer.push(a.payload,s.audioCodec,s.videoCodec,d,i.cc,o,l,u,i.decryptdata)}}},{key:"onInitSegment",value:function(o,r){if(this.state===e.PARSING){var a,i=this.levels[this.level].audioCodec,s=this.levels[this.level].videoCodec;(void 0===i||void 0===r.audiocodec)&&(i=r.audioCodec),(void 0===s||void 0===r.videocodec)&&(s=r.videoCodec);var n=navigator.userAgent.toLowerCase();this.audiocodecswitch&&1!==r.audioChannelCount&&-1===n.indexOf("android")&&-1===n.indexOf("firefox")&&(i="mp4a.40.5"),this.sourceBuffer||(this.sourceBuffer={},t.logger.log("selected A/V codecs for sourceBuffers:"+i+","+s),i&&(a=this.sourceBuffer.audio=this.mediaSource.addSourceBuffer("video/mp4;codecs="+i),a.addEventListener("updateend",this.onsbue),a.addEventListener("error",this.onsbe)),s&&(a=this.sourceBuffer.video=this.mediaSource.addSourceBuffer("video/mp4;codecs="+s),a.addEventListener("updateend",this.onsbue),a.addEventListener("error",this.onsbe))),i&&this.mp4segments.push({type:"audio",data:r.audioMoov}),s&&this.mp4segments.push({type:"video",data:r.videoMoov}),this.tick()}}},{key:"onFragParsing",value:function(n,i){if(this.state===e.PARSING){this.tparse2=Date.now();var a=this.levels[this.level],s=this.fragCurrent;t.logger.log("parsed data, type/startPTS/endPTS/startDTS/endDTS/nb:"+i.type+"/"+i.startPTS.toFixed(3)+"/"+i.endPTS.toFixed(3)+"/"+i.startDTS.toFixed(3)+"/"+i.endDTS.toFixed(3)+"/"+i.nb);var l=o.default.updateFragPTS(a.details,s.sn,i.startPTS,i.endPTS);this.hls.trigger(r.default.LEVEL_PTS_UPDATED,{details:a.details,level:this.level,drift:l}),this.mp4segments.push({type:i.type,data:i.moof}),this.mp4segments.push({type:i.type,data:i.mdat}),this.nextLoadPosition=i.endPTS,this.bufferRange.push({type:i.type,start:i.startPTS,end:i.endPTS,frag:s}),this.tick()}else t.logger.warn("not in PARSING state, discarding "+n)}},{key:"onFragParsed",value:function(){this.state===e.PARSING&&(this.state=e.PARSED,this.stats.tparsed=performance.now(),this.tick())}},{key:"onError",value:function(a,r){switch(r.details){case i.ErrorDetails.FRAG_LOAD_ERROR:case i.ErrorDetails.FRAG_LOAD_TIMEOUT:case i.ErrorDetails.FRAG_LOOP_LOADING_ERROR:case i.ErrorDetails.LEVEL_LOAD_ERROR:case i.ErrorDetails.LEVEL_LOAD_TIMEOUT:case i.ErrorDetails.KEY_LOAD_ERROR:case i.ErrorDetails.KEY_LOAD_TIMEOUT:t.logger.warn("buffer controller: "+r.details+" while loading frag,switch to "+(r.fatal?"ERROR":"IDLE")+" state ..."),this.state=r.fatal?e.ERROR:e.IDLE}}},{key:"onSBUpdateEnd",value:function(){if(this.state===e.APPENDING&&0===this.mp4segments.length){var a=this.fragCurrent,i=this.stats;if(a){this.fragPrevious=a,i.tbuffered=performance.now(),this.fragLastKbps=Math.round(8*i.length/(i.tbuffered-i.tfirst)),this.hls.trigger(r.default.FRAG_BUFFERED,{stats:i,frag:a}),t.logger.log("media buffered : "+this.timeRangesToString(this.media.buffered));var s=this.levels[this.level].details;if(s&&!s.live&&a.sn===s.endSN){var n=this.mediaSource;n&&"open"===n.readyState&&(t.logger.log("all media data available, signal endOfStream() to MediaSource"),n.endOfStream())}this.state=e.IDLE}}this.tick()}},{key:"_checkBuffer",value:function(){var e=this.media;if(e){var s=e.readyState;if(s){var i=this.seekAfterBuffered;if(i)e.duration>=i&&(e.currentTime=i,this.seekAfterBuffered=void 0);else if(3>s){var a=e.currentTime,n=this.bufferInfo(a,0);if(0===n.len){var r=n.nextStart;r&&.3>r-a&&(t.logger.log("adjust currentTime from "+a+" to "+r),e.currentTime=r)}}}}}},{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}();n.default=y,u.exports=n.default},{"../demux/demuxer":8,"../errors":11,"../events":12,"../helper/level-helper":13,"../utils/binary-search":20,"../utils/logger":21 +}],6:[function(e,n,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 s=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),h=e("../events"),o=r(h),i=e("../errors"),u=e("../demux/tsdemuxer"),a=r(u),l=function(){function e(t,r){d(this,e),this.hls=t,this.remuxer=r}return s(e,[{key:"destroy",value:function(){var e=this.demuxer;e&&e.destroy()}},{key:"push",value:function(t,r,s,n,l,u,d,h){var e=this.demuxer;if(!e){if(!a.default.probe(t))return void this.hls.trigger(o.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"no demux matching with content found"});e=this.demuxer=new a.default(this.hls,this.remuxer)}e.push(t,r,s,n,l,u,d,h)}},{key:"remux",value:function(){var e=this.demuxer;e&&e.remux()}}]),e}();t.default=l,n.exports=t.default},{"../demux/tsdemuxer":10,"../errors":11,"../events":12}],7:[function(t,n,i){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(i,"__esModule",{value:!0});var a=t("../demux/demuxer-inline"),s=r(a),f=t("../events"),e=r(f),l=t("events"),u=r(l),d=t("../remux/mp4-remuxer"),h=r(d),o=function(r){var t=new u.default;t.trigger=function(i){for(var r=arguments.length,a=Array(r>1?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 s.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,n.exports=i.default},{"../demux/demuxer-inline":6,"../events":12,"../remux/mp4-remuxer":19,events:1}],8:[function(t,v,s){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(s,"__esModule",{value:!0});var d=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),h=t("../events"),e=i(h),a=t("../errors"),u=t("../demux/demuxer-inline"),n=i(u),l=t("../demux/demuxer-worker"),f=i(l),r=t("../utils/logger"),g=t("../remux/mp4-remuxer"),o=i(g),p=function(){function i(e){if(c(this,i),this.hls=e,e.config.enableWorker&&"undefined"!=typeof Worker){r.logger.log("demuxing in webworker");try{var a=t("webworkify");this.w=a(f.default),this.onwmsg=this.onWorkerMessage.bind(this),this.w.addEventListener("message",this.onwmsg),this.w.postMessage({cmd:"init"})}catch(t){r.logger.error("error while initializing DemuxerWorker, fallback on DemuxerInline"),this.demuxer=new n.default(e,o.default)}}else this.demuxer=new n.default(e,o.default);this.demuxInitialized=!0}return d(i,[{key:"destroy",value:function(){this.w?(this.w.removeEventListener("message",this.onwmsg),this.w.terminate(),this.w=null):this.demuxer.destroy()}},{key:"pushDecrypted",value:function(e,t,r,i,a,s,n,o){this.w?this.w.postMessage({cmd:"demux",data:e,audioCodec:t,videoCodec:r,timeOffset:i,cc:a,level:s,sn:n,duration:o},[e]):this.demuxer.push(new Uint8Array(e),t,r,i,a,s,n,o)}},{key:"push",value:function(i,n,o,l,u,d,h,f,t){if(i.byteLength>0&&null!=t&&null!=t.key&&"AES-128"===t.method){var s=this;window.crypto.subtle.importKey("raw",t.key,{name:"AES-CBC",length:128},!1,["decrypt"]).then(function(c){window.crypto.subtle.decrypt({name:"AES-CBC",iv:t.iv.buffer},c,i).then(function(e){s.pushDecrypted(e,n,o,l,u,d,h,f)}).catch(function(t){r.logger.error("decrypting error : "+t.message),s.hls.trigger(e.default.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.FRAG_DECRYPT_ERROR,fatal:!0,reason:t.message})})}).catch(function(t){r.logger.error("decrypting error : "+t.message),s.hls.trigger(e.default.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.FRAG_DECRYPT_ERROR,fatal:!0,reason:t.message})})}else this.pushDecrypted(i,n,o,l,u,d,h,f)}},{key:"onWorkerMessage",value:function(t){switch(t.data.event){case e.default.FRAG_PARSING_INIT_SEGMENT:var r={};t.data.audioMoov&&(r.audioMoov=new Uint8Array(t.data.audioMoov),r.audioCodec=t.data.audioCodec,r.audioChannelCount=t.data.audioChannelCount),t.data.videoMoov&&(r.videoMoov=new Uint8Array(t.data.videoMoov),r.videoCodec=t.data.videoCodec,r.videoWidth=t.data.videoWidth,r.videoHeight=t.data.videoHeight),this.hls.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,r);break;case e.default.FRAG_PARSING_DATA:this.hls.trigger(e.default.FRAG_PARSING_DATA,{moof:new Uint8Array(t.data.moof),mdat:new Uint8Array(t.data.mdat),startPTS:t.data.startPTS,endPTS:t.data.endPTS,startDTS:t.data.startDTS,endDTS:t.data.endDTS,type:t.data.type,nb:t.data.nb});break;case e.default.FRAG_PARSING_METADATA:this.hls.trigger(e.default.FRAG_PARSING_METADATA,{samples:t.data.samples});break;default:this.hls.trigger(t.data.event,t.data.data)}}}]),i}();s.default=p,v.exports=s.default},{"../demux/demuxer-inline":6,"../demux/demuxer-worker":7,"../errors":11,"../events":12,"../remux/mp4-remuxer":19,"../utils/logger":21,webworkify:2}],9:[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;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),s=t("../utils/logger"),n=function(){function e(t){i(this,e),this.data=t,this.bytesAvailable=this.data.byteLength,this.word=0,this.bitsAvailable=0}return a(e,[{key:"loadWord",value:function(){var t=this.data.byteLength-this.bytesAvailable,r=new Uint8Array(4),e=Math.min(4,this.bytesAvailable);if(0===e)throw new Error("no bytes available");r.set(this.data.subarray(t,t+e)),this.word=new DataView(r.buffer).getUint32(0),this.bitsAvailable=8*e,this.bytesAvailable-=e}},{key:"skipBits",value:function(e){var t;this.bitsAvailable>e?(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&&s.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|this.readBits(e):r}},{key:"skipLZ",value:function(){var e;for(e=0;e<this.bitsAvailable;++e)if(0!==(this.word&2147483648>>>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 t,c,g,i,a,s,r,f,e,u=0,d=0,h=0,o=0;if(this.readUByte(),t=this.readUByte(),c=this.readBits(5),this.skipBits(3),g=this.readUByte(),this.skipUEG(),100===t||110===t||122===t||144===t){var l=this.readUEG();if(3===l&&this.skipBits(1),this.skipUEG(),this.skipUEG(),this.skipBits(1),this.readBoolean())for(f=3!==l?8:12,e=0;f>e;e++)this.readBoolean()&&(6>e?this.skipScalingList(16):this.skipScalingList(64))}this.skipUEG();var n=this.readUEG();if(0===n)this.readUEG();else if(1===n)for(this.skipBits(1),this.skipEG(),this.skipEG(),i=this.readUEG(),e=0;i>e;e++)this.skipEG();return this.skipUEG(),this.skipBits(1),a=this.readUEG(),s=this.readUEG(),r=this.readBits(1),0===r&&this.skipBits(1),this.skipBits(1),this.readBoolean()&&(u=this.readUEG(),d=this.readUEG(),h=this.readUEG(),o=this.readUEG()),{width:16*(a+1)-2*u-2*d,height:(2-r)*(s+1)*16-2*h-2*o}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}();e.default=n,r.exports=e.default},{"../utils/logger":21}],10:[function(r,n,i){"use strict";function s(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;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),f=r("../events"),a=s(f),l=r("./exp-golomb"),u=s(l),e=r("../utils/logger"),t=r("../errors"),o=function(){function r(e,t){d(this,r),this.observer=e,this.remuxerClass=t,this.lastCC=0,this.PES_TIMESCALE=9e4,this.remuxer=new this.remuxerClass(e)}return h(r,[{key:"switchLevel",value:function(){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack={type:"video",id:-1,sequenceNumber:0,samples:[],len:0,nbNalu:0},this._aacTrack={type:"audio",id:-1,sequenceNumber:0,samples:[],len:0},this._id3Track={type:"id3",id:-1,sequenceNumber:0,samples:[],len:0},this.remuxer.switchLevel()}},{key:"insertDiscontinuity",value:function(){this.switchLevel(),this.remuxer.insertDiscontinuity()}},{key:"push",value:function(i,A,E,_,f,h,v,L){var l,o,n,r,d,u,y,s,R=i.length;this.audioCodec=A,this.videoCodec=E,this.timeOffset=_,this._duration=L,this.contiguous=!1,f!==this.lastCC?(e.logger.log("discontinuity detected"),this.insertDiscontinuity(),this.lastCC=f):h!==this.lastLevel?(e.logger.log("level switch detected"),this.switchLevel(),this.lastLevel=h):v===this.lastSN+1&&(this.contiguous=!0),this.lastSN=v,this.contiguous||(this.aacOverFlow=null);var p=this.pmtParsed,g=this._avcTrack.id,c=this._aacTrack.id,m=this._id3Track.id;for(r=0;R>r;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(s=r+5+i[r+4],s===r+188)continue}else s=r+4;p?u===g?(d&&(l&&this._parseAVCPES(this._parsePES(l)),l={data:[],size:0}),l&&(l.data.push(i.subarray(s,r+188)),l.size+=r+188-s)):u===c?(d&&(o&&this._parseAACPES(this._parsePES(o)),o={data:[],size:0}),o&&(o.data.push(i.subarray(s,r+188)),o.size+=r+188-s)):u===m&&(d&&(n&&this._parseID3PES(this._parsePES(n)),n={data:[],size:0}),n&&(n.data.push(i.subarray(s,r+188)),n.size+=r+188-s)):(d&&(s+=i[s]+1),0===u?this._parsePAT(i,s):u===this._pmtId&&(this._parsePMT(i,s),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)),n&&this._parseID3PES(this._parsePES(n)),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,s,n,i;for(a=(15&r[t+1])<<8|r[t+2],s=t+3+a-4,n=(15&r[t+10])<<8|r[t+11],t+=12+n;s>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,s,r,i,n,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],n=d+9,t.data[0]=t.data[0].subarray(n),t.size-=n,s=new Uint8Array(t.size);t.data.length;)e=t.data.shift(),s.set(e,l),l+=e.byteLength;return{data:s,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),n=[],s=!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,s&&(r+="NDR ");break;case 5:i=!0,s&&(r+="IDR "),g=!0;break;case 6:i=!0,s&&(r+="SEI ");break;case 7:if(i=!0,s&&(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,s&&(r+="PPS "),t.pps||(t.pps=[e.data]);break;case 9:i=!0,s&&(r+="AUD ");break;default:i=!1,r+="unknown NAL "+e.type+" "}i&&(n.push(e),f+=e.data.byteLength)}),(s||r.length)&&e.logger.log(r),n.length&&(g===!0||t.sps)&&(v={units:{units:n,length:f},pts:a.pts,dts:a.dts,key:g},l.push(v),t.len+=f,t.nbNalu+=n.length)}},{key:"_parseAVCNALu",value:function(i){for(var s,r,o,n,a,u,t=0,d=i.byteLength,e=0,h=[];d>t;)switch(s=i[t++],e){case 0:0===s&&(e=1);break;case 1:e=0===s?2:0;break;case 2:case 3:if(0===s)e=3;else if(1===s){if(n=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=n,(1===n||5===n)&&(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,s,r,u,f,h,o,n=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(n.audiosamplerate||(l=this._ADTStoAudioConfig(i,r,this.audioCodec),n.config=l.config,n.audiosamplerate=l.samplerate,n.channelCount=l.channelCount,n.codec=l.codec,n.timescale=this.remuxer.timescale,n.duration=this.remuxer.timescale*this._duration,e.logger.log("parsed codec:"+n.codec+",rate:"+l.samplerate+",nb channel:"+l.channelCount)),h=0;o>r+5&&(s=(3&i[r+3])<<11,s|=i[r+4]<<3,s|=(224&i[r+5])>>>5,u=1&i[r+1]?7:9,s-=u,f=Math.round(p.pts+1024*h*this.PES_TIMESCALE/n.audiosamplerate),s>0&&o>=r+u+s);)for(v={unit:i.subarray(r+u,r+u+s),pts:f,dts:f},this._aacTrack.samples.push(v),this._aacTrack.len+=s,r+=s+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,o){var s,r,n,l,i,f=navigator.userAgent.toLowerCase(),h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];return s=((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:"+o+",ADTS data:type:"+s+",sampleingIndex:"+r+"["+h[r]+"kHz],channelConfig:"+l),-1!==f.indexOf("firefox")?r>=6?(s=5,i=new Array(4),n=r-3):(s=2,i=new Array(2),n=r):-1!==f.indexOf("android")?(s=2,i=new Array(2),n=r):(s=5,i=new Array(4),o&&-1!==o.indexOf("mp4a.40.5")||!o&&r>=6?n=r-3:(o&&-1!==o.indexOf("mp4a.40.2")&&(r>=6||1===l)&&(s=2,i=new Array(2)),n=r)),i[0]=s<<3,i[0]|=(14&r)>>1,i[1]|=(1&r)<<7,i[1]|=l<<3,5===s&&(i[1]|=(14&n)>>1,i[2]=(1&n)<<7,i[2]|=8,i[3]=0),{config:i,samplerate:h[r],channelCount:l,codec:"mp4a.40."+s})}},{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,n.exports=i.default},{"../errors":11,"../events":12,"../utils/logger":21,"./exp-golomb":9}],11:[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},{}],12:[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},{}],13:[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 s=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),t=r("../utils/logger"),n=function(){function e(){a(this,e)}return s(e,null,[{key:"mergeDetails",value:function(s,i){var n,c=Math.max(s.startSN,i.startSN)-i.startSN,d=Math.min(s.endSN,i.endSN)-i.startSN,h=i.startSN-s.startSN,f=s.fragments,o=i.fragments,u=0;if(c>d)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,n=a)}if(u)for(t.logger.log("discontinuity sliding from playlist, take drift into account"),r=0;r<o.length;r++)o[r].cc+=u;if(n)e.updateFragPTS(i,n.sn,n.startPTS,n.endPTS);else{var g=f[h].start;for(r=0;r<o.length;r++)o[r].start+=g}i.PTSKnown=s.PTSKnown}},{key:"updateFragPTS",value:function(i,l,a,n){var o,s,r,t;if(l<i.startSN||l>i.endSN)return 0;o=l-i.startSN,s=i.fragments,r=s[o],isNaN(r.startPTS)||(a=Math.max(a,r.startPTS),n=Math.min(n,r.endPTS));var u=a-r.start;for(r.start=r.startPTS=a,r.endPTS=n,r.duration=n-a,t=o;t>0;t--)e.updatePTS(s,t,t-1);for(t=o;t<s.length-1;t++)e.updatePTS(s,t,t+1);return i.PTSKnown=!0,u}},{key:"updatePTS",value:function(n,i,a){var e=n[i],r=n[a],s=r.startPTS;isNaN(s)?a>i?r.start=e.start+e.duration:r.start=e.start-r.duration:a>i?(e.duration=s-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-s,r.duration<0&&t.logger.error("negative duration computed for "+r+", there should be some duration drift between playlist and fragment!"))}}]),e}();e.default=n,i.exports=e.default},{"../utils/logger":21}],14:[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 s=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),E=t("./events"),i=r(E),n=t("./errors"),u=t("./loader/playlist-loader"),d=r(u),h=t("./loader/fragment-loader"),f=r(h),T=t("./controller/abr-controller"),g=r(T),v=t("./controller/mse-media-controller"),p=r(v),y=t("./controller/level-controller"),m=r(y),e=t("./utils/logger"),R=t("./utils/xhr-loader"),L=r(R),_=t("events"),A=r(_),b=t("./loader/key-loader"),S=r(b),l=function(){function t(){var i=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];o(this,t);var s={autoStartLoad:!0,debug:!1,maxBufferLength:30,maxBufferSize:6e7,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,maxMaxBufferLength:600,enableWorker:!0,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:1,fragLoadingRetryDelay:1e3,fragLoadingLoopThreshold:3,manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:200,loader:L.default,fLoader:void 0,pLoader:void 0,abrController:g.default,mediaController:p.default};for(var a in s)a in i||(i[a]=s[a]);if(void 0!==i.liveMaxLatencyDurationCount&&i.liveMaxLatencyDurationCount<=i.liveSyncDurationCount)throw new Error('Illegal hls.js configuration: "liveMaxLatencyDurationCount" must be strictly superior to "liveSyncDurationCount" in player configuration');(0,e.enableLogs)(i.debug),this.config=i;var r=this.observer=new A.default;r.trigger=function(i){for(var t=arguments.length,a=Array(t>1?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 s(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 n.ErrorTypes}},{key:"ErrorDetails",get:function(){return n.ErrorDetails}}]),s(t,[{key:"destroy",value:function(){e.logger.log("destroy"),this.detachMedia(),this.trigger(i.default.DESTROYING),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)}},{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":11,"./events":12,"./loader/fragment-loader":15,"./loader/key-loader":16,"./loader/playlist-loader":17,"./utils/logger":21,"./utils/xhr-loader":23,events:1}],15:[function(i,a,r){"use strict";function s(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(r,"__esModule",{value:!0});var o=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),l=i("../events"),e=s(l),t=i("../errors"),u=function(){function r(t){n(this,r),this.hls=t,this.onfl=this.onFragLoading.bind(this),t.on(e.default.FRAG_LOADING,this.onfl)}return o(r,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),this.hls.off(e.default.FRAG_LOADING,this.onfl)}},{key:"onFragLoading",value:function(i,r){var t=r.frag;this.frag=t,this.frag.loaded=0;var e=this.hls.config;t.loader=this.loader="undefined"!=typeof e.fLoader?new e.fLoader(e):new e.loader(e),this.loader.load(t.url,"arraybuffer",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),e.fragLoadingTimeOut,e.fragLoadingMaxRetry,e.fragLoadingRetryDelay,this.loadprogress.bind(this),t)}},{key:"loadsuccess",value:function(i,t){var r=i.currentTarget.response;t.length=r.byteLength,this.frag.loader=void 0,this.hls.trigger(e.default.FRAG_LOADED,{payload:r,frag:this.frag,stats:t})}},{key:"loaderror",value:function(r){this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:this.frag,response:r})}},{key:"loadtimeout",value:function(){this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.FRAG_LOAD_TIMEOUT,fatal:!1,frag:this.frag})}},{key:"loadprogress",value:function(r,t){this.frag.loaded=t.loaded,this.hls.trigger(e.default.FRAG_LOAD_PROGRESS,{frag:this.frag,stats:t})}}]),r}();r.default=u,a.exports=r.default},{"../errors":11,"../events":12}],16:[function(i,a,r){"use strict";function s(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(r,"__esModule",{value:!0});var o=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),l=i("../events"),e=s(l),t=i("../errors"),u=function(){function r(t){n(this,r),this.hls=t,this.decryptkey=null,this.decrypturl=null,this.ondkl=this.onDecryptKeyLoading.bind(this),t.on(e.default.KEY_LOADING,this.ondkl)}return o(r,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),this.hls.off(e.default.KEY_LOADING,this.ondkl)}},{key:"onDecryptKeyLoading",value:function(n,s){var t=this.frag=s.frag,a=t.decryptdata,i=a.uri;if(i!==this.decrypturl||null===this.decryptkey){var r=this.hls.config;t.loader=this.loader=new r.loader(r),this.decrypturl=i,this.decryptkey=null,t.loader.load(i,"arraybuffer",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),r.fragLoadingTimeOut,r.fragLoadingMaxRetry,r.fragLoadingRetryDelay,this.loadprogress.bind(this),t)}else this.decryptkey&&(a.key=this.decryptkey,this.hls.trigger(e.default.KEY_LOADED,{frag:t}))}},{key:"loadsuccess",value:function(r){var t=this.frag;this.decryptkey=t.decryptdata.key=new Uint8Array(r.currentTarget.response),t.loader=void 0,this.hls.trigger(e.default.KEY_LOADED,{frag:t})}},{key:"loaderror",value:function(r){this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.KEY_LOAD_ERROR,fatal:!1,frag:this.frag,response:r})}},{key:"loadtimeout",value:function(){this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.KEY_LOAD_TIMEOUT,fatal:!1,frag:this.frag})}},{key:"loadprogress",value:function(){}}]),r}();r.default=u,a.exports=r.default},{"../errors":11,"../events":12}],17:[function(r,n,i){"use strict";function a(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(i,"__esModule",{value:!0});var s=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),h=r("../events"),e=a(h),t=r("../errors"),u=r("../utils/url"),d=a(u),o=function(){function r(t){l(this,r),this.hls=t,this.onml=this.onManifestLoading.bind(this),this.onll=this.onLevelLoading.bind(this),t.on(e.default.MANIFEST_LOADING,this.onml),t.on(e.default.LEVEL_LOADING,this.onll)}return s(r,[{key:"destroy", +value:function(){this.loader&&(this.loader.destroy(),this.loader=null),this.url=this.id=null,this.hls.off(e.default.MANIFEST_LOADING,this.onml),this.hls.off(e.default.LEVEL_LOADING,this.onll)}},{key:"onManifestLoading",value:function(t,e){this.load(e.url,null)}},{key:"onLevelLoading",value:function(t,e){this.load(e.url,e.level,e.id)}},{key:"load",value:function(t,r,i){var e=this.hls.config;this.url=t,this.id=r,this.id2=i,this.loader="undefined"!=typeof e.pLoader?new e.pLoader(e):new e.loader(e),this.loader.load(t,"",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),e.manifestLoadingTimeOut,e.manifestLoadingMaxRetry,e.manifestLoadingRetryDelay)}},{key:"resolve",value:function(e,t){return d.default.buildAbsoluteURL(t,e)}},{key:"parseMasterPlaylist",value:function(s,n){for(var e,i,r,a=[],t={},o=/#EXT-X-STREAM-INF:([^\n\r]*(BAND)WIDTH=(\d+))?([^\n\r]*(CODECS)=\"([^\"\n\r]*)\",?)?([^\n\r]*(RES)OLUTION=(\d+)x(\d+))?([^\n\r]*(NAME)=\"(.*)\")?[^\n\r]*[\r\n]+([^\r\n]+)/g;null!=(e=o.exec(s));){for(e.shift(),e=e.filter(function(e){return void 0!==e}),t.url=this.resolve(e.pop(),n);e.length>0;)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(_,s,L){var t,m,i,n,a,c=0,u=0,r={url:s,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(_));)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?n:parseInt(d[1]),n=parseInt(d[0])+a,i=r.fragments.length?r.fragments[r.fragments.length-1]:null,i&&!i.url&&(i.byteRangeStartOffset=a,i.byteRangeEndOffset=n,i.url=this.resolve(t[2],s));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],s):null,duration:h,start:u,sn:p,level:L,cc:v,byteRangeStartOffset:a,byteRangeEndOffset:n,decryptdata:o}),u+=h,a=null}break;case"KEY":var g=t[1],f=this.parseKeyParamsByRegex(g,/(METHOD)=([^,]*)/),E=this.parseKeyParamsByRegex(g,/(URI)=["]([^,]*)["]/),R=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,s),e.key=null,R&&(e.iv=R,"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(n,i){var o,s=n.currentTarget.responseText,r=n.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(n.currentTarget.getResponseHeader("Last-Modified")),0===s.indexOf("#EXTM3U"))if(s.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(s,r,l);i.tparsed=performance.now(),a.trigger(e.default.LEVEL_LOADED,{details:d,level:l,id:u,stats:i})}else o=this.parseMasterPlaylist(s,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,n.exports=i.default},{"../errors":11,"../events":12,"../utils/url":22}],18:[function(s,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<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),a=function(){function e(){r(this,e)}return i(e,null,[{key:"init",value:function(){e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]};var t;for(t in e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);e.MAJOR_BRAND=new Uint8Array(["i".charCodeAt(0),"s".charCodeAt(0),"o".charCodeAt(0),"m".charCodeAt(0)]),e.AVC1_BRAND=new Uint8Array(["a".charCodeAt(0),"v".charCodeAt(0),"c".charCodeAt(0),"1".charCodeAt(0)]),e.MINOR_VERSION=new Uint8Array([0,0,0,1]),e.VIDEO_HDLR=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),e.AUDIO_HDLR=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]),e.HDLR_TYPES={video:e.VIDEO_HDLR,audio:e.AUDIO_HDLR},e.DREF=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),e.STCO=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSC=e.STCO,e.STTS=e.STCO,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSD=new Uint8Array([0,0,0,0,0,0,0,1]),e.FTYP=e.box(e.types.ftyp,e.MAJOR_BRAND,e.MINOR_VERSION,e.MAJOR_BRAND,e.AVC1_BRAND),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,e.DREF))}},{key:"box",value:function(s){for(var t,a,r=Array.prototype.slice.call(arguments,1),i=0,e=r.length;e--;)i+=r[e].byteLength;for(t=new Uint8Array(i+8),a=new DataView(t.buffer),a.setUint32(0,t.byteLength),t.set(s,4),e=0,i=8;e<r.length;e++)t.set(r[e],i),i+=r[e].byteLength;return t}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}},{key:"mdhd",value:function(t,r){return e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,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(s){var r,t,i=s.samples||[],a=new Uint8Array(4+i.length);for(t=0;t<i.length;t++)r=i[t].flags,a[t+4]=r.dependsOn<<4|r.isDependedOn<<2|r.hasRedundancy;return e.box(e.types.sdtp,a)}},{key:"stbl",value:function(t){return e.box(e.types.stbl,e.stsd(t),e.box(e.types.stts,e.STTS),e.box(e.types.stsc,e.STSC),e.box(e.types.stsz,e.STSZ),e.box(e.types.stco,e.STCO))}},{key:"avc1",value:function(t){var r,a,s,i=[],n=[];for(r=0;r<t.sps.length;r++)a=t.sps[r],s=a.byteLength,i.push(s>>>8&255),i.push(255&s),i=i.concat(Array.prototype.slice.call(a));for(r=0;r<t.pps.length;r++)a=t.pps[r],s=a.byteLength,n.push(s>>>8&255),n.push(255&s),n=n.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(n)));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(n,i){var r,t,a,s;for(r=n.samples||[],s=new Uint8Array(12+16*r.length),i+=8+s.byteLength,s.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<r.length;a++)t=r[a],s.set([t.duration>>>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,s)}},{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},{}],19:[function(i,h,a){"use strict";function s(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;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),f=i("../events"),e=s(f),r=i("../utils/logger"),u=i("../remux/mp4-generator"),t=s(u),n=i("../errors"),o=function(){function i(e){l(this,i),this.observer=e,this.ISGenerated=!1,this.PES2MP4SCALEFACTOR=4,this.PES_TIMESCALE=9e4,this.MP4_TIMESCALE=this.PES_TIMESCALE/this.PES2MP4SCALEFACTOR}return d(i,[{key:"destroy",value:function(){}},{key:"insertDiscontinuity",value:function(){this._initPTS=this._initDTS=this.nextAacPts=this.nextAvcDts=void 0}},{key:"switchLevel",value:function(){this.ISGenerated=!1}},{key:"remux",value:function(r,i,a,t,s){this.ISGenerated||this.generateIS(r,i,t),i.samples.length&&this.remuxVideo(i,t,s),r.samples.length&&this.remuxAudio(r,t,s),a.samples.length&&this.remuxID3(a,t),this.observer.trigger(e.default.FRAG_PARSED)}},{key:"generateIS",value:function(i,r,a){var u=this.observer,o=i.samples,l=r.samples,d=o.length,h=l.length,s=this.PES_TIMESCALE;0===d&&0===h?u.trigger(e.default.ERROR,{type:n.ErrorTypes.MEDIA_ERROR,details:n.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"}):0===h?(i.config&&(u.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,{audioMoov:t.default.initSegment([i]),audioCodec:i.codec,audioChannelCount:i.channelCount}),this.ISGenerated=!0),void 0===this._initPTS&&(this._initPTS=o[0].pts-s*a,this._initDTS=o[0].dts-s*a)):0===d?r.sps&&r.pps&&(u.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,{videoMoov:t.default.initSegment([r]),videoCodec:r.codec,videoWidth:r.width,videoHeight:r.height}),this.ISGenerated=!0,void 0===this._initPTS&&(this._initPTS=l[0].pts-s*a,this._initDTS=l[0].dts-s*a)):i.config&&r.sps&&r.pps&&(u.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,{audioMoov:t.default.initSegment([i]),audioCodec:i.codec,audioChannelCount:i.channelCount,videoMoov:t.default.initSegment([r]),videoCodec:r.codec,videoWidth:r.width,videoHeight:r.height}),this.ISGenerated=!0,void 0===this._initPTS&&(this._initPTS=Math.min(l[0].pts,o[0].pts)-s*a,this._initDTS=Math.min(l[0].dts,o[0].dts)-s*a))}},{key:"remuxVideo",value:function(s,S,b){var R,d,i,E,f,u,A,_,L,c,m,y,n,a,p=8,v=this.PES_TIMESCALE,h=this.PES2MP4SCALEFACTOR,o=[];for(u=new Uint8Array(s.len+4*s.nbNalu+8),R=new DataView(u.buffer),R.setUint32(0,u.byteLength),u.set(t.default.types.mdat,4);s.samples.length;){for(d=s.samples.shift(),E=0;d.units.units.length;)f=d.units.units.shift(),R.setUint32(p,f.data.byteLength),p+=4,u.set(f.data,p),p+=f.data.byteLength,E+=4+f.data.byteLength;if(m=d.pts-this._initDTS,y=d.dts-this._initDTS,void 0!==c)n=this._PTSNormalize(m,c),a=this._PTSNormalize(y,c),i.duration=(a-c)/h,i.duration<0&&(i.duration=0);else{var l,g=this.nextAvcDts;n=this._PTSNormalize(m,g),a=this._PTSNormalize(y,g),l=Math.round((a-g)/90),(b||Math.abs(l)<600)&&l&&(l>1?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,n=Math.max(n-l,a),r.logger.log("Video/PTS/DTS adjusted:"+n+"/"+a)),_=Math.max(0,n),L=Math.max(0,a)}i={size:E,duration:0,cts:(n-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,s.len=0,s.nbNalu=0,navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&(o[0].flags.dependsOn=2,o[0].flags.isNonSync=0),s.samples=o,A=t.default.moof(s.sequenceNumber++,L/h,s),s.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:A,mdat:u,startPTS:_/v,endPTS:(n+h*i.duration)/v,startDTS:L/v,endDTS:(a+h*i.duration)/v,type:"video",nb:o.length})}},{key:"remuxAudio",value:function(a,b,A){var L,d,i,v,l,E,R,y,h,m,p,u,n,_=8,f=this.PES_TIMESCALE,g=this.PES2MP4SCALEFACTOR,o=[];for(l=new Uint8Array(a.len+8),L=new DataView(l.buffer),L.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,_),_+=v.byteLength,m=d.pts-this._initDTS,p=d.dts-this._initDTS,void 0!==h)u=this._PTSNormalize(m,h),n=this._PTSNormalize(p,h),i.duration=(n-h)/g,i.duration<0&&(r.logger.log("invalid AAC sample duration at PTS:"+d.pts+":"+i.duration),i.duration=0);else{var s,c=this.nextAacPts;u=this._PTSNormalize(m,c),n=this._PTSNormalize(p,c),s=Math.round(1e3*(u-c)/f),(A||Math.abs(s)<600)&&s&&(s>1?r.logger.log(s+" ms hole between AAC samples detected,filling it"):-1>s&&r.logger.log(-s+" ms overlapping between AAC samples detected"),u=n=c),R=Math.max(0,u),y=Math.max(0,n)}i={size:v.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},o.push(i),h=n}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:R/f,endPTS:this.nextAacPts/f,startDTS:y/f,endDTS:(n+g*i.duration)/f,type:"audio",nb:o.length})}},{key:"remuxID3",value:function(r,a){var t,s=r.samples.length;if(s){for(var i=0;s>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":11,"../events":12,"../remux/mp4-generator":18,"../utils/logger":21}],20:[function(r,e,i){"use strict";var t={search:function(a,n){for(var t=0,r=a.length-1,e=null,i=null;r>=t;){e=(t+r)/2|0,i=a[e];var s=n(i);if(s>0)t=e+1;else{if(!(0>s))return i;r=e-1}}return null}};e.exports=t},{}],21:[function(n,o,r){"use strict";function t(){}Object.defineProperty(r,"__esModule",{value:!0});var i={log:t,warn:t,info:t,error:t},e=i,a=function(r){if(r===!0||"object"==typeof r){e.log=r.log?r.log.bind(r):void 0,e.info=r.info?r.info.bind(r):void 0,e.error=r.error?r.error.bind(r):void 0,e.warn=r.warn?r.warn.bind(r):void 0;try{e.log()}catch(r){e.log=t,e.info=t,e.error=t,e.warn=t}}else e=i};r.enableLogs=a;var s=e;r.logger=s},{}],22:[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,s=null,n=/^([^#]*)(.*)$/.exec(t);n&&(s=n[2],t=n[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),s&&(r+=s),r},buildAbsolutePath:function(s,n){for(var i,e,o=n,a="",t=s.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},{}],23:[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 s=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),t=r("../utils/logger"),n=function(){function e(t){a(this,e),t&&t.xhrSetup&&(this.xhrSetup=t.xhrSetup)}return s(e,[{key:"destroy",value:function(){this.abort(),this.loader=null}},{key:"abort",value:function(){this.loader&&4!==this.loader.readyState&&(this.stats.aborted=!0,this.loader.abort()),this.timeoutHandle&&window.clearTimeout(this.timeoutHandle)}},{key:"load",value:function(r,i,a,s,n,t,o,l){var u=arguments.length<=8||void 0===arguments[8]?null:arguments[8],e=arguments.length<=9||void 0===arguments[9]?null:arguments[9];this.url=r,!e||isNaN(e.byteRangeStartOffset)||isNaN(e.byteRangeEndOffset)||(this.byteRange=e.byteRangeStartOffset+"-"+e.byteRangeEndOffset),this.responseType=i,this.onSuccess=a,this.onProgress=u,this.onTimeout=n,this.onError=s,this.stats={trequest:performance.now(),retry:0},this.timeout=t,this.maxRetry=o,this.retryDelay=l,this.timeoutHandle=window.setTimeout(this.loadtimeout.bind(this),t),this.loadInternal()}},{key:"loadInternal",value:function(){var e=this.loader=new XMLHttpRequest;e.onload=this.loadsuccess.bind(this),e.onerror=this.loaderror.bind(this),e.onprogress=this.loadprogress.bind(this),e.open("GET",this.url,!0),this.byteRange&&e.setRequestHeader("Range","bytes="+this.byteRange),e.responseType=this.responseType,this.stats.tfirst=null,this.stats.loaded=0,this.xhrSetup&&this.xhrSetup(e),e.send()}},{key:"loadsuccess",value:function(e){window.clearTimeout(this.timeoutHandle),this.stats.tload=performance.now(),this.onSuccess(e,this.stats)}},{key:"loaderror",value:function(e){this.stats.retry<this.maxRetry?(t.logger.warn(e.type+" while loading "+this.url+", retrying in "+this.retryDelay+"..."),this.destroy(),window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,64e3),this.stats.retry++):(window.clearTimeout(this.timeoutHandle),t.logger.error(e.type+" while loading "+this.url),this.onError(e))}},{key:"loadtimeout",value:function(e){t.logger.warn("timeout while loading "+this.url),this.onTimeout(e,this.stats)}},{key:"loadprogress",value:function(t){var e=this.stats;null===e.tfirst&&(e.tfirst=performance.now()),e.loaded=t.loaded,this.onProgress&&this.onProgress(t,e)}}]),e}();e.default=n,i.exports=e.default},{"../utils/logger":21}]},{},[14])(14)}); |