(globalThis.webpackChunksakurairo_scripts=globalThis.webpackChunksakurairo_scripts||[]).push([[4189],{4189:e=>{!function t(r){e.exports=function(){function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function i(t){for(var r=1;r"):k}function w(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;iNumber.MAX_SAFE_INTEGER?1/0:t},t.hexadecimalInteger=function(e){if(this[e]){var t=(this[e]||"0x").slice(2);t=(1&t.length?"0":"")+t;for(var r=new Uint8Array(t.length/2),i=0;iNumber.MAX_SAFE_INTEGER?1/0:t},t.decimalFloatingPoint=function(e){return parseFloat(this[e])},t.optionalFloat=function(e,t){var r=this[e];return r?parseFloat(r):t},t.enumeratedString=function(e){return this[e]},t.bool=function(e){return"YES"===this[e]},t.decimalResolution=function(e){var t=O.exec(this[e]);if(null!==t)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}},e.parseAttrList=function(e){var t,r={},i='"';for(F.lastIndex=0;null!==(t=F.exec(e));){var a=t[2];0===a.indexOf(i)&&a.lastIndexOf(i)===a.length-1&&(a=a.slice(1,-1)),r[t[1].trim()]=a}return r},o(e,[{key:"clientAttrs",get:function(){return Object.keys(this).filter((function(e){return"X-"===e.substring(0,2)}))}}]),e}();function N(e){return"ID"!==e&&"CLASS"!==e&&"START-DATE"!==e&&"DURATION"!==e&&"END-DATE"!==e&&"END-ON-NEXT"!==e}function B(e){return"SCTE35-OUT"===e||"SCTE35-IN"===e}var U=function(){function e(e,t){if(this.attr=void 0,this._startDate=void 0,this._endDate=void 0,this._badValueForSameId=void 0,t){var r=t.attr;for(var i in r)if(Object.prototype.hasOwnProperty.call(e,i)&&e[i]!==r[i]){P.warn('DATERANGE tag attribute: "'+i+'" does not match for tags with ID: "'+e.ID+'"'),this._badValueForSameId=i;break}e=u(new M({}),r,e)}if(this.attr=e,this._startDate=new Date(e["START-DATE"]),"END-DATE"in this.attr){var a=new Date(this.attr["END-DATE"]);S(a.getTime())&&(this._endDate=a)}}return o(e,[{key:"id",get:function(){return this.attr.ID}},{key:"class",get:function(){return this.attr.CLASS}},{key:"startDate",get:function(){return this._startDate}},{key:"endDate",get:function(){if(this._endDate)return this._endDate;var e=this.duration;return null!==e?new Date(this._startDate.getTime()+1e3*e):null}},{key:"duration",get:function(){if("DURATION"in this.attr){var e=this.attr.decimalFloatingPoint("DURATION");if(S(e))return e}else if(this._endDate)return(this._endDate.getTime()-this._startDate.getTime())/1e3;return null}},{key:"plannedDuration",get:function(){return"PLANNED-DURATION"in this.attr?this.attr.decimalFloatingPoint("PLANNED-DURATION"):null}},{key:"endOnNext",get:function(){return this.attr.bool("END-ON-NEXT")}},{key:"isValid",get:function(){return!!this.id&&!this._badValueForSameId&&S(this.startDate.getTime())&&(null===this.duration||this.duration>=0)&&(!this.endOnNext||!!this.class)}}]),e}(),G=function(){this.aborted=!1,this.loaded=0,this.retry=0,this.total=0,this.chunkCount=0,this.bwEstimate=0,this.loading={start:0,first:0,end:0},this.parsing={start:0,end:0},this.buffering={start:0,first:0,end:0}},V={AUDIO:"audio",VIDEO:"video",AUDIOVIDEO:"audiovideo"},H=function(){function e(e){var t;this._byteRange=null,this._url=null,this.baseurl=void 0,this.relurl=void 0,this.elementaryStreams=((t={})[V.AUDIO]=null,t[V.VIDEO]=null,t[V.AUDIOVIDEO]=null,t),this.baseurl=e}return e.prototype.setByteRange=function(e,t){var r,i=e.split("@",2);r=1===i.length?(null==t?void 0:t.byteRangeEndOffset)||0:parseInt(i[1]),this._byteRange=[r,parseInt(i[0])+r]},o(e,[{key:"byteRange",get:function(){return this._byteRange?this._byteRange:[]}},{key:"byteRangeStartOffset",get:function(){return this.byteRange[0]}},{key:"byteRangeEndOffset",get:function(){return this.byteRange[1]}},{key:"url",get:function(){return!this._url&&this.baseurl&&this.relurl&&(this._url=T.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""},set:function(e){this._url=e}}]),e}(),K=function(e){function t(t,r){var i;return(i=e.call(this,r)||this)._decryptdata=null,i.rawProgramDateTime=null,i.programDateTime=null,i.tagList=[],i.duration=0,i.sn=0,i.levelkeys=void 0,i.type=void 0,i.loader=null,i.keyLoader=null,i.level=-1,i.cc=0,i.startPTS=void 0,i.endPTS=void 0,i.startDTS=void 0,i.endDTS=void 0,i.start=0,i.deltaPTS=void 0,i.maxStartPTS=void 0,i.minEndPTS=void 0,i.stats=new G,i.data=void 0,i.bitrateTest=!1,i.title=null,i.initSegment=null,i.endList=void 0,i.gap=void 0,i.urlId=0,i.type=t,i}d(t,e);var r=t.prototype;return r.setKeyFormat=function(e){if(this.levelkeys){var t=this.levelkeys[e];t&&!this._decryptdata&&(this._decryptdata=t.getDecryptData(this.sn))}},r.abortRequests=function(){var e,t;null==(e=this.loader)||e.abort(),null==(t=this.keyLoader)||t.abort()},r.setElementaryStreamInfo=function(e,t,r,i,a,n){void 0===n&&(n=!1);var s=this.elementaryStreams,o=s[e];o?(o.startPTS=Math.min(o.startPTS,t),o.endPTS=Math.max(o.endPTS,r),o.startDTS=Math.min(o.startDTS,i),o.endDTS=Math.max(o.endDTS,a)):s[e]={startPTS:t,endPTS:r,startDTS:i,endDTS:a,partial:n}},r.clearElementaryStreamInfo=function(){var e=this.elementaryStreams;e[V.AUDIO]=null,e[V.VIDEO]=null,e[V.AUDIOVIDEO]=null},o(t,[{key:"decryptdata",get:function(){if(!this.levelkeys&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkeys&&!this.levelkeys.NONE){var e=this.levelkeys.identity;if(e)this._decryptdata=e.getDecryptData(this.sn);else{var t=Object.keys(this.levelkeys);if(1===t.length)return this._decryptdata=this.levelkeys[t[0]].getDecryptData(this.sn)}}return this._decryptdata}},{key:"end",get:function(){return this.start+this.duration}},{key:"endProgramDateTime",get:function(){if(null===this.programDateTime)return null;if(!S(this.programDateTime))return null;var e=S(this.duration)?this.duration:0;return this.programDateTime+1e3*e}},{key:"encrypted",get:function(){var e;if(null!=(e=this._decryptdata)&&e.encrypted)return!0;if(this.levelkeys){var t=Object.keys(this.levelkeys),r=t.length;if(r>1||1===r&&this.levelkeys[t[0]].encrypted)return!0}return!1}}]),t}(H),W=function(e){function t(t,r,i,a,n){var s;(s=e.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 G,s.duration=t.decimalFloatingPoint("DURATION"),s.gap=t.bool("GAP"),s.independent=t.bool("INDEPENDENT"),s.relurl=t.enumeratedString("URI"),s.fragment=r,s.index=a;var o=t.enumeratedString("BYTERANGE");return o&&s.setByteRange(o,n),n&&(s.fragOffset=n.fragOffset+n.duration),s}return d(t,e),o(t,[{key:"start",get:function(){return this.fragment.start+this.fragOffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var e=this.elementaryStreams;return!!(e.audio||e.video||e.audiovideo)}}]),t}(H),Y=10,j=function(){function e(e){this.PTSKnown=!1,this.alignedSliding=!1,this.averagetargetduration=void 0,this.endCC=0,this.endSN=0,this.fragments=void 0,this.fragmentHint=void 0,this.partList=null,this.dateRanges=void 0,this.live=!0,this.ageHeader=0,this.advancedDateTime=void 0,this.updated=!0,this.advanced=!0,this.availabilityDelay=void 0,this.misses=0,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=void 0,this.m3u8="",this.version=null,this.canBlockReload=!1,this.canSkipUntil=0,this.canSkipDateRanges=!1,this.skippedSegments=0,this.recentlyRemovedDateranges=void 0,this.partHoldBack=0,this.holdBack=0,this.partTarget=0,this.preloadHint=void 0,this.renditionReports=void 0,this.tuneInGoal=0,this.deltaUpdateFailed=void 0,this.driftStartTime=0,this.driftEndTime=0,this.driftStart=0,this.driftEnd=0,this.encryptedFragments=void 0,this.playlistParsingError=null,this.variableList=null,this.hasVariableRefs=!1,this.fragments=[],this.encryptedFragments=[],this.dateRanges={},this.url=e}return e.prototype.reloaded=function(e){if(!e)return this.advanced=!0,void(this.updated=!0);var t=this.lastPartSn-e.lastPartSn,r=this.lastPartIndex-e.lastPartIndex;this.updated=this.endSN!==e.endSN||!!r||!!t||!this.live,this.advanced=this.endSN>e.endSN||t>0||0===t&&r>0,this.updated||this.advanced?this.misses=Math.floor(.6*e.misses):this.misses=e.misses+1,this.availabilityDelay=e.availabilityDelay},o(e,[{key:"hasProgramDateTime",get:function(){return!!this.fragments.length&&S(this.fragments[this.fragments.length-1].programDateTime)}},{key:"levelTargetDuration",get:function(){return this.averagetargetduration||this.targetduration||Y}},{key:"drift",get:function(){var e=this.driftEndTime-this.driftStartTime;return e>0?1e3*(this.driftEnd-this.driftStart)/e:1}},{key:"edge",get:function(){return this.partEnd||this.fragmentEnd}},{key:"partEnd",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].end:this.fragmentEnd}},{key:"fragmentEnd",get:function(){var e;return null!=(e=this.fragments)&&e.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 e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].index:-1}},{key:"lastPartSn",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}]),e}(),q=y(void 0);function z(e,t,r){return Uint8Array.prototype.slice?e.slice(t,r):new Uint8Array(Array.prototype.slice.call(e,t,r))}var X,Q=function(e,t){return t+10<=e.length&&73===e[t]&&68===e[t+1]&&51===e[t+2]&&e[t+3]<255&&e[t+4]<255&&e[t+6]<128&&e[t+7]<128&&e[t+8]<128&&e[t+9]<128},J=function(e,t){return t+10<=e.length&&51===e[t]&&68===e[t+1]&&73===e[t+2]&&e[t+3]<255&&e[t+4]<255&&e[t+6]<128&&e[t+7]<128&&e[t+8]<128&&e[t+9]<128},$=function(e,t){for(var r=t,i=0;Q(e,t);)i+=10,i+=Z(e,t+6),J(e,t+10)&&(i+=10),t+=i;if(i>0)return e.subarray(r,r+i)},Z=function(e,t){var r=0;return r=(127&e[t])<<21,r|=(127&e[t+1])<<14,r|=(127&e[t+2])<<7,r|=127&e[t+3]},ee=function(e,t){return Q(e,t)&&Z(e,t+6)+10<=e.length-t},te=function(e){for(var t=ae(e),r=0;r>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:u+=String.fromCharCode(n);break;case 12:case 13:s=e[d++],u+=String.fromCharCode((31&n)<<6|63&s);break;case 14:s=e[d++],o=e[d++],u+=String.fromCharCode((15&n)<<12|(63&s)<<6|(63&o)<<0)}}return u};function he(){if(!navigator.userAgent.includes("PlayStation 4"))return X||void 0===self.TextDecoder||(X=new self.TextDecoder("utf-8")),X}var fe={hexDump:function(e){for(var t="",r=0;r>24,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r}function Le(e){for(var t=e.byteLength,r=0;r8&&109===e[r+4]&&111===e[r+5]&&111===e[r+6]&&102===e[r+7])return!0;r=i>1?r+i:t}return!1}function Ae(e,t){var r=[];if(!t.length)return r;for(var i=e.byteLength,a=0;a1?a+n:i;if(me(e.subarray(a+4,a+8))===t[0])if(1===t.length)r.push(e.subarray(a+8,s));else{var o=Ae(e.subarray(a+8,s),t.slice(1));o.length&&ve.apply(r,o)}a=s}return r}function Re(e){var t=[],r=e[0],i=8,a=ye(e,i);i+=4;var n=0,s=0;0===r?(n=ye(e,i),s=ye(e,i+4),i+=8):(n=Ee(e,i),s=Ee(e,i+8),i+=16),i+=2;var o=e.length+s,l=pe(e,i);i+=2;for(var u=0;u>>31)return P.warn("SIDX has hierarchical references (not supported)"),null;var c=ye(e,d);d+=4,t.push({referenceSize:f,subsegmentDuration:c,info:{duration:c/a,start:o,end:o+f-1}}),o+=f,i=d+=4}return{earliestPresentationTime:n,timescale:a,version:r,referencesCount:l,references:t}}function be(e){for(var t=[],r=Ae(e,["moov","trak"]),a=0;a12){var d=4;if(3!==u[d++])break;d=ke(u,d),d+=2;var h=u[d++];if(128&h&&(d+=2),64&h&&(d+=u[d++]),4!==u[d++])break;d=ke(u,d);var f=u[d++];if(64!==f)break;if(a+="."+Ie(f),d+=12,5!==u[d++])break;d=ke(u,d);var c=u[d++],v=(248&c)>>3;31===v&&(v+=1+((7&c)<<3)+((224&u[d])>>5)),a+="."+v}break;case"hvc1":case"hev1":var g=Ae(r,["hvcC"])[0],m=g[1],p=["","A","B","C"][m>>6],y=31&m,E=ye(g,2),T=(32&m)>>5?"H":"L",S=g[12],L=g.subarray(6,12);a+="."+p+y,a+="."+E.toString(16).toUpperCase(),a+="."+T+S;for(var A="",R=L.length;R--;){var b=L[R];(b||A)&&(A="."+b.toString(16).toUpperCase()+A)}a+=A;break;case"dvh1":case"dvhe":var D=Ae(r,["dvcC"])[0],k=D[2]>>1&127,I=D[2]<<5&32|D[3]>>3&31;a+="."+_e(k)+"."+_e(I);break;case"vp09":var _=Ae(r,["vpcC"])[0],x=_[4],w=_[5],C=_[6]>>4&15;a+="."+_e(x)+"."+_e(w)+"."+_e(C);break;case"av01":var P=Ae(r,["av1C"])[0],O=P[1]>>>5,F=31&P[1],M=P[2]>>>7?"H":"M",N=(64&P[2])>>6,B=(32&P[2])>>5,U=2===O&&N?B?12:10:N?10:8,G=(16&P[2])>>4,V=(8&P[2])>>3,H=(4&P[2])>>2,K=3&P[2],W=1,Y=1,j=1,q=0;a+="."+O+"."+_e(F)+M+"."+_e(U)+"."+G+"."+V+H+K+"."+_e(W)+"."+_e(Y)+"."+_e(j)+"."+q}return{codec:a,encrypted:n}}function ke(e,t){for(var r=t+5;128&e[t++]&&t0;a||(i=Ae(t,["encv"])),i.forEach((function(e){Ae(a?e.subarray(28):e.subarray(78),["sinf"]).forEach((function(e){var t=we(e);if(t){var i=t.subarray(8,24);i.some((function(e){return 0!==e}))||(P.log("[eme] Patching keyId in 'enc"+(a?"a":"v")+">sinf>>tenc' box: "+fe.hexDump(i)+" -> "+fe.hexDump(r)),t.set(r,8))}}))}))})),e}function we(e){var t=Ae(e,["schm"])[0];if(t){var r=me(t.subarray(4,8));if("cbcs"===r||"cenc"===r)return Ae(e,["schi","tenc"])[0]}return null}function Ce(e,t){return Ae(t,["moof","traf"]).reduce((function(t,r){var i=Ae(r,["tfdt"])[0],a=i[0],n=Ae(r,["tfhd"]).reduce((function(t,r){var n=ye(r,4),s=e[n];if(s){var o=ye(i,4);if(1===a){if(o===ce)return P.warn("[mp4-demuxer]: Ignoring assumed invalid signed 64-bit track fragment decode time"),t;o*=ce+1,o+=ye(i,8)}var l=o/(s.timescale||9e4);if(S(l)&&(null===t||l>1&63;return 39===r||40===r}return 6==(31&t)}function Ve(e,t,r,i){var a=He(e),n=0;n+=t;for(var s=0,o=0,l=0;n=a.length)break;s+=l=a[n++]}while(255===l);o=0;do{if(n>=a.length)break;o+=l=a[n++]}while(255===l);var u=a.length-n,d=n;if(ou){P.error("Malformed SEI payload. "+o+" is too small, only "+u+" bytes left to parse.");break}if(4===s){if(181===a[d++]){var h=pe(a,d);if(d+=2,49===h){var f=ye(a,d);if(d+=4,1195456820===f){var c=a[d++];if(3===c){var v=a[d++],g=64&v,m=g?2+3*(31&v):0,p=new Uint8Array(m);if(g){p[0]=v;for(var y=1;y16){for(var E=[],T=0;T<16;T++){var S=a[d++].toString(16);E.push(1==S.length?"0"+S:S),3!==T&&5!==T&&7!==T&&9!==T||E.push("-")}for(var L=o-16,A=new Uint8Array(L),R=0;R>8*(15-r)&255;return t}function je(e){if(void 0===e&&(e=!0),"undefined"!=typeof self)return(e||!self.MediaSource)&&self.ManagedMediaSource||self.MediaSource||self.WebKitMediaSource}function qe(e){return"undefined"!=typeof self&&e===self.ManagedMediaSource}var ze={audio:{a3ds:1,"ac-3":.95,"ac-4":1,alac:.9,alaw:1,dra1:1,"dts+":1,"dts-":1,dtsc:1,dtse:1,dtsh:1,"ec-3":.9,enca:1,fLaC:.9,flac:.9,FLAC:.9,g719:1,g726:1,m4ae:1,mha1:1,mha2:1,mhm1:1,mhm2:1,mlpa:1,mp4a:1,"raw ":1,Opus:1,opus:1,samr:1,sawb:1,sawp:1,sevc:1,sqcp:1,ssmv:1,twos:1,ulaw:1},video:{avc1:1,avc2:1,avc3:1,avc4:1,avcp:1,av01:.8,drac:1,dva1:1,dvav:1,dvh1:.7,dvhe:.7,encv:1,hev1:.75,hvc1:.75,mjp2:1,mp4v:1,mvc1:1,mvc2:1,mvc3:1,mvc4:1,resv:1,rv60:1,s263:1,svc1:1,svc2:1,"vc-1":1,vp08:1,vp09:.9},text:{stpp:1,wvtt:1}};function Xe(e,t){var r=ze[t];return!!r&&!!r[e.slice(0,4)]}function Qe(e,t,r){return void 0===r&&(r=!0),!e.split(",").some((function(e){return!Je(e,t,r)}))}function Je(e,t,r){var i;void 0===r&&(r=!0);var a=je(r);return null!=(i=null==a?void 0:a.isTypeSupported($e(e,t)))&&i}function $e(e,t){return t+'/mp4;codecs="'+e+'"'}function Ze(e){if(e){var t=e.substring(0,4);return ze.video[t]}return 2}function et(e){return e.split(",").reduce((function(e,t){var r=ze.video[t];return r?(2*r+e)/(e?3:2):(ze.audio[t]+e)/(e?2:1)}),0)}var tt={};function rt(e,t){if(void 0===t&&(t=!0),tt[e])return tt[e];for(var r={flac:["flac","fLaC","FLAC"],opus:["opus","Opus"]}[e],i=0;i2){var a=i.shift()+".";a+=parseInt(i.shift()).toString(16),a+=("000"+parseInt(i.shift()).toString(16)).slice(-4),t[r]=a}}return t.join(",")}var ot=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-(SESSION-DATA|SESSION-KEY|DEFINE|CONTENT-STEERING|START):([^\r\n]*)[\r\n]+/g,lt=/#EXT-X-MEDIA:(.*)/g,ut=/^#EXT(?:INF|-X-TARGETDURATION):/m,dt=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[^\r\n]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),ht=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP|INDEPENDENT-SEGMENTS)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),ft=function(){function e(){}return e.findGroup=function(e,t){for(var r=0;r0&&n.length0&&q.bool("CAN-SKIP-DATERANGES"),d.partHoldBack=q.optionalFloat("PART-HOLD-BACK",0),d.holdBack=q.optionalFloat("HOLD-BACK",0);break;case"PART-INF":var z=new M(I);d.partTarget=z.decimalFloatingPoint("PART-TARGET");break;case"PART":var X=d.partList;X||(X=d.partList=[]);var Q=v>0?X[X.length-1]:void 0,J=v++,$=new M(I),Z=new W($,y,t,J,Q);X.push(Z),y.duration+=Z.duration;break;case"PRELOAD-HINT":var ee=new M(I);d.preloadHint=ee;break;case"RENDITION-REPORT":var te=new M(I);d.renditionReports=d.renditionReports||[],d.renditionReports.push(te);break;default:P.warn("line parsed but not handled: "+s)}}}p&&!p.relurl?(h.pop(),g-=p.duration,d.partList&&(d.fragmentHint=p)):d.partList&&(yt(y,p),y.cc=m,d.fragmentHint=y,l&&Tt(y,l,d));var re=h.length,ie=h[0],ae=h[re-1];if((g+=d.skippedSegments*d.targetduration)>0&&re&&ae){d.averagetargetduration=g/re;var ne=ae.sn;d.endSN="initSegment"!==ne?ne:0,d.live||(ae.endList=!0),ie&&(d.startCC=ie.cc)}else d.endSN=0,d.startCC=0;return d.fragmentHint&&(g+=d.fragmentHint.duration),d.totalduration=g,d.endCC=m,E>0&&pt(h,E),d},e}();function ct(e,t,r){var i,a,n=new M(e),s=null!=(i=n.METHOD)?i:"",o=n.URI,l=n.hexadecimalInteger("IV"),u=n.KEYFORMATVERSIONS,d=null!=(a=n.KEYFORMAT)?a:"identity";o&&n.IV&&!l&&P.error("Invalid IV: "+n.IV);var h=o?ft.resolve(o,t):"",f=(u||"1").split("/").map(Number).filter(Number.isFinite);return new We(s,h,d,f,l)}function vt(e){var t=new M(e).decimalFloatingPoint("TIME-OFFSET");return S(t)?t:null}function gt(e,t){var r=(e||"").split(/[ ,]+/).filter((function(e){return e}));["video","audio","text"].forEach((function(e){var i=r.filter((function(t){return Xe(t,e)}));i.length&&(t[e+"Codec"]=i.join(","),r=r.filter((function(e){return-1===i.indexOf(e)})))})),t.unknownCodecs=r}function mt(e,t,r){var i=t[r];i&&(e[r]=i)}function pt(e,t){for(var r=e[t],i=t;i--;){var a=e[i];if(!a)return;a.programDateTime=r.programDateTime-1e3*a.duration,r=a}}function yt(e,t){e.rawProgramDateTime?e.programDateTime=Date.parse(e.rawProgramDateTime):null!=t&&t.programDateTime&&(e.programDateTime=t.endProgramDateTime),S(e.programDateTime)||(e.programDateTime=null,e.rawProgramDateTime=null)}function Et(e,t,r,i){e.relurl=t.URI,t.BYTERANGE&&e.setByteRange(t.BYTERANGE),e.level=r,e.sn="initSegment",i&&(e.levelkeys=i),e.initSegment=null}function Tt(e,t,r){e.levelkeys=t;var i=r.encryptedFragments;i.length&&i[i.length-1].levelkeys===t||!Object.keys(t).some((function(e){return t[e].isCommonEncryption}))||i.push(e)}var St={MANIFEST:"manifest",LEVEL:"level",AUDIO_TRACK:"audioTrack",SUBTITLE_TRACK:"subtitleTrack"},Lt={MAIN:"main",AUDIO:"audio",SUBTITLE:"subtitle"};function At(e){switch(e.type){case St.AUDIO_TRACK:return Lt.AUDIO;case St.SUBTITLE_TRACK:return Lt.SUBTITLE;default:return Lt.MAIN}}function Rt(e,t){var r=e.url;return void 0!==r&&0!==r.indexOf("data:")||(r=t.url),r}var bt=function(){function e(e){this.hls=void 0,this.loaders=Object.create(null),this.variableList=null,this.hls=e,this.registerListeners()}var t=e.prototype;return t.startLoad=function(e){},t.stopLoad=function(){this.destroyInternalLoaders()},t.registerListeners=function(){var e=this.hls;e.on(R.MANIFEST_LOADING,this.onManifestLoading,this),e.on(R.LEVEL_LOADING,this.onLevelLoading,this),e.on(R.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.on(R.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},t.unregisterListeners=function(){var e=this.hls;e.off(R.MANIFEST_LOADING,this.onManifestLoading,this),e.off(R.LEVEL_LOADING,this.onLevelLoading,this),e.off(R.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.off(R.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},t.createInternalLoader=function(e){var t=this.hls.config,r=t.pLoader,i=t.loader,a=new(r||i)(t);return this.loaders[e.type]=a,a},t.getInternalLoader=function(e){return this.loaders[e.type]},t.resetInternalLoader=function(e){this.loaders[e]&&delete this.loaders[e]},t.destroyInternalLoaders=function(){for(var e in this.loaders){var t=this.loaders[e];t&&t.destroy(),this.resetInternalLoader(e)}},t.destroy=function(){this.variableList=null,this.unregisterListeners(),this.destroyInternalLoaders()},t.onManifestLoading=function(e,t){var r=t.url;this.variableList=null,this.load({id:null,level:0,responseType:"text",type:St.MANIFEST,url:r,deliveryDirectives:null})},t.onLevelLoading=function(e,t){var r=t.id,i=t.level,a=t.pathwayId,n=t.url,s=t.deliveryDirectives;this.load({id:r,level:i,pathwayId:a,responseType:"text",type:St.LEVEL,url:n,deliveryDirectives:s})},t.onAudioTrackLoading=function(e,t){var r=t.id,i=t.groupId,a=t.url,n=t.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:St.AUDIO_TRACK,url:a,deliveryDirectives:n})},t.onSubtitleTrackLoading=function(e,t){var r=t.id,i=t.groupId,a=t.url,n=t.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:St.SUBTITLE_TRACK,url:a,deliveryDirectives:n})},t.load=function(e){var t,r,i,a=this,n=this.hls.config,s=this.getInternalLoader(e);if(s){var o=s.context;if(o&&o.url===e.url&&o.level===e.level)return void P.trace("[playlist-loader]: playlist request ongoing");P.log("[playlist-loader]: aborting previous loader for type: "+e.type),s.abort()}if(r=e.type===St.MANIFEST?n.manifestLoadPolicy.default:u({},n.playlistLoadPolicy.default,{timeoutRetry:null,errorRetry:null}),s=this.createInternalLoader(e),S(null==(t=e.deliveryDirectives)?void 0:t.part)&&(e.type===St.LEVEL&&null!==e.level?i=this.hls.levels[e.level].details:e.type===St.AUDIO_TRACK&&null!==e.id?i=this.hls.audioTracks[e.id].details:e.type===St.SUBTITLE_TRACK&&null!==e.id&&(i=this.hls.subtitleTracks[e.id].details),i)){var l=i.partTarget,d=i.targetduration;if(l&&d){var h=1e3*Math.max(3*l,.8*d);r=u({},r,{maxTimeToFirstByteMs:Math.min(h,r.maxTimeToFirstByteMs),maxLoadTimeMs:Math.min(h,r.maxTimeToFirstByteMs)})}}var f=r.errorRetry||r.timeoutRetry||{},c={loadPolicy:r,timeout:r.maxLoadTimeMs,maxRetry:f.maxNumRetry||0,retryDelay:f.retryDelayMs||0,maxRetryDelay:f.maxRetryDelayMs||0},v={onSuccess:function(e,t,r,i){var n=a.getInternalLoader(r);a.resetInternalLoader(r.type);var s=e.data;0===s.indexOf("#EXTM3U")?(t.parsing.start=performance.now(),ft.isMediaPlaylist(s)?a.handleTrackOrLevelPlaylist(e,t,r,i||null,n):a.handleMasterPlaylist(e,t,r,i)):a.handleManifestParsingError(e,r,new Error("no EXTM3U delimiter"),i||null,t)},onError:function(e,t,r,i){a.handleNetworkError(t,r,!1,e,i)},onTimeout:function(e,t,r){a.handleNetworkError(t,r,!0,void 0,e)}};s.load(e,c,v)},t.handleMasterPlaylist=function(e,t,r,i){var a=this.hls,n=e.data,s=Rt(e,r),o=ft.parseMasterPlaylist(n,s);if(o.playlistParsingError)this.handleManifestParsingError(e,r,o.playlistParsingError,i,t);else{var l=o.contentSteering,u=o.levels,d=o.sessionData,h=o.sessionKeys,f=o.startTimeOffset,c=o.variableList;this.variableList=c;var v=ft.parseMasterPlaylistMedia(n,s,o),g=v.AUDIO,m=void 0===g?[]:g,p=v.SUBTITLES,y=v["CLOSED-CAPTIONS"];m.length&&(m.some((function(e){return!e.url}))||!u[0].audioCodec||u[0].attrs.AUDIO||(P.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),m.unshift({type:"main",name:"main",groupId:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new M({}),bitrate:0,url:""}))),a.trigger(R.MANIFEST_LOADED,{levels:u,audioTracks:m,subtitles:p,captions:y,contentSteering:l,url:s,stats:t,networkDetails:i,sessionData:d,sessionKeys:h,startTimeOffset:f,variableList:c})}},t.handleTrackOrLevelPlaylist=function(e,t,r,i,a){var n=this.hls,s=r.id,o=r.level,l=r.type,u=Rt(e,r),d=0,h=S(o)?o:S(s)?s:0,f=At(r),c=ft.parseLevelPlaylist(e.data,u,h,f,d,this.variableList);if(l===St.MANIFEST){var v={attrs:new M({}),bitrate:0,details:c,name:"",url:u};n.trigger(R.MANIFEST_LOADED,{levels:[v],audioTracks:[],url:u,stats:t,networkDetails:i,sessionData:null,sessionKeys:null,contentSteering:null,startTimeOffset:null,variableList:null})}t.parsing.end=performance.now(),r.levelDetails=c,this.handlePlaylistLoaded(c,e,t,r,i,a)},t.handleManifestParsingError=function(e,t,r,i,a){this.hls.trigger(R.ERROR,{type:b.NETWORK_ERROR,details:D.MANIFEST_PARSING_ERROR,fatal:t.type===St.MANIFEST,url:e.url,err:r,error:r,reason:r.message,response:e,context:t,networkDetails:i,stats:a})},t.handleNetworkError=function(e,t,r,a,n){void 0===r&&(r=!1);var s="A network "+(r?"timeout":"error"+(a?" (status "+a.code+")":""))+" occurred while loading "+e.type;e.type===St.LEVEL?s+=": "+e.level+" id: "+e.id:e.type!==St.AUDIO_TRACK&&e.type!==St.SUBTITLE_TRACK||(s+=" id: "+e.id+' group-id: "'+e.groupId+'"');var o=new Error(s);P.warn("[playlist-loader]: "+s);var l=D.UNKNOWN,u=!1,d=this.getInternalLoader(e);switch(e.type){case St.MANIFEST:l=r?D.MANIFEST_LOAD_TIMEOUT:D.MANIFEST_LOAD_ERROR,u=!0;break;case St.LEVEL:l=r?D.LEVEL_LOAD_TIMEOUT:D.LEVEL_LOAD_ERROR,u=!1;break;case St.AUDIO_TRACK:l=r?D.AUDIO_TRACK_LOAD_TIMEOUT:D.AUDIO_TRACK_LOAD_ERROR,u=!1;break;case St.SUBTITLE_TRACK:l=r?D.SUBTITLE_TRACK_LOAD_TIMEOUT:D.SUBTITLE_LOAD_ERROR,u=!1}d&&this.resetInternalLoader(e.type);var h={type:b.NETWORK_ERROR,details:l,fatal:u,url:e.url,loader:d,context:e,error:o,networkDetails:t,stats:n};if(a){var f=(null==t?void 0:t.url)||e.url;h.response=i({url:f,data:void 0},a)}this.hls.trigger(R.ERROR,h)},t.handlePlaylistLoaded=function(e,t,r,i,a,n){var s=this.hls,o=i.type,l=i.level,u=i.id,d=i.groupId,h=i.deliveryDirectives,f=Rt(t,i),c=At(i),v="number"==typeof i.level&&c===Lt.MAIN?l:void 0;if(e.fragments.length){e.targetduration||(e.playlistParsingError=new Error("Missing Target Duration"));var g=e.playlistParsingError;if(g)s.trigger(R.ERROR,{type:b.NETWORK_ERROR,details:D.LEVEL_PARSING_ERROR,fatal:!1,url:f,error:g,reason:g.message,response:t,context:i,level:v,parent:c,networkDetails:a,stats:r});else switch(e.live&&n&&(n.getCacheAge&&(e.ageHeader=n.getCacheAge()||0),n.getCacheAge&&!isNaN(e.ageHeader)||(e.ageHeader=0)),o){case St.MANIFEST:case St.LEVEL:s.trigger(R.LEVEL_LOADED,{details:e,level:v||0,id:u||0,stats:r,networkDetails:a,deliveryDirectives:h});break;case St.AUDIO_TRACK:s.trigger(R.AUDIO_TRACK_LOADED,{details:e,id:u||0,groupId:d||"",stats:r,networkDetails:a,deliveryDirectives:h});break;case St.SUBTITLE_TRACK:s.trigger(R.SUBTITLE_TRACK_LOADED,{details:e,id:u||0,groupId:d||"",stats:r,networkDetails:a,deliveryDirectives:h})}}else{var m=new Error("No Segments found in Playlist");s.trigger(R.ERROR,{type:b.NETWORK_ERROR,details:D.LEVEL_EMPTY_ERROR,fatal:!1,url:f,error:m,reason:m.message,response:t,context:i,level:v,parent:c,networkDetails:a,stats:r})}},e}();function Dt(e,t){var r;try{r=new Event("addtrack")}catch(e){(r=document.createEvent("Event")).initEvent("addtrack",!1,!1)}r.track=e,t.dispatchEvent(r)}function kt(e){var t=e.mode;if("disabled"===t&&(e.mode="hidden"),e.cues)for(var r=e.cues.length;r--;)e.removeCue(e.cues[r]);"disabled"===t&&(e.mode=t)}function It(e,t,r,i){var a=e.mode;if("disabled"===a&&(e.mode="hidden"),e.cues&&e.cues.length>0)for(var n=xt(e.cues,t,r),s=0;se[r].endTime)return-1;for(var i=0,a=r;i<=a;){var n=Math.floor((a+i)/2);if(te[n].startTime&&i-1)for(var n=a,s=e.length;n=t&&o.endTime<=r)i.push(o);else if(o.startTime>r)return i}return i}var wt={audioId3:"org.id3",dateRange:"com.apple.quicktime.HLS",emsg:"https://aomedia.org/emsg/ID3"},Ct=.25;function Pt(){if("undefined"!=typeof self)return self.VTTCue||self.TextTrackCue}function Ot(e,t,r,a,n){var s=new e(t,r,"");try{s.value=a,n&&(s.type=n)}catch(o){s=new e(t,r,JSON.stringify(n?i({type:n},a):a))}return s}var Ft=function(){var e=Pt();try{e&&new e(0,Number.POSITIVE_INFINITY,"")}catch(e){return Number.MAX_VALUE}return Number.POSITIVE_INFINITY}();function Mt(e,t){return e.getTime()/1e3-t}function Nt(e){return Uint8Array.from(e.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer}var Bt=function(){function e(e){this.hls=void 0,this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=e,this._registerListeners()}var t=e.prototype;return t.destroy=function(){this._unregisterListeners(),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=null},t._registerListeners=function(){var e=this.hls;e.on(R.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(R.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(R.MANIFEST_LOADING,this.onManifestLoading,this),e.on(R.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.on(R.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(R.LEVEL_UPDATED,this.onLevelUpdated,this)},t._unregisterListeners=function(){var e=this.hls;e.off(R.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(R.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(R.MANIFEST_LOADING,this.onManifestLoading,this),e.off(R.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.off(R.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(R.LEVEL_UPDATED,this.onLevelUpdated,this)},t.onMediaAttached=function(e,t){this.media=t.media},t.onMediaDetaching=function(){this.id3Track&&(kt(this.id3Track),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={})},t.onManifestLoading=function(){this.dateRangeCuesAppended={}},t.createTrack=function(e){var t=this.getID3Track(e.textTracks);return t.mode="hidden",t},t.getID3Track=function(e){if(this.media){for(var t=0;tFt&&(h=Ft),h-d<=0&&(h=d+Ct);for(var f=0;ft.startDate&&(!e||t.startDate.05&&this.forwardBufferLength>1){var l=Math.min(2,Math.max(1,n)),u=Math.round(2/(1+Math.exp(-.75*o-this.edgeStalled))*20)/20;e.playbackRate=Math.min(l,Math.max(1,u))}else 1!==e.playbackRate&&0!==e.playbackRate&&(e.playbackRate=1)}}}}},t.estimateLiveEdge=function(){var e=this.levelDetails;return null===e?null:e.edge+e.age},t.computeLatency=function(){var e=this.estimateLiveEdge();return null===e?null:e-this.currentTime},o(e,[{key:"latency",get:function(){return this._latency||0}},{key:"maxLatency",get:function(){var e=this.config,t=this.levelDetails;return void 0!==e.liveMaxLatencyDuration?e.liveMaxLatencyDuration:t?e.liveMaxLatencyDurationCount*t.targetduration:0}},{key:"targetLatency",get:function(){var e=this.levelDetails;if(null===e)return null;var t=e.holdBack,r=e.partHoldBack,i=e.targetduration,a=this.config,n=a.liveSyncDuration,s=a.liveSyncDurationCount,o=a.lowLatencyMode,l=this.hls.userConfig,u=o&&r||t;(l.liveSyncDuration||l.liveSyncDurationCount||0===u)&&(u=void 0!==n?n:s*i);var d=i,h=1;return u+Math.min(this.stallCount*h,d)}},{key:"liveSyncPosition",get:function(){var e=this.estimateLiveEdge(),t=this.targetLatency,r=this.levelDetails;if(null===e||null===t||null===r)return null;var i=r.edge,a=e-t-this.edgeStalled,n=i-r.totalduration,s=i-(this.config.lowLatencyMode&&r.partTarget||r.targetduration);return Math.min(Math.max(n,a),s)}},{key:"drift",get:function(){var e=this.levelDetails;return null===e?1:e.drift}},{key:"edgeStalled",get:function(){var e=this.levelDetails;if(null===e)return 0;var t=3*(this.config.lowLatencyMode&&e.partTarget||e.targetduration);return Math.max(e.age-t,0)}},{key:"forwardBufferLength",get:function(){var e=this.media,t=this.levelDetails;if(!e||!t)return 0;var r=e.buffered.length;return(r?e.buffered.end(r-1):t.edge)-this.currentTime}}]),e}(),Gt=["NONE","TYPE-0","TYPE-1",null];function Vt(e){return Gt.indexOf(e)>-1}var Ht=["SDR","PQ","HLG"];function Kt(e){return!!e&&Ht.indexOf(e)>-1}var Wt={No:"",Yes:"YES",v2:"v2"};function Yt(e){var t=e.canSkipUntil,r=e.canSkipDateRanges,i=e.age;return t&&ie.sn?(a=r-e.start,i=e):(a=e.start-r,i=t),i.duration!==a&&(i.duration=a)}else t.sn>e.sn?e.cc===t.cc&&e.minEndPTS?t.start=e.start+(e.minEndPTS-e.start):t.start=e.start+e.duration:t.start=Math.max(e.start-t.duration,0)}function Qt(e,t,r,i,a,n){i-r<=0&&(P.warn("Fragment should have a positive duration",t),i=r+t.duration,n=a+t.duration);var s=r,o=i,l=t.startPTS,u=t.endPTS;if(S(l)){var d=Math.abs(l-r);S(t.deltaPTS)?t.deltaPTS=Math.max(d,t.deltaPTS):t.deltaPTS=d,s=Math.max(r,l),r=Math.min(r,l),a=Math.min(a,t.startDTS),o=Math.min(i,u),i=Math.max(i,u),n=Math.max(n,t.endDTS)}var h=r-t.start;0!==t.start&&(t.start=r),t.duration=i-t.start,t.startPTS=r,t.maxStartPTS=s,t.startDTS=a,t.endPTS=i,t.minEndPTS=o,t.endDTS=n;var f,c=t.sn;if(!e||ce.endSN)return 0;var v=c-e.startSN,g=e.fragments;for(g[v]=t,f=v;f>0;f--)Xt(g[f],g[f-1]);for(f=v;f=0;a--){var n=i[a].initSegment;if(n){r=n;break}}e.fragmentHint&&delete e.fragmentHint.endPTS;var s,o=0;if(er(e,t,(function(e,i){e.relurl&&(o=e.cc-i.cc),S(e.startPTS)&&S(e.endPTS)&&(i.start=i.startPTS=e.startPTS,i.startDTS=e.startDTS,i.maxStartPTS=e.maxStartPTS,i.endPTS=e.endPTS,i.endDTS=e.endDTS,i.minEndPTS=e.minEndPTS,i.duration=e.endPTS-e.startPTS,i.duration&&(s=i),t.PTSKnown=t.alignedSliding=!0),i.elementaryStreams=e.elementaryStreams,i.loader=e.loader,i.stats=e.stats,e.initSegment&&(i.initSegment=e.initSegment,r=e.initSegment)})),r&&(t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments).forEach((function(e){var t;!e||e.initSegment&&e.initSegment.relurl!==(null==(t=r)?void 0:t.relurl)||(e.initSegment=r)})),t.skippedSegments)if(t.deltaUpdateFailed=t.fragments.some((function(e){return!e})),t.deltaUpdateFailed){P.warn("[level-helper] Previous playlist missing segments skipped in delta playlist");for(var l=t.skippedSegments;l--;)t.fragments.shift();t.startSN=t.fragments[0].sn,t.startCC=t.fragments[0].cc}else t.canSkipDateRanges&&(t.dateRanges=$t(e.dateRanges,t.dateRanges,t.recentlyRemovedDateranges));var u=t.fragments;if(o){P.warn("discontinuity sliding from playlist, take drift into account");for(var d=0;d=i.length||rr(t,i[r].start)}function rr(e,t){if(t){for(var r=e.fragments,i=e.skippedSegments;it){var n=1e3*i[i.length-1].duration;n499)}var vr={search:function(e,t){for(var r=0,i=e.length-1,a=null,n=null;r<=i;){var s=t(n=e[a=(r+i)/2|0]);if(s>0)r=a+1;else{if(!(s<0))return n;i=a-1}}return null}};function gr(e,t,r){if(null===t||!Array.isArray(e)||!e.length||!S(t))return null;if(t<(e[0].programDateTime||0))return null;if(t>=(e[e.length-1].endProgramDateTime||0))return null;r=r||0;for(var i=0;i0&&s<15e-7&&(r+=15e-7)}else 0===r&&0===t[0].start&&(n=t[0]);if(n&&((!e||e.level===n.level)&&0===yr(r,i,n)||pr(n,e,Math.min(a,i))))return n;var o=vr.search(t,yr.bind(null,r,i));return!o||o===e&&n?n:o}function pr(e,t,r){if(t&&0===t.start&&t.level0){var i=t.tagList.reduce((function(e,t){return"INF"===t[0]&&(e+=parseFloat(t[1])),e}),r);return e.start<=i}return!1}function yr(e,t,r){if(void 0===e&&(e=0),void 0===t&&(t=0),r.start<=e&&r.start+r.duration>e)return 0;var i=Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return r.start+r.duration-i<=e?1:r.start-i>e&&r.start?-1:0}function Er(e,t,r){var i=1e3*Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return(r.endProgramDateTime||0)-i>e}function Tr(e,t){return vr.search(e,(function(e){return e.cct?-1:0}))}var Sr={DoNothing:0,SendEndCallback:1,SendAlternateToPenaltyBox:2,RemoveAlternatePermanently:3,InsertDiscontinuity:4,RetryRequest:5},Lr={None:0,MoveAllAlternatesMatchingHost:1,MoveAllAlternatesMatchingHDCP:2,SwitchToSDR:4},Ar=function(){function e(e){this.hls=void 0,this.playlistError=0,this.penalizedRenditions={},this.log=void 0,this.warn=void 0,this.error=void 0,this.hls=e,this.log=P.log.bind(P,"[info]:"),this.warn=P.warn.bind(P,"[warning]:"),this.error=P.error.bind(P,"[error]:"),this.registerListeners()}var t=e.prototype;return t.registerListeners=function(){var e=this.hls;e.on(R.ERROR,this.onError,this),e.on(R.MANIFEST_LOADING,this.onManifestLoading,this),e.on(R.LEVEL_UPDATED,this.onLevelUpdated,this)},t.unregisterListeners=function(){var e=this.hls;e&&(e.off(R.ERROR,this.onError,this),e.off(R.ERROR,this.onErrorOut,this),e.off(R.MANIFEST_LOADING,this.onManifestLoading,this),e.off(R.LEVEL_UPDATED,this.onLevelUpdated,this))},t.destroy=function(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}},t.startLoad=function(e){},t.stopLoad=function(){this.playlistError=0},t.getVariantLevelIndex=function(e){return(null==e?void 0:e.type)===Lt.MAIN?e.level:this.hls.loadLevel},t.onManifestLoading=function(){this.playlistError=0,this.penalizedRenditions={}},t.onLevelUpdated=function(){this.playlistError=0},t.onError=function(e,t){var r,i;if(!t.fatal){var a=this.hls,n=t.context;switch(t.details){case D.FRAG_LOAD_ERROR:case D.FRAG_LOAD_TIMEOUT:case D.KEY_LOAD_ERROR:case D.KEY_LOAD_TIMEOUT:return void(t.errorAction=this.getFragRetryOrSwitchAction(t));case D.FRAG_PARSING_ERROR:if(null!=(r=t.frag)&&r.gap)return void(t.errorAction={action:Sr.DoNothing,flags:Lr.None});case D.FRAG_GAP:case D.FRAG_DECRYPT_ERROR:return t.errorAction=this.getFragRetryOrSwitchAction(t),void(t.errorAction.action=Sr.SendAlternateToPenaltyBox);case D.LEVEL_EMPTY_ERROR:case D.LEVEL_PARSING_ERROR:var s,o,l=t.parent===Lt.MAIN?t.level:a.loadLevel;return void(t.details===D.LEVEL_EMPTY_ERROR&&null!=(s=t.context)&&null!=(o=s.levelDetails)&&o.live?t.errorAction=this.getPlaylistRetryOrSwitchAction(t,l):(t.levelRetry=!1,t.errorAction=this.getLevelSwitchAction(t,l)));case D.LEVEL_LOAD_ERROR:case D.LEVEL_LOAD_TIMEOUT:return void("number"==typeof(null==n?void 0:n.level)&&(t.errorAction=this.getPlaylistRetryOrSwitchAction(t,n.level)));case D.AUDIO_TRACK_LOAD_ERROR:case D.AUDIO_TRACK_LOAD_TIMEOUT:case D.SUBTITLE_LOAD_ERROR:case D.SUBTITLE_TRACK_LOAD_TIMEOUT:if(n){var u=a.levels[a.loadLevel];if(u&&(n.type===St.AUDIO_TRACK&&u.hasAudioGroup(n.groupId)||n.type===St.SUBTITLE_TRACK&&u.hasSubtitleGroup(n.groupId)))return t.errorAction=this.getPlaylistRetryOrSwitchAction(t,a.loadLevel),t.errorAction.action=Sr.SendAlternateToPenaltyBox,void(t.errorAction.flags=Lr.MoveAllAlternatesMatchingHost)}return;case D.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:var d=a.levels[a.loadLevel],h=null==d?void 0:d.attrs["HDCP-LEVEL"];return void(h?t.errorAction={action:Sr.SendAlternateToPenaltyBox,flags:Lr.MoveAllAlternatesMatchingHDCP,hdcpLevel:h}:this.keySystemError(t));case D.BUFFER_ADD_CODEC_ERROR:case D.REMUX_ALLOC_ERROR:case D.BUFFER_APPEND_ERROR:return void(t.errorAction=this.getLevelSwitchAction(t,null!=(i=t.level)?i:a.loadLevel));case D.INTERNAL_EXCEPTION:case D.BUFFER_APPENDING_ERROR:case D.BUFFER_FULL_ERROR:case D.LEVEL_SWITCH_ERROR:case D.BUFFER_STALLED_ERROR:case D.BUFFER_SEEK_OVER_HOLE:case D.BUFFER_NUDGE_ON_STALL:return void(t.errorAction={action:Sr.DoNothing,flags:Lr.None})}t.type===b.KEY_SYSTEM_ERROR&&this.keySystemError(t)}},t.keySystemError=function(e){var t=this.getVariantLevelIndex(e.frag);e.levelRetry=!1,e.errorAction=this.getLevelSwitchAction(e,t)},t.getPlaylistRetryOrSwitchAction=function(e,t){var r=ur(this.hls.config.playlistLoadPolicy,e),i=this.playlistError++;if(fr(r,i,lr(e),e.response))return{action:Sr.RetryRequest,flags:Lr.None,retryConfig:r,retryCount:i};var a=this.getLevelSwitchAction(e,t);return r&&(a.retryConfig=r,a.retryCount=i),a},t.getFragRetryOrSwitchAction=function(e){var t=this.hls,r=this.getVariantLevelIndex(e.frag),i=t.levels[r],a=t.config,n=a.fragLoadPolicy,s=a.keyLoadPolicy,o=ur(e.details.startsWith("key")?s:n,e),l=t.levels.reduce((function(e,t){return e+t.fragmentError}),0);if(i&&(e.details!==D.FRAG_GAP&&i.fragmentError++,fr(o,l,lr(e),e.response)))return{action:Sr.RetryRequest,flags:Lr.None,retryConfig:o,retryCount:l};var u=this.getLevelSwitchAction(e,r);return o&&(u.retryConfig=o,u.retryCount=l),u},t.getLevelSwitchAction=function(e,t){var r=this.hls;null==t&&(t=r.loadLevel);var i=this.hls.levels[t];if(i){var a,n,s=e.details;i.loadError++,s===D.BUFFER_APPEND_ERROR&&i.fragmentError++;var o=-1,l=r.levels,u=r.loadLevel,d=r.minAutoLevel,h=r.maxAutoLevel;r.autoLevelEnabled||(r.loadLevel=-1);for(var f,c=null==(a=e.frag)?void 0:a.type,v=(c===Lt.AUDIO&&s===D.FRAG_PARSING_ERROR||"audio"===e.sourceBufferName&&(s===D.BUFFER_ADD_CODEC_ERROR||s===D.BUFFER_APPEND_ERROR))&&l.some((function(e){var t=e.audioCodec;return i.audioCodec!==t})),g="video"===e.sourceBufferName&&(s===D.BUFFER_ADD_CODEC_ERROR||s===D.BUFFER_APPEND_ERROR)&&l.some((function(e){var t=e.codecSet,r=e.audioCodec;return i.codecSet!==t&&i.audioCodec===r})),m=null!=(n=e.context)?n:{},p=m.type,y=m.groupId,E=function(){var t=(T+u)%l.length;if(t!==u&&t>=d&&t<=h&&0===l[t].loadError){var r,a,n=l[t];if(s===D.FRAG_GAP&&c===Lt.MAIN&&e.frag){var f=l[t].details;if(f){var m=mr(e.frag,f.fragments,e.frag.start);if(null!=m&&m.gap)return 0}}else{if(p===St.AUDIO_TRACK&&n.hasAudioGroup(y)||p===St.SUBTITLE_TRACK&&n.hasSubtitleGroup(y))return 0;if(c===Lt.AUDIO&&null!=(r=i.audioGroups)&&r.some((function(e){return n.hasAudioGroup(e)}))||c===Lt.SUBTITLE&&null!=(a=i.subtitleGroups)&&a.some((function(e){return n.hasSubtitleGroup(e)}))||v&&i.audioCodec===n.audioCodec||!v&&i.audioCodec!==n.audioCodec||g&&i.codecSet===n.codecSet)return 0}return o=t,1}},T=l.length;T--&&(0===(f=E())||1!==f););if(o>-1&&r.loadLevel!==o)return e.levelRetry=!0,this.playlistError=0,{action:Sr.SendAlternateToPenaltyBox,flags:Lr.None,nextAutoLevel:o}}return{action:Sr.SendAlternateToPenaltyBox,flags:Lr.MoveAllAlternatesMatchingHost}},t.onErrorOut=function(e,t){var r;switch(null==(r=t.errorAction)?void 0:r.action){case Sr.DoNothing:break;case Sr.SendAlternateToPenaltyBox:this.sendAlternateToPenaltyBox(t),t.errorAction.resolved||t.details===D.FRAG_GAP?/MediaSource readyState: ended/.test(t.error.message)&&(this.warn('MediaSource ended after "'+t.sourceBufferName+'" sourceBuffer append error. Attempting to recover from media error.'),this.hls.recoverMediaError()):t.fatal=!0}t.fatal&&this.hls.stopLoad()},t.sendAlternateToPenaltyBox=function(e){var t=this.hls,r=e.errorAction;if(r){var i=r.flags,a=r.hdcpLevel,n=r.nextAutoLevel;switch(i){case Lr.None:this.switchLevel(e,n);break;case Lr.MoveAllAlternatesMatchingHDCP:a&&(t.maxHdcpLevel=Gt[Gt.indexOf(a)-1],r.resolved=!0),this.warn('Restricting playback to HDCP-LEVEL of "'+t.maxHdcpLevel+'" or lower')}r.resolved||this.switchLevel(e,n)}},t.switchLevel=function(e,t){void 0!==t&&e.errorAction&&(this.warn("switching to level "+t+" after "+e.details),this.hls.nextAutoLevel=t,e.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel)},e}(),Rr=function(){function e(e,t){this.hls=void 0,this.timer=-1,this.requestScheduled=-1,this.canLoad=!1,this.log=void 0,this.warn=void 0,this.log=P.log.bind(P,t+":"),this.warn=P.warn.bind(P,t+":"),this.hls=e}var t=e.prototype;return t.destroy=function(){this.clearTimer(),this.hls=this.log=this.warn=null},t.clearTimer=function(){-1!==this.timer&&(self.clearTimeout(this.timer),this.timer=-1)},t.startLoad=function(){this.canLoad=!0,this.requestScheduled=-1,this.loadPlaylist()},t.stopLoad=function(){this.canLoad=!1,this.clearTimer()},t.switchParams=function(e,t,r){var i=null==t?void 0:t.renditionReports;if(i){for(var a=-1,n=0;n=0&&h>t.partTarget&&(d+=1)}var f=r&&Yt(r);return new jt(u,d>=0?d:void 0,f)}}},t.loadPlaylist=function(e){-1===this.requestScheduled&&(this.requestScheduled=self.performance.now())},t.shouldLoadPlaylist=function(e){return this.canLoad&&!!e&&!!e.url&&(!e.details||e.details.live)},t.shouldReloadPlaylist=function(e){return-1===this.timer&&-1===this.requestScheduled&&this.shouldLoadPlaylist(e)},t.playlistLoaded=function(e,t,r){var i=this,a=t.details,n=t.stats,s=self.performance.now(),o=n.loading.first?Math.max(0,s-n.loading.first):0;if(a.advancedDateTime=Date.now()-o,a.live||null!=r&&r.live){if(a.reloaded(r),r&&this.log("live playlist "+e+" "+(a.advanced?"REFRESHED "+a.lastPartSn+"-"+a.lastPartIndex:a.updated?"UPDATED":"MISSED")),r&&a.fragments.length>0&&Jt(r,a),!this.canLoad||!a.live)return;var l,u=void 0,d=void 0;if(a.canBlockReload&&a.endSN&&a.advanced){var h=this.hls.config.lowLatencyMode,f=a.lastPartSn,c=a.endSN,v=a.lastPartIndex,g=f===c;-1!==v?(u=g?c+1:f,d=g?h?0:v:v+1):u=c+1;var m=a.age,p=m+a.ageHeader,y=Math.min(p-a.partTarget,1.5*a.targetduration);if(y>0){if(r&&y>r.tuneInGoal)this.warn("CDN Tune-in goal increased from: "+r.tuneInGoal+" to: "+y+" with playlist age: "+a.age),y=0;else{var E=Math.floor(y/a.targetduration);u+=E,void 0!==d&&(d+=Math.round(y%a.targetduration/a.partTarget)),this.log("CDN Tune-in age: "+a.ageHeader+"s last advanced "+m.toFixed(2)+"s goal: "+y+" skip sn "+E+" to part "+d)}a.tuneInGoal=y}if(l=this.getDeliveryDirectives(a,t.deliveryDirectives,u,d),h||!g)return void this.loadPlaylist(l)}else(a.canBlockReload||a.canSkipUntil)&&(l=this.getDeliveryDirectives(a,t.deliveryDirectives,u,d));var T=this.hls.mainForwardBufferInfo,S=T?T.end-T.len:0,L=ir(a,1e3*(a.edge-S));a.updated&&s>this.requestScheduled+L&&(this.requestScheduled=n.loading.start),void 0!==u&&a.canBlockReload?this.requestScheduled=n.loading.first+L-(1e3*a.partTarget||1e3):-1===this.requestScheduled||this.requestScheduled+L=u.maxNumRetry)return!1;if(i&&null!=(h=e.context)&&h.deliveryDirectives)this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" without delivery-directives'),this.loadPlaylist();else{var f=dr(u,l);this.timer=self.setTimeout((function(){return t.loadPlaylist()}),f),this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" in '+f+"ms")}e.levelRetry=!0,a.resolved=!0}return d},e}(),br=function(){function e(e,t,r){void 0===t&&(t=0),void 0===r&&(r=0),this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=e,this.alpha_=e?Math.exp(Math.log(.5)/e):0,this.estimate_=t,this.totalWeight_=r}var t=e.prototype;return t.sample=function(e,t){var r=Math.pow(this.alpha_,e);this.estimate_=t*(1-r)+r*this.estimate_,this.totalWeight_+=e},t.getTotalWeight=function(){return this.totalWeight_},t.getEstimate=function(){if(this.alpha_){var e=1-Math.pow(this.alpha_,this.totalWeight_);if(e)return this.estimate_/e}return this.estimate_},e}(),Dr=function(){function e(e,t,r,i){void 0===i&&(i=100),this.defaultEstimate_=void 0,this.minWeight_=void 0,this.minDelayMs_=void 0,this.slow_=void 0,this.fast_=void 0,this.defaultTTFB_=void 0,this.ttfb_=void 0,this.defaultEstimate_=r,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new br(e),this.fast_=new br(t),this.defaultTTFB_=i,this.ttfb_=new br(e)}var t=e.prototype;return t.update=function(e,t){var r=this.slow_,i=this.fast_,a=this.ttfb_;r.halfLife!==e&&(this.slow_=new br(e,r.getEstimate(),r.getTotalWeight())),i.halfLife!==t&&(this.fast_=new br(t,i.getEstimate(),i.getTotalWeight())),a.halfLife!==e&&(this.ttfb_=new br(e,a.getEstimate(),a.getTotalWeight()))},t.sample=function(e,t){var r=(e=Math.max(e,this.minDelayMs_))/1e3,i=8*t/r;this.fast_.sample(r,i),this.slow_.sample(r,i)},t.sampleTTFB=function(e){var t=e/1e3,r=Math.sqrt(2)*Math.exp(-Math.pow(t,2)/2);this.ttfb_.sample(r,Math.max(e,5))},t.canEstimate=function(){return this.fast_.getTotalWeight()>=this.minWeight_},t.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},t.getEstimateTTFB=function(){return this.ttfb_.getTotalWeight()>=this.minWeight_?this.ttfb_.getEstimate():this.defaultTTFB_},t.destroy=function(){},e}();function kr(){if("function"==typeof matchMedia){var e=matchMedia("(dynamic-range: high)"),t=matchMedia("bad query");if(e.media!==t.media)return!0===e.matches}return!1}function Ir(e,t){var r=!1,i=[];return e&&(r="SDR"!==e,i=[e]),t&&(i=t.allowedVideoRanges||Ht.slice(0),i=(r=void 0!==t.preferHDR?t.preferHDR:kr())?i.filter((function(e){return"SDR"!==e})):["SDR"]),{preferHDR:r,allowedVideoRanges:i}}function _r(e,t,r,i,a){for(var n=Object.keys(e),s=null==i?void 0:i.channels,o=null==i?void 0:i.audioCodec,l=s&&2===parseInt(s),u=!0,d=!1,h=1/0,f=1/0,c=1/0,v=0,g=[],m=Ir(t,a),p=m.preferHDR,y=m.allowedVideoRanges,E=function(){var t=e[n[T]];u=t.channels[2]>0,h=Math.min(h,t.minHeight),f=Math.min(f,t.minFramerate),c=Math.min(c,t.minBitrate);var r=y.filter((function(e){return t.videoRanges[e]>0}));r.length>0&&(d=!0,g=r)},T=n.length;T--;)E();h=S(h)?h:0,f=S(f)?f:0;var L=Math.max(1080,h),A=Math.max(30,f);return c=S(c)?c:r,r=Math.max(c,r),d||(t=void 0,g=[]),{codecSet:n.reduce((function(t,i){var a=e[i];if(i===t)return t;if(a.minBitrate>r)return xr(i,"min bitrate of "+a.minBitrate+" > current estimate of "+r),t;if(!a.hasDefaultAudio)return xr(i,"no renditions with default or auto-select sound found"),t;if(o&&i.indexOf(o.substring(0,4))%5!=0)return xr(i,'audio codec preference "'+o+'" not found'),t;if(s&&!l){if(!a.channels[s])return xr(i,"no renditions with "+s+" channel sound found (channels options: "+Object.keys(a.channels)+")"),t}else if((!o||l)&&u&&0===a.channels[2])return xr(i,"no renditions with stereo sound found"),t;return a.minHeight>L?(xr(i,"min resolution of "+a.minHeight+" > maximum of "+L),t):a.minFramerate>A?(xr(i,"min framerate of "+a.minFramerate+" > maximum of "+A),t):g.some((function(e){return a.videoRanges[e]>0}))?a.maxScore=et(t)||a.fragmentError>e[t].fragmentError)?t:(v=a.maxScore,i):(xr(i,"no variants with VIDEO-RANGE of "+JSON.stringify(g)+" found"),t)}),void 0),videoRanges:g,preferHDR:p,minFramerate:f,minBitrate:c}}function xr(e,t){P.log('[abr] start candidates with "'+e+'" ignored because '+t)}function wr(e){return e.reduce((function(e,t){var r=e.groups[t.groupId];r||(r=e.groups[t.groupId]={tracks:[],channels:{2:0},hasDefault:!1,hasAutoSelect:!1}),r.tracks.push(t);var i=t.channels||"2";return r.channels[i]=(r.channels[i]||0)+1,r.hasDefault=r.hasDefault||t.default,r.hasAutoSelect=r.hasAutoSelect||t.autoselect,r.hasDefault&&(e.hasDefaultAudio=!0),r.hasAutoSelect&&(e.hasAutoSelectAudio=!0),e}),{hasDefaultAudio:!1,hasAutoSelectAudio:!1,groups:{}})}function Cr(e,t,r,i){return e.slice(r,i+1).reduce((function(e,t){if(!t.codecSet)return e;var r=t.audioGroups,i=e[t.codecSet];i||(e[t.codecSet]=i={minBitrate:1/0,minHeight:1/0,minFramerate:1/0,maxScore:0,videoRanges:{SDR:0},channels:{2:0},hasDefaultAudio:!r,fragmentError:0}),i.minBitrate=Math.min(i.minBitrate,t.bitrate);var a=Math.min(t.height,t.width);return i.minHeight=Math.min(i.minHeight,a),i.minFramerate=Math.min(i.minFramerate,t.frameRate),i.maxScore=Math.max(i.maxScore,t.score),i.fragmentError+=t.fragmentError,i.videoRanges[t.videoRange]=(i.videoRanges[t.videoRange]||0)+1,e}),{})}var Pr=function(){function e(e){var t=this;this.hls=void 0,this.lastLevelLoadSec=0,this.lastLoadedFragLevel=-1,this.firstSelection=-1,this._nextAutoLevel=-1,this.nextAutoLevelKey="",this.audioTracksByGroup=null,this.codecTiers=null,this.timer=-1,this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this._abandonRulesCheck=function(){var e=t.fragCurrent,r=t.partCurrent,i=t.hls,a=i.autoLevelEnabled,n=i.media;if(e&&n){var s=performance.now(),o=r?r.stats:e.stats,l=r?r.duration:e.duration,u=s-o.loading.start,d=i.minAutoLevel;if(o.aborted||o.loaded&&o.loaded===o.total||e.level<=d)return t.clearTimer(),void(t._nextAutoLevel=-1);if(a&&!n.paused&&n.playbackRate&&n.readyState){var h=i.mainForwardBufferInfo;if(null!==h){var f=t.bwEstimator.getEstimateTTFB(),c=Math.abs(n.playbackRate);if(!(u<=Math.max(f,l/(2*c)*1e3))){var v=h.len/c,g=o.loading.first?o.loading.first-o.loading.start:-1,m=o.loaded&&g>-1,p=t.getBwEstimate(),y=i.levels,E=y[e.level],T=o.total||Math.max(o.loaded,Math.round(l*E.averageBitrate/8)),L=m?u-g:u;L<1&&m&&(L=Math.min(u,8*o.loaded/p));var A=m?1e3*o.loaded/L:0,b=A?(T-o.loaded)/A:8*T/p+f/1e3;if(!(b<=v)){var D,k=A?8*A:p,I=Number.POSITIVE_INFINITY;for(D=e.level-1;D>d;D--){var _=y[D].maxBitrate;if((I=t.getTimeToLoadFrag(f/1e3,k,l*_,!y[D].details))=b||I>10*l)){i.nextLoadLevel=i.nextAutoLevel=D,m?t.bwEstimator.sample(u-Math.min(f,g),o.loaded):t.bwEstimator.sampleTTFB(u);var x=y[D].maxBitrate;t.getBwEstimate()*t.hls.config.abrBandWidthUpFactor>x&&t.resetEstimator(x),t.clearTimer(),P.warn("[abr] Fragment "+e.sn+(r?" part "+r.index:"")+" of level "+e.level+" is loading too slowly;\n Time to underbuffer: "+v.toFixed(3)+" s\n Estimated load time for current fragment: "+b.toFixed(3)+" s\n Estimated load time for down switch fragment: "+I.toFixed(3)+" s\n TTFB estimate: "+(0|g)+" ms\n Current BW estimate: "+(S(p)?0|p:"Unknown")+" bps\n New BW estimate: "+(0|t.getBwEstimate())+" bps\n Switching to level "+D+" @ "+(0|x)+" bps"),i.trigger(R.FRAG_LOAD_EMERGENCY_ABORTED,{frag:e,part:r,stats:o})}}}}}}},this.hls=e,this.bwEstimator=this.initEstimator(),this.registerListeners()}var t=e.prototype;return t.resetEstimator=function(e){e&&(P.log("setting initial bwe to "+e),this.hls.config.abrEwmaDefaultEstimate=e),this.firstSelection=-1,this.bwEstimator=this.initEstimator()},t.initEstimator=function(){var e=this.hls.config;return new Dr(e.abrEwmaSlowVoD,e.abrEwmaFastVoD,e.abrEwmaDefaultEstimate)},t.registerListeners=function(){var e=this.hls;e.on(R.MANIFEST_LOADING,this.onManifestLoading,this),e.on(R.FRAG_LOADING,this.onFragLoading,this),e.on(R.FRAG_LOADED,this.onFragLoaded,this),e.on(R.FRAG_BUFFERED,this.onFragBuffered,this),e.on(R.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(R.LEVEL_LOADED,this.onLevelLoaded,this),e.on(R.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(R.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.on(R.ERROR,this.onError,this)},t.unregisterListeners=function(){var e=this.hls;e&&(e.off(R.MANIFEST_LOADING,this.onManifestLoading,this),e.off(R.FRAG_LOADING,this.onFragLoading,this),e.off(R.FRAG_LOADED,this.onFragLoaded,this),e.off(R.FRAG_BUFFERED,this.onFragBuffered,this),e.off(R.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(R.LEVEL_LOADED,this.onLevelLoaded,this),e.off(R.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(R.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.off(R.ERROR,this.onError,this))},t.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this._abandonRulesCheck=null,this.fragCurrent=this.partCurrent=null},t.onManifestLoading=function(e,t){this.lastLoadedFragLevel=-1,this.firstSelection=-1,this.lastLevelLoadSec=0,this.fragCurrent=this.partCurrent=null,this.onLevelsUpdated(),this.clearTimer()},t.onLevelsUpdated=function(){this.lastLoadedFragLevel>-1&&this.fragCurrent&&(this.lastLoadedFragLevel=this.fragCurrent.level),this._nextAutoLevel=-1,this.onMaxAutoLevelUpdated(),this.codecTiers=null,this.audioTracksByGroup=null},t.onMaxAutoLevelUpdated=function(){this.firstSelection=-1,this.nextAutoLevelKey=""},t.onFragLoading=function(e,t){var r,i=t.frag;this.ignoreFragment(i)||(i.bitrateTest||(this.fragCurrent=i,this.partCurrent=null!=(r=t.part)?r:null),this.clearTimer(),this.timer=self.setInterval(this._abandonRulesCheck,100))},t.onLevelSwitching=function(e,t){this.clearTimer()},t.onError=function(e,t){if(!t.fatal)switch(t.details){case D.BUFFER_ADD_CODEC_ERROR:case D.BUFFER_APPEND_ERROR:this.lastLoadedFragLevel=-1,this.firstSelection=-1;break;case D.FRAG_LOAD_TIMEOUT:var r=t.frag,i=this.fragCurrent,a=this.partCurrent;if(r&&i&&r.sn===i.sn&&r.level===i.level){var n=performance.now(),s=a?a.stats:r.stats,o=n-s.loading.start,l=s.loading.first?s.loading.first-s.loading.start:-1;if(s.loaded&&l>-1){var u=this.bwEstimator.getEstimateTTFB();this.bwEstimator.sample(o-Math.min(u,l),s.loaded)}else this.bwEstimator.sampleTTFB(o)}}},t.getTimeToLoadFrag=function(e,t,r,i){return e+r/t+(i?this.lastLevelLoadSec:0)},t.onLevelLoaded=function(e,t){var r=this.hls.config,i=t.stats.loading,a=i.end-i.start;S(a)&&(this.lastLevelLoadSec=a/1e3),t.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD)},t.onFragLoaded=function(e,t){var r=t.frag,i=t.part,a=i?i.stats:r.stats;if(r.type===Lt.MAIN&&this.bwEstimator.sampleTTFB(a.loading.first-a.loading.start),!this.ignoreFragment(r)){if(this.clearTimer(),r.level===this._nextAutoLevel&&(this._nextAutoLevel=-1),this.firstSelection=-1,this.hls.config.abrMaxWithRealBitrate){var n=i?i.duration:r.duration,s=this.hls.levels[r.level],o=(s.loaded?s.loaded.bytes:0)+a.loaded,l=(s.loaded?s.loaded.duration:0)+n;s.loaded={bytes:o,duration:l},s.realBitrate=Math.round(8*o/l)}if(r.bitrateTest){var u={stats:a,frag:r,part:i,id:r.type};this.onFragBuffered(R.FRAG_BUFFERED,u),r.bitrateTest=!1}else this.lastLoadedFragLevel=r.level}},t.onFragBuffered=function(e,t){var r=t.frag,i=t.part,a=null!=i&&i.stats.loaded?i.stats:r.stats;if(!a.aborted&&!this.ignoreFragment(r)){var n=a.parsing.end-a.loading.start-Math.min(a.loading.first-a.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(n,a.loaded),a.bwEstimate=this.getBwEstimate(),r.bitrateTest?this.bitrateTestDelay=n/1e3:this.bitrateTestDelay=0}},t.ignoreFragment=function(e){return e.type!==Lt.MAIN||"initSegment"===e.sn},t.clearTimer=function(){this.timer>-1&&(self.clearInterval(this.timer),this.timer=-1)},t.getAutoLevelKey=function(){return this.getBwEstimate()+"_"+this.getStarvationDelay().toFixed(2)},t.getNextABRAutoLevel=function(){var e=this.fragCurrent,t=this.partCurrent,r=this.hls,i=r.maxAutoLevel,a=r.config,n=r.minAutoLevel,s=t?t.duration:e?e.duration:0,o=this.getBwEstimate(),l=this.getStarvationDelay(),u=a.abrBandWidthFactor,d=a.abrBandWidthUpFactor;if(l){var h=this.findBestLevel(o,n,i,l,0,u,d);if(h>=0)return h}var f=s?Math.min(s,a.maxStarvationDelay):a.maxStarvationDelay;if(!l){var c=this.bitrateTestDelay;c&&(f=(s?Math.min(s,a.maxLoadingDelay):a.maxLoadingDelay)-c,P.info("[abr] bitrate test took "+Math.round(1e3*c)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*f)+" ms"),u=d=1)}var v=this.findBestLevel(o,n,i,l,f,u,d);if(P.info("[abr] "+(l?"rebuffering expected":"buffer is empty")+", optimal quality level "+v),v>-1)return v;var g=r.levels[n],m=r.levels[r.loadLevel];return(null==g?void 0:g.bitrate)<(null==m?void 0:m.bitrate)?n:r.loadLevel},t.getStarvationDelay=function(){var e=this.hls,t=e.media;if(!t)return 1/0;var r=t&&0!==t.playbackRate?Math.abs(t.playbackRate):1,i=e.mainForwardBufferInfo;return(i?i.len:0)/r},t.getBwEstimate=function(){return this.bwEstimator.canEstimate()?this.bwEstimator.getEstimate():this.hls.config.abrEwmaDefaultEstimate},t.findBestLevel=function(e,t,r,i,a,n,s){var o,l=this,u=i+a,d=this.lastLoadedFragLevel,h=-1===d?this.hls.firstLevel:d,f=this.fragCurrent,c=this.partCurrent,v=this.hls,g=v.levels,m=v.allAudioTracks,p=v.loadLevel,y=v.config;if(1===g.length)return 0;var E,T=g[h],L=!(null==T||null==(o=T.details)||!o.live),A=-1===p||-1===d,R="SDR",b=(null==T?void 0:T.frameRate)||0,D=y.audioPreference,k=y.videoPreference,I=this.audioTracksByGroup||(this.audioTracksByGroup=wr(m));if(A){if(-1!==this.firstSelection)return this.firstSelection;var _=_r(this.codecTiers||(this.codecTiers=Cr(g,I,t,r)),R,e,D,k),x=_.codecSet,w=_.videoRanges,C=_.minFramerate,O=_.minBitrate,F=_.preferHDR;E=x,R=F?w[w.length-1]:w[0],b=C,e=Math.max(e,O),P.log("[abr] picked start tier "+JSON.stringify(_))}else E=null==T?void 0:T.codecSet,R=null==T?void 0:T.videoRange;for(var M,N=c?c.duration:f?f.duration:0,B=this.bwEstimator.getEstimateTTFB()/1e3,U=[],G=function(){var t,o=g[V],f=V>h;if(!o)return 0;if(E&&o.codecSet!==E||R&&o.videoRange!==R||f&&b>o.frameRate||!f&&b>0&&b=2*N&&0===a?g[V].averageBitrate:g[V].maxBitrate,k=l.getTimeToLoadFrag(B,v,D*y,void 0===m);if(v>=D&&(V===d||0===o.loadError&&0===o.fragmentError)&&(k<=B||!S(k)||L&&!l.bitrateTestDelay||k"+V+" adjustedbw("+Math.round(v)+")-bitrate="+Math.round(v-D)+" ttfb:"+B.toFixed(1)+" avgDuration:"+y.toFixed(1)+" maxFetchDuration:"+u.toFixed(1)+" fetchDuration:"+k.toFixed(1)+" firstSelection:"+A+" codecSet:"+E+" videoRange:"+R+" hls.loadLevel:"+p)),A&&(l.firstSelection=V),{v:V}}},V=r;V>=t;V--)if(0!==(M=G())&&M)return M.v;return-1},o(e,[{key:"firstAutoLevel",get:function(){var e=this.hls,t=e.maxAutoLevel,r=e.minAutoLevel,i=this.getBwEstimate(),a=this.hls.config.maxStarvationDelay,n=this.findBestLevel(i,r,t,0,a,1,1);if(n>-1)return n;var s=this.hls.firstLevel,o=Math.min(Math.max(s,r),t);return P.warn("[abr] Could not find best starting auto level. Defaulting to first in playlist "+s+" clamped to "+o),o}},{key:"forcedAutoLevel",get:function(){return this.nextAutoLevelKey?-1:this._nextAutoLevel}},{key:"nextAutoLevel",get:function(){var e=this.forcedAutoLevel,t=this.bwEstimator.canEstimate(),r=this.lastLoadedFragLevel>-1;if(!(-1===e||t&&r&&this.nextAutoLevelKey!==this.getAutoLevelKey()))return e;var i=t&&r?this.getNextABRAutoLevel():this.firstAutoLevel;if(-1!==e){var a=this.hls.levels;if(a.length>Math.max(e,i)&&a[e].loadError<=a[i].loadError)return e}return this._nextAutoLevel=i,this.nextAutoLevelKey=this.getAutoLevelKey(),i},set:function(e){var t=this.hls,r=t.maxAutoLevel,i=t.minAutoLevel,a=Math.min(Math.max(e,i),r);this._nextAutoLevel!==a&&(this.nextAutoLevelKey="",this._nextAutoLevel=a)}}]),e}(),Or={length:0,start:function(){return 0},end:function(){return 0}},Fr=function(){function e(){}return e.isBuffered=function(t,r){try{if(t)for(var i=e.getBuffered(t),a=0;a=i.start(a)&&r<=i.end(a))return!0}catch(e){}return!1},e.bufferInfo=function(t,r,i){try{if(t){var a,n=e.getBuffered(t),s=[];for(a=0;as&&(i[n-1].end=e[a].end):i.push(e[a])}else i.push(e[a])}else i=e;for(var o,l=0,u=t,d=t,h=0;h=f&&t "+e+")")},this.hls=e;var r="[buffer-controller]";this.appendSource=qe(je(e.config.preferManagedMediaSource)),this.log=P.log.bind(P,r),this.warn=P.warn.bind(P,r),this.error=P.error.bind(P,r),this._initSourceBuffer(),this.registerListeners()}var t=e.prototype;return t.hasSourceTypes=function(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0},t.destroy=function(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null,this.hls=null},t.registerListeners=function(){var e=this.hls;e.on(R.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(R.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(R.MANIFEST_LOADING,this.onManifestLoading,this),e.on(R.MANIFEST_PARSED,this.onManifestParsed,this),e.on(R.BUFFER_RESET,this.onBufferReset,this),e.on(R.BUFFER_APPENDING,this.onBufferAppending,this),e.on(R.BUFFER_CODECS,this.onBufferCodecs,this),e.on(R.BUFFER_EOS,this.onBufferEos,this),e.on(R.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(R.LEVEL_UPDATED,this.onLevelUpdated,this),e.on(R.FRAG_PARSED,this.onFragParsed,this),e.on(R.FRAG_CHANGED,this.onFragChanged,this)},t.unregisterListeners=function(){var e=this.hls;e.off(R.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(R.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(R.MANIFEST_LOADING,this.onManifestLoading,this),e.off(R.MANIFEST_PARSED,this.onManifestParsed,this),e.off(R.BUFFER_RESET,this.onBufferReset,this),e.off(R.BUFFER_APPENDING,this.onBufferAppending,this),e.off(R.BUFFER_CODECS,this.onBufferCodecs,this),e.off(R.BUFFER_EOS,this.onBufferEos,this),e.off(R.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(R.LEVEL_UPDATED,this.onLevelUpdated,this),e.off(R.FRAG_PARSED,this.onFragParsed,this),e.off(R.FRAG_CHANGED,this.onFragChanged,this)},t._initSourceBuffer=function(){this.sourceBuffer={},this.operationQueue=new Mr(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.appendErrors={audio:0,video:0,audiovideo:0},this.lastMpegAudioChunk=null},t.onManifestLoading=function(){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=0,this.details=null},t.onManifestParsed=function(e,t){var r=2;t.audio&&!t.video||t.altAudio,r=1,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=r,this.log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},t.onMediaAttaching=function(e,t){var r=this.media=t.media,i=je(this.appendSource);if(r&&i){var a,n=this.mediaSource=new i;this.log("created media source: "+(null==(a=n.constructor)?void 0:a.name)),n.addEventListener("sourceopen",this._onMediaSourceOpen),n.addEventListener("sourceended",this._onMediaSourceEnded),n.addEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(n.addEventListener("startstreaming",this._onStartStreaming),n.addEventListener("endstreaming",this._onEndStreaming));var s=this._objectUrl=self.URL.createObjectURL(n);if(this.appendSource)try{r.removeAttribute("src");var o=self.ManagedMediaSource;r.disableRemotePlayback=r.disableRemotePlayback||o&&n instanceof o,Ur(r),Gr(r,s),r.load()}catch(e){r.src=s}else r.src=s;r.addEventListener("emptied",this._onMediaEmptied)}},t.onMediaDetaching=function(){var e=this.media,t=this.mediaSource,r=this._objectUrl;if(t){if(this.log("media source detaching"),"open"===t.readyState)try{t.endOfStream()}catch(e){this.warn("onMediaDetaching: "+e.message+" while calling endOfStream")}this.onBufferReset(),t.removeEventListener("sourceopen",this._onMediaSourceOpen),t.removeEventListener("sourceended",this._onMediaSourceEnded),t.removeEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(t.removeEventListener("startstreaming",this._onStartStreaming),t.removeEventListener("endstreaming",this._onEndStreaming)),e&&(e.removeEventListener("emptied",this._onMediaEmptied),r&&self.URL.revokeObjectURL(r),this.mediaSrc===r?(e.removeAttribute("src"),this.appendSource&&Ur(e),e.load()):this.warn("media|source.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(R.MEDIA_DETACHED,void 0)},t.onBufferReset=function(){var e=this;this.getSourceBufferTypes().forEach((function(t){e.resetBuffer(t)})),this._initSourceBuffer()},t.resetBuffer=function(e){var t=this.sourceBuffer[e];try{var r;t&&(this.removeBufferListeners(e),this.sourceBuffer[e]=void 0,null!=(r=this.mediaSource)&&r.sourceBuffers.length&&this.mediaSource.removeSourceBuffer(t))}catch(t){this.warn("onBufferReset "+e,t)}},t.onBufferCodecs=function(e,t){var r=this,i=this.getSourceBufferTypes().length,a=Object.keys(t);if(a.forEach((function(e){if(i){var a=r.tracks[e];if(a&&"function"==typeof a.buffer.changeType){var n,s=t[e],o=s.id,l=s.codec,u=s.levelCodec,d=s.container,h=s.metadata,f=nt(a.codec,a.levelCodec),c=null==f?void 0:f.replace(Nr,"$1"),v=nt(l,u),g=null==(n=v)?void 0:n.replace(Nr,"$1");if(v&&c!==g){"audio"===e.slice(0,5)&&(v=at(v,r.appendSource));var m=d+";codecs="+v;r.appendChangeType(e,m),r.log("switching codec "+f+" to "+v),r.tracks[e]={buffer:a.buffer,codec:l,container:d,levelCodec:u,metadata:h,id:o}}}}else r.pendingTracks[e]=t[e]})),!i){var n=Math.max(this.bufferCodecEventsExpected-1,0);this.bufferCodecEventsExpected!==n&&(this.log(n+" bufferCodec event(s) expected "+a.join(",")),this.bufferCodecEventsExpected=n),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks()}},t.appendChangeType=function(e,t){var r=this,i=this.operationQueue,a={execute:function(){var a=r.sourceBuffer[e];a&&(r.log("changing "+e+" sourceBuffer type to "+t),a.changeType(t)),i.shiftAndExecuteNext(e)},onStart:function(){},onComplete:function(){},onError:function(t){r.warn("Failed to change "+e+" SourceBuffer type",t)}};i.append(a,e,!!this.pendingTracks[e])},t.onBufferAppending=function(e,t){var r=this,i=this.hls,a=this.operationQueue,n=this.tracks,s=t.data,o=t.type,l=t.frag,u=t.part,d=t.chunkMeta,h=d.buffering[o],f=self.performance.now();h.start=f;var c=l.stats.buffering,v=u?u.stats.buffering:null;0===c.start&&(c.start=f),v&&0===v.start&&(v.start=f);var g=n.audio,m=!1;"audio"===o&&"audio/mpeg"===(null==g?void 0:g.container)&&(m=!this.lastMpegAudioChunk||1===d.id||this.lastMpegAudioChunk.sn!==d.sn,this.lastMpegAudioChunk=d);var p=l.start,y={execute:function(){if(h.executeStart=self.performance.now(),m){var e=r.sourceBuffer[o];if(e){var t=p-e.timestampOffset;Math.abs(t)>=.1&&(r.log("Updating audio SourceBuffer timestampOffset to "+p+" (delta: "+t+") sn: "+l.sn+")"),e.timestampOffset=p)}}r.appendExecutor(s,o)},onStart:function(){},onComplete:function(){var e=self.performance.now();h.executeEnd=h.end=e,0===c.first&&(c.first=e),v&&0===v.first&&(v.first=e);var t=r.sourceBuffer,i={};for(var a in t)i[a]=Fr.getBuffered(t[a]);r.appendErrors[o]=0,"audio"===o||"video"===o?r.appendErrors.audiovideo=0:(r.appendErrors.audio=0,r.appendErrors.video=0),r.hls.trigger(R.BUFFER_APPENDED,{type:o,frag:l,part:u,chunkMeta:d,parent:l.type,timeRanges:i})},onError:function(e){var t={type:b.MEDIA_ERROR,parent:l.type,details:D.BUFFER_APPEND_ERROR,sourceBufferName:o,frag:l,part:u,chunkMeta:d,error:e,err:e,fatal:!1};if(e.code===DOMException.QUOTA_EXCEEDED_ERR)t.details=D.BUFFER_FULL_ERROR;else{var a=++r.appendErrors[o];t.details=D.BUFFER_APPEND_ERROR,r.warn("Failed "+a+"/"+i.config.appendErrorMaxRetry+' times to append segment in "'+o+'" sourceBuffer'),a>=i.config.appendErrorMaxRetry&&(t.fatal=!0)}i.trigger(R.ERROR,t)}};a.append(y,o,!!this.pendingTracks[o])},t.onBufferFlushing=function(e,t){var r=this,i=this.operationQueue,a=function(e){return{execute:r.removeExecutor.bind(r,e,t.startOffset,t.endOffset),onStart:function(){},onComplete:function(){r.hls.trigger(R.BUFFER_FLUSHED,{type:e})},onError:function(t){r.warn("Failed to remove from "+e+" SourceBuffer",t)}}};t.type?i.append(a(t.type),t.type):this.getSourceBufferTypes().forEach((function(e){i.append(a(e),e)}))},t.onFragParsed=function(e,t){var r=this,i=t.frag,a=t.part,n=[],s=a?a.elementaryStreams:i.elementaryStreams;s[V.AUDIOVIDEO]?n.push("audiovideo"):(s[V.AUDIO]&&n.push("audio"),s[V.VIDEO]&&n.push("video"));var o=function(){var e=self.performance.now();i.stats.buffering.end=e,a&&(a.stats.buffering.end=e);var t=a?a.stats:i.stats;r.hls.trigger(R.FRAG_BUFFERED,{frag:i,part:a,stats:t,id:i.type})};0===n.length&&this.warn("Fragments must have at least one ElementaryStreamType set. type: "+i.type+" level: "+i.level+" sn: "+i.sn),this.blockBuffers(o,n)},t.onFragChanged=function(e,t){this.trimBuffers()},t.onBufferEos=function(e,t){var r=this;this.getSourceBufferTypes().reduce((function(e,i){var a=r.sourceBuffer[i];return!a||t.type&&t.type!==i||(a.ending=!0,a.ended||(a.ended=!0,r.log(i+" sourceBuffer now EOS"))),e&&!(a&&!a.ended)}),!0)&&(this.log("Queueing mediaSource.endOfStream()"),this.blockBuffers((function(){r.getSourceBufferTypes().forEach((function(e){var t=r.sourceBuffer[e];t&&(t.ending=!1)}));var e=r.mediaSource;e&&"open"===e.readyState?(r.log("Calling mediaSource.endOfStream()"),e.endOfStream()):e&&r.log("Could not call mediaSource.endOfStream(). mediaSource.readyState: "+e.readyState)})))},t.onLevelUpdated=function(e,t){var r=t.details;r.fragments.length&&(this.details=r,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())},t.trimBuffers=function(){var e=this.hls,t=this.details,r=this.media;if(r&&null!==t&&this.getSourceBufferTypes().length){var i=e.config,a=r.currentTime,n=t.levelTargetDuration,s=t.live&&null!==i.liveBackBufferLength?i.liveBackBufferLength:i.backBufferLength;if(S(s)&&s>0){var o=Math.max(s,n),l=Math.floor(a/n)*n-o;this.flushBackBuffer(a,n,l)}if(S(i.frontBufferFlushThreshold)&&i.frontBufferFlushThreshold>0){var u=Math.max(i.maxBufferLength,i.frontBufferFlushThreshold),d=Math.max(u,n),h=Math.floor(a/n)*n+d;this.flushFrontBuffer(a,n,h)}}},t.flushBackBuffer=function(e,t,r){var i=this,a=this.details,n=this.sourceBuffer;this.getSourceBufferTypes().forEach((function(s){var o=n[s];if(o){var l=Fr.getBuffered(o);if(l.length>0&&r>l.start(0)){if(i.hls.trigger(R.BACK_BUFFER_REACHED,{bufferEnd:r}),null!=a&&a.live)i.hls.trigger(R.LIVE_BACK_BUFFER_REACHED,{bufferEnd:r});else if(o.ended&&l.end(l.length-1)-e<2*t)return void i.log("Cannot flush "+s+" back buffer while SourceBuffer is in ended state");i.hls.trigger(R.BUFFER_FLUSHING,{startOffset:0,endOffset:r,type:s})}}}))},t.flushFrontBuffer=function(e,t,r){var i=this,a=this.sourceBuffer;this.getSourceBufferTypes().forEach((function(n){var s=a[n];if(s){var o=Fr.getBuffered(s),l=o.length;if(l<2)return;var u=o.start(l-1),d=o.end(l-1);if(r>u||e>=u&&e<=d)return;if(s.ended&&e-d<2*t)return void i.log("Cannot flush "+n+" front buffer while SourceBuffer is in ended state");i.hls.trigger(R.BUFFER_FLUSHING,{startOffset:u,endOffset:1/0,type:n})}}))},t.updateMediaElementDuration=function(){if(this.details&&this.media&&this.mediaSource&&"open"===this.mediaSource.readyState){var e=this.details,t=this.hls,r=this.media,i=this.mediaSource,a=e.fragments[0].start+e.totalduration,n=r.duration,s=S(i.duration)?i.duration:0;e.live&&t.config.liveDurationInfinity?(i.duration=1/0,this.updateSeekableRange(e)):(a>s&&a>n||!S(n))&&(this.log("Updating Media Source duration to "+a.toFixed(3)),i.duration=a)}},t.updateSeekableRange=function(e){var t=this.mediaSource,r=e.fragments;if(r.length&&e.live&&null!=t&&t.setLiveSeekableRange){var i=Math.max(0,r[0].start),a=Math.max(i,i+e.totalduration);this.log("Media Source duration is set to "+t.duration+". Setting seekable range to "+i+"-"+a+"."),t.setLiveSeekableRange(i,a)}},t.checkPendingTracks=function(){var e=this.bufferCodecEventsExpected,t=this.operationQueue,r=this.pendingTracks,i=Object.keys(r).length;if(i&&(!e||2===i||"audiovideo"in r)){this.createSourceBuffers(r),this.pendingTracks={};var a=this.getSourceBufferTypes();if(a.length)this.hls.trigger(R.BUFFER_CREATED,{tracks:this.tracks}),a.forEach((function(e){t.executeNext(e)}));else{var n=new Error("could not create source buffer for media codec(s)");this.hls.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:n,reason:n.message})}}},t.createSourceBuffers=function(e){var t=this,r=this.sourceBuffer,i=this.mediaSource;if(!i)throw Error("createSourceBuffers called when mediaSource was null");var a=function(a){if(!r[a]){var n,s=e[a];if(!s)throw Error("source buffer exists for track "+a+", however track does not");var o=-1===(null==(n=s.levelCodec)?void 0:n.indexOf(","))?s.levelCodec:s.codec;o&&"audio"===a.slice(0,5)&&(o=at(o,t.appendSource));var l=s.container+";codecs="+o;t.log("creating sourceBuffer("+l+")");try{var u=r[a]=i.addSourceBuffer(l),d=a;t.addBufferListener(d,"updatestart",t._onSBUpdateStart),t.addBufferListener(d,"updateend",t._onSBUpdateEnd),t.addBufferListener(d,"error",t._onSBUpdateError),t.appendSource&&t.addBufferListener(d,"bufferedchange",(function(e,r){var i=r.removedRanges;null!=i&&i.length&&t.hls.trigger(R.BUFFER_FLUSHED,{type:a})})),t.tracks[a]={buffer:u,codec:o,container:s.container,levelCodec:s.levelCodec,metadata:s.metadata,id:s.id}}catch(e){t.error("error while trying to add sourceBuffer: "+e.message),t.hls.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:e,sourceBufferName:a,mimeType:l})}}};for(var n in e)a(n)},t._onSBUpdateStart=function(e){this.operationQueue.current(e).onStart()},t._onSBUpdateEnd=function(e){var t;if("closed"!==(null==(t=this.mediaSource)?void 0:t.readyState)){var r=this.operationQueue;r.current(e).onComplete(),r.shiftAndExecuteNext(e)}else this.resetBuffer(e)},t._onSBUpdateError=function(e,t){var r,i=new Error(e+" SourceBuffer error. MediaSource readyState: "+(null==(r=this.mediaSource)?void 0:r.readyState));this.error(""+i,t),this.hls.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_APPENDING_ERROR,sourceBufferName:e,error:i,fatal:!1});var a=this.operationQueue.current(e);a&&a.onError(i)},t.removeExecutor=function(e,t,r){var i=this.media,a=this.mediaSource,n=this.operationQueue,s=this.sourceBuffer[e];if(!i||!a||!s)return this.warn("Attempting to remove from the "+e+" SourceBuffer, but it does not exist"),void n.shiftAndExecuteNext(e);var o=S(i.duration)?i.duration:1/0,l=S(a.duration)?a.duration:1/0,u=Math.max(0,t),d=Math.min(r,o,l);d>u&&(!s.ending||s.ended)?(s.ended=!1,this.log("Removing ["+u+","+d+"] from the "+e+" SourceBuffer"),s.remove(u,d)):n.shiftAndExecuteNext(e)},t.appendExecutor=function(e,t){var r=this.sourceBuffer[t];if(r)r.ended=!1,r.appendBuffer(e);else if(!this.pendingTracks[t])throw new Error("Attempting to append to the "+t+" SourceBuffer, but it does not exist")},t.blockBuffers=function(e,t){var r=this;if(void 0===t&&(t=this.getSourceBufferTypes()),!t.length)return this.log("Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(e);var i=this.operationQueue,a=t.map((function(e){return i.appendBlocker(e)}));Promise.all(a).then((function(){e(),t.forEach((function(e){var t=r.sourceBuffer[e];null!=t&&t.updating||i.shiftAndExecuteNext(e)}))}))},t.getSourceBufferTypes=function(){return Object.keys(this.sourceBuffer)},t.addBufferListener=function(e,t,r){var i=this.sourceBuffer[e];if(i){var a=r.bind(this,e);this.listeners[e].push({event:t,listener:a}),i.addEventListener(t,a)}},t.removeBufferListeners=function(e){var t=this.sourceBuffer[e];t&&this.listeners[e].forEach((function(e){t.removeEventListener(e.event,e.listener)}))},o(e,[{key:"mediaSrc",get:function(){var e,t,r=(null==(e=this.media)||null==(t=e.querySelector)?void 0:t.call(e,"source"))||this.media;return null==r?void 0:r.src}}]),e}();function Ur(e){var t=e.querySelectorAll("source");[].slice.call(t).forEach((function(t){e.removeChild(t)}))}function Gr(e,t){var r=self.document.createElement("source");r.type="video/mp4",r.src=t,e.appendChild(r)}var Vr=function(){function e(e){this.hls=void 0,this.autoLevelCapping=void 0,this.firstLevel=void 0,this.media=void 0,this.restrictedLevels=void 0,this.timer=void 0,this.clientRect=void 0,this.streamController=void 0,this.hls=e,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.firstLevel=-1,this.media=null,this.restrictedLevels=[],this.timer=void 0,this.clientRect=null,this.registerListeners()}var t=e.prototype;return t.setStreamController=function(e){this.streamController=e},t.destroy=function(){this.hls&&this.unregisterListener(),this.timer&&this.stopCapping(),this.media=null,this.clientRect=null,this.hls=this.streamController=null},t.registerListeners=function(){var e=this.hls;e.on(R.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.on(R.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(R.MANIFEST_PARSED,this.onManifestParsed,this),e.on(R.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(R.BUFFER_CODECS,this.onBufferCodecs,this),e.on(R.MEDIA_DETACHING,this.onMediaDetaching,this)},t.unregisterListener=function(){var e=this.hls;e.off(R.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.off(R.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(R.MANIFEST_PARSED,this.onManifestParsed,this),e.off(R.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(R.BUFFER_CODECS,this.onBufferCodecs,this),e.off(R.MEDIA_DETACHING,this.onMediaDetaching,this)},t.onFpsDropLevelCapping=function(e,t){var r=this.hls.levels[t.droppedLevel];this.isLevelAllowed(r)&&this.restrictedLevels.push({bitrate:r.bitrate,height:r.height,width:r.width})},t.onMediaAttaching=function(e,t){this.media=t.media instanceof HTMLVideoElement?t.media:null,this.clientRect=null,this.timer&&this.hls.levels.length&&this.detectPlayerSize()},t.onManifestParsed=function(e,t){var r=this.hls;this.restrictedLevels=[],this.firstLevel=t.firstLevel,r.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onLevelsUpdated=function(e,t){this.timer&&S(this.autoLevelCapping)&&this.detectPlayerSize()},t.onBufferCodecs=function(e,t){this.hls.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onMediaDetaching=function(){this.stopCapping()},t.detectPlayerSize=function(){if(this.media){if(this.mediaHeight<=0||this.mediaWidth<=0)return void(this.clientRect=null);var e=this.hls.levels;if(e.length){var t=this.hls,r=this.getMaxLevel(e.length-1);r!==this.autoLevelCapping&&P.log("Setting autoLevelCapping to "+r+": "+e[r].height+"p@"+e[r].bitrate+" for media "+this.mediaWidth+"x"+this.mediaHeight),t.autoLevelCapping=r,t.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=t.autoLevelCapping}}},t.getMaxLevel=function(t){var r=this,i=this.hls.levels;if(!i.length)return-1;var a=i.filter((function(e,i){return r.isLevelAllowed(e)&&i<=t}));return this.clientRect=null,e.getMaxLevelByMediaSize(a,this.mediaWidth,this.mediaHeight)},t.startCapping=function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},t.stopCapping=function(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)},t.getDimensions=function(){if(this.clientRect)return this.clientRect;var e=this.media,t={width:0,height:0};if(e){var r=e.getBoundingClientRect();t.width=r.width,t.height=r.height,t.width||t.height||(t.width=r.right-r.left||e.width||0,t.height=r.bottom-r.top||e.height||0)}return this.clientRect=t,t},t.isLevelAllowed=function(e){return!this.restrictedLevels.some((function(t){return e.bitrate===t.bitrate&&e.width===t.width&&e.height===t.height}))},e.getMaxLevelByMediaSize=function(e,t,r){if(null==e||!e.length)return-1;for(var i=function(e,t){return!t||e.width!==t.width||e.height!==t.height},a=e.length-1,n=Math.max(t,r),s=0;s=n||o.height>=n)&&i(o,e[s+1])){a=s;break}}return a},o(e,[{key:"mediaWidth",get:function(){return this.getDimensions().width*this.contentScaleFactor}},{key:"mediaHeight",get:function(){return this.getDimensions().height*this.contentScaleFactor}},{key:"contentScaleFactor",get:function(){var e=1;if(!this.hls.config.ignoreDevicePixelRatio)try{e=self.devicePixelRatio}catch(e){}return e}}]),e}(),Hr=function(){function e(e){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=e,this.registerListeners()}var t=e.prototype;return t.setStreamController=function(e){this.streamController=e},t.registerListeners=function(){this.hls.on(R.MEDIA_ATTACHING,this.onMediaAttaching,this)},t.unregisterListeners=function(){this.hls.off(R.MEDIA_ATTACHING,this.onMediaAttaching,this)},t.destroy=function(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null},t.onMediaAttaching=function(e,t){var r=this.hls.config;if(r.capLevelOnFPSDrop){var i=t.media instanceof self.HTMLVideoElement?t.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)}},t.checkFPS=function(e,t,r){var i=performance.now();if(t){if(this.lastTime){var a=i-this.lastTime,n=r-this.lastDroppedFrames,s=t-this.lastDecodedFrames,o=1e3*n/a,l=this.hls;if(l.trigger(R.FPS_DROP,{currentDropped:n,currentDecoded:s,totalDroppedFrames:r}),o>0&&n>l.config.fpsDroppedMonitoringThreshold*s){var u=l.currentLevel;P.warn("drop FPS ratio greater than max allowed value for currentLevel: "+u),u>0&&(-1===l.autoLevelCapping||l.autoLevelCapping>=u)&&(u-=1,l.trigger(R.FPS_DROP_LEVEL_CAPPING,{level:u,droppedLevel:l.currentLevel}),l.autoLevelCapping=u,this.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=r,this.lastDecodedFrames=t}},t.checkFPSInterval=function(){var e=this.media;if(e)if(this.isVideoPlaybackQualityAvailable){var t=e.getVideoPlaybackQuality();this.checkFPS(e,t.totalVideoFrames,t.droppedVideoFrames)}else this.checkFPS(e,e.webkitDecodedFrameCount,e.webkitDroppedFrameCount)},e}(),Kr=3e5,Wr=function(){function e(e){this.hls=void 0,this.log=void 0,this.loader=null,this.uri=null,this.pathwayId=".",this.pathwayPriority=null,this.timeToLoad=300,this.reloadTimer=-1,this.updated=0,this.started=!1,this.enabled=!0,this.levels=null,this.audioTracks=null,this.subtitleTracks=null,this.penalizedPathways={},this.hls=e,this.log=P.log.bind(P,"[content-steering]:"),this.registerListeners()}var t=e.prototype;return t.registerListeners=function(){var e=this.hls;e.on(R.MANIFEST_LOADING,this.onManifestLoading,this),e.on(R.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(R.MANIFEST_PARSED,this.onManifestParsed,this),e.on(R.ERROR,this.onError,this)},t.unregisterListeners=function(){var e=this.hls;e&&(e.off(R.MANIFEST_LOADING,this.onManifestLoading,this),e.off(R.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(R.MANIFEST_PARSED,this.onManifestParsed,this),e.off(R.ERROR,this.onError,this))},t.startLoad=function(){if(this.started=!0,this.clearTimeout(),this.enabled&&this.uri){if(this.updated){var e=1e3*this.timeToLoad-(performance.now()-this.updated);if(e>0)return void this.scheduleRefresh(this.uri,e)}this.loadSteeringManifest(this.uri)}},t.stopLoad=function(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),this.clearTimeout()},t.clearTimeout=function(){-1!==this.reloadTimer&&(self.clearTimeout(this.reloadTimer),this.reloadTimer=-1)},t.destroy=function(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null},t.removeLevel=function(e){var t=this.levels;t&&(this.levels=t.filter((function(t){return t!==e})))},t.onManifestLoading=function(){this.stopLoad(),this.enabled=!0,this.timeToLoad=300,this.updated=0,this.uri=null,this.pathwayId=".",this.levels=this.audioTracks=this.subtitleTracks=null},t.onManifestLoaded=function(e,t){var r=t.contentSteering;null!==r&&(this.pathwayId=r.pathwayId,this.uri=r.uri,this.started&&this.startLoad())},t.onManifestParsed=function(e,t){this.audioTracks=t.audioTracks,this.subtitleTracks=t.subtitleTracks},t.onError=function(e,t){var r=t.errorAction;if((null==r?void 0:r.action)===Sr.SendAlternateToPenaltyBox&&r.flags===Lr.MoveAllAlternatesMatchingHost){var i=this.levels,a=this.pathwayPriority,n=this.pathwayId;if(t.context){var s=t.context,o=s.groupId,l=s.pathwayId,u=s.type;o&&i?n=this.getPathwayForGroupId(o,u,n):l&&(n=l)}n in this.penalizedPathways||(this.penalizedPathways[n]=performance.now()),!a&&i&&(a=i.reduce((function(e,t){return-1===e.indexOf(t.pathwayId)&&e.push(t.pathwayId),e}),[])),a&&a.length>1&&(this.updatePathwayPriority(a),r.resolved=this.pathwayId!==n),r.resolved||P.warn("Could not resolve "+t.details+' ("'+t.error.message+'") with content-steering for Pathway: '+n+" levels: "+(i?i.length:i)+" priorities: "+JSON.stringify(a)+" penalized: "+JSON.stringify(this.penalizedPathways))}},t.filterParsedLevels=function(e){this.levels=e;var t=this.getLevelsForPathway(this.pathwayId);if(0===t.length){var r=e[0].pathwayId;this.log("No levels found in Pathway "+this.pathwayId+'. Setting initial Pathway to "'+r+'"'),t=this.getLevelsForPathway(r),this.pathwayId=r}return t.length!==e.length?(this.log("Found "+t.length+"/"+e.length+' levels in Pathway "'+this.pathwayId+'"'),t):e},t.getLevelsForPathway=function(e){return null===this.levels?[]:this.levels.filter((function(t){return e===t.pathwayId}))},t.updatePathwayPriority=function(e){var t;this.pathwayPriority=e;var r=this.penalizedPathways,i=performance.now();Object.keys(r).forEach((function(e){i-r[e]>Kr&&delete r[e]}));for(var a=0;a0){this.log('Setting Pathway to "'+n+'"'),this.pathwayId=n,or(t),this.hls.trigger(R.LEVELS_UPDATED,{levels:t});var l=this.hls.levels[s];o&&l&&this.levels&&(l.attrs["STABLE-VARIANT-ID"]!==o.attrs["STABLE-VARIANT-ID"]&&l.bitrate!==o.bitrate&&this.log("Unstable Pathways change from bitrate "+o.bitrate+" to "+l.bitrate),this.hls.nextLoadLevel=s);break}}}},t.getPathwayForGroupId=function(e,t,r){for(var i=this.getLevelsForPathway(r).concat(this.levels||[]),a=0;a=2&&(0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start),a.timeout!==a.loadPolicy.maxLoadTimeMs&&(self.clearTimeout(this.requestTimeout),a.timeout=a.loadPolicy.maxLoadTimeMs,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),a.loadPolicy.maxLoadTimeMs-(r.loading.first-r.loading.start)))),4===i)){self.clearTimeout(this.requestTimeout),t.onreadystatechange=null,t.onprogress=null;var n=t.status,s="text"!==t.responseType;if(n>=200&&n<300&&(s&&t.response||null!==t.responseText)){r.loading.end=Math.max(self.performance.now(),r.loading.first);var o=s?t.response:t.responseText,l="arraybuffer"===t.responseType?o.byteLength:o.length;if(r.loaded=r.total=l,r.bwEstimate=8e3*r.total/(r.loading.end-r.loading.first),!this.callbacks)return;var u=this.callbacks.onProgress;if(u&&u(r,e,o,t),!this.callbacks)return;var d={url:t.responseURL,data:o,code:n};this.callbacks.onSuccess(d,r,e,t)}else{var h=a.loadPolicy.errorRetry;fr(h,r.retry,!1,{url:e.url,data:void 0,code:n})?this.retry(h):(P.error(n+" while loading "+e.url),this.callbacks.onError({code:n,text:t.statusText},e,t,r))}}}},t.loadtimeout=function(){if(this.config){var e=this.config.loadPolicy.timeoutRetry;if(fr(e,this.stats.retry,!0))this.retry(e);else{var t;P.warn("timeout while loading "+(null==(t=this.context)?void 0:t.url));var r=this.callbacks;r&&(this.abortInternal(),r.onTimeout(this.stats,this.context,this.loader))}}},t.retry=function(e){var t=this.context,r=this.stats;this.retryDelay=dr(e,r.retry),r.retry++,P.warn((status?"HTTP Status "+status:"Timeout")+" while loading "+(null==t?void 0:t.url)+", retrying "+r.retry+"/"+e.maxNumRetry+" in "+this.retryDelay+"ms"),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay)},t.loadprogress=function(e){var t=this.stats;t.loaded=e.loaded,e.lengthComputable&&(t.total=e.total)},t.getCacheAge=function(){var e=null;if(this.loader&&qr.test(this.loader.getAllResponseHeaders())){var t=this.loader.getResponseHeader("age");e=t?parseFloat(t):null}return e},t.getResponseHeader=function(e){return this.loader&&new RegExp("^"+e+":\\s*[\\d.]+\\s*$","im").test(this.loader.getAllResponseHeaders())?this.loader.getResponseHeader(e):null},e}(),Xr=function(){function e(){this.chunks=[],this.dataLength=0}var t=e.prototype;return t.push=function(e){this.chunks.push(e),this.dataLength+=e.length},t.flush=function(){var e,t=this.chunks,r=this.dataLength;return t.length?(e=1===t.length?t[0]:Qr(t,r),this.reset(),e):new Uint8Array(0)},t.reset=function(){this.chunks.length=0,this.dataLength=0},e}();function Qr(e,t){for(var r=new Uint8Array(t),i=0,a=0;a=i&&a(t,r,n.flush(),e)):a(t,r,l,e),o()})).catch((function(){return Promise.reject()}))}()},e}();function ei(e,t){var r={method:"GET",mode:"cors",credentials:"same-origin",signal:t,headers:new self.Headers(u({},e.headers))};return e.rangeEnd&&r.headers.set("Range","bytes="+e.rangeStart+"-"+String(e.rangeEnd-1)),r}function ti(e){var t=$r.exec(e);if(t)return parseInt(t[2])-parseInt(t[1])+1}function ri(e){var t=e.get("Content-Range");if(t){var r=ti(t);if(S(r))return r}var i=e.get("Content-Length");if(i)return parseInt(i)}function ii(e,t){return new self.Request(e.url,t)}var ai,ni=function(e){function t(t,r,i){var a;return(a=e.call(this,t)||this).code=void 0,a.details=void 0,a.code=r,a.details=i,a}return d(t,e),t}(m(Error)),si=i(i({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,preferManagedMediaSource:!0,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,frontBufferFlushThreshold:1/0,maxBufferSize:6e7,maxBufferHole:.1,highBufferWatchdogPeriod:2,nudgeOffset:.1,nudgeMaxRetry:3,maxFragLookUpTolerance:.25,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxLiveSyncPlaybackRate:1,liveDurationInfinity:!1,liveBackBufferLength:null,maxMaxBufferLength:600,enableWorker:!0,workerPath:null,enableSoftwareAES:!0,startLevel:void 0,startFragPrefetch:!1,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:3,loader:zr,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:Pr,bufferController:Br,capLevelController:Vr,errorController:Ar,fpsController:Hr,stretchShortVideoTrack:!1,maxAudioFramesDrift:1,forceKeyFrameOnDiscontinuity:!0,abrEwmaFastLive:3,abrEwmaSlowLive:9,abrEwmaFastVoD:3,abrEwmaSlowVoD:9,abrEwmaDefaultEstimate:5e5,abrEwmaDefaultEstimateMax:5e6,abrBandWidthFactor:.95,abrBandWidthUpFactor:.7,abrMaxWithRealBitrate:!1,maxStarvationDelay:4,maxLoadingDelay:4,minAutoBitrate:0,emeEnabled:!1,widevineLicenseUrl:void 0,drmSystems:{},drmSystemOptions:{},requestMediaKeySystemAccessFunc:null,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0,useMediaCapabilities:!1,certLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:null,errorRetry:null}},keyLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"},errorRetry:{maxNumRetry:8,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"}}},manifestLoadPolicy:{default:{maxTimeToFirstByteMs:1/0,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},playlistLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:2,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},fragLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:12e4,timeoutRetry:{maxNumRetry:4,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:6,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},steeringManifestLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,manifestLoadingMaxRetryTimeout:64e3,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,levelLoadingMaxRetryTimeout:64e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3},oi()),{},{subtitleStreamController:void 0,subtitleTrackController:void 0,timelineController:void 0,audioStreamController:void 0,audioTrackController:void 0,emeController:void 0,cmcdController:void 0,contentSteeringController:Wr});function oi(){return{cueHandler:q,enableWebVTT:!1,enableIMSC1:!1,enableCEA708Captions:!1,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}}function li(e,t){if((t.liveSyncDurationCount||t.liveMaxLatencyDurationCount)&&(t.liveSyncDuration||t.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==t.liveMaxLatencyDurationCount&&(void 0===t.liveSyncDurationCount||t.liveMaxLatencyDurationCount<=t.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(void 0!==t.liveMaxLatencyDuration&&(void 0===t.liveSyncDuration||t.liveMaxLatencyDuration<=t.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');var r=ui(e),a=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];return["manifest","level","frag"].forEach((function(e){var i=("level"===e?"playlist":e)+"LoadPolicy",n=void 0===t[i],s=[];a.forEach((function(a){var o=e+"Loading"+a,l=t[o];if(void 0!==l&&n){s.push(o);var u=r[i].default;switch(t[i]={default:u},a){case"TimeOut":u.maxLoadTimeMs=l,u.maxTimeToFirstByteMs=l;break;case"MaxRetry":u.errorRetry.maxNumRetry=l,u.timeoutRetry.maxNumRetry=l;break;case"RetryDelay":u.errorRetry.retryDelayMs=l,u.timeoutRetry.retryDelayMs=l;break;case"MaxRetryTimeout":u.errorRetry.maxRetryDelayMs=l,u.timeoutRetry.maxRetryDelayMs=l}}})),s.length&&P.warn('hls.js config: "'+s.join('", "')+'" setting(s) are deprecated, use "'+i+'": '+JSON.stringify(t[i]))})),i(i({},r),t)}function ui(e){return e&&"object"==typeof e?Array.isArray(e)?e.map(ui):Object.keys(e).reduce((function(t,r){return t[r]=ui(e[r]),t}),{}):e}function di(e){var t=e.loader;t!==Zr&&t!==zr?(P.log("[config]: Custom loader detected, cannot enable progressive streaming"),e.progressive=!1):Jr()&&(e.loader=Zr,e.progressive=!0,e.enableSoftwareAES=!0,P.log("[config]: Progressive streaming enabled, using FetchLoader"))}var hi=function(e){function t(t,r){var i;return(i=e.call(this,t,"[level-controller]")||this)._levels=[],i._firstLevel=-1,i._maxAutoLevel=-1,i._startLevel=void 0,i.currentLevel=null,i.currentLevelIndex=-1,i.manualLevelIndex=-1,i.steering=void 0,i.onParsedComplete=void 0,i.steering=r,i._registerListeners(),i}d(t,e);var r=t.prototype;return r._registerListeners=function(){var e=this.hls;e.on(R.MANIFEST_LOADING,this.onManifestLoading,this),e.on(R.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(R.LEVEL_LOADED,this.onLevelLoaded,this),e.on(R.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(R.FRAG_BUFFERED,this.onFragBuffered,this),e.on(R.ERROR,this.onError,this)},r._unregisterListeners=function(){var e=this.hls;e.off(R.MANIFEST_LOADING,this.onManifestLoading,this),e.off(R.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(R.LEVEL_LOADED,this.onLevelLoaded,this),e.off(R.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(R.FRAG_BUFFERED,this.onFragBuffered,this),e.off(R.ERROR,this.onError,this)},r.destroy=function(){this._unregisterListeners(),this.steering=null,this.resetLevels(),e.prototype.destroy.call(this)},r.stopLoad=function(){this._levels.forEach((function(e){e.loadError=0,e.fragmentError=0})),e.prototype.stopLoad.call(this)},r.resetLevels=function(){this._startLevel=void 0,this.manualLevelIndex=-1,this.currentLevelIndex=-1,this.currentLevel=null,this._levels=[],this._maxAutoLevel=-1},r.onManifestLoading=function(e,t){this.resetLevels()},r.onManifestLoaded=function(e,t){var r=this.hls.config.preferManagedMediaSource,i=[],a={},n={},s=!1,o=!1,l=!1;t.levels.forEach((function(e){var t,u,d=e.attrs,h=e.audioCodec,f=e.videoCodec;-1!==(null==(t=h)?void 0:t.indexOf("mp4a.40.34"))&&(ai||(ai=/chrome|firefox/i.test(navigator.userAgent)),ai&&(e.audioCodec=h=void 0)),h&&(e.audioCodec=h=at(h,r)),0===(null==(u=f)?void 0:u.indexOf("avc1"))&&(f=e.videoCodec=st(f));var c=e.width,v=e.height,g=e.unknownCodecs;if(s||(s=!(!c||!v)),o||(o=!!f),l||(l=!!h),!(null!=g&&g.length||h&&!Qe(h,"audio",r)||f&&!Qe(f,"video",r))){var m=d.CODECS,p=d["FRAME-RATE"],y=d["HDCP-LEVEL"],E=d["PATHWAY-ID"],T=d.RESOLUTION,S=d["VIDEO-RANGE"],L=(E||".")+"-"+e.bitrate+"-"+T+"-"+p+"-"+m+"-"+S+"-"+y;if(a[L])if(a[L].uri===e.url||e.attrs["PATHWAY-ID"])a[L].addGroupId("audio",d.AUDIO),a[L].addGroupId("text",d.SUBTITLES);else{var A=n[L]+=1;e.attrs["PATHWAY-ID"]=new Array(A+1).join(".");var R=new qt(e);a[L]=R,i.push(R)}else{var b=new qt(e);a[L]=b,n[L]=1,i.push(b)}}})),this.filterAndSortMediaOptions(i,t,s,o,l)},r.filterAndSortMediaOptions=function(e,t,r,i,a){var n=this,s=[],o=[],l=e;if((r||i)&&a&&(l=l.filter((function(e){var t=e.videoCodec,r=e.videoRange,i=e.width,a=e.height;return(!!t||!(!i||!a))&&Kt(r)}))),0!==l.length){if(t.audioTracks){var u=this.hls.config.preferManagedMediaSource;fi(s=t.audioTracks.filter((function(e){return!e.audioCodec||Qe(e.audioCodec,"audio",u)})))}t.subtitles&&fi(o=t.subtitles);var d=l.slice(0);l.sort((function(e,t){if(e.attrs["HDCP-LEVEL"]!==t.attrs["HDCP-LEVEL"])return(e.attrs["HDCP-LEVEL"]||"")>(t.attrs["HDCP-LEVEL"]||"")?1:-1;if(r&&e.height!==t.height)return e.height-t.height;if(e.frameRate!==t.frameRate)return e.frameRate-t.frameRate;if(e.videoRange!==t.videoRange)return Ht.indexOf(e.videoRange)-Ht.indexOf(t.videoRange);if(e.videoCodec!==t.videoCodec){var i=Ze(e.videoCodec),a=Ze(t.videoCodec);if(i!==a)return a-i}if(e.uri===t.uri&&e.codecSet!==t.codecSet){var n=et(e.codecSet),s=et(t.codecSet);if(n!==s)return s-n}return e.averageBitrate!==t.averageBitrate?e.averageBitrate-t.averageBitrate:0}));var h=d[0];if(this.steering&&(l=this.steering.filterParsedLevels(l)).length!==d.length)for(var f=0;fm&&m===si.abrEwmaDefaultEstimate&&(this.hls.bandwidthEstimate=p)}break}var y=a&&!i,E={levels:l,audioTracks:s,subtitleTracks:o,sessionData:t.sessionData,sessionKeys:t.sessionKeys,firstLevel:this._firstLevel,stats:t.stats,audio:a,video:i,altAudio:!y&&s.some((function(e){return!!e.url}))};this.hls.trigger(R.MANIFEST_PARSED,E),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}else Promise.resolve().then((function(){if(n.hls){t.levels.length&&n.warn("One or more CODECS in variant not supported: "+JSON.stringify(t.levels[0].attrs));var e=new Error("no level with compatible codecs found in manifest");n.hls.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:t.url,error:e,reason:e.message})}}))},r.onError=function(e,t){!t.fatal&&t.context&&t.context.type===St.LEVEL&&t.context.level===this.level&&this.checkRetry(t)},r.onFragBuffered=function(e,t){var r=t.frag;if(void 0!==r&&r.type===Lt.MAIN){var i=r.elementaryStreams;if(!Object.keys(i).some((function(e){return!!i[e]})))return;var a=this._levels[r.level];null!=a&&a.loadError&&(this.log("Resetting level error count of "+a.loadError+" on frag buffered"),a.loadError=0)}},r.onLevelLoaded=function(e,t){var r,i,a=t.level,n=t.details,s=this._levels[a];if(!s)return this.warn("Invalid level index "+a),void(null!=(i=t.deliveryDirectives)&&i.skip&&(n.deltaUpdateFailed=!0));a===this.currentLevelIndex?(0===s.fragmentError&&(s.loadError=0),this.playlistLoaded(a,t,s.details)):null!=(r=t.deliveryDirectives)&&r.skip&&(n.deltaUpdateFailed=!0)},r.loadPlaylist=function(t){e.prototype.loadPlaylist.call(this);var r=this.currentLevelIndex,i=this.currentLevel;if(i&&this.shouldLoadPlaylist(i)){var a=i.uri;if(t)try{a=t.addDirectives(a)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: "+e)}var n=i.attrs["PATHWAY-ID"];this.log("Loading level index "+r+(void 0!==(null==t?void 0:t.msn)?" at sn "+t.msn+" part "+t.part:"")+" with"+(n?" Pathway "+n:"")+" "+a),this.clearTimer(),this.hls.trigger(R.LEVEL_LOADING,{url:a,level:r,pathwayId:i.attrs["PATHWAY-ID"],id:0,deliveryDirectives:t||null})}},r.removeLevel=function(e){var t,r=this,i=this._levels.filter((function(t,i){return i!==e||(r.steering&&r.steering.removeLevel(t),t===r.currentLevel&&(r.currentLevel=null,r.currentLevelIndex=-1,t.details&&t.details.fragments.forEach((function(e){return e.level=-1}))),!1)}));or(i),this._levels=i,this.currentLevelIndex>-1&&null!=(t=this.currentLevel)&&t.details&&(this.currentLevelIndex=this.currentLevel.details.fragments[0].level),this.hls.trigger(R.LEVELS_UPDATED,{levels:i})},r.onLevelsUpdated=function(e,t){var r=t.levels;this._levels=r},r.checkMaxAutoUpdated=function(){var e=this.hls,t=e.autoLevelCapping,r=e.maxAutoLevel,i=e.maxHdcpLevel;this._maxAutoLevel!==r&&(this._maxAutoLevel=r,this.hls.trigger(R.MAX_AUTO_LEVEL_UPDATED,{autoLevelCapping:t,levels:this.levels,maxAutoLevel:r,minAutoLevel:this.hls.minAutoLevel,maxHdcpLevel:i}))},o(t,[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(e){var t=this._levels;if(0!==t.length){if(e<0||e>=t.length){var r=new Error("invalid level idx"),i=e<0;if(this.hls.trigger(R.ERROR,{type:b.OTHER_ERROR,details:D.LEVEL_SWITCH_ERROR,level:e,fatal:i,error:r,reason:r.message}),i)return;e=Math.min(e,t.length-1)}var a=this.currentLevelIndex,n=this.currentLevel,s=n?n.attrs["PATHWAY-ID"]:void 0,o=t[e],l=o.attrs["PATHWAY-ID"];if(this.currentLevelIndex=e,this.currentLevel=o,a!==e||!o.details||!n||s!==l){this.log("Switching to level "+e+" ("+(o.height?o.height+"p ":"")+(o.videoRange?o.videoRange+" ":"")+(o.codecSet?o.codecSet+" ":"")+"@"+o.bitrate+")"+(l?" with Pathway "+l:"")+" from level "+a+(s?" with Pathway "+s:""));var u={level:e,attrs:o.attrs,details:o.details,bitrate:o.bitrate,averageBitrate:o.averageBitrate,maxBitrate:o.maxBitrate,realBitrate:o.realBitrate,width:o.width,height:o.height,codecSet:o.codecSet,audioCodec:o.audioCodec,videoCodec:o.videoCodec,audioGroups:o.audioGroups,subtitleGroups:o.subtitleGroups,loaded:o.loaded,loadError:o.loadError,fragmentError:o.fragmentError,name:o.name,id:o.id,uri:o.uri,url:o.url,urlId:0,audioGroupIds:o.audioGroupIds,textGroupIds:o.textGroupIds};this.hls.trigger(R.LEVEL_SWITCHING,u);var d=o.details;if(!d||d.live){var h=this.switchParams(o.uri,null==n?void 0:n.details,d);this.loadPlaylist(h)}}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(e){this.manualLevelIndex=e,void 0===this._startLevel&&(this._startLevel=e),-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var e=this.hls.config.startLevel;return void 0!==e?e:this.hls.firstAutoLevel}return this._startLevel},set:function(e){this._startLevel=e}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(e){this.level=e,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=e)}}]),t}(Rr);function fi(e){var t={};e.forEach((function(e){var r=e.groupId||"";e.id=t[r]=t[r]||0,t[r]++}))}var ci={NOT_LOADED:"NOT_LOADED",APPENDING:"APPENDING",PARTIAL:"PARTIAL",OK:"OK"},vi=function(){function e(e){this.activePartLists=Object.create(null),this.endListFragments=Object.create(null),this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hasGaps=!1,this.hls=e,this._registerListeners()}var t=e.prototype;return t._registerListeners=function(){var e=this.hls;e.on(R.BUFFER_APPENDED,this.onBufferAppended,this),e.on(R.FRAG_BUFFERED,this.onFragBuffered,this),e.on(R.FRAG_LOADED,this.onFragLoaded,this)},t._unregisterListeners=function(){var e=this.hls;e.off(R.BUFFER_APPENDED,this.onBufferAppended,this),e.off(R.FRAG_BUFFERED,this.onFragBuffered,this),e.off(R.FRAG_LOADED,this.onFragLoaded,this)},t.destroy=function(){this._unregisterListeners(),this.fragments=this.activePartLists=this.endListFragments=this.timeRanges=null},t.getAppendedFrag=function(e,t){var r=this.activePartLists[t];if(r)for(var i=r.length;i--;){var a=r[i];if(!a)break;var n=a.end;if(a.start<=e&&null!==n&&e<=n)return a}return this.getBufferedFrag(e,t)},t.getBufferedFrag=function(e,t){for(var r=this.fragments,i=Object.keys(r),a=i.length;a--;){var n=r[i[a]];if((null==n?void 0:n.body.type)===t&&n.buffered){var s=n.body;if(s.start<=e&&e<=s.end)return s}}return null},t.detectEvictedFragments=function(e,t,r,i){var a=this;this.timeRanges&&(this.timeRanges[e]=t);var n=(null==i?void 0:i.fragment.sn)||-1;Object.keys(this.fragments).forEach((function(i){var s=a.fragments[i];if(s&&!(n>=s.body.sn))if(s.buffered||s.loaded){var o=s.range[e];o&&o.time.some((function(e){var r=!a.isTimeBuffered(e.startPTS,e.endPTS,t);return r&&a.removeFragment(s.body),r}))}else s.body.type===r&&a.removeFragment(s.body)}))},t.detectPartialFragments=function(e){var t=this,r=this.timeRanges,i=e.frag,a=e.part;if(r&&"initSegment"!==i.sn){var n=mi(i),s=this.fragments[n];if(!(!s||s.buffered&&i.gap)){var o=!i.relurl;Object.keys(r).forEach((function(e){var n=i.elementaryStreams[e];if(n){var l=r[e],u=o||!0===n.partial;s.range[e]=t.getBufferedTimes(i,a,u,l)}})),s.loaded=null,Object.keys(s.range).length?(s.buffered=!0,(s.body.endList=i.endList||s.body.endList)&&(this.endListFragments[s.body.type]=s),gi(s)||this.removeParts(i.sn-1,i.type)):this.removeFragment(s.body)}}},t.removeParts=function(e,t){var r=this.activePartLists[t];r&&(this.activePartLists[t]=r.filter((function(t){return t.fragment.sn>=e})))},t.fragBuffered=function(e,t){var r=mi(e),i=this.fragments[r];!i&&t&&(i=this.fragments[r]={body:e,appendedPTS:null,loaded:null,buffered:!1,range:Object.create(null)},e.gap&&(this.hasGaps=!0)),i&&(i.loaded=null,i.buffered=!0)},t.getBufferedTimes=function(e,t,r,i){for(var a={time:[],partial:r},n=e.start,s=e.end,o=e.minEndPTS||s,l=e.maxStartPTS||n,u=0;u=d&&o<=h){a.time.push({startPTS:Math.max(n,i.start(u)),endPTS:Math.min(s,i.end(u))});break}if(nd){var f=Math.max(n,i.start(u)),c=Math.min(s,i.end(u));c>f&&(a.partial=!0,a.time.push({startPTS:f,endPTS:c}))}else if(s<=d)break}return a},t.getPartialFragment=function(e){var t,r,i,a=null,n=0,s=this.bufferPadding,o=this.fragments;return Object.keys(o).forEach((function(l){var u=o[l];u&&gi(u)&&(r=u.body.start-s,i=u.body.end+s,e>=r&&e<=i&&(t=Math.min(e-r,i-e),n<=t&&(a=u.body,n=t)))})),a},t.isEndListAppended=function(e){var t=this.endListFragments[e];return void 0!==t&&(t.buffered||gi(t))},t.getState=function(e){var t=mi(e),r=this.fragments[t];return r?r.buffered?gi(r)?ci.PARTIAL:ci.OK:ci.APPENDING:ci.NOT_LOADED},t.isTimeBuffered=function(e,t,r){for(var i,a,n=0;n=i&&t<=a)return!0;if(t<=i)return!1}return!1},t.onFragLoaded=function(e,t){var r=t.frag,i=t.part;if("initSegment"!==r.sn&&!r.bitrateTest){var a=i?null:t,n=mi(r);this.fragments[n]={body:r,appendedPTS:null,loaded:a,buffered:!1,range:Object.create(null)}}},t.onBufferAppended=function(e,t){var r=this,i=t.frag,a=t.part,n=t.timeRanges;if("initSegment"!==i.sn){var s=i.type;if(a){var o=this.activePartLists[s];o||(this.activePartLists[s]=o=[]),o.push(a)}this.timeRanges=n,Object.keys(n).forEach((function(e){var t=n[e];r.detectEvictedFragments(e,t,s,a)}))}},t.onFragBuffered=function(e,t){this.detectPartialFragments(t)},t.hasFragment=function(e){var t=mi(e);return!!this.fragments[t]},t.hasParts=function(e){var t;return!(null==(t=this.activePartLists[e])||!t.length)},t.removeFragmentsInRange=function(e,t,r,i,a){var n=this;i&&!this.hasGaps||Object.keys(this.fragments).forEach((function(s){var o=n.fragments[s];if(o){var l=o.body;l.type!==r||i&&!l.gap||l.starte&&(o.buffered||a)&&n.removeFragment(l)}}))},t.removeFragment=function(e){var t=mi(e);e.stats.loaded=0,e.clearElementaryStreamInfo();var r=this.activePartLists[e.type];if(r){var i=e.sn;this.activePartLists[e.type]=r.filter((function(e){return e.fragment.sn!==i}))}delete this.fragments[t],e.endList&&delete this.endListFragments[e.type]},t.removeAllFragments=function(){this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activePartLists=Object.create(null),this.hasGaps=!1},e}();function gi(e){var t,r,i;return e.buffered&&(e.body.gap||(null==(t=e.range.video)?void 0:t.partial)||(null==(r=e.range.audio)?void 0:r.partial)||(null==(i=e.range.audiovideo)?void 0:i.partial))}function mi(e){return e.type+"_"+e.level+"_"+e.sn}var pi=Math.pow(2,17),yi=function(){function e(e){this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=e}var t=e.prototype;return t.destroy=function(){this.loader&&(this.loader.destroy(),this.loader=null)},t.abort=function(){this.loader&&this.loader.abort()},t.load=function(e,t){var r=this,a=e.url;if(!a)return Promise.reject(new Si({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_ERROR,fatal:!1,frag:e,error:new Error("Fragment does not have a "+(a?"part list":"url")),networkDetails:null}));this.abort();var n=this.config,s=n.fLoader,o=n.loader;return new Promise((function(l,u){if(r.loader&&r.loader.destroy(),e.gap){if(e.tagList.some((function(e){return"GAP"===e[0]})))return void u(Ti(e));e.gap=!1}var d=r.loader=e.loader=s?new s(n):new o(n),h=Ei(e),f=hr(n.fragLoadPolicy.default),c={loadPolicy:f,timeout:f.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:"initSegment"===e.sn?1/0:pi};e.stats=d.stats,d.load(h,c,{onSuccess:function(t,i,a,n){r.resetLoader(e,d);var s=t.data;a.resetIV&&e.decryptdata&&(e.decryptdata.iv=new Uint8Array(s.slice(0,16)),s=s.slice(16)),l({frag:e,part:null,payload:s,networkDetails:n})},onError:function(t,n,s,o){r.resetLoader(e,d),u(new Si({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_ERROR,fatal:!1,frag:e,response:i({url:a,data:void 0},t),error:new Error("HTTP Error "+t.code+" "+t.text),networkDetails:s,stats:o}))},onAbort:function(t,i,a){r.resetLoader(e,d),u(new Si({type:b.NETWORK_ERROR,details:D.INTERNAL_ABORTED,fatal:!1,frag:e,error:new Error("Aborted"),networkDetails:a,stats:t}))},onTimeout:function(t,i,a){r.resetLoader(e,d),u(new Si({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,error:new Error("Timeout after "+c.timeout+"ms"),networkDetails:a,stats:t}))},onProgress:function(r,i,a,n){t&&t({frag:e,part:null,payload:a,networkDetails:n})}})}))},t.loadPart=function(e,t,r){var a=this;this.abort();var n=this.config,s=n.fLoader,o=n.loader;return new Promise((function(l,u){if(a.loader&&a.loader.destroy(),e.gap||t.gap)u(Ti(e,t));else{var d=a.loader=e.loader=s?new s(n):new o(n),h=Ei(e,t),f=hr(n.fragLoadPolicy.default),c={loadPolicy:f,timeout:f.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:pi};t.stats=d.stats,d.load(h,c,{onSuccess:function(i,n,s,o){a.resetLoader(e,d),a.updateStatsFromPart(e,t);var u={frag:e,part:t,payload:i.data,networkDetails:o};r(u),l(u)},onError:function(r,n,s,o){a.resetLoader(e,d),u(new Si({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_ERROR,fatal:!1,frag:e,part:t,response:i({url:h.url,data:void 0},r),error:new Error("HTTP Error "+r.code+" "+r.text),networkDetails:s,stats:o}))},onAbort:function(r,i,n){e.stats.aborted=t.stats.aborted,a.resetLoader(e,d),u(new Si({type:b.NETWORK_ERROR,details:D.INTERNAL_ABORTED,fatal:!1,frag:e,part:t,error:new Error("Aborted"),networkDetails:n,stats:r}))},onTimeout:function(r,i,n){a.resetLoader(e,d),u(new Si({type:b.NETWORK_ERROR,details:D.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,part:t,error:new Error("Timeout after "+c.timeout+"ms"),networkDetails:n,stats:r}))}})}}))},t.updateStatsFromPart=function(e,t){var r=e.stats,i=t.stats,a=i.total;if(r.loaded+=i.loaded,a){var n=Math.round(e.duration/t.duration),s=Math.min(Math.round(r.loaded/a),n),o=(n-s)*Math.round(r.loaded/s);r.total=r.loaded+o}else r.total=Math.max(r.loaded,r.total);var l=r.loading,u=i.loading;l.start?l.first+=u.first-u.start:(l.start=u.start,l.first=u.first),l.end=u.end},t.resetLoader=function(e,t){e.loader=null,this.loader===t&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),t.destroy()},e}();function Ei(e,t){void 0===t&&(t=null);var r=t||e,i={frag:e,part:t,responseType:"arraybuffer",url:r.url,headers:{},rangeStart:0,rangeEnd:0},a=r.byteRangeStartOffset,n=r.byteRangeEndOffset;if(S(a)&&S(n)){var s,o=a,l=n;if("initSegment"===e.sn&&"AES-128"===(null==(s=e.decryptdata)?void 0:s.method)){var u=n-a;u%16&&(l=n+(16-u%16)),0!==a&&(i.resetIV=!0,o=a-16)}i.rangeStart=o,i.rangeEnd=l}return i}function Ti(e,t){var r=new Error("GAP "+(e.gap?"tag":"attribute")+" found"),i={type:b.MEDIA_ERROR,details:D.FRAG_GAP,fatal:!1,frag:e,error:r,networkDetails:null};return t&&(i.part=t),(t||e).stats.aborted=!0,new Si(i)}var Si=function(e){function t(t){var r;return(r=e.call(this,t.error.message)||this).data=void 0,r.data=t,r}return d(t,e),t}(m(Error)),Li=function(){function e(e){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=e}var t=e.prototype;return t.abort=function(e){for(var t in this.keyUriToKeyInfo){var r=this.keyUriToKeyInfo[t].loader;if(r){var i;if(e&&e!==(null==(i=r.context)?void 0:i.frag.type))return;r.abort()}}},t.detach=function(){for(var e in this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e];(t.mediaKeySessionContext||t.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[e]}},t.destroy=function(){for(var e in this.detach(),this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e].loader;t&&t.destroy()}this.keyUriToKeyInfo={}},t.createKeyLoadError=function(e,t,r,i,a){return void 0===t&&(t=D.KEY_LOAD_ERROR),new Si({type:b.NETWORK_ERROR,details:t,fatal:!1,frag:e,response:a,error:r,networkDetails:i})},t.loadClear=function(e,t){var r=this;if(this.emeController&&this.config.emeEnabled)for(var i=e.sn,a=e.cc,n=function(){var e=t[s];if(a<=e.cc&&("initSegment"===i||"initSegment"===e.sn||i1&&this.tickImmediate(),this._tickCallCount=0)},t.tickImmediate=function(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)},t.doTick=function(){},e}(),Ri=function(e,t,r,i,a,n){void 0===i&&(i=0),void 0===a&&(a=-1),void 0===n&&(n=!1),this.level=void 0,this.sn=void 0,this.part=void 0,this.id=void 0,this.size=void 0,this.partial=void 0,this.transmuxing=bi(),this.buffering={audio:bi(),video:bi(),audiovideo:bi()},this.level=e,this.sn=t,this.id=r,this.size=i,this.part=a,this.partial=n};function bi(){return{start:0,executeStart:0,executeEnd:0,end:0}}function Di(e,t){for(var r=0,i=e.length;rr.startCC||e&&e.cc>>8^255&m^99,e[c]=m,t[m]=c;var p=f[c],y=f[p],E=f[y],T=257*f[m]^16843008*m;i[c]=T<<24|T>>>8,a[c]=T<<16|T>>>16,n[c]=T<<8|T>>>24,s[c]=T,T=16843009*E^65537*y^257*p^16843008*c,l[m]=T<<24|T>>>8,u[m]=T<<16|T>>>16,d[m]=T<<8|T>>>24,h[m]=T,c?(c=p^f[f[f[E^p]]],v^=f[f[v]]):c=v=1}},t.expandKey=function(e){for(var t=this.uint8ArrayToUint32Array_(e),r=!0,i=0;is.end){var d=n>u;(n0&&null!=n&&n.key&&n.iv&&"AES-128"===n.method){var s=self.performance.now();return r.decrypter.decrypt(new Uint8Array(a),n.key.buffer,n.iv.buffer).catch((function(t){throw i.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_DECRYPT_ERROR,fatal:!1,error:t,reason:t.message,frag:e}),t})).then((function(a){var n=self.performance.now();return i.trigger(R.FRAG_DECRYPTED,{frag:e,payload:a,stats:{tstart:s,tdecrypt:n}}),t.payload=a,r.completeInitSegmentLoad(t)}))}return r.completeInitSegmentLoad(t)})).catch((function(t){r.state!==Vi.STOPPED&&r.state!==Vi.ERROR&&(r.warn(t),r.resetFragmentLoading(e))}))},r.completeInitSegmentLoad=function(e){if(!this.levels)throw new Error("init load aborted, missing levels");var t=e.frag.stats;this.state=Vi.IDLE,e.frag.data=new Uint8Array(e.payload),t.parsing.start=t.buffering.start=self.performance.now(),t.parsing.end=t.buffering.end=self.performance.now(),this.tick()},r.fragContextChanged=function(e){var t=this.fragCurrent;return!e||!t||e.sn!==t.sn||e.level!==t.level},r.fragBufferedComplete=function(e,t){var r,i,a,n,s=this.mediaBuffer?this.mediaBuffer:this.media;if(this.log("Buffered "+e.type+" sn: "+e.sn+(t?" part: "+t.index:"")+" of "+(this.playlistType===Lt.MAIN?"level":"track")+" "+e.level+" (frag:["+(null!=(r=e.startPTS)?r:NaN).toFixed(3)+"-"+(null!=(i=e.endPTS)?i:NaN).toFixed(3)+"] > buffer:"+(s?Gi.toString(Fr.getBuffered(s)):"(detached)")+")"),"initSegment"!==e.sn){var o;if(e.type!==Lt.SUBTITLE){var l=e.elementaryStreams;if(!Object.keys(l).some((function(e){return!!l[e]})))return void(this.state=Vi.IDLE)}var u=null==(o=this.levels)?void 0:o[e.level];null!=u&&u.fragmentError&&(this.log("Resetting level fragment error count of "+u.fragmentError+" on frag buffered"),u.fragmentError=0)}this.state=Vi.IDLE,s&&(!this.loadedmetadata&&e.type==Lt.MAIN&&s.buffered.length&&(null==(a=this.fragCurrent)?void 0:a.sn)===(null==(n=this.fragPrevious)?void 0:n.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())},r.seekToStartPos=function(){},r._handleFragmentLoadComplete=function(e){var t=this.transmuxer;if(t){var r=e.frag,i=e.part,a=e.partsLoaded,n=!a||0===a.length||a.some((function(e){return!e})),s=new Ri(r.level,r.sn,r.stats.chunkCount+1,0,i?i.index:-1,!n);t.flush(s)}},r._handleFragmentLoadProgress=function(e){},r._doFragLoad=function(e,t,r,i){var a,n=this;void 0===r&&(r=null);var s=null==t?void 0:t.details;if(!this.levels||!s)throw new Error("frag load aborted, missing level"+(s?"":" detail")+"s");var o=null;if(!e.encrypted||null!=(a=e.decryptdata)&&a.key?!e.encrypted&&s.encryptedFragments.length&&this.keyLoader.loadClear(e,s.encryptedFragments):(this.log("Loading key for "+e.sn+" of ["+s.startSN+"-"+s.endSN+"], "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+e.level),this.state=Vi.KEY_LOADING,this.fragCurrent=e,o=this.keyLoader.load(e).then((function(e){if(!n.fragContextChanged(e.frag))return n.hls.trigger(R.KEY_LOADED,e),n.state===Vi.KEY_LOADING&&(n.state=Vi.IDLE),e})),this.hls.trigger(R.KEY_LOADING,{frag:e}),null===this.fragCurrent&&(o=Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING")))),r=Math.max(e.start,r||0),this.config.lowLatencyMode&&"initSegment"!==e.sn){var l=s.partList;if(l&&i){r>e.end&&s.fragmentHint&&(e=s.fragmentHint);var u=this.getNextPart(l,e,r);if(u>-1){var d,h=l[u];return this.log("Loading part sn: "+e.sn+" p: "+h.index+" cc: "+e.cc+" of playlist ["+s.startSN+"-"+s.endSN+"] parts [0-"+u+"-"+(l.length-1)+"] "+("[stream-controller]"===this.logPrefix?"level":"track")+": "+e.level+", target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=h.start+h.duration,this.state=Vi.FRAG_LOADING,d=o?o.then((function(r){return!r||n.fragContextChanged(r.frag)?null:n.doFragPartsLoad(e,h,t,i)})).catch((function(e){return n.handleFragLoadError(e)})):this.doFragPartsLoad(e,h,t,i).catch((function(e){return n.handleFragLoadError(e)})),this.hls.trigger(R.FRAG_LOADING,{frag:e,part:h,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):d}if(!e.url||this.loadedEndOfParts(l,r))return Promise.resolve(null)}}this.log("Loading fragment "+e.sn+" cc: "+e.cc+" "+(s?"of ["+s.startSN+"-"+s.endSN+"] ":"")+("[stream-controller]"===this.logPrefix?"level":"track")+": "+e.level+", target: "+parseFloat(r.toFixed(3))),S(e.sn)&&!this.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),this.state=Vi.FRAG_LOADING;var f,c=this.config.progressive;return f=c&&o?o.then((function(t){return!t||n.fragContextChanged(null==t?void 0:t.frag)?null:n.fragmentLoader.load(e,i)})).catch((function(e){return n.handleFragLoadError(e)})):Promise.all([this.fragmentLoader.load(e,c?i:void 0),o]).then((function(e){var t=e[0];return!c&&t&&i&&i(t),t})).catch((function(e){return n.handleFragLoadError(e)})),this.hls.trigger(R.FRAG_LOADING,{frag:e,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):f},r.doFragPartsLoad=function(e,t,r,i){var a=this;return new Promise((function(n,s){var o,l=[],u=null==(o=r.details)?void 0:o.partList;!function t(o){a.fragmentLoader.loadPart(e,o,i).then((function(i){l[o.index]=i;var s=i.part;a.hls.trigger(R.FRAG_LOADED,i);var d=nr(r,e.sn,o.index+1)||sr(u,e.sn,o.index+1);if(!d)return n({frag:e,part:s,partsLoaded:l});t(d)})).catch(s)}(t)}))},r.handleFragLoadError=function(e){if("data"in e){var t=e.data;e.data&&t.details===D.INTERNAL_ABORTED?this.handleFragLoadAborted(t.frag,t.part):this.hls.trigger(R.ERROR,t)}else this.hls.trigger(R.ERROR,{type:b.OTHER_ERROR,details:D.INTERNAL_EXCEPTION,err:e,error:e,fatal:!0});return null},r._handleTransmuxerFlush=function(e){var t=this.getCurrentContext(e);if(t&&this.state===Vi.PARSING){var r=t.frag,i=t.part,a=t.level,n=self.performance.now();r.stats.parsing.end=n,i&&(i.stats.parsing.end=n),this.updateLevelTiming(r,i,a,e.partial)}else this.fragCurrent||this.state===Vi.STOPPED||this.state===Vi.ERROR||(this.state=Vi.IDLE)},r.getCurrentContext=function(e){var t=this.levels,r=this.fragCurrent,i=e.level,a=e.sn,n=e.part;if(null==t||!t[i])return this.warn("Levels object was unset while buffering fragment "+a+" of level "+i+". The current chunk will not be buffered."),null;var s=t[i],o=n>-1?nr(s,a,n):null,l=o?o.fragment:ar(s,a,r);return l?(r&&r!==l&&(l.stats=r.stats),{frag:l,part:o,level:s}):null},r.bufferFragmentData=function(e,t,r,i,a){var n;if(e&&this.state===Vi.PARSING){var s=e.data1,o=e.data2,l=s;if(s&&o&&(l=Ne(s,o)),null!=(n=l)&&n.length){var u={type:e.type,frag:t,part:r,chunkMeta:i,parent:t.type,data:l};if(this.hls.trigger(R.BUFFER_APPENDING,u),e.dropped&&e.independent&&!r){if(a)return;this.flushBufferGap(t)}}}},r.flushBufferGap=function(e){var t=this.media;if(t)if(Fr.isBuffered(t,t.currentTime)){var r=t.currentTime,i=Fr.bufferInfo(t,r,0),a=e.duration,n=Math.min(2*this.config.maxFragLookUpTolerance,.25*a),s=Math.max(Math.min(e.start-n,i.end-n),r+n);e.start-s>n&&this.flushMainBuffer(s,e.start)}else this.flushMainBuffer(0,e.start)},r.getFwdBufferInfo=function(e,t){var r=this.getLoadPosition();return S(r)?this.getFwdBufferInfoAtPos(e,r,t):null},r.getFwdBufferInfoAtPos=function(e,t,r){var i=this.config.maxBufferHole,a=Fr.bufferInfo(e,t,i);if(0===a.len&&void 0!==a.nextStart){var n=this.fragmentTracker.getBufferedFrag(t,r);if(n&&a.nextStart=i&&(r.maxMaxBufferLength=a,this.warn("Reduce max buffer length to "+a+"s"),!0)},r.getAppendedFrag=function(e,t){var r=this.fragmentTracker.getAppendedFrag(e,Lt.MAIN);return r&&"fragment"in r?r.fragment:r},r.getNextFragment=function(e,t){var r=t.fragments,i=r.length;if(!i)return null;var a,n=this.config,s=r[0].start;if(t.live){var o=n.initialLiveManifestSize;if(it},r.getNextFragmentLoopLoading=function(e,t,r,i,a){var n=e.gap,s=this.getNextFragment(this.nextLoadPosition,t);if(null===s)return s;if(e=s,n&&e&&!e.gap&&r.nextStart){var o=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,r.nextStart,i);if(null!==o&&r.len+o.len>=a)return this.log('buffer full after gaps in "'+i+'" playlist starting at sn: '+e.sn),null}return e},r.mapToInitFragWhenRequired=function(e){return null==e||!e.initSegment||null!=e&&e.initSegment.data||this.bitrateTest?e:e.initSegment},r.getNextPart=function(e,t,r){for(var i=-1,a=!1,n=!0,s=0,o=e.length;s-1&&rr.start&&r.loaded},r.getInitialLiveFragment=function(e,t){var r=this.fragPrevious,i=null;if(r){if(e.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: "+r.programDateTime),i=gr(t,r.endProgramDateTime,this.config.maxFragLookUpTolerance)),!i){var a=r.sn+1;if(a>=e.startSN&&a<=e.endSN){var n=t[a-e.startSN];r.cc===n.cc&&(i=n,this.log("Live playlist, switching playlist, load frag with next SN: "+i.sn))}i||(i=Tr(t,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?e.fragmentEnd:e.edge,e))}return i},r.getFragmentAtPosition=function(e,t,r){var i,a=this.config,n=this.fragPrevious,s=r.fragments,o=r.endSN,l=r.fragmentHint,u=a.maxFragLookUpTolerance,d=r.partList,h=!!(a.lowLatencyMode&&null!=d&&d.length&&l);if(h&&l&&!this.bitrateTest&&(s=s.concat(l),o=l.sn),i=et-u?0:u):s[s.length-1]){var f=i.sn-r.startSN,c=this.fragmentTracker.getState(i);if((c===ci.OK||c===ci.PARTIAL&&i.gap)&&(n=i),n&&i.sn===n.sn&&(!h||d[0].fragment.sn>i.sn)&&n&&i.level===n.level){var v=s[f+1];i=i.sn=n-t.maxFragLookUpTolerance&&a<=s;if(null!==i&&r.duration>i&&(a"+e.startSN+" prev-sn: "+(o?o.sn:"na")+" fragments: "+i),l}return a},r.waitForCdnTuneIn=function(e){var t=3;return e.live&&e.canBlockReload&&e.partTarget&&e.tuneInGoal>Math.max(e.partHoldBack,e.partTarget*t)},r.setStartPosition=function(e,t){var r=this.startPosition;if(r "+(null==(a=this.fragCurrent)?void 0:a.url))}else{var n=t.details===D.FRAG_GAP;n&&this.fragmentTracker.fragBuffered(i,!0);var s=t.errorAction,o=s||{},l=o.action,u=o.retryCount,d=void 0===u?0:u,h=o.retryConfig;if(s&&l===Sr.RetryRequest&&h){this.resetStartWhenNotLoaded(this.levelLastLoaded);var f=dr(h,d);this.warn("Fragment "+i.sn+" of "+e+" "+i.level+" errored with "+t.details+", retrying loading "+(d+1)+"/"+h.maxNumRetry+" in "+f+"ms"),s.resolved=!0,this.retryDate=self.performance.now()+f,this.state=Vi.FRAG_LOADING_WAITING_RETRY}else if(h&&s){if(this.resetFragmentErrors(e),!(d.5;a&&this.reduceMaxBufferLength(i.len,(null==t?void 0:t.duration)||10);var n=!a;return n&&this.warn("Buffer full error while media.currentTime is not buffered, flush "+r+" buffer"),t&&(this.fragmentTracker.removeFragment(t),this.nextLoadPosition=t.start),this.resetLoadingState(),n}return!1},r.resetFragmentErrors=function(e){e===Lt.AUDIO&&(this.fragCurrent=null),this.loadedmetadata||(this.startFragRequested=!1),this.state!==Vi.STOPPED&&(this.state=Vi.IDLE)},r.afterBufferFlushed=function(e,t,r){if(e){var i=Fr.getBuffered(e);this.fragmentTracker.detectEvictedFragments(t,i,r),this.state===Vi.ENDED&&this.resetLoadingState()}},r.resetLoadingState=function(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=Vi.IDLE},r.resetStartWhenNotLoaded=function(e){if(!this.loadedmetadata){this.startFragRequested=!1;var t=e?e.details:null;null!=t&&t.live?(this.startPosition=-1,this.setStartPosition(t,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}},r.resetWhenMissingContext=function(e){this.warn("The loading context changed while buffering fragment "+e.sn+" of level "+e.level+". This chunk will not be buffered."),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState()},r.removeUnbufferedFrags=function(e){void 0===e&&(e=0),this.fragmentTracker.removeFragmentsInRange(e,1/0,this.playlistType,!1,!0)},r.updateLevelTiming=function(e,t,r,i){var a,n=this,s=r.details;if(s){if(!Object.keys(e.elementaryStreams).reduce((function(t,a){var o=e.elementaryStreams[a];if(o){var l=o.endPTS-o.startPTS;if(l<=0)return n.warn("Could not parse fragment "+e.sn+" "+a+" duration reliably ("+l+")"),t||!1;var u=i?0:Qt(s,e,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return n.hls.trigger(R.LEVEL_PTS_UPDATED,{details:s,level:r,drift:u,type:a,frag:e,start:o.startPTS,end:o.endPTS}),!0}return t}),!1)&&null===(null==(a=this.transmuxer)?void 0:a.error)){var o=new Error("Found no media in fragment "+e.sn+" of level "+e.level+" resetting transmuxer to fallback to playlist timing");if(0===r.fragmentError&&(r.fragmentError++,e.gap=!0,this.fragmentTracker.removeFragment(e),this.fragmentTracker.fragBuffered(e,!0)),this.warn(o.message),this.hls.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!1,error:o,frag:e,reason:"Found no media in msn "+e.sn+' of level "'+r.url+'"'}),!this.hls)return;this.resetTransmuxer()}this.state=Vi.PARSED,this.hls.trigger(R.FRAG_PARSED,{frag:e,part:t})}else this.warn("level.details undefined")},r.resetTransmuxer=function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)},r.recoverWorkerError=function(e){"demuxerWorker"===e.event&&(this.fragmentTracker.removeAllFragments(),this.resetTransmuxer(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState())},o(t,[{key:"state",get:function(){return this._state},set:function(e){var t=this._state;t!==e&&(this._state=e,this.log(t+"->"+e))}}]),t}(Ai);function Ki(){return self.SourceBuffer||self.WebKitSourceBuffer}function Wi(){if(!je())return!1;var e=Ki();return!e||e.prototype&&"function"==typeof e.prototype.appendBuffer&&"function"==typeof e.prototype.remove}function Yi(){if(!Wi())return!1;var e=je();return"function"==typeof(null==e?void 0:e.isTypeSupported)&&(["avc1.42E01E,mp4a.40.2","av01.0.01M.08","vp09.00.50.08"].some((function(t){return e.isTypeSupported($e(t,"video"))}))||["mp4a.40.2","fLaC"].some((function(t){return e.isTypeSupported($e(t,"audio"))})))}function ji(){var e,t=Ki();return"function"==typeof(null==t||null==(e=t.prototype)?void 0:e.changeType)}function qi(e,t){return void 0===e&&(e=""),void 0===t&&(t=9e4),{type:e,id:-1,pid:-1,inputTimeScale:t,sequenceNumber:-1,samples:[],dropped:0}}var zi=function(){function e(){this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null,this.lastPTS=null}var t=e.prototype;return t.resetInitSegment=function(e,t,r,i){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}},t.resetTimeStamp=function(e){this.initPTS=e,this.resetContiguity()},t.resetContiguity=function(){this.basePTS=null,this.lastPTS=null,this.frameIndex=0},t.canParse=function(e,t){return!1},t.appendFrame=function(e,t,r){},t.demux=function(e,t){this.cachedData&&(e=Ne(this.cachedData,e),this.cachedData=null);var r,i=$(e,0),a=i?i.length:0,n=this._audioTrack,s=this._id3Track,o=i?te(i):void 0,l=e.length;for((null===this.basePTS||0===this.frameIndex&&S(o))&&(this.basePTS=Xi(o,t,this.initPTS),this.lastPTS=this.basePTS),null===this.lastPTS&&(this.lastPTS=this.basePTS),i&&i.length>0&&s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:i,type:wt.audioId3,duration:Number.POSITIVE_INFINITY});a>>6);var h=(60&t[r+2])>>>2;if(!(h>d.length-1))return s=(1&t[r+2])<<2,s|=(192&t[r+3])>>>6,P.log("manifest codec:"+i+", ADTS type:"+a+", samplingIndex:"+h),/firefox/i.test(l)?h>=6?(a=5,o=new Array(4),n=h-3):(a=2,o=new Array(2),n=h):-1!==l.indexOf("android")?(a=2,o=new Array(2),n=h):(a=5,o=new Array(4),i&&(-1!==i.indexOf("mp4a.40.29")||-1!==i.indexOf("mp4a.40.5"))||!i&&h>=6?n=h-3:((i&&-1!==i.indexOf("mp4a.40.2")&&(h>=6&&1===s||/vivaldi/i.test(l))||!i&&1===s)&&(a=2,o=new Array(2)),n=h)),o[0]=a<<3,o[0]|=(14&h)>>1,o[1]|=(1&h)<<7,o[1]|=s<<3,5===a&&(o[1]|=(14&n)>>1,o[2]=(1&n)<<7,o[2]|=8,o[3]=0),{config:o,samplerate:d[h],channelCount:s,codec:"mp4a.40."+a,manifestCodec:u};var f=new Error("invalid ADTS sampling index:"+h);e.emit(R.ERROR,R.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!0,error:f,reason:f.message})}function Ji(e,t){return 255===e[t]&&240==(246&e[t+1])}function $i(e,t){return 1&e[t+1]?7:9}function Zi(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function ea(e,t){return t+5=e.length)return!1;var i=Zi(e,t);if(i<=r)return!1;var a=t+i;return a===e.length||ta(e,a)}return!1}function aa(e,t,r,i,a){if(!e.samplerate){var n=Qi(t,r,i,a);if(!n)return;e.config=n.config,e.samplerate=n.samplerate,e.channelCount=n.channelCount,e.codec=n.codec,e.manifestCodec=n.manifestCodec,P.log("parsed codec:"+e.codec+", rate:"+n.samplerate+", channels:"+n.channelCount)}}function na(e){return 9216e4/e}function sa(e,t){var r=$i(e,t);if(t+r<=e.length){var i=Zi(e,t)-r;if(i>0)return{headerLength:r,frameLength:i}}}function oa(e,t,r,i,a){var n,s=i+a*na(e.samplerate),o=sa(t,r);if(o){var l=o.frameLength,u=o.headerLength,d=u+l,h=Math.max(0,r+d-t.length);h?(n=new Uint8Array(d-u)).set(t.subarray(r+u,t.length),0):n=t.subarray(r+u,r+d);var f={unit:n,pts:s};return h||e.samples.push(f),{sample:f,length:d,missing:h}}var c=t.length-r;return(n=new Uint8Array(c)).set(t.subarray(r,t.length),0),{sample:{unit:n,pts:s},length:c,missing:-1}}var la=null,ua=[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],da=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],ha=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],fa=[0,1,1,4];function ca(e,t,r,i,a){if(!(r+24>t.length)){var n=va(t,r);if(n&&r+n.frameLength<=t.length){var s=i+a*(9e4*n.samplesPerFrame/n.sampleRate),o={unit:t.subarray(r,r+n.frameLength),pts:s,dts:s};return e.config=[],e.channelCount=n.channelCount,e.samplerate=n.sampleRate,e.samples.push(o),{sample:o,length:n.frameLength,missing:0}}}}function va(e,t){var r=e[t+1]>>3&3,i=e[t+1]>>1&3,a=e[t+2]>>4&15,n=e[t+2]>>2&3;if(1!==r&&0!==a&&15!==a&&3!==n){var s=e[t+2]>>1&1,o=e[t+3]>>6,l=1e3*ua[14*(3===r?3-i:3===i?3:4)+a-1],u=da[3*(3===r?0:2===r?1:2)+n],d=3===o?1:2,h=ha[r][i],f=fa[i],c=8*h*f,v=Math.floor(h*l/u+s)*f;if(null===la){var g=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);la=g?parseInt(g[1]):0}return!!la&&la<=87&&2===i&&l>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:u,channelCount:d,frameLength:v,samplesPerFrame:c}}}function ga(e,t){return 255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}function ma(e,t){return t+10;){s[0]=e[t];var o=Math.min(i,8),l=8-o;n[0]=4278190080>>>24+l<>l,r=r?r<e?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,e-=(t=e>>3)<<3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)},t.readBits=function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;if(e>32&&P.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0)this.word<<=t;else{if(!(this.bytesAvailable>0))throw new Error("no bits available");this.loadWord()}return(t=e-t)>0&&this.bitsAvailable?r<>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()},t.skipUEG=function(){this.skipBits(1+this.skipLZ())},t.skipEG=function(){this.skipBits(1+this.skipLZ())},t.readUEG=function(){var e=this.skipLZ();return this.readBits(e+1)-1},t.readEG=function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)},t.readBoolean=function(){return 1===this.readBits(1)},t.readUByte=function(){return this.readBits(8)},t.readUShort=function(){return this.readBits(16)},t.readUInt=function(){return this.readBits(32)},t.skipScalingList=function(e){for(var t=8,r=8,i=0;i4){var c=new Ra(f).readSliceType();2!==c&&4!==c&&7!==c&&9!==c||(d=!0)}d&&null!=(h=l)&&h.frame&&!l.key&&(s.pushAccessUnit(l,e),l=s.VideoSample=null),l||(l=s.VideoSample=s.createVideoSample(!0,r.pts,r.dts,"")),l.frame=!0,l.key=d;break;case 5:n=!0,null!=(o=l)&&o.frame&&!l.key&&(s.pushAccessUnit(l,e),l=s.VideoSample=null),l||(l=s.VideoSample=s.createVideoSample(!0,r.pts,r.dts,"")),l.key=!0,l.frame=!0;break;case 6:n=!0,Ve(i.data,1,r.pts,t.samples);break;case 7:var v,g;n=!0,u=!0;var m=i.data,p=new Ra(m).readSPS();if(!e.sps||e.width!==p.width||e.height!==p.height||(null==(v=e.pixelRatio)?void 0:v[0])!==p.pixelRatio[0]||(null==(g=e.pixelRatio)?void 0:g[1])!==p.pixelRatio[1]){e.width=p.width,e.height=p.height,e.pixelRatio=p.pixelRatio,e.sps=[m],e.duration=a;for(var y=m.subarray(1,4),E="avc1.",T=0;T<3;T++){var S=y[T].toString(16);S.length<2&&(S="0"+S),E+=S}e.codec=E}break;case 8:n=!0,e.pps=[i.data];break;case 9:n=!0,e.audFound=!0,l&&s.pushAccessUnit(l,e),l=s.VideoSample=s.createVideoSample(!1,r.pts,r.dts,"");break;case 12:n=!0;break;default:n=!1,l&&(l.debug+="unknown NAL "+i.type+" ")}l&&n&&l.units.push(i)})),i&&l&&(this.pushAccessUnit(l,e),this.VideoSample=null)},r.parseAVCNALu=function(e,t){var r,i,a=t.byteLength,n=e.naluState||0,s=n,o=[],l=0,u=-1,d=0;for(-1===n&&(u=0,d=31&t[0],n=0,l=1);l=0){var h={data:t.subarray(u,i),type:d};o.push(h)}else{var f=this.getLastNalUnit(e.samples);f&&(s&&l<=4-s&&f.state&&(f.data=f.data.subarray(0,f.data.byteLength-s)),i>0&&(f.data=Ne(f.data,t.subarray(0,i)),f.state=0))}l=0&&n>=0){var c={data:t.subarray(u,a),type:d,state:n};o.push(c)}if(0===o.length){var v=this.getLastNalUnit(e.samples);v&&(v.data=Ne(v.data,t))}return e.naluState=n,o},t}(Aa),Da=function(){function e(e,t,r){this.keyData=void 0,this.decrypter=void 0,this.keyData=r,this.decrypter=new Ui(t,{removePKCS7Padding:!1})}var t=e.prototype;return t.decryptBuffer=function(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer)},t.decryptAacSample=function(e,t,r){var i=this,a=e[t].unit;if(!(a.length<=16)){var n=a.subarray(16,a.length-a.length%16),s=n.buffer.slice(n.byteOffset,n.byteOffset+n.length);this.decryptBuffer(s).then((function(n){var s=new Uint8Array(n);a.set(s,16),i.decrypter.isSync()||i.decryptAacSamples(e,t+1,r)}))}},t.decryptAacSamples=function(e,t,r){for(;;t++){if(t>=e.length)return void r();if(!(e[t].unit.length<32||(this.decryptAacSample(e,t,r),this.decrypter.isSync())))return}},t.getAvcEncryptedData=function(e){for(var t=16*Math.floor((e.length-48)/160)+16,r=new Int8Array(t),i=0,a=32;a=e.length)return void i();for(var a=e[t].units;!(r>=a.length);r++){var n=a[r];if(!(n.data.length<=48||1!==n.type&&5!==n.type||(this.decryptAvcSample(e,t,r,i,n),this.decrypter.isSync())))return}}},e}(),ka=188,Ia=function(){function e(e,t,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._pmtId=-1,this._videoTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.remainderData=null,this.videoParser=void 0,this.observer=e,this.config=t,this.typeSupported=r,this.videoParser=new ba}e.probe=function(t){var r=e.syncOffset(t);return r>0&&P.warn("MPEG2-TS detected but first sync word found @ offset "+r),-1!==r},e.syncOffset=function(e){for(var t=e.length,r=Math.min(5*ka,t-ka)+1,i=0;i1&&(0===n&&s>2||o+ka>r))return n}i++}return-1},e.createTrack=function(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:ge[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===e?t:void 0}};var t=e.prototype;return t.resetInitSegment=function(t,r,i,a){this.pmtParsed=!1,this._pmtId=-1,this._videoTrack=e.createTrack("video"),this._audioTrack=e.createTrack("audio",a),this._id3Track=e.createTrack("id3"),this._txtTrack=e.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=i,this._duration=a},t.resetTimeStamp=function(){},t.resetContiguity=function(){var e=this._audioTrack,t=this._videoTrack,r=this._id3Track;e&&(e.pesData=null),t&&(t.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null,this.remainderData=null},t.demux=function(t,r,i,a){var n;void 0===i&&(i=!1),void 0===a&&(a=!1),i||(this.sampleAes=null);var s=this._videoTrack,o=this._audioTrack,l=this._id3Track,u=this._txtTrack,d=s.pid,h=s.pesData,f=o.pid,c=l.pid,v=o.pesData,g=l.pesData,m=null,p=this.pmtParsed,y=this._pmtId,E=t.length;if(this.remainderData&&(E=(t=Ne(this.remainderData,t)).length,this.remainderData=null),E>4>1){if((b=L+5+t[L+4])===L+ka)continue}else b=L+4;switch(R){case d:A&&(h&&(n=Oa(h))&&this.videoParser.parseAVCPES(s,u,n,!1,this._duration),h={data:[],size:0}),h&&(h.data.push(t.subarray(b,L+ka)),h.size+=L+ka-b);break;case f:if(A){if(v&&(n=Oa(v)))switch(o.segmentCodec){case"aac":this.parseAACPES(o,n);break;case"mp3":this.parseMPEGPES(o,n)}v={data:[],size:0}}v&&(v.data.push(t.subarray(b,L+ka)),v.size+=L+ka-b);break;case c:A&&(g&&(n=Oa(g))&&this.parseID3PES(l,n),g={data:[],size:0}),g&&(g.data.push(t.subarray(b,L+ka)),g.size+=L+ka-b);break;case 0:A&&(b+=t[b]+1),y=this._pmtId=xa(t,b);break;case y:A&&(b+=t[b]+1);var D=wa(t,b,this.typeSupported,i,this.observer);(d=D.videoPid)>0&&(s.pid=d,s.segmentCodec=D.segmentVideoCodec),(f=D.audioPid)>0&&(o.pid=f,o.segmentCodec=D.segmentAudioCodec),(c=D.id3Pid)>0&&(l.pid=c),null===m||p||(P.warn("MPEG-TS PMT found at "+L+" after unknown PID '"+m+"'. Backtracking to sync byte @"+T+" to parse all TS packets."),m=null,L=T-188),p=this.pmtParsed=!0;break;case 17:case 8191:break;default:m=R}}else S++;S>0&&Ca(this.observer,new Error("Found "+S+" TS packet/s that do not start with 0x47")),s.pesData=h,o.pesData=v,l.pesData=g;var k={audioTrack:o,videoTrack:s,id3Track:l,textTrack:u};return a&&this.extractRemainingSamples(k),k},t.flush=function(){var e,t=this.remainderData;return this.remainderData=null,e=t?this.demux(t,-1,!1,!0):{videoTrack:this._videoTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(e),this.sampleAes?this.decrypt(e,this.sampleAes):e},t.extractRemainingSamples=function(e){var t,r=e.audioTrack,i=e.videoTrack,a=e.id3Track,n=e.textTrack,s=i.pesData,o=r.pesData,l=a.pesData;if(s&&(t=Oa(s))?(this.videoParser.parseAVCPES(i,n,t,!0,this._duration),i.pesData=null):i.pesData=s,o&&(t=Oa(o))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,t);break;case"mp3":this.parseMPEGPES(r,t)}r.pesData=null}else null!=o&&o.size&&P.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;l&&(t=Oa(l))?(this.parseID3PES(a,t),a.pesData=null):a.pesData=l},t.demuxSampleAes=function(e,t,r){var i=this.demux(e,r,!0,!this.config.progressive),a=this.sampleAes=new Da(this.observer,this.config,t);return this.decrypt(i,a)},t.decrypt=function(e,t){return new Promise((function(r){var i=e.audioTrack,a=e.videoTrack;i.samples&&"aac"===i.segmentCodec?t.decryptAacSamples(i.samples,0,(function(){a.samples?t.decryptAvcSamples(a.samples,0,0,(function(){r(e)})):r(e)})):a.samples&&t.decryptAvcSamples(a.samples,0,0,(function(){r(e)}))}))},t.destroy=function(){this._duration=0},t.parseAACPES=function(e,t){var r,i,a,n=0,s=this.aacOverFlow,o=t.data;if(s){this.aacOverFlow=null;var l=s.missing,u=s.sample.unit.byteLength;if(-1===l)o=Ne(s.sample.unit,o);else{var d=u-l;s.sample.unit.set(o.subarray(0,l),d),e.samples.push(s.sample),n=s.missing}}for(r=n,i=o.length;r0)for(var u=t+5,d=l;d>2;){106===e[u]&&P.warn("AC-3 in M2TS support not included in build");var h=e[u+1]+2;u+=h,d-=h}break;case 194:case 135:return Ca(a,new Error("Unsupported EC-3 in M2TS found")),n;case 36:return Ca(a,new Error("Unsupported HEVC in M2TS found")),n}t+=l+5}return n}function Ca(e,t,r){P.warn("parsing error: "+t.message),e.emit(R.ERROR,R.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!1,levelRetry:r,error:t,reason:t.message})}function Pa(e){P.log(e+" with AES-128-CBC encryption found in unencrypted stream")}function Oa(e){var t,r,i,a,n,s=0,o=e.data;if(!e||0===e.size)return null;for(;o[0].length<19&&o.length>1;)o[0]=Ne(o[0],o[1]),o.splice(1,1);if(1===((t=o[0])[0]<<16)+(t[1]<<8)+t[2]){if((r=(t[4]<<8)+t[5])&&r>e.size-6)return null;var l=t[7];192&l&&(a=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,64&l?a-(n=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2)>54e5&&(P.warn(Math.round((a-n)/9e4)+"s delta between PTS and DTS, align them"),a=n):n=a);var u=(i=t[8])+9;if(e.size<=u)return null;e.size-=u;for(var d=new Uint8Array(e.size),h=0,f=o.length;hc){u-=c;continue}t=t.subarray(u),c-=u,u=0}d.set(t,s),s+=c}return r&&(r-=i+3),{data:d,pts:a,dts:n,len:r}}return null}var Fa=function(e){function t(){return e.apply(this,arguments)||this}d(t,e);var r=t.prototype;return r.resetInitSegment=function(t,r,i,a){e.prototype.resetInitSegment.call(this,t,r,i,a),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:r,duration:a,inputTimeScale:9e4,dropped:0}},t.probe=function(e){if(!e)return!1;var t=$(e,0),r=(null==t?void 0:t.length)||0;if(t&&11===e[r]&&119===e[r+1]&&void 0!==te(t)&&La(e,r)<=16)return!1;for(var i=e.length;r1?r-1:0),a=1;a>24&255,o[1]=t>>16&255,o[2]=t>>8&255,o[3]=255&t,o.set(e,4),n=0,t=8;n>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,85,196,0,0]))},e.mdia=function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))},e.mfhd=function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))},e.minf=function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))},e.moof=function(t,r,i){return e.box(e.types.moof,e.mfhd(t),e.traf(i,r))},e.moov=function(t){for(var r=t.length,i=[];r--;)i[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(e.mvex(t)))},e.mvex=function(t){for(var r=t.length,i=[];r--;)i[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(i))},e.mvhd=function(t,r){r*=t;var i=Math.floor(r/(Na+1)),a=Math.floor(r%(Na+1)),n=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return e.box(e.types.mvhd,n)},e.sdtp=function(t){var r,i,a=t.samples||[],n=new Uint8Array(4+a.length);for(r=0;r>>8&255),n.push(255&a),n=n.concat(Array.prototype.slice.call(i));for(r=0;r>>8&255),s.push(255&a),s=s.concat(Array.prototype.slice.call(i));var o=e.box(e.types.avcC,new Uint8Array([1,n[3],n[4],n[5],255,224|t.sps.length].concat(n).concat([t.pps.length]).concat(s))),l=t.width,u=t.height,d=t.pixelRatio[0],h=t.pixelRatio[1];return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,l>>8&255,255&l,u>>8&255,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),e.box(e.types.pasp,new Uint8Array([d>>24,d>>16&255,d>>8&255,255&d,h>>24,h>>16&255,h>>8&255,255&h])))},e.esds=function(e){var t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))},e.audioStsd=function(e){var t=e.samplerate;return 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,t>>8&255,255&t,0,0])},e.mp4a=function(t){return e.box(e.types.mp4a,e.audioStsd(t),e.box(e.types.esds,e.esds(t)))},e.mp3=function(t){return e.box(e.types[".mp3"],e.audioStsd(t))},e.ac3=function(t){return e.box(e.types["ac-3"],e.audioStsd(t),e.box(e.types.dac3,t.config))},e.stsd=function(t){return"audio"===t.type?"mp3"===t.segmentCodec&&"mp3"===t.codec?e.box(e.types.stsd,e.STSD,e.mp3(t)):"ac3"===t.segmentCodec?e.box(e.types.stsd,e.STSD,e.ac3(t)):e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))},e.tkhd=function(t){var r=t.id,i=t.duration*t.timescale,a=t.width,n=t.height,s=Math.floor(i/(Na+1)),o=Math.floor(i%(Na+1));return e.box(e.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,a>>8&255,255&a,0,0,n>>8&255,255&n,0,0]))},e.traf=function(t,r){var i=e.sdtp(t),a=t.id,n=Math.floor(r/(Na+1)),s=Math.floor(r%(Na+1));return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a])),e.box(e.types.tfdt,new Uint8Array([1,0,0,0,n>>24,n>>16&255,n>>8&255,255&n,s>>24,s>>16&255,s>>8&255,255&s])),e.trun(t,i.length+16+20+8+16+8+8),i)},e.trak=function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))},e.trex=function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},e.trun=function(t,r){var i,a,n,s,o,l,u=t.samples||[],d=u.length,h=12+16*d,f=new Uint8Array(h);for(r+=8+h,f.set(["video"===t.type?1:0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i>>24&255,n>>>16&255,n>>>8&255,255&n,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return e.box(e.types.trun,f)},e.initSegment=function(t){e.types||e.init();var r=e.moov(t);return Ne(e.FTYP,r)},e}();Ba.types=void 0,Ba.HDLR_TYPES=void 0,Ba.STTS=void 0,Ba.STSC=void 0,Ba.STCO=void 0,Ba.STSZ=void 0,Ba.VMHD=void 0,Ba.SMHD=void 0,Ba.STSD=void 0,Ba.FTYP=void 0,Ba.DINF=void 0;var Ua=9e4;function Ga(e,t,r,i){void 0===r&&(r=1),void 0===i&&(i=!1);var a=e*t*r;return i?Math.round(a):a}function Va(e,t){return void 0===t&&(t=!1),Ga(e,1e3,1/Ua,t)}var Ha=1e4,Ka=1024,Wa=1152,Ya=1536,ja=null,qa=null,za=function(){function e(e,t,r,i){if(this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=null,this._initDTS=null,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.videoTrackConfig=void 0,this.observer=e,this.config=t,this.typeSupported=r,this.ISGenerated=!1,null===ja){var a=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);ja=a?parseInt(a[1]):0}if(null===qa){var n=navigator.userAgent.match(/Safari\/(\d+)/i);qa=n?parseInt(n[1]):0}}var t=e.prototype;return t.destroy=function(){this.config=this.videoTrackConfig=this._initPTS=this._initDTS=null},t.resetTimeStamp=function(e){P.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=e},t.resetNextTimestamp=function(){P.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},t.resetInitSegment=function(){P.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1,this.videoTrackConfig=void 0},t.getVideoStartPts=function(e){var t=!1,r=e.reduce((function(e,r){var i=r.pts-e;return i<-4294967296?(t=!0,Xa(e,r.pts)):i>0?e:r.pts}),e[0].pts);return t&&P.debug("PTS rollover detected"),r},t.remux=function(e,t,r,i,a,n,s,o){var l,u,d,h,f,c,v=a,g=a,m=e.pid>-1,p=t.pid>-1,y=t.samples.length,E=e.samples.length>0,T=s&&y>0||y>1;if((!m||E)&&(!p||T)||this.ISGenerated||s){if(this.ISGenerated){var S,L,A,R,b=this.videoTrackConfig;!b||t.width===b.width&&t.height===b.height&&(null==(S=t.pixelRatio)?void 0:S[0])===(null==(L=b.pixelRatio)?void 0:L[0])&&(null==(A=t.pixelRatio)?void 0:A[1])===(null==(R=b.pixelRatio)?void 0:R[1])||this.resetInitSegment()}else d=this.generateIS(e,t,a,n);var D,k=this.isVideoContiguous,I=-1;if(T&&(I=Qa(t.samples),!k&&this.config.forceKeyFrameOnDiscontinuity))if(c=!0,I>0){P.warn("[mp4-remuxer]: Dropped "+I+" out of "+y+" video samples due to a missing keyframe");var _=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(I),t.dropped+=I,D=g+=(t.samples[0].pts-_)/t.inputTimeScale}else-1===I&&(P.warn("[mp4-remuxer]: No keyframe found out of "+y+" video samples"),c=!1);if(this.ISGenerated){if(E&&T){var x=this.getVideoStartPts(t.samples),w=(Xa(e.samples[0].pts,x)-x)/t.inputTimeScale;v+=Math.max(0,w),g+=Math.max(0,-w)}if(E){if(e.samplerate||(P.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),d=this.generateIS(e,t,a,n)),u=this.remuxAudio(e,v,this.isAudioContiguous,n,p||T||o===Lt.AUDIO?g:void 0),T){var C=u?u.endPTS-u.startPTS:0;t.inputTimeScale||(P.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),d=this.generateIS(e,t,a,n)),l=this.remuxVideo(t,g,k,C)}}else T&&(l=this.remuxVideo(t,g,k,0));l&&(l.firstKeyFrame=I,l.independent=-1!==I,l.firstKeyFramePTS=D)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(r.samples.length&&(f=Ja(r,a,this._initPTS,this._initDTS)),i.samples.length&&(h=$a(i,a,this._initPTS))),{audio:u,video:l,initSegment:d,independent:c,text:h,id3:f}},t.generateIS=function(e,t,r,i){var a,n,s,o=e.samples,l=t.samples,u=this.typeSupported,d={},h=this._initPTS,f=!h||i,c="audio/mp4";if(f&&(a=n=1/0),e.config&&o.length){switch(e.timescale=e.samplerate,e.segmentCodec){case"mp3":u.mpeg?(c="audio/mpeg",e.codec=""):u.mp3&&(e.codec="mp3");break;case"ac3":e.codec="ac-3"}d.audio={id:"audio",container:c,codec:e.codec,initSegment:"mp3"===e.segmentCodec&&u.mpeg?new Uint8Array(0):Ba.initSegment([e]),metadata:{channelCount:e.channelCount}},f&&(s=e.inputTimeScale,h&&s===h.timescale?f=!1:a=n=o[0].pts-Math.round(s*r))}if(t.sps&&t.pps&&l.length){if(t.timescale=t.inputTimeScale,d.video={id:"main",container:"video/mp4",codec:t.codec,initSegment:Ba.initSegment([t]),metadata:{width:t.width,height:t.height}},f)if(s=t.inputTimeScale,h&&s===h.timescale)f=!1;else{var v=this.getVideoStartPts(l),g=Math.round(s*r);n=Math.min(n,Xa(l[0].dts,v)-g),a=Math.min(a,v-g)}this.videoTrackConfig={width:t.width,height:t.height,pixelRatio:t.pixelRatio}}if(Object.keys(d).length)return this.ISGenerated=!0,f?(this._initPTS={baseTime:a,timescale:s},this._initDTS={baseTime:n,timescale:s}):a=s=void 0,{tracks:d,initPTS:a,timescale:s}},t.remuxVideo=function(e,t,r,i){var a,n,s=e.inputTimeScale,o=e.samples,l=[],d=o.length,h=this._initPTS,f=this.nextAvcDts,c=8,v=this.videoSampleDuration,g=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,p=!1;if(!r||null===f){var y=t*s,E=o[0].pts-Xa(o[0].dts,o[0].pts);ja&&null!==f&&Math.abs(y-E-f)<15e3?r=!0:f=y-E}for(var T=h.baseTime*s/h.timescale,S=0;S0?S-1:S].dts&&(p=!0)}p&&o.sort((function(e,t){var r=e.dts-t.dts,i=e.pts-t.pts;return r||i})),a=o[0].dts;var A=(n=o[o.length-1].dts)-a,k=A?Math.round(A/(d-1)):v||e.inputTimeScale/30;if(r){var I=a-f,_=I>k,x=I<-1;if((_||x)&&(_?P.warn("AVC: "+Va(I,!0)+" ms ("+I+"dts) hole between fragments detected at "+t.toFixed(3)):P.warn("AVC: "+Va(-I,!0)+" ms ("+I+"dts) overlapping between fragments detected at "+t.toFixed(3)),!x||f>=o[0].pts||ja)){a=f;var w=o[0].pts-I;if(_)o[0].dts=a,o[0].pts=w;else for(var C=0;Cw);C++)o[C].dts-=I,o[C].pts-=I;P.log("Video: Initial PTS/DTS adjusted: "+Va(w,!0)+"/"+Va(a,!0)+", delta: "+Va(I,!0)+" ms")}}for(var O=0,F=0,M=a=Math.max(0,a),N=0;N0?$.dts-o[J-1].dts:k;if(se=J>0?$.pts-o[J-1].pts:k,oe.stretchShortVideoTrack&&null!==this.nextAudioPts){var ue=Math.floor(oe.maxBufferHole*s),de=(i?g+i*s:this.nextAudioPts)-$.pts;de>ue?((v=de-le)<0?v=le:j=!0,P.log("[mp4-remuxer]: It is approximately "+de/90+" ms to the next segment; using duration "+v/90+" ms for the last video frame.")):v=le}else v=le}var he=Math.round($.pts-$.dts);q=Math.min(q,v),X=Math.max(X,v),z=Math.min(z,se),Q=Math.max(Q,se),l.push(new Za($.key,v,ee,he))}if(l.length)if(ja){if(ja<70){var fe=l[0].flags;fe.dependsOn=2,fe.isNonSync=0}}else if(qa&&Q-z0&&(i&&Math.abs(p-m)<9e3||Math.abs(Xa(v[0].pts-y,p)-m)<20*l),v.forEach((function(e){e.pts=Xa(e.pts-y,p)})),!r||m<0){if(v=v.filter((function(e){return e.pts>=0})),!v.length)return;m=0===a?0:i&&!c?Math.max(0,p):v[0].pts}if("aac"===e.segmentCodec)for(var E=this.config.maxAudioFramesDrift,T=0,S=m;T=E*l&&I0))return;N+=g;try{O=new Uint8Array(N)}catch(e){return void this.observer.emit(R.ERROR,R.ERROR,{type:b.MUX_ERROR,details:D.REMUX_ALLOC_ERROR,fatal:!1,error:e,bytes:N,reason:"fail allocating audio mdat "+N})}h||(new DataView(O.buffer).setUint32(0,N),O.set(Ba.types.mdat,4))}O.set(H,g);var W=H.byteLength;g+=W,f.push(new Za(!0,o,W,0)),M=K}var Y=f.length;if(Y){var j=f[f.length-1];this.nextAudioPts=m=M+s*j.duration;var q=h?new Uint8Array(0):Ba.moof(e.sequenceNumber++,F/s,u({},e,{samples:f}));e.samples=[];var z=F/n,X=m/n,Q={data1:q,data2:O,startPTS:z,endPTS:X,startDTS:z,endDTS:X,type:"audio",hasAudio:!0,hasVideo:!1,nb:Y};return this.isAudioContiguous=!0,Q}},t.remuxEmptyAudio=function(e,t,r,i){var a=e.inputTimeScale,n=a/(e.samplerate?e.samplerate:a),s=this.nextAudioPts,o=this._initDTS,l=9e4*o.baseTime/o.timescale,u=(null!==s?s:i.startDTS*a)+l,d=i.endDTS*a+l,h=n*Ka,f=Math.ceil((d-u)/h),c=Ma.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);if(P.warn("[mp4-remuxer]: remux empty Audio"),c){for(var v=[],g=0;g4294967296;)e+=r;return e}function Qa(e){for(var t=0;t0?this.lastEndTime=y:(P.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var E=!!c.audio,T=!!c.video,L="";E&&(L+="audio"),T&&(L+="video");var A={data1:h,startPTS:p,startDTS:p,endPTS:y,endDTS:y,type:L,hasAudio:E,hasVideo:T,nb:1,dropped:0};return d.audio="audio"===A.type?A:void 0,d.video="audio"!==A.type?A:void 0,d.initSegment=f,d.id3=Ja(r,a,l,l),i.samples.length&&(d.text=$a(i,a,l)),d},e}();function tn(e,t,r,i){if(null===e)return!0;var a=Math.max(i,1),n=t-e.baseTime/e.timescale;return Math.abs(n-r)>a}function rn(e,t){var r=null==e?void 0:e.codec;if(r&&r.length>4)return r;if(t===V.AUDIO){if("ec-3"===r||"ac-3"===r||"alac"===r)return r;if("fLaC"===r||"Opus"===r)return at(r,!1);var i="mp4a.40.5";return P.info('Parsed audio codec "'+r+'" or audio object type not handled. Using "'+i+'"'),i}return P.warn('Unhandled video codec "'+r+'"'),"hvc1"===r||"hev1"===r?"hvc1.1.6.L120.90":"av01"===r?"av01.0.04M.08":"avc1.42e01e"}var an,nn="undefined"!=typeof self?self:void 0;try{an=self.performance.now.bind(self.performance)}catch(e){P.debug("Unable to use Performance API on this environment"),an=null==nn?void 0:nn.Date.now}var sn=[{demux:Sa,remux:en},{demux:Ia,remux:za},{demux:Ea,remux:za},{demux:Fa,remux:za}],on=function(){function e(e,t,r,i,a){this.async=!1,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.observer=e,this.typeSupported=t,this.config=r,this.vendor=i,this.id=a}var t=e.prototype;return t.configure=function(e){this.transmuxConfig=e,this.decrypter&&this.decrypter.reset()},t.push=function(e,t,r,i){var a=this,n=r.transmuxing;n.executeStart=an();var s=new Uint8Array(e),o=this.currentTransmuxState,l=this.transmuxConfig;i&&(this.currentTransmuxState=i);var u=i||o,d=u.contiguous,h=u.discontinuity,f=u.trackSwitch,c=u.accurateTimeOffset,v=u.timeOffset,g=u.initSegmentChange,m=l.audioCodec,p=l.videoCodec,y=l.defaultInitPts,E=l.duration,T=l.initSegmentData,S=ln(s,t);if(S&&"AES-128"===S.method){var L=this.getDecrypter();if(!L.isSync())return this.decryptionPromise=L.webCryptoDecrypt(s,S.key.buffer,S.iv.buffer).then((function(e){var t=a.push(e,null,r);return a.decryptionPromise=null,t})),this.decryptionPromise;var A=L.softwareDecrypt(s,S.key.buffer,S.iv.buffer);if(r.part>-1&&(A=L.flush()),!A)return n.executeEnd=an(),un(r);s=new Uint8Array(A)}var k=this.needsProbing(h,f);if(k){var I=this.configureTransmuxer(s);if(I)return P.warn("[transmuxer] "+I.message),this.observer.emit(R.ERROR,R.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,fatal:!1,error:I,reason:I.message}),n.executeEnd=an(),un(r)}(h||f||g||k)&&this.resetInitSegment(T,m,p,E,t),(h||g||k)&&this.resetInitialTimestamp(y),d||this.resetContiguity();var _=this.transmux(s,S,v,c,r),x=this.currentTransmuxState;return x.contiguous=!0,x.discontinuity=!1,x.trackSwitch=!1,n.executeEnd=an(),_},t.flush=function(e){var t=this,r=e.transmuxing;r.executeStart=an();var i=this.decrypter,a=this.currentTransmuxState,n=this.decryptionPromise;if(n)return n.then((function(){return t.flush(e)}));var s=[],o=a.timeOffset;if(i){var l=i.flush();l&&s.push(this.push(l,null,e))}var u=this.demuxer,d=this.remuxer;if(!u||!d)return r.executeEnd=an(),[un(e)];var h=u.flush(o);return dn(h)?h.then((function(r){return t.flushRemux(s,r,e),s})):(this.flushRemux(s,h,e),s)},t.flushRemux=function(e,t,r){var i=t.audioTrack,a=t.videoTrack,n=t.id3Track,s=t.textTrack,o=this.currentTransmuxState,l=o.accurateTimeOffset,u=o.timeOffset;P.log("[transmuxer.ts]: Flushed fragment "+r.sn+(r.part>-1?" p: "+r.part:"")+" of level "+r.level);var d=this.remuxer.remux(i,a,n,s,u,l,!0,this.id);e.push({remuxResult:d,chunkMeta:r}),r.transmuxing.executeEnd=an()},t.resetInitialTimestamp=function(e){var t=this.demuxer,r=this.remuxer;t&&r&&(t.resetTimeStamp(e),r.resetTimeStamp(e))},t.resetContiguity=function(){var e=this.demuxer,t=this.remuxer;e&&t&&(e.resetContiguity(),t.resetNextTimestamp())},t.resetInitSegment=function(e,t,r,i,a){var n=this.demuxer,s=this.remuxer;n&&s&&(n.resetInitSegment(e,t,r,i),s.resetInitSegment(e,t,r,a))},t.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},t.transmux=function(e,t,r,i,a){return t&&"SAMPLE-AES"===t.method?this.transmuxSampleAes(e,t,r,i,a):this.transmuxUnencrypted(e,r,i,a)},t.transmuxUnencrypted=function(e,t,r,i){var a=this.demuxer.demux(e,t,!1,!this.config.progressive),n=a.audioTrack,s=a.videoTrack,o=a.id3Track,l=a.textTrack;return{remuxResult:this.remuxer.remux(n,s,o,l,t,r,!1,this.id),chunkMeta:i}},t.transmuxSampleAes=function(e,t,r,i,a){var n=this;return this.demuxer.demuxSampleAes(e,t,r).then((function(e){return{remuxResult:n.remuxer.remux(e.audioTrack,e.videoTrack,e.id3Track,e.textTrack,r,i,!1,n.id),chunkMeta:a}}))},t.configureTransmuxer=function(e){for(var t,r=this.config,i=this.observer,a=this.typeSupported,n=this.vendor,s=0,o=sn.length;s0&&null!=(null==t?void 0:t.key)&&null!==t.iv&&null!=t.method&&(r=t),r}var un=function(e){return{remuxResult:{},chunkMeta:e}};function dn(e){return"then"in e&&e.then instanceof Function}var hn=function(e,t,r,i,a){this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=e,this.videoCodec=t,this.initSegmentData=r,this.duration=i,this.defaultInitPts=a||null},fn=function(e,t,r,i,a,n){this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=e,this.contiguous=t,this.accurateTimeOffset=r,this.trackSwitch=i,this.timeOffset=a,this.initSegmentChange=n},cn={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,r="~";function i(){}function a(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function n(e,t,i,n,s){if("function"!=typeof i)throw new TypeError("The listener must be a function");var o=new a(i,n||e,s),l=r?r+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],o]:e._events[l].push(o):(e._events[l]=o,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new i:delete e._events[t]}function o(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(r=!1)),o.prototype.eventNames=function(){var e,i,a=[];if(0===this._eventsCount)return a;for(i in e=this._events)t.call(e,i)&&a.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?a.concat(Object.getOwnPropertySymbols(e)):a},o.prototype.listeners=function(e){var t=r?r+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var a=0,n=i.length,s=new Array(n);a1&&l.id===(null==m?void 0:m.stats.chunkCount),L=!y&&(1===E||0===E&&(1===T||S&&T<=0)),A=self.performance.now();(y||E||0===a.stats.parsing.start)&&(a.stats.parsing.start=A),!n||!T&&L||(n.stats.parsing.start=A);var R=!(m&&(null==(d=a.initSegment)?void 0:d.url)===(null==(h=m.initSegment)?void 0:h.url)),b=new fn(p,L,o,y,v,R);if(!L||p||R){P.log("[transmuxer-interface, "+a.type+"]: Starting new transmux session for sn: "+l.sn+" p: "+l.part+" level: "+l.level+" id: "+l.id+"\n discontinuity: "+p+"\n trackSwitch: "+y+"\n contiguous: "+L+"\n accurateTimeOffset: "+o+"\n timeOffset: "+v+"\n initSegmentChange: "+R);var D=new hn(r,i,t,s,u);this.configureTransmuxer(D)}if(this.frag=a,this.part=n,this.workerContext)this.workerContext.worker.postMessage({cmd:"demux",data:e,decryptdata:g,chunkMeta:l,state:b},e instanceof ArrayBuffer?[e]:[]);else if(c){var k=c.push(e,g,l,b);dn(k)?(c.async=!0,k.then((function(e){f.handleTransmuxComplete(e)})).catch((function(e){f.transmuxerError(e,l,"transmuxer-interface push error")}))):(c.async=!1,this.handleTransmuxComplete(k))}},t.flush=function(e){var t=this;e.transmuxing.start=self.performance.now();var r=this.transmuxer;if(this.workerContext)this.workerContext.worker.postMessage({cmd:"flush",chunkMeta:e});else if(r){var i=r.flush(e);dn(i)||r.async?(dn(i)||(i=Promise.resolve(i)),i.then((function(r){t.handleFlushResult(r,e)})).catch((function(r){t.transmuxerError(r,e,"transmuxer-interface flush error")}))):this.handleFlushResult(i,e)}},t.transmuxerError=function(e,t,r){this.hls&&(this.error=e,this.hls.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.FRAG_PARSING_ERROR,chunkMeta:t,frag:this.frag||void 0,fatal:!1,error:e,err:e,reason:r}))},t.handleFlushResult=function(e,t){var r=this;e.forEach((function(e){r.handleTransmuxComplete(e)})),this.onFlush(t)},t.onWorkerMessage=function(e){var t=e.data;if(null!=t&&t.event){var r=this.hls;if(this.hls)switch(t.event){case"init":var i,a=null==(i=this.workerContext)?void 0:i.objectURL;a&&self.URL.revokeObjectURL(a);break;case"transmuxComplete":this.handleTransmuxComplete(t.data);break;case"flush":this.onFlush(t.data);break;case"workerLog":P[t.data.logType]&&P[t.data.logType](t.data.message);break;default:t.data=t.data||{},t.data.frag=this.frag,t.data.id=this.id,r.trigger(t.event,t.data)}}else P.warn("worker message received with no "+(t?"event name":"data"))},t.configureTransmuxer=function(e){var t=this.transmuxer;this.workerContext?this.workerContext.worker.postMessage({cmd:"configure",config:e}):t&&t.configure(e)},t.handleTransmuxComplete=function(e){e.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(e)},e}(),Rn=250,bn=2,Dn=.1,kn=.05,In=function(){function e(e,t,r,i){this.config=void 0,this.media=null,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=e,this.media=t,this.fragmentTracker=r,this.hls=i}var t=e.prototype;return t.destroy=function(){this.media=null,this.hls=this.fragmentTracker=null},t.poll=function(e,t){var r=this.config,i=this.media,a=this.stalled;if(null!==i){var n=i.currentTime,s=i.seeking,o=this.seeking&&!s,l=!this.seeking&&s;if(this.seeking=s,n===e)if(l||o)this.stalled=null;else if(i.paused&&!s||i.ended||0===i.playbackRate||!Fr.getBuffered(i).length)this.nudgeRetry=0;else{var u=Fr.bufferInfo(i,n,0),d=u.nextStart||0;if(s){var h=u.len>bn,f=!d||t&&t.start<=n||d-n>bn&&!this.fragmentTracker.getPartialFragment(n);if(h||f)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var c;if(!(u.len>0||d))return;var v=Math.max(d,u.start||0)-n,g=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,m=(null==g||null==(c=g.details)?void 0:c.live)?2*g.details.targetduration:bn,p=this.fragmentTracker.getPartialFragment(n);if(v>0&&(v<=m||p))return void(i.paused||this._trySkipBufferHole(p))}var y=self.performance.now();if(null!==a){var E=y-a;if(s||!(E>=Rn)||(this._reportStall(u),this.media)){var T=Fr.bufferInfo(i,n,r.maxBufferHole);this._tryFixBufferStall(T,E)}}else this.stalled=y}else if(this.moved=!0,s||(this.nudgeRetry=0),null!==a){if(this.stallReported){var S=self.performance.now()-a;P.warn("playback not stuck anymore @"+n+", after "+Math.round(S)+"ms"),this.stallReported=!1}this.stalled=null}}},t._tryFixBufferStall=function(e,t){var r=this.config,i=this.fragmentTracker,a=this.media;if(null!==a){var n=a.currentTime,s=i.getPartialFragment(n);if(s&&(this._trySkipBufferHole(s)||!this.media))return;(e.len>r.maxBufferHole||e.nextStart&&e.nextStart-n1e3*r.highBufferWatchdogPeriod&&(P.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}},t._reportStall=function(e){var t=this.hls,r=this.media;if(!this.stallReported&&r){this.stallReported=!0;var i=new Error("Playback stalling at @"+r.currentTime+" due to low buffer ("+JSON.stringify(e)+")");P.warn(i.message),t.trigger(R.ERROR,{type:b.MEDIA_ERROR,details:D.BUFFER_STALLED_ERROR,fatal:!1,error:i,buffer:e.len})}},t._trySkipBufferHole=function(e){var t=this.config,r=this.hls,i=this.media;if(null===i)return 0;var a=i.currentTime,n=Fr.bufferInfo(i,a,0),s=a0&&n.len<1&&i.readyState<3,u=s-a;if(u>0&&(o||l)){if(u>t.maxBufferHole){var d=this.fragmentTracker,h=!1;if(0===a){var f=d.getAppendedFrag(0,Lt.MAIN);f&&s1?(i=0,this.bitrateTest=!0):i=r.firstAutoLevel),r.nextLoadLevel=i,this.level=r.loadLevel,this.loadedmetadata=!1}t>0&&-1===e&&(this.log("Override startPosition with lastCurrentTime @"+t.toFixed(3)),e=t),this.state=Vi.IDLE,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}else this._forceStartLoad=!0,this.state=Vi.STOPPED},r.stopLoad=function(){this._forceStartLoad=!1,e.prototype.stopLoad.call(this)},r.doTick=function(){switch(this.state){case Vi.WAITING_LEVEL:var e=this.levels,t=this.level,r=null==e?void 0:e[t],i=null==r?void 0:r.details;if(i&&(!i.live||this.levelLastLoaded===r)){if(this.waitForCdnTuneIn(i))break;this.state=Vi.IDLE;break}if(this.hls.nextLoadLevel!==this.level){this.state=Vi.IDLE;break}break;case Vi.FRAG_LOADING_WAITING_RETRY:var a,n=self.performance.now(),s=this.retryDate;if(!s||n>=s||null!=(a=this.media)&&a.seeking){var o=this.levels,l=this.level,u=null==o?void 0:o[l];this.resetStartWhenNotLoaded(u||null),this.state=Vi.IDLE}}this.state===Vi.IDLE&&this.doTickIdle(),this.onTickEnd()},r.onTickEnd=function(){e.prototype.onTickEnd.call(this),this.checkBuffer(),this.checkFragmentChanged()},r.doTickIdle=function(){var e=this.hls,t=this.levelLastLoaded,r=this.levels,i=this.media;if(null!==t&&(i||!this.startFragRequested&&e.config.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)){var a=e.nextLoadLevel;if(null!=r&&r[a]){var n=r[a],s=this.getMainFwdBufferInfo();if(null!==s){var o=this.getLevelDetails();if(o&&this._streamEnded(s,o)){var l={};return this.altAudio&&(l.type="video"),this.hls.trigger(R.BUFFER_EOS,l),void(this.state=Vi.ENDED)}e.loadLevel!==a&&-1===e.manualLevel&&this.log("Adapting to level "+a+" from level "+this.level),this.level=e.nextLoadLevel=a;var u=n.details;if(!u||this.state===Vi.WAITING_LEVEL||u.live&&this.levelLastLoaded!==n)return this.level=a,void(this.state=Vi.WAITING_LEVEL);var d=s.len,h=this.getMaxBufferLength(n.maxBitrate);if(!(d>=h)){this.backtrackFragment&&this.backtrackFragment.start>s.end&&(this.backtrackFragment=null);var f=this.backtrackFragment?this.backtrackFragment.start:s.end,c=this.getNextFragment(f,u);if(this.couldBacktrack&&!this.fragPrevious&&c&&"initSegment"!==c.sn&&this.fragmentTracker.getState(c)!==ci.OK){var v,g=(null!=(v=this.backtrackFragment)?v:c).sn-u.startSN,m=u.fragments[g-1];m&&c.cc===m.cc&&(c=m,this.fragmentTracker.removeFragment(m))}else this.backtrackFragment&&s.len&&(this.backtrackFragment=null);if(c&&this.isLoopLoading(c,f)){if(!c.gap){var p=this.audioOnly&&!this.altAudio?V.AUDIO:V.VIDEO,y=(p===V.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;y&&this.afterBufferFlushed(y,p,Lt.MAIN)}c=this.getNextFragmentLoopLoading(c,u,s,Lt.MAIN,h)}c&&(!c.initSegment||c.initSegment.data||this.bitrateTest||(c=c.initSegment),this.loadFragment(c,n,f))}}}}},r.loadFragment=function(t,r,i){var a=this.fragmentTracker.getState(t);this.fragCurrent=t,a===ci.NOT_LOADED||a===ci.PARTIAL?"initSegment"===t.sn?this._loadInitSegment(t,r):this.bitrateTest?(this.log("Fragment "+t.sn+" of level "+t.level+" is being downloaded to test bitrate and will not be buffered"),this._loadBitrateTestFrag(t,r)):(this.startFragRequested=!0,e.prototype.loadFragment.call(this,t,r,i)):this.clearTrackerIfNeeded(t)},r.getBufferedFrag=function(e){return this.fragmentTracker.getBufferedFrag(e,Lt.MAIN)},r.followingBufferedFrag=function(e){return e?this.getBufferedFrag(e.end+.5):null},r.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},r.nextLevelSwitch=function(){var e=this.levels,t=this.media;if(null!=t&&t.readyState){var r,i=this.getAppendedFrag(t.currentTime);i&&i.start>1&&this.flushMainBuffer(0,i.start-1);var a=this.getLevelDetails();if(null!=a&&a.live){var n=this.getMainFwdBufferInfo();if(!n||n.len<2*a.targetduration)return}if(!t.paused&&e){var s=e[this.hls.nextLoadLevel],o=this.fragLastKbps;r=o&&this.fragCurrent?this.fragCurrent.duration*s.maxBitrate/(1e3*o)+1:0}else r=0;var l=this.getBufferedFrag(t.currentTime+r);if(l){var u=this.followingBufferedFrag(l);if(u){this.abortCurrentFrag();var d=u.maxStartPTS?u.maxStartPTS:u.start,h=u.duration,f=Math.max(l.end,d+Math.min(Math.max(h-this.config.maxFragLookUpTolerance,h*(this.couldBacktrack?.5:.125)),h*(this.couldBacktrack?.75:.25)));this.flushMainBuffer(f,Number.POSITIVE_INFINITY)}}}},r.abortCurrentFrag=function(){var e=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,e&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.state){case Vi.KEY_LOADING:case Vi.FRAG_LOADING:case Vi.FRAG_LOADING_WAITING_RETRY:case Vi.PARSING:case Vi.PARSED:this.state=Vi.IDLE}this.nextLoadPosition=this.getLoadPosition()},r.flushMainBuffer=function(t,r){e.prototype.flushMainBuffer.call(this,t,r,this.altAudio?"video":null)},r.onMediaAttached=function(t,r){e.prototype.onMediaAttached.call(this,t,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 In(this.config,i,this.fragmentTracker,this.hls)},r.onMediaDetaching=function(){var t=this.media;t&&this.onvplaying&&this.onvseeked&&(t.removeEventListener("playing",this.onvplaying),t.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),e.prototype.onMediaDetaching.call(this)},r.onMediaPlaying=function(){this.tick()},r.onMediaSeeked=function(){var e=this.media,t=e?e.currentTime:null;S(t)&&this.log("Media seeked to "+t.toFixed(3));var r=this.getMainFwdBufferInfo();null!==r&&0!==r.len?this.tick():this.warn('Main forward buffer length on "seeked" event '+(r?r.len:"empty")+")")},r.onManifestLoading=function(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(R.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=!1,this.startPosition=this.lastCurrentTime=this.fragLastKbps=0,this.levels=this.fragPlaying=this.backtrackFragment=this.levelLastLoaded=null,this.altAudio=this.audioOnly=this.startFragRequested=!1},r.onManifestParsed=function(e,t){var r=!1,i=!1;t.levels.forEach((function(e){var t=e.audioCodec;t&&(r=r||-1!==t.indexOf("mp4a.40.2"),i=i||-1!==t.indexOf("mp4a.40.5"))})),this.audioCodecSwitch=r&&i&&!ji(),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=t.levels,this.startFragRequested=!1},r.onLevelLoading=function(e,t){var r=this.levels;if(r&&this.state===Vi.IDLE){var i=r[t.level];(!i.details||i.details.live&&this.levelLastLoaded!==i||this.waitForCdnTuneIn(i.details))&&(this.state=Vi.WAITING_LEVEL)}},r.onLevelLoaded=function(e,t){var r,i=this.levels,a=t.level,n=t.details,s=n.totalduration;if(i){this.log("Level "+a+" loaded ["+n.startSN+","+n.endSN+"]"+(n.lastPartSn?"[part-"+n.lastPartSn+"-"+n.lastPartIndex+"]":"")+", cc ["+n.startCC+", "+n.endCC+"] duration:"+s);var o=i[a],l=this.fragCurrent;!l||this.state!==Vi.FRAG_LOADING&&this.state!==Vi.FRAG_LOADING_WAITING_RETRY||l.level!==t.level&&l.loader&&this.abortCurrentFrag();var u=0;if(n.live||null!=(r=o.details)&&r.live){var d;if(this.checkLiveUpdate(n),n.deltaUpdateFailed)return;u=this.alignPlaylists(n,o.details,null==(d=this.levelLastLoaded)?void 0:d.details)}if(o.details=n,this.levelLastLoaded=o,this.hls.trigger(R.LEVEL_UPDATED,{details:n,level:a}),this.state===Vi.WAITING_LEVEL){if(this.waitForCdnTuneIn(n))return;this.state=Vi.IDLE}this.startFragRequested?n.live&&this.synchronizeToLiveEdge(n):this.setStartPosition(n,u),this.tick()}else this.warn("Levels were reset while loading level "+a)},r._handleFragmentLoadProgress=function(e){var t,r=e.frag,i=e.part,a=e.payload,n=this.levels;if(n){var s=n[r.level],o=s.details;if(!o)return this.warn("Dropping fragment "+r.sn+" of level "+r.level+" after level details were reset"),void this.fragmentTracker.removeFragment(r);var l=s.videoCodec,u=o.PTSKnown||!o.live,d=null==(t=r.initSegment)?void 0:t.data,h=this._getAudioCodec(s),f=this.transmuxer=this.transmuxer||new An(this.hls,Lt.MAIN,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),c=i?i.index:-1,v=-1!==c,g=new Ri(r.level,r.sn,r.stats.chunkCount,a.byteLength,c,v),m=this.initPTS[r.cc];f.push(a,d,h,l,r,i,o.totalduration,u,g,m)}else this.warn("Levels were reset while fragment load was in progress. Fragment "+r.sn+" of level "+r.level+" will not be buffered")},r.onAudioTrackSwitching=function(e,t){var r=this.altAudio;if(!t.url){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var i=this.fragCurrent;i&&(this.log("Switching to main audio track, cancel main fragment load"),i.abortRequests(),this.fragmentTracker.removeFragment(i)),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();var a=this.hls;r&&(a.trigger(R.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:null}),this.fragmentTracker.removeAllFragments()),a.trigger(R.AUDIO_TRACK_SWITCHED,t)}},r.onAudioTrackSwitched=function(e,t){var r=t.id,i=!!this.hls.audioTracks[r].url;if(i){var a=this.videoBuffer;a&&this.mediaBuffer!==a&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=a)}this.altAudio=i,this.tick()},r.onBufferCreated=function(e,t){var r,i,a=t.tracks,n=!1;for(var s in a){var o=a[s];if("main"===o.id){if(i=s,r=o,"video"===s){var l=a[s];l&&(this.videoBuffer=l.buffer)}}else n=!0}n&&r?(this.log("Alternate track found, use "+i+".buffered to schedule main fragment loading"),this.mediaBuffer=r.buffer):this.mediaBuffer=this.media},r.onFragBuffered=function(e,t){var r=t.frag,i=t.part;if(!r||r.type===Lt.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===Vi.PARSED&&(this.state=Vi.IDLE));var a=i?i.stats:r.stats;this.fragLastKbps=Math.round(8*a.total/(a.buffering.end-a.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,i)}},r.onError=function(e,t){var r;if(t.fatal)this.state=Vi.ERROR;else switch(t.details){case D.FRAG_GAP:case D.FRAG_PARSING_ERROR:case D.FRAG_DECRYPT_ERROR:case D.FRAG_LOAD_ERROR:case D.FRAG_LOAD_TIMEOUT:case D.KEY_LOAD_ERROR:case D.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(Lt.MAIN,t);break;case D.LEVEL_LOAD_ERROR:case D.LEVEL_LOAD_TIMEOUT:case D.LEVEL_PARSING_ERROR:t.levelRetry||this.state!==Vi.WAITING_LEVEL||(null==(r=t.context)?void 0:r.type)!==St.LEVEL||(this.state=Vi.IDLE);break;case D.BUFFER_APPEND_ERROR:case D.BUFFER_FULL_ERROR:if(!t.parent||"main"!==t.parent)return;if(t.details===D.BUFFER_APPEND_ERROR)return void this.resetLoadingState();this.reduceLengthAndFlushBuffer(t)&&this.flushMainBuffer(0,Number.POSITIVE_INFINITY);break;case D.INTERNAL_EXCEPTION:this.recoverWorkerError(t)}},r.checkBuffer=function(){var e=this.media,t=this.gapController;if(e&&t&&e.readyState){if(this.loadedmetadata||!Fr.getBuffered(e).length){var r=this.state!==Vi.IDLE?this.fragCurrent:null;t.poll(this.lastCurrentTime,r)}this.lastCurrentTime=e.currentTime}},r.onFragLoadEmergencyAborted=function(){this.state=Vi.IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()},r.onBufferFlushed=function(e,t){var r=t.type;if(r!==V.AUDIO||this.audioOnly&&!this.altAudio){var i=(r===V.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(i,r,Lt.MAIN),this.tick()}},r.onLevelsUpdated=function(e,t){this.level>-1&&this.fragCurrent&&(this.level=this.fragCurrent.level),this.levels=t.levels},r.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},r.seekToStartPos=function(){var e=this.media;if(e){var t=e.currentTime,r=this.startPosition;if(r>=0&&t0&&(aE.cc;if(!1!==a.independent){var A=d.startPTS,b=d.endPTS,D=d.startDTS,k=d.endDTS;if(l)l.elementaryStreams[d.type]={startPTS:A,endPTS:b,startDTS:D,endDTS:k};else if(d.firstKeyFrame&&d.independent&&1===n.id&&!L&&(this.couldBacktrack=!0),d.dropped&&d.independent){var I=this.getMainFwdBufferInfo(),_=(I?I.end:this.getLoadPosition())+this.config.maxBufferHole,x=d.firstKeyFramePTS?d.firstKeyFramePTS:A;if(!T&&_bn&&(o.gap=!0);o.setElementaryStreamInfo(d.type,A,b,D,k),this.backtrackFragment&&(this.backtrackFragment=o),this.bufferFragmentData(d,o,l,n,T||L)}else{if(!T&&!L)return void this.backtrack(o);o.gap=!0}}if(g){var w=g.startPTS,C=g.endPTS,P=g.startDTS,O=g.endDTS;l&&(l.elementaryStreams[V.AUDIO]={startPTS:w,endPTS:C,startDTS:P,endDTS:O}),o.setElementaryStreamInfo(V.AUDIO,w,C,P,O),this.bufferFragmentData(g,o,l,n)}if(v&&null!=f&&null!=(t=f.samples)&&t.length){var F={id:r,frag:o,details:v,samples:f.samples};i.trigger(R.FRAG_PARSING_METADATA,F)}if(v&&h){var M={id:r,frag:o,details:v,samples:h.samples};i.trigger(R.FRAG_PARSING_USERDATA,M)}}}else this.resetWhenMissingContext(n)},r._bufferInitSegment=function(e,t,r,i){var a=this;if(this.state===Vi.PARSING){this.audioOnly=!!t.audio&&!t.video,this.altAudio&&!this.audioOnly&&delete t.audio;var n=t.audio,s=t.video,o=t.audiovideo;if(n){var l=e.audioCodec,u=navigator.userAgent.toLowerCase();if(this.audioCodecSwitch){l&&(l=-1!==l.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5");var d=n.metadata;d&&"channelCount"in d&&1!==(d.channelCount||1)&&-1===u.indexOf("firefox")&&(l="mp4a.40.5")}l&&-1!==l.indexOf("mp4a.40.5")&&-1!==u.indexOf("android")&&"audio/mpeg"!==n.container&&(l="mp4a.40.2",this.log("Android: force audio codec to "+l)),e.audioCodec&&e.audioCodec!==l&&this.log('Swapping manifest audio codec "'+e.audioCodec+'" for "'+l+'"'),n.levelCodec=l,n.id="main",this.log("Init audio buffer, container:"+n.container+", codecs[selected/level/parsed]=["+(l||"")+"/"+(e.audioCodec||"")+"/"+n.codec+"]")}s&&(s.levelCodec=e.videoCodec,s.id="main",this.log("Init video buffer, container:"+s.container+", codecs[level/parsed]=["+(e.videoCodec||"")+"/"+s.codec+"]")),o&&this.log("Init audiovideo buffer, container:"+o.container+", codecs[level/parsed]=["+e.codecs+"/"+o.codec+"]"),this.hls.trigger(R.BUFFER_CODECS,t),Object.keys(t).forEach((function(e){var n=t[e].initSegment;null!=n&&n.byteLength&&a.hls.trigger(R.BUFFER_APPENDING,{type:e,data:n,frag:r,part:null,chunkMeta:i,parent:r.type})})),this.tickImmediate()}},r.getMainFwdBufferInfo=function(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,Lt.MAIN)},r.backtrack=function(e){this.couldBacktrack=!0,this.backtrackFragment=e,this.resetTransmuxer(),this.flushBufferGap(e),this.fragmentTracker.removeFragment(e),this.fragPrevious=null,this.nextLoadPosition=e.start,this.state=Vi.IDLE},r.checkFragmentChanged=function(){var e=this.media,t=null;if(e&&e.readyState>1&&!1===e.seeking){var r=e.currentTime;if(Fr.isBuffered(e,r)?t=this.getAppendedFrag(r):Fr.isBuffered(e,r+.1)&&(t=this.getAppendedFrag(r+.1)),t){this.backtrackFragment=null;var i=this.fragPlaying,a=t.level;i&&t.sn===i.sn&&i.level===a||(this.fragPlaying=t,this.hls.trigger(R.FRAG_CHANGED,{frag:t}),i&&i.level===a||this.hls.trigger(R.LEVEL_SWITCHED,{level:a}))}}},o(t,[{key:"nextLevel",get:function(){var e=this.nextBufferedFrag;return e?e.level:-1}},{key:"currentFrag",get:function(){var e=this.media;return e?this.fragPlaying||this.getAppendedFrag(e.currentTime):null}},{key:"currentProgramDateTime",get:function(){var e=this.media;if(e){var t=e.currentTime,r=this.currentFrag;if(r&&S(t)&&S(r.programDateTime)){var i=r.programDateTime+1e3*(t-r.start);return new Date(i)}}return null}},{key:"currentLevel",get:function(){var e=this.currentFrag;return e?e.level:-1}},{key:"nextBufferedFrag",get:function(){var e=this.currentFrag;return e?this.followingBufferedFrag(e):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}]),t}(Hi),wn=function(){function e(t){void 0===t&&(t={}),this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this.started=!1,this._emitter=new vn,this._autoLevelCapping=-1,this._maxHdcpLevel=null,this.abrController=void 0,this.bufferController=void 0,this.capLevelController=void 0,this.latencyController=void 0,this.levelController=void 0,this.streamController=void 0,this.audioTrackController=void 0,this.subtitleTrackController=void 0,this.emeController=void 0,this.cmcdController=void 0,this._media=null,this.url=null,this.triggeringException=void 0,C(t.debug||!1,"Hls instance");var r=this.config=li(e.DefaultConfig,t);this.userConfig=t,r.progressive&&di(r);var i=r.abrController,a=r.bufferController,n=r.capLevelController,s=r.errorController,o=r.fpsController,l=new s(this),u=this.abrController=new i(this),d=this.bufferController=new a(this),h=this.capLevelController=new n(this),f=new o(this),c=new bt(this),v=new Bt(this),g=r.contentSteeringController,m=g?new g(this):null,p=this.levelController=new hi(this,m),y=new vi(this),E=new Li(this.config),T=this.streamController=new xn(this,y,E);h.setStreamController(T),f.setStreamController(T);var S=[c,p,T];m&&S.splice(1,0,m),this.networkControllers=S;var L=[u,d,h,f,v,y];this.audioTrackController=this.createController(r.audioTrackController,S);var A=r.audioStreamController;A&&S.push(new A(this,y,E)),this.subtitleTrackController=this.createController(r.subtitleTrackController,S);var b=r.subtitleStreamController;b&&S.push(new b(this,y,E)),this.createController(r.timelineController,L),E.emeController=this.emeController=this.createController(r.emeController,L),this.cmcdController=this.createController(r.cmcdController,L),this.latencyController=this.createController(Ut,L),this.coreComponents=L,S.push(l);var D=l.onErrorOut;"function"==typeof D&&this.on(R.ERROR,D,l)}e.isMSESupported=function(){return Wi()},e.isSupported=function(){return Yi()},e.getMediaSource=function(){return je()};var t=e.prototype;return t.createController=function(e,t){if(e){var r=new e(this);return t&&t.push(r),r}return null},t.on=function(e,t,r){void 0===r&&(r=this),this._emitter.on(e,t,r)},t.once=function(e,t,r){void 0===r&&(r=this),this._emitter.once(e,t,r)},t.removeAllListeners=function(e){this._emitter.removeAllListeners(e)},t.off=function(e,t,r,i){void 0===r&&(r=this),this._emitter.off(e,t,r,i)},t.listeners=function(e){return this._emitter.listeners(e)},t.emit=function(e,t,r){return this._emitter.emit(e,t,r)},t.trigger=function(e,t){if(this.config.debug)return this.emit(e,e,t);try{return this.emit(e,e,t)}catch(t){if(P.error("An internal error happened while handling event "+e+'. Error message: "'+t.message+'". Here is a stacktrace:',t),!this.triggeringException){this.triggeringException=!0;var r=e===R.ERROR;this.trigger(R.ERROR,{type:b.OTHER_ERROR,details:D.INTERNAL_EXCEPTION,fatal:r,event:e,error:t}),this.triggeringException=!1}}return!1},t.listenerCount=function(e){return this._emitter.listenerCount(e)},t.destroy=function(){P.log("destroy"),this.trigger(R.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((function(e){return e.destroy()})),this.networkControllers.length=0,this.coreComponents.forEach((function(e){return e.destroy()})),this.coreComponents.length=0;var e=this.config;e.xhrSetup=e.fetchSetup=void 0,this.userConfig=null},t.attachMedia=function(e){P.log("attachMedia"),this._media=e,this.trigger(R.MEDIA_ATTACHING,{media:e})},t.detachMedia=function(){P.log("detachMedia"),this.trigger(R.MEDIA_DETACHING,void 0),this._media=null},t.loadSource=function(e){this.stopLoad();var t=this.media,r=this.url,i=this.url=T.buildAbsoluteURL(self.location.href,e,{alwaysNormalize:!0});this._autoLevelCapping=-1,this._maxHdcpLevel=null,P.log("loadSource:"+i),t&&r&&(r!==i||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(t)),this.trigger(R.MANIFEST_LOADING,{url:e})},t.startLoad=function(e){void 0===e&&(e=-1),P.log("startLoad("+e+")"),this.started=!0,this.networkControllers.forEach((function(t){t.startLoad(e)}))},t.stopLoad=function(){P.log("stopLoad"),this.started=!1,this.networkControllers.forEach((function(e){e.stopLoad()}))},t.resumeBuffering=function(){this.started&&this.networkControllers.forEach((function(e){"fragmentLoader"in e&&e.startLoad(-1)}))},t.pauseBuffering=function(){this.networkControllers.forEach((function(e){"fragmentLoader"in e&&e.stopLoad()}))},t.swapAudioCodec=function(){P.log("swapAudioCodec"),this.streamController.swapAudioCodec()},t.recoverMediaError=function(){P.log("recoverMediaError");var e=this._media;this.detachMedia(),e&&this.attachMedia(e)},t.removeLevel=function(e){this.levelController.removeLevel(e)},t.setAudioOption=function(e){var t;return null==(t=this.audioTrackController)?void 0:t.setAudioOption(e)},t.setSubtitleOption=function(e){var t;return null==(t=this.subtitleTrackController)||t.setSubtitleOption(e),null},o(e,[{key:"levels",get:function(){var e=this.levelController.levels;return e||[]}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(e){P.log("set currentLevel:"+e),this.levelController.manualLevel=e,this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(e){P.log("set nextLevel:"+e),this.levelController.manualLevel=e,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(e){P.log("set loadLevel:"+e),this.levelController.manualLevel=e}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(e){this.levelController.nextLoadLevel=e}},{key:"firstLevel",get:function(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)},set:function(e){P.log("set firstLevel:"+e),this.levelController.firstLevel=e}},{key:"startLevel",get:function(){var e=this.levelController.startLevel;return-1===e&&this.abrController.forcedAutoLevel>-1?this.abrController.forcedAutoLevel:e},set:function(e){P.log("set startLevel:"+e),-1!==e&&(e=Math.max(e,this.minAutoLevel)),this.levelController.startLevel=e}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(e){var t=!!e;t!==this.config.capLevelToPlayerSize&&(t?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=t)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping!==e&&(P.log("set autoLevelCapping:"+e),this._autoLevelCapping=e,this.levelController.checkMaxAutoUpdated())}},{key:"bandwidthEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimate():NaN},set:function(e){this.abrController.resetEstimator(e)}},{key:"ttfbEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimateTTFB():NaN}},{key:"maxHdcpLevel",get:function(){return this._maxHdcpLevel},set:function(e){Vt(e)&&this._maxHdcpLevel!==e&&(this._maxHdcpLevel=e,this.levelController.checkMaxAutoUpdated())}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}},{key:"minAutoLevel",get:function(){var e=this.levels,t=this.config.minAutoBitrate;if(!e)return 0;for(var r=e.length,i=0;i=t)return i;return 0}},{key:"maxAutoLevel",get:function(){var e,t=this.levels,r=this.autoLevelCapping,i=this.maxHdcpLevel;if(e=-1===r&&null!=t&&t.length?t.length-1:r,i)for(var a=e;a--;){var n=t[a].attrs["HDCP-LEVEL"];if(n&&n<=i)return a}return e}},{key:"firstAutoLevel",get:function(){return this.abrController.firstAutoLevel}},{key:"nextAutoLevel",get:function(){return this.abrController.nextAutoLevel},set:function(e){this.abrController.nextAutoLevel=e}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"mainForwardBufferInfo",get:function(){return this.streamController.getMainFwdBufferInfo()}},{key:"allAudioTracks",get:function(){var e=this.audioTrackController;return e?e.allAudioTracks:[]}},{key:"audioTracks",get:function(){var e=this.audioTrackController;return e?e.audioTracks:[]}},{key:"audioTrack",get:function(){var e=this.audioTrackController;return e?e.audioTrack:-1},set:function(e){var t=this.audioTrackController;t&&(t.audioTrack=e)}},{key:"allSubtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.allSubtitleTracks:[]}},{key:"subtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTrack:-1},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleTrack=e)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var e=this.subtitleTrackController;return!!e&&e.subtitleDisplay},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleDisplay=e)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(e){this.config.lowLatencyMode=e}},{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}}],[{key:"version",get:function(){return"1.5.15"}},{key:"Events",get:function(){return R}},{key:"ErrorTypes",get:function(){return b}},{key:"ErrorDetails",get:function(){return D}},{key:"DefaultConfig",get:function(){return e.defaultConfig?e.defaultConfig:si},set:function(t){e.defaultConfig=t}}]),e}();return wn.defaultConfig=void 0,wn}()}(!1)}}]); //# sourceMappingURL=4189.js.map