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

5 lines
122 KiB
JavaScript
Raw Normal View History

2016-03-25 09:35:19 -07:00
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Hls=e()}}(function(){return function s(e,t,r){function n(a,d){if(!t[a]){if(!e[a]){var l="function"==typeof require&&require;if(!d&&l)return l(a,!0);if(i)return i(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 n(r?r:t)},o,o.exports,s,e,t,r)}return t[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)n(r[a]);return n}({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 i(e){return"number"==typeof e}function r(e){return"object"==typeof e&&null!==e}function n(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(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},e.prototype.emit=function(l){var s,e,u,a,i,o;if(this._events||(this._events={}),"error"===l&&(!this._events.error||r(this._events.error)&&!this._events.error.length)){if(s=arguments[1],s instanceof Error)throw s;throw TypeError('Uncaught, unspecified "error" event.')}if(e=this._events[l],n(e))return!1;if(t(e))switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),e.apply(this,a)}else if(r(e))for(a=Array.prototype.slice.call(arguments,1),o=e.slice(),u=o.length,i=0;u>i;i++)o[i].apply(this,a);return!0},e.prototype.addListener=function(a,i){var s;if(!t(i))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,t(i.listener)?i.listener:i),this._events[a]?r(this._events[a])?this._events[a].push(i):this._events[a]=[this._events[a],i]:this._events[a]=i,r(this._events[a])&&!this._events[a].warned&&(s=n(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,s&&s>0&&this._events[a].length>s&&(this._events[a].warned=!0,"function"==typeof console.trace)),this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(n,e){function r(){this.removeListener(n,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(n,r),this},e.prototype.removeListener=function(a,n){var e,s,o,i;if(!t(n))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===n||t(e.listener)&&e.listener===n)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,n);else if(r(e)){for(i=o;i-- >0;)if(e[i]===n||e[i].listener&&e[i].listener===n){s=i;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,n)}return this},e.prototype.removeAllListeners=function(r){var n,e;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[r]&&delete this._events[r],this;if(0===arguments.length){for(n in this._events)"removeListener"!==n&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events={},this}if(e=this._events[r],t(e))this.removeListener(r,e);else if(e)for(;e.length;)this.removeListener(r,e[e.length-1]);return delete this._events[r],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.prototype.listenerCount=function(r){if(this._events){var e=this._events[r];if(t(e))return 1;if(e)return e.length}return 0},e.listenerCount=function(e,t){return e.listenerCount(t)}},{}]
this.previouslyPaused||this.media.play()}},{key:"nextLevelSwitch",value:function(){var a,n,t;if(n=this.getBufferRange(this.media.currentTime),n&&n.start>1&&(this.hls.trigger(r.default.BUFFER_FLUSHING,{startOffset:0,endOffset:n.start-1}),this.state=e.PAUSED),this.media.paused)a=0;else{var o=this.hls.nextLoadLevel,l=this.levels[o],s=this.fragLastKbps;a=s&&this.fragCurrent?this.fragCurrent.duration*l.bitrate/(1e3*s)+1:0}if(t=this.getBufferRange(this.media.currentTime+a),t&&(t=this.followingBufferRange(t))){this.hls.trigger(r.default.BUFFER_FLUSHING,{startOffset:t.start,endOffset:Number.POSITIVE_INFINITY}),this.state=e.PAUSED;var i=this.fragCurrent;i&&i.loader&&i.loader.abort(),this.fragCurrent=null,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold}}},{key:"onMediaAttached",value:function(t){var e=this.media=t.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),this.onvended=this.onMediaEnded.bind(this),e.addEventListener("seeking",this.onvseeking),e.addEventListener("seeked",this.onvseeked),e.addEventListener("ended",this.onvended),this.levels&&this.config.autoStartLoad&&this.hls.startLoad()}},{key:"onMediaDetaching",value:function(){var e=this.media;e&&e.ended&&(t.logger.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0);var r=this.levels;r&&r.forEach(function(e){e.details&&e.details.fragments.forEach(function(e){e.loadCounter=void 0})}),e&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("seeked",this.onvseeked),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvended=null),this.media=null,this.loadedmetadata=!1,this.stopLoad()}},{key:"onMediaSeeking",value:function(){if(this.state===e.FRAG_LOADING){if(0===s.default.bufferInfo(this.media,this.media.currentTime,this.config.maxBufferHole).len){t.logger.log("seeking outside of buffer while fragment load in progress, cancel fragment load");var r=this.fragCurrent;r&&(r.loader&&r.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.state=e.IDLE}}else this.state===e.ENDED&&(this.state=e.IDLE);this.media&&(this.lastCurrentTime=this.media.currentTime),void 0!==this.fragLoadIdx&&(this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold),this.tick()}},{key:"onMediaSeeked",value:function(){this.tick()}},{key:"onMediaEnded",value:function(){t.logger.log("media ended"),this.startPosition=this.lastCurrentTime=0}},{key:"onManifestLoading",value:function(){t.logger.log("trigger BUFFER_RESET"),this.hls.trigger(r.default.BUFFER_RESET),this.bufferRange=[],this.stalled=!1}},{key:"onManifestParsed",value:function(r){var e,n=!1,a=!1;r.levels.forEach(function(t){e=t.audioCodec,e&&(-1!==e.indexOf("mp4a.40.2")&&(n=!0),-1!==e.indexOf("mp4a.40.5")&&(a=!0))}),this.audioCodecSwitch=n&&a,this.audioCodecSwitch&&t.logger.log("both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=r.levels,this.startLevelLoaded=!1,this.startFragRequested=!1,this.config.autoStartLoad&&this.hls.startLoad()}},{key:"onLevelLoaded",value:function(s){var n=s.details,a=s.level,o=this.levels[a],l=n.totalduration,i=0;if(t.logger.log("level "+a+" loaded ["+n.startSN+","+n.endSN+"],duration:"+l),this.levelLastLoaded=a,n.live){var d=o.details;d?(u.default.mergeDetails(d,n),i=n.fragments[0].start,n.PTSKnown?t.logger.log("live playlist sliding:"+i.toFixed(3)):t.logger.log("live playlist - outdated PTS, unknown sliding")):(n.PTSKnown=!1,t.logger.log("live playlist - first load, unknown sliding"))}else n.PTSKnown=!1;if(o.details=n,this.hls.trigger(r.default.LEVEL_UPDATED,{details:n,level:a}),this.startFragRequested===!1){if(n.live){var f=void 0!==this.config.liveSyncDuration?this.config.liveSyncDuration:this.config.liveSyncDurationCount*n.targetduration;this.startPosition=Math.max(0,i+l-f)}this.nextLoadPosition=this.startPosition}this.state===e.WAITING_LEVEL&&(this.state=e.IDLE),this.tick()}},{key:"onKeyLoaded",value:function(){this.state===e.KEY_LOADING&&(this.state=e.IDLE,this.tick())}},{key:"onFragLoaded",value:function(a){var n=this.f
}e&&(c=e[0]/e[1])}return{width:Math.ceil((16*(a+1)-2*s-2*d)*c),height:(2-n)*(i+1)*16-(n?2:4)*(f+h)}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}();e.default=i},{"../utils/logger":36}],18:[function(r,s,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var a=function(){function e(n,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(n,e.key,e)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(t,"__esModule",{value:!0});var e=r("../utils/logger"),i=function(){function t(a){n(this,t),this._hasTimeStamp=!1;for(var l,u,d,f,h,s,o,i,r=0;;)if(o=this.readUTF(a,r,3),r+=3,"ID3"===o)r+=3,l=127&a[r++],u=127&a[r++],d=127&a[r++],f=127&a[r++],h=(l<<21)+(u<<14)+(d<<7)+f,s=r+h,this._parseID3Frames(a,r,s),r=s;else{if("3DI"!==o)return r-=3,i=r,void(i&&(this.hasTimeStamp||e.logger.warn("ID3 tag found, but no timestamp"),this._length=i,this._payload=a.subarray(0,i)));r+=7,e.logger.log("3DI footer found, end: "+r)}}return a(t,[{key:"readUTF",value:function(n,e,a){var t="",r=e,i=e+a;do t+=String.fromCharCode(n[r++]);while(i>r);return t}},{key:"_parseID3Frames",value:function(r,t,i){for(var a,s,o,l,n;i>=t+8;)switch(a=this.readUTF(r,t,4),t+=4,s=r[t++]<<24+r[t++]<<16+r[t++]<<8+r[t++],l=r[t++]<<8+r[t++],o=t,a){case"PRIV":if("com.apple.streaming.transportStreamTimestamp"===this.readUTF(r,t,44)){t+=44,t+=4;var u=1&r[t++];this._hasTimeStamp=!0,n=((r[t++]<<23)+(r[t++]<<15)+(r[t++]<<7)+r[t++])/45,u&&(n+=47721858.84),n=Math.round(n),e.logger.trace("ID3 timestamp found: "+n),this._timeStamp=n}}}},{key:"hasTimeStamp",get:function(){return this._hasTimeStamp}},{key:"timeStamp",get:function(){return this._timeStamp}},{key:"length",get:function(){return this._length}},{key:"payload",get:function(){return this._payload}}]),t}();t.default=i},{"../utils/logger":36}],19:[function(t,v,a){"use strict";function n(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")}var f=function(){function e(n,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(n,e.key,e)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(a,"__esModule",{value:!0});var h=t("./adts"),c=n(h),l=t("../events"),i=n(l),d=t("./exp-golomb"),s=n(d),e=t("../utils/logger"),r=t("../errors"),o=function(){function t(e,r){u(this,t),this.observer=e,this.remuxerClass=r,this.lastCC=0,this.remuxer=new this.remuxerClass(e)}return f(t,[{key:"switchLevel",value:function(){this.pmtParsed=!1,this._pmtId=-1,this.lastAacPTS=null,this.aacOverFlow=null,this._avcTrack={container:"video/mp2t",type:"video",id:-1,sequenceNumber:0,samples:[],len:0,nbNalu:0},this._aacTrack={container:"video/mp2t",type:"audio",id:-1,sequenceNumber:0,samples:[],len:0},this._id3Track={type:"id3",id:-1,sequenceNumber:0,samples:[],len:0},this._txtTrack={type:"text",id:-1,sequenceNumber:0,samples:[],len:0},this.remuxer.switchLevel()}},{key:"insertDiscontinuity",value:function(){this.switchLevel(),this.remuxer.insertDiscontinuity()}},{key:"push",value:function(n,R,L,_,p,m,E,A){var s,o,l,t,d,u,y,a,c=n.length,b=this.remuxer.passthrough;this.audioCodec=R,this.videoCodec=L,this.timeOffset=_,this._duration=A,this.contiguous=!1,p!==this.lastCC?(e.logger.log("discontinuity detected"),this.insertDiscontinuity(),this.lastCC=p):m!==this.lastLevel?(e.logger.log("level switch detected"),this.switchLevel(),this.lastLevel=m):E===this.lastSN+1&&(this.contiguous=!0),this.lastSN=E,this.contiguous||(this.aacOverFlow=null);var g=this.pmtParsed,h=this._avcTrack.id,f=this._aacTrack.id,v=this._id3Track.id;for(c-=c%188,t=0;c>t;t+=188)if(71===n[t]){if(d=!!(64&n[t+1]),u=((31&n[t+1])<<8)+n[t+2],y=(48&n[t+3])>>4,y>1){if(a=t+5+n[t+4],a===t+188)continue}else a=t+4;if(g)if(u===h){if(d){if(s&&(this._parseAVCPES(this._parsePES(s)),b&&this._avc
e.name=r.NAME;var t=r.CODECS;if(t){t=t.split(",");for(var o=0;o<t.length;o++){var i=t[o];-1!==i.indexOf("avc1")?e.videoCodec=this.avc1toavcoti(i):e.audioCodec=i}}l.push(e)}return l}},{key:"avc1toavcoti",value:function(r){var e,t=r.split(".");return t.length>2?(e=t.shift()+".",e+=parseInt(t.shift()).toString(16),e+=("000"+parseInt(t.shift()).toString(16)).substr(-4)):e=r,e}},{key:"cloneObj",value:function(e){return JSON.parse(JSON.stringify(e))}},{key:"parseLevelPlaylist",value:function(L,l,A){var e,b,s,i,g=0,o=0,n={url:l,fragments:[],live:!0,startSN:0},r={method:null,key:null,iv:null,uri:null},E=0,f=null,t=null;for(b=/(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT-X-(KEY):(.*))|(?:#EXT(INF):([\d\.]+)[^\r\n]*([\r\n]+[^#|\r\n]+)?)|(?:#EXT-X-(BYTERANGE):([\d]+[@[\d]*)]*[\r\n]+([^#|\r\n]+)?|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(PROGRAM-DATE-TIME):(.*))/g;null!==(e=b.exec(L));)switch(e.shift(),e=e.filter(function(e){return void 0!==e}),e[0]){case"MEDIA-SEQUENCE":g=n.startSN=parseInt(e[1]);break;case"TARGETDURATION":n.targetduration=parseFloat(e[1]);break;case"ENDLIST":n.live=!1;break;case"DIS":E++;break;case"BYTERANGE":var c=e[1].split("@");i=1===c.length?s:parseInt(c[1]),s=parseInt(c[0])+i,t&&!t.url&&(t.byteRangeStartOffset=i,t.byteRangeEndOffset=s,t.url=this.resolve(e[2],l));break;case"INF":var v=parseFloat(e[1]);if(!isNaN(v)){var u,m=g++;if(r.method&&r.uri&&!r.iv){u=this.cloneObj(r);for(var y=new Uint8Array(16),d=12;16>d;d++)y[d]=m>>8*(15-d)&255;u.iv=y}else u=r;var k=e[2]?this.resolve(e[2],l):null;t={url:k,duration:v,start:o,sn:m,level:A,cc:E,byteRangeStartOffset:i,byteRangeEndOffset:s,decryptdata:u,programDateTime:f},n.fragments.push(t),o+=v,i=null,f=null}break;case"KEY":var R=e[1],p=new a.default(R),h=p.enumeratedString("METHOD"),_=p.URI,S=p.hexadecimalInteger("IV");h&&(r={method:null,key:null,iv:null,uri:null},_&&"AES-128"===h&&(r.method=h,r.uri=this.resolve(_,l),r.key=null,r.iv=S));break;case"PROGRAM-DATE-TIME":f=new Date(Date.parse(e[1]))}return t&&!t.url&&(n.fragments.pop(),o-=t.duration),n.totalduration=o,n.endSN=g-1,n}},{key:"loadsuccess",value:function(u,n){var s,o=u.currentTarget,i=o.responseText,r=o.responseURL,l=this.id,d=this.id2,a=this.hls;if(void 0===r&&(r=this.url),n.tload=performance.now(),n.mtime=new Date(o.getResponseHeader("Last-Modified")),0===i.indexOf("#EXTM3U"))if(i.indexOf("#EXTINF:")>0)if(null===this.id)a.trigger(t.default.MANIFEST_LOADED,{levels:[{url:r}],url:r,stats:n});else{var f=this.parseLevelPlaylist(i,r,l);n.tparsed=performance.now(),a.trigger(t.default.LEVEL_LOADED,{details:f,level:l,id:d,stats:n})}else s=this.parseMasterPlaylist(i,r),s.length?a.trigger(t.default.MANIFEST_LOADED,{levels:s,url:r,stats:n}):a.trigger(t.default.ERROR,{type:e.ErrorTypes.NETWORK_ERROR,details:e.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:r,reason:"no level found in manifest"});else a.trigger(t.default.ERROR,{type:e.ErrorTypes.NETWORK_ERROR,details:e.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:r,reason:"no EXTM3U delimiter"})}},{key:"loaderror",value:function(a){var r,n;null===this.id?(r=e.ErrorDetails.MANIFEST_LOAD_ERROR,n=!0):(r=e.ErrorDetails.LEVEL_LOAD_ERROR,n=!1),this.loader&&this.loader.abort(),this.hls.trigger(t.default.ERROR,{type:e.ErrorTypes.NETWORK_ERROR,details:r,fatal:n,url:this.url,loader:this.loader,response:a.currentTarget,level:this.id,id:this.id2})}},{key:"loadtimeout",value:function(){var r,n;null===this.id?(r=e.ErrorDetails.MANIFEST_LOAD_TIMEOUT,n=!0):(r=e.ErrorDetails.LEVEL_LOAD_TIMEOUT,n=!1),this.loader&&this.loader.abort(),this.hls.trigger(t.default.ERROR,{type:e.ErrorTypes.NETWORK_ERROR,details:r,fatal:n,url:this.url,loader:this.loader,level:this.id,id:this.id2})}}]),r}(i.default);s.default=u},{"../errors":20,"../event-handler":21,"../events":22,"../utils/attr-list":33,"../utils/url":37}],30:[function(a,i,e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(n,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=