"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 n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,r),n.l=!0,n.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 n in t)r.d(i,n,function(e){return t[e]}.bind(null,n));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(){},n={trace:i,debug:i,log:i,warn:i,info:i,error:i},a=n;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,n,a){void 0===a&&(a=!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,n)):s[t]={startpts:e,endpts:r,startdts:i,enddts:n,partial:a}},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(n.a)(this.programdatetime))return null;var t=object(n.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,n,a){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=n;var o=e.enumeratedstring("byterange");return o&&s.setbyterange(o,a),a&&(s.fragoffset=a.fragoffset+a.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),n=r(5),a=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,n,a=[];if(!e.length)return a;"data"in t?(r=t.data,i=t.start,n=t.end):(i=0,n=(r=t).bytelength);for(var u=i;u1?u+d:n;if(o(r.subarray(u+4,u+8))===e[0])if(1===e.length)a.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(a,f)}u=c}return a}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 n=[],a=i[0],s=a.data[0],o=0===s?8:16,u=l(a,o);o+=4;o+=0===s?8:16,o+=2;var d=a.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}(a,o);o+=2;for(var f=0;f>>31)return console.warn("sidx has hierarchical references (not supported)"),null;var m=l(a,g);g+=4,n.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:n,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 n(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(a);break;case 12:case 13:s=t[h++],u+=string.fromcharcode((31&a)<<6|63&s);break;case 14:s=t[h++],o=t[h++],u+=string.fromcharcode((15&a)<<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 n})),r.d(e,"b",(function(){return a})),r.d(e,"a",(function(){return s}));function i(t,e,r,i){void 0===r&&(r=1),void 0===i&&(i=!1);var n=t*e*r;return i?math.round(n):n}function n(t,e,r,n){return void 0===r&&(r=1),void 0===n&&(n=!1),i(t,e,1/r,n)}function a(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),n=r(2),a=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,n=o.b(t,0),a=n?n.length:0,s=this._audiotrack,h=this._id3track,c=n?o.d(n):void 0,f=t.length;for(0!==this.frameindex&&null!==this.initpts||(this.initpts=d(c,e)),n&&n.length>0&&h.samples.push({pts:this.initpts,dts:this.initpts,data:n}),i=this.initpts;a>>5}function m(t,e){return e+1=t.length)return!1;var i=p(t,e);if(i<=r)return!1;var n=e+i;return n===t.length||m(t,n)}return!1}function t(t,e,r,a,s){if(!t.samplerate){var o=function(t,e,r,a){var s,o,l,u,h=navigator.useragent.tolowercase(),d=a,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:"+a+", 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),a&&(-1!==a.indexof("mp4a.40.29")||-1!==a.indexof("mp4a.40.5"))||!a&&g>=6?o=g-3:((a&&-1!==a.indexof("mp4a.40.2")&&(g>=6&&1===l||/vivaldi/i.test(h))||!a&&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:n.b.media_error,details:n.a.frag_parsing_error,fatal:!0,reason:"invalid adts sampling index:"+g})}(e,r,a,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 b(t){return 9216e4/t}function e(t,e,r,i,n){var a=function(t,e,r,i,n){var a=v(t,e),s=p(t,e);if((s-=a)>0)return{headerlength:a,framelength:s,stamp:r+i*n}}(e,r,i,n,b(t.samplerate));if(a){var s,o=a.framelength,l=a.headerlength,u=a.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 n=i.prototype;return n.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 d=r,k=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,n){if(!(r+24>e.length)){var a=x(e,r);if(a&&r+a.framelength<=e.length){var s=i+n*(9e4*a.samplesperframe/a.samplerate),o={unit:e.subarray(r,r+a.framelength),pts:s,dts:s};return t.config=[],t.channelcount=a.channelcount,t.samplerate=a.samplerate,t.samples.push(o),{sample:o,length:a.framelength,missing:0}}}}function x(t,e){var r=t[e+1]>>3&3,i=t[e+1]>>1&3,n=t[e+2]>>4&15,a=t[e+2]>>2&3;if(1!==r&&0!==n&&15!==n&&3!==a){var s=t[e+2]>>1&1,o=t[e+3]>>6,l=1e3*_[14*(3===r?3-i:3===i?3:4)+n-1],u=i[3*(3===r?0:2===r?1:2)+a],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===k){var v=(navigator.useragent||"").match(/chrome\/(\d+)/i);k=v?parseint(v[1]):0}return!!k&&k<=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 m(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,n=32;n<=t.length-16;n+=160,i+=16)r.set(t.subarray(n,n+16),i);return r},e.getavcdecryptedunit=function(t,e){for(var r=new uint8array(e),i=0,n=32;n<=t.length-16;n+=160,i+=16)t.set(r.subarray(i,i+16),n);return t},e.decryptavcsample=function(t,e,r,i,n,a){var s=q(n.data),o=this.getavcencrypteddata(s),l=this;this.decryptbuffer(o.buffer,(function(o){n.data=l.getavcdecryptedunit(s,o),a||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 n=t[e].units;!(r>=n.length);r++){var a=n[r];if(!(a.data.length<=48||1!==a.type&&5!==a.type)){var s=this.decrypter.issync();if(this.decryptavcsample(t,e,r,i,a,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((k=a+5+e[a+4])===a+188)continue}else k=a+4;switch(d){case c:r&&(g&&(o=v(g))&&this.parseavcpes(o,!1),g={data:[],size:0}),g&&(g.data.push(e.subarray(k,a+188)),g.size+=a+188-k);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(k,a+188)),m.size+=a+188-k);break;case p:r&&(y&&(o=v(y))&&this.parseid3pes(o),y={data:[],size:0}),y&&(y.data.push(e.subarray(k,a+188)),y.size+=a+188-k);break;case 0:r&&(k+=e[k]+1),e=this._pmtid=j(e,k);break;case e:r&&(k+=e[k]+1);var _=h(e,k,!0===this.typesupported.mpeg||!0===this.typesupported.mp3,a);(c=_.avc)>0&&(u.pid=c),(v=_.audio)>0&&(h.pid=v,h.isaac=_.isaac),(p=_.id3)>0&&(d.pid=p),t&&!b&&(f.b.log("reparse from beginning"),t=!1,a=l-188),b=this.pmtparsed=!0;break;case 17:case 8191:break;default:t=!0}}else this.observer.emit(i.a.error,i.a.error,{type:n.b.media_error,details:n.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,n=t.id3track,a=i.pesdata,s=r.pesdata,o=n.pesdata;a&&(e=v(a))?(this.parseavcpes(e,!0),i.pesdata=null):i.pesdata=a,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),n.pesdata=null):n.pesdata=o},e.demuxsampleaes=function(t,e,r){var i=this.demux(t,r,!0,!this.config.progressive),n=this.sampleaes=new u(this.observer,this.config,e);return this.decrypt(i,n)},e.decrypt=function(t,e){return new promise((function(r){var i=t.audiotrack,n=t.avctrack;i.samples&&i.isaac?e.decryptaacsamples(i.samples,0,(function(){n.samples?e.decryptavcsamples(n.samples,0,0,(function(){r(t)})):r(t)})):n.samples&&e.decryptavcsamples(n.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,n=this._avctrack,a=this.parseavcnalu(t.data),s=this.avcsample,l=!1;t.data=null,s&&a.length&&!n.audfound&&(w(s,n),s=this.avcsample=k(!1,t.pts,t.dts,"")),a.foreach((function(e){switch(e.type){case 1:r=!0,s||(s=i.avcsample=k(!0,t.pts,t.dts,"")),s.frame=!0;var a=e.data;if(l&&a.length>4){var u=new n(a).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=[],b=0;b<16;b++)t.push(h.readubyte().tostring(16)),3!==b&&5!==b&&7!==b&&9!==b||t.push("-");for(var e=c-16,s=new uint8array(e),l=0;l=0){var d={data:t.subarray(u,l-a-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-a-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&&a>=0){var g={data:t.subarray(u,i),type:h,state:a};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 n.nalustate=a,o},e.parseaacpes=function(t){var e,r,a,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&&(n=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&u?n-(a=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((n-a)/9e4)+"s delta between pts and dts, align them"),n=a):a=n);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:n,dts:a,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 n=r[i-1];t.pts=n.pts,t.dts=n.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 b={data1:h,startpts:v,startdts:v,endpts:p,enddts:p,type:t,hasaudio:m,hasvideo:y,nb:1,dropped:0};return u.audio="audio"===b.type?b:void 0,u.video="audio"!==b.type?b: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,nt=tt,at=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:d,remux:nt},{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,n){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 at.a,this.observer=t,this.typesupported=e,this.config=r,this.vendor=i,this.id=n}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 n=this,a=r.transmuxing;a.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=n.push(t,null,r);return n.decryptionpromise=null,e})),this.decryptionpromise;var g=f.softwaredecrypt(s,c.key.buffer,c.iv.buffer);if(!g)return a.executeend=it(),ut(r);s=new uint8array(g)}var v=i||h,p=v.contiguous,m=v.discontinuity,y=v.trackswitch,t=v.accuratetimeoffset,b=v.timeoffset,e=d.audiocodec,s=d.videocodec,l=d.defaultinitpts,a=d.duration,r=d.initsegmentdata;if((m||y)&&this.resetinitsegment(r,e,s,a),m&&this.resetinitialtimestamp(l),p||this.resetcontiguity(),this.needsprobing(s,m,y)){if(o.datalength){var d=o.flush();s=object(l.a)(d,s)}this.configuretransmuxer(s,d)}var k=this.transmux(s,c,b,t,r),_=this.currenttransmuxstate;return _.contiguous=!0,_.discontinuity=!1,_.trackswitch=!1,a.executeend=it(),k},e.flush=function(t){var e=this,r=t.transmuxing;r.executestart=it();var a=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(a){var d=a.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:n.b.media_error,details:n.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,n=e.avctrack,a=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,n,a,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 n=this.demuxer,a=this.remuxer;n&&a&&(n.resetinitsegment(e,r,i),a.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,n){return e&&"sample-aes"===e.method?this.transmuxsampleaes(t,e,r,i,n):this.transmuxunencrypted(t,r,i,n)},e.transmuxunencrypted=function(t,e,r,i){var n=this.demuxer.demux(t,e,!1,!this.config.progressive),a=n.audiotrack,s=n.avctrack,o=n.id3track,l=n.texttrack;return{remuxresult:this.remuxer.remux(a,s,o,l,e,r,!1,this.id),chunkmeta:i}},e.transmuxsampleaes=function(t,e,r,i,n){var a=this;return this.demuxer.demuxsampleaes(t,e,r).then((function(t){return{remuxresult:a.remuxer.remux(t.audiotrack,t.avctrack,t.id3track,t.texttrack,r,i,!1,a.id),chunkmeta:n}}))},e.configuretransmuxer=function(t,e){for(var r,i=this.config,n=this.observer,a=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],b=257*c[p]^16843008*p;i[f]=b<<24|b>>>8,n[f]=b<<16|b>>>16,a[f]=b<<8|b>>>24,s[f]=b,b=16843009*t^65537*y^257*m^16843008*f,l[p]=b<<24|b>>>8,u[p]=b<<16|b>>>16,h[p]=b<<8|b>>>24,d[p]=b,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),n=1;n>24&255,o[1]=e>>16&255,o[2]=e>>8&255,o[3]=255&e,o.set(t,4),a=0,e=8;a>24&255,e>>16&255,e>>8&255,255&e,i>>24,i>>16&255,i>>8&255,255&i,n>>24,n>>16&255,n>>8&255,255&n,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/(a+1)),n=math.floor(r%(a+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,n>>24,n>>16&255,n>>8&255,255&n,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,n=e.samples||[],a=new uint8array(4+n.length);for(r=0;r>>8&255),a.push(255&n),a=a.concat(array.prototype.slice.call(i));for(r=0;r>>8&255),s.push(255&n),s=s.concat(array.prototype.slice.call(i));var o=t.box(t.types.avcc,new uint8array([1,a[3],a[4],a[5],255,224|e.sps.length].concat(a).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,n=e.width,s=e.height,o=math.floor(i/(a+1)),l=math.floor(i%(a+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,n>>8&255,255&n,0,0,s>>8&255,255&s,0,0]))},t.traf=function(e,r){var i=t.sdtp(e),n=e.id,s=math.floor(r/(a+1)),o=math.floor(r%(a+1));return t.box(t.types.traf,t.box(t.types.tfhd,new uint8array([0,0,0,0,n>>24,n>>16&255,n>>8&255,255&n])),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,n,a,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,a>>>16&255,a>>>8&255,255&a,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,n,a,s,o){var l,u,c,f,g,v,p=n,m=n,t=t.pid>-1,b=e.pid>-1,e=e.samples.length,s=t.samples.length>0,l=e>1;if((!t||s)&&(!b||l)||this.isgenerated||s){this.isgenerated||(c=this.generateis(t,e,n));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 "+e+" video samples due to a missing keyframe");var d=this.getvideostartpts(e.samples);e.samples=e.samples.slice(r),e.dropped+=r,m+=(e.samples[0].pts-d)/(e.timescale||9e4)}else-1===r&&(h.b.warn("[mp4-remuxer]: no keyframe found out of "+e+" video samples"),v=!1);if(this.isgenerated){if(s&&l){var k=this.getvideostartpts(e.samples),_=(y(t.samples[0].pts,k)-k)/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,n)),u=this.remuxaudio(t,p,this.isaudiocontiguous,a,b||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,n)),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,n)),i.samples.length&&(f=this.remuxtext(i,n))),{audio:u,video:l,initsegment:c,independent:v,text:f,id3:g}},e.generateis=function(t,e,r){var n,a,s,l=t.samples,u=e.samples,h=this.typesupported,d={},c=!object(i.a)(this._initpts),f="audio/mp4";if(c&&(n=a=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,n=a=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);a=math.min(a,y(u[0].dts,g)-v),n=math.min(n,g-v)}if(object.keys(d).length)return this.isgenerated=!0,c&&(this._initpts=n,this._initdts=a),{tracks:d,initpts:n,timescale:s}},e.remuxvideo=function(t,e,r,i){var n,a,s,d=t.inputtimescale,v=t.samples,m=[],b=v.length,e=this._initpts,s=this.nextavcdts,l=8,a=number.positive_infinity,r=number.negative_infinity,d=0,k=!1;r&&null!==s||(s=e*d-(v[0].pts-y(v[0].dts,v[0].pts)));for(var _=0;_i.pts){d=math.max(math.min(d,i.pts-i.dts),-18e3)}i.dts0?_-1:_].dts&&(k=!0)}k&&v.sort((function(t,e){var r=t.dts-e.dts,i=t.pts-e.pts;return r||i})),a=v[0].dts,s=v[v.length-1].dts;var c=math.round((s-a)/(b-1));if(d<0){if(d<-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=d,o=0;oc;if(m||p<-1){m?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"),a=s;var f=v[0].pts-p;v[0].dts=a,v[0].pts=f,h.b.log("video: first pts/dts adjusted: "+object(c.b)(f,!0)+"/"+object(c.b)(a,!0)+", delta: "+object(c.b)(p,!0)+" ms")}}p&&(a=math.max(0,a));for(var n=0,u=0,b=0;b0?x-1:x].dts;if(it.stretchshortvideotrack&&null!==this.nextaudiopts){var at=math.floor(it.maxbufferhole*d),st=(i?a+i*d:this.nextaudiopts)-z.pts;st>at?((n=st-nt)<0&&(n=nt),h.b.log("[mp4-remuxer]: it is approximately "+st/90+" ms to the next segment; using duration "+n/90+" ms for the last video frame.")):n=nt}else n=nt}var ot=math.round(z.pts-z.dts);m.push(new t(z.key,n,$,ot))}if(m.length&&g&&g<70){var lt=m[0].flags;lt.dependson=2,lt.isnonsync=0}this.nextavcdts=s=s+n,this.isvideocontiguous=!0;var ut={data1:o.moof(t.sequencenumber++,a,f({},t,{samples:m})),data2:w,startpts:a/d,endpts:(r+n)/d,startdts:a/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,a){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=[],b=t.samples,e=p?0:8,s=this.nextaudiopts||-1,l=e*s;if(this.isaudiocontiguous=r=r||b.length&&s>0&&(i&&math.abs(l-s)<9e3||math.abs(y(b[0].pts-v,l)-s)<20*g),b.foreach((function(t){t.pts=y(t.pts-v,l)})),!r||s<0){if(!(b=b.filter((function(t){return t.pts>=0}))).length)return;s=0===a?0:i?math.max(0,l):b[0].pts}if(t.isaac)for(var a=void 0!==a,r=this.config.maxaudioframesdrift,d=0,k=s;d=r*g&&w<1e4&&a){var o=math.round(c/g);(k=i-o*g)<0&&(o--,k+=g),0===d&&(this.nextaudiopts=s=k),h.b.warn("[mp4-remuxer]: injecting "+o+" audio frame @ "+(k/s).tofixed(3)+"s due to "+math.round(1e3*c/s)+" ms gap.");for(var x=0;x0))return;b+=e;try{f=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(f.buffer).setuint32(0,b),f.set(o.types.mdat,4))}f.set(v,e);var y=v.bytelength;e+=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:f,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 a=t.inputtimescale,s=a/(t.samplerate?t.samplerate:a),o=this.nextaudiopts,l=(null!==o?o:i.startdts*a)+this._initdts,u=i.enddts*a+this._initdts,d=1024*s,c=math.ceil((u-l)/d),f=n.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 b(t)},b=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 a}));var i=r(11);function n(t,e){for(var r=0;r0}),!1)}t.exports=function(t,e){e=e||{};var n={main:r.m},o=e.all?{main:object.keys(n.main)}:function(t,e){for(var r={main:[e]},i={main:[]},n={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(n.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,b=new regexp([/#extinf:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\s[\s ]*)/.source,/#ext-x-byterange:*(.+)/.source,/#ext-x-program-date-time:(.+)/.source,/#.*/.source].join("|"),"g"),e=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,n=[],a={},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)),n.push(l)}else if(i[3]){var h=new v(i[3]);h["data-id"]&&(s=!0,a[h["data-id"]]=h)}return{levels:n,sessiondata:s?a:null}},t.parsemasterplaylistmedia=function(e,r,i,n){var a;void 0===n&&(n=[]);var s=[],o=0;for(t.lastindex=0;null!==(a=t.exec(e));){var l=new v(a[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(n.length){var h=t.findgroup(n,u.groupid)||n[0];r(u,h,"audiocodec"),r(u,h,"textcodec")}s.push(u)}}return s},t.parselevelplaylist=function(t,e,r,a,s){var l,h,f,g=new d(e),p=g.fragments,m=null,y=0,t=0,l=0,a=0,r=null,k=new u.b(a,e),_=-1,i=!1;for(b.lastindex=0,g.m3u8=t;null!==(l=b.exec(t));){i&&(i=!1,(k=new u.b(a,e)).start=l,k.sn=y,k.cc=a,k.level=r,m&&(k.initsegment=m,k.rawprogramdatetime=m.rawprogramdatetime));var c=l[1];if(c){k.duration=parsefloat(c);var w=(" "+l[2]).slice(1);k.title=w||null,k.taglist.push(w?["inf",c,w]:["inf",c])}else if(l[3])object(n.a)(k.duration)&&(k.start=l,f&&(k.levelkey=f),k.sn=y,k.level=r,k.cc=a,k.urlid=s,p.push(k),k.relurl=(" "+l[3]).slice(1),d(k,r),r=k,l+=k.duration,y++,t=0,i=!0);else if(l[4]){var o=(" "+l[4]).slice(1);r?k.setbyterange(o,r):k.setbyterange(o)}else if(l[5])k.rawprogramdatetime=(" "+l[5]).slice(1),k.taglist.push(["program-date-time",k.rawprogramdatetime]),-1===_&&(_=p.length);else{if(!(l=l[0].match(e))){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(n.a)(x)&&(g.starttimeoffset=x);break;case"map":var z=new v(p);k.relurl=z.uri,z.byterange&&k.setbyterange(z.byterange),k.level=r,k.sn="initsegment",f&&(k.levelkey=f),k.initsegment=null,m=k,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),k,e,tt,z);j.push(et),k.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&&(d(k,r),k.cc=a,g.fragmenthint=k);var nt=p.length,at=p[0],st=p[nt-1];if((l+=g.skippedsegments*g.targetduration)>0&&nt&&st){g.averagetargetduration=l/nt;var ot=st.sn;g.endsn="initsegment"!==ot?ot:0,at&&(g.startcc=at.cc,at.initsegment||g.fragments.every((function(t){return t.relurl&&(e=t.relurl,s.test(null!=(r=null===(n=i.parseurl(e))||void 0===n?void 0:n.path)?r:""));var e,r,n}))&&(o.b.warn("mp4 fragments found but no init segment (probably no map, incomplete m3u8), trying to fetch sidx"),(k=new u.b(a,e)).relurl=st.relurl,k.level=r,k.sn="initsegment",at.initsegment=k,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 n=t[i];if(!n)return;n.programdatetime=r.programdatetime-1e3*n.duration,r=n}}(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 n=i.filter((function(t){return 0===t.lastindexof("avc1",0)||0===t.lastindexof("mp4a",0)}));e[r+"codec"]=n.length>0?n[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 d(t,e){t.rawprogramdatetime?t.programdatetime=date.parse(t.rawprogramdatetime):null!=e&&e.programdatetime&&(t.programdatetime=e.endprogramdatetime),object(n.a)(t.programdatetime)||(t.programdatetime=null,t.rawprogramdatetime=null)}var k=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(a.a.manifest_loading,this.onmanifestloading,this),t.on(a.a.level_loading,this.onlevelloading,this),t.on(a.a.audio_track_loading,this.onaudiotrackloading,this),t.on(a.a.subtitle_track_loading,this.onsubtitletrackloading,this)},e.unregisterlisteners=function(){var t=this.hls;t.off(a.a.manifest_loading,this.onmanifestloading,this),t.off(a.a.level_loading,this.onlevelloading,this),t.off(a.a.audio_track_loading,this.onaudiotrackloading,this),t.off(a.a.subtitle_track_loading,this.onsubtitletrackloading,this)},e.createinternalloader=function(t){var e=this.hls.config,r=e.ploader,i=e.loader,n=new(r||i)(e);return t.loader=n,this.loaders[t.type]=n,n},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:k.a.manifest,url:r,deliverydirectives:null})},e.onlevelloading=function(t,e){var r=e.id,i=e.level,n=e.url,a=e.deliverydirectives;this.load({id:r,groupid:null,level:i,responsetype:"text",type:k.a.level,url:n,deliverydirectives:a})},e.onaudiotrackloading=function(t,e){var r=e.id,i=e.groupid,n=e.url,a=e.deliverydirectives;this.load({id:r,groupid:i,level:null,responsetype:"text",type:k.a.audio_track,url:n,deliverydirectives:a})},e.onsubtitletrackloading=function(t,e){var r=e.id,i=e.groupid,n=e.url,a=e.deliverydirectives;this.load({id:r,groupid:i,level:null,responsetype:"text",type:k.a.subtitle_track,url:n,deliverydirectives:a})},e.load=function(t){var e,r,i,n,a,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 k.a.manifest:r=l.manifestloadingmaxretry,i=l.manifestloadingtimeout,n=l.manifestloadingretrydelay,a=l.manifestloadingmaxretrytimeout;break;case k.a.level:case k.a.audio_track:case k.a.subtitle_track:r=0,i=l.levelloadingtimeout;break;default:r=l.levelloadingmaxretry,i=l.levelloadingtimeout,n=l.levelloadingretrydelay,a=l.levelloadingmaxretrytimeout}if((u=this.createinternalloader(t),null!==(e=t.deliverydirectives)&&void 0!==e&&e.part)&&(t.type===k.a.level&&null!==t.level?s=this.hls.levels[t.level].details:t.type===k.a.audio_track&&null!==t.id?s=this.hls.audiotracks[t.id].details:t.type===k.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:n,maxretrydelay:a,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 n=t.data;0===n.indexof("#extm3u")?(e.parsing.start=performance.now(),n.indexof("#extinf:")>0||n.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 n=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:""}));n.trigger(a.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(n.a)(l)?l:0,f=object(n.a)(u)?u:c,g=function(t){switch(t.type){case k.a.audio_track:return k.b.audio;case k.a.subtitle_track:return k.b.subtitle;default:return k.b.main}}(r),p=l.parselevelplaylist(t.data,d,f,g,c);if(p.fragments.length){if(h===k.a.manifest){var m={attrs:new v({}),bitrate:0,details:p,name:"",url:d};o.trigger(a.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(a.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,n=e.leveldetails;i.foreach((function(t,e){var i=t.info,a=n.fragments[e];0===a.byterange.length&&a.setbyterange(string(1+i.end-i.start)+"@"+string(i.start)),a.initsegment&&a.initsegment.setbyterange(string(r.moovendoffset)+"@0")}))}},e.handlemanifestparsingerror=function(t,e,r,i){this.hls.trigger(a.a.error,{type:s.b.network_error,details:s.a.manifest_parsing_error,fatal:e.type===k.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 n=s.a.unknown,l=!1,u=this.getinternalloader(t);switch(t.type){case k.a.manifest:n=r?s.a.manifest_load_timeout:s.a.manifest_load_error,l=!0;break;case k.a.level:n=r?s.a.level_load_timeout:s.a.level_load_error,l=!1;break;case k.a.audio_track:n=r?s.a.audio_track_load_timeout:s.a.audio_track_load_error,l=!1;break;case k.a.subtitle_track:n=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:n,fatal:l,url:t.url,loader:u,context:t,networkdetails:e};i&&(h.response=i),this.hls.trigger(a.a.error,h)},e.handleplaylistloaded=function(t,e,r,i){var n=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)),n){case k.a.manifest:case k.a.level:this.hls.trigger(a.a.level_loaded,{details:h,level:s||0,id:o||0,stats:e,networkdetails:i,deliverydirectives:d});break;case k.a.audio_track:this.hls.trigger(a.a.audio_track_loaded,{details:h,id:o||0,groupid:l||"",stats:e,networkdetails:i,deliverydirectives:d});break;case k.a.subtitle_track:this.hls.trigger(a.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(a.a.key_loading,this.onkeyloading,this)},e._unregisterlisteners=function(){this.hls.off(a.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,n=this.loaders[i];if(r.decryptdata){var s=r.decryptdata.uri;if(s!==this.decrypturl||null===this.decryptkey){var l=this.hls.config;if(n&&(o.b.warn("abort previous key loader for type:"+i),n.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(a.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(a.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(a.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(a.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 n=function(t,e,r){var i=[],n=function(t,e){if(et[r].endtime)return-1;var i=0,n=r;for(;i<=n;){var a=math.floor((n+i)/2);if(et[a].starttime&&i-1)for(var a=n,s=t.length;a=e&&o.endtime<=r)i.push(o);else if(o.starttime>r)return i}return i}(t.cues,e,r),a=0;a.05&&this.forwardbufferlength>1){var u=math.min(2,math.max(1,a)),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)}}}}},n.estimateliveedge=function(){var t=this.leveldetails;return null===t?null:t.edge+t.age},n.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,n=this.config,a=n.livesyncduration,s=n.livesyncdurationcount,o=n.lowlatencymode,l=this.hls.userconfig,u=o&&r||e;(l.livesyncduration||l.livesyncdurationcount||0===u)&&(u=void 0!==a?a: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,n=t-e-this.edgestalled,a=i-r.totalduration,s=i-(this.config.lowlatencymode&&r.parttarget||r.targetduration);return math.min(math.max(a,n),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?(a=r-t.start,i=t):(a=t.start-r,i=e),i.duration!==a&&(i.duration=a)}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,a,s){i-r<=0&&(o.b.warn("fragment should have a positive duration",e),i=r+e.duration,s=a+e.duration);var l=r,u=i,h=e.startpts,d=e.endpts;if(object(n.a)(h)){var c=math.abs(h-r);object(n.a)(e.deltapts)?e.deltapts=math.max(c,e.deltapts):e.deltapts=c,l=math.max(r,h),r=math.min(r,h),a=math.min(a,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=a,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;a--){var s=i[a].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,n=math.max(t.startsn,e.startsn)-e.startsn,a=(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=n;u<=a;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(n.a)(o))return new k(o,object(n.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,n=e.details,a=e.stats,s=a.loading.end?math.max(0,self.performance.now()-a.loading.end):0;if(n.advanceddatetime=date.now()-s,n.live||null!=r&&r.live){if(n.reloaded(r),r&&this.log("live playlist "+t+" "+(n.advanced?"refreshed "+n.lastpartsn+"-"+n.lastpartindex:"missed")),r&&n.fragments.length>0&&q(r,n),!this.canload||!n.live)return;var o,l=void 0,u=void 0;if(n.canblockreload&&n.endsn&&n.advanced){var h=this.hls.config.lowlatencymode,d=n.lastpartsn,c=n.endsn,f=n.lastpartindex,g=d===c;-1!==f?(l=g?c+1:d,u=g?h?0:f:f+1):l=c+1;var v=n.age,p=v+n.ageheader,m=math.min(p-n.parttarget,1.5*n.targetduration);if(m>0){if(r&&m>r.tuneingoal)this.warn("cdn tune-in goal increased from: "+r.tuneingoal+" to: "+m+" with playlist age: "+n.age),m=0;else{var y=math.floor(m/n.targetduration);if(l+=y,void 0!==u)u+=math.round(m%n.targetduration/n.parttarget);this.log("cdn tune-in age: "+n.ageheader+"s last advanced "+v.tofixed(2)+"s goal: "+m+" skip sn "+y+" to part "+u)}n.tuneingoal=m}if(o=this.getdeliverydirectives(n,e.deliverydirectives,l,u),h||!g)return void this.loadplaylist(o)}else o=this.getdeliverydirectives(n,e.deliverydirectives,l,u);var t=function(t,e){var r,i=1e3*t.leveltargetduration,n=i/2,a=t.age,s=a>0&&a<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(n,2*o),u),t.availabilitydelay=(t.availabilitydelay||0)+r}else r=n;else s?(l=math.min(l||i/2,a),t.availabilitydelay=l,r=l+i-a):r=i-o;return math.round(r)}(n,a);void 0!==l&&n.canblockreload&&(t-=n.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 n=function(t,e){var r=t.canskipuntil,i=t.canskipdateranges,n=t.endsn;return r&&(void 0!==e?e-n: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 a=math.min(math.pow(2,this.retrycount)*i.levelloadingretrydelay,i.levelloadingmaxretrytimeout);this.timer=self.settimeout((function(){return r.loadplaylist()}),a),this.warn("retry playlist loading #"+this.retrycount+" in "+a+' ms after "'+t.details+'"')}else this.warn('cannot recover from error "'+t.details+'"'),this.cleartimer(),t.fatal=!0;return n},t}();function $(){return($=object.assign||function(t){for(var e=1;e0){r=n[0].bitrate,n.sort((function(t,e){return t.bitrate-e.bitrate})),this._levels=n;for(var f=0;fthis.hls.config.fragloadingmaxretry&&(a=r.frag.level)):a=r.frag.level}break;case s.a.level_load_error:case s.a.level_load_timeout:i&&(i.deliverydirectives&&(l=!1),a=i.level),o=!0;break;case s.a.remux_alloc_error:a=r.level,o=!0}void 0!==a&&this.recoverlevel(r,a,o,l)}}},u.recoverlevel=function(t,e,r,i){var n=t.details,a=this._levels[e];if(a.loaderror++,r){if(!this.retryloadingorfail(t))return void(this.currentlevelindex=-1);t.levelretry=!0}if(i){var s=a.url.length;if(s>1&&a.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===k.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,n=e.level,a=e.details,s=this._levels[n];if(!s)return this.warn("invalid level index "+n),void(null!==(i=e.deliverydirectives)&&void 0!==i&&i.skip&&(a.deltaupdatefailed=!0));n===this.currentlevelindex?(0===s.fragmenterror&&(s.loaderror=0,this.retrycount=0),this.playlistloaded(n,e,s.details)):null!==(r=e.deliverydirectives)&&void 0!==r&&r.skip&&(a.deltaupdatefailed=!0)},u.onaudiotrackswitched=function(t,e){var r=this.hls.levels[this.currentlevelindex];if(r&&r.audiogroupids){for(var i=-1,n=this.hls.audiotracks[e.id].groupid,a=0;a0){var i=r.urlid,n=r.url[i];if(t)try{n=t.adddirectives(n)}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+" "+n),this.cleartimer(),this.hls.trigger(a.a.level_loading,{url:n,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,n){return n!==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(a.a.levels_updated,{levels:i})},n=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(a.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 n=this.currentlevelindex,o=r[n],l=r[t];this.log("switching to level "+t+" from "+n),this.currentlevelindex=t;var u=$({},l,{level:t,maxbitrate:l.maxbitrate,uri:l.uri,urlid:l.urlid});delete u._urlid,this.hls.trigger(a.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(n.prototype,o),l&&j(n,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(a.a.buffer_appended,this.onbufferappended,this),t.on(a.a.frag_buffered,this.onfragbuffered,this),t.on(a.a.frag_loaded,this.onfragloaded,this)},e._unregisterlisteners=function(){var t=this.hls;t.off(a.a.buffer_appended,this.onbufferappended,this),t.off(a.a.frag_buffered,this.onfragbuffered,this),t.off(a.a.frag_loaded,this.onfragloaded,this)},e.destroy=function(){this._unregisterlisteners(),this.fragments=this.timeranges=null},e.getappendedfrag=function(t,e){if(e===k.b.main){var r=this.activefragment,i=this.activeparts;if(!r)return null;if(i)for(var n=i.length;n--;){var a=i[n],s=a?a.end:r.appendedpts;if(a.start<=t&&void 0!==s&&t<=s)return n>9&&(this.activeparts=i.slice(n-9)),a}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),n=i.length;n--;){var a=r[i[n]];if((null==a?void 0:a.body.type)===e&&a.buffered){var s=a.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(n){var a=i.fragments[n];if(a)if(a.buffered){var s=a.range[t];s&&s.time.some((function(t){var r=!i.istimebuffered(t.startpts,t.endpts,e);return r&&i.removefragment(a.body),r}))}else a.body.type===r&&i.removefragment(a.body)}))},e.detectpartialfragments=function(t){var e=this,r=this.timeranges,i=t.frag,n=t.part;if(r&&"initsegment"!==i.sn){var a=at(i),s=this.fragments[a];s&&(object.keys(r).foreach((function(t){var a=i.elementarystreams[t];if(a){var o=r[t],l=null!==n||!0===a.partial;s.range[t]=e.getbufferedtimes(i,n,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=at(t),r=this.fragments[e];r&&(r.backtrack=r.loaded=null,r.buffered=!0)},e.getbufferedtimes=function(t,e,r,i){for(var n={time:[],partial:r},a=e?e.start:t.start,s=e?e.end:t.end,o=t.minendpts||s,l=t.maxstartpts||a,u=0;u=h&&o<=d){n.time.push({startpts:math.max(a,i.start(u)),endpts:math.min(s,i.end(u))});break}if(ah)n.partial=!0,n.time.push({startpts:math.max(a,i.start(u)),endpts:math.min(s,i.end(u))});else if(s<=h)break}return n},e.getpartialfragment=function(t){var e,r,i,n=null,a=0,s=this.bufferpadding,o=this.fragments;return object.keys(o).foreach((function(l){var u=o[l];u&&nt(u)&&(r=u.body.start-s,i=u.body.end+s,t>=r&&t<=i&&(e=math.min(t-r,i-t),a<=e&&(n=u.body,a=e)))})),n},e.getstate=function(t){var e=at(t),r=this.fragments[e];return r?r.buffered?nt(r)?tt.partial:tt.ok:r.backtrack?tt.backtracked:tt.appending:tt.not_loaded},e.backtrack=function(t,e){var r=at(t),i=this.fragments[r];if(!i||i.backtrack)return null;var n=i.backtrack=e||i.loaded;return i.loaded=null,n},e.getbacktrackdata=function(t){var e=at(t),r=this.fragments[e];if(r){var i,n=r.backtrack;if(null!=n&&null!==(i=n.payload)&&void 0!==i&&i.bytelength)return n;this.removefragment(t)}return null},e.istimebuffered=function(t,e,r){for(var i,n,a=0;a=i&&e<=n)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 n=at(r);this.fragments[n]={body:r,loaded:e,backtrack:null,buffered:!1,range:object.create(null)}}},e.onbufferappended=function(t,e){var r=this,i=e.frag,n=e.part,a=e.timeranges;if(i.type===k.b.main)if(this.activefragment=i,n){var s=this.activeparts;s||(this.activeparts=s=[]),s.push(n)}else this.activeparts=null;this.timeranges=a,object.keys(a).foreach((function(t){var e=a[t];if(r.detectevictedfragments(t,e),!n)for(var s=0;st&&i.removefragment(s)}}))},e.removefragment=function(t){var e=at(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 nt(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 at(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),n=0;n=i.start(n)&&r<=i.end(n))return!0}catch(t){}return!1},t.bufferinfo=function(e,r,i){try{if(e){var n,a=t.getbuffered(e),s=[];for(n=0;ns&&(i[a-1].end=t[n].end):i.push(t[n])}else i.push(t[n])}else i=t;for(var o,l=0,u=e,h=e,d=0;d=c&&er.startcc||t&&t.cc0)r=n+1;else{if(!(s<0))return a;i=n-1}}return null}};function pt(t,e,r){if(null===e||!array.isarray(t)||!t.length||!object(n.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 tt(t,e,r){var i=1e3*math.min(e,r.duration+(r.deltapts?r.deltapts:0));return(r.endprogramdatetime||0)-i>t}function bt(t){var e="function"==typeof map?new map:void 0;return(bt=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,at(this).constructor)}return i.prototype=object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),lt(i,t)})(t)}function et(t,e,r){return(et=st()?reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var n=new(function.bind.apply(t,i));return r&<(n,r.prototype),n}).apply(null,arguments)}function st(){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 lt(t,e){return(lt=object.setprototypeof||function(t,e){return t.__proto__=e,t})(t,e)}function at(t){return(at=object.setprototypeof?object.getprototypeof:function(t){return t.__proto__||object.getprototypeof(t)})(t)}var rt=math.pow(2,17),dt=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 _t({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 n=this.config,a=n.floader,o=n.loader;return new promise((function(i,l){r.loader&&r.loader.destroy();var u=r.loader=t.loader=a?new a(n):new o(n),h=kt(t),d={timeout:n.fragloadingtimeout,maxretry:0,retrydelay:0,maxretrydelay:n.fragloadingmaxretrytimeout,highwatermark:rt};t.stats=u.stats,u.load(h,d,{onsuccess:function(e,n,a,s){r.resetloader(t,u),i({frag:t,part:null,payload:e.data,networkdetails:s})},onerror:function(e,i,n){r.resetloader(t,u),l(new _t({type:s.b.network_error,details:s.a.frag_load_error,fatal:!1,frag:t,response:e,networkdetails:n}))},onabort:function(e,i,n){r.resetloader(t,u),l(new _t({type:s.b.network_error,details:s.a.internal_aborted,fatal:!1,frag:t,networkdetails:n}))},ontimeout:function(e,i,n){r.resetloader(t,u),l(new _t({type:s.b.network_error,details:s.a.frag_load_timeout,fatal:!1,frag:t,networkdetails:n}))},onprogress:function(r,i,n,a){e&&e({frag:t,part:null,payload:n,networkdetails:a})}})}))},e.loadpart=function(t,e,r){var i=this;this.abort();var n=this.config,a=n.floader,o=n.loader;return new promise((function(l,u){i.loader&&i.loader.destroy();var h=i.loader=t.loader=a?new a(n):new o(n),d=kt(t,e),c={timeout:n.fragloadingtimeout,maxretry:0,retrydelay:0,maxretrydelay:n.fragloadingmaxretrytimeout,highwatermark:rt};e.stats=h.stats,h.load(d,c,{onsuccess:function(n,a,s,o){i.resetloader(t,h),i.updatestatsfrompart(t,e);var u={frag:t,part:e,payload:n.data,networkdetails:o};r(u),l(u)},onerror:function(r,n,a){i.resetloader(t,h),u(new _t({type:s.b.network_error,details:s.a.frag_load_error,fatal:!1,frag:t,part:e,response:r,networkdetails:a}))},onabort:function(r,n,a){t.stats.aborted=e.stats.aborted,i.resetloader(t,h),u(new _t({type:s.b.network_error,details:s.a.internal_aborted,fatal:!1,frag:t,part:e,networkdetails:a}))},ontimeout:function(r,n,a){i.resetloader(t,h),u(new _t({type:s.b.network_error,details:s.a.frag_load_timeout,fatal:!1,frag:t,part:e,networkdetails:a}))}})}))},e.updatestatsfrompart=function(t,e){var r=t.stats,i=e.stats,n=i.total;if(r.loaded+=i.loaded,n){var a=math.round(t.duration/e.duration),s=math.min(math.round(r.loaded/n),a),o=(a-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,headers:{},rangestart:0,rangeend:0},a=r.byterangestartoffset,s=r.byterangeendoffset;return object(n.a)(a)&&object(n.a)(s)&&(i.rangestart=a,i.rangeend=s),i}var _t=function(t){var e,r;function i(e){for(var r,i=arguments.length,n=new array(i>1?i-1:0),a=1;ae.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(n),s.key.buffer,s.iv.buffer).then((function(e){var n=self.performance.now();return i.trigger(a.a.frag_decrypted,{frag:t,payload:e,stats:{tstart:o,tdecrypt:n}}),r.payload=e,r}))}return r})).then((function(r){var i=e.fragcurrent,n=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=pt,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&&n.trigger(a.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+" "+ct.tostring(lt.getbuffered(r))),this.state=pt,this.tick()},c._handlefragmentloadcomplete=function(t){var e=this.transmuxer;if(e){var r=t.frag,i=t.part,n=t.partsloaded,a=!n||0===n.length||n.some((function(t){return!t})),s=new ut(r.level,r.sn,r.stats.chunkcount+1,0,i?i.index:-1,!a);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(a.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(n.a)(t.sn)&&!this.bitratetest&&(this.nextloadposition=t.start+t.duration),this.state=ft,this.hls.trigger(a.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 n=this;return new promise((function(s,o){var l=[];!function r(u){var h=e[u];n.fragmentloader.loadpart(t,h,i).then((function(i){l[h.index]=i;var o=i.part;n.hls.trigger(a.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(a.a.error,e),null},c._handletransmuxerflush=function(t){var e=this.getcurrentcontext(t);if(e&&this.state===bt){var r=e.frag,i=e.part,n=e.level,a=self.performance.now();r.stats.parsing.end=a,i&&(i.stats.parsing.end=a),this.updateleveltiming(r,i,n,t.partial)}else this.fragcurrent||(this.state=pt)},c.getcurrentcontext=function(t){var e=this.levels,r=t.level,i=t.sn,n=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 a=e[r],s=n>-1?function(t,e,r){if(!t||!t.details)return null;var i=t.details.partlist;if(i)for(var n=i.length;n--;){var a=i[n];if(a.index===r&&a.fragment.sn===e)return a}return null}(a,i,n):null,o=s?s.fragment:function(t,e,r){if(!t||!t.details)return null;var i=t.details,n=i.fragments[e-i.startsn];return n||((n=i.fragmenthint)&&n.sn===e?n:ea&&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(n.a)(i))return null;var a=lt.bufferinfo(t,i,r.maxbufferhole);if(0===a.len&&void 0!==a.nextstart){var s=this.fragmenttracker.getbufferedfrag(i,e);if(s&&a.nextstart=r&&(e.maxmaxbufferlength/=2,this.warn("reduce max buffer length to "+e.maxmaxbufferlength+"s"),!0)},c.getnextfragment=function(t,e){var r,i,n=e.fragments,a=n.length;if(!a)return null;var s,o=this.config,l=n[0].start;if(e.live){var u=o.initiallivemanifestsize;if(a-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=pt(e,r.endprogramdatetime,this.config.maxfraglookuptolerance)),!i){var n=r.sn+1;if(n>=t.startsn&&n<=t.endsn){var a=e[n-t.startsn];r.cc===a.cc&&(i=a,this.log("live playlist, switching playlist, load frag with next sn: "+i.sn))}i||(i=function(t,e){return vt.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,n=this.config,a=this.fragprevious,s=r.fragments,o=r.endsn,l=r.fragmenthint,u=n.maxfraglookuptolerance,h=!!(n.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=a&&i.level===a.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=a?s[g--]:s[--g];i||(i=f)}else a&&i.sn===a.sn&&!h&&c&&(i.sn=a-e.maxfraglookuptolerance&&n<=s;if(null!==i&&r.duration>i&&(n"+t.startsn+" prev-sn: "+(a?a.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))}}])&&wt(u.prototype,h),d&&wt(u,d),i}(st);function qt(){return self.mediasource||self.webkitmediasource}function xt(){return self.sourcebuffer||self.webkitsourcebuffer}var zt=r(18),qt=r(10),$t=r(14),jt=qt()||{istypesupported:function(){return!1}},zt=function(){function t(t,e,r,i){var n=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=n.frag,r.id=n.id,t.trigger(e,r)};this.observer=new $t.eventemitter,this.observer.on(a.a.frag_decrypted,u),this.observer.on(a.a.error,u);var h={mp4:jt.istypesupported("video/mp4"),mpeg:jt.istypesupported("audio/mpeg"),mp3:jt.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=zt(19),this.onwmsg=this.onworkermessage.bind(this),c.addeventlistener("message",this.onwmsg),c.onerror=function(e){t.trigger(a.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 qt.c(this.observer,h,l,d,e),this.worker=null}}else this.transmuxer=new qt.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,n,a,s,l,u,h){var d=this;u.transmuxing.start=self.performance.now();var c=this.transmuxer,f=this.worker,g=a?a.start:n.start,v=n.decryptdata,p=this.frag,m=!(p&&n.cc===p.cc),y=!(p&&u.level===p.level),t=p?u.sn-p.sn:-1,b=this.part?u.part-this.part.index:1,e=!y&&(1===t||0===t&&1===b),s=self.performance.now();(y||t||0===n.stats.parsing.start)&&(n.stats.parsing.start=s),!a||!b&&e||(a.stats.parsing.start=s);var l=new qt.b(m,e,l,y,g);if(!e||m){o.b.log("[transmuxer-interface, "+n.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: "+e+"\n accuratetimeoffset: "+l+"\n timeoffset: "+g);var a=new qt.a(r,i,e,s,h);this.configuretransmuxer(a)}if(this.frag=n,this.part=a,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(qt.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 n=r.flush(t);object(qt.d)(n)?n.then((function(r){e.handleflushresult(r,t)})):this.handleflushresult(n,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}(),te=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,n=r.currenttime,a=r.seeking,s=this.seeking&&!a,l=!this.seeking&&a;if(this.seeking=a,n===t){if((l||s)&&(this.stalled=null),!r.paused&&!r.ended&&0!==r.playbackrate&<.getbuffered(r).length){var u=lt.bufferinfo(r,n,0),h=u.len>0,d=u.nextstart||0;if(h||d){if(a){var c=u.len>2,f=!d||d-n>2&&!this.fragmenttracker.getpartialfragment(n);if(c||f)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var g,v=math.max(d,u.start||0)-n,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;!a&&t>=250&&this._reportstall(u.len);var b=lt.bufferinfo(r,n,e.maxbufferhole);this._tryfixbufferstall(b,t)}else this.stalled=y}}}else if(this.moved=!0,null!==i){if(this.stallreported){var e=self.performance.now()-i;o.b.warn("playback not stuck anymore @"+n+", after "+math.round(e)+"ms"),this.stallreported=!1}this.stalled=null,this.nudgeretry=0}},e._tryfixbufferstall=function(t,e){var r=this.config,i=this.fragmenttracker,n=this.media.currenttime,a=i.getpartialfragment(n);if(a&&this._tryskipbufferhole(a))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(a.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,n=i.currenttime,l=0,u=lt.getbuffered(i),h=0;h=l&&n0&&-1===t&&(this.log("override startposition with lastcurrenttime @"+e.tofixed(3)),t=e),this.state=pt,this.nextloadposition=this.startposition=this.lastcurrenttime=t,this.tick()}else this._forcestartload=!0,this.state=xt},c.stopload=function(){this._forcestartload=!1,t.prototype.stopload.call(this)},c.dotick=function(){switch(this.state){case pt:this.dotickidle();break;case wt: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=pt;break}break;case nt:var n,a=self.performance.now(),s=this.retrydate;(!s||a>=s||null!==(n=this.media)&&void 0!==n&&n.seeking)&&(this.log("retrydate reached, switch back to idle state"),this.state=pt)}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,n=this.levels,s=this.media,o=r.config,l=r.nextloadlevel;if(null!==i&&(s||!this.startfragrequested&&o.startfragprefetch)&&(!this.altaudio||!this.audioonly)&&n&&n[l]){var h=n[l];this.level=r.nextloadlevel=l;var d=h.details;if(!d||this.state===wt||d.live&&this.levellastloaded!==l)this.state=wt;else{var c=this.getfwdbufferinfo(this.mediabuffer?this.mediabuffer:s,k.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(a.a.buffer_eos,f),void(this.state=jt)}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,k.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 n,a=this.fragmenttracker.getstate(e);if(this.fragcurrent=e,a===tt.backtracked){var s=this.fragmenttracker.getbacktrackdata(e);if(s)return this._handlefragmentloadprogress(s),void this._handlefragmentloadcomplete(s);a=tt.not_loaded}a===tt.not_loaded||a===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)):a===tt.appending?this.reducemaxbufferlength(e.duration)&&this.fragmenttracker.removefragment(e):0===(null===(n=this.media)||void 0===n?void 0:n.buffered.length)&&this.fragmenttracker.removeallfragments()},c.getappendedfrag=function(t){var e=this.fragmenttracker.getappendedfrag(t,k.b.main);return e&&"fragment"in e?e.fragment:e},c.getbufferedfrag=function(t){return this.fragmenttracker.getbufferedfrag(t,k.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 n=t[this.hls.nextloadlevel],a=this.fraglastkbps;r=a&&this.fragcurrent?this.fragcurrent.duration*n.maxbitrate/(1e3*a)+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===mt&&(this.state=pt),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 te(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(n.a)(e)&&this.log("media seeked to "+e.tofixed(3)),this.tick()},c.onmanifestloading=function(){this.log("trigger buffer_reset"),this.hls.trigger(a.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,n,a=!1,s=!1;e.levels.foreach((function(t){(r=t.audiocodec)&&(-1!==r.indexof("mp4a.40.2")&&(a=!0),-1!==r.indexof("mp4a.40.5")&&(s=!0))})),this.audiocodecswitch=a&&s&&!("function"==typeof(null==(n=xt())||null===(i=n.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===pt){var i=r[e.level];(!i.details||i.details.live&&this.levellastloaded!==e.level||this.waitforcdntunein(i.details))&&(this.state=wt)}},c.onlevelloaded=function(t,e){var r,i=this.levels,n=e.level,s=e.details,o=s.totalduration;if(i){this.log("level "+n+" loaded ["+s.startsn+","+s.endsn+"], cc ["+s.startcc+", "+s.endcc+"] duration:"+o);var l=this.fragcurrent;!l||this.state!==ft&&this.state!==nt||l.level!==e.level&&l.loader&&(this.state=pt,l.loader.abort());var u=i[n],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=n,this.hls.trigger(a.a.level_updated,{details:s,level:n}),this.state===wt){if(this.waitforcdntunein(s))return;this.state=pt}this.startfragrequested?s.live&&this.synchronizetoliveedge(s):this.setstartposition(s,h),this.tick()}else this.warn("levels were reset while loading level "+n)},c._handlefragmentloadprogress=function(t){var e,r=t.frag,i=t.part,n=t.payload,a=this.levels;if(a){var s=a[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 zt(this.hls,k.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,n.bytelength,f,g),p=this.initpts[r.cc];c.push(n,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,n=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(a.a.buffer_flushing,{startoffset:0,endoffset:number.positive_infinity,type:"audio"}),o.trigger(a.a.audio_track_switched,{id:n})}},c.onaudiotrackswitched=function(t,e){var r=e.id,i=!!this.hls.audiotracks[r].url;if(i){var n=this.videobuffer;n&&this.mediabuffer!==n&&(this.log("switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediabuffer=n)}this.altaudio=i,this.tick()},c.onbuffercreated=function(t,e){var r,i,n=e.tracks,a=!1;for(var s in n){var o=n[s];if("main"===o.id){if(i=s,r=o,"video"===s){var l=n[s];l&&(this.videobuffer=l.buffer)}}else a=!0}a&&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===k.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===gt&&(this.state=pt));var n=i?i.stats:r.stats;this.fraglastkbps=math.round(8*n.total/(n.buffering.end-n.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(k.b.main,e);break;case s.a.level_load_error:case s.a.level_load_timeout:this.state!==ht&&(e.fatal?(this.warn(""+e.details),this.state=ht):e.levelretry||this.state!==wt||(this.state=pt));break;case s.a.buffer_full_error:if("main"===e.parent&&(this.state===bt||this.state===gt)){var r=!0,i=this.getfwdbufferinfo(this.media,k.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=pt,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,k.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&&(n1&&!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,n=e.level;i&&e.sn===i.sn&&i.level===n&&e.urlid===i.urlid||(this.hls.trigger(a.a.frag_changed,{frag:e}),i&&i.level===n||this.hls.trigger(a.a.level_switched,{level:n}),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}}])&&ee(l.prototype,h),d&&ee(l,d),i}(yt),ne=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 ne(t),this.fast_=new ne(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 ne(t,r.getestimate(),r.gettotalweight())),this.fast_.halflife!==e&&(this.fast_=new ne(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 se(t,e){for(var r=0;r=2*h/c||y<=b)){var e,s=number.positive_infinity;for(e=t.level-1;e>g;e--){if((s=h*f[e].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 "+e+"\n current bw estimate: "+(object(n.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: "+b.tofixed(3)+" s"),r.nextloadlevel=e,this.bwestimator.sample(d,u.loaded),this.cleartimer(),t.loader&&(this.fragcurrent=this.partcurrent=null,t.loader.abort()),r.trigger(a.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===k.b.main&&object(n.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(a.a.frag_buffered,d),r.bitratetest=!1}}},l.onfragbuffered=function(t,e){var r=e.frag,i=e.part,n=i?i.stats:r.stats;if(!n.aborted&&r.type===k.b.main&&"initsegment"!==r.sn){var a=n.parsing.end-n.loading.start;this.bwestimator.sample(a,n.loaded),n.bwestimate=this.bwestimator.getestimate(),r.bitratetest?this.bitratetestdelay=a/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,n=r.config,a=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():n.abrewmadefaultestimate,c=(lt.bufferinfo(s,u,n.maxbufferhole).end-u)/h,f=this.findbestlevel(d,a,i,c,n.abrbandwidthfactor,n.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,n.maxstarvationdelay):n.maxstarvationdelay,v=n.abrbandwidthfactor,p=n.abrbandwidthupfactor;if(!c){var m=this.bitratetestdelay;if(m)g=(l?math.min(l,n.maxloadingdelay):n.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,a,i,c+g,v,p),math.max(f,0)},l.findbestlevel=function(t,e,r,i,n,a){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,b=void 0;b=p<=h?n*t:a*t;var e=d[p].maxbitrate,s=e*t/b;if(o.b.trace("level/adjustedbw/bitrate/avgduration/maxfetchduration/fetchduration: "+p+"/"+math.round(b)+"/"+e+"/"+t+"/"+i+"/"+s),b>e&&(!s||f&&!this.bitratetestdelay||s0&&-1===t?(this.log("override startposition with lastcurrenttime @"+e.tofixed(3)),this.state=pt):(this.loadedmetadata=!1,this.state=ut),this.nextloadposition=this.startposition=this.lastcurrenttime=t,this.tick()},l.dotick=function(){switch(this.state){case pt:this.dotickidle();break;case ut:var e,r=this.levels,i=this.trackid,n=null==r||null===(e=r[i])||void 0===e?void 0:e.details;if(n){if(this.waitforcdntunein(n))break;this.state=vt}break;case nt:var a,s=performance.now(),l=this.retrydate;(!l||s>=l||null!==(a=this.media)&&void 0!==a&&a.seeking)&&(this.log("retrydate reached, switch back to idle state"),this.state=pt);break;case vt: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);yt(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=pt}this.ontickend()},l.clearwaitingfragment=function(){var t=this.waitingdata;t&&(this.fragmenttracker.removefragment(t.frag),this.waitingdata=null,this.waitingvideocc=-1,this.state=pt)},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,n=this.media,s=this.trackid,o=r.config;if(i&&i[s]&&(n||!this.startfragrequested&&o.startfragprefetch)){var l=i[s].details;if(!l||l.live&&this.levellastloaded!==s||this.waitforcdntunein(l))this.state=ut;else{this.bufferflushed&&(this.bufferflushed=!1,this.afterbufferflushed(this.mediabuffer?this.mediabuffer:this.media,u.a.audio,k.b.audio));var h=this.getfwdbufferinfo(this.mediabuffer?this.mediabuffer:this.media,k.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(a.a.buffer_eos,{type:"audio"}),void(this.state=jt);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"),n.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,k.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=pt):this.state=xt,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,n=e.details,a=e.id;if(i){this.log("track "+a+" loaded ["+n.startsn+","+n.endsn+"],duration:"+n.totalduration);var s=i[a],o=0;if(n.live||null!==(r=s.details)&&void 0!==r&&r.live){var l=this.maindetails;if(n.fragments[0]||(n.deltaupdatefailed=!0),n.deltaupdatefailed||!l)return;!s.details&&n.hasprogramdatetime&&l.hasprogramdatetime?(gt(n,l),o=n.fragments[0].start):o=this.alignplaylists(n,s.details)}s.details=n,this.levellastloaded=a,this.startfragrequested||!this.maindetails&&n.live||this.setstartposition(s.details,o),this.state!==ut||this.waitforcdntunein(n)||(this.state=pt),this.tick()}else this.warn("audio tracks were reset while loading level "+a)},l._handlefragmentloadprogress=function(t){var e,r=t.frag,i=t.part,n=t.payload,a=this.config,s=this.trackid,l=this.levels;if(l){var u=l[s],h=u.details,d=a.defaultaudiocodec||u.audiocodec||"mp4a.40.2",c=this.transmuxer;c||(c=this.transmuxer=new zt(this.hls,k.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,n.bytelength,v,p);c.push(n,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 le.a,complete:!1}).cache.push(new uint8array(n)),this.waitingvideocc=this.videotrackcc,this.state=vt}}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===k.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(a.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(k.b.audio,r);break;case s.a.audio_track_load_error:case s.a.audio_track_load_timeout:this.state!==ht&&this.state!==xt&&(this.state=r.fatal?ht:pt,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===bt||this.state===gt)){var i=!0,n=this.getfwdbufferinfo(this.mediabuffer,k.b.audio);n&&n.len>.5&&(i=!this.reducemaxbufferlength(n.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,n=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=n.audio,c=n.text,f=n.id3,g=n.initsegment;if(!this.fragcontextchanged(l)){if(this.state=bt,this.audioswitch&&d&&this.completeaudioswitch(),null!=g&&g.tracks&&(this._bufferinitsegment(g.tracks,l,s),i.trigger(a.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=ue({frag:l,id:r},f);i.trigger(a.a.frag_parsing_metadata,t)}if(c){var b=ue({frag:l,id:r},c);i.trigger(a.a.frag_parsing_userdata,b)}}},l._bufferinitsegment=function(t,e,r){if(this.state===bt){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(a.a.buffer_codecs,t);var n=i.initsegment;if(null!=n&&n.bytelength){var s={type:"audio",frag:e,part:null,chunkmeta:r,parent:e.type,data:n};this.hls.trigger(a.a.buffer_appending,s)}this.tick()}}},l.loadfragment=function(e,r,i){var a=this.fragmenttracker.getstate(e);this.fragcurrent=e,(this.audioswitch||a===tt.not_loaded||a===tt.partial)&&("initsegment"===e.sn?this._loadinitsegment(e):r.live&&!object(n.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=vt):(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(a.a.audio_track_switched,{id:i})},i}(yt);function ce(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],n=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(a.a.audio_track_switching,{id:n,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(a.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=n[o].start&&s<=n[o].end){a=n[o];break}var l=r.start+r.duration;a?a.end=l:(a={start:s,end:l},n.push(a)),this.fragmenttracker.fragbuffered(r)}}},u.onbufferflushing=function(t,e){var r=e.startoffset,i=e.endoffset;if(0===r&&i!==number.positive_infinity){var n=this.currenttrackid,a=this.levels;if(!a.length||!a[n]||!a[n].details)return;var s=i-a[n].details.targetduration;if(s<=0)return;e.endoffsetsubtitles=math.max(0,s),this.tracksbuffered.foreach((function(t){for(var e=0;e=s.length||n!==a)&&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?gt(i,l):u&&z(i,u.start)}if(o.details=i,this.levellastloaded=n,this.tick(),i.live&&!this.fragcurrent&&this.media&&this.state===pt)mt(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,n=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();n.trigger(a.a.frag_decrypted,{frag:e,payload:t,stats:{tstart:s,tdecrypt:r}})}))}},u.dotick=function(){if(this.media){if(this.state===pt){var t,e=this.currenttrackid,r=this.levels;if(!r.length||!r[e]||!r[e].details)return;var i=r[e].details,n=i.targetduration,s=this.config,l=this.media,u=lt.bufferedinfo(this.mediabuffertimeranges,l.currenttime-n,s.maxbufferhole),h=u.end;if(u.len>this.getmaxbufferlength()+n)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),be(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,n=this.trackid,a=this.tracksingroup[n];if(a){var s=a.details;a.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,n=this.tracks.filter((function(t){return!r||t.groupid===r}));this.tracksingroup=n;var s=this.findtrackid(null==i?void 0:i.name)||this.findtrackid();this.groupid=r;var o={subtitletracks:n};this.log("updating subtitle tracks, "+n.length+' track(s) found in "'+r+'" group-id'),this.hls.trigger(a.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 n=i[t];if(this.log("switching to subtitle track "+t),this.trackid=t,n){var s=n.id,o=n.groupid,l=void 0===o?"":o,u=n.name,h=n.type,d=n.url;this.hls.trigger(a.a.subtitle_track_switch,{id:s,groupid:l,name:u,type:h,url:d});var c=this.switchparams(n.url,null==e?void 0:e.details);this.loadplaylist(c)}else this.hls.trigger(a.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=be(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(a.a.media_attaching,this.onmediaattaching,this),t.on(a.a.media_detaching,this.onmediadetaching,this),t.on(a.a.manifest_parsed,this.onmanifestparsed,this),t.on(a.a.buffer_reset,this.onbufferreset,this),t.on(a.a.buffer_appending,this.onbufferappending,this),t.on(a.a.buffer_codecs,this.onbuffercodecs,this),t.on(a.a.buffer_eos,this.onbuffereos,this),t.on(a.a.buffer_flushing,this.onbufferflushing,this),t.on(a.a.level_updated,this.onlevelupdated,this),t.on(a.a.frag_parsed,this.onfragparsed,this),t.on(a.a.frag_changed,this.onfragchanged,this)},e.unregisterlisteners=function(){var t=this.hls;t.off(a.a.media_attaching,this.onmediaattaching,this),t.off(a.a.media_detaching,this.onmediadetaching,this),t.off(a.a.manifest_parsed,this.onmanifestparsed,this),t.off(a.a.buffer_reset,this.onbufferreset,this),t.off(a.a.buffer_appending,this.onbufferappending,this),t.off(a.a.buffer_codecs,this.onbuffercodecs,this),t.off(a.a.buffer_eos,this.onbuffereos,this),t.off(a.a.buffer_flushing,this.onbufferflushing,this),t.off(a.a.level_updated,this.onlevelupdated,this),t.off(a.a.frag_parsed,this.onfragparsed,this),t.off(a.a.frag_changed,this.onfragchanged,this)},e._initsourcebuffer=function(){this.sourcebuffer={},this.operationqueue=new le(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&&ae){var i=this.mediasource=new ae;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(a.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 n=r.tracks[t];if(n&&"function"==typeof n.buffer.changetype){var a=e[t],s=a.codec,o=a.levelcodec,l=a.container;if((n.levelcodec||n.codec).replace(re,"$1")!==(o||s).replace(re,"$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,n={execute:function(){var n=r.sourcebuffer[t];n&&(o.b.log("[buffer-controller]: changing "+t+" sourcebuffer type to "+e),n.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(n,t)},e.onbufferappending=function(t,e){var r=this,i=this.hls,n=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),b={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 n in e)i[n]=lt.getbuffered(e[n]);r.appenderror=0,r.hls.trigger(a.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(a.a.error,e)}};n.append(b,h)},e.onbufferflushing=function(t,e){var r=this,i=this.operationqueue,n=function(t){return{execute:r.removeexecutor.bind(r,t,e.startoffset,e.endoffset),onstart:function(){},oncomplete:function(){r.hls.trigger(a.a.buffer_flushed,{type:t})},onerror:function(e){o.b.warn("[buffer-controller]: failed to remove from "+t+" sourcebuffer",e)}}};e.type?i.append(n(e.type),e.type):this.getsourcebuffertypes().foreach((function(t){i.append(n(t),t)}))},e.onfragparsed=function(t,e){var r=this,i=e.frag,n=e.part,s=[],l=n?n.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,n&&(n.stats.buffering.end=t);var e=n?n.stats:i.stats;r.hls.trigger(a.a.frag_buffered,{frag:i,part:n,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 n=r.sourcebuffer[i];return e.type&&e.type!==i||n&&!n.ended&&(n.ended=!0,o.b.log("[buffer-controller]: "+i+" sourcebuffer now eos")),t&&!(n&&!n.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(n.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 n=i[r];if(n){var s=lt.getbuffered(n);s.length>0&&d>s.start(0)&&(t.trigger(a.a.back_buffer_reached,{bufferend:d}),e.live&&t.trigger(a.a.live_back_buffer_reached,{bufferend:d}),t.trigger(a.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,a=t.fragments[0].start+t.totalduration,s=r.duration,l=object(n.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)):(a>l&&a>s||!object(n.a)(s))&&(o.b.log("[buffer-controller]: updating media source duration to "+a.tofixed(3)),i.duration=a)}},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),n=math.max(i,i+t.totalduration);e.setliveseekablerange(i,n)}},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 n=this.getsourcebuffertypes();if(0===n.length)return void this.hls.trigger(a.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)"});n.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 n in t)if(!e[n]){var l=t[n];if(!l)throw error("source buffer exists for track "+n+", 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[n]=r.addsourcebuffer(h),c=n;this.addbufferlistener(c,"updatestart",this._onsbupdatestart),this.addbufferlistener(c,"updateend",this._onsbupdateend),this.addbufferlistener(c,"error",this._onsbupdateerror),this.tracks[n]={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(a.a.error,{type:s.b.media_error,details:s.a.buffer_add_codec_error,fatal:!1,error:t,mimetype:h})}}i&&this.hls.trigger(a.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(a.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,a=this.mediasource,s=this.operationqueue,l=this.sourcebuffer[t];if(!i||!a||!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(n.a)(i.duration)?i.duration:1/0,h=object(n.a)(a.duration)?a.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,n=e.map((function(t){return i.appendblocker(t)}));promise.all(n).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 n=r.bind(this,t);this.listeners[t].push({event:e,listener:n}),i.addeventlistener(e,n)}},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},_e=function(t){var e=t;return ke.hasownproperty(t)&&(e=ke[t]),string.fromcharcode(e)},ie={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},ce={17:2,18:4,21:6,22:8,23:10,19:13,20:15},we={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},oe={25:2,26:4,29:6,30:8,31:10,27:13,28:15},xe=["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 pe=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}(),me=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=_e(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}(),be=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 ue(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}(),ge=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 be(r),this.nondisplayedmemory=new be(r),this.lastoutputscreen=new be(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 ke(t,e,r){r.a=t,r.b=e}function je(t,e,r){return r.a===t&&r.b===e}var he=function(){function t(t,e,r){this.channels=void 0,this.currentchannel=0,this.cmdhistory=void 0,this.logger=void 0;var i=new pe;this.channels=[null,new ge(t,e,i),new ge(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,n,a=!1;this.logger.time=t;for(var s=0;s ("+me([i,n])+")"),(r=this.parsecmd(i,n))||(r=this.parsemidrow(i,n)),r||(r=this.parsepac(i,n)),r||(r=this.parsebackgroundattributes(i,n)),!r&&(a=this.parsechars(i,n))){var o=this.currentchannel;if(o&&o>0)this.channels[o].insertchars(a);else this.logger.log(ee.warning,"no channel found yet. text-mode?")}r||a||this.logger.log(ee.warning,"couldn't parse cleaned data "+me([i,n])+" orig: "+me([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(je(t,e,r))return ke(null,null,r),this.logger.log(ee.debug,"repeated command ("+me([t,e])+") is dropped"),!0;var i=20===t||21===t||23===t?1:2,n=this.channels[i];return 20===t||21===t||28===t||29===t?32===e?n.ccrcl():33===e?n.ccbs():34===e?n.ccaof():35===e?n.ccaon():36===e?n.ccder():37===e?n.ccru(2):38===e?n.ccru(3):39===e?n.ccru(4):40===e?n.ccfon():41===e?n.ccrdc():42===e?n.cctr():43===e?n.ccrtd():44===e?n.ccedm():45===e?n.cccr():46===e?n.ccenm():47===e&&n.cceoc():n.ccto(e-32),ke(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 ("+me([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(je(t,e,i))return ke(null,null,i),!0;var n=t<=23?1:2;r=e>=64&&e<=95?1===n?ie[t]:we[t]:1===n?ce[t]:oe[t];var a=this.channels[n];return!!a&&(a.setpac(this.interpretpac(r,e)),ke(t,e,i),this.currentchannel=n,!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,n=null,a=null;(t>=25?(r=2,a=t-8):(r=1,a=t),a>=17&&a<=19)?(i=17===a?e+80:18===a?e+112:e+144,this.logger.log(ee.info,"special char '"+_e(i)+"' in channel "+r),n=[i]):t>=32&&t<=127&&(n=0===e?[t]:[t,e]);if(n){var s=me(n);this.logger.log(ee.debug,"char codes = "+s.join(",")),ke(t,e,this.cmdhistory)}return n},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=xe[r],e%2==1&&(i.background=i.background+"_semi")):45===e?i.background="transparent":(i.foreground="black",47===e&&(i.underline=!0));var n=t<=23?1:2;return this.channels[n].setbkgdata(i),ke(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}(),we=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 n(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",n({},l,{get:function(){return b},set:function(t){var e=i(t);if(!e)throw new syntaxerror("an invalid or illegal string was specified.");b=e,this.hasbeenreset=!0}})),object.defineproperty(o,"size",n({},l,{get:function(){return e},set:function(t){if(t<0||t>100)throw new error("size must be between 0 and 100.");e=t,this.hasbeenreset=!0}})),object.defineproperty(o,"align",n({},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 a.prototype.getcueashtml=function(){return self.webvtt.convertcuetodomtree(self,this.text)},a}(),ye=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 qe(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 xe=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 ze(t,e,r,i){var n=i?t.split(i):[t];for(var a in n)if("string"==typeof n[a]){var s=n[a].split(r);if(2===s.length)e(s[0],s[1])}}var qe=new we(0,0,""),$e="middle"===qe.align?"middle":"center";function je(t,e,r){var i=t;function n(){var e=qe(t);if(null===e)throw new error("malformed timestamp: "+i);return t=t.replace(/^[^\sa-za-z-]+/,""),e}function a(){t=t.replace(/^\s+/,"")}if(a(),e.starttime=n(),a(),"--\x3e"!==t.substr(0,3))throw new error("malformed time stamp (time stamps must be separated by '--\x3e'): "+i);t=t.substr(3),a(),e.endtime=n(),a(),function(t,e){var i=new xe;ze(t,(function(t,e){var n;switch(t){case"region":for(var a=r.length-1;a>=0;a--)if(r[a].id===e){i.set(t,r[a].region);break}break;case"vertical":i.alt(t,e,["rl","lr"]);break;case"line":n=e.split(","),i.integer(t,n[0]),i.percent(t,n[0])&&i.set("snaptolines",!1),i.alt(t,n[0],["auto"]),2===n.length&&i.alt("linealign",n[1],["start",$e,"end"]);break;case"position":n=e.split(","),i.percent(t,n[0]),2===n.length&&i.alt("positionalign",n[1],["start",$e,"end","line-left","line-right","auto"]);break;case"size":i.percent(t,e);break;case"align":i.alt(t,e,["start",$e,"end","left","right"])}}),/:/,/\s/),e.region=i.get("region",null),e.vertical=i.get("vertical","");var n=i.get("line","auto");"auto"===n&&-1===qe.line&&(n=-1),e.line=n,e.linealign=i.get("linealign","start"),e.snaptolines=i.get("snaptolines",!0),e.size=i.get("size",100),e.align=i.get("align",$e);var a=i.get("position","auto");"auto"===a&&50===qe.position&&(a="start"===e.align||"left"===e.align?0:"end"===e.align||"right"===e.align?100:50),e.position=a}(t,e)}function ze(t){return t.replace(//gi,"\n")}var tr=function(){function t(){this.state="initial",this.buffer="",this.decoder=new ye,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=ze(t);r>>0).tostring()};function sr(t,e,r){return ar(t.tostring())+ar(e.tostring())+ar(r)}function or(t,e,r,i,a,s,o,l){var u,h=new tr,d=object(m.f)(new uint8array(t)).trim().replace(ir,"\n").split("\n"),c=[],f=object(er.a)(e,r),g="00:00.000",v=0,p=0,m=!0,y=!1;h.oncue=function(t){var e=i[a],r=i.ccoffset,n=(v-f)/9e4;if(null!=e&&e.new&&(void 0!==p?r=i.ccoffset=e.start:function(t,e,r){var i=t[e],n=t[i.prevcc];if(!n||!n.new&&i.new)return t.ccoffset=t.presentationoffset=i.start,void(i.new=!1);for(;null!==(a=n)&&void 0!==a&&a.new;){var a;t.ccoffset+=i.start-n.start,i.new=!1,n=t[(i=n).prevcc]}t.presentationoffset=r}(i,a,n)),n&&(r=n-i.presentationoffset),y){var o=t.endtime-t.starttime,l=object(rr.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=sr(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(nr(t,"x-timestamp-map=")){m=!1,y=!0,t.substr(16).split(",").foreach((function(t){nr(t,"local:")?g=t.substr(6):nr(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)),a=t.length>9?parseint(t.substr(0,t.indexof(":"))):0;if(!(object(n.a)(e)&&object(n.a)(r)&&object(n.a)(i)&&object(n.a)(a)))throw error("malformed x-timestamp-map: local:"+t);return e+=1e3*r,e+=6e4*i,e+=36e5*a}(g)/1e3}catch(t){y=!1,u=t}return}""===t&&(m=!1)}h.parse(t+"\n")})),h.flush()}function lr(){return(lr=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||n.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(a.a.cues_parsed,{type:"captions",cues:v,track:t})}},e.oninitptsfound=function(t,e){var r=this,i=e.frag,n=e.id,s=e.initpts,o=e.timescale,l=this.unparsedvttfrags;"main"===n&&(this.initpts[i.cc]=s,this.timescale[i.cc]=o),l.length&&(this.unparsedvttfrags=[],l.foreach((function(t){r.onfragloaded(a.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}}},n.getmaxlevel=function(e){var r=this,i=this.hls.levels;if(!i.length)return-1;var n=i.filter((function(i,n){return t.islevelallowed(n,r.restrictedlevels)&&n<=e}));return this.clientrect=null,t.getmaxlevelbymediasize(n,this.mediawidth,this.mediaheight)},n.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())},n.stopcapping=function(){this.restrictedlevels=[],this.firstlevel=-1,this.autolevelcapping=number.positive_infinity,this.timer&&(self.clearinterval(this.timer),this.timer=void 0)},n.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,n,a=t.length-1,s=0;s=e||o.height>=r)&&(i=o,!(n=t[s+1])||i.width!==n.width||i.height!==n.height)){a=s;break}}return a},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}}])&&br(e.prototype,r),i&&br(e,i),t}(),lr=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(a.a.media_attaching,this.onmediaattaching,this)},e.unregisterlisteners=function(){this.hls.off(a.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 n=i-this.lasttime,s=r-this.lastdroppedframes,l=e-this.lastdecodedframes,u=1e3*s/n,h=this.hls;if(h.trigger(a.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(a.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 ar="undefined"!=typeof self&&self.navigator&&self.navigator.requestmediakeysystemaccess?self.navigator.requestmediakeysystemaccess.bind(self.navigator):null;function rr(t,e){for(var r=0;r3)return void this.hls.trigger(a.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)}}},n._generatelicenserequestchallenge=function(t,e){switch(t.mediakeysystemdomain){case er.widevine:return e}throw new error("unsupported key-system: "+t.mediakeysystemdomain)},n._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(a.a.error,{type:s.b.key_system_error,details:s.a.key_system_no_access,fatal:!0});try{var i=this.getlicenseserverurl(r.mediakeysystemdomain),n=this._createlicensexhr(i,t,e);o.b.log("sending license request to url: "+i);var l=this._generatelicenserequestchallenge(r,t);n.send(l)}catch(t){o.b.error("failure requesting drm license: "+t),this.hls.trigger(a.a.error,{type:s.b.key_system_error,details:s.a.key_system_license_request_failed,fatal:!0})}},n.onmediaattached=function(t,e){if(this._emeenabled){var r=e.media;this._media=r,r.addeventlistener("encrypted",this._onmediaencrypted)}},n.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(){})))},n.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}}])&&rr(e.prototype,r),i&&rr(e,i),t}();function cr(t,e){for(var r=0;r=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new typeerror("invalid attempt to iterate non-iterable instance.\nin order to be iterable, non-array objects must have a [symbol.iterator]() method.")}function xr(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new array(e);rr&&(r=n.bitrate)}return r>0?r:nan},e.getbufferlength=function(t){var e=this.hls.media,r=t===dr.audio?this.audiobuffer:this.videobuffer;return r&&e?1e3*lt.bufferinfo(r,e.currenttime,this.config.maxbufferhole).len:nan},e.createplaylistloader=function(){var t=this.config.ploader,e=this.applyplaylistdata,r=t||this.config.loader;return function(){function t(t){this.loader=void 0,this.loader=new r(t)}var i=t.prototype;return i.destroy=function(){this.loader.destroy()},i.abort=function(){this.loader.abort()},i.load=function(t,r,i){e(t),this.loader.load(t,r,i)},wr(t,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),t}()},e.createfragmentloader=function(){var t=this.config.floader,e=this.applyfragmentdata,r=t||this.config.loader;return function(){function t(t){this.loader=void 0,this.loader=new r(t)}var i=t.prototype;return i.destroy=function(){this.loader.destroy()},i.abort=function(){this.loader.abort()},i.load=function(t,r,i){e(t),this.loader.load(t,r,i)},wr(t,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),t}()},t.uuid=function(){var t=url.createobjecturl(new blob),e=t.tostring();return url.revokeobjecturl(t),e.substr(e.lastindexof("/")+1)},t.serialize=function(t){for(var e,r=[],i=function(t){return!number.isnan(t)&&null!=t&&""!==t&&!1!==t},n=function(t){return math.round(t)},a=function(t){return 100*n(t/100)},s={br:n,d:n,bl:a,dl:a,mtp:a,nor:function(t){return encodeuricomponent(t)},rtp:a,tb:n},o=or(object.keys(t||{}).sort());!(e=o()).done;){var l=e.value,u=t[l];if(i(u)&&!("v"===l&&1===u||"pr"==l&&1===u)){var h=s[l];h&&(u=h(u));var d=typeof u,c=void 0;c="ot"===l||"sf"===l||"st"===l?l+"="+u:"boolean"===d?l:"number"===d?l+"="+u:l+"="+json.stringify(u),r.push(c)}}return r.join(",")},t.toheaders=function(e){for(var r={},i=["object","request","session","status"],n=[{},{},{},{}],a={br:0,d:0,ot:0,tb:0,bl:1,dl:1,mtp:1,nor:1,nrr:1,su:1,cid:2,pr:2,sf:2,sid:2,st:2,v:2,bs:3,rtp:3},s=0,o=object.keys(e);s=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 a=e.status;if(a>=200&&a<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>=n.maxretry||a>=400&&a<499?(o.b.error(a+" while loading "+t.url),this.callbacks.onerror({code:a,text:e.statustext},t,e)):(o.b.warn(a+" 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,n.maxretrydelay),r.retry++)}else self.cleartimeout(this.requesttimeout),this.requesttimeout=self.settimeout(this.loadtimeout.bind(this),n.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&&nr.test(this.loader.getallresponseheaders())){var e=this.loader.getresponseheader("age");t=e?parsefloat(e):null}return t},t}();function br(t){var e="function"==typeof map?new map:void 0;return(br=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 gr(t,arguments,hr(this).constructor)}return i.prototype=object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),jr(i,t)})(t)}function gr(t,e,r){return(gr=kr()?reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var n=new(function.bind.apply(t,i));return r&&jr(n,r.prototype),n}).apply(null,arguments)}function kr(){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 jr(t,e){return(jr=object.setprototypeof||function(t,e){return t.__proto__=e,t})(t,e)}function hr(t){return(hr=object.setprototypeof?object.getprototypeof:function(t){return t.__proto__||object.getprototypeof(t)})(t)}function vr(){return(vr=object.assign||function(t){for(var e=1;e=i&&n(e,r,a.flush(),t)):n(e,r,l,t),o()})).catch((function(){return promise.reject()}))}()},t}();function yr(t,e){return new self.request(t.url,e)}var qr=function(t){var e,r;function i(e,r,i){var n;return(n=t.call(this,e)||this).code=void 0,n.details=void 0,n.code=r,n.details=i,n}return r=t,(e=i).prototype=object.create(r.prototype),e.prototype.constructor=e,jr(e,r),i}(br(error)),xr=wr,zr=/\s/;function qr(){return(qr=object.assign||function(t){for(var e=1;e=16?o--:o++;var f=ze(l.trim()),g=sr(e,r,f);t&&t.cues&&t.cues.getcuebyid(g)||((a=new h(e,r,f)).id=g,a.line=d+1,a.align="left",a.position=10+math.min(80,10*math.floor(8*o/32)),u.push(a))}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:me,subtitletrackcontroller:se,timelinecontroller:yr,audiostreamcontroller:de,audiotrackcontroller:ge,emecontroller:ir,cmcdcontroller:mr});function ei(t){var e=t.loader;e!==xr&&e!==ur?(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=xr,t.progressive=!0,t.enablesoftwareaes=!0,o.b.log("[config]: progressive streaming enabled, using fetchloader"))}function ri(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}}])&&ri(e.prototype,r),n&&ri(e,n),t}();ii.defaultconfig=void 0}]).default})); //# sourcemappingurl=hls.min.js.map