"undefined"!=typeof window&&function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.hls=e():t.hls=e()}(this,(function(){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var a=e[i]={i:i,l:!1,exports:{}};return t[i].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||object.defineproperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof symbol&&symbol.tostringtag&&object.defineproperty(t,symbol.tostringtag,{value:"module"}),object.defineproperty(t,"__esmodule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esmodule)return t;var i=object.create(null);if(r.r(i),object.defineproperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)r.d(i,a,function(e){return t[e]}.bind(null,a));return i},r.n=function(t){var e=t&&t.__esmodule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return object.prototype.hasownproperty.call(t,e)},r.p="/dist/",r(r.s=20)}([function(t,e,r){"use strict";var i;r.d(e,"a",(function(){return i})),function(t){t.media_attaching="hlsmediaattaching",t.media_attached="hlsmediaattached",t.media_detaching="hlsmediadetaching",t.media_detached="hlsmediadetached",t.buffer_reset="hlsbufferreset",t.buffer_codecs="hlsbuffercodecs",t.buffer_created="hlsbuffercreated",t.buffer_appending="hlsbufferappending",t.buffer_appended="hlsbufferappended",t.buffer_eos="hlsbuffereos",t.buffer_flushing="hlsbufferflushing",t.buffer_flushed="hlsbufferflushed",t.manifest_loading="hlsmanifestloading",t.manifest_loaded="hlsmanifestloaded",t.manifest_parsed="hlsmanifestparsed",t.level_switching="hlslevelswitching",t.level_switched="hlslevelswitched",t.level_loading="hlslevelloading",t.level_loaded="hlslevelloaded",t.level_updated="hlslevelupdated",t.level_pts_updated="hlslevelptsupdated",t.levels_updated="hlslevelsupdated",t.audio_tracks_updated="hlsaudiotracksupdated",t.audio_track_switching="hlsaudiotrackswitching",t.audio_track_switched="hlsaudiotrackswitched",t.audio_track_loading="hlsaudiotrackloading",t.audio_track_loaded="hlsaudiotrackloaded",t.subtitle_tracks_updated="hlssubtitletracksupdated",t.subtitle_tracks_cleared="hlssubtitletrackscleared",t.subtitle_track_switch="hlssubtitletrackswitch",t.subtitle_track_loading="hlssubtitletrackloading",t.subtitle_track_loaded="hlssubtitletrackloaded",t.subtitle_frag_processed="hlssubtitlefragprocessed",t.cues_parsed="hlscuesparsed",t.non_native_text_tracks_found="hlsnonnativetexttracksfound",t.init_pts_found="hlsinitptsfound",t.frag_loading="hlsfragloading",t.frag_load_emergency_aborted="hlsfragloademergencyaborted",t.frag_loaded="hlsfragloaded",t.frag_decrypted="hlsfragdecrypted",t.frag_parsing_init_segment="hlsfragparsinginitsegment",t.frag_parsing_userdata="hlsfragparsinguserdata",t.frag_parsing_metadata="hlsfragparsingmetadata",t.frag_parsed="hlsfragparsed",t.frag_buffered="hlsfragbuffered",t.frag_changed="hlsfragchanged",t.fps_drop="hlsfpsdrop",t.fps_drop_level_capping="hlsfpsdroplevelcapping",t.error="hlserror",t.destroying="hlsdestroying",t.key_loading="hlskeyloading",t.key_loaded="hlskeyloaded",t.live_back_buffer_reached="hlslivebackbufferreached",t.back_buffer_reached="hlsbackbufferreached"}(i||(i={}))},function(t,e,r){"use strict";r.d(e,"a",(function(){return o})),r.d(e,"b",(function(){return l}));var i=function(){},a={trace:i,debug:i,log:i,warn:i,info:i,error:i},n=a;function s(t){var e=self.console[t];return e?e.bind(self.console,"["+t+"] >"):i}function o(t){if(self.console&&!0===t||"object"==typeof t){!function(t){for(var e=arguments.length,r=new array(e>1?e-1:0),i=1;i>8*(15-r)&255;return e},r.setdecryptdatafromlevelkey=function(t,e){var r=t;return"aes-128"===(null==t?void 0:t.method)&&t.uri&&!t.iv&&((r=o.a.fromuri(t.uri)).method=t.method,r.iv=this.createinitializationvector(e),r.keyformat="identity"),r},r.setelementarystreaminfo=function(t,e,r,i,a,n){void 0===n&&(n=!1);var s=this.elementarystreams,o=s[t];o?(o.startpts=math.min(o.startpts,e),o.endpts=math.max(o.endpts,r),o.startdts=math.min(o.startdts,i),o.enddts=math.max(o.enddts,a)):s[t]={startpts:e,endpts:r,startdts:i,enddts:a,partial:n}},r.clearelementarystreaminfo=function(){var t=this.elementarystreams;t[i.audio]=null,t[i.video]=null,t[i.audiovideo]=null},c(e,[{key:"decryptdata",get:function(){if(!this.levelkey&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkey){var t=this.sn;"number"!=typeof t&&(this.levelkey&&"aes-128"===this.levelkey.method&&!this.levelkey.iv&&s.b.warn('missing iv for initialization segment with method="'+this.levelkey.method+'" - compliance issue'),t=0),this._decryptdata=this.setdecryptdatafromlevelkey(this.levelkey,t)}return this._decryptdata}},{key:"end",get:function(){return this.start+this.duration}},{key:"endprogramdatetime",get:function(){if(null===this.programdatetime)return null;if(!object(a.a)(this.programdatetime))return null;var t=object(a.a)(this.duration)?this.duration:0;return this.programdatetime+1e3*t}},{key:"encrypted",get:function(){var t;return!(null===(t=this.decryptdata)||void 0===t||!t.keyformat||!this.decryptdata.uri)}}]),e}(f),v=function(t){function e(e,r,i,a,n){var s;(s=t.call(this,i)||this).fragoffset=0,s.duration=0,s.gap=!1,s.independent=!1,s.relurl=void 0,s.fragment=void 0,s.index=void 0,s.stats=new l.a,s.duration=e.decimalfloatingpoint("duration"),s.gap=e.bool("gap"),s.independent=e.bool("independent"),s.relurl=e.enumeratedstring("uri"),s.fragment=r,s.index=a;var o=e.enumeratedstring("byterange");return o&&s.setbyterange(o,n),n&&(s.fragoffset=n.fragoffset+n.duration),s}return u(e,t),c(e,[{key:"start",get:function(){return this.fragment.start+this.fragoffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var t=this.elementarystreams;return!!(t.audio||t.video||t.audiovideo)}}]),e}(f)},function(t,e,r){"use strict";r.d(e,"b",(function(){return h})),r.d(e,"g",(function(){return d})),r.d(e,"f",(function(){return c})),r.d(e,"d",(function(){return f})),r.d(e,"c",(function(){return g})),r.d(e,"e",(function(){return p})),r.d(e,"h",(function(){return m})),r.d(e,"a",(function(){return y}));var i=r(9),a=r(5),n=math.pow(2,32)-1,s=[].push;function o(t){return string.fromcharcode.apply(null,t)}function l(t,e){"data"in t&&(e+=t.start,t=t.data);var r=t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3];return r<0?4294967296+r:r}function u(t,e,r){"data"in t&&(e+=t.start,t=t.data),t[e]=r>>24,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r}function h(t,e){var r,i,a,n=[];if(!e.length)return n;"data"in t?(r=t.data,i=t.start,a=t.end):(i=0,a=(r=t).bytelength);for(var u=i;u1?u+d:a;if(o(r.subarray(u+4,u+8))===e[0])if(1===e.length)n.push({data:r,start:u+8,end:c});else{var f=h({data:r,start:u+8,end:c},e.slice(1));f.length&&s.apply(n,f)}u=c}return n}function d(t){var e=h(t,["moov"])[0],r=e?e.end:null,i=h(t,["sidx"]);if(!i||!i[0])return null;var a=[],n=i[0],s=n.data[0],o=0===s?8:16,u=l(n,o);o+=4;o+=0===s?8:16,o+=2;var d=n.end+0,c=function(t,e){"data"in t&&(e+=t.start,t=t.data);var r=t[e]<<8|t[e+1];return r<0?65536+r:r}(n,o);o+=2;for(var f=0;f>>31)return console.warn("sidx has hierarchical references (not supported)"),null;var m=l(n,g);g+=4,a.push({referencesize:p,subsegmentduration:m,info:{duration:m/u,start:d,end:d+p-1}}),d+=p,o=g+=4}return{earliestpresentationtime:0,timescale:u,version:s,referencescount:c,references:a,moovendoffset:r}}function c(t){for(var e=[],r=h(t,["moov","trak"]),i=0;i0)return t.subarray(r,r+i)},o=function(t,e){var r=0;return r=(127&t[e])<<21,r|=(127&t[e+1])<<14,r|=(127&t[e+2])<<7,r|=127&t[e+3]},l=function(t,e){return a(t,e)&&o(t,e+6)+10<=t.length-e},u=function(t){for(var e=c(t),r=0;r>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:u+=string.fromcharcode(n);break;case 12:case 13:s=t[h++],u+=string.fromcharcode((31&n)<<6|63&s);break;case 14:s=t[h++],o=t[h++],u+=string.fromcharcode((15&n)<<12|(63&s)<<6|(63&o)<<0)}}return u};function t(){return i||void 0===self.textdecoder||(i=new self.textdecoder("utf-8")),i}},function(t,e,r){"use strict";r.d(e,"c",(function(){return a})),r.d(e,"b",(function(){return n})),r.d(e,"a",(function(){return s}));function i(t,e,r,i){void 0===r&&(r=1),void 0===i&&(i=!1);var a=t*e*r;return i?math.round(a):a}function a(t,e,r,a){return void 0===r&&(r=1),void 0===a&&(a=!1),i(t,e,1/r,a)}function n(t,e){return void 0===e&&(e=!1),i(t,1e3,1/9e4,e)}function s(t,e){return void 0===e&&(e=1),i(t,9e4,1/e)}},function(t,e,r){"use strict";function i(t,e,r){return uint8array.prototype.slice?t.slice(e,r):new uint8array(array.prototype.slice.call(t,e,r))}r.d(e,"a",(function(){return i}))},function(t,e,r){"use strict";r.d(e,"c",(function(){return lt})),r.d(e,"d",(function(){return ht})),r.d(e,"a",(function(){return dt})),r.d(e,"b",(function(){return ct}));var i=r(0),a=r(2),n=r(15),s=r(3),o=r(7);var l=r(6),u=r(9),h=function(){function t(){this._audiotrack=void 0,this._id3track=void 0,this.frameindex=0,this.cacheddata=null,this.initpts=null}var e=t.prototype;return e.resetinitsegment=function(t,e,r){this._id3track={type:"id3",id:0,pid:-1,inputtimescale:9e4,sequencenumber:0,samples:[],dropped:0}},e.resettimestamp=function(){},e.resetcontiguity=function(){},e.canparse=function(t,e){return!1},e.appendframe=function(t,e,r){},e.demux=function(t,e){this.cacheddata&&(t=object(l.a)(this.cacheddata,t),this.cacheddata=null);var r,i,a=o.b(t,0),n=a?a.length:0,s=this._audiotrack,h=this._id3track,c=a?o.d(a):void 0,f=t.length;for(0!==this.frameindex&&null!==this.initpts||(this.initpts=d(c,e)),a&&a.length>0&&h.samples.push({pts:this.initpts,dts:this.initpts,data:a}),i=this.initpts;n>>5}function m(t,e){return e+1=t.length)return!1;var i=p(t,e);if(i<=r)return!1;var a=e+i;return a===t.length||m(t,a)}return!1}function t(t,e,r,n,s){if(!t.samplerate){var o=function(t,e,r,n){var s,o,l,u,h=navigator.useragent.tolowercase(),d=n,c=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];s=1+((192&e[r+2])>>>6);var g=(60&e[r+2])>>>2;if(!(g>c.length-1))return l=(1&e[r+2])<<2,l|=(192&e[r+3])>>>6,f.b.log("manifest codec:"+n+", adts type:"+s+", samplingindex:"+g),/firefox/i.test(h)?g>=6?(s=5,u=new array(4),o=g-3):(s=2,u=new array(2),o=g):-1!==h.indexof("android")?(s=2,u=new array(2),o=g):(s=5,u=new array(4),n&&(-1!==n.indexof("mp4a.40.29")||-1!==n.indexof("mp4a.40.5"))||!n&&g>=6?o=g-3:((n&&-1!==n.indexof("mp4a.40.2")&&(g>=6&&1===l||/vivaldi/i.test(h))||!n&&1===l)&&(s=2,u=new array(2)),o=g)),u[0]=s<<3,u[0]|=(14&g)>>1,u[1]|=(1&g)<<7,u[1]|=l<<3,5===s&&(u[1]|=(14&o)>>1,u[2]=(1&o)<<7,u[2]|=8,u[3]=0),{config:u,samplerate:c[g],channelcount:l,codec:"mp4a.40."+s,manifestcodec:d};t.trigger(i.a.error,{type:a.b.media_error,details:a.a.frag_parsing_error,fatal:!0,reason:"invalid adts sampling index:"+g})}(e,r,n,s);if(!o)return;t.config=o.config,t.samplerate=o.samplerate,t.channelcount=o.channelcount,t.codec=o.codec,t.manifestcodec=o.manifestcodec,f.b.log("parsed codec:"+t.codec+", rate:"+o.samplerate+", channels:"+o.channelcount)}}function e(t){return 9216e4/t}function b(t,e,r,i,a){var n=function(t,e,r,i,a){var n=v(t,e),s=p(t,e);if((s-=n)>0)return{headerlength:n,framelength:s,stamp:r+i*a}}(e,r,i,a,e(t.samplerate));if(n){var s,o=n.framelength,l=n.headerlength,u=n.stamp,h=l+o,d=math.max(0,r+h-e.length);d?(s=new uint8array(h-l)).set(e.subarray(r+l,e.length),0):s=e.subarray(r+l,r+h);var c={unit:s,pts:u};return d||t.samples.push(c),{sample:c,length:h,missing:d}}}function s(t,e){return(s=object.setprototypeof||function(t,e){return t.__proto__=e,t})(t,e)}var l=function(t){var e,r;function i(e,r){var i;return(i=t.call(this)||this).observer=void 0,i.config=void 0,i.observer=e,i.config=r,i}r=t,(e=i).prototype=object.create(r.prototype),e.prototype.constructor=e,s(e,r);var a=i.prototype;return a.resetinitsegment=function(e,r,i){t.prototype.resetinitsegment.call(this,e,r,i),this._audiotrack={container:"audio/adts",type:"audio",id:0,pid:-1,sequencenumber:0,isaac:!0,samples:[],manifestcodec:e,duration:i,inputtimescale:9e4,dropped:0}},i.probe=function(t){if(!t)return!1;for(var e=(o.b(t,0)||[]).length,r=t.length;e0},e.demux=function(t){var e=t,r={type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0};if(this.config.progressive){this.remainderdata&&(e=object(l.a)(this.remainderdata,t));var i=object(l.h)(e);this.remainderdata=i.remainder,r.samples=i.valid||new uint8array}else r.samples=e;return{audiotrack:{type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0},avctrack:r,id3track:{type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0},texttrack:{type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0}}},e.flush=function(){var t={type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0};return t.samples=this.remainderdata||new uint8array,this.remainderdata=null,{audiotrack:{type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0},avctrack:t,id3track:{type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0},texttrack:{type:"",id:-1,pid:-1,inputtimescale:9e4,sequencenumber:-1,samples:[],dropped:0}}},e.demuxsampleaes=function(t,e,r){return promise.reject(new error("the mp4 demuxer does not support sample-aes decryption"))},e.destroy=function(){},t}();r.minprobebytelength=1024;var k=r,d=null,_=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],i=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],c=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],w=[0,1,1,4];function o(t,e,r,i,a){if(!(r+24>e.length)){var n=x(e,r);if(n&&r+n.framelength<=e.length){var s=i+a*(9e4*n.samplesperframe/n.samplerate),o={unit:e.subarray(r,r+n.framelength),pts:s,dts:s};return t.config=[],t.channelcount=n.channelcount,t.samplerate=n.samplerate,t.samples.push(o),{sample:o,length:n.framelength,missing:0}}}}function x(t,e){var r=t[e+1]>>3&3,i=t[e+1]>>1&3,a=t[e+2]>>4&15,n=t[e+2]>>2&3;if(1!==r&&0!==a&&15!==a&&3!==n){var s=t[e+2]>>1&1,o=t[e+3]>>6,l=1e3*_[14*(3===r?3-i:3===i?3:4)+a-1],u=i[3*(3===r?0:2===r?1:2)+n],h=3===o?1:2,d=c[r][i],c=w[i],f=8*d*c,g=math.floor(d*l/u+s)*c;if(null===d){var v=(navigator.useragent||"").match(/chrome\/(\d+)/i);d=v?parseint(v[1]):0}return!!d&&d<=87&&2===i&&l>=224e3&&0===o&&(t[e+3]=128|t[e+3]),{samplerate:u,channelcount:h,framelength:g,samplesperframe:f}}}function p(t,e){return 255===t[e]&&224==(224&t[e+1])&&0!=(6&t[e+1])}function f(t,e){return e+1t?(this.word<<=t,this.bitsavailable-=t):(t-=this.bitsavailable,t-=(e=t>>3)>>3,this.bytesavailable-=e,this.loadword(),this.word<<=t,this.bitsavailable-=t)},e.readbits=function(t){var e=math.min(this.bitsavailable,t),r=this.word>>>32-e;return t>32&&f.b.error("cannot read more than 32 bits at a time"),this.bitsavailable-=e,this.bitsavailable>0?this.word<<=e:this.bytesavailable>0&&this.loadword(),(e=t-e)>0&&this.bitsavailable?r<>>t))return this.word<<=t,this.bitsavailable-=t,t;return this.loadword(),t+this.skiplz()},e.skipueg=function(){this.skipbits(1+this.skiplz())},e.skipeg=function(){this.skipbits(1+this.skiplz())},e.readueg=function(){var t=this.skiplz();return this.readbits(t+1)-1},e.readeg=function(){var t=this.readueg();return 1&t?1+t>>>1:-1*(t>>>1)},e.readboolean=function(){return 1===this.readbits(1)},e.readubyte=function(){return this.readbits(8)},e.readushort=function(){return this.readbits(16)},e.readuint=function(){return this.readbits(32)},e.skipscalinglist=function(t){for(var e=8,r=8,i=0;i=t.length)return void r();if(!(t[e].unit.length<32)){var i=this.decrypter.issync();if(this.decryptaacsample(t,e,r,i),!i)return}}},e.getavcencrypteddata=function(t){for(var e=16*math.floor((t.length-48)/160)+16,r=new int8array(e),i=0,a=32;a<=t.length-16;a+=160,i+=16)r.set(t.subarray(a,a+16),i);return r},e.getavcdecryptedunit=function(t,e){for(var r=new uint8array(e),i=0,a=32;a<=t.length-16;a+=160,i+=16)t.set(r.subarray(i,i+16),a);return t},e.decryptavcsample=function(t,e,r,i,a,n){var s=q(a.data),o=this.getavcencrypteddata(s),l=this;this.decryptbuffer(o.buffer,(function(o){a.data=l.getavcdecryptedunit(s,o),n||l.decryptavcsamples(t,e,r+1,i)}))},e.decryptavcsamples=function(t,e,r,i){if(t instanceof uint8array)throw new error("cannot decrypt samples of type uint8array");for(;;e++,r=0){if(e>=t.length)return void i();for(var a=t[e].units;!(r>=a.length);r++){var n=a[r];if(!(n.data.length<=48||1!==n.type&&5!==n.type)){var s=this.decrypter.issync();if(this.decryptavcsample(t,e,r,i,n,s),!s)return}}}},t}(),b={video:1,audio:2,id3:3,text:4},g=function(){function t(t,e,r){this.observer=void 0,this.config=void 0,this.typesupported=void 0,this.sampleaes=null,this.pmtparsed=!1,this.audiocodec=void 0,this.videocodec=void 0,this._duration=0,this.aaclastpts=null,this._initpts=null,this._initdts=null,this._pmtid=-1,this._avctrack=void 0,this._audiotrack=void 0,this._id3track=void 0,this._txttrack=void 0,this.aacoverflow=null,this.avcsample=null,this.remainderdata=null,this.observer=t,this.config=e,this.typesupported=r}t.probe=function(e){var r=t.syncoffset(e);return!(r<0)&&(r&&f.b.warn("mpeg2-ts detected but first sync word found @ offset "+r+", junk ahead ?"),!0)},t.syncoffset=function(t){for(var e=math.min(1e3,t.length-564),r=0;r>4>1){if((d=a+5+e[a+4])===a+188)continue}else d=a+4;switch(k){case c:r&&(g&&(o=v(g))&&this.parseavcpes(o,!1),g={data:[],size:0}),g&&(g.data.push(e.subarray(d,a+188)),g.size+=a+188-d);break;case v:r&&(m&&(o=v(m))&&(h.isaac?this.parseaacpes(o):this.parsempegpes(o)),m={data:[],size:0}),m&&(m.data.push(e.subarray(d,a+188)),m.size+=a+188-d);break;case p:r&&(y&&(o=v(y))&&this.parseid3pes(o),y={data:[],size:0}),y&&(y.data.push(e.subarray(d,a+188)),y.size+=a+188-d);break;case 0:r&&(d+=e[d]+1),b=this._pmtid=j(e,d);break;case b:r&&(d+=e[d]+1);var _=h(e,d,!0===this.typesupported.mpeg||!0===this.typesupported.mp3,n);(c=_.avc)>0&&(u.pid=c),(v=_.audio)>0&&(h.pid=v,h.isaac=_.isaac),(p=_.id3)>0&&(d.pid=p),t&&!e&&(f.b.log("reparse from beginning"),t=!1,a=l-188),e=this.pmtparsed=!0;break;case 17:case 8191:break;default:t=!0}}else this.observer.emit(i.a.error,i.a.error,{type:a.b.media_error,details:a.a.frag_parsing_error,fatal:!1,reason:"ts packet did not start with 0x47"});u.pesdata=g,h.pesdata=m,d.pesdata=y;var i={audiotrack:h,avctrack:u,id3track:d,texttrack:this._txttrack};return s&&this.extractremainingsamples(i),i},e.flush=function(){var t,e=this.remainderdata;return this.remainderdata=null,t=e?this.demux(e,-1,!1,!0):{audiotrack:this._audiotrack,avctrack:this._avctrack,texttrack:this._txttrack,id3track:this._id3track},this.extractremainingsamples(t),this.sampleaes?this.decrypt(t,this.sampleaes):t},e.extractremainingsamples=function(t){var e,r=t.audiotrack,i=t.avctrack,a=t.id3track,n=i.pesdata,s=r.pesdata,o=a.pesdata;n&&(e=v(n))?(this.parseavcpes(e,!0),i.pesdata=null):i.pesdata=n,s&&(e=v(s))?(r.isaac?this.parseaacpes(e):this.parsempegpes(e),r.pesdata=null):(null!=s&&s.size&&f.b.log("last aac pes packet truncated,might overlap between fragments"),r.pesdata=s),o&&(e=v(o))?(this.parseid3pes(e),a.pesdata=null):a.pesdata=o},e.demuxsampleaes=function(t,e,r){var i=this.demux(t,r,!0,!this.config.progressive),a=this.sampleaes=new u(this.observer,this.config,e);return this.decrypt(i,a)},e.decrypt=function(t,e){return new promise((function(r){var i=t.audiotrack,a=t.avctrack;i.samples&&i.isaac?e.decryptaacsamples(i.samples,0,(function(){a.samples?e.decryptavcsamples(a.samples,0,0,(function(){r(t)})):r(t)})):a.samples&&e.decryptavcsamples(a.samples,0,0,(function(){r(t)}))}))},e.destroy=function(){this._initpts=this._initdts=null,this._duration=0},e.parseavcpes=function(t,e){var r,i=this,a=this._avctrack,n=this.parseavcnalu(t.data),s=this.avcsample,l=!1;t.data=null,s&&n.length&&!a.audfound&&(w(s,a),s=this.avcsample=k(!1,t.pts,t.dts,"")),n.foreach((function(e){switch(e.type){case 1:r=!0,s||(s=i.avcsample=k(!0,t.pts,t.dts,"")),s.frame=!0;var n=e.data;if(l&&n.length>4){var u=new n(n).readslicetype();2!==u&&4!==u&&7!==u&&9!==u||(s.key=!0)}break;case 5:r=!0,s||(s=i.avcsample=k(!0,t.pts,t.dts,"")),s.key=!0,s.frame=!0;break;case 6:r=!0;var h=new n(q(e.data));h.readubyte();for(var d=0,c=0,f=!1,g=0;!f&&h.bytesavailable>1;){d=0;do{d+=g=h.readubyte()}while(255===g);c=0;do{c+=g=h.readubyte()}while(255===g);if(4===d&&0!==h.bytesavailable){if(f=!0,181===h.readubyte())if(49===h.readushort())if(1195456820===h.readuint())if(3===h.readubyte()){for(var v=h.readubyte(),p=31&v,m=[v,h.readubyte()],y=0;y16){for(var t=[],e=0;e<16;e++)t.push(h.readubyte().tostring(16)),3!==e&&5!==e&&7!==e&&9!==e||t.push("-");for(var b=c-16,s=new uint8array(b),l=0;l=0){var d={data:t.subarray(u,l-n-1),type:h};o.push(d)}else{var c=this.getlastnalunit();if(c&&(s&&l<=4-s&&c.state&&(c.data=c.data.subarray(0,c.data.bytelength-s)),(r=l-n-1)>0)){var f=new uint8array(c.data.bytelength+r);f.set(c.data,0),f.set(t.subarray(0,r),c.data.bytelength),c.data=f}}l=0&&n>=0){var g={data:t.subarray(u,i),type:h,state:n};o.push(g)}if(0===o.length){var v=this.getlastnalunit();if(v){var p=new uint8array(v.data.bytelength+t.bytelength);p.set(v.data,0),p.set(t,v.data.bytelength),v.data=p}}return a.nalustate=n,o},e.parseaacpes=function(t){var e,r,n,s,o,l=0,u=this._audiotrack,h=this.aacoverflow,d=t.data;if(h){this.aacoverflow=null;var c=h.sample.unit.bytelength,g=math.min(h.missing,c),v=c-g;h.sample.unit.set(d.subarray(0,g),v),u.samples.push(h.sample),l=h.missing}for(e=l,r=d.length;e1;){var l=new uint8array(o[0].length+o[1].length);l.set(o[0]),l.set(o[1],o[0].length),o[0]=l,o.splice(1,1)}if(1===((e=o[0])[0]<<16)+(e[1]<<8)+e[2]){if((r=(e[4]<<8)+e[5])&&r>t.size-6)return null;var u=e[7];192&u&&(a=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&u?a-(n=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(f.b.warn(math.round((a-n)/9e4)+"s delta between pts and dts, align them"),a=n):n=a);var h=(i=e[8])+9;if(t.size<=h)return null;t.size-=h;for(var d=new uint8array(t.size),c=0,g=o.length;cv){h-=v;continue}e=e.subarray(h),v-=h,h=0}d.set(e,s),s+=v}return r&&(r-=i+3),{data:d,pts:a,dts:n,len:r}}return null}function w(t,e){if(t.units.length&&t.frame){if(void 0===t.pts){var r=e.samples,i=r.length;if(!i)return void e.dropped++;var a=r[i-1];t.pts=a.pts,t.dts=a.dts}e.samples.push(t)}t.debug.length&&f.b.log(t.pts+"/"+t.dts+":"+t.debug)}function y(t,e){var r=t.length;if(r>0){if(e.pts>=t[r-1].pts)t.push(e);else for(var i=r-1;i>=0;i--)if(e.pts0?this.lastenddts=p:(f.b.warn("duration parsed from mp4 should be greater than zero"),this.resetnexttimestamp());var m=!!c.audio,y=!!c.video,t="";m&&(t+="audio"),y&&(t+="video");var e={data1:h,startpts:v,startdts:v,endpts:p,enddts:p,type:t,hasaudio:m,hasvideo:y,nb:1,dropped:0};return u.audio="audio"===e.type?e:void 0,u.video="audio"!==e.type?e:void 0,u.text=i,u.id3=r,u.initsegment=d,u},t}(),et=function(t,e,r){return object(l.d)(t,e)-r};function rt(t,e){var r=null==t?void 0:t.codec;return r&&r.length>4?r:"hvc1"===r?"hvc1.1.c.l120.90":"av01"===r?"av01.0.04m.08":"avc1"===r||e===z.a.video?"avc1.42e01e":"mp4a.40.5"}var it,at=tt,nt=r(13);try{it=self.performance.now.bind(self.performance)}catch(t){f.b.debug("unable to use performance api on this environment"),it=self.date.now}var st=[{demux:x,remux:j.a},{demux:k,remux:at},{demux:a,remux:j.a},{demux:$,remux:j.a}],ot=1024;st.foreach((function(t){var e=t.demux;ot=math.max(ot,e.minprobebytelength)}));var lt=function(){function t(t,e,r,i,a){this.observer=void 0,this.typesupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionpromise=null,this.transmuxconfig=void 0,this.currenttransmuxstate=void 0,this.cache=new nt.a,this.observer=t,this.typesupported=e,this.config=r,this.vendor=i,this.id=a}var e=t.prototype;return e.configure=function(t){this.transmuxconfig=t,this.decrypter&&this.decrypter.reset()},e.push=function(t,e,r,i){var a=this,n=r.transmuxing;n.executestart=it();var s=new uint8array(t),o=this.cache,u=this.config,h=this.currenttransmuxstate,d=this.transmuxconfig;i&&(this.currenttransmuxstate=i);var c=function(t,e){var r=null;t.bytelength>0&&null!=e&&null!=e.key&&null!==e.iv&&null!=e.method&&(r=e);return r}(s,e);if(c&&"aes-128"===c.method){var f=this.getdecrypter();if(!u.enablesoftwareaes)return this.decryptionpromise=f.webcryptodecrypt(s,c.key.buffer,c.iv.buffer).then((function(t){var e=a.push(t,null,r);return a.decryptionpromise=null,e})),this.decryptionpromise;var g=f.softwaredecrypt(s,c.key.buffer,c.iv.buffer);if(!g)return n.executeend=it(),ut(r);s=new uint8array(g)}var v=i||h,p=v.contiguous,m=v.discontinuity,y=v.trackswitch,t=v.accuratetimeoffset,e=v.timeoffset,b=d.audiocodec,s=d.videocodec,l=d.defaultinitpts,a=d.duration,r=d.initsegmentdata;if((m||y)&&this.resetinitsegment(r,b,s,a),m&&this.resetinitialtimestamp(l),p||this.resetcontiguity(),this.needsprobing(s,m,y)){if(o.datalength){var k=o.flush();s=object(l.a)(k,s)}this.configuretransmuxer(s,d)}var d=this.transmux(s,c,e,t,r),_=this.currenttransmuxstate;return _.contiguous=!0,_.discontinuity=!1,_.trackswitch=!1,n.executeend=it(),d},e.flush=function(t){var e=this,r=t.transmuxing;r.executestart=it();var n=this.decrypter,s=this.cache,o=this.currenttransmuxstate,l=this.decryptionpromise;if(l)return l.then((function(){return e.flush(t)}));var u=[],h=o.timeoffset;if(n){var d=n.flush();d&&u.push(this.push(d,null,t))}var c=s.datalength;s.reset();var f=this.demuxer,g=this.remuxer;if(!f||!g)return c>=ot&&this.observer.emit(i.a.error,i.a.error,{type:a.b.media_error,details:a.a.frag_parsing_error,fatal:!0,reason:"no demux matching with content found"}),r.executeend=it(),[ut(t)];var v=f.flush(h);return ht(v)?v.then((function(r){return e.flushremux(u,r,t),u})):(this.flushremux(u,v,t),u)},e.flushremux=function(t,e,r){var i=e.audiotrack,a=e.avctrack,n=e.id3track,s=e.texttrack,o=this.currenttransmuxstate,l=o.accuratetimeoffset,u=o.timeoffset;f.b.log("[transmuxer.ts]: flushed fragment "+r.sn+(r.part>-1?" p: "+r.part:"")+" of level "+r.level);var h=this.remuxer.remux(i,a,n,s,u,l,!0,this.id);t.push({remuxresult:h,chunkmeta:r}),r.transmuxing.executeend=it()},e.resetinitialtimestamp=function(t){var e=this.demuxer,r=this.remuxer;e&&r&&(e.resettimestamp(t),r.resettimestamp(t))},e.resetcontiguity=function(){var t=this.demuxer,e=this.remuxer;t&&e&&(t.resetcontiguity(),e.resetnexttimestamp())},e.resetinitsegment=function(t,e,r,i){var a=this.demuxer,n=this.remuxer;a&&n&&(a.resetinitsegment(e,r,i),n.resetinitsegment(t,e,r))},e.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},e.transmux=function(t,e,r,i,a){return e&&"sample-aes"===e.method?this.transmuxsampleaes(t,e,r,i,a):this.transmuxunencrypted(t,r,i,a)},e.transmuxunencrypted=function(t,e,r,i){var a=this.demuxer.demux(t,e,!1,!this.config.progressive),n=a.audiotrack,s=a.avctrack,o=a.id3track,l=a.texttrack;return{remuxresult:this.remuxer.remux(n,s,o,l,e,r,!1,this.id),chunkmeta:i}},e.transmuxsampleaes=function(t,e,r,i,a){var n=this;return this.demuxer.demuxsampleaes(t,e,r).then((function(t){return{remuxresult:n.remuxer.remux(t.audiotrack,t.avctrack,t.id3track,t.texttrack,r,i,!1,n.id),chunkmeta:a}}))},e.configuretransmuxer=function(t,e){for(var r,i=this.config,a=this.observer,n=this.typesupported,s=this.vendor,o=e.audiocodec,l=e.defaultinitpts,u=e.duration,h=e.initsegmentdata,d=e.videocodec,c=0,g=st.length;c>>8^255&p^99,t[f]=p,e[p]=f;var m=c[f],y=c[m],t=c[y],e=257*c[p]^16843008*p;i[f]=e<<24|e>>>8,a[f]=e<<16|e>>>16,n[f]=e<<8|e>>>24,s[f]=e,e=16843009*t^65537*y^257*m^16843008*f,l[p]=e<<24|e>>>8,u[p]=e<<16|e>>>16,h[p]=e<<8|e>>>24,d[p]=e,f?(f=m^c[c[c[t^m]]],g^=c[c[g]]):f=g=1}},e.expandkey=function(t){for(var e=this.uint8arraytouint32array_(t),r=!0,i=0;i1?r-1:0),a=1;a>24&255,o[1]=e>>16&255,o[2]=e>>8&255,o[3]=255&e,o.set(t,4),n=0,e=8;n>24&255,e>>16&255,e>>8&255,255&e,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,85,196,0,0]))},t.mdia=function(e){return t.box(t.types.mdia,t.mdhd(e.timescale,e.duration),t.hdlr(e.type),t.minf(e))},t.mfhd=function(e){return t.box(t.types.mfhd,new uint8array([0,0,0,0,e>>24,e>>16&255,e>>8&255,255&e]))},t.minf=function(e){return"audio"===e.type?t.box(t.types.minf,t.box(t.types.smhd,t.smhd),t.dinf,t.stbl(e)):t.box(t.types.minf,t.box(t.types.vmhd,t.vmhd),t.dinf,t.stbl(e))},t.moof=function(e,r,i){return t.box(t.types.moof,t.mfhd(e),t.traf(i,r))},t.moov=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trak(e[r]);return t.box.apply(null,[t.types.moov,t.mvhd(e[0].timescale,e[0].duration)].concat(i).concat(t.mvex(e)))},t.mvex=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trex(e[r]);return t.box.apply(null,[t.types.mvex].concat(i))},t.mvhd=function(e,r){r*=e;var i=math.floor(r/(n+1)),a=math.floor(r%(n+1)),s=new uint8array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,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 t.box(t.types.mvhd,s)},t.sdtp=function(e){var r,i,a=e.samples||[],n=new uint8array(4+a.length);for(r=0;r>>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=t.box(t.types.avcc,new uint8array([1,n[3],n[4],n[5],255,224|e.sps.length].concat(n).concat([e.pps.length]).concat(s))),l=e.width,u=e.height,h=e.pixelratio[0],d=e.pixelratio[1];return t.box(t.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,t.box(t.types.btrt,new uint8array([0,28,156,128,0,45,198,192,0,45,198,192])),t.box(t.types.pasp,new uint8array([h>>24,h>>16&255,h>>8&255,255&h,d>>24,d>>16&255,d>>8&255,255&d])))},t.esds=function(t){var e=t.config.length;return new uint8array([0,0,0,0,3,23+e,0,1,0,4,15+e,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([e]).concat(t.config).concat([6,1,2]))},t.mp4a=function(e){var r=e.samplerate;return t.box(t.types.mp4a,new uint8array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelcount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),t.box(t.types.esds,t.esds(e)))},t.mp3=function(e){var r=e.samplerate;return t.box(t.types[".mp3"],new uint8array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelcount,0,16,0,0,0,0,r>>8&255,255&r,0,0]))},t.stsd=function(e){return"audio"===e.type?e.isaac||"mp3"!==e.codec?t.box(t.types.stsd,t.stsd,t.mp4a(e)):t.box(t.types.stsd,t.stsd,t.mp3(e)):t.box(t.types.stsd,t.stsd,t.avc1(e))},t.tkhd=function(e){var r=e.id,i=e.duration*e.timescale,a=e.width,s=e.height,o=math.floor(i/(n+1)),l=math.floor(i%(n+1));return t.box(t.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,o>>24,o>>16&255,o>>8&255,255&o,l>>24,l>>16&255,l>>8&255,255&l,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,s>>8&255,255&s,0,0]))},t.traf=function(e,r){var i=t.sdtp(e),a=e.id,s=math.floor(r/(n+1)),o=math.floor(r%(n+1));return t.box(t.types.traf,t.box(t.types.tfhd,new uint8array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a])),t.box(t.types.tfdt,new uint8array([1,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o])),t.trun(e,i.length+16+20+8+16+8+8),i)},t.trak=function(e){return e.duration=e.duration||4294967295,t.box(t.types.trak,t.tkhd(e),t.mdia(e))},t.trex=function(e){var r=e.id;return t.box(t.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]))},t.trun=function(e,r){var i,a,n,s,o,l,u=e.samples||[],h=u.length,d=12+16*h,c=new uint8array(d);for(r+=8+d,c.set([0,0,15,1,h>>>24&255,h>>>16&255,h>>>8&255,255&h,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 t.box(t.types.trun,c)},t.initsegment=function(e){t.types||t.init();var r=t.moov(e),i=new uint8array(t.ftyp.bytelength+r.bytelength);return i.set(t.ftyp),i.set(r,t.ftyp.bytelength),i},t}();s.types=void 0,s.hdlr_types=void 0,s.stts=void 0,s.stsc=void 0,s.stco=void 0,s.stsz=void 0,s.vmhd=void 0,s.smhd=void 0,s.stsd=void 0,s.ftyp=void 0,s.dinf=void 0;var o=s,l=r(0),u=r(2),h=r(1),d=r(4),c=r(8);function f(){return(f=object.assign||function(t){for(var e=1;e0?t:r.pts}),t[0].pts);return e&&h.b.debug("pts rollover detected"),r},e.remux=function(t,e,r,i,a,n,s,o){var l,u,c,f,g,v,p=a,m=a,t=t.pid>-1,e=e.pid>-1,b=e.samples.length,s=t.samples.length>0,l=b>1;if((!t||s)&&(!e||l)||this.isgenerated||s){this.isgenerated||(c=this.generateis(t,e,a));var a=this.isvideocontiguous,r=-1;if(l&&(r=function(t){for(var e=0;e0){h.b.warn("[mp4-remuxer]: dropped "+r+" out of "+b+" video samples due to a missing keyframe");var k=this.getvideostartpts(e.samples);e.samples=e.samples.slice(r),e.dropped+=r,m+=(e.samples[0].pts-k)/(e.timescale||9e4)}else-1===r&&(h.b.warn("[mp4-remuxer]: no keyframe found out of "+b+" video samples"),v=!1);if(this.isgenerated){if(s&&l){var d=this.getvideostartpts(e.samples),_=(y(t.samples[0].pts,d)-d)/e.inputtimescale;p+=math.max(0,_),m+=math.max(0,-_)}if(s){if(t.samplerate||(h.b.warn("[mp4-remuxer]: regenerate initsegment as audio detected"),c=this.generateis(t,e,a)),u=this.remuxaudio(t,p,this.isaudiocontiguous,n,e||l||o===d.b.audio?m:void 0),l){var i=u?u.endpts-u.startpts:0;e.inputtimescale||(h.b.warn("[mp4-remuxer]: regenerate initsegment as video detected"),c=this.generateis(t,e,a)),l=this.remuxvideo(e,m,a,i)}}else l&&(l=this.remuxvideo(e,m,a,0));l&&(l.firstkeyframe=r,l.independent=-1!==r)}}return this.isgenerated&&(r.samples.length&&(g=this.remuxid3(r,a)),i.samples.length&&(f=this.remuxtext(i,a))),{audio:u,video:l,initsegment:c,independent:v,text:f,id3:g}},e.generateis=function(t,e,r){var a,n,s,l=t.samples,u=e.samples,h=this.typesupported,d={},c=!object(i.a)(this._initpts),f="audio/mp4";if(c&&(a=n=1/0),t.config&&l.length&&(t.timescale=t.samplerate,t.isaac||(h.mpeg?(f="audio/mpeg",t.codec=""):h.mp3&&(t.codec="mp3")),d.audio={id:"audio",container:f,codec:t.codec,initsegment:!t.isaac&&h.mpeg?new uint8array(0):o.initsegment([t]),metadata:{channelcount:t.channelcount}},c&&(s=t.inputtimescale,a=n=l[0].pts-math.round(s*r))),e.sps&&e.pps&&u.length&&(e.timescale=e.inputtimescale,d.video={id:"main",container:"video/mp4",codec:e.codec,initsegment:o.initsegment([e]),metadata:{width:e.width,height:e.height}},c)){s=e.inputtimescale;var g=this.getvideostartpts(u),v=math.round(s*r);n=math.min(n,y(u[0].dts,g)-v),a=math.min(a,g-v)}if(object.keys(d).length)return this.isgenerated=!0,c&&(this._initpts=a,this._initdts=n),{tracks:d,initpts:a,timescale:s}},e.remuxvideo=function(t,e,r,i){var a,n,s,d=t.inputtimescale,v=t.samples,m=[],e=v.length,b=this._initpts,s=this.nextavcdts,l=8,a=number.positive_infinity,r=number.negative_infinity,k=0,d=!1;r&&null!==s||(s=e*d-(v[0].pts-y(v[0].dts,v[0].pts)));for(var _=0;_i.pts){k=math.max(math.min(k,i.pts-i.dts),-18e3)}i.dts0?_-1:_].dts&&(d=!0)}d&&v.sort((function(t,e){var r=t.dts-e.dts,i=t.pts-e.pts;return r||i})),n=v[0].dts,s=v[v.length-1].dts;var c=math.round((s-n)/(e-1));if(k<0){if(k<-2*c){h.b.warn("pts < dts detected in video samples, offsetting dts from pts by "+object(c.b)(-c,!0)+" ms");for(var w=k,o=0;oc;if(f||p<-1){f?h.b.warn("avc: "+object(c.b)(p,!0)+" ms ("+p+"dts) hole between fragments detected, filling it"):h.b.warn("avc: "+object(c.b)(-p,!0)+" ms ("+p+"dts) overlapping between fragments detected"),n=s;var m=v[0].pts-p;v[0].dts=n,v[0].pts=m,h.b.log("video: first pts/dts adjusted: "+object(c.b)(m,!0)+"/"+object(c.b)(n,!0)+", delta: "+object(c.b)(p,!0)+" ms")}}p&&(n=math.max(0,n));for(var n=0,u=0,b=0;b0?x-1:x].dts;if(it.stretchshortvideotrack&&null!==this.nextaudiopts){var nt=math.floor(it.maxbufferhole*d),st=(i?a+i*d:this.nextaudiopts)-z.pts;st>nt?((a=st-at)<0&&(a=at),h.b.log("[mp4-remuxer]: it is approximately "+st/90+" ms to the next segment; using duration "+a/90+" ms for the last video frame.")):a=at}else a=at}var ot=math.round(z.pts-z.dts);m.push(new t(z.key,a,$,ot))}if(m.length&&g&&g<70){var lt=m[0].flags;lt.dependson=2,lt.isnonsync=0}this.nextavcdts=s=s+a,this.isvideocontiguous=!0;var ut={data1:o.moof(t.sequencenumber++,n,f({},t,{samples:m})),data2:w,startpts:a/d,endpts:(r+a)/d,startdts:n/d,enddts:s/d,type:"video",hasaudio:!1,hasvideo:!0,nb:m.length,dropped:t.dropped};return t.samples=[],t.dropped=0,ut},e.remuxaudio=function(t,e,r,i,n){var s=t.inputtimescale,d=s/(t.samplerate?t.samplerate:s),c=t.isaac?1024:1152,g=c*d,v=this._initpts,p=!t.isaac&&this.typesupported.mpeg,m=[],e=t.samples,b=p?0:8,s=this.nextaudiopts||-1,l=e*s;if(this.isaudiocontiguous=r=r||e.length&&s>0&&(i&&math.abs(l-s)<9e3||math.abs(y(e[0].pts-v,l)-s)<20*g),e.foreach((function(t){t.pts=y(t.pts-v,l)})),!r||s<0){if(!(e=e.filter((function(t){return t.pts>=0}))).length)return;s=0===n?0:i?math.max(0,l):e[0].pts}if(t.isaac)for(var a=void 0!==n,r=this.config.maxaudioframesdrift,k=0,d=s;k=r*g&&w<1e4&&a){var o=math.round(c/g);(d=i-o*g)<0&&(o--,d+=g),0===k&&(this.nextaudiopts=s=d),h.b.warn("[mp4-remuxer]: injecting "+o+" audio frame @ "+(d/s).tofixed(3)+"s due to "+math.round(1e3*c/s)+" ms gap.");for(var x=0;x0))return;b+=b;try{m=new uint8array(b)}catch(t){return void this.observer.emit(l.a.error,l.a.error,{type:u.b.mux_error,details:u.a.remux_alloc_error,fatal:!1,bytes:b,reason:"fail allocating audio mdat "+b})}p||(new dataview(m.buffer).setuint32(0,b),m.set(o.types.mdat,4))}m.set(v,b);var y=v.bytelength;b+=y,m.push(new t(!0,c,y,0)),u=w}var q=m.length;if(q){var x=m[m.length-1];this.nextaudiopts=s=u+d*x.duration;var z=p?new uint8array(0):o.moof(t.sequencenumber++,n/d,f({},t,{samples:m}));t.samples=[];var q=n/s,$=s/s,j={data1:z,data2:m,startpts:q,endpts:$,startdts:q,enddts:$,type:"audio",hasaudio:!0,hasvideo:!1,nb:q};return this.isaudiocontiguous=!0,j}},e.remuxemptyaudio=function(t,e,r,i){var n=t.inputtimescale,s=n/(t.samplerate?t.samplerate:n),o=this.nextaudiopts,l=(null!==o?o:i.startdts*n)+this._initdts,u=i.enddts*n+this._initdts,d=1024*s,c=math.ceil((u-l)/d),f=a.getsilentframe(t.manifestcodec||t.codec,t.channelcount);if(h.b.warn("[mp4-remuxer]: remux empty audio"),f){for(var g=[],v=0;v4294967296;)t+=r;return t}var t=function(t,e,r,i){this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=e,this.size=r,this.cts=i,this.flags=new e(t)},e=function(t){this.isleading=0,this.isdependedon=0,this.hasredundancy=0,this.degradprio=0,this.dependson=1,this.isnonsync=1,this.dependson=t?2:1,this.isnonsync=t?0:1}},function(t,e,r){"use strict";r.d(e,"a",(function(){return n}));var i=r(11);function a(t,e){for(var r=0;r0}),!1)}t.exports=function(t,e){e=e||{};var a={main:r.m},o=e.all?{main:object.keys(a.main)}:function(t,e){for(var r={main:[e]},i={main:[]},a={main:{}};s(r);)for(var o=object.keys(r),l=0;lt.endsn||e>0||0===e&&r>0,this.updated||this.advanced?this.misses=math.floor(.6*t.misses):this.misses=t.misses+1,this.availabilitydelay=t.availabilitydelay},e=t,(r=[{key:"hasprogramdatetime",get:function(){return!!this.fragments.length&&object(a.a)(this.fragments[this.fragments.length-1].programdatetime)}},{key:"leveltargetduration",get:function(){return this.averagetargetduration||this.targetduration||10}},{key:"drift",get:function(){var t=this.driftendtime-this.driftstarttime;return t>0?1e3*(this.driftend-this.driftstart)/t:1}},{key:"edge",get:function(){return this.partend||this.fragmentend}},{key:"partend",get:function(){var t;return null!==(t=this.partlist)&&void 0!==t&&t.length?this.partlist[this.partlist.length-1].end:this.fragmentend}},{key:"fragmentend",get:function(){var t;return null!==(t=this.fragments)&&void 0!==t&&t.length?this.fragments[this.fragments.length-1].end:0}},{key:"age",get:function(){return this.advanceddatetime?math.max(date.now()-this.advanceddatetime,0)/1e3:0}},{key:"lastpartindex",get:function(){var t;return null!==(t=this.partlist)&&void 0!==t&&t.length?this.partlist[this.partlist.length-1].index:-1}},{key:"lastpartsn",get:function(){var t;return null!==(t=this.partlist)&&void 0!==t&&t.length?this.partlist[this.partlist.length-1].fragment.sn:this.endsn}}])&&h(e.prototype,r),i&&h(e,i),t}(),c=r(17),f=/^(\d+)x(\d+)$/,g=/\s*(.+?)\s*=((?:\".*?\")|.*?)(?:,|$)/g,v=function(){function t(e){for(var r in"string"==typeof e&&(e=t.parseattrlist(e)),e)e.hasownproperty(r)&&(this[r]=e[r])}var e=t.prototype;return e.decimalinteger=function(t){var e=parseint(this[t],10);return e>number.max_safe_integer?1/0:e},e.hexadecimalinteger=function(t){if(this[t]){var e=(this[t]||"0x").slice(2);e=(1&e.length?"0":"")+e;for(var r=new uint8array(e.length/2),i=0;inumber.max_safe_integer?1/0:e},e.decimalfloatingpoint=function(t){return parsefloat(this[t])},e.optionalfloat=function(t,e){var r=this[t];return r?parsefloat(r):e},e.enumeratedstring=function(t){return this[t]},e.bool=function(t){return"yes"===this[t]},e.decimalresolution=function(t){var e=f.exec(this[t]);if(null!==e)return{width:parseint(e[1],10),height:parseint(e[2],10)}},t.parseattrlist=function(t){var e,r={};for(g.lastindex=0;null!==(e=g.exec(t));){var i=e[2];0===i.indexof('"')&&i.lastindexof('"')===i.length-1&&(i=i.slice(1,-1)),r[e[1]]=i}return r},t}(),p={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,av01:!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},text:{stpp:!0,wvtt:!0}};function m(t,e){return mediasource.istypesupported((e||"video")+'/mp4;codecs="'+t+'"')}var y=/#ext-x-stream-inf:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#ext-x-session-data:([^\r\n]*)[\r\n]+/g,t=/#ext-x-media:(.*)/g,e=new regexp([/#extinf:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\s[\s ]*)/.source,/#ext-x-byterange:*(.+)/.source,/#ext-x-program-date-time:(.+)/.source,/#.*/.source].join("|"),"g"),b=new regexp([/#(extm3u)/.source,/#ext-x-(playlist-type):(.+)/.source,/#ext-x-(media-sequence): *(\d+)/.source,/#ext-x-(skip):(.+)/.source,/#ext-x-(targetduration): *(\d+)/.source,/#ext-x-(key):(.+)/.source,/#ext-x-(start):(.+)/.source,/#ext-x-(endlist)/.source,/#ext-x-(discontinuity-seq)uence: *(\d+)/.source,/#ext-x-(dis)continuity/.source,/#ext-x-(version):(\d+)/.source,/#ext-x-(map):(.+)/.source,/#ext-x-(server-control):(.+)/.source,/#ext-x-(part-inf):(.+)/.source,/#ext-x-(gap)/.source,/#ext-x-(bitrate):\s*(\d+)/.source,/#ext-x-(part):(.+)/.source,/#ext-x-(preload-hint):(.+)/.source,/#ext-x-(rendition-report):(.+)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),s=/\.(mp4|m4s|m4v|m4a)$/i;var l=function(){function t(){}return t.findgroup=function(t,e){for(var r=0;r2){var r=e.shift()+".";return r+=parseint(e.shift()).tostring(16),r+=("000"+parseint(e.shift()).tostring(16)).substr(-4)}return t},t.resolve=function(t,e){return i.buildabsoluteurl(e,t,{alwaysnormalize:!0})},t.parsemasterplaylist=function(e,r){var i,a=[],n={},s=!1;for(y.lastindex=0;null!=(i=y.exec(e));)if(i[1]){var o=new v(i[1]),l={attrs:o,bitrate:o.decimalinteger("average-bandwidth")||o.decimalinteger("bandwidth"),name:o.name,url:t.resolve(i[2],r)},u=o.decimalresolution("resolution");u&&(l.width=u.width,l.height=u.height),a((o.codecs||"").split(/[ ,]+/).filter((function(t){return t})),l),l.videocodec&&-1!==l.videocodec.indexof("avc1")&&(l.videocodec=t.convertavc1toavcoti(l.videocodec)),a.push(l)}else if(i[3]){var h=new v(i[3]);h["data-id"]&&(s=!0,n[h["data-id"]]=h)}return{levels:a,sessiondata:s?n:null}},t.parsemasterplaylistmedia=function(e,r,i,a){var n;void 0===a&&(a=[]);var s=[],o=0;for(t.lastindex=0;null!==(n=t.exec(e));){var l=new v(n[1]);if(l.type===i){var u={attrs:l,bitrate:0,id:o++,groupid:l["group-id"],instreamid:l["instream-id"],name:l.name||l.language||"",type:i,default:l.bool("default"),autoselect:l.bool("autoselect"),forced:l.bool("forced"),lang:l.language,url:l.uri?t.resolve(l.uri,r):""};if(a.length){var h=t.findgroup(a,u.groupid)||a[0];r(u,h,"audiocodec"),r(u,h,"textcodec")}s.push(u)}}return s},t.parselevelplaylist=function(t,e,r,n,s){var l,h,f,g=new d(e),p=g.fragments,m=null,y=0,t=0,l=0,a=0,r=null,d=new u.b(n,e),_=-1,i=!1;for(e.lastindex=0,g.m3u8=t;null!==(l=e.exec(t));){i&&(i=!1,(d=new u.b(n,e)).start=l,d.sn=y,d.cc=a,d.level=r,m&&(d.initsegment=m,d.rawprogramdatetime=m.rawprogramdatetime));var c=l[1];if(c){d.duration=parsefloat(c);var w=(" "+l[2]).slice(1);d.title=w||null,d.taglist.push(w?["inf",c,w]:["inf",c])}else if(l[3])object(a.a)(d.duration)&&(d.start=l,f&&(d.levelkey=f),d.sn=y,d.level=r,d.cc=a,d.urlid=s,p.push(d),d.relurl=(" "+l[3]).slice(1),k(d,r),r=d,l+=d.duration,y++,t=0,i=!0);else if(l[4]){var o=(" "+l[4]).slice(1);r?d.setbyterange(o,r):d.setbyterange(o)}else if(l[5])d.rawprogramdatetime=(" "+l[5]).slice(1),d.taglist.push(["program-date-time",d.rawprogramdatetime]),-1===_&&(_=p.length);else{if(!(l=l[0].match(b))){o.b.warn("no matches on slow regex match for level playlist!");continue}for(h=1;h-1){o.b.warn("keyformat "+q+" is not supported from the manifest");continue}if("identity"!==q)continue;j&&(f=c.a.fromurl(e,h),h&&["aes-128","sample-aes","sample-aes-cenc"].indexof(j)>=0&&(f.method=j,f.keyformat=q,y&&(f.keyid=y),w&&(f.keyformatversions=w),f.iv=v));break;case"start":var x=new v(p).decimalfloatingpoint("time-offset");object(a.a)(x)&&(g.starttimeoffset=x);break;case"map":var z=new v(p);d.relurl=z.uri,z.byterange&&d.setbyterange(z.byterange),d.level=r,d.sn="initsegment",f&&(d.levelkey=f),d.initsegment=null,m=d,i=!0;break;case"server-control":var q=new v(p);g.canblockreload=q.bool("can-block-reload"),g.canskipuntil=q.optionalfloat("can-skip-until",0),g.canskipdateranges=g.canskipuntil>0&&q.bool("can-skip-dateranges"),g.partholdback=q.optionalfloat("part-hold-back",0),g.holdback=q.optionalfloat("hold-back",0);break;case"part-inf":var $=new v(p);g.parttarget=$.decimalfloatingpoint("part-target");break;case"part":var j=g.partlist;j||(j=g.partlist=[]);var z=t>0?j[j.length-1]:void 0,tt=t++,et=new u.c(new v(p),d,e,tt,z);j.push(et),d.duration+=et.duration;break;case"preload-hint":var rt=new v(p);g.preloadhint=rt;break;case"rendition-report":var it=new v(p);g.renditionreports=g.renditionreports||[],g.renditionreports.push(it);break;default:o.b.warn("line parsed but not handled: "+l)}}}r&&!r.relurl?(p.pop(),l-=r.duration,g.partlist&&(g.fragmenthint=r)):g.partlist&&(k(d,r),d.cc=a,g.fragmenthint=d);var at=p.length,nt=p[0],st=p[at-1];if((l+=g.skippedsegments*g.targetduration)>0&&at&&st){g.averagetargetduration=l/at;var ot=st.sn;g.endsn="initsegment"!==ot?ot:0,nt&&(g.startcc=nt.cc,nt.initsegment||g.fragments.every((function(t){return t.relurl&&(e=t.relurl,s.test(null!=(r=null===(a=i.parseurl(e))||void 0===a?void 0:a.path)?r:""));var e,r,a}))&&(o.b.warn("mp4 fragments found but no init segment (probably no map, incomplete m3u8), trying to fetch sidx"),(d=new u.b(n,e)).relurl=st.relurl,d.level=r,d.sn="initsegment",nt.initsegment=d,g.needsidxranges=!0))}else g.endsn=0,g.startcc=0;return g.fragmenthint&&(l+=g.fragmenthint.duration),g.totalduration=l,g.endcc=a,_>0&&function(t,e){for(var r=t[e],i=e;i--;){var a=t[i];if(!a)return;a.programdatetime=r.programdatetime-1e3*a.duration,r=a}}(p,_),g},t}();function a(t,e){["video","audio","text"].foreach((function(r){var i=t.filter((function(t){return function(t,e){var r=p[e];return!!r&&!0===r[t.slice(0,4)]}(t,r)}));if(i.length){var a=i.filter((function(t){return 0===t.lastindexof("avc1",0)||0===t.lastindexof("mp4a",0)}));e[r+"codec"]=a.length>0?a[0]:i[0],t=t.filter((function(t){return-1===i.indexof(t)}))}})),e.unknowncodecs=t}function r(t,e,r){var i=e[r];i&&(t[r]=i)}function k(t,e){t.rawprogramdatetime?t.programdatetime=date.parse(t.rawprogramdatetime):null!=e&&e.programdatetime&&(t.programdatetime=e.endprogramdatetime),object(a.a)(t.programdatetime)||(t.programdatetime=null,t.rawprogramdatetime=null)}var d=r(4);function _(t,e){var r=t.url;return void 0!==r&&0!==r.indexof("data:")||(r=e.url),r}var i=function(){function t(t){this.hls=void 0,this.loaders=object.create(null),this.hls=t,this.registerlisteners()}var e=t.prototype;return e.registerlisteners=function(){var t=this.hls;t.on(n.a.manifest_loading,this.onmanifestloading,this),t.on(n.a.level_loading,this.onlevelloading,this),t.on(n.a.audio_track_loading,this.onaudiotrackloading,this),t.on(n.a.subtitle_track_loading,this.onsubtitletrackloading,this)},e.unregisterlisteners=function(){var t=this.hls;t.off(n.a.manifest_loading,this.onmanifestloading,this),t.off(n.a.level_loading,this.onlevelloading,this),t.off(n.a.audio_track_loading,this.onaudiotrackloading,this),t.off(n.a.subtitle_track_loading,this.onsubtitletrackloading,this)},e.createinternalloader=function(t){var e=this.hls.config,r=e.ploader,i=e.loader,a=new(r||i)(e);return t.loader=a,this.loaders[t.type]=a,a},e.getinternalloader=function(t){return this.loaders[t.type]},e.resetinternalloader=function(t){this.loaders[t]&&delete this.loaders[t]},e.destroyinternalloaders=function(){for(var t in this.loaders){var e=this.loaders[t];e&&e.destroy(),this.resetinternalloader(t)}},e.destroy=function(){this.unregisterlisteners(),this.destroyinternalloaders()},e.onmanifestloading=function(t,e){var r=e.url;this.load({id:null,groupid:null,level:0,responsetype:"text",type:d.a.manifest,url:r,deliverydirectives:null})},e.onlevelloading=function(t,e){var r=e.id,i=e.level,a=e.url,n=e.deliverydirectives;this.load({id:r,groupid:null,level:i,responsetype:"text",type:d.a.level,url:a,deliverydirectives:n})},e.onaudiotrackloading=function(t,e){var r=e.id,i=e.groupid,a=e.url,n=e.deliverydirectives;this.load({id:r,groupid:i,level:null,responsetype:"text",type:d.a.audio_track,url:a,deliverydirectives:n})},e.onsubtitletrackloading=function(t,e){var r=e.id,i=e.groupid,a=e.url,n=e.deliverydirectives;this.load({id:r,groupid:i,level:null,responsetype:"text",type:d.a.subtitle_track,url:a,deliverydirectives:n})},e.load=function(t){var e,r,i,a,n,s,l=this.hls.config,u=this.getinternalloader(t);if(u){var h=u.context;if(h&&h.url===t.url)return void o.b.trace("[playlist-loader]: playlist request ongoing");o.b.log("[playlist-loader]: aborting previous loader for type: "+t.type),u.abort()}switch(t.type){case d.a.manifest:r=l.manifestloadingmaxretry,i=l.manifestloadingtimeout,a=l.manifestloadingretrydelay,n=l.manifestloadingmaxretrytimeout;break;case d.a.level:case d.a.audio_track:case d.a.subtitle_track:r=0,i=l.levelloadingtimeout;break;default:r=l.levelloadingmaxretry,i=l.levelloadingtimeout,a=l.levelloadingretrydelay,n=l.levelloadingmaxretrytimeout}if((u=this.createinternalloader(t),null!==(e=t.deliverydirectives)&&void 0!==e&&e.part)&&(t.type===d.a.level&&null!==t.level?s=this.hls.levels[t.level].details:t.type===d.a.audio_track&&null!==t.id?s=this.hls.audiotracks[t.id].details:t.type===d.a.subtitle_track&&null!==t.id&&(s=this.hls.subtitletracks[t.id].details),s)){var d=s.parttarget,c=s.targetduration;d&&c&&(i=math.min(1e3*math.max(3*d,.8*c),i))}var f={timeout:i,maxretry:r,retrydelay:a,maxretrydelay:n,highwatermark:0},g={onsuccess:this.loadsuccess.bind(this),onerror:this.loaderror.bind(this),ontimeout:this.loadtimeout.bind(this)};u.load(t,f,g)},e.loadsuccess=function(t,e,r,i){if(void 0===i&&(i=null),r.issidxrequest)return this.handlesidxrequest(t,r),void this.handleplaylistloaded(t,e,r,i);this.resetinternalloader(r.type);var a=t.data;0===a.indexof("#extm3u")?(e.parsing.start=performance.now(),a.indexof("#extinf:")>0||a.indexof("#ext-x-targetduration:")>0?this.handletrackorlevelplaylist(t,e,r,i):this.handlemasterplaylist(t,e,r,i)):this.handlemanifestparsingerror(t,r,"no extm3u delimiter",i)},e.loaderror=function(t,e,r){void 0===r&&(r=null),this.handlenetworkerror(e,r,!1,t)},e.loadtimeout=function(t,e,r){void 0===r&&(r=null),this.handlenetworkerror(e,r,!0)},e.handlemasterplaylist=function(t,e,r,i){var a=this.hls,s=t.data,l=_(t,r),u=l.parsemasterplaylist(s,l),h=u.levels,d=u.sessiondata;if(h.length){var c=h.map((function(t){return{id:t.attrs.audio,audiocodec:t.audiocodec}})),f=h.map((function(t){return{id:t.attrs.subtitles,textcodec:t.textcodec}})),g=l.parsemasterplaylistmedia(s,l,"audio",c),p=l.parsemasterplaylistmedia(s,l,"subtitles",f),m=l.parsemasterplaylistmedia(s,l,"closed-captions");if(g.length)g.some((function(t){return!t.url}))||!h[0].audiocodec||h[0].attrs.audio||(o.b.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),g.unshift({type:"main",name:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new v({}),bitrate:0,url:""}));a.trigger(n.a.manifest_loaded,{levels:h,audiotracks:g,subtitles:p,captions:m,url:l,stats:e,networkdetails:i,sessiondata:d})}else this.handlemanifestparsingerror(t,r,"no level found in manifest",i)},e.handletrackorlevelplaylist=function(t,e,r,i){var o=this.hls,l=r.id,u=r.level,h=r.type,d=_(t,r),c=object(a.a)(l)?l:0,f=object(a.a)(u)?u:c,g=function(t){switch(t.type){case d.a.audio_track:return d.b.audio;case d.a.subtitle_track:return d.b.subtitle;default:return d.b.main}}(r),p=l.parselevelplaylist(t.data,d,f,g,c);if(p.fragments.length){if(h===d.a.manifest){var m={attrs:new v({}),bitrate:0,details:p,name:"",url:d};o.trigger(n.a.manifest_loaded,{levels:[m],audiotracks:[],url:d,stats:e,networkdetails:i,sessiondata:null})}if(e.parsing.end=performance.now(),p.needsidxranges){var y,t=null===(y=p.fragments[0].initsegment)||void 0===y?void 0:y.url;this.load({url:t,issidxrequest:!0,type:h,level:u,leveldetails:p,id:l,groupid:null,rangestart:0,rangeend:2048,responsetype:"arraybuffer",deliverydirectives:null})}else r.leveldetails=p,this.handleplaylistloaded(t,e,r,i)}else o.trigger(n.a.error,{type:s.b.network_error,details:s.a.level_empty_error,fatal:!1,url:d,reason:"no fragments found in level",level:"number"==typeof r.level?r.level:void 0})},e.handlesidxrequest=function(t,e){var r=object(l.g)(new uint8array(t.data));if(r){var i=r.references,a=e.leveldetails;i.foreach((function(t,e){var i=t.info,n=a.fragments[e];0===n.byterange.length&&n.setbyterange(string(1+i.end-i.start)+"@"+string(i.start)),n.initsegment&&n.initsegment.setbyterange(string(r.moovendoffset)+"@0")}))}},e.handlemanifestparsingerror=function(t,e,r,i){this.hls.trigger(n.a.error,{type:s.b.network_error,details:s.a.manifest_parsing_error,fatal:e.type===d.a.manifest,url:t.url,reason:r,response:t,context:e,networkdetails:i})},e.handlenetworkerror=function(t,e,r,i){void 0===r&&(r=!1),o.b.warn("[playlist-loader]: a network "+(r?"timeout":"error")+" occurred while loading "+t.type+" level: "+t.level+" id: "+t.id+' group-id: "'+t.groupid+'"');var a=s.a.unknown,l=!1,u=this.getinternalloader(t);switch(t.type){case d.a.manifest:a=r?s.a.manifest_load_timeout:s.a.manifest_load_error,l=!0;break;case d.a.level:a=r?s.a.level_load_timeout:s.a.level_load_error,l=!1;break;case d.a.audio_track:a=r?s.a.audio_track_load_timeout:s.a.audio_track_load_error,l=!1;break;case d.a.subtitle_track:a=r?s.a.subtitle_track_load_timeout:s.a.subtitle_load_error,l=!1}u&&this.resetinternalloader(t.type);var h={type:s.b.network_error,details:a,fatal:l,url:t.url,loader:u,context:t,networkdetails:e};i&&(h.response=i),this.hls.trigger(n.a.error,h)},e.handleplaylistloaded=function(t,e,r,i){var a=r.type,s=r.level,o=r.id,l=r.groupid,u=r.loader,h=r.leveldetails,d=r.deliverydirectives;if(null!=h&&h.targetduration){if(u)switch(h.live&&(u.getcacheage&&(h.ageheader=u.getcacheage()||0),u.getcacheage&&!isnan(h.ageheader)||(h.ageheader=0)),a){case d.a.manifest:case d.a.level:this.hls.trigger(n.a.level_loaded,{details:h,level:s||0,id:o||0,stats:e,networkdetails:i,deliverydirectives:d});break;case d.a.audio_track:this.hls.trigger(n.a.audio_track_loaded,{details:h,id:o||0,groupid:l||"",stats:e,networkdetails:i,deliverydirectives:d});break;case d.a.subtitle_track:this.hls.trigger(n.a.subtitle_track_loaded,{details:h,id:o||0,groupid:l||"",stats:e,networkdetails:i,deliverydirectives:d})}}else this.handlemanifestparsingerror(t,r,"invalid target duration",i)},t}(),c=function(){function t(t){this.hls=void 0,this.loaders={},this.decryptkey=null,this.decrypturl=null,this.hls=t,this._registerlisteners()}var e=t.prototype;return e._registerlisteners=function(){this.hls.on(n.a.key_loading,this.onkeyloading,this)},e._unregisterlisteners=function(){this.hls.off(n.a.key_loading,this.onkeyloading)},e.destroy=function(){for(var t in this._unregisterlisteners(),this.loaders){var e=this.loaders[t];e&&e.destroy()}this.loaders={}},e.onkeyloading=function(t,e){var r=e.frag,i=r.type,a=this.loaders[i];if(r.decryptdata){var s=r.decryptdata.uri;if(s!==this.decrypturl||null===this.decryptkey){var l=this.hls.config;if(a&&(o.b.warn("abort previous key loader for type:"+i),a.abort()),!s)return void o.b.warn("key uri is falsy");var u=l.loader,h=r.loader=this.loaders[i]=new u(l);this.decrypturl=s,this.decryptkey=null;var d={url:s,frag:r,responsetype:"arraybuffer"},c={timeout:l.fragloadingtimeout,maxretry:0,retrydelay:l.fragloadingretrydelay,maxretrydelay:l.fragloadingmaxretrytimeout,highwatermark:0},f={onsuccess:this.loadsuccess.bind(this),onerror:this.loaderror.bind(this),ontimeout:this.loadtimeout.bind(this)};h.load(d,c,f)}else this.decryptkey&&(r.decryptdata.key=this.decryptkey,this.hls.trigger(n.a.key_loaded,{frag:r}))}else o.b.warn("missing decryption data on fragment in onkeyloading")},e.loadsuccess=function(t,e,r){var i=r.frag;i.decryptdata?(this.decryptkey=i.decryptdata.key=new uint8array(t.data),i.loader=null,delete this.loaders[i.type],this.hls.trigger(n.a.key_loaded,{frag:i})):o.b.error("after key load, decryptdata unset")},e.loaderror=function(t,e){var r=e.frag,i=r.loader;i&&i.abort(),delete this.loaders[r.type],this.hls.trigger(n.a.error,{type:s.b.network_error,details:s.a.key_load_error,fatal:!1,frag:r,response:t})},e.loadtimeout=function(t,e){var r=e.frag,i=r.loader;i&&i.abort(),delete this.loaders[r.type],this.hls.trigger(n.a.error,{type:s.b.network_error,details:s.a.key_load_timeout,fatal:!1,frag:r})},t}();function w(t,e){var r;try{r=new event("addtrack")}catch(t){(r=document.createevent("event")).initevent("addtrack",!1,!1)}r.track=t,e.dispatchevent(r)}function o(t,e){var r=t.mode;if("disabled"===r&&(t.mode="hidden"),t.cues&&!t.cues.getcuebyid(e.id))try{if(t.addcue(e),!t.cues.getcuebyid(e.id))throw new error("addcue is failed for: "+e)}catch(r){o.b.debug("[texttrack-utils]: "+r);var i=new self.texttrackcue(e.starttime,e.endtime,e.text);i.id=e.id,t.addcue(i)}"disabled"===r&&(t.mode=r)}function x(t){var e=t.mode;if("disabled"===e&&(t.mode="hidden"),t.cues)for(var r=t.cues.length;r--;)t.removecue(t.cues[r]);"disabled"===e&&(t.mode=e)}function p(t,e,r){var i=t.mode;if("disabled"===i&&(t.mode="hidden"),t.cues&&t.cues.length>0)for(var a=function(t,e,r){var i=[],a=function(t,e){if(et[r].endtime)return-1;var i=0,a=r;for(;i<=a;){var n=math.floor((a+i)/2);if(et[n].starttime&&i-1)for(var n=a,s=t.length;n=e&&o.endtime<=r)i.push(o);else if(o.starttime>r)return i}return i}(t.cues,e,r),n=0;n.05&&this.forwardbufferlength>1){var u=math.min(2,math.max(1,n)),h=math.round(2/(1+math.exp(-.75*o-this.edgestalled))*20)/20;t.playbackrate=math.min(u,math.max(1,h))}else 1!==t.playbackrate&&0!==t.playbackrate&&(t.playbackrate=1)}}}}},a.estimateliveedge=function(){var t=this.leveldetails;return null===t?null:t.edge+t.age},a.computelatency=function(){var t=this.estimateliveedge();return null===t?null:t-this.currenttime},e=t,(r=[{key:"latency",get:function(){return this._latency||0}},{key:"maxlatency",get:function(){var t=this.config,e=this.leveldetails;return void 0!==t.livemaxlatencyduration?t.livemaxlatencyduration:e?t.livemaxlatencydurationcount*e.targetduration:0}},{key:"targetlatency",get:function(){var t=this.leveldetails;if(null===t)return null;var e=t.holdback,r=t.partholdback,i=t.targetduration,a=this.config,n=a.livesyncduration,s=a.livesyncdurationcount,o=a.lowlatencymode,l=this.hls.userconfig,u=o&&r||e;(l.livesyncduration||l.livesyncdurationcount||0===u)&&(u=void 0!==n?n:s*i);var h=i;return u+math.min(1*this.stallcount,h)}},{key:"livesyncposition",get:function(){var t=this.estimateliveedge(),e=this.targetlatency,r=this.leveldetails;if(null===t||null===e||null===r)return null;var i=r.edge,a=t-e-this.edgestalled,n=i-r.totalduration,s=i-(this.config.lowlatencymode&&r.parttarget||r.targetduration);return math.min(math.max(n,a),s)}},{key:"drift",get:function(){var t=this.leveldetails;return null===t?1:t.drift}},{key:"edgestalled",get:function(){var t=this.leveldetails;if(null===t)return 0;var e=3*(this.config.lowlatencymode&&t.parttarget||t.targetduration);return math.max(t.age-e,0)}},{key:"forwardbufferlength",get:function(){var t=this.media,e=this.leveldetails;if(!t||!e)return 0;var r=t.buffered.length;return r?t.buffered.end(r-1):e.edge-this.currenttime}}])&&n(e.prototype,r),i&&n(e,i),t}();function g(t,e){for(var r=0;rt.sn?(n=r-t.start,i=t):(n=t.start-r,i=e),i.duration!==n&&(i.duration=n)}else if(e.sn>t.sn){t.cc===e.cc&&t.minendpts?e.start=t.start+(t.minendpts-t.start):e.start=t.start+t.duration}else e.start=math.max(t.start-e.duration,0)}function y(t,e,r,i,n,s){i-r<=0&&(o.b.warn("fragment should have a positive duration",e),i=r+e.duration,s=n+e.duration);var l=r,u=i,h=e.startpts,d=e.endpts;if(object(a.a)(h)){var c=math.abs(h-r);object(a.a)(e.deltapts)?e.deltapts=math.max(c,e.deltapts):e.deltapts=c,l=math.max(r,h),r=math.min(r,h),n=math.min(n,e.startdts),u=math.min(i,d),i=math.max(i,d),s=math.max(s,e.enddts)}e.duration=i-r;var f=r-e.start;e.appendedpts=i,e.start=e.startpts=r,e.maxstartpts=l,e.startdts=n,e.endpts=i,e.minendpts=u,e.enddts=s;var g,v=e.sn;if(!t||vt.endsn)return 0;var p=v-t.startsn,m=t.fragments;for(m[p]=e,g=p;g>0;g--)w(m[g],m[g-1]);for(g=p;g=0;n--){var s=i[n].initsegment;if(s){r=s;break}}t.fragmenthint&&delete t.fragmenthint.endpts;var l,u=0;if(function(t,e,r){for(var i=e.skippedsegments,a=math.max(t.startsn,e.startsn)-e.startsn,n=(t.fragmenthint?1:0)+(i?e.endsn:math.min(t.endsn,e.endsn))-e.startsn,s=e.startsn-t.startsn,o=e.fragmenthint?e.fragments.concat(e.fragmenthint):e.fragments,l=t.fragmenthint?t.fragments.concat(t.fragmenthint):t.fragments,u=a;u<=n;u++){var h=l[s+u],d=o[u];i&&!d&&u=i.length||z(e,i[r].start)}function z(t,e){if(e){for(var r=t.fragments,i=t.skippedsegments;ie.parttarget&&(l+=1)}if(object(a.a)(o))return new k(o,object(a.a)(l)?l:void 0,u.no)}}},e.loadplaylist=function(t){},e.shouldloadtrack=function(t){return this.canload&&t&&!!t.url&&(!t.details||t.details.live)},e.playlistloaded=function(t,e,r){var i=this,a=e.details,n=e.stats,s=n.loading.end?math.max(0,self.performance.now()-n.loading.end):0;if(a.advanceddatetime=date.now()-s,a.live||null!=r&&r.live){if(a.reloaded(r),r&&this.log("live playlist "+t+" "+(a.advanced?"refreshed "+a.lastpartsn+"-"+a.lastpartindex:"missed")),r&&a.fragments.length>0&&q(r,a),!this.canload||!a.live)return;var o,l=void 0,u=void 0;if(a.canblockreload&&a.endsn&&a.advanced){var h=this.hls.config.lowlatencymode,d=a.lastpartsn,c=a.endsn,f=a.lastpartindex,g=d===c;-1!==f?(l=g?c+1:d,u=g?h?0:f:f+1):l=c+1;var v=a.age,p=v+a.ageheader,m=math.min(p-a.parttarget,1.5*a.targetduration);if(m>0){if(r&&m>r.tuneingoal)this.warn("cdn tune-in goal increased from: "+r.tuneingoal+" to: "+m+" with playlist age: "+a.age),m=0;else{var y=math.floor(m/a.targetduration);if(l+=y,void 0!==u)u+=math.round(m%a.targetduration/a.parttarget);this.log("cdn tune-in age: "+a.ageheader+"s last advanced "+v.tofixed(2)+"s goal: "+m+" skip sn "+y+" to part "+u)}a.tuneingoal=m}if(o=this.getdeliverydirectives(a,e.deliverydirectives,l,u),h||!g)return void this.loadplaylist(o)}else o=this.getdeliverydirectives(a,e.deliverydirectives,l,u);var t=function(t,e){var r,i=1e3*t.leveltargetduration,a=i/2,n=t.age,s=n>0&&n<3*i,o=e.loading.end-e.loading.start,l=t.availabilitydelay;if(!1===t.updated)if(s){var u=333*t.misses;r=math.max(math.min(a,2*o),u),t.availabilitydelay=(t.availabilitydelay||0)+r}else r=a;else s?(l=math.min(l||i/2,n),t.availabilitydelay=l,r=l+i-n):r=i-o;return math.round(r)}(a,n);void 0!==l&&a.canblockreload&&(t-=a.parttarget||1),this.log("reload live playlist "+t+" in "+math.round(t)+" ms"),this.timer=self.settimeout((function(){return i.loadplaylist(o)}),t)}else this.cleartimer()},e.getdeliverydirectives=function(t,e,r,i){var a=function(t,e){var r=t.canskipuntil,i=t.canskipdateranges,a=t.endsn;return r&&(void 0!==e?e-a:0)-1&&null!==(e=t.context)&&void 0!==e&&e.deliverydirectives)this.warn("retry playlist loading #"+this.retrycount+' after "'+t.details+'"'),this.loadplaylist();else{var n=math.min(math.pow(2,this.retrycount)*i.levelloadingretrydelay,i.levelloadingmaxretrytimeout);this.timer=self.settimeout((function(){return r.loadplaylist()}),n),this.warn("retry playlist loading #"+this.retrycount+" in "+n+' ms after "'+t.details+'"')}else this.warn('cannot recover from error "'+t.details+'"'),this.cleartimer(),t.fatal=!0;return a},t}();function $(){return($=object.assign||function(t){for(var e=1;e0){r=a[0].bitrate,a.sort((function(t,e){return t.bitrate-e.bitrate})),this._levels=a;for(var f=0;fthis.hls.config.fragloadingmaxretry&&(n=r.frag.level)):n=r.frag.level}break;case s.a.level_load_error:case s.a.level_load_timeout:i&&(i.deliverydirectives&&(l=!1),n=i.level),o=!0;break;case s.a.remux_alloc_error:n=r.level,o=!0}void 0!==n&&this.recoverlevel(r,n,o,l)}}},u.recoverlevel=function(t,e,r,i){var a=t.details,n=this._levels[e];if(n.loaderror++,r){if(!this.retryloadingorfail(t))return void(this.currentlevelindex=-1);t.levelretry=!0}if(i){var s=n.url.length;if(s>1&&n.loaderror1){var i=(e.urlid+1)%r;this.warn("switching to redundant url-id "+i),this._levels.foreach((function(t){t.urlid=i})),this.level=t}},u.onfragloaded=function(t,e){var r=e.frag;if(void 0!==r&&r.type===d.b.main){var i=this._levels[r.level];void 0!==i&&(i.fragmenterror=0,i.loaderror=0)}},u.onlevelloaded=function(t,e){var r,i,a=e.level,n=e.details,s=this._levels[a];if(!s)return this.warn("invalid level index "+a),void(null!==(i=e.deliverydirectives)&&void 0!==i&&i.skip&&(n.deltaupdatefailed=!0));a===this.currentlevelindex?(0===s.fragmenterror&&(s.loaderror=0,this.retrycount=0),this.playlistloaded(a,e,s.details)):null!==(r=e.deliverydirectives)&&void 0!==r&&r.skip&&(n.deltaupdatefailed=!0)},u.onaudiotrackswitched=function(t,e){var r=this.hls.levels[this.currentlevelindex];if(r&&r.audiogroupids){for(var i=-1,a=this.hls.audiotracks[e.id].groupid,n=0;n0){var i=r.urlid,a=r.url[i];if(t)try{a=t.adddirectives(a)}catch(t){this.warn("could not construct new url with hls delivery directives: "+t)}this.log("attempt loading level index "+e+(t?" at sn "+t.msn+" part "+t.part:"")+" with url-id "+i+" "+a),this.cleartimer(),this.hls.trigger(n.a.level_loading,{url:a,level:e,id:i,deliverydirectives:t||null})}},u.removelevel=function(t,e){var r=function(t,r){return r!==e},i=this._levels.filter((function(i,a){return a!==t||i.url.length>1&&void 0!==e&&(i.url=i.url.filter(r),i.audiogroupids&&(i.audiogroupids=i.audiogroupids.filter(r)),i.textgroupids&&(i.textgroupids=i.textgroupids.filter(r)),i.urlid=0,!0)})).map((function(t,e){var r=t.details;return null!=r&&r.fragments&&r.fragments.foreach((function(t){t.level=e})),t}));this._levels=i,this.hls.trigger(n.a.levels_updated,{levels:i})},a=i,(o=[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentlevelindex},set:function(t){var e,r=this._levels;if(0!==r.length&&(this.currentlevelindex!==t||null===(e=r[t])||void 0===e||!e.details)){if(t<0||t>=r.length){var i=t<0;if(this.hls.trigger(n.a.error,{type:s.b.other_error,details:s.a.level_switch_error,level:t,fatal:i,reason:"invalid level idx"}),i)return;t=math.min(t,r.length-1)}this.cleartimer();var a=this.currentlevelindex,o=r[a],l=r[t];this.log("switching to level "+t+" from "+a),this.currentlevelindex=t;var u=$({},l,{level:t,maxbitrate:l.maxbitrate,uri:l.uri,urlid:l.urlid});delete u._urlid,this.hls.trigger(n.a.level_switching,u);var h=l.details;if(!h||h.live){var d=this.switchparams(l.uri,null==o?void 0:o.details);this.loadplaylist(d)}}}},{key:"manuallevel",get:function(){return this.manuallevelindex},set:function(t){this.manuallevelindex=t,void 0===this._startlevel&&(this._startlevel=t),-1!==t&&(this.level=t)}},{key:"firstlevel",get:function(){return this._firstlevel},set:function(t){this._firstlevel=t}},{key:"startlevel",get:function(){if(void 0===this._startlevel){var t=this.hls.config.startlevel;return void 0!==t?t:this._firstlevel}return this._startlevel},set:function(t){this._startlevel=t}},{key:"nextloadlevel",get:function(){return-1!==this.manuallevelindex?this.manuallevelindex:this.hls.nextautolevel},set:function(t){this.level=t,-1===this.manuallevelindex&&(this.hls.nextautolevel=t)}}])&&j(a.prototype,o),l&&j(a,l),i}(q);!function(t){t.not_loaded="not_loaded",t.backtracked="backtracked",t.appending="appending",t.partial="partial",t.ok="ok"}(tt||(tt={}));var it=function(){function t(t){this.activefragment=null,this.activeparts=null,this.fragments=object.create(null),this.timeranges=object.create(null),this.bufferpadding=.2,this.hls=void 0,this.hls=t,this._registerlisteners()}var e=t.prototype;return e._registerlisteners=function(){var t=this.hls;t.on(n.a.buffer_appended,this.onbufferappended,this),t.on(n.a.frag_buffered,this.onfragbuffered,this),t.on(n.a.frag_loaded,this.onfragloaded,this)},e._unregisterlisteners=function(){var t=this.hls;t.off(n.a.buffer_appended,this.onbufferappended,this),t.off(n.a.frag_buffered,this.onfragbuffered,this),t.off(n.a.frag_loaded,this.onfragloaded,this)},e.destroy=function(){this._unregisterlisteners(),this.fragments=this.timeranges=null},e.getappendedfrag=function(t,e){if(e===d.b.main){var r=this.activefragment,i=this.activeparts;if(!r)return null;if(i)for(var a=i.length;a--;){var n=i[a],s=n?n.end:r.appendedpts;if(n.start<=t&&void 0!==s&&t<=s)return a>9&&(this.activeparts=i.slice(a-9)),n}else if(r.start<=t&&void 0!==r.appendedpts&&t<=r.appendedpts)return r}return this.getbufferedfrag(t,e)},e.getbufferedfrag=function(t,e){for(var r=this.fragments,i=object.keys(r),a=i.length;a--;){var n=r[i[a]];if((null==n?void 0:n.body.type)===e&&n.buffered){var s=n.body;if(s.start<=t&&t<=s.end)return s}}return null},e.detectevictedfragments=function(t,e,r){var i=this;object.keys(this.fragments).foreach((function(a){var n=i.fragments[a];if(n)if(n.buffered){var s=n.range[t];s&&s.time.some((function(t){var r=!i.istimebuffered(t.startpts,t.endpts,e);return r&&i.removefragment(n.body),r}))}else n.body.type===r&&i.removefragment(n.body)}))},e.detectpartialfragments=function(t){var e=this,r=this.timeranges,i=t.frag,a=t.part;if(r&&"initsegment"!==i.sn){var n=nt(i),s=this.fragments[n];s&&(object.keys(r).foreach((function(t){var n=i.elementarystreams[t];if(n){var o=r[t],l=null!==a||!0===n.partial;s.range[t]=e.getbufferedtimes(i,a,l,o)}})),s.backtrack=s.loaded=null,object.keys(s.range).length?s.buffered=!0:this.removefragment(s.body))}},e.fragbuffered=function(t){var e=nt(t),r=this.fragments[e];r&&(r.backtrack=r.loaded=null,r.buffered=!0)},e.getbufferedtimes=function(t,e,r,i){for(var a={time:[],partial:r},n=e?e.start:t.start,s=e?e.end:t.end,o=t.minendpts||s,l=t.maxstartpts||n,u=0;u=h&&o<=d){a.time.push({startpts:math.max(n,i.start(u)),endpts:math.min(s,i.end(u))});break}if(nh)a.partial=!0,a.time.push({startpts:math.max(n,i.start(u)),endpts:math.min(s,i.end(u))});else if(s<=h)break}return a},e.getpartialfragment=function(t){var e,r,i,a=null,n=0,s=this.bufferpadding,o=this.fragments;return object.keys(o).foreach((function(l){var u=o[l];u&&at(u)&&(r=u.body.start-s,i=u.body.end+s,t>=r&&t<=i&&(e=math.min(t-r,i-t),n<=e&&(a=u.body,n=e)))})),a},e.getstate=function(t){var e=nt(t),r=this.fragments[e];return r?r.buffered?at(r)?tt.partial:tt.ok:r.backtrack?tt.backtracked:tt.appending:tt.not_loaded},e.backtrack=function(t,e){var r=nt(t),i=this.fragments[r];if(!i||i.backtrack)return null;var a=i.backtrack=e||i.loaded;return i.loaded=null,a},e.getbacktrackdata=function(t){var e=nt(t),r=this.fragments[e];if(r){var i,a=r.backtrack;if(null!=a&&null!==(i=a.payload)&&void 0!==i&&i.bytelength)return a;this.removefragment(t)}return null},e.istimebuffered=function(t,e,r){for(var i,a,n=0;n=i&&e<=a)return!0;if(e<=i)return!1}return!1},e.onfragloaded=function(t,e){var r=e.frag,i=e.part;if("initsegment"!==r.sn&&!r.bitratetest&&!i){var a=nt(r);this.fragments[a]={body:r,loaded:e,backtrack:null,buffered:!1,range:object.create(null)}}},e.onbufferappended=function(t,e){var r=this,i=e.frag,a=e.part,n=e.timeranges;if(i.type===d.b.main)if(this.activefragment=i,a){var s=this.activeparts;s||(this.activeparts=s=[]),s.push(a)}else this.activeparts=null;this.timeranges=n,object.keys(n).foreach((function(t){var e=n[t];if(r.detectevictedfragments(t,e),!a)for(var s=0;st&&i.removefragment(s)}}))},e.removefragment=function(t){var e=nt(t);t.stats.loaded=0,t.clearelementarystreaminfo(),delete this.fragments[e]},e.removeallfragments=function(){this.fragments=object.create(null),this.activefragment=null,this.activeparts=null},t}();function at(t){var e,r;return t.buffered&&((null===(e=t.range.video)||void 0===e?void 0:e.partial)||(null===(r=t.range.audio)||void 0===r?void 0:r.partial))}function nt(t){return t.type+"_"+t.level+"_"+t.urlid+"_"+t.sn}var st=function(){function t(){this._boundtick=void 0,this._ticktimer=null,this._tickinterval=null,this._tickcallcount=0,this._boundtick=this.tick.bind(this)}var e=t.prototype;return e.destroy=function(){this.onhandlerdestroying(),this.onhandlerdestroyed()},e.onhandlerdestroying=function(){this.clearnexttick(),this.clearinterval()},e.onhandlerdestroyed=function(){},e.hasinterval=function(){return!!this._tickinterval},e.hasnexttick=function(){return!!this._ticktimer},e.setinterval=function(t){return!this._tickinterval&&(this._tickinterval=self.setinterval(this._boundtick,t),!0)},e.clearinterval=function(){return!!this._tickinterval&&(self.clearinterval(this._tickinterval),this._tickinterval=null,!0)},e.clearnexttick=function(){return!!this._ticktimer&&(self.cleartimeout(this._ticktimer),this._ticktimer=null,!0)},e.tick=function(){this._tickcallcount++,1===this._tickcallcount&&(this.dotick(),this._tickcallcount>1&&this.tickimmediate(),this._tickcallcount=0)},e.tickimmediate=function(){this.clearnexttick(),this._ticktimer=self.settimeout(this._boundtick,0)},e.dotick=function(){},t}(),ot={length:0,start:function(){return 0},end:function(){return 0}},lt=function(){function t(){}return t.isbuffered=function(e,r){try{if(e)for(var i=t.getbuffered(e),a=0;a=i.start(a)&&r<=i.end(a))return!0}catch(t){}return!1},t.bufferinfo=function(e,r,i){try{if(e){var a,n=t.getbuffered(e),s=[];for(a=0;as&&(i[n-1].end=t[a].end):i.push(t[a])}else i.push(t[a])}else i=t;for(var o,l=0,u=e,h=e,d=0;d=c&&er.startcc||t&&t.cc0)r=a+1;else{if(!(s<0))return n;i=a-1}}return null}};function vt(t,e,r){if(null===e||!array.isarray(t)||!t.length||!object(a.a)(e))return null;if(e<(t[0].programdatetime||0))return null;if(e>=(t[t.length-1].endprogramdatetime||0))return null;r=r||0;for(var i=0;it&&r.start?-1:0}function yt(t,e,r){var i=1e3*math.min(e,r.duration+(r.deltapts?r.deltapts:0));return(r.endprogramdatetime||0)-i>t}function tt(t){var e="function"==typeof map?new map:void 0;return(tt=function(t){if(null===t||(r=t,-1===function.tostring.call(r).indexof("[native code]")))return t;var r;if("function"!=typeof t)throw new typeerror("super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return et(t,arguments,lt(this).constructor)}return i.prototype=object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),st(i,t)})(t)}function et(t,e,r){return(et=bt()?reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var a=new(function.bind.apply(t,i));return r&&st(a,r.prototype),a}).apply(null,arguments)}function bt(){if("undefined"==typeof reflect||!reflect.construct)return!1;if(reflect.construct.sham)return!1;if("function"==typeof proxy)return!0;try{return boolean.prototype.valueof.call(reflect.construct(boolean,[],(function(){}))),!0}catch(t){return!1}}function st(t,e){return(st=object.setprototypeof||function(t,e){return t.__proto__=e,t})(t,e)}function lt(t){return(lt=object.setprototypeof?object.getprototypeof:function(t){return t.__proto__||object.getprototypeof(t)})(t)}var at=math.pow(2,17),rt=function(){function t(t){this.config=void 0,this.loader=null,this.partloadtimeout=-1,this.config=t}var e=t.prototype;return e.destroy=function(){this.loader&&(this.loader.destroy(),this.loader=null)},e.abort=function(){this.loader&&this.loader.abort()},e.load=function(t,e){var r=this,i=t.url;if(!i)return promise.reject(new dt({type:s.b.network_error,details:s.a.frag_load_error,fatal:!1,frag:t,networkdetails:null},"fragment does not have a "+(i?"part list":"url")));this.abort();var a=this.config,n=a.floader,o=a.loader;return new promise((function(i,l){r.loader&&r.loader.destroy();var u=r.loader=t.loader=n?new n(a):new o(a),h=kt(t),d={timeout:a.fragloadingtimeout,maxretry:0,retrydelay:0,maxretrydelay:a.fragloadingmaxretrytimeout,highwatermark:at};t.stats=u.stats,u.load(h,d,{onsuccess:function(e,a,n,s){r.resetloader(t,u),i({frag:t,part:null,payload:e.data,networkdetails:s})},onerror:function(e,i,a){r.resetloader(t,u),l(new dt({type:s.b.network_error,details:s.a.frag_load_error,fatal:!1,frag:t,response:e,networkdetails:a}))},onabort:function(e,i,a){r.resetloader(t,u),l(new dt({type:s.b.network_error,details:s.a.internal_aborted,fatal:!1,frag:t,networkdetails:a}))},ontimeout:function(e,i,a){r.resetloader(t,u),l(new dt({type:s.b.network_error,details:s.a.frag_load_timeout,fatal:!1,frag:t,networkdetails:a}))},onprogress:function(r,i,a,n){e&&e({frag:t,part:null,payload:a,networkdetails:n})}})}))},e.loadpart=function(t,e,r){var i=this;this.abort();var a=this.config,n=a.floader,o=a.loader;return new promise((function(l,u){i.loader&&i.loader.destroy();var h=i.loader=t.loader=n?new n(a):new o(a),d=kt(t,e),c={timeout:a.fragloadingtimeout,maxretry:0,retrydelay:0,maxretrydelay:a.fragloadingmaxretrytimeout,highwatermark:at};e.stats=h.stats,h.load(d,c,{onsuccess:function(a,n,s,o){i.resetloader(t,h),i.updatestatsfrompart(t,e);var u={frag:t,part:e,payload:a.data,networkdetails:o};r(u),l(u)},onerror:function(r,a,n){i.resetloader(t,h),u(new dt({type:s.b.network_error,details:s.a.frag_load_error,fatal:!1,frag:t,part:e,response:r,networkdetails:n}))},onabort:function(r,a,n){t.stats.aborted=e.stats.aborted,i.resetloader(t,h),u(new dt({type:s.b.network_error,details:s.a.internal_aborted,fatal:!1,frag:t,part:e,networkdetails:n}))},ontimeout:function(r,a,n){i.resetloader(t,h),u(new dt({type:s.b.network_error,details:s.a.frag_load_timeout,fatal:!1,frag:t,part:e,networkdetails:n}))}})}))},e.updatestatsfrompart=function(t,e){var r=t.stats,i=e.stats,a=i.total;if(r.loaded+=i.loaded,a){var n=math.round(t.duration/e.duration),s=math.min(math.round(r.loaded/a),n),o=(n-s)*math.round(r.loaded/s);r.total=r.loaded+o}else r.total=math.max(r.loaded,r.total);var l=r.loading,u=i.loading;l.start?l.first+=u.first-u.start:(l.start=u.start,l.first=u.first),l.end=u.end},e.resetloader=function(t,e){t.loader=null,this.loader===e&&(self.cleartimeout(this.partloadtimeout),this.loader=null),e.destroy()},t}();function kt(t,e){void 0===e&&(e=null);var r=e||t,i={frag:t,part:e,responsetype:"arraybuffer",url:r.url,rangestart:0,rangeend:0},n=r.byterangestartoffset,s=r.byterangeendoffset;return object(a.a)(n)&&object(a.a)(s)&&(i.rangestart=n,i.rangeend=s),i}var dt=function(t){var e,r;function i(e){for(var r,i=arguments.length,a=new array(i>1?i-1:0),n=1;ne.start+e.duration+l;(s0&&s&&s.key&&s.iv&&"aes-128"===s.method){var o=self.performance.now();return e.decrypter.webcryptodecrypt(new uint8array(a),s.key.buffer,s.iv.buffer).then((function(e){var a=self.performance.now();return i.trigger(n.a.frag_decrypted,{frag:t,payload:e,stats:{tstart:o,tdecrypt:a}}),r.payload=e,r}))}return r})).then((function(r){var i=e.fragcurrent,a=e.hls,s=e.levels;if(!s)throw new error("init load aborted, missing levels");s[t.level].details;var o=t.stats;e.state=xt,e.fragloaderror=0,t.data=new uint8array(r.payload),o.parsing.start=o.buffering.start=self.performance.now(),o.parsing.end=o.buffering.end=self.performance.now(),r.frag===i&&a.trigger(n.a.frag_buffered,{stats:o,frag:i,part:null,id:t.type}),e.tick()})).catch((function(r){e.warn(r),e.resetfragmentloading(t)}))},c.fragcontextchanged=function(t){var e=this.fragcurrent;return!t||!e||t.level!==e.level||t.sn!==e.sn||t.urlid!==e.urlid},c.fragbufferedcomplete=function(t,e){var r=this.mediabuffer?this.mediabuffer:this.media;this.log("buffered "+t.type+" sn: "+t.sn+(e?" part: "+e.index:"")+" of "+("[stream-controller]"===this.logprefix?"level":"track")+" "+t.level+" "+it.tostring(lt.getbuffered(r))),this.state=xt,this.tick()},c._handlefragmentloadcomplete=function(t){var e=this.transmuxer;if(e){var r=t.frag,i=t.part,a=t.partsloaded,n=!a||0===a.length||a.some((function(t){return!t})),s=new ut(r.level,r.sn,r.stats.chunkcount+1,0,i?i.index:-1,!n);e.flush(s)}},c._handlefragmentloadprogress=function(t){},c._dofragload=function(t,e,r,i){var s=this;if(void 0===r&&(r=null),!this.levels)throw new error("frag load aborted, missing levels");if(r=math.max(t.start,r||0),this.config.lowlatencymode&&e){var o=e.partlist;if(o&&i){r>t.end&&e.fragmenthint&&(t=e.fragmenthint);var l=this.getnextpart(o,t,r);if(l>-1){var u=o[l];return this.log("loading part sn: "+t.sn+" p: "+u.index+" cc: "+t.cc+" of playlist ["+e.startsn+"-"+e.endsn+"] parts [0-"+l+"-"+(o.length-1)+"] "+("[stream-controller]"===this.logprefix?"level":"track")+": "+t.level+", target: "+parsefloat(r.tofixed(3))),this.nextloadposition=u.start+u.duration,this.state=ft,this.hls.trigger(n.a.frag_loading,{frag:t,part:o[l],targetbuffertime:r}),this.dofragpartsload(t,o,l,i).catch((function(t){return s.handlefragloaderror(t)}))}if(!t.url||this.loadedendofparts(o,r))return promise.resolve(null)}}return this.log("loading fragment "+t.sn+" cc: "+t.cc+" "+(e?"of ["+e.startsn+"-"+e.endsn+"] ":"")+("[stream-controller]"===this.logprefix?"level":"track")+": "+t.level+", target: "+parsefloat(r.tofixed(3))),object(a.a)(t.sn)&&!this.bitratetest&&(this.nextloadposition=t.start+t.duration),this.state=ft,this.hls.trigger(n.a.frag_loading,{frag:t,targetbuffertime:r}),this.fragmentloader.load(t,i).catch((function(t){return s.handlefragloaderror(t)}))},c.dofragpartsload=function(t,e,r,i){var a=this;return new promise((function(s,o){var l=[];!function r(u){var h=e[u];a.fragmentloader.loadpart(t,h,i).then((function(i){l[h.index]=i;var o=i.part;a.hls.trigger(n.a.frag_loaded,i);var d=e[u+1];if(!d||d.fragment!==t)return s({frag:t,part:o,partsloaded:l});r(u+1)})).catch(o)}(r)}))},c.handlefragloaderror=function(t){var e=t.data;return e&&e.details===s.a.internal_aborted?this.handlefragloadaborted(e.frag,e.part):this.hls.trigger(n.a.error,e),null},c._handletransmuxerflush=function(t){var e=this.getcurrentcontext(t);if(e&&this.state===ut){var r=e.frag,i=e.part,a=e.level,n=self.performance.now();r.stats.parsing.end=n,i&&(i.stats.parsing.end=n),this.updateleveltiming(r,i,a,t.partial)}else this.fragcurrent||(this.state=xt)},c.getcurrentcontext=function(t){var e=this.levels,r=t.level,i=t.sn,a=t.part;if(!e||!e[r])return this.warn("levels object was unset while buffering fragment "+i+" of level "+r+". the current chunk will not be buffered."),null;var n=e[r],s=a>-1?function(t,e,r){if(!t||!t.details)return null;var i=t.details.partlist;if(i)for(var a=i.length;a--;){var n=i[a];if(n.index===r&&n.fragment.sn===e)return n}return null}(n,i,a):null,o=s?s.fragment:function(t,e,r){if(!t||!t.details)return null;var i=t.details,a=i.fragments[e-i.startsn];return a||((a=i.fragmenthint)&&a.sn===e?a:en&&this.flushmainbuffer(s,t.start)}else this.flushmainbuffer(0,t.start)},c.getfwdbufferinfo=function(t,e){var r=this.config,i=this.getloadposition();if(!object(a.a)(i))return null;var n=lt.bufferinfo(t,i,r.maxbufferhole);if(0===n.len&&void 0!==n.nextstart){var s=this.fragmenttracker.getbufferedfrag(i,e);if(s&&n.nextstart=r&&(e.maxmaxbufferlength/=2,this.warn("reduce max buffer length to "+e.maxmaxbufferlength+"s"),!0)},c.getnextfragment=function(t,e){var r,i,a=e.fragments,n=a.length;if(!n)return null;var s,o=this.config,l=a[0].start;if(e.live){var u=o.initiallivemanifestsize;if(n-1&&rr.start&&r.loaded},c.getinitiallivefragment=function(t,e){var r=this.fragprevious,i=null;if(r){if(t.hasprogramdatetime&&(this.log("live playlist, switching playlist, load frag with same pdt: "+r.programdatetime),i=vt(e,r.endprogramdatetime,this.config.maxfraglookuptolerance)),!i){var a=r.sn+1;if(a>=t.startsn&&a<=t.endsn){var n=e[a-t.startsn];r.cc===n.cc&&(i=n,this.log("live playlist, switching playlist, load frag with next sn: "+i.sn))}i||(i=function(t,e){return gt.search(t,(function(t){return t.cce?-1:0}))}(e,r.cc))&&this.log("live playlist, switching playlist, load frag with same cc: "+i.sn)}}else{var s=this.hls.livesyncposition;null!==s&&(i=this.getfragmentatposition(s,this.bitratetest?t.fragmentend:t.edge,t))}return i},c.getfragmentatposition=function(t,e,r){var i,a=this.config,n=this.fragprevious,s=r.fragments,o=r.endsn,l=r.fragmenthint,u=a.maxfraglookuptolerance,h=!!(a.lowlatencymode&&r.partlist&&l);(h&&l&&!this.bitratetest&&(s=s.concat(l),o=l.sn),te-u?0:u):i=s[s.length-1];if(i){var d=i.sn-r.startsn,c=n&&i.level===n.level,f=s[d+1];if(this.fragmenttracker.getstate(i)===tt.backtracked){i=null;for(var g=d;s[g]&&this.fragmenttracker.getstate(s[g])===tt.backtracked;)i=n?s[g--]:s[--g];i||(i=f)}else n&&i.sn===n.sn&&!h&&c&&(i.sn=n-e.maxfraglookuptolerance&&a<=s;if(null!==i&&r.duration>i&&(a"+t.startsn+" prev-sn: "+(n?n.sn:"na")+" fragments: "+o),d}return l},c.waitforcdntunein=function(t){return t.live&&t.canblockreload&&t.tuneingoal>math.max(t.partholdback,3*t.parttarget)},c.setstartposition=function(t,e){var r=this.startposition;if(r"+t))}}])&&ct(u.prototype,h),d&&ct(u,d),i}(st);function yt(){return self.mediasource||self.webkitmediasource}function qt(){return self.sourcebuffer||self.webkitsourcebuffer}var xt=r(18),zt=r(10),qt=r(14),$t=yt()||{istypesupported:function(){return!1}},jt=function(){function t(t,e,r,i){var a=this;this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.worker=void 0,this.onwmsg=void 0,this.transmuxer=null,this.ontransmuxcomplete=void 0,this.onflush=void 0,this.hls=t,this.id=e,this.ontransmuxcomplete=r,this.onflush=i;var l=t.config,u=function(e,r){(r=r||{}).frag=a.frag,r.id=a.id,t.trigger(e,r)};this.observer=new qt.eventemitter,this.observer.on(n.a.frag_decrypted,u),this.observer.on(n.a.error,u);var h={mp4:$t.istypesupported("video/mp4"),mpeg:$t.istypesupported("audio/mpeg"),mp3:$t.istypesupported('audio/mp4; codecs="mp3"')},d=navigator.vendor;if(l.enableworker&&"undefined"!=typeof worker){var c;o.b.log("demuxing in webworker");try{c=this.worker=xt(19),this.onwmsg=this.onworkermessage.bind(this),c.addeventlistener("message",this.onwmsg),c.onerror=function(e){t.trigger(n.a.error,{type:s.b.other_error,details:s.a.internal_exception,fatal:!0,event:"demuxerworker",error:new error(e.message+" ("+e.filename+":"+e.lineno+")")})},c.postmessage({cmd:"init",typesupported:h,vendor:d,id:e,config:json.stringify(l)})}catch(t){o.b.warn("error in worker:",t),o.b.error("error while initializing demuxerworker, fallback to inline"),c&&self.url.revokeobjecturl(c.objecturl),this.transmuxer=new zt.c(this.observer,h,l,d,e),this.worker=null}}else this.transmuxer=new zt.c(this.observer,h,l,d,e)}var e=t.prototype;return e.destroy=function(){var t=this.worker;if(t)t.removeeventlistener("message",this.onwmsg),t.terminate(),this.worker=null;else{var e=this.transmuxer;e&&(e.destroy(),this.transmuxer=null)}var r=this.observer;r&&r.removealllisteners(),this.observer=null},e.push=function(t,e,r,i,a,n,s,l,u,h){var d=this;u.transmuxing.start=self.performance.now();var c=this.transmuxer,f=this.worker,g=n?n.start:a.start,v=a.decryptdata,p=this.frag,m=!(p&&a.cc===p.cc),y=!(p&&u.level===p.level),t=p?u.sn-p.sn:-1,e=this.part?u.part-this.part.index:1,b=!y&&(1===t||0===t&&1===e),s=self.performance.now();(y||t||0===a.stats.parsing.start)&&(a.stats.parsing.start=s),!n||!e&&b||(n.stats.parsing.start=s);var l=new zt.b(m,b,l,y,g);if(!b||m){o.b.log("[transmuxer-interface, "+a.type+"]: starting new transmux session for sn: "+u.sn+" p: "+u.part+" level: "+u.level+" id: "+u.id+"\n discontinuity: "+m+"\n trackswitch: "+y+"\n contiguous: "+b+"\n accuratetimeoffset: "+l+"\n timeoffset: "+g);var a=new zt.a(r,i,e,s,h);this.configuretransmuxer(a)}if(this.frag=a,this.part=n,f)f.postmessage({cmd:"demux",data:t,decryptdata:v,chunkmeta:u,state:l},t instanceof arraybuffer?[t]:[]);else if(c){var r=c.push(t,v,u,l);object(zt.d)(r)?r.then((function(t){d.handletransmuxcomplete(t)})):this.handletransmuxcomplete(r)}},e.flush=function(t){var e=this;t.transmuxing.start=self.performance.now();var r=this.transmuxer,i=this.worker;if(i)i.postmessage({cmd:"flush",chunkmeta:t});else if(r){var a=r.flush(t);object(zt.d)(a)?a.then((function(r){e.handleflushresult(r,t)})):this.handleflushresult(a,t)}},e.handleflushresult=function(t,e){var r=this;t.foreach((function(t){r.handletransmuxcomplete(t)})),this.onflush(e)},e.onworkermessage=function(t){var e=t.data,r=this.hls;switch(e.event){case"init":self.url.revokeobjecturl(this.worker.objecturl);break;case"transmuxcomplete":this.handletransmuxcomplete(e.data);break;case"flush":this.onflush(e.data);break;default:e.data=e.data||{},e.data.frag=this.frag,e.data.id=this.id,r.trigger(e.event,e.data)}},e.configuretransmuxer=function(t){var e=this.worker,r=this.transmuxer;e?e.postmessage({cmd:"configure",config:t}):r&&r.configure(t)},e.handletransmuxcomplete=function(t){t.chunkmeta.transmuxing.end=self.performance.now(),this.ontransmuxcomplete(t)},t}(),zt=function(){function t(t,e,r,i){this.config=void 0,this.media=void 0,this.fragmenttracker=void 0,this.hls=void 0,this.nudgeretry=0,this.stallreported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=t,this.media=e,this.fragmenttracker=r,this.hls=i}var e=t.prototype;return e.destroy=function(){this.hls=this.fragmenttracker=this.media=null},e.poll=function(t){var e=this.config,r=this.media,i=this.stalled,a=r.currenttime,n=r.seeking,s=this.seeking&&!n,l=!this.seeking&&n;if(this.seeking=n,a===t){if((l||s)&&(this.stalled=null),!r.paused&&!r.ended&&0!==r.playbackrate&<.getbuffered(r).length){var u=lt.bufferinfo(r,a,0),h=u.len>0,d=u.nextstart||0;if(h||d){if(n){var c=u.len>2,f=!d||d-a>2&&!this.fragmenttracker.getpartialfragment(a);if(c||f)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var g,v=math.max(d,u.start||0)-a,p=this.hls.levels?this.hls.levels[this.hls.currentlevel]:null,m=(null==p||null===(g=p.details)||void 0===g?void 0:g.live)?2*p.details.targetduration:2;if(v>0&&v<=m)return void this._tryskipbufferhole(null)}var y=self.performance.now();if(null!==i){var t=y-i;!n&&t>=250&&this._reportstall(u.len);var e=lt.bufferinfo(r,a,e.maxbufferhole);this._tryfixbufferstall(e,t)}else this.stalled=y}}}else if(this.moved=!0,null!==i){if(this.stallreported){var b=self.performance.now()-i;o.b.warn("playback not stuck anymore @"+a+", after "+math.round(b)+"ms"),this.stallreported=!1}this.stalled=null,this.nudgeretry=0}},e._tryfixbufferstall=function(t,e){var r=this.config,i=this.fragmenttracker,a=this.media.currenttime,n=i.getpartialfragment(a);if(n&&this._tryskipbufferhole(n))return;t.len>r.maxbufferhole&&e>1e3*r.highbufferwatchdogperiod&&(o.b.warn("trying to nudge playhead over buffer-hole"),this.stalled=null,this._trynudgebuffer())},e._reportstall=function(t){var e=this.hls,r=this.media;this.stallreported||(this.stallreported=!0,o.b.warn("playback stalling at @"+r.currenttime+" due to low buffer (buffer="+t+")"),e.trigger(n.a.error,{type:s.b.media_error,details:s.a.buffer_stalled_error,fatal:!1,buffer:t}))},e._tryskipbufferhole=function(t){for(var e=this.config,r=this.hls,i=this.media,a=i.currenttime,l=0,u=lt.getbuffered(i),h=0;h=l&&a0&&-1===t&&(this.log("override startposition with lastcurrenttime @"+e.tofixed(3)),t=e),this.state=xt,this.nextloadposition=this.startposition=this.lastcurrenttime=t,this.tick()}else this._forcestartload=!0,this.state=ot},c.stopload=function(){this._forcestartload=!1,t.prototype.stopload.call(this)},c.dotick=function(){switch(this.state){case xt:this.dotickidle();break;case vt:var t,e=this.levels,r=this.level,i=null==e||null===(t=e[r])||void 0===t?void 0:t.details;if(i&&(!i.live||this.levellastloaded===this.level)){if(this.waitforcdntunein(i))break;this.state=xt;break}break;case mt:var a,n=self.performance.now(),s=this.retrydate;(!s||n>=s||null!==(a=this.media)&&void 0!==a&&a.seeking)&&(this.log("retrydate reached, switch back to idle state"),this.state=xt)}this.ontickend()},c.ontickend=function(){t.prototype.ontickend.call(this),this.checkbuffer(),this.checkfragmentchanged()},c.dotickidle=function(){var t,e,r=this.hls,i=this.levellastloaded,a=this.levels,s=this.media,o=r.config,l=r.nextloadlevel;if(null!==i&&(s||!this.startfragrequested&&o.startfragprefetch)&&(!this.altaudio||!this.audioonly)&&a&&a[l]){var h=a[l];this.level=r.nextloadlevel=l;var d=h.details;if(!d||this.state===vt||d.live&&this.levellastloaded!==l)this.state=vt;else{var c=this.getfwdbufferinfo(this.mediabuffer?this.mediabuffer:s,d.b.main);if(null!==c)if(!(c.len>=this.getmaxbufferlength(h.maxbitrate))){if(this._streamended(c,d)){var f={};return this.altaudio&&(f.type="video"),this.hls.trigger(n.a.buffer_eos,f),void(this.state=kt)}var g=c.end,v=this.getnextfragment(g,d);if(this.couldbacktrack&&!this.fragprevious&&v&&"initsegment"!==v.sn){var p=v.sn-d.startsn;p>1&&(v=d.fragments[p-1],this.fragmenttracker.removefragment(v))}if(v&&this.fragmenttracker.getstate(v)===tt.ok&&this.nextloadposition>g){var m=this.audioonly&&!this.altaudio?u.a.audio:u.a.video;this.afterbufferflushed(s,m,d.b.main),v=this.getnextfragment(this.nextloadposition,d)}v&&(!v.initsegment||v.initsegment.data||this.bitratetest||(v=v.initsegment),"identity"!==(null===(t=v.decryptdata)||void 0===t?void 0:t.keyformat)||null!==(e=v.decryptdata)&&void 0!==e&&e.key?this.loadfragment(v,d,g):this.loadkey(v,d))}}}},c.loadfragment=function(e,r,i){var a,n=this.fragmenttracker.getstate(e);if(this.fragcurrent=e,n===tt.backtracked){var s=this.fragmenttracker.getbacktrackdata(e);if(s)return this._handlefragmentloadprogress(s),void this._handlefragmentloadcomplete(s);n=tt.not_loaded}n===tt.not_loaded||n===tt.partial?"initsegment"===e.sn?this._loadinitsegment(e):this.bitratetest?(e.bitratetest=!0,this.log("fragment "+e.sn+" of level "+e.level+" is being downloaded to test bitrate and will not be buffered"),this._loadbitratetestfrag(e)):(this.startfragrequested=!0,t.prototype.loadfragment.call(this,e,r,i)):n===tt.appending?this.reducemaxbufferlength(e.duration)&&this.fragmenttracker.removefragment(e):0===(null===(a=this.media)||void 0===a?void 0:a.buffered.length)&&this.fragmenttracker.removeallfragments()},c.getappendedfrag=function(t){var e=this.fragmenttracker.getappendedfrag(t,d.b.main);return e&&"fragment"in e?e.fragment:e},c.getbufferedfrag=function(t){return this.fragmenttracker.getbufferedfrag(t,d.b.main)},c.followingbufferedfrag=function(t){return t?this.getbufferedfrag(t.end+.5):null},c.immediatelevelswitch=function(){this.abortcurrentfrag(),this.flushmainbuffer(0,number.positive_infinity)},c.nextlevelswitch=function(){var t=this.levels,e=this.media;if(null!=e&&e.readystate){var r,i=this.getappendedfrag(e.currenttime);if(i&&i.start>1&&this.flushmainbuffer(0,i.start-1),!e.paused&&t){var a=t[this.hls.nextloadlevel],n=this.fraglastkbps;r=n&&this.fragcurrent?this.fragcurrent.duration*a.maxbitrate/(1e3*n)+1:0}else r=0;var s=this.getbufferedfrag(e.currenttime+r);if(s){var o=this.followingbufferedfrag(s);if(o){this.abortcurrentfrag();var l=o.maxstartpts?o.maxstartpts:o.start,u=o.duration,h=math.max(s.end,l+math.min(math.max(u-this.config.maxfraglookuptolerance,.5*u),.75*u));this.flushmainbuffer(h,number.positive_infinity)}}}},c.abortcurrentfrag=function(){var t=this.fragcurrent;this.fragcurrent=null,null!=t&&t.loader&&t.loader.abort(),this.state===pt&&(this.state=xt),this.nextloadposition=this.getloadposition()},c.flushmainbuffer=function(e,r){t.prototype.flushmainbuffer.call(this,e,r,this.altaudio?"video":null)},c.onmediaattached=function(e,r){t.prototype.onmediaattached.call(this,e,r);var i=r.media;this.onvplaying=this.onmediaplaying.bind(this),this.onvseeked=this.onmediaseeked.bind(this),i.addeventlistener("playing",this.onvplaying),i.addeventlistener("seeked",this.onvseeked),this.gapcontroller=new zt(this.config,i,this.fragmenttracker,this.hls)},c.onmediadetaching=function(){var e=this.media;e&&(e.removeeventlistener("playing",this.onvplaying),e.removeeventlistener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videobuffer=null),this.fragplaying=null,this.gapcontroller&&(this.gapcontroller.destroy(),this.gapcontroller=null),t.prototype.onmediadetaching.call(this)},c.onmediaplaying=function(){this.tick()},c.onmediaseeked=function(){var t=this.media,e=t?t.currenttime:null;object(a.a)(e)&&this.log("media seeked to "+e.tofixed(3)),this.tick()},c.onmanifestloading=function(){this.log("trigger buffer_reset"),this.hls.trigger(n.a.buffer_reset,void 0),this.fragmenttracker.removeallfragments(),this.couldbacktrack=this.stalled=!1,this.startposition=this.lastcurrenttime=0,this.fragplaying=null},c.onmanifestparsed=function(t,e){var r,i,a,n=!1,s=!1;e.levels.foreach((function(t){(r=t.audiocodec)&&(-1!==r.indexof("mp4a.40.2")&&(n=!0),-1!==r.indexof("mp4a.40.5")&&(s=!0))})),this.audiocodecswitch=n&&s&&!("function"==typeof(null==(a=qt())||null===(i=a.prototype)||void 0===i?void 0:i.changetype)),this.audiocodecswitch&&this.log("both aac/he-aac audio found in levels; declaring level codec as he-aac"),this.levels=e.levels,this.startfragrequested=!1},c.onlevelloading=function(t,e){var r=this.levels;if(r&&this.state===xt){var i=r[e.level];(!i.details||i.details.live&&this.levellastloaded!==e.level||this.waitforcdntunein(i.details))&&(this.state=vt)}},c.onlevelloaded=function(t,e){var r,i=this.levels,a=e.level,s=e.details,o=s.totalduration;if(i){this.log("level "+a+" loaded ["+s.startsn+","+s.endsn+"], cc ["+s.startcc+", "+s.endcc+"] duration:"+o);var l=this.fragcurrent;!l||this.state!==ft&&this.state!==mt||l.level!==e.level&&l.loader&&(this.state=xt,l.loader.abort());var u=i[a],h=0;if(s.live||null!==(r=u.details)&&void 0!==r&&r.live){if(s.fragments[0]||(s.deltaupdatefailed=!0),s.deltaupdatefailed)return;h=this.alignplaylists(s,u.details)}if(u.details=s,this.levellastloaded=a,this.hls.trigger(n.a.level_updated,{details:s,level:a}),this.state===vt){if(this.waitforcdntunein(s))return;this.state=xt}this.startfragrequested?s.live&&this.synchronizetoliveedge(s):this.setstartposition(s,h),this.tick()}else this.warn("levels were reset while loading level "+a)},c._handlefragmentloadprogress=function(t){var e,r=t.frag,i=t.part,a=t.payload,n=this.levels;if(n){var s=n[r.level],o=s.details;if(o){var l=s.videocodec,u=o.ptsknown||!o.live,h=null===(e=r.initsegment)||void 0===e?void 0:e.data,d=this._getaudiocodec(s),c=this.transmuxer=this.transmuxer||new jt(this.hls,d.b.main,this._handletransmuxcomplete.bind(this),this._handletransmuxerflush.bind(this)),f=i?i.index:-1,g=-1!==f,v=new ut(r.level,r.sn,r.stats.chunkcount,a.bytelength,f,g),p=this.initpts[r.cc];c.push(a,h,d,l,r,i,o.totalduration,u,v,p)}else this.warn("dropping fragment "+r.sn+" of level "+r.level+" after level details were reset")}else this.warn("levels were reset while fragment load was in progress. fragment "+r.sn+" of level "+r.level+" will not be buffered")},c.onaudiotrackswitching=function(t,e){var r=this.altaudio,i=!!e.url,a=e.id;if(!i){if(this.mediabuffer!==this.media){this.log("switching on main audio, use media.buffered to schedule main fragment loading"),this.mediabuffer=this.media;var s=this.fragcurrent;null!=s&&s.loader&&(this.log("switching to main audio track, cancel main fragment load"),s.loader.abort()),this.resettransmuxer(),this.resetloadingstate()}else this.audioonly&&this.resettransmuxer();var o=this.hls;r&&o.trigger(n.a.buffer_flushing,{startoffset:0,endoffset:number.positive_infinity,type:"audio"}),o.trigger(n.a.audio_track_switched,{id:a})}},c.onaudiotrackswitched=function(t,e){var r=e.id,i=!!this.hls.audiotracks[r].url;if(i){var a=this.videobuffer;a&&this.mediabuffer!==a&&(this.log("switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediabuffer=a)}this.altaudio=i,this.tick()},c.onbuffercreated=function(t,e){var r,i,a=e.tracks,n=!1;for(var s in a){var o=a[s];if("main"===o.id){if(i=s,r=o,"video"===s){var l=a[s];l&&(this.videobuffer=l.buffer)}}else n=!0}n&&r?(this.log("alternate track found, use "+i+".buffered to schedule main fragment loading"),this.mediabuffer=r.buffer):this.mediabuffer=this.media},c.onfragbuffered=function(t,e){var r=e.frag,i=e.part;if(!r||r.type===d.b.main){if(this.fragcontextchanged(r))return this.warn("fragment "+r.sn+(i?" p: "+i.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state),void(this.state===bt&&(this.state=xt));var a=i?i.stats:r.stats;this.fraglastkbps=math.round(8*a.total/(a.buffering.end-a.loading.first)),"initsegment"!==r.sn&&(this.fragprevious=r),this.fragbufferedcomplete(r,i)}},c.onerror=function(t,e){switch(e.details){case s.a.frag_load_error:case s.a.frag_load_timeout:case s.a.key_load_error:case s.a.key_load_timeout:this.onfragmentorkeyloaderror(d.b.main,e);break;case s.a.level_load_error:case s.a.level_load_timeout:this.state!==jt&&(e.fatal?(this.warn(""+e.details),this.state=jt):e.levelretry||this.state!==vt||(this.state=xt));break;case s.a.buffer_full_error:if("main"===e.parent&&(this.state===ut||this.state===bt)){var r=!0,i=this.getfwdbufferinfo(this.media,d.b.main);i&&i.len>.5&&(r=!this.reducemaxbufferlength(i.len)),r&&(this.warn("buffer full error also media.currenttime is not buffered, flush main"),this.immediatelevelswitch()),this.resetloadingstate()}}},c.checkbuffer=function(){var t=this.media,e=this.gapcontroller;if(t&&e&&t.readystate){var r=lt.getbuffered(t);!this.loadedmetadata&&r.length?(this.loadedmetadata=!0,this.seektostartpos()):e.poll(this.lastcurrenttime),this.lastcurrenttime=t.currenttime}},c.onfragloademergencyaborted=function(){this.state=xt,this.loadedmetadata||(this.startfragrequested=!1,this.nextloadposition=this.startposition),this.tickimmediate()},c.onbufferflushed=function(t,e){var r=e.type;if(r!==u.a.audio||this.audioonly&&!this.altaudio){var i=(r===u.a.video?this.videobuffer:this.mediabuffer)||this.media;this.afterbufferflushed(i,r,d.b.main)}},c.onlevelsupdated=function(t,e){this.levels=e.levels},c.swapaudiocodec=function(){this.audiocodecswap=!this.audiocodecswap},c.seektostartpos=function(){var t=this.media,e=t.currenttime,r=this.startposition;if(r>=0&&e0&&a1&&!1===t.seeking){var r=t.currenttime;if(lt.isbuffered(t,r)?e=this.getappendedfrag(r):lt.isbuffered(t,r+.1)&&(e=this.getappendedfrag(r+.1)),e){var i=this.fragplaying,a=e.level;i&&e.sn===i.sn&&i.level===a&&e.urlid===i.urlid||(this.hls.trigger(n.a.frag_changed,{frag:e}),i&&i.level===a||this.hls.trigger(n.a.level_switched,{level:a}),this.fragplaying=e)}}},l=i,(h=[{key:"nextlevel",get:function(){var t=this.nextbufferedfrag;return t?t.level:-1}},{key:"currentlevel",get:function(){var t=this.media;if(t){var e=this.getappendedfrag(t.currenttime);if(e)return e.level}return-1}},{key:"nextbufferedfrag",get:function(){var t=this.media;if(t){var e=this.getappendedfrag(t.currenttime);return this.followingbufferedfrag(e)}return null}},{key:"forcestartload",get:function(){return this._forcestartload}}])&&te(l.prototype,h),d&&te(l,d),i}(wt),ie=function(){function t(t,e,r){void 0===e&&(e=0),void 0===r&&(r=0),this.halflife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalweight_=void 0,this.halflife=t,this.alpha_=t?math.exp(math.log(.5)/t):0,this.estimate_=e,this.totalweight_=r}var e=t.prototype;return e.sample=function(t,e){var r=math.pow(this.alpha_,t);this.estimate_=e*(1-r)+r*this.estimate_,this.totalweight_+=t},e.gettotalweight=function(){return this.totalweight_},e.getestimate=function(){if(this.alpha_){var t=1-math.pow(this.alpha_,this.totalweight_);if(t)return this.estimate_/t}return this.estimate_},t}(),ae=function(){function t(t,e,r){this.defaultestimate_=void 0,this.minweight_=void 0,this.mindelayms_=void 0,this.slow_=void 0,this.fast_=void 0,this.defaultestimate_=r,this.minweight_=.001,this.mindelayms_=50,this.slow_=new ie(t),this.fast_=new ie(e)}var e=t.prototype;return e.update=function(t,e){var r=this.slow_,i=this.fast_;this.slow_.halflife!==t&&(this.slow_=new ie(t,r.getestimate(),r.gettotalweight())),this.fast_.halflife!==e&&(this.fast_=new ie(e,i.getestimate(),i.gettotalweight()))},e.sample=function(t,e){var r=(t=math.max(t,this.mindelayms_))/1e3,i=8*e/r;this.fast_.sample(r,i),this.slow_.sample(r,i)},e.canestimate=function(){var t=this.fast_;return t&&t.gettotalweight()>=this.minweight_},e.getestimate=function(){return this.canestimate()?math.min(this.fast_.getestimate(),this.slow_.getestimate()):this.defaultestimate_},e.destroy=function(){},t}();function ne(t,e){for(var r=0;r=2*h/c||y<=e)){var b,s=number.positive_infinity;for(b=t.level-1;b>g;b--){if((s=h*f[b].maxbitrate/(6.4*m))=y)){var l=this.bwestimator.getestimate();o.b.warn("fragment "+t.sn+(e?" part "+e.index:"")+" of level "+t.level+" is loading too slowly and will cause an underbuffer; aborting and switching to level "+b+"\n current bw estimate: "+(object(a.a)(l)?(l/1024).tofixed(3):"unknown")+" kb/s\n estimated load time for current fragment: "+y.tofixed(3)+" s\n estimated load time for the next fragment: "+s.tofixed(3)+" s\n time to underbuffer: "+e.tofixed(3)+" s"),r.nextloadlevel=b,this.bwestimator.sample(d,u.loaded),this.cleartimer(),t.loader&&(this.fragcurrent=this.partcurrent=null,t.loader.abort()),r.trigger(n.a.frag_load_emergency_aborted,{frag:t,part:e,stats:u})}}}}}},l.onfragloaded=function(t,e){var r=e.frag,i=e.part;if(r.type===d.b.main&&object(a.a)(r.sn)){var s=i?i.stats:r.stats,o=i?i.duration:r.duration;if(this.cleartimer(),this.lastloadedfraglevel=r.level,this._nextautolevel=-1,this.hls.config.abrmaxwithrealbitrate){var l=this.hls.levels[r.level],u=(l.loaded?l.loaded.bytes:0)+s.loaded,h=(l.loaded?l.loaded.duration:0)+o;l.loaded={bytes:u,duration:h},l.realbitrate=math.round(8*u/h)}if(r.bitratetest){var d={stats:s,frag:r,part:i,id:r.type};this.onfragbuffered(n.a.frag_buffered,d),r.bitratetest=!1}}},l.onfragbuffered=function(t,e){var r=e.frag,i=e.part,a=i?i.stats:r.stats;if(!a.aborted&&r.type===d.b.main&&"initsegment"!==r.sn){var n=a.parsing.end-a.loading.start;this.bwestimator.sample(n,a.loaded),a.bwestimate=this.bwestimator.getestimate(),r.bitratetest?this.bitratetestdelay=n/1e3:this.bitratetestdelay=0}},l.onerror=function(t,e){switch(e.details){case s.a.frag_load_error:case s.a.frag_load_timeout:this.cleartimer()}},l.cleartimer=function(){self.clearinterval(this.timer),this.timer=void 0},l.getnextabrautolevel=function(){var t=this.fragcurrent,e=this.partcurrent,r=this.hls,i=r.maxautolevel,a=r.config,n=r.minautolevel,s=r.media,l=e?e.duration:t?t.duration:0,u=s?s.currenttime:0,h=s&&0!==s.playbackrate?math.abs(s.playbackrate):1,d=this.bwestimator?this.bwestimator.getestimate():a.abrewmadefaultestimate,c=(lt.bufferinfo(s,u,a.maxbufferhole).end-u)/h,f=this.findbestlevel(d,n,i,c,a.abrbandwidthfactor,a.abrbandwidthupfactor);if(f>=0)return f;o.b.trace((c?"rebuffering expected":"buffer is empty")+", finding optimal quality level");var g=l?math.min(l,a.maxstarvationdelay):a.maxstarvationdelay,v=a.abrbandwidthfactor,p=a.abrbandwidthupfactor;if(!c){var m=this.bitratetestdelay;if(m)g=(l?math.min(l,a.maxloadingdelay):a.maxloadingdelay)-m,o.b.trace("bitrate test took "+math.round(1e3*m)+"ms, set first fragment max fetchduration to "+math.round(1e3*g)+" ms"),v=p=1}return f=this.findbestlevel(d,n,i,c+g,v,p),math.max(f,0)},l.findbestlevel=function(t,e,r,i,a,n){for(var s,l=this.fragcurrent,u=this.partcurrent,h=this.lastloadedfraglevel,d=this.hls.levels,c=d[h],f=!(null==c||null===(s=c.details)||void 0===s||!s.live),g=null==c?void 0:c.codecset,v=u?u.duration:l?l.duration:0,p=r;p>=e;p--){var m=d[p];if(m&&(!g||m.codecset===g)){var y=m.details,t=(u?null==y?void 0:y.parttarget:null==y?void 0:y.averagetargetduration)||v,e=void 0;e=p<=h?a*t:n*t;var b=d[p].maxbitrate,s=b*t/e;if(o.b.trace("level/adjustedbw/bitrate/avgduration/maxfetchduration/fetchduration: "+p+"/"+math.round(e)+"/"+b+"/"+t+"/"+i+"/"+s),e>b&&(!s||f&&!this.bitratetestdelay||s0&&-1===t?(this.log("override startposition with lastcurrenttime @"+e.tofixed(3)),this.state=xt):(this.loadedmetadata=!1,this.state=nt),this.nextloadposition=this.startposition=this.lastcurrenttime=t,this.tick()},l.dotick=function(){switch(this.state){case xt:this.dotickidle();break;case nt:var e,r=this.levels,i=this.trackid,a=null==r||null===(e=r[i])||void 0===e?void 0:e.details;if(a){if(this.waitforcdntunein(a))break;this.state=ht}break;case mt:var n,s=performance.now(),l=this.retrydate;(!l||s>=l||null!==(n=this.media)&&void 0!==n&&n.seeking)&&(this.log("retrydate reached, switch back to idle state"),this.state=xt);break;case ht:var u=this.waitingdata;if(u){var h=u.frag,d=u.part,c=u.cache,f=u.complete;if(void 0!==this.initpts[h.cc]){this.waitingdata=null,this.waitingvideocc=-1,this.state=ft;var g={frag:h,part:d,payload:c.flush(),networkdetails:null};this._handlefragmentloadprogress(g),f&&t.prototype._handlefragmentloadcomplete.call(this,g)}else if(this.videotrackcc!==this.waitingvideocc)o.b.log("waiting fragment cc ("+h.cc+") cancelled because video is at cc "+this.videotrackcc),this.clearwaitingfragment();else{var v=this.getloadposition(),p=lt.bufferinfo(this.mediabuffer,v,this.config.maxbufferhole);mt(p.end,this.config.maxfraglookuptolerance,h)<0&&(o.b.log("waiting fragment cc ("+h.cc+") @ "+h.start+" cancelled because another fragment at "+p.end+" is needed"),this.clearwaitingfragment())}}else this.state=xt}this.ontickend()},l.clearwaitingfragment=function(){var t=this.waitingdata;t&&(this.fragmenttracker.removefragment(t.frag),this.waitingdata=null,this.waitingvideocc=-1,this.state=xt)},l.ontickend=function(){var t=this.media;if(t&&t.readystate){var e=(this.mediabuffer?this.mediabuffer:t).buffered;!this.loadedmetadata&&e.length&&(this.loadedmetadata=!0),this.lastcurrenttime=t.currenttime}},l.dotickidle=function(){var t,e,r=this.hls,i=this.levels,a=this.media,s=this.trackid,o=r.config;if(i&&i[s]&&(a||!this.startfragrequested&&o.startfragprefetch)){var l=i[s].details;if(!l||l.live&&this.levellastloaded!==s||this.waitforcdntunein(l))this.state=nt;else{this.bufferflushed&&(this.bufferflushed=!1,this.afterbufferflushed(this.mediabuffer?this.mediabuffer:this.media,u.a.audio,d.b.audio));var h=this.getfwdbufferinfo(this.mediabuffer?this.mediabuffer:this.media,d.b.audio);if(null!==h){var d=h.len,c=this.getmaxbufferlength(),f=this.audioswitch;if(!(d>=c)||f){if(!f&&this._streamended(h,l))return r.trigger(n.a.buffer_eos,{type:"audio"}),void(this.state=kt);var g=l.fragments[0].start,v=h.end;if(f){var p=this.getloadposition();v=p,l.ptsknown&&pg||h.nextstart)&&(this.log("alt audio track ahead of main track, seek to start of alt audio track"),a.currenttime=g+.05)}var m=this.getnextfragment(v,l);m?"identity"!==(null===(t=m.decryptdata)||void 0===t?void 0:t.keyformat)||null!==(e=m.decryptdata)&&void 0!==e&&e.key?this.loadfragment(m,l,v):this.loadkey(m,l):this.bufferflushed=!0}}}}},l.getmaxbufferlength=function(){var e=t.prototype.getmaxbufferlength.call(this),r=this.getfwdbufferinfo(this.videobuffer?this.videobuffer:this.media,d.b.main);return null===r?e:math.max(e,r.len)},l.onmediadetaching=function(){this.videobuffer=null,t.prototype.onmediadetaching.call(this)},l.onaudiotracksupdated=function(t,e){var r=e.audiotracks;this.resettransmuxer(),this.levels=r.map((function(t){return new j(t)}))},l.onaudiotrackswitching=function(t,e){var r=!!e.url;this.trackid=e.id;var i=this.fragcurrent;null!=i&&i.loader&&i.loader.abort(),this.fragcurrent=null,this.clearwaitingfragment(),r?this.setinterval(100):this.resettransmuxer(),r?(this.audioswitch=!0,this.state=xt):this.state=ot,this.tick()},l.onmanifestloading=function(){this.maindetails=null,this.fragmenttracker.removeallfragments(),this.startposition=this.lastcurrenttime=0,this.bufferflushed=!1},l.onlevelloaded=function(t,e){this.maindetails=e.details},l.onaudiotrackloaded=function(t,e){var r,i=this.levels,a=e.details,n=e.id;if(i){this.log("track "+n+" loaded ["+a.startsn+","+a.endsn+"],duration:"+a.totalduration);var s=i[n],o=0;if(a.live||null!==(r=s.details)&&void 0!==r&&r.live){var l=this.maindetails;if(a.fragments[0]||(a.deltaupdatefailed=!0),a.deltaupdatefailed||!l)return;!s.details&&a.hasprogramdatetime&&l.hasprogramdatetime?(ft(a,l),o=a.fragments[0].start):o=this.alignplaylists(a,s.details)}s.details=a,this.levellastloaded=n,this.startfragrequested||!this.maindetails&&a.live||this.setstartposition(s.details,o),this.state!==nt||this.waitforcdntunein(a)||(this.state=xt),this.tick()}else this.warn("audio tracks were reset while loading level "+n)},l._handlefragmentloadprogress=function(t){var e,r=t.frag,i=t.part,a=t.payload,n=this.config,s=this.trackid,l=this.levels;if(l){var u=l[s],h=u.details,d=n.defaultaudiocodec||u.audiocodec||"mp4a.40.2",c=this.transmuxer;c||(c=this.transmuxer=new jt(this.hls,d.b.audio,this._handletransmuxcomplete.bind(this),this._handletransmuxerflush.bind(this)));var f=this.initpts[r.cc],g=null===(e=r.initsegment)||void 0===e?void 0:e.data;if(void 0!==f){var v=i?i.index:-1,p=-1!==v,m=new ut(r.level,r.sn,r.stats.chunkcount,a.bytelength,v,p);c.push(a,g,d,"",r,i,h.totalduration,!1,m,f)}else{o.b.log("unknown video pts for cc "+r.cc+", waiting for video pts before demuxing audio frag "+r.sn+" of ["+h.startsn+" ,"+h.endsn+"],track "+s),(this.waitingdata=this.waitingdata||{frag:r,part:i,cache:new oe.a,complete:!1}).cache.push(new uint8array(a)),this.waitingvideocc=this.videotrackcc,this.state=ht}}else this.warn("audio tracks were reset while fragment load was in progress. fragment "+r.sn+" of level "+r.level+" will not be buffered")},l._handlefragmentloadcomplete=function(e){this.waitingdata?this.waitingdata.complete=!0:t.prototype._handlefragmentloadcomplete.call(this,e)},l.onbufferreset=function(){this.mediabuffer=this.videobuffer=null,this.loadedmetadata=!1},l.onbuffercreated=function(t,e){var r=e.tracks.audio;r&&(this.mediabuffer=r.buffer),e.tracks.video&&(this.videobuffer=e.tracks.video.buffer)},l.onfragbuffered=function(t,e){var r=e.frag,i=e.part;r.type===d.b.audio&&(this.fragcontextchanged(r)?this.warn("fragment "+r.sn+(i?" p: "+i.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state+", audioswitch: "+this.audioswitch):("initsegment"!==r.sn&&(this.fragprevious=r,this.audioswitch&&(this.audioswitch=!1,this.hls.trigger(n.a.audio_track_switched,{id:this.trackid}))),this.fragbufferedcomplete(r,i)))},l.onerror=function(e,r){switch(r.details){case s.a.frag_load_error:case s.a.frag_load_timeout:case s.a.key_load_error:case s.a.key_load_timeout:this.onfragmentorkeyloaderror(d.b.audio,r);break;case s.a.audio_track_load_error:case s.a.audio_track_load_timeout:this.state!==jt&&this.state!==ot&&(this.state=r.fatal?jt:xt,this.warn(r.details+" while loading frag, switching to "+this.state+" state"));break;case s.a.buffer_full_error:if("audio"===r.parent&&(this.state===ut||this.state===bt)){var i=!0,a=this.getfwdbufferinfo(this.mediabuffer,d.b.audio);a&&a.len>.5&&(i=!this.reducemaxbufferlength(a.len)),i&&(this.warn("buffer full error also media.currenttime is not buffered, flush audio buffer"),this.fragcurrent=null,t.prototype.flushmainbuffer.call(this,0,number.positive_infinity,"audio")),this.resetloadingstate()}}},l.onbufferflushed=function(t,e){e.type===u.a.audio&&(this.bufferflushed=!0)},l._handletransmuxcomplete=function(t){var e,r="audio",i=this.hls,a=t.remuxresult,s=t.chunkmeta,o=this.getcurrentcontext(s);if(!o)return this.warn("the loading context changed while buffering fragment "+s.sn+" of level "+s.level+". this chunk will not be buffered."),void this.resetlivestartwhennotloaded(s.level);var l=o.frag,h=o.part,d=a.audio,c=a.text,f=a.id3,g=a.initsegment;if(!this.fragcontextchanged(l)){if(this.state=ut,this.audioswitch&&d&&this.completeaudioswitch(),null!=g&&g.tracks&&(this._bufferinitsegment(g.tracks,l,s),i.trigger(n.a.frag_parsing_init_segment,{frag:l,id:r,tracks:g.tracks})),d){var v=d.startpts,p=d.endpts,m=d.startdts,y=d.enddts;h&&(h.elementarystreams[u.a.audio]={startpts:v,endpts:p,startdts:m,enddts:y}),l.setelementarystreaminfo(u.a.audio,v,p,m,y),this.bufferfragmentdata(d,l,h,s)}if(null!=f&&null!==(e=f.samples)&&void 0!==e&&e.length){var t=le({frag:l,id:r},f);i.trigger(n.a.frag_parsing_metadata,t)}if(c){var e=le({frag:l,id:r},c);i.trigger(n.a.frag_parsing_userdata,e)}}},l._bufferinitsegment=function(t,e,r){if(this.state===ut){t.video&&delete t.video;var i=t.audio;if(i){i.levelcodec=i.codec,i.id="audio",this.log("init audio buffer, container:"+i.container+", codecs[parsed]=["+i.codec+"]"),this.hls.trigger(n.a.buffer_codecs,t);var a=i.initsegment;if(null!=a&&a.bytelength){var s={type:"audio",frag:e,part:null,chunkmeta:r,parent:e.type,data:a};this.hls.trigger(n.a.buffer_appending,s)}this.tick()}}},l.loadfragment=function(e,r,i){var n=this.fragmenttracker.getstate(e);this.fragcurrent=e,(this.audioswitch||n===tt.not_loaded||n===tt.partial)&&("initsegment"===e.sn?this._loadinitsegment(e):r.live&&!object(a.a)(this.initpts[e.cc])?(this.log("waiting for video pts in continuity counter "+e.cc+" of live stream before loading audio fragment "+e.sn+" of level "+this.trackid),this.state=ht):(this.startfragrequested=!0,t.prototype.loadfragment.call(this,e,r,i)))},l.completeaudioswitch=function(){var e=this.hls,r=this.media,i=this.trackid;r&&(this.log("switching audio track : flushing all audio"),t.prototype.flushmainbuffer.call(this,0,number.positive_infinity,"audio")),this.audioswitch=!1,e.trigger(n.a.audio_track_switched,{id:i})},i}(wt);function de(t,e){for(var r=0;r=e.length)this.warn("invalid id passed to audio-track controller");else{this.cleartimer();var r=e[this.trackid];this.log("now switching to audio-track index "+t);var i=e[t],a=i.id,s=i.groupid,o=void 0===s?"":s,l=i.name,u=i.type,h=i.url;if(this.trackid=t,this.trackname=l,this.selectdefaulttrack=!1,this.hls.trigger(n.a.audio_track_switching,{id:a,groupid:o,name:l,type:u,url:h}),!i.details||i.details.live){var d=this.switchparams(i.url,null==r?void 0:r.details);this.loadplaylist(d)}}},u.selectinitialtrack=function(){this.tracksingroup;var t=this.trackname,e=this.findtrackid(t)||this.findtrackid();-1!==e?this.setaudiotrack(e):(this.warn("no track found for running audio group-id: "+this.groupid),this.hls.trigger(n.a.error,{type:s.b.media_error,details:s.a.audio_track_load_error,fatal:!0}))},u.findtrackid=function(t){for(var e=this.tracksingroup,r=0;r=a[o].start&&s<=a[o].end){n=a[o];break}var l=r.start+r.duration;n?n.end=l:(n={start:s,end:l},a.push(n)),this.fragmenttracker.fragbuffered(r)}}},u.onbufferflushing=function(t,e){var r=e.startoffset,i=e.endoffset;if(0===r&&i!==number.positive_infinity){var a=this.currenttrackid,n=this.levels;if(!n.length||!n[a]||!n[a].details)return;var s=i-n[a].details.targetduration;if(s<=0)return;e.endoffsetsubtitles=math.max(0,s),this.tracksbuffered.foreach((function(t){for(var e=0;e=s.length||a!==n)&&o){if(this.mediabuffer=this.mediabuffertimeranges,i.live||null!==(r=o.details)&&void 0!==r&&r.live){var l=this.maindetails;if(i.deltaupdatefailed||!l)return;var u=l.fragments[0];if(o.details)0===this.alignplaylists(i,o.details)&&u&&z(i,u.start);else i.hasprogramdatetime&&l.hasprogramdatetime?ft(i,l):u&&z(i,u.start)}if(o.details=i,this.levellastloaded=a,this.tick(),i.live&&!this.fragcurrent&&this.media&&this.state===xt)pt(null,i.fragments,this.media.currenttime,0)||(this.warn("subtitle playlist not aligned with playback"),o.details=void 0)}}},u._handlefragmentloadcomplete=function(t){var e=t.frag,r=t.payload,i=e.decryptdata,a=this.hls;if(!this.fragcontextchanged(e)&&r&&r.bytelength>0&&i&&i.key&&i.iv&&"aes-128"===i.method){var s=performance.now();this.decrypter.webcryptodecrypt(new uint8array(r),i.key.buffer,i.iv.buffer).then((function(t){var r=performance.now();a.trigger(n.a.frag_decrypted,{frag:e,payload:t,stats:{tstart:s,tdecrypt:r}})}))}},u.dotick=function(){if(this.media){if(this.state===xt){var t,e=this.currenttrackid,r=this.levels;if(!r.length||!r[e]||!r[e].details)return;var i=r[e].details,a=i.targetduration,s=this.config,l=this.media,u=lt.bufferedinfo(this.mediabuffertimeranges,l.currenttime-a,s.maxbufferhole),h=u.end;if(u.len>this.getmaxbufferlength()+a)return;var d,c=i.fragments,f=c.length,g=i.edge,v=this.fragprevious;if(h-1&&(this.subtitletrack=this.queueddefaulttrack,this.queueddefaulttrack=-1),this.usetexttrackpolling=!(this.media.texttracks&&"onchange"in this.media.texttracks),this.usetexttrackpolling?this.polltrackchange(500):this.media.texttracks.addeventlistener("change",this.asyncpolltrackchange))},l.polltrackchange=function(t){self.clearinterval(this.subtitlepollinginterval),this.subtitlepollinginterval=self.setinterval(this.trackchangelistener,t)},l.onmediadetaching=function(){this.media&&(self.clearinterval(this.subtitlepollinginterval),this.usetexttrackpolling||this.media.texttracks.removeeventlistener("change",this.asyncpolltrackchange),this.trackid>-1&&(this.queueddefaulttrack=this.trackid),te(this.media.texttracks).foreach((function(t){x(t)})),this.subtitletrack=-1,this.media=null)},l.onmanifestloading=function(){this.tracks=[],this.groupid=null,this.tracksingroup=[],this.trackid=-1,this.selectdefaulttrack=!0},l.onmanifestparsed=function(t,e){this.tracks=e.subtitletracks},l.onsubtitletrackloaded=function(t,e){var r=e.id,i=e.details,a=this.trackid,n=this.tracksingroup[a];if(n){var s=n.details;n.details=e.details,this.log("subtitle track "+r+" loaded ["+i.startsn+"-"+i.endsn+"]"),r===this.trackid&&(this.retrycount=0,this.playlistloaded(r,e,s))}else this.warn("invalid subtitle track id "+r)},l.onlevelloading=function(t,e){this.switchlevel(e.level)},l.onlevelswitching=function(t,e){this.switchlevel(e.level)},l.switchlevel=function(t){var e=this.hls.levels[t];if(null!=e&&e.textgroupids){var r=e.textgroupids[e.urlid];if(this.groupid!==r){var i=this.tracksingroup?this.tracksingroup[this.trackid]:void 0,a=this.tracks.filter((function(t){return!r||t.groupid===r}));this.tracksingroup=a;var s=this.findtrackid(null==i?void 0:i.name)||this.findtrackid();this.groupid=r;var o={subtitletracks:a};this.log("updating subtitle tracks, "+a.length+' track(s) found in "'+r+'" group-id'),this.hls.trigger(n.a.subtitle_tracks_updated,o),-1!==s&&this.setsubtitletrack(s,i)}}},l.findtrackid=function(t){for(var e=this.tracksingroup,r=0;r=i.length)){this.cleartimer();var a=i[t];if(this.log("switching to subtitle track "+t),this.trackid=t,a){var s=a.id,o=a.groupid,l=void 0===o?"":o,u=a.name,h=a.type,d=a.url;this.hls.trigger(n.a.subtitle_track_switch,{id:s,groupid:l,name:u,type:h,url:d});var c=this.switchparams(a.url,null==e?void 0:e.details);this.loadplaylist(c)}else this.hls.trigger(n.a.subtitle_track_switch,{id:t})}}else this.queueddefaulttrack=t},l.ontexttrackschanged=function(){if(this.usetexttrackpolling||self.clearinterval(this.subtitlepollinginterval),this.media&&this.hls.config.rendertexttracksnatively){for(var t=-1,e=te(this.media.texttracks),r=0;r0||object.keys(this.pendingtracks).length>0},e.destroy=function(){this.unregisterlisteners(),this.details=null},e.registerlisteners=function(){var t=this.hls;t.on(n.a.media_attaching,this.onmediaattaching,this),t.on(n.a.media_detaching,this.onmediadetaching,this),t.on(n.a.manifest_parsed,this.onmanifestparsed,this),t.on(n.a.buffer_reset,this.onbufferreset,this),t.on(n.a.buffer_appending,this.onbufferappending,this),t.on(n.a.buffer_codecs,this.onbuffercodecs,this),t.on(n.a.buffer_eos,this.onbuffereos,this),t.on(n.a.buffer_flushing,this.onbufferflushing,this),t.on(n.a.level_updated,this.onlevelupdated,this),t.on(n.a.frag_parsed,this.onfragparsed,this),t.on(n.a.frag_changed,this.onfragchanged,this)},e.unregisterlisteners=function(){var t=this.hls;t.off(n.a.media_attaching,this.onmediaattaching,this),t.off(n.a.media_detaching,this.onmediadetaching,this),t.off(n.a.manifest_parsed,this.onmanifestparsed,this),t.off(n.a.buffer_reset,this.onbufferreset,this),t.off(n.a.buffer_appending,this.onbufferappending,this),t.off(n.a.buffer_codecs,this.onbuffercodecs,this),t.off(n.a.buffer_eos,this.onbuffereos,this),t.off(n.a.buffer_flushing,this.onbufferflushing,this),t.off(n.a.level_updated,this.onlevelupdated,this),t.off(n.a.frag_parsed,this.onfragparsed,this),t.off(n.a.frag_changed,this.onfragchanged,this)},e._initsourcebuffer=function(){this.sourcebuffer={},this.operationqueue=new se(this.sourcebuffer),this.listeners={audio:[],video:[],audiovideo:[]}},e.onmanifestparsed=function(t,e){var r=2;(e.audio&&!e.video||!e.altaudio)&&(r=1),this.buffercodeceventsexpected=this._buffercodeceventstotal=r,this.details=null,o.b.log(this.buffercodeceventsexpected+" buffercodec event(s) expected")},e.onmediaattaching=function(t,e){var r=this.media=e.media;if(r&&le){var i=this.mediasource=new le;i.addeventlistener("sourceopen",this._onmediasourceopen),i.addeventlistener("sourceended",this._onmediasourceended),i.addeventlistener("sourceclose",this._onmediasourceclose),r.src=self.url.createobjecturl(i),this._objecturl=r.src}},e.onmediadetaching=function(){var t=this.media,e=this.mediasource,r=this._objecturl;if(e){if(o.b.log("[buffer-controller]: media source detaching"),"open"===e.readystate)try{e.endofstream()}catch(t){o.b.warn("[buffer-controller]: onmediadetaching: "+t.message+" while calling endofstream")}this.onbufferreset(),e.removeeventlistener("sourceopen",this._onmediasourceopen),e.removeeventlistener("sourceended",this._onmediasourceended),e.removeeventlistener("sourceclose",this._onmediasourceclose),t&&(r&&self.url.revokeobjecturl(r),t.src===r?(t.removeattribute("src"),t.load()):o.b.warn("[buffer-controller]: 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.hls.trigger(n.a.media_detached,void 0)},e.onbufferreset=function(){var t=this;this.getsourcebuffertypes().foreach((function(e){var r=t.sourcebuffer[e];try{r&&(t.removebufferlisteners(e),t.mediasource&&t.mediasource.removesourcebuffer(r),t.sourcebuffer[e]=void 0)}catch(t){o.b.warn("[buffer-controller]: failed to reset the "+e+" buffer",t)}})),this._initsourcebuffer()},e.onbuffercodecs=function(t,e){var r=this,i=this.getsourcebuffertypes().length;object.keys(e).foreach((function(t){if(i){var a=r.tracks[t];if(a&&"function"==typeof a.buffer.changetype){var n=e[t],s=n.codec,o=n.levelcodec,l=n.container;if((a.levelcodec||a.codec).replace(ae,"$1")!==(o||s).replace(ae,"$1")){var u=l+";codecs="+(o||s);r.appendchangetype(t,u)}}}else r.pendingtracks[t]=e[t]})),i||(this.buffercodeceventsexpected=math.max(this.buffercodeceventsexpected-1,0),this.mediasource&&"open"===this.mediasource.readystate&&this.checkpendingtracks())},e.appendchangetype=function(t,e){var r=this,i=this.operationqueue,a={execute:function(){var a=r.sourcebuffer[t];a&&(o.b.log("[buffer-controller]: changing "+t+" sourcebuffer type to "+e),a.changetype(e)),i.shiftandexecutenext(t)},onstart:function(){},oncomplete:function(){},onerror:function(e){o.b.warn("[buffer-controller]: failed to change "+t+" sourcebuffer type",e)}};i.append(a,t)},e.onbufferappending=function(t,e){var r=this,i=this.hls,a=this.operationqueue,l=this.tracks,u=e.data,h=e.type,d=e.frag,c=e.part,f=e.chunkmeta,g=f.buffering[h],v=self.performance.now();g.start=v;var p=d.stats.buffering,m=c?c.stats.buffering:null;0===p.start&&(p.start=v),m&&0===m.start&&(m.start=v);var y=l.audio,t="audio"===h&&1===f.id&&"audio/mpeg"===(null==y?void 0:y.container),e={execute:function(){if(g.executestart=self.performance.now(),t){var t=r.sourcebuffer[h];if(t){var e=d.start-t.timestampoffset;math.abs(e)>=.1&&(o.b.log("[buffer-controller]: updating audio sourcebuffer timestampoffset to "+d.start+" (delta: "+e+") sn: "+d.sn+")"),t.timestampoffset=d.start)}}r.appendexecutor(u,h)},onstart:function(){},oncomplete:function(){var t=self.performance.now();g.executeend=g.end=t,0===p.first&&(p.first=t),m&&0===m.first&&(m.first=t);var e=r.sourcebuffer,i={};for(var a in e)i[a]=lt.getbuffered(e[a]);r.appenderror=0,r.hls.trigger(n.a.buffer_appended,{type:h,frag:d,part:c,chunkmeta:f,parent:d.type,timeranges:i})},onerror:function(t){o.b.error("[buffer-controller]: error encountered while trying to append to the "+h+" sourcebuffer",t);var e={type:s.b.media_error,parent:d.type,details:s.a.buffer_append_error,err:t,fatal:!1};t.code===domexception.quota_exceeded_err?e.details=s.a.buffer_full_error:(r.appenderror++,e.details=s.a.buffer_append_error,r.appenderror>i.config.appenderrormaxretry&&(o.b.error("[buffer-controller]: failed "+i.config.appenderrormaxretry+" times to append segment in sourcebuffer"),e.fatal=!0)),i.trigger(n.a.error,e)}};a.append(e,h)},e.onbufferflushing=function(t,e){var r=this,i=this.operationqueue,a=function(t){return{execute:r.removeexecutor.bind(r,t,e.startoffset,e.endoffset),onstart:function(){},oncomplete:function(){r.hls.trigger(n.a.buffer_flushed,{type:t})},onerror:function(e){o.b.warn("[buffer-controller]: failed to remove from "+t+" sourcebuffer",e)}}};e.type?i.append(a(e.type),e.type):this.getsourcebuffertypes().foreach((function(t){i.append(a(t),t)}))},e.onfragparsed=function(t,e){var r=this,i=e.frag,a=e.part,s=[],l=a?a.elementarystreams:i.elementarystreams;l[u.a.audiovideo]?s.push("audiovideo"):(l[u.a.audio]&&s.push("audio"),l[u.a.video]&&s.push("video"));0===s.length&&o.b.warn("fragments must have at least one elementarystreamtype set. type: "+i.type+" level: "+i.level+" sn: "+i.sn),this.blockbuffers((function(){var t=self.performance.now();i.stats.buffering.end=t,a&&(a.stats.buffering.end=t);var e=a?a.stats:i.stats;r.hls.trigger(n.a.frag_buffered,{frag:i,part:a,stats:e,id:i.type})}),s)},e.onfragchanged=function(t,e){this.flushbackbuffer()},e.onbuffereos=function(t,e){var r=this;this.getsourcebuffertypes().reduce((function(t,i){var a=r.sourcebuffer[i];return e.type&&e.type!==i||a&&!a.ended&&(a.ended=!0,o.b.log("[buffer-controller]: "+i+" sourcebuffer now eos")),t&&!(a&&!a.ended)}),!0)&&this.blockbuffers((function(){var t=r.mediasource;t&&"open"===t.readystate&&t.endofstream()}))},e.onlevelupdated=function(t,e){var r=e.details;r.fragments.length&&(this.details=r,this.getsourcebuffertypes().length?this.blockbuffers(this.updatemediaelementduration.bind(this)):this.updatemediaelementduration())},e.flushbackbuffer=function(){var t=this.hls,e=this.details,r=this.media,i=this.sourcebuffer;if(r&&null!==e){var s=this.getsourcebuffertypes();if(s.length){var o=e.live&&null!==t.config.livebackbufferlength?t.config.livebackbufferlength:t.config.backbufferlength;if(object(a.a)(o)&&!(o<0)){var l=r.currenttime,u=e.leveltargetduration,h=math.max(o,u),d=math.floor(l/u)*u-h;s.foreach((function(r){var a=i[r];if(a){var s=lt.getbuffered(a);s.length>0&&d>s.start(0)&&(t.trigger(n.a.back_buffer_reached,{bufferend:d}),e.live&&t.trigger(n.a.live_back_buffer_reached,{bufferend:d}),t.trigger(n.a.buffer_flushing,{startoffset:0,endoffset:d,type:r}))}}))}}}},e.updatemediaelementduration=function(){if(this.details&&this.media&&this.mediasource&&"open"===this.mediasource.readystate){var t=this.details,e=this.hls,r=this.media,i=this.mediasource,n=t.fragments[0].start+t.totalduration,s=r.duration,l=object(a.a)(i.duration)?i.duration:0;t.live&&e.config.livedurationinfinity?(o.b.log("[buffer-controller]: media source duration is set to infinity"),i.duration=1/0,this.updateseekablerange(t)):(n>l&&n>s||!object(a.a)(s))&&(o.b.log("[buffer-controller]: updating media source duration to "+n.tofixed(3)),i.duration=n)}},e.updateseekablerange=function(t){var e=this.mediasource,r=t.fragments;if(r.length&&t.live&&null!=e&&e.setliveseekablerange){var i=math.max(0,r[0].start),a=math.max(i,i+t.totalduration);e.setliveseekablerange(i,a)}},e.checkpendingtracks=function(){var t=this.buffercodeceventsexpected,e=this.operationqueue,r=this.pendingtracks,i=object.keys(r).length;if(i&&!t||2===i){this.createsourcebuffers(r),this.pendingtracks={};var a=this.getsourcebuffertypes();if(0===a.length)return void this.hls.trigger(n.a.error,{type:s.b.media_error,details:s.a.buffer_incompatible_codecs_error,fatal:!0,reason:"could not create source buffer for media codec(s)"});a.foreach((function(t){e.executenext(t)}))}},e.createsourcebuffers=function(t){var e=this.sourcebuffer,r=this.mediasource;if(!r)throw error("createsourcebuffers called when mediasource was null");var i=0;for(var a in t)if(!e[a]){var l=t[a];if(!l)throw error("source buffer exists for track "+a+", however track does not");var u=l.levelcodec||l.codec,h=l.container+";codecs="+u;o.b.log("[buffer-controller]: creating sourcebuffer("+h+")");try{var d=e[a]=r.addsourcebuffer(h),c=a;this.addbufferlistener(c,"updatestart",this._onsbupdatestart),this.addbufferlistener(c,"updateend",this._onsbupdateend),this.addbufferlistener(c,"error",this._onsbupdateerror),this.tracks[a]={buffer:d,codec:u,container:l.container,levelcodec:l.levelcodec,id:l.id},i++}catch(t){o.b.error("[buffer-controller]: error while trying to add sourcebuffer: "+t.message),this.hls.trigger(n.a.error,{type:s.b.media_error,details:s.a.buffer_add_codec_error,fatal:!1,error:t,mimetype:h})}}i&&this.hls.trigger(n.a.buffer_created,{tracks:this.tracks})},e._onsbupdatestart=function(t){this.operationqueue.current(t).onstart()},e._onsbupdateend=function(t){var e=this.operationqueue;e.current(t).oncomplete(),e.shiftandexecutenext(t)},e._onsbupdateerror=function(t,e){o.b.error("[buffer-controller]: "+t+" sourcebuffer error",e),this.hls.trigger(n.a.error,{type:s.b.media_error,details:s.a.buffer_appending_error,fatal:!1});var r=this.operationqueue.current(t);r&&r.onerror(e)},e.removeexecutor=function(t,e,r){var i=this.media,n=this.mediasource,s=this.operationqueue,l=this.sourcebuffer[t];if(!i||!n||!l)return o.b.warn("[buffer-controller]: attempting to remove from the "+t+" sourcebuffer, but it does not exist"),void s.shiftandexecutenext(t);var u=object(a.a)(i.duration)?i.duration:1/0,h=object(a.a)(n.duration)?n.duration:1/0,d=math.max(0,e),c=math.min(r,u,h);c>d?(o.b.log("[buffer-controller]: removing ["+d+","+c+"] from the "+t+" sourcebuffer"),l.remove(d,c)):s.shiftandexecutenext(t)},e.appendexecutor=function(t,e){var r=this.operationqueue,i=this.sourcebuffer[e];if(!i)return o.b.warn("[buffer-controller]: attempting to append to the "+e+" sourcebuffer, but it does not exist"),void r.shiftandexecutenext(e);i.ended=!1,i.appendbuffer(t)},e.blockbuffers=function(t,e){var r=this;if(void 0===e&&(e=this.getsourcebuffertypes()),!e.length)return o.b.log("[buffer-controller]: blocking operation requested, but no sourcebuffers exist"),void promise.resolve(t);var i=this.operationqueue,a=e.map((function(t){return i.appendblocker(t)}));promise.all(a).then((function(){t(),e.foreach((function(t){var e=r.sourcebuffer[t];e&&e.updating||i.shiftandexecutenext(t)}))}))},e.getsourcebuffertypes=function(){return object.keys(this.sourcebuffer)},e.addbufferlistener=function(t,e,r){var i=this.sourcebuffer[t];if(i){var a=r.bind(this,t);this.listeners[t].push({event:e,listener:a}),i.addeventlistener(e,a)}},e.removebufferlisteners=function(t){var e=this.sourcebuffer[t];e&&this.listeners[t].foreach((function(t){e.removeeventlistener(t.event,t.listener)}))},t}(),ke={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},de=function(t){var e=t;return ke.hasownproperty(t)&&(e=ke[t]),string.fromcharcode(e)},_e={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},ie={17:2,18:4,21:6,22:8,23:10,19:13,20:15},ce={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},we={25:2,26:4,29:6,30:8,31:10,27:13,28:15},oe=["white","green","blue","cyan","red","yellow","magenta","black","transparent"];!function(t){t[t.error=0]="error",t[t.text=1]="text",t[t.warning=2]="warning",t[t.info=2]="info",t[t.debug=3]="debug",t[t.data=3]="data"}(ee||(ee={}));var xe=function(){function t(){this.time=null,this.verboselevel=ee.error}return t.prototype.log=function(t,e){this.verboselevel>=t&&o.b.log(this.time+" ["+t+"] "+e)},t}(),pe=function(t){for(var e=[],r=0;r100&&(this.logger.log(ee.debug,"too large cursor position "+this.pos),this.pos=100)},e.movecursor=function(t){var e=this.pos+t;if(t>1)for(var r=this.pos+1;r=144&&this.backspace();var e=de(t);this.pos>=100?this.logger.log(ee.error,"cannot insert "+t.tostring(16)+" ("+e+") at position "+this.pos+". skipping it!"):(this.chars[this.pos].setchar(e,this.currpenstate),this.movecursor(1))},e.clearfrompos=function(t){var e;for(e=t;e<100;e++)this.chars[e].reset()},e.clear=function(){this.clearfrompos(0),this.pos=0,this.currpenstate.reset()},e.cleartoendofrow=function(){this.clearfrompos(this.pos)},e.gettextstring=function(){for(var t=[],e=!0,r=0;r<100;r++){var i=this.chars[r].uchar;" "!==i&&(e=!1),t.push(i)}return e?"":t.join("")},e.setpenstyles=function(t){this.currpenstate.setstyles(t),this.chars[this.pos].setpenstate(this.currpenstate)},t}(),ue=function(){function t(t){this.rows=void 0,this.currrow=void 0,this.nrrolluprows=void 0,this.lastoutputscreen=void 0,this.logger=void 0,this.rows=[];for(var e=0;e<15;e++)this.rows.push(new ne(t));this.logger=t,this.currrow=14,this.nrrolluprows=null,this.lastoutputscreen=null,this.reset()}var e=t.prototype;return e.reset=function(){for(var t=0;t<15;t++)this.rows[t].clear();this.currrow=14},e.equals=function(t){for(var e=!0,r=0;r<15;r++)if(!this.rows[r].equals(t.rows[r])){e=!1;break}return e},e.copy=function(t){for(var e=0;e<15;e++)this.rows[e].copy(t.rows[e])},e.isempty=function(){for(var t=!0,e=0;e<15;e++)if(!this.rows[e].isempty()){t=!1;break}return t},e.backspace=function(){this.rows[this.currrow].backspace()},e.cleartoendofrow=function(){this.rows[this.currrow].cleartoendofrow()},e.insertchar=function(t){this.rows[this.currrow].insertchar(t)},e.setpen=function(t){this.rows[this.currrow].setpenstyles(t)},e.movecursor=function(t){this.rows[this.currrow].movecursor(t)},e.setcursor=function(t){this.logger.log(ee.info,"setcursor: "+t),this.rows[this.currrow].setcursor(t)},e.setpac=function(t){this.logger.log(ee.info,"pacdata = "+json.stringify(t));var e=t.row-1;if(this.nrrolluprows&&e0&&(r=t?"["+e.join(" | ")+"]":e.join("\n")),r},e.gettextandformat=function(){return this.rows},t}(),be=function(){function t(t,e,r){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.logger=void 0,this.chnr=t,this.outputfilter=e,this.mode=null,this.verbose=0,this.displayedmemory=new ue(r),this.nondisplayedmemory=new ue(r),this.lastoutputscreen=new ue(r),this.currrolluprow=this.displayedmemory.rows[14],this.writescreen=this.displayedmemory,this.mode=null,this.cuestarttime=null,this.logger=r}var e=t.prototype;return e.reset=function(){this.mode=null,this.displayedmemory.reset(),this.nondisplayedmemory.reset(),this.lastoutputscreen.reset(),this.outputfilter.reset(),this.currrolluprow=this.displayedmemory.rows[14],this.writescreen=this.displayedmemory,this.mode=null,this.cuestarttime=null},e.gethandler=function(){return this.outputfilter},e.sethandler=function(t){this.outputfilter=t},e.setpac=function(t){this.writescreen.setpac(t)},e.setbkgdata=function(t){this.writescreen.setbkgdata(t)},e.setmode=function(t){t!==this.mode&&(this.mode=t,this.logger.log(ee.info,"mode="+t),"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=t)},e.insertchars=function(t){for(var e=0;e=46,e.italics)e.foreground="white";else{var r=math.floor(t/2)-16;e.foreground=["white","green","blue","cyan","red","yellow","magenta"][r]}this.logger.log(ee.info,"midrow: "+json.stringify(e)),this.writescreen.setpen(e)},e.outputdataupdate=function(t){void 0===t&&(t=!1);var e=this.logger.time;null!==e&&this.outputfilter&&(null!==this.cuestarttime||this.displayedmemory.isempty()?this.displayedmemory.equals(this.lastoutputscreen)||(this.outputfilter.newcue(this.cuestarttime,e,this.lastoutputscreen),t&&this.outputfilter.dispatchcue&&this.outputfilter.dispatchcue(),this.cuestarttime=this.displayedmemory.isempty()?null:e):this.cuestarttime=e,this.lastoutputscreen.copy(this.displayedmemory))},e.cuesplitattime=function(t){this.outputfilter&&(this.displayedmemory.isempty()||(this.outputfilter.newcue&&this.outputfilter.newcue(this.cuestarttime,t,this.displayedmemory),this.cuestarttime=t))},t}();function ge(t,e,r){r.a=t,r.b=e}function ke(t,e,r){return r.a===t&&r.b===e}var je=function(){function t(t,e,r){this.channels=void 0,this.currentchannel=0,this.cmdhistory=void 0,this.logger=void 0;var i=new xe;this.channels=[null,new be(t,e,i),new be(t+1,r,i)],this.cmdhistory={a:null,b:null},this.logger=i}var e=t.prototype;return e.gethandler=function(t){return this.channels[t].gethandler()},e.sethandler=function(t,e){this.channels[t].sethandler(e)},e.adddata=function(t,e){var r,i,a,n=!1;this.logger.time=t;for(var s=0;s ("+pe([i,a])+")"),(r=this.parsecmd(i,a))||(r=this.parsemidrow(i,a)),r||(r=this.parsepac(i,a)),r||(r=this.parsebackgroundattributes(i,a)),!r&&(n=this.parsechars(i,a))){var o=this.currentchannel;if(o&&o>0)this.channels[o].insertchars(n);else this.logger.log(ee.warning,"no channel found yet. text-mode?")}r||n||this.logger.log(ee.warning,"couldn't parse cleaned data "+pe([i,a])+" orig: "+pe([e[s],e[s+1]]))}},e.parsecmd=function(t,e){var r=this.cmdhistory;if(!((20===t||28===t||21===t||29===t)&&e>=32&&e<=47)&&!((23===t||31===t)&&e>=33&&e<=35))return!1;if(ke(t,e,r))return ge(null,null,r),this.logger.log(ee.debug,"repeated command ("+pe([t,e])+") is dropped"),!0;var i=20===t||21===t||23===t?1:2,a=this.channels[i];return 20===t||21===t||28===t||29===t?32===e?a.ccrcl():33===e?a.ccbs():34===e?a.ccaof():35===e?a.ccaon():36===e?a.ccder():37===e?a.ccru(2):38===e?a.ccru(3):39===e?a.ccru(4):40===e?a.ccfon():41===e?a.ccrdc():42===e?a.cctr():43===e?a.ccrtd():44===e?a.ccedm():45===e?a.cccr():46===e?a.ccenm():47===e&&a.cceoc():a.ccto(e-32),ge(t,e,r),this.currentchannel=i,!0},e.parsemidrow=function(t,e){var r=0;if((17===t||25===t)&&e>=32&&e<=47){if((r=17===t?1:2)!==this.currentchannel)return this.logger.log(ee.error,"mismatch channel in midrow parsing"),!1;var i=this.channels[r];return!!i&&(i.ccmidrow(e),this.logger.log(ee.debug,"midrow ("+pe([t,e])+")"),!0)}return!1},e.parsepac=function(t,e){var r,i=this.cmdhistory;if(!((t>=17&&t<=23||t>=25&&t<=31)&&e>=64&&e<=127)&&!((16===t||24===t)&&e>=64&&e<=95))return!1;if(ke(t,e,i))return ge(null,null,i),!0;var a=t<=23?1:2;r=e>=64&&e<=95?1===a?_e[t]:ce[t]:1===a?ie[t]:we[t];var n=this.channels[a];return!!n&&(n.setpac(this.interpretpac(r,e)),ge(t,e,i),this.currentchannel=a,!0)},e.interpretpac=function(t,e){var r,i={color:null,italics:!1,indent:null,underline:!1,row:t};return r=e>95?e-96:e-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},e.parsechars=function(t,e){var r,i,a=null,n=null;(t>=25?(r=2,n=t-8):(r=1,n=t),n>=17&&n<=19)?(i=17===n?e+80:18===n?e+112:e+144,this.logger.log(ee.info,"special char '"+de(i)+"' in channel "+r),a=[i]):t>=32&&t<=127&&(a=0===e?[t]:[t,e]);if(a){var s=pe(a);this.logger.log(ee.debug,"char codes = "+s.join(",")),ge(t,e,this.cmdhistory)}return a},e.parsebackgroundattributes=function(t,e){var r;if(!((16===t||24===t)&&e>=32&&e<=47)&&!((23===t||31===t)&&e>=45&&e<=47))return!1;var i={};16===t||24===t?(r=math.floor((e-32)/2),i.background=oe[r],e%2==1&&(i.background=i.background+"_semi")):45===e?i.background="transparent":(i.foreground="black",47===e&&(i.underline=!0));var a=t<=23?1:2;return this.channels[a].setbkgdata(i),ge(t,e,this.cmdhistory),!0},e.reset=function(){for(var t=0;tt)&&(this.starttime=t),this.endtime=e,this.screen=r,this.timelinecontroller.createcaptionstrack(this.trackname)},e.reset=function(){this.cueranges=[]},t}(),ve=function(){if("undefined"!=typeof self&&self.vttcue)return self.vttcue;var t=["","lr","rl"],e=["start","middle","end","left","right"];function r(t,e){if("string"!=typeof e)return!1;if(!array.isarray(t))return!1;var r=e.tolowercase();return!!~t.indexof(r)&&r}function i(t){return r(e,t)}function a(t){for(var e=arguments.length,r=new array(e>1?e-1:0),i=1;i100)throw new error("position must be between 0 and 100.");t=t,this.hasbeenreset=!0}})),object.defineproperty(o,"positionalign",a({},l,{get:function(){return e},set:function(t){var e=i(t);if(!e)throw new syntaxerror("an invalid or illegal string was specified.");e=e,this.hasbeenreset=!0}})),object.defineproperty(o,"size",a({},l,{get:function(){return b},set:function(t){if(t<0||t>100)throw new error("size must be between 0 and 100.");b=t,this.hasbeenreset=!0}})),object.defineproperty(o,"align",a({},l,{get:function(){return s},set:function(t){var e=i(t);if(!e)throw new syntaxerror("an invalid or illegal string was specified.");s=e,this.hasbeenreset=!0}})),o.displaystate=void 0}return n.prototype.getcueashtml=function(){return self.webvtt.convertcuetodomtree(self,this.text)},n}(),we=function(){function t(){}return t.prototype.decode=function(t,e){if(!t)return"";if("string"!=typeof t)throw new error("error - expected string data.");return decodeuricomponent(encodeuricomponent(t))},t}();function ye(t){function e(t,e,r,i){return 3600*(0|t)+60*(0|e)+(0|r)+parsefloat(i||0)}var r=t.match(/^(?:(\d+):)?(\d{2}):(\d{2})(\.\d+)?/);return r?parsefloat(r[2])>59?e(r[2],r[3],0,r[4]):e(r[1],r[2],r[3],r[4]):null}var qe=function(){function t(){this.values=object.create(null)}var e=t.prototype;return e.set=function(t,e){this.get(t)||""===e||(this.values[t]=e)},e.get=function(t,e,r){return r?this.has(t)?this.values[t]:e[r]:this.has(t)?this.values[t]:e},e.has=function(t){return t in this.values},e.alt=function(t,e,r){for(var i=0;i=0&&r<=100)return this.set(t,r),!0}return!1},t}();function xe(t,e,r,i){var a=i?t.split(i):[t];for(var n in a)if("string"==typeof a[n]){var s=a[n].split(r);if(2===s.length)e(s[0],s[1])}}var ze=new ve(0,0,""),qe="middle"===ze.align?"middle":"center";function $e(t,e,r){var i=t;function a(){var e=ye(t);if(null===e)throw new error("malformed timestamp: "+i);return t=t.replace(/^[^\sa-za-z-]+/,""),e}function n(){t=t.replace(/^\s+/,"")}if(n(),e.starttime=a(),n(),"--\x3e"!==t.substr(0,3))throw new error("malformed time stamp (time stamps must be separated by '--\x3e'): "+i);t=t.substr(3),n(),e.endtime=a(),n(),function(t,e){var i=new qe;xe(t,(function(t,e){var a;switch(t){case"region":for(var n=r.length-1;n>=0;n--)if(r[n].id===e){i.set(t,r[n].region);break}break;case"vertical":i.alt(t,e,["rl","lr"]);break;case"line":a=e.split(","),i.integer(t,a[0]),i.percent(t,a[0])&&i.set("snaptolines",!1),i.alt(t,a[0],["auto"]),2===a.length&&i.alt("linealign",a[1],["start",qe,"end"]);break;case"position":a=e.split(","),i.percent(t,a[0]),2===a.length&&i.alt("positionalign",a[1],["start",qe,"end","line-left","line-right","auto"]);break;case"size":i.percent(t,e);break;case"align":i.alt(t,e,["start",qe,"end","left","right"])}}),/:/,/\s/),e.region=i.get("region",null),e.vertical=i.get("vertical","");var a=i.get("line","auto");"auto"===a&&-1===ze.line&&(a=-1),e.line=a,e.linealign=i.get("linealign","start"),e.snaptolines=i.get("snaptolines",!0),e.size=i.get("size",100),e.align=i.get("align",qe);var n=i.get("position","auto");"auto"===n&&50===ze.position&&(n="start"===e.align||"left"===e.align?0:"end"===e.align||"right"===e.align?100:50),e.position=n}(t,e)}function je(t){return t.replace(//gi,"\n")}var ze=function(){function t(){this.state="initial",this.buffer="",this.decoder=new we,this.regionlist=[],this.cue=null,this.oncue=void 0,this.onparsingerror=void 0,this.onflush=void 0}var e=t.prototype;return e.parse=function(t){var e=this;function r(){var t=e.buffer,r=0;for(t=je(t);r>>0).tostring()};function nr(t,e,r){return ar(t.tostring())+ar(e.tostring())+ar(r)}function sr(t,e,r,i,n,s,o,l){var u,h=new ze,d=object(f.f)(new uint8array(t)).trim().replace(rr,"\n").split("\n"),c=[],f=object(tr.a)(e,r),g="00:00.000",v=0,p=0,m=!0,y=!1;h.oncue=function(t){var e=i[n],r=i.ccoffset,a=(v-f)/9e4;if(null!=e&&e.new&&(void 0!==p?r=i.ccoffset=e.start:function(t,e,r){var i=t[e],a=t[i.prevcc];if(!a||!a.new&&i.new)return t.ccoffset=t.presentationoffset=i.start,void(i.new=!1);for(;null!==(n=a)&&void 0!==n&&n.new;){var n;t.ccoffset+=i.start-a.start,i.new=!1,a=t[(i=a).prevcc]}t.presentationoffset=r}(i,n,a)),a&&(r=a-i.presentationoffset),y){var o=t.endtime-t.starttime,l=object(er.b)(9e4*(t.starttime+r-p),9e4*s)/9e4;t.starttime=l,t.endtime=l+o}var u=t.text.trim();t.text=decodeuricomponent(encodeuricomponent(u)),t.id||(t.id=nr(t.starttime,t.endtime,u)),t.endtime>0&&c.push(t)},h.onparsingerror=function(t){u=t},h.onflush=function(){u?l(u):o(c)},d.foreach((function(t){if(m){if(ir(t,"x-timestamp-map=")){m=!1,y=!0,t.substr(16).split(",").foreach((function(t){ir(t,"local:")?g=t.substr(6):ir(t,"mpegts:")&&(v=parseint(t.substr(7)))}));try{p=function(t){var e=parseint(t.substr(-3)),r=parseint(t.substr(-6,2)),i=parseint(t.substr(-9,2)),n=t.length>9?parseint(t.substr(0,t.indexof(":"))):0;if(!(object(a.a)(e)&&object(a.a)(r)&&object(a.a)(i)&&object(a.a)(n)))throw error("malformed x-timestamp-map: local:"+t);return e+=1e3*r,e+=6e4*i,e+=36e5*n}(g)/1e3}catch(t){y=!1,u=t}return}""===t&&(m=!1)}h.parse(t+"\n")})),h.flush()}function or(){return(or=object.assign||function(t){for(var e=1;e=0&&(c[0]=math.min(c[0],e),c[1]=math.max(c[1],r),h=!0,f/(r-e)>.5))return}if(h||a.push([e,r]),this.config.rendertexttracksnatively){var g=this.captionstracks[t];this.cues.newcue(g,e,r,i)}else{var v=this.cues.newcue(null,e,r,i);this.hls.trigger(n.a.cues_parsed,{type:"captions",cues:v,track:t})}},e.oninitptsfound=function(t,e){var r=this,i=e.frag,a=e.id,s=e.initpts,o=e.timescale,l=this.unparsedvttfrags;"main"===a&&(this.initpts[i.cc]=s,this.timescale[i.cc]=o),l.length&&(this.unparsedvttfrags=[],l.foreach((function(t){r.onfragloaded(n.a.frag_loaded,t)})))},e.getexistingtrack=function(t){var e=this.media;if(e)for(var r=0;r0&&this.mediawidth>0){var t=this.hls.levels;if(t.length){var e=this.hls;e.autolevelcapping=this.getmaxlevel(t.length-1),e.autolevelcapping>this.autolevelcapping&&this.streamcontroller&&this.streamcontroller.nextlevelswitch(),this.autolevelcapping=e.autolevelcapping}}},a.getmaxlevel=function(e){var r=this,i=this.hls.levels;if(!i.length)return-1;var a=i.filter((function(i,a){return t.islevelallowed(a,r.restrictedlevels)&&a<=e}));return this.clientrect=null,t.getmaxlevelbymediasize(a,this.mediawidth,this.mediaheight)},a.startcapping=function(){this.timer||(this.autolevelcapping=number.positive_infinity,this.hls.firstlevel=this.getmaxlevel(this.firstlevel),self.clearinterval(this.timer),this.timer=self.setinterval(this.detectplayersize.bind(this),1e3),this.detectplayersize())},a.stopcapping=function(){this.restrictedlevels=[],this.firstlevel=-1,this.autolevelcapping=number.positive_infinity,this.timer&&(self.clearinterval(this.timer),this.timer=void 0)},a.getdimensions=function(){if(this.clientrect)return this.clientrect;var t=this.media,e={width:0,height:0};if(t){var r=t.getboundingclientrect();e.width=r.width,e.height=r.height,e.width||e.height||(e.width=r.right-r.left||t.width||0,e.height=r.bottom-r.top||t.height||0)}return this.clientrect=e,e},t.islevelallowed=function(t,e){return void 0===e&&(e=[]),-1===e.indexof(t)},t.getmaxlevelbymediasize=function(t,e,r){if(!t||!t.length)return-1;for(var i,a,n=t.length-1,s=0;s=e||o.height>=r)&&(i=o,!(a=t[s+1])||i.width!==a.width||i.height!==a.height)){n=s;break}}return n},e=t,i=[{key:"contentscalefactor",get:function(){var t=1;try{t=self.devicepixelratio}catch(t){}return t}}],(r=[{key:"mediawidth",get:function(){return this.getdimensions().width*t.contentscalefactor}},{key:"mediaheight",get:function(){return this.getdimensions().height*t.contentscalefactor}}])&&tr(e.prototype,r),i&&tr(e,i),t}(),sr=function(){function t(t){this.hls=void 0,this.isvideoplaybackqualityavailable=!1,this.timer=void 0,this.media=null,this.lasttime=void 0,this.lastdroppedframes=0,this.lastdecodedframes=0,this.streamcontroller=void 0,this.hls=t,this.registerlisteners()}var e=t.prototype;return e.setstreamcontroller=function(t){this.streamcontroller=t},e.registerlisteners=function(){this.hls.on(n.a.media_attaching,this.onmediaattaching,this)},e.unregisterlisteners=function(){this.hls.off(n.a.media_attaching,this.onmediaattaching)},e.destroy=function(){this.timer&&clearinterval(this.timer),this.unregisterlisteners(),this.isvideoplaybackqualityavailable=!1,this.media=null},e.onmediaattaching=function(t,e){var r=this.hls.config;if(r.caplevelonfpsdrop){var i=e.media instanceof self.htmlvideoelement?e.media:null;this.media=i,i&&"function"==typeof i.getvideoplaybackquality&&(this.isvideoplaybackqualityavailable=!0),self.clearinterval(this.timer),this.timer=self.setinterval(this.checkfpsinterval.bind(this),r.fpsdroppedmonitoringperiod)}},e.checkfps=function(t,e,r){var i=performance.now();if(e){if(this.lasttime){var a=i-this.lasttime,s=r-this.lastdroppedframes,l=e-this.lastdecodedframes,u=1e3*s/a,h=this.hls;if(h.trigger(n.a.fps_drop,{currentdropped:s,currentdecoded:l,totaldroppedframes:r}),u>0&&s>h.config.fpsdroppedmonitoringthreshold*l){var d=h.currentlevel;o.b.warn("drop fps ratio greater than max allowed value for currentlevel: "+d),d>0&&(-1===h.autolevelcapping||h.autolevelcapping>=d)&&(d-=1,h.trigger(n.a.fps_drop_level_capping,{level:d,droppedlevel:h.currentlevel}),h.autolevelcapping=d,this.streamcontroller.nextlevelswitch())}}this.lasttime=i,this.lastdroppedframes=r,this.lastdecodedframes=e}},e.checkfpsinterval=function(){var t=this.media;if(t)if(this.isvideoplaybackqualityavailable){var e=t.getvideoplaybackquality();this.checkfps(t,e.totalvideoframes,e.droppedvideoframes)}else this.checkfps(t,t.webkitdecodedframecount,t.webkitdroppedframecount)},t}();!function(t){t.widevine="com.widevine.alpha",t.playready="com.microsoft.playready"}(er||(er={}));var lr="undefined"!=typeof self&&self.navigator&&self.navigator.requestmediakeysystemaccess?self.navigator.requestmediakeysystemaccess.bind(self.navigator):null;function ar(t,e){for(var r=0;r3)return void this.hls.trigger(n.a.error,{type:s.b.key_system_error,details:s.a.key_system_license_request_failed,fatal:!0});var u=3-this._requestlicensefailurecount+1;o.b.warn("retrying license request, "+u+" attempts left"),this._requestlicense(r,i)}}},a._generatelicenserequestchallenge=function(t,e){switch(t.mediakeysystemdomain){case er.widevine:return e}throw new error("unsupported key-system: "+t.mediakeysystemdomain)},a._requestlicense=function(t,e){o.b.log("requesting content license for key-system");var r=this._mediakeyslist[0];if(!r)return o.b.error("fatal error: media is encrypted but no key-system access has been obtained yet"),void this.hls.trigger(n.a.error,{type:s.b.key_system_error,details:s.a.key_system_no_access,fatal:!0});try{var i=this.getlicenseserverurl(r.mediakeysystemdomain),a=this._createlicensexhr(i,t,e);o.b.log("sending license request to url: "+i);var l=this._generatelicenserequestchallenge(r,t);a.send(l)}catch(t){o.b.error("failure requesting drm license: "+t),this.hls.trigger(n.a.error,{type:s.b.key_system_error,details:s.a.key_system_license_request_failed,fatal:!0})}},a.onmediaattached=function(t,e){if(this._emeenabled){var r=e.media;this._media=r,r.addeventlistener("encrypted",this._onmediaencrypted)}},a.onmediadetached=function(){var t=this._media,e=this._mediakeyslist;t&&(t.removeeventlistener("encrypted",this._onmediaencrypted),this._media=null,this._mediakeyslist=[],promise.all(e.map((function(t){if(t.mediakeyssession)return t.mediakeyssession.close().catch((function(){}))}))).then((function(){return t.setmediakeys(null)})).catch((function(){})))},a.onmanifestparsed=function(t,e){if(this._emeenabled){var r=e.levels.map((function(t){return t.audiocodec})).filter((function(t){return!!t})),i=e.levels.map((function(t){return t.videocodec})).filter((function(t){return!!t}));this._attemptkeysystemaccess(er.widevine,r,i)}},e=t,(r=[{key:"requestmediakeysystemaccess",get:function(){if(!this._requestmediakeysystemaccess)throw new error("no requestmediakeysystemaccess function configured");return this._requestmediakeysystemaccess}}])&&ar(e.prototype,r),i&&ar(e,i),t}(),kr=r(12),dr=/^age:\s*[\d.]+\s*$/m,_r=function(){function t(t){this.xhrsetup=void 0,this.requesttimeout=void 0,this.retrytimeout=void 0,this.retrydelay=void 0,this.config=null,this.callbacks=null,this.context=void 0,this.loader=null,this.stats=void 0,this.xhrsetup=t?t.xhrsetup:null,this.stats=new kr.a,this.retrydelay=0}var e=t.prototype;return e.destroy=function(){this.callbacks=null,this.abortinternal(),this.loader=null,this.config=null},e.abortinternal=function(){var t=this.loader;self.cleartimeout(this.requesttimeout),self.cleartimeout(this.retrytimeout),t&&(t.onreadystatechange=null,t.onprogress=null,4!==t.readystate&&(this.stats.aborted=!0,t.abort()))},e.abort=function(){var t;this.abortinternal(),null!==(t=this.callbacks)&&void 0!==t&&t.onabort&&this.callbacks.onabort(this.stats,this.context,this.loader)},e.load=function(t,e,r){if(this.stats.loading.start)throw new error("loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=t,this.config=e,this.callbacks=r,this.retrydelay=e.retrydelay,this.loadinternal()},e.loadinternal=function(){var t=this.config,e=this.context;if(t){var r=this.loader=new self.xmlhttprequest,i=this.stats;i.loading.first=0,i.loaded=0;var a=this.xhrsetup;try{if(a)try{a(r,e.url)}catch(t){r.open("get",e.url,!0),a(r,e.url)}r.readystate||r.open("get",e.url,!0)}catch(t){return void this.callbacks.onerror({code:r.status,text:t.message},e,r)}e.rangeend&&r.setrequestheader("range","bytes="+e.rangestart+"-"+(e.rangeend-1)),r.onreadystatechange=this.readystatechange.bind(this),r.onprogress=this.loadprogress.bind(this),r.responsetype=e.responsetype,self.cleartimeout(this.requesttimeout),this.requesttimeout=self.settimeout(this.loadtimeout.bind(this),t.timeout),r.send()}},e.readystatechange=function(){var t=this.context,e=this.loader,r=this.stats;if(t&&e){var i=e.readystate,a=this.config;if(!r.aborted&&i>=2)if(self.cleartimeout(this.requesttimeout),0===r.loading.first&&(r.loading.first=math.max(self.performance.now(),r.loading.start)),4===i){e.onreadystatechange=null,e.onprogress=null;var n=e.status;if(n>=200&&n<300){var s,l;if(r.loading.end=math.max(self.performance.now(),r.loading.first),l="arraybuffer"===t.responsetype?(s=e.response).bytelength:(s=e.responsetext).length,r.loaded=r.total=l,!this.callbacks)return;var u=this.callbacks.onprogress;if(u&&u(r,t,s,e),!this.callbacks)return;var h={url:e.responseurl,data:s};this.callbacks.onsuccess(h,r,t,e)}else r.retry>=a.maxretry||n>=400&&n<499?(o.b.error(n+" while loading "+t.url),this.callbacks.onerror({code:n,text:e.statustext},t,e)):(o.b.warn(n+" while loading "+t.url+", retrying in "+this.retrydelay+"..."),this.abortinternal(),this.loader=null,self.cleartimeout(this.retrytimeout),this.retrytimeout=self.settimeout(this.loadinternal.bind(this),this.retrydelay),this.retrydelay=math.min(2*this.retrydelay,a.maxretrydelay),r.retry++)}else self.cleartimeout(this.requesttimeout),this.requesttimeout=self.settimeout(this.loadtimeout.bind(this),a.timeout)}},e.loadtimeout=function(){o.b.warn("timeout while loading "+this.context.url);var t=this.callbacks;t&&(this.abortinternal(),t.ontimeout(this.stats,this.context,this.loader))},e.loadprogress=function(t){var e=this.stats;e.loaded=t.loaded,t.lengthcomputable&&(e.total=t.total)},e.getcacheage=function(){var t=null;if(this.loader&&dr.test(this.loader.getallresponseheaders())){var e=this.loader.getresponseheader("age");t=e?parsefloat(e):null}return t},t}();function ir(t){var e="function"==typeof map?new map:void 0;return(ir=function(t){if(null===t||(r=t,-1===function.tostring.call(r).indexof("[native code]")))return t;var r;if("function"!=typeof t)throw new typeerror("super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return cr(t,arguments,xr(this).constructor)}return i.prototype=object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),or(i,t)})(t)}function cr(t,e,r){return(cr=wr()?reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var a=new(function.bind.apply(t,i));return r&&or(a,r.prototype),a}).apply(null,arguments)}function wr(){if("undefined"==typeof reflect||!reflect.construct)return!1;if(reflect.construct.sham)return!1;if("function"==typeof proxy)return!0;try{return boolean.prototype.valueof.call(reflect.construct(boolean,[],(function(){}))),!0}catch(t){return!1}}function or(t,e){return(or=object.setprototypeof||function(t,e){return t.__proto__=e,t})(t,e)}function xr(t){return(xr=object.setprototypeof?object.getprototypeof:function(t){return t.__proto__||object.getprototypeof(t)})(t)}var pr=function(){function t(t){this.fetchsetup=void 0,this.requesttimeout=void 0,this.request=void 0,this.response=void 0,this.controller=void 0,this.context=void 0,this.config=null,this.callbacks=null,this.stats=void 0,this.loader=null,this.fetchsetup=t.fetchsetup||fr,this.controller=new self.abortcontroller,this.stats=new kr.a}var e=t.prototype;return e.destroy=function(){this.loader=this.callbacks=null,this.abortinternal()},e.abortinternal=function(){var t=this.response;t&&t.ok||(this.stats.aborted=!0,this.controller.abort())},e.abort=function(){var t;this.abortinternal(),null!==(t=this.callbacks)&&void 0!==t&&t.onabort&&this.callbacks.onabort(this.stats,this.context,this.response)},e.load=function(t,e,r){var i=this,n=this.stats;if(n.loading.start)throw new error("loader can only be used once.");n.loading.start=self.performance.now();var s=function(t,e){var r={method:"get",mode:"cors",credentials:"same-origin",signal:e};t.rangeend&&(r.headers=new self.headers({range:"bytes="+t.rangestart+"-"+string(t.rangeend-1)}));return r}(t,this.controller.signal),o=r.onprogress,l="arraybuffer"===t.responsetype,u=l?"bytelength":"length";this.context=t,this.config=e,this.callbacks=r,this.request=this.fetchsetup(t,s),self.cleartimeout(this.requesttimeout),this.requesttimeout=self.settimeout((function(){i.abortinternal(),r.ontimeout(n,t,i.response)}),e.timeout),self.fetch(this.request).then((function(r){if(i.response=i.loader=r,!r.ok){var s=r.status,u=r.statustext;throw new mr(u||"fetch, bad network response",s,r)}return n.loading.first=math.max(self.performance.now(),n.loading.start),n.total=parseint(r.headers.get("content-length")||"0"),o&&object(a.a)(e.highwatermark)?i.loadprogressively(r,n,t,e.highwatermark,o):l?r.arraybuffer():r.text()})).then((function(s){var l=i.response;self.cleartimeout(i.requesttimeout),n.loading.end=math.max(self.performance.now(),n.loading.first),n.loaded=n.total=s[u];var h={url:l.url,data:s};o&&!object(a.a)(e.highwatermark)&&o(n,t,s,l),r.onsuccess(h,n,t,l)})).catch((function(e){if(self.cleartimeout(i.requesttimeout),!n.aborted){var a=e.code||0;r.onerror({code:a,text:e.message},t,e.details)}}))},e.getcacheage=function(){var t=null;if(this.response){var e=this.response.headers.get("age");t=e?parsefloat(e):null}return t},e.loadprogressively=function(t,e,r,i,a){void 0===i&&(i=0);var n=new oe.a,s=t.body.getreader();return function o(){return s.read().then((function(s){if(s.done)return n.datalength&&a(e,r,n.flush(),t),promise.resolve(new arraybuffer(0));var l=s.value,u=l.length;return e.loaded+=u,u=i&&a(e,r,n.flush(),t)):a(e,r,l,t),o()})).catch((function(){return promise.reject()}))}()},t}();function fr(t,e){return new self.request(t.url,e)}var mr=function(t){var e,r;function i(e,r,i){var a;return(a=t.call(this,e)||this).code=void 0,a.details=void 0,a.code=r,a.details=i,a}return r=t,(e=i).prototype=object.create(r.prototype),e.prototype.constructor=e,or(e,r),i}(ir(error)),nr=pr,ur=/\s/;function br(){return(br=object.assign||function(t){for(var e=1;e=16?o--:o++;var f=je(l.trim()),g=nr(e,r,f);t&&t.cues&&t.cues.getcuebyid(g)||((n=new h(e,r,f)).id=g,n.line=d+1,n.align="left",n.position=10+math.min(80,10*math.floor(8*o/32)),u.push(n))}return t&&u.length&&(u.sort((function(t,e){return"auto"===t.line||"auto"===e.line?0:t.line>8&&e.line>8?e.line-t.line:t.line-e.line})),u.foreach((function(e){return o(t,e)}))),u}},enablecea708captions:!0,enablewebvtt:!0,enableimsc1:!0,captionstexttrack1label:"english",captionstexttrack1languagecode:"en",captionstexttrack2label:"spanish",captionstexttrack2languagecode:"es",captionstexttrack3label:"unknown cc",captionstexttrack3languagecode:"",captionstexttrack4label:"unknown cc",captionstexttrack4languagecode:"",rendertexttracksnatively:!0}),{},{subtitlestreamcontroller:pe,subtitletrackcontroller:be,timelinecontroller:mr,audiostreamcontroller:he,audiotrackcontroller:fe,emecontroller:rr});function vr(t){var e=t.loader;e!==nr&&e!==_r?(o.b.log("[config]: custom loader detected, cannot enable progressive streaming"),t.progressive=!1):function(){if(self.fetch&&self.abortcontroller&&self.readablestream&&self.request)try{return new self.readablestream({}),!0}catch(t){}return!1}()&&(t.loader=nr,t.progressive=!0,t.enablesoftwareaes=!0,o.b.log("[config]: progressive streaming enabled, using fetchloader"))}function wr(t,e){for(var r=0;re)return i;return 0}},{key:"maxautolevel",get:function(){var t=this.levels,e=this.autolevelcapping;return-1===e&&t&&t.length?t.length-1:e}},{key:"nextautolevel",get:function(){return math.min(math.max(this.abrcontroller.nextautolevel,this.minautolevel),this.maxautolevel)},set:function(t){this.abrcontroller.nextautolevel=math.max(this.minautolevel,t)}},{key:"audiotracks",get:function(){var t=this.audiotrackcontroller;return t?t.audiotracks:[]}},{key:"audiotrack",get:function(){var t=this.audiotrackcontroller;return t?t.audiotrack:-1},set:function(t){var e=this.audiotrackcontroller;e&&(e.audiotrack=t)}},{key:"subtitletracks",get:function(){var t=this.subtitletrackcontroller;return t?t.subtitletracks:[]}},{key:"subtitletrack",get:function(){var t=this.subtitletrackcontroller;return t?t.subtitletrack:-1},set:function(t){var e=this.subtitletrackcontroller;e&&(e.subtitletrack=t)}},{key:"media",get:function(){return this._media}},{key:"subtitledisplay",get:function(){var t=this.subtitletrackcontroller;return!!t&&t.subtitledisplay},set:function(t){var e=this.subtitletrackcontroller;e&&(e.subtitledisplay=t)}},{key:"lowlatencymode",get:function(){return this.config.lowlatencymode},set:function(t){this.config.lowlatencymode=t}},{key:"livesyncposition",get:function(){return this.latencycontroller.livesyncposition}},{key:"latency",get:function(){return this.latencycontroller.latency}},{key:"maxlatency",get:function(){return this.latencycontroller.maxlatency}},{key:"targetlatency",get:function(){return this.latencycontroller.targetlatency}},{key:"drift",get:function(){return this.latencycontroller.drift}},{key:"forcestartload",get:function(){return this.streamcontroller.forcestartload}}])&&wr(e.prototype,r),a&&wr(e,a),t}();yr.defaultconfig=void 0}]).default}));