mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-18 11:28:23 -07:00
4 lines
78 KiB
JavaScript
4 lines
78 KiB
JavaScript
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Hls=t()}}(function(){return function n(e,t,i){function r(s,d){if(!t[s]){if(!e[s]){var l="function"==typeof require&&require;if(!d&&l)return l(s,!0);if(a)return a(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var o=t[s]={exports:{}};e[s][0].call(o.exports,function(t){var i=e[s][1][t];return r(i?i:t)},o,o.exports,n,e,t,i)}return t[s].exports}for(var a="function"==typeof require&&require,s=0;s<i.length;s++)r(i[s]);return r}({1:[function(n,s,o){function e(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function t(e){return"function"==typeof e}function a(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function r(e){return void 0===e}s.exports=e,e.EventEmitter=e,e.prototype._events=void 0,e.prototype._maxListeners=void 0,e.defaultMaxListeners=10,e.prototype.setMaxListeners=function(e){if(!a(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},e.prototype.emit=function(u){var o,s,a,n,e,l;if(this._events||(this._events={}),"error"===u&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(o=arguments[1],o instanceof Error)throw o;throw TypeError('Uncaught, unspecified "error" event.')}if(s=this._events[u],r(s))return!1;if(t(s))switch(arguments.length){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:for(a=arguments.length,n=new Array(a-1),e=1;a>e;e++)n[e-1]=arguments[e];s.apply(this,n)}else if(i(s)){for(a=arguments.length,n=new Array(a-1),e=1;a>e;e++)n[e-1]=arguments[e];for(l=s.slice(),a=l.length,e=0;a>e;e++)l[e].apply(this,n)}return!0},e.prototype.addListener=function(s,a){var n;if(!t(a))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",s,t(a.listener)?a.listener:a),this._events[s]?i(this._events[s])?this._events[s].push(a):this._events[s]=[this._events[s],a]:this._events[s]=a,i(this._events[s])&&!this._events[s].warned){var n;n=r(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[s].length>n&&(this._events[s].warned=!0,"function"==typeof console.trace)}return this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(r,e){function i(){this.removeListener(r,i),s||(s=!0,e.apply(this,arguments))}if(!t(e))throw TypeError("listener must be a function");var s=!1;return i.listener=e,this.on(r,i),this},e.prototype.removeListener=function(s,r){var e,n,o,a;if(!t(r))throw TypeError("listener must be a function");if(!this._events||!this._events[s])return this;if(e=this._events[s],o=e.length,n=-1,e===r||t(e.listener)&&e.listener===r)delete this._events[s],this._events.removeListener&&this.emit("removeListener",s,r);else if(i(e)){for(a=o;a-->0;)if(e[a]===r||e[a].listener&&e[a].listener===r){n=a;break}if(0>n)return this;1===e.length?(e.length=0,delete this._events[s]):e.splice(n,1),this._events.removeListener&&this.emit("removeListener",s,r)}return this},e.prototype.removeAllListeners=function(e){var r,i;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(r in this._events)"removeListener"!==r&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],t(i))this.removeListener(e,i);else for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},e.prototype.listeners=function(e){var i;return i=this._events&&this._events[e]?t(this._events[e])?[this._events[e]]:this._events[e].slice():[]},e.listenerCount=function(e,i){var r;return r=e._events&&e._events[i]?t(e._events[i])?1:e._events[i].length:0}},{}],2:[function(a,r,n){var s=arguments[3],e=arguments[4],i=arguments[5],t=JSON.stringify;r.exports=function(u){for(var r,o=Object.keys(i),a=0,l=o.length;l>a;a++){var n=o[a];if(i[n].exports===u){r=n;break}}if(!r){r=Math.floor(Math.pow(16,8)*Math.random()).toString(16);for(var d={},a=0,l=o.length;l>a;a++){var n=o[a];d[n]=n}e[r]=[Function(["require","module","exports"],"("+u+")(self)"),d]}var h=Math.floor(Math.pow(16,8)*Math.random()).toString(16),f={};f[r]=r,e[h]=[Function(["require"],"require("+t(r)+")(self)"),f];var c="("+s+")({"+Object.keys(e).map(function(i){return t(i)+":["+e[i][0]+","+t(e[i][1])+"]"}).join(",")+"},{},["+t(h)+"])",v=window.URL||window.webkitURL||window.mozURL||window.msURL;return new Worker(v.createObjectURL(new Blob([c],{type:"text/javascript"})))}},{}],3:[function(i,r,e){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),o=i("../events"),t=s(o),l=function(){function e(i){a(this,e),this.hls=i,this.lastfetchlevel=0,this._autoLevelCapping=-1,this._nextAutoLevel=-1,this.onflp=this.onFragmentLoadProgress.bind(this),i.on(t.default.FRAG_LOAD_PROGRESS,this.onflp)}return n(e,[{key:"destroy",value:function(){this.hls.off(t.default.FRAG_LOAD_PROGRESS,this.onflp)}},{key:"onFragmentLoadProgress",value:function(i,t){var e=t.stats;void 0===e.aborted&&(this.lastfetchduration=(new Date-e.trequest)/1e3,this.lastfetchlevel=t.frag.level,this.lastbw=8*e.loaded/this.lastfetchduration,this._nextAutoLevel=-1)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping=e}},{key:"nextAutoLevel",get:function(){var i,e,t,r=this.lastbw,s=this.hls;if(t=-1===this._autoLevelCapping?s.levels.length-1:this._autoLevelCapping,-1!==this._nextAutoLevel)return Math.min(this._nextAutoLevel,t);for(e=0;t>=e;e++)if(i=e<=this.lastfetchlevel?.8*r:.7*r,i<s.levels[e].bitrate)return Math.max(0,e-1);return e-1},set:function(e){this._nextAutoLevel=e}}]),e}();e.default=l,r.exports=e.default},{"../events":12}],4:[function(r,c,a){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(a,"__esModule",{value:!0});var u=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),f=r("../events"),t=s(f),e=r("../utils/logger"),o=r("../demux/demuxer"),d=s(o),h=r("../helper/level-helper"),n=s(h),i=r("../errors"),v=function(){function r(e){l(this,r),this.ERROR=-2,this.STARTING=-1,this.IDLE=0,this.LOADING=1,this.WAITING_LEVEL=2,this.PARSING=3,this.PARSED=4,this.APPENDING=5,this.BUFFER_FLUSHING=6,this.config=e.config,this.hls=e,this.onsbue=this.onSBUpdateEnd.bind(this),this.onsbe=this.onSBUpdateError.bind(this),this.onmse=this.onMSEAttached.bind(this),this.onmsed0=this.onMSEDetaching.bind(this),this.onmsed=this.onMSEDetached.bind(this),this.onmp=this.onManifestParsed.bind(this),this.onll=this.onLevelLoaded.bind(this),this.onfl=this.onFragLoaded.bind(this),this.onis=this.onInitSegment.bind(this),this.onfpg=this.onFragParsing.bind(this),this.onfp=this.onFragParsed.bind(this),this.onerr=this.onError.bind(this),this.ontick=this.tick.bind(this),e.on(t.default.MSE_ATTACHED,this.onmse),e.on(t.default.MSE_DETACHING,this.onmsed0),e.on(t.default.MSE_DETACHED,this.onmsed),e.on(t.default.MANIFEST_PARSED,this.onmp)}return u(r,[{key:"destroy",value:function(){this.stop();var e=this.hls;e.off(t.default.MSE_ATTACHED,this.onmse),e.off(t.default.MSE_DETACHING,this.onmsed0),e.off(t.default.MSE_DETACHED,this.onmsed),e.off(t.default.MANIFEST_PARSED,this.onmp),this.state=this.IDLE}},{key:"startLoad",value:function(){this.levels&&this.video?(this.startInternal(),this.lastCurrentTime?(e.logger.log("seeking @ "+this.lastCurrentTime),this.lastPaused||(e.logger.log("resuming video"),this.video.play()),this.state=this.IDLE):(this.lastCurrentTime=0,this.state=this.STARTING),this.nextLoadPosition=this.startPosition=this.lastCurrentTime,this.tick()):e.logger.warn("cannot start loading as either manifest not parsed or video not attached")}},{key:"startInternal",value:function(){var e=this.hls;this.stop(),this.demuxer=new d.default(e),this.timer=setInterval(this.ontick,100),this.level=-1,e.on(t.default.FRAG_LOADED,this.onfl),e.on(t.default.FRAG_PARSING_INIT_SEGMENT,this.onis),e.on(t.default.FRAG_PARSING_DATA,this.onfpg),e.on(t.default.FRAG_PARSED,this.onfp),e.on(t.default.ERROR,this.onerr),e.on(t.default.LEVEL_LOADED,this.onll)}},{key:"stop",value:function(){this.mp4segments=[],this.flushRange=[],this.bufferRange=[];var i=this.fragCurrent;if(i&&(i.loader&&i.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.sourceBuffer){for(var s in this.sourceBuffer){var r=this.sourceBuffer[s];try{this.mediaSource.removeSourceBuffer(r),r.removeEventListener("updateend",this.onsbue),r.removeEventListener("error",this.onsbe)}catch(e){}}this.sourceBuffer=null}this.timer&&(clearInterval(this.timer),this.timer=null),this.demuxer&&(this.demuxer.destroy(),this.demuxer=null);var e=this.hls;e.off(t.default.FRAG_LOADED,this.onfl),e.off(t.default.FRAG_PARSED,this.onfp),e.off(t.default.FRAG_PARSING_DATA,this.onfpg),e.off(t.default.LEVEL_LOADED,this.onll),e.off(t.default.FRAG_PARSING_INIT_SEGMENT,this.onis),e.off(t.default.ERROR,this.onerr)}},{key:"tick",value:function(){var d,n,a,h;switch(this.state){case this.ERROR:break;case this.STARTING:this.startLevel=this.hls.startLevel,-1===this.startLevel&&(this.startLevel=0,this.fragBitrateTest=!0),this.level=this.hls.nextLoadLevel=this.startLevel,this.state=this.WAITING_LEVEL,this.loadedmetadata=!1;break;case this.IDLE:if(!this.video)break;d=this.loadedmetadata?this.video.currentTime:this.nextLoadPosition,n=this.startFragmentRequested===!1?this.startLevel:this.hls.nextLoadLevel;var c,R=this.bufferInfo(d,.3),k=R.len,l=R.end;if(this.levels[n].hasOwnProperty("bitrate")?(c=Math.max(8*this.config.maxBufferSize/this.levels[n].bitrate,this.config.maxBufferLength),c=Math.min(c,this.config.maxMaxBufferLength)):c=this.config.maxBufferLength,c>k){if(this.hls.nextLoadLevel=n,this.level=n,a=this.levels[n].details,"undefined"==typeof a){this.state=this.WAITING_LEVEL;break}var o=a.fragments,f=o.length,u=o[0].start,b=o[f-1].start+o[f-1].duration,r=void 0;if(a.live){if(l<Math.max(u,b-this.config.liveMaxLatencyDurationCount*a.targetduration)&&(this.seekAfterBuffered=u+Math.max(0,a.totalduration-this.config.liveSyncDurationCount*a.targetduration),e.logger.log("buffer end: "+l+" is located too far from the end of live sliding playlist, media position will be reseted to: "+this.seekAfterBuffered.toFixed(3)),l=this.seekAfterBuffered),this.startFragmentRequested&&!a.PTSKnown){if(this.fragPrevious){var g=this.fragPrevious.sn+1;g>=a.startSN&&g<=a.endSN&&(r=o[g-a.startSN],e.logger.log("live playlist, switching playlist, load frag with next SN: "+r.sn))}r||(r=o[Math.round(f/2)],e.logger.log("live playlist, switching playlist, unknown, load middle frag : "+r.sn))}}else u>l&&(r=o[0]);if(!r){if(l>b)break;for(h=0;f>h&&(r=o[h],u=r.start,!(l>=u&&u+r.duration>l));h++);if(this.fragPrevious&&r.level===this.fragPrevious.level&&r.sn===this.fragPrevious.sn){if(h===f-1)break;r=o[h+1],e.logger.log("SN just loaded, load next one: "+r.sn)}}if(e.logger.log("Loading "+r.sn+" of ["+a.startSN+" ,"+a.endSN+"],level "+n+", currentTime:"+d+",bufferEnd:"+l.toFixed(3)),r.autoLevel=this.hls.autoLevelEnabled,this.levels.length>1&&(r.expectedLen=Math.round(r.duration*this.levels[n].bitrate/8),r.trequest=new Date),void 0!==this.fragLoadIdx?this.fragLoadIdx++:this.fragLoadIdx=0,r.loadCounter){r.loadCounter++;var A=this.config.fragLoadingLoopThreshold;if(r.loadCounter>A&&Math.abs(this.fragLoadIdx-r.loadIdx)<A)return void this.hls.trigger(t.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_LOOP_LOADING_ERROR,fatal:!1,frag:r})}else r.loadCounter=1;r.loadIdx=this.fragLoadIdx,this.fragCurrent=r,this.startFragmentRequested=!0,this.hls.trigger(t.default.FRAG_LOADING,{frag:r}),this.state=this.LOADING}break;case this.WAITING_LEVEL:n=this.levels[this.level],n&&n.details&&(this.state=this.IDLE);break;case this.LOADING:var p=this.video,s=this.fragCurrent;if(p&&(!p.paused||this.loadedmetadata===!1)&&s.autoLevel&&this.level&&this.levels.length>1){var T=new Date-s.trequest;if(T>500*s.duration){var _=1e3*s.loaded/T;s.expectedLen<s.loaded&&(s.expectedLen=s.loaded),d=p.currentTime;var m=(s.expectedLen-s.loaded)/_,y=this.bufferInfo(d,.3).end-d,S=s.duration*this.levels[this.hls.nextLoadLevel].bitrate/(8*_);y<2*s.duration&&m>y&&m>S&&(e.logger.warn("loading too slow, abort fragment loading"),e.logger.log("fragLoadedDelay/bufferStarvationDelay/fragLevelNextLoadedDelay :"+m.toFixed(1)+"/"+y.toFixed(1)+"/"+S.toFixed(1)),s.loader.abort(),this.hls.trigger(t.default.FRAG_LOAD_EMERGENCY_ABORTED,{frag:s}),this.state=this.IDLE)}}break;case this.PARSING:break;case this.PARSED:case this.APPENDING:if(this.sourceBuffer){if(this.sourceBuffer.audio&&this.sourceBuffer.audio.updating||this.sourceBuffer.video&&this.sourceBuffer.video.updating);else if(this.mp4segments.length){var E=this.mp4segments.shift();try{this.sourceBuffer[E.type].appendBuffer(E.data),this.appendError=0}catch(r){e.logger.error("error while trying to append buffer:"+r.message+",try appending later"),this.mp4segments.unshift(E),this.appendError?this.appendError++:this.appendError=1;var v={type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_APPENDING_ERROR,frag:this.fragCurrent};if(this.appendError>this.config.appendErrorMaxRetry)return e.logger.log("fail "+this.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),v.fatal=!0,this.hls.trigger(t.default.ERROR,v),void(this.state=this.ERROR);v.fatal=!1,this.hls.trigger(t.default.ERROR,v)}this.state=this.APPENDING}}else this.state=this.IDLE;break;case this.BUFFER_FLUSHING:for(;this.flushRange.length;){var L=this.flushRange[0];if(!this.flushBuffer(L.start,L.end))break;this.flushRange.shift()}0===this.flushRange.length&&(this.immediateSwitch&&this.immediateLevelSwitchEnd(),this.state=this.IDLE,this.fragPrevious=null)}this._checkFragmentChanged()}},{key:"bufferInfo",value:function(i,a){var l,o,s,u,e,h=this.video,r=h.buffered,t=[];for(e=0;e<r.length;e++)t.length&&r.start(e)-t[t.length-1].end<a?t[t.length-1].end=r.end(e):t.push({start:r.start(e),end:r.end(e)});for(e=0,l=0,o=s=i;e<t.length;e++){var n=t[e].start,d=t[e].end;i+a>=n&&d>i?(o=n,s=d+a,l=s-i):n>i+a&&(u=n)}return{len:l,start:o,end:s,nextStart:u}}},{key:"getBufferRange",value:function(i){var e,t;for(e=this.bufferRange.length-1;e>=0;e--)if(t=this.bufferRange[e],i>=t.start&&i<=t.end)return t;return null}},{key:"followingBufferRange",value:function(e){return e?this.getBufferRange(e.end+.5):null}},{key:"isBuffered",value:function(i){for(var r=this.video,t=r.buffered,e=0;e<t.length;e++)if(i>=t.start(e)&&i<=t.end(e))return!0;return!1}},{key:"_checkFragmentChanged",value:function(){var r,i,s=this.video;if(s&&s.seeking===!1&&(i=s.currentTime,i>Math.sign(s.playbackRate)*this.lastCurrentTime&&(this.lastCurrentTime=i),this.isBuffered(i)?r=this.getBufferRange(i):this.isBuffered(i+.1)&&(r=this.getBufferRange(i+.1)),r)){var a=r.frag;a!==this.fragPlaying&&(this.fragPlaying=a,this.hls.trigger(t.default.FRAG_CHANGED,{frag:a}));var n=this.levels[this.level].details;if(n&&!n.live&&a.sn===n.endSN){var o=this.mediaSource;o&&"open"===o.readyState&&(e.logger.log("all media data available, signal endOfStream() to MediaSource"),o.endOfStream())}}}},{key:"flushBuffer",value:function(d,l){var i,t,o,n,r,s;if(this.flushBufferCounter++<2*this.bufferRange.length&&this.sourceBuffer)for(var u in this.sourceBuffer){if(i=this.sourceBuffer[u],i.updating)return!1;for(t=0;t<i.buffered.length;t++)if(o=i.buffered.start(t),n=i.buffered.end(t),-1!==navigator.userAgent.toLowerCase().indexOf("firefox")&&l===Number.POSITIVE_INFINITY?(r=d,s=l):(r=Math.max(o,d),s=Math.min(n,l)),s-r>.5)return e.logger.log("flush "+u+" ["+r+","+s+"], of ["+o+","+n+"], pos:"+this.video.currentTime),i.remove(r,s),!1}var a,h=[];for(t=0;t<this.bufferRange.length;t++)a=this.bufferRange[t],this.isBuffered((a.start+a.end)/2)&&h.push(a);return this.bufferRange=h,e.logger.log("buffer flushed"),!0}},{key:"immediateLevelSwitch",value:function(){e.logger.log("immediateLevelSwitch"),this.immediateSwitch||(this.immediateSwitch=!0,this.previouslyPaused=this.video.paused,this.video.pause());var t=this.fragCurrent;t&&t.loader&&t.loader.abort(),this.fragCurrent=null,this.flushBufferCounter=0,this.flushRange.push({start:0,end:Number.POSITIVE_INFINITY}),this.state=this.BUFFER_FLUSHING,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold,this.tick()}},{key:"immediateLevelSwitchEnd",value:function(){this.immediateSwitch=!1,this.video.currentTime-=1e-4,this.previouslyPaused||this.video.play()}},{key:"nextLevelSwitch",value:function(){var t,i,e;if(i=this.getBufferRange(this.video.currentTime),i&&this.flushRange.push({start:0,end:i.start-1}),this.video.paused)t=0;else{var r=this.hls.nextLoadLevel,s=this.levels[r];t=this.hls.stats.fragLastKbps&&this.fragCurrent?this.fragCurrent.duration*s.bitrate/(1e3*this.hls.stats.fragLastKbps)+1:0}e=this.getBufferRange(this.video.currentTime+t),e&&(e=this.followingBufferRange(e),e&&this.flushRange.push({start:e.start,end:Number.POSITIVE_INFINITY})),this.flushRange.length&&(this.flushBufferCounter=0,this.state=this.BUFFER_FLUSHING,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold,this.tick())}},{key:"onMSEAttached",value:function(i,t){var e=t.video;this.video=e,this.mediaSource=t.mediaSource,this.onvseeking=this.onVideoSeeking.bind(this),this.onvseeked=this.onVideoSeeked.bind(this),this.onvmetadata=this.onVideoMetadata.bind(this),this.onvended=this.onVideoEnded.bind(this),e.addEventListener("seeking",this.onvseeking),e.addEventListener("seeked",this.onvseeked),e.addEventListener("loadedmetadata",this.onvmetadata),e.addEventListener("ended",this.onvended),this.levels&&this.config.autoStartLoad&&this.startLoad()}},{key:"onMSEDetaching",value:function(){var t=this.video;t&&t.ended&&(e.logger.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0)}},{key:"onMSEDetached",value:function(){var e=this.video;e&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("seeked",this.onvseeked),e.removeEventListener("loadedmetadata",this.onvmetadata),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvmetadata=null),this.video=null,this.loadedmetadata=!1,this.stop()}},{key:"onVideoSeeking",value:function(){this.state===this.LOADING&&0===this.bufferInfo(this.video.currentTime,.3).len&&(e.logger.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),this.fragCurrent.loader.abort(),this.fragCurrent=null,this.fragPrevious=null,this.state=this.IDLE),this.video&&(this.lastCurrentTime=this.video.currentTime),void 0!==this.fragLoadIdx&&(this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold),this.tick()}},{key:"onVideoSeeked",value:function(){this.tick()}},{key:"onVideoMetadata",value:function(){this.video.currentTime!==this.startPosition&&(this.video.currentTime=this.startPosition),this.loadedmetadata=!0,this.tick()}},{key:"onVideoEnded",value:function(){e.logger.log("video ended"),this.startPosition=this.lastCurrentTime=0}},{key:"onManifestParsed",value:function(a,i){var t,r=!1,s=!1;i.levels.forEach(function(e){t=e.codecs,t&&(-1!==t.indexOf("mp4a.40.2")&&(r=!0),-1!==t.indexOf("mp4a.40.5")&&(s=!0))}),this.audiocodecswitch=r&&s,this.audiocodecswitch&&e.logger.log("both AAC/HE-AAC audio found in levels; declaring audio codec as HE-AAC"),this.levels=i.levels,this.startLevelLoaded=!1,this.startFragmentRequested=!1,this.video&&this.config.autoStartLoad&&this.startLoad()}},{key:"onLevelLoaded",value:function(u,s){var i=s.details,r=s.level,a=this.levels[r],o=i.totalduration;if(e.logger.log("level "+r+" loaded ["+i.startSN+","+i.endSN+"],duration:"+o),i.live){var l=a.details;l?(n.default.mergeDetails(l,i),i.PTSKnown?e.logger.log("live playlist sliding:"+i.fragments[0].start.toFixed(3)):e.logger.log("live playlist - outdated PTS, unknown sliding")):(i.PTSKnown=!1,e.logger.log("live playlist - first load, unknown sliding"))}else i.PTSKnown=!1;a.details=i,this.hls.trigger(t.default.LEVEL_UPDATED,{details:i,level:r}),this.startLevelLoaded===!1&&(i.live&&(this.startPosition=Math.max(0,o-this.config.liveSyncDurationCount*i.targetduration)),this.nextLoadPosition=this.startPosition,this.startLevelLoaded=!0),this.state===this.WAITING_LEVEL&&(this.state=this.IDLE),this.tick()}},{key:"onFragLoaded",value:function(l,i){var r=this.fragCurrent;if(this.state===this.LOADING&&r&&i.frag.level===r.level&&i.frag.sn===r.sn)if(this.fragBitrateTest===!0)this.state=this.IDLE,this.fragBitrateTest=!1,i.stats.tparsed=i.stats.tbuffered=new Date,this.hls.trigger(t.default.FRAG_BUFFERED,{stats:i.stats,frag:r});else{this.state=this.PARSING,this.stats=i.stats;var s=this.levels[this.level],a=s.details,n=a.totalduration,o=r.start;e.logger.log("Demuxing "+r.sn+" of ["+a.startSN+" ,"+a.endSN+"],level "+this.level),this.demuxer.push(i.payload,s.audioCodec,s.videoCodec,o,r.cc,this.level,n)}}},{key:"onInitSegment",value:function(a,t){if(this.state===this.PARSING){var r,i=this.levels[this.level].audioCodec,s=this.levels[this.level].videoCodec;(void 0===i||void 0===t.audiocodec)&&(i=t.audioCodec),(void 0===s||void 0===t.videocodec)&&(s=t.videoCodec),this.audiocodecswitch&&2===t.audioChannelCount&&-1===navigator.userAgent.toLowerCase().indexOf("android")&&-1===navigator.userAgent.toLowerCase().indexOf("firefox")&&(i="mp4a.40.5"),this.sourceBuffer||(this.sourceBuffer={},e.logger.log("selected A/V codecs for sourceBuffers:"+i+","+s),i&&(r=this.sourceBuffer.audio=this.mediaSource.addSourceBuffer("video/mp4;codecs="+i),r.addEventListener("updateend",this.onsbue),r.addEventListener("error",this.onsbe)),s&&(r=this.sourceBuffer.video=this.mediaSource.addSourceBuffer("video/mp4;codecs="+s),r.addEventListener("updateend",this.onsbue),r.addEventListener("error",this.onsbe))),i&&this.mp4segments.push({type:"audio",data:t.audioMoov}),s&&this.mp4segments.push({type:"video",data:t.videoMoov}),this.tick()}}},{key:"onFragParsing",value:function(a,i){if(this.state===this.PARSING){this.tparse2=Date.now();var r=this.levels[this.level],s=this.fragCurrent;e.logger.log("parsed data, type/startPTS/endPTS/startDTS/endDTS/nb:"+i.type+"/"+i.startPTS.toFixed(3)+"/"+i.endPTS.toFixed(3)+"/"+i.startDTS.toFixed(3)+"/"+i.endDTS.toFixed(3)+"/"+i.nb);var o=n.default.updateFragPTS(r.details,s.sn,i.startPTS,i.endPTS);this.hls.trigger(t.default.LEVEL_PTS_UPDATED,{details:r.details,level:this.level,drift:o}),this.mp4segments.push({type:i.type,data:i.moof}),this.mp4segments.push({type:i.type,data:i.mdat}),this.nextLoadPosition=i.endPTS,this.bufferRange.push({type:i.type,start:i.startPTS,end:i.endPTS,frag:s}),this.tick()}else e.logger.warn("not in PARSING state, discarding "+a)}},{key:"onFragParsed",value:function(){this.state===this.PARSING&&(this.state=this.PARSED,this.stats.tparsed=new Date,this.tick())}},{key:"onError",value:function(r,t){switch(t.details){case i.ErrorDetails.FRAG_LOAD_ERROR:case i.ErrorDetails.FRAG_LOAD_TIMEOUT:case i.ErrorDetails.FRAG_LOOP_LOADING_ERROR:case i.ErrorDetails.LEVEL_LOAD_ERROR:case i.ErrorDetails.LEVEL_LOAD_TIMEOUT:e.logger.warn("buffer controller: "+t.details+" while loading frag,switch to "+(t.fatal?"ERROR":"IDLE")+" state ..."),this.state=t.fatal?this.ERROR:this.IDLE}}},{key:"onSBUpdateEnd",value:function(){if(this.state===this.APPENDING&&0===this.mp4segments.length){var s=this.fragCurrent;s&&(this.fragPrevious=s,this.stats.tbuffered=new Date,this.hls.trigger(t.default.FRAG_BUFFERED,{stats:this.stats,frag:s}),e.logger.log("video buffered : "+this.timeRangesToString(this.video.buffered)),this.state=this.IDLE);var i=this.video;if(i)if(this.seekAfterBuffered)i.currentTime=this.seekAfterBuffered;else{var a=i.currentTime,n=this.bufferInfo(a,0);if(0===n.len){var r=n.nextStart;r&&.3>r-a&&(e.logger.log("adjust currentTime from "+a+" to "+r),i.currentTime=r)}}this.seekAfterBuffered=void 0}this.tick()}},{key:"onSBUpdateError",value:function(r){e.logger.error("sourceBuffer error:"+r),this.state=this.ERROR,this.hls.trigger(t.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_APPENDING_ERROR,fatal:!0,frag:this.fragCurrent})}},{key:"timeRangesToString",value:function(t){for(var i="",r=t.length,e=0;r>e;e++)i+="["+t.start(e)+","+t.end(e)+"]";return i}},{key:"currentLevel",get:function(){if(this.video){var e=this.getBufferRange(this.video.currentTime);if(e)return e.frag.level}return-1}},{key:"nextBufferRange",get:function(){return this.video?this.followingBufferRange(this.getBufferRange(this.video.currentTime)):null}},{key:"nextLevel",get:function(){var e=this.nextBufferRange;return e?e.frag.level:-1}}]),r}();a.default=v,c.exports=a.default},{"../demux/demuxer":8,"../errors":11,"../events":12,"../helper/level-helper":13,"../utils/logger":19}],5:[function(r,a,s){"use strict";function l(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(s,"__esModule",{value:!0});var d=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),n=r("../events"),e=l(n),t=r("../utils/logger"),i=r("../errors"),o=function(){function r(t){u(this,r),this.hls=t,this.onml=this.onManifestLoaded.bind(this),this.onll=this.onLevelLoaded.bind(this),this.onerr=this.onError.bind(this),this.ontick=this.tick.bind(this),t.on(e.default.MANIFEST_LOADED,this.onml),t.on(e.default.LEVEL_LOADED,this.onll),t.on(e.default.ERROR,this.onerr),this._manualLevel=this._autoLevelCapping=-1}return d(r,[{key:"destroy",value:function(){var t=this.hls;t.off(e.default.MANIFEST_LOADED,this.onml),t.off(e.default.LEVEL_LOADED,this.onll),t.off(e.default.ERROR,this.onerr),this.timer&&clearInterval(this.timer),this._manualLevel=-1}},{key:"onManifestLoaded",value:function(d,n){var a,r,s=[],i=[],o={},l=!1,u=!1;for(n.levels.forEach(function(e){e.videoCodec&&(l=!0),e.audioCodec&&(u=!0);var t=o[e.bitrate];void 0===t?(o[e.bitrate]=i.length,e.url=[e.url],e.urlId=0,s.push(e)):s[t].url.push(e.url)}),l&&u?s.forEach(function(e){e.videoCodec&&i.push(e)}):i=s,a=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===a){this._firstLevel=r,t.logger.log("manifest loaded,"+i.length+" level(s) found, first bitrate:"+a);break}this.hls.trigger(e.default.MANIFEST_PARSED,{levels:this._levels,firstLevel:this._firstLevel,stats:n.stats})}},{key:"setLevelInternal",value:function(r){if(r>=0&&r<this._levels.length){this.timer&&(clearInterval(this.timer),this.timer=null),this._level=r,t.logger.log("switching to level "+r),this.hls.trigger(e.default.LEVEL_SWITCH,{level:r});var s=this._levels[r];if(void 0===s.details||s.details.live===!0){t.logger.log("(re)loading playlist for level "+r);var a=s.urlId;this.hls.trigger(e.default.LEVEL_LOADING,{url:s.url[a],level:r,id:a})}}else this.hls.trigger(e.default.ERROR,{type:i.ErrorTypes.OTHER_ERROR,details:i.ErrorDetails.LEVEL_SWITCH_ERROR,level:r,fatal:!1,reason:"invalid level idx"})}},{key:"onError",value:function(n,s){var r,e,a=s.details;switch(a){case i.ErrorDetails.FRAG_LOAD_ERROR:case i.ErrorDetails.FRAG_LOAD_TIMEOUT:case i.ErrorDetails.FRAG_LOOP_LOADING_ERROR:r=s.frag.level;break;case i.ErrorDetails.LEVEL_LOAD_ERROR:case i.ErrorDetails.LEVEL_LOAD_TIMEOUT:r=s.level}if(void 0!==r)if(e=this._levels[r],e.urlId<e.url.length-1)e.urlId++,e.details=void 0,t.logger.warn("level controller,"+a+" for level "+r+": switching to redundant stream id "+e.urlId);else{var o=-1===this._manualLevel&&r;o?(t.logger.warn("level controller,"+a+": emergency switch-down for next fragment"),this.hls.abrController.nextAutoLevel=0):e&&e.details&&e.details.live?t.logger.warn("level controller,"+a+" on live stream, discard"):(t.logger.error("cannot recover "+a+" error"),this._level=void 0,this.timer&&(clearInterval(this.timer),this.timer=null,s.fatal=!0,this.hls.trigger(n,s)))}}},{key:"onLevelLoaded",value:function(t,e){e.details.live&&!this.timer&&(this.timer=setInterval(this.ontick,1e3*e.details.targetduration))}},{key:"tick",value:function(){var t=this._level;if(void 0!==t){var i=this._levels[t],r=i.urlId;this.hls.trigger(e.default.LEVEL_LOADING,{url:i.url[r],level:t,id:r})}}},{key:"nextLoadLevel",value:function(){return-1!==this._manualLevel?this._manualLevel:this.hls.abrController.nextAutoLevel}},{key:"levels",get:function(){return this._levels}},{key:"level",get:function(){return this._level},set:function(e){(this._level!==e||void 0===this._levels[e].details)&&this.setLevelInternal(e)}},{key:"manualLevel",get:function(){return this._manualLevel},set:function(e){this._manualLevel=e,-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){return void 0===this._startLevel?this._firstLevel:this._startLevel},set:function(e){this._startLevel=e}}]),r}();s.default=o,a.exports=s.default},{"../errors":11,"../events":12,"../utils/logger":19}],6:[function(t,i,e){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),n=t("../demux/tsdemuxer"),o=r(n),l=function(){function e(t,i){s(this,e),this.hls=t,this.demuxer=new o.default(t,i)}return a(e,[{key:"destroy",value:function(){this.demuxer.destroy()}},{key:"push",value:function(e,t,i,r,s,a,n){this.demuxer.push(e,t,i,r,s,a,n)}},{key:"remux",value:function(){this.demuxer.remux()}}]),e}();e.default=l,i.exports=e.default},{"../demux/tsdemuxer":10}],7:[function(t,n,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var s=t("../demux/demuxer-inline"),a=i(s),f=t("../events"),e=i(f),l=t("events"),u=i(l),d=t("../remux/mp4-remuxer"),h=i(d),o=function(i){var t=new u.default;t.trigger=function(r){for(var i=arguments.length,s=Array(i>1?i-1:0),e=1;i>e;e++)s[e-1]=arguments[e];t.emit.apply(t,[r,r].concat(s))},t.off=function(s){for(var i=arguments.length,r=Array(i>1?i-1:0),e=1;i>e;e++)r[e-1]=arguments[e];t.removeListener.apply(t,[s].concat(r))},i.addEventListener("message",function(e){switch(e.data.cmd){case"init":i.demuxer=new a.default(t,h.default);break;case"demux":i.demuxer.push(new Uint8Array(e.data.data),e.data.audioCodec,e.data.videoCodec,e.data.timeOffset,e.data.cc,e.data.level,e.data.duration),i.demuxer.remux()}}),t.on(e.default.FRAG_PARSING_INIT_SEGMENT,function(s,t){var e={event:s},r=[];t.audioCodec&&(e.audioCodec=t.audioCodec,e.audioMoov=t.audioMoov.buffer,e.audioChannelCount=t.audioChannelCount,r.push(e.audioMoov)),t.videoCodec&&(e.videoCodec=t.videoCodec,e.videoMoov=t.videoMoov.buffer,e.videoWidth=t.videoWidth,e.videoHeight=t.videoHeight,r.push(e.videoMoov)),i.postMessage(e,r)}),t.on(e.default.FRAG_PARSING_DATA,function(r,e){
|
|
var t={event:r,type:e.type,startPTS:e.startPTS,endPTS:e.endPTS,startDTS:e.startDTS,endDTS:e.endDTS,moof:e.moof.buffer,mdat:e.mdat.buffer,nb:e.nb};i.postMessage(t,[t.moof,t.mdat])}),t.on(e.default.FRAG_PARSED,function(e){i.postMessage({event:e})}),t.on(e.default.ERROR,function(e,t){i.postMessage({event:e,data:t})}),t.on(e.default.FRAG_PARSING_METADATA,function(e,t){var r={event:e,samples:t.samples};i.postMessage(r)})};r.default=o,n.exports=r.default},{"../demux/demuxer-inline":6,"../events":12,"../remux/mp4-remuxer":18,events:1}],8:[function(e,l,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var f=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),v=e("../events"),t=i(v),g=e("../demux/demuxer-inline"),s=i(g),d=e("../demux/demuxer-worker"),h=i(d),a=e("../utils/logger"),c=e("../remux/mp4-remuxer"),n=i(c),o=function(){function i(t){if(u(this,i),this.hls=t,t.config.enableWorker&&"undefined"!=typeof Worker){a.logger.log("demuxing in webworker");try{var r=e("webworkify");this.w=r(h.default),this.onwmsg=this.onWorkerMessage.bind(this),this.w.addEventListener("message",this.onwmsg),this.w.postMessage({cmd:"init"})}catch(e){a.logger.error("error while initializing DemuxerWorker, fallback on DemuxerInline"),this.demuxer=new s.default(t,n.default)}}else this.demuxer=new s.default(t,n.default);this.demuxInitialized=!0}return f(i,[{key:"destroy",value:function(){this.w?(this.w.removeEventListener("message",this.onwmsg),this.w.terminate(),this.w=null):this.demuxer.destroy()}},{key:"push",value:function(e,t,i,r,s,a,n){this.w?this.w.postMessage({cmd:"demux",data:e,audioCodec:t,videoCodec:i,timeOffset:r,cc:s,level:a,duration:n},[e]):(this.demuxer.push(new Uint8Array(e),t,i,r,s,a,n),this.demuxer.remux())}},{key:"onWorkerMessage",value:function(e){switch(e.data.event){case t.default.FRAG_PARSING_INIT_SEGMENT:var i={};e.data.audioMoov&&(i.audioMoov=new Uint8Array(e.data.audioMoov),i.audioCodec=e.data.audioCodec,i.audioChannelCount=e.data.audioChannelCount),e.data.videoMoov&&(i.videoMoov=new Uint8Array(e.data.videoMoov),i.videoCodec=e.data.videoCodec,i.videoWidth=e.data.videoWidth,i.videoHeight=e.data.videoHeight),this.hls.trigger(t.default.FRAG_PARSING_INIT_SEGMENT,i);break;case t.default.FRAG_PARSING_DATA:this.hls.trigger(t.default.FRAG_PARSING_DATA,{moof:new Uint8Array(e.data.moof),mdat:new Uint8Array(e.data.mdat),startPTS:e.data.startPTS,endPTS:e.data.endPTS,startDTS:e.data.startDTS,endDTS:e.data.endDTS,type:e.data.type,nb:e.data.nb});break;case t.default.FRAG_PARSING_METADATA:this.hls.trigger(t.default.FRAG_PARSING_METADATA,{samples:e.data.samples});break;default:this.hls.trigger(e.data.event,e.data.data)}}}]),i}();r.default=o,l.exports=r.default},{"../demux/demuxer-inline":6,"../demux/demuxer-worker":7,"../events":12,"../remux/mp4-remuxer":18,"../utils/logger":19,webworkify:2}],9:[function(t,i,e){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),a=t("../utils/logger"),n=function(){function e(t){r(this,e),this.data=t,this.bytesAvailable=this.data.byteLength,this.word=0,this.bitsAvailable=0}return s(e,[{key:"loadWord",value:function(){var t=this.data.byteLength-this.bytesAvailable,i=new Uint8Array(4),e=Math.min(4,this.bytesAvailable);if(0===e)throw new Error("no bytes available");i.set(this.data.subarray(t,t+e)),this.word=new DataView(i.buffer).getUint32(0),this.bitsAvailable=8*e,this.bytesAvailable-=e}},{key:"skipBits",value:function(e){var t;this.bitsAvailable>e?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,t=e>>3,e-=t>>3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)}},{key:"readBits",value:function(t){var e=Math.min(this.bitsAvailable,t),i=this.word>>>32-e;return t>32&&a.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=e,this.bitsAvailable>0?this.word<<=e:this.bytesAvailable>0&&this.loadWord(),e=t-e,e>0?i<<e|this.readBits(e):i}},{key:"skipLZ",value:function(){var e;for(e=0;e<this.bitsAvailable;++e)if(0!==(this.word&2147483648>>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"skipScalingList",value:function(s){var t,r,i=8,e=8;for(t=0;s>t;t++)0!==e&&(r=this.readEG(),e=(i+r+256)%256),i=0===e?i:e}},{key:"readSPS",value:function(){var t,o,l,r,s,a,i,v,e,u=0,d=0,h=0,f=0;if(this.readUByte(),t=this.readUByte(),o=this.readBits(5),this.skipBits(3),l=this.readUByte(),this.skipUEG(),100===t||110===t||122===t||144===t){var c=this.readUEG();if(3===c&&this.skipBits(1),this.skipUEG(),this.skipUEG(),this.skipBits(1),this.readBoolean())for(v=3!==c?8:12,e=0;v>e;e++)this.readBoolean()&&(6>e?this.skipScalingList(16):this.skipScalingList(64))}this.skipUEG();var n=this.readUEG();if(0===n)this.readUEG();else if(1===n)for(this.skipBits(1),this.skipEG(),this.skipEG(),r=this.readUEG(),e=0;r>e;e++)this.skipEG();return this.skipUEG(),this.skipBits(1),s=this.readUEG(),a=this.readUEG(),i=this.readBits(1),0===i&&this.skipBits(1),this.skipBits(1),this.readBoolean()&&(u=this.readUEG(),d=this.readUEG(),h=this.readUEG(),f=this.readUEG()),{profileIdc:t,profileCompat:o,levelIdc:l,width:16*(s+1)-2*u-2*d,height:(2-i)*(a+1)*16-2*h-2*f}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}();e.default=n,i.exports=e.default},{"../utils/logger":19}],10:[function(i,h,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var d=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),f=i("../events"),s=a(f),l=i("./exp-golomb"),n=a(l),t=i("../utils/logger"),e=i("../errors"),o=function(){function i(e,t){u(this,i),this.observer=e,this.remuxerClass=t,this.lastCC=0,this.PES_TIMESCALE=9e4,this.remuxer=new this.remuxerClass(this.observer)}return d(i,[{key:"switchLevel",value:function(){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack={type:"video",id:-1,sequenceNumber:0,samples:[],len:0,nbNalu:0},this._aacTrack={type:"audio",id:-1,sequenceNumber:0,samples:[],len:0},this._id3Track={type:"id3",id:-1,sequenceNumber:0,samples:[],len:0},this.remuxer.switchLevel()}},{key:"insertDiscontinuity",value:function(){this.switchLevel(),this.remuxer.insertDiscontinuity()}},{key:"push",value:function(r,L,E,A,v,h,_){var n,o,l,i,d,u,p,a,y=r.length;this.audioCodec=L,this.videoCodec=E,this.timeOffset=A,this._duration=_,v!==this.lastCC?(t.logger.log("discontinuity detected"),this.insertDiscontinuity(),this.lastCC=v):h!==this.lastLevel&&(t.logger.log("level switch detected"),this.switchLevel(),this.lastLevel=h);var m=this.pmtParsed,c=this._avcTrack.id,f=this._aacTrack.id,g=this._id3Track.id;for(i=0;y>i;i+=188)if(71===r[i]){if(d=!!(64&r[i+1]),u=((31&r[i+1])<<8)+r[i+2],p=(48&r[i+3])>>4,p>1){if(a=i+5+r[i+4],a===i+188)continue}else a=i+4;m?u===c?(d&&(n&&this._parseAVCPES(this._parsePES(n)),n={data:[],size:0}),n&&(n.data.push(r.subarray(a,i+188)),n.size+=i+188-a)):u===f?(d&&(o&&this._parseAACPES(this._parsePES(o)),o={data:[],size:0}),o&&(o.data.push(r.subarray(a,i+188)),o.size+=i+188-a)):u===g&&(d&&(l&&this._parseID3PES(this._parsePES(l)),l={data:[],size:0}),l&&(l.data.push(r.subarray(a,i+188)),l.size+=i+188-a)):(d&&(a+=r[a]+1),0===u?this._parsePAT(r,a):u===this._pmtId&&(this._parsePMT(r,a),m=this.pmtParsed=!0,c=this._avcTrack.id,f=this._aacTrack.id,g=this._id3Track.id))}else this.observer.trigger(s.default.ERROR,{type:e.ErrorTypes.MEDIA_ERROR,details:e.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});n&&this._parseAVCPES(this._parsePES(n)),o&&this._parseAACPES(this._parsePES(o)),l&&this._parseID3PES(this._parsePES(l))}},{key:"remux",value:function(){this.remuxer.remux(this._aacTrack,this._avcTrack,this._id3Track,this.timeOffset)}},{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(i,e){var s,a,n,r;for(s=(15&i[e+1])<<8|i[e+2],a=e+3+s-4,n=(15&i[e+10])<<8|i[e+11],e+=12+n;a>e;){switch(r=(31&i[e+1])<<8|i[e+2],i[e]){case 15:this._aacTrack.id=r;break;case 21:this._id3Track.id=r;break;case 27:this._avcTrack.id=r;break;default:t.logger.log("unkown stream type:"+i[e])}e+=((15&i[e+3])<<8|i[e+4])+5}}},{key:"_parsePES",value:function(t){var e,s,u,o,d,a,i,r,n,l=0;if(e=t.data[0],u=(e[0]<<16)+(e[1]<<8)+e[2],1===u){for(o=(e[4]<<8)+e[5],s=e[7],192&s&&(i=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,i>4294967295&&(i-=8589934592),64&s?(r=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2,r>4294967295&&(r-=8589934592)):r=i),d=e[8],n=d+9,t.data[0]=t.data[0].subarray(n),t.size-=n,a=new Uint8Array(t.size);t.data.length;)e=t.data.shift(),a.set(e,l),l+=e.byteLength;return{data:a,pts:i,dts:r,len:o}}return null}},{key:"_parseAVCPES",value:function(t){var i,u,a=this,e=this._avcTrack,r=!1;if(i=this._parseAVCNALu(t.data),0===i.length&this._avcTrack.samples.length>0){var o=this._avcTrack.samples[this._avcTrack.samples.length-1],s=o.units.units[o.units.units.length-1],l=new Uint8Array(s.data.byteLength+t.data.byteLength);l.set(s.data,0),l.set(t.data,s.data.byteLength),s.data=l,o.units.length+=t.data.byteLength,this._avcTrack.len+=t.data.byteLength}t.data=null,i.units.forEach(function(t){switch(t.type){case 1:var s=new n.default(t.data).readSliceType();(2===s||4===s||7===s||9===s)&&(r=!0);break;case 5:r=!0;break;case 7:if(!e.sps){var d=new n.default(t.data),i=d.readSPS();e.width=i.width,e.height=i.height,e.profileIdc=i.profileIdc,e.profileCompat=i.profileCompat,e.levelIdc=i.levelIdc,e.sps=[t.data],e.timescale=a.remuxer.timescale,e.duration=a.remuxer.timescale*a._duration;for(var h=t.data.subarray(1,4),u="avc1.",l=0;3>l;l++){var o=h[l].toString(16);o.length<2&&(o="0"+o),u+=o}e.codec=u}break;case 8:e.pps||(e.pps=[t.data])}}),i.length&&(r===!0||e.sps)&&(u={units:i,pts:t.pts,dts:t.dts,key:r},this._avcTrack.samples.push(u),this._avcTrack.len+=i.length,this._avcTrack.nbNalu+=i.units.length)}},{key:"_parseAVCNALu",value:function(r){for(var a,s,l,n,i,d,t=0,o=r.byteLength,e=0,h=[],f=0;o>t;)switch(a=r[t++],e){case 0:0===a&&(e=1);break;case 1:e=0===a?2:0;break;case 2:case 3:if(0===a)e=3;else if(1===a){if(n=31&r[t],i)l={data:r.subarray(i,t-e-1),type:d},f+=t-e-1-i,h.push(l);else if(s=t-e-1,s&&this._avcTrack.samples.length){var c=this._avcTrack.samples[this._avcTrack.samples.length-1],u=c.units.units[c.units.units.length-1],v=new Uint8Array(u.data.byteLength+s);v.set(u.data,0),v.set(r.subarray(0,s),u.data.byteLength),u.data=v,c.units.length+=s,this._avcTrack.len+=s}i=t,d=n,(1===n||5===n)&&(t=o),e=0}else e=0}return i&&(l={data:r.subarray(i,o),type:d},f+=o-i,h.push(l)),{units:h,length:f}}},{key:"_parseAACPES",value:function(p){var g,o,n,i,u,f,h,l,a=this._aacTrack,r=p.data;if(this.aacOverFlow){var v=new Uint8Array(this.aacOverFlow.byteLength+r.byteLength);v.set(this.aacOverFlow,0),v.set(r,this.aacOverFlow.byteLength),r=v}for(i=0,l=r.length;l-1>i&&(255!==r[i]||240!==(240&r[i+1]));i++);if(i){var c,d;if(l-1>i?(c="AAC PES did not start with ADTS header,offset:"+i,d=!1):(c="no ADTS header found in AAC PES",d=!0),this.observer.trigger(s.default.ERROR,{type:e.ErrorTypes.MEDIA_ERROR,details:e.ErrorDetails.FRAG_PARSING_ERROR,fatal:d,reason:c}),d)return}for(a.audiosamplerate||(o=this._ADTStoAudioConfig(r,i,this.audioCodec),a.config=o.config,a.audiosamplerate=o.samplerate,a.channelCount=o.channelCount,a.codec=o.codec,a.timescale=this.remuxer.timescale,a.duration=this.remuxer.timescale*this._duration,t.logger.log("parsed codec:"+a.codec+",rate:"+o.samplerate+",nb channel:"+o.channelCount)),h=0;l>i+5&&(n=(3&r[i+3])<<11,n|=r[i+4]<<3,n|=(224&r[i+5])>>>5,u=1&r[i+1]?7:9,n-=u,f=Math.round(p.pts+1024*h*this.PES_TIMESCALE/a.audiosamplerate),l>=i+u+n);)g={unit:r.subarray(i+u,i+u+n),pts:f,dts:f},this._aacTrack.samples.push(g),this._aacTrack.len+=n,i+=n+u,h++;l>i?this.aacOverFlow=r.subarray(i,l):this.aacOverFlow=null}},{key:"_ADTStoAudioConfig",value:function(u,d,o){var a,i,n,l,r,f=navigator.userAgent.toLowerCase(),h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];return a=((192&u[d+2])>>>6)+1,i=(60&u[d+2])>>>2,i>h.length-1?void this.observer.trigger(s.default.ERROR,{type:e.ErrorTypes.MEDIA_ERROR,details:e.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+i}):(l=(1&u[d+2])<<2,l|=(192&u[d+3])>>>6,t.logger.log("manifest codec:"+o+",ADTS data:type:"+a+",sampleingIndex:"+i+"["+h[i]+"kHz],channelConfig:"+l),-1!==f.indexOf("firefox")?i>=6?(a=5,r=new Array(4),n=i-3):(a=2,r=new Array(2),n=i):-1!==f.indexOf("android")?(a=2,r=new Array(2),n=i):(a=5,r=new Array(4),o&&-1!==o.indexOf("mp4a.40.5")||!o&&i>=6?n=i-3:(o&&-1!==o.indexOf("mp4a.40.2")&&(i>=6||1===l)&&(a=2,r=new Array(2)),n=i)),r[0]=a<<3,r[0]|=(14&i)>>1,r[1]|=(1&i)<<7,r[1]|=l<<3,5===a&&(r[1]|=(14&n)>>1,r[2]=(1&n)<<7,r[2]|=8,r[3]=0),{config:r,samplerate:h[i],channelCount:l,codec:"mp4a.40."+a})}},{key:"_parseID3PES",value:function(e){this._id3Track.samples.push(e)}}]),i}();r.default=o,h.exports=r.default},{"../errors":11,"../events":12,"../utils/logger":19,"./exp-golomb":9}],11:[function(r,s,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t={NETWORK_ERROR:"hlsNetworkError",MEDIA_ERROR:"hlsMediaError",OTHER_ERROR:"hlsOtherError"};e.ErrorTypes=t;var i={MANIFEST_LOAD_ERROR:"manifestLoadError",MANIFEST_LOAD_TIMEOUT:"manifestLoadTimeOut",MANIFEST_PARSING_ERROR:"manifestParsingError",LEVEL_LOAD_ERROR:"levelLoadError",LEVEL_LOAD_TIMEOUT:"levelLoadTimeOut",LEVEL_SWITCH_ERROR:"levelSwitchError",FRAG_LOAD_ERROR:"fragLoadError",FRAG_LOOP_LOADING_ERROR:"fragLoopLoadingError",FRAG_LOAD_TIMEOUT:"fragLoadTimeOut",FRAG_PARSING_ERROR:"fragParsingError",FRAG_APPENDING_ERROR:"fragAppendingError"};e.ErrorDetails=i},{}],12:[function(i,t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={MSE_ATTACHED:"hlsMediaSourceAttached",MSE_DETACHING:"hlsMediaSourceDetaching",MSE_DETACHED:"hlsMediaSourceDetached",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsPTSUpdated",LEVEL_SWITCH:"hlsLevelSwitch",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_PROGRESS:"hlsFragLoadProgress",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_METADATA:"hlsFraParsingMetadata",FRAG_PARSING_DATA:"hlsFragParsingData",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFPSDrop",ERROR:"hlsError",DESTROYING:"hlsDestroying"},t.exports=e.default},{}],13:[function(i,r,e){"use strict";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),t=i("../utils/logger"),n=function(){function e(){s(this,e)}return a(e,null,[{key:"mergeDetails",value:function(a,r){var n,c=Math.max(a.startSN,r.startSN)-r.startSN,d=Math.min(a.endSN,r.endSN)-r.startSN,h=r.startSN-a.startSN,f=a.fragments,o=r.fragments,u=0;if(c>d)return void(r.PTSKnown=!1);for(var i=c;d>=i;i++){var l=f[h+i],s=o[i];u=l.cc-s.cc,isNaN(l.startPTS)||(s.start=s.startPTS=l.startPTS,s.endPTS=l.endPTS,s.duration=l.duration,n=s)}if(u)for(t.logger.log("discontinuity sliding from playlist, take drift into account"),i=0;i<o.length;i++)o[i].cc+=u;if(n)e.updateFragPTS(r,n.sn,n.startPTS,n.endPTS);else{var v=f[h].start;for(i=0;i<o.length;i++)o[i].start+=v}r.PTSKnown=a.PTSKnown}},{key:"updateFragPTS",value:function(r,l,s,n){var o,a,i,t;if(l<r.startSN||l>r.endSN)return 0;o=l-r.startSN,a=r.fragments,i=a[o],isNaN(i.startPTS)||(s=Math.max(s,i.startPTS),n=Math.min(n,i.endPTS));var u=s-i.start;for(i.start=i.startPTS=s,i.endPTS=n,i.duration=n-s,t=o;t>0;t--)e.updatePTS(a,t,t-1);for(t=o;t<a.length-1;t++)e.updatePTS(a,t,t+1);return r.PTSKnown=!0,u}},{key:"updatePTS",value:function(n,r,s){var e=n[r],i=n[s],a=i.startPTS;isNaN(a)?s>r?i.start=e.start+e.duration:i.start=e.start-i.duration:s>r?(e.duration=a-e.start,e.duration<0&&t.logger.error("negative duration computed for "+e+", there should be some duration drift between playlist and fragment!")):(i.duration=e.start-a,i.duration<0&&t.logger.error("negative duration computed for "+i+", there should be some duration drift between playlist and fragment!"))}}]),e}();e.default=n,r.exports=e.default},{"../utils/logger":19}],14:[function(t,f,s){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(s,"__esModule",{value:!0});var a=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),E=t("./events"),r=i(E),n=t("./errors"),u=t("./loader/playlist-loader"),d=i(u),h=t("./loader/fragment-loader"),S=i(h),c=t("./controller/abr-controller"),v=i(c),g=t("./controller/buffer-controller"),p=i(g),m=t("./controller/level-controller"),y=i(m),e=t("./utils/logger"),L=t("./utils/xhr-loader"),_=i(L),A=t("events"),b=i(A),l=function(){function t(){var r=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];o(this,t);var a={autoStartLoad:!0,debug:!1,maxBufferLength:30,maxBufferSize:6e7,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,maxMaxBufferLength:600,enableWorker:!0,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:1,fragLoadingRetryDelay:1e3,fragLoadingLoopThreshold:3,manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:200,loader:_.default,abrController:v.default};for(var s in a)s in r||(r[s]=a[s]);if(void 0!==r.liveMaxLatencyDurationCount&&r.liveMaxLatencyDurationCount<=r.liveSyncDurationCount)throw new Error('Illegal hls.js configuration: "liveMaxLatencyDurationCount" must be strictly superior to "liveSyncDurationCount" in player configuration');(0,e.enableLogs)(r.debug),this.config=r;var i=this.observer=new b.default;i.trigger=function(r){for(var t=arguments.length,s=Array(t>1?t-1:0),e=1;t>e;e++)s[e-1]=arguments[e];i.emit.apply(i,[r,r].concat(s))},i.off=function(s){for(var t=arguments.length,r=Array(t>1?t-1:0),e=1;t>e;e++)r[e-1]=arguments[e];i.removeListener.apply(i,[s].concat(r))},this.on=i.on.bind(i),this.off=i.off.bind(i),this.trigger=i.trigger.bind(i),this.playlistLoader=new d.default(this),this.fragmentLoader=new S.default(this),this.levelController=new y.default(this),this.abrController=new r.abrController(this),this.bufferController=new p.default(this)}return a(t,null,[{key:"isSupported",value:function(){return window.MediaSource&&window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')}},{key:"Events",get:function(){return r.default}},{key:"ErrorTypes",get:function(){return n.ErrorTypes}},{key:"ErrorDetails",get:function(){return n.ErrorDetails}}]),a(t,[{key:"destroy",value:function(){e.logger.log("destroy"),this.trigger(r.default.DESTROYING),this.playlistLoader.destroy(),this.fragmentLoader.destroy(),this.levelController.destroy(),this.bufferController.destroy(),this.url=null,this.detachVideo(),this.observer.removeAllListeners()}},{key:"attachVideo",value:function(i){e.logger.log("attachVideo"),this.video=i;var t=this.mediaSource=new MediaSource;this.onmso=this.onMediaSourceOpen.bind(this),this.onmse=this.onMediaSourceEnded.bind(this),this.onmsc=this.onMediaSourceClose.bind(this),t.addEventListener("sourceopen",this.onmso),t.addEventListener("sourceended",this.onmse),t.addEventListener("sourceclose",this.onmsc),i.src=URL.createObjectURL(t),i.addEventListener("error",this.onverror)}},{key:"detachVideo",value:function(){e.logger.log("detachVideo");var i=this.video;e.logger.log("trigger MSE_DETACHING"),this.trigger(r.default.MSE_DETACHING);var t=this.mediaSource;t&&("open"===t.readyState&&t.endOfStream(),t.removeEventListener("sourceopen",this.onmso),t.removeEventListener("sourceended",this.onmse),t.removeEventListener("sourceclose",this.onmsc),i.src="",this.mediaSource=null,e.logger.log("trigger MSE_DETACHED"),this.trigger(r.default.MSE_DETACHED)),this.onmso=this.onmse=this.onmsc=null,i&&(this.video=null)}},{key:"loadSource",value:function(t){e.logger.log("loadSource:"+t),this.url=t,this.trigger(r.default.MANIFEST_LOADING,{url:t})}},{key:"startLoad",value:function(){e.logger.log("startLoad"),this.bufferController.startLoad()}},{key:"recoverMediaError",value:function(){e.logger.log("recoverMediaError");var t=this.video;this.detachVideo(),this.attachVideo(t)}},{key:"onMediaSourceOpen",value:function(){e.logger.log("media source opened"),this.trigger(r.default.MSE_ATTACHED,{video:this.video,mediaSource:this.mediaSource}),this.mediaSource.removeEventListener("sourceopen",this.onmso)}},{key:"onMediaSourceClose",value:function(){e.logger.log("media source closed")}},{key:"onMediaSourceEnded",value:function(){e.logger.log("media source ended")}},{key:"levels",get:function(){return this.levelController.levels}},{key:"currentLevel",get:function(){return this.bufferController.currentLevel},set:function(t){e.logger.log("set currentLevel:"+t),this.loadLevel=t,this.bufferController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.bufferController.nextLevel},set:function(t){e.logger.log("set nextLevel:"+t),this.levelController.manualLevel=t,this.bufferController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(t){e.logger.log("set loadLevel:"+t),this.levelController.manualLevel=t}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel()},set:function(e){this.levelController.level=e}},{key:"firstLevel",get:function(){return this.levelController.firstLevel},set:function(t){e.logger.log("set firstLevel:"+t),this.levelController.firstLevel=t}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(t){e.logger.log("set startLevel:"+t),this.levelController.startLevel=t}},{key:"autoLevelCapping",get:function(){return this.abrController.autoLevelCapping},set:function(t){e.logger.log("set autoLevelCapping:"+t),this.abrController.autoLevelCapping=t}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}}]),t}();s.default=l,f.exports=s.default},{"./controller/abr-controller":3,"./controller/buffer-controller":4,"./controller/level-controller":5,"./errors":11,"./events":12,"./loader/fragment-loader":15,"./loader/playlist-loader":16,"./utils/logger":19,"./utils/xhr-loader":20,events:1}],15:[function(r,s,i){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),l=r("../events"),e=a(l),t=r("../errors"),u=function(){function i(t){n(this,i),this.hls=t,this.onfl=this.onFragLoading.bind(this),t.on(e.default.FRAG_LOADING,this.onfl)}return o(i,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),this.hls.off(e.default.FRAG_LOADING,this.onfl)}},{key:"onFragLoading",value:function(r,i){var t=i.frag;this.frag=t,this.frag.loaded=0;var e=this.hls.config;t.loader=this.loader=new e.loader(e),this.loader.load(t.url,"arraybuffer",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),e.fragLoadingTimeOut,e.fragLoadingMaxRetry,e.fragLoadingRetryDelay,this.loadprogress.bind(this),t)}},{key:"loadsuccess",value:function(r,t){var i=r.currentTarget.response;t.length=i.byteLength,this.frag.loader=void 0,this.hls.trigger(e.default.FRAG_LOADED,{payload:i,frag:this.frag,stats:t})}},{key:"loaderror",value:function(i){this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:this.frag,response:i})}},{key:"loadtimeout",value:function(){this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.FRAG_LOAD_TIMEOUT,fatal:!1,frag:this.frag})}},{key:"loadprogress",value:function(i,t){this.frag.loaded=t.loaded,this.hls.trigger(e.default.FRAG_LOAD_PROGRESS,{frag:this.frag,stats:t})}}]),i}();i.default=u,s.exports=i.default},{"../errors":11,"../events":12}],16:[function(r,s,i){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),l=r("../events"),e=a(l),t=r("../errors"),u=function(){function i(t){n(this,i),this.hls=t,this.onml=this.onManifestLoading.bind(this),this.onll=this.onLevelLoading.bind(this),t.on(e.default.MANIFEST_LOADING,this.onml),t.on(e.default.LEVEL_LOADING,this.onll)}return o(i,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),this.url=this.id=null,this.hls.off(e.default.MANIFEST_LOADING,this.onml),this.hls.off(e.default.LEVEL_LOADING,this.onll)}},{key:"onManifestLoading",value:function(t,e){this.load(e.url,null)}},{key:"onLevelLoading",value:function(t,e){this.load(e.url,e.level,e.id)}},{key:"load",value:function(t,i,r){var e=this.hls.config;this.url=t,this.id=i,this.id2=r,this.loader=new e.loader(e),this.loader.load(t,"",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),e.manifestLoadingTimeOut,e.manifestLoadingMaxRetry,e.manifestLoadingRetryDelay)}},{key:"resolve",value:function(n,o){var i,e=document,t=e.getElementsByTagName("base")[0],l=t&&t.href,r=e.head||e.getElementsByTagName("head")[0],s=t||r.appendChild(e.createElement("base")),a=e.createElement("a");return s.href=o,a.href=n,i=a.href,t?t.href=l:r.removeChild(s),i}},{key:"parseMasterPlaylist",value:function(a,n){for(var e,r,i,s=[],t={},o=/#EXT-X-STREAM-INF:([^\n\r]*(BAND)WIDTH=(\d+))?([^\n\r]*(CODECS)=\"([^\"\n\r]*)\",?)?([^\n\r]*(RES)OLUTION=(\d+)x(\d+))?([^\n\r]*(NAME)=\"(.*)\")?[^\n\r]*[\r\n]+([^\r\n]+)/g;null!=(e=o.exec(a));){for(e.shift(),e=e.filter(function(e){return void 0!==e}),t.url=this.resolve(e.pop(),n);e.length>0;)switch(e.shift()){case"RES":t.width=parseInt(e.shift()),t.height=parseInt(e.shift());break;case"BAND":t.bitrate=parseInt(e.shift());break;case"NAME":t.name=e.shift();break;case"CODECS":for(r=e.shift().split(",");r.length>0;)i=r.shift(),-1!==i.indexOf("avc1")?t.videoCodec=this.avc1toavcoti(i):t.audioCodec=i}s.push(t),t={}}return s}},{key:"avc1toavcoti",value:function(i){var e,t=i.split(".");return t.length>2?(e=t.shift()+".",e+=parseInt(t.shift()).toString(16),e+=("00"+parseInt(t.shift()).toString(16)).substr(-4)):e=i,e}},{key:"parseLevelPlaylist",value:function(l,a,u){var e,n,i=0,r=0,t={url:a,fragments:[],live:!0,startSN:0},o=0;for(n=/(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT(INF):([\d\.]+)[^\r\n]*[\r\n]+([^\r\n]+)|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))/g;null!==(e=n.exec(l));)switch(e.shift(),e=e.filter(function(e){return void 0!==e}),e[0]){case"MEDIA-SEQUENCE":i=t.startSN=parseInt(e[1]);break;case"TARGETDURATION":t.targetduration=parseFloat(e[1]);break;case"ENDLIST":t.live=!1;break;case"DIS":o++;break;case"INF":var s=parseFloat(e[1]);isNaN(s)||(t.fragments.push({url:this.resolve(e[2],a),duration:s,start:r,sn:i++,level:u,cc:o}),r+=s)}return t.totalduration=r,t.endSN=i-1,t}},{key:"loadsuccess",value:function(n,r){var o,a=n.currentTarget.responseText,i=n.currentTarget.responseURL,l=this.id,u=this.id2,s=this.hls;void 0===i&&(i=this.url),r.tload=new Date,r.mtime=new Date(n.currentTarget.getResponseHeader("Last-Modified")),0===a.indexOf("#EXTM3U")?a.indexOf("#EXTINF:")>0?null===this.id?s.trigger(e.default.MANIFEST_LOADED,{levels:[{url:i}],url:i,stats:r}):s.trigger(e.default.LEVEL_LOADED,{details:this.parseLevelPlaylist(a,i,l),level:l,id:u,stats:r}):(o=this.parseMasterPlaylist(a,i),o.length?s.trigger(e.default.MANIFEST_LOADED,{levels:o,url:i,stats:r}):s.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:i,reason:"no level found in manifest"})):s.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:i,reason:"no EXTM3U delimiter"})}},{key:"loaderror",value:function(s){var i,r;null===this.id?(i=t.ErrorDetails.MANIFEST_LOAD_ERROR,r=!0):(i=t.ErrorDetails.LEVEL_LOAD_ERROR,r=!1),this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:i,fatal:r,url:this.url,loader:this.loader,response:s.currentTarget,level:this.id,id:this.id2})}},{key:"loadtimeout",value:function(){var i,r;null===this.id?(i=t.ErrorDetails.MANIFEST_LOAD_TIMEOUT,r=!0):(i=t.ErrorDetails.LEVEL_LOAD_TIMEOUT,r=!1),this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:i,fatal:r,url:this.url,loader:this.loader,level:this.id,id:this.id2})}}]),i}();i.default=u,s.exports=i.default},{"../errors":11,"../events":12}],17:[function(a,t,e){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),s=function(){function e(){i(this,e)}return r(e,null,[{key:"init",value:function(){e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],
|
|
trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]};var t;for(t in e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);e.MAJOR_BRAND=new Uint8Array(["i".charCodeAt(0),"s".charCodeAt(0),"o".charCodeAt(0),"m".charCodeAt(0)]),e.AVC1_BRAND=new Uint8Array(["a".charCodeAt(0),"v".charCodeAt(0),"c".charCodeAt(0),"1".charCodeAt(0)]),e.MINOR_VERSION=new Uint8Array([0,0,0,1]),e.VIDEO_HDLR=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),e.AUDIO_HDLR=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]),e.HDLR_TYPES={video:e.VIDEO_HDLR,audio:e.AUDIO_HDLR},e.DREF=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),e.STCO=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSC=e.STCO,e.STTS=e.STCO,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSD=new Uint8Array([0,0,0,0,0,0,0,1]),e.FTYP=e.box(e.types.ftyp,e.MAJOR_BRAND,e.MINOR_VERSION,e.MAJOR_BRAND,e.AVC1_BRAND),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,e.DREF))}},{key:"box",value:function(a){for(var t,s,i=Array.prototype.slice.call(arguments,1),r=0,e=i.length;e--;)r+=i[e].byteLength;for(t=new Uint8Array(r+8),s=new DataView(t.buffer),s.setUint32(0,t.byteLength),t.set(a,4),e=0,r=8;e<i.length;e++)t.set(i[e],r),r+=i[e].byteLength;return t}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}},{key:"mdhd",value:function(t,i){return e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,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,i,r){return e.box(e.types.moof,e.mfhd(t),e.traf(r,i))}},{key:"moov",value:function(t){for(var i=t.length,r=[];i--;)r[i]=e.trak(t[i]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(r).concat(e.mvex(t)))}},{key:"mvex",value:function(i){for(var t=i.length,r=[];t--;)r[t]=e.trex(i[t]);return e.box.apply(null,[e.types.mvex].concat(r))}},{key:"mvhd",value:function(t,i){var r=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,i>>24&255,i>>16&255,i>>8&255,255&i,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,r)}},{key:"sdtp",value:function(a){var i,t,r=a.samples||[],s=new Uint8Array(4+r.length);for(t=0;t<r.length;t++)i=r[t].flags,s[t+4]=i.dependsOn<<4|i.isDependedOn<<2|i.hasRedundancy;return e.box(e.types.sdtp,s)}},{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 i,r=[],s=[];for(i=0;i<t.sps.length;i++)r.push(t.sps[i].byteLength>>>8&255),r.push(255&t.sps[i].byteLength),r=r.concat(Array.prototype.slice.call(t.sps[i]));for(i=0;i<t.pps.length;i++)s.push(t.pps[i].byteLength>>>8&255),s.push(255&t.pps[i].byteLength),s=s.concat(Array.prototype.slice.call(t.pps[i]));return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,t.width>>8&255,255&t.width,t.height>>8&255,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,19,118,105,100,101,111,106,115,45,99,111,110,116,114,105,98,45,104,108,115,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),e.box(e.types.avcC,new Uint8Array([1,t.profileIdc,t.profileCompat,t.levelIdc,255].concat([t.sps.length]).concat(r).concat([t.pps.length]).concat(s))),e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value:function(e){return new Uint8Array([0,0,0,0,3,23+e.config.length,0,1,0,4,15+e.config.length,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([e.config.length]).concat(e.config).concat([6,1,2]))}},{key:"mp4a",value:function(t){return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,t.audiosamplerate>>8&255,255&t.audiosamplerate,0,0]),e.box(e.types.esds,e.esds(t)))}},{key:"stsd",value:function(t){return"audio"===t.type?e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,t.id>>24&255,t.id>>16&255,t.id>>8&255,255&t.id,0,0,0,0,t.duration>>24,t.duration>>16&255,t.duration>>8&255,255&t.duration,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,t.width>>8&255,255&t.width,0,0,t.height>>8&255,255&t.height,0,0]))}},{key:"traf",value:function(t,i){var r=e.sdtp(t);return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,t.id>>24,t.id>>16&255,t.id>>8&255,255&t.id])),e.box(e.types.tfdt,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i])),e.trun(t,r.length+16+16+8+16+8+8),r)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t.id>>24,t.id>>16&255,t.id>>8&255,255&t.id,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(n,r){var i,t,s,a;for(i=n.samples||[],a=new Uint8Array(12+16*i.length),r+=8+a.byteLength,a.set([0,0,15,1,i.length>>>24&255,i.length>>>16&255,i.length>>>8&255,255&i.length,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),s=0;s<i.length;s++)t=i[s],a.set([t.duration>>>24&255,t.duration>>>16&255,t.duration>>>8&255,255&t.duration,t.size>>>24&255,t.size>>>16&255,t.size>>>8&255,255&t.size,t.flags.isLeading<<2|t.flags.dependsOn,t.flags.isDependedOn<<6|t.flags.hasRedundancy<<4|t.flags.paddingValue<<1|t.flags.isNonSync,61440&t.flags.degradPrio,15&t.flags.degradPrio,t.cts>>>24&255,t.cts>>>16&255,t.cts>>>8&255,255&t.cts],12+16*s);return e.box(e.types.trun,a)}},{key:"initSegment",value:function(r){e.types||e.init();var t,i=e.moov(r);return t=new Uint8Array(e.FTYP.byteLength+i.byteLength),t.set(e.FTYP),t.set(i,e.FTYP.byteLength),t}}]),e}();e.default=s,t.exports=e.default},{}],18:[function(r,h,s){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(s,"__esModule",{value:!0});var d=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),f=r("../events"),e=a(f),i=r("../utils/logger"),u=r("../remux/mp4-generator"),t=a(u),n=r("../errors"),o=function(){function r(e){l(this,r),this.observer=e,this.ISGenerated=!1,this.PES2MP4SCALEFACTOR=4,this.PES_TIMESCALE=9e4,this.MP4_TIMESCALE=this.PES_TIMESCALE/this.PES2MP4SCALEFACTOR}return d(r,[{key:"destroy",value:function(){}},{key:"insertDiscontinuity",value:function(){this._initPTS=this._initDTS=this.nextAacPts=this.nextAvcDts=void 0}},{key:"switchLevel",value:function(){this.ISGenerated=!1}},{key:"remux",value:function(i,r,s,t){this.ISGenerated||this.generateIS(i,r,t),r.samples.length&&this.remuxVideo(r,t),i.samples.length&&this.remuxAudio(i,t),s.samples.length&&this.remuxID3(s,t),this.observer.trigger(e.default.FRAG_PARSED)}},{key:"generateIS",value:function(r,i,s){var u=this.observer,o=r.samples,l=i.samples,d=o.length,h=l.length,a=this.PES_TIMESCALE;0===d&&0===h?u.trigger(e.default.ERROR,{type:n.ErrorTypes.MEDIA_ERROR,details:n.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"}):0===h?(r.config&&(u.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,{audioMoov:t.default.initSegment([r]),audioCodec:r.codec,audioChannelCount:r.channelCount}),this.ISGenerated=!0),void 0===this._initPTS&&(this._initPTS=o[0].pts-a*s,this._initDTS=o[0].dts-a*s)):0===d?i.sps&&i.pps&&(u.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,{videoMoov:t.default.initSegment([i]),videoCodec:i.codec,videoWidth:i.width,videoHeight:i.height}),this.ISGenerated=!0,void 0===this._initPTS&&(this._initPTS=l[0].pts-a*s,this._initDTS=l[0].dts-a*s)):r.config&&i.sps&&i.pps&&(u.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,{audioMoov:t.default.initSegment([r]),audioCodec:r.codec,audioChannelCount:r.channelCount,videoMoov:t.default.initSegment([i]),videoCodec:i.codec,videoWidth:i.width,videoHeight:i.height}),this.ISGenerated=!0,void 0===this._initPTS&&(this._initPTS=Math.min(l[0].pts,o[0].pts)-a*s,this._initDTS=Math.min(l[0].dts,o[0].dts)-a*s))}},{key:"remuxVideo",value:function(a,T){var _,u,s,y,c,o,S,A,E,v,L,p,n,r,g=8,f=this.PES_TIMESCALE,h=this.PES2MP4SCALEFACTOR,d=[];for(o=new Uint8Array(a.len+4*a.nbNalu+8),_=new DataView(o.buffer),_.setUint32(0,o.byteLength),o.set(t.default.types.mdat,4);a.samples.length;){for(u=a.samples.shift(),y=0;u.units.units.length;)c=u.units.units.shift(),_.setUint32(g,c.data.byteLength),g+=4,o.set(c.data,g),g+=c.data.byteLength,y+=4+c.data.byteLength;if(L=u.pts-this._initDTS,p=u.dts-this._initDTS,void 0!==v)n=this._PTSNormalize(L,v),r=this._PTSNormalize(p,v),s.duration=(r-v)/h,s.duration<0&&(s.duration=0);else{if(n=this._PTSNormalize(L,this.nextAvcDts),r=this._PTSNormalize(p,this.nextAvcDts),this.nextAvcDts){var l=Math.round((r-this.nextAvcDts)/90),b=Math.abs(l);if(300>b)l>1?i.logger.log("AVC:"+l+" ms hole between fragments detected,filling it"):-1>l&&i.logger.log("AVC:"+-l+" ms overlapping between fragments detected"),b&&(r=this.nextAvcDts,n=Math.max(n-l,r),i.logger.log("Video/PTS/DTS adjusted:"+n+"/"+r));else{var m=f*T;if(Math.abs(m-r)>3600*f){var R=m-r;r=m,n=r,this._initPTS-=R,this._initDTS-=R}}}A=Math.max(0,n),E=Math.max(0,r)}s={size:y,duration:0,cts:(n-r)/h,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0}},u.key===!0?(s.flags.dependsOn=2,s.flags.isNonSync=0):(s.flags.dependsOn=1,s.flags.isNonSync=1),d.push(s),v=r}d.length>=2&&(s.duration=d[d.length-2].duration),this.nextAvcDts=r+s.duration*h,a.len=0,a.nbNalu=0,a.samples=d,S=t.default.moof(a.sequenceNumber++,E/h,a),a.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:S,mdat:o,startPTS:A/f,endPTS:(n+h*s.duration)/f,startDTS:E/f,endDTS:(r+h*s.duration)/f,type:"video",nb:d.length})}},{key:"remuxAudio",value:function(a,R){var b,f,n,c,u,A,_,m,d,p,g,r,s,L=8,o=this.PES_TIMESCALE,v=this.PES2MP4SCALEFACTOR,l=[];for(u=new Uint8Array(a.len+8),b=new DataView(u.buffer),b.setUint32(0,u.byteLength),u.set(t.default.types.mdat,4);a.samples.length;){if(f=a.samples.shift(),c=f.unit,u.set(c,L),L+=c.byteLength,p=f.pts-this._initDTS,g=f.dts-this._initDTS,void 0!==d)r=this._PTSNormalize(p,d),s=this._PTSNormalize(g,d),n.duration=(s-d)/v,n.duration<0&&(n.duration=0);else{if(r=this._PTSNormalize(p,this.nextAacPts),s=this._PTSNormalize(g,this.nextAacPts),this.nextAacPts&&this.nextAacPts!==r){var h=Math.round(1e3*(r-this.nextAacPts)/o),E=Math.abs(h);if(E>1&&300>E)h>0?i.logger.log("AAC:"+h+" ms hole between fragments detected,filling it"):i.logger.log("AAC:"+-h+" ms overlapping between fragments detected"),r=s=this.nextAacPts,i.logger.log("Audio/PTS/DTS adjusted:"+r+"/"+s);else if(E){var y=o*R;if(Math.abs(y-r)>3600*o){var S=y-r;r=y,s=r,this._initPTS-=S,this._initDTS-=S}}}_=Math.max(0,r),m=Math.max(0,s)}n={size:c.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},l.push(n),d=s}l.length>=2&&(n.duration=l[l.length-2].duration),this.nextAacPts=r+v*n.duration,a.len=0,a.samples=l,A=t.default.moof(a.sequenceNumber++,m/v,a),a.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:A,mdat:u,startPTS:_/o,endPTS:this.nextAacPts/o,startDTS:m/o,endDTS:(s+v*n.duration)/o,type:"audio",nb:l.length})}},{key:"remuxID3",value:function(i,s){var t,a=i.samples.length;if(a){for(var r=0;a>r;r++)t=i.samples[r],t.pts=(t.pts-this._initPTS)/this.PES_TIMESCALE,t.dts=(t.dts-this._initDTS)/this.PES_TIMESCALE;this.observer.trigger(e.default.FRAG_PARSING_METADATA,{samples:i.samples})}i.samples=[],s=s}},{key:"_PTSNormalize",value:function(e,t){var i;if(void 0===t)return e;for(i=e>t?-8589934592:8589934592;Math.abs(e-t)>4294967296;)e+=i;return e}},{key:"timescale",get:function(){return this.MP4_TIMESCALE}}]),r}();s.default=o,h.exports=s.default},{"../errors":11,"../events":12,"../remux/mp4-generator":17,"../utils/logger":19}],19:[function(n,o,i){"use strict";function t(){}Object.defineProperty(i,"__esModule",{value:!0});var r={log:t,warn:t,info:t,error:t},e=r,s=function(i){if(i===!0||"object"==typeof i){e.log=i.log?i.log.bind(i):void 0,e.info=i.info?i.info.bind(i):void 0,e.error=i.error?i.error.bind(i):void 0,e.warn=i.warn?i.warn.bind(i):void 0;try{e.log()}catch(i){e.log=t,e.info=t,e.error=t,e.warn=t}}else e=r};i.enableLogs=s;var a=e;i.logger=a},{}],20:[function(i,r,e){"use strict";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function e(r,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,e.key,e)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),t=i("../utils/logger"),n=function(){function e(t){s(this,e),t&&t.xhrSetup&&(this.xhrSetup=t.xhrSetup)}return a(e,[{key:"destroy",value:function(){this.abort(),this.loader=null}},{key:"abort",value:function(){this.loader&&4!==this.loader.readyState&&(this.stats.aborted=!0,this.loader.abort()),this.timeoutHandle&&window.clearTimeout(this.timeoutHandle)}},{key:"load",value:function(t,i,r,s,a,e,n,o){var l=arguments.length<=8||void 0===arguments[8]?null:arguments[8];this.url=t,this.responseType=i,this.onSuccess=r,this.onProgress=l,this.onTimeout=a,this.onError=s,this.stats={trequest:new Date,retry:0},this.timeout=e,this.maxRetry=n,this.retryDelay=o,this.timeoutHandle=window.setTimeout(this.loadtimeout.bind(this),e),this.loadInternal()}},{key:"loadInternal",value:function(){var e=this.loader=new XMLHttpRequest;e.onload=this.loadsuccess.bind(this),e.onerror=this.loaderror.bind(this),e.onprogress=this.loadprogress.bind(this),e.open("GET",this.url,!0),e.responseType=this.responseType,this.stats.tfirst=null,this.stats.loaded=0,this.xhrSetup&&this.xhrSetup(e),e.send()}},{key:"loadsuccess",value:function(e){window.clearTimeout(this.timeoutHandle),this.stats.tload=new Date,this.onSuccess(e,this.stats)}},{key:"loaderror",value:function(e){this.stats.retry<this.maxRetry?(t.logger.warn(e.type+" while loading "+this.url+", retrying in "+this.retryDelay+"..."),this.destroy(),window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,64e3),this.stats.retry++):(window.clearTimeout(this.timeoutHandle),t.logger.error(e.type+" while loading "+this.url),this.onError(e))}},{key:"loadtimeout",value:function(e){t.logger.warn("timeout while loading "+this.url),this.onTimeout(e,this.stats)}},{key:"loadprogress",value:function(t){var e=this.stats;null===e.tfirst&&(e.tfirst=new Date),e.loaded=t.loaded,this.onProgress&&this.onProgress(t,e)}}]),e}();e.default=n,r.exports=e.default},{"../utils/logger":19}]},{},[14])(14)});
|