mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-19 03:48:18 -07:00
6 lines
131 KiB
JavaScript
6 lines
131 KiB
JavaScript
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Hls=e()}}(function(){return function e(t,r,a){function i(s,o){if(!r[s]){if(!t[s]){var l="function"==typeof require&&require;if(!o&&l)return l(s,!0);if(n)return n(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var r=t[s][1][e];return i(r?r:e)},d,d.exports,e,t,r,a)}return r[s].exports}for(var n="function"==typeof require&&require,s=0;s<a.length;s++)i(a[s]);return i}({1:[function(e,t,r){function a(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function n(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}t.exports=a,a.EventEmitter=a,a.prototype._events=void 0,a.prototype._maxListeners=void 0,a.defaultMaxListeners=10,a.prototype.setMaxListeners=function(e){if(!n(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},a.prototype.emit=function(e){var t,r,a,n,l,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[e],o(r))return!1;if(i(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:n=Array.prototype.slice.call(arguments,1),r.apply(this,n)}else if(s(r))for(n=Array.prototype.slice.call(arguments,1),u=r.slice(),a=u.length,l=0;l<a;l++)u[l].apply(this,n);return!0},a.prototype.addListener=function(e,t){var r;if(!i(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=o(this._maxListeners)?a.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,"function"==typeof console.trace)),this},a.prototype.on=a.prototype.addListener,a.prototype.once=function(e,t){function r(){this.removeListener(e,r),a||(a=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var a=!1;return r.listener=t,this.on(e,r),this},a.prototype.removeListener=function(e,t){var r,a,n,o;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],n=r.length,a=-1,r===t||i(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(r)){for(o=n;o-- >0;)if(r[o]===t||r[o].listener&&r[o].listener===t){a=o;break}if(a<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(a,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},a.prototype.removeAllListeners=function(e){var t,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(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],i(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},a.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},a.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},a.listenerCount=function(e,t){return e.listenerCount(t)}},{}],2:[function(e,t,r){var a=arguments[3],i=arguments[4],n=arguments[5],s=JSON.stringify;t.exports=function(e){for(var t,r=Object.keys(n),o=0,l=r.length;o<l;o++){var u=r[o],d=n[u].exports;if(d===e||d.default===e){t=u;break}}if(!t){t=Math.floor(Math.pow(16,8)*Math.random()).toString(16);for(var f={},o=0,l=r.length;o<l;o++){var u=r[o];f[u]=u}i[t]=[Function(["require","module","exports"],"("+e+")(self)"),f]}var h=Math.floor(Math.pow(16,8)*Math.random()).toString(16),c={};c[t]=t,i[h]=[Function(["require"],"var f = require("+s(t)+");(f.default ? f.default : f)(self);"),c];var v="("+a+")({"+Object.keys(i).map(function(e){return s(e)+":["+i[e][0]+","+s(i[e][1])+"]"}).join(",")+"},{},["+s(h)+"])",g=window.URL||window.webkitURL||window.mozURL||window.msURL;return new Worker(g.createObjectURL(new Blob([v],{type:"text/javascript"})))}},{}],3:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=e("../helper/buffer-helper"),c=a(h),v=e("../errors"),g=e("../utils/logger"),p=e("./ewma-bandwidth-estimator"),y=a(p),m=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this,e,u.default.FRAG_LOADING,u.default.FRAG_LOADED,u.default.ERROR));return r.lastLoadedFragLevel=0,r._autoLevelCapping=-1,r._nextAutoLevel=-1,r.hls=e,r.onCheck=r.abandonRulesCheck.bind(r),r}return s(t,e),o(t,[{key:"destroy",value:function(){this.clearTimer(),f.default.prototype.destroy.call(this)}},{key:"onFragLoading",value:function(e){if(this.timer||(this.timer=setInterval(this.onCheck,100)),!this.bwEstimator){var t=this.hls,r=e.frag.level,a=t.levels[r].details.live,i=t.config,n=void 0,s=void 0;a?(n=i.abrEwmaFastLive,s=i.abrEwmaSlowLive):(n=i.abrEwmaFastVoD,s=i.abrEwmaSlowVoD),this.bwEstimator=new y.default(t,s,n,i.abrEwmaDefaultEstimate)}var o=e.frag;o.trequest=performance.now(),this.fragCurrent=o}},{key:"abandonRulesCheck",value:function(){var e=this.hls,t=e.media,r=this.fragCurrent;if(!r.loader||r.loader.stats&&r.loader.stats.aborted)return g.logger.warn("frag loader destroy or aborted, disarm abandonRulesCheck"),void this.clearTimer();if(t&&(!t.paused||!t.readyState)&&r.autoLevel&&r.level){var a=performance.now()-r.trequest;if(a>500*r.duration){var i=e.levels,n=Math.max(1,1e3*r.loaded/a),s=Math.max(r.loaded,Math.round(r.duration*i[r.level].bitrate/8)),o=t.currentTime,l=(s-r.loaded)/n,d=c.default.bufferInfo(t,o,e.config.maxBufferHole).end-o;if(d<2*r.duration&&l>d){var f=void 0,h=void 0;for(h=r.level-1;h>=0&&(f=r.duration*i[h].bitrate/(6.4*n),g.logger.log("fragLoadedDelay/bufferStarvationDelay/fragLevelNextLoadedDelay["+h+"] :"+l.toFixed(1)+"/"+d.toFixed(1)+"/"+f.toFixed(1)),!(f<d));h--);if(f<l){h=Math.max(0,h),e.nextLoadLevel=h,this.bwEstimator.sample(a,r.loaded),g.logger.warn("loading too slow, abort fragment loading and switch to level "+h);var v=r.loader,p=v.stats;v.abort(),this.clearTimer(),e.trigger(u.default.FRAG_LOAD_EMERGENCY_ABORTED,{frag:r,stats:p})}}}}}},{key:"onFragLoaded",value:function(e){var t=e.stats,r=e.frag;if(void 0===t.aborted&&1===r.loadCounter){var a=t.tload-t.trequest;this.bwEstimator.sample(a,t.loaded),r.bitrateTest?this.bitrateTestDelay=a/1e3:this.bitrateTestDelay=0}this.clearTimer(),this.lastLoadedFragLevel=r.level,this._nextAutoLevel=-1}},{key:"onError",value:function(e){switch(e.details){case v.ErrorDetails.FRAG_LOAD_ERROR:case v.ErrorDetails.FRAG_LOAD_TIMEOUT:this.clearTimer()}}},{key:"clearTimer",value:function(){this.timer&&(clearInterval(this.timer),this.timer=null)}},{key:"findBestLevel",value:function(e,t,r,a,i,n,s,o){for(var l=a;l>=0;l--){var u=o[l],d=u.details,f=d?d.totalduration/d.fragments.length:t,h=void 0;h=l<=e?n*r:s*r;var c=o[l].bitrate,v=c*f/h;if(g.logger.trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: "+l+"/"+Math.round(h)+"/"+c+"/"+f+"/"+i+"/"+v),h>c&&(!v||v<i))return l}return-1}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping=e}},{key:"nextAutoLevel",get:function(){var e=this._nextAutoLevel,t=this.bwEstimator;if(!(e===-1||t&&t.canEstimate()))return Math.min(e,this.maxAutoLevel);var r=this.nextABRAutoLevel;return e!==-1&&(r=Math.min(e,r)),r},set:function(e){this._nextAutoLevel=e}},{key:"maxAutoLevel",get:function(){var e,t=this.hls.levels,r=this._autoLevelCapping;return e=r===-1&&t&&t.length?t.length-1:r}},{key:"nextABRAutoLevel",get:function(){var e=this.hls,t=this.maxAutoLevel,r=e.levels,a=e.config,i=e.media,n=this.lastLoadedFragLevel,s=this.fragCurrent?this.fragCurrent.duration:0,o=i?i.currentTime:0,l=i&&0!==i.playbackRate?Math.abs(i.playbackRate):1,u=this.bwEstimator?this.bwEstimator.getEstimate():a.abrEwmaDefaultEstimate,d=(c.default.bufferInfo(i,o,a.maxBufferHole).end-o)/l,f=this.findBestLevel(n,s,u,t,d,a.abrBandWidthFactor,a.abrBandWidthUpFactor,r);if(f>=0)return f;g.logger.trace("rebuffering expected to happen, lets try to find a quality level minimizing the rebuffering");var h=a.maxStarvationDelay;if(0===d){var v=this.bitrateTestDelay;v&&(h-=v,g.logger.trace("bitrate test took "+Math.round(1e3*v)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*h)+" ms"))}return f=this.findBestLevel(n,s,u,t,d+h,a.abrBandWidthFactor,a.abrBandWidthUpFactor,r),Math.max(f,0)}}]),t}(f.default);r.default=m},{"../errors":21,"../event-handler":22,"../events":23,"../helper/buffer-helper":24,"../utils/logger":38,"./ewma-bandwidth-estimator":6}],4:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=e("../utils/logger"),c=e("../errors"),v=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this,e,u.default.MEDIA_ATTACHING,u.default.MEDIA_DETACHING,u.default.BUFFER_RESET,u.default.BUFFER_APPENDING,u.default.BUFFER_CODECS,u.default.BUFFER_EOS,u.default.BUFFER_FLUSHING,u.default.LEVEL_UPDATED));return r._msDuration=null,r._levelDuration=null,r.onsbue=r.onSBUpdateEnd.bind(r),r.onsbe=r.onSBUpdateError.bind(r),r}return s(t,e),o(t,[{key:"destroy",value:function(){f.default.prototype.destroy.call(this)}},{key:"onMediaAttaching",value:function(e){var t=this.media=e.media;if(t){var r=this.mediaSource=new MediaSource;this.onmso=this.onMediaSourceOpen.bind(this),this.onmse=this.onMediaSourceEnded.bind(this),this.onmsc=this.onMediaSourceClose.bind(this),r.addEventListener("sourceopen",this.onmso),r.addEventListener("sourceended",this.onmse),r.addEventListener("sourceclose",this.onmsc),t.src=URL.createObjectURL(r)}}},{key:"onMediaDetaching",value:function(){var e=this.mediaSource;if(e){if("open"===e.readyState)try{e.endOfStream()}catch(e){h.logger.warn("onMediaDetaching:"+e.message+" while calling endOfStream")}e.removeEventListener("sourceopen",this.onmso),e.removeEventListener("sourceended",this.onmse),e.removeEventListener("sourceclose",this.onmsc),this.media&&(this.media.removeAttribute("src"),this.media.load()),this.mediaSource=null,this.media=null,this.pendingTracks=null,this.sourceBuffer=null,this.flushRange=[],this.segments=[],this.appended=0}this.onmso=this.onmse=this.onmsc=null,this.hls.trigger(u.default.MEDIA_DETACHED)}},{key:"onMediaSourceOpen",value:function(){h.logger.log("media source opened"),this.hls.trigger(u.default.MEDIA_ATTACHED,{media:this.media}),this.mediaSource.removeEventListener("sourceopen",this.onmso);var e=this.pendingTracks;e&&(this.onBufferCodecs(e),this.pendingTracks=null,this.doAppending())}},{key:"onMediaSourceClose",value:function(){h.logger.log("media source closed")}},{key:"onMediaSourceEnded",value:function(){h.logger.log("media source ended")}},{key:"onSBUpdateEnd",value:function(){this._needsFlush&&this.doFlush(),this._needsEos&&this.onBufferEos(),this.hls.trigger(u.default.BUFFER_APPENDED),this.doAppending()}},{key:"onSBUpdateError",value:function(e){h.logger.error("sourceBuffer error:"+e),this.hls.trigger(u.default.ERROR,{type:c.ErrorTypes.MEDIA_ERROR,details:c.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1})}},{key:"onBufferReset",value:function(){var e=this.sourceBuffer;if(e){for(var t in e){var r=e[t];try{this.mediaSource.removeSourceBuffer(r),r.removeEventListener("updateend",this.onsbue),r.removeEventListener("error",this.onsbe)}catch(e){}}this.sourceBuffer=null}this.flushRange=[],this.segments=[],this.appended=0}},{key:"onBufferCodecs",value:function(e){var t=this.mediaSource;if(!t||"open"!==t.readyState)return void(this.pendingTracks=e);if(!this.sourceBuffer){var r={};for(var a in e){var i=e[a],n=i.levelCodec||i.codec,s=i.container+";codecs="+n;h.logger.log("creating sourceBuffer with mimeType:"+s);var o=r[a]=t.addSourceBuffer(s);o.addEventListener("updateend",this.onsbue),o.addEventListener("error",this.onsbe)}this.sourceBuffer=r}}},{key:"onBufferAppending",value:function(e){this.segments?this.segments.push(e):this.segments=[e],this.doAppending()}},{key:"onBufferAppendFail",value:function(e){h.logger.error("sourceBuffer error:"+e.event),this.hls.trigger(u.default.ERROR,{type:c.ErrorTypes.MEDIA_ERROR,details:c.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1,frag:this.fragCurrent})}},{key:"onBufferEos",value:function(){var e=this.sourceBuffer,t=this.mediaSource;t&&"open"===t.readyState&&(e.audio&&e.audio.updating||e.video&&e.video.updating?this._needsEos=!0:(h.logger.log("all media data available, signal endOfStream() to MediaSource and stop loading fragment"),t.endOfStream(),this._needsEos=!1))}},{key:"onBufferFlushing",value:function(e){this.flushRange.push({start:e.startOffset,end:e.endOffset}),this.flushBufferCounter=0,this.doFlush()}},{key:"onLevelUpdated",value:function(e){var t=e.details;0!==t.fragments.length&&(this._levelDuration=t.totalduration+t.fragments[0].start,this.updateMediaElementDuration())}},{key:"updateMediaElementDuration",value:function(){if(null!==this._levelDuration){var e=this.media,t=this.mediaSource,r=this.sourceBuffer;if(e&&t&&r&&0!==e.readyState&&"open"===t.readyState){for(var a in r)if(r[a].updating)return;null===this._msDuration&&(this._msDuration=t.duration),this._levelDuration>this._msDuration&&(h.logger.log("Updating mediasource duration to "+this._levelDuration),t.duration=this._levelDuration,this._msDuration=this._levelDuration)}}}},{key:"doFlush",value:function(){for(;this.flushRange.length;){var e=this.flushRange[0];if(!this.flushBuffer(e.start,e.end))return void(this._needsFlush=!0);this.flushRange.shift(),this.flushBufferCounter=0}if(0===this.flushRange.length){this._needsFlush=!1;var t=0,r=this.sourceBuffer;if(r)for(var a in r)t+=r[a].buffered.length;this.appended=t,this.hls.trigger(u.default.BUFFER_FLUSHED)}}},{key:"doAppending",value:function(){var e=this.hls,t=this.sourceBuffer,r=this.segments;if(t){if(this.media.error)return r=[],void h.logger.error("trying to append although a media error occured, flush segment and abort");for(var a in t)if(t[a].updating)return;if(r.length){var i=r.shift();try{t[i.type].appendBuffer(i.data),this.appendError=0,this.appended++}catch(t){h.logger.error("error while trying to append buffer:"+t.message),r.unshift(i);var n={type:c.ErrorTypes.MEDIA_ERROR};if(22===t.code)return this.segments=[],n.details=c.ErrorDetails.BUFFER_FULL_ERROR,void e.trigger(u.default.ERROR,n);if(this.appendError?this.appendError++:this.appendError=1,n.details=c.ErrorDetails.BUFFER_APPEND_ERROR,n.frag=this.fragCurrent,this.appendError>e.config.appendErrorMaxRetry)return h.logger.log("fail "+e.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),r=[],n.fatal=!0,void e.trigger(u.default.ERROR,n);n.fatal=!1,e.trigger(u.default.ERROR,n)}}}}},{key:"flushBuffer",value:function(e,t){var r,a,i,n,s,o;if(this.flushBufferCounter<this.appended&&this.sourceBuffer)for(var l in this.sourceBuffer){if(r=this.sourceBuffer[l],r.updating)return h.logger.warn("cannot flush, sb updating in progress"),!1;for(a=0;a<r.buffered.length;a++)if(i=r.buffered.start(a),n=r.buffered.end(a),navigator.userAgent.toLowerCase().indexOf("firefox")!==-1&&t===Number.POSITIVE_INFINITY?(s=e,o=t):(s=Math.max(i,e),o=Math.min(n,t)),Math.min(o,n)-s>.5)return this.flushBufferCounter++,h.logger.log("flush "+l+" ["+s+","+o+"], of ["+i+","+n+"], pos:"+this.media.currentTime),r.remove(s,o),!1}else h.logger.warn("abort flushing too many retries");return h.logger.log("buffer flushed"),!0}}]),t}(f.default);r.default=v},{"../errors":21,"../event-handler":22,"../events":23,"../utils/logger":38}],5:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=function(e){function t(e){return i(this,t),n(this,Object.getPrototypeOf(t).call(this,e,u.default.MEDIA_ATTACHING,u.default.MANIFEST_PARSED))}return s(t,e),o(t,[{key:"destroy",value:function(){this.hls.config.capLevelToPlayerSize&&(this.media=null,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(this.timer=clearInterval(this.timer)))}},{key:"onMediaAttaching",value:function(e){this.media=e.media instanceof HTMLVideoElement?e.media:null}},{key:"onManifestParsed",value:function(e){this.hls.config.capLevelToPlayerSize&&(this.autoLevelCapping=Number.POSITIVE_INFINITY,this.levels=e.levels,this.hls.firstLevel=this.getMaxLevel(e.firstLevel),clearInterval(this.timer),this.timer=setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())}},{key:"detectPlayerSize",value:function(){if(this.media){var e=this.levels?this.levels.length:0;e&&(this.hls.autoLevelCapping=this.getMaxLevel(e-1),this.hls.autoLevelCapping>this.autoLevelCapping&&this.hls.streamController.nextLevelSwitch(),this.autoLevelCapping=this.hls.autoLevelCapping)}}},{key:"getMaxLevel",value:function(e){var t=void 0,r=void 0,a=void 0,i=this.mediaWidth,n=this.mediaHeight,s=0,o=0;for(r=0;r<=e&&(a=this.levels[r],t=r,s=a.width,o=a.height,!(i<=s||n<=o));r++);return t}},{key:"contentScaleFactor",get:function(){var e=1;try{e=window.devicePixelRatio}catch(e){}return e}},{key:"mediaWidth",get:function(){var e=void 0;return this.media&&(e=this.media.width||this.media.clientWidth||this.media.offsetWidth,e*=this.contentScaleFactor),e}},{key:"mediaHeight",get:function(){var e=void 0;return this.media&&(e=this.media.height||this.media.clientHeight||this.media.offsetHeight,e*=this.contentScaleFactor),e}}]),t}(f.default);r.default=h},{"../event-handler":22,"../events":23}],6:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("../utils/ewma"),o=a(s),l=function(){function e(t,r,a,n){i(this,e),this.hls=t,this.defaultEstimate_=n,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new o.default(r),this.fast_=new o.default(a)}return n(e,[{key:"sample",value:function(e,t){e=Math.max(e,this.minDelayMs_);var r=8e3*t/e,a=e/1e3;this.fast_.sample(a,r),this.slow_.sample(a,r)}},{key:"canEstimate",value:function(){var e=this.fast_;return e&&e.getTotalWeight()>=this.minWeight_}},{key:"getEstimate",value:function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_}},{key:"destroy",value:function(){}}]),e}();r.default=l},{"../utils/ewma":37}],7:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=e("../utils/logger"),c=e("../errors"),v=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this,e,u.default.MANIFEST_LOADED,u.default.LEVEL_LOADED,u.default.ERROR));return r.ontick=r.tick.bind(r),r._manualLevel=r._autoLevelCapping=-1,r}return s(t,e),o(t,[{key:"destroy",value:function(){this.timer&&(clearTimeout(this.timer),this.timer=null),this._manualLevel=-1}},{key:"startLoad",value:function(){this.canload=!0,this.timer&&this.tick()}},{key:"stopLoad",value:function(){this.canload=!1}},{key:"onManifestLoaded",value:function(e){var t,r,a=[],i=[],n={},s=!1,o=!1,l=this.hls;if(e.levels.forEach(function(e){e.videoCodec&&(s=!0),e.audioCodec&&(o=!0);var t=n[e.bitrate];void 0===t?(n[e.bitrate]=a.length,e.url=[e.url],e.urlId=0,a.push(e)):a[t].url.push(e.url)}),s&&o?a.forEach(function(e){e.videoCodec&&i.push(e)}):i=a,i=i.filter(function(e){var t=function(e){return MediaSource.isTypeSupported("audio/mp4;codecs="+e)},r=function(e){return MediaSource.isTypeSupported("video/mp4;codecs="+e)},a=e.audioCodec,i=e.videoCodec;return(!a||t(a))&&(!i||r(i))}),i.length){for(t=i[0].bitrate,i.sort(function(e,t){return e.bitrate-t.bitrate}),this._levels=i,r=0;r<i.length;r++)if(i[r].bitrate===t){this._firstLevel=r,h.logger.log("manifest loaded,"+i.length+" level(s) found, first bitrate:"+t);break}l.trigger(u.default.MANIFEST_PARSED,{levels:this._levels,firstLevel:this._firstLevel,stats:e.stats})}else l.trigger(u.default.ERROR,{type:c.ErrorTypes.MEDIA_ERROR,details:c.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:l.url,reason:"no level with compatible codecs found in manifest"})}},{key:"setLevelInternal",value:function(e){var t=this._levels;if(e>=0&&e<t.length){this.timer&&(clearTimeout(this.timer),this.timer=null),this._level=e,h.logger.log("switching to level "+e),this.hls.trigger(u.default.LEVEL_SWITCH,{level:e});var r=t[e],a=r.details;if(!a||a.live===!0&&performance.now()-a.tload>1e3){h.logger.log("(re)loading playlist for level "+e);var i=r.urlId;this.hls.trigger(u.default.LEVEL_LOADING,{url:r.url[i],level:e,id:i})}}else this.hls.trigger(u.default.ERROR,{type:c.ErrorTypes.OTHER_ERROR,details:c.ErrorDetails.LEVEL_SWITCH_ERROR,level:e,fatal:!1,reason:"invalid level idx"})}},{key:"onError",value:function(e){if(!e.fatal){var t=e.details,r=this.hls,a=void 0,i=void 0,n=!1;switch(t){case c.ErrorDetails.FRAG_LOAD_ERROR:case c.ErrorDetails.FRAG_LOAD_TIMEOUT:case c.ErrorDetails.FRAG_LOOP_LOADING_ERROR:case c.ErrorDetails.KEY_LOAD_ERROR:case c.ErrorDetails.KEY_LOAD_TIMEOUT:a=e.frag.level;break;case c.ErrorDetails.LEVEL_LOAD_ERROR:case c.ErrorDetails.LEVEL_LOAD_TIMEOUT:a=e.level,n=!0}if(void 0!==a)if(i=this._levels[a],i.urlId<i.url.length-1)i.urlId++,i.details=void 0,h.logger.warn("level controller,"+t+" for level "+a+": switching to redundant stream id "+i.urlId);else{var s=this._manualLevel===-1&&a;s?(h.logger.warn("level controller,"+t+": switch-down for next fragment"),r.nextLoadLevel=a-1):i&&i.details&&i.details.live?(h.logger.warn("level controller,"+t+" on live stream, discard"),n&&(this._level=void 0)):t!==c.ErrorDetails.FRAG_LOAD_ERROR&&t!==c.ErrorDetails.FRAG_LOAD_TIMEOUT&&t!==c.ErrorDetails.FRAG_LOOP_LOADING_ERROR&&(h.logger.error("cannot recover "+t+" error"),this._level=void 0,this.timer&&(clearTimeout(this.timer),this.timer=null),e.fatal=!0,r.trigger(u.default.ERROR,e))}}}},{key:"onLevelLoaded",value:function(e){if(e.level===this._level){var t=e.details;if(t.live){var r=1e3*t.targetduration,a=this._levels[e.level],i=a.details;i&&t.endSN===i.endSN&&(r/=2,h.logger.log("same live playlist, reload twice faster")),r-=performance.now()-e.stats.trequest,r=Math.max(1e3,Math.round(r)),h.logger.log("live playlist, reload in "+r+" ms"),this.timer=setTimeout(this.ontick,r)}else this.timer=null}}},{key:"tick",value:function(){var e=this._level;if(void 0!==e&&this.canload){var t=this._levels[e],r=t.urlId;this.hls.trigger(u.default.LEVEL_LOADING,{url:t.url[r],level:e,id:r})}}},{key:"levels",get:function(){return this._levels}},{key:"level",get:function(){return this._level},set:function(e){var t=this._levels;t&&t.length>e&&(this._level===e&&void 0!==t[e].details||this.setLevelInternal(e))}},{key:"manualLevel",get:function(){return this._manualLevel},set:function(e){this._manualLevel=e,void 0===this._startLevel&&(this._startLevel=e),e!==-1&&(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}},{key:"nextLoadLevel",get:function(){return this._manualLevel!==-1?this._manualLevel:this.hls.abrController.nextAutoLevel},set:function(e){this.level=e,this._manualLevel===-1&&(this.hls.abrController.nextAutoLevel=e)}}]),t}(f.default);r.default=v},{"../errors":21,"../event-handler":22,"../events":23,"../utils/logger":38}],8:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../demux/demuxer"),u=a(l),d=e("../events"),f=a(d),h=e("../event-handler"),c=a(h),v=e("../utils/logger"),g=e("../utils/binary-search"),p=a(g),y=e("../helper/buffer-helper"),m=a(y),E=e("../helper/level-helper"),b=a(E),_=e("../errors"),R={STOPPED:"STOPPED",STARTING:"STARTING",IDLE:"IDLE",PAUSED:"PAUSED",KEY_LOADING:"KEY_LOADING",FRAG_LOADING:"FRAG_LOADING",FRAG_LOADING_WAITING_RETRY:"FRAG_LOADING_WAITING_RETRY",WAITING_LEVEL:"WAITING_LEVEL",PARSING:"PARSING",PARSED:"PARSED",ENDED:"ENDED",ERROR:"ERROR"},L=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this,e,f.default.MEDIA_ATTACHED,f.default.MEDIA_DETACHING,f.default.MANIFEST_LOADING,f.default.MANIFEST_PARSED,f.default.LEVEL_LOADED,f.default.KEY_LOADED,f.default.FRAG_LOADED,f.default.FRAG_LOAD_EMERGENCY_ABORTED,f.default.FRAG_PARSING_INIT_SEGMENT,f.default.FRAG_PARSING_DATA,f.default.FRAG_PARSED,f.default.ERROR,f.default.BUFFER_APPENDED,f.default.BUFFER_FLUSHED));return r.config=e.config,r.audioCodecSwap=!1,r.ticks=0,r.ontick=r.tick.bind(r),r}return s(t,e),o(t,[{key:"destroy",value:function(){this.stopLoad(),this.timer&&(clearInterval(this.timer),this.timer=null),c.default.prototype.destroy.call(this),this.state=R.STOPPED}},{key:"startLoad",value:function(e){if(this.levels){var t=this.media,r=this.lastCurrentTime;this.stopLoad(),this.demuxer=new u.default(this.hls),this.timer||(this.timer=setInterval(this.ontick,100)),this.level=-1,this.fragLoadError=0,t&&r>0?(v.logger.log("configure startPosition @"+r),this.lastPaused||(v.logger.log("resuming video"),t.play())):this.lastCurrentTime=this.startPosition?this.startPosition:e,this.state=this.startFragRequested?R.IDLE:R.STARTING,this.nextLoadPosition=this.startPosition=this.lastCurrentTime,this.tick()}else v.logger.warn("cannot start loading as manifest not parsed yet"),this.state=R.STOPPED}},{key:"stopLoad",value:function(){var e=this.fragCurrent;e&&(e.loader&&e.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.demuxer&&(this.demuxer.destroy(),this.demuxer=null),this.state=R.STOPPED}},{key:"tick",value:function(){this.ticks++,1===this.ticks&&(this.doTick(),this.ticks>1&&setTimeout(this.tick,1),this.ticks=0)}},{key:"doTick",value:function(){var e,t,r,a=this.hls,i=a.config,n=this.media,s=n&&n.seeking;switch(this.state){case R.ERROR:case R.PAUSED:break;case R.STARTING:var o=a.startLevel;o===-1&&(o=0,this.fragBitrateTest=!0),this.level=a.nextLoadLevel=o,this.state=R.WAITING_LEVEL,this.loadedmetadata=!1;break;case R.IDLE:if(!n&&(this.startFragRequested||!i.startFragPrefetch))break;e=this.loadedmetadata?n.currentTime:this.nextLoadPosition,t=a.nextLoadLevel;var l,u=m.default.bufferInfo(n,e,i.maxBufferHole),d=u.len,h=u.end,c=this.fragPrevious;if(l=this.levels[t].hasOwnProperty("bitrate")?Math.max(8*i.maxBufferSize/this.levels[t].bitrate,i.maxBufferLength):i.maxBufferLength,l=Math.min(l,i.maxMaxBufferLength),d<l){if(a.nextLoadLevel=t,this.level=t,r=this.levels[t].details,"undefined"==typeof r||r.live&&this.levelLastLoaded!==t){
|
|
this.state=R.WAITING_LEVEL;break}if(!r.live&&c&&c.sn===r.endSN&&(!s||n.duration-h<=c.duration/2)){this.hls.trigger(f.default.BUFFER_EOS),this.state=R.ENDED;break}var g=r.fragments,y=g.length;if(0===y)break;var E=g[0].start,b=g[y-1].start+g[y-1].duration,L=void 0;if(r.live){var A=void 0!==i.liveMaxLatencyDuration?i.liveMaxLatencyDuration:i.liveMaxLatencyDurationCount*r.targetduration;if(h<Math.max(E,b-A)){var T=void 0!==i.liveSyncDuration?i.liveSyncDuration:i.liveSyncDurationCount*r.targetduration,k=E+Math.max(0,r.totalduration-T);v.logger.log("buffer end: "+h+" is located too far from the end of live sliding playlist, reset currentTime to : "+k.toFixed(3)),h=k,n&&n.readyState&&n.duration>k&&(n.currentTime=k)}if(r.PTSKnown&&h>b)break;if(this.startFragRequested&&!r.PTSKnown){if(c){var S=c.sn+1;S>=r.startSN&&S<=r.endSN&&(L=g[S-r.startSN],v.logger.log("live playlist, switching playlist, load frag with next SN: "+L.sn))}L||(L=g[Math.min(y-1,Math.round(y/2))],v.logger.log("live playlist, switching playlist, unknown, load middle frag : "+L.sn))}}else h<E&&(L=g[0]);if(L||!function(){var e=i.maxFragLookUpTolerance;h<b?((h>b-e||s)&&(e=0),L=p.default.search(g,function(t){return t.start+t.duration-e<=h?1:t.start-e>h?-1:0})):L=g[y-1]}(),L){if(E=L.start,c&&L.level===c.level&&L.sn===c.sn){if(!(L.sn<r.endSN))break;var w=c.deltaPTS,D=L.sn-r.startSN;if(w&&w>i.maxBufferHole&&c.dropped?(L=g[D-1],v.logger.warn("SN just loaded, with large PTS gap between audio and video, maybe frag is not starting with a keyframe ? load previous one to try to overcome this"),c.loadCounter--):(L=g[D+1],v.logger.log("SN just loaded, load next one: "+L.sn)),!L)break}if(null!=L.decryptdata.uri&&null==L.decryptdata.key)v.logger.log("Loading key for "+L.sn+" of ["+r.startSN+" ,"+r.endSN+"],level "+t),this.state=R.KEY_LOADING,a.trigger(f.default.KEY_LOADING,{frag:L});else{if(v.logger.log("Loading "+L.sn+" of ["+r.startSN+" ,"+r.endSN+"],level "+t+", currentTime:"+e+",bufferEnd:"+h.toFixed(3)),void 0!==this.fragLoadIdx?this.fragLoadIdx++:this.fragLoadIdx=0,L.loadCounter){L.loadCounter++;var O=i.fragLoadingLoopThreshold;if(L.loadCounter>O&&Math.abs(this.fragLoadIdx-L.loadIdx)<O)return void a.trigger(f.default.ERROR,{type:_.ErrorTypes.MEDIA_ERROR,details:_.ErrorDetails.FRAG_LOOP_LOADING_ERROR,fatal:!1,frag:L})}else L.loadCounter=1;L.loadIdx=this.fragLoadIdx,this.fragCurrent=L,this.startFragRequested=!0,L.autoLevel=a.autoLevelEnabled,L.bitrateTest=this.fragBitrateTest,a.trigger(f.default.FRAG_LOADING,{frag:L}),this.state=R.FRAG_LOADING}}}break;case R.WAITING_LEVEL:t=this.levels[this.level],t&&t.details&&(this.state=R.IDLE);break;case R.FRAG_LOADING_WAITING_RETRY:var P=performance.now(),I=this.retryDate;(!I||P>=I||s)&&(v.logger.log("mediaController: retryDate reached, switch back to IDLE state"),this.state=R.IDLE);break;case R.STOPPED:case R.FRAG_LOADING:case R.PARSING:case R.PARSED:case R.ENDED:}this._checkBuffer(),this._checkFragmentChanged()}},{key:"getBufferRange",value:function(e){var t,r,a=this.bufferRange;if(a)for(t=a.length-1;t>=0;t--)if(r=a[t],e>=r.start&&e<=r.end)return r;return null}},{key:"followingBufferRange",value:function(e){return e?this.getBufferRange(e.end+.5):null}},{key:"isBuffered",value:function(e){var t=this.media;if(t)for(var r=t.buffered,a=0;a<r.length;a++)if(e>=r.start(a)&&e<=r.end(a))return!0;return!1}},{key:"_checkFragmentChanged",value:function(){var e,t,r=this.media;if(r&&r.seeking===!1&&(t=r.currentTime,t>r.playbackRate*this.lastCurrentTime&&(this.lastCurrentTime=t),this.isBuffered(t)?e=this.getBufferRange(t):this.isBuffered(t+.1)&&(e=this.getBufferRange(t+.1)),e)){var a=e.frag;a!==this.fragPlaying&&(this.fragPlaying=a,this.hls.trigger(f.default.FRAG_CHANGED,{frag:a}))}}},{key:"immediateLevelSwitch",value:function(){if(v.logger.log("immediateLevelSwitch"),!this.immediateSwitch){this.immediateSwitch=!0;var e=this.media,t=void 0;e?(t=e.paused,e.pause()):t=!0,this.previouslyPaused=t}var r=this.fragCurrent;r&&r.loader&&r.loader.abort(),this.fragCurrent=null,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold,this.state=R.PAUSED,this.hls.trigger(f.default.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY})}},{key:"immediateLevelSwitchEnd",value:function(){this.immediateSwitch=!1;var e=this.media;e&&e.readyState&&(e.currentTime-=1e-4,this.previouslyPaused||e.play())}},{key:"nextLevelSwitch",value:function(){var e=this.media;if(e&&e.readyState){var t=void 0,r=void 0,a=void 0;if(this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold,r=this.getBufferRange(e.currentTime),r&&r.start>1&&(this.state=R.PAUSED,this.hls.trigger(f.default.BUFFER_FLUSHING,{startOffset:0,endOffset:r.start-1})),e.paused)t=0;else{var i=this.hls.nextLoadLevel,n=this.levels[i],s=this.fragLastKbps;t=s&&this.fragCurrent?this.fragCurrent.duration*n.bitrate/(1e3*s)+1:0}if(a=this.getBufferRange(e.currentTime+t),a&&(a=this.followingBufferRange(a))){var o=this.fragCurrent;o&&o.loader&&o.loader.abort(),this.fragCurrent=null,this.state=R.PAUSED,this.hls.trigger(f.default.BUFFER_FLUSHING,{startOffset:a.start,endOffset:Number.POSITIVE_INFINITY})}}}},{key:"onMediaAttached",value:function(e){var t=this.media=e.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),this.onvended=this.onMediaEnded.bind(this),t.addEventListener("seeking",this.onvseeking),t.addEventListener("seeked",this.onvseeked),t.addEventListener("ended",this.onvended);var r=this.config;this.levels&&r.autoStartLoad&&this.hls.startLoad(r.startPosition)}},{key:"onMediaDetaching",value:function(){var e=this.media;e&&e.ended&&(v.logger.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0);var t=this.levels;t&&t.forEach(function(e){e.details&&e.details.fragments.forEach(function(e){e.loadCounter=void 0})}),e&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("seeked",this.onvseeked),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvended=null),this.media=null,this.loadedmetadata=!1,this.stopLoad()}},{key:"onMediaSeeking",value:function(){if(this.state===R.FRAG_LOADING){if(0===m.default.bufferInfo(this.media,this.media.currentTime,this.config.maxBufferHole).len){v.logger.log("seeking outside of buffer while fragment load in progress, cancel fragment load");var e=this.fragCurrent;e&&(e.loader&&e.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.state=R.IDLE}}else this.state===R.ENDED&&(this.state=R.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:"onMediaEnded",value:function(){v.logger.log("media ended"),this.startPosition=this.lastCurrentTime=0}},{key:"onManifestLoading",value:function(){v.logger.log("trigger BUFFER_RESET"),this.hls.trigger(f.default.BUFFER_RESET),this.bufferRange=[],this.stalled=!1}},{key:"onManifestParsed",value:function(e){var t,r=!1,a=!1;e.levels.forEach(function(e){t=e.audioCodec,t&&(t.indexOf("mp4a.40.2")!==-1&&(r=!0),t.indexOf("mp4a.40.5")!==-1&&(a=!0))}),this.audioCodecSwitch=r&&a,this.audioCodecSwitch&&v.logger.log("both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=e.levels,this.startLevelLoaded=!1,this.startFragRequested=!1;var i=this.config;i.autoStartLoad&&this.hls.startLoad(i.startPosition)}},{key:"onLevelLoaded",value:function(e){var t=e.details,r=e.level,a=this.levels[r],i=t.totalduration,n=0;if(v.logger.log("level "+r+" loaded ["+t.startSN+","+t.endSN+"],duration:"+i),this.levelLastLoaded=r,t.live){var s=a.details;s?(b.default.mergeDetails(s,t),n=t.fragments[0].start,t.PTSKnown?v.logger.log("live playlist sliding:"+n.toFixed(3)):v.logger.log("live playlist - outdated PTS, unknown sliding")):(t.PTSKnown=!1,v.logger.log("live playlist - first load, unknown sliding"))}else t.PTSKnown=!1;if(a.details=t,this.hls.trigger(f.default.LEVEL_UPDATED,{details:t,level:r}),this.startFragRequested===!1){if(this.startPosition===-1){var o=t.startTimeOffset;if(isNaN(o))if(t.live){var l=void 0!==this.config.liveSyncDuration?this.config.liveSyncDuration:this.config.liveSyncDurationCount*t.targetduration;this.startPosition=Math.max(0,n+i-l)}else this.startPosition=0;else v.logger.log("start time offset found in playlist, adjust startPosition to "+o),this.startPosition=o}this.nextLoadPosition=this.startPosition}this.state===R.WAITING_LEVEL&&(this.state=R.IDLE),this.tick()}},{key:"onKeyLoaded",value:function(){this.state===R.KEY_LOADING&&(this.state=R.IDLE,this.tick())}},{key:"onFragLoaded",value:function(e){var t=this.fragCurrent,r=e.frag;if(this.state===R.FRAG_LOADING&&t&&r.level===t.level&&r.sn===t.sn){var a=e.stats;if(v.logger.log("Loaded "+t.sn+" of level "+t.level),this.fragBitrateTest=!1,r.bitrateTest===!0&&this.hls.nextLoadLevel)this.state=R.IDLE,this.startFragRequested=!1,a.tparsed=a.tbuffered=performance.now(),this.hls.trigger(f.default.FRAG_BUFFERED,{stats:a,frag:t}),this.tick();else{this.state=R.PARSING,this.stats=a;var i=this.levels[this.level],n=i.details,s=n.totalduration,o=void 0===t.startDTS||isNaN(t.startDTS)?t.start:t.startDTS,l=t.level,u=t.sn,d=i.audioCodec||this.config.defaultAudioCodec;this.audioCodecSwap&&(v.logger.log("swapping playlist audio codec"),void 0===d&&(d=this.lastAudioCodec),d&&(d=d.indexOf("mp4a.40.5")!==-1?"mp4a.40.2":"mp4a.40.5")),this.pendingAppending=0,v.logger.log("Demuxing "+u+" of ["+n.startSN+" ,"+n.endSN+"],level "+l+", cc "+t.cc);var h=this.demuxer;h&&h.push(e.payload,d,i.videoCodec,o,t.cc,l,u,s,t.decryptdata)}}this.fragLoadError=0}},{key:"onFragParsingInitSegment",value:function(e){if(this.state===R.PARSING){var t,r,a=e.tracks;if(r=a.audio){var i=this.levels[this.level].audioCodec,n=navigator.userAgent.toLowerCase();i&&this.audioCodecSwap&&(v.logger.log("swapping playlist audio codec"),i=i.indexOf("mp4a.40.5")!==-1?"mp4a.40.2":"mp4a.40.5"),this.audioCodecSwitch&&1!==r.metadata.channelCount&&n.indexOf("firefox")===-1&&(i="mp4a.40.5"),n.indexOf("android")!==-1&&(i="mp4a.40.2",v.logger.log("Android: force audio codec to"+i)),r.levelCodec=i}if(r=a.video,r&&(r.levelCodec=this.levels[this.level].videoCodec),e.unique){var s={codec:"",levelCodec:""};for(t in e.tracks)r=a[t],s.container=r.container,s.codec&&(s.codec+=",",s.levelCodec+=","),r.codec&&(s.codec+=r.codec),r.levelCodec&&(s.levelCodec+=r.levelCodec);a={audiovideo:s}}this.hls.trigger(f.default.BUFFER_CODECS,a);for(t in a){r=a[t],v.logger.log("track:"+t+",container:"+r.container+",codecs[level/parsed]=["+r.levelCodec+"/"+r.codec+"]");var o=r.initSegment;o&&(this.pendingAppending++,this.hls.trigger(f.default.BUFFER_APPENDING,{type:t,data:o}))}this.tick()}}},{key:"onFragParsingData",value:function(e){var t=this;if(this.state===R.PARSING){this.tparse2=Date.now();var r=this.levels[this.level],a=this.fragCurrent;v.logger.log("parsed "+e.type+",PTS:["+e.startPTS.toFixed(3)+","+e.endPTS.toFixed(3)+"],DTS:["+e.startDTS.toFixed(3)+"/"+e.endDTS.toFixed(3)+"],nb:"+e.nb+",dropped:"+(e.dropped||0));var i=b.default.updateFragPTSDTS(r.details,a.sn,e.startPTS,e.endPTS,e.startDTS,e.endDTS),n=this.hls;n.trigger(f.default.LEVEL_PTS_UPDATED,{details:r.details,level:this.level,drift:i}),"video"===e.type&&(a.dropped=e.dropped),[e.data1,e.data2].forEach(function(r){r&&(t.pendingAppending++,n.trigger(f.default.BUFFER_APPENDING,{type:e.type,data:r}))}),this.nextLoadPosition=e.endPTS,this.bufferRange.push({type:e.type,start:e.startPTS,end:e.endPTS,frag:a}),this.tick()}else v.logger.warn("not in PARSING state but "+this.state+", ignoring FRAG_PARSING_DATA event")}},{key:"onFragParsed",value:function(){this.state===R.PARSING&&(this.stats.tparsed=performance.now(),this.state=R.PARSED,this._checkAppendedParsed())}},{key:"onBufferAppended",value:function(){switch(this.state){case R.PARSING:case R.PARSED:this.pendingAppending--,this._checkAppendedParsed()}}},{key:"_checkAppendedParsed",value:function(){if(this.state===R.PARSED&&0===this.pendingAppending){var e=this.fragCurrent,t=this.stats;e&&(this.fragPrevious=e,t.tbuffered=performance.now(),this.fragLastKbps=Math.round(8*t.length/(t.tbuffered-t.tfirst)),this.hls.trigger(f.default.FRAG_BUFFERED,{stats:t,frag:e}),v.logger.log("media buffered : "+this.timeRangesToString(this.media.buffered)),this.state=R.IDLE),this.tick()}}},{key:"onError",value:function(e){var t=this.media,r=t&&this.isBuffered(t.currentTime)&&this.isBuffered(t.currentTime+.4),a=e.frag||this.fragCurrent;switch(e.details){case _.ErrorDetails.FRAG_LOAD_ERROR:case _.ErrorDetails.FRAG_LOAD_TIMEOUT:if(!e.fatal){var i=this.fragLoadError;if(i?i++:i=1,i<=this.config.fragLoadingMaxRetry||r){this.fragLoadError=i,a.loadCounter=0;var n=Math.min(Math.pow(2,i-1)*this.config.fragLoadingRetryDelay,64e3);v.logger.warn("mediaController: frag loading failed, retry in "+n+" ms"),this.retryDate=performance.now()+n,this.state=R.FRAG_LOADING_WAITING_RETRY}else v.logger.error("mediaController: "+e.details+" reaches max retry, redispatch as fatal ..."),e.fatal=!0,this.hls.trigger(f.default.ERROR,e),this.state=R.ERROR}break;case _.ErrorDetails.FRAG_LOOP_LOADING_ERROR:e.fatal||(r?(this._reduceMaxMaxBufferLength(a.duration),this.state=R.IDLE):a.autoLevel&&0!==a.level||(e.fatal=!0,this.hls.trigger(f.default.ERROR,e),this.state=R.ERROR));break;case _.ErrorDetails.LEVEL_LOAD_ERROR:case _.ErrorDetails.LEVEL_LOAD_TIMEOUT:case _.ErrorDetails.KEY_LOAD_ERROR:case _.ErrorDetails.KEY_LOAD_TIMEOUT:this.state!==R.ERROR&&(this.state=e.fatal?R.ERROR:R.IDLE,v.logger.warn("mediaController: "+e.details+" while loading frag,switch to "+this.state+" state ..."));break;case _.ErrorDetails.BUFFER_FULL_ERROR:this.state!==R.PARSING&&this.state!==R.PARSED||(this._reduceMaxMaxBufferLength(a.duration),this.state=R.IDLE)}}},{key:"_reduceMaxMaxBufferLength",value:function(e){this.config.maxMaxBufferLength>=e&&(this.config.maxMaxBufferLength/=2,v.logger.warn("reduce max buffer length to "+this.config.maxMaxBufferLength+"s and switch to IDLE state"),this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold)}},{key:"_checkBuffer",value:function(){var e=this.media;if(e&&e.readyState){var t=e.currentTime,r=e.buffered;if(!this.loadedmetadata&&r.length){this.loadedmetadata=!0;var a=this.startPosition;if(!t&&t!==a&&a){v.logger.log("target start position:"+a);var i=r.start(0),n=r.end(0);(a<i||a>n)&&(a=i,v.logger.log("target start position not buffered, seek to buffered.start(0) "+i)),v.logger.log("adjust currentTime from "+t+" to "+a),e.currentTime=a}}else{var s=m.default.bufferInfo(e,t,0),o=!(e.paused||e.ended||0===e.buffered.length),l=.4,u=t>e.playbackRate*this.lastCurrentTime;if(this.stalled&&u&&(this.stalled=!1,v.logger.log("playback not stuck anymore @"+t)),o&&s.len<=l&&(u?(l=0,this.seekHoleNudgeDuration=0):this.stalled?this.seekHoleNudgeDuration+=this.config.seekHoleNudgeDuration:(this.seekHoleNudgeDuration=0,v.logger.log("playback seems stuck @"+t),this.hls.trigger(f.default.ERROR,{type:_.ErrorTypes.MEDIA_ERROR,details:_.ErrorDetails.BUFFER_STALLED_ERROR,fatal:!1}),this.stalled=!0),s.len<=l)){var d=s.nextStart,h=d-t;if(d&&h<this.config.maxSeekHole&&h>0){v.logger.log("adjust currentTime from "+e.currentTime+" to next buffered @ "+d+" + nudge "+this.seekHoleNudgeDuration);var c=d+this.seekHoleNudgeDuration-e.currentTime;e.currentTime=d+this.seekHoleNudgeDuration,this.hls.trigger(f.default.ERROR,{type:_.ErrorTypes.MEDIA_ERROR,details:_.ErrorDetails.BUFFER_SEEK_OVER_HOLE,fatal:!1,hole:c})}}}}}},{key:"onFragLoadEmergencyAborted",value:function(){this.state=R.IDLE,this.tick()}},{key:"onBufferFlushed",value:function(){var e,t,r=[];for(t=0;t<this.bufferRange.length;t++)e=this.bufferRange[t],this.isBuffered((e.start+e.end)/2)&&r.push(e);this.bufferRange=r,this.immediateSwitch&&this.immediateLevelSwitchEnd(),this.state=R.IDLE,this.fragPrevious=null}},{key:"swapAudioCodec",value:function(){this.audioCodecSwap=!this.audioCodecSwap}},{key:"timeRangesToString",value:function(e){for(var t="",r=e.length,a=0;a<r;a++)t+="["+e.start(a)+","+e.end(a)+"]";return t}},{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}}]),t}(c.default);r.default=L},{"../demux/demuxer":17,"../errors":21,"../event-handler":22,"../events":23,"../helper/buffer-helper":24,"../helper/level-helper":25,"../utils/binary-search":35,"../utils/logger":38}],9:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=e("../utils/cea-708-interpreter"),c=a(h),v=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this,e,u.default.MEDIA_ATTACHING,u.default.MEDIA_DETACHING,u.default.FRAG_PARSING_USERDATA,u.default.MANIFEST_LOADING,u.default.FRAG_LOADED));return r.hls=e,r.config=e.config,r.config.enableCEA708Captions&&(r.cea708Interpreter=new c.default),r}return s(t,e),o(t,[{key:"destroy",value:function(){f.default.prototype.destroy.call(this)}},{key:"onMediaAttaching",value:function(e){var t=this.media=e.media;this.cea708Interpreter.attach(t)}},{key:"onMediaDetaching",value:function(){this.cea708Interpreter.detach()}},{key:"onManifestLoading",value:function(){this.lastPts=Number.POSITIVE_INFINITY}},{key:"onFragLoaded",value:function(e){var t=e.frag.start;t<=this.lastPts&&this.cea708Interpreter.clear(),this.lastPts=t}},{key:"onFragParsingUserdata",value:function(e){for(var t=0;t<e.samples.length;t++)this.cea708Interpreter.push(e.samples[t].pts,e.samples[t].bytes)}}]),t}(f.default);r.default=v},{"../event-handler":22,"../events":23,"../utils/cea-708-interpreter":36}],10:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=function(){function e(t){a(this,e),this._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],this._precompute();var r,i,n,s,o,l=this._tables[0][4],u=this._tables[1],d=t.length,f=1;if(4!==d&&6!==d&&8!==d)throw new Error("Invalid aes key size="+d);for(s=t.slice(0),o=[],this._key=[s,o],r=d;r<4*d+28;r++)n=s[r-1],(r%d===0||8===d&&r%d===4)&&(n=l[n>>>24]<<24^l[n>>16&255]<<16^l[n>>8&255]<<8^l[255&n],r%d===0&&(n=n<<8^n>>>24^f<<24,f=f<<1^283*(f>>7))),s[r]=s[r-d]^n;for(i=0;r;i++,r--)n=s[3&i?r:r-4],r<=4||i<4?o[i]=n:o[i]=u[0][l[n>>>24]]^u[1][l[n>>16&255]]^u[2][l[n>>8&255]]^u[3][l[255&n]]}return i(e,[{key:"_precompute",value:function(){var e,t,r,a,i,n,s,o,l,u=this._tables[0],d=this._tables[1],f=u[4],h=d[4],c=[],v=[];for(e=0;e<256;e++)v[(c[e]=e<<1^283*(e>>7))^e]=e;for(t=r=0;!f[t];t^=a||1,r=v[r]||1)for(s=r^r<<1^r<<2^r<<3^r<<4,s=s>>8^255&s^99,f[t]=s,h[s]=t,n=c[i=c[a=c[t]]],l=16843009*n^65537*i^257*a^16843008*t,o=257*c[s]^16843008*s,e=0;e<4;e++)u[e][t]=o=o<<24^o>>>8,d[e][s]=l=l<<24^l>>>8;for(e=0;e<5;e++)u[e]=u[e].slice(0),d[e]=d[e].slice(0)}},{key:"decrypt",value:function(e,t,r,a,i,n){var s,o,l,u,d=this._key[1],f=e^d[0],h=a^d[1],c=r^d[2],v=t^d[3],g=d.length/4-2,p=4,y=this._tables[1],m=y[0],E=y[1],b=y[2],_=y[3],R=y[4];for(u=0;u<g;u++)s=m[f>>>24]^E[h>>16&255]^b[c>>8&255]^_[255&v]^d[p],o=m[h>>>24]^E[c>>16&255]^b[v>>8&255]^_[255&f]^d[p+1],l=m[c>>>24]^E[v>>16&255]^b[f>>8&255]^_[255&h]^d[p+2],v=m[v>>>24]^E[f>>16&255]^b[h>>8&255]^_[255&c]^d[p+3],p+=4,f=s,h=o,c=l;for(u=0;u<4;u++)i[(3&-u)+n]=R[f>>>24]<<24^R[h>>16&255]<<16^R[c>>8&255]<<8^R[255&v]^d[p++],s=f,f=h,h=c,c=v,v=s}}]),e}();r.default=n},{}],11:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("./aes"),o=a(s),l=function(){function e(t,r){i(this,e),this.key=t,this.iv=r}return n(e,[{key:"ntoh",value:function(e){return e<<24|(65280&e)<<8|(16711680&e)>>8|e>>>24}},{key:"doDecrypt",value:function(e,t,r){var a,i,n,s,l,u,d,f,h,c=new Int32Array(e.buffer,e.byteOffset,e.byteLength>>2),v=new o.default(Array.prototype.slice.call(t)),g=new Uint8Array(e.byteLength),p=new Int32Array(g.buffer);for(a=~~r[0],i=~~r[1],n=~~r[2],s=~~r[3],h=0;h<c.length;h+=4)l=~~this.ntoh(c[h]),u=~~this.ntoh(c[h+1]),d=~~this.ntoh(c[h+2]),f=~~this.ntoh(c[h+3]),v.decrypt(l,u,d,f,p,h),p[h]=this.ntoh(p[h]^a),p[h+1]=this.ntoh(p[h+1]^i),p[h+2]=this.ntoh(p[h+2]^n),p[h+3]=this.ntoh(p[h+3]^s),a=l,i=u,n=d,s=f;return g}},{key:"localDecrypt",value:function(e,t,r,a){var i=this.doDecrypt(e,t,r);a.set(i,e.byteOffset)}},{key:"decrypt",value:function(e){var t=32e3,r=new Int32Array(e),a=new Uint8Array(e.byteLength),i=0,n=this.key,s=this.iv;for(this.localDecrypt(r.subarray(i,i+t),n,s,a),i=t;i<r.length;i+=t)s=new Uint32Array([this.ntoh(r[i-4]),this.ntoh(r[i-3]),this.ntoh(r[i-2]),this.ntoh(r[i-1])]),this.localDecrypt(r.subarray(i,i+t),n,s,a);return a}}]),e}();r.default=l},{"./aes":10}],12:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("./aes128-decrypter"),o=a(s),l=e("../errors"),u=e("../utils/logger"),d=function(){function e(t){i(this,e),this.hls=t;try{var r=window?window.crypto:crypto;this.subtle=r.subtle||r.webkitSubtle,this.disableWebCrypto=!this.subtle}catch(e){this.disableWebCrypto=!0}}return n(e,[{key:"destroy",value:function(){}},{key:"decrypt",value:function(e,t,r,a){this.disableWebCrypto&&this.hls.config.enableSoftwareAES?this.decryptBySoftware(e,t,r,a):this.decryptByWebCrypto(e,t,r,a)}},{key:"decryptByWebCrypto",value:function(e,t,r,a){var i=this;u.logger.log("decrypting by WebCrypto API"),this.subtle.importKey("raw",t,{name:"AES-CBC",length:128},!1,["decrypt"]).then(function(n){i.subtle.decrypt({name:"AES-CBC",iv:r.buffer},n,e).then(a).catch(function(n){i.onWebCryptoError(n,e,t,r,a)})}).catch(function(n){i.onWebCryptoError(n,e,t,r,a)})}},{key:"decryptBySoftware",value:function(e,t,r,a){u.logger.log("decrypting by JavaScript Implementation");var i=new DataView(t.buffer),n=new Uint32Array([i.getUint32(0),i.getUint32(4),i.getUint32(8),i.getUint32(12)]);i=new DataView(r.buffer);var s=new Uint32Array([i.getUint32(0),i.getUint32(4),i.getUint32(8),i.getUint32(12)]),l=new o.default(n,s);a(l.decrypt(e).buffer)}},{key:"onWebCryptoError",value:function(e,t,r,a,i){this.hls.config.enableSoftwareAES?(u.logger.log("disabling to use WebCrypto API"),this.disableWebCrypto=!0,this.decryptBySoftware(t,r,a,i)):(u.logger.error("decrypting error : "+e.message),this.hls.trigger(Event.ERROR,{type:l.ErrorTypes.MEDIA_ERROR,details:l.ErrorDetails.FRAG_DECRYPT_ERROR,fatal:!0,reason:e.message}))}}]),e}();r.default=d},{"../errors":21,"../utils/logger":38,"./aes128-decrypter":11}],13:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("./adts"),o=a(s),l=e("../utils/logger"),u=e("../demux/id3"),d=a(u),f=function(){function e(t,r){i(this,e),this.observer=t,this.remuxerClass=r,this.remuxer=new this.remuxerClass(t),this._aacTrack={container:"audio/adts",type:"audio",id:-1,sequenceNumber:0,samples:[],len:0}}return n(e,[{key:"push",value:function(e,t,r,a,i,n,s,u){var f,h,c,v,g,p,y,m,E,b=this._aacTrack,_=new d.default(e),R=90*_.timeStamp;for(g=_.length,m=e.length;g<m-1&&(255!==e[g]||240!==(240&e[g+1]));g++);for(b.audiosamplerate||(f=o.default.getAudioConfig(this.observer,e,g,t),b.config=f.config,b.audiosamplerate=f.samplerate,b.channelCount=f.channelCount,b.codec=f.codec,b.duration=u,l.logger.log("parsed codec:"+b.codec+",rate:"+f.samplerate+",nb channel:"+f.channelCount)),v=0,c=9216e4/b.audiosamplerate;g+5<m&&(p=1&e[g+1]?7:9,h=(3&e[g+3])<<11|e[g+4]<<3|(224&e[g+5])>>>5,h-=p,h>0&&g+p+h<=m);)for(y=R+v*c,E={unit:e.subarray(g+p,g+p+h),pts:y,dts:y},b.samples.push(E),b.len+=h,g+=h+p,v++;g<m-1&&(255!==e[g]||240!==(240&e[g+1]));g++);this.remuxer.remux(this._aacTrack,{samples:[]},{samples:[{pts:R,dts:R,unit:_.payload}]},{samples:[]},a)}},{key:"destroy",value:function(){}}],[{key:"probe",value:function(e){var t,r,a=new d.default(e);if(a.hasTimeStamp)for(t=a.length,r=e.length;t<r-1;t++)if(255===e[t]&&240===(240&e[t+1]))return!0;return!1}}]),e}();r.default=f},{"../demux/id3":19,"../utils/logger":38,"./adts":14}],14:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=e("../utils/logger"),s=e("../errors"),o=function(){function e(){a(this,e)}return i(e,null,[{key:"getAudioConfig",value:function(e,t,r,a){var i,o,l,u,d,f=navigator.userAgent.toLowerCase(),h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];return i=((192&t[r+2])>>>6)+1,o=(60&t[r+2])>>>2,o>h.length-1?void e.trigger(Event.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+o}):(u=(1&t[r+2])<<2,u|=(192&t[r+3])>>>6,n.logger.log("manifest codec:"+a+",ADTS data:type:"+i+",sampleingIndex:"+o+"["+h[o]+"Hz],channelConfig:"+u),f.indexOf("firefox")!==-1?o>=6?(i=5,d=new Array(4),l=o-3):(i=2,d=new Array(2),l=o):f.indexOf("android")!==-1?(i=2,d=new Array(2),l=o):(i=5,d=new Array(4),a&&(a.indexOf("mp4a.40.29")!==-1||a.indexOf("mp4a.40.5")!==-1)||!a&&o>=6?l=o-3:((a&&a.indexOf("mp4a.40.2")!==-1&&o>=6&&1===u||!a&&1===u)&&(i=2,d=new Array(2)),l=o)),d[0]=i<<3,d[0]|=(14&o)>>1,d[1]|=(1&o)<<7,d[1]|=u<<3,5===i&&(d[1]|=(14&l)>>1,d[2]=(1&l)<<7,d[2]|=8,d[3]=0),{config:d,samplerate:h[o],channelCount:u,codec:"mp4a.40."+i})}}]),e}();r.default=o},{"../errors":21,"../utils/logger":38}],15:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("../events"),o=a(s),l=e("../errors"),u=e("../demux/aacdemuxer"),d=a(u),f=e("../demux/tsdemuxer"),h=a(f),c=e("../remux/mp4-remuxer"),v=a(c),g=e("../remux/passthrough-remuxer"),p=a(g),y=function(){function e(t,r){i(this,e),this.hls=t,this.typeSupported=r}return n(e,[{key:"destroy",value:function(){var e=this.demuxer;e&&e.destroy()}},{key:"push",value:function(e,t,r,a,i,n,s,u){var f=this.demuxer;if(!f){var c=this.hls;if(h.default.probe(e))f=this.typeSupported.mp2t===!0?new h.default(c,p.default):new h.default(c,v.default);else{if(!d.default.probe(e))return void c.trigger(o.default.ERROR,{type:l.ErrorTypes.MEDIA_ERROR,details:l.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"no demux matching with content found"});f=new d.default(c,v.default)}this.demuxer=f}f.push(e,t,r,a,i,n,s,u)}}]),e}();r.default=y},{"../demux/aacdemuxer":13,"../demux/tsdemuxer":20,"../errors":21,"../events":23,"../remux/mp4-remuxer":32,"../remux/passthrough-remuxer":33}],16:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var i=e("../demux/demuxer-inline"),n=a(i),s=e("../events"),o=a(s),l=e("events"),u=a(l),d=function(e){var t=new u.default;t.trigger=function(e){for(var r=arguments.length,a=Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];t.emit.apply(t,[e,e].concat(a))},t.off=function(e){for(var r=arguments.length,a=Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];t.removeListener.apply(t,[e].concat(a))},e.addEventListener("message",function(r){var a=r.data;switch(a.cmd){case"init":e.demuxer=new n.default(t,a.typeSupported);break;case"demux":e.demuxer.push(new Uint8Array(a.data),a.audioCodec,a.videoCodec,a.timeOffset,a.cc,a.level,a.sn,a.duration)}}),t.on(o.default.FRAG_PARSING_INIT_SEGMENT,function(t,r){e.postMessage({event:t,tracks:r.tracks,unique:r.unique})}),t.on(o.default.FRAG_PARSING_DATA,function(t,r){var a={event:t,type:r.type,startPTS:r.startPTS,endPTS:r.endPTS,startDTS:r.startDTS,endDTS:r.endDTS,data1:r.data1.buffer,data2:r.data2.buffer,nb:r.nb,dropped:r.dropped};e.postMessage(a,[a.data1,a.data2])}),t.on(o.default.FRAG_PARSED,function(t){e.postMessage({event:t})}),t.on(o.default.ERROR,function(t,r){e.postMessage({event:t,data:r})}),t.on(o.default.FRAG_PARSING_METADATA,function(t,r){var a={event:t,samples:r.samples};e.postMessage(a)}),t.on(o.default.FRAG_PARSING_USERDATA,function(t,r){var a={event:t,samples:r.samples};e.postMessage(a)})};r.default=d},{"../demux/demuxer-inline":15,"../events":23,events:1}],17:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("../events"),o=a(s),l=e("../demux/demuxer-inline"),u=a(l),d=e("../demux/demuxer-worker"),f=a(d),h=e("../utils/logger"),c=e("../crypt/decrypter"),v=a(c),g=e("../errors"),p=function(){function t(r){i(this,t),this.hls=r;var a={mp4:MediaSource.isTypeSupported("video/mp4"),mp2t:r.config.enableMP2TPassThrough&&MediaSource.isTypeSupported("video/mp2t")};if(r.config.enableWorker&&"undefined"!=typeof Worker){h.logger.log("demuxing in webworker");try{var n=e("webworkify"),s=this.w=n(f.default);this.onwmsg=this.onWorkerMessage.bind(this),s.addEventListener("message",this.onwmsg),
|
|
s.onerror=function(e){r.trigger(o.default.ERROR,{type:g.ErrorTypes.OTHER_ERROR,details:g.ErrorDetails.INTERNAL_EXCEPTION,fatal:!0,event:"demuxerWorker",err:{message:e.message+" ("+e.filename+":"+e.lineno+")"}})},s.postMessage({cmd:"init",typeSupported:a})}catch(e){h.logger.error("error while initializing DemuxerWorker, fallback on DemuxerInline"),this.demuxer=new u.default(r,a)}}else this.demuxer=new u.default(r,a);this.demuxInitialized=!0}return n(t,[{key:"destroy",value:function(){var e=this.w;if(e)e.removeEventListener("message",this.onwmsg),e.terminate(),this.w=null;else{var t=this.demuxer;t&&(t.destroy(),this.demuxer=null)}var r=this.decrypter;r&&(r.destroy(),this.decrypter=null)}},{key:"pushDecrypted",value:function(e,t,r,a,i,n,s,o){var l=this.w;if(l)l.postMessage({cmd:"demux",data:e,audioCodec:t,videoCodec:r,timeOffset:a,cc:i,level:n,sn:s,duration:o},[e]);else{var u=this.demuxer;u&&u.push(new Uint8Array(e),t,r,a,i,n,s,o)}}},{key:"push",value:function(e,t,r,a,i,n,s,o,l){if(e.byteLength>0&&null!=l&&null!=l.key&&"AES-128"===l.method){null==this.decrypter&&(this.decrypter=new v.default(this.hls));var u=this;this.decrypter.decrypt(e,l.key,l.iv,function(e){u.pushDecrypted(e,t,r,a,i,n,s,o)})}else this.pushDecrypted(e,t,r,a,i,n,s,o)}},{key:"onWorkerMessage",value:function(e){var t=e.data;switch(t.event){case o.default.FRAG_PARSING_INIT_SEGMENT:var r={};r.tracks=t.tracks,r.unique=t.unique,this.hls.trigger(o.default.FRAG_PARSING_INIT_SEGMENT,r);break;case o.default.FRAG_PARSING_DATA:this.hls.trigger(o.default.FRAG_PARSING_DATA,{data1:new Uint8Array(t.data1),data2:new Uint8Array(t.data2),startPTS:t.startPTS,endPTS:t.endPTS,startDTS:t.startDTS,endDTS:t.endDTS,type:t.type,nb:t.nb,dropped:t.dropped});break;case o.default.FRAG_PARSING_METADATA:this.hls.trigger(o.default.FRAG_PARSING_METADATA,{samples:t.samples});break;case o.default.FRAG_PARSING_USERDATA:this.hls.trigger(o.default.FRAG_PARSING_USERDATA,{samples:t.samples});break;default:this.hls.trigger(t.event,t.data)}}}]),t}();r.default=p},{"../crypt/decrypter":12,"../demux/demuxer-inline":15,"../demux/demuxer-worker":16,"../errors":21,"../events":23,"../utils/logger":38,webworkify:2}],18:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=e("../utils/logger"),s=function(){function e(t){a(this,e),this.data=t,this.bytesAvailable=this.data.byteLength,this.word=0,this.bitsAvailable=0}return i(e,[{key:"loadWord",value:function(){var e=this.data.byteLength-this.bytesAvailable,t=new Uint8Array(4),r=Math.min(4,this.bytesAvailable);if(0===r)throw new Error("no bytes available");t.set(this.data.subarray(e,e+r)),this.word=new DataView(t.buffer).getUint32(0),this.bitsAvailable=8*r,this.bytesAvailable-=r}},{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(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;return e>32&&n.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0?this.word<<=t:this.bytesAvailable>0&&this.loadWord(),t=e-t,t>0?r<<t|this.readBits(t):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:"readUShort",value:function(){return this.readBits(16)}},{key:"readUInt",value:function(){return this.readBits(32)}},{key:"skipScalingList",value:function(e){var t,r,a=8,i=8;for(t=0;t<e;t++)0!==i&&(r=this.readEG(),i=(a+r+256)%256),a=0===i?a:i}},{key:"readSPS",value:function(){var e,t,r,a,i,n,s,o,l,u=0,d=0,f=0,h=0,c=1;if(this.readUByte(),e=this.readUByte(),t=this.readBits(5),this.skipBits(3),r=this.readUByte(),this.skipUEG(),100===e||110===e||122===e||244===e||44===e||83===e||86===e||118===e||128===e){var v=this.readUEG();if(3===v&&this.skipBits(1),this.skipUEG(),this.skipUEG(),this.skipBits(1),this.readBoolean())for(o=3!==v?8:12,l=0;l<o;l++)this.readBoolean()&&(l<6?this.skipScalingList(16):this.skipScalingList(64))}this.skipUEG();var g=this.readUEG();if(0===g)this.readUEG();else if(1===g)for(this.skipBits(1),this.skipEG(),this.skipEG(),a=this.readUEG(),l=0;l<a;l++)this.skipEG();if(this.skipUEG(),this.skipBits(1),i=this.readUEG(),n=this.readUEG(),s=this.readBits(1),0===s&&this.skipBits(1),this.skipBits(1),this.readBoolean()&&(u=this.readUEG(),d=this.readUEG(),f=this.readUEG(),h=this.readUEG()),this.readBoolean()&&this.readBoolean()){var p=void 0,y=this.readUByte();switch(y){case 1:p=[1,1];break;case 2:p=[12,11];break;case 3:p=[10,11];break;case 4:p=[16,11];break;case 5:p=[40,33];break;case 6:p=[24,11];break;case 7:p=[20,11];break;case 8:p=[32,11];break;case 9:p=[80,33];break;case 10:p=[18,11];break;case 11:p=[15,11];break;case 12:p=[64,33];break;case 13:p=[160,99];break;case 14:p=[4,3];break;case 15:p=[3,2];break;case 16:p=[2,1];break;case 255:p=[this.readUByte()<<8|this.readUByte(),this.readUByte()<<8|this.readUByte()]}p&&(c=p[0]/p[1])}return{width:Math.ceil((16*(i+1)-2*u-2*d)*c),height:(2-s)*(n+1)*16-(s?2:4)*(f+h)}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}();r.default=s},{"../utils/logger":38}],19:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=e("../utils/logger"),s=function(){function e(t){a(this,e),this._hasTimeStamp=!1;for(var r,i,s,o,l,u,d,f,h=0;;)if(d=this.readUTF(t,h,3),h+=3,"ID3"===d)h+=3,r=127&t[h++],i=127&t[h++],s=127&t[h++],o=127&t[h++],l=(r<<21)+(i<<14)+(s<<7)+o,u=h+l,this._parseID3Frames(t,h,u),h=u;else{if("3DI"!==d)return h-=3,f=h,void(f&&(this.hasTimeStamp||n.logger.warn("ID3 tag found, but no timestamp"),this._length=f,this._payload=t.subarray(0,f)));h+=7,n.logger.log("3DI footer found, end: "+h)}}return i(e,[{key:"readUTF",value:function(e,t,r){var a="",i=t,n=t+r;do a+=String.fromCharCode(e[i++]);while(i<n);return a}},{key:"_parseID3Frames",value:function(e,t,r){for(var a,i,s,o,l;t+8<=r;)switch(a=this.readUTF(e,t,4),t+=4,i=e[t++]<<24+e[t++]<<16+e[t++]<<8+e[t++],o=e[t++]<<8+e[t++],s=t,a){case"PRIV":if("com.apple.streaming.transportStreamTimestamp"===this.readUTF(e,t,44)){t+=44,t+=4;var u=1&e[t++];this._hasTimeStamp=!0,l=((e[t++]<<23)+(e[t++]<<15)+(e[t++]<<7)+e[t++])/45,u&&(l+=47721858.84),l=Math.round(l),n.logger.trace("ID3 timestamp found: "+l),this._timeStamp=l}}}},{key:"hasTimeStamp",get:function(){return this._hasTimeStamp}},{key:"timeStamp",get:function(){return this._timeStamp}},{key:"length",get:function(){return this._length}},{key:"payload",get:function(){return this._payload}}]),e}();r.default=s},{"../utils/logger":38}],20:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("./adts"),o=a(s),l=e("../events"),u=a(l),d=e("./exp-golomb"),f=a(d),h=e("../utils/logger"),c=e("../errors"),v=function(){function e(t,r){i(this,e),this.observer=t,this.remuxerClass=r,this.lastCC=0,this.remuxer=new this.remuxerClass(t)}return n(e,[{key:"switchLevel",value:function(){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack={container:"video/mp2t",type:"video",id:-1,sequenceNumber:0,samples:[],len:0,nbNalu:0,dropped:0},this._aacTrack={container:"video/mp2t",type:"audio",id:-1,sequenceNumber:0,samples:[],len:0},this._id3Track={type:"id3",id:-1,sequenceNumber:0,samples:[],len:0},this._txtTrack={type:"text",id:-1,sequenceNumber:0,samples:[],len:0},this.aacOverFlow=null,this.aacLastPTS=null,this.avcNaluState=0,this.remuxer.switchLevel()}},{key:"insertDiscontinuity",value:function(){this.switchLevel(),this.remuxer.insertDiscontinuity()}},{key:"push",value:function(e,t,r,a,i,n,s,o){var l,d,f,v,g,p,y,m,E=e.length,b=this.remuxer.passthrough,_=!1;this.audioCodec=t,this.videoCodec=r,this.timeOffset=a,this._duration=o,this.contiguous=!1,i!==this.lastCC&&(h.logger.log("discontinuity detected"),this.insertDiscontinuity(),this.lastCC=i),n!==this.lastLevel?(h.logger.log("level switch detected"),this.switchLevel(),this.lastLevel=n):s===this.lastSN+1&&(this.contiguous=!0),this.lastSN=s;var R=this.pmtParsed,L=this._avcTrack.id,A=this._aacTrack.id,T=this._id3Track.id;for(E-=E%188,v=0;v<E;v+=188)if(71===e[v]){if(g=!!(64&e[v+1]),p=((31&e[v+1])<<8)+e[v+2],y=(48&e[v+3])>>4,y>1){if(m=v+5+e[v+4],m===v+188)continue}else m=v+4;if(R)if(p===L){if(g){if(l&&(this._parseAVCPES(this._parsePES(l)),b&&this._avcTrack.codec&&(A===-1||this._aacTrack.codec)))return void this.remux(e);l={data:[],size:0}}l&&(l.data.push(e.subarray(m,v+188)),l.size+=v+188-m)}else if(p===A){if(g){if(d&&(this._parseAACPES(this._parsePES(d)),b&&this._aacTrack.codec&&(L===-1||this._avcTrack.codec)))return void this.remux(e);d={data:[],size:0}}d&&(d.data.push(e.subarray(m,v+188)),d.size+=v+188-m)}else p===T&&(g&&(f&&this._parseID3PES(this._parsePES(f)),f={data:[],size:0}),f&&(f.data.push(e.subarray(m,v+188)),f.size+=v+188-m));else g&&(m+=e[m]+1),0===p?this._parsePAT(e,m):p===this._pmtId?(this._parsePMT(e,m),R=this.pmtParsed=!0,L=this._avcTrack.id,A=this._aacTrack.id,T=this._id3Track.id,_&&(h.logger.log("reparse from beginning"),_=!1,v=-188)):(h.logger.log("unknown PID found before PAT/PMT"),_=!0)}else this.observer.trigger(u.default.ERROR,{type:c.ErrorTypes.MEDIA_ERROR,details:c.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});l&&this._parseAVCPES(this._parsePES(l)),d&&this._parseAACPES(this._parsePES(d)),f&&this._parseID3PES(this._parsePES(f)),this.remux(null)}},{key:"remux",value:function(e){this.remuxer.remux(this._aacTrack,this._avcTrack,this._id3Track,this._txtTrack,this.timeOffset,this.contiguous,e)}},{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(e,t){var r,a,i,n;for(r=(15&e[t+1])<<8|e[t+2],a=t+3+r-4,i=(15&e[t+10])<<8|e[t+11],t+=12+i;t<a;){switch(n=(31&e[t+1])<<8|e[t+2],e[t]){case 15:this._aacTrack.id=n;break;case 21:this._id3Track.id=n;break;case 27:this._avcTrack.id=n;break;default:h.logger.log("unkown stream type:"+e[t])}t+=((15&e[t+3])<<8|e[t+4])+5}}},{key:"_parsePES",value:function(e){var t,r,a,i,n,s,o,l,u,d=0,f=e.data;if(t=f[0],a=(t[0]<<16)+(t[1]<<8)+t[2],1===a){for(i=(t[4]<<8)+t[5],r=t[7],192&r&&(o=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,o>4294967295&&(o-=8589934592),64&r?(l=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2,l>4294967295&&(l-=8589934592)):l=o),n=t[8],u=n+9,e.size-=u,s=new Uint8Array(e.size);f.length;){t=f.shift();var h=t.byteLength;if(u){if(u>h){u-=h;continue}t=t.subarray(u),h-=u,u=0}s.set(t,d),d+=h}return{data:s,pts:o,dts:l,len:i}}return null}},{key:"_parseAVCPES",value:function(e){var t,r,a,i,n=this,s=this._avcTrack,o=s.samples,l=this._parseAVCNALu(e.data),u=[],d=!1,c=!1,v=0;if(0===l.length&&o.length>0){var g=o[o.length-1],p=g.units.units[g.units.units.length-1],y=new Uint8Array(p.data.byteLength+e.data.byteLength);y.set(p.data,0),y.set(e.data,p.data.byteLength),p.data=y,g.units.length+=e.data.byteLength,s.len+=e.data.byteLength}e.data=null;var m="",E=function(){u.length&&(c===!0||s.sps&&(o.length||this.contiguous)?(r={units:{units:u,length:v},pts:e.pts,dts:e.dts,key:c},o.push(r),s.len+=v,s.nbNalu+=u.length):s.dropped++,u=[],v=0)}.bind(this);l.forEach(function(r){switch(r.type){case 1:a=!0,d&&(m+="NDR ");break;case 5:a=!0,d&&(m+="IDR "),c=!0;break;case 6:a=!0,d&&(m+="SEI "),t=new f.default(r.data),t.readUByte();var o=t.readUByte();if(4===o){var l=0;do l=t.readUByte();while(255===l);var h=t.readUByte();if(181===h){var g=t.readUShort();if(49===g){var p=t.readUInt();if(1195456820===p){var y=t.readUByte();if(3===y){var b=t.readUByte(),_=t.readUByte(),R=31&b,L=[b,_];for(i=0;i<R;i++)L.push(t.readUByte()),L.push(t.readUByte()),L.push(t.readUByte());n._txtTrack.samples.push({type:3,pts:e.pts,bytes:L})}}}}}break;case 7:if(a=!0,d&&(m+="SPS "),!s.sps){t=new f.default(r.data);var A=t.readSPS();s.width=A.width,s.height=A.height,s.sps=[r.data],s.duration=n._duration;var T=r.data.subarray(1,4),k="avc1.";for(i=0;i<3;i++){var S=T[i].toString(16);S.length<2&&(S="0"+S),k+=S}s.codec=k}break;case 8:a=!0,d&&(m+="PPS "),s.pps||(s.pps=[r.data]);break;case 9:a=!1,d&&(m+="AUD "),E();break;default:a=!1,m+="unknown NAL "+r.type+" "}a&&(u.push(r),v+=r.data.byteLength)}),(d||m.length)&&h.logger.log(m),E()}},{key:"_parseAVCNALu",value:function(e){for(var t,r,a,i,n,s,o=0,l=e.byteLength,u=this.avcNaluState,d=[];o<l;)switch(t=e[o++],u){case 0:0===t&&(u=1);break;case 1:u=0===t?2:0;break;case 2:case 3:if(0===t)u=3;else if(1===t&&o<l){if(i=31&e[o],n)a={data:e.subarray(n,o-u-1),type:s},d.push(a);else{var f=this.avcNaluState;if(f&&o<=4-f){var h=this._avcTrack,c=h.samples;if(c.length){var v=c[c.length-1],g=v.units.units,p=g[g.length-1];p.state&&(p.data=p.data.subarray(0,p.data.byteLength-f),v.units.length-=f,h.len-=f)}}if(r=o-u-1,r>0){var y=this._avcTrack,m=y.samples;if(m.length){var E=m[m.length-1],b=E.units.units,_=b[b.length-1],R=new Uint8Array(_.data.byteLength+r);R.set(_.data,0),R.set(e.subarray(0,r),_.data.byteLength),_.data=R,E.units.length+=r,y.len+=r}}}n=o,s=i,u=0}else u=0}return n&&(a={data:e.subarray(n,l),type:s,state:u},d.push(a),this.avcNaluState=u),d}},{key:"_parseAACPES",value:function(e){var t,r,a,i,n,s,l,d,f,v=this._aacTrack,g=e.data,p=e.pts,y=0,m=this._duration,E=this.audioCodec,b=this.aacOverFlow,_=this.aacLastPTS;if(b){var R=new Uint8Array(b.byteLength+g.byteLength);R.set(b,0),R.set(g,b.byteLength),g=R}for(n=y,d=g.length;n<d-1&&(255!==g[n]||240!==(240&g[n+1]));n++);if(n){var L,A;if(n<d-1?(L="AAC PES did not start with ADTS header,offset:"+n,A=!1):(L="no ADTS header found in AAC PES",A=!0),this.observer.trigger(u.default.ERROR,{type:c.ErrorTypes.MEDIA_ERROR,details:c.ErrorDetails.FRAG_PARSING_ERROR,fatal:A,reason:L}),A)return}if(v.audiosamplerate||(t=o.default.getAudioConfig(this.observer,g,n,E),v.config=t.config,v.audiosamplerate=t.samplerate,v.channelCount=t.channelCount,v.codec=t.codec,v.duration=m,h.logger.log("parsed codec:"+v.codec+",rate:"+t.samplerate+",nb channel:"+t.channelCount)),i=0,a=9216e4/v.audiosamplerate,b&&_){var T=_+a;Math.abs(T-p)>1&&(h.logger.log("AAC: align PTS for overlapping frames by "+Math.round((T-p)/90)),p=T)}for(;n+5<d&&(s=1&g[n+1]?7:9,r=(3&g[n+3])<<11|g[n+4]<<3|(224&g[n+5])>>>5,r-=s,r>0&&n+s+r<=d);)for(l=p+i*a,f={unit:g.subarray(n+s,n+s+r),pts:l,dts:l},v.samples.push(f),v.len+=r,n+=r+s,i++;n<d-1&&(255!==g[n]||240!==(240&g[n+1]));n++);b=n<d?g.subarray(n,d):null,this.aacOverFlow=b,this.aacLastPTS=l}},{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]}}]),e}();r.default=v},{"../errors":21,"../events":23,"../utils/logger":38,"./adts":14,"./exp-golomb":18}],21:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});r.ErrorTypes={NETWORK_ERROR:"networkError",MEDIA_ERROR:"mediaError",OTHER_ERROR:"otherError"},r.ErrorDetails={MANIFEST_LOAD_ERROR:"manifestLoadError",MANIFEST_LOAD_TIMEOUT:"manifestLoadTimeOut",MANIFEST_PARSING_ERROR:"manifestParsingError",MANIFEST_INCOMPATIBLE_CODECS_ERROR:"manifestIncompatibleCodecsError",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",BUFFER_STALLED_ERROR:"bufferStalledError",BUFFER_FULL_ERROR:"bufferFullError",BUFFER_SEEK_OVER_HOLE:"bufferSeekOverHole",INTERNAL_EXCEPTION:"internalException"}},{}],22:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),o=e("./utils/logger"),l=e("./errors"),u=e("./events"),d=a(u),f=function(){function e(t){i(this,e),this.hls=t,this.onEvent=this.onEvent.bind(this);for(var r=arguments.length,a=Array(r>1?r-1:0),n=1;n<r;n++)a[n-1]=arguments[n];this.handledEvents=a,this.useGenericHandler=!0,this.registerListeners()}return s(e,[{key:"destroy",value:function(){this.unregisterListeners()}},{key:"isEventHandler",value:function(){return"object"===n(this.handledEvents)&&this.handledEvents.length&&"function"==typeof this.onEvent}},{key:"registerListeners",value:function(){this.isEventHandler()&&this.handledEvents.forEach(function(e){if("hlsEventGeneric"===e)throw new Error("Forbidden event name: "+e);this.hls.on(e,this.onEvent)}.bind(this))}},{key:"unregisterListeners",value:function(){this.isEventHandler()&&this.handledEvents.forEach(function(e){this.hls.off(e,this.onEvent)}.bind(this))}},{key:"onEvent",value:function(e,t){this.onEventGeneric(e,t)}},{key:"onEventGeneric",value:function(e,t){var r=function(e,t){var r="on"+e.replace("hls","");if("function"!=typeof this[r])throw new Error("Event "+e+" has no generic handler in this "+this.constructor.name+" class (tried "+r+")");return this[r].bind(this,t)};try{r.call(this,e,t).call()}catch(t){o.logger.error("internal error happened while processing "+e+":"+t.message),this.hls.trigger(d.default.ERROR,{type:l.ErrorTypes.OTHER_ERROR,details:l.ErrorDetails.INTERNAL_EXCEPTION,fatal:!1,event:e,err:t})}}}]),e}();r.default=f},{"./errors":21,"./events":23,"./utils/logger":38}],23:[function(e,t,r){"use strict";t.exports={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",BUFFER_RESET:"hlsBufferReset",BUFFER_CODECS:"hlsBufferCodecs",BUFFER_APPENDING:"hlsBufferAppending",BUFFER_APPENDED:"hlsBufferAppended",BUFFER_EOS:"hlsBufferEos",BUFFER_FLUSHING:"hlsBufferFlushing",BUFFER_FLUSHED:"hlsBufferFlushed",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsLevelPtsUpdated",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_USERDATA:"hlsFragParsingUserdata",FRAG_PARSING_METADATA:"hlsFragParsingMetadata",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"}},{}],24:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=function(){function e(){a(this,e)}return i(e,null,[{key:"bufferInfo",value:function(e,t,r){if(e){var a,i=e.buffered,n=[];for(a=0;a<i.length;a++)n.push({start:i.start(a),end:i.end(a)});return this.bufferedInfo(n,t,r)}return{len:0,start:0,end:0,nextStart:void 0}}},{key:"bufferedInfo",value:function(e,t,r){var a,i,n,s,o,l=[];for(e.sort(function(e,t){var r=e.start-t.start;return r?r:t.end-e.end}),o=0;o<e.length;o++){var u=l.length;if(u){var d=l[u-1].end;e[o].start-d<r?e[o].end>d&&(l[u-1].end=e[o].end):l.push(e[o])}else l.push(e[o])}for(o=0,a=0,i=n=t;o<l.length;o++){var f=l[o].start,h=l[o].end;if(t+r>=f&&t<h)i=f,n=h,a=n-t;else if(t+r<f){s=f;break}}return{len:a,start:i,end:n,nextStart:s}}}]),e}();r.default=n},{}],25:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=e("../utils/logger"),s=function(){function e(){a(this,e)}return i(e,null,[{key:"mergeDetails",value:function(t,r){var a,i=Math.max(t.startSN,r.startSN)-r.startSN,s=Math.min(t.endSN,r.endSN)-r.startSN,o=r.startSN-t.startSN,l=t.fragments,u=r.fragments,d=0;if(s<i)return void(r.PTSKnown=!1);for(var f=i;f<=s;f++){var h=l[o+f],c=u[f];c&&h&&(d=h.cc-c.cc,isNaN(h.startPTS)||(c.start=c.startPTS=h.startPTS,c.endPTS=h.endPTS,c.duration=h.duration,a=c))}if(d)for(n.logger.log("discontinuity sliding from playlist, take drift into account"),f=0;f<u.length;f++)u[f].cc+=d;if(a)e.updateFragPTSDTS(r,a.sn,a.startPTS,a.endPTS,a.startDTS,a.endDTS);else if(o>=0&&o<l.length){var v=l[o].start;for(f=0;f<u.length;f++)u[f].start+=v}r.PTSKnown=t.PTSKnown}},{key:"updateFragPTSDTS",value:function(t,r,a,i,n,s){var o,l,u,d;if(r<t.startSN||r>t.endSN)return 0;if(o=r-t.startSN,l=t.fragments,u=l[o],!isNaN(u.startPTS)){var f=Math.abs(u.startPTS-a);isNaN(u.deltaPTS)?u.deltaPTS=f:u.deltaPTS=Math.max(f,u.deltaPTS),a=Math.min(a,u.startPTS),i=Math.max(i,u.endPTS),n=Math.min(n,u.startDTS),s=Math.max(s,u.endDTS)}var h=a-u.start;for(u.start=u.startPTS=a,u.endPTS=i,u.startDTS=n,u.endDTS=s,u.duration=i-a,d=o;d>0;d--)e.updatePTS(l,d,d-1);for(d=o;d<l.length-1;d++)e.updatePTS(l,d,d+1);return t.PTSKnown=!0,h}},{key:"updatePTS",value:function(e,t,r){var a=e[t],i=e[r],s=i.startPTS;isNaN(s)?r>t?i.start=a.start+a.duration:i.start=a.start-i.duration:r>t?(a.duration=s-a.start,a.duration<0&&n.logger.error("negative duration computed for frag "+a.sn+",level "+a.level+", there should be some duration drift between playlist and fragment!")):(i.duration=a.start-s,i.duration<0&&n.logger.error("negative duration computed for frag "+i.sn+",level "+i.level+", there should be some duration drift between playlist and fragment!"))}}]),e}();r.default=s},{"../utils/logger":38}],26:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("./events"),o=a(s),l=e("./errors"),u=e("./loader/playlist-loader"),d=a(u),f=e("./loader/fragment-loader"),h=a(f),c=e("./controller/abr-controller"),v=a(c),g=e("./controller/buffer-controller"),p=a(g),y=e("./controller/cap-level-controller"),m=a(y),E=e("./controller/stream-controller"),b=a(E),_=e("./controller/level-controller"),R=a(_),L=e("./controller/timeline-controller"),A=a(L),T=e("./utils/logger"),k=e("./utils/xhr-loader"),S=a(k),w=e("events"),D=a(w),O=e("./loader/key-loader"),P=a(O),I=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];i(this,e);var r=e.DefaultConfig;if((t.liveSyncDurationCount||t.liveMaxLatencyDurationCount)&&(t.liveSyncDuration||t.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");for(var a in r)a in t||(t[a]=r[a]);if(void 0!==t.liveMaxLatencyDurationCount&&t.liveMaxLatencyDurationCount<=t.liveSyncDurationCount)throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be gt "liveSyncDurationCount"');if(void 0!==t.liveMaxLatencyDuration&&(t.liveMaxLatencyDuration<=t.liveSyncDuration||void 0===t.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be gt "liveSyncDuration"');(0,T.enableLogs)(t.debug),this.config=t;var n=this.observer=new D.default;n.trigger=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];n.emit.apply(n,[e,e].concat(r))},n.off=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];n.removeListener.apply(n,[e].concat(r))},this.on=n.on.bind(n),this.off=n.off.bind(n),this.trigger=n.trigger.bind(n),this.playlistLoader=new d.default(this),this.fragmentLoader=new h.default(this),this.levelController=new R.default(this),this.abrController=new t.abrController(this),this.bufferController=new t.bufferController(this),this.capLevelController=new t.capLevelController(this),this.streamController=new t.streamController(this),this.timelineController=new t.timelineController(this),this.keyLoader=new P.default(this)}return n(e,null,[{key:"isSupported",value:function(){return window.MediaSource&&"function"==typeof window.MediaSource.isTypeSupported&&window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')}},{key:"Events",get:function(){return o.default}},{key:"ErrorTypes",get:function(){return l.ErrorTypes}},{key:"ErrorDetails",get:function(){return l.ErrorDetails}},{key:"DefaultConfig",get:function(){return e.defaultConfig||(e.defaultConfig={autoStartLoad:!0,startPosition:-1,debug:!1,capLevelToPlayerSize:!1,maxBufferLength:30,maxBufferSize:6e7,maxBufferHole:.5,maxSeekHole:2,seekHoleNudgeDuration:.01,stalledInBufferedNudgeThreshold:10,maxFragLookUpTolerance:.2,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxMaxBufferLength:600,enableWorker:!0,enableSoftwareAES:!0,manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingLoopThreshold:3,startFragPrefetch:!1,appendErrorMaxRetry:3,loader:S.default,fLoader:void 0,pLoader:void 0,abrController:v.default,bufferController:p.default,capLevelController:m.default,streamController:b.default,timelineController:A.default,enableCEA708Captions:!0,enableMP2TPassThrough:!1,abrEwmaFastLive:5,abrEwmaSlowLive:9,abrEwmaFastVoD:4,abrEwmaSlowVoD:15,abrEwmaDefaultEstimate:5e5,abrBandWidthFactor:.8,abrBandWidthUpFactor:.7,maxStarvationDelay:2}),e.defaultConfig},set:function(t){e.defaultConfig=t}}]),n(e,[{key:"destroy",value:function(){T.logger.log("destroy"),this.trigger(o.default.DESTROYING),this.detachMedia(),this.playlistLoader.destroy(),this.fragmentLoader.destroy(),this.levelController.destroy(),this.abrController.destroy(),this.bufferController.destroy(),this.capLevelController.destroy(),this.streamController.destroy(),this.timelineController.destroy(),this.keyLoader.destroy(),this.url=null,this.observer.removeAllListeners()}},{key:"attachMedia",value:function(e){T.logger.log("attachMedia"),this.media=e,this.trigger(o.default.MEDIA_ATTACHING,{media:e})}},{key:"detachMedia",value:function(){T.logger.log("detachMedia"),this.trigger(o.default.MEDIA_DETACHING),this.media=null}},{key:"loadSource",value:function(e){T.logger.log("loadSource:"+e),this.url=e,this.trigger(o.default.MANIFEST_LOADING,{url:e})}},{key:"startLoad",value:function(){var e=arguments.length<=0||void 0===arguments[0]?-1:arguments[0];T.logger.log("startLoad"),this.levelController.startLoad(),this.streamController.startLoad(e)}},{key:"stopLoad",value:function(){T.logger.log("stopLoad"),this.levelController.stopLoad(),this.streamController.stopLoad()}},{key:"swapAudioCodec",value:function(){T.logger.log("swapAudioCodec"),this.streamController.swapAudioCodec()}},{key:"recoverMediaError",value:function(){T.logger.log("recoverMediaError");var e=this.media;this.detachMedia(),this.attachMedia(e)}},{key:"levels",get:function(){return this.levelController.levels}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(e){T.logger.log("set currentLevel:"+e),this.loadLevel=e,this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(e){T.logger.log("set nextLevel:"+e),this.levelController.manualLevel=e,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(e){T.logger.log("set loadLevel:"+e),this.levelController.manualLevel=e}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(e){this.levelController.nextLoadLevel=e}},{key:"firstLevel",get:function(){return this.levelController.firstLevel},set:function(e){T.logger.log("set firstLevel:"+e),this.levelController.firstLevel=e}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(e){T.logger.log("set startLevel:"+e),this.levelController.startLevel=e}},{key:"autoLevelCapping",get:function(){return this.abrController.autoLevelCapping},set:function(e){T.logger.log("set autoLevelCapping:"+e),this.abrController.autoLevelCapping=e}},{key:"autoLevelEnabled",get:function(){return this.levelController.manualLevel===-1}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}}]),e}();r.default=I},{"./controller/abr-controller":3,"./controller/buffer-controller":4,"./controller/cap-level-controller":5,"./controller/level-controller":7,"./controller/stream-controller":8,"./controller/timeline-controller":9,"./errors":21,"./events":23,"./loader/fragment-loader":28,"./loader/key-loader":29,"./loader/playlist-loader":30,"./utils/logger":38,"./utils/xhr-loader":40,events:1}],27:[function(e,t,r){"use strict";t.exports=e("./hls.js").default},{"./hls.js":26}],28:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=e("../errors"),c=function(e){function t(e){return i(this,t),n(this,Object.getPrototypeOf(t).call(this,e,u.default.FRAG_LOADING))}return s(t,e),o(t,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),f.default.prototype.destroy.call(this)}},{key:"onFragLoading",value:function(e){var t=e.frag;this.frag=t,this.frag.loaded=0;var r=this.hls.config;t.loader=this.loader="undefined"!=typeof r.fLoader?new r.fLoader(r):new r.loader(r),this.loader.load(t.url,"arraybuffer",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),r.fragLoadingTimeOut,0,0,this.loadprogress.bind(this),t)}},{key:"loadsuccess",value:function(e,t){var r=e.currentTarget.response;t.length=r.byteLength,this.frag.loader=void 0,this.hls.trigger(u.default.FRAG_LOADED,{payload:r,frag:this.frag,stats:t})}},{key:"loaderror",value:function(e){this.loader&&this.loader.abort(),this.hls.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:h.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:this.frag,response:e})}},{key:"loadtimeout",value:function(){this.loader&&this.loader.abort(),this.hls.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:h.ErrorDetails.FRAG_LOAD_TIMEOUT,fatal:!1,frag:this.frag})}},{key:"loadprogress",value:function(e,t){this.frag.loaded=t.loaded,this.hls.trigger(u.default.FRAG_LOAD_PROGRESS,{frag:this.frag,stats:t})}}]),t}(f.default);r.default=c},{"../errors":21,"../event-handler":22,"../events":23}],29:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=e("../errors"),c=function(e){function t(e){i(this,t);var r=n(this,Object.getPrototypeOf(t).call(this,e,u.default.KEY_LOADING));return r.decryptkey=null,r.decrypturl=null,r}return s(t,e),o(t,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),f.default.prototype.destroy.call(this)}},{key:"onKeyLoading",value:function(e){var t=this.frag=e.frag,r=t.decryptdata,a=r.uri;if(a!==this.decrypturl||null===this.decryptkey){var i=this.hls.config;t.loader=this.loader=new i.loader(i),this.decrypturl=a,this.decryptkey=null,t.loader.load(a,"arraybuffer",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),i.fragLoadingTimeOut,i.fragLoadingMaxRetry,i.fragLoadingRetryDelay,this.loadprogress.bind(this),t)}else this.decryptkey&&(r.key=this.decryptkey,this.hls.trigger(u.default.KEY_LOADED,{frag:t}))}},{key:"loadsuccess",value:function(e){var t=this.frag;this.decryptkey=t.decryptdata.key=new Uint8Array(e.currentTarget.response),t.loader=void 0,this.hls.trigger(u.default.KEY_LOADED,{frag:t})}},{key:"loaderror",value:function(e){this.loader&&this.loader.abort(),this.hls.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:h.ErrorDetails.KEY_LOAD_ERROR,fatal:!1,frag:this.frag,response:e})}},{key:"loadtimeout",value:function(){this.loader&&this.loader.abort(),this.hls.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:h.ErrorDetails.KEY_LOAD_TIMEOUT,fatal:!1,frag:this.frag})}},{key:"loadprogress",value:function(){}}]),t}(f.default);r.default=c},{"../errors":21,"../event-handler":22,"../events":23}],30:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),l=e("../events"),u=a(l),d=e("../event-handler"),f=a(d),h=e("../errors"),c=e("../utils/url"),v=a(c),g=e("../utils/attr-list"),p=a(g),y=e("../utils/logger"),m=function(e){function t(e){return i(this,t),n(this,Object.getPrototypeOf(t).call(this,e,u.default.MANIFEST_LOADING,u.default.LEVEL_LOADING))}return s(t,e),o(t,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),this.url=this.id=null,f.default.prototype.destroy.call(this)}},{key:"onManifestLoading",value:function(e){this.load(e.url,null)}},{key:"onLevelLoading",value:function(e){this.load(e.url,e.level,e.id)}},{key:"load",value:function(e,t,r){var a,i,n,s=this.hls.config;if(this.loading&&this.loader){if(this.url===e&&this.id===t&&this.id2===r)return;this.loader.abort()}this.url=e,this.id=t,this.id2=r,null===this.id?(a=s.manifestLoadingMaxRetry,i=s.manifestLoadingTimeOut,n=s.manifestLoadingRetryDelay):(a=s.levelLoadingMaxRetry,i=s.levelLoadingTimeOut,n=s.levelLoadingRetryDelay),this.loader="undefined"!=typeof s.pLoader?new s.pLoader(s):new s.loader(s),this.loading=!0,this.loader.load(e,"",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),i,a,n)}},{key:"resolve",value:function(e,t){return v.default.buildAbsoluteURL(t,e)}},{key:"parseMasterPlaylist",value:function(e,t){for(var r=[],a=void 0,i=/#EXT-X-STREAM-INF:([^\n\r]*)[\r\n]+([^\r\n]+)/g;null!=(a=i.exec(e));){var n={},s=n.attrs=new p.default(a[1]);n.url=this.resolve(a[2],t);var o=s.decimalResolution("RESOLUTION");o&&(n.width=o.width,n.height=o.height),n.bitrate=s.decimalInteger("AVERAGE-BANDWIDTH")||s.decimalInteger("BANDWIDTH"),n.name=s.NAME;var l=s.CODECS;if(l){l=l.split(",");for(var u=0;u<l.length;u++){var d=l[u];d.indexOf("avc1")!==-1?n.videoCodec=this.avc1toavcoti(d):n.audioCodec=d}}r.push(n)}return r}},{key:"createInitializationVector",value:function(e){for(var t=new Uint8Array(16),r=12;r<16;r++)t[r]=e>>8*(15-r)&255;return t}},{key:"fragmentDecryptdataFromLevelkey",value:function(e,t){var r=e;return e&&e.method&&e.uri&&!e.iv&&(r=this.cloneObj(e),r.iv=this.createInitializationVector(t)),r}},{key:"avc1toavcoti",value:function(e){var t,r=e.split(".");return r.length>2?(t=r.shift()+".",t+=parseInt(r.shift()).toString(16),t+=("000"+parseInt(r.shift()).toString(16)).substr(-4)):t=e,t}},{key:"cloneObj",value:function(e){return JSON.parse(JSON.stringify(e))}},{key:"parseLevelPlaylist",value:function(e,t,r){var a,i,n,s=0,o=0,l={version:null,type:null,url:t,fragments:[],live:!0,startSN:0},u={method:null,key:null,iv:null,uri:null},d=0,f=null,h=null,c=null,v=null,g=null,m=null;for(n=/(?:(?:#(EXTM3U))|(?:#EXT-X-(PLAYLIST-TYPE):(.+))|(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT-X-(KEY):(.+))|(?:#EXT-X-(START):(.+))|(?:#EXT(INF):(\d+(?:\.\d+)?)(?:,(.*))?)|(?:(?!#)()(\S.+))|(?:#EXT-X-(BYTERANGE):(\d+(?:@\d+(?:\.\d+)?))|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(PROGRAM-DATE-TIME):(.+))|(?:#EXT-X-(VERSION):(\d+))|(?:(#)(.*):(.*))|(?:(#)(.*)))(?:.*)\r?\n?/g;null!==(i=n.exec(e));)switch(i.shift(),i=i.filter(function(e){return void 0!==e}),i[0]){case"VERSION":l.version=parseInt(i[1]);break;case"PLAYLIST-TYPE":l.type=i[1].toUpperCase();break;case"MEDIA-SEQUENCE":s=l.startSN=parseInt(i[1]);break;case"TARGETDURATION":l.targetduration=parseFloat(i[1]);break;case"EXTM3U":break;case"ENDLIST":l.live=!1;break;case"DIS":d++;break;case"BYTERANGE":var E=i[1].split("@");m=1===E.length?g:parseInt(E[1]),g=parseInt(E[0])+m;break;case"INF":c=parseFloat(i[1]),v=i[2]?i[2]:null;break;case"":if(!isNaN(c)){var b=s++;a=this.fragmentDecryptdataFromLevelkey(u,b);var _=i[1]?this.resolve(i[1],t):null;h={url:_,duration:c,title:v,start:o,sn:b,level:r,cc:d,decryptdata:a,programDateTime:f},null!==m&&(h.byteRangeStartOffset=m,h.byteRangeEndOffset=g),l.fragments.push(h),o+=c,c=null,v=null,m=null,f=null}break;case"KEY":var R=i[1],L=new p.default(R),A=L.enumeratedString("METHOD"),T=L.URI,k=L.hexadecimalInteger("IV");A&&(u={method:null,key:null,iv:null,uri:null},T&&"AES-128"===A&&(u.method=A,u.uri=this.resolve(T,t),u.key=null,u.iv=k));break;case"START":var S=i[1],w=new p.default(S),D=w.decimalFloatingPoint("TIME-OFFSET");D&&(l.startTimeOffset=D);break;case"PROGRAM-DATE-TIME":f=new Date(Date.parse(i[1]));break;case"#":i.shift();break;default:y.logger.warn("line parsed but not handled: "+i)}return h&&!h.url&&(l.fragments.pop(),o-=h.duration),l.totalduration=o,l.endSN=s-1,l}},{key:"loadsuccess",value:function(e,t){var r,a=e.currentTarget,i=a.responseText,n=a.responseURL,s=this.id,o=this.id2,l=this.hls;if(this.loading=!1,void 0===n&&(n=this.url),t.tload=performance.now(),t.mtime=new Date(a.getResponseHeader("Last-Modified")),0===i.indexOf("#EXTM3U"))if(i.indexOf("#EXTINF:")>0){var d=this.parseLevelPlaylist(i,n,s||0);d.tload=t.tload,null===s&&l.trigger(u.default.MANIFEST_LOADED,{levels:[{url:n,details:d}],url:n,stats:t}),t.tparsed=performance.now(),l.trigger(u.default.LEVEL_LOADED,{details:d,level:s||0,id:o,stats:t})}else r=this.parseMasterPlaylist(i,n),r.length?l.trigger(u.default.MANIFEST_LOADED,{levels:r,url:n,stats:t}):l.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:h.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:n,reason:"no level found in manifest"});else l.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:h.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:n,reason:"no EXTM3U delimiter"})}},{key:"loaderror",value:function(e){var t,r;null===this.id?(t=h.ErrorDetails.MANIFEST_LOAD_ERROR,r=!0):(t=h.ErrorDetails.LEVEL_LOAD_ERROR,r=!1),this.loader&&this.loader.abort(),this.loading=!1,this.hls.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:t,fatal:r,url:this.url,loader:this.loader,response:e.currentTarget,level:this.id,id:this.id2})}},{key:"loadtimeout",value:function(){var e,t;null===this.id?(e=h.ErrorDetails.MANIFEST_LOAD_TIMEOUT,t=!0):(e=h.ErrorDetails.LEVEL_LOAD_TIMEOUT,t=!1),this.loader&&this.loader.abort(),this.loading=!1,this.hls.trigger(u.default.ERROR,{type:h.ErrorTypes.NETWORK_ERROR,details:e,fatal:t,url:this.url,loader:this.loader,level:this.id,id:this.id2})}}]),t}(f.default);r.default=m},{"../errors":21,"../event-handler":22,"../events":23,"../utils/attr-list":34,"../utils/logger":38,"../utils/url":39}],31:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=function(){function e(){a(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)]);var r=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),a=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:r,audio:a};var i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),n=new Uint8Array([0,0,0,0,0,0,0,0]);e.STTS=e.STSC=e.STCO=n,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]);var s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,s,l,s,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,i))}},{key:"box",value:function(e){for(var t,r=Array.prototype.slice.call(arguments,1),a=8,i=r.length,n=i;i--;)a+=r[i].byteLength;for(t=new Uint8Array(a),t[0]=a>>24&255,t[1]=a>>16&255,t[2]=a>>8&255,t[3]=255&a,t.set(e,4),i=0,a=8;i<n;i++)t.set(r[i],a),a+=r[i].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 r*=t,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,a){return e.box(e.types.moof,e.mfhd(t),e.traf(a,r))}},{key:"moov",value:function(t){for(var r=t.length,a=[];r--;)a[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(a).concat(e.mvex(t)))}},{key:"mvex",value:function(t){for(var r=t.length,a=[];r--;)a[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(a))}},{key:"mvhd",value:function(t,r){r*=t;var a=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,a)}},{key:"sdtp",value:function(t){var r,a,i=t.samples||[],n=new Uint8Array(4+i.length);for(a=0;a<i.length;a++)r=i[a].flags,n[a+4]=r.dependsOn<<4|r.isDependedOn<<2|r.hasRedundancy;return e.box(e.types.sdtp,n)}},{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,i,n=[],s=[];for(r=0;r<t.sps.length;r++)a=t.sps[r],i=a.byteLength,n.push(i>>>8&255),n.push(255&i),n=n.concat(Array.prototype.slice.call(a));for(r=0;r<t.pps.length;r++)a=t.pps[r],i=a.byteLength,s.push(i>>>8&255),s.push(255&i),s=s.concat(Array.prototype.slice.call(a));var o=e.box(e.types.avcC,new Uint8Array([1,n[3],n[4],n[5],255,224|t.sps.length].concat(n).concat([t.pps.length]).concat(s))),l=t.width,u=t.height;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,l>>8&255,255&l,u>>8&255,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value:function(e){var t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))}},{key:"mp4a",value:function(t){var r=t.audiosamplerate;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,r>>8&255,255&r,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){var r=t.id,a=t.duration*t.timescale,i=t.width,n=t.height;return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a,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,i>>8&255,255&i,0,0,n>>8&255,255&n,0,0]))}},{key:"traf",value:function(t,r){var a=e.sdtp(t),i=t.id;return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i])),e.box(e.types.tfdt,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])),e.trun(t,a.length+16+16+8+16+8+8),a)}},{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){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(t,r){var a,i,n,s,o,l,u=t.samples||[],d=u.length,f=12+16*d,h=new Uint8Array(f);for(r+=8+f,h.set([0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),a=0;a<d;a++)i=u[a],n=i.duration,s=i.size,o=i.flags,l=i.cts,h.set([n>>>24&255,n>>>16&255,n>>>8&255,255&n,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*a);return e.box(e.types.trun,h)}},{key:"initSegment",value:function(t){e.types||e.init();var r,a=e.moov(t);return r=new Uint8Array(e.FTYP.byteLength+a.byteLength),r.set(e.FTYP),r.set(a,e.FTYP.byteLength),r}}]),e}();r.default=n},{}],32:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("../events"),o=a(s),l=e("../utils/logger"),u=e("../remux/mp4-generator"),d=a(u),f=e("../errors"),h=function(){function e(t){i(this,e),this.observer=t,this.ISGenerated=!1,this.PES2MP4SCALEFACTOR=4,this.PES_TIMESCALE=9e4,this.MP4_TIMESCALE=this.PES_TIMESCALE/this.PES2MP4SCALEFACTOR}return n(e,[{key:"destroy",value:function(){}},{key:"insertDiscontinuity",value:function(){this._initPTS=this._initDTS=void 0}},{key:"switchLevel",value:function(){this.ISGenerated=!1}},{key:"remux",value:function(e,t,r,a,i,n){this.ISGenerated||this.generateIS(e,t,i),this.ISGenerated&&(t.samples.length&&this.remuxVideo(t,i,n),e.samples.length&&this.remuxAudio(e,i,n)),r.samples.length&&this.remuxID3(r,i),a.samples.length&&this.remuxText(a,i),this.observer.trigger(o.default.FRAG_PARSED)}},{key:"generateIS",value:function(e,t,r){var a,i,n=this.observer,s=e.samples,u=t.samples,h=this.PES_TIMESCALE,c={},v={tracks:c,unique:!1},g=void 0===this._initPTS;g&&(a=i=1/0),e.config&&s.length&&(e.timescale=e.audiosamplerate,e.timescale*e.duration>Math.pow(2,32)&&!function(){var t=function e(t,r){return r?e(r,t%r):t};e.timescale=e.audiosamplerate/t(e.audiosamplerate,1024)}(),l.logger.log("audio mp4 timescale :"+e.timescale),c.audio={container:"audio/mp4",codec:e.codec,initSegment:d.default.initSegment([e]),metadata:{channelCount:e.channelCount}},g&&(a=i=s[0].pts-h*r)),t.sps&&t.pps&&u.length&&(t.timescale=this.MP4_TIMESCALE,c.video={container:"video/mp4",codec:t.codec,initSegment:d.default.initSegment([t]),metadata:{width:t.width,height:t.height}},g&&(a=Math.min(a,u[0].pts-h*r),i=Math.min(i,u[0].dts-h*r))),Object.keys(c).length?(n.trigger(o.default.FRAG_PARSING_INIT_SEGMENT,v),this.ISGenerated=!0,g&&(this._initPTS=a,this._initDTS=i)):n.trigger(o.default.ERROR,{type:f.ErrorTypes.MEDIA_ERROR,details:f.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"})}},{key:"remuxVideo",value:function(e,t,r){var a,i,n,s,u,f,h,c,v,g,p,y,m,E,b,_=8,R=this.PES_TIMESCALE,L=this.PES2MP4SCALEFACTOR,A=[],T=e.samples.reduce(function(e,t){return Math.max(Math.min(e,t.pts-t.dts),-18e3)},0);for(T<0&&l.logger.warn("PTS < DTS detected in video samples, shifting DTS by "+Math.round(T/90)+" ms to overcome this issue"),f=new Uint8Array(e.len+4*e.nbNalu+8),a=new DataView(f.buffer),a.setUint32(0,f.byteLength),f.set(d.default.types.mdat,4);e.samples.length;){for(i=e.samples.shift(),s=0;i.units.units.length;)u=i.units.units.shift(),a.setUint32(_,u.data.byteLength),_+=4,f.set(u.data,_),_+=u.data.byteLength,s+=4+u.data.byteLength;if(p=i.pts-this._initDTS,y=i.dts-this._initDTS+T,y=Math.min(p,y),void 0!==g){m=this._PTSNormalize(p,g),E=this._PTSNormalize(y,g);var k=(E-g)/L;k<=0&&(l.logger.log("invalid sample duration at PTS/DTS: "+i.pts+"/"+i.dts+":"+k),k=1),n.duration=k}else{var S=void 0,w=void 0;S=r?this.nextAvcDts:t*R,m=this._PTSNormalize(p,S),E=this._PTSNormalize(y,S),w=Math.round((E-S)/90),r&&w&&(w>1?l.logger.log("AVC:"+w+" ms hole between fragments detected,filling it"):w<-1&&l.logger.log("AVC:"+-w+" ms overlapping between fragments detected"),E=S,m=Math.max(m-w,E),l.logger.log("Video/PTS/DTS adjusted: "+m+"/"+E+",delta:"+w)),c=Math.max(0,m),v=Math.max(0,E)}n={size:s,duration:0,cts:(m-E)/L,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0}},b=n.flags,i.key===!0?(b.dependsOn=2,b.isNonSync=0):(b.dependsOn=1,b.isNonSync=1),A.push(n),g=E}var D=0;A.length>=2&&(D=A[A.length-2].duration,n.duration=D),this.nextAvcDts=E+D*L;var O=e.dropped;e.len=0,e.nbNalu=0,e.dropped=0,A.length&&navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&(b=A[0].flags,b.dependsOn=2,b.isNonSync=0),e.samples=A,h=d.default.moof(e.sequenceNumber++,v/L,e),e.samples=[],this.observer.trigger(o.default.FRAG_PARSING_DATA,{data1:h,data2:f,startPTS:c/R,endPTS:(m+L*D)/R,startDTS:v/R,endDTS:this.nextAvcDts/R,type:"video",nb:A.length,dropped:O})}},{key:"remuxAudio",value:function(e,t,r){var a,i,n,s,u,f,h,c,v,g,p,y,m,E=8,b=this.PES_TIMESCALE,_=e.timescale,R=b/_,L=1024*e.timescale/e.audiosamplerate,A=[],T=[];for(e.samples.sort(function(e,t){return e.pts-t.pts}),T=e.samples;T.length;){if(i=T.shift(),s=i.unit,g=i.pts-this._initDTS,p=i.dts-this._initDTS,void 0!==v)y=this._PTSNormalize(g,v),m=this._PTSNormalize(p,v),n.duration=(m-v)/R,Math.abs(n.duration-L)>L/10&&l.logger.log("invalid AAC sample duration at PTS "+Math.round(g/90)+",should be 1024,found :"+Math.round(n.duration*e.audiosamplerate/e.timescale)),n.duration=L,y=m=L*R+v;else{var k=void 0,S=void 0;if(k=r?this.nextAacPts:t*b,y=this._PTSNormalize(g,k),m=this._PTSNormalize(p,k),S=Math.round(1e3*(y-k)/b),r&&S){if(S>0)l.logger.log(S+" ms hole between AAC samples detected,filling it");else if(S<-12){l.logger.log(-S+" ms overlapping between AAC samples detected, drop frame"),e.len-=s.byteLength;continue}y=m=k}if(h=Math.max(0,y),c=Math.max(0,m),!(e.len>0))return;u=new Uint8Array(e.len+8),a=new DataView(u.buffer),a.setUint32(0,u.byteLength),u.set(d.default.types.mdat,4)}u.set(s,E),E+=s.byteLength,n={size:s.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},A.push(n),v=m}var w=0,D=A.length;D>=2&&(w=A[D-2].duration,n.duration=w),D&&(this.nextAacPts=y+R*w,e.len=0,e.samples=A,f=d.default.moof(e.sequenceNumber++,c/R,e),e.samples=[],this.observer.trigger(o.default.FRAG_PARSING_DATA,{data1:f,data2:u,startPTS:h/b,endPTS:this.nextAacPts/b,startDTS:c/b,endDTS:(m+R*w)/b,type:"audio",nb:D}))}},{key:"remuxID3",value:function(e,t){var r,a=e.samples.length;if(a){for(var i=0;i<a;i++)r=e.samples[i],r.pts=(r.pts-this._initPTS)/this.PES_TIMESCALE,r.dts=(r.dts-this._initDTS)/this.PES_TIMESCALE;this.observer.trigger(o.default.FRAG_PARSING_METADATA,{samples:e.samples})}e.samples=[],t=t}},{key:"remuxText",value:function(e,t){e.samples.sort(function(e,t){return e.pts-t.pts});var r,a=e.samples.length;if(a){for(var i=0;i<a;i++)r=e.samples[i],r.pts=(r.pts-this._initPTS)/this.PES_TIMESCALE;this.observer.trigger(o.default.FRAG_PARSING_USERDATA,{samples:e.samples})}e.samples=[],t=t}},{key:"_PTSNormalize",value:function(e,t){var r;if(void 0===t)return e;for(r=t<e?-8589934592:8589934592;Math.abs(e-t)>4294967296;)e+=r;return e}},{key:"passthrough",get:function(){return!1}}]),e}();r.default=h},{"../errors":21,"../events":23,"../remux/mp4-generator":31,"../utils/logger":38}],33:[function(e,t,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),s=e("../events"),o=a(s),l=function(){function e(t){i(this,e),this.observer=t,this.ISGenerated=!1}return n(e,[{key:"destroy",value:function(){}},{key:"insertDiscontinuity",value:function(){}},{key:"switchLevel",value:function(){this.ISGenerated=!1}},{key:"remux",value:function(e,t,r,a,i,n){var s=this.observer;if(!this.ISGenerated){var l={},u={tracks:l,unique:!0},d=t,f=d.codec;f&&(u.tracks.video={container:d.container,codec:f,metadata:{width:d.width,height:d.height}}),d=e,f=d.codec,f&&(u.tracks.audio={container:d.container,codec:f,metadata:{channelCount:d.channelCount}}),this.ISGenerated=!0,s.trigger(o.default.FRAG_PARSING_INIT_SEGMENT,u)}s.trigger(o.default.FRAG_PARSING_DATA,{data1:n,startPTS:i,startDTS:i,type:"audiovideo",nb:1,dropped:0})}},{key:"passthrough",get:function(){return!0}}]),e}();r.default=l},{"../events":23}],34:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=function(){function e(t){a(this,e),"string"==typeof t&&(t=e.parseAttrList(t));for(var r in t)t.hasOwnProperty(r)&&(this[r]=t[r])}return i(e,[{key:"decimalInteger",value:function(e){var t=parseInt(this[e],10);return t>Number.MAX_SAFE_INTEGER?1/0:t}},{key:"hexadecimalInteger",value:function(e){if(this[e]){var t=(this[e]||"0x").slice(2);t=(1&t.length?"0":"")+t;for(var r=new Uint8Array(t.length/2),a=0;a<t.length/2;a++)r[a]=parseInt(t.slice(2*a,2*a+2),16);return r}return null}},{key:"hexadecimalIntegerAsNumber",value:function(e){var t=parseInt(this[e],16);return t>Number.MAX_SAFE_INTEGER?1/0:t}},{key:"decimalFloatingPoint",value:function(e){return parseFloat(this[e])}},{key:"enumeratedString",value:function(e){return this[e]}},{key:"decimalResolution",value:function(e){var t=/^(\d+)x(\d+)$/.exec(this[e]);if(null!==t)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}}}],[{key:"parseAttrList",value:function(e){for(var t,r=/\s*(.+?)\s*=((?:\".*?\")|.*?)(?:,|$)/g,a={};null!==(t=r.exec(e));){var i=t[2],n='"';0===i.indexOf(n)&&i.lastIndexOf(n)===i.length-1&&(i=i.slice(1,-1)),a[t[1]]=i}return a}}]),e}();r.default=n},{}],35:[function(e,t,r){"use strict";var a={search:function(e,t){for(var r=0,a=e.length-1,i=null,n=null;r<=a;){i=(r+a)/2|0,n=e[i];var s=t(n);if(s>0)r=i+1;else{if(!(s<0))return n;a=i-1}}return null}};t.exports=a},{}],36:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=function(){function e(){a(this,e)}return i(e,[{key:"attach",value:function(e){this.media=e,this.display=[],this.memory=[]}},{key:"detach",value:function(){this.clear()}},{key:"destroy",value:function(){}},{key:"_createCue",value:function(){var e=window.VTTCue||window.TextTrackCue,t=this.cue=new e(-1,-1,"");t.text="",t.pauseOnExit=!1,t.startTime=Number.MAX_VALUE,t.endTime=Number.MAX_VALUE,this.memory.push(t)}},{key:"clear",value:function(){var e=this._textTrack;if(e&&e.cues)for(;e.cues.length>0;)e.removeCue(e.cues[0])}},{key:"push",value:function(e,t){this.cue||this._createCue();for(var r,a,i,n,s,o=31&t[0],l=2,u=0;u<o;u++)if(r=t[l++],a=127&t[l++],i=127&t[l++],n=0!==(4&r),s=3&r,(0!==a||0!==i)&&n&&0===s){if(32&a||64&a)this.cue.text+=this._fromCharCode(a)+this._fromCharCode(i);else if((17===a||25===a)&&i>=48&&i<=63)switch(i){case 48:this.cue.text+="®";break;case 49:this.cue.text+="°";break;case 50:this.cue.text+="½";break;case 51:this.cue.text+="¿";break;case 52:this.cue.text+="™";break;case 53:this.cue.text+="¢";break;case 54:this.cue.text+="";break;case 55:this.cue.text+="£";break;case 56:this.cue.text+="♪";break;case 57:this.cue.text+=" ";break;case 58:this.cue.text+="è";break;case 59:this.cue.text+="â";break;case 60:this.cue.text+="ê";break;case 61:this.cue.text+="î";break;case 62:this.cue.text+="ô";break;case 63:this.cue.text+="û"}if((17===a||25===a)&&i>=32&&i<=47)switch(i){case 32:break;case 33:break;case 34:break;case 35:break;case 36:break;case 37:break;case 38:break;case 39:break;case 40:break;case 41:break;case 42:break;case 43:break;case 44:break;case 45:break;case 46:break;case 47:}if((20===a||28===a)&&i>=32&&i<=47)switch(i){case 32:this._clearActiveCues(e);break;case 33:this.cue.text=this.cue.text.substr(0,this.cue.text.length-1);break;case 34:break;case 35:break;case 36:break;case 37:break;case 38:break;case 39:break;case 40:break;case 41:this._clearActiveCues(e);break;case 42:break;case 43:break;case 44:this._clearActiveCues(e);break;case 45:break;case 46:this._text="";break;case 47:this._flipMemory(e)}if((23===a||31===a)&&i>=33&&i<=35)switch(i){case 33:break;case 34:break;case 35:}}}},{key:"_fromCharCode",value:function(e){switch(e){case 42:return"á";case 2:return"á";case 2:return"é";case 4:return"í";case 5:return"ó";case 6:return"ú";case 3:return"ç";case 4:return"÷";case 5:return"Ñ";case 6:return"ñ";case 7:return"█";default:return String.fromCharCode(e)}}},{key:"_flipMemory",value:function(e){this._clearActiveCues(e),this._flushCaptions(e)}},{key:"_flushCaptions",value:function(e){this._has708||(this._textTrack=this.media.addTextTrack("captions","English","en"),this._has708=!0);var t=!0,r=!1,a=void 0;try{for(var i,n=this.memory[Symbol.iterator]();!(t=(i=n.next()).done);t=!0){var s=i.value;s.startTime=e,this._textTrack.addCue(s),this.display.push(s)}}catch(e){r=!0,a=e}finally{try{!t&&n.return&&n.return()}finally{if(r)throw a}}this.memory=[],
|
|
this.cue=null}},{key:"_clearActiveCues",value:function(e){var t=!0,r=!1,a=void 0;try{for(var i,n=this.display[Symbol.iterator]();!(t=(i=n.next()).done);t=!0){var s=i.value;s.endTime=e}}catch(e){r=!0,a=e}finally{try{!t&&n.return&&n.return()}finally{if(r)throw a}}this.display=[]}},{key:"_clearBufferedCues",value:function(){}}]),e}();r.default=n},{}],37:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=function(){function e(t){a(this,e),this.alpha_=t?Math.exp(Math.log(.5)/t):0,this.estimate_=0,this.totalWeight_=0}return i(e,[{key:"sample",value:function(e,t){var r=Math.pow(this.alpha_,e);this.estimate_=t*(1-r)+r*this.estimate_,this.totalWeight_+=e}},{key:"getTotalWeight",value:function(){return this.totalWeight_}},{key:"getEstimate",value:function(){if(this.alpha_){var e=1-Math.pow(this.alpha_,this.totalWeight_);return this.estimate_/e}return this.estimate_}}]),e}();r.default=n},{}],38:[function(e,t,r){"use strict";function a(){}function i(e,t){return t="["+e+"] > "+t}function n(e){var t=window.console[e];return t?function(){for(var r=arguments.length,a=Array(r),n=0;n<r;n++)a[n]=arguments[n];a[0]&&(a[0]=i(e,a[0])),t.apply(window.console,a)}:a}function s(e){for(var t=arguments.length,r=Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];r.forEach(function(t){u[t]=e[t]?e[t].bind(e):n(t)})}Object.defineProperty(r,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},l={trace:a,debug:a,log:a,warn:a,info:a,error:a},u=l;r.enableLogs=function(e){if(e===!0||"object"===("undefined"==typeof e?"undefined":o(e))){s(e,"debug","log","info","warn","error");try{u.log()}catch(e){u=l}}else u=l},r.logger=u},{}],39:[function(e,t,r){"use strict";var a={buildAbsoluteURL:function(e,t){if(t=t.trim(),/^[a-z]+:/i.test(t))return t;var r=null,i=null,n=/^([^#]*)(.*)$/.exec(t);n&&(i=n[2],t=n[1]);var s=/^([^\?]*)(.*)$/.exec(t);s&&(r=s[2],t=s[1]);var o=/^([^#]*)(.*)$/.exec(e);o&&(e=o[1]);var l=/^([^\?]*)(.*)$/.exec(e);l&&(e=l[1]);var u=/^(([a-z]+:)?\/\/[a-z0-9\.\-_~]+(:[0-9]+)?)?(\/.*)$/i.exec(e);if(!u)throw new Error("Error trying to parse base URL.");var d=u[2]||"",f=u[1]||"",h=u[4],c=null;return c=/^\/\//.test(t)?d+"//"+a.buildAbsolutePath("",t.substring(2)):/^\//.test(t)?f+"/"+a.buildAbsolutePath("",t.substring(1)):a.buildAbsolutePath(f+h,t),r&&(c+=r),i&&(c+=i),c},buildAbsolutePath:function(e,t){for(var r,a,i=t,n="",s=e.replace(/[^\/]*$/,i.replace(/(\/|^)(?:\.?\/+)+/g,"$1")),o=0;a=s.indexOf("/../",o),a>-1;o=a+r)r=/^\/(?:\.\.\/)*/.exec(s.slice(a))[0].length,n=(n+s.substring(o,a)).replace(new RegExp("(?:\\/+[^\\/]*){0,"+(r-1)/3+"}$"),"/");return n+s.substr(o)}};t.exports=a},{}],40:[function(e,t,r){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),n=e("../utils/logger"),s=function(){function e(t){a(this,e),t&&t.xhrSetup&&(this.xhrSetup=t.xhrSetup)}return i(e,[{key:"destroy",value:function(){this.abort(),this.loader=null}},{key:"abort",value:function(){var e=this.loader,t=this.timeoutHandle;e&&4!==e.readyState&&(this.stats.aborted=!0,e.abort()),t&&window.clearTimeout(t)}},{key:"load",value:function(e,t,r,a,i,n,s,o){var l=arguments.length<=8||void 0===arguments[8]?null:arguments[8],u=arguments.length<=9||void 0===arguments[9]?null:arguments[9];this.url=e,!u||isNaN(u.byteRangeStartOffset)||isNaN(u.byteRangeEndOffset)||(this.byteRange=u.byteRangeStartOffset+"-"+(u.byteRangeEndOffset-1)),this.responseType=t,this.onSuccess=r,this.onProgress=l,this.onTimeout=i,this.onError=a,this.stats={trequest:performance.now(),retry:0},this.timeout=n,this.maxRetry=s,this.retryDelay=o,this.loadInternal()}},{key:"loadInternal",value:function(){var e;e="undefined"!=typeof XDomainRequest?this.loader=new XDomainRequest:this.loader=new XMLHttpRequest,e.onreadystatechange=this.readystatechange.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;var t=this.stats;t.tfirst=0,t.loaded=0,this.xhrSetup&&this.xhrSetup(e,this.url),this.timeoutHandle=window.setTimeout(this.loadtimeout.bind(this),this.timeout/2),e.send()}},{key:"readystatechange",value:function(e){var t=e.currentTarget,r=t.readyState,a=this.stats;if(!a.aborted&&r>=2&&(0===a.tfirst&&(a.tfirst=Math.max(performance.now(),a.trequest),window.clearTimeout(this.timeoutHandle),this.timeoutHandle=window.setTimeout(this.loadtimeout.bind(this),this.timeout-(a.tfirst-a.trequest))),4===r)){var i=t.status;i>=200&&i<300?(window.clearTimeout(this.timeoutHandle),a.tload=Math.max(a.tfirst,performance.now()),this.onSuccess(e,a)):a.retry>=this.maxRetry||i>=400&&i<499?(window.clearTimeout(this.timeoutHandle),n.logger.error(i+" while loading "+this.url),this.onError(e)):(n.logger.warn(i+" while loading "+this.url+", retrying in "+this.retryDelay+"..."),this.destroy(),this.timeoutHandle=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,64e3),a.retry++)}}},{key:"loadtimeout",value:function(e){n.logger.warn("timeout while loading "+this.url),this.onTimeout(e,this.stats)}},{key:"loadprogress",value:function(e){var t=this.stats;t.loaded=e.loaded,this.onProgress&&this.onProgress(e,t)}}]),e}();r.default=s},{"../utils/logger":38}]},{},[27])(27)});
|