/*! JW Player version 8.36.2 Copyright (c) 2024, JW Player, All Rights Reserved This source code and its use and distribution is subject to the terms and conditions of the applicable license agreement. https://www.jwplayer.com/tos/ This product includes portions of other software. For the full text of licenses, see https://ssl.p.jwpcdn.com/player/v/8.36.2/notice.txt */ (self.webpackChunkjwplayer=self.webpackChunkjwplayer||[]).push([[98],{8377:(t,e,r)=>{"use strict";r.d(e,{M:()=>i,_:()=>n});const i=function(t,e){let r;const i=t.kind||"cc";return r=t.default||t.defaulttrack?"default":t._id||t.file||i+e,r},n=function(t,e){let r=t.label||t.name||t.language;return r||(r="CC",(e+=1)>1&&(r+=` [${e}]`)),{label:r,unknownCount:e}}},6103:(t,e,r)=>{"use strict";r.d(e,{VS:()=>g,xl:()=>f});var i=r(7477),n=r(2894),a=r(6886),s=r(7941),o=r(7387),l=r(2957),u=r(4446);const h=t=>{throw new u.rG(null,t)};const d=function(t){return t.map((t=>new i.Z(t.begin,t.end,t.text)))},c=function(t,e,i,a){let c,f,g=t.responseXML?t.responseXML.firstChild:null;if(g)for("xml"===(0,s.r1)(g)&&(g=g.nextSibling);g&&g.nodeType===g.COMMENT_NODE;)g=g.nextSibling;try{if(g&&"tt"===(0,s.r1)(g)){if(!t.responseXML)throw new Error("Empty XML response");c=function(t){t||h(306007);const e=[];let r=t.getElementsByTagName("p"),i=30;const n=t.getElementsByTagName("tt");if(null!=n&&n[0]){const t=parseFloat(n[0].getAttribute("ttp:frameRate")||"");isNaN(t)||(i=t)}r||h(306005),r.length||(r=t.getElementsByTagName("tt:p"),r.length||(r=t.getElementsByTagName("tts:p")));for(let n=0;n\s+<").replace(/(<\/?)tts?:/g,"$1").replace(//g,"\r\n");if(u){const t=a.getAttribute("begin")||"",r=a.getAttribute("dur")||"",n=a.getAttribute("end")||"",s={begin:(0,l.m9)(t,i),text:u};n?s.end=(0,l.m9)(n,i):r&&(s.end=(s.begin||0)+(0,l.m9)(r,i)),e.push(s)}}return e.length||h(306005),e}(t.responseXML),f=d(c),delete e.xhr,i(f)}else{const s=t.responseText;s.indexOf("WEBVTT")>=0?r.e(347).then(function(t){return r(2776).default}.bind(null,r)).catch((0,n.Jt)(301131)).then((t=>{const r=new t(window);f=[],r.oncue=function(t){f.push(t)},r.onflush=function(){delete e.xhr,i(f)},r.parse(s)})).catch((t=>{delete e.xhr,a((0,u.Mm)(null,u.Y7,t))})):(c=(0,o.Z)(s),f=d(c),delete e.xhr,i(f))}}catch(t){delete e.xhr,a((0,u.Mm)(null,u.Y7,t))}},f=function(t,e,r){t.xhr=(0,a.h)(t.file,(function(i){c(i,t,e,r)}),((t,e,i,n)=>{r((0,u.l9)(n,u.Y7))}))},g=function(t){t&&t.forEach((t=>{const e=t.xhr;e&&(e.onload=null,e.onreadystatechange=null,e.onerror=null,"abort"in e&&e.abort()),delete t.xhr}))}},7387:(t,e,r)=>{"use strict";r.d(e,{Z:()=>a});var i=r(2957);const n=t=>{const e={},r=t.split(/\r?\n/);let n=1;if(r[0].indexOf(" --\x3e ")>0&&(n=0),r.length>n+1&&r[n+1]){const t=r[n],a=t.indexOf(" --\x3e ");a>0&&(e.begin=(0,i.m9)(t.substr(0,a)),e.end=(0,i.m9)(t.substr(a+5)),e.text=r.slice(n+1).join("\r\n"))}return e};function a(t){const e=[],r=(t=(0,i.fy)(t)).split(/(\r?\n){2}/);for(let t=0;t{"use strict";r.d(e,{Z:()=>a});let i=window.VTTCue;const n=t=>{if("string"!=typeof t)return!1;return!!{start:!0,middle:!0,end:!0,left:!0,right:!0}[t.toLowerCase()]&&t.toLowerCase()};if(!i){const t="auto";i=function(e,r,i){const a=this;a.hasBeenReset=!1;let s="",o=!1,l=e,u=r,h=i,d=null,c="",f=!0,g=t,v="start",m=t,p=100,y="middle";Object.defineProperty(a,"id",{enumerable:!0,get:()=>s,set(t){s=`${t}`}}),Object.defineProperty(a,"pauseOnExit",{enumerable:!0,get:()=>o,set(t){o=Boolean(t)}}),Object.defineProperty(a,"startTime",{enumerable:!0,get:()=>l,set(t){if("number"!=typeof t)throw new TypeError("Start time must be set to a number.");l=t,this.hasBeenReset=!0}}),Object.defineProperty(a,"endTime",{enumerable:!0,get:()=>u,set(t){if("number"!=typeof t)throw new TypeError("End time must be set to a number.");u=t,this.hasBeenReset=!0}}),Object.defineProperty(a,"text",{enumerable:!0,get:()=>h,set(t){h=`${t}`,this.hasBeenReset=!0}}),Object.defineProperty(a,"region",{enumerable:!0,get:()=>d,set(t){d=t,this.hasBeenReset=!0}}),Object.defineProperty(a,"vertical",{enumerable:!0,get:()=>c,set(t){const e=(t=>"string"==typeof t&&(!!{"":!0,lr:!0,rl:!0}[t.toLowerCase()]&&t.toLowerCase()))(t);if(!1===e)throw new SyntaxError("An invalid or illegal string was specified.");c=e,this.hasBeenReset=!0}}),Object.defineProperty(a,"snapToLines",{enumerable:!0,get:()=>f,set(t){f=Boolean(t),this.hasBeenReset=!0}}),Object.defineProperty(a,"line",{enumerable:!0,get:()=>g,set(e){if("number"!=typeof e&&e!==t)throw new SyntaxError("An invalid number or illegal string was specified.");g=e,this.hasBeenReset=!0}}),Object.defineProperty(a,"lineAlign",{enumerable:!0,get:()=>v,set(t){const e=n(t);if(!e)throw new SyntaxError("An invalid or illegal string was specified.");v=e,this.hasBeenReset=!0}}),Object.defineProperty(a,"position",{enumerable:!0,get:()=>m,set(t){if(t<0||t>100)throw new Error("Position must be between 0 and 100.");m=t,this.hasBeenReset=!0}}),Object.defineProperty(a,"size",{enumerable:!0,get:()=>p,set(t){if(t<0||t>100)throw new Error("Size must be between 0 and 100.");p=t,this.hasBeenReset=!0}}),Object.defineProperty(a,"align",{enumerable:!0,get:()=>y,set(t){const e=n(t);if(!e)throw new SyntaxError("An invalid or illegal string was specified.");y=e,this.hasBeenReset=!0}}),a.displayState=void 0},i.prototype.getCueAsHTML=function(){return window.WebVTT.convertCueToDOMTree(window,this.text)}}const a=i},2728:(t,e,r)=>{"use strict";r.d(e,{Z:()=>a});var i=r(1643),n=r(6042);function a(t,e){let r,a=e;return{start(){this.stop(),r=window.setInterval((()=>{const e=t.getBandwidthEstimate();(0,n.qh)(e)&&(a=e,t.trigger(i.qG,{bandwidthEstimate:a}))}),1e3)},stop(){clearInterval(r)},getEstimate:()=>a}}},548:(t,e,r)=>{"use strict";r.d(e,{Zv:()=>i,i0:()=>a,pR:()=>n});const i=1,n=i+1,a=25},4506:(t,e,r)=>{"use strict";r.d(e,{Z:()=>i});const i=t=>({bitrate:t.bitrate,label:t.label,width:t.width,height:t.height})},3328:(t,e,r)=>{"use strict";r.d(e,{Z:()=>R});var i=r(6103),n=r(8377);const a={TIT2:"title",TT2:"title",WXXX:"url",TPE1:"artist",TP1:"artist",TALB:"album",TAL:"album"},s=(t,e)=>{const r=t.length;let i,n,a,s="",o=e||0;for(;o>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:s+=String.fromCharCode(i);break;case 12:case 13:n=t[o++],s+=String.fromCharCode((31&i)<<6|63&n);break;case 14:n=t[o++],a=t[o++],s+=String.fromCharCode((15&i)<<12|(63&n)<<6|63&a)}return s},o=t=>{const e=(t=>{let e="0x";for(let r=0;r>1|(8323072&e)>>2|(2130706432&e)>>3},l=t=>{const e={};if(!("value"in t)&&"data"in t&&t.data instanceof ArrayBuffer){const e=new Uint8Array(t.data);let r=e.length;t={value:{key:"",data:""}};let i=10;for(;i<14&&i0){const r=s(e.subarray(n,n+=l),0);if("PRIV"===t.value.key){if("com.apple.streaming.transportStreamTimestamp"===r){const r=1&o(e.subarray(n,n+=4)),i=o(e.subarray(n,n+=4))+(r?4294967296:0);t.value.data=i}else t.value.data=s(e,n+1);t.value.info=r}else t.value.info=r,t.value.data=s(e,n+1)}else{const r=e[n];t.value.data=1===r||2===r?((t,e)=>{const r=t.length-1;let i="",n=e||0;for(;n{null!=e&&e.length&&(0,d.S6)(e,(function(e){const i=e._id||"";if(r&&(e._id=void 0),!u.Browser.ie&&!u.Browser.safari||!t||!/^(native|subtitle|cc)/.test(i)){if(u.Browser.ie&&"disabled"===e.mode||(e.mode="disabled",e.mode="hidden"),e.cues)for(let t=e.cues.length;t--;)e.removeCue(e.cues[t]);e.embedded||(e.mode="disabled"),e.inuse=!1}}))},g=t=>/^native(?:captions|subtitles)/.test(t),v=t=>"captions"===t||"subtitles"===t,m=function(t){const e=t.target,{activeCues:r,cues:i}=e,n=e._id,a=this._cues,s=this._activeCues;if(null!=i&&i.length){const t=a[n];a[n]=Array.prototype.slice.call(i),this.parseNativeID3Cues(i,t)}else delete a[n];if(null!=r&&r.length){const t=s[n],e=s[n]=Array.prototype.slice.call(r);this.triggerActiveCues(e,t)}else delete s[n]},p=(t,e,r)=>{if(u.Browser.ie){let i=r;(t||"metadata"===e.kind)&&(i=new window.TextTrackCue(r.startTime,r.endTime,r.text),r.value&&(i.value=r.value)),((t,e)=>{const r=[],i=t.mode;t.mode="hidden";const n=t.cues;if(n)for(let i=n.length-1;i>=0&&n[i].startTime>e.startTime;i--)r.unshift(n[i]),t.removeCue(n[i]);try{t.addCue(e),r.forEach((e=>t.addCue(e)))}catch(t){c.error(t)}t.mode=i})(e,i)}else try{e.addCue(r)}catch(t){c.error(t)}},y=function(t){const e=this._textTracks,r=this._tracksById;if(t.length>e.length)return!0;for(let e=0;et.startTime===e.startTime&&t.endTime===e.endTime&&t.text===e.text&&t.data===e.data&&JSON.stringify(t.value)===JSON.stringify(e.value),L=t=>{const e=l(t);return{metadataType:"id3",metadataTime:t.startTime,metadata:e}},R={_itemTracks:null,_textTracks:null,_currentTextTrackIndex:-1,_tracksById:null,_cuesByTrackId:null,_cachedVTTCues:null,_metaCuesByTextTime:null,_unknownCount:0,_activeCues:null,_cues:null,textTrackChangeHandler:null,addTrackHandler:null,cueChangeHandler:null,renderNatively:!1,_initTextTracks(){this._textTracks=[],this._tracksById={},this._metaCuesByTextTime={},this._cuesByTrackId={},this._cachedVTTCues={},this._cues={},this._activeCues={},this._unknownCount=0},addTracksListener(t,e,r){t&&(this.removeTracksListener(t,e,r),this.instreamMode||(t.addEventListener?t.addEventListener(e,r):t[`on${e}`]=r))},removeTracksListener(t,e,r){t&&(t.removeEventListener&&r?t.removeEventListener(e,r):t[`on${e}`]=null)},clearTracks(){(0,i.VS)(this._itemTracks);const{_tracksById:t}=this;if(t&&Object.keys(t).forEach((e=>{if(0===e.indexOf("nativemetadata")){const r=t[e];this.cueChangeHandler&&r.removeEventListener("cuechange",this.cueChangeHandler),f(this.renderNatively,[r],!0)}})),this._itemTracks=null,this._textTracks=null,this._tracksById=null,this._cuesByTrackId=null,this._metaCuesByTextTime=null,this._unknownCount=0,this._currentTextTrackIndex=-1,this._activeCues={},this._cues={},this.renderNatively){const t=this.video.textTracks;this.textTrackChangeHandler&&this.removeTracksListener(t,"change",this.textTrackChangeHandler),f(this.renderNatively,t,!0)}},clearMetaCues(){const{_tracksById:t,_cachedVTTCues:e}=this;t&&e&&Object.keys(t).forEach((r=>{if(0===r.indexOf("nativemetadata")){const i=t[r];f(this.renderNatively,[i],!1),i.mode="hidden",i.inuse=!0,i._id&&(e[i._id]={})}}))},clearCueData(t){const e=this._cachedVTTCues;null!=e&&e[t]&&(e[t]={},this._tracksById&&(this._tracksById[t].data=[]))},disableTextTrack(){const t=this.getCurrentTextTrack();if(t){t.mode="disabled";const e=t._id;(e&&g(e)||this.renderNatively&&u.OS.iOS)&&(t.mode="hidden")}},enableTextTrack(){const t=this.getCurrentTextTrack();t&&(t.mode="showing")},getCurrentTextTrack(){if(this._textTracks)return this._textTracks[this._currentTextTrackIndex]},getSubtitlesTrack(){return this._currentTextTrackIndex},addTextTracks(t){var e;const r=[];return t?(this._textTracks||this._initTextTracks(),t.forEach((t=>{if(t.includedInManifest||t.kind&&!v(t.kind))return;const e=this._createTrack(t);this._addTrackToList(e),r.push(e),t.file&&(t.data=[],(0,i.xl)(t,(t=>{e.sideloaded=!0,this.addVTTCuesToTrack(e,t)}),(t=>{this.trigger(h.cM,t)})))})),null!=this&&null!=(e=this._textTracks)&&e.length&&this.trigger(h.jt,{tracks:this._textTracks}),r):r},setTextTracks(t){var e;if(this._currentTextTrackIndex=-1,t){if(this._textTracks){const t=this._tracksById;this._activeCues={},this._cues={},this._unknownCount=0,this._textTracks=this._textTracks.filter((e=>{const r=e._id;return this.renderNatively&&r&&g(r)?(delete t[r],!1):(e.name&&0===e.name.indexOf("CC")&&this._unknownCount++,0===r.indexOf("nativemetadata")&&"com.apple.streaming"===e.inBandMetadataTrackDispatchType&&delete t[r],!0)}),this)}else this._initTextTracks();if(t.length){let e=0;const r=t.length,i=this._tracksById,a=this._cuesByTrackId;for(;e{t.mode=t.embedded?"hidden":"disabled"})),this._currentTextTrackIndex===t-1)return;this.disableTextTrack(),this._currentTextTrackIndex=t-1;const e=this.getCurrentTextTrack();e&&(e.mode="showing"),this.trigger(h.UF,{currentTrack:this._currentTextTrackIndex+1,tracks:this._textTracks})},createCue:(t,e,r)=>new(window.VTTCue||window.TextTrackCue)(t,Math.max(e||0,t+.25),r),addVTTCue(t,e){this._tracksById||this._initTextTracks();const r=t.track?t.track:`native${t.type}`;let i=this._tracksById[r];const n="captions"===t.type?"CC":"ID3 Metadata",a=t.cue;if(!i){const e={kind:t.type,_id:r,label:n,default:!1};this.renderNatively||"metadata"===e.kind?(i=this._createTrack(e),i.embedded=!0,this.setTextTracks(this.video.textTracks)):i=this.addTextTracks([e])[0]}if(this._cacheVTTCue(i,a,e)){const t=this.renderNatively||"metadata"===i.kind;return t?p(t,i,a):i.data.push(a),a}return null},addVTTCuesToTrack(t,e){var r,i;if(!this.renderNatively)return;const n=t._id,a=this._tracksById;let s=this._cuesByTrackId;const o=a[n];if(!o)return s||(s=this._cuesByTrackId={}),void(s[n]={cues:e,loaded:!1});if(null!=(r=s)&&null!=(i=r[n])&&i.loaded)return;let l;for(s[n]={cues:e,loaded:!0};l=e.shift();)p(this.renderNatively,o,l)},parseNativeID3Cues(t,e){const r=t[t.length-1];if(e&&e.length===t.length&&(r._parsed||S(e[e.length-1],r)))return;const i=[],n=[];let a=-1,s=-1,o=-1;for(let e=0;e0)for(let e=0;e{const e=L(t);this.trigger(h.O1,e)}))},triggerActiveCues(t,e){const r=t.filter((t=>{if(null!=e&&e.some((e=>S(t,e))))return!1;if(t.data)return!0;const r=t.text?(t=>{let e;try{e=JSON.parse(t.text)}catch(t){return null}const r={metadataType:e.metadataType,metadataTime:t.startTime,metadata:e};return e.programDateTime&&(r.programDateTime=e.programDateTime),r})(t):null;if(r)"emsg"===r.metadataType&&(r.metadata=r.metadata||{},r.metadata.messageData=t.value),this.trigger(h.rx,r);else if(t.value)return!0;return!1}));r.length&&r.forEach((t=>{const e=L(t);this.trigger(h.rx,e)}))},ensureMetaTracksActive(){const t=this.video.textTracks,e=t.length;for(let r=0;rt.embedded||"subs"===t.groupid));this._initTextTracks();const e=this._tracksById;t.forEach((t=>{e[t._id]=t})),this._textTracks=t}}},9601:(t,e,r)=>{"use strict";r.d(e,{E:()=>n,Z:()=>a});var i=r(4446);const n=t=>t>=400&&t<600?t:6;function a(t,e,r){let a=t+1e3,s=i.ul;return e>0?(403===e&&(s=i.H4),a+=n(e)):"http:"===`${r}`.substring(0,5)&&"https:"===document.location.protocol?a+=12:0===e&&(a+=11),{code:a,key:s}}},5099:(t,e,r)=>{"use strict";r.d(e,{Z:()=>n});const i=(t,e,r)=>{const i=new Error(r);return i.name=t,i.code=e,i};function n(t){return new Promise((function(e,r){if(t.paused)return r(i("NotAllowedError",0,"play() failed."));let n;const a=function(t){if(n(),"playing"!==t.type){const e=`The play() request was interrupted by a "${t.type}" event.`;return"error"===t.type?r(i("NotSupportedError",9,e)):r(i("AbortError",20,e))}e()},s=function(){t.addEventListener("playing",a),t.addEventListener("abort",a),t.addEventListener("error",a),t.addEventListener("pause",a)};n=function(){t.removeEventListener("play",s),t.removeEventListener("playing",a),t.removeEventListener("pause",a),t.removeEventListener("abort",a),t.removeEventListener("error",a)},t.addEventListener("play",s)}))}},5256:(t,e,r)=>{"use strict";r.d(e,{_T:()=>i,c3:()=>o,ji:()=>a});const i=t=>Math.floor(t/1e3),n=(t,e)=>{let r=null;if(e&&t){const n=Object.keys(t);if(n.length){const a=((t,e)=>{let r,i=null,n=1/0;return t.forEach((t=>{r=Math.abs(parseFloat(t)-e),r{if(!t)return"";const a=t.bitrate||t.bandwidth;return n(e,a)||((t,e,r)=>{if(!t&&!e)return"";let n="",a="";return e&&(a=`${i(e)} kbps`,n=a),t&&(n=`${t}p`,e&&r&&(n+=` (${a})`)),n})(t.height,a,r)},s=function(t,e){return t.some((function(t){let r;for(let i=0;i!!Array.isArray(t)&&s(t,["height","bitrate","bandwidth"])},686:(t,e,r)=>{"use strict";r.d(e,{s:()=>n,v:()=>a});const i=t=>void 0===t?120:Math.max(t,0),n=(t,e)=>t!==1/0&&Math.abs(t)>=Math.max(i(e),0),a=(t,e)=>{let r="VOD";return t===1/0?r="LIVE":t<0&&(r=n(t,i(e))?"DVR":"LIVE"),r}},3949:(t,e,r)=>{"use strict";r.d(e,{Z:()=>n});var i=r(9974);const n={container:null,volume(t){this.video.volume=Math.min(Math.max(0,t/100),1)},mute(t){this.video.muted=Boolean(t),this.video.muted||this.video.removeAttribute("muted")},getContainer(){return this.container},setContainer(t){this.container=t,this.video.parentNode!==t&&t.appendChild(this.video)},removeFromContainer(){const{container:t,video:e}=this;this.container=null,t&&t===e.parentNode&&t.removeChild(e)},remove(){this.stop(),this.destroy(),this.removeFromContainer()},atEdgeOfLiveStream(){if(!this.isLive())return!1;return(0,i.Z)(this.video.buffered)-this.video.currentTime<=2}}},186:(t,e,r)=>{"use strict";r.d(e,{Z:()=>i});const i={_eventsOn(){},_eventsOff(){},attachMedia(){this._eventsOn()},detachMedia(){return this._eventsOff()}}},8702:(t,e,r)=>{"use strict";r.d(e,{Z:()=>s});var i=r(1643),n=r(1261),a=r(5678);const s={canplay(){this.renderNatively&&this.setTextTracks(this.video.textTracks),this.trigger(i.Jl)},play(){this.stallTime=-1,this.video.paused||this.state===i._5||this.state===i.r0||this.setState(i.ik)},loadedmetadata(){const t={metadataType:"media",duration:this.getDuration(),height:this.video.videoHeight,width:this.video.videoWidth,seekRange:this.getSeekRange()},e=this.drmUsed;e&&(t.drm=e),this.trigger(i.rx,t)},timeupdate(){const t=this.video.currentTime,e=this.getCurrentTime(),r=this.getDuration();if(isNaN(r))return;this.seeking||this.video.paused||this.state!==i.nQ&&this.state!==i.ik||this.stallTime===t||(this.stallTime=-1,this.setState(i.r0),this.trigger(i.Gj));const n={position:e,duration:r,currentTime:t,seekRange:this.getSeekRange(),metadata:{currentTime:t},absolutePosition:(0,a.e)(this)},s=this.getLiveLatency();if(null!==s&&(n.latency=s,this.getTargetLatency)){const t=this.getTargetLatency();null!==t&&(n.targetLatency=t)}(this.state===i.r0||this.seeking&&this.state!==i.bc)&&this.trigger(i.R2,n)},click(t){this.trigger(i.ot,t)},volumechange(){const t=this.video;this.trigger(i.yH,{volume:Math.round(100*t.volume)}),this.trigger(i.gy,{mute:t.muted})},seeking(){if(this.state===i.ik){const t=this.video.buffered.length?this.video.buffered.start(0):-1;if(this.video.currentTime===t)return}else if(this.state===i.bc)return;this.seeking=!0},seeked(){this.seeking&&(this.seeking=!1,this.trigger(i.aQ))},playing(){-1===this.stallTime&&this.setState(i.r0),this.trigger(i.Gj)},pause(){this.state!==i.xQ&&(this.video.ended||this.video.error||this.video.currentTime!==this.video.duration&&this.setState(i._5))},progress(){const t=this.getDuration();if(t<=0||t===1/0)return;const e=this.video.buffered;if(!e||0===e.length)return;const r=(0,n.v)(e.end(e.length-1)/t,0,1);this.trigger(i.uT,{bufferPercent:100*r,position:this.getCurrentTime(),duration:t,currentTime:this.video.currentTime,seekRange:this.getSeekRange(),absolutePosition:(0,a.e)(this)})},ratechange(){this.trigger(i.TJ,{playbackRate:this.video.playbackRate})},ended(){this.state!==i.bc&&this.state!==i.xQ&&this.trigger(i.Ms)}}},5678:(t,e,r)=>{"use strict";r.d(e,{e:()=>i});const i=t=>{var e;const r=1e3*(null==t||null==(e=t.video)?void 0:e.currentTime);return null!=t&&t.startDateTime&&r?new Date(t.startDateTime+r):null}},9974:(t,e,r)=>{"use strict";function i(t){return t&&t.length?t.end(t.length-1):0}r.d(e,{Z:()=>i})},9054:(t,e,r)=>{"use strict";r.r(e),r.d(e,{default:()=>W});var i={};r.r(i),r.d(i,{debug:()=>g,error:()=>y,info:()=>m,log:()=>v,warn:()=>p});var n=r(6042);class a{constructor(t,e,r,i){this.video=t,this.hlsjs=r,this.videoListeners=e,this.hlsjsListeners=i}on(){this.off(),(0,n.S6)(this.videoListeners,((t,e)=>{this.video.addEventListener(e,t,!1)})),(0,n.S6)(this.hlsjsListeners,((t,e)=>{this.hlsjs.on(e,t)}))}off(){(0,n.S6)(this.videoListeners,((t,e)=>{this.video.removeEventListener(e,t)})),(0,n.S6)(this.hlsjsListeners,((t,e)=>{this.hlsjs.off(e,t)}))}}var s=r(5256),o=r(8348);const l=t=>t.audioGroupIds?t.audioGroupIds[t._urlId||t.urlId]:void 0,u=(t,e)=>{const r=(0,s.c3)(t),i=(0,n.UI)(t,((t,i)=>({label:(0,s.ji)(t,e,r),level_id:t.id,hlsjsIndex:i,bitrate:t.bitrate,height:t.height,width:t.width,audioGroupId:l(t)})));return i.sort(((t,e)=>t.height&&e.height&&t.height!==e.height?e.height-t.height:(e.bitrate||0)-(t.bitrate||0))),i.length>1&&i.unshift({label:"Auto",level_id:"auto",hlsjsIndex:-1}),i},h=(t,e)=>Math.max(0,(0,n.cq)(e,(0,n.sE)(e,(e=>e.hlsjsIndex===t)))),d=(t,e,r,i=t.length)=>{const n=(()=>{try{return window.devicePixelRatio}catch(t){}return 1})();e*=n,r*=n,o.OS.tizen&&(e=1/0,r=1/0);for(let n=0;n=e||i.height>=r)&&(a=i,!(s=t[n+1])||a.width!==s.width||a.height!==s.height))return n}var a,s;return i-1};const c=r(8494).Z.logger.child("providers/hlsjs"),f=t=>c[t].bind(c),g=f("debug"),v=f("log"),m=f("info"),p=f("warn"),y=f("error");var T=r(548),E=r(5083);const S=(t,e,r)=>({xhrSetup(i,n){if(t&&(i.withCredentials=!0),e){const t=n.indexOf("?")>0?"&token=":"?token=";i.open("GET",n+t+e,!0)}"function"==typeof r&&r(i,n)},fetchSetup(r,i){if(e){const t=r.url.indexOf("?")>0?"&token=":"?token=";r.url=r.url+t+e}return t&&(i.credentials="include"),new Request(r.url,i)}});var L=r(9601),R=r(4446);let k=function(t){return t[t.BASE_ERROR=23e4]="BASE_ERROR",t[t.ERROR_LIVE_STREAM_DOWN_OR_ENDED=230001]="ERROR_LIVE_STREAM_DOWN_OR_ENDED",t[t.MANIFEST_ERROR_CONNECTION_LOST=232002]="MANIFEST_ERROR_CONNECTION_LOST",t[t.ERROR_CONNECTION_LOST=230002]="ERROR_CONNECTION_LOST",t[t.MANIFEST_PARSING_ERROR=232600]="MANIFEST_PARSING_ERROR",t[t.LEVEL_EMPTY_ERROR=232631]="LEVEL_EMPTY_ERROR",t[t.MANIFEST_INCOMPATIBLE_CODECS_ERROR=232632]="MANIFEST_INCOMPATIBLE_CODECS_ERROR",t[t.FRAG_PARSING_ERROR=233600]="FRAG_PARSING_ERROR",t[t.FRAG_DECRYPT_ERROR=233650]="FRAG_DECRYPT_ERROR",t[t.BUFFER_STALLED_ERROR=234001]="BUFFER_STALLED_ERROR",t[t.BUFFER_APPEND_ERROR=234002]="BUFFER_APPEND_ERROR",t[t.PROTECTED_CONTENT_ACCESS_ERROR=232403]="PROTECTED_CONTENT_ACCESS_ERROR",t}({});const A=t=>{if(t){if(/^frag/.test(t))return 2e3;if(/^(manifest|level|audioTrack)/.test(t))return 1e3;if(/^key/.test(t))return 4e3}return 0};var b=r(328),D=r(3949),_=r(186),C=r(3328);class w extends b.ZP{}Object.assign(w.prototype,D.Z,_.Z,C.Z);const I=w;var x=r(4506),P=r(3343),O=r(686),M=r(1643),F=r(5004),N=r(8702),U=r(386),B=r(5099),G=r(2728),H=r(7477),K=r(1384);const V=(t,e,r)=>{const i=t.sources[0];return void 0!==i[r]?i[r]:void 0!==t[r]?t[r]:e[r]};var j=r(4560);const Y=function(t){const{MEDIA_ATTACHED:e,MEDIA_DETACHED:r,MANIFEST_PARSED:s,LEVEL_LOADED:c,LEVEL_UPDATED:f,LEVEL_PTS_UPDATED:g,FRAG_CHANGED:v,FRAG_LOADED:m,LEVEL_SWITCHED:y,FRAG_PARSING_METADATA:b,BUFFER_APPENDED:D,BUFFER_CODECS:_,FRAG_BUFFERED:C,INIT_PTS_FOUND:w,NON_NATIVE_TEXT_TRACKS_FOUND:j,CUES_PARSED:Y,AUDIO_TRACKS_UPDATED:W,ERROR:q}=t.Events,{MEDIA_ERROR:X,NETWORK_ERROR:z}=t.ErrorTypes,Q=function(t){const{NETWORK_ERROR:e}=t.ErrorTypes,{MANIFEST_PARSING_ERROR:r,LEVEL_EMPTY_ERROR:i,MANIFEST_INCOMPATIBLE_CODECS_ERROR:n,FRAG_PARSING_ERROR:a,FRAG_DECRYPT_ERROR:s,BUFFER_STALLED_ERROR:o,BUFFER_APPEND_ERROR:l,INTERNAL_EXCEPTION:u,MANIFEST_LOAD_ERROR:h,MANIFEST_LOAD_TIMEOUT:d,LEVEL_LOAD_ERROR:c,LEVEL_LOAD_TIMEOUT:f,FRAG_LOAD_ERROR:g,FRAG_LOAD_TIMEOUT:v,BUFFER_SEEK_OVER_HOLE:m,BUFFER_NUDGE_ON_STALL:p}=t.ErrorDetails,y=[h,d,r,n,c,f,g,v],T=[o,m,p],E=[i,c,f];return function(t){const{details:h,response:d,type:c}=t;let f=t.fatal,g=y.indexOf(h)<0;const v=T.indexOf(h)>=0;let m=E.indexOf(h)>=0,p=R.ul,S=k.BASE_ERROR;switch(h){case r:S=k.MANIFEST_PARSING_ERROR;break;case i:S=k.LEVEL_EMPTY_ERROR;break;case n:p=R.zO,S=k.MANIFEST_INCOMPATIBLE_CODECS_ERROR;break;case a:S=k.FRAG_PARSING_ERROR;break;case s:S=k.FRAG_DECRYPT_ERROR;break;case o:S=k.BUFFER_STALLED_ERROR;break;case l:S=k.BUFFER_APPEND_ERROR;break;case u:S=239e3;break;default:c===e&&(!1===navigator.onLine?(g=!1,f="manifestLoadError"===h,m=!1,S=f?k.MANIFEST_ERROR_CONNECTION_LOST:k.ERROR_CONNECTION_LOST,p=R.MD):/TimeOut$/.test(h)?S=k.BASE_ERROR+1001+A(h):d&&(({code:S,key:p}=(0,L.Z)(k.BASE_ERROR,d.code,t.url)),S+=A(h)))}return{key:p,code:S,recoverable:g,stalling:v,suppressLevel:m,fatal:f,error:t}}}(t);return class L extends I{constructor(t,e,r){var i;super(),this.bandwidthMonitor=(0,G.Z)(this,e.bandwidthEstimate),this.bitrateSelection=e.bitrateSelection,this.bufferStallTimeout=1e3,this.connectionTimeoutDuration=1e4,this.dvrEnd=null,this.dvrPosition=null,this.dvrUpdatedTime=0,this.eventHandler=null,this.hlsjs=null,this.hlsjsConfig=null,this.hlsjsOptions=null,this.jwConfig=e,this.lastPosition=0,this.maxRetries=3,this.playerId=t,this.processPlaylistMetadata=P.q,this.recoveryInterval=5e3,this.renderNatively=(i=e.renderCaptionsNatively,!(!o.OS.iOS&&!o.Browser.safari)||o.Browser.chrome&&i),this.savedVideoProperties=!1,this.seeking=!1,this.staleManifestDurationMultiplier=3e3,this.state=M.bc,this.supports=L.supports,this.supportsPlaybackRate=!0,this.video=r,this.playerWidth=0,this.playerHeight=0,this.playerStretching=null,this.capLevels=!1,this.levelDuration=0,this.live=!1,this.liveEdgePosition=null,this.liveEdgeUpdated=0,this.staleManifestTimeout=-1,this.connectionTimeout=-1,this.programDateSyncTime=0,this.retryCount=0,this.stallTime=-1,this.jwLevels=[],this.audioTracks=null,this.audioTracksArray=null,this.resetLifecycleVariables()}resetLifecycleVariables(){this.resetRecovery(),this.stopStaleTimeout(),this.stopConnectionTimeout(),this.stallTime=-1,this.streamBitrate=-1,this.videoFound=!1,this.videoHeight=0,this.src=null,this.currentHlsjsLevel=null,this.currentAudioTrackIndex=null,this.currentJwItem=null,this.jwLevels=[],this.audioTracks=null,this.audioTracksArray=null,this.lastRecoveryTime=null,this.lastEndSn=null,this.levelDuration=0,this.live=!1,this.liveEdgePosition=null,this.liveEdgeUpdated=0,this.liveEdgeSn=-1,this.livePaused=!1,this.recoveringMediaError=!1,this.recoveringNetworkError=!1,this.streamType="VOD",this.lastProgramDateTime=0,this.programDateSyncTime=0}resetRecovery(){this.retryCount=0}stopStaleTimeout(){clearTimeout(this.staleManifestTimeout),this.staleManifestTimeout=-1}stopConnectionTimeout(){clearTimeout(this.connectionTimeout),this.connectionTimeout=-1}startConnectionTimeout(){-1===this.connectionTimeout&&(this.connectionTimeout=window.setTimeout((()=>{navigator.onLine?this.hlsjs.startLoad():this.handleError(k.ERROR_CONNECTION_LOST,null,R.MD)}),this.connectionTimeoutDuration))}initHlsjs(e){var r;const s=this.jwConfig.hlsjsConfig,o=Boolean(this.jwConfig.cmcd),l=Boolean(this.hlsjsOptions);let u=null==(r=this.hlsjsOptions)?void 0:r.cmcd;!l&&o&&(u=Object.assign({},{contentId:null==e?void 0:e.mediaid},this.jwConfig.cmcd));const h={cmcd:u,withCredentials:Boolean(V(e,this.jwConfig,"withCredentials")),aesToken:V(e,this.jwConfig,"aestoken"),renderTextTracksNatively:this.renderNatively,onXhrOpen:e.sources[0].onXhrOpen,liveSyncDuration:V(e,this.jwConfig,"liveSyncDuration"),hlsjsConfig:s};if(this.setupSideloadedTracks(e.tracks),this.capLevels=!e.stereomode,this.hlsjs&&(0,n.wB)(this.hlsjsOptions)(h))return;this.hlsjsOptions=h,this.restoreVideoProperties(),this.stopStaleTimeout(),this.stopConnectionTimeout(),this.hlsjsConfig=function(t){const{withCredentials:e,aesToken:r,renderTextTracksNatively:a,onXhrOpen:s,liveSyncDuration:o,hlsjsConfig:l,cmcd:u}=t,h=(0,n.ei)(l||{},["liveSyncDuration","liveSyncDurationCount","liveMaxLatencyDuration","liveMaxLatencyDurationCount","liveBackBufferLength","backBufferLength","loader","pLoader","fLoader","fragLoadingMaxRetry","fragLoadingRetryDelay","enableWorker","debug"]),d={autoStartLoad:!1,capLevelToPlayerSize:!1,captionsTextTrack1Label:"",captionsTextTrack2Label:"",captionsTextTrack3Label:"",captionsTextTrack4Label:"",captionsTextTrack1LanguageCode:"",captionsTextTrack2LanguageCode:"",captionsTextTrack3LanguageCode:"",captionsTextTrack4LanguageCode:"",debug:i,fragLoadingMaxRetry:2,fragLoadingRetryDelay:4e3,maxMaxBufferLength:T.i0,renderTextTracksNatively:a,startLevel:-1,testBandwidth:!1};u&&(d.cmcd={sessionId:u.sessionId,contentId:u.contentId,useHeaders:u.useHeaders});const{liveSyncDurationCount:c,liveMaxLatencyDurationCount:f,liveMaxLatencyDuration:g}=h;return void 0!==c||void 0!==f?(h.liveSyncDuration=h.liveMaxLatencyDuration=void 0,h.liveSyncDurationCount=(0,n.xV)(c)?c:1/0,h.liveMaxLatencyDurationCount=(0,n.xV)(f)?f:1/0):void 0===o&&void 0===g||(h.liveSyncDurationCount=h.liveMaxLatencyDurationCount=void 0,d.liveSyncDuration=(0,E.G0)(o),h.liveMaxLatencyDuration=(0,n.xV)(g)?g:1/0),e||r||s?Object.assign({},d,S(e,r,s),h):Object.assign({},d,h)}(h);const d=Object.assign({},this.hlsjsConfig),c=this.bandwidthMonitor.getEstimate();(0,n.qh)(c)&&(d.abrEwmaDefaultEstimate=c),d.appendErrorMaxRetry=1,this.hlsjs=new t(d),this.eventHandler=new a(this.video,this.createVideoListeners(),this.hlsjs,this.createHlsjsListeners())}init(t){this.destroy(),this.initHlsjs(t)}preload(t){"metadata"===t.preload&&(this.maxBufferLength=T.Zv),this.load(t)}load(t){const{hlsjs:e,video:r,src:i}=this;if(!e)return;const n=t.sources[0].file,a=n.url&&"string"==typeof n.url?n.url:n;if(i===a&&this.videoSrc===r.src)return void(this.maxBufferLength=T.i0);let s=t.starttime||-1;s<-1&&(s=this.lastPosition),this.initHlsjs(t),this.currentJwItem=t,this.src=a,this.videoHeight=0,this._eventsOn(),e.config.startPosition=s,e.loadSource(a),e.attachMedia(r),this.videoSrc=r.src}restartStream(t){const e=Object.assign({},this.currentJwItem);t?e.starttime=t:delete e.starttime,this.src=null,this._clearNonNativeCues(),this.clearMetaCues(),this.clearTracks(),this.init(e),this.load(e),delete e.starttime}play(){return this.livePaused&&(this.livePaused=!1,this.restartStream()),this.video.play()||(0,B.Z)(this.video)}pause(){this.stopConnectionTimeout(),this.live&&"LIVE"===this.streamType&&!this.livePaused&&this.livePause(),this.video.pause()}livePause(){this.hlsjs&&(this.livePaused=!0,this.hlsjs.stopLoad(),this.stopStaleTimeout())}stop(){this.clearTracks(),this.hlsjs&&(this._eventsOff(),this.hlsjs.stopLoad()),this.pause(),this.setState(M.bc)}seek(t){const e=this.getDuration();if(!e||e===1/0||(0,n.i2)(e))return;this.stopStaleTimeout(),this.stopConnectionTimeout();let r=this.dvrEnd&&t<0?this.dvrEnd+t:t;const i=this.getSeekRange();if("DVR"===this.streamType&&null!==this.dvrEnd&&(this.dvrPosition=r-this.dvrEnd,t<0)){r+=Math.min(12,((0,F.z)()-this.dvrUpdatedTime)/1e3)}this.seeking=!0;const a=this.video.currentTime;this.trigger(M.NZ,{position:this.getCurrentTime(),offset:r,duration:e,currentTime:a,seekRange:i,metadata:{currentTime:a}}),this.video.currentTime=r;const s=this.video.currentTime,o={position:this.getCurrentTime(),duration:e,currentTime:s,seekRange:i,metadata:{currentTime:s}};this.trigger("time",o)}getCurrentQuality(){let t=0;return this.hlsjs&&!this.hlsjs.autoLevelEnabled&&(t=h(this.hlsjs.manualLevel,this.jwLevels)),t}getQualityLevels(){return(0,n.UI)(this.jwLevels,(t=>(0,x.Z)(t)))}getCurrentAudioTrack(){return(0,n.hj)(this.currentAudioTrackIndex)?this.currentAudioTrackIndex:-1}getAudioTracks(){return this.audioTracks||[]}getCurrentTime(){return this.live&&"DVR"===this.streamType?(this.dvrPosition||this.updateDvrPosition(this.getSeekRange()),this.dvrPosition):this.video.currentTime}getDuration(){if(this.live&&this.currentJwItem){const t=this.levelDuration,e=this.currentJwItem.minDvrWindow;return(0,O.s)(t,e)?(this.streamType="DVR",-t):(this.streamType="LIVE",1/0)}return this.streamType="VOD",this.video.duration}getCurrentHlsjsLevel(){let t=0;const{hlsjs:e}=this;return e&&(t=e.streamController.loadedmetadata&&e.currentLevel>0?e.currentLevel:e.firstLevel),t}getName(){return{name:"hlsjs"}}getPlaybackRate(){return this.video.playbackRate}getSeekRange(){const{levelDuration:t,video:e}=this,{seekable:r,duration:i}=e,a=r.length?Math.max(r.end(0),r.end(r.length-1)):i;return(0,n.i2)(i)?{start:0,end:0}:{start:Math.max(0,a-t),end:a}}getBandwidthEstimate(){const{hlsjs:t}=this;return t?t.bandwidthEstimate:null}getLiveLatency(){let t=null;if(this.live&&null!==this.liveEdgePosition){const e=(0,F.z)();t=this.liveEdgePosition+(e-this.liveEdgeUpdated)/1e3-this.video.currentTime;const r=this.lastProgramDateTime;if(r){const i=e/1e3-(r/1e3+(this.video.currentTime-this.programDateSyncTime))-t;i>0&&i<10&&(t+=i)}}return t}getTargetLatency(){return this.hlsjs&&this.hlsjs.targetLatency||null}setCurrentQuality(t){if(t<0)return;const e=((t,e)=>{let r=-1;return t>-1&&e[t]&&(r=e[t].hlsjsIndex),r})(t,this.jwLevels);this.hlsjs.nextLevel=e,this.trigger(M.aM,{levels:this.jwLevels,currentQuality:t}),this.bitrateSelection=this.jwLevels[t].bitrate}setCurrentAudioTrack(t){const e=this.getCurrentHlsjsLevel(),r=this.hlsjs.levels[e],i=h(e,this.jwLevels);if(!this.jwLevels||!this.jwLevels[i]||!r)return;if(!this.audioTracksArray||!(0,n.dp)(this.audioTracksArray)||!(0,n.hj)(t))return;let a=this.audioTracks=this.audioTracksArray;if(!a||!(0,n.dp)(a)||!a[t]||this.currentAudioTrackIndex===t)return;this.trigger(M.j0,{tracks:a,currentTrack:t}),a=this.audioTracks;let s=a[t];null!==this.currentAudioTrackIndex&&s.hlsjsIndex!==this.hlsjs.audioTrack&&(this.trigger(M._B,{tracks:a,currentTrack:t}),s=this.audioTracks[t]),this.currentAudioTrackIndex=t,s.hlsjsIndex!==this.hlsjs.audioTrack&&(this.hlsjs.audioTrack=s.hlsjsIndex)}updateAudioTrack(t){if(!this.hlsjs||!this.hlsjs.audioTracks.length)return;let e=this.currentAudioTrackIndex;(0,n.hj)(e)?this.audioTracks&&this.audioTracks[e].hlsjsIndex===this.hlsjs.audioTrack||(this.currentAudioTrackIndex=null):e=this.audioTracksArray?((t=[])=>Math.max((0,n.cq)(t,(0,n.sE)(t,(t=>t.defaulttrack))),0))(this.audioTracksArray):0,this.setCurrentAudioTrack(e)}updateDvrPosition(t){this.dvrPosition=this.video.currentTime-t.end,this.dvrEnd=t.end,this.dvrUpdatedTime=(0,F.z)()}setCurrentSubtitleTrack(t){this.hlsjs.subtitleTrack=t}setPlaybackRate(t){this.video.playbackRate=this.video.defaultPlaybackRate=t}get maxBufferLength(){return this.hlsjs?this.hlsjs.config.maxMaxBufferLength:NaN}set maxBufferLength(t){this.hlsjs&&(this.hlsjs.config.maxMaxBufferLength=t)}isLive(){return this.live}checkAdaptation(t){const{levels:e,autoLevelEnabled:r}=this.hlsjs,i=e[t];if(!i)return;let{width:n,height:a,bitrate:s}=i;if(n=n||this.video.videoWidth,a=a||this.video.videoHeight,a===this.videoHeight&&s===this.streamBitrate)return;const l=h(t,this.jwLevels);let u="api";-1!==this.streamBitrate&&this.streamBitrate||this.videoHeight?r&&(u="auto"):u="initial choice",this.videoHeight=a,this.streamBitrate=s;const d=r?"auto":"manual",c=r&&e.length>1?"auto":this.jwLevels[l].label,f=()=>{this.trigger(M.ug,{reason:u,mode:d,level:{bitrate:s,index:l,label:c,width:n,height:a}})};o.Browser.ie?this.once("time",f,this):f()}createVideoListeners(){const t={waiting:()=>{this.startConnectionTimeout(),this.seeking?this.setState(M.ik):this.state===M.r0&&(this.atEdgeOfLiveStream()&&this.setPlaybackRate(1),this.stallTime=this.video.currentTime,this.setState(M.nQ))}};return Object.keys(N.Z).forEach((e=>{const r=N.Z[e];"playing"===e?t[e]=function(){const t=this.getCurrentHlsjsLevel();this.checkAdaptation(t),r.call(this)}.bind(this):"ended"===e?t[e]=function(){this.videoHeight=0,this.streamBitrate=-1,r.call(this)}.bind(this):"error"!==e&&(t[e]=r.bind(this))})),t}createHlsjsListeners(){const t={};return t[e]=()=>{this.recoveringMediaError&&(this.hlsjs.startLoad(),this.recoveringMediaError=!1,this.resetRecovery(),this.stopStaleTimeout(),this.stopConnectionTimeout())},t[r]=()=>{this._clearNonNativeCues()},t[s]=(t,e)=>{const{levels:r}=e,i=this.hlsjs,{bitrateSelection:a,jwConfig:s}=this;let o=-1,l=-1;if(this.currentHlsjsLevel=null,this.jwLevels=u(r,s.qualityLabels),this.capLevels&&(this.playerWidth||this.playerHeight)&&this.playerStretching){const t=d(r,this.playerWidth,this.playerHeight,e.firstLevel+1);i.levelController.firstLevel!==t&&(i.firstLevel=t),this.resize(this.playerWidth,this.playerHeight,this.playerStretching)}(0,n.qh)(a)&&(o=((t,e)=>{if(!e)return-1;let r=Number.MAX_VALUE,i=-1;for(let n=0;n{const{endSN:r,live:i,targetduration:n}=e.details;this.checkStaleManifest(r,i,n)},t[f]=(t,e)=>{const{live:r,totalduration:i}=e.details;this.live=r,this.levelDuration=i;const n=this.getSeekRange(),a=null!==this.dvrEnd&&Math.abs(this.dvrEnd-n.end)>1;"DVR"===this.streamType&&a&&this.updateDvrPosition(n),r&&this.state===M.bc&&this.livePause()},t[g]=(t,e)=>{const{fragments:r,totalduration:i}=e.details;if(this.levelDuration=i,r.length){const t=r[r.length-1];t.sn!==this.liveEdgeSn&&(this.liveEdgeUpdated=(0,F.z)(),this.liveEdgeSn=t.sn,this.liveEdgePosition=t.start+t.duration)}},t[y]=(t,e)=>{const{level:r}=e;r!==this.currentHlsjsLevel?this.setCurrentLevel(r):this.checkAdaptation(r)},t[m]=(t,e)=>{this.lastProgramDateTime=e.frag.programDateTime,this.programDateSyncTime=e.frag.start,this.lastProgramDateTime&&!this.startDateTime&&(this.startDateTime=this.lastProgramDateTime,this.trigger(M.AQ,{ready:!0,startDateTime:this.startDateTime}))},t[v]=(t,e)=>{this.lastProgramDateTime=e.frag.programDateTime,this.programDateSyncTime=e.frag.start},t[b]=(t,e)=>{e.samples&&([].some.call(this.video.textTracks,(t=>!t.inuse))&&this.setTextTracks(this.video.textTracks),null!=e&&e.samples&&e.samples.forEach((t=>{this.trigger(M.rx,{metadataType:"dai-hls",metadata:{messageData:t.data,start:t.pts,type:"ID3"}})})))},t[D]=()=>{-1!==this.connectionTimeout&&this.stopConnectionTimeout(),this.atEdgeOfLiveStream()||this.stopStaleTimeout(),this.recoveringNetworkError&&(this.resetRecovery(),this.recoveringNetworkError=!1)},t[_]=(t,e)=>{if(e.audio&&this.videoFound)return;const r=e.audiovideo||e.video?"video":"audio";this.videoFound=this.videoFound||"video"===r,this.trigger(M.oZ,{mediaType:r})},t[C]=(t,e)=>{const r=e.frag;(r.tagList||[]).forEach((([t,e])=>this.processPlaylistMetadata(t,e,r)))},t[w]=(t,e)=>{const{frag:r,initPTS:i}=e;this.processPlaylistMetadata("DISCONTINUITY",i,r)},this.renderNatively||(t[j]=(t,e)=>{this.addTextTracks(e.tracks)},t[Y]=(t,e)=>{var r;if(null!=e&&null!=(r=e.cues)&&r.length){let t;const r=!(e.cues[0]instanceof H.Z);e.cues.forEach((i=>{if(r){const t=i;(i=new H.Z(t.startTime,t.endTime,t.text)).position=t.position}t||(t=e.cues.filter((t=>t.startTime===i.startTime)).length),i.align="center",i.line=90-5*t,i.position=50,this.addVTTCue({type:e.type,cue:i,track:e.track}),t--}))}}),t[W]=(t,e)=>{const{audioTracks:r}=e,i=this.hlsjs.levels,a=this.getCurrentHlsjsLevel();null!=r&&r.length&&(this.audioTracksArray=(t=>(0,n.u4)(t,((t,e,r)=>(t.push({autoselect:e.autoselect,defaulttrack:e.default,groupid:e.groupId,language:e.lang,name:e.name,hlsjsIndex:r}),t)),[]))(r),this.jwLevels.forEach((t=>{const e=t.hlsjsIndex>0?i[t.hlsjsIndex]:null;e&&(t.audioGroupId=l(e))})),this.updateAudioTrack(i[a]))},t[q]=(t,e)=>{const r=this.hlsjs,i=Q(e),{type:n}=e,{key:a}=i;let s;if(p(e),"DVR"===this.streamType&&n===z){const t=this.getSeekRange();this.updateDvrPosition(t)}if(232403===i.code&&this.retryCount=this.lastRecoveryTime+this.recoveryInterval)&&(p("Attempting to recover, retry count:",l),n===z?/^manifest/.test(e.details)||s?(this.recoverManifestError(),this.retryCount=l):r.startLoad():n===X&&("bufferAppendError"===e.details?(p("Encountered a bufferAppendError in hls not attempting to recover media and destroying instance"),r.destroy()):(this.recoveringMediaError=!0,r.recoverMediaError())),this.recoveringNetworkError=!0,this.retryCount+=1,this.lastRecoveryTime=t)}this.trigger(M.cM,new R.rG(null,i.code+1e5,e))},t}resize(t,e,r){if(this.playerWidth=t,this.playerHeight=e,this.playerStretching=r,this.capLevels){const t=this.hlsjs;if(null!=t&&t.levels){const e=t.autoLevelCapping,r=d(t.levels,this.playerWidth,this.playerHeight);r!==e&&(t.autoLevelCapping=r,r>e&&-1!==e&&this.state!==M.bc&&this.state!==M.xQ&&t.streamController.nextLevelSwitch())}}}recoverManifestError(){const{currentTime:t,paused:e}=this.video;t||!e?(this.restartStream(t),e||this.play().catch((()=>{}))):(this.hlsjs.stopLoad(),this.hlsjs.loadSource(this.src))}_eventsOn(){const{bandwidthMonitor:t,eventHandler:e,video:r}=this;e&&e.on(),t.start(),(0,K.Nm)(this,r)}_eventsOff(){const{bandwidthMonitor:t,eventHandler:e,hlsjs:r,video:i}=this;r&&e&&(this.disableTextTrack(),this.lastPosition=this.video.currentTime,r.detachMedia(),e.off()),this.off(null,null,this),t.stop(),this.resetLifecycleVariables(),(0,K.IP)(i)}handleError(t,e,r){this.resetLifecycleVariables(),this.trigger(M.Ew,new R.rG(r,t,e))}destroy(){this.hlsjs&&(this._eventsOff(),this.hlsjs.destroy(),this.hlsjs=null,this.hlsjsOptions=null)}restoreVideoProperties(){this.savedVideoProperties&&(this.volume(this.jwConfig.volume),this.mute(this.jwConfig.mute),this.savedVideoProperties=!1)}checkStaleManifest(t,e,r){const i=null!==this.jwConfig.liveTimeout?1e3*this.jwConfig.liveTimeout:this.staleManifestDurationMultiplier*r;e&&this.lastEndSn===t&&0!==i?-1===this.staleManifestTimeout&&(this.staleManifestTimeout=window.setTimeout((()=>{this.checkStreamEnded()}),i)):this.stopStaleTimeout(),this.lastEndSn=t,this.live=e}checkStreamEnded(){this.hlsjs&&(this.video.ended||this.atEdgeOfLiveStream())&&(this.hlsjs.stopLoad(),this.handleError(k.ERROR_LIVE_STREAM_DOWN_OR_ENDED,null,R.Sp))}setCurrentLevel(t){this.currentHlsjsLevel=t,this.checkAdaptation(t),this.updateAudioTrack(this.hlsjs.levels[t])}_clearNonNativeCues(){!this.renderNatively&&this._textTracks&&this._textTracks.forEach((t=>{this.clearCueData(t._id)}))}static setEdition(t){L.supports=(0,U.Z)(t)}}}(r.n(j)());class W extends Y{getName(){return{name:"hlsjs"}}static getName(){return{name:"hlsjs"}}}},3343:(t,e,r)=>{"use strict";r.d(e,{q:()=>s});var i=r(6042),n=r(1643);const a=(t,e)=>{const r=t[e];return(0,i.xV)(r)&&r>=0?r:null},s=function(t,e,r){const s=((t,e,r)=>{let n,s;if(n=(0,i.xV)(r.startPTS)?a(r,"startPTS"):a(r,"start"),null===n)return null;switch(t){case"PROGRAM-DATE-TIME":return s="program-date-time",{metadataType:s,programDateTime:e,start:n,end:n+a(r,"duration")};case"EXT-X-DATERANGE":{const a={},o=e.split(",").map((t=>{const e=t.split("="),r=e[0],i=(e[1]||"").replace(/^"|"$/g,"");return a[r]=i,{name:r,value:i}})),l=a["START-DATE"];if(!l)return null;const u=a["END-DATE"];let h=n;if((0,i.xV)(r.programDateTime)&&(h+=(new Date(l).getTime()-new Date(r.programDateTime).getTime())/1e3),isNaN(h))return null;let d=parseFloat(a["PLANNED-DURATION"]||a.DURATION)||0;return!d&&u&&(d=(new Date(u).getTime()-new Date(l).getTime())/1e3),s="date-range",{metadataType:"date-range",tag:t,content:e,attributes:o,start:h,end:h+d,startDate:l,endDate:u,duration:d}}case"EXT-X-CUE-IN":case"EXT-X-CUE-OUT":return s="scte-35",{metadataType:s,tag:t,content:e,start:n,end:n+(parseFloat(e)||0)};case"DISCONTINUITY":{const i=n+a(r,"duration");let o;return"cc"in r&&(o=r.cc),s="discontinuity",{metadataType:s,tag:t,discontinuitySequence:o,PTS:e,start:n,end:i}}default:return null}})(t,e,r);if(s){if(!(0,i.xV)(s.start))return;const a=this.createCue(s.start,s.end,JSON.stringify(s)),o=`${r.sn}_${t}_${e}`;if(this.addVTTCue({type:"metadata",cue:a},o)){const t=s.metadataType;delete s.metadataType,this.trigger(n.O1,{metadataType:t,metadata:s})}}}},4560:function(t,e){!function r(i){var n,a;n=this,a=function(){"use strict";function t(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function e(e){for(var r=1;rt.length)&&(e=t.length);for(var r=0,i=new Array(e);r1?e-1:0),i=1;i"):L}(e)}))}(t,"debug","log","info","warn","error");try{k.log('Debug logs enabled for "'+e+'" in hls.js version 1.5.13')}catch(t){k=R}}else k=R}var b=k,D=/^(\d+)x(\d+)$/,_=/(.+?)=(".*?"|.*?)(?:,|$)/g,C=function(){function t(e){"string"==typeof e&&(e=t.parseAttrList(e)),o(this,e)}var e=t.prototype;return e.decimalInteger=function(t){var e=parseInt(this[t],10);return e>Number.MAX_SAFE_INTEGER?1/0:e},e.hexadecimalInteger=function(t){if(this[t]){var e=(this[t]||"0x").slice(2);e=(1&e.length?"0":"")+e;for(var r=new Uint8Array(e.length/2),i=0;iNumber.MAX_SAFE_INTEGER?1/0:e},e.decimalFloatingPoint=function(t){return parseFloat(this[t])},e.optionalFloat=function(t,e){var r=this[t];return r?parseFloat(r):e},e.enumeratedString=function(t){return this[t]},e.bool=function(t){return"YES"===this[t]},e.decimalResolution=function(t){var e=D.exec(this[t]);if(null!==e)return{width:parseInt(e[1],10),height:parseInt(e[2],10)}},t.parseAttrList=function(t){var e,r={};for(_.lastIndex=0;null!==(e=_.exec(t));){var i=e[2];0===i.indexOf('"')&&i.lastIndexOf('"')===i.length-1&&(i=i.slice(1,-1)),r[e[1].trim()]=i}return r},s(t,[{key:"clientAttrs",get:function(){return Object.keys(this).filter((function(t){return"X-"===t.substring(0,2)}))}}]),t}();function w(t){return"SCTE35-OUT"===t||"SCTE35-IN"===t}var I=function(){function t(t,e){if(this.attr=void 0,this._startDate=void 0,this._endDate=void 0,this._badValueForSameId=void 0,e){var r=e.attr;for(var i in r)if(Object.prototype.hasOwnProperty.call(t,i)&&t[i]!==r[i]){b.warn('DATERANGE tag attribute: "'+i+'" does not match for tags with ID: "'+t.ID+'"'),this._badValueForSameId=i;break}t=o(new C({}),r,t)}if(this.attr=t,this._startDate=new Date(t["START-DATE"]),"END-DATE"in this.attr){var n=new Date(this.attr["END-DATE"]);m(n.getTime())&&(this._endDate=n)}}return s(t,[{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 t=this.duration;return null!==t?new Date(this._startDate.getTime()+1e3*t):null}},{key:"duration",get:function(){if("DURATION"in this.attr){var t=this.attr.decimalFloatingPoint("DURATION");if(m(t))return t}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&&m(this.startDate.getTime())&&(null===this.duration||this.duration>=0)&&(!this.endOnNext||!!this.class)}}]),t}(),x=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}},P="audio",O="video",M="audiovideo",F=function(){function t(t){var e;this._byteRange=null,this._url=null,this.baseurl=void 0,this.relurl=void 0,this.elementaryStreams=((e={})[P]=null,e[O]=null,e[M]=null,e),this.baseurl=t}return t.prototype.setByteRange=function(t,e){var r,i=t.split("@",2);r=1===i.length?(null==e?void 0:e.byteRangeEndOffset)||0:parseInt(i[1]),this._byteRange=[r,parseInt(i[0])+r]},s(t,[{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=v.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""},set:function(t){this._url=t}}]),t}(),N=function(t){function e(e,r){var i;return(i=t.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 x,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=e,i}l(e,t);var r=e.prototype;return r.setKeyFormat=function(t){if(this.levelkeys){var e=this.levelkeys[t];e&&!this._decryptdata&&(this._decryptdata=e.getDecryptData(this.sn))}},r.abortRequests=function(){var t,e;null==(t=this.loader)||t.abort(),null==(e=this.keyLoader)||e.abort()},r.setElementaryStreamInfo=function(t,e,r,i,n,a){void 0===a&&(a=!1);var s=this.elementaryStreams,o=s[t];o?(o.startPTS=Math.min(o.startPTS,e),o.endPTS=Math.max(o.endPTS,r),o.startDTS=Math.min(o.startDTS,i),o.endDTS=Math.max(o.endDTS,n)):s[t]={startPTS:e,endPTS:r,startDTS:i,endDTS:n,partial:a}},r.clearElementaryStreamInfo=function(){var t=this.elementaryStreams;t[P]=null,t[O]=null,t[M]=null},s(e,[{key:"decryptdata",get:function(){if(!this.levelkeys&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkeys&&!this.levelkeys.NONE){var t=this.levelkeys.identity;if(t)this._decryptdata=t.getDecryptData(this.sn);else{var e=Object.keys(this.levelkeys);if(1===e.length)return this._decryptdata=this.levelkeys[e[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(!m(this.programDateTime))return null;var t=m(this.duration)?this.duration:0;return this.programDateTime+1e3*t}},{key:"encrypted",get:function(){var t;if(null!=(t=this._decryptdata)&&t.encrypted)return!0;if(this.levelkeys){var e=Object.keys(this.levelkeys),r=e.length;if(r>1||1===r&&this.levelkeys[e[0]].encrypted)return!0}return!1}}]),e}(F),U=function(t){function e(e,r,i,n,a){var s;(s=t.call(this,i)||this).fragOffset=0,s.duration=0,s.gap=!1,s.independent=!1,s.relurl=void 0,s.fragment=void 0,s.index=void 0,s.stats=new x,s.duration=e.decimalFloatingPoint("DURATION"),s.gap=e.bool("GAP"),s.independent=e.bool("INDEPENDENT"),s.relurl=e.enumeratedString("URI"),s.fragment=r,s.index=n;var o=e.enumeratedString("BYTERANGE");return o&&s.setByteRange(o,a),a&&(s.fragOffset=a.fragOffset+a.duration),s}return l(e,t),s(e,[{key:"start",get:function(){return this.fragment.start+this.fragOffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var t=this.elementaryStreams;return!!(t.audio||t.video||t.audiovideo)}}]),e}(F),B=function(){function t(t){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=t}return t.prototype.reloaded=function(t){if(!t)return this.advanced=!0,void(this.updated=!0);var e=this.lastPartSn-t.lastPartSn,r=this.lastPartIndex-t.lastPartIndex;this.updated=this.endSN!==t.endSN||!!r||!!e||!this.live,this.advanced=this.endSN>t.endSN||e>0||0===e&&r>0,this.updated||this.advanced?this.misses=Math.floor(.6*t.misses):this.misses=t.misses+1,this.availabilityDelay=t.availabilityDelay},s(t,[{key:"hasProgramDateTime",get:function(){return!!this.fragments.length&&m(this.fragments[this.fragments.length-1].programDateTime)}},{key:"levelTargetDuration",get:function(){return this.averagetargetduration||this.targetduration||10}},{key:"drift",get:function(){var t=this.driftEndTime-this.driftStartTime;return t>0?1e3*(this.driftEnd-this.driftStart)/t:1}},{key:"edge",get:function(){return this.partEnd||this.fragmentEnd}},{key:"partEnd",get:function(){var t;return null!=(t=this.partList)&&t.length?this.partList[this.partList.length-1].end:this.fragmentEnd}},{key:"fragmentEnd",get:function(){var t;return null!=(t=this.fragments)&&t.length?this.fragments[this.fragments.length-1].end:0}},{key:"age",get:function(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}},{key:"lastPartIndex",get:function(){var t;return null!=(t=this.partList)&&t.length?this.partList[this.partList.length-1].index:-1}},{key:"lastPartSn",get:function(){var t;return null!=(t=this.partList)&&t.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}]),t}();function G(t){return Uint8Array.from(atob(t),(function(t){return t.charCodeAt(0)}))}function H(t){return Uint8Array.from(unescape(encodeURIComponent(t)),(function(t){return t.charCodeAt(0)}))}var K="undefined"!=typeof self?self:void 0,V={CLEARKEY:"org.w3.clearkey",FAIRPLAY:"com.apple.fps",PLAYREADY:"com.microsoft.playready",WIDEVINE:"com.widevine.alpha"},j="org.w3.clearkey",Y="com.apple.streamingkeydelivery",W="com.microsoft.playready",q="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";function X(t){switch(t){case Y:return V.FAIRPLAY;case W:return V.PLAYREADY;case q:return V.WIDEVINE;case j:return V.CLEARKEY}}var z="edef8ba979d64acea3c827dcd51d21ed";function Q(t){switch(t){case V.FAIRPLAY:return Y;case V.PLAYREADY:return W;case V.WIDEVINE:return q;case V.CLEARKEY:return j}}function Z(t){var e=t.drmSystems,r=t.widevineLicenseUrl,i=e?[V.FAIRPLAY,V.WIDEVINE,V.PLAYREADY,V.CLEARKEY].filter((function(t){return!!e[t]})):[];return!i[V.WIDEVINE]&&r&&i.push(V.WIDEVINE),i}var $,J=null!=K&&null!=($=K.navigator)&&$.requestMediaKeySystemAccess?self.navigator.requestMediaKeySystemAccess.bind(self.navigator):null;function tt(t,e,r){return Uint8Array.prototype.slice?t.slice(e,r):new Uint8Array(Array.prototype.slice.call(t,e,r))}var et,rt=function(t,e){return e+10<=t.length&&73===t[e]&&68===t[e+1]&&51===t[e+2]&&t[e+3]<255&&t[e+4]<255&&t[e+6]<128&&t[e+7]<128&&t[e+8]<128&&t[e+9]<128},it=function(t,e){return e+10<=t.length&&51===t[e]&&68===t[e+1]&&73===t[e+2]&&t[e+3]<255&&t[e+4]<255&&t[e+6]<128&&t[e+7]<128&&t[e+8]<128&&t[e+9]<128},nt=function(t,e){for(var r=e,i=0;rt(t,e);)i+=10,i+=at(t,e+6),it(t,e+10)&&(i+=10),e+=i;if(i>0)return t.subarray(r,r+i)},at=function(t,e){var r=0;return r=(127&t[e])<<21,r|=(127&t[e+1])<<14,(r|=(127&t[e+2])<<7)|127&t[e+3]},st=function(t,e){return rt(t,e)&&at(t,e+6)+10<=t.length-e},ot=function(t){for(var e=ht(t),r=0;r>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:u+=String.fromCharCode(a);break;case 12:case 13:s=t[h++],u+=String.fromCharCode((31&a)<<6|63&s);break;case 14:s=t[h++],o=t[h++],u+=String.fromCharCode((15&a)<<12|(63&s)<<6|63&o)}}return u};var pt=function(t){for(var e="",r=0;r>24,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r}function Dt(t,e){var r=[];if(!e.length)return r;for(var i=t.byteLength,n=0;n1?n+a:i;if(St(t.subarray(n+4,n+8))===e[0])if(1===e.length)r.push(t.subarray(n+8,s));else{var o=Dt(t.subarray(n+8,s),e.slice(1));o.length&&Tt.apply(r,o)}n=s}return r}function _t(t){var e=[],r=t[0],i=8,n=Rt(t,i);i+=4;var a=0,s=0;0===r?(a=Rt(t,i),s=Rt(t,i+4),i+=8):(a=kt(t,i),s=kt(t,i+8),i+=16),i+=2;var o=t.length+s,l=Lt(t,i);i+=2;for(var u=0;u>>31)return b.warn("SIDX has hierarchical references (not supported)"),null;var f=Rt(t,h);h+=4,e.push({referenceSize:c,subsegmentDuration:f,info:{duration:f/n,start:o,end:o+c-1}}),o+=c,i=h+=4}return{earliestPresentationTime:a,timescale:n,version:r,referencesCount:l,references:e}}function Ct(t){for(var r=[],i=Dt(t,["moov","trak"]),n=0;n12){var h=4;if(3!==u[h++])break;h=It(u,h),h+=2;var d=u[h++];if(128&d&&(h+=2),64&d&&(h+=u[h++]),4!==u[h++])break;h=It(u,h);var c=u[h++];if(64!==c)break;if(n+="."+xt(c),h+=12,5!==u[h++])break;h=It(u,h);var f=u[h++],g=(248&f)>>3;31===g&&(g+=1+((7&f)<<3)+((224&u[h])>>5)),n+="."+g}break;case"hvc1":case"hev1":var v=Dt(r,["hvcC"])[0],m=v[1],p=["","A","B","C"][m>>6],y=31&m,T=Rt(v,2),E=(32&m)>>5?"H":"L",S=v[12],L=v.subarray(6,12);n+="."+p+y,n+="."+T.toString(16).toUpperCase(),n+="."+E+S;for(var R="",k=L.length;k--;){var A=L[k];(A||R)&&(R="."+A.toString(16).toUpperCase()+R)}n+=R;break;case"dvh1":case"dvhe":var b=Dt(r,["dvcC"])[0],D=b[2]>>1&127,_=b[2]<<5&32|b[3]>>3&31;n+="."+Pt(D)+"."+Pt(_);break;case"vp09":var C=Dt(r,["vpcC"])[0],w=C[4],I=C[5],x=C[6]>>4&15;n+="."+Pt(w)+"."+Pt(I)+"."+Pt(x);break;case"av01":var P=Dt(r,["av1C"])[0],O=P[1]>>>5,M=31&P[1],F=P[2]>>>7?"H":"M",N=(64&P[2])>>6,U=(32&P[2])>>5,B=2===O&&N?U?12:10:N?10:8,G=(16&P[2])>>4,H=(8&P[2])>>3,K=(4&P[2])>>2,V=3&P[2];n+="."+O+"."+Pt(M)+F+"."+Pt(B)+"."+G+"."+H+K+V+"."+Pt(1)+"."+Pt(1)+"."+Pt(1)+".0"}return{codec:n,encrypted:a}}function It(t,e){for(var r=e+5;128&t[e++]&&e>1&63;return 39===r||40===r}return 6==(31&e)}function Bt(t,e,r,i){var n=Gt(t),a=0;a+=e;for(var s=0,o=0,l=0;a=n.length)break;s+=l=n[a++]}while(255===l);o=0;do{if(a>=n.length)break;o+=l=n[a++]}while(255===l);var u=n.length-a,h=a;if(ou){b.error("Malformed SEI payload. "+o+" is too small, only "+u+" bytes left to parse.");break}if(4===s){if(181===n[h++]){var d=Lt(n,h);if(h+=2,49===d){var c=Rt(n,h);if(h+=4,1195456820===c){var f=n[h++];if(3===f){var g=n[h++],v=64&g,m=v?2+3*(31&g):0,p=new Uint8Array(m);if(v){p[0]=g;for(var y=1;y16){for(var T=[],E=0;E<16;E++){var S=n[h++].toString(16);T.push(1==S.length?"0"+S:S),3!==E&&5!==E&&7!==E&&9!==E||T.push("-")}for(var L=o-16,R=new Uint8Array(L),k=0;k>8*(15-r)&255;return e}(e);return new t(this.method,this.uri,"identity",this.keyFormatVersions,r)}var i=function(t){var e,r,i=t.split(":"),n=null;if("data"===i[0]&&2===i.length){var a=i[1].split(";"),s=a[a.length-1].split(",");if(2===s.length){var o="base64"===s[0],l=s[1];o?(a.splice(-1,1),n=G(l)):(e=H(l).subarray(0,16),(r=new Uint8Array(16)).set(e,16-e.length),n=r)}}return n}(this.uri);if(i)switch(this.keyFormat){case q:this.pssh=i,i.length>=22&&(this.keyId=i.subarray(i.length-22,i.length-6));break;case W:var n=new Uint8Array([154,4,240,121,152,64,66,134,171,146,230,91,224,136,95,149]);this.pssh=function(t,e,r){if(16!==t.byteLength)throw new RangeError("Invalid system id");var i,n,a;if(e){i=1,n=new Uint8Array(16*e.length);for(var s=0;s0?(a=new Uint8Array(4),e.length>0&&new DataView(a.buffer).setUint32(0,e.length,!1)):a=new Uint8Array;var l=new Uint8Array(4);return r&&r.byteLength>0&&new DataView(l.buffer).setUint32(0,r.byteLength,!1),function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i>24&255,o[1]=a>>16&255,o[2]=a>>8&255,o[3]=255&a,o.set(t,4),s=0,a=8;s0&&a.length0&&X.bool("CAN-SKIP-DATERANGES"),h.partHoldBack=X.optionalFloat("PART-HOLD-BACK",0),h.holdBack=X.optionalFloat("HOLD-BACK",0);break;case"PART-INF":var z=new C(w);h.partTarget=z.decimalFloatingPoint("PART-TARGET");break;case"PART":var Q=h.partList;Q||(Q=h.partList=[]);var Z=g>0?Q[Q.length-1]:void 0,$=g++,J=new C(w);Yt(h,J,["BYTERANGE","URI"]);var tt=new U(J,T,e,$,Z);Q.push(tt),T.duration+=tt.duration;break;case"PRELOAD-HINT":var et=new C(w);Yt(h,et,["URI"]),h.preloadHint=et;break;case"RENDITION-REPORT":var rt=new C(w);Yt(h,rt,["URI"]),h.renditionReports=h.renditionReports||[],h.renditionReports.push(rt);break;default:b.warn("line parsed but not handled: "+s)}}}y&&!y.relurl?(d.pop(),v-=y.duration,h.partList&&(h.fragmentHint=y)):h.partList&&(me(T,y),T.cc=p,h.fragmentHint=T,u&&ye(T,u,h));var it=d.length,nt=d[0],at=d[it-1];if((v+=h.skippedSegments*h.targetduration)>0&&it&&at){h.averagetargetduration=v/it;var st=at.sn;h.endSN="initSegment"!==st?st:0,h.live||(at.endList=!0),nt&&(h.startCC=nt.cc)}else h.endSN=0,h.startCC=0;return h.fragmentHint&&(v+=h.fragmentHint.duration),h.totalduration=v,h.endCC=p,E>0&&function(t,e){for(var r=t[e],i=e;i--;){var n=t[i];if(!n)return;n.programDateTime=r.programDateTime-1e3*n.duration,r=n}}(d,E),h},t}();function ce(t,e,r){var i,n,a=new C(t);Yt(r,a,["KEYFORMAT","KEYFORMATVERSIONS","URI","IV","URI"]);var s=null!=(i=a.METHOD)?i:"",o=a.URI,l=a.hexadecimalInteger("IV"),u=a.KEYFORMATVERSIONS,h=null!=(n=a.KEYFORMAT)?n:"identity";o&&a.IV&&!l&&b.error("Invalid IV: "+a.IV);var d=o?de.resolve(o,e):"",c=(u||"1").split("/").map(Number).filter(Number.isFinite);return new Kt(s,d,h,c,l)}function fe(t){var e=new C(t).decimalFloatingPoint("TIME-OFFSET");return m(e)?e:null}function ge(t,e){var r=(t||"").split(/[ ,]+/).filter((function(t){return t}));["video","audio","text"].forEach((function(t){var i=r.filter((function(e){return function(t,e){var r=Qt[e];return!!r&&!!r[t.slice(0,4)]}(e,t)}));i.length&&(e[t+"Codec"]=i.join(","),r=r.filter((function(t){return-1===i.indexOf(t)})))})),e.unknownCodecs=r}function ve(t,e,r){var i=e[r];i&&(t[r]=i)}function me(t,e){t.rawProgramDateTime?t.programDateTime=Date.parse(t.rawProgramDateTime):null!=e&&e.programDateTime&&(t.programDateTime=e.endProgramDateTime),m(t.programDateTime)||(t.programDateTime=null,t.rawProgramDateTime=null)}function pe(t,e,r,i){t.relurl=e.URI,e.BYTERANGE&&t.setByteRange(e.BYTERANGE),t.level=r,t.sn="initSegment",i&&(t.levelkeys=i),t.initSegment=null}function ye(t,e,r){t.levelkeys=e;var i=r.encryptedFragments;i.length&&i[i.length-1].levelkeys===e||!Object.keys(e).some((function(t){return e[t].isCommonEncryption}))||i.push(t)}var Te="manifest",Ee="level",Se="audioTrack",Le="subtitleTrack",Re="main",ke="audio",Ae="subtitle";function be(t){switch(t.type){case Se:return ke;case Le:return Ae;default:return Re}}function De(t,e){var r=t.url;return void 0!==r&&0!==r.indexOf("data:")||(r=e.url),r}var _e=function(){function t(t){this.hls=void 0,this.loaders=Object.create(null),this.variableList=null,this.hls=t,this.registerListeners()}var r=t.prototype;return r.startLoad=function(t){},r.stopLoad=function(){this.destroyInternalLoaders()},r.registerListeners=function(){var t=this.hls;t.on(T.MANIFEST_LOADING,this.onManifestLoading,this),t.on(T.LEVEL_LOADING,this.onLevelLoading,this),t.on(T.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.on(T.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},r.unregisterListeners=function(){var t=this.hls;t.off(T.MANIFEST_LOADING,this.onManifestLoading,this),t.off(T.LEVEL_LOADING,this.onLevelLoading,this),t.off(T.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.off(T.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},r.createInternalLoader=function(t){var e=this.hls.config,r=e.pLoader,i=e.loader,n=new(r||i)(e);return this.loaders[t.type]=n,n},r.getInternalLoader=function(t){return this.loaders[t.type]},r.resetInternalLoader=function(t){this.loaders[t]&&delete this.loaders[t]},r.destroyInternalLoaders=function(){for(var t in this.loaders){var e=this.loaders[t];e&&e.destroy(),this.resetInternalLoader(t)}},r.destroy=function(){this.variableList=null,this.unregisterListeners(),this.destroyInternalLoaders()},r.onManifestLoading=function(t,e){var r=e.url;this.variableList=null,this.load({id:null,level:0,responseType:"text",type:Te,url:r,deliveryDirectives:null})},r.onLevelLoading=function(t,e){var r=e.id,i=e.level,n=e.pathwayId,a=e.url,s=e.deliveryDirectives;this.load({id:r,level:i,pathwayId:n,responseType:"text",type:Ee,url:a,deliveryDirectives:s})},r.onAudioTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:Se,url:n,deliveryDirectives:a})},r.onSubtitleTrackLoading=function(t,e){var r=e.id,i=e.groupId,n=e.url,a=e.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:Le,url:n,deliveryDirectives:a})},r.load=function(t){var e,r,i,n=this,a=this.hls.config,s=this.getInternalLoader(t);if(s){var l=s.context;if(l&&l.url===t.url&&l.level===t.level)return void b.trace("[playlist-loader]: playlist request ongoing");b.log("[playlist-loader]: aborting previous loader for type: "+t.type),s.abort()}if(r=t.type===Te?a.manifestLoadPolicy.default:o({},a.playlistLoadPolicy.default,{timeoutRetry:null,errorRetry:null}),s=this.createInternalLoader(t),m(null==(e=t.deliveryDirectives)?void 0:e.part)&&(t.type===Ee&&null!==t.level?i=this.hls.levels[t.level].details:t.type===Se&&null!==t.id?i=this.hls.audioTracks[t.id].details:t.type===Le&&null!==t.id&&(i=this.hls.subtitleTracks[t.id].details),i)){var u=i.partTarget,h=i.targetduration;if(u&&h){var d=1e3*Math.max(3*u,.8*h);r=o({},r,{maxTimeToFirstByteMs:Math.min(d,r.maxTimeToFirstByteMs),maxLoadTimeMs:Math.min(d,r.maxTimeToFirstByteMs)})}}var c=r.errorRetry||r.timeoutRetry||{},f={loadPolicy:r,timeout:r.maxLoadTimeMs,maxRetry:c.maxNumRetry||0,retryDelay:c.retryDelayMs||0,maxRetryDelay:c.maxRetryDelayMs||0},g={onSuccess:function(t,e,r,i){var a=n.getInternalLoader(r);n.resetInternalLoader(r.type);var s=t.data;0===s.indexOf("#EXTM3U")?(e.parsing.start=performance.now(),de.isMediaPlaylist(s)?n.handleTrackOrLevelPlaylist(t,e,r,i||null,a):n.handleMasterPlaylist(t,e,r,i)):n.handleManifestParsingError(t,r,new Error("no EXTM3U delimiter"),i||null,e)},onError:function(t,e,r,i){n.handleNetworkError(e,r,!1,t,i)},onTimeout:function(t,e,r){n.handleNetworkError(e,r,!0,void 0,t)}};s.load(t,f,g)},r.handleMasterPlaylist=function(t,e,r,i){var n=this.hls,a=t.data,s=De(t,r),o=de.parseMasterPlaylist(a,s);if(o.playlistParsingError)this.handleManifestParsingError(t,r,o.playlistParsingError,i,e);else{var l=o.contentSteering,u=o.levels,h=o.sessionData,d=o.sessionKeys,c=o.startTimeOffset,f=o.variableList;this.variableList=f;var g=de.parseMasterPlaylistMedia(a,s,o),v=g.AUDIO,m=void 0===v?[]:v,p=g.SUBTITLES,y=g["CLOSED-CAPTIONS"];m.length&&(m.some((function(t){return!t.url}))||!u[0].audioCodec||u[0].attrs.AUDIO||(b.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 C({}),bitrate:0,url:""}))),n.trigger(T.MANIFEST_LOADED,{levels:u,audioTracks:m,subtitles:p,captions:y,contentSteering:l,url:s,stats:e,networkDetails:i,sessionData:h,sessionKeys:d,startTimeOffset:c,variableList:f})}},r.handleTrackOrLevelPlaylist=function(t,e,r,i,n){var a=this.hls,s=r.id,o=r.level,l=r.type,u=De(t,r),h=m(o)?o:m(s)?s:0,d=be(r),c=de.parseLevelPlaylist(t.data,u,h,d,0,this.variableList);if(l===Te){var f={attrs:new C({}),bitrate:0,details:c,name:"",url:u};a.trigger(T.MANIFEST_LOADED,{levels:[f],audioTracks:[],url:u,stats:e,networkDetails:i,sessionData:null,sessionKeys:null,contentSteering:null,startTimeOffset:null,variableList:null})}e.parsing.end=performance.now(),r.levelDetails=c,this.handlePlaylistLoaded(c,t,e,r,i,n)},r.handleManifestParsingError=function(t,e,r,i,n){this.hls.trigger(T.ERROR,{type:E.NETWORK_ERROR,details:S.MANIFEST_PARSING_ERROR,fatal:e.type===Te,url:t.url,err:r,error:r,reason:r.message,response:t,context:e,networkDetails:i,stats:n})},r.handleNetworkError=function(t,r,i,n,a){void 0===i&&(i=!1);var s="A network "+(i?"timeout":"error"+(n?" (status "+n.code+")":""))+" occurred while loading "+t.type;t.type===Ee?s+=": "+t.level+" id: "+t.id:t.type!==Se&&t.type!==Le||(s+=" id: "+t.id+' group-id: "'+t.groupId+'"');var o=new Error(s);b.warn("[playlist-loader]: "+s);var l=S.UNKNOWN,u=!1,h=this.getInternalLoader(t);switch(t.type){case Te:l=i?S.MANIFEST_LOAD_TIMEOUT:S.MANIFEST_LOAD_ERROR,u=!0;break;case Ee:l=i?S.LEVEL_LOAD_TIMEOUT:S.LEVEL_LOAD_ERROR,u=!1;break;case Se:l=i?S.AUDIO_TRACK_LOAD_TIMEOUT:S.AUDIO_TRACK_LOAD_ERROR,u=!1;break;case Le:l=i?S.SUBTITLE_TRACK_LOAD_TIMEOUT:S.SUBTITLE_LOAD_ERROR,u=!1}h&&this.resetInternalLoader(t.type);var d={type:E.NETWORK_ERROR,details:l,fatal:u,url:t.url,loader:h,context:t,error:o,networkDetails:r,stats:a};if(n){var c=(null==r?void 0:r.url)||t.url;d.response=e({url:c,data:void 0},n)}this.hls.trigger(T.ERROR,d)},r.handlePlaylistLoaded=function(t,e,r,i,n,a){var s=this.hls,o=i.type,l=i.level,u=i.id,h=i.groupId,d=i.deliveryDirectives,c=De(e,i),f=be(i),g="number"==typeof i.level&&f===Re?l:void 0;if(t.fragments.length){t.targetduration||(t.playlistParsingError=new Error("Missing Target Duration"));var v=t.playlistParsingError;if(v)s.trigger(T.ERROR,{type:E.NETWORK_ERROR,details:S.LEVEL_PARSING_ERROR,fatal:!1,url:c,error:v,reason:v.message,response:e,context:i,level:g,parent:f,networkDetails:n,stats:r});else switch(t.live&&a&&(a.getCacheAge&&(t.ageHeader=a.getCacheAge()||0),a.getCacheAge&&!isNaN(t.ageHeader)||(t.ageHeader=0)),o){case Te:case Ee:s.trigger(T.LEVEL_LOADED,{details:t,level:g||0,id:u||0,stats:r,networkDetails:n,deliveryDirectives:d});break;case Se:s.trigger(T.AUDIO_TRACK_LOADED,{details:t,id:u||0,groupId:h||"",stats:r,networkDetails:n,deliveryDirectives:d});break;case Le:s.trigger(T.SUBTITLE_TRACK_LOADED,{details:t,id:u||0,groupId:h||"",stats:r,networkDetails:n,deliveryDirectives:d})}}else{var m=new Error("No Segments found in Playlist");s.trigger(T.ERROR,{type:E.NETWORK_ERROR,details:S.LEVEL_EMPTY_ERROR,fatal:!1,url:c,error:m,reason:m.message,response:e,context:i,level:g,parent:f,networkDetails:n,stats:r})}},t}();function Ce(t,e){var r;try{r=new Event("addtrack")}catch(t){(r=document.createEvent("Event")).initEvent("addtrack",!1,!1)}r.track=t,e.dispatchEvent(r)}function we(t,e){var r=t.mode;if("disabled"===r&&(t.mode="hidden"),t.cues&&!t.cues.getCueById(e.id))try{if(t.addCue(e),!t.cues.getCueById(e.id))throw new Error("addCue is failed for: "+e)}catch(r){b.debug("[texttrack-utils]: "+r);try{var i=new self.TextTrackCue(e.startTime,e.endTime,e.text);i.id=e.id,t.addCue(i)}catch(t){b.debug("[texttrack-utils]: Legacy TextTrackCue fallback failed: "+t)}}"disabled"===r&&(t.mode=r)}function Ie(t){var e=t.mode;if("disabled"===e&&(t.mode="hidden"),t.cues)for(var r=t.cues.length;r--;)t.removeCue(t.cues[r]);"disabled"===e&&(t.mode=e)}function xe(t,e,r,i){var n=t.mode;if("disabled"===n&&(t.mode="hidden"),t.cues&&t.cues.length>0)for(var a=function(t,e,r){var i=[],n=function(t,e){if(et[r].endTime)return-1;for(var i=0,n=r;i<=n;){var a=Math.floor((n+i)/2);if(et[a].startTime&&i-1)for(var a=n,s=t.length;a=e&&o.endTime<=r)i.push(o);else if(o.startTime>r)return i}return i}(t.cues,e,r),s=0;sUe&&(d=Ue),d-h<=0&&(d=h+.25);for(var c=0;ce.startDate&&(!t||e.startDate.05&&this.forwardBufferLength>1){var l=Math.min(2,Math.max(1,a)),u=Math.round(2/(1+Math.exp(-.75*o-this.edgeStalled))*20)/20;t.playbackRate=Math.min(l,Math.max(1,u))}else 1!==t.playbackRate&&0!==t.playbackRate&&(t.playbackRate=1)}}}}},e.estimateLiveEdge=function(){var t=this.levelDetails;return null===t?null:t.edge+t.age},e.computeLatency=function(){var t=this.estimateLiveEdge();return null===t?null:t-this.currentTime},s(t,[{key:"latency",get:function(){return this._latency||0}},{key:"maxLatency",get:function(){var t=this.config,e=this.levelDetails;return void 0!==t.liveMaxLatencyDuration?t.liveMaxLatencyDuration:e?t.liveMaxLatencyDurationCount*e.targetduration:0}},{key:"targetLatency",get:function(){var t=this.levelDetails;if(null===t)return null;var e=t.holdBack,r=t.partHoldBack,i=t.targetduration,n=this.config,a=n.liveSyncDuration,s=n.liveSyncDurationCount,o=n.lowLatencyMode,l=this.hls.userConfig,u=o&&r||e;(l.liveSyncDuration||l.liveSyncDurationCount||0===u)&&(u=void 0!==a?a:s*i);var h=i;return u+Math.min(1*this.stallCount,h)}},{key:"liveSyncPosition",get:function(){var t=this.estimateLiveEdge(),e=this.targetLatency,r=this.levelDetails;if(null===t||null===e||null===r)return null;var i=r.edge,n=t-e-this.edgeStalled,a=i-r.totalduration,s=i-(this.config.lowLatencyMode&&r.partTarget||r.targetduration);return Math.min(Math.max(a,n),s)}},{key:"drift",get:function(){var t=this.levelDetails;return null===t?1:t.drift}},{key:"edgeStalled",get:function(){var t=this.levelDetails;if(null===t)return 0;var e=3*(this.config.lowLatencyMode&&t.partTarget||t.targetduration);return Math.max(t.age-e,0)}},{key:"forwardBufferLength",get:function(){var t=this.media,e=this.levelDetails;if(!t||!e)return 0;var r=t.buffered.length;return(r?t.buffered.end(r-1):e.edge)-this.currentTime}}]),t}(),Ke=["NONE","TYPE-0","TYPE-1",null],Ve=["SDR","PQ","HLG"];function je(t){var e=t.canSkipUntil,r=t.canSkipDateRanges,i=t.age;return e&&it.sn?(n=r-t.start,i=t):(n=t.start-r,i=e),i.duration!==n&&(i.duration=n)}else e.sn>t.sn?t.cc===e.cc&&t.minEndPTS?e.start=t.start+(t.minEndPTS-t.start):e.start=t.start+t.duration:e.start=Math.max(t.start-e.duration,0)}function ze(t,e,r,i,n,a){i-r<=0&&(b.warn("Fragment should have a positive duration",e),i=r+e.duration,a=n+e.duration);var s=r,o=i,l=e.startPTS,u=e.endPTS;if(m(l)){var h=Math.abs(l-r);m(e.deltaPTS)?e.deltaPTS=Math.max(h,e.deltaPTS):e.deltaPTS=h,s=Math.max(r,l),r=Math.min(r,l),n=Math.min(n,e.startDTS),o=Math.min(i,u),i=Math.max(i,u),a=Math.max(a,e.endDTS)}var d=r-e.start;0!==e.start&&(e.start=r),e.duration=i-e.start,e.startPTS=r,e.maxStartPTS=s,e.startDTS=n,e.endPTS=i,e.minEndPTS=o,e.endDTS=a;var c,f=e.sn;if(!t||ft.endSN)return 0;var g=f-t.startSN,v=t.fragments;for(v[g]=e,c=g;c>0;c--)Xe(v[c],v[c-1]);for(c=g;c=0;n--){var a=i[n].initSegment;if(a){r=a;break}}t.fragmentHint&&delete t.fragmentHint.endPTS;var s,l,u,h,d,c=0;if(function(t,e,r){for(var i=e.skippedSegments,n=Math.max(t.startSN,e.startSN)-e.startSN,a=(t.fragmentHint?1:0)+(i?e.endSN:Math.min(t.endSN,e.endSN))-e.startSN,s=e.startSN-t.startSN,o=e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments,l=t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments,u=n;u<=a;u++){var h=l[s+u],d=o[u];i&&!d&&u=i.length||$e(e,i[r].start)}function $e(t,e){if(e){for(var r=t.fragments,i=t.skippedSegments;i499)}(n)||!!r);return t.shouldRetry?t.shouldRetry(t,e,r,i,a):a}var or=function(t,e){for(var r=0,i=t.length-1,n=null,a=null;r<=i;){var s=e(a=t[n=(r+i)/2|0]);if(s>0)r=n+1;else{if(!(s<0))return a;i=n-1}}return null};function lr(t,e,r,i,n){void 0===r&&(r=0),void 0===i&&(i=0),void 0===n&&(n=.005);var a=null;if(t){a=e[t.sn-e[0].sn+1]||null;var s=t.endDTS-r;s>0&&s<15e-7&&(r+=15e-7)}else 0===r&&0===e[0].start&&(a=e[0]);if(a&&((!t||t.level===a.level)&&0===ur(r,i,a)||function(t,e,r){if(e&&0===e.start&&e.level0){var i=e.tagList.reduce((function(t,e){return"INF"===e[0]&&(t+=parseFloat(e[1])),t}),r);return t.start<=i}return!1}(a,t,Math.min(n,i))))return a;var o=or(e,ur.bind(null,r,i));return!o||o===t&&a?a:o}function ur(t,e,r){if(void 0===t&&(t=0),void 0===e&&(e=0),r.start<=t&&r.start+r.duration>t)return 0;var i=Math.min(e,r.duration+(r.deltaPTS?r.deltaPTS:0));return r.start+r.duration-i<=t?1:r.start-i>t&&r.start?-1:0}function hr(t,e,r){var i=1e3*Math.min(e,r.duration+(r.deltaPTS?r.deltaPTS:0));return(r.endProgramDateTime||0)-i>t}var dr=function(){function t(t){this.hls=void 0,this.playlistError=0,this.penalizedRenditions={},this.log=void 0,this.warn=void 0,this.error=void 0,this.hls=t,this.log=b.log.bind(b,"[info]:"),this.warn=b.warn.bind(b,"[warning]:"),this.error=b.error.bind(b,"[error]:"),this.registerListeners()}var e=t.prototype;return e.registerListeners=function(){var t=this.hls;t.on(T.ERROR,this.onError,this),t.on(T.MANIFEST_LOADING,this.onManifestLoading,this),t.on(T.LEVEL_UPDATED,this.onLevelUpdated,this)},e.unregisterListeners=function(){var t=this.hls;t&&(t.off(T.ERROR,this.onError,this),t.off(T.ERROR,this.onErrorOut,this),t.off(T.MANIFEST_LOADING,this.onManifestLoading,this),t.off(T.LEVEL_UPDATED,this.onLevelUpdated,this))},e.destroy=function(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}},e.startLoad=function(t){},e.stopLoad=function(){this.playlistError=0},e.getVariantLevelIndex=function(t){return(null==t?void 0:t.type)===Re?t.level:this.hls.loadLevel},e.onManifestLoading=function(){this.playlistError=0,this.penalizedRenditions={}},e.onLevelUpdated=function(){this.playlistError=0},e.onError=function(t,e){var r,i;if(!e.fatal){var n=this.hls,a=e.context;switch(e.details){case S.FRAG_LOAD_ERROR:case S.FRAG_LOAD_TIMEOUT:case S.KEY_LOAD_ERROR:case S.KEY_LOAD_TIMEOUT:return void(e.errorAction=this.getFragRetryOrSwitchAction(e));case S.FRAG_PARSING_ERROR:if(null!=(r=e.frag)&&r.gap)return void(e.errorAction={action:0,flags:0});case S.FRAG_GAP:case S.FRAG_DECRYPT_ERROR:return e.errorAction=this.getFragRetryOrSwitchAction(e),void(e.errorAction.action=2);case S.LEVEL_EMPTY_ERROR:case S.LEVEL_PARSING_ERROR:var s,o,l=e.parent===Re?e.level:n.loadLevel;return void(e.details===S.LEVEL_EMPTY_ERROR&&null!=(s=e.context)&&null!=(o=s.levelDetails)&&o.live?e.errorAction=this.getPlaylistRetryOrSwitchAction(e,l):(e.levelRetry=!1,e.errorAction=this.getLevelSwitchAction(e,l)));case S.LEVEL_LOAD_ERROR:case S.LEVEL_LOAD_TIMEOUT:return void("number"==typeof(null==a?void 0:a.level)&&(e.errorAction=this.getPlaylistRetryOrSwitchAction(e,a.level)));case S.AUDIO_TRACK_LOAD_ERROR:case S.AUDIO_TRACK_LOAD_TIMEOUT:case S.SUBTITLE_LOAD_ERROR:case S.SUBTITLE_TRACK_LOAD_TIMEOUT:if(a){var u=n.levels[n.loadLevel];if(u&&(a.type===Se&&u.hasAudioGroup(a.groupId)||a.type===Le&&u.hasSubtitleGroup(a.groupId)))return e.errorAction=this.getPlaylistRetryOrSwitchAction(e,n.loadLevel),e.errorAction.action=2,void(e.errorAction.flags=1)}return;case S.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:var h=n.levels[n.loadLevel],d=null==h?void 0:h.attrs["HDCP-LEVEL"];return void(d?e.errorAction={action:2,flags:2,hdcpLevel:d}:this.keySystemError(e));case S.BUFFER_ADD_CODEC_ERROR:case S.REMUX_ALLOC_ERROR:case S.BUFFER_APPEND_ERROR:return void(e.errorAction=this.getLevelSwitchAction(e,null!=(i=e.level)?i:n.loadLevel));case S.INTERNAL_EXCEPTION:case S.BUFFER_APPENDING_ERROR:case S.BUFFER_FULL_ERROR:case S.LEVEL_SWITCH_ERROR:case S.BUFFER_STALLED_ERROR:case S.BUFFER_SEEK_OVER_HOLE:case S.BUFFER_NUDGE_ON_STALL:return void(e.errorAction={action:0,flags:0})}e.type===E.KEY_SYSTEM_ERROR&&this.keySystemError(e)}},e.keySystemError=function(t){var e=this.getVariantLevelIndex(t.frag);t.levelRetry=!1,t.errorAction=this.getLevelSwitchAction(t,e)},e.getPlaylistRetryOrSwitchAction=function(t,e){var r=ir(this.hls.config.playlistLoadPolicy,t),i=this.playlistError++;if(sr(r,i,rr(t),t.response))return{action:5,flags:0,retryConfig:r,retryCount:i};var n=this.getLevelSwitchAction(t,e);return r&&(n.retryConfig=r,n.retryCount=i),n},e.getFragRetryOrSwitchAction=function(t){var e=this.hls,r=this.getVariantLevelIndex(t.frag),i=e.levels[r],n=e.config,a=n.fragLoadPolicy,s=n.keyLoadPolicy,o=ir(t.details.startsWith("key")?s:a,t),l=e.levels.reduce((function(t,e){return t+e.fragmentError}),0);if(i&&(t.details!==S.FRAG_GAP&&i.fragmentError++,sr(o,l,rr(t),t.response)))return{action:5,flags:0,retryConfig:o,retryCount:l};var u=this.getLevelSwitchAction(t,r);return o&&(u.retryConfig=o,u.retryCount=l),u},e.getLevelSwitchAction=function(t,e){var r=this.hls;null==e&&(e=r.loadLevel);var i=this.hls.levels[e];if(i){var n,a,s=t.details;i.loadError++,s===S.BUFFER_APPEND_ERROR&&i.fragmentError++;var o=-1,l=r.levels,u=r.loadLevel,h=r.minAutoLevel,d=r.maxAutoLevel;r.autoLevelEnabled||(r.loadLevel=-1);for(var c,f=null==(n=t.frag)?void 0:n.type,g=(f===ke&&s===S.FRAG_PARSING_ERROR||"audio"===t.sourceBufferName&&(s===S.BUFFER_ADD_CODEC_ERROR||s===S.BUFFER_APPEND_ERROR))&&l.some((function(t){var e=t.audioCodec;return i.audioCodec!==e})),v="video"===t.sourceBufferName&&(s===S.BUFFER_ADD_CODEC_ERROR||s===S.BUFFER_APPEND_ERROR)&&l.some((function(t){var e=t.codecSet,r=t.audioCodec;return i.codecSet!==e&&i.audioCodec===r})),m=null!=(a=t.context)?a:{},p=m.type,y=m.groupId,T=function(){var e=(E+u)%l.length;if(e!==u&&e>=h&&e<=d&&0===l[e].loadError){var r,n,a=l[e];if(s===S.FRAG_GAP&&f===Re&&t.frag){var c=l[e].details;if(c){var m=lr(t.frag,c.fragments,t.frag.start);if(null!=m&&m.gap)return 0}}else{if(p===Se&&a.hasAudioGroup(y)||p===Le&&a.hasSubtitleGroup(y))return 0;if(f===ke&&null!=(r=i.audioGroups)&&r.some((function(t){return a.hasAudioGroup(t)}))||f===Ae&&null!=(n=i.subtitleGroups)&&n.some((function(t){return a.hasSubtitleGroup(t)}))||g&&i.audioCodec===a.audioCodec||!g&&i.audioCodec!==a.audioCodec||v&&i.codecSet===a.codecSet)return 0}return o=e,1}},E=l.length;E--&&(0===(c=T())||1!==c););if(o>-1&&r.loadLevel!==o)return t.levelRetry=!0,this.playlistError=0,{action:2,flags:0,nextAutoLevel:o}}return{action:2,flags:1}},e.onErrorOut=function(t,e){var r;switch(null==(r=e.errorAction)?void 0:r.action){case 0:break;case 2:this.sendAlternateToPenaltyBox(e),e.errorAction.resolved||e.details===S.FRAG_GAP?/MediaSource readyState: ended/.test(e.error.message)&&(this.warn('MediaSource ended after "'+e.sourceBufferName+'" sourceBuffer append error. Attempting to recover from media error.'),this.hls.recoverMediaError()):e.fatal=!0}e.fatal&&this.hls.stopLoad()},e.sendAlternateToPenaltyBox=function(t){var e=this.hls,r=t.errorAction;if(r){var i=r.flags,n=r.hdcpLevel,a=r.nextAutoLevel;switch(i){case 0:this.switchLevel(t,a);break;case 2:n&&(e.maxHdcpLevel=Ke[Ke.indexOf(n)-1],r.resolved=!0),this.warn('Restricting playback to HDCP-LEVEL of "'+e.maxHdcpLevel+'" or lower')}r.resolved||this.switchLevel(t,a)}},e.switchLevel=function(t,e){void 0!==e&&t.errorAction&&(this.warn("switching to level "+e+" after "+t.details),this.hls.nextAutoLevel=e,t.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel)},t}(),cr=function(){function t(t,e){this.hls=void 0,this.timer=-1,this.requestScheduled=-1,this.canLoad=!1,this.log=void 0,this.warn=void 0,this.log=b.log.bind(b,e+":"),this.warn=b.warn.bind(b,e+":"),this.hls=t}var e=t.prototype;return e.destroy=function(){this.clearTimer(),this.hls=this.log=this.warn=null},e.clearTimer=function(){-1!==this.timer&&(self.clearTimeout(this.timer),this.timer=-1)},e.startLoad=function(){this.canLoad=!0,this.requestScheduled=-1,this.loadPlaylist()},e.stopLoad=function(){this.canLoad=!1,this.clearTimer()},e.switchParams=function(t,e,r){var i=null==e?void 0:e.renditionReports;if(i){for(var n=-1,a=0;a=0&&d>e.partTarget&&(h+=1)}var c=r&&je(r);return new Ye(u,h>=0?h:void 0,c)}}},e.loadPlaylist=function(t){-1===this.requestScheduled&&(this.requestScheduled=self.performance.now())},e.shouldLoadPlaylist=function(t){return this.canLoad&&!!t&&!!t.url&&(!t.details||t.details.live)},e.shouldReloadPlaylist=function(t){return-1===this.timer&&-1===this.requestScheduled&&this.shouldLoadPlaylist(t)},e.playlistLoaded=function(t,e,r){var i=this,n=e.details,a=e.stats,s=self.performance.now(),o=a.loading.first?Math.max(0,s-a.loading.first):0;if(n.advancedDateTime=Date.now()-o,n.live||null!=r&&r.live){if(n.reloaded(r),r&&this.log("live playlist "+t+" "+(n.advanced?"REFRESHED "+n.lastPartSn+"-"+n.lastPartIndex:n.updated?"UPDATED":"MISSED")),r&&n.fragments.length>0&&Qe(r,n),!this.canLoad||!n.live)return;var l,u=void 0,h=void 0;if(n.canBlockReload&&n.endSN&&n.advanced){var d=this.hls.config.lowLatencyMode,c=n.lastPartSn,f=n.endSN,g=n.lastPartIndex,v=c===f;-1!==g?(u=v?f+1:c,h=v?d?0:g:g+1):u=f+1;var m=n.age,p=m+n.ageHeader,y=Math.min(p-n.partTarget,1.5*n.targetduration);if(y>0){if(r&&y>r.tuneInGoal)this.warn("CDN Tune-in goal increased from: "+r.tuneInGoal+" to: "+y+" with playlist age: "+n.age),y=0;else{var T=Math.floor(y/n.targetduration);u+=T,void 0!==h&&(h+=Math.round(y%n.targetduration/n.partTarget)),this.log("CDN Tune-in age: "+n.ageHeader+"s last advanced "+m.toFixed(2)+"s goal: "+y+" skip sn "+T+" to part "+h)}n.tuneInGoal=y}if(l=this.getDeliveryDirectives(n,e.deliveryDirectives,u,h),d||!v)return void this.loadPlaylist(l)}else(n.canBlockReload||n.canSkipUntil)&&(l=this.getDeliveryDirectives(n,e.deliveryDirectives,u,h));var E=this.hls.mainForwardBufferInfo,S=E?E.end-E.len:0,L=function(t,e){void 0===e&&(e=1/0);var r=1e3*t.targetduration;if(t.updated){var i=t.fragments;if(i.length&&4*r>e){var n=1e3*i[i.length-1].duration;nthis.requestScheduled+L&&(this.requestScheduled=a.loading.start),void 0!==u&&n.canBlockReload?this.requestScheduled=a.loading.first+L-(1e3*n.partTarget||1e3):-1===this.requestScheduled||this.requestScheduled+L=u.maxNumRetry)return!1;if(i&&null!=(d=t.context)&&d.deliveryDirectives)this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" without delivery-directives'),this.loadPlaylist();else{var c=nr(u,l);this.timer=self.setTimeout((function(){return e.loadPlaylist()}),c),this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" in '+c+"ms")}t.levelRetry=!0,n.resolved=!0}return h},t}(),fr=function(){function t(t,e,r){void 0===e&&(e=0),void 0===r&&(r=0),this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=t,this.alpha_=t?Math.exp(Math.log(.5)/t):0,this.estimate_=e,this.totalWeight_=r}var e=t.prototype;return e.sample=function(t,e){var r=Math.pow(this.alpha_,t);this.estimate_=e*(1-r)+r*this.estimate_,this.totalWeight_+=t},e.getTotalWeight=function(){return this.totalWeight_},e.getEstimate=function(){if(this.alpha_){var t=1-Math.pow(this.alpha_,this.totalWeight_);if(t)return this.estimate_/t}return this.estimate_},t}(),gr=function(){function t(t,e,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 fr(t),this.fast_=new fr(e),this.defaultTTFB_=i,this.ttfb_=new fr(t)}var e=t.prototype;return e.update=function(t,e){var r=this.slow_,i=this.fast_,n=this.ttfb_;r.halfLife!==t&&(this.slow_=new fr(t,r.getEstimate(),r.getTotalWeight())),i.halfLife!==e&&(this.fast_=new fr(e,i.getEstimate(),i.getTotalWeight())),n.halfLife!==t&&(this.ttfb_=new fr(t,n.getEstimate(),n.getTotalWeight()))},e.sample=function(t,e){var r=(t=Math.max(t,this.minDelayMs_))/1e3,i=8*e/r;this.fast_.sample(r,i),this.slow_.sample(r,i)},e.sampleTTFB=function(t){var e=t/1e3,r=Math.sqrt(2)*Math.exp(-Math.pow(e,2)/2);this.ttfb_.sample(r,Math.max(t,5))},e.canEstimate=function(){return this.fast_.getTotalWeight()>=this.minWeight_},e.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},e.getEstimateTTFB=function(){return this.ttfb_.getTotalWeight()>=this.minWeight_?this.ttfb_.getEstimate():this.defaultTTFB_},e.destroy=function(){},t}(),vr={supported:!0,configurations:[],decodingInfoResults:[{supported:!0,powerEfficient:!0,smooth:!0}]},mr={};function pr(t,r,i){var n=t.videoCodec,a=t.audioCodec;if(!n||!a||!i)return Promise.resolve(vr);var s={width:t.width,height:t.height,bitrate:Math.ceil(Math.max(.9*t.bitrate,t.averageBitrate)),framerate:t.frameRate||30},o=t.videoRange;"SDR"!==o&&(s.transferFunction=o.toLowerCase());var l=n.split(",").map((function(t){return{type:"media-source",video:e(e({},s),{},{contentType:Jt(t,"video")})}}));return a&&t.audioGroups&&t.audioGroups.forEach((function(t){var e;t&&(null==(e=r.groups[t])||e.tracks.forEach((function(e){if(e.groupId===t){var r=e.channels||"",i=parseFloat(r);m(i)&&i>2&&l.push.apply(l,a.split(",").map((function(t){return{type:"media-source",audio:{contentType:Jt(t,"audio"),channels:""+i}}})))}})))})),Promise.all(l.map((function(t){var e=function(t){var e=t.audio,r=t.video,i=r||e;if(i){var n=i.contentType.split('"')[1];if(r)return"r"+r.height+"x"+r.width+"f"+Math.ceil(r.framerate)+(r.transferFunction||"sd")+"_"+n+"_"+Math.ceil(r.bitrate/1e5);if(e)return"c"+e.channels+(e.spatialRendering?"s":"n")+"_"+n}return""}(t);return mr[e]||(mr[e]=i.decodingInfo(t))}))).then((function(t){return{supported:!t.some((function(t){return!t.supported})),configurations:l,decodingInfoResults:t}})).catch((function(t){return{supported:!1,configurations:l,decodingInfoResults:[],error:t}}))}function yr(t,e){b.log('[abr] start candidates with "'+t+'" ignored because '+e)}function Tr(t,e,r){if("attrs"in t){var i=e.indexOf(t);if(-1!==i)return i}for(var n=0;n-1,y=e.getBwEstimate(),E=i.levels,S=E[t.level],L=o.total||Math.max(o.loaded,Math.round(l*S.averageBitrate/8)),R=p?u-v:u;R<1&&p&&(R=Math.min(u,8*o.loaded/y));var k=p?1e3*o.loaded/R:0,A=k?(L-o.loaded)/k:8*L/y+c/1e3;if(!(A<=g)){var D,_=k?8*k:y,C=Number.POSITIVE_INFINITY;for(D=t.level-1;D>h;D--){var w=E[D].maxBitrate;if((C=e.getTimeToLoadFrag(c/1e3,_,l*w,!E[D].details))=A||C>10*l)){i.nextLoadLevel=i.nextAutoLevel=D,p?e.bwEstimator.sample(u-Math.min(c,v),o.loaded):e.bwEstimator.sampleTTFB(u);var I=E[D].maxBitrate;e.getBwEstimate()*e.hls.config.abrBandWidthUpFactor>I&&e.resetEstimator(I),e.clearTimer(),b.warn("[abr] Fragment "+t.sn+(r?" part "+r.index:"")+" of level "+t.level+" is loading too slowly;\n Time to underbuffer: "+g.toFixed(3)+" s\n Estimated load time for current fragment: "+A.toFixed(3)+" s\n Estimated load time for down switch fragment: "+C.toFixed(3)+" s\n TTFB estimate: "+(0|v)+" ms\n Current BW estimate: "+(m(y)?0|y:"Unknown")+" bps\n New BW estimate: "+(0|e.getBwEstimate())+" bps\n Switching to level "+D+" @ "+(0|I)+" bps"),i.trigger(T.FRAG_LOAD_EMERGENCY_ABORTED,{frag:t,part:r,stats:o})}}}}}}},this.hls=t,this.bwEstimator=this.initEstimator(),this.registerListeners()}var e=t.prototype;return e.resetEstimator=function(t){t&&(b.log("setting initial bwe to "+t),this.hls.config.abrEwmaDefaultEstimate=t),this.firstSelection=-1,this.bwEstimator=this.initEstimator()},e.initEstimator=function(){var t=this.hls.config;return new gr(t.abrEwmaSlowVoD,t.abrEwmaFastVoD,t.abrEwmaDefaultEstimate)},e.registerListeners=function(){var t=this.hls;t.on(T.MANIFEST_LOADING,this.onManifestLoading,this),t.on(T.FRAG_LOADING,this.onFragLoading,this),t.on(T.FRAG_LOADED,this.onFragLoaded,this),t.on(T.FRAG_BUFFERED,this.onFragBuffered,this),t.on(T.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(T.LEVEL_LOADED,this.onLevelLoaded,this),t.on(T.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(T.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),t.on(T.ERROR,this.onError,this)},e.unregisterListeners=function(){var t=this.hls;t&&(t.off(T.MANIFEST_LOADING,this.onManifestLoading,this),t.off(T.FRAG_LOADING,this.onFragLoading,this),t.off(T.FRAG_LOADED,this.onFragLoaded,this),t.off(T.FRAG_BUFFERED,this.onFragBuffered,this),t.off(T.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(T.LEVEL_LOADED,this.onLevelLoaded,this),t.off(T.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(T.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),t.off(T.ERROR,this.onError,this))},e.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this._abandonRulesCheck=null,this.fragCurrent=this.partCurrent=null},e.onManifestLoading=function(t,e){this.lastLoadedFragLevel=-1,this.firstSelection=-1,this.lastLevelLoadSec=0,this.fragCurrent=this.partCurrent=null,this.onLevelsUpdated(),this.clearTimer()},e.onLevelsUpdated=function(){this.lastLoadedFragLevel>-1&&this.fragCurrent&&(this.lastLoadedFragLevel=this.fragCurrent.level),this._nextAutoLevel=-1,this.onMaxAutoLevelUpdated(),this.codecTiers=null,this.audioTracksByGroup=null},e.onMaxAutoLevelUpdated=function(){this.firstSelection=-1,this.nextAutoLevelKey=""},e.onFragLoading=function(t,e){var r,i=e.frag;this.ignoreFragment(i)||(i.bitrateTest||(this.fragCurrent=i,this.partCurrent=null!=(r=e.part)?r:null),this.clearTimer(),this.timer=self.setInterval(this._abandonRulesCheck,100))},e.onLevelSwitching=function(t,e){this.clearTimer()},e.onError=function(t,e){if(!e.fatal)switch(e.details){case S.BUFFER_ADD_CODEC_ERROR:case S.BUFFER_APPEND_ERROR:this.lastLoadedFragLevel=-1,this.firstSelection=-1;break;case S.FRAG_LOAD_TIMEOUT:var r=e.frag,i=this.fragCurrent,n=this.partCurrent;if(r&&i&&r.sn===i.sn&&r.level===i.level){var a=performance.now(),s=n?n.stats:r.stats,o=a-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)}}},e.getTimeToLoadFrag=function(t,e,r,i){return t+r/e+(i?this.lastLevelLoadSec:0)},e.onLevelLoaded=function(t,e){var r=this.hls.config,i=e.stats.loading,n=i.end-i.start;m(n)&&(this.lastLevelLoadSec=n/1e3),e.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD)},e.onFragLoaded=function(t,e){var r=e.frag,i=e.part,n=i?i.stats:r.stats;if(r.type===Re&&this.bwEstimator.sampleTTFB(n.loading.first-n.loading.start),!this.ignoreFragment(r)){if(this.clearTimer(),r.level===this._nextAutoLevel&&(this._nextAutoLevel=-1),this.firstSelection=-1,this.hls.config.abrMaxWithRealBitrate){var a=i?i.duration:r.duration,s=this.hls.levels[r.level],o=(s.loaded?s.loaded.bytes:0)+n.loaded,l=(s.loaded?s.loaded.duration:0)+a;s.loaded={bytes:o,duration:l},s.realBitrate=Math.round(8*o/l)}if(r.bitrateTest){var u={stats:n,frag:r,part:i,id:r.type};this.onFragBuffered(T.FRAG_BUFFERED,u),r.bitrateTest=!1}else this.lastLoadedFragLevel=r.level}},e.onFragBuffered=function(t,e){var r=e.frag,i=e.part,n=null!=i&&i.stats.loaded?i.stats:r.stats;if(!n.aborted&&!this.ignoreFragment(r)){var a=n.parsing.end-n.loading.start-Math.min(n.loading.first-n.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(a,n.loaded),n.bwEstimate=this.getBwEstimate(),r.bitrateTest?this.bitrateTestDelay=a/1e3:this.bitrateTestDelay=0}},e.ignoreFragment=function(t){return t.type!==Re||"initSegment"===t.sn},e.clearTimer=function(){this.timer>-1&&(self.clearInterval(this.timer),this.timer=-1)},e.getAutoLevelKey=function(){return this.getBwEstimate()+"_"+this.getStarvationDelay().toFixed(2)},e.getNextABRAutoLevel=function(){var t=this.fragCurrent,e=this.partCurrent,r=this.hls,i=r.maxAutoLevel,n=r.config,a=r.minAutoLevel,s=e?e.duration:t?t.duration:0,o=this.getBwEstimate(),l=this.getStarvationDelay(),u=n.abrBandWidthFactor,h=n.abrBandWidthUpFactor;if(l){var d=this.findBestLevel(o,a,i,l,0,u,h);if(d>=0)return d}var c=s?Math.min(s,n.maxStarvationDelay):n.maxStarvationDelay;if(!l){var f=this.bitrateTestDelay;f&&(c=(s?Math.min(s,n.maxLoadingDelay):n.maxLoadingDelay)-f,b.info("[abr] bitrate test took "+Math.round(1e3*f)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*c)+" ms"),u=h=1)}var g=this.findBestLevel(o,a,i,l,c,u,h);if(b.info("[abr] "+(l?"rebuffering expected":"buffer is empty")+", optimal quality level "+g),g>-1)return g;var v=r.levels[a],m=r.levels[r.loadLevel];return(null==v?void 0:v.bitrate)<(null==m?void 0:m.bitrate)?a:r.loadLevel},e.getStarvationDelay=function(){var t=this.hls,e=t.media;if(!e)return 1/0;var r=e&&0!==e.playbackRate?Math.abs(e.playbackRate):1,i=t.mainForwardBufferInfo;return(i?i.len:0)/r},e.getBwEstimate=function(){return this.bwEstimator.canEstimate()?this.bwEstimator.getEstimate():this.hls.config.abrEwmaDefaultEstimate},e.findBestLevel=function(t,e,r,i,n,a,s){var o,l=this,u=i+n,h=this.lastLoadedFragLevel,d=-1===h?this.hls.firstLevel:h,c=this.fragCurrent,f=this.partCurrent,g=this.hls,v=g.levels,p=g.allAudioTracks,y=g.loadLevel,T=g.config;if(1===v.length)return 0;var E,S=v[d],L=!(null==S||null==(o=S.details)||!o.live),R=-1===y||-1===h,k="SDR",A=(null==S?void 0:S.frameRate)||0,D=T.audioPreference,_=T.videoPreference,C=this.audioTracksByGroup||(this.audioTracksByGroup=function(t){return t.reduce((function(t,e){var r=t.groups[e.groupId];r||(r=t.groups[e.groupId]={tracks:[],channels:{2:0},hasDefault:!1,hasAutoSelect:!1}),r.tracks.push(e);var i=e.channels||"2";return r.channels[i]=(r.channels[i]||0)+1,r.hasDefault=r.hasDefault||e.default,r.hasAutoSelect=r.hasAutoSelect||e.autoselect,r.hasDefault&&(t.hasDefaultAudio=!0),r.hasAutoSelect&&(t.hasAutoSelectAudio=!0),t}),{hasDefaultAudio:!1,hasAutoSelectAudio:!1,groups:{}})}(p));if(R){if(-1!==this.firstSelection)return this.firstSelection;var w=this.codecTiers||(this.codecTiers=function(t,e,r,i){return t.slice(r,i+1).reduce((function(t,r){if(!r.codecSet)return t;var i=r.audioGroups,n=t[r.codecSet];n||(t[r.codecSet]=n={minBitrate:1/0,minHeight:1/0,minFramerate:1/0,maxScore:0,videoRanges:{SDR:0},channels:{2:0},hasDefaultAudio:!i,fragmentError:0}),n.minBitrate=Math.min(n.minBitrate,r.bitrate);var a=Math.min(r.height,r.width);return n.minHeight=Math.min(n.minHeight,a),n.minFramerate=Math.min(n.minFramerate,r.frameRate),n.maxScore=Math.max(n.maxScore,r.score),n.fragmentError+=r.fragmentError,n.videoRanges[r.videoRange]=(n.videoRanges[r.videoRange]||0)+1,i&&i.forEach((function(t){if(t){var r=e.groups[t];r&&(n.hasDefaultAudio=n.hasDefaultAudio||e.hasDefaultAudio?r.hasDefault:r.hasAutoSelect||!e.hasDefaultAudio&&!e.hasAutoSelectAudio,Object.keys(r.channels).forEach((function(t){n.channels[t]=(n.channels[t]||0)+r.channels[t]})))}})),t}),{})}(v,C,e,r)),I=function(t,e,r,i,n){for(var a=Object.keys(t),s=null==i?void 0:i.channels,o=null==i?void 0:i.audioCodec,l=s&&2===parseInt(s),u=!0,h=!1,d=1/0,c=1/0,f=1/0,g=0,v=[],p=function(t,e){var r=!1,i=[];return t&&(r="SDR"!==t,i=[t]),e&&(i=e.allowedVideoRanges||Ve.slice(0),i=(r=void 0!==e.preferHDR?e.preferHDR:function(){if("function"==typeof matchMedia){var t=matchMedia("(dynamic-range: high)"),e=matchMedia("bad query");if(t.media!==e.media)return!0===t.matches}return!1}())?i.filter((function(t){return"SDR"!==t})):["SDR"]),{preferHDR:r,allowedVideoRanges:i}}(e,n),y=p.preferHDR,T=p.allowedVideoRanges,E=function(){var e=t[a[S]];u=e.channels[2]>0,d=Math.min(d,e.minHeight),c=Math.min(c,e.minFramerate),f=Math.min(f,e.minBitrate);var r=T.filter((function(t){return e.videoRanges[t]>0}));r.length>0&&(h=!0,v=r)},S=a.length;S--;)E();d=m(d)?d:0,c=m(c)?c:0;var L=Math.max(1080,d),R=Math.max(30,c);return f=m(f)?f:r,r=Math.max(f,r),h||(e=void 0,v=[]),{codecSet:a.reduce((function(e,i){var n=t[i];if(i===e)return e;if(n.minBitrate>r)return yr(i,"min bitrate of "+n.minBitrate+" > current estimate of "+r),e;if(!n.hasDefaultAudio)return yr(i,"no renditions with default or auto-select sound found"),e;if(o&&i.indexOf(o.substring(0,4))%5!=0)return yr(i,'audio codec preference "'+o+'" not found'),e;if(s&&!l){if(!n.channels[s])return yr(i,"no renditions with "+s+" channel sound found (channels options: "+Object.keys(n.channels)+")"),e}else if((!o||l)&&u&&0===n.channels[2])return yr(i,"no renditions with stereo sound found"),e;return n.minHeight>L?(yr(i,"min resolution of "+n.minHeight+" > maximum of "+L),e):n.minFramerate>R?(yr(i,"min framerate of "+n.minFramerate+" > maximum of "+R),e):v.some((function(t){return n.videoRanges[t]>0}))?n.maxScore=ee(e)||n.fragmentError>t[e].fragmentError)?e:(g=n.maxScore,i):(yr(i,"no variants with VIDEO-RANGE of "+JSON.stringify(v)+" found"),e)}),void 0),videoRanges:v,preferHDR:y,minFramerate:c,minBitrate:f}}(w,k,t,D,_),x=I.codecSet,P=I.videoRanges,O=I.minFramerate,M=I.minBitrate,F=I.preferHDR;E=x,k=F?P[P.length-1]:P[0],A=O,t=Math.max(t,M),b.log("[abr] picked start tier "+JSON.stringify(I))}else E=null==S?void 0:S.codecSet,k=null==S?void 0:S.videoRange;for(var N,U=f?f.duration:c?c.duration:0,B=this.bwEstimator.getEstimateTTFB()/1e3,G=[],H=function(){var e,o=v[K],c=K>d;if(!o)return 0;if(T.useMediaCapabilities&&!o.supportedResult&&!o.supportedPromise){var g=navigator.mediaCapabilities;"function"==typeof(null==g?void 0:g.decodingInfo)&&function(t,e,r,i,n,a){var s=t.audioCodec?t.audioGroups:null,o=null==a?void 0:a.audioCodec,l=null==a?void 0:a.channels,u=l?parseInt(l):o?1/0:2,h=null;if(null!=s&&s.length)try{h=1===s.length&&s[0]?e.groups[s[0]].channels:s.reduce((function(t,r){if(r){var i=e.groups[r];if(!i)throw new Error("Audio track group "+r+" not found");Object.keys(i.channels).forEach((function(e){t[e]=(t[e]||0)+i.channels[e]}))}return t}),{2:0})}catch(t){return!0}return void 0!==t.videoCodec&&(t.width>1920&&t.height>1088||t.height>1920&&t.width>1088||t.frameRate>Math.max(i,30)||"SDR"!==t.videoRange&&t.videoRange!==r||t.bitrate>Math.max(n,8e6))||!!h&&m(u)&&Object.keys(h).some((function(t){return parseInt(t)>u}))}(o,C,k,A,t,D)?(o.supportedPromise=pr(o,C,g),o.supportedPromise.then((function(t){if(l.hls){o.supportedResult=t;var e=l.hls.levels,r=e.indexOf(o);t.error?b.warn('[abr] MediaCapabilities decodingInfo error: "'+t.error+'" for level '+r+" "+JSON.stringify(t)):t.supported||(b.warn("[abr] Unsupported MediaCapabilities decodingInfo result for level "+r+" "+JSON.stringify(t)),r>-1&&e.length>1&&(b.log("[abr] Removing unsupported level "+r),l.hls.removeLevel(r)))}}))):o.supportedResult=vr}if(E&&o.codecSet!==E||k&&o.videoRange!==k||c&&A>o.frameRate||!c&&A>0&&A=2*U&&0===n?v[K].averageBitrate:v[K].maxBitrate,x=l.getTimeToLoadFrag(B,p,I*w,void 0===_);if(p>=I&&(K===h||0===o.loadError&&0===o.fragmentError)&&(x<=B||!m(x)||L&&!l.bitrateTestDelay||x"+K+" adjustedbw("+Math.round(p)+")-bitrate="+Math.round(p-I)+" ttfb:"+B.toFixed(1)+" avgDuration:"+w.toFixed(1)+" maxFetchDuration:"+u.toFixed(1)+" fetchDuration:"+x.toFixed(1)+" firstSelection:"+R+" codecSet:"+E+" videoRange:"+k+" hls.loadLevel:"+y)),R&&(l.firstSelection=K),{v:K}}},K=r;K>=e;K--)if(0!==(N=H())&&N)return N.v;return-1},s(t,[{key:"firstAutoLevel",get:function(){var t=this.hls,e=t.maxAutoLevel,r=t.minAutoLevel,i=this.getBwEstimate(),n=this.hls.config.maxStarvationDelay,a=this.findBestLevel(i,r,e,0,n,1,1);if(a>-1)return a;var s=this.hls.firstLevel,o=Math.min(Math.max(s,r),e);return b.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 t=this.forcedAutoLevel,e=this.bwEstimator.canEstimate(),r=this.lastLoadedFragLevel>-1;if(!(-1===t||e&&r&&this.nextAutoLevelKey!==this.getAutoLevelKey()))return t;var i=e&&r?this.getNextABRAutoLevel():this.firstAutoLevel;if(-1!==t){var n=this.hls.levels;if(n.length>Math.max(t,i)&&n[t].loadError<=n[i].loadError)return t}return this._nextAutoLevel=i,this.nextAutoLevelKey=this.getAutoLevelKey(),i},set:function(t){var e=this.hls,r=e.maxAutoLevel,i=e.minAutoLevel,n=Math.min(Math.max(t,i),r);this._nextAutoLevel!==n&&(this.nextAutoLevelKey="",this._nextAutoLevel=n)}}]),t}(),kr=function(){function t(){this._boundTick=void 0,this._tickTimer=null,this._tickInterval=null,this._tickCallCount=0,this._boundTick=this.tick.bind(this)}var e=t.prototype;return e.destroy=function(){this.onHandlerDestroying(),this.onHandlerDestroyed()},e.onHandlerDestroying=function(){this.clearNextTick(),this.clearInterval()},e.onHandlerDestroyed=function(){},e.hasInterval=function(){return!!this._tickInterval},e.hasNextTick=function(){return!!this._tickTimer},e.setInterval=function(t){return!this._tickInterval&&(this._tickCallCount=0,this._tickInterval=self.setInterval(this._boundTick,t),!0)},e.clearInterval=function(){return!!this._tickInterval&&(self.clearInterval(this._tickInterval),this._tickInterval=null,!0)},e.clearNextTick=function(){return!!this._tickTimer&&(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0)},e.tick=function(){this._tickCallCount++,1===this._tickCallCount&&(this.doTick(),this._tickCallCount>1&&this.tickImmediate(),this._tickCallCount=0)},e.tickImmediate=function(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)},e.doTick=function(){},t}(),Ar="NOT_LOADED",br="APPENDING",Dr="PARTIAL",_r="OK",Cr=function(){function t(t){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=t,this._registerListeners()}var e=t.prototype;return e._registerListeners=function(){var t=this.hls;t.on(T.BUFFER_APPENDED,this.onBufferAppended,this),t.on(T.FRAG_BUFFERED,this.onFragBuffered,this),t.on(T.FRAG_LOADED,this.onFragLoaded,this)},e._unregisterListeners=function(){var t=this.hls;t.off(T.BUFFER_APPENDED,this.onBufferAppended,this),t.off(T.FRAG_BUFFERED,this.onFragBuffered,this),t.off(T.FRAG_LOADED,this.onFragLoaded,this)},e.destroy=function(){this._unregisterListeners(),this.fragments=this.activePartLists=this.endListFragments=this.timeRanges=null},e.getAppendedFrag=function(t,e){var r=this.activePartLists[e];if(r)for(var i=r.length;i--;){var n=r[i];if(!n)break;var a=n.end;if(n.start<=t&&null!==a&&t<=a)return n}return this.getBufferedFrag(t,e)},e.getBufferedFrag=function(t,e){for(var r=this.fragments,i=Object.keys(r),n=i.length;n--;){var a=r[i[n]];if((null==a?void 0:a.body.type)===e&&a.buffered){var s=a.body;if(s.start<=t&&t<=s.end)return s}}return null},e.detectEvictedFragments=function(t,e,r,i){var n=this;this.timeRanges&&(this.timeRanges[t]=e);var a=(null==i?void 0:i.fragment.sn)||-1;Object.keys(this.fragments).forEach((function(i){var s=n.fragments[i];if(s&&!(a>=s.body.sn))if(s.buffered||s.loaded){var o=s.range[t];o&&o.time.some((function(t){var r=!n.isTimeBuffered(t.startPTS,t.endPTS,e);return r&&n.removeFragment(s.body),r}))}else s.body.type===r&&n.removeFragment(s.body)}))},e.detectPartialFragments=function(t){var e=this,r=this.timeRanges,i=t.frag,n=t.part;if(r&&"initSegment"!==i.sn){var a=Ir(i),s=this.fragments[a];if(!(!s||s.buffered&&i.gap)){var o=!i.relurl;Object.keys(r).forEach((function(t){var a=i.elementaryStreams[t];if(a){var l=r[t],u=o||!0===a.partial;s.range[t]=e.getBufferedTimes(i,n,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),wr(s)||this.removeParts(i.sn-1,i.type)):this.removeFragment(s.body)}}},e.removeParts=function(t,e){var r=this.activePartLists[e];r&&(this.activePartLists[e]=r.filter((function(e){return e.fragment.sn>=t})))},e.fragBuffered=function(t,e){var r=Ir(t),i=this.fragments[r];!i&&e&&(i=this.fragments[r]={body:t,appendedPTS:null,loaded:null,buffered:!1,range:Object.create(null)},t.gap&&(this.hasGaps=!0)),i&&(i.loaded=null,i.buffered=!0)},e.getBufferedTimes=function(t,e,r,i){for(var n={time:[],partial:r},a=t.start,s=t.end,o=t.minEndPTS||s,l=t.maxStartPTS||a,u=0;u=h&&o<=d){n.time.push({startPTS:Math.max(a,i.start(u)),endPTS:Math.min(s,i.end(u))});break}if(ah){var c=Math.max(a,i.start(u)),f=Math.min(s,i.end(u));f>c&&(n.partial=!0,n.time.push({startPTS:c,endPTS:f}))}else if(s<=h)break}return n},e.getPartialFragment=function(t){var e,r,i,n=null,a=0,s=this.bufferPadding,o=this.fragments;return Object.keys(o).forEach((function(l){var u=o[l];u&&wr(u)&&(r=u.body.start-s,i=u.body.end+s,t>=r&&t<=i&&(e=Math.min(t-r,i-t),a<=e&&(n=u.body,a=e)))})),n},e.isEndListAppended=function(t){var e=this.endListFragments[t];return void 0!==e&&(e.buffered||wr(e))},e.getState=function(t){var e=Ir(t),r=this.fragments[e];return r?r.buffered?wr(r)?Dr:_r:br:Ar},e.isTimeBuffered=function(t,e,r){for(var i,n,a=0;a=i&&e<=n)return!0;if(e<=i)return!1}return!1},e.onFragLoaded=function(t,e){var r=e.frag,i=e.part;if("initSegment"!==r.sn&&!r.bitrateTest){var n=i?null:e,a=Ir(r);this.fragments[a]={body:r,appendedPTS:null,loaded:n,buffered:!1,range:Object.create(null)}}},e.onBufferAppended=function(t,e){var r=this,i=e.frag,n=e.part,a=e.timeRanges;if("initSegment"!==i.sn){var s=i.type;if(n){var o=this.activePartLists[s];o||(this.activePartLists[s]=o=[]),o.push(n)}this.timeRanges=a,Object.keys(a).forEach((function(t){var e=a[t];r.detectEvictedFragments(t,e,s,n)}))}},e.onFragBuffered=function(t,e){this.detectPartialFragments(e)},e.hasFragment=function(t){var e=Ir(t);return!!this.fragments[e]},e.hasParts=function(t){var e;return!(null==(e=this.activePartLists[t])||!e.length)},e.removeFragmentsInRange=function(t,e,r,i,n){var a=this;i&&!this.hasGaps||Object.keys(this.fragments).forEach((function(s){var o=a.fragments[s];if(o){var l=o.body;l.type!==r||i&&!l.gap||l.startt&&(o.buffered||n)&&a.removeFragment(l)}}))},e.removeFragment=function(t){var e=Ir(t);t.stats.loaded=0,t.clearElementaryStreamInfo();var r=this.activePartLists[t.type];if(r){var i=t.sn;this.activePartLists[t.type]=r.filter((function(t){return t.fragment.sn!==i}))}delete this.fragments[e],t.endList&&delete this.endListFragments[t.type]},e.removeAllFragments=function(){this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activePartLists=Object.create(null),this.hasGaps=!1},t}();function wr(t){var e,r,i;return t.buffered&&(t.body.gap||(null==(e=t.range.video)?void 0:e.partial)||(null==(r=t.range.audio)?void 0:r.partial)||(null==(i=t.range.audiovideo)?void 0:i.partial))}function Ir(t){return t.type+"_"+t.level+"_"+t.sn}var xr={length:0,start:function(){return 0},end:function(){return 0}},Pr=function(){function t(){}return t.isBuffered=function(e,r){try{if(e)for(var i=t.getBuffered(e),n=0;n=i.start(n)&&r<=i.end(n))return!0}catch(t){}return!1},t.bufferInfo=function(e,r,i){try{if(e){var n,a=t.getBuffered(e),s=[];for(n=0;ns&&(i[a-1].end=t[n].end):i.push(t[n])}else i.push(t[n])}else i=t;for(var o,l=0,u=e,h=e,d=0;d=c&&e>>8^255&m^99,t[f]=m,e[m]=f;var p=c[f],y=c[p],T=c[y],E=257*c[m]^16843008*m;i[f]=E<<24|E>>>8,n[f]=E<<16|E>>>16,a[f]=E<<8|E>>>24,s[f]=E,E=16843009*T^65537*y^257*p^16843008*f,l[m]=E<<24|E>>>8,u[m]=E<<16|E>>>16,h[m]=E<<8|E>>>24,d[m]=E,f?(f=p^c[c[c[T^p]]],g^=c[c[g]]):f=g=1}},e.expandKey=function(t){for(var e=this.uint8ArrayToUint32Array_(t),r=!0,i=0;is.end){var h=a>u;(a0&&null!=a&&a.key&&a.iv&&"AES-128"===a.method){var s=self.performance.now();return r.decrypter.decrypt(new Uint8Array(n),a.key.buffer,a.iv.buffer).catch((function(e){throw i.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.FRAG_DECRYPT_ERROR,fatal:!1,error:e,reason:e.message,frag:t}),e})).then((function(n){var a=self.performance.now();return i.trigger(T.FRAG_DECRYPTED,{frag:t,payload:n,stats:{tstart:s,tdecrypt:a}}),e.payload=n,r.completeInitSegmentLoad(e)}))}return r.completeInitSegmentLoad(e)})).catch((function(e){r.state!==Xr&&r.state!==ii&&(r.warn(e),r.resetFragmentLoading(t))}))},r.completeInitSegmentLoad=function(t){if(!this.levels)throw new Error("init load aborted, missing levels");var e=t.frag.stats;this.state=zr,t.frag.data=new Uint8Array(t.payload),e.parsing.start=e.buffering.start=self.performance.now(),e.parsing.end=e.buffering.end=self.performance.now(),this.tick()},r.fragContextChanged=function(t){var e=this.fragCurrent;return!t||!e||t.sn!==e.sn||t.level!==e.level},r.fragBufferedComplete=function(t,e){var r,i,n,a,s=this.mediaBuffer?this.mediaBuffer:this.media;if(this.log("Buffered "+t.type+" sn: "+t.sn+(e?" part: "+e.index:"")+" of "+(this.playlistType===Re?"level":"track")+" "+t.level+" (frag:["+(null!=(r=t.startPTS)?r:NaN).toFixed(3)+"-"+(null!=(i=t.endPTS)?i:NaN).toFixed(3)+"] > buffer:"+(s?function(t){for(var e="",r=t.length,i=0;it.end&&s.fragmentHint&&(t=s.fragmentHint);var u=this.getNextPart(l,t,r);if(u>-1){var h,d=l[u];return this.log("Loading part sn: "+t.sn+" p: "+d.index+" cc: "+t.cc+" of playlist ["+s.startSN+"-"+s.endSN+"] parts [0-"+u+"-"+(l.length-1)+"] "+("[stream-controller]"===this.logPrefix?"level":"track")+": "+t.level+", target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=d.start+d.duration,this.state=Zr,h=o?o.then((function(r){return!r||a.fragContextChanged(r.frag)?null:a.doFragPartsLoad(t,d,e,i)})).catch((function(t){return a.handleFragLoadError(t)})):this.doFragPartsLoad(t,d,e,i).catch((function(t){return a.handleFragLoadError(t)})),this.hls.trigger(T.FRAG_LOADING,{frag:t,part:d,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):h}if(!t.url||this.loadedEndOfParts(l,r))return Promise.resolve(null)}}this.log("Loading fragment "+t.sn+" cc: "+t.cc+" "+(s?"of ["+s.startSN+"-"+s.endSN+"] ":"")+("[stream-controller]"===this.logPrefix?"level":"track")+": "+t.level+", target: "+parseFloat(r.toFixed(3))),m(t.sn)&&!this.bitrateTest&&(this.nextLoadPosition=t.start+t.duration),this.state=Zr;var c,f=this.config.progressive;return c=f&&o?o.then((function(e){return!e||a.fragContextChanged(null==e?void 0:e.frag)?null:a.fragmentLoader.load(t,i)})).catch((function(t){return a.handleFragLoadError(t)})):Promise.all([this.fragmentLoader.load(t,f?i:void 0),o]).then((function(t){var e=t[0];return!f&&e&&i&&i(e),e})).catch((function(t){return a.handleFragLoadError(t)})),this.hls.trigger(T.FRAG_LOADING,{frag:t,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):c},r.doFragPartsLoad=function(t,e,r,i){var n=this;return new Promise((function(a,s){var o,l=[],u=null==(o=r.details)?void 0:o.partList;!function e(o){n.fragmentLoader.loadPart(t,o,i).then((function(i){l[o.index]=i;var s=i.part;n.hls.trigger(T.FRAG_LOADED,i);var h=Je(r,t.sn,o.index+1)||tr(u,t.sn,o.index+1);if(!h)return a({frag:t,part:s,partsLoaded:l});e(h)})).catch(s)}(e)}))},r.handleFragLoadError=function(t){if("data"in t){var e=t.data;t.data&&e.details===S.INTERNAL_ABORTED?this.handleFragLoadAborted(e.frag,e.part):this.hls.trigger(T.ERROR,e)}else this.hls.trigger(T.ERROR,{type:E.OTHER_ERROR,details:S.INTERNAL_EXCEPTION,err:t,error:t,fatal:!0});return null},r._handleTransmuxerFlush=function(t){var e=this.getCurrentContext(t);if(e&&this.state===ti){var r=e.frag,i=e.part,n=e.level,a=self.performance.now();r.stats.parsing.end=a,i&&(i.stats.parsing.end=a),this.updateLevelTiming(r,i,n,t.partial)}else this.fragCurrent||this.state===Xr||this.state===ii||(this.state=zr)},r.getCurrentContext=function(t){var e=this.levels,r=this.fragCurrent,i=t.level,n=t.sn,a=t.part;if(null==e||!e[i])return this.warn("Levels object was unset while buffering fragment "+n+" of level "+i+". The current chunk will not be buffered."),null;var s=e[i],o=a>-1?Je(s,n,a):null,l=o?o.fragment:function(t,e,r){if(null==t||!t.details)return null;var i=t.details,n=i.fragments[e-i.startSN];return n||((n=i.fragmentHint)&&n.sn===e?n:ea&&this.flushMainBuffer(s,t.start)}else this.flushMainBuffer(0,t.start)},r.getFwdBufferInfo=function(t,e){var r=this.getLoadPosition();return m(r)?this.getFwdBufferInfoAtPos(t,r,e):null},r.getFwdBufferInfoAtPos=function(t,e,r){var i=this.config.maxBufferHole,n=Pr.bufferInfo(t,e,i);if(0===n.len&&void 0!==n.nextStart){var a=this.fragmentTracker.getBufferedFrag(e,r);if(a&&n.nextStart=i&&(r.maxMaxBufferLength=n,this.warn("Reduce max buffer length to "+n+"s"),!0)},r.getAppendedFrag=function(t,e){var r=this.fragmentTracker.getAppendedFrag(t,Re);return r&&"fragment"in r?r.fragment:r},r.getNextFragment=function(t,e){var r=e.fragments,i=r.length;if(!i)return null;var n,a=this.config,s=r[0].start;if(e.live){var o=a.initialLiveManifestSize;if(ie},r.getNextFragmentLoopLoading=function(t,e,r,i,n){var a=t.gap,s=this.getNextFragment(this.nextLoadPosition,e);if(null===s)return s;if(t=s,a&&t&&!t.gap&&r.nextStart){var o=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,r.nextStart,i);if(null!==o&&r.len+o.len>=n)return this.log('buffer full after gaps in "'+i+'" playlist starting at sn: '+t.sn),null}return t},r.mapToInitFragWhenRequired=function(t){return null==t||!t.initSegment||null!=t&&t.initSegment.data||this.bitrateTest?t:t.initSegment},r.getNextPart=function(t,e,r){for(var i=-1,n=!1,a=!0,s=0,o=t.length;s-1&&rr.start&&r.loaded},r.getInitialLiveFragment=function(t,e){var r=this.fragPrevious,i=null;if(r){if(t.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: "+r.programDateTime),i=function(t,e,r){if(null===e||!Array.isArray(t)||!t.length||!m(e))return null;if(e<(t[0].programDateTime||0))return null;if(e>=(t[t.length-1].endProgramDateTime||0))return null;r=r||0;for(var i=0;i=t.startSN&&n<=t.endSN){var a=e[n-t.startSN];r.cc===a.cc&&(i=a,this.log("Live playlist, switching playlist, load frag with next SN: "+i.sn))}i||(i=function(t,e){return or(t,(function(t){return t.cce?-1:0}))}(e,r.cc),i&&this.log("Live playlist, switching playlist, load frag with same CC: "+i.sn))}}else{var s=this.hls.liveSyncPosition;null!==s&&(i=this.getFragmentAtPosition(s,this.bitrateTest?t.fragmentEnd:t.edge,t))}return i},r.getFragmentAtPosition=function(t,e,r){var i,n=this.config,a=this.fragPrevious,s=r.fragments,o=r.endSN,l=r.fragmentHint,u=n.maxFragLookUpTolerance,h=r.partList,d=!!(n.lowLatencyMode&&null!=h&&h.length&&l);if(d&&l&&!this.bitrateTest&&(s=s.concat(l),o=l.sn),i=te-u?0:u):s[s.length-1]){var c=i.sn-r.startSN,f=this.fragmentTracker.getState(i);if((f===_r||f===Dr&&i.gap)&&(a=i),a&&i.sn===a.sn&&(!d||h[0].fragment.sn>i.sn)&&a&&i.level===a.level){var g=s[c+1];i=i.sn=a-e.maxFragLookUpTolerance&&n<=s;if(null!==i&&r.duration>i&&(nr.startCC||t&&t.cc"+t.startSN+" prev-sn: "+(o?o.sn:"na")+" fragments: "+i),l}return n},r.waitForCdnTuneIn=function(t){return t.live&&t.canBlockReload&&t.partTarget&&t.tuneInGoal>Math.max(t.partHoldBack,3*t.partTarget)},r.setStartPosition=function(t,e){var r=this.startPosition;if(r "+(null==(n=this.fragCurrent)?void 0:n.url))}else{var a=e.details===S.FRAG_GAP;a&&this.fragmentTracker.fragBuffered(i,!0);var s=e.errorAction,o=s||{},l=o.action,u=o.retryCount,h=void 0===u?0:u,d=o.retryConfig;if(s&&5===l&&d){this.resetStartWhenNotLoaded(this.levelLastLoaded);var c=nr(d,h);this.warn("Fragment "+i.sn+" of "+t+" "+i.level+" errored with "+e.details+", retrying loading "+(h+1)+"/"+d.maxNumRetry+" in "+c+"ms"),s.resolved=!0,this.retryDate=self.performance.now()+c,this.state=$r}else if(d&&s){if(this.resetFragmentErrors(t),!(h.5;n&&this.reduceMaxBufferLength(i.len,(null==e?void 0:e.duration)||10);var a=!n;return a&&this.warn("Buffer full error while media.currentTime is not buffered, flush "+r+" buffer"),e&&(this.fragmentTracker.removeFragment(e),this.nextLoadPosition=e.start),this.resetLoadingState(),a}return!1},r.resetFragmentErrors=function(t){t===ke&&(this.fragCurrent=null),this.loadedmetadata||(this.startFragRequested=!1),this.state!==Xr&&(this.state=zr)},r.afterBufferFlushed=function(t,e,r){if(t){var i=Pr.getBuffered(t);this.fragmentTracker.detectEvictedFragments(e,i,r),this.state===ri&&this.resetLoadingState()}},r.resetLoadingState=function(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=zr},r.resetStartWhenNotLoaded=function(t){if(!this.loadedmetadata){this.startFragRequested=!1;var e=t?t.details:null;null!=e&&e.live?(this.startPosition=-1,this.setStartPosition(e,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}},r.resetWhenMissingContext=function(t){this.warn("The loading context changed while buffering fragment "+t.sn+" of level "+t.level+". This chunk will not be buffered."),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState()},r.removeUnbufferedFrags=function(t){void 0===t&&(t=0),this.fragmentTracker.removeFragmentsInRange(t,1/0,this.playlistType,!1,!0)},r.updateLevelTiming=function(t,e,r,i){var n,a=this,s=r.details;if(s){if(!Object.keys(t.elementaryStreams).reduce((function(e,n){var o=t.elementaryStreams[n];if(o){var l=o.endPTS-o.startPTS;if(l<=0)return a.warn("Could not parse fragment "+t.sn+" "+n+" duration reliably ("+l+")"),e||!1;var u=i?0:ze(s,t,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return a.hls.trigger(T.LEVEL_PTS_UPDATED,{details:s,level:r,drift:u,type:n,frag:t,start:o.startPTS,end:o.endPTS}),!0}return e}),!1)&&null===(null==(n=this.transmuxer)?void 0:n.error)){var o=new Error("Found no media in fragment "+t.sn+" of level "+t.level+" resetting transmuxer to fallback to playlist timing");if(0===r.fragmentError&&(r.fragmentError++,t.gap=!0,this.fragmentTracker.removeFragment(t),this.fragmentTracker.fragBuffered(t,!0)),this.warn(o.message),this.hls.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.FRAG_PARSING_ERROR,fatal:!1,error:o,frag:t,reason:"Found no media in msn "+t.sn+' of level "'+r.url+'"'}),!this.hls)return;this.resetTransmuxer()}this.state=ei,this.hls.trigger(T.FRAG_PARSED,{frag:t,part:e})}else this.warn("level.details undefined")},r.resetTransmuxer=function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)},r.recoverWorkerError=function(t){"demuxerWorker"===t.event&&(this.fragmentTracker.removeAllFragments(),this.resetTransmuxer(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState())},s(e,[{key:"state",get:function(){return this._state},set:function(t){var e=this._state;e!==t&&(this._state=t,this.log(e+"->"+t))}}]),e}(kr),oi=function(){function t(){this.chunks=[],this.dataLength=0}var e=t.prototype;return e.push=function(t){this.chunks.push(t),this.dataLength+=t.length},e.flush=function(){var t,e=this.chunks,r=this.dataLength;return e.length?(t=1===e.length?e[0]:function(t,e){for(var r=new Uint8Array(e),i=0,n=0;n0&&s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:i,type:Oe,duration:Number.POSITIVE_INFINITY});n>>5}function gi(t,e){return e+1=t.length)return!1;var i=fi(t,e);if(i<=r)return!1;var n=e+i;return n===t.length||gi(t,n)}return!1}function mi(t,e,r,i,n){if(!t.samplerate){var a=function(t,e,r,i){var n,a,s,o,l=navigator.userAgent.toLowerCase(),u=i,h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];n=1+((192&e[r+2])>>>6);var d=(60&e[r+2])>>>2;if(!(d>h.length-1))return s=(1&e[r+2])<<2,s|=(192&e[r+3])>>>6,b.log("manifest codec:"+i+", ADTS type:"+n+", samplingIndex:"+d),/firefox/i.test(l)?d>=6?(n=5,o=new Array(4),a=d-3):(n=2,o=new Array(2),a=d):-1!==l.indexOf("android")?(n=2,o=new Array(2),a=d):(n=5,o=new Array(4),i&&(-1!==i.indexOf("mp4a.40.29")||-1!==i.indexOf("mp4a.40.5"))||!i&&d>=6?a=d-3:((i&&-1!==i.indexOf("mp4a.40.2")&&(d>=6&&1===s||/vivaldi/i.test(l))||!i&&1===s)&&(n=2,o=new Array(2)),a=d)),o[0]=n<<3,o[0]|=(14&d)>>1,o[1]|=(1&d)<<7,o[1]|=s<<3,5===n&&(o[1]|=(14&a)>>1,o[2]=(1&a)<<7,o[2]|=8,o[3]=0),{config:o,samplerate:h[d],channelCount:s,codec:"mp4a.40."+n,manifestCodec:u};var c=new Error("invalid ADTS sampling index:"+d);t.emit(T.ERROR,T.ERROR,{type:E.MEDIA_ERROR,details:S.FRAG_PARSING_ERROR,fatal:!0,error:c,reason:c.message})}(e,r,i,n);if(!a)return;t.config=a.config,t.samplerate=a.samplerate,t.channelCount=a.channelCount,t.codec=a.codec,t.manifestCodec=a.manifestCodec,b.log("parsed codec:"+t.codec+", rate:"+a.samplerate+", channels:"+a.channelCount)}}function pi(t){return 9216e4/t}function yi(t,e,r,i,n){var a,s=i+n*pi(t.samplerate),o=function(t,e){var r=ci(t,e);if(e+r<=t.length){var i=fi(t,e)-r;if(i>0)return{headerLength:r,frameLength:i}}}(e,r);if(o){var l=o.frameLength,u=o.headerLength,h=u+l,d=Math.max(0,r+h-e.length);d?(a=new Uint8Array(h-u)).set(e.subarray(r+u,e.length),0):a=e.subarray(r+u,r+h);var c={unit:a,pts:s};return d||t.samples.push(c),{sample:c,length:h,missing:d}}var f=e.length-r;return(a=new Uint8Array(f)).set(e.subarray(r,e.length),0),{sample:{unit:a,pts:s},length:f,missing:-1}}var Ti=null,Ei=[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],Si=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],Li=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],Ri=[0,1,1,4];function ki(t,e,r,i,n){if(!(r+24>e.length)){var a=Ai(e,r);if(a&&r+a.frameLength<=e.length){var s=i+n*(9e4*a.samplesPerFrame/a.sampleRate),o={unit:e.subarray(r,r+a.frameLength),pts:s,dts:s};return t.config=[],t.channelCount=a.channelCount,t.samplerate=a.sampleRate,t.samples.push(o),{sample:o,length:a.frameLength,missing:0}}}}function Ai(t,e){var r=t[e+1]>>3&3,i=t[e+1]>>1&3,n=t[e+2]>>4&15,a=t[e+2]>>2&3;if(1!==r&&0!==n&&15!==n&&3!==a){var s=t[e+2]>>1&1,o=t[e+3]>>6,l=1e3*Ei[14*(3===r?3-i:3===i?3:4)+n-1],u=Si[3*(3===r?0:2===r?1:2)+a],h=3===o?1:2,d=Li[r][i],c=Ri[i],f=8*d*c,g=Math.floor(d*l/u+s)*c;if(null===Ti){var v=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Ti=v?parseInt(v[1]):0}return!!Ti&&Ti<=87&&2===i&&l>=224e3&&0===o&&(t[e+3]=128|t[e+3]),{sampleRate:u,channelCount:h,frameLength:g,samplesPerFrame:f}}}function bi(t,e){return!(255!==t[e]||224&~t[e+1]||!(6&t[e+1]))}function Di(t,e){return e+18&&109===t[r+4]&&111===t[r+5]&&111===t[r+6]&&102===t[r+7])return!0;r=i>1?r+i:e}return!1}(t)},e.demux=function(t,e){this.timeOffset=e;var r=t,i=this.videoTrack,n=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=Ft(this.remainderData,t));var a=function(t){var e={valid:null,remainder:null},r=Dt(t,["moof"]);if(r.length<2)return e.remainder=t,e;var i=r[r.length-1];return e.valid=tt(t,0,i.byteOffset-8),e.remainder=tt(t,i.byteOffset-8),e}(r);this.remainderData=a.remainder,i.samples=a.valid||new Uint8Array}else i.samples=r;var s=this.extractID3Track(i,e);return n.samples=Nt(e,i),{videoTrack:i,audioTrack:this.audioTrack,id3Track:s,textTrack:this.txtTrack}},e.flush=function(){var t=this.timeOffset,e=this.videoTrack,r=this.txtTrack;e.samples=this.remainderData||new Uint8Array,this.remainderData=null;var i=this.extractID3Track(e,this.timeOffset);return r.samples=Nt(t,e),{videoTrack:e,audioTrack:li(),id3Track:i,textTrack:li()}},e.extractID3Track=function(t,e){var r=this.id3Track;if(t.samples.length){var i=Dt(t.samples,["emsg"]);i&&i.forEach((function(t){var i=function(t){var e=t[0],r="",i="",n=0,a=0,s=0,o=0,l=0,u=0;if(0===e){for(;"\0"!==St(t.subarray(u,u+1));)r+=St(t.subarray(u,u+1)),u+=1;for(r+=St(t.subarray(u,u+1)),u+=1;"\0"!==St(t.subarray(u,u+1));)i+=St(t.subarray(u,u+1)),u+=1;i+=St(t.subarray(u,u+1)),u+=1,n=Rt(t,12),a=Rt(t,16),o=Rt(t,20),l=Rt(t,24),u=28}else if(1===e){n=Rt(t,u+=4);var h=Rt(t,u+=4),d=Rt(t,u+=4);for(u+=4,s=Math.pow(2,32)*h+d,p(s)||(s=Number.MAX_SAFE_INTEGER,b.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=Rt(t,u),l=Rt(t,u+=4),u+=4;"\0"!==St(t.subarray(u,u+1));)r+=St(t.subarray(u,u+1)),u+=1;for(r+=St(t.subarray(u,u+1)),u+=1;"\0"!==St(t.subarray(u,u+1));)i+=St(t.subarray(u,u+1)),u+=1;i+=St(t.subarray(u,u+1)),u+=1}return{schemeIdUri:r,value:i,timeScale:n,presentationTime:s,presentationTimeDelta:a,eventDuration:o,id:l,payload:t.subarray(u,t.byteLength)}}(t);if(wi.test(i.schemeIdUri)){var n=m(i.presentationTime)?i.presentationTime/i.timeScale:e+i.presentationTimeDelta/i.timeScale,a=4294967295===i.eventDuration?Number.POSITIVE_INFINITY:i.eventDuration/i.timeScale;a<=.001&&(a=Number.POSITIVE_INFINITY);var s=i.payload;r.samples.push({data:s,len:s.byteLength,dts:n,pts:n,type:Me,duration:a})}}))}return r},e.demuxSampleAes=function(t,e,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},e.destroy=function(){},t}(),xi=function(t,e){var r=0,i=5;e+=i;for(var n=new Uint32Array(1),a=new Uint32Array(1),s=new Uint8Array(1);i>0;){s[0]=t[e];var o=Math.min(i,8),l=8-o;a[0]=4278190080>>>24+l<>l,r=r?r<e.length)return-1;if(11!==e[r]||119!==e[r+1])return-1;var a=e[r+4]>>6;if(a>=3)return-1;var s=[48e3,44100,32e3][a],o=63&e[r+4],l=2*[64,69,96,64,70,96,80,87,120,80,88,120,96,104,144,96,105,144,112,121,168,112,122,168,128,139,192,128,140,192,160,174,240,160,175,240,192,208,288,192,209,288,224,243,336,224,244,336,256,278,384,256,279,384,320,348,480,320,349,480,384,417,576,384,418,576,448,487,672,448,488,672,512,557,768,512,558,768,640,696,960,640,697,960,768,835,1152,768,836,1152,896,975,1344,896,976,1344,1024,1114,1536,1024,1115,1536,1152,1253,1728,1152,1254,1728,1280,1393,1920,1280,1394,1920][3*o+a];if(r+l>e.length)return-1;var u=e[r+6]>>5,h=0;2===u?h+=2:(1&u&&1!==u&&(h+=2),4&u&&(h+=2));var d=(e[r+6]<<8|e[r+7])>>12-h&1,c=[2,1,2,3,3,4,4,5][u]+d,f=e[r+5]>>3,g=7&e[r+5],v=new Uint8Array([a<<6|f<<1|g>>2,(3&g)<<6|u<<3|d<<2|o>>4,o<<4&224]),m=i+n*(1536/s*9e4),p=e.subarray(r,r+l);return t.config=v,t.channelCount=c,t.samplerate=s,t.samples.push({unit:p,pts:m}),l}var Mi=function(){function t(){this.VideoSample=null}var e=t.prototype;return e.createVideoSample=function(t,e,r,i){return{key:t,frame:!1,pts:e,dts:r,units:[],debug:i,length:0}},e.getLastNalUnit=function(t){var e,r,i=this.VideoSample;if(i&&0!==i.units.length||(i=t[t.length-1]),null!=(e=i)&&e.units){var n=i.units;r=n[n.length-1]}return r},e.pushAccessUnit=function(t,e){if(t.units.length&&t.frame){if(void 0===t.pts){var r=e.samples,i=r.length;if(!i)return void e.dropped++;var n=r[i-1];t.pts=n.pts,t.dts=n.dts}e.samples.push(t)}t.debug.length&&b.log(t.pts+"/"+t.dts+":"+t.debug)},t}(),Fi=function(){function t(t){this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=t,this.bytesAvailable=t.byteLength,this.word=0,this.bitsAvailable=0}var e=t.prototype;return e.loadWord=function(){var t=this.data,e=this.bytesAvailable,r=t.byteLength-e,i=new Uint8Array(4),n=Math.min(4,e);if(0===n)throw new Error("no bytes available");i.set(t.subarray(r,r+n)),this.word=new DataView(i.buffer).getUint32(0),this.bitsAvailable=8*n,this.bytesAvailable-=n},e.skipBits=function(t){var e;t=Math.min(t,8*this.bytesAvailable+this.bitsAvailable),this.bitsAvailable>t?(this.word<<=t,this.bitsAvailable-=t):(t-=this.bitsAvailable,t-=(e=t>>3)<<3,this.bytesAvailable-=e,this.loadWord(),this.word<<=t,this.bitsAvailable-=t)},e.readBits=function(t){var e=Math.min(this.bitsAvailable,t),r=this.word>>>32-e;if(t>32&&b.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=e,this.bitsAvailable>0)this.word<<=e;else{if(!(this.bytesAvailable>0))throw new Error("no bits available");this.loadWord()}return(e=t-e)>0&&this.bitsAvailable?r<>>t)return this.word<<=t,this.bitsAvailable-=t,t;return this.loadWord(),t+this.skipLZ()},e.skipUEG=function(){this.skipBits(1+this.skipLZ())},e.skipEG=function(){this.skipBits(1+this.skipLZ())},e.readUEG=function(){var t=this.skipLZ();return this.readBits(t+1)-1},e.readEG=function(){var t=this.readUEG();return 1&t?1+t>>>1:-1*(t>>>1)},e.readBoolean=function(){return 1===this.readBits(1)},e.readUByte=function(){return this.readBits(8)},e.readUShort=function(){return this.readBits(16)},e.readUInt=function(){return this.readBits(32)},e.skipScalingList=function(t){for(var e=8,r=8,i=0;i4){var f=new Fi(c).readSliceType();2!==f&&4!==f&&7!==f&&9!==f||(h=!0)}h&&null!=(d=l)&&d.frame&&!l.key&&(s.pushAccessUnit(l,t),l=s.VideoSample=null),l||(l=s.VideoSample=s.createVideoSample(!0,r.pts,r.dts,"")),l.frame=!0,l.key=h;break;case 5:a=!0,null!=(o=l)&&o.frame&&!l.key&&(s.pushAccessUnit(l,t),l=s.VideoSample=null),l||(l=s.VideoSample=s.createVideoSample(!0,r.pts,r.dts,"")),l.key=!0,l.frame=!0;break;case 6:a=!0,Bt(i.data,1,r.pts,e.samples);break;case 7:var g,v;a=!0,u=!0;var m=i.data,p=new Fi(m).readSPS();if(!t.sps||t.width!==p.width||t.height!==p.height||(null==(g=t.pixelRatio)?void 0:g[0])!==p.pixelRatio[0]||(null==(v=t.pixelRatio)?void 0:v[1])!==p.pixelRatio[1]){t.width=p.width,t.height=p.height,t.pixelRatio=p.pixelRatio,t.sps=[m],t.duration=n;for(var y=m.subarray(1,4),T="avc1.",E=0;E<3;E++){var S=y[E].toString(16);S.length<2&&(S="0"+S),T+=S}t.codec=T}break;case 8:a=!0,t.pps=[i.data];break;case 9:a=!0,t.audFound=!0,l&&s.pushAccessUnit(l,t),l=s.VideoSample=s.createVideoSample(!1,r.pts,r.dts,"");break;case 12:a=!0;break;default:a=!1,l&&(l.debug+="unknown NAL "+i.type+" ")}l&&a&&l.units.push(i)})),i&&l&&(this.pushAccessUnit(l,t),this.VideoSample=null)},r.parseAVCNALu=function(t,e){var r,i,n=e.byteLength,a=t.naluState||0,s=a,o=[],l=0,u=-1,h=0;for(-1===a&&(u=0,h=31&e[0],a=0,l=1);l=0){var d={data:e.subarray(u,i),type:h};o.push(d)}else{var c=this.getLastNalUnit(t.samples);c&&(s&&l<=4-s&&c.state&&(c.data=c.data.subarray(0,c.data.byteLength-s)),i>0&&(c.data=Ft(c.data,e.subarray(0,i)),c.state=0))}l=0&&a>=0){var f={data:e.subarray(u,n),type:h,state:a};o.push(f)}if(0===o.length){var g=this.getLastNalUnit(t.samples);g&&(g.data=Ft(g.data,e))}return t.naluState=a,o},e}(Mi),Ui=function(){function t(t,e,r){this.keyData=void 0,this.decrypter=void 0,this.keyData=r,this.decrypter=new qr(e,{removePKCS7Padding:!1})}var e=t.prototype;return e.decryptBuffer=function(t){return this.decrypter.decrypt(t,this.keyData.key.buffer,this.keyData.iv.buffer)},e.decryptAacSample=function(t,e,r){var i=this,n=t[e].unit;if(!(n.length<=16)){var a=n.subarray(16,n.length-n.length%16),s=a.buffer.slice(a.byteOffset,a.byteOffset+a.length);this.decryptBuffer(s).then((function(a){var s=new Uint8Array(a);n.set(s,16),i.decrypter.isSync()||i.decryptAacSamples(t,e+1,r)}))}},e.decryptAacSamples=function(t,e,r){for(;;e++){if(e>=t.length)return void r();if(!(t[e].unit.length<32||(this.decryptAacSample(t,e,r),this.decrypter.isSync())))return}},e.getAvcEncryptedData=function(t){for(var e=16*Math.floor((t.length-48)/160)+16,r=new Int8Array(e),i=0,n=32;n=t.length)return void i();for(var n=t[e].units;!(r>=n.length);r++){var a=n[r];if(!(a.data.length<=48||1!==a.type&&5!==a.type||(this.decryptAvcSample(t,e,r,i,a),this.decrypter.isSync())))return}}},t}(),Bi=188,Gi=function(){function t(t,e,r){this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._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=t,this.config=e,this.typeSupported=r,this.videoParser=new Ni}t.probe=function(e){var r=t.syncOffset(e);return r>0&&b.warn("MPEG2-TS detected but first sync word found @ offset "+r),-1!==r},t.syncOffset=function(t){for(var e=t.length,r=Math.min(940,e-Bi)+1,i=0;i1&&(0===a&&s>2||o+Bi>r))return a}i++}return-1},t.createTrack=function(t,e){return{container:"video"===t||"audio"===t?"video/mp2t":void 0,type:t,id:Et[t],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===t?e:void 0}};var e=t.prototype;return e.resetInitSegment=function(e,r,i,n){this.pmtParsed=!1,this._pmtId=-1,this._videoTrack=t.createTrack("video"),this._audioTrack=t.createTrack("audio",n),this._id3Track=t.createTrack("id3"),this._txtTrack=t.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=i,this._duration=n},e.resetTimeStamp=function(){},e.resetContiguity=function(){var t=this._audioTrack,e=this._videoTrack,r=this._id3Track;t&&(t.pesData=null),e&&(e.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null,this.remainderData=null},e.demux=function(e,r,i,n){var a;void 0===i&&(i=!1),void 0===n&&(n=!1),i||(this.sampleAes=null);var s=this._videoTrack,o=this._audioTrack,l=this._id3Track,u=this._txtTrack,h=s.pid,d=s.pesData,c=o.pid,f=l.pid,g=o.pesData,v=l.pesData,m=null,p=this.pmtParsed,y=this._pmtId,T=e.length;if(this.remainderData&&(T=(e=Ft(this.remainderData,e)).length,this.remainderData=null),T>4>1){if((A=L+5+e[L+4])===L+Bi)continue}else A=L+4;switch(k){case h:R&&(d&&(a=Wi(d))&&this.videoParser.parseAVCPES(s,u,a,!1,this._duration),d={data:[],size:0}),d&&(d.data.push(e.subarray(A,L+Bi)),d.size+=L+Bi-A);break;case c:if(R){if(g&&(a=Wi(g)))switch(o.segmentCodec){case"aac":this.parseAACPES(o,a);break;case"mp3":this.parseMPEGPES(o,a);break;case"ac3":this.parseAC3PES(o,a)}g={data:[],size:0}}g&&(g.data.push(e.subarray(A,L+Bi)),g.size+=L+Bi-A);break;case f:R&&(v&&(a=Wi(v))&&this.parseID3PES(l,a),v={data:[],size:0}),v&&(v.data.push(e.subarray(A,L+Bi)),v.size+=L+Bi-A);break;case 0:R&&(A+=e[A]+1),y=this._pmtId=Ki(e,A);break;case y:R&&(A+=e[A]+1);var D=Vi(e,A,this.typeSupported,i,this.observer);(h=D.videoPid)>0&&(s.pid=h,s.segmentCodec=D.segmentVideoCodec),(c=D.audioPid)>0&&(o.pid=c,o.segmentCodec=D.segmentAudioCodec),(f=D.id3Pid)>0&&(l.pid=f),null===m||p||(b.warn("MPEG-TS PMT found at "+L+" after unknown PID '"+m+"'. Backtracking to sync byte @"+E+" to parse all TS packets."),m=null,L=E-188),p=this.pmtParsed=!0;break;case 17:case 8191:break;default:m=k}}else S++;S>0&&ji(this.observer,new Error("Found "+S+" TS packet/s that do not start with 0x47")),s.pesData=d,o.pesData=g,l.pesData=v;var _={audioTrack:o,videoTrack:s,id3Track:l,textTrack:u};return n&&this.extractRemainingSamples(_),_},e.flush=function(){var t,e=this.remainderData;return this.remainderData=null,t=e?this.demux(e,-1,!1,!0):{videoTrack:this._videoTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(t),this.sampleAes?this.decrypt(t,this.sampleAes):t},e.extractRemainingSamples=function(t){var e,r=t.audioTrack,i=t.videoTrack,n=t.id3Track,a=t.textTrack,s=i.pesData,o=r.pesData,l=n.pesData;if(s&&(e=Wi(s))?(this.videoParser.parseAVCPES(i,a,e,!0,this._duration),i.pesData=null):i.pesData=s,o&&(e=Wi(o))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,e);break;case"mp3":this.parseMPEGPES(r,e);break;case"ac3":this.parseAC3PES(r,e)}r.pesData=null}else null!=o&&o.size&&b.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;l&&(e=Wi(l))?(this.parseID3PES(n,e),n.pesData=null):n.pesData=l},e.demuxSampleAes=function(t,e,r){var i=this.demux(t,r,!0,!this.config.progressive),n=this.sampleAes=new Ui(this.observer,this.config,e);return this.decrypt(i,n)},e.decrypt=function(t,e){return new Promise((function(r){var i=t.audioTrack,n=t.videoTrack;i.samples&&"aac"===i.segmentCodec?e.decryptAacSamples(i.samples,0,(function(){n.samples?e.decryptAvcSamples(n.samples,0,0,(function(){r(t)})):r(t)})):n.samples&&e.decryptAvcSamples(n.samples,0,0,(function(){r(t)}))}))},e.destroy=function(){this._duration=0},e.parseAACPES=function(t,e){var r,i,n,a=0,s=this.aacOverFlow,o=e.data;if(s){this.aacOverFlow=null;var l=s.missing,u=s.sample.unit.byteLength;if(-1===l)o=Ft(s.sample.unit,o);else{var h=u-l;s.sample.unit.set(o.subarray(0,l),h),t.samples.push(s.sample),a=s.missing}}for(r=a,i=o.length;r0;)o+=n;else b.warn("[tsdemuxer]: AC3 PES unknown PTS")},e.parseID3PES=function(t,e){if(void 0!==e.pts){var r=o({},e,{type:this._videoTrack?Me:Oe,duration:Number.POSITIVE_INFINITY});t.samples.push(r)}else b.warn("[tsdemuxer]: ID3 PES unknown PTS")},t}();function Hi(t,e){return((31&t[e+1])<<8)+t[e+2]}function Ki(t,e){return(31&t[e+10])<<8|t[e+11]}function Vi(t,e,r,i,n){var a={audioPid:-1,videoPid:-1,id3Pid:-1,segmentVideoCodec:"avc",segmentAudioCodec:"aac"},s=e+3+((15&t[e+1])<<8|t[e+2])-4;for(e+=12+((15&t[e+10])<<8|t[e+11]);e0)for(var u=e+5,h=l;h>2;){106===t[u]&&(!0!==r.ac3?b.log("AC-3 audio found, not supported in this browser for now"):(a.audioPid=o,a.segmentAudioCodec="ac3"));var d=t[u+1]+2;u+=d,h-=d}break;case 194:case 135:return ji(n,new Error("Unsupported EC-3 in M2TS found")),a;case 36:return ji(n,new Error("Unsupported HEVC in M2TS found")),a}e+=l+5}return a}function ji(t,e,r){b.warn("parsing error: "+e.message),t.emit(T.ERROR,T.ERROR,{type:E.MEDIA_ERROR,details:S.FRAG_PARSING_ERROR,fatal:!1,levelRetry:r,error:e,reason:e.message})}function Yi(t){b.log(t+" with AES-128-CBC encryption found in unencrypted stream")}function Wi(t){var e,r,i,n,a,s=0,o=t.data;if(!t||0===t.size)return null;for(;o[0].length<19&&o.length>1;)o[0]=Ft(o[0],o[1]),o.splice(1,1);if(1===((e=o[0])[0]<<16)+(e[1]<<8)+e[2]){if((r=(e[4]<<8)+e[5])&&r>t.size-6)return null;var l=e[7];192&l&&(n=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&l?n-(a=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(b.warn(Math.round((n-a)/9e4)+"s delta between PTS and DTS, align them"),n=a):a=n);var u=(i=e[8])+9;if(t.size<=u)return null;t.size-=u;for(var h=new Uint8Array(t.size),d=0,c=o.length;df){u-=f;continue}e=e.subarray(u),f-=u,u=0}h.set(e,s),s+=f}return r&&(r-=i+3),{data:h,pts:n,dts:a,len:r}}return null}var qi=function(t){function e(){return t.apply(this,arguments)||this}l(e,t);var r=e.prototype;return r.resetInitSegment=function(e,r,i,n){t.prototype.resetInitSegment.call(this,e,r,i,n),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:r,duration:n,inputTimeScale:9e4,dropped:0}},e.probe=function(t){if(!t)return!1;var e=nt(t,0),r=(null==e?void 0:e.length)||0;if(e&&11===t[r]&&119===t[r+1]&&void 0!==ot(e)&&xi(t,r)<=16)return!1;for(var i=t.length;r1?r-1:0),n=1;n>24&255,o[1]=e>>16&255,o[2]=e>>8&255,o[3]=255&e,o.set(t,4),a=0,e=8;a>24&255,e>>16&255,e>>8&255,255&e,i>>24,i>>16&255,i>>8&255,255&i,n>>24,n>>16&255,n>>8&255,255&n,85,196,0,0]))},t.mdia=function(e){return t.box(t.types.mdia,t.mdhd(e.timescale,e.duration),t.hdlr(e.type),t.minf(e))},t.mfhd=function(e){return t.box(t.types.mfhd,new Uint8Array([0,0,0,0,e>>24,e>>16&255,e>>8&255,255&e]))},t.minf=function(e){return"audio"===e.type?t.box(t.types.minf,t.box(t.types.smhd,t.SMHD),t.DINF,t.stbl(e)):t.box(t.types.minf,t.box(t.types.vmhd,t.VMHD),t.DINF,t.stbl(e))},t.moof=function(e,r,i){return t.box(t.types.moof,t.mfhd(e),t.traf(i,r))},t.moov=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trak(e[r]);return t.box.apply(null,[t.types.moov,t.mvhd(e[0].timescale,e[0].duration)].concat(i).concat(t.mvex(e)))},t.mvex=function(e){for(var r=e.length,i=[];r--;)i[r]=t.trex(e[r]);return t.box.apply(null,[t.types.mvex].concat(i))},t.mvhd=function(e,r){r*=e;var i=Math.floor(r/(zi+1)),n=Math.floor(r%(zi+1)),a=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,i>>24,i>>16&255,i>>8&255,255&i,n>>24,n>>16&255,n>>8&255,255&n,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return t.box(t.types.mvhd,a)},t.sdtp=function(e){var r,i,n=e.samples||[],a=new Uint8Array(4+n.length);for(r=0;r>>8&255),a.push(255&n),a=a.concat(Array.prototype.slice.call(i));for(r=0;r>>8&255),s.push(255&n),s=s.concat(Array.prototype.slice.call(i));var o=t.box(t.types.avcC,new Uint8Array([1,a[3],a[4],a[5],255,224|e.sps.length].concat(a).concat([e.pps.length]).concat(s))),l=e.width,u=e.height,h=e.pixelRatio[0],d=e.pixelRatio[1];return t.box(t.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,l>>8&255,255&l,u>>8&255,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,t.box(t.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),t.box(t.types.pasp,new Uint8Array([h>>24,h>>16&255,h>>8&255,255&h,d>>24,d>>16&255,d>>8&255,255&d])))},t.esds=function(t){var e=t.config.length;return new Uint8Array([0,0,0,0,3,23+e,0,1,0,4,15+e,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([e]).concat(t.config).concat([6,1,2]))},t.audioStsd=function(t){var e=t.samplerate;return new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,e>>8&255,255&e,0,0])},t.mp4a=function(e){return t.box(t.types.mp4a,t.audioStsd(e),t.box(t.types.esds,t.esds(e)))},t.mp3=function(e){return t.box(t.types[".mp3"],t.audioStsd(e))},t.ac3=function(e){return t.box(t.types["ac-3"],t.audioStsd(e),t.box(t.types.dac3,e.config))},t.stsd=function(e){return"audio"===e.type?"mp3"===e.segmentCodec&&"mp3"===e.codec?t.box(t.types.stsd,t.STSD,t.mp3(e)):"ac3"===e.segmentCodec?t.box(t.types.stsd,t.STSD,t.ac3(e)):t.box(t.types.stsd,t.STSD,t.mp4a(e)):t.box(t.types.stsd,t.STSD,t.avc1(e))},t.tkhd=function(e){var r=e.id,i=e.duration*e.timescale,n=e.width,a=e.height,s=Math.floor(i/(zi+1)),o=Math.floor(i%(zi+1));return t.box(t.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,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,n>>8&255,255&n,0,0,a>>8&255,255&a,0,0]))},t.traf=function(e,r){var i=t.sdtp(e),n=e.id,a=Math.floor(r/(zi+1)),s=Math.floor(r%(zi+1));return t.box(t.types.traf,t.box(t.types.tfhd,new Uint8Array([0,0,0,0,n>>24,n>>16&255,n>>8&255,255&n])),t.box(t.types.tfdt,new Uint8Array([1,0,0,0,a>>24,a>>16&255,a>>8&255,255&a,s>>24,s>>16&255,s>>8&255,255&s])),t.trun(e,i.length+16+20+8+16+8+8),i)},t.trak=function(e){return e.duration=e.duration||4294967295,t.box(t.types.trak,t.tkhd(e),t.mdia(e))},t.trex=function(e){var r=e.id;return t.box(t.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},t.trun=function(e,r){var i,n,a,s,o,l,u=e.samples||[],h=u.length,d=12+16*h,c=new Uint8Array(d);for(r+=8+d,c.set(["video"===e.type?1:0,0,15,1,h>>>24&255,h>>>16&255,h>>>8&255,255&h,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i>>24&255,a>>>16&255,a>>>8&255,255&a,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return t.box(t.types.trun,c)},t.initSegment=function(e){t.types||t.init();var r=t.moov(e);return Ft(t.FTYP,r)},t}();Qi.types=void 0,Qi.HDLR_TYPES=void 0,Qi.STTS=void 0,Qi.STSC=void 0,Qi.STCO=void 0,Qi.STSZ=void 0,Qi.VMHD=void 0,Qi.SMHD=void 0,Qi.STSD=void 0,Qi.FTYP=void 0,Qi.DINF=void 0;function Zi(t,e,r,i){void 0===r&&(r=1),void 0===i&&(i=!1);var n=t*e*r;return i?Math.round(n):n}function $i(t,e){return void 0===e&&(e=!1),Zi(t,1e3,1/9e4,e)}var Ji=null,tn=null,en=function(){function t(t,e,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=t,this.config=e,this.typeSupported=r,this.ISGenerated=!1,null===Ji){var n=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Ji=n?parseInt(n[1]):0}if(null===tn){var a=navigator.userAgent.match(/Safari\/(\d+)/i);tn=a?parseInt(a[1]):0}}var e=t.prototype;return e.destroy=function(){this.config=this.videoTrackConfig=this._initPTS=this._initDTS=null},e.resetTimeStamp=function(t){b.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=t},e.resetNextTimestamp=function(){b.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},e.resetInitSegment=function(){b.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1,this.videoTrackConfig=void 0},e.getVideoStartPts=function(t){var e=!1,r=t.reduce((function(t,r){var i=r.pts-t;return i<-4294967296?(e=!0,rn(t,r.pts)):i>0?t:r.pts}),t[0].pts);return e&&b.debug("PTS rollover detected"),r},e.remux=function(t,e,r,i,n,a,s,o){var l,u,h,d,c,f,g=n,v=n,m=t.pid>-1,p=e.pid>-1,y=e.samples.length,T=t.samples.length>0,E=s&&y>0||y>1;if((!m||T)&&(!p||E)||this.ISGenerated||s){if(this.ISGenerated){var S,L,R,k,A=this.videoTrackConfig;!A||e.width===A.width&&e.height===A.height&&(null==(S=e.pixelRatio)?void 0:S[0])===(null==(L=A.pixelRatio)?void 0:L[0])&&(null==(R=e.pixelRatio)?void 0:R[1])===(null==(k=A.pixelRatio)?void 0:k[1])||this.resetInitSegment()}else h=this.generateIS(t,e,n,a);var D,_=this.isVideoContiguous,C=-1;if(E&&(C=function(t){for(var e=0;e0){b.warn("[mp4-remuxer]: Dropped "+C+" out of "+y+" video samples due to a missing keyframe");var w=this.getVideoStartPts(e.samples);e.samples=e.samples.slice(C),e.dropped+=C,D=v+=(e.samples[0].pts-w)/e.inputTimeScale}else-1===C&&(b.warn("[mp4-remuxer]: No keyframe found out of "+y+" video samples"),f=!1);if(this.ISGenerated){if(T&&E){var I=this.getVideoStartPts(e.samples),x=(rn(t.samples[0].pts,I)-I)/e.inputTimeScale;g+=Math.max(0,x),v+=Math.max(0,-x)}if(T){if(t.samplerate||(b.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),h=this.generateIS(t,e,n,a)),u=this.remuxAudio(t,g,this.isAudioContiguous,a,p||E||o===ke?v:void 0),E){var P=u?u.endPTS-u.startPTS:0;e.inputTimeScale||(b.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),h=this.generateIS(t,e,n,a)),l=this.remuxVideo(e,v,_,P)}}else E&&(l=this.remuxVideo(e,v,_,0));l&&(l.firstKeyFrame=C,l.independent=-1!==C,l.firstKeyFramePTS=D)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(r.samples.length&&(c=nn(r,n,this._initPTS,this._initDTS)),i.samples.length&&(d=an(i,n,this._initPTS))),{audio:u,video:l,initSegment:h,independent:f,text:d,id3:c}},e.generateIS=function(t,e,r,i){var n,a,s,o=t.samples,l=e.samples,u=this.typeSupported,h={},d=this._initPTS,c=!d||i,f="audio/mp4";if(c&&(n=a=1/0),t.config&&o.length){switch(t.timescale=t.samplerate,t.segmentCodec){case"mp3":u.mpeg?(f="audio/mpeg",t.codec=""):u.mp3&&(t.codec="mp3");break;case"ac3":t.codec="ac-3"}h.audio={id:"audio",container:f,codec:t.codec,initSegment:"mp3"===t.segmentCodec&&u.mpeg?new Uint8Array(0):Qi.initSegment([t]),metadata:{channelCount:t.channelCount}},c&&(s=t.inputTimeScale,d&&s===d.timescale?c=!1:n=a=o[0].pts-Math.round(s*r))}if(e.sps&&e.pps&&l.length){if(e.timescale=e.inputTimeScale,h.video={id:"main",container:"video/mp4",codec:e.codec,initSegment:Qi.initSegment([e]),metadata:{width:e.width,height:e.height}},c)if(s=e.inputTimeScale,d&&s===d.timescale)c=!1;else{var g=this.getVideoStartPts(l),v=Math.round(s*r);a=Math.min(a,rn(l[0].dts,g)-v),n=Math.min(n,g-v)}this.videoTrackConfig={width:e.width,height:e.height,pixelRatio:e.pixelRatio}}if(Object.keys(h).length)return this.ISGenerated=!0,c?(this._initPTS={baseTime:n,timescale:s},this._initDTS={baseTime:a,timescale:s}):n=s=void 0,{tracks:h,initPTS:n,timescale:s}},e.remuxVideo=function(t,e,r,i){var n,a,s=t.inputTimeScale,l=t.samples,u=[],h=l.length,d=this._initPTS,c=this.nextAvcDts,f=8,g=this.videoSampleDuration,v=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,p=!1;if(!r||null===c){var y=e*s,L=l[0].pts-rn(l[0].dts,l[0].pts);Ji&&null!==c&&Math.abs(y-L-c)<15e3?r=!0:c=y-L}for(var R=d.baseTime*s/d.timescale,k=0;k0?k-1:k].dts&&(p=!0)}p&&l.sort((function(t,e){var r=t.dts-e.dts,i=t.pts-e.pts;return r||i})),n=l[0].dts;var D=l[l.length-1].dts-n,_=D?Math.round(D/(h-1)):g||t.inputTimeScale/30;if(r){var C=n-c,w=C>_,I=C<-1;if((w||I)&&(w?b.warn("AVC: "+$i(C,!0)+" ms ("+C+"dts) hole between fragments detected at "+e.toFixed(3)):b.warn("AVC: "+$i(-C,!0)+" ms ("+C+"dts) overlapping between fragments detected at "+e.toFixed(3)),!I||c>=l[0].pts||Ji)){n=c;var x=l[0].pts-C;if(w)l[0].dts=n,l[0].pts=x;else for(var P=0;Px);P++)l[P].dts-=C,l[P].pts-=C;b.log("Video: Initial PTS/DTS adjusted: "+$i(x,!0)+"/"+$i(n,!0)+", delta: "+$i(C,!0)+" ms")}}for(var O=0,M=0,F=n=Math.max(0,n),N=0;N0?$.dts-l[Z-1].dts:_;if(st=Z>0?$.pts-l[Z-1].pts:_,ot.stretchShortVideoTrack&&null!==this.nextAudioPts){var ut=Math.floor(ot.maxBufferHole*s),ht=(i?v+i*s:this.nextAudioPts)-$.pts;ht>ut?((g=ht-lt)<0?g=lt:W=!0,b.log("[mp4-remuxer]: It is approximately "+ht/90+" ms to the next segment; using duration "+g/90+" ms for the last video frame.")):g=lt}else g=lt}var dt=Math.round($.pts-$.dts);q=Math.min(q,g),z=Math.max(z,g),X=Math.min(X,st),Q=Math.max(Q,st),u.push(new on($.key,g,tt,dt))}if(u.length)if(Ji){if(Ji<70){var ct=u[0].flags;ct.dependsOn=2,ct.isNonSync=0}}else if(tn&&Q-X0&&(i&&Math.abs(p-m)<9e3||Math.abs(rn(g[0].pts-y,p)-m)<20*u),g.forEach((function(t){t.pts=rn(t.pts-y,p)})),!r||m<0){if(g=g.filter((function(t){return t.pts>=0})),!g.length)return;m=0===n?0:i&&!f?Math.max(0,p):g[0].pts}if("aac"===t.segmentCodec)for(var L=this.config.maxAudioFramesDrift,R=0,k=m;R=L*u&&C<1e4&&f){var w=Math.round(_/u);(k=D-w*u)<0&&(w--,k+=u),0===R&&(this.nextAudioPts=m=k),b.warn("[mp4-remuxer]: Injecting "+w+" audio frame @ "+(k/a).toFixed(3)+"s due to "+Math.round(1e3*_/a)+" ms gap.");for(var I=0;I0))return;N+=v;try{O=new Uint8Array(N)}catch(t){return void this.observer.emit(T.ERROR,T.ERROR,{type:E.MUX_ERROR,details:S.REMUX_ALLOC_ERROR,fatal:!1,error:t,bytes:N,reason:"fail allocating audio mdat "+N})}d||(new DataView(O.buffer).setUint32(0,N),O.set(Qi.types.mdat,4))}O.set(K,v);var j=K.byteLength;v+=j,c.push(new on(!0,l,j,0)),F=V}var Y=c.length;if(Y){var W=c[c.length-1];this.nextAudioPts=m=F+s*W.duration;var q=d?new Uint8Array(0):Qi.moof(t.sequenceNumber++,M/s,o({},t,{samples:c}));t.samples=[];var X=M/a,z=m/a,Q={data1:q,data2:O,startPTS:X,endPTS:z,startDTS:X,endDTS:z,type:"audio",hasAudio:!0,hasVideo:!1,nb:Y};return this.isAudioContiguous=!0,Q}},e.remuxEmptyAudio=function(t,e,r,i){var n=t.inputTimeScale,a=n/(t.samplerate?t.samplerate:n),s=this.nextAudioPts,o=this._initDTS,l=9e4*o.baseTime/o.timescale,u=(null!==s?s:i.startDTS*n)+l,h=i.endDTS*n+l,d=1024*a,c=Math.ceil((h-u)/d),f=Xi.getSilentFrame(t.manifestCodec||t.codec,t.channelCount);if(b.warn("[mp4-remuxer]: remux empty Audio"),f){for(var g=[],v=0;v4294967296;)t+=r;return t}function nn(t,e,r,i){var n=t.samples.length;if(n){for(var a=t.inputTimeScale,s=0;s0;n||(i=Dt(e,["encv"])),i.forEach((function(t){Dt(n?t.subarray(28):t.subarray(78),["sinf"]).forEach((function(t){var e=Ot(t);if(e){var i=e.subarray(8,24);i.some((function(t){return 0!==t}))||(b.log("[eme] Patching keyId in 'enc"+(n?"a":"v")+">sinf>>tenc' box: "+pt(i)+" -> "+pt(r)),e.set(r,8))}}))}))})),t}(t,i)),this.emitInitSegment=!0},e.generateInitSegment=function(t){var e=this.audioCodec,r=this.videoCodec;if(null==t||!t.byteLength)return this.initTracks=void 0,void(this.initData=void 0);var i=this.initData=Ct(t);i.audio&&(e=un(i.audio,P)),i.video&&(r=un(i.video,O));var n={};i.audio&&i.video?n.audiovideo={container:"video/mp4",codec:e+","+r,initSegment:t,id:"main"}:i.audio?n.audio={container:"audio/mp4",codec:e,initSegment:t,id:"audio"}:i.video?n.video={container:"video/mp4",codec:r,initSegment:t,id:"main"}:b.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=n},e.remux=function(t,e,r,i,n,a){var s,o,l=this.initPTS,u=this.lastEndTime,h={audio:void 0,video:void 0,text:i,id3:r,initSegment:void 0};m(u)||(u=this.lastEndTime=n||0);var d=e.samples;if(null==d||!d.length)return h;var c={initPTS:void 0,timescale:1},f=this.initData;if(null!=(s=f)&&s.length||(this.generateInitSegment(d),f=this.initData),null==(o=f)||!o.length)return b.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),h;this.emitInitSegment&&(c.tracks=this.initTracks,this.emitInitSegment=!1);var g=function(t,e){for(var r=0,i=0,n=0,a=Dt(t,["moof","traf"]),s=0;sn}(l,p,n,g)||c.timescale!==l.timescale&&a)&&(c.initPTS=p-n,l&&1===l.timescale&&b.warn("Adjusting initPTS by "+(c.initPTS-l.baseTime)),this.initPTS=l={baseTime:c.initPTS,timescale:1});var y=t?p-l.baseTime/l.timescale:u,T=y+g;!function(t,e,r){Dt(e,["moof","traf"]).forEach((function(e){Dt(e,["tfhd"]).forEach((function(i){var n=Rt(i,4),a=t[n];if(a){var s=a.timescale||9e4;Dt(e,["tfdt"]).forEach((function(t){var e=t[0],i=r*s;if(i){var n=Rt(t,4);if(0===e)n-=i,bt(t,4,n=Math.max(n,0));else{n*=Math.pow(2,32),n+=Rt(t,8),n-=i,n=Math.max(n,0);var a=Math.floor(n/(yt+1)),o=Math.floor(n%(yt+1));bt(t,4,a),bt(t,8,o)}}}))}}))}))}(f,d,l.baseTime/l.timescale),g>0?this.lastEndTime=T:(b.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var E=!!f.audio,S=!!f.video,L="";E&&(L+="audio"),S&&(L+="video");var R={data1:d,startPTS:y,startDTS:y,endPTS:T,endDTS:T,type:L,hasAudio:E,hasVideo:S,nb:1,dropped:0};return h.audio="audio"===R.type?R:void 0,h.video="audio"!==R.type?R:void 0,h.initSegment=c,h.id3=nn(r,n,l,l),i.samples.length&&(h.text=an(i,n,l)),h},t}();function un(t,e){var r=null==t?void 0:t.codec;if(r&&r.length>4)return r;if(e===P){if("ec-3"===r||"ac-3"===r||"alac"===r)return r;if("fLaC"===r||"Opus"===r)return ne(r,!1);var i="mp4a.40.5";return b.info('Parsed audio codec "'+r+'" or audio object type not handled. Using "'+i+'"'),i}return b.warn('Unhandled video codec "'+r+'"'),"hvc1"===r||"hev1"===r?"hvc1.1.6.L120.90":"av01"===r?"av01.0.04M.08":"avc1.42e01e"}try{sn=self.performance.now.bind(self.performance)}catch(t){b.debug("Unable to use Performance API on this environment"),sn=null==K?void 0:K.Date.now}var hn=[{demux:Ii,remux:ln},{demux:Gi,remux:en},{demux:Ci,remux:en},{demux:qi,remux:en}];hn.splice(2,0,{demux:Pi,remux:en});var dn=function(){function t(t,e,r,i,n){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=t,this.typeSupported=e,this.config=r,this.vendor=i,this.id=n}var e=t.prototype;return e.configure=function(t){this.transmuxConfig=t,this.decrypter&&this.decrypter.reset()},e.push=function(t,e,r,i){var n=this,a=r.transmuxing;a.executeStart=sn();var s=new Uint8Array(t),o=this.currentTransmuxState,l=this.transmuxConfig;i&&(this.currentTransmuxState=i);var u=i||o,h=u.contiguous,d=u.discontinuity,c=u.trackSwitch,f=u.accurateTimeOffset,g=u.timeOffset,v=u.initSegmentChange,m=l.audioCodec,p=l.videoCodec,y=l.defaultInitPts,L=l.duration,R=l.initSegmentData,k=function(t,e){var r=null;return t.byteLength>0&&null!=(null==e?void 0:e.key)&&null!==e.iv&&null!=e.method&&(r=e),r}(s,e);if(k&&"AES-128"===k.method){var A=this.getDecrypter();if(!A.isSync())return this.decryptionPromise=A.webCryptoDecrypt(s,k.key.buffer,k.iv.buffer).then((function(t){var e=n.push(t,null,r);return n.decryptionPromise=null,e})),this.decryptionPromise;var D=A.softwareDecrypt(s,k.key.buffer,k.iv.buffer);if(r.part>-1&&(D=A.flush()),!D)return a.executeEnd=sn(),cn(r);s=new Uint8Array(D)}var _=this.needsProbing(d,c);if(_){var C=this.configureTransmuxer(s);if(C)return b.warn("[transmuxer] "+C.message),this.observer.emit(T.ERROR,T.ERROR,{type:E.MEDIA_ERROR,details:S.FRAG_PARSING_ERROR,fatal:!1,error:C,reason:C.message}),a.executeEnd=sn(),cn(r)}(d||c||v||_)&&this.resetInitSegment(R,m,p,L,e),(d||v||_)&&this.resetInitialTimestamp(y),h||this.resetContiguity();var w=this.transmux(s,k,g,f,r),I=this.currentTransmuxState;return I.contiguous=!0,I.discontinuity=!1,I.trackSwitch=!1,a.executeEnd=sn(),w},e.flush=function(t){var e=this,r=t.transmuxing;r.executeStart=sn();var i=this.decrypter,n=this.currentTransmuxState,a=this.decryptionPromise;if(a)return a.then((function(){return e.flush(t)}));var s=[],o=n.timeOffset;if(i){var l=i.flush();l&&s.push(this.push(l,null,t))}var u=this.demuxer,h=this.remuxer;if(!u||!h)return r.executeEnd=sn(),[cn(t)];var d=u.flush(o);return fn(d)?d.then((function(r){return e.flushRemux(s,r,t),s})):(this.flushRemux(s,d,t),s)},e.flushRemux=function(t,e,r){var i=e.audioTrack,n=e.videoTrack,a=e.id3Track,s=e.textTrack,o=this.currentTransmuxState,l=o.accurateTimeOffset,u=o.timeOffset;b.log("[transmuxer.ts]: Flushed fragment "+r.sn+(r.part>-1?" p: "+r.part:"")+" of level "+r.level);var h=this.remuxer.remux(i,n,a,s,u,l,!0,this.id);t.push({remuxResult:h,chunkMeta:r}),r.transmuxing.executeEnd=sn()},e.resetInitialTimestamp=function(t){var e=this.demuxer,r=this.remuxer;e&&r&&(e.resetTimeStamp(t),r.resetTimeStamp(t))},e.resetContiguity=function(){var t=this.demuxer,e=this.remuxer;t&&e&&(t.resetContiguity(),e.resetNextTimestamp())},e.resetInitSegment=function(t,e,r,i,n){var a=this.demuxer,s=this.remuxer;a&&s&&(a.resetInitSegment(t,e,r,i),s.resetInitSegment(t,e,r,n))},e.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},e.transmux=function(t,e,r,i,n){return e&&"SAMPLE-AES"===e.method?this.transmuxSampleAes(t,e,r,i,n):this.transmuxUnencrypted(t,r,i,n)},e.transmuxUnencrypted=function(t,e,r,i){var n=this.demuxer.demux(t,e,!1,!this.config.progressive),a=n.audioTrack,s=n.videoTrack,o=n.id3Track,l=n.textTrack;return{remuxResult:this.remuxer.remux(a,s,o,l,e,r,!1,this.id),chunkMeta:i}},e.transmuxSampleAes=function(t,e,r,i,n){var a=this;return this.demuxer.demuxSampleAes(t,e,r).then((function(t){return{remuxResult:a.remuxer.remux(t.audioTrack,t.videoTrack,t.id3Track,t.textTrack,r,i,!1,a.id),chunkMeta:n}}))},e.configureTransmuxer=function(t){for(var e,r=this.config,i=this.observer,n=this.typeSupported,a=this.vendor,s=0,o=hn.length;s1&&l.id===(null==m?void 0:m.stats.chunkCount),L=!y&&(1===T||0===T&&(1===E||S&&E<=0)),R=self.performance.now();(y||T||0===n.stats.parsing.start)&&(n.stats.parsing.start=R),!a||!E&&L||(a.stats.parsing.start=R);var k=!(m&&(null==(h=n.initSegment)?void 0:h.url)===(null==(d=m.initSegment)?void 0:d.url)),A=new vn(p,L,o,y,g,k);if(!L||p||k){b.log("[transmuxer-interface, "+n.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: "+g+"\n initSegmentChange: "+k);var D=new gn(r,i,e,s,u);this.configureTransmuxer(D)}if(this.frag=n,this.part=a,this.workerContext)this.workerContext.worker.postMessage({cmd:"demux",data:t,decryptdata:v,chunkMeta:l,state:A},t instanceof ArrayBuffer?[t]:[]);else if(f){var _=f.push(t,v,l,A);fn(_)?(f.async=!0,_.then((function(t){c.handleTransmuxComplete(t)})).catch((function(t){c.transmuxerError(t,l,"transmuxer-interface push error")}))):(f.async=!1,this.handleTransmuxComplete(_))}},e.flush=function(t){var e=this;t.transmuxing.start=self.performance.now();var r=this.transmuxer;if(this.workerContext)this.workerContext.worker.postMessage({cmd:"flush",chunkMeta:t});else if(r){var i=r.flush(t);fn(i)||r.async?(fn(i)||(i=Promise.resolve(i)),i.then((function(r){e.handleFlushResult(r,t)})).catch((function(r){e.transmuxerError(r,t,"transmuxer-interface flush error")}))):this.handleFlushResult(i,t)}},e.transmuxerError=function(t,e,r){this.hls&&(this.error=t,this.hls.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.FRAG_PARSING_ERROR,chunkMeta:e,frag:this.frag||void 0,fatal:!1,error:t,err:t,reason:r}))},e.handleFlushResult=function(t,e){var r=this;t.forEach((function(t){r.handleTransmuxComplete(t)})),this.onFlush(e)},e.onWorkerMessage=function(t){var e=t.data;if(null!=e&&e.event){var r=this.hls;if(this.hls)switch(e.event){case"init":var i,n=null==(i=this.workerContext)?void 0:i.objectURL;n&&self.URL.revokeObjectURL(n);break;case"transmuxComplete":this.handleTransmuxComplete(e.data);break;case"flush":this.onFlush(e.data);break;case"workerLog":b[e.data.logType]&&b[e.data.logType](e.data.message);break;default:e.data=e.data||{},e.data.frag=this.frag,e.data.id=this.id,r.trigger(e.event,e.data)}}else b.warn("worker message received with no "+(e?"event name":"data"))},e.configureTransmuxer=function(t){var e=this.transmuxer;this.workerContext?this.workerContext.worker.postMessage({cmd:"configure",config:t}):e&&e.configure(t)},e.handleTransmuxComplete=function(t){t.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(t)},t}();function Ln(t,e){if(t.length!==e.length)return!1;for(var r=0;r0&&-1===t?(this.log("Override startPosition with lastCurrentTime @"+e.toFixed(3)),t=e,this.state=zr):(this.loadedmetadata=!1,this.state=Jr),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()},i.doTick=function(){switch(this.state){case zr:this.doTickIdle();break;case Jr:var e,r=this.levels,i=this.trackId,n=null==r||null==(e=r[i])?void 0:e.details;if(n){if(this.waitForCdnTuneIn(n))break;this.state=ni}break;case $r:var a,s=performance.now(),o=this.retryDate;if(!o||s>=o||null!=(a=this.media)&&a.seeking){var l=this.levels,u=this.trackId;this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded((null==l?void 0:l[u])||null),this.state=zr}break;case ni:var h=this.waitingData;if(h){var d=h.frag,c=h.part,f=h.cache,g=h.complete;if(void 0!==this.initPTS[d.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=Zr;var v={frag:d,part:c,payload:f.flush(),networkDetails:null};this._handleFragmentLoadProgress(v),g&&t.prototype._handleFragmentLoadComplete.call(this,v)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log("Waiting fragment cc ("+d.cc+") cancelled because video is at cc "+this.videoTrackCC),this.clearWaitingFragment();else{var m=this.getLoadPosition(),p=Pr.bufferInfo(this.mediaBuffer,m,this.config.maxBufferHole);ur(p.end,this.config.maxFragLookUpTolerance,d)<0&&(this.log("Waiting fragment cc ("+d.cc+") @ "+d.start+" cancelled because another fragment at "+p.end+" is needed"),this.clearWaitingFragment())}}else this.state=zr}this.onTickEnd()},i.clearWaitingFragment=function(){var t=this.waitingData;t&&(this.fragmentTracker.removeFragment(t.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=zr)},i.resetLoadingState=function(){this.clearWaitingFragment(),t.prototype.resetLoadingState.call(this)},i.onTickEnd=function(){var t=this.media;null!=t&&t.readyState&&(this.lastCurrentTime=t.currentTime)},i.doTickIdle=function(){var t=this.hls,e=this.levels,r=this.media,i=this.trackId,n=t.config;if((r||!this.startFragRequested&&n.startFragPrefetch)&&null!=e&&e[i]){var a=e[i],s=a.details;if(!s||s.live&&this.levelLastLoaded!==a||this.waitForCdnTuneIn(s))this.state=Jr;else{var o=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&o&&(this.bufferFlushed=!1,this.afterBufferFlushed(o,P,ke));var l=this.getFwdBufferInfo(o,ke);if(null!==l){var u=this.bufferedTrack,h=this.switchingTrack;if(!h&&this._streamEnded(l,s))return t.trigger(T.BUFFER_EOS,{type:"audio"}),void(this.state=ri);var d=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,Re),c=l.len,f=this.getMaxBufferLength(null==d?void 0:d.len),g=s.fragments,v=g[0].start,m=this.flushing?this.getLoadPosition():l.end;if(h&&r){var p=this.getLoadPosition();u&&!Rn(h.attrs,u.attrs)&&(m=p),s.PTSKnown&&pv||l.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),r.currentTime=v+.05)}if(!(c>=f&&!h&&md.end+s.targetduration;if(S||(null==d||!d.len)&&l.len){var L=this.getAppendedFrag(y.start,Re);if(null===L)return;if(E||(E=!!L.gap||!!S&&0===d.len),S&&!E||E&&l.nextStart&&l.nextStart-1)n=a[o];else{var l=Tr(s,this.tracks);n=this.tracks[l]}}var u=this.findTrackId(n);-1===u&&n&&(u=this.findTrackId(null));var h={audioTracks:a};this.log("Updating audio tracks, "+a.length+" track(s) found in group(s): "+(null==r?void 0:r.join(","))),this.hls.trigger(T.AUDIO_TRACKS_UPDATED,h);var d=this.trackId;if(-1!==u&&-1===d)this.setAudioTrack(u);else if(a.length&&-1===d){var c,f=new Error("No audio track selected for current audio group-ID(s): "+(null==(c=this.groupIds)?void 0:c.join(","))+" track count: "+a.length);this.warn(f.message),this.hls.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.AUDIO_TRACK_LOAD_ERROR,fatal:!0,error:f})}}else this.shouldReloadPlaylist(n)&&this.setAudioTrack(this.trackId)}},i.onError=function(t,e){!e.fatal&&e.context&&(e.context.type!==Se||e.context.id!==this.trackId||this.groupIds&&-1===this.groupIds.indexOf(e.context.groupId)||(this.requestScheduled=-1,this.checkRetry(e)))},i.setAudioOption=function(t){var e=this.hls;if(e.config.audioPreference=t,t){var r=this.allAudioTracks;if(this.selectDefaultTrack=!1,r.length){var i=this.currentTrack;if(i&&Er(t,i,Sr))return i;var n=Tr(t,this.tracksInGroup,Sr);if(n>-1){var a=this.tracksInGroup[n];return this.setAudioTrack(n),a}if(i){var s=e.loadLevel;-1===s&&(s=e.firstAutoLevel);var o=function(t,e,r,i,n){var a=e[i],s=e.reduce((function(t,e,r){var i=e.uri;return(t[i]||(t[i]=[])).push(r),t}),{})[a.uri];s.length>1&&(i=Math.max.apply(Math,s));var o=a.videoRange,l=a.frameRate,u=a.codecSet.substring(0,4),h=Lr(e,i,(function(e){if(e.videoRange!==o||e.frameRate!==l||e.codecSet.substring(0,4)!==u)return!1;var i=e.audioGroups,a=r.filter((function(t){return!i||-1!==i.indexOf(t.groupId)}));return Tr(t,a,n)>-1}));return h>-1?h:Lr(e,i,(function(e){var i=e.audioGroups,a=r.filter((function(t){return!i||-1!==i.indexOf(t.groupId)}));return Tr(t,a,n)>-1}))}(t,e.levels,r,s,Sr);if(-1===o)return null;e.nextLoadLevel=o}if(t.channels||t.audioCodec){var l=Tr(t,r);if(l>-1)return r[l]}}}return null},i.setAudioTrack=function(t){var r=this.tracksInGroup;if(t<0||t>=r.length)this.warn("Invalid audio track id: "+t);else{this.clearTimer(),this.selectDefaultTrack=!1;var i=this.currentTrack,n=r[t],a=n.details&&!n.details.live;if(!(t===this.trackId&&n===i&&a||(this.log("Switching to audio-track "+t+' "'+n.name+'" lang:'+n.lang+" group:"+n.groupId+" channels:"+n.channels),this.trackId=t,this.currentTrack=n,this.hls.trigger(T.AUDIO_TRACK_SWITCHING,e({},n)),a))){var s=this.switchParams(n.url,null==i?void 0:i.details,n.details);this.loadPlaylist(s)}}},i.findTrackId=function(t){for(var e=this.tracksInGroup,r=0;r=n[o].start&&s<=n[o].end){a=n[o];break}var l=r.start+r.duration;a?a.end=l:(a={start:s,end:l},n.push(a)),this.fragmentTracker.fragBuffered(r),this.fragBufferedComplete(r,null)}}},r.onBufferFlushing=function(t,e){var r=e.startOffset,i=e.endOffset;if(0===r&&i!==Number.POSITIVE_INFINITY){var n=i-1;if(n<=0)return;e.endOffsetSubtitles=Math.max(0,n),this.tracksBuffered.forEach((function(t){for(var e=0;e=n.length)&&o){this.log("Subtitle track "+s+" loaded ["+a.startSN+","+a.endSN+"]"+(a.lastPartSn?"[part-"+a.lastPartSn+"-"+a.lastPartIndex+"]":"")+",duration:"+a.totalduration),this.mediaBuffer=this.mediaBufferTimeRanges;var l=0;if(a.live||null!=(r=o.details)&&r.live){var u=this.mainDetails;if(a.deltaUpdateFailed||!u)return;var h,d=u.fragments[0];o.details?0===(l=this.alignPlaylists(a,o.details,null==(h=this.levelLastLoaded)?void 0:h.details))&&d&&$e(a,l=d.start):a.hasProgramDateTime&&u.hasProgramDateTime?(Ur(a,u),l=a.fragments[0].start):d&&$e(a,l=d.start)}o.details=a,this.levelLastLoaded=o,s===i&&(this.startFragRequested||!this.mainDetails&&a.live||this.setStartPosition(this.mainDetails||a,l),this.tick(),a.live&&!this.fragCurrent&&this.media&&this.state===zr&&(lr(null,a.fragments,this.media.currentTime,0)||(this.warn("Subtitle playlist not aligned with playback"),o.details=void 0)))}}else this.warn("Subtitle tracks were reset while loading level "+s)},r._handleFragmentLoadComplete=function(t){var e=this,r=t.frag,i=t.payload,n=r.decryptdata,a=this.hls;if(!this.fragContextChanged(r)&&i&&i.byteLength>0&&null!=n&&n.key&&n.iv&&"AES-128"===n.method){var s=performance.now();this.decrypter.decrypt(new Uint8Array(i),n.key.buffer,n.iv.buffer).catch((function(t){throw a.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.FRAG_DECRYPT_ERROR,fatal:!1,error:t,reason:t.message,frag:r}),t})).then((function(t){var e=performance.now();a.trigger(T.FRAG_DECRYPTED,{frag:r,payload:t,stats:{tstart:s,tdecrypt:e}})})).catch((function(t){e.warn(t.name+": "+t.message),e.state=zr}))}},r.doTick=function(){if(this.media){if(this.state===zr){var t=this.currentTrackId,e=this.levels,r=null==e?void 0:e[t];if(!r||!e.length||!r.details)return;var i=this.config,n=this.getLoadPosition(),a=Pr.bufferedInfo(this.tracksBuffered[this.currentTrackId]||[],n,i.maxBufferHole),s=a.end,o=a.len,l=this.getFwdBufferInfo(this.media,Re),u=r.details;if(o>this.getMaxBufferLength(null==l?void 0:l.len)+u.levelTargetDuration)return;var h=u.fragments,d=h.length,c=u.edge,f=null,g=this.fragPrevious;if(sc-v?0:v;!(f=lr(g,h,Math.max(h[0].start,s),m))&&g&&g.start>>=0)>i-1)throw new DOMException("Failed to execute '"+e+"' on 'TimeRanges': The index provided ("+r+") is greater than the maximum bound ("+i+")");return t[r][e]};this.buffered={get length(){return t.length},end:function(r){return e("end",r,t.length)},start:function(r){return e("start",r,t.length)}}},Cn=function(t){function e(e){var r;return(r=t.call(this,e,"[subtitle-track-controller]")||this).media=null,r.tracks=[],r.groupIds=null,r.tracksInGroup=[],r.trackId=-1,r.currentTrack=null,r.selectDefaultTrack=!0,r.queuedDefaultTrack=-1,r.asyncPollTrackChange=function(){return r.pollTrackChange(0)},r.useTextTrackPolling=!1,r.subtitlePollingInterval=-1,r._subtitleDisplay=!0,r.onTextTracksChanged=function(){if(r.useTextTrackPolling||self.clearInterval(r.subtitlePollingInterval),r.media&&r.hls.config.renderTextTracksNatively){for(var t=null,e=Pe(r.media.textTracks),i=0;i-1&&(this.subtitleTrack=this.queuedDefaultTrack,this.queuedDefaultTrack=-1),this.useTextTrackPolling=!(this.media.textTracks&&"onchange"in this.media.textTracks),this.useTextTrackPolling?this.pollTrackChange(500):this.media.textTracks.addEventListener("change",this.asyncPollTrackChange))},r.pollTrackChange=function(t){self.clearInterval(this.subtitlePollingInterval),this.subtitlePollingInterval=self.setInterval(this.onTextTracksChanged,t)},r.onMediaDetaching=function(){this.media&&(self.clearInterval(this.subtitlePollingInterval),this.useTextTrackPolling||this.media.textTracks.removeEventListener("change",this.asyncPollTrackChange),this.trackId>-1&&(this.queuedDefaultTrack=this.trackId),Pe(this.media.textTracks).forEach((function(t){Ie(t)})),this.subtitleTrack=-1,this.media=null)},r.onManifestLoading=function(){this.tracks=[],this.groupIds=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0},r.onManifestParsed=function(t,e){this.tracks=e.subtitleTracks},r.onSubtitleTrackLoaded=function(t,e){var r=e.id,i=e.groupId,n=e.details,a=this.tracksInGroup[r];if(a&&a.groupId===i){var s=a.details;a.details=e.details,this.log("Subtitle track "+r+' "'+a.name+'" lang:'+a.lang+" group:"+i+" loaded ["+n.startSN+"-"+n.endSN+"]"),r===this.trackId&&this.playlistLoaded(r,e,s)}else this.warn("Subtitle track with id:"+r+" and group:"+i+" not found in active group "+(null==a?void 0:a.groupId))},r.onLevelLoading=function(t,e){this.switchLevel(e.level)},r.onLevelSwitching=function(t,e){this.switchLevel(e.level)},r.switchLevel=function(t){var e=this.hls.levels[t];if(e){var r=e.subtitleGroups||null,i=this.groupIds,n=this.currentTrack;if(!r||(null==i?void 0:i.length)!==(null==r?void 0:r.length)||null!=r&&r.some((function(t){return-1===(null==i?void 0:i.indexOf(t))}))){this.groupIds=r,this.trackId=-1,this.currentTrack=null;var a=this.tracks.filter((function(t){return!r||-1!==r.indexOf(t.groupId)}));if(a.length)this.selectDefaultTrack&&!a.some((function(t){return t.default}))&&(this.selectDefaultTrack=!1),a.forEach((function(t,e){t.id=e}));else if(!n&&!this.tracksInGroup.length)return;this.tracksInGroup=a;var s=this.hls.config.subtitlePreference;if(!n&&s){this.selectDefaultTrack=!1;var o=Tr(s,a);if(o>-1)n=a[o];else{var l=Tr(s,this.tracks);n=this.tracks[l]}}var u=this.findTrackId(n);-1===u&&n&&(u=this.findTrackId(null));var h={subtitleTracks:a};this.log("Updating subtitle tracks, "+a.length+' track(s) found in "'+(null==r?void 0:r.join(","))+'" group-id'),this.hls.trigger(T.SUBTITLE_TRACKS_UPDATED,h),-1!==u&&-1===this.trackId&&this.setSubtitleTrack(u)}else this.shouldReloadPlaylist(n)&&this.setSubtitleTrack(this.trackId)}},r.findTrackId=function(t){for(var e=this.tracksInGroup,r=this.selectDefaultTrack,i=0;i-1){var n=this.tracksInGroup[i];return this.setSubtitleTrack(i),n}if(r)return null;var a=Tr(t,e);if(a>-1)return e[a]}}return null},r.loadPlaylist=function(e){t.prototype.loadPlaylist.call(this);var r=this.currentTrack;if(this.shouldLoadPlaylist(r)&&r){var i=r.id,n=r.groupId,a=r.url;if(e)try{a=e.addDirectives(a)}catch(t){this.warn("Could not construct new URL with HLS Delivery Directives: "+t)}this.log("Loading subtitle playlist for id "+i),this.hls.trigger(T.SUBTITLE_TRACK_LOADING,{url:a,id:i,groupId:n,deliveryDirectives:e||null})}},r.toggleTrackModes=function(){var t=this.media;if(t){var e,r=Pe(t.textTracks),i=this.currentTrack;if(i&&((e=r.filter((function(t){return kn(i,t)}))[0])||this.warn('Unable to find subtitle TextTrack with name "'+i.name+'" and language "'+i.lang+'"')),[].slice.call(r).forEach((function(t){"disabled"!==t.mode&&t!==e&&(t.mode="disabled")})),e){var n=this.subtitleDisplay?"showing":"hidden";e.mode!==n&&(e.mode=n)}}},r.setSubtitleTrack=function(t){var e=this.tracksInGroup;if(this.media)if(t<-1||t>=e.length||!m(t))this.warn("Invalid subtitle track id: "+t);else{this.clearTimer(),this.selectDefaultTrack=!1;var r=this.currentTrack,i=e[t]||null;if(this.trackId=t,this.currentTrack=i,this.toggleTrackModes(),i){var n=!!i.details&&!i.details.live;if(t!==this.trackId||i!==r||!n){this.log("Switching to subtitle-track "+t+(i?' "'+i.name+'" lang:'+i.lang+" group:"+i.groupId:""));var a=i.id,s=i.groupId,o=void 0===s?"":s,l=i.name,u=i.type,h=i.url;this.hls.trigger(T.SUBTITLE_TRACK_SWITCH,{id:a,groupId:o,name:l,type:u,url:h});var d=this.switchParams(i.url,null==r?void 0:r.details,i.details);this.loadPlaylist(d)}}else this.hls.trigger(T.SUBTITLE_TRACK_SWITCH,{id:t})}else this.queuedDefaultTrack=t},s(e,[{key:"subtitleDisplay",get:function(){return this._subtitleDisplay},set:function(t){this._subtitleDisplay=t,this.trackId>-1&&this.toggleTrackModes()}},{key:"allSubtitleTracks",get:function(){return this.tracks}},{key:"subtitleTracks",get:function(){return this.tracksInGroup}},{key:"subtitleTrack",get:function(){return this.trackId},set:function(t){this.selectDefaultTrack=!1,this.setSubtitleTrack(t)}}]),e}(cr),wn=function(){function t(t){this.buffers=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.buffers=t}var e=t.prototype;return e.append=function(t,e,r){var i=this.queues[e];i.push(t),1!==i.length||r||this.executeNext(e)},e.insertAbort=function(t,e){this.queues[e].unshift(t),this.executeNext(e)},e.appendBlocker=function(t){var e,r=new Promise((function(t){e=t})),i={execute:e,onStart:function(){},onComplete:function(){},onError:function(){}};return this.append(i,t),r},e.executeNext=function(t){var e=this.queues[t];if(e.length){var r=e[0];try{r.execute()}catch(e){b.warn('[buffer-operation-queue]: Exception executing "'+t+'" SourceBuffer operation: '+e),r.onError(e);var i=this.buffers[t];null!=i&&i.updating||this.shiftAndExecuteNext(t)}}},e.shiftAndExecuteNext=function(t){this.queues[t].shift(),this.executeNext(t)},e.current=function(t){return this.queues[t][0]},t}(),In=/(avc[1234]|hvc1|hev1|dvh[1e]|vp09|av01)(?:\.[^.,]+)+/,xn=function(){function t(t){var e=this;this.details=null,this._objectUrl=null,this.operationQueue=void 0,this.listeners=void 0,this.hls=void 0,this.bufferCodecEventsExpected=0,this._bufferCodecEventsTotal=0,this.media=null,this.mediaSource=null,this.lastMpegAudioChunk=null,this.appendSource=void 0,this.appendErrors={audio:0,video:0,audiovideo:0},this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this.log=void 0,this.warn=void 0,this.error=void 0,this._onEndStreaming=function(t){e.hls&&e.hls.pauseBuffering()},this._onStartStreaming=function(t){e.hls&&e.hls.resumeBuffering()},this._onMediaSourceOpen=function(){var t=e.media,r=e.mediaSource;e.log("Media source opened"),t&&(t.removeEventListener("emptied",e._onMediaEmptied),e.updateMediaElementDuration(),e.hls.trigger(T.MEDIA_ATTACHED,{media:t,mediaSource:r})),r&&r.removeEventListener("sourceopen",e._onMediaSourceOpen),e.checkPendingTracks()},this._onMediaSourceClose=function(){e.log("Media source closed")},this._onMediaSourceEnded=function(){e.log("Media source ended")},this._onMediaEmptied=function(){var t=e.mediaSrc,r=e._objectUrl;t!==r&&b.error("Media element src was set while attaching MediaSource ("+r+" > "+t+")")},this.hls=t;var r,i="[buffer-controller]";this.appendSource=(r=zt(t.config.preferManagedMediaSource),"undefined"!=typeof self&&r===self.ManagedMediaSource),this.log=b.log.bind(b,i),this.warn=b.warn.bind(b,i),this.error=b.error.bind(b,i),this._initSourceBuffer(),this.registerListeners()}var e=t.prototype;return e.hasSourceTypes=function(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0},e.destroy=function(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null,this.hls=null},e.registerListeners=function(){var t=this.hls;t.on(T.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(T.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(T.MANIFEST_LOADING,this.onManifestLoading,this),t.on(T.MANIFEST_PARSED,this.onManifestParsed,this),t.on(T.BUFFER_RESET,this.onBufferReset,this),t.on(T.BUFFER_APPENDING,this.onBufferAppending,this),t.on(T.BUFFER_CODECS,this.onBufferCodecs,this),t.on(T.BUFFER_EOS,this.onBufferEos,this),t.on(T.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(T.LEVEL_UPDATED,this.onLevelUpdated,this),t.on(T.FRAG_PARSED,this.onFragParsed,this),t.on(T.FRAG_CHANGED,this.onFragChanged,this)},e.unregisterListeners=function(){var t=this.hls;t.off(T.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(T.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(T.MANIFEST_LOADING,this.onManifestLoading,this),t.off(T.MANIFEST_PARSED,this.onManifestParsed,this),t.off(T.BUFFER_RESET,this.onBufferReset,this),t.off(T.BUFFER_APPENDING,this.onBufferAppending,this),t.off(T.BUFFER_CODECS,this.onBufferCodecs,this),t.off(T.BUFFER_EOS,this.onBufferEos,this),t.off(T.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(T.LEVEL_UPDATED,this.onLevelUpdated,this),t.off(T.FRAG_PARSED,this.onFragParsed,this),t.off(T.FRAG_CHANGED,this.onFragChanged,this)},e._initSourceBuffer=function(){this.sourceBuffer={},this.operationQueue=new wn(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.appendErrors={audio:0,video:0,audiovideo:0},this.lastMpegAudioChunk=null},e.onManifestLoading=function(){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=0,this.details=null},e.onManifestParsed=function(t,e){var r=2;(e.audio&&!e.video||!e.altAudio)&&(r=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=r,this.log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},e.onMediaAttaching=function(t,e){var r=this.media=e.media,i=zt(this.appendSource);if(r&&i){var n,a=this.mediaSource=new i;this.log("created media source: "+(null==(n=a.constructor)?void 0:n.name)),a.addEventListener("sourceopen",this._onMediaSourceOpen),a.addEventListener("sourceended",this._onMediaSourceEnded),a.addEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(a.addEventListener("startstreaming",this._onStartStreaming),a.addEventListener("endstreaming",this._onEndStreaming));var s=this._objectUrl=self.URL.createObjectURL(a);if(this.appendSource)try{r.removeAttribute("src");var o=self.ManagedMediaSource;r.disableRemotePlayback=r.disableRemotePlayback||o&&a instanceof o,Pn(r),function(t,e){var r=self.document.createElement("source");r.type="video/mp4",r.src=e,t.appendChild(r)}(r,s),r.load()}catch(t){r.src=s}else r.src=s;r.addEventListener("emptied",this._onMediaEmptied)}},e.onMediaDetaching=function(){var t=this.media,e=this.mediaSource,r=this._objectUrl;if(e){if(this.log("media source detaching"),"open"===e.readyState)try{e.endOfStream()}catch(t){this.warn("onMediaDetaching: "+t.message+" while calling endOfStream")}this.onBufferReset(),e.removeEventListener("sourceopen",this._onMediaSourceOpen),e.removeEventListener("sourceended",this._onMediaSourceEnded),e.removeEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(e.removeEventListener("startstreaming",this._onStartStreaming),e.removeEventListener("endstreaming",this._onEndStreaming)),t&&(t.removeEventListener("emptied",this._onMediaEmptied),r&&self.URL.revokeObjectURL(r),this.mediaSrc===r?(t.removeAttribute("src"),this.appendSource&&Pn(t),t.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(T.MEDIA_DETACHED,void 0)},e.onBufferReset=function(){var t=this;this.getSourceBufferTypes().forEach((function(e){t.resetBuffer(e)})),this._initSourceBuffer()},e.resetBuffer=function(t){var e=this.sourceBuffer[t];try{var r;e&&(this.removeBufferListeners(t),this.sourceBuffer[t]=void 0,null!=(r=this.mediaSource)&&r.sourceBuffers.length&&this.mediaSource.removeSourceBuffer(e))}catch(e){this.warn("onBufferReset "+t,e)}},e.onBufferCodecs=function(t,e){var r=this,i=this.getSourceBufferTypes().length,n=Object.keys(e);if(n.forEach((function(t){if(i){var n=r.tracks[t];if(n&&"function"==typeof n.buffer.changeType){var a,s=e[t],o=s.id,l=s.codec,u=s.levelCodec,h=s.container,d=s.metadata,c=ae(n.codec,n.levelCodec),f=null==c?void 0:c.replace(In,"$1"),g=ae(l,u),v=null==(a=g)?void 0:a.replace(In,"$1");if(g&&f!==v){"audio"===t.slice(0,5)&&(g=ne(g,r.appendSource));var m=h+";codecs="+g;r.appendChangeType(t,m),r.log("switching codec "+c+" to "+g),r.tracks[t]={buffer:n.buffer,codec:l,container:h,levelCodec:u,metadata:d,id:o}}}}else r.pendingTracks[t]=e[t]})),!i){var a=Math.max(this.bufferCodecEventsExpected-1,0);this.bufferCodecEventsExpected!==a&&(this.log(a+" bufferCodec event(s) expected "+n.join(",")),this.bufferCodecEventsExpected=a),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks()}},e.appendChangeType=function(t,e){var r=this,i=this.operationQueue,n={execute:function(){var n=r.sourceBuffer[t];n&&(r.log("changing "+t+" sourceBuffer type to "+e),n.changeType(e)),i.shiftAndExecuteNext(t)},onStart:function(){},onComplete:function(){},onError:function(e){r.warn("Failed to change "+t+" SourceBuffer type",e)}};i.append(n,t,!!this.pendingTracks[t])},e.onBufferAppending=function(t,e){var r=this,i=this.hls,n=this.operationQueue,a=this.tracks,s=e.data,o=e.type,l=e.frag,u=e.part,h=e.chunkMeta,d=h.buffering[o],c=self.performance.now();d.start=c;var f=l.stats.buffering,g=u?u.stats.buffering:null;0===f.start&&(f.start=c),g&&0===g.start&&(g.start=c);var v=a.audio,m=!1;"audio"===o&&"audio/mpeg"===(null==v?void 0:v.container)&&(m=!this.lastMpegAudioChunk||1===h.id||this.lastMpegAudioChunk.sn!==h.sn,this.lastMpegAudioChunk=h);var p=l.start,y={execute:function(){if(d.executeStart=self.performance.now(),m){var t=r.sourceBuffer[o];if(t){var e=p-t.timestampOffset;Math.abs(e)>=.1&&(r.log("Updating audio SourceBuffer timestampOffset to "+p+" (delta: "+e+") sn: "+l.sn+")"),t.timestampOffset=p)}}r.appendExecutor(s,o)},onStart:function(){},onComplete:function(){var t=self.performance.now();d.executeEnd=d.end=t,0===f.first&&(f.first=t),g&&0===g.first&&(g.first=t);var e=r.sourceBuffer,i={};for(var n in e)i[n]=Pr.getBuffered(e[n]);r.appendErrors[o]=0,"audio"===o||"video"===o?r.appendErrors.audiovideo=0:(r.appendErrors.audio=0,r.appendErrors.video=0),r.hls.trigger(T.BUFFER_APPENDED,{type:o,frag:l,part:u,chunkMeta:h,parent:l.type,timeRanges:i})},onError:function(t){var e={type:E.MEDIA_ERROR,parent:l.type,details:S.BUFFER_APPEND_ERROR,sourceBufferName:o,frag:l,part:u,chunkMeta:h,error:t,err:t,fatal:!1};if(t.code===DOMException.QUOTA_EXCEEDED_ERR)e.details=S.BUFFER_FULL_ERROR;else{var n=++r.appendErrors[o];e.details=S.BUFFER_APPEND_ERROR,r.warn("Failed "+n+"/"+i.config.appendErrorMaxRetry+' times to append segment in "'+o+'" sourceBuffer'),n>=i.config.appendErrorMaxRetry&&(e.fatal=!0)}i.trigger(T.ERROR,e)}};n.append(y,o,!!this.pendingTracks[o])},e.onBufferFlushing=function(t,e){var r=this,i=this.operationQueue,n=function(t){return{execute:r.removeExecutor.bind(r,t,e.startOffset,e.endOffset),onStart:function(){},onComplete:function(){r.hls.trigger(T.BUFFER_FLUSHED,{type:t})},onError:function(e){r.warn("Failed to remove from "+t+" SourceBuffer",e)}}};e.type?i.append(n(e.type),e.type):this.getSourceBufferTypes().forEach((function(t){i.append(n(t),t)}))},e.onFragParsed=function(t,e){var r=this,i=e.frag,n=e.part,a=[],s=n?n.elementaryStreams:i.elementaryStreams;s[M]?a.push("audiovideo"):(s[P]&&a.push("audio"),s[O]&&a.push("video")),0===a.length&&this.warn("Fragments must have at least one ElementaryStreamType set. type: "+i.type+" level: "+i.level+" sn: "+i.sn),this.blockBuffers((function(){var t=self.performance.now();i.stats.buffering.end=t,n&&(n.stats.buffering.end=t);var e=n?n.stats:i.stats;r.hls.trigger(T.FRAG_BUFFERED,{frag:i,part:n,stats:e,id:i.type})}),a)},e.onFragChanged=function(t,e){this.trimBuffers()},e.onBufferEos=function(t,e){var r=this;this.getSourceBufferTypes().reduce((function(t,i){var n=r.sourceBuffer[i];return!n||e.type&&e.type!==i||(n.ending=!0,n.ended||(n.ended=!0,r.log(i+" sourceBuffer now EOS"))),t&&!(n&&!n.ended)}),!0)&&(this.log("Queueing mediaSource.endOfStream()"),this.blockBuffers((function(){r.getSourceBufferTypes().forEach((function(t){var e=r.sourceBuffer[t];e&&(e.ending=!1)}));var t=r.mediaSource;t&&"open"===t.readyState?(r.log("Calling mediaSource.endOfStream()"),t.endOfStream()):t&&r.log("Could not call mediaSource.endOfStream(). mediaSource.readyState: "+t.readyState)})))},e.onLevelUpdated=function(t,e){var r=e.details;r.fragments.length&&(this.details=r,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())},e.trimBuffers=function(){var t=this.hls,e=this.details,r=this.media;if(r&&null!==e&&this.getSourceBufferTypes().length){var i=t.config,n=r.currentTime,a=e.levelTargetDuration,s=e.live&&null!==i.liveBackBufferLength?i.liveBackBufferLength:i.backBufferLength;if(m(s)&&s>0){var o=Math.max(s,a),l=Math.floor(n/a)*a-o;this.flushBackBuffer(n,a,l)}if(m(i.frontBufferFlushThreshold)&&i.frontBufferFlushThreshold>0){var u=Math.max(i.maxBufferLength,i.frontBufferFlushThreshold),h=Math.max(u,a),d=Math.floor(n/a)*a+h;this.flushFrontBuffer(n,a,d)}}},e.flushBackBuffer=function(t,e,r){var i=this,n=this.details,a=this.sourceBuffer;this.getSourceBufferTypes().forEach((function(s){var o=a[s];if(o){var l=Pr.getBuffered(o);if(l.length>0&&r>l.start(0)){if(i.hls.trigger(T.BACK_BUFFER_REACHED,{bufferEnd:r}),null!=n&&n.live)i.hls.trigger(T.LIVE_BACK_BUFFER_REACHED,{bufferEnd:r});else if(o.ended&&l.end(l.length-1)-t<2*e)return void i.log("Cannot flush "+s+" back buffer while SourceBuffer is in ended state");i.hls.trigger(T.BUFFER_FLUSHING,{startOffset:0,endOffset:r,type:s})}}}))},e.flushFrontBuffer=function(t,e,r){var i=this,n=this.sourceBuffer;this.getSourceBufferTypes().forEach((function(a){var s=n[a];if(s){var o=Pr.getBuffered(s),l=o.length;if(l<2)return;var u=o.start(l-1),h=o.end(l-1);if(r>u||t>=u&&t<=h)return;if(s.ended&&t-h<2*e)return void i.log("Cannot flush "+a+" front buffer while SourceBuffer is in ended state");i.hls.trigger(T.BUFFER_FLUSHING,{startOffset:u,endOffset:1/0,type:a})}}))},e.updateMediaElementDuration=function(){if(this.details&&this.media&&this.mediaSource&&"open"===this.mediaSource.readyState){var t=this.details,e=this.hls,r=this.media,i=this.mediaSource,n=t.fragments[0].start+t.totalduration,a=r.duration,s=m(i.duration)?i.duration:0;t.live&&e.config.liveDurationInfinity?(i.duration=1/0,this.updateSeekableRange(t)):(n>s&&n>a||!m(a))&&(this.log("Updating Media Source duration to "+n.toFixed(3)),i.duration=n)}},e.updateSeekableRange=function(t){var e=this.mediaSource,r=t.fragments;if(r.length&&t.live&&null!=e&&e.setLiveSeekableRange){var i=Math.max(0,r[0].start),n=Math.max(i,i+t.totalduration);this.log("Media Source duration is set to "+e.duration+". Setting seekable range to "+i+"-"+n+"."),e.setLiveSeekableRange(i,n)}},e.checkPendingTracks=function(){var t=this.bufferCodecEventsExpected,e=this.operationQueue,r=this.pendingTracks,i=Object.keys(r).length;if(i&&(!t||2===i||"audiovideo"in r)){this.createSourceBuffers(r),this.pendingTracks={};var n=this.getSourceBufferTypes();if(n.length)this.hls.trigger(T.BUFFER_CREATED,{tracks:this.tracks}),n.forEach((function(t){e.executeNext(t)}));else{var a=new Error("could not create source buffer for media codec(s)");this.hls.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:a,reason:a.message})}}},e.createSourceBuffers=function(t){var e=this,r=this.sourceBuffer,i=this.mediaSource;if(!i)throw Error("createSourceBuffers called when mediaSource was null");var n=function(n){if(!r[n]){var a,s=t[n];if(!s)throw Error("source buffer exists for track "+n+", however track does not");var o=-1===(null==(a=s.levelCodec)?void 0:a.indexOf(","))?s.levelCodec:s.codec;o&&"audio"===n.slice(0,5)&&(o=ne(o,e.appendSource));var l=s.container+";codecs="+o;e.log("creating sourceBuffer("+l+")");try{var u=r[n]=i.addSourceBuffer(l),h=n;e.addBufferListener(h,"updatestart",e._onSBUpdateStart),e.addBufferListener(h,"updateend",e._onSBUpdateEnd),e.addBufferListener(h,"error",e._onSBUpdateError),e.appendSource&&e.addBufferListener(h,"bufferedchange",(function(t,r){var i=r.removedRanges;null!=i&&i.length&&e.hls.trigger(T.BUFFER_FLUSHED,{type:n})})),e.tracks[n]={buffer:u,codec:o,container:s.container,levelCodec:s.levelCodec,metadata:s.metadata,id:s.id}}catch(t){e.error("error while trying to add sourceBuffer: "+t.message),e.hls.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:t,sourceBufferName:n,mimeType:l})}}};for(var a in t)n(a)},e._onSBUpdateStart=function(t){this.operationQueue.current(t).onStart()},e._onSBUpdateEnd=function(t){var e;if("closed"!==(null==(e=this.mediaSource)?void 0:e.readyState)){var r=this.operationQueue;r.current(t).onComplete(),r.shiftAndExecuteNext(t)}else this.resetBuffer(t)},e._onSBUpdateError=function(t,e){var r,i=new Error(t+" SourceBuffer error. MediaSource readyState: "+(null==(r=this.mediaSource)?void 0:r.readyState));this.error(""+i,e),this.hls.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.BUFFER_APPENDING_ERROR,sourceBufferName:t,error:i,fatal:!1});var n=this.operationQueue.current(t);n&&n.onError(i)},e.removeExecutor=function(t,e,r){var i=this.media,n=this.mediaSource,a=this.operationQueue,s=this.sourceBuffer[t];if(!i||!n||!s)return this.warn("Attempting to remove from the "+t+" SourceBuffer, but it does not exist"),void a.shiftAndExecuteNext(t);var o=m(i.duration)?i.duration:1/0,l=m(n.duration)?n.duration:1/0,u=Math.max(0,e),h=Math.min(r,o,l);h>u&&(!s.ending||s.ended)?(s.ended=!1,this.log("Removing ["+u+","+h+"] from the "+t+" SourceBuffer"),s.remove(u,h)):a.shiftAndExecuteNext(t)},e.appendExecutor=function(t,e){var r=this.sourceBuffer[e];if(r)r.ended=!1,r.appendBuffer(t);else if(!this.pendingTracks[e])throw new Error("Attempting to append to the "+e+" SourceBuffer, but it does not exist")},e.blockBuffers=function(t,e){var r=this;if(void 0===e&&(e=this.getSourceBufferTypes()),!e.length)return this.log("Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(t);var i=this.operationQueue,n=e.map((function(t){return i.appendBlocker(t)}));Promise.all(n).then((function(){t(),e.forEach((function(t){var e=r.sourceBuffer[t];null!=e&&e.updating||i.shiftAndExecuteNext(t)}))}))},e.getSourceBufferTypes=function(){return Object.keys(this.sourceBuffer)},e.addBufferListener=function(t,e,r){var i=this.sourceBuffer[t];if(i){var n=r.bind(this,t);this.listeners[t].push({event:e,listener:n}),i.addEventListener(e,n)}},e.removeBufferListeners=function(t){var e=this.sourceBuffer[t];e&&this.listeners[t].forEach((function(t){e.removeEventListener(t.event,t.listener)}))},s(t,[{key:"mediaSrc",get:function(){var t,e=(null==(t=this.media)?void 0:t.firstChild)||this.media;return null==e?void 0:e.src}}]),t}();function Pn(t){var e=t.querySelectorAll("source");[].slice.call(e).forEach((function(e){t.removeChild(e)}))}var On={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608,128:174,129:176,130:189,131:191,132:8482,133:162,134:163,135:9834,136:224,137:32,138:232,139:226,140:234,141:238,142:244,143:251,144:193,145:201,146:211,147:218,148:220,149:252,150:8216,151:161,152:42,153:8217,154:9473,155:169,156:8480,157:8226,158:8220,159:8221,160:192,161:194,162:199,163:200,164:202,165:203,166:235,167:206,168:207,169:239,170:212,171:217,172:249,173:219,174:171,175:187,176:195,177:227,178:205,179:204,180:236,181:210,182:242,183:213,184:245,185:123,186:125,187:92,188:94,189:95,190:124,191:8764,192:196,193:228,194:214,195:246,196:223,197:165,198:164,199:9475,200:197,201:229,202:216,203:248,204:9487,205:9491,206:9495,207:9499},Mn=function(t){return String.fromCharCode(On[t]||t)},Fn=15,Nn=100,Un={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},Bn={17:2,18:4,21:6,22:8,23:10,19:13,20:15},Gn={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},Hn={25:2,26:4,29:6,30:8,31:10,27:13,28:15},Kn=["white","green","blue","cyan","red","yellow","magenta","black","transparent"],Vn=function(){function t(){this.time=null,this.verboseLevel=0}return t.prototype.log=function(t,e){if(this.verboseLevel>=t){var r="function"==typeof e?e():e;b.log(this.time+" ["+t+"] "+r)}},t}(),jn=function(t){for(var e=[],r=0;rNn&&(this.logger.log(3,"Too large cursor position "+this.pos),this.pos=Nn)},e.moveCursor=function(t){var e=this.pos+t;if(t>1)for(var r=this.pos+1;r=144&&this.backSpace();var r=Mn(t);this.pos>=Nn?this.logger.log(0,(function(){return"Cannot insert "+t.toString(16)+" ("+r+") at position "+e.pos+". Skipping it!"})):(this.chars[this.pos].setChar(r,this.currPenState),this.moveCursor(1))},e.clearFromPos=function(t){var e;for(e=t;e0&&(r=t?"["+e.join(" | ")+"]":e.join("\n")),r},e.getTextAndFormat=function(){return this.rows},t}(),zn=function(){function t(t,e,r){this.chNr=void 0,this.outputFilter=void 0,this.mode=void 0,this.verbose=void 0,this.displayedMemory=void 0,this.nonDisplayedMemory=void 0,this.lastOutputScreen=void 0,this.currRollUpRow=void 0,this.writeScreen=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chNr=t,this.outputFilter=e,this.mode=null,this.verbose=0,this.displayedMemory=new Xn(r),this.nonDisplayedMemory=new Xn(r),this.lastOutputScreen=new Xn(r),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.logger=r}var e=t.prototype;return e.reset=function(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.outputFilter.reset(),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null},e.getHandler=function(){return this.outputFilter},e.setHandler=function(t){this.outputFilter=t},e.setPAC=function(t){this.writeScreen.setPAC(t)},e.setBkgData=function(t){this.writeScreen.setBkgData(t)},e.setMode=function(t){t!==this.mode&&(this.mode=t,this.logger.log(2,(function(){return"MODE="+t})),"MODE_POP-ON"===this.mode?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),"MODE_ROLL-UP"!==this.mode&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=t)},e.insertChars=function(t){for(var e=this,r=0;r=46,e.italics)e.foreground="white";else{var r=Math.floor(t/2)-16;e.foreground=["white","green","blue","cyan","red","yellow","magenta"][r]}this.logger.log(2,"MIDROW: "+JSON.stringify(e)),this.writeScreen.setPen(e)},e.outputDataUpdate=function(t){void 0===t&&(t=!1);var e=this.logger.time;null!==e&&this.outputFilter&&(null!==this.cueStartTime||this.displayedMemory.isEmpty()?this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue(this.cueStartTime,e,this.lastOutputScreen),t&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:e):this.cueStartTime=e,this.lastOutputScreen.copy(this.displayedMemory))},e.cueSplitAtTime=function(t){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,t,this.displayedMemory),this.cueStartTime=t))},t}(),Qn=function(){function t(t,e,r){this.channels=void 0,this.currentChannel=0,this.cmdHistory={a:null,b:null},this.logger=void 0;var i=this.logger=new Vn;this.channels=[null,new zn(t,e,i),new zn(t+1,r,i)]}var e=t.prototype;return e.getHandler=function(t){return this.channels[t].getHandler()},e.setHandler=function(t,e){this.channels[t].setHandler(e)},e.addData=function(t,e){var r=this;this.logger.time=t;for(var i=function(t){var i=127&e[t],n=127&e[t+1],a=!1,s=null;if(0===i&&0===n)return 0;r.logger.log(3,(function(){return"["+jn([e[t],e[t+1]])+"] -> ("+jn([i,n])+")"}));var o=r.cmdHistory;if(i>=16&&i<=31){if(function(t,e,r){return r.a===t&&r.b===e}(i,n,o))return Zn(null,null,o),r.logger.log(3,(function(){return"Repeated command ("+jn([i,n])+") is dropped"})),0;Zn(i,n,r.cmdHistory),(a=r.parseCmd(i,n))||(a=r.parseMidrow(i,n)),a||(a=r.parsePAC(i,n)),a||(a=r.parseBackgroundAttributes(i,n))}else Zn(null,null,o);if(!a&&(s=r.parseChars(i,n))){var l=r.currentChannel;l&&l>0?r.channels[l].insertChars(s):r.logger.log(2,"No channel found yet. TEXT-MODE?")}a||s||r.logger.log(2,(function(){return"Couldn't parse cleaned data "+jn([i,n])+" orig: "+jn([e[t],e[t+1]])}))},n=0;n=32&&e<=47||(23===t||31===t)&&e>=33&&e<=35))return!1;var r=20===t||21===t||23===t?1:2,i=this.channels[r];return 20===t||21===t||28===t||29===t?32===e?i.ccRCL():33===e?i.ccBS():34===e?i.ccAOF():35===e?i.ccAON():36===e?i.ccDER():37===e?i.ccRU(2):38===e?i.ccRU(3):39===e?i.ccRU(4):40===e?i.ccFON():41===e?i.ccRDC():42===e?i.ccTR():43===e?i.ccRTD():44===e?i.ccEDM():45===e?i.ccCR():46===e?i.ccENM():47===e&&i.ccEOC():i.ccTO(e-32),this.currentChannel=r,!0},e.parseMidrow=function(t,e){var r=0;if((17===t||25===t)&&e>=32&&e<=47){if((r=17===t?1:2)!==this.currentChannel)return this.logger.log(0,"Mismatch channel in midrow parsing"),!1;var i=this.channels[r];return!!i&&(i.ccMIDROW(e),this.logger.log(3,(function(){return"MIDROW ("+jn([t,e])+")"})),!0)}return!1},e.parsePAC=function(t,e){var r;if(!((t>=17&&t<=23||t>=25&&t<=31)&&e>=64&&e<=127||(16===t||24===t)&&e>=64&&e<=95))return!1;var i=t<=23?1:2;r=e>=64&&e<=95?1===i?Un[t]:Gn[t]:1===i?Bn[t]:Hn[t];var n=this.channels[i];return!!n&&(n.setPAC(this.interpretPAC(r,e)),this.currentChannel=i,!0)},e.interpretPAC=function(t,e){var r,i={color:null,italics:!1,indent:null,underline:!1,row:t};return r=e>95?e-96:e-64,i.underline=!(1&~r),r<=13?i.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(r/2)]:r<=15?(i.italics=!0,i.color="white"):i.indent=4*Math.floor((r-16)/2),i},e.parseChars=function(t,e){var r,i,n=null,a=null;return t>=25?(r=2,a=t-8):(r=1,a=t),a>=17&&a<=19?(i=17===a?e+80:18===a?e+112:e+144,this.logger.log(2,(function(){return"Special char '"+Mn(i)+"' in channel "+r})),n=[i]):t>=32&&t<=127&&(n=0===e?[t]:[t,e]),n&&this.logger.log(3,(function(){return"Char codes = "+jn(n).join(",")})),n},e.parseBackgroundAttributes=function(t,e){var r;if(!((16===t||24===t)&&e>=32&&e<=47||(23===t||31===t)&&e>=45&&e<=47))return!1;var i={};16===t||24===t?(r=Math.floor((e-32)/2),i.background=Kn[r],e%2==1&&(i.background=i.background+"_semi")):45===e?i.background="transparent":(i.foreground="black",47===e&&(i.underline=!0));var n=t<=23?1:2;return this.channels[n].setBkgData(i),!0},e.reset=function(){for(var t=0;tt)&&(this.startTime=t),this.endTime=e,this.screen=r,this.timelineController.createCaptionsTrack(this.trackName)},e.reset=function(){this.cueRanges=[],this.startTime=null},t}(),Jn=function(){if(null!=K&&K.VTTCue)return self.VTTCue;var t=["","lr","rl"],e=["start","middle","end","left","right"];function r(t,e){if("string"!=typeof e)return!1;if(!Array.isArray(t))return!1;var r=e.toLowerCase();return!!~t.indexOf(r)&&r}function i(t){return r(e,t)}function n(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i100)throw new Error("Position must be between 0 and 100.");T=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"positionAlign",n({},l,{get:function(){return E},set:function(t){var e=i(t);if(!e)throw new SyntaxError("An invalid or illegal string was specified.");E=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"size",n({},l,{get:function(){return S},set:function(t){if(t<0||t>100)throw new Error("Size must be between 0 and 100.");S=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"align",n({},l,{get:function(){return L},set:function(t){var e=i(t);if(!e)throw new SyntaxError("An invalid or illegal string was specified.");L=e,this.hasBeenReset=!0}})),o.displayState=void 0}return a.prototype.getCueAsHTML=function(){return self.WebVTT.convertCueToDOMTree(self,this.text)},a}(),ta=function(){function t(){}return t.prototype.decode=function(t,e){if(!t)return"";if("string"!=typeof t)throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(t))},t}();function ea(t){function e(t,e,r,i){return 3600*(0|t)+60*(0|e)+(0|r)+parseFloat(i||0)}var r=t.match(/^(?:(\d+):)?(\d{2}):(\d{2})(\.\d+)?/);return r?parseFloat(r[2])>59?e(r[2],r[3],0,r[4]):e(r[1],r[2],r[3],r[4]):null}var ra=function(){function t(){this.values=Object.create(null)}var e=t.prototype;return e.set=function(t,e){this.get(t)||""===e||(this.values[t]=e)},e.get=function(t,e,r){return r?this.has(t)?this.values[t]:e[r]:this.has(t)?this.values[t]:e},e.has=function(t){return t in this.values},e.alt=function(t,e,r){for(var i=0;i=0&&r<=100)return this.set(t,r),!0}return!1},t}();function ia(t,e,r,i){var n=i?t.split(i):[t];for(var a in n)if("string"==typeof n[a]){var s=n[a].split(r);2===s.length&&e(s[0],s[1])}}var na=new Jn(0,0,""),aa="middle"===na.align?"middle":"center";function sa(t,e,r){var i=t;function n(){var e=ea(t);if(null===e)throw new Error("Malformed timestamp: "+i);return t=t.replace(/^[^\sa-zA-Z-]+/,""),e}function a(){t=t.replace(/^\s+/,"")}if(a(),e.startTime=n(),a(),"--\x3e"!==t.slice(0,3))throw new Error("Malformed time stamp (time stamps must be separated by '--\x3e'): "+i);t=t.slice(3),a(),e.endTime=n(),a(),function(t,e){var i=new ra;ia(t,(function(t,e){var n;switch(t){case"region":for(var a=r.length-1;a>=0;a--)if(r[a].id===e){i.set(t,r[a].region);break}break;case"vertical":i.alt(t,e,["rl","lr"]);break;case"line":n=e.split(","),i.integer(t,n[0]),i.percent(t,n[0])&&i.set("snapToLines",!1),i.alt(t,n[0],["auto"]),2===n.length&&i.alt("lineAlign",n[1],["start",aa,"end"]);break;case"position":n=e.split(","),i.percent(t,n[0]),2===n.length&&i.alt("positionAlign",n[1],["start",aa,"end","line-left","line-right","auto"]);break;case"size":i.percent(t,e);break;case"align":i.alt(t,e,["start",aa,"end","left","right"])}}),/:/,/\s/),e.region=i.get("region",null),e.vertical=i.get("vertical","");var n=i.get("line","auto");"auto"===n&&-1===na.line&&(n=-1),e.line=n,e.lineAlign=i.get("lineAlign","start"),e.snapToLines=i.get("snapToLines",!0),e.size=i.get("size",100),e.align=i.get("align",aa);var a=i.get("position","auto");"auto"===a&&50===na.position&&(a="start"===e.align||"left"===e.align?0:"end"===e.align||"right"===e.align?100:50),e.position=a}(t,e)}function oa(t){return t.replace(//gi,"\n")}var la=function(){function t(){this.state="INITIAL",this.buffer="",this.decoder=new ta,this.regionList=[],this.cue=null,this.oncue=void 0,this.onparsingerror=void 0,this.onflush=void 0}var e=t.prototype;return e.parse=function(t){var e=this;function r(){var t=e.buffer,r=0;for(t=oa(t);r>>0).toString()};function ca(t,e,r){return da(t.toString())+da(e.toString())+da(r)}var fa="stpp.ttml.im1t",ga=/^(\d{2,}):(\d{2}):(\d{2}):(\d{2})\.?(\d+)?$/,va=/^(\d*(?:\.\d*)?)(h|m|s|ms|f|t)$/,ma={left:"start",center:"center",right:"end",start:"start",end:"end"};function pa(t,e,r,i){var n=Dt(new Uint8Array(t),["mdat"]);if(0!==n.length){var a,s,l,u=n.map((function(t){return mt(t)})),h=(a=e.baseTime,1,void 0===(s=e.timescale)&&(s=1),void 0===l&&(l=!1),Zi(a,1,1/s,l));try{u.forEach((function(t){return r(function(t,e){var r=(new DOMParser).parseFromString(t,"text/xml").getElementsByTagName("tt")[0];if(!r)throw new Error("Invalid ttml");var i={frameRate:30,subFrameRate:1,frameRateMultiplier:0,tickRate:0},n=Object.keys(i).reduce((function(t,e){return t[e]=r.getAttribute("ttp:"+e)||i[e],t}),{}),a="preserve"!==r.getAttribute("xml:space"),s=Ta(ya(r,"styling","style")),l=Ta(ya(r,"layout","region")),u=ya(r,"body","[begin]");return[].map.call(u,(function(t){var r=Ea(t,a);if(!r||!t.hasAttribute("begin"))return null;var i=Ra(t.getAttribute("begin"),n),u=Ra(t.getAttribute("dur"),n),h=Ra(t.getAttribute("end"),n);if(null===i)throw La(t);if(null===h){if(null===u)throw La(t);h=i+u}var d=new Jn(i-e,h-e,r);d.id=ca(d.startTime,d.endTime,d.text);var c=function(t,e,r){var i="http://www.w3.org/ns/ttml#styling",n=null,a=null!=t&&t.hasAttribute("style")?t.getAttribute("style"):null;return a&&r.hasOwnProperty(a)&&(n=r[a]),["displayAlign","textAlign","color","backgroundColor","fontSize","fontFamily"].reduce((function(r,a){var s=Sa(e,i,a)||Sa(t,i,a)||Sa(n,i,a);return s&&(r[a]=s),r}),{})}(l[t.getAttribute("region")],s[t.getAttribute("style")],s),f=c.textAlign;if(f){var g=ma[f];g&&(d.lineAlign=g),d.align=f}return o(d,c),d})).filter((function(t){return null!==t}))}(t,h))}))}catch(t){i(t)}}else i(new Error("Could not parse IMSC1 mdat"))}function ya(t,e,r){var i=t.getElementsByTagName(e)[0];return i?[].slice.call(i.querySelectorAll(r)):[]}function Ta(t){return t.reduce((function(t,e){var r=e.getAttribute("xml:id");return r&&(t[r]=e),t}),{})}function Ea(t,e){return[].slice.call(t.childNodes).reduce((function(t,r,i){var n;return"br"===r.nodeName&&i?t+"\n":null!=(n=r.childNodes)&&n.length?Ea(r,e):e?t+r.textContent.trim().replace(/\s+/g," "):t+r.textContent}),"")}function Sa(t,e,r){return t&&t.hasAttributeNS(e,r)?t.getAttributeNS(e,r):null}function La(t){return new Error("Could not parse ttml timestamp "+t)}function Ra(t,e){if(!t)return null;var r=ea(t);return null===r&&(ga.test(t)?r=function(t,e){var r=ga.exec(t),i=(0|r[4])+(0|r[5])/e.subFrameRate;return 3600*(0|r[1])+60*(0|r[2])+(0|r[3])+i/e.frameRate}(t,e):va.test(t)&&(r=function(t,e){var r=va.exec(t),i=Number(r[1]);switch(r[2]){case"h":return 3600*i;case"m":return 60*i;case"ms":return 1e3*i;case"f":return i/e.frameRate;case"t":return i/e.tickRate}return i}(t,e))),r}var ka=function(){function t(t){this.hls=void 0,this.media=null,this.config=void 0,this.enabled=!0,this.Cues=void 0,this.textTracks=[],this.tracks=[],this.initPTS=[],this.unparsedVttFrags=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.cea608Parser1=void 0,this.cea608Parser2=void 0,this.lastCc=-1,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}},this.captionsProperties=void 0,this.hls=t,this.config=t.config,this.Cues=t.config.cueHandler,this.captionsProperties={textTrack1:{label:this.config.captionsTextTrack1Label,languageCode:this.config.captionsTextTrack1LanguageCode},textTrack2:{label:this.config.captionsTextTrack2Label,languageCode:this.config.captionsTextTrack2LanguageCode},textTrack3:{label:this.config.captionsTextTrack3Label,languageCode:this.config.captionsTextTrack3LanguageCode},textTrack4:{label:this.config.captionsTextTrack4Label,languageCode:this.config.captionsTextTrack4LanguageCode}},t.on(T.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(T.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(T.MANIFEST_LOADING,this.onManifestLoading,this),t.on(T.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(T.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(T.FRAG_LOADING,this.onFragLoading,this),t.on(T.FRAG_LOADED,this.onFragLoaded,this),t.on(T.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.on(T.FRAG_DECRYPTED,this.onFragDecrypted,this),t.on(T.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(T.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.on(T.BUFFER_FLUSHING,this.onBufferFlushing,this)}var e=t.prototype;return e.destroy=function(){var t=this.hls;t.off(T.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(T.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(T.MANIFEST_LOADING,this.onManifestLoading,this),t.off(T.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(T.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(T.FRAG_LOADING,this.onFragLoading,this),t.off(T.FRAG_LOADED,this.onFragLoaded,this),t.off(T.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.off(T.FRAG_DECRYPTED,this.onFragDecrypted,this),t.off(T.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(T.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.off(T.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=null,this.cea608Parser1=this.cea608Parser2=void 0},e.initCea608Parsers=function(){if(this.config.enableCEA708Captions&&(!this.cea608Parser1||!this.cea608Parser2)){var t=new $n(this,"textTrack1"),e=new $n(this,"textTrack2"),r=new $n(this,"textTrack3"),i=new $n(this,"textTrack4");this.cea608Parser1=new Qn(1,t,e),this.cea608Parser2=new Qn(3,r,i)}},e.addCues=function(t,e,r,i,n){for(var a,s,o,l,u=!1,h=n.length;h--;){var d=n[h],c=(a=d[0],s=d[1],o=e,l=r,Math.min(s,l)-Math.max(a,o));if(c>=0&&(d[0]=Math.min(d[0],e),d[1]=Math.max(d[1],r),u=!0,c/(r-e)>.5))return}if(u||n.push([e,r]),this.config.renderTextTracksNatively){var f=this.captionsTracks[t];this.Cues.newCue(f,e,r,i)}else{var g=this.Cues.newCue(null,e,r,i);this.hls.trigger(T.CUES_PARSED,{type:"captions",cues:g,track:t})}},e.onInitPtsFound=function(t,e){var r=this,i=e.frag,n=e.id,a=e.initPTS,s=e.timescale,o=this.unparsedVttFrags;"main"===n&&(this.initPTS[i.cc]={baseTime:a,timescale:s}),o.length&&(this.unparsedVttFrags=[],o.forEach((function(t){r.onFragLoaded(T.FRAG_LOADED,t)})))},e.getExistingTrack=function(t,e){var r=this.media;if(r)for(var i=0;i0&&c.push(t)},h.onparsingerror=function(t){u=t},h.onflush=function(){u?s(u):a(c)},d.forEach((function(t){if(y){if(ha(t,"X-TIMESTAMP-MAP=")){y=!1,t.slice(16).split(",").forEach((function(t){ha(t,"LOCAL:")?g=t.slice(6):ha(t,"MPEGTS:")&&(v=parseInt(t.slice(7)))}));try{p=function(t){var e=parseInt(t.slice(-3)),r=parseInt(t.slice(-6,-4)),i=parseInt(t.slice(-9,-7)),n=t.length>9?parseInt(t.substring(0,t.indexOf(":"))):0;if(!(m(e)&&m(r)&&m(i)&&m(n)))throw Error("Malformed X-TIMESTAMP-MAP: Local:"+t);return e+=1e3*r,(e+=6e4*i)+36e5*n}(g)/1e3}catch(t){u=t}return}""===t&&(y=!1)}h.parse(t+"\n")})),h.flush()}(null!=(e=i.initSegment)&&e.data?Ft(i.initSegment.data,new Uint8Array(n)):n,this.initPTS[i.cc],this.vttCCs,i.cc,i.start,(function(t){r._appendCues(t,i.level),l.trigger(T.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:i})}),(function(e){var a="Missing initPTS for VTT MPEGTS"===e.message;a?s.push(t):r._fallbackToIMSC1(i,n),b.log("Failed to parse VTT cue: "+e),a&&o>i.cc||l.trigger(T.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:i,error:e})}))}else s.push(t)},e._fallbackToIMSC1=function(t,e){var r=this,i=this.tracks[t.level];i.textCodec||pa(e,this.initPTS[t.cc],(function(){i.textCodec=fa,r._parseIMSC1(t,e)}),(function(){i.textCodec="wvtt"}))},e._appendCues=function(t,e){var r=this.hls;if(this.config.renderTextTracksNatively){var i=this.textTracks[e];if(!i||"disabled"===i.mode)return;t.forEach((function(t){return we(i,t)}))}else{var n=this.tracks[e];if(!n)return;var a=n.default?"default":"subtitles"+e;r.trigger(T.CUES_PARSED,{type:"subtitles",cues:t,track:a})}},e.onFragDecrypted=function(t,e){e.frag.type===Ae&&this.onFragLoaded(T.FRAG_LOADED,e)},e.onSubtitleTracksCleared=function(){this.tracks=[],this.captionsTracks={}},e.onFragParsingUserdata=function(t,e){this.initCea608Parsers();var r=this.cea608Parser1,i=this.cea608Parser2;if(this.enabled&&r&&i){var n=e.frag,a=e.samples;if(n.type!==Re||"NONE"!==this.closedCaptionsForLevel(n))for(var s=0;sthis.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=e.autoLevelCapping}}},e.getMaxLevel=function(e){var r=this,i=this.hls.levels;if(!i.length)return-1;var n=i.filter((function(t,i){return r.isLevelAllowed(t)&&i<=e}));return this.clientRect=null,t.getMaxLevelByMediaSize(n,this.mediaWidth,this.mediaHeight)},e.startCapping=function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},e.stopCapping=function(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)},e.getDimensions=function(){if(this.clientRect)return this.clientRect;var t=this.media,e={width:0,height:0};if(t){var r=t.getBoundingClientRect();e.width=r.width,e.height=r.height,e.width||e.height||(e.width=r.right-r.left||t.width||0,e.height=r.bottom-r.top||t.height||0)}return this.clientRect=e,e},e.isLevelAllowed=function(t){return!this.restrictedLevels.some((function(e){return t.bitrate===e.bitrate&&t.width===e.width&&t.height===e.height}))},t.getMaxLevelByMediaSize=function(t,e,r){if(null==t||!t.length)return-1;for(var i,n,a=t.length-1,s=Math.max(e,r),o=0;o=s||l.height>=s)&&(i=l,!(n=t[o+1])||i.width!==n.width||i.height!==n.height)){a=o;break}}return a},s(t,[{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 t=1;if(!this.hls.config.ignoreDevicePixelRatio)try{t=self.devicePixelRatio}catch(t){}return t}}]),t}(),_a=function(){function t(t){this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=t,this.registerListeners()}var e=t.prototype;return e.setStreamController=function(t){this.streamController=t},e.registerListeners=function(){this.hls.on(T.MEDIA_ATTACHING,this.onMediaAttaching,this)},e.unregisterListeners=function(){this.hls.off(T.MEDIA_ATTACHING,this.onMediaAttaching,this)},e.destroy=function(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null},e.onMediaAttaching=function(t,e){var r=this.hls.config;if(r.capLevelOnFPSDrop){var i=e.media instanceof self.HTMLVideoElement?e.media:null;this.media=i,i&&"function"==typeof i.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),r.fpsDroppedMonitoringPeriod)}},e.checkFPS=function(t,e,r){var i=performance.now();if(e){if(this.lastTime){var n=i-this.lastTime,a=r-this.lastDroppedFrames,s=e-this.lastDecodedFrames,o=1e3*a/n,l=this.hls;if(l.trigger(T.FPS_DROP,{currentDropped:a,currentDecoded:s,totalDroppedFrames:r}),o>0&&a>l.config.fpsDroppedMonitoringThreshold*s){var u=l.currentLevel;b.warn("drop FPS ratio greater than max allowed value for currentLevel: "+u),u>0&&(-1===l.autoLevelCapping||l.autoLevelCapping>=u)&&(u-=1,l.trigger(T.FPS_DROP_LEVEL_CAPPING,{level:u,droppedLevel:l.currentLevel}),l.autoLevelCapping=u,this.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=r,this.lastDecodedFrames=e}},e.checkFPSInterval=function(){var t=this.media;if(t)if(this.isVideoPlaybackQualityAvailable){var e=t.getVideoPlaybackQuality();this.checkFPS(t,e.totalVideoFrames,e.droppedVideoFrames)}else this.checkFPS(t,t.webkitDecodedFrameCount,t.webkitDroppedFrameCount)},t}(),Ca="[eme]",wa=function(){function t(e){this.hls=void 0,this.config=void 0,this.media=null,this.keyFormatPromise=null,this.keySystemAccessPromises={},this._requestLicenseFailureCount=0,this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},this.setMediaKeysQueue=t.CDMCleanupPromise?[t.CDMCleanupPromise]:[],this.onMediaEncrypted=this._onMediaEncrypted.bind(this),this.onWaitingForKey=this._onWaitingForKey.bind(this),this.debug=b.debug.bind(b,Ca),this.log=b.log.bind(b,Ca),this.warn=b.warn.bind(b,Ca),this.error=b.error.bind(b,Ca),this.hls=e,this.config=e.config,this.registerListeners()}var r=t.prototype;return r.destroy=function(){this.unregisterListeners(),this.onMediaDetached();var t=this.config;t.requestMediaKeySystemAccessFunc=null,t.licenseXhrSetup=t.licenseResponseCallback=void 0,t.drmSystems=t.drmSystemOptions={},this.hls=this.onMediaEncrypted=this.onWaitingForKey=this.keyIdToKeySessionPromise=null,this.config=null},r.registerListeners=function(){this.hls.on(T.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(T.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.on(T.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(T.MANIFEST_LOADED,this.onManifestLoaded,this)},r.unregisterListeners=function(){this.hls.off(T.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(T.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.off(T.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(T.MANIFEST_LOADED,this.onManifestLoaded,this)},r.getLicenseServerUrl=function(t){var e=this.config,r=e.drmSystems,i=e.widevineLicenseUrl,n=r[t];if(n)return n.licenseUrl;if(t===V.WIDEVINE&&i)return i;throw new Error('no license server URL configured for key-system "'+t+'"')},r.getServerCertificateUrl=function(t){var e=this.config.drmSystems[t];if(e)return e.serverCertificateUrl;this.log('No Server Certificate in config.drmSystems["'+t+'"]')},r.attemptKeySystemAccess=function(t){var e=this,r=this.hls.levels,i=function(t,e,r){return!!t&&r.indexOf(t)===e},n=r.map((function(t){return t.audioCodec})).filter(i),a=r.map((function(t){return t.videoCodec})).filter(i);return n.length+a.length===0&&a.push("avc1.42e01e"),new Promise((function(r,i){!function t(s){var o=s.shift();e.getMediaKeysPromise(o,n,a).then((function(t){return r({keySystem:o,mediaKeys:t})})).catch((function(e){s.length?t(s):i(e instanceof Ma?e:new Ma({type:E.KEY_SYSTEM_ERROR,details:S.KEY_SYSTEM_NO_ACCESS,error:e,fatal:!0},e.message))}))}(t)}))},r.requestMediaKeySystemAccess=function(t,e){var r=this.config.requestMediaKeySystemAccessFunc;if("function"!=typeof r){var i="Configured requestMediaKeySystemAccess is not a function "+r;return null===J&&"http:"===self.location.protocol&&(i="navigator.requestMediaKeySystemAccess is not available over insecure protocol "+location.protocol),Promise.reject(new Error(i))}return r(t,e)},r.getMediaKeysPromise=function(t,e,r){var i=this,n=function(t,e,r,i){var n;switch(t){case V.FAIRPLAY:n=["cenc","sinf"];break;case V.WIDEVINE:case V.PLAYREADY:n=["cenc"];break;case V.CLEARKEY:n=["cenc","keyids"];break;default:throw new Error("Unknown key-system: "+t)}return function(t,e,r,i){return[{initDataTypes:t,persistentState:i.persistentState||"optional",distinctiveIdentifier:i.distinctiveIdentifier||"optional",sessionTypes:i.sessionTypes||[i.sessionType||"temporary"],audioCapabilities:e.map((function(t){return{contentType:'audio/mp4; codecs="'+t+'"',robustness:i.audioRobustness||"",encryptionScheme:i.audioEncryptionScheme||null}})),videoCapabilities:r.map((function(t){return{contentType:'video/mp4; codecs="'+t+'"',robustness:i.videoRobustness||"",encryptionScheme:i.videoEncryptionScheme||null}}))}]}(n,e,r,i)}(t,e,r,this.config.drmSystemOptions),a=this.keySystemAccessPromises[t],s=null==a?void 0:a.keySystemAccess;if(!s){this.log('Requesting encrypted media "'+t+'" key-system access with config: '+JSON.stringify(n)),s=this.requestMediaKeySystemAccess(t,n);var o=this.keySystemAccessPromises[t]={keySystemAccess:s};return s.catch((function(e){i.log('Failed to obtain access to key-system "'+t+'": '+e)})),s.then((function(e){i.log('Access for key-system "'+e.keySystem+'" obtained');var r=i.fetchServerCertificate(t);return i.log('Create media-keys for "'+t+'"'),o.mediaKeys=e.createMediaKeys().then((function(e){return i.log('Media-keys created for "'+t+'"'),r.then((function(r){return r?i.setMediaKeysServerCertificate(e,t,r):e}))})),o.mediaKeys.catch((function(e){i.error('Failed to create media-keys for "'+t+'"}: '+e)})),o.mediaKeys}))}return s.then((function(){return a.mediaKeys}))},r.createMediaKeySessionContext=function(t){var e=t.decryptdata,r=t.keySystem,i=t.mediaKeys;this.log('Creating key-system session "'+r+'" keyId: '+pt(e.keyId||[]));var n=i.createSession(),a={decryptdata:e,keySystem:r,mediaKeys:i,mediaKeysSession:n,keyStatus:"status-pending"};return this.mediaKeySessions.push(a),a},r.renewKeySession=function(t){var e=t.decryptdata;if(e.pssh){var r=this.createMediaKeySessionContext(t),i=this.getKeyIdString(e);this.keyIdToKeySessionPromise[i]=this.generateRequestWithPreferredKeySession(r,"cenc",e.pssh,"expired")}else this.warn("Could not renew expired session. Missing pssh initData.");this.removeSession(t)},r.getKeyIdString=function(t){if(!t)throw new Error("Could not read keyId of undefined decryptdata");if(null===t.keyId)throw new Error("keyId is null");return pt(t.keyId)},r.updateKeySession=function(t,e){var r,i=t.mediaKeysSession;return this.log('Updating key-session "'+i.sessionId+'" for keyID '+pt((null==(r=t.decryptdata)?void 0:r.keyId)||[])+"\n } (data length: "+(e?e.byteLength:e)+")"),i.update(e)},r.selectKeySystemFormat=function(t){var e=Object.keys(t.levelkeys||{});return this.keyFormatPromise||(this.log("Selecting key-system from fragment (sn: "+t.sn+" "+t.type+": "+t.level+") key formats "+e.join(", ")),this.keyFormatPromise=this.getKeyFormatPromise(e)),this.keyFormatPromise},r.getKeyFormatPromise=function(t){var e=this;return new Promise((function(r,i){var n=Z(e.config),a=t.map(X).filter((function(t){return!!t&&-1!==n.indexOf(t)}));return e.getKeySystemSelectionPromise(a).then((function(t){var e=t.keySystem,n=Q(e);n?r(n):i(new Error('Unable to find format for key-system "'+e+'"'))})).catch(i)}))},r.loadKey=function(t){var e=this,r=t.keyInfo.decryptdata,i=this.getKeyIdString(r),n="(keyId: "+i+' format: "'+r.keyFormat+'" method: '+r.method+" uri: "+r.uri+")";this.log("Starting session for key "+n);var a=this.keyIdToKeySessionPromise[i];return a||(a=this.keyIdToKeySessionPromise[i]=this.getKeySystemForKeyPromise(r).then((function(i){var a=i.keySystem,s=i.mediaKeys;return e.throwIfDestroyed(),e.log("Handle encrypted media sn: "+t.frag.sn+" "+t.frag.type+": "+t.frag.level+" using key "+n),e.attemptSetMediaKeys(a,s).then((function(){e.throwIfDestroyed();var t=e.createMediaKeySessionContext({keySystem:a,mediaKeys:s,decryptdata:r});return e.generateRequestWithPreferredKeySession(t,"cenc",r.pssh,"playlist-key")}))}))).catch((function(t){return e.handleError(t)})),a},r.throwIfDestroyed=function(t){if(!this.hls)throw new Error("invalid state")},r.handleError=function(t){this.hls&&(this.error(t.message),t instanceof Ma?this.hls.trigger(T.ERROR,t.data):this.hls.trigger(T.ERROR,{type:E.KEY_SYSTEM_ERROR,details:S.KEY_SYSTEM_NO_KEYS,error:t,fatal:!0}))},r.getKeySystemForKeyPromise=function(t){var e=this.getKeyIdString(t),r=this.keyIdToKeySessionPromise[e];if(!r){var i=X(t.keyFormat),n=i?[i]:Z(this.config);return this.attemptKeySystemAccess(n)}return r},r.getKeySystemSelectionPromise=function(t){if(t.length||(t=Z(this.config)),0===t.length)throw new Ma({type:E.KEY_SYSTEM_ERROR,details:S.KEY_SYSTEM_NO_CONFIGURED_LICENSE,fatal:!0},"Missing key-system license configuration options "+JSON.stringify({drmSystems:this.config.drmSystems}));return this.attemptKeySystemAccess(t)},r._onMediaEncrypted=function(t){var e=this,r=t.initDataType,i=t.initData;if(this.debug('"'+t.type+'" event: init data type: "'+r+'"'),null!==i){var n,a;if("sinf"===r&&this.config.drmSystems[V.FAIRPLAY]){var s=St(new Uint8Array(i));try{var o=G(JSON.parse(s).sinf),l=Ot(new Uint8Array(o));if(!l)return;n=l.subarray(8,24),a=V.FAIRPLAY}catch(t){return void this.warn('Failed to parse sinf "encrypted" event message initData')}}else{var u=function(t){if(!(t instanceof ArrayBuffer)||t.byteLength<32)return null;var e={version:0,systemId:"",kids:null,data:null},r=new DataView(t),i=r.getUint32(0);if(t.byteLength!==i&&i>44)return null;if(1886614376!==r.getUint32(4))return null;if(e.version=r.getUint32(8)>>>24,e.version>1)return null;e.systemId=pt(new Uint8Array(t,12,16));var n=r.getUint32(28);if(0===e.version){if(i-320)for(var a,s=0,o=n.length;s in key message");return H(atob(f))},r.setupLicenseXHR=function(t,e,r,i){var n=this,a=this.config.licenseXhrSetup;return a?Promise.resolve().then((function(){if(!r.decryptdata)throw new Error("Key removed");return a.call(n.hls,t,e,r,i)})).catch((function(s){if(!r.decryptdata)throw s;return t.open("POST",e,!0),a.call(n.hls,t,e,r,i)})).then((function(r){return t.readyState||t.open("POST",e,!0),{xhr:t,licenseChallenge:r||i}})):(t.open("POST",e,!0),Promise.resolve({xhr:t,licenseChallenge:i}))},r.requestLicense=function(t,e){var r=this,i=this.config.keyLoadPolicy.default;return new Promise((function(n,a){var s=r.getLicenseServerUrl(t.keySystem);r.log("Sending license request to URL: "+s);var o=new XMLHttpRequest;o.responseType="arraybuffer",o.onreadystatechange=function(){if(!r.hls||!t.mediaKeysSession)return a(new Error("invalid state"));if(4===o.readyState)if(200===o.status){r._requestLicenseFailureCount=0;var l=o.response;r.log("License received "+(l instanceof ArrayBuffer?l.byteLength:l));var u=r.config.licenseResponseCallback;if(u)try{l=u.call(r.hls,o,s,t)}catch(t){r.error(t)}n(l)}else{var h=i.errorRetry,d=h?h.maxNumRetry:0;if(r._requestLicenseFailureCount++,r._requestLicenseFailureCount>d||o.status>=400&&o.status<500)a(new Ma({type:E.KEY_SYSTEM_ERROR,details:S.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0,networkDetails:o,response:{url:s,data:void 0,code:o.status,text:o.statusText}},"License Request XHR failed ("+s+"). Status: "+o.status+" ("+o.statusText+")"));else{var c=d-r._requestLicenseFailureCount+1;r.warn("Retrying license request, "+c+" attempts left"),r.requestLicense(t,e).then(n,a)}}},t.licenseXhr&&t.licenseXhr.readyState!==XMLHttpRequest.DONE&&t.licenseXhr.abort(),t.licenseXhr=o,r.setupLicenseXHR(o,s,t,e).then((function(e){var i=e.xhr,n=e.licenseChallenge;t.keySystem==V.PLAYREADY&&(n=r.unpackPlayReadyKeyMessage(i,n)),i.send(n)}))}))},r.onMediaAttached=function(t,e){if(this.config.emeEnabled){var r=e.media;this.media=r,r.addEventListener("encrypted",this.onMediaEncrypted),r.addEventListener("waitingforkey",this.onWaitingForKey)}},r.onMediaDetached=function(){var e=this,r=this.media,i=this.mediaKeySessions;r&&(r.removeEventListener("encrypted",this.onMediaEncrypted),r.removeEventListener("waitingforkey",this.onWaitingForKey),this.media=null),this._requestLicenseFailureCount=0,this.setMediaKeysQueue=[],this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},Kt.clearKeyUriToKeyIdMap();var n=i.length;t.CDMCleanupPromise=Promise.all(i.map((function(t){return e.removeSession(t)})).concat(null==r?void 0:r.setMediaKeys(null).catch((function(t){e.log("Could not clear media keys: "+t)})))).then((function(){n&&(e.log("finished closing key sessions and clearing media keys"),i.length=0)})).catch((function(t){e.log("Could not close sessions and clear media keys: "+t)}))},r.onManifestLoading=function(){this.keyFormatPromise=null},r.onManifestLoaded=function(t,e){var r=e.sessionKeys;if(r&&this.config.emeEnabled&&!this.keyFormatPromise){var i=r.reduce((function(t,e){return-1===t.indexOf(e.keyFormat)&&t.push(e.keyFormat),t}),[]);this.log("Selecting key-system from session-keys "+i.join(", ")),this.keyFormatPromise=this.getKeyFormatPromise(i)}},r.removeSession=function(t){var e=this,r=t.mediaKeysSession,i=t.licenseXhr;if(r){this.log("Remove licenses and keys and close session "+r.sessionId),t._onmessage&&(r.removeEventListener("message",t._onmessage),t._onmessage=void 0),t._onkeystatuseschange&&(r.removeEventListener("keystatuseschange",t._onkeystatuseschange),t._onkeystatuseschange=void 0),i&&i.readyState!==XMLHttpRequest.DONE&&i.abort(),t.mediaKeysSession=t.decryptdata=t.licenseXhr=void 0;var n=this.mediaKeySessions.indexOf(t);return n>-1&&this.mediaKeySessions.splice(n,1),r.remove().catch((function(t){e.log("Could not remove session: "+t)})).then((function(){return r.close()})).catch((function(t){e.log("Could not close session: "+t)}))}},t}();wa.CDMCleanupPromise=void 0;var Ia,xa,Pa,Oa,Ma=function(t){function e(e,r){var i;return(i=t.call(this,r)||this).data=void 0,e.error||(e.error=new Error(r)),i.data=e,e.err=e.error,i}return l(e,t),e}(c(Error));!function(t){t.MANIFEST="m",t.AUDIO="a",t.VIDEO="v",t.MUXED="av",t.INIT="i",t.CAPTION="c",t.TIMED_TEXT="tt",t.KEY="k",t.OTHER="o"}(Ia||(Ia={})),function(t){t.DASH="d",t.HLS="h",t.SMOOTH="s",t.OTHER="o"}(xa||(xa={})),function(t){t.OBJECT="CMCD-Object",t.REQUEST="CMCD-Request",t.SESSION="CMCD-Session",t.STATUS="CMCD-Status"}(Pa||(Pa={}));var Fa=((Oa={})[Pa.OBJECT]=["br","d","ot","tb"],Oa[Pa.REQUEST]=["bl","dl","mtp","nor","nrr","su"],Oa[Pa.SESSION]=["cid","pr","sf","sid","st","v"],Oa[Pa.STATUS]=["bs","rtp"],Oa),Na=function t(e,r){this.value=void 0,this.params=void 0,Array.isArray(e)&&(e=e.map((function(e){return e instanceof t?e:new t(e)}))),this.value=e,this.params=r},Ua=function(t){this.description=void 0,this.description=t},Ba="Dict";var Ga="Bare Item",Ha="Boolean",Ka="Byte Sequence",Va="Decimal",ja="Integer",Ya=/[\x00-\x1f\x7f]+/,Wa="Token",qa="Key";function Xa(t,e,r){return function(t,e,r,i){return new Error("failed to "+t+' "'+(n=e,(Array.isArray(n)?JSON.stringify(n):n instanceof Map?"Map{}":n instanceof Set?"Set{}":"object"==typeof n?JSON.stringify(n):String(n))+'" as ')+r,{cause:i});var n}("serialize",t,e,r)}function za(t){if(function(t){return t<-999999999999999||99999999999999912)throw Xa(t,Va);var r=e.toString();return r.includes(".")?r:r+".0"}var $a="String";function Ja(t){var e,r=(e=t).description||e.toString().slice(7,-1);if(!1===/^([a-zA-Z*])([!#$%&'*+\-.^_`|~\w:/]*)$/.test(r))throw Xa(r,Wa);return r}function ts(t){switch(typeof t){case"number":if(!m(t))throw Xa(t,Ga);return Number.isInteger(t)?za(t):Za(t);case"string":return function(t){if(Ya.test(t))throw Xa(t,$a);return'"'+t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}(t);case"symbol":return Ja(t);case"boolean":return function(t){if("boolean"!=typeof t)throw Xa(t,Ha);return t?"?1":"?0"}(t);case"object":if(t instanceof Date)return function(t){return"@"+za(t.getTime()/1e3)}(t);if(t instanceof Uint8Array)return function(t){if(!1===ArrayBuffer.isView(t))throw Xa(t,Ka);return":"+(e=t,btoa(String.fromCharCode.apply(String,e))+":");var e}(t);if(t instanceof Ua)return Ja(t);default:throw Xa(t,Ga)}}function es(t){if(!1===/^[a-z*][a-z0-9\-_.*]*$/.test(t))throw Xa(t,qa);return t}function rs(t){return null==t?"":Object.entries(t).map((function(t){var e=t[0],r=t[1];return!0===r?";"+es(e):";"+es(e)+"="+ts(r)})).join("")}function is(t){return t instanceof Na?""+ts(t.value)+rs(t.params):ts(t)}var ns=function(t){return"ot"===t||"sf"===t||"st"===t},as=function(t){return"number"==typeof t?m(t):null!=t&&""!==t&&!1!==t},ss=function(t){return Math.round(t)},os=function(t){return 100*ss(t/100)},ls={br:ss,d:ss,bl:os,dl:os,mtp:os,nor:function(t,e){return null!=e&&e.baseUrl&&(t=function(t,e){var r=new URL(t),i=new URL(e);if(r.origin!==i.origin)return t;for(var n=r.pathname.split("/").slice(1),a=i.pathname.split("/").slice(1,-1);n[0]===a[0];)n.shift(),a.shift();for(;a.length;)a.shift(),n.unshift("..");return n.join("/")}(t,e.baseUrl)),encodeURIComponent(t)},rtp:os,tb:ss};function us(t,e){return void 0===e&&(e={}),t?function(t,e){return function(t,e){var r;if(void 0===e&&(e={whitespace:!0}),"object"!=typeof t)throw Xa(t,Ba);var i=t instanceof Map?t.entries():Object.entries(t),n=null!=(r=e)&&r.whitespace?" ":"";return Array.from(i).map((function(t){var e=t[0],r=t[1];r instanceof Na==0&&(r=new Na(r));var i,n=es(e);return!0===r.value?n+=rs(r.params):(n+="=",Array.isArray(r.value)?n+="("+(i=r).value.map(is).join(" ")+")"+rs(i.params):n+=is(r)),n})).join(","+n)}(t,e)}(function(t,e){var r={};if(null==t||"object"!=typeof t)return r;var i=Object.keys(t).sort(),n=o({},ls,null==e?void 0:e.formatters),a=null==e?void 0:e.filter;return i.forEach((function(i){if(null==a||!a(i)){var s=t[i],o=n[i];o&&(s=o(s,e)),"v"===i&&1===s||"pr"==i&&1===s||as(s)&&(ns(i)&&"string"==typeof s&&(s=new Ua(s)),r[i]=s)}})),r}(t,e),o({whitespace:!1},e)):""}var hs=/CMCD=[^&#]+/;var ds=function(){function t(t){var e=this;this.hls=void 0,this.config=void 0,this.media=void 0,this.sid=void 0,this.cid=void 0,this.useHeaders=!1,this.includeKeys=void 0,this.initialized=!1,this.starved=!1,this.buffering=!0,this.audioBuffer=void 0,this.videoBuffer=void 0,this.onWaiting=function(){e.initialized&&(e.starved=!0),e.buffering=!0},this.onPlaying=function(){e.initialized||(e.initialized=!0),e.buffering=!1},this.applyPlaylistData=function(t){try{e.apply(t,{ot:Ia.MANIFEST,su:!e.initialized})}catch(t){b.warn("Could not generate manifest CMCD data.",t)}},this.applyFragmentData=function(t){try{var r=t.frag,i=e.hls.levels[r.level],n=e.getObjectType(r),a={d:1e3*r.duration,ot:n};n!==Ia.VIDEO&&n!==Ia.AUDIO&&n!=Ia.MUXED||(a.br=i.bitrate/1e3,a.tb=e.getTopBandwidth(n)/1e3,a.bl=e.getBufferLength(n)),e.apply(t,a)}catch(t){b.warn("Could not generate segment CMCD data.",t)}},this.hls=t;var r=this.config=t.config,i=r.cmcd;null!=i&&(r.pLoader=this.createPlaylistLoader(),r.fLoader=this.createFragmentLoader(),this.sid=i.sessionId||function(){try{return crypto.randomUUID()}catch(i){try{var t=URL.createObjectURL(new Blob),e=t.toString();return URL.revokeObjectURL(t),e.slice(e.lastIndexOf("/")+1)}catch(t){var r=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=(r+16*Math.random())%16|0;return r=Math.floor(r/16),("x"==t?e:3&e|8).toString(16)}))}}}(),this.cid=i.contentId,this.useHeaders=!0===i.useHeaders,this.includeKeys=i.includeKeys,this.registerListeners())}var e=t.prototype;return e.registerListeners=function(){var t=this.hls;t.on(T.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(T.MEDIA_DETACHED,this.onMediaDetached,this),t.on(T.BUFFER_CREATED,this.onBufferCreated,this)},e.unregisterListeners=function(){var t=this.hls;t.off(T.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(T.MEDIA_DETACHED,this.onMediaDetached,this),t.off(T.BUFFER_CREATED,this.onBufferCreated,this)},e.destroy=function(){this.unregisterListeners(),this.onMediaDetached(),this.hls=this.config=this.audioBuffer=this.videoBuffer=null,this.onWaiting=this.onPlaying=null},e.onMediaAttached=function(t,e){this.media=e.media,this.media.addEventListener("waiting",this.onWaiting),this.media.addEventListener("playing",this.onPlaying)},e.onMediaDetached=function(){this.media&&(this.media.removeEventListener("waiting",this.onWaiting),this.media.removeEventListener("playing",this.onPlaying),this.media=null)},e.onBufferCreated=function(t,e){var r,i;this.audioBuffer=null==(r=e.tracks.audio)?void 0:r.buffer,this.videoBuffer=null==(i=e.tracks.video)?void 0:i.buffer},e.createData=function(){var t;return{v:1,sf:xa.HLS,sid:this.sid,cid:this.cid,pr:null==(t=this.media)?void 0:t.playbackRate,mtp:this.hls.bandwidthEstimate/1e3}},e.apply=function(t,e){void 0===e&&(e={}),o(e,this.createData());var r=e.ot===Ia.INIT||e.ot===Ia.VIDEO||e.ot===Ia.MUXED;this.starved&&r&&(e.bs=!0,e.su=!0,this.starved=!1),null==e.su&&(e.su=this.buffering);var i=this.includeKeys;i&&(e=Object.keys(e).reduce((function(t,r){return i.includes(r)&&(t[r]=e[r]),t}),{})),this.useHeaders?(t.headers||(t.headers={}),function(t,e,r){o(t,function(t,e){var r;if(void 0===e&&(e={}),!t)return{};var i=Object.entries(t),n=Object.entries(Fa).concat(Object.entries((null==(r=e)?void 0:r.customHeaderMap)||{})),a=i.reduce((function(t,e){var r,i=e[0],a=e[1],s=(null==(r=n.find((function(t){return t[1].includes(i)})))?void 0:r[0])||Pa.REQUEST;return null!=t[s]||(t[s]={}),t[s][i]=a,t}),{});return Object.entries(a).reduce((function(t,r){var i=r[0],n=r[1];return t[i]=us(n,e),t}),{})}(e,r))}(t.headers,e)):t.url=function(t,e,r){var i=function(t,e){if(void 0===e&&(e={}),!t)return"";var r=us(t,e);return"CMCD="+encodeURIComponent(r)}(e,r);if(!i)return t;if(hs.test(t))return t.replace(hs,i);var n=t.includes("?")?"&":"?";return""+t+n+i}(t.url,e)},e.getObjectType=function(t){var e=t.type;return"subtitle"===e?Ia.TIMED_TEXT:"initSegment"===t.sn?Ia.INIT:"audio"===e?Ia.AUDIO:"main"===e?this.hls.audioTracks.length?Ia.VIDEO:Ia.MUXED:void 0},e.getTopBandwidth=function(t){var e,r=0,i=this.hls;if(t===Ia.AUDIO)e=i.audioTracks;else{var n=i.maxAutoLevel,a=n>-1?n+1:i.levels.length;e=i.levels.slice(0,a)}for(var s,o=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return f(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(s=o()).done;){var l=s.value;l.bitrate>r&&(r=l.bitrate)}return r>0?r:NaN},e.getBufferLength=function(t){var e=this.hls.media,r=t===Ia.AUDIO?this.audioBuffer:this.videoBuffer;return r&&e?1e3*Pr.bufferInfo(r,e.currentTime,this.config.maxBufferHole).len:NaN},e.createPlaylistLoader=function(){var t=this.config.pLoader,e=this.applyPlaylistData,r=t||this.config.loader;return function(){function t(t){this.loader=void 0,this.loader=new r(t)}var i=t.prototype;return i.destroy=function(){this.loader.destroy()},i.abort=function(){this.loader.abort()},i.load=function(t,r,i){e(t),this.loader.load(t,r,i)},s(t,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),t}()},e.createFragmentLoader=function(){var t=this.config.fLoader,e=this.applyFragmentData,r=t||this.config.loader;return function(){function t(t){this.loader=void 0,this.loader=new r(t)}var i=t.prototype;return i.destroy=function(){this.loader.destroy()},i.abort=function(){this.loader.abort()},i.load=function(t,r,i){e(t),this.loader.load(t,r,i)},s(t,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),t}()},t}(),cs=function(){function t(t){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=t,this.log=b.log.bind(b,"[content-steering]:"),this.registerListeners()}var e=t.prototype;return e.registerListeners=function(){var t=this.hls;t.on(T.MANIFEST_LOADING,this.onManifestLoading,this),t.on(T.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(T.MANIFEST_PARSED,this.onManifestParsed,this),t.on(T.ERROR,this.onError,this)},e.unregisterListeners=function(){var t=this.hls;t&&(t.off(T.MANIFEST_LOADING,this.onManifestLoading,this),t.off(T.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(T.MANIFEST_PARSED,this.onManifestParsed,this),t.off(T.ERROR,this.onError,this))},e.startLoad=function(){if(this.started=!0,this.clearTimeout(),this.enabled&&this.uri){if(this.updated){var t=1e3*this.timeToLoad-(performance.now()-this.updated);if(t>0)return void this.scheduleRefresh(this.uri,t)}this.loadSteeringManifest(this.uri)}},e.stopLoad=function(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),this.clearTimeout()},e.clearTimeout=function(){-1!==this.reloadTimer&&(self.clearTimeout(this.reloadTimer),this.reloadTimer=-1)},e.destroy=function(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null},e.removeLevel=function(t){var e=this.levels;e&&(this.levels=e.filter((function(e){return e!==t})))},e.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},e.onManifestLoaded=function(t,e){var r=e.contentSteering;null!==r&&(this.pathwayId=r.pathwayId,this.uri=r.uri,this.started&&this.startLoad())},e.onManifestParsed=function(t,e){this.audioTracks=e.audioTracks,this.subtitleTracks=e.subtitleTracks},e.onError=function(t,e){var r=e.errorAction;if(2===(null==r?void 0:r.action)&&1===r.flags){var i=this.levels,n=this.pathwayPriority,a=this.pathwayId;if(e.context){var s=e.context,o=s.groupId,l=s.pathwayId,u=s.type;o&&i?a=this.getPathwayForGroupId(o,u,a):l&&(a=l)}a in this.penalizedPathways||(this.penalizedPathways[a]=performance.now()),!n&&i&&(n=i.reduce((function(t,e){return-1===t.indexOf(e.pathwayId)&&t.push(e.pathwayId),t}),[])),n&&n.length>1&&(this.updatePathwayPriority(n),r.resolved=this.pathwayId!==a),r.resolved||b.warn("Could not resolve "+e.details+' ("'+e.error.message+'") with content-steering for Pathway: '+a+" levels: "+(i?i.length:i)+" priorities: "+JSON.stringify(n)+" penalized: "+JSON.stringify(this.penalizedPathways))}},e.filterParsedLevels=function(t){this.levels=t;var e=this.getLevelsForPathway(this.pathwayId);if(0===e.length){var r=t[0].pathwayId;this.log("No levels found in Pathway "+this.pathwayId+'. Setting initial Pathway to "'+r+'"'),e=this.getLevelsForPathway(r),this.pathwayId=r}return e.length!==t.length?(this.log("Found "+e.length+"/"+t.length+' levels in Pathway "'+this.pathwayId+'"'),e):t},e.getLevelsForPathway=function(t){return null===this.levels?[]:this.levels.filter((function(e){return t===e.pathwayId}))},e.updatePathwayPriority=function(t){var e;this.pathwayPriority=t;var r=this.penalizedPathways,i=performance.now();Object.keys(r).forEach((function(t){i-r[t]>3e5&&delete r[t]}));for(var n=0;n0){this.log('Setting Pathway to "'+a+'"'),this.pathwayId=a,er(e),this.hls.trigger(T.LEVELS_UPDATED,{levels:e});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}}}},e.getPathwayForGroupId=function(t,e,r){for(var i=this.getLevelsForPathway(r).concat(this.levels||[]),n=0;n=2&&(0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start),n.timeout!==n.loadPolicy.maxLoadTimeMs&&(self.clearTimeout(this.requestTimeout),n.timeout=n.loadPolicy.maxLoadTimeMs,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),n.loadPolicy.maxLoadTimeMs-(r.loading.first-r.loading.start)))),4===i)){self.clearTimeout(this.requestTimeout),e.onreadystatechange=null,e.onprogress=null;var a=e.status,s="text"!==e.responseType;if(a>=200&&a<300&&(s&&e.response||null!==e.responseText)){r.loading.end=Math.max(self.performance.now(),r.loading.first);var o=s?e.response:e.responseText,l="arraybuffer"===e.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,t,o,e),!this.callbacks)return;var h={url:e.responseURL,data:o,code:a};this.callbacks.onSuccess(h,r,t,e)}else{var d=n.loadPolicy.errorRetry;sr(d,r.retry,!1,{url:t.url,data:void 0,code:a})?this.retry(d):(b.error(a+" while loading "+t.url),this.callbacks.onError({code:a,text:e.statusText},t,e,r))}}}},e.loadtimeout=function(){if(this.config){var t=this.config.loadPolicy.timeoutRetry;if(sr(t,this.stats.retry,!0))this.retry(t);else{var e;b.warn("timeout while loading "+(null==(e=this.context)?void 0:e.url));var r=this.callbacks;r&&(this.abortInternal(),r.onTimeout(this.stats,this.context,this.loader))}}},e.retry=function(t){var e=this.context,r=this.stats;this.retryDelay=nr(t,r.retry),r.retry++,b.warn((status?"HTTP Status "+status:"Timeout")+" while loading "+(null==e?void 0:e.url)+", retrying "+r.retry+"/"+t.maxNumRetry+" in "+this.retryDelay+"ms"),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay)},e.loadprogress=function(t){var e=this.stats;e.loaded=t.loaded,t.lengthComputable&&(e.total=t.total)},e.getCacheAge=function(){var t=null;if(this.loader&&vs.test(this.loader.getAllResponseHeaders())){var e=this.loader.getResponseHeader("age");t=e?parseFloat(e):null}return t},e.getResponseHeader=function(t){return this.loader&&new RegExp("^"+t+":\\s*[\\d.]+\\s*$","im").test(this.loader.getAllResponseHeaders())?this.loader.getResponseHeader(t):null},t}(),ps=/(\d+)-(\d+)\/(\d+)/,ys=function(){function t(t){this.fetchSetup=void 0,this.requestTimeout=void 0,this.request=null,this.response=null,this.controller=void 0,this.context=null,this.config=null,this.callbacks=null,this.stats=void 0,this.loader=null,this.fetchSetup=t.fetchSetup||Ts,this.controller=new self.AbortController,this.stats=new x}var e=t.prototype;return e.destroy=function(){this.loader=this.callbacks=this.context=this.config=this.request=null,this.abortInternal(),this.response=null,this.fetchSetup=this.controller=this.stats=null},e.abortInternal=function(){this.controller&&!this.stats.loading.end&&(this.stats.aborted=!0,this.controller.abort())},e.abort=function(){var t;this.abortInternal(),null!=(t=this.callbacks)&&t.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.response)},e.load=function(t,e,r){var i=this,n=this.stats;if(n.loading.start)throw new Error("Loader can only be used once.");n.loading.start=self.performance.now();var a=function(t,e){var r={method:"GET",mode:"cors",credentials:"same-origin",signal:e,headers:new self.Headers(o({},t.headers))};return t.rangeEnd&&r.headers.set("Range","bytes="+t.rangeStart+"-"+String(t.rangeEnd-1)),r}(t,this.controller.signal),s=r.onProgress,l="arraybuffer"===t.responseType,u=l?"byteLength":"length",h=e.loadPolicy,d=h.maxTimeToFirstByteMs,c=h.maxLoadTimeMs;this.context=t,this.config=e,this.callbacks=r,this.request=this.fetchSetup(t,a),self.clearTimeout(this.requestTimeout),e.timeout=d&&m(d)?d:c,this.requestTimeout=self.setTimeout((function(){i.abortInternal(),r.onTimeout(n,t,i.response)}),e.timeout),self.fetch(this.request).then((function(a){i.response=i.loader=a;var o=Math.max(self.performance.now(),n.loading.start);if(self.clearTimeout(i.requestTimeout),e.timeout=c,i.requestTimeout=self.setTimeout((function(){i.abortInternal(),r.onTimeout(n,t,i.response)}),c-(o-n.loading.start)),!a.ok){var u=a.status,h=a.statusText;throw new Ss(h||"fetch, bad network response",u,a)}return n.loading.first=o,n.total=function(t){var e=t.get("Content-Range");if(e){var r=function(t){var e=ps.exec(t);if(e)return parseInt(e[2])-parseInt(e[1])+1}(e);if(m(r))return r}var i=t.get("Content-Length");if(i)return parseInt(i)}(a.headers)||n.total,s&&m(e.highWaterMark)?i.loadProgressively(a,n,t,e.highWaterMark,s):l?a.arrayBuffer():"json"===t.responseType?a.json():a.text()})).then((function(a){var o=i.response;if(!o)throw new Error("loader destroyed");self.clearTimeout(i.requestTimeout),n.loading.end=Math.max(self.performance.now(),n.loading.first);var l=a[u];l&&(n.loaded=n.total=l);var h={url:o.url,data:a,code:o.status};s&&!m(e.highWaterMark)&&s(n,t,a,o),r.onSuccess(h,n,t,o)})).catch((function(e){if(self.clearTimeout(i.requestTimeout),!n.aborted){var a=e&&e.code||0,s=e?e.message:null;r.onError({code:a,text:s},t,e?e.details:null,n)}}))},e.getCacheAge=function(){var t=null;if(this.response){var e=this.response.headers.get("age");t=e?parseFloat(e):null}return t},e.getResponseHeader=function(t){return this.response?this.response.headers.get(t):null},e.loadProgressively=function(t,e,r,i,n){void 0===i&&(i=0);var a=new oi,s=t.body.getReader();return function o(){return s.read().then((function(s){if(s.done)return a.dataLength&&n(e,r,a.flush(),t),Promise.resolve(new ArrayBuffer(0));var l=s.value,u=l.length;return e.loaded+=u,u=i&&n(e,r,a.flush(),t)):n(e,r,l,t),o()})).catch((function(){return Promise.reject()}))}()},t}();function Ts(t,e){return new self.Request(t.url,e)}var Es,Ss=function(t){function e(e,r,i){var n;return(n=t.call(this,e)||this).code=void 0,n.details=void 0,n.code=r,n.details=i,n}return l(e,t),e}(c(Error)),Ls=/\s/,Rs=e(e({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:ms,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:Rr,bufferController:xn,capLevelController:Da,errorController:dr,fpsController:_a,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:J,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0,useMediaCapabilities:!0,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},{cueHandler:{newCue:function(t,e,r,i){for(var n,a,s,o,l,u=[],h=self.VTTCue||self.TextTrackCue,d=0;d=16?o--:o++;var g=oa(l.trim()),v=ca(e,r,g);null!=t&&null!=(c=t.cues)&&c.getCueById(v)||((a=new h(e,r,g)).id=v,a.line=d+1,a.align="left",a.position=10+Math.min(80,10*Math.floor(8*o/32)),u.push(a))}return t&&u.length&&(u.sort((function(t,e){return"auto"===t.line||"auto"===e.line?0:t.line>8&&e.line>8?e.line-t.line:t.line-e.line})),u.forEach((function(e){return we(t,e)}))),u}},enableWebVTT:!0,enableIMSC1:!0,enableCEA708Captions:!0,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}),{},{subtitleStreamController:Dn,subtitleTrackController:Cn,timelineController:ka,audioStreamController:An,audioTrackController:bn,emeController:wa,cmcdController:ds,contentSteeringController:cs});function ks(t){return t&&"object"==typeof t?Array.isArray(t)?t.map(ks):Object.keys(t).reduce((function(e,r){return e[r]=ks(t[r]),e}),{}):t}var As=function(t){function e(e,r){var i;return(i=t.call(this,e,"[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}l(e,t);var r=e.prototype;return r._registerListeners=function(){var t=this.hls;t.on(T.MANIFEST_LOADING,this.onManifestLoading,this),t.on(T.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(T.LEVEL_LOADED,this.onLevelLoaded,this),t.on(T.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(T.FRAG_BUFFERED,this.onFragBuffered,this),t.on(T.ERROR,this.onError,this)},r._unregisterListeners=function(){var t=this.hls;t.off(T.MANIFEST_LOADING,this.onManifestLoading,this),t.off(T.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(T.LEVEL_LOADED,this.onLevelLoaded,this),t.off(T.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(T.FRAG_BUFFERED,this.onFragBuffered,this),t.off(T.ERROR,this.onError,this)},r.destroy=function(){this._unregisterListeners(),this.steering=null,this.resetLevels(),t.prototype.destroy.call(this)},r.stopLoad=function(){this._levels.forEach((function(t){t.loadError=0,t.fragmentError=0})),t.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(t,e){this.resetLevels()},r.onManifestLoaded=function(t,e){var r=this.hls.config.preferManagedMediaSource,i=[],n={},a={},s=!1,o=!1,l=!1;e.levels.forEach((function(t){var e,u,h=t.attrs,d=t.audioCodec,c=t.videoCodec;-1!==(null==(e=d)?void 0:e.indexOf("mp4a.40.34"))&&(Es||(Es=/chrome|firefox/i.test(navigator.userAgent)),Es&&(t.audioCodec=d=void 0)),d&&(t.audioCodec=d=ne(d,r)),0===(null==(u=c)?void 0:u.indexOf("avc1"))&&(c=t.videoCodec=function(t){for(var e=t.split(","),r=0;r2){var n=i.shift()+".";n+=parseInt(i.shift()).toString(16),n+=("000"+parseInt(i.shift()).toString(16)).slice(-4),e[r]=n}}return e.join(",")}(c));var f=t.width,g=t.height,v=t.unknownCodecs;if(s||(s=!(!f||!g)),o||(o=!!c),l||(l=!!d),!(null!=v&&v.length||d&&!Zt(d,"audio",r)||c&&!Zt(c,"video",r))){var m=h.CODECS,p=h["FRAME-RATE"],y=h["HDCP-LEVEL"],T=h["PATHWAY-ID"],E=h.RESOLUTION,S=h["VIDEO-RANGE"],L=(T||".")+"-"+t.bitrate+"-"+E+"-"+p+"-"+m+"-"+S+"-"+y;if(n[L])if(n[L].uri===t.url||t.attrs["PATHWAY-ID"])n[L].addGroupId("audio",h.AUDIO),n[L].addGroupId("text",h.SUBTITLES);else{var R=a[L]+=1;t.attrs["PATHWAY-ID"]=new Array(R+1).join(".");var k=new We(t);n[L]=k,i.push(k)}else{var A=new We(t);n[L]=A,a[L]=1,i.push(A)}}})),this.filterAndSortMediaOptions(i,e,s,o,l)},r.filterAndSortMediaOptions=function(t,e,r,i,n){var a=this,s=[],o=[],l=t;if((r||i)&&n&&(l=l.filter((function(t){var e,r=t.videoCodec,i=t.videoRange,n=t.width,a=t.height;return(!!r||!(!n||!a))&&!!(e=i)&&Ve.indexOf(e)>-1}))),0!==l.length){if(e.audioTracks){var u=this.hls.config.preferManagedMediaSource;bs(s=e.audioTracks.filter((function(t){return!t.audioCodec||Zt(t.audioCodec,"audio",u)})))}e.subtitles&&bs(o=e.subtitles);var h=l.slice(0);l.sort((function(t,e){if(t.attrs["HDCP-LEVEL"]!==e.attrs["HDCP-LEVEL"])return(t.attrs["HDCP-LEVEL"]||"")>(e.attrs["HDCP-LEVEL"]||"")?1:-1;if(r&&t.height!==e.height)return t.height-e.height;if(t.frameRate!==e.frameRate)return t.frameRate-e.frameRate;if(t.videoRange!==e.videoRange)return Ve.indexOf(t.videoRange)-Ve.indexOf(e.videoRange);if(t.videoCodec!==e.videoCodec){var i=te(t.videoCodec),n=te(e.videoCodec);if(i!==n)return n-i}if(t.uri===e.uri&&t.codecSet!==e.codecSet){var a=ee(t.codecSet),s=ee(e.codecSet);if(a!==s)return s-a}return t.averageBitrate!==e.averageBitrate?t.averageBitrate-e.averageBitrate:0}));var d=h[0];if(this.steering&&(l=this.steering.filterParsedLevels(l)).length!==h.length)for(var c=0;cm&&m===Rs.abrEwmaDefaultEstimate&&(this.hls.bandwidthEstimate=p)}break}var y=n&&!i,L={levels:l,audioTracks:s,subtitleTracks:o,sessionData:e.sessionData,sessionKeys:e.sessionKeys,firstLevel:this._firstLevel,stats:e.stats,audio:n,video:i,altAudio:!y&&s.some((function(t){return!!t.url}))};this.hls.trigger(T.MANIFEST_PARSED,L),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}else Promise.resolve().then((function(){if(a.hls){e.levels.length&&a.warn("One or more CODECS in variant not supported: "+JSON.stringify(e.levels[0].attrs));var t=new Error("no level with compatible codecs found in manifest");a.hls.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:e.url,error:t,reason:t.message})}}))},r.onError=function(t,e){!e.fatal&&e.context&&e.context.type===Ee&&e.context.level===this.level&&this.checkRetry(e)},r.onFragBuffered=function(t,e){var r=e.frag;if(void 0!==r&&r.type===Re){var i=r.elementaryStreams;if(!Object.keys(i).some((function(t){return!!i[t]})))return;var n=this._levels[r.level];null!=n&&n.loadError&&(this.log("Resetting level error count of "+n.loadError+" on frag buffered"),n.loadError=0)}},r.onLevelLoaded=function(t,e){var r,i,n=e.level,a=e.details,s=this._levels[n];if(!s)return this.warn("Invalid level index "+n),void(null!=(i=e.deliveryDirectives)&&i.skip&&(a.deltaUpdateFailed=!0));n===this.currentLevelIndex?(0===s.fragmentError&&(s.loadError=0),this.playlistLoaded(n,e,s.details)):null!=(r=e.deliveryDirectives)&&r.skip&&(a.deltaUpdateFailed=!0)},r.loadPlaylist=function(e){t.prototype.loadPlaylist.call(this);var r=this.currentLevelIndex,i=this.currentLevel;if(i&&this.shouldLoadPlaylist(i)){var n=i.uri;if(e)try{n=e.addDirectives(n)}catch(t){this.warn("Could not construct new URL with HLS Delivery Directives: "+t)}var a=i.attrs["PATHWAY-ID"];this.log("Loading level index "+r+(void 0!==(null==e?void 0:e.msn)?" at sn "+e.msn+" part "+e.part:"")+" with"+(a?" Pathway "+a:"")+" "+n),this.clearTimer(),this.hls.trigger(T.LEVEL_LOADING,{url:n,level:r,pathwayId:i.attrs["PATHWAY-ID"],id:0,deliveryDirectives:e||null})}},r.removeLevel=function(t){var e,r=this,i=this._levels.filter((function(e,i){return i!==t||(r.steering&&r.steering.removeLevel(e),e===r.currentLevel&&(r.currentLevel=null,r.currentLevelIndex=-1,e.details&&e.details.fragments.forEach((function(t){return t.level=-1}))),!1)}));er(i),this._levels=i,this.currentLevelIndex>-1&&null!=(e=this.currentLevel)&&e.details&&(this.currentLevelIndex=this.currentLevel.details.fragments[0].level),this.hls.trigger(T.LEVELS_UPDATED,{levels:i})},r.onLevelsUpdated=function(t,e){var r=e.levels;this._levels=r},r.checkMaxAutoUpdated=function(){var t=this.hls,e=t.autoLevelCapping,r=t.maxAutoLevel,i=t.maxHdcpLevel;this._maxAutoLevel!==r&&(this._maxAutoLevel=r,this.hls.trigger(T.MAX_AUTO_LEVEL_UPDATED,{autoLevelCapping:e,levels:this.levels,maxAutoLevel:r,minAutoLevel:this.hls.minAutoLevel,maxHdcpLevel:i}))},s(e,[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(t){var e=this._levels;if(0!==e.length){if(t<0||t>=e.length){var r=new Error("invalid level idx"),i=t<0;if(this.hls.trigger(T.ERROR,{type:E.OTHER_ERROR,details:S.LEVEL_SWITCH_ERROR,level:t,fatal:i,error:r,reason:r.message}),i)return;t=Math.min(t,e.length-1)}var n=this.currentLevelIndex,a=this.currentLevel,s=a?a.attrs["PATHWAY-ID"]:void 0,o=e[t],l=o.attrs["PATHWAY-ID"];if(this.currentLevelIndex=t,this.currentLevel=o,n!==t||!o.details||!a||s!==l){this.log("Switching to level "+t+" ("+(o.height?o.height+"p ":"")+(o.videoRange?o.videoRange+" ":"")+(o.codecSet?o.codecSet+" ":"")+"@"+o.bitrate+")"+(l?" with Pathway "+l:"")+" from level "+n+(s?" with Pathway "+s:""));var u={level:t,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(T.LEVEL_SWITCHING,u);var h=o.details;if(!h||h.live){var d=this.switchParams(o.uri,null==a?void 0:a.details,h);this.loadPlaylist(d)}}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(t){this.manualLevelIndex=t,void 0===this._startLevel&&(this._startLevel=t),-1!==t&&(this.level=t)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(t){this._firstLevel=t}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var t=this.hls.config.startLevel;return void 0!==t?t:this.hls.firstAutoLevel}return this._startLevel},set:function(t){this._startLevel=t}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(t){this.level=t,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=t)}}]),e}(cr);function bs(t){var e={};t.forEach((function(t){var r=t.groupId||"";t.id=e[r]=e[r]||0,e[r]++}))}var Ds=function(){function t(t){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=t}var r=t.prototype;return r.abort=function(t){for(var e in this.keyUriToKeyInfo){var r=this.keyUriToKeyInfo[e].loader;if(r){var i;if(t&&t!==(null==(i=r.context)?void 0:i.frag.type))return;r.abort()}}},r.detach=function(){for(var t in this.keyUriToKeyInfo){var e=this.keyUriToKeyInfo[t];(e.mediaKeySessionContext||e.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[t]}},r.destroy=function(){for(var t in this.detach(),this.keyUriToKeyInfo){var e=this.keyUriToKeyInfo[t].loader;e&&e.destroy()}this.keyUriToKeyInfo={}},r.createKeyLoadError=function(t,e,r,i,n){return void 0===e&&(e=S.KEY_LOAD_ERROR),new Vr({type:E.NETWORK_ERROR,details:e,fatal:!1,frag:t,response:n,error:r,networkDetails:i})},r.loadClear=function(t,e){var r=this;if(this.emeController&&this.config.emeEnabled)for(var i=t.sn,n=t.cc,a=function(){var t=e[s];if(n<=t.cc&&("initSegment"===i||"initSegment"===t.sn||i2,c=!h||e&&e.start<=a||h-a>2&&!this.fragmentTracker.getPartialFragment(a);if(d||c)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var f;if(!(u.len>0||h))return;var g=Math.max(h,u.start||0)-a,v=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,m=(null==v||null==(f=v.details)?void 0:f.live)?2*v.details.targetduration:2,p=this.fragmentTracker.getPartialFragment(a);if(g>0&&(g<=m||p))return void(i.paused||this._trySkipBufferHole(p))}var y=self.performance.now();if(null!==n){var T=y-n;if(s||!(T>=250)||(this._reportStall(u),this.media)){var E=Pr.bufferInfo(i,a,r.maxBufferHole);this._tryFixBufferStall(E,T)}}else this.stalled=y}else if(this.moved=!0,s||(this.nudgeRetry=0),null!==n){if(this.stallReported){var S=self.performance.now()-n;b.warn("playback not stuck anymore @"+a+", after "+Math.round(S)+"ms"),this.stallReported=!1}this.stalled=null}}},e._tryFixBufferStall=function(t,e){var r=this.config,i=this.fragmentTracker,n=this.media;if(null!==n){var a=n.currentTime,s=i.getPartialFragment(a);if(s&&(this._trySkipBufferHole(s)||!this.media))return;(t.len>r.maxBufferHole||t.nextStart&&t.nextStart-a1e3*r.highBufferWatchdogPeriod&&(b.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}},e._reportStall=function(t){var e=this.hls,r=this.media;if(!this.stallReported&&r){this.stallReported=!0;var i=new Error("Playback stalling at @"+r.currentTime+" due to low buffer ("+JSON.stringify(t)+")");b.warn(i.message),e.trigger(T.ERROR,{type:E.MEDIA_ERROR,details:S.BUFFER_STALLED_ERROR,fatal:!1,error:i,buffer:t.len})}},e._trySkipBufferHole=function(t){var e=this.config,r=this.hls,i=this.media;if(null===i)return 0;var n=i.currentTime,a=Pr.bufferInfo(i,n,0),s=n0&&a.len<1&&i.readyState<3,u=s-n;if(u>0&&(o||l)){if(u>e.maxBufferHole){var h=this.fragmentTracker,d=!1;if(0===n){var c=h.getAppendedFrag(0,Re);c&&s1?(i=0,this.bitrateTest=!0):i=r.firstAutoLevel),r.nextLoadLevel=i,this.level=r.loadLevel,this.loadedmetadata=!1}e>0&&-1===t&&(this.log("Override startPosition with lastCurrentTime @"+e.toFixed(3)),t=e),this.state=zr,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}else this._forceStartLoad=!0,this.state=Xr},r.stopLoad=function(){this._forceStartLoad=!1,t.prototype.stopLoad.call(this)},r.doTick=function(){switch(this.state){case ai:var t=this.levels,e=this.level,r=null==t?void 0:t[e],i=null==r?void 0:r.details;if(i&&(!i.live||this.levelLastLoaded===r)){if(this.waitForCdnTuneIn(i))break;this.state=zr;break}if(this.hls.nextLoadLevel!==this.level){this.state=zr;break}break;case $r:var n,a=self.performance.now(),s=this.retryDate;if(!s||a>=s||null!=(n=this.media)&&n.seeking){var o=this.levels,l=this.level,u=null==o?void 0:o[l];this.resetStartWhenNotLoaded(u||null),this.state=zr}}this.state===zr&&this.doTickIdle(),this.onTickEnd()},r.onTickEnd=function(){t.prototype.onTickEnd.call(this),this.checkBuffer(),this.checkFragmentChanged()},r.doTickIdle=function(){var t=this.hls,e=this.levelLastLoaded,r=this.levels,i=this.media;if(null!==e&&(i||!this.startFragRequested&&t.config.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)){var n=t.nextLoadLevel;if(null!=r&&r[n]){var a=r[n],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(T.BUFFER_EOS,l),void(this.state=ri)}t.loadLevel!==n&&-1===t.manualLevel&&this.log("Adapting to level "+n+" from level "+this.level),this.level=t.nextLoadLevel=n;var u=a.details;if(!u||this.state===ai||u.live&&this.levelLastLoaded!==a)return this.level=n,void(this.state=ai);var h=s.len,d=this.getMaxBufferLength(a.maxBitrate);if(!(h>=d)){this.backtrackFragment&&this.backtrackFragment.start>s.end&&(this.backtrackFragment=null);var c=this.backtrackFragment?this.backtrackFragment.start:s.end,f=this.getNextFragment(c,u);if(this.couldBacktrack&&!this.fragPrevious&&f&&"initSegment"!==f.sn&&this.fragmentTracker.getState(f)!==_r){var g,v=(null!=(g=this.backtrackFragment)?g:f).sn-u.startSN,m=u.fragments[v-1];m&&f.cc===m.cc&&(f=m,this.fragmentTracker.removeFragment(m))}else this.backtrackFragment&&s.len&&(this.backtrackFragment=null);if(f&&this.isLoopLoading(f,c)){if(!f.gap){var p=this.audioOnly&&!this.altAudio?P:O,y=(p===O?this.videoBuffer:this.mediaBuffer)||this.media;y&&this.afterBufferFlushed(y,p,Re)}f=this.getNextFragmentLoopLoading(f,u,s,Re,d)}f&&(!f.initSegment||f.initSegment.data||this.bitrateTest||(f=f.initSegment),this.loadFragment(f,a,c))}}}}},r.loadFragment=function(e,r,i){var n=this.fragmentTracker.getState(e);this.fragCurrent=e,n===Ar||n===Dr?"initSegment"===e.sn?this._loadInitSegment(e,r):this.bitrateTest?(this.log("Fragment "+e.sn+" of level "+e.level+" is being downloaded to test bitrate and will not be buffered"),this._loadBitrateTestFrag(e,r)):(this.startFragRequested=!0,t.prototype.loadFragment.call(this,e,r,i)):this.clearTrackerIfNeeded(e)},r.getBufferedFrag=function(t){return this.fragmentTracker.getBufferedFrag(t,Re)},r.followingBufferedFrag=function(t){return t?this.getBufferedFrag(t.end+.5):null},r.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},r.nextLevelSwitch=function(){var t=this.levels,e=this.media;if(null!=e&&e.readyState){var r,i=this.getAppendedFrag(e.currentTime);i&&i.start>1&&this.flushMainBuffer(0,i.start-1);var n=this.getLevelDetails();if(null!=n&&n.live){var a=this.getMainFwdBufferInfo();if(!a||a.len<2*n.targetduration)return}if(!e.paused&&t){var s=t[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(e.currentTime+r);if(l){var u=this.followingBufferedFrag(l);if(u){this.abortCurrentFrag();var h=u.maxStartPTS?u.maxStartPTS:u.start,d=u.duration,c=Math.max(l.end,h+Math.min(Math.max(d-this.config.maxFragLookUpTolerance,d*(this.couldBacktrack?.5:.125)),d*(this.couldBacktrack?.75:.25)));this.flushMainBuffer(c,Number.POSITIVE_INFINITY)}}}},r.abortCurrentFrag=function(){var t=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,t&&(t.abortRequests(),this.fragmentTracker.removeFragment(t)),this.state){case Qr:case Zr:case $r:case ti:case ei:this.state=zr}this.nextLoadPosition=this.getLoadPosition()},r.flushMainBuffer=function(e,r){t.prototype.flushMainBuffer.call(this,e,r,this.altAudio?"video":null)},r.onMediaAttached=function(e,r){t.prototype.onMediaAttached.call(this,e,r);var i=r.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),i.addEventListener("playing",this.onvplaying),i.addEventListener("seeked",this.onvseeked),this.gapController=new ws(this.config,i,this.fragmentTracker,this.hls)},r.onMediaDetaching=function(){var e=this.media;e&&this.onvplaying&&this.onvseeked&&(e.removeEventListener("playing",this.onvplaying),e.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),t.prototype.onMediaDetaching.call(this)},r.onMediaPlaying=function(){this.tick()},r.onMediaSeeked=function(){var t=this.media,e=t?t.currentTime:null;m(e)&&this.log("Media seeked to "+e.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(T.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(t,e){var r,i,n=!1,a=!1;e.levels.forEach((function(t){var e=t.audioCodec;e&&(n=n||-1!==e.indexOf("mp4a.40.2"),a=a||-1!==e.indexOf("mp4a.40.5"))})),this.audioCodecSwitch=n&&a&&!("function"==typeof(null==(i=_s())||null==(r=i.prototype)?void 0:r.changeType)),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=e.levels,this.startFragRequested=!1},r.onLevelLoading=function(t,e){var r=this.levels;if(r&&this.state===zr){var i=r[e.level];(!i.details||i.details.live&&this.levelLastLoaded!==i||this.waitForCdnTuneIn(i.details))&&(this.state=ai)}},r.onLevelLoaded=function(t,e){var r,i=this.levels,n=e.level,a=e.details,s=a.totalduration;if(i){this.log("Level "+n+" loaded ["+a.startSN+","+a.endSN+"]"+(a.lastPartSn?"[part-"+a.lastPartSn+"-"+a.lastPartIndex+"]":"")+", cc ["+a.startCC+", "+a.endCC+"] duration:"+s);var o=i[n],l=this.fragCurrent;!l||this.state!==Zr&&this.state!==$r||l.level!==e.level&&l.loader&&this.abortCurrentFrag();var u=0;if(a.live||null!=(r=o.details)&&r.live){var h;if(this.checkLiveUpdate(a),a.deltaUpdateFailed)return;u=this.alignPlaylists(a,o.details,null==(h=this.levelLastLoaded)?void 0:h.details)}if(o.details=a,this.levelLastLoaded=o,this.hls.trigger(T.LEVEL_UPDATED,{details:a,level:n}),this.state===ai){if(this.waitForCdnTuneIn(a))return;this.state=zr}this.startFragRequested?a.live&&this.synchronizeToLiveEdge(a):this.setStartPosition(a,u),this.tick()}else this.warn("Levels were reset while loading level "+n)},r._handleFragmentLoadProgress=function(t){var e,r=t.frag,i=t.part,n=t.payload,a=this.levels;if(a){var s=a[r.level],o=s.details;if(!o)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,h=null==(e=r.initSegment)?void 0:e.data,d=this._getAudioCodec(s),c=this.transmuxer=this.transmuxer||new Sn(this.hls,Re,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),f=i?i.index:-1,g=-1!==f,v=new Or(r.level,r.sn,r.stats.chunkCount,n.byteLength,f,g),m=this.initPTS[r.cc];c.push(n,h,d,l,r,i,o.totalduration,u,v,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(t,e){var r=this.altAudio;if(!e.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 n=this.hls;r&&(n.trigger(T.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:null}),this.fragmentTracker.removeAllFragments()),n.trigger(T.AUDIO_TRACK_SWITCHED,e)}},r.onAudioTrackSwitched=function(t,e){var r=e.id,i=!!this.hls.audioTracks[r].url;if(i){var n=this.videoBuffer;n&&this.mediaBuffer!==n&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=n)}this.altAudio=i,this.tick()},r.onBufferCreated=function(t,e){var r,i,n=e.tracks,a=!1;for(var s in n){var o=n[s];if("main"===o.id){if(i=s,r=o,"video"===s){var l=n[s];l&&(this.videoBuffer=l.buffer)}}else a=!0}a&&r?(this.log("Alternate track found, use "+i+".buffered to schedule main fragment loading"),this.mediaBuffer=r.buffer):this.mediaBuffer=this.media},r.onFragBuffered=function(t,e){var r=e.frag,i=e.part;if(!r||r.type===Re){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===ei&&(this.state=zr));var n=i?i.stats:r.stats;this.fragLastKbps=Math.round(8*n.total/(n.buffering.end-n.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,i)}},r.onError=function(t,e){var r;if(e.fatal)this.state=ii;else switch(e.details){case S.FRAG_GAP:case S.FRAG_PARSING_ERROR:case S.FRAG_DECRYPT_ERROR:case S.FRAG_LOAD_ERROR:case S.FRAG_LOAD_TIMEOUT:case S.KEY_LOAD_ERROR:case S.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(Re,e);break;case S.LEVEL_LOAD_ERROR:case S.LEVEL_LOAD_TIMEOUT:case S.LEVEL_PARSING_ERROR:e.levelRetry||this.state!==ai||(null==(r=e.context)?void 0:r.type)!==Ee||(this.state=zr);break;case S.BUFFER_APPEND_ERROR:case S.BUFFER_FULL_ERROR:if(!e.parent||"main"!==e.parent)return;if(e.details===S.BUFFER_APPEND_ERROR)return void this.resetLoadingState();this.reduceLengthAndFlushBuffer(e)&&this.flushMainBuffer(0,Number.POSITIVE_INFINITY);break;case S.INTERNAL_EXCEPTION:this.recoverWorkerError(e)}},r.checkBuffer=function(){var t=this.media,e=this.gapController;if(t&&e&&t.readyState){if(this.loadedmetadata||!Pr.getBuffered(t).length){var r=this.state!==zr?this.fragCurrent:null;e.poll(this.lastCurrentTime,r)}this.lastCurrentTime=t.currentTime}},r.onFragLoadEmergencyAborted=function(){this.state=zr,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()},r.onBufferFlushed=function(t,e){var r=e.type;if(r!==P||this.audioOnly&&!this.altAudio){var i=(r===O?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(i,r,Re),this.tick()}},r.onLevelsUpdated=function(t,e){this.level>-1&&this.fragCurrent&&(this.level=this.fragCurrent.level),this.levels=e.levels},r.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},r.seekToStartPos=function(){var t=this.media;if(t){var e=t.currentTime,r=this.startPosition;if(r>=0&&e0&&(nS.cc;if(!1!==n.independent){var k=h.startPTS,A=h.endPTS,b=h.startDTS,D=h.endDTS;if(l)l.elementaryStreams[h.type]={startPTS:k,endPTS:A,startDTS:b,endDTS:D};else if(h.firstKeyFrame&&h.independent&&1===a.id&&!R&&(this.couldBacktrack=!0),h.dropped&&h.independent){var _=this.getMainFwdBufferInfo(),C=(_?_.end:this.getLoadPosition())+this.config.maxBufferHole,w=h.firstKeyFramePTS?h.firstKeyFramePTS:k;if(!L&&C2&&(o.gap=!0);o.setElementaryStreamInfo(h.type,k,A,b,D),this.backtrackFragment&&(this.backtrackFragment=o),this.bufferFragmentData(h,o,l,a,L||R)}else{if(!L&&!R)return void this.backtrack(o);o.gap=!0}}if(v){var I=v.startPTS,x=v.endPTS,O=v.startDTS,M=v.endDTS;l&&(l.elementaryStreams[P]={startPTS:I,endPTS:x,startDTS:O,endDTS:M}),o.setElementaryStreamInfo(P,I,x,O,M),this.bufferFragmentData(v,o,l,a)}if(g&&null!=c&&null!=(e=c.samples)&&e.length){var F={id:r,frag:o,details:g,samples:c.samples};i.trigger(T.FRAG_PARSING_METADATA,F)}if(g&&d){var N={id:r,frag:o,details:g,samples:d.samples};i.trigger(T.FRAG_PARSING_USERDATA,N)}}}else this.resetWhenMissingContext(a)},r._bufferInitSegment=function(t,e,r,i){var n=this;if(this.state===ti){this.audioOnly=!!e.audio&&!e.video,this.altAudio&&!this.audioOnly&&delete e.audio;var a=e.audio,s=e.video,o=e.audiovideo;if(a){var l=t.audioCodec,u=navigator.userAgent.toLowerCase();if(this.audioCodecSwitch){l&&(l=-1!==l.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5");var h=a.metadata;h&&"channelCount"in h&&1!==(h.channelCount||1)&&-1===u.indexOf("firefox")&&(l="mp4a.40.5")}l&&-1!==l.indexOf("mp4a.40.5")&&-1!==u.indexOf("android")&&"audio/mpeg"!==a.container&&(l="mp4a.40.2",this.log("Android: force audio codec to "+l)),t.audioCodec&&t.audioCodec!==l&&this.log('Swapping manifest audio codec "'+t.audioCodec+'" for "'+l+'"'),a.levelCodec=l,a.id="main",this.log("Init audio buffer, container:"+a.container+", codecs[selected/level/parsed]=["+(l||"")+"/"+(t.audioCodec||"")+"/"+a.codec+"]")}s&&(s.levelCodec=t.videoCodec,s.id="main",this.log("Init video buffer, container:"+s.container+", codecs[level/parsed]=["+(t.videoCodec||"")+"/"+s.codec+"]")),o&&this.log("Init audiovideo buffer, container:"+o.container+", codecs[level/parsed]=["+t.codecs+"/"+o.codec+"]"),this.hls.trigger(T.BUFFER_CODECS,e),Object.keys(e).forEach((function(t){var a=e[t].initSegment;null!=a&&a.byteLength&&n.hls.trigger(T.BUFFER_APPENDING,{type:t,data:a,frag:r,part:null,chunkMeta:i,parent:r.type})})),this.tickImmediate()}},r.getMainFwdBufferInfo=function(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,Re)},r.backtrack=function(t){this.couldBacktrack=!0,this.backtrackFragment=t,this.resetTransmuxer(),this.flushBufferGap(t),this.fragmentTracker.removeFragment(t),this.fragPrevious=null,this.nextLoadPosition=t.start,this.state=zr},r.checkFragmentChanged=function(){var t=this.media,e=null;if(t&&t.readyState>1&&!1===t.seeking){var r=t.currentTime;if(Pr.isBuffered(t,r)?e=this.getAppendedFrag(r):Pr.isBuffered(t,r+.1)&&(e=this.getAppendedFrag(r+.1)),e){this.backtrackFragment=null;var i=this.fragPlaying,n=e.level;i&&e.sn===i.sn&&i.level===n||(this.fragPlaying=e,this.hls.trigger(T.FRAG_CHANGED,{frag:e}),i&&i.level===n||this.hls.trigger(T.LEVEL_SWITCHED,{level:n}))}}},s(e,[{key:"nextLevel",get:function(){var t=this.nextBufferedFrag;return t?t.level:-1}},{key:"currentFrag",get:function(){var t=this.media;return t?this.fragPlaying||this.getAppendedFrag(t.currentTime):null}},{key:"currentProgramDateTime",get:function(){var t=this.media;if(t){var e=t.currentTime,r=this.currentFrag;if(r&&m(e)&&m(r.programDateTime)){var i=r.programDateTime+1e3*(e-r.start);return new Date(i)}}return null}},{key:"currentLevel",get:function(){var t=this.currentFrag;return t?t.level:-1}},{key:"nextBufferedFrag",get:function(){var t=this.currentFrag;return t?this.followingBufferedFrag(t):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}]),e}(si),xs=function(){function t(r){void 0===r&&(r={}),this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this.started=!1,this._emitter=new pn,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,A(r.debug||!1,"Hls instance");var i=this.config=function(t,r){if((r.liveSyncDurationCount||r.liveMaxLatencyDurationCount)&&(r.liveSyncDuration||r.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==r.liveMaxLatencyDurationCount&&(void 0===r.liveSyncDurationCount||r.liveMaxLatencyDurationCount<=r.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(void 0!==r.liveMaxLatencyDuration&&(void 0===r.liveSyncDuration||r.liveMaxLatencyDuration<=r.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');var i=ks(t),n=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];return["manifest","level","frag"].forEach((function(t){var e=("level"===t?"playlist":t)+"LoadPolicy",a=void 0===r[e],s=[];n.forEach((function(n){var o=t+"Loading"+n,l=r[o];if(void 0!==l&&a){s.push(o);var u=i[e].default;switch(r[e]={default:u},n){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&&b.warn('hls.js config: "'+s.join('", "')+'" setting(s) are deprecated, use "'+e+'": '+JSON.stringify(r[e]))})),e(e({},i),r)}(t.DefaultConfig,r);this.userConfig=r,i.progressive&&function(t){var e=t.loader;e!==ys&&e!==ms?(b.log("[config]: Custom loader detected, cannot enable progressive streaming"),t.progressive=!1):function(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch(t){}return!1}()&&(t.loader=ys,t.progressive=!0,t.enableSoftwareAES=!0,b.log("[config]: Progressive streaming enabled, using FetchLoader"))}(i);var n=i.abrController,a=i.bufferController,s=i.capLevelController,o=i.errorController,l=i.fpsController,u=new o(this),h=this.abrController=new n(this),d=this.bufferController=new a(this),c=this.capLevelController=new s(this),f=new l(this),g=new _e(this),v=new Ge(this),m=i.contentSteeringController,p=m?new m(this):null,y=this.levelController=new As(this,p),E=new Cr(this),S=new Ds(this.config),L=this.streamController=new Is(this,E,S);c.setStreamController(L),f.setStreamController(L);var R=[g,y,L];p&&R.splice(1,0,p),this.networkControllers=R;var k=[h,d,c,f,v,E];this.audioTrackController=this.createController(i.audioTrackController,R);var D=i.audioStreamController;D&&R.push(new D(this,E,S)),this.subtitleTrackController=this.createController(i.subtitleTrackController,R);var _=i.subtitleStreamController;_&&R.push(new _(this,E,S)),this.createController(i.timelineController,k),S.emeController=this.emeController=this.createController(i.emeController,k),this.cmcdController=this.createController(i.cmcdController,k),this.latencyController=this.createController(He,k),this.coreComponents=k,R.push(u);var C=u.onErrorOut;"function"==typeof C&&this.on(T.ERROR,C,u)}t.isMSESupported=function(){return Cs()},t.isSupported=function(){return function(){if(!Cs())return!1;var t=zt();return"function"==typeof(null==t?void 0:t.isTypeSupported)&&(["avc1.42E01E,mp4a.40.2","av01.0.01M.08","vp09.00.50.08"].some((function(e){return t.isTypeSupported(Jt(e,"video"))}))||["mp4a.40.2","fLaC"].some((function(e){return t.isTypeSupported(Jt(e,"audio"))})))}()},t.getMediaSource=function(){return zt()};var r=t.prototype;return r.createController=function(t,e){if(t){var r=new t(this);return e&&e.push(r),r}return null},r.on=function(t,e,r){void 0===r&&(r=this),this._emitter.on(t,e,r)},r.once=function(t,e,r){void 0===r&&(r=this),this._emitter.once(t,e,r)},r.removeAllListeners=function(t){this._emitter.removeAllListeners(t)},r.off=function(t,e,r,i){void 0===r&&(r=this),this._emitter.off(t,e,r,i)},r.listeners=function(t){return this._emitter.listeners(t)},r.emit=function(t,e,r){return this._emitter.emit(t,e,r)},r.trigger=function(t,e){if(this.config.debug)return this.emit(t,t,e);try{return this.emit(t,t,e)}catch(e){if(b.error("An internal error happened while handling event "+t+'. Error message: "'+e.message+'". Here is a stacktrace:',e),!this.triggeringException){this.triggeringException=!0;var r=t===T.ERROR;this.trigger(T.ERROR,{type:E.OTHER_ERROR,details:S.INTERNAL_EXCEPTION,fatal:r,event:t,error:e}),this.triggeringException=!1}}return!1},r.listenerCount=function(t){return this._emitter.listenerCount(t)},r.destroy=function(){b.log("destroy"),this.trigger(T.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((function(t){return t.destroy()})),this.networkControllers.length=0,this.coreComponents.forEach((function(t){return t.destroy()})),this.coreComponents.length=0;var t=this.config;t.xhrSetup=t.fetchSetup=void 0,this.userConfig=null},r.attachMedia=function(t){b.log("attachMedia"),this._media=t,this.trigger(T.MEDIA_ATTACHING,{media:t})},r.detachMedia=function(){b.log("detachMedia"),this.trigger(T.MEDIA_DETACHING,void 0),this._media=null},r.loadSource=function(t){this.stopLoad();var e=this.media,r=this.url,i=this.url=v.buildAbsoluteURL(self.location.href,t,{alwaysNormalize:!0});this._autoLevelCapping=-1,this._maxHdcpLevel=null,b.log("loadSource:"+i),e&&r&&(r!==i||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(e)),this.trigger(T.MANIFEST_LOADING,{url:t})},r.startLoad=function(t){void 0===t&&(t=-1),b.log("startLoad("+t+")"),this.started=!0,this.networkControllers.forEach((function(e){e.startLoad(t)}))},r.stopLoad=function(){b.log("stopLoad"),this.started=!1,this.networkControllers.forEach((function(t){t.stopLoad()}))},r.resumeBuffering=function(){this.started&&this.networkControllers.forEach((function(t){"fragmentLoader"in t&&t.startLoad(-1)}))},r.pauseBuffering=function(){this.networkControllers.forEach((function(t){"fragmentLoader"in t&&t.stopLoad()}))},r.swapAudioCodec=function(){b.log("swapAudioCodec"),this.streamController.swapAudioCodec()},r.recoverMediaError=function(){b.log("recoverMediaError");var t=this._media;this.detachMedia(),t&&this.attachMedia(t)},r.removeLevel=function(t){this.levelController.removeLevel(t)},r.setAudioOption=function(t){var e;return null==(e=this.audioTrackController)?void 0:e.setAudioOption(t)},r.setSubtitleOption=function(t){var e;return null==(e=this.subtitleTrackController)||e.setSubtitleOption(t),null},s(t,[{key:"levels",get:function(){return this.levelController.levels||[]}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(t){b.log("set currentLevel:"+t),this.levelController.manualLevel=t,this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(t){b.log("set nextLevel:"+t),this.levelController.manualLevel=t,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(t){b.log("set loadLevel:"+t),this.levelController.manualLevel=t}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(t){this.levelController.nextLoadLevel=t}},{key:"firstLevel",get:function(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)},set:function(t){b.log("set firstLevel:"+t),this.levelController.firstLevel=t}},{key:"startLevel",get:function(){var t=this.levelController.startLevel;return-1===t&&this.abrController.forcedAutoLevel>-1?this.abrController.forcedAutoLevel:t},set:function(t){b.log("set startLevel:"+t),-1!==t&&(t=Math.max(t,this.minAutoLevel)),this.levelController.startLevel=t}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(t){var e=!!t;e!==this.config.capLevelToPlayerSize&&(e?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=e)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(t){this._autoLevelCapping!==t&&(b.log("set autoLevelCapping:"+t),this._autoLevelCapping=t,this.levelController.checkMaxAutoUpdated())}},{key:"bandwidthEstimate",get:function(){var t=this.abrController.bwEstimator;return t?t.getEstimate():NaN},set:function(t){this.abrController.resetEstimator(t)}},{key:"ttfbEstimate",get:function(){var t=this.abrController.bwEstimator;return t?t.getEstimateTTFB():NaN}},{key:"maxHdcpLevel",get:function(){return this._maxHdcpLevel},set:function(t){(function(t){return Ke.indexOf(t)>-1})(t)&&this._maxHdcpLevel!==t&&(this._maxHdcpLevel=t,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 t=this.levels,e=this.config.minAutoBitrate;if(!t)return 0;for(var r=t.length,i=0;i=e)return i;return 0}},{key:"maxAutoLevel",get:function(){var t,e=this.levels,r=this.autoLevelCapping,i=this.maxHdcpLevel;if(t=-1===r&&null!=e&&e.length?e.length-1:r,i)for(var n=t;n--;){var a=e[n].attrs["HDCP-LEVEL"];if(a&&a<=i)return n}return t}},{key:"firstAutoLevel",get:function(){return this.abrController.firstAutoLevel}},{key:"nextAutoLevel",get:function(){return this.abrController.nextAutoLevel},set:function(t){this.abrController.nextAutoLevel=t}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"mainForwardBufferInfo",get:function(){return this.streamController.getMainFwdBufferInfo()}},{key:"allAudioTracks",get:function(){var t=this.audioTrackController;return t?t.allAudioTracks:[]}},{key:"audioTracks",get:function(){var t=this.audioTrackController;return t?t.audioTracks:[]}},{key:"audioTrack",get:function(){var t=this.audioTrackController;return t?t.audioTrack:-1},set:function(t){var e=this.audioTrackController;e&&(e.audioTrack=t)}},{key:"allSubtitleTracks",get:function(){var t=this.subtitleTrackController;return t?t.allSubtitleTracks:[]}},{key:"subtitleTracks",get:function(){var t=this.subtitleTrackController;return t?t.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var t=this.subtitleTrackController;return t?t.subtitleTrack:-1},set:function(t){var e=this.subtitleTrackController;e&&(e.subtitleTrack=t)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var t=this.subtitleTrackController;return!!t&&t.subtitleDisplay},set:function(t){var e=this.subtitleTrackController;e&&(e.subtitleDisplay=t)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(t){this.config.lowLatencyMode=t}},{key:"liveSyncPosition",get:function(){return this.latencyController.liveSyncPosition}},{key:"latency",get:function(){return this.latencyController.latency}},{key:"maxLatency",get:function(){return this.latencyController.maxLatency}},{key:"targetLatency",get:function(){return this.latencyController.targetLatency}},{key:"drift",get:function(){return this.latencyController.drift}},{key:"forceStartLoad",get:function(){return this.streamController.forceStartLoad}}],[{key:"version",get:function(){return"1.5.13"}},{key:"Events",get:function(){return T}},{key:"ErrorTypes",get:function(){return E}},{key:"ErrorDetails",get:function(){return S}},{key:"DefaultConfig",get:function(){return t.defaultConfig?t.defaultConfig:Rs},set:function(e){t.defaultConfig=e}}]),t}();return xs.defaultConfig=void 0,xs},"object"==typeof e&&void 0!==t?t.exports=a():"function"==typeof define&&define.amd?define(a):(n="undefined"!=typeof globalThis?globalThis:n||self).Hls=a()}(!1)}}]);