jellyfin-web/dashboard-ui/bower_components/hls.js/dist/hls.min.js

5 lines
104 KiB
JavaScript
Raw Normal View History

2016-01-30 11:52:33 -07:00
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Hls=t()}}(function(){return function s(e,t,r){function i(a,d){if(!t[a]){if(!e[a]){var l="function"==typeof require&&require;if(!d&&l)return l(a,!0);if(n)return n(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var o=t[a]={exports:{}};e[a][0].call(o.exports,function(t){var r=e[a][1][t];return i(r?r:t)},o,o.exports,s,e,t,r)}return t[a].exports}for(var n="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(s,a,o){function e(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function t(e){return"function"==typeof e}function n(e){return"number"==typeof e}function r(e){return"object"==typeof e&&null!==e}function i(e){return void 0===e}a.exports=e,e.EventEmitter=e,e.prototype._events=void 0,e.prototype._maxListeners=void 0,e.defaultMaxListeners=10,e.prototype.setMaxListeners=function(e){if(!n(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},e.prototype.emit=function(u){var o,a,n,s,e,l;if(this._events||(this._events={}),"error"===u&&(!this._events.error||r(this._events.error)&&!this._events.error.length)){if(o=arguments[1],o instanceof Error)throw o;throw TypeError('Uncaught, unspecified "error" event.')}if(a=this._events[u],i(a))return!1;if(t(a))switch(arguments.length){case 1:a.call(this);break;case 2:a.call(this,arguments[1]);break;case 3:a.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,s=new Array(n-1),e=1;n>e;e++)s[e-1]=arguments[e];a.apply(this,s)}else if(r(a)){for(n=arguments.length,s=new Array(n-1),e=1;n>e;e++)s[e-1]=arguments[e];for(l=a.slice(),n=l.length,e=0;n>e;e++)l[e].apply(this,s)}return!0},e.prototype.addListener=function(a,n){var s;if(!t(n))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,t(n.listener)?n.listener:n),this._events[a]?r(this._events[a])?this._events[a].push(n):this._events[a]=[this._events[a],n]:this._events[a]=n,r(this._events[a])&&!this._events[a].warned){var s;s=i(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,s&&s>0&&this._events[a].length>s&&(this._events[a].warned=!0,"function"==typeof console.trace)}return this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(i,e){function r(){this.removeListener(i,r),a||(a=!0,e.apply(this,arguments))}if(!t(e))throw TypeError("listener must be a function");var a=!1;return r.listener=e,this.on(i,r),this},e.prototype.removeListener=function(a,i){var e,s,o,n;if(!t(i))throw TypeError("listener must be a function");if(!this._events||!this._events[a])return this;if(e=this._events[a],o=e.length,s=-1,e===i||t(e.listener)&&e.listener===i)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,i);else if(r(e)){for(n=o;n-->0;)if(e[n]===i||e[n].listener&&e[n].listener===i){s=n;break}if(0>s)return this;1===e.length?(e.length=0,delete this._events[a]):e.splice(s,1),this._events.removeListener&&this.emit("removeListener",a,i)}return this},e.prototype.removeAllListeners=function(e){var i,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(i in this._events)"removeListener"!==i&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],t(r))this.removeListener(e,r);else for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},e.prototype.listeners=function(e){var r;return r=this._events&&this._events[e]?t(this._events[e])?[this._events[e]]:this._events[e].slice():[]},e.listenerCount=function(e,r){var i;return i=e._events&&e._events[r]?t(e._events[r])?1:e._events[r].length:0}},{}],2:[func
case i.ErrorDetails.FRAG_LOAD_TIMEOUT:if(!a.fatal){var n=this.fragLoadError;if(n?n++:n=1,n<=this.config.fragLoadingMaxRetry){this.fragLoadError=n,a.frag.loadCounter=0;var s=Math.min(Math.pow(2,n-1)*this.config.fragLoadingRetryDelay,64e3);t.logger.warn("mediaController: frag loading failed, retry in "+s+" ms"),this.retryDate=performance.now()+s,this.state=e.FRAG_LOADING_WAITING_RETRY}else t.logger.error("mediaController: "+a.details+" reaches max retry, redispatch as fatal ..."),a.fatal=!0,this.hls.trigger(r.default.ERROR,a),this.state=e.ERROR}break;case i.ErrorDetails.FRAG_LOOP_LOADING_ERROR:case i.ErrorDetails.LEVEL_LOAD_ERROR:case i.ErrorDetails.LEVEL_LOAD_TIMEOUT:case i.ErrorDetails.KEY_LOAD_ERROR:case i.ErrorDetails.KEY_LOAD_TIMEOUT:t.logger.warn("mediaController: "+a.details+" while loading frag,switch to "+(a.fatal?"ERROR":"IDLE")+" state ..."),this.state=a.fatal?e.ERROR:e.IDLE}}},{key:"onSBUpdateEnd",value:function(){if(this.state===e.APPENDING&&0===this.mp4segments.length){var a=this.fragCurrent,i=this.stats;a&&(this.fragPrevious=a,i.tbuffered=performance.now(),this.fragLastKbps=Math.round(8*i.length/(i.tbuffered-i.tfirst)),this.hls.trigger(r.default.FRAG_BUFFERED,{stats:i,frag:a}),t.logger.log("media buffered : "+this.timeRangesToString(this.media.buffered)),this.state=e.IDLE)}this.tick()}},{key:"_checkBuffer",value:function(){var e=this.media;if(e){var u=e.readyState;if(u){var s=this.seekAfterBuffered;if(s)e.duration>=s&&(e.currentTime=s,this.seekAfterBuffered=void 0);else{var a=e.currentTime,o=this.bufferInfo(a,0),f=!(e.paused||e.ended||e.seeking||3>u),l=.2,d=a>e.playbackRate*this.lastCurrentTime;if(this.stalled&&d&&(this.stalled=!1),o.len<=l&&(d||!f?l=0:(t.logger.log("playback seems stuck"),this.stalled||(this.hls.trigger(r.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.BUFFER_STALLED_ERROR,fatal:!1}),this.stalled=!0)),o.len<=l)){var n=o.nextStart,h=n-a;n&&h<this.config.maxSeekHole&&h>.005&&!e.seeking&&(t.logger.log("adjust currentTime from "+a+" to "+n),e.currentTime=n)}}}}}},{key:"swapAudioCodec",value:function(){this.audioCodecSwap=!this.audioCodecSwap}},{key:"onSBUpdateError",value:function(a){t.logger.error("sourceBuffer error:"+a),this.state=e.ERROR,this.hls.trigger(r.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1,frag:this.fragCurrent})}},{key:"timeRangesToString",value:function(t){for(var r="",i=t.length,e=0;i>e;e++)r+="["+t.start(e)+","+t.end(e)+"]";return r}},{key:"onMediaSourceOpen",value:function(){t.logger.log("media source opened"),this.hls.trigger(r.default.MEDIA_ATTACHED),this.onvseeking=this.onMediaSeeking.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),this.onvmetadata=this.onMediaMetadata.bind(this),this.onvended=this.onMediaEnded.bind(this);var e=this.media;e.addEventListener("seeking",this.onvseeking),e.addEventListener("seeked",this.onvseeked),e.addEventListener("loadedmetadata",this.onvmetadata),e.addEventListener("ended",this.onvended),this.levels&&this.config.autoStartLoad&&this.startLoad(),this.mediaSource.removeEventListener("sourceopen",this.onmso)}},{key:"onMediaSourceClose",value:function(){t.logger.log("media source closed")}},{key:"onMediaSourceEnded",value:function(){t.logger.log("media source ended")}},{key:"currentLevel",get:function(){if(this.media){var e=this.getBufferRange(this.media.currentTime);if(e)return e.frag.level}return-1}},{key:"nextBufferRange",get:function(){return this.media?this.followingBufferRange(this.getBufferRange(this.media.currentTime)):null}},{key:"nextLevel",get:function(){var e=this.nextBufferRange;return e?e.frag.level:-1}}]),a}(o.default);s.default=_,h.exports=s.default},{"../demux/demuxer":13,"../errors":17,"../event-handler":18,"../events":19,"../helper/level-helper":20,"../utils/binary-search":28,"../utils/logger":29}],6:[function(n,t,e){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e
this.lastAacPTS=h}},{key:"_parseID3PES",value:function(e){this._id3Track.samples.push(e)}}],[{key:"probe",value:function(e){return e.length>=564&&71===e[0]&&71===e[188]&&71===e[376]?!0:!1}}]),t}();i.default=u,o.exports=i.default},{"../errors":17,"../events":19,"../utils/logger":29,"./adts":10,"./exp-golomb":14}],17:[function(i,a,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t={NETWORK_ERROR:"hlsNetworkError",MEDIA_ERROR:"hlsMediaError",OTHER_ERROR:"hlsOtherError"};e.ErrorTypes=t;var r={MANIFEST_LOAD_ERROR:"manifestLoadError",MANIFEST_LOAD_TIMEOUT:"manifestLoadTimeOut",MANIFEST_PARSING_ERROR:"manifestParsingError",LEVEL_LOAD_ERROR:"levelLoadError",LEVEL_LOAD_TIMEOUT:"levelLoadTimeOut",LEVEL_SWITCH_ERROR:"levelSwitchError",FRAG_LOAD_ERROR:"fragLoadError",FRAG_LOOP_LOADING_ERROR:"fragLoopLoadingError",FRAG_LOAD_TIMEOUT:"fragLoadTimeOut",FRAG_DECRYPT_ERROR:"fragDecryptError",FRAG_PARSING_ERROR:"fragParsingError",KEY_LOAD_ERROR:"keyLoadError",KEY_LOAD_TIMEOUT:"keyLoadTimeOut",BUFFER_APPEND_ERROR:"bufferAppendError",BUFFER_APPENDING_ERROR:"bufferAppendingError",BUFFER_STALLED_ERROR:"bufferStalledError"};e.ErrorDetails=r},{}],18:[function(n,t,e){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),a=function(){function e(n){r(this,e),this.hls=n,this.onEvent=this.onEvent.bind(this);for(var i=arguments.length,a=Array(i>1?i-1:0),t=1;i>t;t++)a[t-1]=arguments[t];this.handledEvents=a,this.useGenericHandler=!0,this.registerListeners()}return i(e,[{key:"destroy",value:function(){this.unregisterListeners()}},{key:"isEventHandler",value:function(){return"object"==typeof 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(t,r){var e="on"+t.replace("hls","");if("function"!=typeof this[e])throw new Error("Event "+t+" has no generic handler in this "+this.constructor.name+" class (tried "+e+")");return this[e].bind(this,r)};r.call(this,e,t).call()}}]),e}();e.default=a,t.exports=e.default},{}],19:[function(t,e,r){"use strict";e.exports={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"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_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"}},{}],20:[function(r,i,e){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(i,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object
videoCodec:t.codec,videoWidth:t.width,videoHeight:t.height}),this.ISGenerated=!0,void 0===this._initPTS&&(this._initPTS=l[0].pts-n*a,this._initDTS=l[0].dts-n*a)):i.config&&t.sps&&t.pps&&(u.trigger(e.default.FRAG_PARSING_INIT_SEGMENT,{audioMoov:r.default.initSegment([i]),audioCodec:i.codec,audioChannelCount:i.channelCount,videoMoov:r.default.initSegment([t]),videoCodec:t.codec,videoWidth:t.width,videoHeight:t.height}),this.ISGenerated=!0,void 0===this._initPTS&&(this._initPTS=Math.min(l[0].pts,o[0].pts)-n*a,this._initDTS=Math.min(l[0].dts,o[0].dts)-n*a))}},{key:"remuxVideo",value:function(a,w,k){var A,l,g,L,v,d,S,T,R,f,_,c,o,i,s,p=8,E=this.PES_TIMESCALE,h=this.PES2MP4SCALEFACTOR,u=[];for(d=new Uint8Array(a.len+4*a.nbNalu+8),A=new DataView(d.buffer),A.setUint32(0,d.byteLength),d.set(r.default.types.mdat,4);a.samples.length;){for(l=a.samples.shift(),L=0;l.units.units.length;)v=l.units.units.shift(),A.setUint32(p,v.data.byteLength),p+=4,d.set(v.data,p),p+=v.data.byteLength,L+=4+v.data.byteLength;if(_=l.pts-this._initDTS,c=l.dts-this._initDTS,c=Math.min(_,c),void 0!==f){o=this._PTSNormalize(_,f),i=this._PTSNormalize(c,f);var y=(i-f)/h;0>=y&&(t.logger.log("invalid sample duration at PTS/DTS: "+l.pts+"/"+l.dts+":"+y),y=1),g.duration=y}else{var n,m=this.nextAvcDts;o=this._PTSNormalize(_,m),i=this._PTSNormalize(c,m),n=Math.round((i-m)/90),(k||Math.abs(n)<600)&&n&&(n>1?t.logger.log("AVC:"+n+" ms hole between fragments detected,filling it"):-1>n&&t.logger.log("AVC:"+-n+" ms overlapping between fragments detected"),i=m,o=Math.max(o-n,i),t.logger.log("Video/PTS/DTS adjusted: "+o+"/"+i+",delta:"+n)),T=Math.max(0,o),R=Math.max(0,i)}g={size:L,duration:0,cts:(o-i)/h,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0}},s=g.flags,l.key===!0?(s.dependsOn=2,s.isNonSync=0):(s.dependsOn=1,s.isNonSync=1),u.push(g),f=i}var b=0;u.length>=2&&(b=u[u.length-2].duration,g.duration=b),this.nextAvcDts=i+b*h,a.len=0,a.nbNalu=0,u.length&&navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&(s=u[0].flags,s.dependsOn=2,s.isNonSync=0),a.samples=u,S=r.default.moof(a.sequenceNumber++,R/h,a),a.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:S,mdat:d,startPTS:T/E,endPTS:(o+h*b)/E,startDTS:R/E,endDTS:this.nextAvcDts/E,type:"video",nb:u.length})}},{key:"remuxAudio",value:function(i,k,S){var L,f,s,d,u,R,A,_,h,l,E,o,n,T=8,c=this.PES_TIMESCALE,p=this.PES2MP4SCALEFACTOR,g=[],b=[];for(i.samples.forEach(function(e){void 0===l||e.pts>l?(b.push(e),l=e.pts):t.logger.warn("dropping past audio frame")});b.length;){if(f=b.shift(),d=f.unit,l=f.pts-this._initDTS,E=f.dts-this._initDTS,void 0!==h)o=this._PTSNormalize(l,h),n=this._PTSNormalize(E,h),s.duration=(n-h)/p,s.duration<0&&(t.logger.log("invalid AAC sample duration at PTS:"+f.pts+":"+s.duration),s.duration=0);else{var a,m=this.nextAacPts;if(o=this._PTSNormalize(l,m),n=this._PTSNormalize(E,m),a=Math.round(1e3*(o-m)/c),(S||Math.abs(a)<600)&&a){if(a>0)t.logger.log(a+" ms hole between AAC samples detected,filling it");else if(-12>a){t.logger.log(-a+" ms overlapping between AAC samples detected, drop frame"),i.len-=d.byteLength;continue}o=n=m}A=Math.max(0,o),_=Math.max(0,n),u=new Uint8Array(i.len+8),L=new DataView(u.buffer),L.setUint32(0,u.byteLength),u.set(r.default.types.mdat,4)}u.set(d,T),T+=d.byteLength,s={size:d.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},g.push(s),h=n}var y=0,v=g.length;v>=2&&(y=g[v-2].duration,s.duration=y),v&&(this.nextAacPts=o+p*y,i.len=0,i.samples=g,R=r.default.moof(i.sequenceNumber++,_/p,i),i.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:R,mdat:u,startPTS:A/c,endPTS:this.nextAacPts/c,startDTS:_/c,endDTS:(n+p*y)/c,type:"audio",nb:v}))}},{key:"remuxID3",value:function(r,a){var t,n=r.samples.length;if(n){for(var i=0;n>i;i++)t=r.samples[i],t.pts=(t.pts-this._initPTS)/this.PES_TIMESCALE,t.dts=(t.dts-this._initDTS)/this.PES_TIMESCALE;this.observer.trigger(e.default.FRAG_PARSING_METADATA,{samples:r.samples})}r.samples=[],a=a}},{key:"_PTSNormalize",value:function(e,t){var r;if(void 0===t)retu