(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d1e3ca3"],{2415:function(e,t,r){"use strict";r.r(t);var i=r("ba56"),a=r.n(i);function n(e){var t=e.src,r=e.autoplay,i=void 0!==r&&r,n=e.media,s=e.callback,o=void 0===s?function(){return{}}:s;if(a.a.isSupported()){var l=new a.a;l.loadSource(t),l.attachMedia(n),l.on(a.a.Events.ERROR,(function(e,t){if(t.fatal)switch(t.type){case a.a.ErrorTypes.NETWORK_ERROR:l.startLoad();break;default:l.destroy();break}})),i&&l.on(a.a.Events.MANIFEST_PARSED,(function(){n.play()})),o(l)}}t["default"]=n},ba56:function(e,t,r){"undefined"!==typeof window&&function(t,r){e.exports=r()}(0,(function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(i,a,function(t){return e[t]}.bind(null,a));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s="./src/hls.ts")}({"./node_modules/eventemitter3/index.js": /*!*********************************************!*\ !*** ./node_modules/eventemitter3/index.js ***! \*********************************************/ /*! no static exports found */ /*! ModuleConcatenation bailout: Module is not an ECMAScript module */function(e,t,r){"use strict";var i=Object.prototype.hasOwnProperty,a="~";function n(){}function s(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function o(e,t,r,i,n){if("function"!==typeof r)throw new TypeError("The listener must be a function");var o=new s(r,i||e,n),l=a?a+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],o]:e._events[l].push(o):(e._events[l]=o,e._eventsCount++),e}function l(e,t){0===--e._eventsCount?e._events=new n:delete e._events[t]}function u(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(a=!1)),u.prototype.eventNames=function(){var e,t,r=[];if(0===this._eventsCount)return r;for(t in e=this._events)i.call(e,t)&&r.push(a?t.slice(1):t);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},u.prototype.listeners=function(e){var t=a?a+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,n=r.length,s=new Array(n);i0}),!1)}function d(e,t){var r={main:[t]},i={main:[]},a={main:{}};while(u(r))for(var n=Object.keys(r),s=0;s>>8^255&v^99,e[h]=v,t[v]=h;var m=f[h],y=f[m],E=f[y],T=257*f[v]^16843008*v;i[h]=T<<24|T>>>8,a[h]=T<<16|T>>>16,n[h]=T<<8|T>>>24,s[h]=T,T=16843009*E^65537*y^257*m^16843008*h,l[v]=T<<24|T>>>8,u[v]=T<<16|T>>>16,d[v]=T<<8|T>>>24,c[v]=T,h?(h=m^f[f[f[E^m]]],g^=f[f[g]]):h=g=1}},t.expandKey=function(e){var t=this.uint8ArrayToUint32Array_(e),r=!0,i=0;while(i>>6),l=(60&t[r+2])>>>2,!(l>g.length-1))return d=(1&t[r+2])<<2,d|=(192&t[r+3])>>>6,o["logger"].log("manifest codec:"+n+",ADTS data:type:"+s+",sampleingIndex:"+l+"["+g[l]+"Hz],channelConfig:"+d),/firefox/i.test(f)?l>=6?(s=5,c=new Array(4),u=l-3):(s=2,c=new Array(2),u=l):-1!==f.indexOf("android")?(s=2,c=new Array(2),u=l):(s=5,c=new Array(4),n&&(-1!==n.indexOf("mp4a.40.29")||-1!==n.indexOf("mp4a.40.5"))||!n&&l>=6?u=l-3:((n&&-1!==n.indexOf("mp4a.40.2")&&(l>=6&&1===d||/vivaldi/i.test(f))||!n&&1===d)&&(s=2,c=new Array(2)),u=l)),c[0]=s<<3,c[0]|=(14&l)>>1,c[1]|=(1&l)<<7,c[1]|=d<<3,5===s&&(c[1]|=(14&u)>>1,c[2]=(1&u)<<7,c[2]|=8,c[3]=0),{config:c,samplerate:g[l],channelCount:d,codec:"mp4a.40."+s,manifestCodec:h};e.trigger(i["default"].ERROR,{type:a["ErrorTypes"].MEDIA_ERROR,details:a["ErrorDetails"].FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+l})}function d(e,t){return 255===e[t]&&240===(246&e[t+1])}function c(e,t){return 1&e[t+1]?7:9}function f(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function h(e,t){return!!(t+10&&t+n+s<=l)return o=r+i*a,{headerLength:n,frameLength:s,stamp:o}}function y(e,t,r,i,a){var n=v(e.samplerate),s=m(t,r,i,a,n);if(s){var o=s.stamp,l=s.headerLength,u=s.frameLength,d={unit:t.subarray(r+l,r+l+u),pts:o,dts:o};return e.samples.push(d),{sample:d,length:u+l}}}var E=r("./src/demux/id3.js"),T=function(){function e(e,t,r){this.observer=e,this.config=r,this.remuxer=t}var t=e.prototype;return t.resetInitSegment=function(e,t,r,i){this._audioTrack={container:"audio/adts",type:"audio",id:0,sequenceNumber:0,isAAC:!0,samples:[],len:0,manifestCodec:t,duration:i,inputTimeScale:9e4}},t.resetTimeStamp=function(){},e.probe=function(e){if(!e)return!1;for(var t=E["default"].getID3Data(e,0)||[],r=t.length,i=e.length;rt.length)){var n=this.parseHeader(t,r);if(n&&r+n.frameLength<=t.length){var s=9e4*n.samplesPerFrame/n.sampleRate,o=i+a*s,l={unit:t.subarray(r,r+n.frameLength),pts:o,dts:o};return e.config=[],e.channelCount=n.channelCount,e.samplerate=n.sampleRate,e.samples.push(l),{sample:l,length:n.frameLength}}}},parseHeader:function(e,t){var r=e[t+1]>>3&3,i=e[t+1]>>1&3,a=e[t+2]>>4&15,n=e[t+2]>>2&3,s=e[t+2]>>1&1;if(1!==r&&0!==a&&15!==a&&3!==n){var o=3===r?3-i:3===i?3:4,l=1e3*_.BitratesMap[14*o+a-1],u=3===r?0:2===r?1:2,d=_.SamplingRateMap[3*u+n],c=e[t+3]>>6===3?1:2,f=_.SamplesCoefficients[r][i],h=_.BytesInSlot[i],g=8*f*h,p=parseInt(f*l/d+s,10)*h;return{sampleRate:d,channelCount:c,frameLength:p,samplesPerFrame:g}}},isHeaderPattern:function(e,t){return 255===e[t]&&224===(224&e[t+1])&&0!==(6&e[t+1])},isHeader:function(e,t){return!!(t+1e?(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)},t.readBits=function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;return e>32&&o["logger"].error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0?this.word<<=t:this.bytesAvailable>0&&this.loadWord(),t=e-t,t>0&&this.bitsAvailable?r<>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()},t.skipUEG=function(){this.skipBits(1+this.skipLZ())},t.skipEG=function(){this.skipBits(1+this.skipLZ())},t.readUEG=function(){var e=this.skipLZ();return this.readBits(e+1)-1},t.readEG=function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)},t.readBoolean=function(){return 1===this.readBits(1)},t.readUByte=function(){return this.readBits(8)},t.readUShort=function(){return this.readBits(16)},t.readUInt=function(){return this.readBits(32)},t.skipScalingList=function(e){var t,r,i=8,a=8;for(t=0;t=e.length)return void r();if(!(e[t].unit.length<32)){var i=this.decrypter.isSync();if(this.decryptAacSample(e,t,r,i),!i)return}}},t.getAvcEncryptedData=function(e){for(var t=16*Math.floor((e.length-48)/160)+16,r=new Int8Array(t),i=0,a=32;a<=e.length-16;a+=160,i+=16)r.set(e.subarray(a,a+16),i);return r},t.getAvcDecryptedUnit=function(e,t){t=new Uint8Array(t);for(var r=0,i=32;i<=e.length-16;i+=160,r+=16)e.set(t.subarray(r,r+16),i);return e},t.decryptAvcSample=function(e,t,r,i,a,n){var s=this.discardEPB(a.data),o=this.getAvcEncryptedData(s),l=this;this.decryptBuffer(o.buffer,(function(o){a.data=l.getAvcDecryptedUnit(s,o),n||l.decryptAvcSamples(e,t,r+1,i)}))},t.decryptAvcSamples=function(e,t,r,i){for(;;t++,r=0){if(t>=e.length)return void i();for(var a=e[t].units;;r++){if(r>=a.length)break;var n=a[r];if(!(n.length<=48||1!==n.type&&5!==n.type)){var s=this.decrypter.isSync();if(this.decryptAvcSample(e,t,r,i,n,s),!s)return}}}},e}(),w=L,k={video:1,audio:2,id3:3,text:4},I=function(){function e(e,t,r,i){this.observer=e,this.config=r,this.typeSupported=i,this.remuxer=t,this.sampleAes=null}var t=e.prototype;return t.setDecryptData=function(e){null!=e&&null!=e.key&&"SAMPLE-AES"===e.method?this.sampleAes=new w(this.observer,this.config,e,this.discardEPB):this.sampleAes=null},e.probe=function(t){var r=e._syncOffset(t);return!(r<0)&&(r&&o["logger"].warn("MPEG2-TS detected but first sync word found @ offset "+r+", junk ahead ?"),!0)},e._syncOffset=function(e){var t=Math.min(1e3,e.length-564),r=0;while(r>4,c>1){if(f=l+5+t[l+4],f===l+188)continue}else f=l+4;switch(d){case T:u&&(A&&(h=k(A))&&I(h,!1),A={data:[],size:0}),A&&(A.data.push(t.subarray(f,l+188)),A.size+=l+188-f);break;case S:u&&(R&&(h=k(R))&&(y.isAAC?O(h):C(h)),R={data:[],size:0}),R&&(R.data.push(t.subarray(f,l+188)),R.size+=l+188-f);break;case b:u&&(D&&(h=k(D))&&P(h),D={data:[],size:0}),D&&(D.data.push(t.subarray(f,l+188)),D.size+=l+188-f);break;case 0:u&&(f+=t[f]+1),_=this._pmtId=L(t,f);break;case _:u&&(f+=t[f]+1);var F=w(t,f,!0===this.typeSupported.mpeg||!0===this.typeSupported.mp3,null!=this.sampleAes);T=F.avc,T>0&&(m.pid=T),S=F.audio,S>0&&(y.pid=S,y.isAAC=F.isAAC),b=F.id3,b>0&&(E.pid=b),p&&!v&&(o["logger"].log("reparse from beginning"),p=!1,l=x-188),v=this.pmtParsed=!0;break;case 17:case 8191:break;default:p=!0;break}}else this.observer.trigger(i["default"].ERROR,{type:a["ErrorTypes"].MEDIA_ERROR,details:a["ErrorDetails"].FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});A&&(h=k(A))?(I(h,!0),m.pesData=null):m.pesData=A,R&&(h=k(R))?(y.isAAC?O(h):C(h),y.pesData=null):(R&&R.size&&o["logger"].log("last AAC PES packet truncated,might overlap between fragments"),y.pesData=R),D&&(h=k(D))?(P(h),E.pesData=null):E.pesData=D,null==this.sampleAes?this.remuxer.remux(y,m,E,this._txtTrack,r,n,s):this.decryptAndRemux(y,m,E,this._txtTrack,r,n,s)},t.decryptAndRemux=function(e,t,r,i,a,n,s){if(e.samples&&e.isAAC){var o=this;this.sampleAes.decryptAacSamples(e.samples,0,(function(){o.decryptAndRemuxAvc(e,t,r,i,a,n,s)}))}else this.decryptAndRemuxAvc(e,t,r,i,a,n,s)},t.decryptAndRemuxAvc=function(e,t,r,i,a,n,s){if(t.samples){var o=this;this.sampleAes.decryptAvcSamples(t.samples,0,0,(function(){o.remuxer.remux(e,t,r,i,a,n,s)}))}else this.remuxer.remux(e,t,r,i,a,n,s)},t.destroy=function(){this._initPTS=this._initDTS=void 0,this._duration=0},t._parsePAT=function(e,t){return(31&e[t+10])<<8|e[t+11]},t._parsePMT=function(e,t,r,i){var a,n,s,l,u={audio:-1,avc:-1,id3:-1,isAAC:!0};a=(15&e[t+1])<<8|e[t+2],n=t+3+a-4,s=(15&e[t+10])<<8|e[t+11],t+=12+s;while(t1){var h=new Uint8Array(f[0].length+f[1].length);h.set(f[0]),h.set(f[1],f[0].length),f[0]=h,f.splice(1,1)}if(t=f[0],i=(t[0]<<16)+(t[1]<<8)+t[2],1===i){if(a=(t[4]<<8)+t[5],a&&a>e.size-6)return null;if(r=t[7],192&r&&(l=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,l>4294967295&&(l-=8589934592),64&r?(u=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2,u>4294967295&&(u-=8589934592),l-u>54e5&&(o["logger"].warn(Math.round((l-u)/9e4)+"s delta between PTS and DTS, align them"),l=u)):u=l),n=t[8],d=n+9,e.size<=d)return null;e.size-=d,s=new Uint8Array(e.size);for(var g=0,p=f.length;gv){d-=v;continue}t=t.subarray(d),v-=d,d=0}s.set(t,c),c+=v}return a&&(a-=n+3),{data:s,pts:l,dts:u,len:a}}return null},t.pushAccesUnit=function(e,t){if(e.units.length&&e.frame){var r=t.samples,i=r.length;if(isNaN(e.pts)){if(!i)return void t.dropped++;var a=r[i-1];e.pts=a.pts,e.dts=a.dts}!this.config.forceKeyFrameOnDiscontinuity||!0===e.key||t.sps&&(i||this.contiguous)?(e.id=i,r.push(e)):t.dropped++}e.debug.length&&o["logger"].log(e.pts+"/"+e.dts+":"+e.debug)},t._parseAVCPES=function(e,t){var r,i,a,n=this,s=this._avcTrack,o=this._parseAVCNALu(e.data),l=!1,u=this.avcSample,d=!1,c=this.pushAccesUnit.bind(this),f=function(e,t,r,i){return{key:e,pts:t,dts:r,units:[],debug:i}};e.data=null,u&&o.length&&!s.audFound&&(c(u,s),u=this.avcSample=f(!1,e.pts,e.dts,"")),o.forEach((function(t){switch(t.type){case 1:i=!0,u||(u=n.avcSample=f(!0,e.pts,e.dts,"")),l&&(u.debug+="NDR "),u.frame=!0;var o=t.data;if(d&&o.length>4){var h=new D(o).readSliceType();2!==h&&4!==h&&7!==h&&9!==h||(u.key=!0)}break;case 5:i=!0,u||(u=n.avcSample=f(!0,e.pts,e.dts,"")),l&&(u.debug+="IDR "),u.key=!0,u.frame=!0;break;case 6:i=!0,l&&u&&(u.debug+="SEI "),r=new D(n.discardEPB(t.data)),r.readUByte();var g=0,p=0,v=!1,m=0;while(!v&&r.bytesAvailable>1){g=0;do{m=r.readUByte(),g+=m}while(255===m);p=0;do{m=r.readUByte(),p+=m}while(255===m);if(4===g&&0!==r.bytesAvailable){v=!0;var y=r.readUByte();if(181===y){var T=r.readUShort();if(49===T){var S=r.readUInt();if(1195456820===S){var b=r.readUByte();if(3===b){var _=r.readUByte(),A=r.readUByte(),R=31&_,L=[_,A];for(a=0;a16){var w=[];for(a=0;a<16;a++)w.push(r.readUByte().toString(16)),3!==a&&5!==a&&7!==a&&9!==a||w.push("-");var k=p-16,I=new Uint8Array(k);for(a=0;a0){if(t.pts>=e[r-1].pts)e.push(t);else for(var i=r-1;i>=0;i--)if(t.pts=0)i={data:e.subarray(f,s-u-1),type:n},c.push(i);else{var h=this._getLastNalUnit();if(h&&(d&&s<=4-d&&h.state&&(h.data=h.data.subarray(0,h.data.byteLength-d)),r=s-u-1,r>0)){var g=new Uint8Array(h.data.byteLength+r);g.set(h.data,0),g.set(e.subarray(0,r),h.data.byteLength),h.data=g}}s=0&&u>=0&&(i={data:e.subarray(f,o),type:n,state:u},c.push(i)),0===c.length){var p=this._getLastNalUnit();if(p){var v=new Uint8Array(p.data.byteLength+e.byteLength);v.set(p.data,0),v.set(e,p.data.byteLength),p.data=v}}return l.naluState=u,c},t.discardEPB=function(e){var t,r,i=e.byteLength,a=[],n=1;while(n1&&(o["logger"].log("AAC: align PTS for overlapping frames by "+Math.round((b-g)/90)),g=b)}while(n>24&255,t[1]=i>>16&255,t[2]=i>>8&255,t[3]=255&i,t.set(e,4),a=0,i=8;a>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,85,196,0,0]))},e.mdia=function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))},e.mfhd=function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))},e.minf=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))},e.moof=function(t,r,i){return e.box(e.types.moof,e.mfhd(t),e.traf(i,r))},e.moov=function(t){var r=t.length,i=[];while(r--)i[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(e.mvex(t)))},e.mvex=function(t){var r=t.length,i=[];while(r--)i[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(i))},e.mvhd=function(t,r){r*=t;var i=Math.floor(r/(M+1)),a=Math.floor(r%(M+1)),n=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,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,a>>24,a>>16&255,a>>8&255,255&a,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,n)},e.sdtp=function(t){var r,i,a=t.samples||[],n=new Uint8Array(4+a.length);for(i=0;i>>8&255),n.push(255&a),n=n.concat(Array.prototype.slice.call(i));for(r=0;r>>8&255),s.push(255&a),s=s.concat(Array.prototype.slice.call(i));var o=e.box(e.types.avcC,new Uint8Array([1,n[3],n[4],n[5],255,224|t.sps.length].concat(n).concat([t.pps.length]).concat(s))),l=t.width,u=t.height,d=t.pixelRatio[0],c=t.pixelRatio[1];return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,l>>8&255,255&l,u>>8&255,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),e.box(e.types.pasp,new Uint8Array([d>>24,d>>16&255,d>>8&255,255&d,c>>24,c>>16&255,c>>8&255,255&c])))},e.esds=function(e){var t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))},e.mp4a=function(t){var r=t.samplerate;return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),e.box(e.types.esds,e.esds(t)))},e.mp3=function(t){var r=t.samplerate;return e.box(e.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]))},e.stsd=function(t){return"audio"===t.type?t.isAAC||"mp3"!==t.codec?e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.mp3(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))},e.tkhd=function(t){var r=t.id,i=t.duration*t.timescale,a=t.width,n=t.height,s=Math.floor(i/(M+1)),o=Math.floor(i%(M+1));return e.box(e.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o,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,a>>8&255,255&a,0,0,n>>8&255,255&n,0,0]))},e.traf=function(t,r){var i=e.sdtp(t),a=t.id,n=Math.floor(r/(M+1)),s=Math.floor(r%(M+1));return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a])),e.box(e.types.tfdt,new Uint8Array([1,0,0,0,n>>24,n>>16&255,n>>8&255,255&n,s>>24,s>>16&255,s>>8&255,255&s])),e.trun(t,i.length+16+20+8+16+8+8),i)},e.trak=function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))},e.trex=function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},e.trun=function(t,r){var i,a,n,s,o,l,u=t.samples||[],d=u.length,c=12+16*d,f=new Uint8Array(c);for(r+=8+c,f.set([0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i>>24&255,n>>>16&255,n>>>8&255,255&n,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return e.box(e.types.trun,f)},e.initSegment=function(t){e.types||e.init();var r,i=e.moov(t);return r=new Uint8Array(e.FTYP.byteLength+i.byteLength),r.set(e.FTYP),r.set(i,e.FTYP.byteLength),r},e}(),U=N,B=9e4;function G(e,t,r,i){void 0===r&&(r=1),void 0===i&&(i=!1);var a=e*t*r;return i?Math.round(a):a}function K(e,t){return void 0===t&&(t=!1),G(e,1e3,1/B,t)}function j(e,t){return void 0===t&&(t=1),G(e,B,1/t)}var H,V=j(10),W=j(.2),Y=function(){function e(e,t,r,i){this.observer=e,this.config=t,this.typeSupported=r;var a=navigator.userAgent;this.isSafari=i&&i.indexOf("Apple")>-1&&a&&!a.match("CriOS"),this.ISGenerated=!1}var t=e.prototype;return t.destroy=function(){},t.resetTimeStamp=function(e){this._initPTS=this._initDTS=e},t.resetInitSegment=function(){this.ISGenerated=!1},t.remux=function(e,t,r,a,n,s,l){if(this.ISGenerated||this.generateIS(e,t,n),this.ISGenerated){var u=e.samples.length,d=t.samples.length,c=n,f=n;if(u&&d){var h=(e.samples[0].pts-t.samples[0].pts)/t.inputTimeScale;c+=Math.max(0,h),f+=Math.max(0,-h)}if(u){e.timescale||(o["logger"].warn("regenerate InitSegment as audio detected"),this.generateIS(e,t,n));var g,p=this.remuxAudio(e,c,s,l);if(d)p&&(g=p.endPTS-p.startPTS),t.timescale||(o["logger"].warn("regenerate InitSegment as video detected"),this.generateIS(e,t,n)),this.remuxVideo(t,f,s,g,l)}else if(d){var v=this.remuxVideo(t,f,s,0,l);v&&e.codec&&this.remuxEmptyAudio(e,c,s,v)}}r.samples.length&&this.remuxID3(r,n),a.samples.length&&this.remuxText(a,n),this.observer.trigger(i["default"].FRAG_PARSED)},t.generateIS=function(e,t,r){var n,s,l=this.observer,u=e.samples,d=t.samples,c=this.typeSupported,f="audio/mp4",h={},g={tracks:h},p=void 0===this._initPTS;if(p&&(n=s=1/0),e.config&&u.length&&(e.timescale=e.samplerate,o["logger"].log("audio sampling rate : "+e.samplerate),e.isAAC||(c.mpeg?(f="audio/mpeg",e.codec=""):c.mp3&&(e.codec="mp3")),h.audio={container:f,codec:e.codec,initSegment:!e.isAAC&&c.mpeg?new Uint8Array:U.initSegment([e]),metadata:{channelCount:e.channelCount}},p&&(n=s=u[0].pts-e.inputTimeScale*r)),t.sps&&t.pps&&d.length){var v=t.inputTimeScale;t.timescale=v,h.video={container:"video/mp4",codec:t.codec,initSegment:U.initSegment([t]),metadata:{width:t.width,height:t.height}},p&&(n=Math.min(n,d[0].pts-v*r),s=Math.min(s,d[0].dts-v*r),this.observer.trigger(i["default"].INIT_PTS_FOUND,{initPTS:n}))}Object.keys(h).length?(l.trigger(i["default"].FRAG_PARSING_INIT_SEGMENT,g),this.ISGenerated=!0,p&&(this._initPTS=n,this._initDTS=s)):l.trigger(i["default"].ERROR,{type:a["ErrorTypes"].MEDIA_ERROR,details:a["ErrorDetails"].FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"})},t.remuxVideo=function(e,t,r,n,s){var l,u,d,c,f,h,g,p=8,v=e.timescale,m=e.samples,y=[],E=m.length,T=this._PTSNormalize,S=this._initPTS,b=this.nextAvcDts,_=this.isSafari;if(0!==E){_&&(r|=m.length&&b&&(s&&Math.abs(t-b/v)<.1||Math.abs(m[0].pts-b-S)1?o["logger"].log("AVC: "+K(L,!0)+" ms hole between fragments detected,filling it"):L<-1&&o["logger"].log("AVC: "+K(-L,!0)+" ms overlapping between fragments detected"),f=b,m[0].dts=f,c=Math.max(c-L,b),m[0].pts=c,o["logger"].log("Video: PTS/DTS adjusted: "+K(c,!0)+"/"+K(f,!0)+", delta: "+K(L,!0)+" ms")),D=m[m.length-1],g=Math.max(D.dts,0),h=Math.max(D.pts,0,g),_&&(l=Math.round((g-f)/(m.length-1)));for(var w=0,k=0,I=0;I0?B-1:B].dts;if(J.stretchShortVideoTrack){var Z=J.maxBufferHole,ee=Math.floor(Z*v),te=(n?c+n*v:this.nextAudioPts)-G.pts;te>ee?(l=te-$,l<0&&(l=$),o["logger"].log("It is approximately "+K(te,!1)+" ms to the next segment; using duration "+K(l,!1)+" ms for the last video frame.")):l=$}else l=$}V=Math.round(G.pts-G.dts)}y.push({size:H,duration:l,cts:V,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:G.key?2:1,isNonSync:G.key?0:1}})}this.nextAvcDts=g+l;var re=e.dropped;if(e.nbNalu=0,e.dropped=0,y.length&&navigator.userAgent.toLowerCase().indexOf("chrome")>-1){var ie=y[0].flags;ie.dependsOn=2,ie.isNonSync=0}e.samples=y,d=U.moof(e.sequenceNumber++,f,e),e.samples=[];var ae={data1:d,data2:u,startPTS:c/v,endPTS:(h+l)/v,startDTS:f/v,endDTS:this.nextAvcDts/v,type:"video",hasAudio:!1,hasVideo:!0,nb:y.length,dropped:re};return this.observer.trigger(i["default"].FRAG_PARSING_DATA,ae),ae}},t.remuxAudio=function(e,t,r,n){var s,l,u,d,c,f,h=e.inputTimeScale,g=e.timescale,p=h/g,v=e.isAAC?1024:1152,m=v*p,y=this._PTSNormalize,E=this._initPTS,T=!e.isAAC&&this.typeSupported.mpeg,S=T?0:8,b=e.samples,_=[],A=this.nextAudioPts;if(r|=b.length&&A&&(n&&Math.abs(t-A/h)<.1||Math.abs(b[0].pts-A-E)<20*m),b.forEach((function(e){e.pts=e.dts=y(e.pts-E,t*h)})),b=b.filter((function(e){return e.pts>=0})),0!==b.length){if(r||(A=n?t*h:b[0].pts),e.isAAC)for(var R=this.config.maxAudioFramesDrift,D=0,L=A;D=R*m&&w0&&W0&&(l=F.getSilentFrame(e.manifestCodec||e.codec,e.channelCount),l||(l=j.subarray()),M+=Y*l.length);else if(W<-12){o["logger"].log("drop overlapping AAC sample, expected/parsed/delta: "+K(A,!0)+" ms / "+K(H,!0)+" ms / "+K(-W,!0)+" ms"),M-=j.byteLength;continue}H=A}if(c=H,!(M>0))return;M+=S;try{u=new Uint8Array(M)}catch(ee){return void this.observer.trigger(i["default"].ERROR,{type:a["ErrorTypes"].MUX_ERROR,details:a["ErrorDetails"].REMUX_ALLOC_ERROR,fatal:!1,bytes:M,reason:"fail allocating audio mdat "+M})}if(!T){var q=new DataView(u.buffer);q.setUint32(0,M),u.set(U.types.mdat,4)}for(var z=0;z=2&&(Q=_[x-2].duration,s.duration=Q),x){this.nextAudioPts=A=f+p*Q,e.samples=_,d=T?new Uint8Array:U.moof(e.sequenceNumber++,c/p,e),e.samples=[];var J=c/h,$=A/h,Z={data1:d,data2:u,startPTS:J,endPTS:$,startDTS:J,endDTS:$,type:"audio",hasAudio:!0,hasVideo:!1,nb:x};return this.observer.trigger(i["default"].FRAG_PARSING_DATA,Z),Z}return null}},t.remuxEmptyAudio=function(e,t,r,i){var a=e.inputTimeScale,n=e.samplerate?e.samplerate:a,s=a/n,l=this.nextAudioPts,u=(void 0!==l?l:i.startDTS*a)+this._initDTS,d=i.endDTS*a+this._initDTS,c=1024,f=s*c,h=Math.ceil((d-u)/f),g=F.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);if(o["logger"].warn("remux empty Audio"),g){for(var p=[],v=0;v4294967296)e+=r;return e},e}(),q=Y,z=function(){function e(e){this.observer=e}var t=e.prototype;return t.destroy=function(){},t.resetTimeStamp=function(){},t.resetInitSegment=function(){},t.remux=function(e,t,r,a,n,s,o,l){var u=this.observer,d="";e&&(d+="audio"),t&&(d+="video"),u.trigger(i["default"].FRAG_PARSING_DATA,{data1:l,startPTS:n,startDTS:n,type:d,hasAudio:!!e,hasVideo:!!t,nb:1,dropped:0}),u.trigger(i["default"].FRAG_PARSED)},e}(),X=z,Q=Object(l["getSelfScope"])();try{H=Q.performance.now.bind(Q.performance)}catch($){o["logger"].debug("Unable to use Performance API on this environment"),H=Q.Date.now}var J=function(){function e(e,t,r,i){this.observer=e,this.typeSupported=t,this.config=r,this.vendor=i}var t=e.prototype;return t.destroy=function(){var e=this.demuxer;e&&e.destroy()},t.push=function(e,t,r,a,s,o,l,u,d,c,f,h){var g=this;if(e.byteLength>0&&null!=t&&null!=t.key&&"AES-128"===t.method){var p=this.decrypter;null==p&&(p=this.decrypter=new n["default"](this.observer,this.config));var v=H();p.decrypt(e,t.key.buffer,t.iv.buffer,(function(e){var n=H();g.observer.trigger(i["default"].FRAG_DECRYPTED,{stats:{tstart:v,tdecrypt:n}}),g.pushDecrypted(new Uint8Array(e),t,new Uint8Array(r),a,s,o,l,u,d,c,f,h)}))}else this.pushDecrypted(new Uint8Array(e),t,new Uint8Array(r),a,s,o,l,u,d,c,f,h)},t.pushDecrypted=function(e,t,r,n,s,o,l,u,d,c,f,h){var g=this.demuxer;if(!g||(l||u)&&!this.probe(e)){for(var p=this.observer,v=this.typeSupported,m=this.config,y=[{demux:O,remux:q},{demux:b["default"],remux:X},{demux:S,remux:q},{demux:P,remux:q}],E=0,T=y.length;E1?r-1:0),a=1;a1?r-1:0),a=1;a0)return t.subarray(i,i+a)},e._readSize=function(e,t){var r=0;return r=(127&e[t])<<21,r|=(127&e[t+1])<<14,r|=(127&e[t+2])<<7,r|=127&e[t+3],r},e.getTimeStamp=function(t){for(var r=e.getID3Frames(t),i=0;i>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:d+=String.fromCharCode(n);break;case 12:case 13:o=e[c++],d+=String.fromCharCode((31&n)<<6|63&o);break;case 14:o=e[c++],l=e[c++],d+=String.fromCharCode((15&n)<<12|(63&o)<<6|(63&l)<<0);break;default:}}return d},e}();function s(){var e=Object(a["getSelfScope"])();return i||"undefined"===typeof e.TextDecoder||(i=new e.TextDecoder("utf-8")),i}var o=n._utf8ArrayToStr;t["default"]=n},"./src/demux/mp4demuxer.js": /*!*********************************!*\ !*** ./src/demux/mp4demuxer.js ***! \*********************************/ /*! exports provided: default */function(e,t,r){"use strict";r.r(t);var i=r(/*! ../utils/logger */"./src/utils/logger.js"),a=r(/*! ../events */"./src/events.js"),n=Math.pow(2,32)-1,s=function(){function e(e,t){this.observer=e,this.remuxer=t}var t=e.prototype;return t.resetTimeStamp=function(e){this.initPTS=e},t.resetInitSegment=function(t,r,i,n){if(t&&t.byteLength){var s=this.initData=e.parseInitSegment(t);null==r&&(r="mp4a.40.5"),null==i&&(i="avc1.42e01e");var o={};s.audio&&s.video?o.audiovideo={container:"video/mp4",codec:r+","+i,initSegment:n?t:null}:(s.audio&&(o.audio={container:"audio/mp4",codec:r,initSegment:n?t:null}),s.video&&(o.video={container:"video/mp4",codec:i,initSegment:n?t:null})),this.observer.trigger(a["default"].FRAG_PARSING_INIT_SEGMENT,{tracks:o})}else r&&(this.audioCodec=r),i&&(this.videoCodec=i)},e.probe=function(t){return e.findBox({data:t,start:0,end:Math.min(t.length,16384)},["moof"]).length>0},e.bin2str=function(e){return String.fromCharCode.apply(null,e)},e.readUint16=function(e,t){e.data&&(t+=e.start,e=e.data);var r=e[t]<<8|e[t+1];return r<0?65536+r:r},e.readUint32=function(e,t){e.data&&(t+=e.start,e=e.data);var r=e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3];return r<0?4294967296+r:r},e.writeUint32=function(e,t,r){e.data&&(t+=e.start,e=e.data),e[t]=r>>24,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r},e.findBox=function(t,r){var i,a,n,s,o,l,u,d=[];if(t.data?(l=t.start,s=t.end,t=t.data):(l=0,s=t.byteLength),!r.length)return null;for(i=l;i1?i+a:s,n===r[0]&&(1===r.length?d.push({data:t,start:i+8,end:u}):(o=e.findBox({data:t,start:i+8,end:u},r.slice(1)),o.length&&(d=d.concat(o)))),i=u;return d},e.parseSegmentIndex=function(t){var r,i=e.findBox(t,["moov"])[0],a=i?i.end:null,n=0,s=e.findBox(t,["sidx"]);if(!s||!s[0])return null;r=[],s=s[0];var o=s.data[0];n=0===o?8:16;var l=e.readUint32(s,n);n+=4;var u=0,d=0;n+=0===o?8:16,n+=2;var c=s.end+d,f=e.readUint16(s,n);n+=2;for(var h=0;h>>31;if(1===m)return void console.warn("SIDX has hierarchical references (not supported)");var y=e.readUint32(s,g);g+=4,r.push({referenceSize:v,subsegmentDuration:y,info:{duration:y/l,start:c,end:c+v-1}}),c+=v,g+=4,n=g}return{earliestPresentationTime:u,timescale:l,version:o,referencesCount:f,references:r,moovEndOffset:a}},e.parseInitSegment=function(t){var r=[],a=e.findBox(t,["moov","trak"]);return a.forEach((function(t){var a=e.findBox(t,["tkhd"])[0];if(a){var n=a.data[a.start],s=0===n?12:20,o=e.readUint32(a,s),l=e.findBox(t,["mdia","mdhd"])[0];if(l){n=l.data[l.start],s=0===n?12:20;var u=e.readUint32(l,s),d=e.findBox(t,["mdia","hdlr"])[0];if(d){var c=e.bin2str(d.data.subarray(d.start+8,d.start+12)),f={soun:"audio",vide:"video"}[c];if(f){var h=e.findBox(t,["mdia","minf","stbl","stsd"]);if(h.length){h=h[0];var g=e.bin2str(h.data.subarray(h.start+12,h.start+16));i["logger"].log("MP4Demuxer:"+f+":"+g+" found")}r[o]={timescale:u,type:f},r[f]={timescale:u,id:o}}}}}})),r},e.getStartDTS=function(t,r){var i,a,n;return i=e.findBox(r,["moof","traf"]),a=[].concat.apply([],i.map((function(r){return e.findBox(r,["tfhd"]).map((function(i){var a,n,s;return a=e.readUint32(i,4),n=t[a].timescale||9e4,s=e.findBox(r,["tfdt"]).map((function(t){var r,i;return r=t.data[t.start],i=e.readUint32(t,4),1===r&&(i*=Math.pow(2,32),i+=e.readUint32(t,8)),i}))[0],s/n}))}))),n=Math.min.apply(null,a),isFinite(n)?n:0},e.offsetStartDTS=function(t,r,i){e.findBox(r,["moof","traf"]).map((function(r){return e.findBox(r,["tfhd"]).map((function(a){var s=e.readUint32(a,4),o=t[s].timescale||9e4;e.findBox(r,["tfdt"]).map((function(t){var r=t.data[t.start],a=e.readUint32(t,4);if(0===r)e.writeUint32(t,4,a-i*o);else{a*=Math.pow(2,32),a+=e.readUint32(t,8),a-=i*o,a=Math.max(a,0);var s=Math.floor(a/(n+1)),l=Math.floor(a%(n+1));e.writeUint32(t,4,s),e.writeUint32(t,8,l)}}))}))}))},t.append=function(t,r,i,n){var s=this.initData;s||(this.resetInitSegment(t,this.audioCodec,this.videoCodec,!1),s=this.initData);var o,l=this.initPTS;if(void 0===l){var u=e.getStartDTS(s,t);this.initPTS=l=u-r,this.observer.trigger(a["default"].INIT_PTS_FOUND,{initPTS:l})}e.offsetStartDTS(s,t,l),o=e.getStartDTS(s,t),this.remuxer.remux(s.audio,s.video,null,null,o,i,n,t)},t.destroy=function(){},e}();t["default"]=s},"./src/errors.ts": /*!***********************!*\ !*** ./src/errors.ts ***! \***********************/ /*! exports provided: ErrorTypes, ErrorDetails */function(e,t,r){"use strict";var i,a;r.r(t),r.d(t,"ErrorTypes",(function(){return i})),r.d(t,"ErrorDetails",(function(){return a})),function(e){e["NETWORK_ERROR"]="networkError",e["MEDIA_ERROR"]="mediaError",e["KEY_SYSTEM_ERROR"]="keySystemError",e["MUX_ERROR"]="muxError",e["OTHER_ERROR"]="otherError"}(i||(i={})),function(e){e["KEY_SYSTEM_NO_KEYS"]="keySystemNoKeys",e["KEY_SYSTEM_NO_ACCESS"]="keySystemNoAccess",e["KEY_SYSTEM_NO_SESSION"]="keySystemNoSession",e["KEY_SYSTEM_LICENSE_REQUEST_FAILED"]="keySystemLicenseRequestFailed",e["KEY_SYSTEM_NO_INIT_DATA"]="keySystemNoInitData",e["MANIFEST_LOAD_ERROR"]="manifestLoadError",e["MANIFEST_LOAD_TIMEOUT"]="manifestLoadTimeOut",e["MANIFEST_PARSING_ERROR"]="manifestParsingError",e["MANIFEST_INCOMPATIBLE_CODECS_ERROR"]="manifestIncompatibleCodecsError",e["LEVEL_LOAD_ERROR"]="levelLoadError",e["LEVEL_LOAD_TIMEOUT"]="levelLoadTimeOut",e["LEVEL_SWITCH_ERROR"]="levelSwitchError",e["AUDIO_TRACK_LOAD_ERROR"]="audioTrackLoadError",e["AUDIO_TRACK_LOAD_TIMEOUT"]="audioTrackLoadTimeOut",e["FRAG_LOAD_ERROR"]="fragLoadError",e["FRAG_LOAD_TIMEOUT"]="fragLoadTimeOut",e["FRAG_DECRYPT_ERROR"]="fragDecryptError",e["FRAG_PARSING_ERROR"]="fragParsingError",e["REMUX_ALLOC_ERROR"]="remuxAllocError",e["KEY_LOAD_ERROR"]="keyLoadError",e["KEY_LOAD_TIMEOUT"]="keyLoadTimeOut",e["BUFFER_ADD_CODEC_ERROR"]="bufferAddCodecError",e["BUFFER_APPEND_ERROR"]="bufferAppendError",e["BUFFER_APPENDING_ERROR"]="bufferAppendingError",e["BUFFER_STALLED_ERROR"]="bufferStalledError",e["BUFFER_FULL_ERROR"]="bufferFullError",e["BUFFER_SEEK_OVER_HOLE"]="bufferSeekOverHole",e["BUFFER_NUDGE_ON_STALL"]="bufferNudgeOnStall",e["INTERNAL_EXCEPTION"]="internalException"}(a||(a={}))},"./src/events.js": /*!***********************!*\ !*** ./src/events.js ***! \***********************/ /*! exports provided: default */function(e,t,r){"use strict";r.r(t);var i={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",BUFFER_RESET:"hlsBufferReset",BUFFER_CODECS:"hlsBufferCodecs",BUFFER_CREATED:"hlsBufferCreated",BUFFER_APPENDING:"hlsBufferAppending",BUFFER_APPENDED:"hlsBufferAppended",BUFFER_EOS:"hlsBufferEos",BUFFER_FLUSHING:"hlsBufferFlushing",BUFFER_FLUSHED:"hlsBufferFlushed",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_SWITCHING:"hlsLevelSwitching",LEVEL_SWITCHED:"hlsLevelSwitched",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsLevelPtsUpdated",AUDIO_TRACKS_UPDATED:"hlsAudioTracksUpdated",AUDIO_TRACK_SWITCHING:"hlsAudioTrackSwitching",AUDIO_TRACK_SWITCHED:"hlsAudioTrackSwitched",AUDIO_TRACK_LOADING:"hlsAudioTrackLoading",AUDIO_TRACK_LOADED:"hlsAudioTrackLoaded",SUBTITLE_TRACKS_UPDATED:"hlsSubtitleTracksUpdated",SUBTITLE_TRACK_SWITCH:"hlsSubtitleTrackSwitch",SUBTITLE_TRACK_LOADING:"hlsSubtitleTrackLoading",SUBTITLE_TRACK_LOADED:"hlsSubtitleTrackLoaded",SUBTITLE_FRAG_PROCESSED:"hlsSubtitleFragProcessed",INIT_PTS_FOUND:"hlsInitPtsFound",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_PROGRESS:"hlsFragLoadProgress",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_DECRYPTED:"hlsFragDecrypted",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_USERDATA:"hlsFragParsingUserdata",FRAG_PARSING_METADATA:"hlsFragParsingMetadata",FRAG_PARSING_DATA:"hlsFragParsingData",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFpsDrop",FPS_DROP_LEVEL_CAPPING:"hlsFpsDropLevelCapping",ERROR:"hlsError",DESTROYING:"hlsDestroying",KEY_LOADING:"hlsKeyLoading",KEY_LOADED:"hlsKeyLoaded",STREAM_STATE_TRANSITION:"hlsStreamStateTransition",LIVE_BACK_BUFFER_REACHED:"hlsLiveBackBufferReached"};t["default"]=i},"./src/hls.ts": /*!*********************************!*\ !*** ./src/hls.ts + 50 modules ***! \*********************************/ /*! exports provided: default */ /*! ModuleConcatenation bailout: Cannot concat with ./src/crypt/decrypter.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/demux/demuxer-inline.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/demux/id3.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/demux/mp4demuxer.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/errors.ts because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/events.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/polyfills/number-isFinite.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/utils/get-self-scope.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./src/utils/logger.js because of ./src/demux/demuxer-worker.js */ /*! ModuleConcatenation bailout: Cannot concat with ./node_modules/eventemitter3/index.js (<- Module is not an ECMAScript module) */ /*! ModuleConcatenation bailout: Cannot concat with ./node_modules/url-toolkit/src/url-toolkit.js (<- Module is not an ECMAScript module) */function(e,t,r){"use strict";r.r(t);var i={};r.r(i),r.d(i,"newCue",(function(){return gr}));var a,n,s=r("./node_modules/url-toolkit/src/url-toolkit.js"),o=r("./src/errors.ts"),l=r("./src/polyfills/number-isFinite.js"),u=r("./src/events.js"),d=r("./src/utils/logger.js"),c={hlsEventGeneric:!0,hlsHandlerDestroying:!0,hlsHandlerDestroyed:!0},f=function(){function e(e){this.hls=void 0,this.handledEvents=void 0,this.useGenericHandler=void 0,this.hls=e,this.onEvent=this.onEvent.bind(this);for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i>8*(15-r)&255;return t},t.setDecryptDataFromLevelKey=function(e,t){var r=e;return e&&e.method&&e.uri&&!e.iv&&(r=new y(e.baseuri,e.reluri),r.method=e.method,r.iv=this.createInitializationVector(t)),r},T(e,[{key:"url",get:function(){return!this._url&&this.relurl&&(this._url=Object(s["buildAbsoluteURL"])(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url},set:function(e){this._url=e}},{key:"byteRange",get:function(){return this._byteRange?this._byteRange:[]}},{key:"byteRangeStartOffset",get:function(){return this.byteRange[0]}},{key:"byteRangeEndOffset",get:function(){return this.byteRange[1]}},{key:"decryptdata",get:function(){if(!this.levelkey&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkey){var e=this.sn;"number"!==typeof e&&(this.levelkey&&"AES-128"===this.levelkey.method&&!this.levelkey.iv&&d["logger"].warn('missing IV for initialization segment with method="'+this.levelkey.method+'" - compliance issue'),e=0),this._decryptdata=this.setDecryptDataFromLevelKey(this.levelkey,e)}return this._decryptdata}},{key:"endProgramDateTime",get:function(){if(null===this.programDateTime)return null;if(!Object(l["isFiniteNumber"])(this.programDateTime))return null;var e=Object(l["isFiniteNumber"])(this.duration)?this.duration:0;return this.programDateTime+1e3*e}},{key:"encrypted",get:function(){return!(!this.decryptdata||null===this.decryptdata.uri||null!==this.decryptdata.key)}}]),e}();function b(e,t){for(var r=0;rNumber.MAX_SAFE_INTEGER?1/0:t},t.hexadecimalInteger=function(e){if(this[e]){var t=(this[e]||"0x").slice(2);t=(1&t.length?"0":"")+t;for(var r=new Uint8Array(t.length/2),i=0;iNumber.MAX_SAFE_INTEGER?1/0:t},t.decimalFloatingPoint=function(e){return parseFloat(this[e])},t.enumeratedString=function(e){return this[e]},t.decimalResolution=function(e){var t=R.exec(this[e]);if(null!==t)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}},e.parseAttrList=function(e){var t,r={};D.lastIndex=0;while(null!==(t=D.exec(e))){var i=t[2],a='"';0===i.indexOf(a)&&i.lastIndexOf(a)===i.length-1&&(i=i.slice(1,-1)),r[t[1]]=i}return r},e}(),w=L,k={audio:{a3ds:!0,"ac-3":!0,"ac-4":!0,alac:!0,alaw:!0,dra1:!0,"dts+":!0,"dts-":!0,dtsc:!0,dtse:!0,dtsh:!0,"ec-3":!0,enca:!0,g719:!0,g726:!0,m4ae:!0,mha1:!0,mha2:!0,mhm1:!0,mhm2:!0,mlpa:!0,mp4a:!0,"raw ":!0,Opus:!0,samr:!0,sawb:!0,sawp:!0,sevc:!0,sqcp:!0,ssmv:!0,twos:!0,ulaw:!0},video:{avc1:!0,avc2:!0,avc3:!0,avc4:!0,avcp:!0,drac:!0,dvav:!0,dvhe:!0,encv:!0,hev1:!0,hvc1:!0,mjp2:!0,mp4v:!0,mvc1:!0,mvc2:!0,mvc3:!0,mvc4:!0,resv:!0,rv60:!0,s263:!0,svc1:!0,svc2:!0,"vc-1":!0,vp08:!0,vp09:!0}};function I(e,t){var r=k[t];return!!r&&!0===r[e.slice(0,4)]}function O(e,t){return MediaSource.isTypeSupported((t||"video")+'/mp4;codecs="'+e+'"')}var C=/#EXT-X-STREAM-INF:([^\n\r]*)[\r\n]+([^\r\n]+)/g,P=/#EXT-X-MEDIA:(.*)/g,x=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/|(?!#)([\S+ ?]+)/.source,/|#EXT-X-BYTERANGE:*(.+)/.source,/|#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/|#.*/.source].join(""),"g"),F=/(?:(?:#(EXTM3U))|(?:#EXT-X-(PLAYLIST-TYPE):(.+))|(?:#EXT-X-(MEDIA-SEQUENCE): *(\d+))|(?:#EXT-X-(TARGETDURATION): *(\d+))|(?:#EXT-X-(KEY):(.+))|(?:#EXT-X-(START):(.+))|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DISCONTINUITY-SEQ)UENCE:(\d+))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(VERSION):(\d+))|(?:#EXT-X-(MAP):(.+))|(?:(#)([^:]*):(.*))|(?:(#)(.*))(?:.*)\r?\n?/,M=/\.(mp4|m4s|m4v|m4a)$/i,N=function(){function e(){}return e.findGroup=function(e,t){for(var r=0;r2?(t=r.shift()+".",t+=parseInt(r.shift()).toString(16),t+=("000"+parseInt(r.shift()).toString(16)).substr(-4)):t=e,t},e.resolve=function(e,t){return s["buildAbsoluteURL"](t,e,{alwaysNormalize:!0})},e.parseMasterPlaylist=function(t,r){var i,a=[];function n(e,t){["video","audio"].forEach((function(r){var i=e.filter((function(e){return I(e,r)}));if(i.length){var a=i.filter((function(e){return 0===e.lastIndexOf("avc1",0)||0===e.lastIndexOf("mp4a",0)}));t[r+"Codec"]=a.length>0?a[0]:i[0],e=e.filter((function(e){return-1===i.indexOf(e)}))}})),t.unknownCodecs=e}C.lastIndex=0;while(null!=(i=C.exec(t))){var s={},o=s.attrs=new w(i[1]);s.url=e.resolve(i[2],r);var l=o.decimalResolution("RESOLUTION");l&&(s.width=l.width,s.height=l.height),s.bitrate=o.decimalInteger("AVERAGE-BANDWIDTH")||o.decimalInteger("BANDWIDTH"),s.name=o.NAME,n([].concat((o.CODECS||"").split(/[ ,]+/)),s),s.videoCodec&&-1!==s.videoCodec.indexOf("avc1")&&(s.videoCodec=e.convertAVC1ToAVCOTI(s.videoCodec)),a.push(s)}return a},e.parseMasterPlaylistMedia=function(t,r,i,a){var n;void 0===a&&(a=[]);var s=[],o=0;P.lastIndex=0;while(null!==(n=P.exec(t))){var l=new w(n[1]);if(l.TYPE===i){var u={id:o++,groupId:l["GROUP-ID"],name:l.NAME||l.LANGUAGE,type:i,default:"YES"===l.DEFAULT,autoselect:"YES"===l.AUTOSELECT,forced:"YES"===l.FORCED,lang:l.LANGUAGE};if(l.URI&&(u.url=e.resolve(l.URI,r)),a.length){var d=e.findGroup(a,u.groupId);u.audioCodec=d?d.codec:a[0].codec}s.push(u)}}return s},e.parseLevelPlaylist=function(e,t,r,i,a){var n,s,o,u=0,c=0,f=new A(t),h=0,g=null,p=new S,v=null;x.lastIndex=0;while(null!==(n=x.exec(e))){var m=n[1];if(m){p.duration=parseFloat(m);var E=(" "+n[2]).slice(1);p.title=E||null,p.tagList.push(E?["INF",m,E]:["INF",m])}else if(n[3]){if(Object(l["isFiniteNumber"])(p.duration)){var T=u++;p.type=i,p.start=c,o&&(p.levelkey=o),p.sn=T,p.level=r,p.cc=h,p.urlId=a,p.baseurl=t,p.relurl=(" "+n[3]).slice(1),B(p,g),f.fragments.push(p),g=p,c+=p.duration,p=new S}}else if(n[4]){var b=(" "+n[4]).slice(1);g?p.setByteRange(b,g):p.setByteRange(b)}else if(n[5])p.rawProgramDateTime=(" "+n[5]).slice(1),p.tagList.push(["PROGRAM-DATE-TIME",p.rawProgramDateTime]),null===v&&(v=f.fragments.length);else{if(n=n[0].match(F),!n){d["logger"].warn("No matches on slow regex match for level playlist!");continue}for(s=1;s=0&&(o.method=k,o.key=null,o.iv=O));break;case"START":var C=new w(_),P=C.decimalFloatingPoint("TIME-OFFSET");Object(l["isFiniteNumber"])(P)&&(f.startTimeOffset=P);break;case"MAP":var N=new w(_);p.relurl=N.URI,N.BYTERANGE&&p.setByteRange(N.BYTERANGE),p.baseurl=t,p.level=r,p.type=i,p.sn="initSegment",f.initSegment=p,p=new S,p.rawProgramDateTime=f.initSegment.rawProgramDateTime;break;default:d["logger"].warn("line parsed but not handled: "+n);break}}}return p=g,p&&!p.relurl&&(f.fragments.pop(),c-=p.duration),f.totalduration=c,f.averagetargetduration=c/f.fragments.length,f.endSN=u-1,f.startCC=f.fragments[0]?f.fragments[0].cc:0,f.endCC=h,!f.initSegment&&f.fragments.length&&f.fragments.every((function(e){return M.test(e.relurl)}))&&(d["logger"].warn("MP4 fragments found but no init segment (probably no MAP, incomplete M3U8), trying to fetch SIDX"),p=new S,p.relurl=f.fragments[0].relurl,p.baseurl=t,p.level=r,p.type=i,p.sn="initSegment",f.initSegment=p,f.needSidxRanges=!0),v&&U(f.fragments,v),f},e}();function U(e,t){for(var r=e[t],i=t-1;i>=0;i--){var a=e[i];a.programDateTime=r.programDateTime-1e3*a.duration,r=a}}function B(e,t){e.rawProgramDateTime?e.programDateTime=Date.parse(e.rawProgramDateTime):t&&t.programDateTime&&(e.programDateTime=t.endProgramDateTime),Object(l["isFiniteNumber"])(e.programDateTime)||(e.programDateTime=null,e.rawProgramDateTime=null)}function G(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var K=window,j=K.performance,H=function(e){function t(t){var r;return r=e.call(this,t,u["default"].MANIFEST_LOADING,u["default"].LEVEL_LOADING,u["default"].AUDIO_TRACK_LOADING,u["default"].SUBTITLE_TRACK_LOADING)||this,r.loaders={},r}G(t,e),t.canHaveQualityLevels=function(e){return e!==a.AUDIO_TRACK&&e!==a.SUBTITLE_TRACK},t.mapContextToLevelType=function(e){var t=e.type;switch(t){case a.AUDIO_TRACK:return n.AUDIO;case a.SUBTITLE_TRACK:return n.SUBTITLE;default:return n.MAIN}},t.getResponseUrl=function(e,t){var r=e.url;return void 0!==r&&0!==r.indexOf("data:")||(r=t.url),r};var r=t.prototype;return r.createInternalLoader=function(e){var t=this.hls.config,r=t.pLoader,i=t.loader,a=r||i,n=new a(t);return e.loader=n,this.loaders[e.type]=n,n},r.getInternalLoader=function(e){return this.loaders[e.type]},r.resetInternalLoader=function(e){this.loaders[e]&&delete this.loaders[e]},r.destroyInternalLoaders=function(){for(var e in this.loaders){var t=this.loaders[e];t&&t.destroy(),this.resetInternalLoader(e)}},r.destroy=function(){this.destroyInternalLoaders(),e.prototype.destroy.call(this)},r.onManifestLoading=function(e){this.load({url:e.url,type:a.MANIFEST,level:0,id:null,responseType:"text"})},r.onLevelLoading=function(e){this.load({url:e.url,type:a.LEVEL,level:e.level,id:e.id,responseType:"text"})},r.onAudioTrackLoading=function(e){this.load({url:e.url,type:a.AUDIO_TRACK,level:null,id:e.id,responseType:"text"})},r.onSubtitleTrackLoading=function(e){this.load({url:e.url,type:a.SUBTITLE_TRACK,level:null,id:e.id,responseType:"text"})},r.load=function(e){var t=this.hls.config;d["logger"].debug("Loading playlist of type "+e.type+", level: "+e.level+", id: "+e.id);var r,i,n,s,o=this.getInternalLoader(e);if(o){var l=o.context;if(l&&l.url===e.url)return d["logger"].trace("playlist request ongoing"),!1;d["logger"].warn("aborting previous loader for type: "+e.type),o.abort()}switch(e.type){case a.MANIFEST:r=t.manifestLoadingMaxRetry,i=t.manifestLoadingTimeOut,n=t.manifestLoadingRetryDelay,s=t.manifestLoadingMaxRetryTimeout;break;case a.LEVEL:r=0,s=0,n=0,i=t.levelLoadingTimeOut;break;default:r=t.levelLoadingMaxRetry,i=t.levelLoadingTimeOut,n=t.levelLoadingRetryDelay,s=t.levelLoadingMaxRetryTimeout;break}o=this.createInternalLoader(e);var u={timeout:i,maxRetry:r,retryDelay:n,maxRetryDelay:s},c={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};return d["logger"].debug("Calling internal loader delegate for URL: "+e.url),o.load(e,u,c),!0},r.loadsuccess=function(e,t,r,i){if(void 0===i&&(i=null),r.isSidxRequest)return this._handleSidxRequest(e,r),void this._handlePlaylistLoaded(e,t,r,i);if(this.resetInternalLoader(r.type),"string"!==typeof e.data)throw new Error('expected responseType of "text" for PlaylistLoader');var a=e.data;t.tload=j.now(),0===a.indexOf("#EXTM3U")?a.indexOf("#EXTINF:")>0||a.indexOf("#EXT-X-TARGETDURATION:")>0?this._handleTrackOrLevelPlaylist(e,t,r,i):this._handleMasterPlaylist(e,t,r,i):this._handleManifestParsingError(e,r,"no EXTM3U delimiter",i)},r.loaderror=function(e,t,r){void 0===r&&(r=null),this._handleNetworkError(t,r,!1,e)},r.loadtimeout=function(e,t,r){void 0===r&&(r=null),this._handleNetworkError(t,r,!0)},r._handleMasterPlaylist=function(e,r,i,a){var n=this.hls,s=e.data,o=t.getResponseUrl(e,i),l=N.parseMasterPlaylist(s,o);if(l.length){var c=l.map((function(e){return{id:e.attrs.AUDIO,codec:e.audioCodec}})),f=N.parseMasterPlaylistMedia(s,o,"AUDIO",c),h=N.parseMasterPlaylistMedia(s,o,"SUBTITLES");if(f.length){var g=!1;f.forEach((function(e){e.url||(g=!0)})),!1===g&&l[0].audioCodec&&!l[0].attrs.AUDIO&&(d["logger"].log("audio codec signaled in quality level, but no embedded audio track signaled, create one"),f.unshift({type:"main",name:"main",default:!1,autoselect:!1,forced:!1,id:-1}))}n.trigger(u["default"].MANIFEST_LOADED,{levels:l,audioTracks:f,subtitles:h,url:o,stats:r,networkDetails:a})}else this._handleManifestParsingError(e,i,"no level found in manifest",a)},r._handleTrackOrLevelPlaylist=function(e,r,i,n){var s=this.hls,o=i.id,d=i.level,c=i.type,f=t.getResponseUrl(e,i),h=Object(l["isFiniteNumber"])(o)?o:0,g=Object(l["isFiniteNumber"])(d)?d:h,p=t.mapContextToLevelType(i),v=N.parseLevelPlaylist(e.data,f,g,p,h);if(v.tload=r.tload,c===a.MANIFEST){var m={url:f,details:v};s.trigger(u["default"].MANIFEST_LOADED,{levels:[m],audioTracks:[],url:f,stats:r,networkDetails:n})}if(r.tparsed=j.now(),v.needSidxRanges){var y=v.initSegment.url;this.load({url:y,isSidxRequest:!0,type:c,level:d,levelDetails:v,id:o,rangeStart:0,rangeEnd:2048,responseType:"arraybuffer"})}else i.levelDetails=v,this._handlePlaylistLoaded(e,r,i,n)},r._handleSidxRequest=function(e,t){if("string"===typeof e.data)throw new Error("sidx request must be made with responseType of array buffer");var r=g["default"].parseSegmentIndex(new Uint8Array(e.data));if(r){var i=r.references,a=t.levelDetails;i.forEach((function(e,t){var r=e.info;if(a){var i=a.fragments[t];0===i.byteRange.length&&i.setByteRange(String(1+r.end-r.start)+"@"+String(r.start))}})),a&&a.initSegment.setByteRange(String(r.moovEndOffset)+"@0")}},r._handleManifestParsingError=function(e,t,r,i){this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].NETWORK_ERROR,details:o["ErrorDetails"].MANIFEST_PARSING_ERROR,fatal:!0,url:e.url,reason:r,networkDetails:i})},r._handleNetworkError=function(e,t,r,i){var n,s;void 0===r&&(r=!1),void 0===i&&(i=null),d["logger"].info("A network error occured while loading a "+e.type+"-type playlist");var l=this.getInternalLoader(e);switch(e.type){case a.MANIFEST:n=r?o["ErrorDetails"].MANIFEST_LOAD_TIMEOUT:o["ErrorDetails"].MANIFEST_LOAD_ERROR,s=!0;break;case a.LEVEL:n=r?o["ErrorDetails"].LEVEL_LOAD_TIMEOUT:o["ErrorDetails"].LEVEL_LOAD_ERROR,s=!1;break;case a.AUDIO_TRACK:n=r?o["ErrorDetails"].AUDIO_TRACK_LOAD_TIMEOUT:o["ErrorDetails"].AUDIO_TRACK_LOAD_ERROR,s=!1;break;default:s=!1}l&&(l.abort(),this.resetInternalLoader(e.type));var c={type:o["ErrorTypes"].NETWORK_ERROR,details:n,fatal:s,url:e.url,loader:l,context:e,networkDetails:t};i&&(c.response=i),this.hls.trigger(u["default"].ERROR,c)},r._handlePlaylistLoaded=function(e,r,i,n){var s=i.type,o=i.level,l=i.id,d=i.levelDetails;if(d&&d.targetduration){var c=t.canHaveQualityLevels(i.type);if(c)this.hls.trigger(u["default"].LEVEL_LOADED,{details:d,level:o||0,id:l||0,stats:r,networkDetails:n});else switch(s){case a.AUDIO_TRACK:this.hls.trigger(u["default"].AUDIO_TRACK_LOADED,{details:d,id:l,stats:r,networkDetails:n});break;case a.SUBTITLE_TRACK:this.hls.trigger(u["default"].SUBTITLE_TRACK_LOADED,{details:d,id:l,stats:r,networkDetails:n});break}}else this._handleManifestParsingError(e,i,"invalid target duration",n)},t}(h),V=H;function W(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var Y=function(e){function t(t){var r;return r=e.call(this,t,u["default"].FRAG_LOADING)||this,r.loaders={},r}W(t,e);var r=t.prototype;return r.destroy=function(){var t=this.loaders;for(var r in t){var i=t[r];i&&i.destroy()}this.loaders={},e.prototype.destroy.call(this)},r.onFragLoading=function(e){var t=e.frag,r=t.type,i=this.loaders,a=this.hls.config,n=a.fLoader,s=a.loader;t.loaded=0;var o,u,c,f=i[r];f&&(d["logger"].warn("abort previous fragment loader for type: "+r),f.abort()),f=i[r]=t.loader=a.fLoader?new n(a):new s(a),o={url:t.url,frag:t,responseType:"arraybuffer",progressData:!1};var h=t.byteRangeStartOffset,g=t.byteRangeEndOffset;Object(l["isFiniteNumber"])(h)&&Object(l["isFiniteNumber"])(g)&&(o.rangeStart=h,o.rangeEnd=g),u={timeout:a.fragLoadingTimeOut,maxRetry:0,retryDelay:0,maxRetryDelay:a.fragLoadingMaxRetryTimeout},c={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this),onProgress:this.loadprogress.bind(this)},f.load(o,u,c)},r.loadsuccess=function(e,t,r,i){void 0===i&&(i=null);var a=e.data,n=r.frag;n.loader=void 0,this.loaders[n.type]=void 0,this.hls.trigger(u["default"].FRAG_LOADED,{payload:a,frag:n,stats:t,networkDetails:i})},r.loaderror=function(e,t,r){void 0===r&&(r=null);var i=t.frag,a=i.loader;a&&a.abort(),this.loaders[i.type]=void 0,this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].NETWORK_ERROR,details:o["ErrorDetails"].FRAG_LOAD_ERROR,fatal:!1,frag:t.frag,response:e,networkDetails:r})},r.loadtimeout=function(e,t,r){void 0===r&&(r=null);var i=t.frag,a=i.loader;a&&a.abort(),this.loaders[i.type]=void 0,this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].NETWORK_ERROR,details:o["ErrorDetails"].FRAG_LOAD_TIMEOUT,fatal:!1,frag:t.frag,networkDetails:r})},r.loadprogress=function(e,t,r,i){void 0===i&&(i=null);var a=t.frag;a.loaded=e.loaded,this.hls.trigger(u["default"].FRAG_LOAD_PROGRESS,{frag:a,stats:e,networkDetails:i})},t}(h),q=Y;function z(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var X=function(e){function t(t){var r;return r=e.call(this,t,u["default"].KEY_LOADING)||this,r.loaders={},r.decryptkey=null,r.decrypturl=null,r}z(t,e);var r=t.prototype;return r.destroy=function(){for(var t in this.loaders){var r=this.loaders[t];r&&r.destroy()}this.loaders={},e.prototype.destroy.call(this)},r.onKeyLoading=function(e){var t=e.frag,r=t.type,i=this.loaders[r];if(t.decryptdata){var a=t.decryptdata.uri;if(a!==this.decrypturl||null===this.decryptkey){var n=this.hls.config;if(i&&(d["logger"].warn("abort previous key loader for type:"+r),i.abort()),!a)return void d["logger"].warn("key uri is falsy");t.loader=this.loaders[r]=new n.loader(n),this.decrypturl=a,this.decryptkey=null;var s={url:a,frag:t,responseType:"arraybuffer"},o={timeout:n.fragLoadingTimeOut,maxRetry:0,retryDelay:n.fragLoadingRetryDelay,maxRetryDelay:n.fragLoadingMaxRetryTimeout},l={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};t.loader.load(s,o,l)}else this.decryptkey&&(t.decryptdata.key=this.decryptkey,this.hls.trigger(u["default"].KEY_LOADED,{frag:t}))}else d["logger"].warn("Missing decryption data on fragment in onKeyLoading")},r.loadsuccess=function(e,t,r){var i=r.frag;i.decryptdata?(this.decryptkey=i.decryptdata.key=new Uint8Array(e.data),i.loader=void 0,delete this.loaders[i.type],this.hls.trigger(u["default"].KEY_LOADED,{frag:i})):d["logger"].error("after key load, decryptdata unset")},r.loaderror=function(e,t){var r=t.frag,i=r.loader;i&&i.abort(),delete this.loaders[r.type],this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].NETWORK_ERROR,details:o["ErrorDetails"].KEY_LOAD_ERROR,fatal:!1,frag:r,response:e})},r.loadtimeout=function(e,t){var r=t.frag,i=r.loader;i&&i.abort(),delete this.loaders[r.type],this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].NETWORK_ERROR,details:o["ErrorDetails"].KEY_LOAD_TIMEOUT,fatal:!1,frag:r})},t}(h),Q=X;function J(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var $={NOT_LOADED:"NOT_LOADED",APPENDING:"APPENDING",PARTIAL:"PARTIAL",OK:"OK"},Z=function(e){function t(t){var r;return r=e.call(this,t,u["default"].BUFFER_APPENDED,u["default"].FRAG_BUFFERED,u["default"].FRAG_LOADED)||this,r.bufferPadding=.2,r.fragments=Object.create(null),r.timeRanges=Object.create(null),r.config=t.config,r}J(t,e);var r=t.prototype;return r.destroy=function(){this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.config=null,h.prototype.destroy.call(this),e.prototype.destroy.call(this)},r.getBufferedFrag=function(e,t){var r=this.fragments,i=Object.keys(r).filter((function(i){var a=r[i];if(a.body.type!==t)return!1;if(!a.buffered)return!1;var n=a.body;return n.startPTS<=e&&e<=n.endPTS}));if(0===i.length)return null;var a=i.pop();return r[a].body},r.detectEvictedFragments=function(e,t){var r,i,a=this;Object.keys(this.fragments).forEach((function(n){var s=a.fragments[n];if(!0===s.buffered){var o=s.range[e];if(o){r=o.time;for(var l=0;l=i&&t<=a){n.push({startPTS:Math.max(e,r.start(o)),endPTS:Math.min(t,r.end(o))});break}if(ei)n.push({startPTS:Math.max(e,r.start(o)),endPTS:Math.min(t,r.end(o))}),s=!0;else if(t<=i)break}return{time:n,partial:s}},r.getFragmentKey=function(e){return e.type+"_"+e.level+"_"+e.urlId+"_"+e.sn},r.getPartialFragment=function(e){var t,r,i,a=this,n=null,s=0;return Object.keys(this.fragments).forEach((function(o){var l=a.fragments[o];a.isPartial(l)&&(r=l.body.startPTS-a.bufferPadding,i=l.body.endPTS+a.bufferPadding,e>=r&&e<=i&&(t=Math.min(e-r,i-e),s<=t&&(n=l.body,s=t)))})),n},r.getState=function(e){var t=this.getFragmentKey(e),r=this.fragments[t],i=$.NOT_LOADED;return void 0!==r&&(i=r.buffered?!0===this.isPartial(r)?$.PARTIAL:$.OK:$.APPENDING),i},r.isPartial=function(e){return!0===e.buffered&&(void 0!==e.range.video&&!0===e.range.video.partial||void 0!==e.range.audio&&!0===e.range.audio.partial)},r.isTimeBuffered=function(e,t,r){for(var i,a,n=0;n=i&&t<=a)return!0;if(t<=i)return!1}return!1},r.onFragLoaded=function(e){var t=e.frag;Object(l["isFiniteNumber"])(t.sn)&&!t.bitrateTest&&(this.fragments[this.getFragmentKey(t)]={body:t,range:Object.create(null),buffered:!1})},r.onBufferAppended=function(e){var t=this;this.timeRanges=e.timeRanges,Object.keys(this.timeRanges).forEach((function(e){var r=t.timeRanges[e];t.detectEvictedFragments(e,r)}))},r.onFragBuffered=function(e){this.detectPartialFragments(e.frag)},r.hasFragment=function(e){var t=this.getFragmentKey(e);return void 0!==this.fragments[t]},r.removeFragment=function(e){var t=this.getFragmentKey(e);delete this.fragments[t]},r.removeAllFragments=function(){this.fragments=Object.create(null)},t}(h),ee={search:function(e,t){var r=0,i=e.length-1,a=null,n=null;while(r<=i){a=(r+i)/2|0,n=e[a];var s=t(n);if(s>0)r=a+1;else{if(!(s<0))return n;i=a-1}}return null}},te=ee,re=function(){function e(){}return e.isBuffered=function(e,t){try{if(e)for(var r=e.buffered,i=0;i=r.start(i)&&t<=r.end(i))return!0}catch(a){}return!1},e.bufferInfo=function(e,t,r){try{if(e){var i,a=e.buffered,n=[];for(i=0;is&&(i[n-1].end=e[a].end):i.push(e[a])}else i.push(e[a])}else i=e;for(var o,l=0,u=t,d=t,c=0;c=f&&t1?t-1:0),i=1;it?(i.duration=n-i.start,i.duration<0&&d["logger"].warn("negative duration computed for frag "+i.sn+",level "+i.level+", there should be some duration drift between playlist and fragment!")):(a.duration=i.start-n,a.duration<0&&d["logger"].warn("negative duration computed for frag "+a.sn+",level "+a.level+", there should be some duration drift between playlist and fragment!")):a.start=r>t?i.start+i.duration:Math.max(i.start-a.duration,0)}function ve(e,t,r,i,a,n){var s=r;if(Object(l["isFiniteNumber"])(t.startPTS)){var o=Math.abs(t.startPTS-r);Object(l["isFiniteNumber"])(t.deltaPTS)?t.deltaPTS=Math.max(o,t.deltaPTS):t.deltaPTS=o,s=Math.max(r,t.startPTS),r=Math.min(r,t.startPTS),i=Math.max(i,t.endPTS),a=Math.min(a,t.startDTS),n=Math.max(n,t.endDTS)}var u=r-t.start;t.start=t.startPTS=r,t.maxStartPTS=s,t.endPTS=i,t.startDTS=a,t.endDTS=n,t.duration=i-r;var d,c,f,h=t.sn;if(!e||he.endSN)return 0;for(d=h-e.startSN,c=e.fragments,c[d]=t,f=d;f>0;f--)pe(c,f,f-1);for(f=d;fi.length))for(var n=0;nt?-1:0}))}function De(e,t,r){var i=!1;return t&&t.details&&r&&(r.endCC>r.startCC||e&&e.cc=(a||0))return null;r=r||0;for(var n=0;ne&&r.start?-1:0}function Fe(e,t,r){var i=1e3*Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0)),a=r.endProgramDateTime||0;return a-i>e}var Me=250,Ne=2,Ue=.1,Be=.05,Ge=function(){function e(e,t,r,i){this.config=e,this.media=t,this.fragmentTracker=r,this.hls=i,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1}var t=e.prototype;return t.poll=function(e){var t=this.config,r=this.media,i=this.stalled,a=r.currentTime,n=r.seeking,s=this.seeking&&!n,o=!this.seeking&&n;if(this.seeking=n,a===e){if((o||s)&&(this.stalled=null),!r.paused&&!r.ended&&0!==r.playbackRate&&r.buffered.length){var l=re.bufferInfo(r,a,0),u=l.len>0,c=l.nextStart||0;if(u||c){if(n){var f=l.len>Ne,h=!c||c-a>Ne;if(f||h)return;this.moved=!1}if(!this.moved&&this.stalled){var g=Math.max(c,l.start||0)-a;if(g>0&&g<=Ne)return void this._trySkipBufferHole(null)}var p=self.performance.now();if(null!==i){var v=p-i;!n&&v>=Me&&this._reportStall(l.len);var m=re.bufferInfo(r,a,t.maxBufferHole);this._tryFixBufferStall(m,v)}else this.stalled=p}}}else if(this.moved=!0,null!==i){if(this.stallReported){var y=self.performance.now()-i;d["logger"].warn("playback not stuck anymore @"+a+", after "+Math.round(y)+"ms"),this.stallReported=!1}this.stalled=null,this.nudgeRetry=0}},t._tryFixBufferStall=function(e,t){var r=this.config,i=this.fragmentTracker,a=this.media,n=a.currentTime,s=i.getPartialFragment(n);if(s){var o=this._trySkipBufferHole(s);if(o)return}e.len>r.maxBufferHole&&t>1e3*r.highBufferWatchdogPeriod&&(d["logger"].warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())},t._reportStall=function(e){var t=this.hls,r=this.media,i=this.stallReported;i||(this.stallReported=!0,d["logger"].warn("Playback stalling at @"+r.currentTime+" due to low buffer"),t.trigger(u["default"].ERROR,{type:o["ErrorTypes"].MEDIA_ERROR,details:o["ErrorDetails"].BUFFER_STALLED_ERROR,fatal:!1,buffer:e}))},t._trySkipBufferHole=function(e){for(var t=this.config,r=this.hls,i=this.media,a=i.currentTime,n=0,s=0;s=n&&a1?i-1:0),n=1;n1&&(this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)),this._tickCallCount=0)},r.doTick=function(){},t}(h);function Ve(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var We={STOPPED:"STOPPED",STARTING:"STARTING",IDLE:"IDLE",PAUSED:"PAUSED",KEY_LOADING:"KEY_LOADING",FRAG_LOADING:"FRAG_LOADING",FRAG_LOADING_WAITING_RETRY:"FRAG_LOADING_WAITING_RETRY",WAITING_TRACK:"WAITING_TRACK",PARSING:"PARSING",PARSED:"PARSED",BUFFER_FLUSHING:"BUFFER_FLUSHING",ENDED:"ENDED",ERROR:"ERROR",WAITING_INIT_PTS:"WAITING_INIT_PTS",WAITING_LEVEL:"WAITING_LEVEL"},Ye=function(e){function t(){return e.apply(this,arguments)||this}Ve(t,e);var r=t.prototype;return r.doTick=function(){},r.startLoad=function(){},r.stopLoad=function(){var e=this.fragCurrent;e&&(e.loader&&e.loader.abort(),this.fragmentTracker.removeFragment(e)),this.demuxer&&(this.demuxer.destroy(),this.demuxer=null),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=We.STOPPED},r._streamEnded=function(e,t){var r=this.fragCurrent,i=this.fragmentTracker;if(!t.live&&r&&!r.backtracked&&r.sn===t.endSN&&!e.nextStart){var a=i.getState(r);return a===$.PARTIAL||a===$.OK}return!1},r.onMediaSeeking=function(){var e=this.config,t=this.media,r=this.mediaBuffer,i=this.state,a=t?t.currentTime:null,n=re.bufferInfo(r||t,a,this.config.maxBufferHole);if(Object(l["isFiniteNumber"])(a)&&d["logger"].log("media seeking to "+a.toFixed(3)),i===We.FRAG_LOADING){var s=this.fragCurrent;if(0===n.len&&s){var o=e.maxFragLookUpTolerance,u=s.start-o,c=s.start+s.duration+o;ac?(s.loader&&(d["logger"].log("seeking outside of buffer while fragment load in progress, cancel fragment load"),s.loader.abort()),this.fragCurrent=null,this.fragPrevious=null,this.state=We.IDLE):d["logger"].log("seeking outside of buffer but within currently loaded fragment range")}}else i===We.ENDED&&(0===n.len&&(this.fragPrevious=null,this.fragCurrent=null),this.state=We.IDLE);t&&(this.lastCurrentTime=a),this.loadedmetadata||(this.nextLoadPosition=this.startPosition=a),this.tick()},r.onMediaEnded=function(){this.startPosition=this.lastCurrentTime=0},r.onHandlerDestroying=function(){this.stopLoad(),e.prototype.onHandlerDestroying.call(this)},r.onHandlerDestroyed=function(){this.state=We.STOPPED,this.fragmentTracker=null},r.computeLivePosition=function(e,t){var r=void 0!==this.config.liveSyncDuration?this.config.liveSyncDuration:this.config.liveSyncDurationCount*t.targetduration;return e+Math.max(0,t.totalduration-r)},t}(He);function qe(e,t){for(var r=0;r0&&-1===e&&(d["logger"].log("override startPosition with lastCurrentTime @"+t.toFixed(3)),e=t),this.state=We.IDLE,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}else this.forceStartLoad=!0,this.state=We.STOPPED},r.stopLoad=function(){this.forceStartLoad=!1,e.prototype.stopLoad.call(this)},r.doTick=function(){switch(this.state){case We.BUFFER_FLUSHING:this.fragLoadError=0;break;case We.IDLE:this._doTickIdle();break;case We.WAITING_LEVEL:var e=this.levels[this.level];e&&e.details&&(this.state=We.IDLE);break;case We.FRAG_LOADING_WAITING_RETRY:var t=window.performance.now(),r=this.retryDate;(!r||t>=r||this.media&&this.media.seeking)&&(d["logger"].log("mediaController: retryDate reached, switch back to IDLE state"),this.state=We.IDLE);break;case We.ERROR:case We.STOPPED:case We.FRAG_LOADING:case We.PARSING:case We.PARSED:case We.ENDED:break;default:break}this._checkBuffer(),this._checkFragmentChanged()},r._doTickIdle=function(){var e=this.hls,t=e.config,r=this.media;if(void 0!==this.levelLastLoaded&&(r||!this.startFragRequested&&t.startFragPrefetch)){var i;i=this.loadedmetadata?r.currentTime:this.nextLoadPosition;var a=e.nextLoadLevel,n=this.levels[a];if(n){var s,o=n.bitrate;s=o?Math.max(8*t.maxBufferSize/o,t.maxBufferLength):t.maxBufferLength,s=Math.min(s,t.maxMaxBufferLength);var l=re.bufferInfo(this.mediaBuffer?this.mediaBuffer:r,i,t.maxBufferHole),c=l.len;if(!(c>=s)){d["logger"].trace("buffer length of "+c.toFixed(3)+" is below max of "+s.toFixed(3)+". checking for more payload ..."),this.level=e.nextLoadLevel=a;var f=n.details;if(!f||f.live&&this.levelLastLoaded!==a)this.state=We.WAITING_LEVEL;else{if(this._streamEnded(l,f)){var h={};return this.altAudio&&(h.type="video"),this.hls.trigger(u["default"].BUFFER_EOS,h),void(this.state=We.ENDED)}this._fetchPayloadOrEos(i,l,f)}}}}},r._fetchPayloadOrEos=function(e,t,r){var i=this.fragPrevious,a=this.level,n=r.fragments,s=n.length;if(0!==s){var o,l=n[0].start,u=n[s-1].start+n[s-1].duration,c=t.end;if(r.initSegment&&!r.initSegment.data)o=r.initSegment;else if(r.live){var f=this.config.initialLiveManifestSize;if(sf&&f>u.currentTime&&(d["logger"].log("buffer end: "+t.toFixed(3)+" is located too far from the end of live sliding playlist, reset currentTime to : "+f.toFixed(3)),u.currentTime=f),this.nextLoadPosition=f}if(e.PTSKnown&&t>i&&u&&u.readyState)return null;if(this.startFragRequested&&!e.PTSKnown){if(a)if(e.hasProgramDateTime)d["logger"].log("live playlist, switching playlist, load frag with same PDT: "+a.programDateTime),o=Ce(n,a.endProgramDateTime,l.maxFragLookUpTolerance);else{var h=a.sn+1;if(h>=e.startSN&&h<=e.endSN){var g=n[h-e.startSN];a.cc===g.cc&&(o=g,d["logger"].log("live playlist, switching playlist, load frag with next SN: "+o.sn))}o||(o=te.search(n,(function(e){return a.cc-e.cc})),o&&d["logger"].log("live playlist, switching playlist, load frag with same CC: "+o.sn))}o||(o=n[Math.min(s-1,Math.round(s/2))],d["logger"].log("live playlist, switching playlist, unknown, load middle frag : "+o.sn))}return o},r._findFragment=function(e,t,r,i,a,n,s){var o,l=this.hls.config;if(an-l.maxFragLookUpTolerance?0:l.maxFragLookUpTolerance;o=Pe(t,i,a,u)}else o=i[r-1];if(o){var c=o.sn-s.startSN,f=t&&o.level===t.level,h=i[c-1],g=i[c+1];if(t&&o.sn===t.sn)if(f&&!o.backtracked)if(o.snl.maxBufferHole&&t.dropped&&c?(o=h,d["logger"].warn("Previous fragment was dropped with large PTS gap between audio and video. Maybe fragment is not starting with a keyframe? Loading previous one to try to overcome this")):(o=g,d["logger"].log("Re-loading fragment with SN: "+o.sn))}else o=null;else o.backtracked&&(g&&g.backtracked?(d["logger"].warn("Already backtracked from fragment "+g.sn+", will not backtrack to fragment "+o.sn+". Loading fragment "+g.sn),o=g):(d["logger"].warn("Loaded fragment with dropped frames, backtracking 1 segment to find a keyframe"),o.dropped=0,h?(o=h,o.backtracked=!0):c&&(o=null)))}return o},r._loadKey=function(e){this.state=We.KEY_LOADING,this.hls.trigger(u["default"].KEY_LOADING,{frag:e})},r._loadFragment=function(e){var t=this.fragmentTracker.getState(e);this.fragCurrent=e,"initSegment"!==e.sn&&(this.startFragRequested=!0),Object(l["isFiniteNumber"])(e.sn)&&!e.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),e.backtracked||t===$.NOT_LOADED||t===$.PARTIAL?(e.autoLevel=this.hls.autoLevelEnabled,e.bitrateTest=this.bitrateTest,this.hls.trigger(u["default"].FRAG_LOADING,{frag:e}),this.demuxer||(this.demuxer=new he(this.hls,"main")),this.state=We.FRAG_LOADING):t===$.APPENDING&&this._reduceMaxBufferLength(e.duration)&&this.fragmentTracker.removeFragment(e)},r.getBufferedFrag=function(e){return this.fragmentTracker.getBufferedFrag(e,n.MAIN)},r.followingBufferedFrag=function(e){return e?this.getBufferedFrag(e.endPTS+.5):null},r._checkFragmentChanged=function(){var e,t,r=this.media;if(r&&r.readyState&&!1===r.seeking&&(t=r.currentTime,t>this.lastCurrentTime&&(this.lastCurrentTime=t),re.isBuffered(r,t)?e=this.getBufferedFrag(t):re.isBuffered(r,t+.1)&&(e=this.getBufferedFrag(t+.1)),e)){var i=e;if(i!==this.fragPlaying){this.hls.trigger(u["default"].FRAG_CHANGED,{frag:i});var a=i.level;this.fragPlaying&&this.fragPlaying.level===a||this.hls.trigger(u["default"].LEVEL_SWITCHED,{level:a}),this.fragPlaying=i}}},r.immediateLevelSwitch=function(){if(d["logger"].log("immediateLevelSwitch"),!this.immediateSwitch){this.immediateSwitch=!0;var e,t=this.media;t?(e=t.paused,t.pause()):e=!0,this.previouslyPaused=e}var r=this.fragCurrent;r&&r.loader&&r.loader.abort(),this.fragCurrent=null,this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},r.immediateLevelSwitchEnd=function(){var e=this.media;e&&e.buffered.length&&(this.immediateSwitch=!1,re.isBuffered(e,e.currentTime)&&(e.currentTime-=1e-4),this.previouslyPaused||e.play())},r.nextLevelSwitch=function(){var e=this.media;if(e&&e.readyState){var t,r,i;if(r=this.getBufferedFrag(e.currentTime),r&&r.startPTS>1&&this.flushMainBuffer(0,r.startPTS-1),e.paused)t=0;else{var a=this.hls.nextLoadLevel,n=this.levels[a],s=this.fragLastKbps;t=s&&this.fragCurrent?this.fragCurrent.duration*n.bitrate/(1e3*s)+1:0}if(i=this.getBufferedFrag(e.currentTime+t),i&&(i=this.followingBufferedFrag(i),i)){var o=this.fragCurrent;o&&o.loader&&o.loader.abort(),this.fragCurrent=null,this.flushMainBuffer(i.maxStartPTS,Number.POSITIVE_INFINITY)}}},r.flushMainBuffer=function(e,t){this.state=We.BUFFER_FLUSHING;var r={startOffset:e,endOffset:t};this.altAudio&&(r.type="video"),this.hls.trigger(u["default"].BUFFER_FLUSHING,r)},r.onMediaAttached=function(e){var t=this.media=this.mediaBuffer=e.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),this.onvended=this.onMediaEnded.bind(this),t.addEventListener("seeking",this.onvseeking),t.addEventListener("seeked",this.onvseeked),t.addEventListener("ended",this.onvended);var r=this.config;this.levels&&r.autoStartLoad&&this.hls.startLoad(r.startPosition),this.gapController=new Ge(r,t,this.fragmentTracker,this.hls)},r.onMediaDetaching=function(){var e=this.media;e&&e.ended&&(d["logger"].log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0);var t=this.levels;t&&t.forEach((function(e){e.details&&e.details.fragments.forEach((function(e){e.backtracked=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.fragmentTracker.removeAllFragments(),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.stopLoad()},r.onMediaSeeked=function(){var e=this.media,t=e?e.currentTime:void 0;Object(l["isFiniteNumber"])(t)&&d["logger"].log("media seeked to "+t.toFixed(3)),this.tick()},r.onManifestLoading=function(){d["logger"].log("trigger BUFFER_RESET"),this.hls.trigger(u["default"].BUFFER_RESET),this.fragmentTracker.removeAllFragments(),this.stalled=!1,this.startPosition=this.lastCurrentTime=0},r.onManifestParsed=function(e){var t,r=!1,i=!1;e.levels.forEach((function(e){t=e.audioCodec,t&&(-1!==t.indexOf("mp4a.40.2")&&(r=!0),-1!==t.indexOf("mp4a.40.5")&&(i=!0))})),this.audioCodecSwitch=r&&i,this.audioCodecSwitch&&d["logger"].log("both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.altAudio=e.altAudio,this.levels=e.levels,this.startFragRequested=!1;var a=this.config;(a.autoStartLoad||this.forceStartLoad)&&this.hls.startLoad(a.startPosition)},r.onLevelLoaded=function(e){var t=e.details,r=e.level,i=this.levels[this.levelLastLoaded],a=this.levels[r],n=t.totalduration,s=0;if(d["logger"].log("level "+r+" loaded ["+t.startSN+","+t.endSN+"],duration:"+n),t.live){var o=a.details;o&&t.fragments.length>0?(me(o,t),s=t.fragments[0].start,this.liveSyncPosition=this.computeLivePosition(s,o),t.PTSKnown&&Object(l["isFiniteNumber"])(s)?d["logger"].log("live playlist sliding:"+s.toFixed(3)):(d["logger"].log("live playlist - outdated PTS, unknown sliding"),ke(this.fragPrevious,i,t))):(d["logger"].log("live playlist - first load, unknown sliding"),t.PTSKnown=!1,ke(this.fragPrevious,i,t))}else t.PTSKnown=!1;if(a.details=t,this.levelLastLoaded=r,this.hls.trigger(u["default"].LEVEL_UPDATED,{details:t,level:r}),!1===this.startFragRequested){if(-1===this.startPosition||-1===this.lastCurrentTime){var c=t.startTimeOffset;Object(l["isFiniteNumber"])(c)?(c<0&&(d["logger"].log("negative start time offset "+c+", count from end of last fragment"),c=s+n+c),d["logger"].log("start time offset found in playlist, adjust startPosition to "+c),this.startPosition=c):t.live?(this.startPosition=this.computeLivePosition(s,t),d["logger"].log("configure startPosition to "+this.startPosition)):this.startPosition=0,this.lastCurrentTime=this.startPosition}this.nextLoadPosition=this.startPosition}this.state===We.WAITING_LEVEL&&(this.state=We.IDLE),this.tick()},r.onKeyLoaded=function(){this.state===We.KEY_LOADING&&(this.state=We.IDLE,this.tick())},r.onFragLoaded=function(e){var t=this.fragCurrent,r=this.hls,i=this.levels,a=this.media,n=e.frag;if(this.state===We.FRAG_LOADING&&t&&"main"===n.type&&n.level===t.level&&n.sn===t.sn){var s=e.stats,o=i[t.level],l=o.details;if(this.bitrateTest=!1,this.stats=s,d["logger"].log("Loaded "+t.sn+" of ["+l.startSN+" ,"+l.endSN+"],level "+t.level),n.bitrateTest&&r.nextLoadLevel)this.state=We.IDLE,this.startFragRequested=!1,s.tparsed=s.tbuffered=window.performance.now(),r.trigger(u["default"].FRAG_BUFFERED,{stats:s,frag:t,id:"main"}),this.tick();else if("initSegment"===n.sn)this.state=We.IDLE,s.tparsed=s.tbuffered=window.performance.now(),l.initSegment.data=e.payload,r.trigger(u["default"].FRAG_BUFFERED,{stats:s,frag:t,id:"main"}),this.tick();else{d["logger"].log("Parsing "+t.sn+" of ["+l.startSN+" ,"+l.endSN+"],level "+t.level+", cc "+t.cc),this.state=We.PARSING,this.pendingBuffering=!0,this.appended=!1,n.bitrateTest&&(n.bitrateTest=!1,this.fragmentTracker.onFragLoaded({frag:n}));var c=!(a&&a.seeking)&&(l.PTSKnown||!l.live),f=l.initSegment?l.initSegment.data:[],h=this._getAudioCodec(o),g=this.demuxer=this.demuxer||new he(this.hls,"main");g.push(e.payload,f,h,o.videoCodec,t,l.totalduration,c)}}this.fragLoadError=0},r.onFragParsingInitSegment=function(e){var t=this.fragCurrent,r=e.frag;if(t&&"main"===e.id&&r.sn===t.sn&&r.level===t.level&&this.state===We.PARSING){var i,a,n=e.tracks;if(n.audio&&this.altAudio&&delete n.audio,a=n.audio,a){var s=this.levels[this.level].audioCodec,o=navigator.userAgent.toLowerCase();s&&this.audioCodecSwap&&(d["logger"].log("swapping playlist audio codec"),s=-1!==s.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),this.audioCodecSwitch&&1!==a.metadata.channelCount&&-1===o.indexOf("firefox")&&(s="mp4a.40.5"),-1!==o.indexOf("android")&&"audio/mpeg"!==a.container&&(s="mp4a.40.2",d["logger"].log("Android: force audio codec to "+s)),a.levelCodec=s,a.id=e.id}for(i in a=n.video,a&&(a.levelCodec=this.levels[this.level].videoCodec,a.id=e.id),this.hls.trigger(u["default"].BUFFER_CODECS,n),n){a=n[i],d["logger"].log("main track:"+i+",container:"+a.container+",codecs[level/parsed]=["+a.levelCodec+"/"+a.codec+"]");var l=a.initSegment;l&&(this.appended=!0,this.pendingBuffering=!0,this.hls.trigger(u["default"].BUFFER_APPENDING,{type:i,data:l,parent:"main",content:"initSegment"}))}this.tick()}},r.onFragParsingData=function(e){var t=this,r=this.fragCurrent,i=e.frag;if(r&&"main"===e.id&&i.sn===r.sn&&i.level===r.level&&("audio"!==e.type||!this.altAudio)&&this.state===We.PARSING){var a=this.levels[this.level],n=r;if(Object(l["isFiniteNumber"])(e.endPTS)||(e.endPTS=e.startPTS+r.duration,e.endDTS=e.startDTS+r.duration),!0===e.hasAudio&&n.addElementaryStream(m.AUDIO),!0===e.hasVideo&&n.addElementaryStream(m.VIDEO),d["logger"].log("Parsed "+e.type+",PTS:["+e.startPTS.toFixed(3)+","+e.endPTS.toFixed(3)+"],DTS:["+e.startDTS.toFixed(3)+"/"+e.endDTS.toFixed(3)+"],nb:"+e.nb+",dropped:"+(e.dropped||0)),"video"===e.type)if(n.dropped=e.dropped,n.dropped)if(n.backtracked)d["logger"].warn("Already backtracked on this fragment, appending with the gap",n.sn);else{var s=a.details;if(!s||n.sn!==s.startSN)return d["logger"].warn("missing video frame(s), backtracking fragment",n.sn),this.fragmentTracker.removeFragment(n),n.backtracked=!0,this.nextLoadPosition=e.startPTS,this.state=We.IDLE,this.fragPrevious=n,void this.tick();d["logger"].warn("missing video frame(s) on first frag, appending with gap",n.sn)}else n.backtracked=!1;var o=ve(a.details,n,e.startPTS,e.endPTS,e.startDTS,e.endDTS),c=this.hls;c.trigger(u["default"].LEVEL_PTS_UPDATED,{details:a.details,level:this.level,drift:o,type:e.type,start:e.startPTS,end:e.endPTS}),[e.data1,e.data2].forEach((function(r){r&&r.length&&t.state===We.PARSING&&(t.appended=!0,t.pendingBuffering=!0,c.trigger(u["default"].BUFFER_APPENDING,{type:e.type,data:r,parent:"main",content:"data"}))})),this.tick()}},r.onFragParsed=function(e){var t=this.fragCurrent,r=e.frag;t&&"main"===e.id&&r.sn===t.sn&&r.level===t.level&&this.state===We.PARSING&&(this.stats.tparsed=window.performance.now(),this.state=We.PARSED,this._checkAppendedParsed())},r.onAudioTrackSwitching=function(e){var t=!!e.url,r=e.id;if(!t){if(this.mediaBuffer!==this.media){d["logger"].log("switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var i=this.fragCurrent;i.loader&&(d["logger"].log("switching to main audio track, cancel main fragment load"),i.loader.abort()),this.fragCurrent=null,this.fragPrevious=null,this.demuxer&&(this.demuxer.destroy(),this.demuxer=null),this.state=We.IDLE}var a=this.hls;a.trigger(u["default"].BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:"audio"}),a.trigger(u["default"].AUDIO_TRACK_SWITCHED,{id:r}),this.altAudio=!1}},r.onAudioTrackSwitched=function(e){var t=e.id,r=!!this.hls.audioTracks[t].url;if(r){var i=this.videoBuffer;i&&this.mediaBuffer!==i&&(d["logger"].log("switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=i)}this.altAudio=r,this.tick()},r.onBufferCreated=function(e){var t,r,i=e.tracks,a=!1;for(var n in i){var s=i[n];"main"===s.id?(r=n,t=s,"video"===n&&(this.videoBuffer=i[n].buffer)):a=!0}a&&t?(d["logger"].log("alternate track found, use "+r+".buffered to schedule main fragment loading"),this.mediaBuffer=t.buffer):this.mediaBuffer=this.media},r.onBufferAppended=function(e){if("main"===e.parent){var t=this.state;t!==We.PARSING&&t!==We.PARSED||(this.pendingBuffering=e.pending>0,this._checkAppendedParsed())}},r._checkAppendedParsed=function(){if(this.state===We.PARSED&&(!this.appended||!this.pendingBuffering)){var e=this.fragCurrent;if(e){var t=this.mediaBuffer?this.mediaBuffer:this.media;d["logger"].log("main buffered : "+_e.toString(t.buffered)),this.fragPrevious=e;var r=this.stats;r.tbuffered=window.performance.now(),this.fragLastKbps=Math.round(8*r.total/(r.tbuffered-r.tfirst)),this.hls.trigger(u["default"].FRAG_BUFFERED,{stats:r,frag:e,id:"main"}),this.state=We.IDLE}this.tick()}},r.onError=function(e){var t=e.frag||this.fragCurrent;if(!t||"main"===t.type){var r=!!this.media&&re.isBuffered(this.media,this.media.currentTime)&&re.isBuffered(this.media,this.media.currentTime+.5);switch(e.details){case o["ErrorDetails"].FRAG_LOAD_ERROR:case o["ErrorDetails"].FRAG_LOAD_TIMEOUT:case o["ErrorDetails"].KEY_LOAD_ERROR:case o["ErrorDetails"].KEY_LOAD_TIMEOUT:if(!e.fatal)if(this.fragLoadError+1<=this.config.fragLoadingMaxRetry){var i=Math.min(Math.pow(2,this.fragLoadError)*this.config.fragLoadingRetryDelay,this.config.fragLoadingMaxRetryTimeout);d["logger"].warn("mediaController: frag loading failed, retry in "+i+" ms"),this.retryDate=window.performance.now()+i,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.fragLoadError++,this.state=We.FRAG_LOADING_WAITING_RETRY}else d["logger"].error("mediaController: "+e.details+" reaches max retry, redispatch as fatal ..."),e.fatal=!0,this.state=We.ERROR;break;case o["ErrorDetails"].LEVEL_LOAD_ERROR:case o["ErrorDetails"].LEVEL_LOAD_TIMEOUT:this.state!==We.ERROR&&(e.fatal?(this.state=We.ERROR,d["logger"].warn("streamController: "+e.details+",switch to "+this.state+" state ...")):e.levelRetry||this.state!==We.WAITING_LEVEL||(this.state=We.IDLE));break;case o["ErrorDetails"].BUFFER_FULL_ERROR:"main"!==e.parent||this.state!==We.PARSING&&this.state!==We.PARSED||(r?(this._reduceMaxBufferLength(this.config.maxBufferLength),this.state=We.IDLE):(d["logger"].warn("buffer full error also media.currentTime is not buffered, flush everything"),this.fragCurrent=null,this.flushMainBuffer(0,Number.POSITIVE_INFINITY)));break;default:break}}},r._reduceMaxBufferLength=function(e){var t=this.config;return t.maxMaxBufferLength>=e&&(t.maxMaxBufferLength/=2,d["logger"].warn("main:reduce max buffer length to "+t.maxMaxBufferLength+"s"),!0)},r._checkBuffer=function(){var e=this.media;if(e&&0!==e.readyState){var t=this.mediaBuffer?this.mediaBuffer:e,r=t.buffered;!this.loadedmetadata&&r.length?(this.loadedmetadata=!0,this._seekToStartPos()):this.immediateSwitch?this.immediateLevelSwitchEnd():this.gapController.poll(this.lastCurrentTime,r)}},r.onFragLoadEmergencyAborted=function(){this.state=We.IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tick()},r.onBufferFlushed=function(){var e=this.mediaBuffer?this.mediaBuffer:this.media;e&&this.fragmentTracker.detectEvictedFragments(m.VIDEO,e.buffered),this.state=We.IDLE,this.fragPrevious=null},r.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},r._seekToStartPos=function(){var e=this.media,t=e.currentTime,r=e.seeking?t:this.startPosition;t!==r&&r>=0&&(d["logger"].log("target start position not buffered, seek to buffered.start(0) "+r+" from current time "+t+" "),e.currentTime=r)},r._getAudioCodec=function(e){var t=this.config.defaultAudioCodec||e.audioCodec;return this.audioCodecSwap&&(d["logger"].log("swapping playlist audio codec"),t&&(t=-1!==t.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5")),t},ze(t,[{key:"state",set:function(e){if(this.state!==e){var t=this.state;this._state=e,d["logger"].log("main stream-controller: "+t+"->"+e),this.hls.trigger(u["default"].STREAM_STATE_TRANSITION,{previousState:t,nextState:e})}},get:function(){return this._state}},{key:"currentLevel",get:function(){var e=this.media;if(e){var t=this.getBufferedFrag(e.currentTime);if(t)return t.level}return-1}},{key:"nextBufferedFrag",get:function(){var e=this.media;return e?this.followingBufferedFrag(this.getBufferedFrag(e.currentTime)):null}},{key:"nextLevel",get:function(){var e=this.nextBufferedFrag;return e?e.level:-1}},{key:"liveSyncPosition",get:function(){return this._liveSyncPosition},set:function(e){this._liveSyncPosition=e}}]),t}(Ye),$e=Je;function Ze(e,t){for(var r=0;r0){t=r[0].bitrate,r.sort((function(e,t){return e.bitrate-t.bitrate})),this._levels=r;for(var c=0;c=0&&e1&&c.loadError0){var t=this.currentLevelIndex,r=e.urlId,i=e.url[r];d["logger"].log("Attempt loading level index "+t+" with URL-id "+r),this.hls.trigger(u["default"].LEVEL_LOADING,{url:i,level:t,id:r})}}},et(t,[{key:"levels",get:function(){return this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(e){var t=this._levels;t&&(e=Math.min(e,t.length-1),this.currentLevelIndex===e&&t[e].details||this.setLevelInternal(e))}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(e){this.manualLevelIndex=e,void 0===this._startLevel&&(this._startLevel=e),-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var e=this.hls.config.startLevel;return void 0!==e?e:this._firstLevel}return this._startLevel},set:function(e){this._startLevel=e}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(e){this.level=e,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=e)}}]),t}(h)),nt=r("./src/demux/id3.js");function st(e,t){var r;try{r=new Event("addtrack")}catch(i){r=document.createEvent("Event"),r.initEvent("addtrack",!1,!1)}r.track=e,t.dispatchEvent(r)}function ot(e){if(e&&e.cues)while(e.cues.length>0)e.removeCue(e.cues[0])}function lt(e,t){if(te[e.length-1].endTime)return e[e.length-1];var r=0,i=e.length-1;while(r<=i){var a=Math.floor((i+r)/2);if(te[a].endTime))return e[a];r=a+1}}return e[r].endTime-to&&(d["logger"].warn("detected an id3 sample with endTime < startTime, adjusting endTime to (startTime + 0.25)"),o=s+.25);for(var l=0;l=this.minWeight_},t.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},t.destroy=function(){},e}(),vt=pt;function mt(e,t){for(var r=0;r500*r.duration/o){var l=e.levels,c=Math.max(1,n.bw?n.bw/8:1e3*n.loaded/s),f=l[r.level],h=f.realBitrate?Math.max(f.realBitrate,f.bitrate):f.bitrate,g=n.total?n.total:Math.max(n.loaded,Math.round(r.duration*h/8)),p=t.currentTime,v=(g-n.loaded)/c,m=(re.bufferInfo(t,p,e.config.maxBufferHole).end-p)/o;if(m<2*r.duration/o&&v>m){var y,E;for(E=r.level-1;E>a;E--){var T=l[E].realBitrate?Math.max(l[E].realBitrate,l[E].bitrate):l[E].bitrate,S=r.duration*T/(6.4*c);if(S=i;u--){var c=l[u];if(c){var f=c.details,h=f?f.totalduration/f.fragments.length:t,g=!!f&&f.live,p=void 0;p=u<=e?s*r:o*r;var v=l[u].realBitrate?Math.max(l[u].realBitrate,l[u].bitrate):l[u].bitrate,m=v*h/p;if(d["logger"].trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: "+u+"/"+Math.round(p)+"/"+v+"/"+h+"/"+n+"/"+m),p>v&&(!m||g&&!this.bitrateTestDelay||m=0)return h;d["logger"].trace("rebuffering expected to happen, lets try to find a quality level minimizing the rebuffering");var g=o?Math.min(o,i.maxStarvationDelay):i.maxStarvationDelay,p=i.abrBandWidthFactor,v=i.abrBandWidthUpFactor;if(0===f){var m=this.bitrateTestDelay;if(m){var y=o?Math.min(o,i.maxLoadingDelay):i.maxLoadingDelay;g=y-m,d["logger"].trace("bitrate test took "+Math.round(1e3*m)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*g)+" ms"),p=v=1}}return h=this._findBestLevel(s,o,c,a,t,f+g,p,v,r),Math.max(h,0)}}]),t}(h),At=_t;function Rt(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var Dt=se(),Lt=function(e){function t(t){var r;return r=e.call(this,t,u["default"].MEDIA_ATTACHING,u["default"].MEDIA_DETACHING,u["default"].MANIFEST_PARSED,u["default"].BUFFER_RESET,u["default"].BUFFER_APPENDING,u["default"].BUFFER_CODECS,u["default"].BUFFER_EOS,u["default"].BUFFER_FLUSHING,u["default"].LEVEL_PTS_UPDATED,u["default"].LEVEL_UPDATED)||this,r._msDuration=null,r._levelDuration=null,r._levelTargetDuration=10,r._live=null,r._objectUrl=null,r._needsFlush=!1,r._needsEos=!1,r.config=void 0,r.audioTimestampOffset=void 0,r.bufferCodecEventsExpected=0,r._bufferCodecEventsTotal=0,r.media=null,r.mediaSource=null,r.segments=[],r.parent=void 0,r.appending=!1,r.appended=0,r.appendError=0,r.flushBufferCounter=0,r.tracks={},r.pendingTracks={},r.sourceBuffer={},r.flushRange=[],r._onMediaSourceOpen=function(){d["logger"].log("media source opened"),r.hls.trigger(u["default"].MEDIA_ATTACHED,{media:r.media});var e=r.mediaSource;e&&e.removeEventListener("sourceopen",r._onMediaSourceOpen),r.checkPendingTracks()},r._onMediaSourceClose=function(){d["logger"].log("media source closed")},r._onMediaSourceEnded=function(){d["logger"].log("media source ended")},r._onSBUpdateEnd=function(){if(r.audioTimestampOffset&&r.sourceBuffer.audio){var e=r.sourceBuffer.audio;d["logger"].warn("change mpeg audio timestamp offset from "+e.timestampOffset+" to "+r.audioTimestampOffset),e.timestampOffset=r.audioTimestampOffset,delete r.audioTimestampOffset}r._needsFlush&&r.doFlush(),r._needsEos&&r.checkEos(),r.appending=!1;var t=r.parent,i=r.segments.reduce((function(e,r){return r.parent===t?e+1:e}),0),a={},n=r.sourceBuffer;for(var s in n){var o=n[s];if(!o)throw Error("handling source buffer update end error: source buffer for "+s+" uninitilized and unable to update buffered TimeRanges.");a[s]=o.buffered}r.hls.trigger(u["default"].BUFFER_APPENDED,{parent:t,pending:i,timeRanges:a}),r._needsFlush||r.doAppending(),r.updateMediaElementDuration(),0===i&&r.flushLiveBackBuffer()},r._onSBUpdateError=function(e){d["logger"].error("sourceBuffer error:",e),r.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].MEDIA_ERROR,details:o["ErrorDetails"].BUFFER_APPENDING_ERROR,fatal:!1})},r.config=t.config,r}Rt(t,e);var r=t.prototype;return r.destroy=function(){h.prototype.destroy.call(this)},r.onLevelPtsUpdated=function(e){var t=e.type,r=this.tracks.audio;if("audio"===t&&r&&"audio/mpeg"===r.container){var i=this.sourceBuffer.audio;if(!i)throw Error("Level PTS Updated and source buffer for audio uninitalized");var a=Math.abs(i.timestampOffset-e.start);if(a>.1){var n=i.updating;try{i.abort()}catch(s){d["logger"].warn("can not abort audio buffer: "+s)}n?this.audioTimestampOffset=e.start:(d["logger"].warn("change mpeg audio timestamp offset from "+i.timestampOffset+" to "+e.start),i.timestampOffset=e.start)}}},r.onManifestParsed=function(e){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=e.altAudio?2:1,d["logger"].log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},r.onMediaAttaching=function(e){var t=this.media=e.media;if(t&&Dt){var r=this.mediaSource=new Dt;r.addEventListener("sourceopen",this._onMediaSourceOpen),r.addEventListener("sourceended",this._onMediaSourceEnded),r.addEventListener("sourceclose",this._onMediaSourceClose),t.src=window.URL.createObjectURL(r),this._objectUrl=t.src}},r.onMediaDetaching=function(){d["logger"].log("media source detaching");var e=this.mediaSource;if(e){if("open"===e.readyState)try{e.endOfStream()}catch(t){d["logger"].warn("onMediaDetaching:"+t.message+" while calling endOfStream")}e.removeEventListener("sourceopen",this._onMediaSourceOpen),e.removeEventListener("sourceended",this._onMediaSourceEnded),e.removeEventListener("sourceclose",this._onMediaSourceClose),this.media&&(this._objectUrl&&window.URL.revokeObjectURL(this._objectUrl),this.media.src===this._objectUrl?(this.media.removeAttribute("src"),this.media.load()):d["logger"].warn("media.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal,this.pendingTracks={},this.tracks={},this.sourceBuffer={},this.flushRange=[],this.segments=[],this.appended=0}this.hls.trigger(u["default"].MEDIA_DETACHED)},r.checkPendingTracks=function(){var e=this.bufferCodecEventsExpected,t=this.pendingTracks,r=Object.keys(t).length;(r&&!e||2===r)&&(this.createSourceBuffers(t),this.pendingTracks={},this.doAppending())},r.onBufferReset=function(){var e=this.sourceBuffer;for(var t in e){var r=e[t];try{r&&(this.mediaSource&&this.mediaSource.removeSourceBuffer(r),r.removeEventListener("updateend",this._onSBUpdateEnd),r.removeEventListener("error",this._onSBUpdateError))}catch(i){}}this.sourceBuffer={},this.flushRange=[],this.segments=[],this.appended=0},r.onBufferCodecs=function(e){var t=this;Object.keys(this.sourceBuffer).length||(Object.keys(e).forEach((function(r){t.pendingTracks[r]=e[r]})),this.bufferCodecEventsExpected=Math.max(this.bufferCodecEventsExpected-1,0),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks())},r.createSourceBuffers=function(e){var t=this.sourceBuffer,r=this.mediaSource;if(!r)throw Error("createSourceBuffers called when mediaSource was null");for(var i in e)if(!t[i]){var a=e[i];if(!a)throw Error("source buffer exists for track "+i+", however track does not");var n=a.levelCodec||a.codec,s=a.container+";codecs="+n;d["logger"].log("creating sourceBuffer("+s+")");try{var l=t[i]=r.addSourceBuffer(s);l.addEventListener("updateend",this._onSBUpdateEnd),l.addEventListener("error",this._onSBUpdateError),this.tracks[i]={buffer:l,codec:n,id:a.id,container:a.container,levelCodec:a.levelCodec}}catch(c){d["logger"].error("error while trying to add sourceBuffer:"+c.message),this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].MEDIA_ERROR,details:o["ErrorDetails"].BUFFER_ADD_CODEC_ERROR,fatal:!1,err:c,mimeType:s})}}this.hls.trigger(u["default"].BUFFER_CREATED,{tracks:this.tracks})},r.onBufferAppending=function(e){this._needsFlush||(this.segments?this.segments.push(e):this.segments=[e],this.doAppending())},r.onBufferEos=function(e){for(var t in this.sourceBuffer)if(!e.type||e.type===t){var r=this.sourceBuffer[t];r&&!r.ended&&(r.ended=!0,d["logger"].log(t+" sourceBuffer now EOS"))}this.checkEos()},r.checkEos=function(){var e=this.sourceBuffer,t=this.mediaSource;if(t&&"open"===t.readyState){for(var r in e){var i=e[r];if(i){if(!i.ended)return;if(i.updating)return void(this._needsEos=!0)}}d["logger"].log("all media data are available, signal endOfStream() to MediaSource and stop loading fragment");try{t.endOfStream()}catch(a){d["logger"].warn("exception while calling mediaSource.endOfStream()")}this._needsEos=!1}else this._needsEos=!1},r.onBufferFlushing=function(e){e.type?this.flushRange.push({start:e.startOffset,end:e.endOffset,type:e.type}):(this.flushRange.push({start:e.startOffset,end:e.endOffset,type:"video"}),this.flushRange.push({start:e.startOffset,end:e.endOffset,type:"audio"})),this.flushBufferCounter=0,this.doFlush()},r.flushLiveBackBuffer=function(){if(this._live){var e=this.config.liveBackBufferLength;if(isFinite(e)&&!(e<0))if(this.media)for(var t=this.media.currentTime,r=this.sourceBuffer,i=Object.keys(r),a=t-Math.max(e,this._levelTargetDuration),n=i.length-1;n>=0;n--){var s=i[n],o=r[s];if(o){var l=o.buffered;l.length>0&&a>l.start(0)&&this.removeBufferRange(s,o,0,a)&&this.hls.trigger(u["default"].LIVE_BACK_BUFFER_REACHED,{bufferEnd:a})}}else d["logger"].error("flushLiveBackBuffer called without attaching media")}},r.onLevelUpdated=function(e){var t=e.details;t.fragments.length>0&&(this._levelDuration=t.totalduration+t.fragments[0].start,this._levelTargetDuration=t.averagetargetduration||t.targetduration||10,this._live=t.live,this.updateMediaElementDuration())},r.updateMediaElementDuration=function(){var e,t=this.config;if(null!==this._levelDuration&&this.media&&this.mediaSource&&this.sourceBuffer&&0!==this.media.readyState&&"open"===this.mediaSource.readyState){for(var r in this.sourceBuffer){var i=this.sourceBuffer[r];if(i&&!0===i.updating)return}e=this.media.duration,null===this._msDuration&&(this._msDuration=this.mediaSource.duration),!0===this._live&&!0===t.liveDurationInfinity?(d["logger"].log("Media Source duration is set to Infinity"),this._msDuration=this.mediaSource.duration=1/0):(this._levelDuration>this._msDuration&&this._levelDuration>e||!Object(l["isFiniteNumber"])(e))&&(d["logger"].log("Updating Media Source duration to "+this._levelDuration.toFixed(3)),this._msDuration=this.mediaSource.duration=this._levelDuration)}},r.doFlush=function(){while(this.flushRange.length){var e=this.flushRange[0];if(!this.flushBuffer(e.start,e.end,e.type))return void(this._needsFlush=!0);this.flushRange.shift(),this.flushBufferCounter=0}if(0===this.flushRange.length){this._needsFlush=!1;var t=0,r=this.sourceBuffer;try{for(var i in r){var a=r[i];a&&(t+=a.buffered.length)}}catch(n){d["logger"].error("error while accessing sourceBuffer.buffered")}this.appended=t,this.hls.trigger(u["default"].BUFFER_FLUSHED)}},r.doAppending=function(){var e=this.config,t=this.hls,r=this.segments,i=this.sourceBuffer;if(Object.keys(i).length){if(!this.media||this.media.error)return this.segments=[],void d["logger"].error("trying to append although a media error occured, flush segment and abort");if(!this.appending){var a=r.shift();if(a)try{var n=i[a.type];if(!n)return void this._onSBUpdateEnd();if(n.updating)return void r.unshift(a);n.ended=!1,this.parent=a.parent,n.appendBuffer(a.data),this.appendError=0,this.appended++,this.appending=!0}catch(l){d["logger"].error("error while trying to append buffer:"+l.message),r.unshift(a);var s={type:o["ErrorTypes"].MEDIA_ERROR,parent:a.parent,details:"",fatal:!1};22===l.code?(this.segments=[],s.details=o["ErrorDetails"].BUFFER_FULL_ERROR):(this.appendError++,s.details=o["ErrorDetails"].BUFFER_APPEND_ERROR,this.appendError>e.appendErrorMaxRetry&&(d["logger"].log("fail "+e.appendErrorMaxRetry+" times to append segment in sourceBuffer"),this.segments=[],s.fatal=!0)),t.trigger(u["default"].ERROR,s)}}}},r.flushBuffer=function(e,t,r){var i=this.sourceBuffer;if(!Object.keys(i).length)return!0;var a="null";if(this.media&&(a=this.media.currentTime.toFixed(3)),d["logger"].log("flushBuffer,pos/start/end: "+a+"/"+e+"/"+t),this.flushBufferCounter>=this.appended)return d["logger"].warn("abort flushing too many retries"),!0;var n=i[r];if(n){if(n.ended=!1,n.updating)return d["logger"].warn("cannot flush, sb updating in progress"),!1;if(this.removeBufferRange(r,n,e,t))return this.flushBufferCounter++,!1}return d["logger"].log("buffer flushed"),!0},r.removeBufferRange=function(e,t,r,i){try{for(var a=0;a.5){var u="null";return this.media&&(u=this.media.currentTime.toString()),d["logger"].log("sb remove "+e+" ["+o+","+l+"], of ["+n+","+s+"], pos:"+u),t.remove(o,l),!0}}}catch(c){d["logger"].warn("removeBufferRange failed",c)}return!1},t}(h),wt=Lt;function kt(e,t){for(var r=0;rthis.autoLevelCapping&&t.streamController.nextLevelSwitch(),this.autoLevelCapping=t.autoLevelCapping}}},r.getMaxLevel=function(e){var r=this;if(!this.levels)return-1;var i=this.levels.filter((function(i,a){return t.isLevelAllowed(a,r.restrictedLevels)&&a<=e}));return t.getMaxLevelByMediaSize(i,this.mediaWidth,this.mediaHeight)},r.startCapping=function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,this.hls.firstLevel=this.getMaxLevel(this.firstLevel),clearInterval(this.timer),this.timer=setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},r.stopCapping=function(){this.restrictedLevels=[],this.firstLevel=null,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(this.timer=clearInterval(this.timer),this.timer=null)},t.isLevelAllowed=function(e,t){return void 0===t&&(t=[]),-1===t.indexOf(e)},t.getMaxLevelByMediaSize=function(e,t,r){if(!e||e&&!e.length)return-1;for(var i=function(e,t){return!t||(e.width!==t.width||e.height!==t.height)},a=e.length-1,n=0;n=t||s.height>=r)&&i(s,e[n+1])){a=n;break}}return a},It(t,[{key:"mediaWidth",get:function(){var e,r=this.media;return r&&(e=r.width||r.clientWidth||r.offsetWidth,e*=t.contentScaleFactor),e}},{key:"mediaHeight",get:function(){var e,r=this.media;return r&&(e=r.height||r.clientHeight||r.offsetHeight,e*=t.contentScaleFactor),e}}],[{key:"contentScaleFactor",get:function(){var e=1;try{e=window.devicePixelRatio}catch(t){}return e}}]),t}(h),Pt=Ct;function xt(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var Ft=window,Mt=Ft.performance,Nt=function(e){function t(t){return e.call(this,t,u["default"].MEDIA_ATTACHING)||this}xt(t,e);var r=t.prototype;return r.destroy=function(){this.timer&&clearInterval(this.timer),this.isVideoPlaybackQualityAvailable=!1},r.onMediaAttaching=function(e){var t=this.hls.config;if(t.capLevelOnFPSDrop){var r=this.video=e.media instanceof window.HTMLVideoElement?e.media:null;"function"===typeof r.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),clearInterval(this.timer),this.timer=setInterval(this.checkFPSInterval.bind(this),t.fpsDroppedMonitoringPeriod)}},r.checkFPS=function(e,t,r){var i=Mt.now();if(t){if(this.lastTime){var a=i-this.lastTime,n=r-this.lastDroppedFrames,s=t-this.lastDecodedFrames,o=1e3*n/a,l=this.hls;if(l.trigger(u["default"].FPS_DROP,{currentDropped:n,currentDecoded:s,totalDroppedFrames:r}),o>0&&n>l.config.fpsDroppedMonitoringThreshold*s){var c=l.currentLevel;d["logger"].warn("drop FPS ratio greater than max allowed value for currentLevel: "+c),c>0&&(-1===l.autoLevelCapping||l.autoLevelCapping>=c)&&(c-=1,l.trigger(u["default"].FPS_DROP_LEVEL_CAPPING,{level:c,droppedLevel:l.currentLevel}),l.autoLevelCapping=c,l.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=r,this.lastDecodedFrames=t}},r.checkFPSInterval=function(){var e=this.video;if(e)if(this.isVideoPlaybackQualityAvailable){var t=e.getVideoPlaybackQuality();this.checkFPS(e,t.totalVideoFrames,t.droppedVideoFrames)}else this.checkFPS(e,e.webkitDecodedFrameCount,e.webkitDroppedFrameCount)},t}(h),Ut=Nt,Bt=window,Gt=Bt.performance,Kt=Bt.XMLHttpRequest,jt=function(){function e(e){e&&e.xhrSetup&&(this.xhrSetup=e.xhrSetup)}var t=e.prototype;return t.destroy=function(){this.abort(),this.loader=null},t.abort=function(){var e=this.loader;e&&4!==e.readyState&&(this.stats.aborted=!0,e.abort()),window.clearTimeout(this.requestTimeout),this.requestTimeout=null,window.clearTimeout(this.retryTimeout),this.retryTimeout=null},t.load=function(e,t,r){this.context=e,this.config=t,this.callbacks=r,this.stats={trequest:Gt.now(),retry:0},this.retryDelay=t.retryDelay,this.loadInternal()},t.loadInternal=function(){var e,t=this.context;e=this.loader=new Kt;var r=this.stats;r.tfirst=0,r.loaded=0;var i=this.xhrSetup;try{if(i)try{i(e,t.url)}catch(a){e.open("GET",t.url,!0),i(e,t.url)}e.readyState||e.open("GET",t.url,!0)}catch(a){return void this.callbacks.onError({code:e.status,text:a.message},t,e)}t.rangeEnd&&e.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),e.onreadystatechange=this.readystatechange.bind(this),e.onprogress=this.loadprogress.bind(this),e.responseType=t.responseType,this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),this.config.timeout),e.send()},t.readystatechange=function(e){var t=e.currentTarget,r=t.readyState,i=this.stats,a=this.context,n=this.config;if(!i.aborted&&r>=2)if(window.clearTimeout(this.requestTimeout),0===i.tfirst&&(i.tfirst=Math.max(Gt.now(),i.trequest)),4===r){var s=t.status;if(s>=200&&s<300){var o,l;i.tload=Math.max(i.tfirst,Gt.now()),"arraybuffer"===a.responseType?(o=t.response,l=o.byteLength):(o=t.responseText,l=o.length),i.loaded=i.total=l;var u={url:t.responseURL,data:o};this.callbacks.onSuccess(u,i,a,t)}else i.retry>=n.maxRetry||s>=400&&s<499?(d["logger"].error(s+" while loading "+a.url),this.callbacks.onError({code:s,text:t.statusText},a,t)):(d["logger"].warn(s+" while loading "+a.url+", retrying in "+this.retryDelay+"..."),this.destroy(),this.retryTimeout=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,n.maxRetryDelay),i.retry++)}else this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),n.timeout)},t.loadtimeout=function(){d["logger"].warn("timeout while loading "+this.context.url),this.callbacks.onTimeout(this.stats,this.context,null)},t.loadprogress=function(e){var t=e.currentTarget,r=this.stats;r.loaded=e.loaded,e.lengthComputable&&(r.total=e.total);var i=this.callbacks.onProgress;i&&i(r,this.context,null,t)},e}(),Ht=jt;function Vt(e,t){for(var r=0;r=this.tracks.length)d["logger"].warn("Invalid audio track id:",e.id);else{if(d["logger"].log("audioTrack "+e.id+" loaded"),this.tracks[e.id].details=e.details,e.details.live&&!this.hasInterval()){var t=1e3*e.details.targetduration;this.setInterval(t)}!e.details.live&&this.hasInterval()&&this.clearInterval()}},r.onAudioTrackSwitched=function(e){var t=this.tracks[e.id].groupId;t&&this.audioGroupId!==t&&(this.audioGroupId=t)},r.onLevelLoaded=function(e){this._selectAudioGroup(e.level)},r.onError=function(e){e.type===o["ErrorTypes"].NETWORK_ERROR&&(e.fatal&&this.clearInterval(),e.details===o["ErrorDetails"].AUDIO_TRACK_LOAD_ERROR&&(d["logger"].warn("Network failure on audio-track id:",e.context.id),this._handleLoadError()))},r._setAudioTrack=function(e){if(this._trackId===e&&this.tracks[this._trackId].details)d["logger"].debug("Same id as current audio-track passed, and track details available -> no-op");else if(e<0||e>=this.tracks.length)d["logger"].warn("Invalid id passed to audio-track controller");else{var t=this.tracks[e];d["logger"].log("Now switching to audio-track index "+e),this.clearInterval(),this._trackId=e;var r=t.url,i=t.type,a=t.id;this.hls.trigger(u["default"].AUDIO_TRACK_SWITCHING,{id:a,type:i,url:r}),this._loadTrackDetailsIfNeeded(t)}},r.doTick=function(){this._updateTrack(this._trackId)},r._selectAudioGroup=function(e){var t=this.hls.levels[e];if(t&&t.audioGroupIds){var r=t.audioGroupIds[t.urlId];this.audioGroupId!==r&&(this.audioGroupId=r,this._selectInitialAudioTrack())}},r._selectInitialAudioTrack=function(){var e=this,t=this.tracks;if(t.length){var r=this.tracks[this._trackId],i=null;if(r&&(i=r.name),this._selectDefaultTrack){var a=t.filter((function(e){return e.default}));a.length?t=a:d["logger"].warn("No default audio tracks defined")}var n=!1,s=function(){t.forEach((function(t){n||e.audioGroupId&&t.groupId!==e.audioGroupId||i&&i!==t.name||(e._setAudioTrack(t.id),n=!0)}))};s(),n||(i=null,s()),n||(d["logger"].error("No track found for running audio group-ID: "+this.audioGroupId),this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].MEDIA_ERROR,details:o["ErrorDetails"].AUDIO_TRACK_LOAD_ERROR,fatal:!0}))}},r._needsTrackLoading=function(e){var t=e.details,r=e.url;return!(t&&!t.live)&&!!r},r._loadTrackDetailsIfNeeded=function(e){if(this._needsTrackLoading(e)){var t=e.url,r=e.id;d["logger"].log("loading audio-track playlist for id: "+r),this.hls.trigger(u["default"].AUDIO_TRACK_LOADING,{url:t,id:r})}},r._updateTrack=function(e){if(!(e<0||e>=this.tracks.length)){this.clearInterval(),this._trackId=e,d["logger"].log("trying to update audio-track "+e);var t=this.tracks[e];this._loadTrackDetailsIfNeeded(t)}},r._handleLoadError=function(){this.trackIdBlacklist[this._trackId]=!0;var e=this._trackId,t=this.tracks[e],r=t.name,i=t.language,a=t.groupId;d["logger"].warn("Loading failed on audio track id: "+e+", group-id: "+a+', name/language: "'+r+'" / "'+i+'"');for(var n=e,s=0;s0&&-1===e?(d["logger"].log("audio:override startPosition with lastCurrentTime @"+t.toFixed(3)),this.state=We.IDLE):(this.lastCurrentTime=this.startPosition?this.startPosition:e,this.state=We.STARTING),this.nextLoadPosition=this.startPosition=this.lastCurrentTime,this.tick()}else this.startPosition=e,this.state=We.STOPPED},r.doTick=function(){var e,t,r,i=this.hls,a=i.config;switch(this.state){case We.ERROR:case We.PAUSED:case We.BUFFER_FLUSHING:break;case We.STARTING:this.state=We.WAITING_TRACK,this.loadedmetadata=!1;break;case We.IDLE:var n=this.tracks;if(!n)break;if(!this.media&&(this.startFragRequested||!a.startFragPrefetch))break;if(this.loadedmetadata)e=this.media.currentTime;else if(e=this.nextLoadPosition,void 0===e)break;var s=this.mediaBuffer?this.mediaBuffer:this.media,o=this.videoBuffer?this.videoBuffer:this.media,c=re.bufferInfo(s,e,a.maxBufferHole),f=re.bufferInfo(o,e,a.maxBufferHole),h=c.len,g=c.end,p=this.fragPrevious,v=Math.min(a.maxBufferLength,a.maxMaxBufferLength),m=Math.max(v,f.len),y=this.audioSwitch,E=this.trackId;if((h_||c.nextStart))return;d["logger"].log("alt audio track ahead of main track, seek to start of alt audio track"),this.media.currentTime=_+.05}if(r.initSegment&&!r.initSegment.data)T=r.initSegment;else if(g<=_){if(T=S[0],null!==this.videoTrackCC&&T.cc!==this.videoTrackCC&&(T=Re(S,this.videoTrackCC)),r.live&&T.loadIdx&&T.loadIdx===this.fragLoadIdx){var R=c.nextStart?c.nextStart:_;return d["logger"].log("no alt audio available @currentTime:"+this.media.currentTime+", seeking @"+(R+.05)),void(this.media.currentTime=R+.05)}}else{var D,L=a.maxFragLookUpTolerance,w=p?S[p.sn-S[0].sn+1]:void 0,k=function(e){var t=Math.min(L,e.duration);return e.start+e.duration-t<=g?1:e.start-t>g&&e.start?-1:0};gA-L&&(L=0),D=w&&!k(w)?w:te.search(S,k)):D=S[b-1],D&&(T=D,_=D.start,p&&T.level===p.level&&T.sn===p.sn&&(T.sn=O||C)&&(d["logger"].log("audioStreamController: retryDate reached, switch back to IDLE state"),this.state=We.IDLE);break;case We.WAITING_INIT_PTS:var P=this.videoTrackCC;if(void 0===this.initPTS[P])break;var x=this.waitingFragment;if(x){var F=x.frag.cc;P!==F?(t=this.tracks[this.trackId],t.details&&t.details.live&&(d["logger"].warn("Waiting fragment CC ("+F+") does not match video track CC ("+P+")"),this.waitingFragment=null,this.state=We.IDLE)):(this.state=We.FRAG_LOADING,this.onFragLoaded(this.waitingFragment),this.waitingFragment=null)}else this.state=We.IDLE;break;case We.STOPPED:case We.FRAG_LOADING:case We.PARSING:case We.PARSED:case We.ENDED:break;default:break}},r.onMediaAttached=function(e){var t=this.media=this.mediaBuffer=e.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),t.addEventListener("seeking",this.onvseeking),t.addEventListener("ended",this.onvended);var r=this.config;this.tracks&&r.autoStartLoad&&this.startLoad(r.startPosition)},r.onMediaDetaching=function(){var e=this.media;e&&e.ended&&(d["logger"].log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),e&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvended=null),this.media=this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()},r.onAudioTracksUpdated=function(e){d["logger"].log("audio tracks updated"),this.tracks=e.audioTracks},r.onAudioTrackSwitching=function(e){var t=!!e.url;this.trackId=e.id,this.fragCurrent=null,this.state=We.PAUSED,this.waitingFragment=null,t?this.setInterval(er):this.demuxer&&(this.demuxer.destroy(),this.demuxer=null),t&&(this.audioSwitch=!0,this.state=We.IDLE),this.tick()},r.onAudioTrackLoaded=function(e){var t=e.details,r=e.id,i=this.tracks[r],a=t.totalduration,n=0;if(d["logger"].log("track "+r+" loaded ["+t.startSN+","+t.endSN+"],duration:"+a),t.live){var s=i.details;s&&t.fragments.length>0?(me(s,t),n=t.fragments[0].start,t.PTSKnown?d["logger"].log("live audio playlist sliding:"+n.toFixed(3)):d["logger"].log("live audio playlist - outdated PTS, unknown sliding")):(t.PTSKnown=!1,d["logger"].log("live audio playlist - first load, unknown sliding"))}else t.PTSKnown=!1;if(i.details=t,!this.startFragRequested){if(-1===this.startPosition){var o=t.startTimeOffset;Object(l["isFiniteNumber"])(o)?(d["logger"].log("start time offset found in playlist, adjust startPosition to "+o),this.startPosition=o):t.live?(this.startPosition=this.computeLivePosition(n,t),d["logger"].log("compute startPosition for audio-track to "+this.startPosition)):this.startPosition=0}this.nextLoadPosition=this.startPosition}this.state===We.WAITING_TRACK&&(this.state=We.IDLE),this.tick()},r.onKeyLoaded=function(){this.state===We.KEY_LOADING&&(this.state=We.IDLE,this.tick())},r.onFragLoaded=function(e){var t=this.fragCurrent,r=e.frag;if(this.state===We.FRAG_LOADING&&t&&"audio"===r.type&&r.level===t.level&&r.sn===t.sn){var i=this.tracks[this.trackId],a=i.details,n=a.totalduration,s=t.level,o=t.sn,l=t.cc,c=this.config.defaultAudioCodec||i.audioCodec||"mp4a.40.2",f=this.stats=e.stats;if("initSegment"===o)this.state=We.IDLE,f.tparsed=f.tbuffered=Zt.now(),a.initSegment.data=e.payload,this.hls.trigger(u["default"].FRAG_BUFFERED,{stats:f,frag:t,id:"audio"}),this.tick();else{this.state=We.PARSING,this.appended=!1,this.demuxer||(this.demuxer=new he(this.hls,"audio"));var h=this.initPTS[l],g=a.initSegment?a.initSegment.data:[];if(a.initSegment||void 0!==h){this.pendingBuffering=!0,d["logger"].log("Demuxing "+o+" of ["+a.startSN+" ,"+a.endSN+"],track "+s);var p=!1;this.demuxer.push(e.payload,g,c,null,t,n,p,h)}else d["logger"].log("unknown video PTS for continuity counter "+l+", waiting for video PTS before demuxing audio frag "+o+" of ["+a.startSN+" ,"+a.endSN+"],track "+s),this.waitingFragment=e,this.state=We.WAITING_INIT_PTS}}this.fragLoadError=0},r.onFragParsingInitSegment=function(e){var t=this.fragCurrent,r=e.frag;if(t&&"audio"===e.id&&r.sn===t.sn&&r.level===t.level&&this.state===We.PARSING){var i,a=e.tracks;if(a.video&&delete a.video,i=a.audio,i){i.levelCodec=i.codec,i.id=e.id,this.hls.trigger(u["default"].BUFFER_CODECS,a),d["logger"].log("audio track:audio,container:"+i.container+",codecs[level/parsed]=["+i.levelCodec+"/"+i.codec+"]");var n=i.initSegment;if(n){var s={type:"audio",data:n,parent:"audio",content:"initSegment"};this.audioSwitch?this.pendingData=[s]:(this.appended=!0,this.pendingBuffering=!0,this.hls.trigger(u["default"].BUFFER_APPENDING,s))}this.tick()}}},r.onFragParsingData=function(e){var t=this,r=this.fragCurrent,i=e.frag;if(r&&"audio"===e.id&&"audio"===e.type&&i.sn===r.sn&&i.level===r.level&&this.state===We.PARSING){var a=this.trackId,n=this.tracks[a],s=this.hls;Object(l["isFiniteNumber"])(e.endPTS)||(e.endPTS=e.startPTS+r.duration,e.endDTS=e.startDTS+r.duration),r.addElementaryStream(m.AUDIO),d["logger"].log("parsed "+e.type+",PTS:["+e.startPTS.toFixed(3)+","+e.endPTS.toFixed(3)+"],DTS:["+e.startDTS.toFixed(3)+"/"+e.endDTS.toFixed(3)+"],nb:"+e.nb),ve(n.details,r,e.startPTS,e.endPTS);var c=this.audioSwitch,f=this.media,h=!1;if(c)if(f&&f.readyState){var g=f.currentTime;d["logger"].log("switching audio track : currentTime:"+g),g>=e.startPTS&&(d["logger"].log("switching audio track : flushing all audio"),this.state=We.BUFFER_FLUSHING,s.trigger(u["default"].BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:"audio"}),h=!0,this.audioSwitch=!1,s.trigger(u["default"].AUDIO_TRACK_SWITCHED,{id:a}))}else this.audioSwitch=!1,s.trigger(u["default"].AUDIO_TRACK_SWITCHED,{id:a});var p=this.pendingData;if(!p)return d["logger"].warn("Apparently attempt to enqueue media payload without codec initialization data upfront"),void s.trigger(u["default"].ERROR,{type:o["ErrorTypes"].MEDIA_ERROR,details:null,fatal:!0});this.audioSwitch||([e.data1,e.data2].forEach((function(t){t&&t.length&&p.push({type:e.type,data:t,parent:"audio",content:"data"})})),!h&&p.length&&(p.forEach((function(e){t.state===We.PARSING&&(t.pendingBuffering=!0,t.hls.trigger(u["default"].BUFFER_APPENDING,e))})),this.pendingData=[],this.appended=!0)),this.tick()}},r.onFragParsed=function(e){var t=this.fragCurrent,r=e.frag;t&&"audio"===e.id&&r.sn===t.sn&&r.level===t.level&&this.state===We.PARSING&&(this.stats.tparsed=Zt.now(),this.state=We.PARSED,this._checkAppendedParsed())},r.onBufferReset=function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1},r.onBufferCreated=function(e){var t=e.tracks.audio;t&&(this.mediaBuffer=t.buffer,this.loadedmetadata=!0),e.tracks.video&&(this.videoBuffer=e.tracks.video.buffer)},r.onBufferAppended=function(e){if("audio"===e.parent){var t=this.state;t!==We.PARSING&&t!==We.PARSED||(this.pendingBuffering=e.pending>0,this._checkAppendedParsed())}},r._checkAppendedParsed=function(){if(this.state===We.PARSED&&(!this.appended||!this.pendingBuffering)){var e=this.fragCurrent,t=this.stats,r=this.hls;if(e){this.fragPrevious=e,t.tbuffered=Zt.now(),r.trigger(u["default"].FRAG_BUFFERED,{stats:t,frag:e,id:"audio"});var i=this.mediaBuffer?this.mediaBuffer:this.media;i&&d["logger"].log("audio buffered : "+_e.toString(i.buffered)),this.audioSwitch&&this.appended&&(this.audioSwitch=!1,r.trigger(u["default"].AUDIO_TRACK_SWITCHED,{id:this.trackId})),this.state=We.IDLE}this.tick()}},r.onError=function(e){var t=e.frag;if(!t||"audio"===t.type)switch(e.details){case o["ErrorDetails"].FRAG_LOAD_ERROR:case o["ErrorDetails"].FRAG_LOAD_TIMEOUT:var r=e.frag;if(r&&"audio"!==r.type)break;if(!e.fatal){var i=this.fragLoadError;i?i++:i=1;var a=this.config;if(i<=a.fragLoadingMaxRetry){this.fragLoadError=i;var n=Math.min(Math.pow(2,i-1)*a.fragLoadingRetryDelay,a.fragLoadingMaxRetryTimeout);d["logger"].warn("AudioStreamController: frag loading failed, retry in "+n+" ms"),this.retryDate=Zt.now()+n,this.state=We.FRAG_LOADING_WAITING_RETRY}else d["logger"].error("AudioStreamController: "+e.details+" reaches max retry, redispatch as fatal ..."),e.fatal=!0,this.state=We.ERROR}break;case o["ErrorDetails"].AUDIO_TRACK_LOAD_ERROR:case o["ErrorDetails"].AUDIO_TRACK_LOAD_TIMEOUT:case o["ErrorDetails"].KEY_LOAD_ERROR:case o["ErrorDetails"].KEY_LOAD_TIMEOUT:this.state!==We.ERROR&&(this.state=e.fatal?We.ERROR:We.IDLE,d["logger"].warn("AudioStreamController: "+e.details+" while loading frag, now switching to "+this.state+" state ..."));break;case o["ErrorDetails"].BUFFER_FULL_ERROR:if("audio"===e.parent&&(this.state===We.PARSING||this.state===We.PARSED)){var s=this.mediaBuffer,l=this.media.currentTime,c=s&&re.isBuffered(s,l)&&re.isBuffered(s,l+.5);if(c){var f=this.config;f.maxMaxBufferLength>=f.maxBufferLength&&(f.maxMaxBufferLength/=2,d["logger"].warn("AudioStreamController: reduce max buffer length to "+f.maxMaxBufferLength+"s")),this.state=We.IDLE}else d["logger"].warn("AudioStreamController: buffer full error also media.currentTime is not buffered, flush audio buffer"),this.fragCurrent=null,this.state=We.BUFFER_FLUSHING,this.hls.trigger(u["default"].BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:"audio"})}break;default:break}},r.onBufferFlushed=function(){var e=this,t=this.pendingData;t&&t.length?(d["logger"].log("AudioStreamController: appending pending audio data after buffer flushed"),t.forEach((function(t){e.hls.trigger(u["default"].BUFFER_APPENDING,t)})),this.appended=!0,this.pendingData=[],this.state=We.PARSED):(this.state=We.IDLE,this.fragPrevious=null,this.tick())},Qt(t,[{key:"state",set:function(e){if(this.state!==e){var t=this.state;this._state=e,d["logger"].log("audio stream:"+t+"->"+e)}},get:function(){return this._state}}]),t}(Ye),rr=tr,ir=function(){if("undefined"!==typeof window&&window.VTTCue)return window.VTTCue;var e="auto",t={"":!0,lr:!0,rl:!0},r={start:!0,middle:!0,end:!0,left:!0,right:!0};function i(e){if("string"!==typeof e)return!1;var r=t[e.toLowerCase()];return!!r&&e.toLowerCase()}function a(e){if("string"!==typeof e)return!1;var t=r[e.toLowerCase()];return!!t&&e.toLowerCase()}function n(e){for(var t=1;t100)throw new Error("Position must be between 0 and 100.");E=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"positionAlign",n({},l,{get:function(){return T},set:function(e){var t=a(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");T=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"size",n({},l,{get:function(){return S},set:function(e){if(e<0||e>100)throw new Error("Size must be between 0 and 100.");S=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"align",n({},l,{get:function(){return b},set:function(e){var t=a(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");b=t,this.hasBeenReset=!0}})),o.displayState=void 0}return s.prototype.getCueAsHTML=function(){var e=window.WebVTT;return e.convertCueToDOMTree(window,this.text)},s}(),ar=function(){return{decode:function(e){if(!e)return"";if("string"!==typeof e)throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(e))}}};function nr(){this.window=window,this.state="INITIAL",this.buffer="",this.decoder=new ar,this.regionList=[]}function sr(e){function t(e,t,r,i){return 3600*(0|e)+60*(0|t)+(0|r)+(0|i)/1e3}var r=e.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);return r?r[3]?t(r[1],r[2],r[3].replace(":",""),r[4]):r[1]>59?t(r[1],r[2],0,r[4]):t(0,r[1],r[2],r[4]):null}function or(){this.values=Object.create(null)}function lr(e,t,r,i){var a=i?e.split(i):[e];for(var n in a)if("string"===typeof a[n]){var s=a[n].split(r);if(2===s.length){var o=s[0],l=s[1];t(o,l)}}}or.prototype={set:function(e,t){this.get(e)||""===t||(this.values[e]=t)},get:function(e,t,r){return r?this.has(e)?this.values[e]:t[r]:this.has(e)?this.values[e]:t},has:function(e){return e in this.values},alt:function(e,t,r){for(var i=0;i=0&&t<=100))&&(this.set(e,t),!0)}};var ur=new ir(0,0,0),dr="middle"===ur.align?"middle":"center";function cr(e,t,r){var i=e;function a(){var t=sr(e);if(null===t)throw new Error("Malformed timestamp: "+i);return e=e.replace(/^[^\sa-zA-Z-]+/,""),t}function n(e,t){var i=new or;lr(e,(function(e,t){switch(e){case"region":for(var a=r.length-1;a>=0;a--)if(r[a].id===t){i.set(e,r[a].region);break}break;case"vertical":i.alt(e,t,["rl","lr"]);break;case"line":var n=t.split(","),s=n[0];i.integer(e,s),i.percent(e,s)&&i.set("snapToLines",!1),i.alt(e,s,["auto"]),2===n.length&&i.alt("lineAlign",n[1],["start",dr,"end"]);break;case"position":n=t.split(","),i.percent(e,n[0]),2===n.length&&i.alt("positionAlign",n[1],["start",dr,"end","line-left","line-right","auto"]);break;case"size":i.percent(e,t);break;case"align":i.alt(e,t,["start",dr,"end","left","right"]);break}}),/:/,/\s/),t.region=i.get("region",null),t.vertical=i.get("vertical","");var a=i.get("line","auto");"auto"===a&&-1===ur.line&&(a=-1),t.line=a,t.lineAlign=i.get("lineAlign","start"),t.snapToLines=i.get("snapToLines",!0),t.size=i.get("size",100),t.align=i.get("align",dr);var n=i.get("position","auto");"auto"===n&&50===ur.position&&(n="start"===t.align||"left"===t.align?0:"end"===t.align||"right"===t.align?100:50),t.position=n}function s(){e=e.replace(/^\s+/,"")}if(s(),t.startTime=a(),s(),"--\x3e"!==e.substr(0,3))throw new Error("Malformed time stamp (time stamps must be separated by '--\x3e'): "+i);e=e.substr(3),s(),t.endTime=a(),s(),n(e,t)}function fr(e){return e.replace(//gi,"\n")}nr.prototype={parse:function(e){var t=this;function r(){var e=t.buffer,r=0;e=fr(e);while(r=16?o--:o++,navigator.userAgent.match(/Firefox\//)?n.line=d+1:n.line=d>7?d-2:d+1,n.align="left",n.position=Math.max(0,Math.min(100,o/32*100)),e.addCue(n)}}var pr,vr={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608,128:174,129:176,130:189,131:191,132:8482,133:162,134:163,135:9834,136:224,137:32,138:232,139:226,140:234,141:238,142:244,143:251,144:193,145:201,146:211,147:218,148:220,149:252,150:8216,151:161,152:42,153:8217,154:9473,155:169,156:8480,157:8226,158:8220,159:8221,160:192,161:194,162:199,163:200,164:202,165:203,166:235,167:206,168:207,169:239,170:212,171:217,172:249,173:219,174:171,175:187,176:195,177:227,178:205,179:204,180:236,181:210,182:242,183:213,184:245,185:123,186:125,187:92,188:94,189:95,190:124,191:8764,192:196,193:228,194:214,195:246,196:223,197:165,198:164,199:9475,200:197,201:229,202:216,203:248,204:9487,205:9491,206:9495,207:9499},mr=function(e){var t=e;return vr.hasOwnProperty(e)&&(t=vr[e]),String.fromCharCode(t)},yr=15,Er=100,Tr={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},Sr={17:2,18:4,21:6,22:8,23:10,19:13,20:15},br={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},_r={25:2,26:4,29:6,30:8,31:10,27:13,28:15},Ar=["white","green","blue","cyan","red","yellow","magenta","black","transparent"];(function(e){e[e["ERROR"]=0]="ERROR",e[e["TEXT"]=1]="TEXT",e[e["WARNING"]=2]="WARNING",e[e["INFO"]=2]="INFO",e[e["DEBUG"]=3]="DEBUG",e[e["DATA"]=3]="DATA"})(pr||(pr={}));var Rr={verboseFilter:{DATA:3,DEBUG:3,INFO:2,WARNING:2,TEXT:1,ERROR:0},time:null,verboseLevel:0,setTime:function(e){this.time=e},log:function(e,t){this.verboseFilter[e];this.verboseLevel}},Dr=function(e){for(var t=[],r=0;rEr&&(Rr.log("ERROR","Too large cursor position "+this.pos),this.pos=Er)},t.moveCursor=function(e){var t=this.pos+e;if(e>1)for(var r=this.pos+1;r=144&&this.backSpace();var t=mr(e);this.pos>=Er?Rr.log("ERROR","Cannot insert "+e.toString(16)+" ("+t+") at position "+this.pos+". Skipping it!"):(this.chars[this.pos].setChar(t,this.currPenState),this.moveCursor(1))},t.clearFromPos=function(e){var t;for(t=e;t0&&(r=e?"["+t.join(" | ")+"]":t.join("\n")),r},t.getTextAndFormat=function(){return this.rows},e}(),Or=function(){function e(e,t){this.chNr=void 0,this.outputFilter=void 0,this.mode=void 0,this.verbose=void 0,this.displayedMemory=void 0,this.nonDisplayedMemory=void 0,this.lastOutputScreen=void 0,this.currRollUpRow=void 0,this.writeScreen=void 0,this.cueStartTime=void 0,this.lastCueEndTime=void 0,this.chNr=e,this.outputFilter=t,this.mode=null,this.verbose=0,this.displayedMemory=new Ir,this.nonDisplayedMemory=new Ir,this.lastOutputScreen=new Ir,this.currRollUpRow=this.displayedMemory.rows[yr-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null}var t=e.prototype;return t.reset=function(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.currRollUpRow=this.displayedMemory.rows[yr-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null},t.getHandler=function(){return this.outputFilter},t.setHandler=function(e){this.outputFilter=e},t.setPAC=function(e){this.writeScreen.setPAC(e)},t.setBkgData=function(e){this.writeScreen.setBkgData(e)},t.setMode=function(e){e!==this.mode&&(this.mode=e,Rr.log("INFO","MODE="+e),"MODE_POP-ON"===this.mode?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),"MODE_ROLL-UP"!==this.mode&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=e)},t.insertChars=function(e){for(var t=0;t=46,t.italics)t.foreground="white";else{var r=Math.floor(e/2)-16,i=["white","green","blue","cyan","red","yellow","magenta"];t.foreground=i[r]}Rr.log("INFO","MIDROW: "+JSON.stringify(t)),this.writeScreen.setPen(t)},t.outputDataUpdate=function(e){void 0===e&&(e=!1);var t=Rr.time;null!==t&&this.outputFilter&&(null!==this.cueStartTime||this.displayedMemory.isEmpty()?this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue(this.cueStartTime,t,this.lastOutputScreen),e&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:t):this.cueStartTime=t,this.lastOutputScreen.copy(this.displayedMemory))},t.cueSplitAtTime=function(e){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,e,this.displayedMemory),this.cueStartTime=e))},e}(),Cr=function(){function e(e,t,r){this.field=void 0,this.outputs=void 0,this.channels=void 0,this.currChNr=void 0,this.lastCmdA=void 0,this.lastCmdB=void 0,this.lastTime=void 0,this.dataCounters=void 0,this.field=e||1,this.outputs=[t,r],this.channels=[new Or(1,t),new Or(2,r)],this.currChNr=-1,this.lastCmdA=null,this.lastCmdB=null,this.lastTime=null,this.dataCounters={padding:0,char:0,cmd:0,other:0}}var t=e.prototype;return t.getHandler=function(e){return this.channels[e].getHandler()},t.setHandler=function(e,t){this.channels[e].setHandler(t)},t.addData=function(e,t){var r,i,a,n=!1;this.lastTime=e,Rr.setTime(e);for(var s=0;s ("+Dr([i,a])+")"),r=this.parseCmd(i,a),r||(r=this.parseMidrow(i,a)),r||(r=this.parsePAC(i,a)),r||(r=this.parseBackgroundAttributes(i,a)),!r&&(n=this.parseChars(i,a),n))if(this.currChNr&&this.currChNr>=0){var o=this.channels[this.currChNr-1];o.insertChars(n)}else Rr.log("WARNING","No channel found yet. TEXT-MODE?");r?this.dataCounters.cmd+=2:n?this.dataCounters.char+=2:(this.dataCounters.other+=2,Rr.log("WARNING","Couldn't parse cleaned data "+Dr([i,a])+" orig: "+Dr([t[s],t[s+1]])))}else this.dataCounters.padding+=2},t.parseCmd=function(e,t){var r=null,i=(20===e||28===e)&&t>=32&&t<=47,a=(23===e||31===e)&&t>=33&&t<=35;if(!i&&!a)return!1;if(e===this.lastCmdA&&t===this.lastCmdB)return this.lastCmdA=null,this.lastCmdB=null,Rr.log("DEBUG","Repeated command ("+Dr([e,t])+") is dropped"),!0;r=20===e||23===e?1:2;var n=this.channels[r-1];return 20===e||28===e?32===t?n.ccRCL():33===t?n.ccBS():34===t?n.ccAOF():35===t?n.ccAON():36===t?n.ccDER():37===t?n.ccRU(2):38===t?n.ccRU(3):39===t?n.ccRU(4):40===t?n.ccFON():41===t?n.ccRDC():42===t?n.ccTR():43===t?n.ccRTD():44===t?n.ccEDM():45===t?n.ccCR():46===t?n.ccENM():47===t&&n.ccEOC():n.ccTO(t-32),this.lastCmdA=e,this.lastCmdB=t,this.currChNr=r,!0},t.parseMidrow=function(e,t){var r=null;if((17===e||25===e)&&t>=32&&t<=47){if(r=17===e?1:2,r!==this.currChNr)return Rr.log("ERROR","Mismatch channel in midrow parsing"),!1;var i=this.channels[r-1];return i.ccMIDROW(t),Rr.log("DEBUG","MIDROW ("+Dr([e,t])+")"),!0}return!1},t.parsePAC=function(e,t){var r=null,i=null,a=(e>=17&&e<=23||e>=25&&e<=31)&&t>=64&&t<=127,n=(16===e||24===e)&&t>=64&&t<=95;if(!a&&!n)return!1;if(e===this.lastCmdA&&t===this.lastCmdB)return this.lastCmdA=null,this.lastCmdB=null,!0;r=e<=23?1:2,i=t>=64&&t<=95?1===r?Tr[e]:br[e]:1===r?Sr[e]:_r[e];var s=this.interpretPAC(i,t),o=this.channels[r-1];return o.setPAC(s),this.lastCmdA=e,this.lastCmdB=t,this.currChNr=r,!0},t.interpretPAC=function(e,t){var r=t,i={color:null,italics:!1,indent:null,underline:!1,row:e};return r=t>95?t-96:t-64,i.underline=1===(1&r),r<=13?i.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(r/2)]:r<=15?(i.italics=!0,i.color="white"):i.indent=4*Math.floor((r-16)/2),i},t.parseChars=function(e,t){var r=null,i=null,a=null;if(e>=25?(r=2,a=e-8):(r=1,a=e),a>=17&&a<=19){var n=t;n=17===a?t+80:18===a?t+112:t+144,Rr.log("INFO","Special char '"+mr(n)+"' in channel "+r),i=[n]}else e>=32&&e<=127&&(i=0===t?[e]:[e,t]);if(i){var s=Dr(i);Rr.log("DEBUG","Char codes = "+s.join(",")),this.lastCmdA=null,this.lastCmdB=null}return i},t.parseBackgroundAttributes=function(e,t){var r,i,a,n,s=(16===e||24===e)&&t>=32&&t<=47,o=(23===e||31===e)&&t>=45&&t<=47;return!(!s&&!o)&&(r={},16===e||24===e?(i=Math.floor((t-32)/2),r.background=Ar[i],t%2===1&&(r.background=r.background+"_semi")):45===t?r.background="transparent":(r.foreground="black",47===t&&(r.underline=!0)),a=e<24?1:2,n=this.channels[a-1],n.setBkgData(r),this.lastCmdA=null,this.lastCmdB=null,!0)},t.reset=function(){for(var e=0;ee)&&(this.startTime=e),this.endTime=t,this.screen=r,this.timelineController.createCaptionsTrack(this.trackName)},e}(),Fr=function(e,t,r){return e.substr(r||0,t.length)===t},Mr=function(e){var t=parseInt(e.substr(-3)),r=parseInt(e.substr(-6,2)),i=parseInt(e.substr(-9,2)),a=e.length>9?parseInt(e.substr(0,e.indexOf(":"))):0;if(!Object(l["isFiniteNumber"])(t)||!Object(l["isFiniteNumber"])(r)||!Object(l["isFiniteNumber"])(i)||!Object(l["isFiniteNumber"])(a))throw Error("Malformed X-TIMESTAMP-MAP: Local:"+e);return t+=1e3*r,t+=6e4*i,t+=36e5*a,t},Nr=function(e){var t=5381,r=e.length;while(r)t=33*t^e.charCodeAt(--r);return(t>>>0).toString()},Ur=function(e,t,r){var i=e[t],a=e[i.prevCC];if(!a||!a.new&&i.new)return e.ccOffset=e.presentationOffset=i.start,void(i.new=!1);while(a&&a.new)e.ccOffset+=i.start-a.start,i.new=!1,i=a,a=e[i.prevCC];e.presentationOffset=r},Br={parse:function(e,t,r,i,a,n){var s,o=/\r\n|\n\r|\n|\r/g,l=Object(nt["utf8ArrayToStr"])(new Uint8Array(e)).trim().replace(o,"\n").split("\n"),u="00:00.000",d=0,c=0,f=0,h=[],g=!0,p=!1,v=new hr;v.oncue=function(e){var t=r[i],a=r.ccOffset;t&&t.new&&(void 0!==c?a=r.ccOffset=t.start:Ur(r,i,f)),f&&(a=f-r.presentationOffset),p&&(e.startTime+=a-c,e.endTime+=a-c),e.id=Nr(e.startTime.toString())+Nr(e.endTime.toString())+Nr(e.text),e.text=decodeURIComponent(encodeURIComponent(e.text)),e.endTime>0&&h.push(e)},v.onparsingerror=function(e){s=e},v.onflush=function(){s&&n?n(s):a(h)},l.forEach((function(e){if(g){if(Fr(e,"X-TIMESTAMP-MAP=")){g=!1,p=!0,e.substr(16).split(",").forEach((function(e){Fr(e,"LOCAL:")?u=e.substr(6):Fr(e,"MPEGTS:")&&(d=parseInt(e.substr(7)))}));try{t+(9e4*r[i].start||0)<0&&(t+=8589934592),d-=t,c=Mr(u)/1e3,f=d/9e4}catch(a){p=!1,s=a}return}""===e&&(g=!1)}v.parse(e+"\n")})),v.flush()}},Gr=Br;function Kr(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function jr(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var Hr=function(e){function t(t){var r;if(r=e.call(this,t,u["default"].MEDIA_ATTACHING,u["default"].MEDIA_DETACHING,u["default"].FRAG_PARSING_USERDATA,u["default"].FRAG_DECRYPTED,u["default"].MANIFEST_LOADING,u["default"].MANIFEST_LOADED,u["default"].FRAG_LOADED,u["default"].INIT_PTS_FOUND)||this,r.media=null,r.config=void 0,r.enabled=!0,r.Cues=void 0,r.textTracks=[],r.tracks=[],r.initPTS=[],r.unparsedVttFrags=[],r.cueRanges=[],r.captionsTracks={},r.captionsProperties=void 0,r.cea608Parser=void 0,r.lastSn=-1,r.prevCC=-1,r.vttCCs=null,r.hls=t,r.config=t.config,r.Cues=t.config.cueHandler,r.captionsProperties={textTrack1:{label:r.config.captionsTextTrack1Label,languageCode:r.config.captionsTextTrack1LanguageCode},textTrack2:{label:r.config.captionsTextTrack2Label,languageCode:r.config.captionsTextTrack2LanguageCode}},r.config.enableCEA708Captions){var i=new xr(Kr(r),"textTrack1"),a=new xr(Kr(r),"textTrack2");r.cea608Parser=new Pr(0,i,a)}return r}jr(t,e);var r=t.prototype;return r.addCues=function(e,t,r,i){for(var a=this.cueRanges,n=!1,s=a.length;s--;){var o=a[s],l=Wr(o[0],o[1],t,r);if(l>=0&&(o[0]=Math.min(o[0],t),o[1]=Math.max(o[1],r),n=!0,l/(r-t)>.5))return}n||a.push([t,r]),this.Cues.newCue(this.captionsTracks[e],t,r,i)},r.onInitPtsFound=function(e){var t=this,r=e.frag,i=e.id,a=e.initPTS,n=this.unparsedVttFrags;"main"===i&&(this.initPTS[r.cc]=a),n.length&&(this.unparsedVttFrags=[],n.forEach((function(e){t.onFragLoaded(e)})))},r.getExistingTrack=function(e){var t=this.media;if(t)for(var r=0;r=n.length||r!==a||!s||this.stopped)this._clearReloadTimer();else if(d["logger"].log("subtitle track "+r+" loaded"),i.live){var o=Se(s.details,i,e.stats.trequest);d["logger"].log("Reloading live subtitle playlist in "+o+"ms"),this.timer=setTimeout((function(){t._loadCurrentTrack()}),o)}else this._clearReloadTimer()},r.startLoad=function(){this.stopped=!1,this._loadCurrentTrack()},r.stopLoad=function(){this.stopped=!0,this._clearReloadTimer()},r._clearReloadTimer=function(){this.timer&&(clearTimeout(this.timer),this.timer=null)},r._loadCurrentTrack=function(){var e=this.trackId,t=this.tracks,r=this.hls,i=t[e];e<0||!i||i.details&&!i.details.live||(d["logger"].log("Loading subtitle track "+e),r.trigger(u["default"].SUBTITLE_TRACK_LOADING,{url:i.url,id:e}))},r._toggleTrackModes=function(e){var t=this.media,r=this.subtitleDisplay,i=this.trackId;if(t){var a=Jr(t.textTracks);if(-1===e)[].slice.call(a).forEach((function(e){e.mode="disabled"}));else{var n=a[i];n&&(n.mode="disabled")}var s=a[e];s&&(s.mode=r?"showing":"hidden")}},r._setSubtitleTrackInternal=function(e){var t=this.hls,r=this.tracks;!Object(l["isFiniteNumber"])(e)||e<-1||e>=r.length||(this.trackId=e,d["logger"].log("Switching to subtitle track "+e),t.trigger(u["default"].SUBTITLE_TRACK_SWITCH,{id:e}),this._loadCurrentTrack())},r._onTextTracksChanged=function(){if(this.media){for(var e=-1,t=Jr(this.media.textTracks),r=0;r=i[s].start&&n<=i[s].end){a=i[s];break}var o=t.start+t.duration;a?a.end=o:(a={start:n,end:o},i.push(a))}}},r.onMediaAttached=function(e){var t=e.media;this.media=t,t.addEventListener("seeking",this._onMediaSeeking),this.state=We.IDLE},r.onMediaDetaching=function(){var e=this;this.media&&(this.media.removeEventListener("seeking",this._onMediaSeeking),this.fragmentTracker.removeAllFragments(),this.currentTrackId=-1,this.tracks.forEach((function(t){e.tracksBuffered[t.id]=[]})),this.media=null,this.state=We.STOPPED)},r.onError=function(e){var t=e.frag;t&&"subtitle"===t.type&&(this.state=We.IDLE)},r.onSubtitleTracksUpdated=function(e){var t=this;d["logger"].log("subtitle tracks updated"),this.tracksBuffered=[],this.tracks=e.subtitleTracks,this.tracks.forEach((function(e){t.tracksBuffered[e.id]=[]}))},r.onSubtitleTrackSwitch=function(e){if(this.currentTrackId=e.id,this.tracks&&this.tracks.length&&-1!==this.currentTrackId){var t=this.tracks[this.currentTrackId];t&&t.details&&this.setInterval(ni)}else this.clearInterval()},r.onSubtitleTrackLoaded=function(e){var t=e.id,r=e.details,i=this.currentTrackId,a=this.tracks,n=a[i];t>=a.length||t!==i||!n||(r.live&&ye(n.details,r,this.lastAVStart),n.details=r,this.setInterval(ni))},r.onKeyLoaded=function(){this.state===We.KEY_LOADING&&(this.state=We.IDLE)},r.onFragLoaded=function(e){var t=this.fragCurrent,r=e.frag.decryptdata,i=e.frag,a=this.hls;if(this.state===We.FRAG_LOADING&&t&&"subtitle"===e.frag.type&&t.sn===e.frag.sn&&e.payload.byteLength>0&&r&&r.key&&"AES-128"===r.method){var n=ai.now();this.decrypter.decrypt(e.payload,r.key.buffer,r.iv.buffer,(function(e){var t=ai.now();a.trigger(u["default"].FRAG_DECRYPTED,{frag:i,payload:e,stats:{tstart:n,tdecrypt:t}})}))}},r.onLevelUpdated=function(e){var t=e.details,r=t.fragments;this.lastAVStart=r.length?r[0].start:0},r.doTick=function(){if(this.media)switch(this.state){case We.IDLE:var e=this.config,t=this.currentTrackId,r=this.fragmentTracker,i=this.media,a=this.tracks;if(!a||!a[t]||!a[t].details)break;var n,s=e.maxBufferHole,o=e.maxFragLookUpTolerance,l=Math.min(e.maxBufferLength,e.maxMaxBufferLength),c=re.bufferedInfo(this._getBuffered(),i.currentTime,s),f=c.end,h=c.len,g=a[t].details,p=g.fragments,v=p.length,m=p[v-1].start+p[v-1].duration;if(h>l)return;var y=this.fragPrevious;fci)return void this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].KEY_SYSTEM_ERROR,details:o["ErrorDetails"].KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0});var a=ci-this._requestLicenseFailureCount+1;d["logger"].warn("Retrying license request, "+a+" attempts left"),this._requestLicense(r,i)}break}},r._generateLicenseRequestChallenge=function(e,t){switch(e.mediaKeySystemDomain){case ri.WIDEVINE:return t}throw new Error("unsupported key-system: "+e.mediaKeySystemDomain)},r._requestLicense=function(e,t){d["logger"].log("Requesting content license for key-system");var r=this._mediaKeysList[0];if(!r)return d["logger"].error("Fatal error: Media is encrypted but no key-system access has been obtained yet"),void this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].KEY_SYSTEM_ERROR,details:o["ErrorDetails"].KEY_SYSTEM_NO_ACCESS,fatal:!0});try{var i=this.getLicenseServerUrl(r.mediaKeySystemDomain),a=this._createLicenseXhr(i,e,t);d["logger"].log("Sending license request to URL: "+i);var n=this._generateLicenseRequestChallenge(r,e);a.send(n)}catch(s){d["logger"].error("Failure requesting DRM license: "+s),this.hls.trigger(u["default"].ERROR,{type:o["ErrorTypes"].KEY_SYSTEM_ERROR,details:o["ErrorDetails"].KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0})}},r.onMediaAttached=function(e){if(this._emeEnabled){var t=e.media;this._media=t,t.addEventListener("encrypted",this._onMediaEncrypted)}},r.onMediaDetached=function(){this._media&&(this._media.removeEventListener("encrypted",this._onMediaEncrypted),this._media=null)},r.onManifestParsed=function(e){if(this._emeEnabled){var t=e.levels.map((function(e){return e.audioCodec})),r=e.levels.map((function(e){return e.videoCodec}));this._attemptKeySystemAccess(ri.WIDEVINE,t,r)}},ui(t,[{key:"requestMediaKeySystemAccess",get:function(){if(!this._requestMediaKeySystemAccess)throw new Error("No requestMediaKeySystemAccess function configured");return this._requestMediaKeySystemAccess}}]),t}(h),pi=gi;function vi(e){for(var t=1;tt)return i}return 0}},{key:"maxAutoLevel",get:function(){var e,t=this.levels,r=this.autoLevelCapping;return e=-1===r&&t&&t.length?t.length-1:r,e}},{key:"nextAutoLevel",get:function(){return Math.min(Math.max(this.abrController.nextAutoLevel,this.minAutoLevel),this.maxAutoLevel)},set:function(e){this.abrController.nextAutoLevel=Math.max(this.minAutoLevel,e)}},{key:"audioTracks",get:function(){var e=this.audioTrackController;return e?e.audioTracks:[]}},{key:"audioTrack",get:function(){var e=this.audioTrackController;return e?e.audioTrack:-1},set:function(e){var t=this.audioTrackController;t&&(t.audioTrack=e)}},{key:"liveSyncPosition",get:function(){return this.streamController.liveSyncPosition}},{key:"subtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTrack:-1},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleTrack=e)}},{key:"subtitleDisplay",get:function(){var e=this.subtitleTrackController;return!!e&&e.subtitleDisplay},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleDisplay=e)}}]),t}(ue);Di.defaultConfig=void 0},"./src/polyfills/number-isFinite.js": /*!******************************************!*\ !*** ./src/polyfills/number-isFinite.js ***! \******************************************/ /*! exports provided: isFiniteNumber */function(e,t,r){"use strict";r.r(t),r.d(t,"isFiniteNumber",(function(){return i}));var i=Number.isFinite||function(e){return"number"===typeof e&&isFinite(e)}},"./src/utils/get-self-scope.js": /*!*************************************!*\ !*** ./src/utils/get-self-scope.js ***! \*************************************/ /*! exports provided: getSelfScope */function(e,t,r){"use strict";function i(){return"undefined"===typeof window?self:window}r.r(t),r.d(t,"getSelfScope",(function(){return i}))},"./src/utils/logger.js": /*!*****************************!*\ !*** ./src/utils/logger.js ***! \*****************************/ /*! exports provided: enableLogs, logger */function(e,t,r){"use strict";r.r(t),r.d(t,"enableLogs",(function(){return c})),r.d(t,"logger",(function(){return f}));var i=r(/*! ./get-self-scope */"./src/utils/get-self-scope.js");function a(){}var n={trace:a,debug:a,log:a,warn:a,info:a,error:a},s=n;function o(e,t){return t="["+e+"] > "+t,t}var l=Object(i["getSelfScope"])();function u(e){var t=l.console[e];return t?function(){for(var r=arguments.length,i=new Array(r),a=0;a1?t-1:0),i=1;i