vendor: 21,754 bytes, lines 1-16
1import{q as xr,s as Yt,r as $,j as A,y as ks,R as hl,B as Ce,O as ul,h as kt,aL as dl,K as fl,ai as wi,f as gl,F as ml,aM as vt}from"./index-BvsqCpEz.js";import{A as pl,a as xl,b as yl,c as Tl,d as El,e as Sl,f as vl,g as Al}from"./MemberDashboard-Cs5Sf23a.js";import{I as _s}from"./input-BedoGODD.js";import{C as Ll}from"./calendar-CAkD_jWe.js";import{P as Rl,a as bl,b as Il}from"./popover-BRjrXi5Z.js";import{C as Dl,P as Cl,s as wl}from"./podcast-handoff-ZZpcEi70.js";import{S as xn,a as yn,b as Tn,c as En,d as Gt}from"./select-kTbLcfik.js";import{u as kl}from"./use-auth-4OwtEfAA.js";import{C as _l}from"./calendar-BX6XEece.js";import{M as Pl}from"./user-DLmK3dAG.js";import{R as Sn}from"./refresh-cw-Dooswkp8.js";import{P as Ml}from"./pause-BSClxgvH.js";import{D as vn}from"./download-0HDG1NIG.js";import{s as qt,f as Ue}from"./format-Dogvratb.js";import{s as Zi}from"./subDays-C60P-3D1.js";import"./index-5yHiP4fM.js";import"./wind-DW6YfAyS.js";import"./arrow-left-DasGo8Zs.js";import"./check-B97Uezjq.js";import"./startOfMonth-Bq5nWt2t.js";import"./chevron-left-DdeOtDWg.js";import"./chevron-right-CPI6eVSm.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Fl=xr("WifiOff",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Ol=xr("ZoomIn",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Nl=xr("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);function Ul(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var Da={exports:{}};(function(a,e){(function(t){var s=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,i=/^(?=([^\/?#]*))\1([^]*)$/,r=/(?:\/|^)\.(?=\/)/g,n=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,o={buildAbsoluteURL:function(l,c,h){if(h=h||{},l=l.trim(),c=c.trim(),!c){if(!h.alwaysNormalize)return l;var u=o.parseURL(l);if(!u)throw new Error("Error trying to parse base URL.");return u.path=o.normalizePath(u.path),o.buildURLFromParts(u)}var d=o.parseURL(c);if(!d)throw new Error("Error trying to parse relative URL.");if(d.scheme)return h.alwaysNormalize?(d.path=o.normalizePath(d.path),o.buildURLFromParts(d)):c;var f=o.parseURL(l);if(!f)throw new Error("Error trying to parse base URL.");if(!f.netLoc&&f.path&&f.path[0]!=="/"){var g=i.exec(f.path);f.netLoc=g[1],f.path=g[2]}f.netLoc&&!f.path&&(f.path="/");var m={scheme:f.scheme,netLoc:d.netLoc,path:null,params:d.params,query:d.query,fragment:d.fragment};if(!d.netLoc&&(m.netLoc=f.netLoc,d.path[0]!=="/"))if(!d.path)m.path=f.path,d.params||(m.params=f.params,d.query||(m.query=f.query));else{var x=f.path,T=x.substring(0,x.lastIndexOf("/")+1)+d.path;m.path=o.normalizePath(T)}return m.path===null&&(m.path=h.alwaysNormalize?o.normalizePath(d.path):d.path),o.buildURLFromParts(m)},parseURL:function(l){var c=s.exec(l);return c?{scheme:c[1]||"",netLoc:c[2]||"",path:c[3]||"",params:c[4]||"",query:c[5]||"",fragment:c[6]||""}:null},normalizePath:function(l){for(l=l.split("").reverse().join("").replace(r,"");l.length!==(l=l.replace(n,"")).length;);return l.split("").reverse().join("")},buildURLFromParts:function(l){return l.scheme+l.netLoc+l.path+l.params+l.query+l.fragment}};a.exports=o})()})(Da);var yr=Da.exports;function An(a,e){var t=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);e&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),t.push.apply(t,s)}return t}function Oe(a){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?An(Object(t),!0).forEach(function(s){Gl(a,s,t[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(t)):An(Object(t)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(t,s))})}return a}function Bl(a,e){if(typeof a!="object"||!a)return a;var t=a[Symbol.toPrimitive];if(t!==void 0){var s=t.call(a,e||"default");if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(a)}function $l(a){var e=Bl(a,"string");return typeof e=="symbol"?e:String(e)}function Gl(a,e,t){return e=$l(e),e in a?Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):a[e]=t,a}function we(){return we=Object.assign?Object.assign.bind():function(a){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(a[s]=t[s])}return a},we.apply(this,arguments)}const j=Number.isFinite||function(a){return typeof a=="number"&&isFinite(a)},Kl=Number.isSafeInteger||function(a){return typeof a=="number"&&Math.abs(a)<=Hl},Hl=Number.MAX_SAFE_INTEGER||9007199254740991;let p=function(a){return a.MEDIA_ATTACHING="hlsMediaAttaching",a.MEDIA_ATTACHED="hlsMediaAttached",a.MEDIA_DETACHING="hlsMediaDetaching",a.MEDIA_DETACHED="hlsMediaDetached",a.BUFFER_RESET="hlsBufferReset",a.BUFFER_CODECS="hlsBufferCodecs",a.BUFFER_CREATED="hlsBufferCreated",a.BUFFER_APPENDING="hlsBufferAppending",a.BUFFER_APPENDED="hlsBufferAppended",a.BUFFER_EOS="hlsBufferEos",a.BUFFER_FLUSHING="hlsBufferFlushing",a.BUFFER_FLUSHED="hlsBufferFlushed",a.MANIFEST_LOADING="hlsManifestLoading",a.MANIFEST_LOADED="hlsManifestLoaded",a.MANIFEST_PARSED="hlsManifestParsed",a.LEVEL_SWITCHING="hlsLevelSwitching",a.LEVEL_SWITCHED="hlsLevelSwitched",a.LEVEL_LOADING="hlsLevelLoading",a.LEVEL_LOADED="hlsLevelLoaded",a.LEVEL_UPDATED="hlsLevelUpdated",a.LEVEL_PTS_UPDATED="hlsLevelPtsUpdated",a.LEVELS_UPDATED="hlsLevelsUpdated",a.AUDIO_TRACKS_UPDATED="hlsAudioTracksUpdated",a.AUDIO_TRACK_SWITCHING="hlsAudioTrackSwitching",a.AUDIO_TRACK_SWITCHED="hlsAudioTrackSwitched",a.AUDIO_TRACK_LOADING="hlsAudioTrackLoading",a.AUDIO_TRACK_LOADED="hlsAudioTrackLoaded",a.SUBTITLE_TRACKS_UPDATED="hlsSubtitleTracksUpdated",a.SUBTITLE_TRACKS_CLEARED="hlsSubtitleTracksCleared",a.SUBTITLE_TRACK_SWITCH="hlsSubtitleTrackSwitch",a.SUBTITLE_TRACK_LOADING="hlsSubtitleTrackLoading",a.SUBTITLE_TRACK_LOADED="hlsSubtitleTrackLoaded",a.SUBTITLE_FRAG_PROCESSED="hlsSubtitleFragProcessed",a.CUES_PARSED="hlsCuesParsed",a.NON_NATIVE_TEXT_TRACKS_FOUND="hlsNonNativeTextTracksFound",a.INIT_PTS_FOUND="hlsInitPtsFound",a.FRAG_LOADING="hlsFragLoading",a.FRAG_LOAD_EMERGENCY_ABORTED="hlsFragLoadEmergencyAborted",a.FRAG_LOADED="hlsFragLoaded",a.FRAG_DECRYPTED="hlsFragDecrypted",a.FRAG_PARSING_INIT_SEGMENT="hlsFragParsingInitSegment",a.FRAG_PARSING_USERDATA="hlsFragParsingUserdata",a.FRAG_PARSING_METADATA="hlsFragParsingMetadata",a.FRAG_PARSED="hlsFragParsed",a.FRAG_BUFFERED="hlsFragBuffered",a.FRAG_CHANGED="hlsFragChanged",a.FPS_DROP="hlsFpsDrop",a.FPS_DROP_LEVEL_CAPPING="hlsFpsDropLevelCapping",a.MAX_AUTO_LEVEL_UPDATED="hlsMaxAutoLevelUpdated",a.ERROR="hlsError",a.DESTROYING="hlsDestroying",a.KEY_LOADING="hlsKeyLoading",a.KEY_LOADED="hlsKeyLoaded",a.LIVE_BACK_BUFFER_REACHED="hlsLiveBackBufferReached",a.BACK_BUFFER_REACHED="hlsBackBufferReached",a.STEERING_MANIFEST_LOADED="hlsSteeringManifestLoaded",a}({}),Z=function(a){return a.NETWORK_ERROR="networkError",a.MEDIA_ERROR="mediaError",a.KEY_SYSTEM_ERROR="keySystemError",a.MUX_ERROR="muxError",a.OTHER_ERROR="otherError",a}({}),w=function(a){return a.KEY_SYSTEM_NO_KEYS="keySystemNoKeys",a.KEY_SYSTEM_NO_ACCESS="keySystemNoAccess",a.KEY_SYSTEM_NO_SESSION="keySystemNoSession",a.KEY_SYSTEM_NO_CONFIGURED_LICENSE="keySystemNoConfiguredLicense",a.KEY_SYSTEM_LICENSE_REQUEST_FAILED="keySystemLicenseRequestFailed",a.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED="keySystemServerCertificateRequestFailed",a.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED="keySystemServerCertificateUpdateFailed",a.KEY_SYSTEM_SESSION_UPDATE_FAILED="keySystemSessionUpdateFailed",a.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED="keySystemStatusOutputRestricted",a.KEY_SYSTEM_STATUS_INTERNAL_ERROR="keySystemStatusInternalError",a.MANIFEST_LOAD_ERROR="manifestLoadError",a.MANIFEST_LOAD_TIMEOUT="manifestLoadTimeOut",a.MANIFEST_PARSING_ERROR="manifestParsingError",a.MANIFEST_INCOMPATIBLE_CODECS_ERROR="manifestIncompatibleCodecsError",a.LEVEL_EMPTY_ERROR="levelEmptyError",a.LEVEL_LOAD_ERROR="levelLoadError",a.LEVEL_LOAD_TIMEOUT="levelLoadTimeOut",a.LEVEL_PARSING_ERROR="levelParsingError",a.LEVEL_SWITCH_ERROR="levelSwitchError",a.AUDIO_TRACK_LOAD_ERROR="audioTrackLoadError",a.AUDIO_TRACK_LOAD_TIMEOUT="audioTrackLoadTimeOut",a.SUBTITLE_LOAD_ERROR="subtitleTrackLoadError",a.SUBTITLE_TRACK_LOAD_TIMEOUT="subtitleTrackLoadTimeOut",a.FRAG_LOAD_ERROR="fragLoadError",a.FRAG_LOAD_TIMEOUT="fragLoadTimeOut",a.FRAG_DECRYPT_ERROR="fragDecryptError",a.FRAG_PARSING_ERROR="fragParsingError",a.FRAG_GAP="fragGap",a.REMUX_ALLOC_ERROR="remuxAllocError",a.KEY_LOAD_ERROR="keyLoadError",a.KEY_LOAD_TIMEOUT="keyLoadTimeOut",a.BUFFER_ADD_CODEC_ERROR="bufferAddCodecError",a.BUFFER_INCOMPATIBLE_CODECS_ERROR="bufferIncompatibleCodecsError",a.BUFFER_APPEND_ERROR="bufferAppendError",a.BUFFER_APPENDING_ERROR="bufferAppendingError",a.BUFFER_STALLED_ERROR="bufferStalledError",a.BUFFER_FULL_ERROR="bufferFullError",a.BUFFER_SEEK_OVER_HOLE="bufferSeekOverHole",a.BUFFER_NUDGE_ON_STALL="bufferNudgeOnStall",a.INTERNAL_EXCEPTION="internalException",a.INTERNAL_ABORTED="aborted",a.UNKNOWN="unknown",a}({});const Pt=function(){},er={trace:Pt,debug:Pt,log:Pt,warn:Pt,info:Pt,error:Pt};let xs=er;function Vl(a){const e=self.console[a];return e?e.bind(self.console,`[${a}] >`):Pt}function jl(a,...e){e.forEach(function(t){xs[t]=a[t]?a[t].bind(a):Vl(t)})}function Wl(a,e){if(typeof console=="object"&&a===!0||typeof a=="object"){jl(a,"debug","log","info","warn","error");try{xs.log(`Debug logs enabled for "${e}" in hls.js version 1.5.17`)}catch{xs=er}}else xs=er}const b=xs,Yl=/^(\d+)x(\d+)$/,Ln=/(.+?)=(".*?"|.*?)(?:,|$)/g;class Ae{constructor(e){typeof e=="string"&&(e=Ae.parseAttrList(e)),we(this,e)}get clientAttrs(){return Object.keys(this).filter(e=>e.substring(0,2)==="X-")}decimalInteger(e){const t=parseInt(this[e],10);return t>Number.MAX_SAFE_INTEGER?1/0:t}hexadecimalInteger(e){if(this[e]){let t=(this[e]||"0x").slice(2);t=(t.length&1?"0":"")+t;const s=new Uint8Array(t.length/2);for(let i=0;i<t.length/2;i++)s[i]=parseInt(t.slice(i*2,i*2+2),16);return s}else return null}hexadecimalIntegerAsNumber(e){const t=parseInt(this[e],16);return t>Number.MAX_SAFE_INTEGER?1/0:t}decimalFloatingPoint(e){return parseFloat(this[e])}optionalFloat(e,t){const s=this[e];return s?parseFloat(s):t}enumeratedString(e){return this[e]}bool(e){return this[e]==="YES"}decimalResolution(e){const t=Yl.exec(this[e]);if(t!==null)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}}static parseAttrList(e){let t;const s={},i='"';for(Ln.lastIndex=0;(t=Ln.exec(e))!==null;){let r=t[2];r.indexOf(i)===0&&r.lastIndexOf(i)===r.length-1&&(r=r.slice(1,-1));const n=t[1].trim();s[n]=r}return s}}function ql(a){return a!=="ID"&&a!=="CLASS"&&a!=="START-DATE"&&a!=="DURATION"&&a!=="END-DATE"&&a!=="END-ON-NEXT"}function zl(a){return a==="SCTE35-OUT"||a==="SCTE35-IN"}class Ca{constructor(e,t){if(this.attr=void 0,this._startDate=void 0,this._endDate=void 0,this._badValueForSameId=void 0,t){const s=t.attr;for(const i in s)if(Object.prototype.hasOwnProperty.call(e,i)&&e[i]!==s[i]){b.warn(`DATERANGE tag attribute: "${i}" does not match for tags with ID: "${e.ID}"`),this._badValueForSameId=i;break}e=we(new Ae({}),s,e)}if(this.attr=e,this._startDate=new Date(e["START-DATE"]),"END-DATE"in this.attr){const s=new Date(this.attr["END-DATE"]);j(s.getTime())&&(this._endDate=s)}}get id(){return this.attr.ID}get class(){return this.attr.CLASS}get startDate(){return this._startDate}get endDate(){if(this._endDate)return this._endDate;const e=this.duration;return e!==null?new Date(this._startDate.getTime()+e*1e3):null}get duration(){if("DURATION"in this.attr){const e=this.attr.decimalFloatingPoint("DURATION");if(j(e))return e}else if(this._endDate)return(this._endDate.getTime()-this._startDate.getTime())/1e3;return null}get plannedDuration(){return"PLANNED-DURATION"in this.attr?this.attr.decimalFloatingPoint("PLANNED-DURATION"):null}get endOnNext(){return this.attr.bool("END-ON-NEXT")}get isValid(){return!!this.id&&!this._badValueForSameId&&j(this.startDate.getTime())&&(this.duration===null||this.duration>=0)&&(!this.endOnNext||!!this.class)}}class hi{constructor(){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}}}var xe={AUDIO:"audio",VIDEO:"video",AUDIOVIDEO:"audiovideo"};class wa{constructor(e){this._byteRange=null,this._url=null,this.baseurl=void 0,this.relurl=void 0,this.elementaryStreams={[xe.AUDIO]:null,[xe.VIDEO]:null,[xe.AUDIOVIDEO]:null},this.baseurl=e}setByteRange(e,t){const s=e.split("@",2);let i;s.length===1?i=(t==null?void 0:t.byteRangeEndOffset)||0:i=parseInt(s[1]),this._byteRange=[i,parseInt(s[0])+i]}get byteRange(){return this._byteRange?this._byteRange:[]}get byteRangeStartOffset(){return this.byteRange[0]}get byteRangeEndOffset(){return this.byteRange[1]}get url(){return!this._url&&this.baseurl&&this.relurl&&(this._url=yr.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""}set url(e){this._url=e}}class ki extends wa{constructor(e,t){super(t),this._decryptdata=null,this.rawProgramDateTime=null,this.programDateTime=null,this.tagList=[],this.duration=0,this.sn=0,this.levelkeys=void 0,this.type=void 0,this.loader=null,this.keyLoader=null,this.level=-1,this.cc=0,this.startPTS=void 0,this.endPTS=void 0,this.startDTS=void 0,this.endDTS=void 0,this.start=0,this.deltaPTS=void 0,this.maxStartPTS=void 0,this.minEndPTS=void 0,this.stats=new hi,this.data=void 0,this.bitrateTest=!1,this.title=null,this.initSegment=null,this.endList=void 0,this.gap=void 0,this.urlId=0,this.type=e}get decryptdata(){const{levelkeys:e}=this;if(!e&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkeys&&!this.levelkeys.NONE){const t=this.levelkeys.identity;if(t)this._decryptdata=t.getDecryptData(this.sn);else{const s=Object.keys(this.levelkeys);if(s.length===1)return this._decryptdata=this.levelkeys[s[0]].getDecryptData(this.sn)}}return this._decryptdata}get end(){return this.start+this.duration}get endProgramDateTime(){if(this.programDateTime===null||!j(this.programDateTime))return null;const e=j(this.duration)?this.duration:0;return this.programDateTime+e*1e3}get encrypted(){var e;if((e=this._decryptdata)!=null&&e.encrypted)return!0;if(this.levelkeys){const t=Object.keys(this.levelkeys),s=t.length;if(s>1||s===1&&this.levelkeys[t[0]].encrypted)return!0}return!1}setKeyFormat(e){if(this.levelkeys){const t=this.levelkeys[e];t&&!this._decryptdata&&(this._decryptdata=t.getDecryptData(this.sn))}}abortRequests(){var e,t;(e=this.loader)==null||e.abort(),(t=this.keyLoader)==null||t.abort()}setElementaryStreamInfo(e,t,s,i,r,n=!1){const{elementaryStreams:o}=this,l=o[e];if(!l){o[e]={startPTS:t,endPTS:s,startDTS:i,endDTS:r,partial:n};return}l.startPTS=Math.min(l.startPTS,t),l.endPTS=Math.max(l.endPTS,s),l.startDTS=Math.min(l.startDTS,i),l.endDTS=Math.max(l.endDTS,r)}clearElementaryStreamInfo(){const{elementaryStreams:e}=this;e[xe.AUDIO]=null,e[xe.VIDEO]=null,e[xe.AUDIOVIDEO]=null}}class Xl extends wa{constructor(e,t,s,i,r){super(s),this.fragOffset=0,this.duration=0,this.gap=!1,this.independent=!1,this.relurl=void 0,this.fragment=void 0,this.index=void 0,this.stats=new hi,this.duration=e.decimalFloatingPoint("DURATION"),this.gap=e.bool("GAP"),this.independent=e.bool("INDEPENDENT"),this.relurl=e.enumeratedString("URI"),this.fragment=t,this.index=i;const n=e.enumeratedString("BYTERANGE");n&&this.setByteRange(n,r),r&&(this.fragOffset=r.fragOffset+r.duration)}get start(){return this.fragment.start+this.fragOffset}get end(){return this.start+this.duration}get loaded(){const{elementaryStreams:e}=this;return!!(e.audio||e.video||e.audiovideo)}}const Ql=10;class Jl{constructor(e){this.PTSKnown=!1,this.alignedSliding=!1,this.averagetargetduration=void 0,this.endCC=0,this.endSN=0,this.fragments=void 0,this.fragmentHint=void 0,this.partList=null,this.dateRanges=void 0,this.live=!0,this.ageHeader=0,this.advancedDateTime=void 0,this.updated=!0,this.advanced=!0,this.availabilityDelay=void 0,this.misses=0,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=void 0,this.m3u8="",this.version=null,this.canBlockReload=!1,this.canSkipUntil=0,this.canSkipDateRanges=!1,this.skippedSegments=0,this.recentlyRemovedDateranges=void 0,this.partHoldBack=0,this.holdBack=0,this.partTarget=0,this.preloadHint=void 0,this.renditionReports=void 0,this.tuneInGoal=0,this.deltaUpdateFailed=void 0,this.driftStartTime=0,this.driftEndTime=0,this.driftStart=0,this.driftEnd=0,this.encryptedFragments=void 0,this.playlistParsingError=null,this.variableList=null,this.hasVariableRefs=!1,this.fragments=[],this.encryptedFragments=[],this.dateRanges={},this.url=e}reloaded(e){if(!e){this.advanced=!0,this.updated=!0;return}const t=this.lastPartSn-e.lastPartSn,s=this.lastPartIndex-e.lastPartIndex;this.updated=this.endSN!==e.endSN||!!s||!!t||!this.live,this.advanced=this.endSN>e.endSN||t>0||t===0&&s>0,this.updated||this.advanced?this.misses=Math.floor(e.misses*.6):this.misses=e.misses+1,this.availabilityDelay=e.availabilityDelay}get hasProgramDateTime(){return this.fragments.length?j(this.fragments[this.fragments.length-1].programDateTime):!1}get levelTargetDuration(){return this.averagetargetduration||this.targetduration||Ql}get drift(){const e=this.driftEndTime-this.driftStartTime;return e>0?(this.driftEnd-this.driftStart)*1e3/e:1}get edge(){return this.partEnd||this.fragmentEnd}get partEnd(){var e;return(e=this.partList)!=null&&e.length?this.partList[this.partList.length-1].end:this.fragmentEnd}get fragmentEnd(){var e;return(e=this.fragments)!=null&&e.length?this.fragments[this.fragments.length-1].end:0}get age(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}get lastPartIndex(){var e;return(e=this.partList)!=null&&e.length?this.partList[this.partList.length-1].index:-1}get lastPartSn(){var e;return(e=this.partList)!=null&&e.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}function Tr(a){return Uint8Array.from(atob(a),e=>e.charCodeAt(0))}function Zl(a){const e=tr(a).subarray(0,16),t=new Uint8Array(16);return t.set(e,16-e.length),t}function ec(a){const e=function(s,i,r){const n=s[i];s[i]=s[r],s[r]=n};e(a,0,3),e(a,1,2),e(a,4,5),e(a,6,7)}function tc(a){const e=a.split(":");let t=null;if(e[0]==="data"&&e.length===2){const s=e[1].split(";"),i=s[s.length-1].split(",");if(i.length===2){const r=i[0]==="base64",n=i[1];r?(s.splice(-1,1),t=Tr(n)):t=Zl(n)}}return t}function tr(a){return Uint8Array.from(unescape(encodeURIComponent(a)),e=>e.charCodeAt(0))}const Jt=typeof self<"u"?self:void 0;var Se={CLEARKEY:"org.w3.clearkey",FAIRPLAY:"com.apple.fps",PLAYREADY:"com.microsoft.playready",WIDEVINE:"com.widevine.alpha"},Ye={CLEARKEY:"org.w3.clearkey",FAIRPLAY:"com.apple.streamingkeydelivery",PLAYREADY:"com.microsoft.playready",WIDEVINE:"urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"};function Rn(a){switch(a){case Ye.FAIRPLAY:return Se.FAIRPLAY;case Ye.PLAYREADY:return Se.PLAYREADY;case Ye.WIDEVINE:return Se.WIDEVINE;case Ye.CLEARKEY:return Se.CLEARKEY}}var ps={CENC:"1077efecc0b24d02ace33c1e52e2fb4b",CLEARKEY:"e2719d58a985b3c9781ab030af78d30e",FAIRPLAY:"94ce86fb07ff4f43adb893d2fa968ca2",PLAYREADY:"9a04f07998404286ab92e65be0885f95",WIDEVINE:"edef8ba979d64acea3c827dcd51d21ed"};function bn(a){if(a===ps.WIDEVINE)return Se.WIDEVINE;if(a===ps.PLAYREADY)return Se.PLAYREADY;if(a===ps.CENC||a===ps.CLEARKEY)return Se.CLEARKEY}function In(a){switch(a){case Se.FAIRPLAY:return Ye.FAIRPLAY;case Se.PLAYREADY:return Ye.PLAYREADY;case Se.WIDEVINE:return Ye.WIDEVINE;case Se.CLEARKEY:return Ye.CLEARKEY}}function _i(a){const{drmSystems:e,widevineLicenseUrl:t}=a,s=e?[Se.FAIRPLAY,Se.WIDEVINE,Se.PLAYREADY,Se.CLEARKEY].filter(i=>!!e[i]):[];return!s[Se.WIDEVINE]&&t&&s.push(Se.WIDEVINE),s}const ka=function(a){return Jt!=null&&(a=Jt.navigator)!=null&&a.requestMediaKeySystemAccess?self.navigator.requestMediaKeySystemAccess.bind(self.navigator):null}();function sc(a,e,t,s){let i;switch(a){case Se.FAIRPLAY:i=["cenc","sinf"];break;case Se.WIDEVINE:case Se.PLAYREADY:i=["cenc"];break;case Se.CLEARKEY:i=["cenc","keyids"];break;default:throw new Error(`Unknown key-system: ${a}`)}return ic(i,e,t,s)}function ic(a,e,t,s){return[{initDataTypes:a,persistentState:s.persistentState||"optional",distinctiveIdentifier:s.distinctiveIdentifier||"optional",sessionTypes:s.sessionTypes||[s.sessionType||"temporary"],audioCapabilities:e.map(r=>({contentType:`audio/mp4; codecs="${r}
16"`,robustness:s.audioRobustness||"",encryptionScheme:s.audioEncryptionScheme||null})),videoCapabilities:t.map(r=>({contentType:`video/mp4; codecs="${r}"`,robustness:s.videoRobustness||"",encryptionScheme:s.videoEncryptionScheme||null}))}]}function Ft(a,e,t){return Uint8Array.prototype.slice?a.slice(e,t):new Uint8Array(Array.prototype.slice.call(a,e,t))}const Er=(a,e)=>e+10<=a.length&&a[e]===73&&a[e+1]===68&&a[e+2]===51&&a[e+3]<255&&a[e+4]<255&&a[e+6]<128&&a[e+7]<128&&a[e+8]<128&&a[e+9]<128,_a=(a,e)=>e+10<=a.length&&a[e]===51&&a[e+1]===68&&a[e+2]===73&&a[e+3]<255&&a[e+4]<255&&a[e+6]<128&&a[e+7]<128&&a[e+8]<128&&a[e+9]<128,ys=(a,e)=>{const t=e;let s=0;for(;Er(a,e);){s+=10;const i=ui(a,e+6);s+=i,_a(a,e+10)&&(s+=10),e+=s}if(s>0)return a.subarray(t,t+s)},ui=(a,e)=>{let t=0;return t=(a[e]&127)<<21,t|=(a[e+1]&127)<<14,t|=(a[e+2]&127)<<7,t|=a[e+3]&127,t},rc=(a,e)=>Er(a,e)&&ui(a,e+6)+10<=a.length-e,Sr=a=>{const e=Ma(a);for(let t=0;t<e.length;t++){const s=e[t];if(Pa(s))return hc(s)}},Pa=a=>a&&a.key==="PRIV"&&a.info==="com.apple.streaming.transportStreamTimestamp",nc=a=>{const e=String.fromCharCode(a[0],a[1],a[2],a[3]),t=ui(a,4),s=10;return{type:e,size:t,data:a.subarray(s,s+t)}},Ma=a=>{let e=0;const t=[];for(;Er(a,e);){const s=ui(a,e+6);e+=10;const i=e+s;for(;e+8<i;){const r=nc(a.subarray(e)),n=ac(r);n&&t.push(n),e+=r.size+10}_a(a,e)&&(e+=10)}return t},ac=a=>a.type==="PRIV"?oc(a):a.type[0]==="W"?cc(a):lc(a),oc=a=>{if(a.size<2)return;const e=dt(a.data,!0),t=new Uint8Array(a.data.subarray(e.length+1));return{key:a.type,info:e,data:t.buffer}},lc=a=>{if(a.size<2)return;if(a.type==="TXXX"){let t=1;const s=dt(a.data.subarray(t),!0);t+=s.length+1;const i=dt(a.data.subarray(t));return{key:a.type,info:s,data:i}}const e=dt(a.data.subarray(1));return{key:a.type,data:e}},cc=a=>{if(a.type==="WXXX"){if(a.size<2)return;let t=1;const s=dt(a.data.subarray(t),!0);t+=s.length+1;const i=dt(a.data.subarray(t));return{key:a.type,info:s,data:i}}const e=dt(a.data);return{key:a.type,data:e}},hc=a=>{if(a.data.byteLength===8){const e=new Uint8Array(a.data),t=e[3]&1;let s=(e[4]<<23)+(e[5]<<15)+(e[6]<<7)+e[7];return s/=45,t&&(s+=4772185884e-2),Math.round(s)}},dt=(a,e=!1)=>{const t=uc();if(t){const c=t.decode(a);if(e){const h=c.indexOf("\0");return h!==-1?c.substring(0,h):c}return c.replace(/\0/g,"")}const s=a.length;let i,r,n,o="",l=0;for(;l<s;){if(i=a[l++],i===0&&e)return o;if(i===0||i===3)continue;switch(i>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:o+=String.fromCharCode(i);break;case 12:case 13:r=a[l++],o+=String.fromCharCode((i&31)<<6|r&63);break;case 14:r=a[l++],n=a[l++],o+=String.fromCharCode((i&15)<<12|(r&63)<<6|(n&63)<<0);break}}return o};let Pi;function uc(){if(!navigator.userAgent.includes("PlayStation 4"))return!Pi&&typeof self.TextDecoder<"u"&&(Pi=new self.TextDecoder("utf-8")),Pi}const ot={hexDump:function(a){let e="";for(let t=0;t<a.length;t++){let s=a[t].toString(16);s.length<2&&(s="0"+s),e+=s}return e}},Zs=Math.pow(2,32)-1,dc=[].push,Fa={video:1,audio:2,id3:3,text:4};function _e(a){return String.fromCharCode.apply(null,a)}function Oa(a,e){const t=a[e]<<8|a[e+1];return t<0?65536+t:t}function X(a,e){const t=Na(a,e);return t<0?4294967296+t:t}function Dn(a,e){let t=X(a,e);return t*=Math.pow(2,32),t+=X(a,e+4),t}function Na(a,e){return a[e]<<24|a[e+1]<<16|a[e+2]<<8|a[e+3]}function Mi(a,e,t){a[e]=t>>24,a[e+1]=t>>16&255,a[e+2]=t>>8&255,a[e+3]=t&255}function fc(a){const e=a.byteLength;for(let t=0;t<e;){const s=X(a,t);if(s>8&&a[t+4]===109&&a[t+5]===111&&a[t+6]===111&&a[t+7]===102)return!0;t=s>1?t+s:e}return!1}function ne(a,e){const t=[];if(!e.length)return t;const s=a.byteLength;for(let i=0;i<s;){const r=X(a,i),n=_e(a.subarray(i+4,i+8)),o=r>1?i+r:s;if(n===e[0])if(e.length===1)t.push(a.subarray(i+8,o));else{const l=ne(a.subarray(i+8,o),e.slice(1));l.length&&dc.apply(t,l)}i=o}return t}function gc(a){const e=[],t=a[0];let s=8;const i=X(a,s);s+=4;let r=0,n=0;t===0?(r=X(a,s),n=X(a,s+4),s+=8):(r=Dn(a,s),n=Dn(a,s+8),s+=16),s+=2;let o=a.length+n;const l=Oa(a,s);s+=2;for(let c=0;c<l;c++){let h=s;const u=X(a,h);h+=4;const d=u&2147483647;if((u&2147483648)>>>31===1)return b.warn("SIDX has hierarchical references (not supported)"),null;const g=X(a,h);h+=4,e.push({referenceSize:d,subsegmentDuration:g,info:{duration:g/i,start:o,end:o+d-1}}),o+=d,h+=4,s=h}return{earliestPresentationTime:r,timescale:i,version:t,referencesCount:l,references:e}}function Ua(a){const e=[],t=ne(a,["moov","trak"]);for(let i=0;i<t.length;i++){const r=t[i],n=ne(r,["tkhd"])[0];if(n){let o=n[0];const l=X(n,o===0?12:20),c=ne(r,["mdia","mdhd"])[0];if(c){o=c[0];const h=X(c,o===0?12:20),u=ne(r,["mdia","hdlr"])[0];if(u){const d=_e(u.subarray(8,12)),f={soun:xe.AUDIO,vide:xe.VIDEO}[d];if(f){const g=ne(r,["mdia","minf","stbl","stsd"])[0],m=mc(g);e[l]={timescale:h,type:f},e[f]=Oe({timescale:h,id:l},m)}}}}}
vendor: 8,709 bytes, line 16
16return ne(a,["moov","mvex","trex"]).forEach(i=>{const r=X(i,4),n=e[r];n&&(n.default={duration:X(i,12),flags:X(i,20)})}),e}function mc(a){const e=a.subarray(8),t=e.subarray(86),s=_e(e.subarray(4,8));let i=s;const r=s==="enca"||s==="encv";if(r){const o=ne(e,[s])[0].subarray(s==="enca"?28:78);ne(o,["sinf"]).forEach(c=>{const h=ne(c,["schm"])[0];if(h){const u=_e(h.subarray(4,8));if(u==="cbcs"||u==="cenc"){const d=ne(c,["frma"])[0];d&&(i=_e(d))}}})}switch(i){case"avc1":case"avc2":case"avc3":case"avc4":{const n=ne(t,["avcC"])[0];i+="."+Ps(n[1])+Ps(n[2])+Ps(n[3]);break}case"mp4a":{const n=ne(e,[s])[0],o=ne(n.subarray(28),["esds"])[0];if(o&&o.length>12){let l=4;if(o[l++]!==3)break;l=Fi(o,l),l+=2;const c=o[l++];if(c&128&&(l+=2),c&64&&(l+=o[l++]),o[l++]!==4)break;l=Fi(o,l);const h=o[l++];if(h===64)i+="."+Ps(h);else break;if(l+=12,o[l++]!==5)break;l=Fi(o,l);const u=o[l++];let d=(u&248)>>3;d===31&&(d+=1+((u&7)<<3)+((o[l]&224)>>5)),i+="."+d}break}case"hvc1":case"hev1":{const n=ne(t,["hvcC"])[0],o=n[1],l=["","A","B","C"][o>>6],c=o&31,h=X(n,2),u=(o&32)>>5?"H":"L",d=n[12],f=n.subarray(6,12);i+="."+l+c,i+="."+h.toString(16).toUpperCase(),i+="."+u+d;let g="";for(let m=f.length;m--;){const x=f[m];(x||g)&&(g="."+x.toString(16).toUpperCase()+g)}i+=g;break}case"dvh1":case"dvhe":{const n=ne(t,["dvcC"])[0],o=n[2]>>1&127,l=n[2]<<5&32|n[3]>>3&31;i+="."+at(o)+"."+at(l);break}case"vp09":{const n=ne(t,["vpcC"])[0],o=n[4],l=n[5],c=n[6]>>4&15;i+="."+at(o)+"."+at(l)+"."+at(c);break}case"av01":{const n=ne(t,["av1C"])[0],o=n[1]>>>5,l=n[1]&31,c=n[2]>>>7?"H":"M",h=(n[2]&64)>>6,u=(n[2]&32)>>5,d=o===2&&h?u?12:10:h?10:8,f=(n[2]&16)>>4,g=(n[2]&8)>>3,m=(n[2]&4)>>2,x=n[2]&3;i+="."+o+"."+at(l)+c+"."+at(d)+"."+f+"."+g+m+x+"."+at(1)+"."+at(1)+"."+at(1)+"."+0;break}}return{codec:i,encrypted:r}}function Fi(a,e){const t=e+5;for(;a[e++]&128&&e<t;);return e}function Ps(a){return("0"+a.toString(16).toUpperCase()).slice(-2)}function at(a){return(a<10?"0":"")+a}function pc(a,e){if(!a||!e)return a;const t=e.keyId;return t&&e.isCommonEncryption&&ne(a,["moov","trak"]).forEach(i=>{const n=ne(i,["mdia","minf","stbl","stsd"])[0].subarray(8);let o=ne(n,["enca"]);const l=o.length>0;l||(o=ne(n,["encv"])),o.forEach(c=>{const h=l?c.subarray(28):c.subarray(78);ne(h,["sinf"]).forEach(d=>{const f=Ba(d);if(f){const g=f.subarray(8,24);g.some(m=>m!==0)||(b.log(`[eme] Patching keyId in 'enc${l?"a":"v"}>sinf>>tenc' box: ${ot.hexDump(g)} -> ${ot.hexDump(t)}`),f.set(t,8))}})})}),a}function Ba(a){const e=ne(a,["schm"])[0];if(e){const t=_e(e.subarray(4,8));if(t==="cbcs"||t==="cenc")return ne(a,["schi","tenc"])[0]}return null}function xc(a,e){return ne(e,["moof","traf"]).reduce((t,s)=>{const i=ne(s,["tfdt"])[0],r=i[0],n=ne(s,["tfhd"]).reduce((o,l)=>{const c=X(l,4),h=a[c];if(h){let u=X(i,4);if(r===1){if(u===Zs)return b.warn("[mp4-demuxer]: Ignoring assumed invalid signed 64-bit track fragment decode time"),o;u*=Zs+1,u+=X(i,8)}const d=h.timescale||9e4,f=u/d;if(j(f)&&(o===null||f<o))return f}return o},null);return n!==null&&j(n)&&(t===null||n<t)?n:t},null)}function yc(a,e){let t=0,s=0,i=0;const r=ne(a,["moof","traf"]);for(let n=0;n<r.length;n++){const o=r[n],l=ne(o,["tfhd"])[0],c=X(l,4),h=e[c];if(!h)continue;const u=h.default,d=X(l,0)|(u==null?void 0:u.flags);let f=u==null?void 0:u.duration;d&8&&(d&2?f=X(l,12):f=X(l,8));const g=h.timescale||9e4,m=ne(o,["trun"]);for(let x=0;x<m.length;x++){if(t=Tc(m[x]),!t&&f){const T=X(m[x],4);t=f*T}h.type===xe.VIDEO?s+=t/g:h.type===xe.AUDIO&&(i+=t/g)}}if(s===0&&i===0){let n=1/0,o=0,l=0;const c=ne(a,["sidx"]);for(let h=0;h<c.length;h++){const u=gc(c[h]);if(u!=null&&u.references){n=Math.min(n,u.earliestPresentationTime/u.timescale);const d=u.references.reduce((f,g)=>f+g.info.duration||0,0);o=Math.max(o,d+u.earliestPresentationTime/u.timescale),l=o-n}}if(l&&j(l))return l}return s||i}function Tc(a){const e=X(a,0);let t=8;e&1&&(t+=4),e&4&&(t+=4);let s=0;const i=X(a,4);for(let r=0;r<i;r++){if(e&256){const n=X(a,t);s+=n,t+=4}e&512&&(t+=4),e&1024&&(t+=4),e&2048&&(t+=4)}return s}function Ec(a,e,t){ne(e,["moof","traf"]).forEach(s=>{ne(s,["tfhd"]).forEach(i=>{const r=X(i,4),n=a[r];if(!n)return;const o=n.timescale||9e4;ne(s,["tfdt"]).forEach(l=>{const c=l[0],h=t*o;if(h){let u=X(l,4);if(c===0)u-=h,u=Math.max(u,0),Mi(l,4,u);else{u*=Math.pow(2,32),u+=X(l,8),u-=h,u=Math.max(u,0);const d=Math.floor(u/(Zs+1)),f=Math.floor(u%(Zs+1));Mi(l,4,d),Mi(l,8,f)}}})})})}function Sc(a){const e={valid:null,remainder:null},t=ne(a,["moof"]);if(t.length<2)return e.remainder=a,e;const s=t[t.length-1];return e.valid=Ft(a,0,s.byteOffset-8),e.remainder=Ft(a,s.byteOffset-8),e}function Ze(a,e){const t=new Uint8Array(a.length+e.length);return t.set(a),t.set(e,a.length),t}function Cn(a,e){const t=[],s=e.samples,i=e.timescale,r=e.id;let n=!1;return ne(s,["moof"]).map(l=>{const c=l.byteOffset-8;ne(l,["traf"]).map(u=>{const d=ne(u,["tfdt"]).map(f=>{const g=f[0];let m=X(f,4);return g===1&&(m*=Math.pow(2,32),m+=X(f,8)),m/i})[0];return d!==void 0&&(a=d),ne(u,["tfhd"]).map(f=>{const g=X(f,4),m=X(f,0)&16777215,x=(m&1)!==0,T=(m&2)!==0,R=(m&8)!==0;let v=0;const D=(m&16)!==0;let L=0;const _=(m&32)!==0;let k=8;g===r&&(x&&(k+=8),T&&(k+=4),R&&(v=X(f,k),k+=4),D&&(L=X(f,k),k+=4),_&&(k+=4),e.type==="video"&&(n=vc(e.codec)),ne(u,["trun"]).map(B=>{const G=B[0],P=X(B,0)&16777215,U=(P&1)!==0;let ee=0;const K=(P&4)!==0,se=(P&256)!==0;let ie=0;const Y=(P&512)!==0;let le=0;const he=(P&1024)!==0,V=(P&2048)!==0;let H=0;const re=X(B,4);let J=8;U&&(ee=X(B,J),J+=4),K&&(J+=4);let de=ee+c;for(let ve=0;ve<re;ve++){if(se?(ie=X(B,J),J+=4):ie=v,Y?(le=X(B,J),J+=4):le=L,he&&(J+=4),V&&(G===0?H=X(B,J):H=Na(B,J),J+=4),e.type===xe.VIDEO){let be=0;for(;be<le;){const Pe=X(s,de);if(de+=4,Ac(n,s[de])){const ye=s.subarray(de,de+Pe);$a(ye,n?2:1,a+H/i,t)}de+=Pe,be+=Pe+4}}a+=ie/i}}))})})}),t}function vc(a){if(!a)return!1;const e=a.indexOf("."),t=e<0?a:a.substring(0,e);return t==="hvc1"||t==="hev1"||t==="dvh1"||t==="dvhe"}function Ac(a,e){if(a){const t=e>>1&63;return t===39||t===40}else return(e&31)===6}function $a(a,e,t,s){const i=Ga(a);let r=0;r+=e;let n=0,o=0,l=0;for(;r<i.length;){n=0;do{if(r>=i.length)break;l=i[r++],n+=l}while(l===255);o=0;do{if(r>=i.length)break;l=i[r++],o+=l}while(l===255);const c=i.length-r;let h=r;if(o<c)r+=o;else if(o>c){b.error(`Malformed SEI payload. ${o} is too small, only ${c} bytes left to parse.`);break}if(n===4){if(i[h++]===181){const d=Oa(i,h);if(h+=2,d===49){const f=X(i,h);if(h+=4,f===1195456820){const g=i[h++];if(g===3){const m=i[h++],x=31&m,T=64&m,R=T?2+x*3:0,v=new Uint8Array(R);if(T){v[0]=m;for(let D=1;D<R;D++)v[D]=i[h++]}s.push({type:g,payloadType:n,pts:t,bytes:v})}}}}}else if(n===5&&o>16){const u=[];for(let g=0;g<16;g++){const m=i[h++].toString(16);u.push(m.length==1?"0"+m:m),(g===3||g===5||g===7||g===9)&&u.push("-")}const d=o-16,f=new Uint8Array(d);for(let g=0;g<d;g++)f[g]=i[h++];s.push({payloadType:n,pts:t,uuid:u.join(""),userData:dt(f),userDataBytes:f})}}}function Ga(a){const e=a.byteLength,t=[];let s=1;for(;s<e-2;)a[s]===0&&a[s+1]===0&&a[s+2]===3?(t.push(s+2),s+=2):s++;if(t.length===0)return a;const i=e-t.length,r=new Uint8Array(i);let n=0;for(s=0;s<i;n++,s++)n===t[0]&&(n++,t.shift()),r[s]=a[n];return r}function Lc(a){const e=a[0];let t="",s="",i=0,r=0,n=0,o=0,l=0,c=0;if(e===0){for(;_e(a.subarray(c,c+1))!=="\0";)t+=_e(a.subarray(c,c+1)),c+=1;for(t+=_e(a.subarray(c,c+1)),c+=1;_e(a.subarray(c,c+1))!=="\0";)s+=_e(a.subarray(c,c+1)),c+=1;s+=_e(a.subarray(c,c+1)),c+=1,i=X(a,12),r=X(a,16),o=X(a,20),l=X(a,24),c=28}else if(e===1){c+=4,i=X(a,c),c+=4;const u=X(a,c);c+=4;const d=X(a,c);for(c+=4,n=2**32*u+d,Kl(n)||(n=Number.MAX_SAFE_INTEGER,b.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=X(a,c),c+=4,l=X(a,c),c+=4;_e(a.subarray(c,c+1))!=="\0";)t+=_e(a.subarray(c,c+1)),c+=1;for(t+=_e(a.subarray(c,c+1)),c+=1;_e(a.subarray(c,c+1))!=="\0";)s+=_e(a.subarray(c,c+1)),c+=1;s+=_e(a.subarray(c,c+1)),c+=1}const h=a.subarray(c,a.byteLength);return{schemeIdUri:t,value:s,timeScale:i,presentationTime:n,presentationTimeDelta:r,eventDuration:o,id:l,payload:h}}function Rc(a,...e){const t=e.length;let s=8,i=t;for(;i--;)s+=e[i].byteLength;const r=new Uint8Array(s);for(r[0]=s>>24&255,r[1]=s>>16&255,r[2]=s>>8&255,r[3]=s&255,r.set(a,4),i=0,s=8;i<t;i++)r.set(e[i],s),s+=e[i].byteLength;return r}function bc(a,e,t){if(a.byteLength!==16)throw new RangeError("Invalid system id");let s,i;s=0,i=new Uint8Array;let r;s>0?(r=new Uint8Array(4),e.length>0&&new DataView(r.buffer).setUint32(0,e.length,!1)):r=new Uint8Array;const n=new Uint8Array(4);return t&&t.byteLength>0&&new DataView(n.buffer).setUint32(0,t.byteLength,!1),Rc([112,115,115,104],new Uint8Array([s,0,0,0]),a,r,i,n,t||new Uint8Array)}function Ic(a){const e=[];
vendor: 4,901 bytes, line 16
16if(a instanceof ArrayBuffer){const t=a.byteLength;let s=0;for(;s+32<t;){const i=new DataView(a,s),r=Dc(i);e.push(r),s+=r.size}}return e}function Dc(a){const e=a.getUint32(0),t=a.byteOffset,s=a.byteLength;if(s<e)return{offset:t,size:s};if(a.getUint32(4)!==1886614376)return{offset:t,size:e};const r=a.getUint32(8)>>>24;if(r!==0&&r!==1)return{offset:t,size:e};const n=a.buffer,o=ot.hexDump(new Uint8Array(n,t+12,16)),l=a.getUint32(28);let c=null,h=null;if(r===0){if(e-32<l||l<22)return{offset:t,size:e};h=new Uint8Array(n,t+32,l)}else if(r===1){if(!l||s<t+32+l*16+16)return{offset:t,size:e};c=[];for(let u=0;u<l;u++)c.push(new Uint8Array(n,t+32+u*16,16))}return{version:r,systemId:o,kids:c,data:h,offset:t,size:e}}let Ms={};class Ts{static clearKeyUriToKeyIdMap(){Ms={}}constructor(e,t,s,i=[1],r=null){this.uri=void 0,this.method=void 0,this.keyFormat=void 0,this.keyFormatVersions=void 0,this.encrypted=void 0,this.isCommonEncryption=void 0,this.iv=null,this.key=null,this.keyId=null,this.pssh=null,this.method=e,this.uri=t,this.keyFormat=s,this.keyFormatVersions=i,this.iv=r,this.encrypted=e?e!=="NONE":!1,this.isCommonEncryption=this.encrypted&&e!=="AES-128"}isSupported(){if(this.method){if(this.method==="AES-128"||this.method==="NONE")return!0;if(this.keyFormat==="identity")return this.method==="SAMPLE-AES";switch(this.keyFormat){case Ye.FAIRPLAY:case Ye.WIDEVINE:case Ye.PLAYREADY:case Ye.CLEARKEY:return["ISO-23001-7","SAMPLE-AES","SAMPLE-AES-CENC","SAMPLE-AES-CTR"].indexOf(this.method)!==-1}}return!1}getDecryptData(e){if(!this.encrypted||!this.uri)return null;if(this.method==="AES-128"&&this.uri&&!this.iv){typeof e!="number"&&(this.method==="AES-128"&&!this.iv&&b.warn(`missing IV for initialization segment with method="${this.method}" - compliance issue`),e=0);const s=Cc(e);return new Ts(this.method,this.uri,"identity",this.keyFormatVersions,s)}const t=tc(this.uri);if(t)switch(this.keyFormat){case Ye.WIDEVINE:this.pssh=t,t.length>=22&&(this.keyId=t.subarray(t.length-22,t.length-6));break;case Ye.PLAYREADY:{const s=new Uint8Array([154,4,240,121,152,64,66,134,171,146,230,91,224,136,95,149]);this.pssh=bc(s,null,t);const i=new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2),r=String.fromCharCode.apply(null,Array.from(i)),n=r.substring(r.indexOf("<"),r.length),c=new DOMParser().parseFromString(n,"text/xml").getElementsByTagName("KID")[0];if(c){const h=c.childNodes[0]?c.childNodes[0].nodeValue:c.getAttribute("VALUE");if(h){const u=Tr(h).subarray(0,16);ec(u),this.keyId=u}}break}default:{let s=t.subarray(0,16);if(s.length!==16){const i=new Uint8Array(16);i.set(s,16-s.length),s=i}this.keyId=s;break}}if(!this.keyId||this.keyId.byteLength!==16){let s=Ms[this.uri];if(!s){const i=Object.keys(Ms).length%Number.MAX_SAFE_INTEGER;s=new Uint8Array(16),new DataView(s.buffer,12,4).setUint32(0,i),Ms[this.uri]=s}this.keyId=s}return this}}function Cc(a){const e=new Uint8Array(16);for(let t=12;t<16;t++)e[t]=a>>8*(15-t)&255;return e}const Ka=/\{\$([a-zA-Z0-9-_]+)\}/g;function wn(a){return Ka.test(a)}function We(a,e,t){if(a.variableList!==null||a.hasVariableRefs)for(let s=t.length;s--;){const i=t[s],r=e[i];r&&(e[i]=sr(a,r))}}function sr(a,e){if(a.variableList!==null||a.hasVariableRefs){const t=a.variableList;return e.replace(Ka,s=>{const i=s.substring(2,s.length-1),r=t==null?void 0:t[i];return r===void 0?(a.playlistParsingError||(a.playlistParsingError=new Error(`Missing preceding EXT-X-DEFINE tag for Variable Reference: "${i}"`)),s):r})}return e}function kn(a,e,t){let s=a.variableList;s||(a.variableList=s={});let i,r;if("QUERYPARAM"in e){i=e.QUERYPARAM;try{const n=new self.URL(t).searchParams;if(n.has(i))r=n.get(i);else throw new Error(`"${i}" does not match any query parameter in URI: "${t}"`)}catch(n){a.playlistParsingError||(a.playlistParsingError=new Error(`EXT-X-DEFINE QUERYPARAM: ${n.message}`))}}else i=e.NAME,r=e.VALUE;i in s?a.playlistParsingError||(a.playlistParsingError=new Error(`EXT-X-DEFINE duplicate Variable Name declarations: "${i}"`)):s[i]=r||""}function wc(a,e,t){const s=e.IMPORT;if(t&&s in t){let i=a.variableList;i||(a.variableList=i={}),i[s]=t[s]}else a.playlistParsingError||(a.playlistParsingError=new Error(`EXT-X-DEFINE IMPORT attribute not found in Multivariant Playlist: "${s}"`))}function Ot(a=!0){return typeof self>"u"?void 0:(a||!self.MediaSource)&&self.ManagedMediaSource||self.MediaSource||self.WebKitMediaSource}function kc(a){return typeof self<"u"&&a===self.ManagedMediaSource}const ei={audio:{a3ds:1,"ac-3":.95,"ac-4":1,alac:.9,alaw:1,dra1:1,"dts+":1,"dts-":1,dtsc:1,dtse:1,dtsh:1,"ec-3":.9,enca:1,fLaC:.9,flac:.9,FLAC:.9,g719:1,g726:1,m4ae:1,mha1:1,mha2:1,mhm1:1,mhm2:1,mlpa:1,mp4a:1,"raw ":1,Opus:1,opus:1,samr:1,sawb:1,sawp:1,sevc:1,sqcp:1,ssmv:1,twos:1,ulaw:1},video:{avc1:1,avc2:1,avc3:1,avc4:1,avcp:1,av01:.8,drac:1,dva1:1,dvav:1,dvh1:.7,dvhe:.7,encv:1,hev1:.75,hvc1:.75,mjp2:1,mp4v:1,mvc1:1,mvc2:1,mvc3:1,mvc4:1,resv:1,rv
vendor: 53,274 bytes, line 16
1660:1,s263:1,svc1:1,svc2:1,"vc-1":1,vp08:1,vp09:.9},text:{stpp:1,wvtt:1}};function _c(a,e){const t=ei[e];return!!t&&!!t[a.slice(0,4)]}function Oi(a,e,t=!0){return!a.split(",").some(s=>!Ha(s,e,t))}function Ha(a,e,t=!0){var s;const i=Ot(t);return(s=i==null?void 0:i.isTypeSupported(Es(a,e)))!=null?s:!1}function Es(a,e){return`${e}/mp4;codecs="${a}"`}function _n(a){if(a){const e=a.substring(0,4);return ei.video[e]}return 2}function ti(a){return a.split(",").reduce((e,t)=>{const s=ei.video[t];return s?(s*2+e)/(e?3:2):(ei.audio[t]+e)/(e?2:1)},0)}const Ni={};function Pc(a,e=!0){if(Ni[a])return Ni[a];const t={flac:["flac","fLaC","FLAC"],opus:["opus","Opus"]}[a];for(let s=0;s<t.length;s++)if(Ha(t[s],"audio",e))return Ni[a]=t[s],t[s];return a}const Mc=/flac|opus/i;function si(a,e=!0){return a.replace(Mc,t=>Pc(t.toLowerCase(),e))}function Pn(a,e){return a&&a!=="mp4a"?a:e&&e.split(",")[0]}function Fc(a){const e=a.split(",");for(let t=0;t<e.length;t++){const s=e[t].split(".");if(s.length>2){let i=s.shift()+".";i+=parseInt(s.shift()).toString(16),i+=("000"+parseInt(s.shift()).toString(16)).slice(-4),e[t]=i}}return e.join(",")}const Mn=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-(SESSION-DATA|SESSION-KEY|DEFINE|CONTENT-STEERING|START):([^\r\n]*)[\r\n]+/g,Fn=/#EXT-X-MEDIA:(.*)/g,Oc=/^#EXT(?:INF|-X-TARGETDURATION):/m,On=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[^\r\n]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),Nc=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP|INDEPENDENT-SEGMENTS)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|"));class ct{static findGroup(e,t){for(let s=0;s<e.length;s++){const i=e[s];if(i.id===t)return i}}static resolve(e,t){return yr.buildAbsoluteURL(t,e,{alwaysNormalize:!0})}static isMediaPlaylist(e){return Oc.test(e)}static parseMasterPlaylist(e,t){const s=wn(e),i={contentSteering:null,levels:[],playlistParsingError:null,sessionData:null,sessionKeys:null,startTimeOffset:null,variableList:null,hasVariableRefs:s},r=[];Mn.lastIndex=0;let n;for(;(n=Mn.exec(e))!=null;)if(n[1]){var o;const c=new Ae(n[1]);We(i,c,["CODECS","SUPPLEMENTAL-CODECS","ALLOWED-CPC","PATHWAY-ID","STABLE-VARIANT-ID","AUDIO","VIDEO","SUBTITLES","CLOSED-CAPTIONS","NAME"]);const h=sr(i,n[2]),u={attrs:c,bitrate:c.decimalInteger("BANDWIDTH")||c.decimalInteger("AVERAGE-BANDWIDTH"),name:c.NAME,url:ct.resolve(h,t)},d=c.decimalResolution("RESOLUTION");d&&(u.width=d.width,u.height=d.height),Uc(c.CODECS,u),(o=u.unknownCodecs)!=null&&o.length||r.push(u),i.levels.push(u)}else if(n[3]){const c=n[3],h=n[4];switch(c){case"SESSION-DATA":{const u=new Ae(h);We(i,u,["DATA-ID","LANGUAGE","VALUE","URI"]);const d=u["DATA-ID"];d&&(i.sessionData===null&&(i.sessionData={}),i.sessionData[d]=u);break}case"SESSION-KEY":{const u=Nn(h,t,i);u.encrypted&&u.isSupported()?(i.sessionKeys===null&&(i.sessionKeys=[]),i.sessionKeys.push(u)):b.warn(`[Keys] Ignoring invalid EXT-X-SESSION-KEY tag: "${h}"`);break}case"DEFINE":{{const u=new Ae(h);We(i,u,["NAME","VALUE","QUERYPARAM"]),kn(i,u,t)}break}case"CONTENT-STEERING":{const u=new Ae(h);We(i,u,["SERVER-URI","PATHWAY-ID"]),i.contentSteering={uri:ct.resolve(u["SERVER-URI"],t),pathwayId:u["PATHWAY-ID"]||"."};break}case"START":{i.startTimeOffset=Un(h);break}}}const l=r.length>0&&r.length<i.levels.length;return i.levels=l?r:i.levels,i.levels.length===0&&(i.playlistParsingError=new Error("no levels found in manifest")),i}static parseMasterPlaylistMedia(e,t,s){let i;const r={},n=s.levels,o={AUDIO:n.map(c=>({id:c.attrs.AUDIO,audioCodec:c.audioCodec})),SUBTITLES:n.map(c=>({id:c.attrs.SUBTITLES,textCodec:c.textCodec})),"CLOSED-CAPTIONS":[]};let l=0;for(Fn.lastIndex=0;(i=Fn.exec(e))!==null;){const c=new Ae(i[1]),h=c.TYPE;if(h){const u=o[h],d=r[h]||[];r[h]=d,We(s,c,["URI","GROUP-ID","LANGUAGE","ASSOC-LANGUAGE","STABLE-RENDITION-ID","NAME","INSTREAM-ID","CHARACTERISTICS","CHANNELS"]);const f=c.LANGUAGE,g=c["ASSOC-LANGUAGE"],m=c.CHANNELS,x=c.CHARACTERISTICS,T=c["INSTREAM-ID"],R={attrs:c,bitrate:0,id:l++,groupId:c["GROUP-ID"]||"",name:c.NAME||f||"",type:h,default:c.bool("DEFAULT"),autoselect:c.bool("AUTOSELECT"),forced:c.bool("FORCED"),lang:f,url:c.URI?ct.resolve(c.URI,t):""};if(g&&(R.assocLang=g),m&&(R.channels=m),x&&(R.characteristics=x),T&&(R.instreamId=T),u!=null&&u.length){const v=ct.findGroup(u,R.groupId)||u[0];Bn(R,v,"audioCodec"),Bn(R,v,"textCodec")}d.push(R)}}return r}static parseLevelPlaylist(e,t,s,i,r,n){const o=new Jl(t),l=o.fragments;let c=null,h=0,u=0,d=0,f=0,g=null,m=new ki(i,t),x,T,R,v=-1,D=!1,L=null;for(On.lastIndex=0,o.m3u8=e,o.hasVariableRefs=wn(e);(x=On.exec(e))!==null;){D&&(D=!1,m=new ki(i,t),m.start=d,m.sn=h,m.cc=f,m.level=s,c&&(m.initSegment=c,m.rawProgramDateTime=c.rawProgramDateTime,c.rawProgramDateTime=null,L&&(m.setByteRange(L),L=null)));const G=x[1];if(G){m.duration=parseFloat(G);const P=(" "+x[2]).slice(1);m.title=P||null,m.tagList.push(P?["INF",G,P]:["INF",G])}else if(x[3]){if(j(m.duration)){m.start=d,R&&Kn(m,R,o),m.sn=h,m.level=s,m.cc=f,l.push(m);const P=(" "+x[3]).slice(1);m.relurl=sr(o,P),$n(m,g),g=m,d+=m.duration,h++,u=0,D=!0}}else if(x[4]){const P=(" "+x[4]).slice(1);g?m.setByteRange(P,g):m.setByteRange(P)}else if(x[5])m.rawProgramDateTime=(" "+x[5]).slice(1),m.tagList.push(["PROGRAM-DATE-TIME",m.rawProgramDateTime]),v===-1&&(v=l.length);else{if(x=x[0].match(Nc),!x){b.warn("No matches on slow regex match for level playlist!");continue}for(T=1;T<x.length&&!(typeof x[T]<"u");T++);const P=(" "+x[T]).slice(1),U=(" "+x[T+1]).slice(1),ee=x[T+2]?(" "+x[T+2]).slice(1):"";switch(P){case"PLAYLIST-TYPE":o.type=U.toUpperCase();break;case"MEDIA-SEQUENCE":h=o.startSN=parseInt(U);break;case"SKIP":{const K=new Ae(U);We(o,K,["RECENTLY-REMOVED-DATERANGES"]);const se=K.decimalInteger("SKIPPED-SEGMENTS");if(j(se)){o.skippedSegments=se;for(let Y=se;Y--;)l.unshift(null);h+=se}const ie=K.enumeratedString("RECENTLY-REMOVED-DATERANGES");ie&&(o.recentlyRemovedDateranges=ie.split(" "));break}case"TARGETDURATION":o.targetduration=Math.max(parseInt(U),1);break;case"VERSION":o.version=parseInt(U);break;case"INDEPENDENT-SEGMENTS":case"EXTM3U":break;case"ENDLIST":o.live=!1;break;case"#":(U||ee)&&m.tagList.push(ee?[U,ee]:[U]);break;case"DISCONTINUITY":f++,m.tagList.push(["DIS"]);break;case"GAP":m.gap=!0,m.tagList.push([P]);break;case"BITRATE":m.tagList.push([P,U]);break;case"DATERANGE":{const K=new Ae(U);We(o,K,["ID","CLASS","START-DATE","END-DATE","SCTE35-CMD","SCTE35-OUT","SCTE35-IN"]),We(o,K,K.clientAttrs);const se=new Ca(K,o.dateRanges[K.ID]);se.isValid||o.skippedSegments?o.dateRanges[se.id]=se:b.warn(`Ignoring invalid DATERANGE tag: "${U}"`),m.tagList.push(["EXT-X-DATERANGE",U]);break}case"DEFINE":{{const K=new Ae(U);We(o,K,["NAME","VALUE","IMPORT","QUERYPARAM"]),"IMPORT"in K?wc(o,K,n):kn(o,K,t)}break}case"DISCONTINUITY-SEQUENCE":f=parseInt(U);break;case"KEY":{const K=Nn(U,t,o);if(K.isSupported()){if(K.method==="NONE"){R=void 0;break}R||(R={}),R[K.keyFormat]&&(R=we({},R)),R[K.keyFormat]=K}else b.warn(`[Keys] Ignoring invalid EXT-X-KEY tag: "${U}"`);break}case"START":o.startTimeOffset=Un(U);break;case"MAP":{const K=new Ae(U);if(We(o,K,["BYTERANGE","URI"]),m.duration){const se=new ki(i,t);Gn(se,K,s,R),c=se,m.initSegment=c,c.rawProgramDateTime&&!m.rawProgramDateTime&&(m.rawProgramDateTime=c.rawProgramDateTime)}else{const se=m.byteRangeEndOffset;if(se){const ie=m.byteRangeStartOffset;L=`${se-ie}@${ie}`}else L=null;Gn(m,K,s,R),c=m,D=!0}break}case"SERVER-CONTROL":{const K=new Ae(U);o.canBlockReload=K.bool("CAN-BLOCK-RELOAD"),o.canSkipUntil=K.optionalFloat("CAN-SKIP-UNTIL",0),o.canSkipDateRanges=o.canSkipUntil>0&&K.bool("CAN-SKIP-DATERANGES"),o.partHoldBack=K.optionalFloat("PART-HOLD-BACK",0),o.holdBack=K.optionalFloat("HOLD-BACK",0);break}case"PART-INF":{const K=new Ae(U);o.partTarget=K.decimalFloatingPoint("PART-TARGET");break}case"PART":{let K=o.partList;K||(K=o.partList=[]);const se=u>0?K[K.length-1]:void 0,ie=u++,Y=new Ae(U);We(o,Y,["BYTERANGE","URI"]);const le=new Xl(Y,m,t,ie,se);K.push(le),m.duration+=le.duration;break}case"PRELOAD-HINT":{const K=new Ae(U);We(o,K,["URI"]),o.preloadHint=K;break}case"RENDITION-REPORT":{const K=new Ae(U);We(o,K,["URI"]),o.renditionReports=o.renditionReports||[],o.renditionReports.push(K);break}default:b.warn(`line parsed but not handled: ${x}`);break}}}g&&!g.relurl?(l.pop(),d-=g.duration,o.partList&&(o.fragmentHint=g)):o.partList&&($n(m,g),m.cc=f,o.fragmentHint=m,R&&Kn(m,R,o));const _=l.length,k=l[0],B=l[_-1];if(d+=o.skippedSegments*o.targetduration,d>0&&_&&B){o.averagetargetduration=d/_;const G=B.sn;o.endSN=G!=="initSegment"?G:0,o.live||(B.endList=!0),k&&(o.startCC=k.cc)}else o.endSN=0,o.startCC=0;return o.fragmentHint&&(d+=o.fragmentHint.duration),o.totalduration=d,o.endCC=f,v>0&&Bc(l,v),o}}function Nn(a,e,t){var s,i;const r=new Ae(a);We(t,r,["KEYFORMAT","KEYFORMATVERSIONS","URI","IV","URI"]);const n=(s=r.METHOD)!=null?s:"",o=r.URI,l=r.hexadecimalInteger("IV"),c=r.KEYFORMATVERSIONS,h=(i=r.KEYFORMAT)!=null?i:"identity";o&&r.IV&&!l&&b.error(`Invalid IV: ${r.IV}`);const u=o?ct.resolve(o,e):"",d=(c||"1").split("/").map(Number).filter(Number.isFinite);return new Ts(n,u,h,d,l)}function Un(a){const t=new Ae(a).decimalFloatingPoint("TIME-OFFSET");return j(t)?t:null}function Uc(a,e){let t=(a||"").split(/[ ,]+/).filter(s=>s);["video","audio","text"].forEach(s=>{const i=t.filter(r=>_c(r,s));i.length&&(e[`${s}Codec`]=i.join(","),t=t.filter(r=>i.indexOf(r)===-1))}),e.unknownCodecs=t}function Bn(a,e,t){const s=e[t];s&&(a[t]=s)}function Bc(a,e){let t=a[e];for(let s=e;s--;){const i=a[s];if(!i)return;i.programDateTime=t.programDateTime-i.duration*1e3,t=i}}function $n(a,e){a.rawProgramDateTime?a.programDateTime=Date.parse(a.rawProgramDateTime):e!=null&&e.programDateTime&&(a.programDateTime=e.endProgramDateTime),j(a.programDateTime)||(a.programDateTime=null,a.rawProgramDateTime=null)}function Gn(a,e,t,s){a.relurl=e.URI,e.BYTERANGE&&a.setByteRange(e.BYTERANGE),a.level=t,a.sn="initSegment",s&&(a.levelkeys=s),a.initSegment=null}function Kn(a,e,t){a.levelkeys=e;const{encryptedFragments:s}=t;(!s.length||s[s.length-1].levelkeys!==e)&&Object.keys(e).some(i=>e[i].isCommonEncryption)&&s.push(a)}var ge={MANIFEST:"manifest",LEVEL:"level",AUDIO_TRACK:"audioTrack",SUBTITLE_TRACK:"subtitleTrack"},Q={MAIN:"main",AUDIO:"audio",SUBTITLE:"subtitle"};function Hn(a){const{type:e}=a;switch(e){case ge.AUDIO_TRACK:return Q.AUDIO;case ge.SUBTITLE_TRACK:return Q.SUBTITLE;default:return Q.MAIN}}function Ui(a,e){let t=a.url;return(t===void 0||t.indexOf("data:")===0)&&(t=e.url),t}class $c{constructor(e){this.hls=void 0,this.loaders=Object.create(null),this.variableList=null,this.hls=e,this.registerListeners()}startLoad(e){}stopLoad(){this.destroyInternalLoaders()}registerListeners(){const{hls:e}=this;e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.LEVEL_LOADING,this.onLevelLoading,this),e.on(p.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.on(p.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)}unregisterListeners(){const{hls:e}=this;e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.LEVEL_LOADING,this.onLevelLoading,this),e.off(p.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.off(p.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)}createInternalLoader(e){const t=this.hls.config,s=t.pLoader,i=t.loader,r=s||i,n=new r(t);return this.loaders[e.type]=n,n}getInternalLoader(e){return this.loaders[e.type]}resetInternalLoader(e){this.loaders[e]&&delete this.loaders[e]}destroyInternalLoaders(){for(const e in this.loaders){const t=this.loaders[e];t&&t.destroy(),this.resetInternalLoader(e)}}destroy(){this.variableList=null,this.unregisterListeners(),this.destroyInternalLoaders()}onManifestLoading(e,t){const{url:s}=t;this.variableList=null,this.load({id:null,level:0,responseType:"text",type:ge.MANIFEST,url:s,deliveryDirectives:null})}onLevelLoading(e,t){const{id:s,level:i,pathwayId:r,url:n,deliveryDirectives:o}=t;this.load({id:s,level:i,pathwayId:r,responseType:"text",type:ge.LEVEL,url:n,deliveryDirectives:o})}onAudioTrackLoading(e,t){const{id:s,groupId:i,url:r,deliveryDirectives:n}=t;this.load({id:s,groupId:i,level:null,responseType:"text",type:ge.AUDIO_TRACK,url:r,deliveryDirectives:n})}onSubtitleTrackLoading(e,t){const{id:s,groupId:i,url:r,deliveryDirectives:n}=t;this.load({id:s,groupId:i,level:null,responseType:"text",type:ge.SUBTITLE_TRACK,url:r,deliveryDirectives:n})}load(e){var t;const s=this.hls.config;let i=this.getInternalLoader(e);if(i){const c=i.context;if(c&&c.url===e.url&&c.level===e.level){b.trace("[playlist-loader]: playlist request ongoing");return}b.log(`[playlist-loader]: aborting previous loader for type: ${e.type}`),i.abort()}let r;if(e.type===ge.MANIFEST?r=s.manifestLoadPolicy.default:r=we({},s.playlistLoadPolicy.default,{timeoutRetry:null,errorRetry:null}),i=this.createInternalLoader(e),j((t=e.deliveryDirectives)==null?void 0:t.part)){let c;if(e.type===ge.LEVEL&&e.level!==null?c=this.hls.levels[e.level].details:e.type===ge.AUDIO_TRACK&&e.id!==null?c=this.hls.audioTracks[e.id].details:e.type===ge.SUBTITLE_TRACK&&e.id!==null&&(c=this.hls.subtitleTracks[e.id].details),c){const h=c.partTarget,u=c.targetduration;if(h&&u){const d=Math.max(h*3,u*.8)*1e3;r=we({},r,{maxTimeToFirstByteMs:Math.min(d,r.maxTimeToFirstByteMs),maxLoadTimeMs:Math.min(d,r.maxTimeToFirstByteMs)})}}}const n=r.errorRetry||r.timeoutRetry||{},o={loadPolicy:r,timeout:r.maxLoadTimeMs,maxRetry:n.maxNumRetry||0,retryDelay:n.retryDelayMs||0,maxRetryDelay:n.maxRetryDelayMs||0},l={onSuccess:(c,h,u,d)=>{const f=this.getInternalLoader(u);this.resetInternalLoader(u.type);const g=c.data;if(g.indexOf("#EXTM3U")!==0){this.handleManifestParsingError(c,u,new Error("no EXTM3U delimiter"),d||null,h);return}h.parsing.start=performance.now(),ct.isMediaPlaylist(g)?this.handleTrackOrLevelPlaylist(c,h,u,d||null,f):this.handleMasterPlaylist(c,h,u,d)},onError:(c,h,u,d)=>{this.handleNetworkError(h,u,!1,c,d)},onTimeout:(c,h,u)=>{this.handleNetworkError(h,u,!0,void 0,c)}};i.load(e,o,l)}handleMasterPlaylist(e,t,s,i){const r=this.hls,n=e.data,o=Ui(e,s),l=ct.parseMasterPlaylist(n,o);if(l.playlistParsingError){this.handleManifestParsingError(e,s,l.playlistParsingError,i,t);return}const{contentSteering:c,levels:h,sessionData:u,sessionKeys:d,startTimeOffset:f,variableList:g}=l;this.variableList=g;const{AUDIO:m=[],SUBTITLES:x,"CLOSED-CAPTIONS":T}=ct.parseMasterPlaylistMedia(n,o,l);m.length&&!m.some(v=>!v.url)&&h[0].audioCodec&&!h[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 Ae({}),bitrate:0,url:""})),r.trigger(p.MANIFEST_LOADED,{levels:h,audioTracks:m,subtitles:x,captions:T,contentSteering:c,url:o,stats:t,networkDetails:i,sessionData:u,sessionKeys:d,startTimeOffset:f,variableList:g})}handleTrackOrLevelPlaylist(e,t,s,i,r){const n=this.hls,{id:o,level:l,type:c}=s,h=Ui(e,s),u=0,d=j(l)?l:j(o)?o:0,f=Hn(s),g=ct.parseLevelPlaylist(e.data,h,d,f,u,this.variableList);if(c===ge.MANIFEST){const m={attrs:new Ae({}),bitrate:0,details:g,name:"",url:h};n.trigger(p.MANIFEST_LOADED,{levels:[m],audioTracks:[],url:h,stats:t,networkDetails:i,sessionData:null,sessionKeys:null,contentSteering:null,startTimeOffset:null,variableList:null})}t.parsing.end=performance.now(),s.levelDetails=g,this.handlePlaylistLoaded(g,e,t,s,i,r)}handleManifestParsingError(e,t,s,i,r){this.hls.trigger(p.ERROR,{type:Z.NETWORK_ERROR,details:w.MANIFEST_PARSING_ERROR,fatal:t.type===ge.MANIFEST,url:e.url,err:s,error:s,reason:s.message,response:e,context:t,networkDetails:i,stats:r})}handleNetworkError(e,t,s=!1,i,r){let n=`A network ${s?"timeout":"error"+(i?" (status "+i.code+")":"")} occurred while loading ${e.type}`;e.type===ge.LEVEL?n+=`: ${e.level} id: ${e.id}`:(e.type===ge.AUDIO_TRACK||e.type===ge.SUBTITLE_TRACK)&&(n+=` id: ${e.id} group-id: "${e.groupId}"`);const o=new Error(n);b.warn(`[playlist-loader]: ${n}`);let l=w.UNKNOWN,c=!1;const h=this.getInternalLoader(e);switch(e.type){case ge.MANIFEST:l=s?w.MANIFEST_LOAD_TIMEOUT:w.MANIFEST_LOAD_ERROR,c=!0;break;case ge.LEVEL:l=s?w.LEVEL_LOAD_TIMEOUT:w.LEVEL_LOAD_ERROR,c=!1;break;case ge.AUDIO_TRACK:l=s?w.AUDIO_TRACK_LOAD_TIMEOUT:w.AUDIO_TRACK_LOAD_ERROR,c=!1;break;case ge.SUBTITLE_TRACK:l=s?w.SUBTITLE_TRACK_LOAD_TIMEOUT:w.SUBTITLE_LOAD_ERROR,c=!1;break}h&&this.resetInternalLoader(e.type);const u={type:Z.NETWORK_ERROR,details:l,fatal:c,url:e.url,loader:h,context:e,error:o,networkDetails:t,stats:r};if(i){const d=(t==null?void 0:t.url)||e.url;u.response=Oe({url:d,data:void 0},i)}this.hls.trigger(p.ERROR,u)}handlePlaylistLoaded(e,t,s,i,r,n){const o=this.hls,{type:l,level:c,id:h,groupId:u,deliveryDirectives:d}=i,f=Ui(t,i),g=Hn(i),m=typeof i.level=="number"&&g===Q.MAIN?c:void 0;if(!e.fragments.length){const T=new Error("No Segments found in Playlist");o.trigger(p.ERROR,{type:Z.NETWORK_ERROR,details:w.LEVEL_EMPTY_ERROR,fatal:!1,url:f,error:T,reason:T.message,response:t,context:i,level:m,parent:g,networkDetails:r,stats:s});return}e.targetduration||(e.playlistParsingError=new Error("Missing Target Duration"));const x=e.playlistParsingError;if(x){o.trigger(p.ERROR,{type:Z.NETWORK_ERROR,details:w.LEVEL_PARSING_ERROR,fatal:!1,url:f,error:x,reason:x.message,response:t,context:i,level:m,parent:g,networkDetails:r,stats:s});return}switch(e.live&&n&&(n.getCacheAge&&(e.ageHeader=n.getCacheAge()||0),(!n.getCacheAge||isNaN(e.ageHeader))&&(e.ageHeader=0)),l){case ge.MANIFEST:case ge.LEVEL:o.trigger(p.LEVEL_LOADED,{details:e,level:m||0,id:h||0,stats:s,networkDetails:r,deliveryDirectives:d});break;case ge.AUDIO_TRACK:o.trigger(p.AUDIO_TRACK_LOADED,{details:e,id:h||0,groupId:u||"",stats:s,networkDetails:r,deliveryDirectives:d});break;case ge.SUBTITLE_TRACK:o.trigger(p.SUBTITLE_TRACK_LOADED,{details:e,id:h||0,groupId:u||"",stats:s,networkDetails:r,deliveryDirectives:d});break}}}function Va(a,e){let t;try{t=new Event("addtrack")}catch{t=document.createEvent("Event"),t.initEvent("addtrack",!1,!1)}t.track=a,e.dispatchEvent(t)}function ja(a,e){const t=a.mode;if(t==="disabled"&&(a.mode="hidden"),a.cues&&!a.cues.getCueById(e.id))try{if(a.addCue(e),!a.cues.getCueById(e.id))throw new Error(`addCue is failed for: ${e}`)}catch(s){b.debug(`[texttrack-utils]: ${s}`);try{const i=new self.TextTrackCue(e.startTime,e.endTime,e.text);i.id=e.id,a.addCue(i)}catch(i){b.debug(`[texttrack-utils]: Legacy TextTrackCue fallback failed: ${i}`)}}t==="disabled"&&(a.mode=t)}function zt(a){const e=a.mode;if(e==="disabled"&&(a.mode="hidden"),a.cues)for(let t=a.cues.length;t--;)a.removeCue(a.cues[t]);e==="disabled"&&(a.mode=e)}function ir(a,e,t,s){const i=a.mode;if(i==="disabled"&&(a.mode="hidden"),a.cues&&a.cues.length>0){const r=Kc(a.cues,e,t);for(let n=0;n<r.length;n++)(!s||s(r[n]))&&a.removeCue(r[n])}i==="disabled"&&(a.mode=i)}function Gc(a,e){if(e<a[0].startTime)return 0;const t=a.length-1;if(e>a[t].endTime)return-1;let s=0,i=t;for(;s<=i;){const r=Math.floor((i+s)/2);if(e<a[r].startTime)i=r-1;else if(e>a[r].startTime&&s<t)s=r+1;else return r}return a[s].startTime-e<e-a[i].startTime?s:i}function Kc(a,e,t){const s=[],i=Gc(a,e);if(i>-1)for(let r=i,n=a.length;r<n;r++){const o=a[r];if(o.startTime>=e&&o.endTime<=t)s.push(o);else if(o.startTime>t)return s}return s}function Vs(a){const e=[];for(let t=0;t<a.length;t++){const s=a[t];(s.kind==="subtitles"||s.kind==="captions")&&s.label&&e.push(a[t])}return e}var it={audioId3:"org.id3",dateRange:"com.apple.quicktime.HLS",emsg:"https://aomedia.org/emsg/ID3"};const Hc=.25;function rr(){if(!(typeof self>"u"))return self.VTTCue||self.TextTrackCue}function Vn(a,e,t,s,i){let r=new a(e,t,"");try{r.value=s,i&&(r.type=i)}catch{r=new a(e,t,JSON.stringify(i?Oe({type:i},s):s))}return r}const Fs=(()=>{const a=rr();try{a&&new a(0,Number.POSITIVE_INFINITY,"")}catch{return Number.MAX_VALUE}return Number.POSITIVE_INFINITY})();function Bi(a,e){return a.getTime()/1e3-e}function Vc(a){return Uint8Array.from(a.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer}class jc{constructor(e){this.hls=void 0,this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=e,this._registerListeners()}destroy(){this._unregisterListeners(),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=null}_registerListeners(){const{hls:e}=this;e.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.on(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(p.LEVEL_UPDATED,this.onLevelUpdated,this)}_unregisterListeners(){const{hls:e}=this;e.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.off(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(p.LEVEL_UPDATED,this.onLevelUpdated,this)}onMediaAttached(e,t){this.media=t.media}onMediaDetaching(){this.id3Track&&(zt(this.id3Track),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={})}onManifestLoading(){this.dateRangeCuesAppended={}}createTrack(e){const t=this.getID3Track(e.textTracks);return t.mode="hidden",t}getID3Track(e){if(this.media){for(let t=0;t<e.length;t++){const s=e[t];if(s.kind==="metadata"&&s.label==="id3")return Va(s,this.media),s}return this.media.addTextTrack("metadata","id3")}}onFragParsingMetadata(e,t){if(!this.media)return;const{hls:{config:{enableEmsgMetadataCues:s,enableID3MetadataCues:i}}}=this;if(!s&&!i)return;const{samples:r}=t;this.id3Track||(this.id3Track=this.createTrack(this.media));const n=rr();if(n)for(let o=0;o<r.length;o++){const l=r[o].type;if(l===it.emsg&&!s||!i)continue;const c=Ma(r[o].data);if(c){const h=r[o].pts;let u=h+r[o].duration;u>Fs&&(u=Fs),u-h<=0&&(u=h+Hc);for(let f=0;f<c.length;f++){const g=c[f];if(!Pa(g)){this.updateId3CueEnds(h,l);const m=Vn(n,h,u,g,l);m&&this.id3Track.addCue(m)}}}}}updateId3CueEnds(e,t){var s;const i=(s=this.id3Track)==null?void 0:s.cues;if(i)for(let r=i.length;r--;){const n=i[r];n.type===t&&n.startTime<e&&n.endTime===Fs&&(n.endTime=e)}}onBufferFlushing(e,{startOffset:t,endOffset:s,type:i}){const{id3Track:r,hls:n}=this;if(!n)return;const{config:{enableEmsgMetadataCues:o,enableID3MetadataCues:l}}=n;if(r&&(o||l)){let c;i==="audio"?c=h=>h.type===it.audioId3&&l:i==="video"?c=h=>h.type===it.emsg&&o:c=h=>h.type===it.audioId3&&l||h.type===it.emsg&&o,ir(r,t,s,c)}}onLevelUpdated(e,{details:t}){if(!this.media||!t.hasProgramDateTime||!this.hls.config.enableDateRangeMetadataCues)return;const{dateRangeCuesAppended:s,id3Track:i}=this,{dateRanges:r}=t,n=Object.keys(r);if(i){const h=Object.keys(s).filter(u=>!n.includes(u));for(let u=h.length;u--;){const d=h[u];Object.keys(s[d].cues).forEach(f=>{i.removeCue(s[d].cues[f])}),delete s[d]}}const o=t.fragments[t.fragments.length-1];if(n.length===0||!j(o==null?void 0:o.programDateTime))return;this.id3Track||(this.id3Track=this.createTrack(this.media));const l=o.programDateTime/1e3-o.start,c=rr();for(let h=0;h<n.length;h++){const u=n[h],d=r[u],f=Bi(d.startDate,l),g=s[u],m=(g==null?void 0:g.cues)||{};let x=(g==null?void 0:g.durationKnown)||!1,T=Fs;const R=d.endDate;if(R)T=Bi(R,l),x=!0;else if(d.endOnNext&&!x){const D=n.reduce((L,_)=>{if(_!==d.id){const k=r[_];if(k.class===d.class&&k.startDate>d.startDate&&(!L||d.startDate<L.startDate))return k}return L},null);D&&(T=Bi(D.startDate,l),x=!0)}const v=Object.keys(d.attr);for(let D=0;D<v.length;D++){const L=v[D];if(!ql(L))continue;const _=m[L];if(_)x&&!g.durationKnown&&(_.endTime=T);else if(c){let k=d.attr[L];zl(L)&&(k=Vc(k));const B=Vn(c,f,T,{key:L,data:k},it.dateRange);B&&(B.id=u,this.id3Track.addCue(B),m[L]=B)}}s[u]={cues:m,dateRange:d,durationKnown:x}}}}class Wc{constructor(e){this.hls=void 0,this.config=void 0,this.media=null,this.levelDetails=null,this.currentTime=0,this.stallCount=0,this._latency=null,this.timeupdateHandler=()=>this.timeupdate(),this.hls=e,this.config=e.config,this.registerListeners()}get latency(){return this._latency||0}get maxLatency(){const{config:e,levelDetails:t}=this;return e.liveMaxLatencyDuration!==void 0?e.liveMaxLatencyDuration:t?e.liveMaxLatencyDurationCount*t.targetduration:0}get targetLatency(){const{levelDetails:e}=this;if(e===null)return null;const{holdBack:t,partHoldBack:s,targetduration:i}=e,{liveSyncDuration:r,liveSyncDurationCount:n,lowLatencyMode:o}=this.config,l=this.hls.userConfig;let c=o&&s||t;(l.liveSyncDuration||l.liveSyncDurationCount||c===0)&&(c=r!==void 0?r:n*i);const h=i;return c+Math.min(this.stallCount*1,h)}get liveSyncPosition(){const e=this.estimateLiveEdge(),t=this.targetLatency,s=this.levelDetails;if(e===null||t===null||s===null)return null;const i=s.edge,r=e-t-this.edgeStalled,n=i-s.totalduration,o=i-(this.config.lowLatencyMode&&s.partTarget||s.targetduration);return Math.min(Math.max(n,r),o)}get drift(){const{levelDetails:e}=this;return e===null?1:e.drift}get edgeStalled(){const{levelDetails:e}=this;if(e===null)return 0;const t=(this.config.lowLatencyMode&&e.partTarget||e.targetduration)*3;return Math.max(e.age-t,0)}get forwardBufferLength(){const{media:e,levelDetails:t}=this;if(!e||!t)return 0;const s=e.buffered.length;return(s?e.buffered.end(s-1):t.edge)-this.currentTime}destroy(){this.unregisterListeners(),this.onMediaDetaching(),this.levelDetails=null,this.hls=this.timeupdateHandler=null}registerListeners(){this.hls.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.on(p.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(p.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.on(p.ERROR,this.onError,this)}unregisterListeners(){this.hls.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.off(p.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(p.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.off(p.ERROR,this.onError,this)}onMediaAttached(e,t){this.media=t.media,this.media.addEventListener("timeupdate",this.timeupdateHandler)}onMediaDetaching(){this.media&&(this.media.removeEventListener("timeupdate",this.timeupdateHandler),this.media=null)}onManifestLoading(){this.levelDetails=null,this._latency=null,this.stallCount=0}onLevelUpdated(e,{details:t}){this.levelDetails=t,t.advanced&&this.timeupdate(),!t.live&&this.media&&this.media.removeEventListener("timeupdate",this.timeupdateHandler)}onError(e,t){var s;t.details===w.BUFFER_STALLED_ERROR&&(this.stallCount++,(s=this.levelDetails)!=null&&s.live&&b.warn("[playback-rate-controller]: Stall detected, adjusting target latency"))}timeupdate(){const{media:e,levelDetails:t}=this;if(!e||!t)return;this.currentTime=e.currentTime;const s=this.computeLatency();if(s===null)return;this._latency=s;const{lowLatencyMode:i,maxLiveSyncPlaybackRate:r}=this.config;if(!i||r===1||!t.live)return;const n=this.targetLatency;if(n===null)return;const o=s-n,l=Math.min(this.maxLatency,n+t.targetduration);if(o<l&&o>.05&&this.forwardBufferLength>1){const h=Math.min(2,Math.max(1,r)),u=Math.round(2/(1+Math.exp(-.75*o-this.edgeStalled))*20)/20;e.playbackRate=Math.min(h,Math.max(1,u))}else e.playbackRate!==1&&e.playbackRate!==0&&(e.playbackRate=1)}estimateLiveEdge(){const{levelDetails:e}=this;return e===null?null:e.edge+e.age}computeLatency(){const e=this.estimateLiveEdge();return e===null?null:e-this.currentTime}}const nr=["NONE","TYPE-0","TYPE-1",null];function Yc(a){return nr.indexOf(a)>-1}const ii=["SDR","PQ","HLG"];function qc(a){return!!a&&ii.indexOf(a)>-1}var js={No:"",Yes:"YES",v2:"v2"};function jn(a){const{canSkipUntil:e,canSkipDateRanges:t,age:s}=a,i=s<e/2;return e&&i?t?js.v2:js.Yes:js.No}class Wn{constructor(e,t,s){this.msn=void 0,this.part=void 0,this.skip=void 0,this.msn=e,this.part=t,this.skip=s}addDirectives(e){const t=new self.URL(e);return this.msn!==void 0&&t.searchParams.set("_HLS_msn",this.msn.toString()),this.part!==void 0&&t.searchParams.set("_HLS_part",this.part.toString()),this.skip&&t.searchParams.set("_HLS_skip",this.skip),t.href}}class Zt{constructor(e){this._attrs=void 0,this.audioCodec=void 0,this.bitrate=void 0,this.codecSet=void 0,this.url=void 0,this.frameRate=void 0,this.height=void 0,this.id=void 0,this.name=void 0,this.videoCodec=void 0,this.width=void 0,this.details=void 0,this.fragmentError=0,this.loadError=0,this.loaded=void 0,this.realBitrate=0,this.supportedPromise=void 0,this.supportedResult=void 0,this._avgBitrate=0,this._audioGroups=void 0,this._subtitleGroups=void 0,this._urlId=0,this.url=[e.url],this._attrs=[e.attrs],this.bitrate=e.bitrate,e.details&&(this.details=e.details),this.id=e.id||0,this.name=e.name,this.width=e.width||0,this.height=e.height||0,this.frameRate=e.attrs.optionalFloat("FRAME-RATE",0),this._avgBitrate=e.attrs.decimalInteger("AVERAGE-BANDWIDTH"),this.audioCodec=e.audioCodec,this.videoCodec=e.videoCodec,this.codecSet=[e.videoCodec,e.audioCodec].filter(t=>!!t).map(t=>t.substring(0,4)).join(","),this.addGroupId("audio",e.attrs.AUDIO),this.addGroupId("text",e.attrs.SUBTITLES)}get maxBitrate(){return Math.max(this.realBitrate,this.bitrate)}get averageBitrate(){return this._avgBitrate||this.realBitrate||this.bitrate}get attrs(){return this._attrs[0]}get codecs(){return this.attrs.CODECS||""}get pathwayId(){return this.attrs["PATHWAY-ID"]||"."}get videoRange(){return this.attrs["VIDEO-RANGE"]||"SDR"}get score(){return this.attrs.optionalFloat("SCORE",0)}get uri(){return this.url[0]||""}hasAudioGroup(e){return Yn(this._audioGroups,e)}hasSubtitleGroup(e){return Yn(this._subtitleGroups,e)}get audioGroups(){return this._audioGroups}get subtitleGroups(){return this._subtitleGroups}addGroupId(e,t){if(t){if(e==="audio"){let s=this._audioGroups;s||(s=this._audioGroups=[]),s.indexOf(t)===-1&&s.push(t)}else if(e==="text"){let s=this._subtitleGroups;s||(s=this._subtitleGroups=[]),s.indexOf(t)===-1&&s.push(t)}}}get urlId(){return 0}set urlId(e){}get audioGroupIds(){return this.audioGroups?[this.audioGroupId]:void 0}get textGroupIds(){return this.subtitleGroups?[this.textGroupId]:void 0}get audioGroupId(){var e;return(e=this.audioGroups)==null?void 0:e[0]}get textGroupId(){var e;return(e=this.subtitleGroups)==null?void 0:e[0]}addFallback(){}}function Yn(a,e){return!e||!a?!1:a.indexOf(e)!==-1}function $i(a,e){const t=e.startPTS;if(j(t)){let s=0,i;e.sn>a.sn?(s=t-a.start,i=a):(s=a.start-t,i=e),i.duration!==s&&(i.duration=s)}else e.sn>a.sn?a.cc===e.cc&&a.minEndPTS?e.start=a.start+(a.minEndPTS-a.start):e.start=a.start+a.duration:e.start=Math.max(a.start-e.duration,0)}function Wa(a,e,t,s,i,r){s-t<=0&&(b.warn("Fragment should have a positive duration",e),s=t+e.duration,r=i+e.duration);let o=t,l=s;const c=e.startPTS,h=e.endPTS;if(j(c)){const x=Math.abs(c-t);j(e.deltaPTS)?e.deltaPTS=Math.max(x,e.deltaPTS):e.deltaPTS=x,o=Math.max(t,c),t=Math.min(t,c),i=Math.min(i,e.startDTS),l=Math.min(s,h),s=Math.max(s,h),r=Math.max(r,e.endDTS)}const u=t-e.start;e.start!==0&&(e.start=t),e.duration=s-e.start,e.startPTS=t,e.maxStartPTS=o,e.startDTS=i,e.endPTS=s,e.minEndPTS=l,e.endDTS=r;const d=e.sn;if(!a||d<a.startSN||d>a.endSN)return 0;let f;const g=d-a.startSN,m=a.fragments;for(m[g]=e,f=g;f>0;f--)$i(m[f],m[f-1]);for(f=g;f<m.length-1;f++)$i(m[f],m[f+1]);return a.fragmentHint&&$i(m[m.length-1],a.fragmentHint),a.PTSKnown=a.alignedSliding=!0,u}function zc(a,e){let t=null;const s=a.fragments;for(let l=s.length-1;l>=0;l--){const c=s[l].initSegment;if(c){t=c;break}}a.fragmentHint&&delete a.fragmentHint.endPTS;let i=0,r;if(Jc(a,e,(l,c)=>{l.relurl&&(i=l.cc-c.cc),j(l.startPTS)&&j(l.endPTS)&&(c.start=c.startPTS=l.startPTS,c.startDTS=l.startDTS,c.maxStartPTS=l.maxStartPTS,c.endPTS=l.endPTS,c.endDTS=l.endDTS,c.minEndPTS=l.minEndPTS,c.duration=l.endPTS-l.startPTS,c.duration&&(r=c),e.PTSKnown=e.alignedSliding=!0),c.elementaryStreams=l.elementaryStreams,c.loader=l.loader,c.stats=l.stats,l.initSegment&&(c.initSegment=l.initSegment,t=l.initSegment)}),t&&(e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments).forEach(c=>{var h;c&&(!c.initSegment||c.initSegment.relurl===((h=t)==null?void 0:h.relurl))&&(c.initSegment=t)}),e.skippedSegments)if(e.deltaUpdateFailed=e.fragments.some(l=>!l),e.deltaUpdateFailed){b.warn("[level-helper] Previous playlist missing segments skipped in delta playlist");for(let l=e.skippedSegments;l--;)e.fragments.shift();e.startSN=e.fragments[0].sn,e.startCC=e.fragments[0].cc}else e.canSkipDateRanges&&(e.dateRanges=Xc(a.dateRanges,e.dateRanges,e.recentlyRemovedDateranges));const n=e.fragments;if(i){b.warn("discontinuity sliding from playlist, take drift into account");for(let l=0;l<n.length;l++)n[l].cc+=i}e.skippedSegments&&(e.startCC=e.fragments[0].cc),Qc(a.partList,e.partList,(l,c)=>{c.elementaryStreams=l.elementaryStreams,c.stats=l.stats}),r?Wa(e,r,r.startPTS,r.endPTS,r.startDTS,r.endDTS):Ya(a,e),n.length&&(e.totalduration=e.edge-n[0].start),e.driftStartTime=a.driftStartTime,e.driftStart=a.driftStart;const o=e.advancedDateTime;if(e.advanced&&o){const l=e.edge;e.driftStart||(e.driftStartTime=o,e.driftStart=l),e.driftEndTime=o,e.driftEnd=l}else e.driftEndTime=a.driftEndTime,e.driftEnd=a.driftEnd,e.advancedDateTime=a.advancedDateTime}function Xc(a,e,t){const s=we({},a);return t&&t.forEach(i=>{delete s[i]}),Object.keys(e).forEach(i=>{const r=new Ca(e[i].attr,s[i]);r.isValid?s[i]=r:b.warn(`Ignoring invalid Playlist Delta Update DATERANGE tag: "${JSON.stringify(e[i].attr)}"`)}),s}function Qc(a,e,t){if(a&&e){let s=0;for(let i=0,r=a.length;i<=r;i++){const n=a[i],o=e[i+s];n&&o&&n.index===o.index&&n.fragment.sn===o.fragment.sn?t(n,o):s--}}}function Jc(a,e,t){const s=e.skippedSegments,i=Math.max(a.startSN,e.startSN)-e.startSN,r=(a.fragmentHint?1:0)+(s?e.endSN:Math.min(a.endSN,e.endSN))-e.startSN,n=e.startSN-a.startSN,o=e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments,l=a.fragmentHint?a.fragments.concat(a.fragmentHint):a.fragments;for(let c=i;c<=r;c++){const h=l[n+c];let u=o[c];s&&!u&&c<s&&(u=e.fragments[c]=h),h&&u&&t(h,u)}}function Ya(a,e){const t=e.startSN+e.skippedSegments-a.startSN,s=a.fragments;t<0||t>=s.length||ar(e,s[t].start)}function ar(a,e){if(e){const t=a.fragments;for(let s=a.skippedSegments;s<t.length;s++)t[s].start+=e;a.fragmentHint&&(a.fragmentHint.start+=e)}}function Zc(a,e=1/0){let t=1e3*a.targetduration;if(a.updated){const s=a.fragments;if(s.length&&t*4>e){const r=s[s.length-1].duration*1e3;r<t&&(t=r)}}else t/=2;return Math.round(t)}function eh(a,e,t){if(!(a!=null&&a.details))return null;const s=a.details;let i=s.fragments[e-s.startSN];return i||(i=s.fragmentHint,i&&i.sn===e)?i:e<s.startSN&&t&&t.sn===e?t:null}function qn(a,e,t){var s;return a!=null&&a.details?qa((s=a.details)==null?void 0:s.partList,e,t):null}function qa(a,e,t){if(a)for(let s=a.length;s--;){const i=a[s];if(i.index===t&&i.fragment.sn===e)return i}return null}function za(a){a.forEach((e,t)=>{const{details:s}=e;s!=null&&s.fragments&&s.fragments.forEach(i=>{i.level=t})})}function ri(a){switch(a.details){case w.FRAG_LOAD_TIMEOUT:case w.KEY_LOAD_TIMEOUT:case w.LEVEL_LOAD_TIMEOUT:case w.MANIFEST_LOAD_TIMEOUT:return!0}return!1}function zn(a,e){const t=ri(e);return a.default[`${t?"timeout":"error"}Retry`]}function vr(a,e){const t=a.backoff==="linear"?1:Math.pow(2,e);return Math.min(t*a.retryDelayMs,a.maxRetryDelayMs)}function Xn(a){return Oe(Oe({},a),{errorRetry:null,timeoutRetry:null})}function ni(a,e,t,s){if(!a)return!1;const i=s==null?void 0:s.code,r=e<a.maxNumRetry&&(th(i)||!!t);return a.shouldRetry?a.shouldRetry(a,e,t,s,r):r}function th(a){return a===0&&navigator.onLine===!1||!!a&&(a<400||a>499)}const Xa={search:function(a,e){let t=0,s=a.length-1,i=null,r=null;for(;t<=s;){i=(t+s)/2|0,r=a[i];const n=e(r);if(n>0)t=i+1;else if(n<0)s=i-1;else return r}return null}};function sh(a,e,t){if(e===null||!Array.isArray(a)||!a.length||!j(e))return null;const s=a[0].programDateTime;if(e<(s||0))return null;const i=a[a.length-1].endProgramDateTime;if(e>=(i||0))return null;t=t||0;for(let r=0;r<a.length;++r){const n=a[r];if(rh(e,t,n))return n}return null}function ai(a,e,t=0,s=0,i=.005){let r=null;if(a){r=e[a.sn-e[0].sn+1]||null;const o=a.endDTS-t;o>0&&o<15e-7&&(t+=15e-7)}else t===0&&e[0].start===0&&(r=e[0]);if(r&&((!a||a.level===r.level)&&or(t,s,r)===0||ih(r,a,Math.min(i,s))))return r;const n=Xa.search(e,or.bind(null,t,s));return n&&(n!==a||!r)?n:r}function ih(a,e,t){if(e&&e.start===0&&e.level<a.level&&(e.endPTS||0)>0){const s=e.tagList.reduce((i,r)=>(r[0]==="INF"&&(i+=parseFloat(r[1])),i),t);return a.start<=s}return!1}function or(a=0,e=0,t){if(t.start<=a&&t.start+t.duration>a)return 0;const s=Math.min(e,t.duration+(t.deltaPTS?t.deltaPTS:0));return t.start+t.duration-s<=a?1:t.start-s>a&&t.start?-1:0}function rh(a,e,t){const s=Math.min(e,t.duration+(t.deltaPTS?t.deltaPTS:0))*1e3;return(t.endProgramDateTime||0)-s>a}function nh(a,e){return Xa.search(a,t=>t.cc<e?1:t.cc>e?-1:0)}var Be={DoNothing:0,SendEndCallback:1,SendAlternateToPenaltyBox:2,RemoveAlternatePermanently:3,InsertDiscontinuity:4,RetryRequest:5},tt={None:0,MoveAllAlternatesMatchingHost:1,MoveAllAlternatesMatchingHDCP:2,SwitchToSDR:4};class ah{constructor(e){this.hls=void 0,this.playlistError=0,this.penalizedRenditions={},this.log=void 0,this.warn=void 0,this.error=void 0,this.hls=e,this.log=b.log.bind(b,"[info]:"),this.warn=b.warn.bind(b,"[warning]:"),this.error=b.error.bind(b,"[error]:"),this.registerListeners()}registerListeners(){const e=this.hls;e.on(p.ERROR,this.onError,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.LEVEL_UPDATED,this.onLevelUpdated,this)}unregisterListeners(){const e=this.hls;e&&(e.off(p.ERROR,this.onError,this),e.off(p.ERROR,this.onErrorOut,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.LEVEL_UPDATED,this.onLevelUpdated,this))}destroy(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}}startLoad(e){}stopLoad(){this.playlistError=0}getVariantLevelIndex(e){return(e==null?void 0:e.type)===Q.MAIN?e.level:this.hls.loadLevel}onManifestLoading(){this.playlistError=0,this.penalizedRenditions={}}onLevelUpdated(){this.playlistError=0}onError(e,t){var s,i;if(t.fatal)return;const r=this.hls,n=t.context;switch(t.details){case w.FRAG_LOAD_ERROR:case w.FRAG_LOAD_TIMEOUT:case w.KEY_LOAD_ERROR:case w.KEY_LOAD_TIMEOUT:t.errorAction=this.getFragRetryOrSwitchAction(t);return;case w.FRAG_PARSING_ERROR:if((s=t.frag)!=null&&s.gap){t.errorAction={action:Be.DoNothing,flags:tt.None};return}case w.FRAG_GAP:case w.FRAG_DECRYPT_ERROR:{t.errorAction=this.getFragRetryOrSwitchAction(t),t.errorAction.action=Be.SendAlternateToPenaltyBox;return}case w.LEVEL_EMPTY_ERROR:case w.LEVEL_PARSING_ERROR:{var o,l;const c=t.parent===Q.MAIN?t.level:r.loadLevel;t.details===w.LEVEL_EMPTY_ERROR&&((o=t.context)!=null&&(l=o.levelDetails)!=null&&l.live)?t.errorAction=this.getPlaylistRetryOrSwitchAction(t,c):(t.levelRetry=!1,t.errorAction=this.getLevelSwitchAction(t,c))}return;case w.LEVEL_LOAD_ERROR:case w.LEVEL_LOAD_TIMEOUT:typeof(n==null?void 0:n.level)=="number"&&(t.errorAction=this.getPlaylistRetryOrSwitchAction(t,n.level));return;case w.AUDIO_TRACK_LOAD_ERROR:case w.AUDIO_TRACK_LOAD_TIMEOUT:case w.SUBTITLE_LOAD_ERROR:case w.SUBTITLE_TRACK_LOAD_TIMEOUT:if(n){const c=r.levels[r.loadLevel];if(c&&(n.type===ge.AUDIO_TRACK&&c.hasAudioGroup(n.groupId)||n.type===ge.SUBTITLE_TRACK&&c.hasSubtitleGroup(n.groupId))){t.errorAction=this.getPlaylistRetryOrSwitchAction(t,r.loadLevel),t.errorAction.action=Be.SendAlternateToPenaltyBox,t.errorAction.flags=tt.MoveAllAlternatesMatchingHost;return}}return;case w.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:{const c=r.levels[r.loadLevel],h=c==null?void 0:c.attrs["HDCP-LEVEL"];h?t.errorAction={action:Be.SendAlternateToPenaltyBox,flags:tt.MoveAllAlternatesMatchingHDCP,hdcpLevel:h}:this.keySystemError(t)}return;case w.BUFFER_ADD_CODEC_ERROR:case w.REMUX_ALLOC_ERROR:case w.BUFFER_APPEND_ERROR:t.errorAction=this.getLevelSwitchAction(t,(i=t.level)!=null?i:r.loadLevel);return;case w.INTERNAL_EXCEPTION:case w.BUFFER_APPENDING_ERROR:case w.BUFFER_FULL_ERROR:case w.LEVEL_SWITCH_ERROR:case w.BUFFER_STALLED_ERROR:case w.BUFFER_SEEK_OVER_HOLE:case w.BUFFER_NUDGE_ON_STALL:t.errorAction={action:Be.DoNothing,flags:tt.None};return}t.type===Z.KEY_SYSTEM_ERROR&&this.keySystemError(t)}keySystemError(e){const t=this.getVariantLevelIndex(e.frag);e.levelRetry=!1,e.errorAction=this.getLevelSwitchAction(e,t)}getPlaylistRetryOrSwitchAction(e,t){const s=this.hls,i=zn(s.config.playlistLoadPolicy,e),r=this.playlistError++;if(ni(i,r,ri(e),e.response))return{action:Be.RetryRequest,flags:tt.None,retryConfig:i,retryCount:r};const o=this.getLevelSwitchAction(e,t);return i&&(o.retryConfig=i,o.retryCount=r),o}getFragRetryOrSwitchAction(e){const t=this.hls,s=this.getVariantLevelIndex(e.frag),i=t.levels[s],{fragLoadPolicy:r,keyLoadPolicy:n}=t.config,o=zn(e.details.startsWith("key")?n:r,e),l=t.levels.reduce((h,u)=>h+u.fragmentError,0);if(i&&(e.details!==w.FRAG_GAP&&i.fragmentError++,ni(o,l,ri(e),e.response)))return{action:Be.RetryRequest,flags:tt.None,retryConfig:o,retryCount:l};const c=this.getLevelSwitchAction(e,s);return o&&(c.retryConfig=o,c.retryCount=l),c}getLevelSwitchAction(e,t){const s=this.hls;t==null&&(t=s.loadLevel);const i=this.hls.levels[t];if(i){var r,n;const c=e.details;i.loadError++,c===w.BUFFER_APPEND_ERROR&&i.fragmentError++;let h=-1;const{levels:u,loadLevel:d,minAutoLevel:f,maxAutoLevel:g}=s;s.autoLevelEnabled||(s.loadLevel=-1);const m=(r=e.frag)==null?void 0:r.type,T=(m===Q.AUDIO&&c===w.FRAG_PARSING_ERROR||e.sourceBufferName==="audio"&&(c===w.BUFFER_ADD_CODEC_ERROR||c===w.BUFFER_APPEND_ERROR))&&u.some(({audioCodec:_})=>i.audioCodec!==_),v=e.sourceBufferName==="video"&&(c===w.BUFFER_ADD_CODEC_ERROR||c===w.BUFFER_APPEND_ERROR)&&u.some(({codecSet:_,audioCodec:k})=>i.codecSet!==_&&i.audioCodec===k),{type:D,groupId:L}=(n=e.context)!=null?n:{};for(let _=u.length;_--;){const k=(_+d)%u.length;if(k!==d&&k>=f&&k<=g&&u[k].loadError===0){var o,l;const B=u[k];if(c===w.FRAG_GAP&&m===Q.MAIN&&e.frag){const G=u[k].details;if(G){const P=ai(e.frag,G.fragments,e.frag.start);if(P!=null&&P.gap)continue}}else{if(D===ge.AUDIO_TRACK&&B.hasAudioGroup(L)||D===ge.SUBTITLE_TRACK&&B.hasSubtitleGroup(L))continue;if(m===Q.AUDIO&&(o=i.audioGroups)!=null&&o.some(G=>B.hasAudioGroup(G))||m===Q.SUBTITLE&&(l=i.subtitleGroups)!=null&&l.some(G=>B.hasSubtitleGroup(G))||T&&i.audioCodec===B.audioCodec||!T&&i.audioCodec!==B.audioCodec||v&&i.codecSet===B.codecSet)continue}h=k;break}}if(h>-1&&s.loadLevel!==h)return e.levelRetry=!0,this.playlistError=0,{action:Be.SendAlternateToPenaltyBox,flags:tt.None,nextAutoLevel:h}}return{action:Be.SendAlternateToPenaltyBox,flags:tt.MoveAllAlternatesMatchingHost}}onErrorOut(e,t){var s;switch((s=t.errorAction)==null?void 0:s.action){case Be.DoNothing:break;case Be.SendAlternateToPenaltyBox:this.sendAlternateToPenaltyBox(t),!t.errorAction.resolved&&t.details!==w.FRAG_GAP?t.fatal=!0:/MediaSource readyState: ended/.test(t.error.message)&&(this.warn(`MediaSource ended after "${t.sourceBufferName}" sourceBuffer append error. Attempting to recover from media error.`),this.hls.recoverMediaError());break}if(t.fatal){this.hls.stopLoad();return}}sendAlternateToPenaltyBox(e){const t=this.hls,s=e.errorAction;if(!s)return;const{flags:i,hdcpLevel:r,nextAutoLevel:n}=s;switch(i){case tt.None:this.switchLevel(e,n);break;case tt.MoveAllAlternatesMatchingHDCP:r&&(t.maxHdcpLevel=nr[nr.indexOf(r)-1],s.resolved=!0),this.warn(`Restricting playback to HDCP-LEVEL of "${t.maxHdcpLevel}" or lower`);break}s.resolved||this.switchLevel(e,n)}switchLevel(e,t){t!==void 0&&e.errorAction&&(this.warn(`switching to level ${t} after ${e.details}`),this.hls.nextAutoLevel=t,e.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel)}}class Ar{constructor(e,t){this.hls=void 0,this.timer=-1,this.requestScheduled=-1,this.canLoad=!1,this.log=void 0,this.warn=void 0,this.log=b.log.bind(b,`${t}:`),this.warn=b.warn.bind(b,`${t}:`),this.hls=e}destroy(){this.clearTimer(),this.hls=this.log=this.warn=null}clearTimer(){this.timer!==-1&&(self.clearTimeout(this.timer),this.timer=-1)}startLoad(){this.canLoad=!0,this.requestScheduled=-1,this.loadPlaylist()}stopLoad(){this.canLoad=!1,this.clearTimer()}switchParams(e,t,s){const i=t==null?void 0:t.renditionReports;if(i){let r=-1;for(let n=0;n<i.length;n++){const o=i[n];let l;try{l=new self.URL(o.URI,t.url).href}catch(c){b.warn(`Could not construct new URL for Rendition Report: ${c}`),l=o.URI||""}if(l===e){r=n;break}else l===e.substring(0,l.length)&&(r=n)}if(r!==-1){const n=i[r],o=parseInt(n["LAST-MSN"])||(t==null?void 0:t.lastPartSn);let l=parseInt(n["LAST-PART"])||(t==null?void 0:t.lastPartIndex);if(this.hls.config.lowLatencyMode){const h=Math.min(t.age-t.partTarget,t.targetduration);l>=0&&h>t.partTarget&&(l+=1)}const c=s&&jn(s);return new Wn(o,l>=0?l:void 0,c)}}}loadPlaylist(e){this.requestScheduled===-1&&(this.requestScheduled=self.performance.now())}shouldLoadPlaylist(e){return this.canLoad&&!!e&&!!e.url&&(!e.details||e.details.live)}shouldReloadPlaylist(e){return this.timer===-1&&this.requestScheduled===-1&&this.shouldLoadPlaylist(e)}playlistLoaded(e,t,s){const{details:i,stats:r}=t,n=self.performance.now(),o=r.loading.first?Math.max(0,n-r.loading.first):0;if(i.advancedDateTime=Date.now()-o,i.live||s!=null&&s.live){if(i.reloaded(s),s&&this.log(`live playlist ${e} ${i.advanced?"REFRESHED "+i.lastPartSn+"-"+i.lastPartIndex:i.updated?"UPDATED":"MISSED"}`),s&&i.fragments.length>0&&zc(s,i),!this.canLoad||!i.live)return;let l,c,h;if(i.canBlockReload&&i.endSN&&i.advanced){const x=this.hls.config.lowLatencyMode,T=i.lastPartSn,R=i.endSN,v=i.lastPartIndex,D=v!==-1,L=T===R,_=x?0:v;D?(c=L?R+1:T,h=L?_:v+1):c=R+1;const k=i.age,B=k+i.ageHeader;let G=Math.min(B-i.partTarget,i.targetduration*1.5);if(G>0){if(s&&G>s.tuneInGoal)this.warn(`CDN Tune-in goal increased from: ${s.tuneInGoal} to: ${G} with playlist age: ${i.age}`),G=0;else{const P=Math.floor(G/i.targetduration);if(c+=P,h!==void 0){const U=Math.round(G%i.targetduration/i.partTarget);h+=U}this.log(`CDN Tune-in age: ${i.ageHeader}s last advanced ${k.toFixed(2)}s goal: ${G} skip sn ${P} to part ${h}`)}i.tuneInGoal=G}if(l=this.getDeliveryDirectives(i,t.deliveryDirectives,c,h),x||!L){this.loadPlaylist(l);return}}else(i.canBlockReload||i.canSkipUntil)&&(l=this.getDeliveryDirectives(i,t.deliveryDirectives,c,h));const u=this.hls.mainForwardBufferInfo,d=u?u.end-u.len:0,f=(i.edge-d)*1e3,g=Zc(i,f);i.updated&&n>this.requestScheduled+g&&(this.requestScheduled=r.loading.start),c!==void 0&&i.canBlockReload?this.requestScheduled=r.loading.first+g-(i.partTarget*1e3||1e3):this.requestScheduled===-1||this.requestScheduled+g<n?this.requestScheduled=n:this.requestScheduled-n<=0&&(this.requestScheduled+=g);let m=this.requestScheduled-n;m=Math.max(0,m),this.log(`reload live playlist ${e} in ${Math.round(m)} ms`),this.timer=self.setTimeout(()=>this.loadPlaylist(l),m)}else this.clearTimer()}getDeliveryDirectives(e,t,s,i){let r=jn(e);return t!=null&&t.skip&&e.deltaUpdateFailed&&(s=t.msn,i=t.part,r=js.No),new Wn(s,i,r)}checkRetry(e){const t=e.details,s=ri(e),i=e.errorAction,{action:r,retryCount:n=0,retryConfig:o}=i||{},l=!!i&&!!o&&(r===Be.RetryRequest||!i.resolved&&r===Be.SendAlternateToPenaltyBox);if(l){var c;if(this.requestScheduled=-1,n>=o.maxNumRetry)return!1;if(s&&(c=e.context)!=null&&c.deliveryDirectives)this.warn(`Retrying playlist loading ${n+1}/${o.maxNumRetry} after "${t}" without delivery-directives`),this.loadPlaylist();else{const h=vr(o,n);this.timer=self.setTimeout(()=>this.loadPlaylist(),h),this.warn(`Retrying playlist loading ${n+1}/${o.maxNumRetry} after "${t}" in ${h}ms`)}e.levelRetry=!0,i.resolved=!0}return l}}class Kt{constructor(e,t=0,s=0){this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=e,this.alpha_=e?Math.exp(Math.log(.5)/e):0,this.estimate_=t,this.totalWeight_=s}sample(e,t){const s=Math.pow(this.alpha_,e);this.estimate_=t*(1-s)+s*this.estimate_,this.totalWeight_+=e}getTotalWeight(){return this.totalWeight_}getEstimate(){if(this.alpha_){const e=1-Math.pow(this.alpha_,this.totalWeight_);if(e)return this.estimate_/e}return this.estimate_}}class oh{constructor(e,t,s,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_=s,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new Kt(e),this.fast_=new Kt(t),this.defaultTTFB_=i,this.ttfb_=new Kt(e)}update(e,t){const{slow_:s,fast_:i,ttfb_:r}=this;s.halfLife!==e&&(this.slow_=new Kt(e,s.getEstimate(),s.getTotalWeight())),i.halfLife!==t&&(this.fast_=new Kt(t,i.getEstimate(),i.getTotalWeight())),r.halfLife!==e&&(this.ttfb_=new Kt(e,r.getEstimate(),r.getTotalWeight()))}sample(e,t){e=Math.max(e,this.minDelayMs_);const s=8*t,i=e/1e3,r=s/i;this.fast_.sample(i,r),this.slow_.sample(i,r)}sampleTTFB(e){const t=e/1e3,s=Math.sqrt(2)*Math.exp(-Math.pow(t,2)/2);this.ttfb_.sample(s,Math.max(e,5))}canEstimate(){return this.fast_.getTotalWeight()>=this.minWeight_}getEstimate(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_}getEstimateTTFB(){return this.ttfb_.getTotalWeight()>=this.minWeight_?this.ttfb_.getEstimate():this.defaultTTFB_}destroy(){}}const Qa={supported:!0,configurations:[],decodingInfoResults:[{supported:!0,powerEfficient:!0,smooth:!0}]},Qn={};function lh(a,e,t,s,i,r){const n=a.audioCodec?a.audioGroups:null,o=r==null?void 0:r.audioCodec,l=r==null?void 0:r.channels,c=l?parseInt(l):o?1/0:2;let h=null;if(n!=null&&n.length)try{n.length===1&&n[0]?h=e.groups[n[0]].channels:h=n.reduce((u,d)=>{if(d){const f=e.groups[d];if(!f)throw new Error(`Audio track group ${d} not found`);Object.keys(f.channels).forEach(g=>{u[g]=(u[g]||0)+f.channels[g]})}return u},{2:0})}catch{return!0}return a.videoCodec!==void 0&&(a.width>1920&&a.height>1088||a.height>1920&&a.width>1088||a.frameRate>Math.max(s,30)||a.videoRange!=="SDR"&&a.videoRange!==t||a.bitrate>Math.max(i,8e6))||!!h&&j(c)&&Object.keys(h).some(u=>parseInt(u)>c)}function ch(a,e,t){const s=a.videoCodec,i=a.audioCodec;if(!s||!i||!t)return Promise.resolve(Qa);const r={width:a.width,height:a.height,bitrate:Math.ceil(Math.max(a.bitrate*.9,a.averageBitrate)),framerate:a.frameRate||30},n=a.videoRange;n!=="SDR"&&(r.transferFunction=n.toLowerCase());const o=s.split(",").map(l=>({type:"media-source",video:Oe(Oe({},r),{},{contentType:Es(l,"video")})}));return i&&a.audioGroups&&a.audioGroups.forEach(l=>{var c;l&&((c=e.groups[l])==null||c.tracks.forEach(h=>{if(h.groupId===l){const u=h.channels||"",d=parseFloat(u);j(d)&&d>2&&o.push.apply(o,i.split(",").map(f=>({type:"media-source",audio:{contentType:Es(f,"audio"),channels:""+d}})))}}))}),Promise.all(o.map(l=>{const c=hh(l);return Qn[c]||(Qn[c]=t.decodingInfo(l))})).then(l=>({supported:!l.some(c=>!c.supported),configurations:o,decodingInfoResults:l})).catch(l=>({supported:!1,configurations:o,decodingInfoResults:[],error:l}))}function hh(a){const{audio:e,video:t}=a,s=t||e;if(s){const i=s.contentType.split('"')[1];if(t)return`r${t.height}x${t.width}f${Math.ceil(t.framerate)}${t.transferFunction||"sd"}_${i}_${Math.ceil(t.bitrate/1e5)}`;if(e)return`c${e.channels}${e.spatialRendering?"s":"n"}_${i}`}return""}function uh(){if(typeof matchMedia=="function"){const a=matchMedia("(dynamic-range: high)"),e=matchMedia("bad query");if(a.media!==e.media)return a.matches===!0}return!1}function dh(a,e){let t=!1,s=[];return a&&(t=a!=="SDR",s=[a]),e&&(s=e.allowedVideoRanges||ii.slice(0),t=e.preferHDR!==void 0?e.preferHDR:uh(),t?s=s.filter(i=>i!=="SDR"):s=["SDR"]),{preferHDR:t,allowedVideoRanges:s}}function fh(a,e,t,s,i){const r=Object.keys(a),n=s==null?void 0:s.channels,o=s==null?void 0:s.audioCodec,l=n&&parseInt(n)===2;let c=!0,h=!1,u=1/0,d=1/0,f=1/0,g=0,m=[];const{preferHDR:x,allowedVideoRanges:T}=dh(e,i);for(let L=r.length;L--;){const _=a[r[L]];c=_.channels[2]>0,u=Math.min(u,_.minHeight),d=Math.min(d,_.minFramerate),f=Math.min(f,_.minBitrate);const k=T.filter(B=>_.videoRanges[B]>0);k.length>0&&(h=!0,m=k)}u=j(u)?u:0,d=j(d)?d:0;const R=Math.max(1080,u),v=Math.max(30,d);return f=j(f)?f:t,t=Math.max(f,t),h||(e=void 0,m=[]),{codecSet:r.reduce((L,_)=>{const k=a[_];if(_===L)return L;if(k.minBitrate>t)return pt(_,`min bitrate of ${k.minBitrate} > current estimate of ${t}`),L;if(!k.hasDefaultAudio)return pt(_,"no renditions with default or auto-select sound found"),L;if(o&&_.indexOf(o.substring(0,4))%5!==0)return pt(_,`audio codec preference "${o}" not found`),L;if(n&&!l){if(!k.channels[n])return pt(_,`no renditions with ${n} channel sound found (channels options: ${Object.keys(k.channels)})`),L}else if((!o||l)&&c&&k.channels[2]===0)return pt(_,"no renditions with stereo sound found"),L;return k.minHeight>R?(pt(_,`min resolution of ${k.minHeight} > maximum of ${R}`),L):k.minFramerate>v?(pt(_,`min framerate of ${k.minFramerate} > maximum of ${v}
16`),L):m.some(B=>k.videoRanges[B]>0)?k.maxScore<g?(pt(_,`max score of ${k.maxScore} < selected max of ${g}`),L):L&&(ti(_)>=ti(L)||k.fragmentError>a[L].fragmentError)?L:(g=k.maxScore,_):(pt(_,`no variants with VIDEO-RANGE of ${JSON.stringify(m)} found`),L)},void 0),videoRanges:m,preferHDR:x,minFramerate:d,minBitrate:f}}function pt(a,e){b.log(`[abr] start candidates with "${a}" ignored because ${e}`)}function gh(a){return a.reduce((e,t)=>{let s=e.groups[t.groupId];s||(s=e.groups[t.groupId]={tracks:[],channels:{2:0},hasDefault:!1,hasAutoSelect:!1}),s.tracks.push(t);const i=t.channels||"2";return s.channels[i]=(s.channels[i]||0)+1,s.hasDefault=s.hasDefault||t.default,s.hasAutoSelect=s.hasAutoSelect||t.autoselect,s.hasDefault&&(e.hasDefaultAudio=!0),s.hasAutoSelect&&(e.hasAutoSelectAudio=!0),e},{hasDefaultAudio:!1,hasAutoSelectAudio:!1,groups:{}})}function mh(a,e,t,s){return a.slice(t,s+1).reduce((i,r)=>{if(!r.codecSet)return i;const n=r.audioGroups;let o=i[r.codecSet];o||(i[r.codecSet]=o={minBitrate:1/0,minHeight:1/0,minFramerate:1/0,maxScore:0,videoRanges:{SDR:0},channels:{2:0},hasDefaultAudio:!n,fragmentError:0}),o.minBitrate=Math.min(o.minBitrate,r.bitrate);const l=Math.min(r.height,r.width);return o.minHeight=Math.min(o.minHeight,l),o.minFramerate=Math.min(o.minFramerate,r.frameRate),o.maxScore=Math.max(o.maxScore,r.score),o.fragmentError+=r.fragmentError,o.videoRanges[r.videoRange]=(o.videoRanges[r.videoRange]||0)+1,n&&n.forEach(c=>{if(!c)return;const h=e.groups[c];h&&(o.hasDefaultAudio=o.hasDefaultAudio||e.hasDefaultAudio?h.hasDefault:h.hasAutoSelect||!e.hasDefaultAudio&&!e.hasAutoSelectAudio,Object.keys(h.channels).forEach(u=>{o.channels[u]=(o.channels[u]||0)+h.channels[u]}))}),i},{})}function ht(a,e,t){if("attrs"in a){const s=e.indexOf(a);if(s!==-1)return s}for(let s=0;s<e.length;s++){const i=e[s];if(Xt(a,i,t))return s}return-1}function Xt(a,e,t){const{groupId:s,name:i,lang:r,assocLang:n,characteristics:o,default:l}=a,c=a.forced;return(s===void 0||e.groupId===s)&&(i===void 0||e.name===i)&&(r===void 0||e.lang===r)&&(r===void 0||e.assocLang===n)&&(l===void 0||e.default===l)&&(c===void 0||e.forced===c)&&(o===void 0||ph(o,e.characteristics))&&(t===void 0||t(a,e))}function ph(a,e=""){const t=a.split(","),s=e.split(",");return t.length===s.length&&!t.some(i=>s.indexOf(i)===-1)}function Ht(a,e){const{audioCodec:t,channels:s}=a;return(t===void 0||(e.audioCodec||"").substring(0,4)===t.substring(0,4))&&(s===void 0||s===(e.channels||"2"))}function xh(a,e,t,s,i){const r=e[s],o=e.reduce((d,f,g)=>{const m=f.uri;return(d[m]||(d[m]=[])).push(g),d},{})[r.uri];o.length>1&&(s=Math.max.apply(Math,o));const l=r.videoRange,c=r.frameRate,h=r.codecSet.substring(0,4),u=Jn(e,s,d=>{if(d.videoRange!==l||d.frameRate!==c||d.codecSet.substring(0,4)!==h)return!1;const f=d.audioGroups,g=t.filter(m=>!f||f.indexOf(m.groupId)!==-1);return ht(a,g,i)>-1});return u>-1?u:Jn(e,s,d=>{const f=d.audioGroups,g=t.filter(m=>!f||f.indexOf(m.groupId)!==-1);return ht(a,g,i)>-1})}function Jn(a,e,t){for(let s=e;s>-1;s--)if(t(a[s]))return s;for(let s=e+1;s<a.length;s++)if(t(a[s]))return s;return-1}class yh{constructor(e){this.hls=void 0,this.lastLevelLoadSec=0,this.lastLoadedFragLevel=-1,this.firstSelection=-1,this._nextAutoLevel=-1,this.nextAutoLevelKey="",this.audioTracksByGroup=null,this.co
vendor: 7,065 bytes, lines 16-23
16decTiers=null,this.timer=-1,this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this._abandonRulesCheck=()=>{const{fragCurrent:t,partCurrent:s,hls:i}=this,{autoLevelEnabled:r,media:n}=i;if(!t||!n)return;const o=performance.now(),l=s?s.stats:t.stats,c=s?s.duration:t.duration,h=o-l.loading.start,u=i.minAutoLevel;if(l.aborted||l.loaded&&l.loaded===l.total||t.level<=u){this.clearTimer(),this._nextAutoLevel=-1;return}if(!r||n.paused||!n.playbackRate||!n.readyState)return;const d=i.mainForwardBufferInfo;if(d===null)return;const f=this.bwEstimator.getEstimateTTFB(),g=Math.abs(n.playbackRate);if(h<=Math.max(f,1e3*(c/(g*2))))return;const m=d.len/g,x=l.loading.first?l.loading.first-l.loading.start:-1,T=l.loaded&&x>-1,R=this.getBwEstimate(),v=i.levels,D=v[t.level],L=l.total||Math.max(l.loaded,Math.round(c*D.averageBitrate/8));let _=T?h-x:h;_<1&&T&&(_=Math.min(h,l.loaded*8/R));const k=T?l.loaded*1e3/_:0,B=k?(L-l.loaded)/k:L*8/R+f/1e3;if(B<=m)return;const G=k?k*8:R;let P=Number.POSITIVE_INFINITY,U;for(U=t.level-1;U>u;U--){const K=v[U].maxBitrate;if(P=this.getTimeToLoadFrag(f/1e3,G,c*K,!v[U].details),P<m)break}if(P>=B||P>c*10)return;i.nextLoadLevel=i.nextAutoLevel=U,T?this.bwEstimator.sample(h-Math.min(f,x),l.loaded):this.bwEstimator.sampleTTFB(h);const ee=v[U].maxBitrate;this.getBwEstimate()*this.hls.config.abrBandWidthUpFactor>ee&&this.resetEstimator(ee),this.clearTimer(),b.warn(`[abr] Fragment ${t.sn}${s?" part "+s.index:""} of level ${t.level} is loading too slowly; 17 Time to underbuffer: ${m.toFixed(3)} s 18 Estimated load time for current fragment: ${B.toFixed(3)} s 19 Estimated load time for down switch fragment: ${P.toFixed(3)} s 20 TTFB estimate: ${x|0} ms 21 Current BW estimate: ${j(R)?R|0:"Unknown"} bps 22 New BW estimate: ${this.getBwEstimate()|0} bps 23 Switching to level ${U} @ ${ee|0} bps`),i.trigger(p.FRAG_LOAD_EMERGENCY_ABORTED,{frag:t,part:s,stats:l})},this.hls=e,this.bwEstimator=this.initEstimator(),this.registerListeners()}resetEstimator(e){e&&(b.log(`setting initial bwe to ${e}`),this.hls.config.abrEwmaDefaultEstimate=e),this.firstSelection=-1,this.bwEstimator=this.initEstimator()}initEstimator(){const e=this.hls.config;return new oh(e.abrEwmaSlowVoD,e.abrEwmaFastVoD,e.abrEwmaDefaultEstimate)}registerListeners(){const{hls:e}=this;e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.FRAG_LOADING,this.onFragLoading,this),e.on(p.FRAG_LOADED,this.onFragLoaded,this),e.on(p.FRAG_BUFFERED,this.onFragBuffered,this),e.on(p.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(p.LEVEL_LOADED,this.onLevelLoaded,this),e.on(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(p.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.on(p.ERROR,this.onError,this)}unregisterListeners(){const{hls:e}=this;e&&(e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.FRAG_LOADING,this.onFragLoading,this),e.off(p.FRAG_LOADED,this.onFragLoaded,this),e.off(p.FRAG_BUFFERED,this.onFragBuffered,this),e.off(p.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(p.LEVEL_LOADED,this.onLevelLoaded,this),e.off(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(p.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.off(p.ERROR,this.onError,this))}destroy(){this.unregisterListeners(),this.clearTimer(),this.hls=this._abandonRulesCheck=null,this.fragCurrent=this.partCurrent=null}onManifestLoading(e,t){this.lastLoadedFragLevel=-1,this.firstSelection=-1,this.lastLevelLoadSec=0,this.fragCurrent=this.partCurrent=null,this.onLevelsUpdated(),this.clearTimer()}onLevelsUpdated(){this.lastLoadedFragLevel>-1&&this.fragCurrent&&(this.lastLoadedFragLevel=this.fragCurrent.level),this._nextAutoLevel=-1,this.onMaxAutoLevelUpdated(),this.codecTiers=null,this.audioTracksByGroup=null}onMaxAutoLevelUpdated(){this.firstSelection=-1,this.nextAutoLevelKey=""}onFragLoading(e,t){const s=t.frag;if(!this.ignoreFragment(s)){if(!s.bitrateTest){var i;this.fragCurrent=s,this.partCurrent=(i=t.part)!=null?i:null}this.clearTimer(),this.timer=self.setInterval(this._abandonRulesCheck,100)}}onLevelSwitching(e,t){this.clearTimer()}onError(e,t){if(!t.fatal)switch(t.details){case w.BUFFER_ADD_CODEC_ERROR:case w.BUFFER_APPEND_ERROR:this.lastLoadedFragLevel=-1,this.firstSelection=-1;break;case w.FRAG_LOAD_TIMEOUT:{const s=t.frag,{fragCurrent:i,partCurrent:r}=this;if(s&&i&&s.sn===i.sn&&s.level===i.level){const n=performance.now(),o=r?r.stats:s.stats,l=n-o.loading.start,c=o.loading.first?o.loading.first-o.loading.start:-1;if(o.loaded&&c>-1){const u=this.bwEstimator.getEstimateTTFB();this.bwEstimator.sample(l-Math.min(u,c),o.loaded)}else this.bwEstimator.sampleTTFB(l)}break}}}getTimeToLoadFrag(e,t,s,i){const r=e+s/t,n=i?this.lastLevelLoadSec:0;return r+n}onLevelLoaded(e,t){const s=this.hls.config,{loading:i}=t.stats,r=i.end-i.start;j(r)&&(this.lastLevelLoadSec=r/1e3),t.details.live?this.bwEstimator.update(s.abrEwmaSlowLive,s.abrEwmaFastLive):this.bwEstimator.update(s.abrEwmaSlowVoD,s.abrEwmaFastVoD)}onFragLoaded(e,{frag:t,part:s}){const i=s?s.stats:t.stats;if(t.type===Q.MAIN&&this.bwEstimator.sampleTTFB(i.loading.first-i.loading.start),!this.ignoreFragment(t)){if(this.clearTimer(),t.level===this._nextAutoLevel&&(this._nextAutoLevel=-1),this.firstSelection=-1,this.hls.config.abrMaxWithRealBitrate){const r=s?s.duration:t.duration,n=this.hls.levels[t.level],o=(n.loaded?n.loaded.bytes:0)+i.loaded,l=(n.loaded?n.loaded.duration:0)+r;n.loaded={bytes:o,duration:l},n.realBitrate=Math.round(8*o/l)}if(t.bitrateTest){const r={stats:i,frag:t,part:s,id:t.type};this.onFragBuffered(p.FRAG_BUFFERED,r),t.bitrateTest=!1}else this.lastLoadedFragLevel=t.level}}onFragBuffered(e,t){const{frag:s,part:i}=t,r=i!=null&&i.stats.loaded?i.stats:s.stats;if(r.aborted||this.ignoreFragment(s))return;const n=r.parsing.end-r.loading.start-Math.min(r.loading.first-r.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(n,r.loaded),r.bwEstimate=this.getBwEstimate(),s.bitrateTest?this.bitrateTestDelay=n/1e3:this.bitrateTestDelay=0}ignoreFragment(e){return e.type!==Q.MAIN||e.sn==="initSegment"}clearTimer(){this.timer>-1&&(self.clearInterval(this.timer),this.timer=-1)}get firstAutoLevel(){const{maxAutoLevel:e,minAutoLevel:t}=this.hls,s=this.getBwEstimate(),i=this.hls.config.maxStarvationDelay,r=this.findBestLevel(s,t,e,0,i,1,1);if(r>-1)return r;const n=this.hls.firstLevel,o=Math.min(Math.max(n,t),e);return b.warn(`[abr] Could not find best starting auto level. Defaulting to first in playlist ${n} clamped to ${o}`),o}get forcedAutoLevel(){return this.nextAutoLevelKey?-1:this._nextAutoLevel}get nextAutoLevel(){const e=this.forcedAutoLevel,s=this.bwEstimator.canEstimate(),i=this.lastLoadedFragLevel>-1;if(e!==-1&&(!s||!i||this.nextAutoLevelKey===this.getAutoLevelKey()))return e;const r=s&&i?this.getNextABRAutoLevel():this.firstAutoLevel;if(e!==-1){const n=this.hls.levels;if(n.length>Math.max(e,r)&&n[e].loadError<=n[r].loadError)return e}return this._nextAutoLevel=r,this.nextAutoLevelKey=this.getAutoLevelKey(),r}getAutoLevelKey(){return`${this.getBwEstimate()}
23_${this.getStarvationDelay().toFixed(2)}`}getNextABRAutoLevel(){const{fragCurrent:e,partCurrent:t,hls:s}=this,{maxAutoLevel:i,config:r,minAutoLevel:n}=s,o=t?t.duration:e?e.duration:0,l=this.getBwEstimate(),c=this.getStarvationDelay();let h=r.abrBandWidthFactor,u=r.abrBandWidthUpFactor;if(c){const x=this.findBestLevel(l,n,i,c,0,h,u);if(x>=0)return x}let d=o?Math.min(o,r.maxStarvationDelay):r.maxStarvationDelay;if(!c){const x=this.bitrateTestDelay;x&&(d=(o?Math.min(o,r.maxLoadingDelay):r.maxLoadingDelay)-x,b.info(`[abr] bitrate test took ${Math.round(1e3*x)}ms, set first fragment max fetchDuration to ${Math.round(1e3*d)} ms`),h=u=1)}const f=this.findBestLevel(l,n,i,c,d,h,u);if(b.info(`[abr] ${c?"rebuffering expected":"buffer is empty"}, optimal quality level ${f}`),f>-1)return f;const g=s.levels[n],m=s.levels[s.loadLevel];return(g==null?void 0:g.bitrate)<(m==null?void 0:m.bitrate)?n:s.loadLevel}getStarvationDelay(){const e=this.hls,t=e.media;if(!t)return 1/0;const s=t&&t.playbackRate!==0?Math.abs(t.playbackRate):1,i=e.mainForwardBufferInfo;return(i?i.len:0)/s}getBwEstimate(){return this.bwEstimator.canEstimate()?this.bwEstimator.getEstimate():this.hls.config.abrEwmaDefaultEstimate}findBestLevel(e,t,s,i,r,n,o){var l;const c=i+r,h=this.lastLoadedFragLevel,u=h===-1?this.hls.firstLevel:h,{fragCurrent:d,partCurrent:f}=this,{levels:g,allAudioTracks:m,loadLevel:x,config:T}=this.hls;if(g.length===1)return 0;const R=g[u],v=!!(R!=null&&(l=R.details)!=null&&l.live),D=x===-1||h===-1;let L,_="SDR",k=(R==null?void 0:R.frameRate)||0;const{audioPreference:B,videoPreference:G}=T,P=this.audioTracksByGroup||(this.audioTracksByGroup=gh(m));if(D){if(this.firstSelection!==-1)return this.firstSelection;const ie=this.codecTiers||(this.codecTiers=mh(g,P,t,s)),Y=fh(ie,_,e,B,G),{codecSet:le,videoRanges:he,minFramerate:V,minBitrate:H,preferHDR:re}=Y;
vendor: 174,657 bytes, lines 23-30
23L=le,_=re?he[he.length-1]:he[0],k=V,e=Math.max(e,H),b.log(`[abr] picked start tier ${JSON.stringify(Y)}`)}else L=R==null?void 0:R.codecSet,_=R==null?void 0:R.videoRange;const U=f?f.duration:d?d.duration:0,ee=this.bwEstimator.getEstimateTTFB()/1e3,K=[];for(let ie=s;ie>=t;ie--){var se;const Y=g[ie],le=ie>u;if(!Y)continue;if(T.useMediaCapabilities&&!Y.supportedResult&&!Y.supportedPromise){const ve=navigator.mediaCapabilities;typeof(ve==null?void 0:ve.decodingInfo)=="function"&&lh(Y,P,_,k,e,B)?(Y.supportedPromise=ch(Y,P,ve),Y.supportedPromise.then(be=>{if(!this.hls)return;Y.supportedResult=be;const Pe=this.hls.levels,ye=Pe.indexOf(Y);be.error?b.warn(`[abr] MediaCapabilities decodingInfo error: "${be.error}" for level ${ye} ${JSON.stringify(be)}`):be.supported||(b.warn(`[abr] Unsupported MediaCapabilities decodingInfo result for level ${ye} ${JSON.stringify(be)}`),ye>-1&&Pe.length>1&&(b.log(`[abr] Removing unsupported level ${ye}`),this.hls.removeLevel(ye)))})):Y.supportedResult=Qa}if(L&&Y.codecSet!==L||_&&Y.videoRange!==_||le&&k>Y.frameRate||!le&&k>0&&k<Y.frameRate||Y.supportedResult&&!((se=Y.supportedResult.decodingInfoResults)!=null&&se[0].smooth)){K.push(ie);continue}const he=Y.details,V=(f?he==null?void 0:he.partTarget:he==null?void 0:he.averagetargetduration)||U;let H;le?H=o*e:H=n*e;const re=U&&i>=U*2&&r===0?g[ie].averageBitrate:g[ie].maxBitrate,J=this.getTimeToLoadFrag(ee,H,re*V,he===void 0);if(H>=re&&(ie===h||Y.loadError===0&&Y.fragmentError===0)&&(J<=ee||!j(J)||v&&!this.bitrateTestDelay||J<c)){const ve=this.forcedAutoLevel;return ie!==x&&(ve===-1||ve!==x)&&(K.length&&b.trace(`[abr] Skipped level(s) ${K.join(",")} of ${s} max with CODECS and VIDEO-RANGE:"${g[K[0]].codecs}" ${g[K[0]].videoRange}; not compatible with "${R.codecs}" ${_}`),b.info(`[abr] switch candidate:${u}->${ie} adjustedbw(${Math.round(H)})-bitrate=${Math.round(H-re)} ttfb:${ee.toFixed(1)} avgDuration:${V.toFixed(1)} maxFetchDuration:${c.toFixed(1)} fetchDuration:${J.toFixed(1)} firstSelection:${D} codecSet:${L} videoRange:${_} hls.loadLevel:${x}`)),D&&(this.firstSelection=ie),ie}}return-1}set nextAutoLevel(e){const{maxAutoLevel:t,minAutoLevel:s}=this.hls,i=Math.min(Math.max(e,s),t);this._nextAutoLevel!==i&&(this.nextAutoLevelKey="",this._nextAutoLevel=i)}}class Th{constructor(){this._boundTick=void 0,this._tickTimer=null,this._tickInterval=null,this._tickCallCount=0,this._boundTick=this.tick.bind(this)}destroy(){this.onHandlerDestroying(),this.onHandlerDestroyed()}onHandlerDestroying(){this.clearNextTick(),this.clearInterval()}onHandlerDestroyed(){}hasInterval(){return!!this._tickInterval}hasNextTick(){return!!this._tickTimer}setInterval(e){return this._tickInterval?!1:(this._tickCallCount=0,this._tickInterval=self.setInterval(this._boundTick,e),!0)}clearInterval(){return this._tickInterval?(self.clearInterval(this._tickInterval),this._tickInterval=null,!0):!1}clearNextTick(){return this._tickTimer?(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0):!1}tick(){this._tickCallCount++,this._tickCallCount===1&&(this.doTick(),this._tickCallCount>1&&this.tickImmediate(),this._tickCallCount=0)}tickImmediate(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)}doTick(){}}var Fe={NOT_LOADED:"NOT_LOADED",APPENDING:"APPENDING",PARTIAL:"PARTIAL",OK:"OK"};class Eh{constructor(e){this.activePartLists=Object.create(null),this.endListFragments=Object.create(null),this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hasGaps=!1,this.hls=e,this._registerListeners()}_registerListeners(){const{hls:e}=this;e.on(p.BUFFER_APPENDED,this.onBufferAppended,this),e.on(p.FRAG_BUFFERED,this.onFragBuffered,this),e.on(p.FRAG_LOADED,this.onFragLoaded,this)}_unregisterListeners(){const{hls:e}=this;e.off(p.BUFFER_APPENDED,this.onBufferAppended,this),e.off(p.FRAG_BUFFERED,this.onFragBuffered,this),e.off(p.FRAG_LOADED,this.onFragLoaded,this)}destroy(){this._unregisterListeners(),this.fragments=this.activePartLists=this.endListFragments=this.timeRanges=null}getAppendedFrag(e,t){const s=this.activePartLists[t];if(s)for(let i=s.length;i--;){const r=s[i];if(!r)break;const n=r.end;if(r.start<=e&&n!==null&&e<=n)return r}return this.getBufferedFrag(e,t)}getBufferedFrag(e,t){const{fragments:s}=this,i=Object.keys(s);for(let r=i.length;r--;){const n=s[i[r]];if((n==null?void 0:n.body.type)===t&&n.buffered){const o=n.body;if(o.start<=e&&e<=o.end)return o}}return null}detectEvictedFragments(e,t,s,i){this.timeRanges&&(this.timeRanges[e]=t);const r=(i==null?void 0:i.fragment.sn)||-1;Object.keys(this.fragments).forEach(n=>{const o=this.fragments[n];if(!o||r>=o.body.sn)return;if(!o.buffered&&!o.loaded){o.body.type===s&&this.removeFragment(o.body);return}const l=o.range[e];l&&l.time.some(c=>{const h=!this.isTimeBuffered(c.startPTS,c.endPTS,t);return h&&this.removeFragment(o.body),h})})}detectPartialFragments(e){const t=this.timeRanges,{frag:s,part:i}=e;if(!t||s.sn==="initSegment")return;const r=Vt(s),n=this.fragments[r];if(!n||n.buffered&&s.gap)return;const o=!s.relurl;Object.keys(t).forEach(l=>{const c=s.elementaryStreams[l];if(!c)return;const h=t[l],u=o||c.partial===!0;n.range[l]=this.getBufferedTimes(s,i,u,h)}),n.loaded=null,Object.keys(n.range).length?(n.buffered=!0,(n.body.endList=s.endList||n.body.endList)&&(this.endListFragments[n.body.type]=n),Os(n)||this.removeParts(s.sn-1,s.type)):this.removeFragment(n.body)}removeParts(e,t){const s=this.activePartLists[t];s&&(this.activePartLists[t]=s.filter(i=>i.fragment.sn>=e))}fragBuffered(e,t){const s=Vt(e);let i=this.fragments[s];!i&&t&&(i=this.fragments[s]={body:e,appendedPTS:null,loaded:null,buffered:!1,range:Object.create(null)},e.gap&&(this.hasGaps=!0)),i&&(i.loaded=null,i.buffered=!0)}getBufferedTimes(e,t,s,i){const r={time:[],partial:s},n=e.start,o=e.end,l=e.minEndPTS||o,c=e.maxStartPTS||n;for(let h=0;h<i.length;h++){const u=i.start(h)-this.bufferPadding,d=i.end(h)+this.bufferPadding;if(c>=u&&l<=d){r.time.push({startPTS:Math.max(n,i.start(h)),endPTS:Math.min(o,i.end(h))});break}else if(n<d&&o>u){const f=Math.max(n,i.start(h)),g=Math.min(o,i.end(h));g>f&&(r.partial=!0,r.time.push({startPTS:f,endPTS:g}))}else if(o<=u)break}return r}getPartialFragment(e){let t=null,s,i,r,n=0;const{bufferPadding:o,fragments:l}=this;return Object.keys(l).forEach(c=>{const h=l[c];h&&Os(h)&&(i=h.body.start-o,r=h.body.end+o,e>=i&&e<=r&&(s=Math.min(e-i,r-e),n<=s&&(t=h.body,n=s)))}),t}isEndListAppended(e){const t=this.endListFragments[e];return t!==void 0&&(t.buffered||Os(t))}getState(e){const t=Vt(e),s=this.fragments[t];return s?s.buffered?Os(s)?Fe.PARTIAL:Fe.OK:Fe.APPENDING:Fe.NOT_LOADED}isTimeBuffered(e,t,s){let i,r;for(let n=0;n<s.length;n++){if(i=s.start(n)-this.bufferPadding,r=s.end(n)+this.bufferPadding,e>=i&&t<=r)return!0;if(t<=i)return!1}return!1}onFragLoaded(e,t){const{frag:s,part:i}=t;if(s.sn==="initSegment"||s.bitrateTest)return;const r=i?null:t,n=Vt(s);this.fragments[n]={body:s,appendedPTS:null,loaded:r,buffered:!1,range:Object.create(null)}}onBufferAppended(e,t){const{frag:s,part:i,timeRanges:r}=t;if(s.sn==="initSegment")return;const n=s.type;if(i){let o=this.activePartLists[n];o||(this.activePartLists[n]=o=[]),o.push(i)}this.timeRanges=r,Object.keys(r).forEach(o=>{const l=r[o];this.detectEvictedFragments(o,l,n,i)})}onFragBuffered(e,t){this.detectPartialFragments(t)}hasFragment(e){const t=Vt(e);return!!this.fragments[t]}hasParts(e){var t;return!!((t=this.activePartLists[e])!=null&&t.length)}removeFragmentsInRange(e,t,s,i,r){i&&!this.hasGaps||Object.keys(this.fragments).forEach(n=>{const o=this.fragments[n];if(!o)return;const l=o.body;l.type!==s||i&&!l.gap||l.start<t&&l.end>e&&(o.buffered||r)&&this.removeFragment(l)})}removeFragment(e){const t=Vt(e);e.stats.loaded=0,e.clearElementaryStreamInfo();const s=this.activePartLists[e.type];if(s){const i=e.sn;this.activePartLists[e.type]=s.filter(r=>r.fragment.sn!==i)}delete this.fragments[t],e.endList&&delete this.endListFragments[e.type]}removeAllFragments(){this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activePartLists=Object.create(null),this.hasGaps=!1}}function Os(a){var e,t,s;return a.buffered&&(a.body.gap||((e=a.range.video)==null?void 0:e.partial)||((t=a.range.audio)==null?void 0:t.partial)||((s=a.range.audiovideo)==null?void 0:s.partial))}function Vt(a){return`${a.type}_${a.level}_${a.sn}`}const Sh={length:0,start:()=>0,end:()=>0};class Ee{static isBuffered(e,t){try{if(e){const s=Ee.getBuffered(e);for(let i=0;i<s.length;i++)if(t>=s.start(i)&&t<=s.end(i))return!0}}catch{}return!1}static bufferInfo(e,t,s){try{if(e){const i=Ee.getBuffered(e),r=[];let n;for(n=0;n<i.length;n++)r.push({start:i.start(n),end:i.end(n)});return this.bufferedInfo(r,t,s)}}catch{}return{len:0,start:t,end:t,nextStart:void 0}}static bufferedInfo(e,t,s){t=Math.max(0,t),e.sort(function(c,h){const u=c.start-h.start;return u||h.end-c.end});let i=[];if(s)for(let c=0;c<e.length;c++){const h=i.length;if(h){const u=i[h-1].end;e[c].start-u<s?e[c].end>u&&(i[h-1].end=e[c].end):i.push(e[c])}else i.push(e[c])}else i=e;let r=0,n,o=t,l=t;for(let c=0;c<i.length;c++){const h=i[c].start,u=i[c].end;if(t+s>=h&&t<u)o=h,l=u,r=l-t;else if(t+s<h){n=h;break}}return{len:r,start:o||0,end:l||0,nextStart:n}}static getBuffered(e){try{return e.buffered}catch(t){return b.log("failed to get media.buffered",t),Sh}}}class Lr{constructor(e,t,s,i=0,r=-1,n=!1){this.level=void 0,this.sn=void 0,this.part=void 0,this.id=void 0,this.size=void 0,this.partial=void 0,this.transmuxing=Ns(),this.buffering={audio:Ns(),video:Ns(),audiovideo:Ns()},this.level=e,this.sn=t,this.id=s,this.size=i,this.part=r,this.partial=n}}function Ns(){return{start:0,executeStart:0,executeEnd:0,end:0}}function Ws(a,e){for(let s=0,i=a.length;s<i;s++){var t;if(((t=a[s])==null?void 0:t.cc)===e)return a[s]}return null}function vh(a,e,t){return!!(e&&(t.endCC>t.startCC||a&&a.cc<t.startCC))}function Ah(a,e){const t=a.fragments,s=e.fragments;if(!s.length||!t.length){b.log("No fragments to align");return}const i=Ws(t,s[0].cc);if(!i||i&&!i.startPTS){b.log("No frag in previous level to align on");return}return i}function Zn(a,e){if(a){const t=a.start+e;a.start=a.startPTS=t,a.endPTS=t+a.duration}}function Ja(a,e){const t=e.fragments;for(let s=0,i=t.length;s<i;s++)Zn(t[s],a);e.fragmentHint&&Zn(e.fragmentHint,a),e.alignedSliding=!0}function Lh(a,e,t){e&&(Rh(a,t,e),!t.alignedSliding&&e&&oi(t,e),!t.alignedSliding&&e&&!t.skippedSegments&&Ya(e,t))}function Rh(a,e,t){if(vh(a,t,e)){const s=Ah(t,e);s&&j(s.start)&&(b.log(`Adjusting PTS using last level due to CC increase within current level ${e.url}`),Ja(s.start,e))}}function oi(a,e){if(!a.hasProgramDateTime||!e.hasProgramDateTime)return;const t=a.fragments,s=e.fragments;if(!t.length||!s.length)return;let i,r;const n=Math.min(e.endCC,a.endCC);e.startCC<n&&a.startCC<n&&(i=Ws(s,n),r=Ws(t,n)),(!i||!r)&&(i=s[Math.floor(s.length/2)],r=Ws(t,i.cc)||t[Math.floor(t.length/2)]);const o=i.programDateTime,l=r.programDateTime;if(!o||!l)return;const c=(l-o)/1e3-(r.start-i.start);Ja(c,a)}const ea=Math.pow(2,17);class bh{constructor(e){this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=e}destroy(){this.loader&&(this.loader.destroy(),this.loader=null)}abort(){this.loader&&this.loader.abort()}load(e,t){const s=e.url;if(!s)return Promise.reject(new yt({type:Z.NETWORK_ERROR,details:w.FRAG_LOAD_ERROR,fatal:!1,frag:e,error:new Error(`Fragment does not have a ${s?"part list":"url"}`),networkDetails:null}));this.abort();const i=this.config,r=i.fLoader,n=i.loader;return new Promise((o,l)=>{if(this.loader&&this.loader.destroy(),e.gap)if(e.tagList.some(f=>f[0]==="GAP")){l(sa(e));return}else e.gap=!1;const c=this.loader=e.loader=r?new r(i):new n(i),h=ta(e),u=Xn(i.fragLoadPolicy.default),d={loadPolicy:u,timeout:u.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:e.sn==="initSegment"?1/0:ea};e.stats=c.stats,c.load(h,d,{onSuccess:(f,g,m,x)=>{this.resetLoader(e,c);let T=f.data;m.resetIV&&e.decryptdata&&(e.decryptdata.iv=new Uint8Array(T.slice(0,16)),T=T.slice(16)),o({frag:e,part:null,payload:T,networkDetails:x})},onError:(f,g,m,x)=>{this.resetLoader(e,c),l(new yt({type:Z.NETWORK_ERROR,details:w.FRAG_LOAD_ERROR,fatal:!1,frag:e,response:Oe({url:s,data:void 0},f),error:new Error(`HTTP Error ${f.code} ${f.text}`),networkDetails:m,stats:x}))},onAbort:(f,g,m)=>{this.resetLoader(e,c),l(new yt({type:Z.NETWORK_ERROR,details:w.INTERNAL_ABORTED,fatal:!1,frag:e,error:new Error("Aborted"),networkDetails:m,stats:f}))},onTimeout:(f,g,m)=>{this.resetLoader(e,c),l(new yt({type:Z.NETWORK_ERROR,details:w.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,error:new Error(`Timeout after ${d.timeout}ms`),networkDetails:m,stats:f}))},onProgress:(f,g,m,x)=>{t&&t({frag:e,part:null,payload:m,networkDetails:x})}})})}loadPart(e,t,s){this.abort();const i=this.config,r=i.fLoader,n=i.loader;return new Promise((o,l)=>{if(this.loader&&this.loader.destroy(),e.gap||t.gap){l(sa(e,t));return}const c=this.loader=e.loader=r?new r(i):new n(i),h=ta(e,t),u=Xn(i.fragLoadPolicy.default),d={loadPolicy:u,timeout:u.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:ea};t.stats=c.stats,c.load(h,d,{onSuccess:(f,g,m,x)=>{this.resetLoader(e,c),this.updateStatsFromPart(e,t);const T={frag:e,part:t,payload:f.data,networkDetails:x};s(T),o(T)},onError:(f,g,m,x)=>{this.resetLoader(e,c),l(new yt({type:Z.NETWORK_ERROR,details:w.FRAG_LOAD_ERROR,fatal:!1,frag:e,part:t,response:Oe({url:h.url,data:void 0},f),error:new Error(`HTTP Error ${f.code} ${f.text}`),networkDetails:m,stats:x}))},onAbort:(f,g,m)=>{e.stats.aborted=t.stats.aborted,this.resetLoader(e,c),l(new yt({type:Z.NETWORK_ERROR,details:w.INTERNAL_ABORTED,fatal:!1,frag:e,part:t,error:new Error("Aborted"),networkDetails:m,stats:f}))},onTimeout:(f,g,m)=>{this.resetLoader(e,c),l(new yt({type:Z.NETWORK_ERROR,details:w.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,part:t,error:new Error(`Timeout after ${d.timeout}ms`),networkDetails:m,stats:f}))}})})}updateStatsFromPart(e,t){const s=e.stats,i=t.stats,r=i.total;if(s.loaded+=i.loaded,r){const l=Math.round(e.duration/t.duration),c=Math.min(Math.round(s.loaded/r),l),u=(l-c)*Math.round(s.loaded/c);s.total=s.loaded+u}else s.total=Math.max(s.loaded,s.total);const n=s.loading,o=i.loading;n.start?n.first+=o.first-o.start:(n.start=o.start,n.first=o.first),n.end=o.end}resetLoader(e,t){e.loader=null,this.loader===t&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),t.destroy()}}function ta(a,e=null){const t=e||a,s={frag:a,part:e,responseType:"arraybuffer",url:t.url,headers:{},rangeStart:0,rangeEnd:0},i=t.byteRangeStartOffset,r=t.byteRangeEndOffset;if(j(i)&&j(r)){var n;let o=i,l=r;if(a.sn==="initSegment"&&((n=a.decryptdata)==null?void 0:n.method)==="AES-128"){const c=r-i;c%16&&(l=r+(16-c%16)),i!==0&&(s.resetIV=!0,o=i-16)}s.rangeStart=o,s.rangeEnd=l}return s}function sa(a,e){const t=new Error(`GAP ${a.gap?"tag":"attribute"} found`),s={type:Z.MEDIA_ERROR,details:w.FRAG_GAP,fatal:!1,frag:a,error:t,networkDetails:null};return e&&(s.part=e),(e||a).stats.aborted=!0,new yt(s)}class yt extends Error{constructor(e){super(e.error.message),this.data=void 0,this.data=e}}class Ih{constructor(e,t){this.subtle=void 0,this.aesIV=void 0,this.subtle=e,this.aesIV=t}decrypt(e,t){return this.subtle.decrypt({name:"AES-CBC",iv:this.aesIV},t,e)}}class Dh{constructor(e,t){this.subtle=void 0,this.key=void 0,this.subtle=e,this.key=t}expandKey(){return this.subtle.importKey("raw",this.key,{name:"AES-CBC"},!1,["encrypt","decrypt"])}}function Ch(a){const e=a.byteLength,t=e&&new DataView(a.buffer).getUint8(e-1);return t?Ft(a,0,e-t):a}class wh{constructor(){this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}uint8ArrayToUint32Array_(e){const t=new DataView(e),s=new Uint32Array(4);for(let i=0;i<4;i++)s[i]=t.getUint32(i*4);return s}initTable(){const e=this.sBox,t=this.invSBox,s=this.subMix,i=s[0],r=s[1],n=s[2],o=s[3],l=this.invSubMix,c=l[0],h=l[1],u=l[2],d=l[3],f=new Uint32Array(256);let g=0,m=0,x=0;for(x=0;x<256;x++)x<128?f[x]=x<<1:f[x]=x<<1^283;for(x=0;x<256;x++){let T=m^m<<1^m<<2^m<<3^m<<4;T=T>>>8^T&255^99,e[g]=T,t[T]=g;const R=f[g],v=f[R],D=f[v];let L=f[T]*257^T*16843008;i[g]=L<<24|L>>>8,r[g]=L<<16|L>>>16,n[g]=L<<8|L>>>24,o[g]=L,L=D*16843009^v*65537^R*257^g*16843008,c[T]=L<<24|L>>>8,h[T]=L<<16|L>>>16,u[T]=L<<8|L>>>24,d[T]=L,g?(g=R^f[f[f[D^R]]],m^=f[f[m]]):g=m=1}}expandKey(e){const t=this.uint8ArrayToUint32Array_(e);let s=!0,i=0;for(;i<t.length&&s;)s=t[i]===this.key[i],i++;if(s)return;this.key=t;const r=this.keySize=t.length;if(r!==4&&r!==6&&r!==8)throw new Error("Invalid aes key size="+r);const n=this.ksRows=(r+6+1)*4;let o,l;const c=this.keySchedule=new Uint32Array(n),h=this.invKeySchedule=new Uint32Array(n),u=this.sBox,d=this.rcon,f=this.invSubMix,g=f[0],m=f[1],x=f[2],T=f[3];let R,v;for(o=0;o<n;o++){if(o<r){R=c[o]=t[o];continue}v=R,o%r===0?(v=v<<8|v>>>24,v=u[v>>>24]<<24|u[v>>>16&255]<<16|u[v>>>8&255]<<8|u[v&255],v^=d[o/r|0]<<24):r>6&&o%r===4&&(v=u[v>>>24]<<24|u[v>>>16&255]<<16|u[v>>>8&255]<<8|u[v&255]),c[o]=R=(c[o-r]^v)>>>0}for(l=0;l<n;l++)o=n-l,l&3?v=c[o]:v=c[o-4],l<4||o<=4?h[l]=v:h[l]=g[u[v>>>24]]^m[u[v>>>16&255]]^x[u[v>>>8&255]]^T[u[v&255]],h[l]=h[l]>>>0}networkToHostOrderSwap(e){return e<<24|(e&65280)<<8|(e&16711680)>>8|e>>>24}decrypt(e,t,s){const i=this.keySize+6,r=this.invKeySchedule,n=this.invSBox,o=this.invSubMix,l=o[0],c=o[1],h=o[2],u=o[3],d=this.uint8ArrayToUint32Array_(s);let f=d[0],g=d[1],m=d[2],x=d[3];const T=new Int32Array(e),R=new Int32Array(T.length);let v,D,L,_,k,B,G,P,U,ee,K,se,ie,Y;const le=this.networkToHostOrderSwap;for(;t<T.length;){for(U=le(T[t]),ee=le(T[t+1]),K=le(T[t+2]),se=le(T[t+3]),k=U^r[0],B=se^r[1],G=K^r[2],P=ee^r[3],ie=4,Y=1;Y<i;Y++)v=l[k>>>24]^c[B>>16&255]^h[G>>8&255]^u[P&255]^r[ie],D=l[B>>>24]^c[G>>16&255]^h[P>>8&255]^u[k&255]^r[ie+1],L=l[G>>>24]^c[P>>16&255]^h[k>>8&255]^u[B&255]^r[ie+2],_=l[P>>>24]^c[k>>16&255]^h[B>>8&255]^u[G&255]^r[ie+3],k=v,B=D,G=L,P=_,ie=ie+4;v=n[k>>>24]<<24^n[B>>16&255]<<16^n[G>>8&255]<<8^n[P&255]^r[ie],D=n[B>>>24]<<24^n[G>>16&255]<<16^n[P>>8&255]<<8^n[k&255]^r[ie+1],L=n[G>>>24]<<24^n[P>>16&255]<<16^n[k>>8&255]<<8^n[B&255]^r[ie+2],_=n[P>>>24]<<24^n[k>>16&255]<<16^n[B>>8&255]<<8^n[G&255]^r[ie+3],R[t]=le(v^f),R[t+1]=le(_^g),R[t+2]=le(L^m),R[t+3]=le(D^x),f=U,g=ee,m=K,x=se,t=t+4}return R.buffer}}const kh=16;class Rr{constructor(e,{removePKCS7Padding:t=!0}={}){if(this.logEnabled=!0,this.removePKCS7Padding=void 0,this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null,this.useSoftware=void 0,this.useSoftware=e.enableSoftwareAES,this.removePKCS7Padding=t,t)try{const s=self.crypto;s&&(this.subtle=s.subtle||s.webkitSubtle)}catch{}this.useSoftware=!this.subtle}destroy(){this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null}isSync(){return this.useSoftware}flush(){const{currentResult:e,remainderData:t}=this;if(!e||t)return this.reset(),null;const s=new Uint8Array(e);return this.reset(),this.removePKCS7Padding?Ch(s):s}reset(){this.currentResult=null,this.currentIV=null,this.remainderData=null,this.softwareDecrypter&&(this.softwareDecrypter=null)}decrypt(e,t,s){return this.useSoftware?new Promise((i,r)=>{this.softwareDecrypt(new Uint8Array(e),t,s);const n=this.flush();n?i(n.buffer):r(new Error("[softwareDecrypt] Failed to decrypt data"))}):this.webCryptoDecrypt(new Uint8Array(e),t,s)}softwareDecrypt(e,t,s){const{currentIV:i,currentResult:r,remainderData:n}=this;this.logOnce("JS AES decrypt"),n&&(e=Ze(n,e),this.remainderData=null);const o=this.getValidChunk(e);if(!o.length)return null;i&&(s=i);let l=this.softwareDecrypter;l||(l=this.softwareDecrypter=new wh),l.expandKey(t);const c=r;return this.currentResult=l.decrypt(o.buffer,0,s),this.currentIV=Ft(o,-16).buffer,c||null}webCryptoDecrypt(e,t,s){if(this.key!==t||!this.fastAesKey){if(!this.subtle)return Promise.resolve(this.onWebCryptoError(e,t,s));this.key=t,this.fastAesKey=new Dh(this.subtle,t)}return this.fastAesKey.expandKey().then(i=>this.subtle?(this.logOnce("WebCrypto AES decrypt"),new Ih(this.subtle,new Uint8Array(s)).decrypt(e.buffer,i)):Promise.reject(new Error("web crypto not initialized"))).catch(i=>(b.warn(`[decrypter]: WebCrypto Error, disable WebCrypto API, ${i.name}: ${i.message}`),this.onWebCryptoError(e,t,s)))}onWebCryptoError(e,t,s){this.useSoftware=!0,this.logEnabled=!0,this.softwareDecrypt(e,t,s);const i=this.flush();if(i)return i.buffer;throw new Error("WebCrypto and softwareDecrypt: failed to decrypt data")}getValidChunk(e){let t=e;const s=e.length-e.length%kh;return s!==e.length&&(t=Ft(e,0,s),this.remainderData=Ft(e,s)),t}logOnce(e){this.logEnabled&&(b.log(`[decrypter]: ${e}`),this.logEnabled=!1)}}const _h={toString:function(a){let e="";const t=a.length;for(let s=0;s<t;s++)e+=`[${a.start(s).toFixed(3)}-${a.end(s).toFixed(3)}]`;return e}},O={STOPPED:"STOPPED",IDLE:"IDLE",KEY_LOADING:"KEY_LOADING",FRAG_LOADING:"FRAG_LOADING",FRAG_LOADING_WAITING_RETRY:"FRAG_LOADING_WAITING_RETRY",WAITING_TRACK:"WAITING_TRACK",PARSING:"PARSING",PARSED:"PARSED",ENDED:"ENDED",ERROR:"ERROR",WAITING_INIT_PTS:"WAITING_INIT_PTS",WAITING_LEVEL:"WAITING_LEVEL"};class br extends Th{constructor(e,t,s,i,r){super(),this.hls=void 0,this.fragPrevious=null,this.fragCurrent=null,this.fragmentTracker=void 0,this.transmuxer=null,this._state=O.STOPPED,this.playlistType=void 0,this.media=null,this.mediaBuffer=null,this.config=void 0,this.bitrateTest=!1,this.lastCurrentTime=0,this.nextLoadPosition=0,this.startPosition=0,this.startTimeOffset=null,this.loadedmetadata=!1,this.retryDate=0,this.levels=null,this.fragmentLoader=void 0,this.keyLoader=void 0,this.levelLastLoaded=null,this.startFragRequested=!1,this.decrypter=void 0,this.initPTS=[],this.onvseeking=null,this.onvended=null,this.logPrefix="",this.log=void 0,this.warn=void 0,this.playlistType=r,this.logPrefix=i,this.log=b.log.bind(b,`${i}:`),this.warn=b.warn.bind(b,`${i}:`),this.hls=e,this.fragmentLoader=new bh(e.config),this.keyLoader=s,this.fragmentTracker=t,this.config=e.config,this.decrypter=new Rr(e.config),e.on(p.MANIFEST_LOADED,this.onManifestLoaded,this)}doTick(){this.onTickEnd()}onTickEnd(){}startLoad(e){}stopLoad(){this.fragmentLoader.abort(),this.keyLoader.abort(this.playlistType);const e=this.fragCurrent;e!=null&&e.loader&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=O.STOPPED}_streamEnded(e,t){if(t.live||e.nextStart||!e.end||!this.media)return!1;const s=t.partList;if(s!=null&&s.length){const r=s[s.length-1];return Ee.isBuffered(this.media,r.start+r.duration/2)}const i=t.fragments[t.fragments.length-1].type;return this.fragmentTracker.isEndListAppended(i)}getLevelDetails(){if(this.levels&&this.levelLastLoaded!==null){var e;return(e=this.levelLastLoaded)==null?void 0:e.details}}onMediaAttached(e,t){const s=this.media=this.mediaBuffer=t.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),s.addEventListener("seeking",this.onvseeking),s.addEventListener("ended",this.onvended);const i=this.config;this.levels&&i.autoStartLoad&&this.state===O.STOPPED&&this.startLoad(i.startPosition)}onMediaDetaching(){const e=this.media;e!=null&&e.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),e&&this.onvseeking&&this.onvended&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.keyLoader&&this.keyLoader.detach(),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()}onMediaSeeking(){const{config:e,fragCurrent:t,media:s,mediaBuffer:i,state:r}=this,n=s?s.currentTime:0,o=Ee.bufferInfo(i||s,n,e.maxBufferHole);if(this.log(`media seeking to ${j(n)?n.toFixed(3):n}, state: ${r}`),this.state===O.ENDED)this.resetLoadingState();else if(t){const l=e.maxFragLookUpTolerance,c=t.start-l,h=t.start+t.duration+l;if(!o.len||h<o.start||c>o.end){const u=n>h;(n<c||u)&&(u&&t.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),t.abortRequests(),this.resetLoadingState()),this.fragPrevious=null)}}s&&(this.fragmentTracker.removeFragmentsInRange(n,1/0,this.playlistType,!0),this.lastCurrentTime=n),!this.loadedmetadata&&!o.len&&(this.nextLoadPosition=this.startPosition=n),this.tickImmediate()}onMediaEnded(){this.startPosition=this.lastCurrentTime=0}onManifestLoaded(e,t){this.startTimeOffset=t.startTimeOffset,this.initPTS=[]}onHandlerDestroying(){this.hls.off(p.MANIFEST_LOADED,this.onManifestLoaded,this),this.stopLoad(),super.onHandlerDestroying(),this.hls=null}onHandlerDestroyed(){this.state=O.STOPPED,this.fragmentLoader&&this.fragmentLoader.destroy(),this.keyLoader&&this.keyLoader.destroy(),this.decrypter&&this.decrypter.destroy(),this.hls=this.log=this.warn=this.decrypter=this.keyLoader=this.fragmentLoader=this.fragmentTracker=null,super.onHandlerDestroyed()}loadFragment(e,t,s){this._loadFragForPlayback(e,t,s)}_loadFragForPlayback(e,t,s){const i=r=>{if(this.fragContextChanged(e)){this.warn(`Fragment ${e.sn}${r.part?" p: "+r.part.index:""} of level ${e.level} was dropped during download.`),this.fragmentTracker.removeFragment(e);return}e.stats.chunkCount++,this._handleFragmentLoadProgress(r)};this._doFragLoad(e,t,s,i).then(r=>{if(!r)return;const n=this.state;if(this.fragContextChanged(e)){(n===O.FRAG_LOADING||!this.fragCurrent&&n===O.PARSING)&&(this.fragmentTracker.removeFragment(e),this.state=O.IDLE);return}"payload"in r&&(this.log(`Loaded fragment ${e.sn} of level ${e.level}`),this.hls.trigger(p.FRAG_LOADED,r)),this._handleFragmentLoadComplete(r)}).catch(r=>{this.state===O.STOPPED||this.state===O.ERROR||(this.warn(`Frag error: ${(r==null?void 0:r.message)||r}`),this.resetFragmentLoading(e))})}clearTrackerIfNeeded(e){var t;const{fragmentTracker:s}=this;if(s.getState(e)===Fe.APPENDING){const r=e.type,n=this.getFwdBufferInfo(this.mediaBuffer,r),o=Math.max(e.duration,n?n.len:this.config.maxBufferLength),l=this.backtrackFragment;((l?e.sn-l.sn:0)===1||this.reduceMaxBufferLength(o,e.duration))&&s.removeFragment(e)}else((t=this.mediaBuffer)==null?void 0:t.buffered.length)===0?s.removeAllFragments():s.hasParts(e.type)&&(s.detectPartialFragments({frag:e,part:null,stats:e.stats,id:e.type}),s.getState(e)===Fe.PARTIAL&&s.removeFragment(e))}checkLiveUpdate(e){if(e.updated&&!e.live){const t=e.fragments[e.fragments.length-1];this.fragmentTracker.detectPartialFragments({frag:t,part:null,stats:t.stats,id:t.type})}e.fragments[0]||(e.deltaUpdateFailed=!0)}flushMainBuffer(e,t,s=null){if(!(e-t))return;const i={startOffset:e,endOffset:t,type:s};this.hls.trigger(p.BUFFER_FLUSHING,i)}_loadInitSegment(e,t){this._doFragLoad(e,t).then(s=>{if(!s||this.fragContextChanged(e)||!this.levels)throw new Error("init load aborted");return s}).then(s=>{const{hls:i}=this,{payload:r}=s,n=e.decryptdata;if(r&&r.byteLength>0&&n!=null&&n.key&&n.iv&&n.method==="AES-128"){const o=self.performance.now();return this.decrypter.decrypt(new Uint8Array(r),n.key.buffer,n.iv.buffer).catch(l=>{throw i.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.FRAG_DECRYPT_ERROR,fatal:!1,error:l,reason:l.message,frag:e}),l}).then(l=>{const c=self.performance.now();return i.trigger(p.FRAG_DECRYPTED,{frag:e,payload:l,stats:{tstart:o,tdecrypt:c}}),s.payload=l,this.completeInitSegmentLoad(s)})}return this.completeInitSegmentLoad(s)}).catch(s=>{this.state===O.STOPPED||this.state===O.ERROR||(this.warn(s),this.resetFragmentLoading(e))})}completeInitSegmentLoad(e){const{levels:t}=this;if(!t)throw new Error("init load aborted, missing levels");const s=e.frag.stats;this.state=O.IDLE,e.frag.data=new Uint8Array(e.payload),s.parsing.start=s.buffering.start=self.performance.now(),s.parsing.end=s.buffering.end=self.performance.now(),this.tick()}fragContextChanged(e){const{fragCurrent:t}=this;return!e||!t||e.sn!==t.sn||e.level!==t.level}fragBufferedComplete(e,t){var s,i,r,n;const o=this.mediaBuffer?this.mediaBuffer:this.media;if(this.log(`Buffered ${e.type} sn: ${e.sn}${t?" part: "+t.index:""} of ${this.playlistType===Q.MAIN?"level":"track"} ${e.level} (frag:[${((s=e.startPTS)!=null?s:NaN).toFixed(3)}-${((i=e.endPTS)!=null?i:NaN).toFixed(3)}] > buffer:${o?_h.toString(Ee.getBuffered(o)):"(detached)"})`),e.sn!=="initSegment"){var l;if(e.type!==Q.SUBTITLE){const h=e.elementaryStreams;if(!Object.keys(h).some(u=>!!h[u])){this.state=O.IDLE;return}}const c=(l=this.levels)==null?void 0:l[e.level];c!=null&&c.fragmentError&&(this.log(`Resetting level fragment error count of ${c.fragmentError} on frag buffered`),c.fragmentError=0)}this.state=O.IDLE,o&&(!this.loadedmetadata&&e.type==Q.MAIN&&o.buffered.length&&((r=this.fragCurrent)==null?void 0:r.sn)===((n=this.fragPrevious)==null?void 0:n.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())}seekToStartPos(){}_handleFragmentLoadComplete(e){const{transmuxer:t}=this;if(!t)return;const{frag:s,part:i,partsLoaded:r}=e,n=!r||r.length===0||r.some(l=>!l),o=new Lr(s.level,s.sn,s.stats.chunkCount+1,0,i?i.index:-1,!n);t.flush(o)}_handleFragmentLoadProgress(e){}_doFragLoad(e,t,s=null,i){var r;const n=t==null?void 0:t.details;if(!this.levels||!n)throw new Error(`frag load aborted, missing level${n?"":" detail"}s`);let o=null;if(e.encrypted&&!((r=e.decryptdata)!=null&&r.key)?(this.log(`Loading key for ${e.sn} of [${n.startSN}-${n.endSN}], ${this.logPrefix==="[stream-controller]"?"level":"track"} ${e.level}`),this.state=O.KEY_LOADING,this.fragCurrent=e,o=this.keyLoader.load(e).then(h=>{if(!this.fragContextChanged(h.frag))return this.hls.trigger(p.KEY_LOADED,h),this.state===O.KEY_LOADING&&(this.state=O.IDLE),h}),this.hls.trigger(p.KEY_LOADING,{frag:e}),this.fragCurrent===null&&(o=Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING")))):!e.encrypted&&n.encryptedFragments.length&&this.keyLoader.loadClear(e,n.encryptedFragments),s=Math.max(e.start,s||0),this.config.lowLatencyMode&&e.sn!=="initSegment"){const h=n.partList;if(h&&i){s>e.end&&n.fragmentHint&&(e=n.fragmentHint);const u=this.getNextPart(h,e,s);if(u>-1){const d=h[u];this.log(`Loading part sn: ${e.sn} p: ${d.index} cc: ${e.cc} of playlist [${n.startSN}-${n.endSN}] parts [0-${u}-${h.length-1}] ${this.logPrefix==="[stream-controller]"?"level":"track"}: ${e.level}, target: ${parseFloat(s.toFixed(3))}`),this.nextLoadPosition=d.start+d.duration,this.state=O.FRAG_LOADING;let f;return o?f=o.then(g=>!g||this.fragContextChanged(g.frag)?null:this.doFragPartsLoad(e,d,t,i)).catch(g=>this.handleFragLoadError(g)):f=this.doFragPartsLoad(e,d,t,i).catch(g=>this.handleFragLoadError(g)),this.hls.trigger(p.FRAG_LOADING,{frag:e,part:d,targetBufferTime:s}),this.fragCurrent===null?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):f}else if(!e.url||this.loadedEndOfParts(h,s))return Promise.resolve(null)}}this.log(`Loading fragment ${e.sn} cc: ${e.cc} ${n?"of ["+n.startSN+"-"+n.endSN+"] ":""}${this.logPrefix==="[stream-controller]"?"level":"track"}: ${e.level}, target: ${parseFloat(s.toFixed(3))}`),j(e.sn)&&!this.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),this.state=O.FRAG_LOADING;const l=this.config.progressive;let c;return l&&o?c=o.then(h=>!h||this.fragContextChanged(h==null?void 0:h.frag)?null:this.fragmentLoader.load(e,i)).catch(h=>this.handleFragLoadError(h)):c=Promise.all([this.fragmentLoader.load(e,l?i:void 0),o]).then(([h])=>(!l&&h&&i&&i(h),h)).catch(h=>this.handleFragLoadError(h)),this.hls.trigger(p.FRAG_LOADING,{frag:e,targetBufferTime:s}),this.fragCurrent===null?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):c}doFragPartsLoad(e,t,s,i){return new Promise((r,n)=>{var o;const l=[],c=(o=s.details)==null?void 0:o.partList,h=u=>{this.fragmentLoader.loadPart(e,u,i).then(d=>{l[u.index]=d;const f=d.part;this.hls.trigger(p.FRAG_LOADED,d);const g=qn(s,e.sn,u.index+1)||qa(c,e.sn,u.index+1);if(g)h(g);else return r({frag:e,part:f,partsLoaded:l})}).catch(n)};h(t)})}handleFragLoadError(e){if("data"in e){const t=e.data;e.data&&t.details===w.INTERNAL_ABORTED?this.handleFragLoadAborted(t.frag,t.part):this.hls.trigger(p.ERROR,t)}else this.hls.trigger(p.ERROR,{type:Z.OTHER_ERROR,details:w.INTERNAL_EXCEPTION,err:e,error:e,fatal:!0});return null}_handleTransmuxerFlush(e){const t=this.getCurrentContext(e);if(!t||this.state!==O.PARSING){!this.fragCurrent&&this.state!==O.STOPPED&&this.state!==O.ERROR&&(this.state=O.IDLE);return}const{frag:s,part:i,level:r}=t,n=self.performance.now();s.stats.parsing.end=n,i&&(i.stats.parsing.end=n),this.updateLevelTiming(s,i,r,e.partial)}getCurrentContext(e){const{levels:t,fragCurrent:s}=this,{level:i,sn:r,part:n}=e;if(!(t!=null&&t[i]))return this.warn(`Levels object was unset while buffering fragment ${r} of level ${i}. The current chunk will not be buffered.`),null;const o=t[i],l=n>-1?qn(o,r,n):null,c=l?l.fragment:eh(o,r,s);return c?(s&&s!==c&&(c.stats=s.stats),{frag:c,part:l,level:o}):null}bufferFragmentData(e,t,s,i,r){var n;if(!e||this.state!==O.PARSING)return;const{data1:o,data2:l}=e;let c=o;if(o&&l&&(c=Ze(o,l)),!((n=c)!=null&&n.length))return;const h={type:e.type,frag:t,part:s,chunkMeta:i,parent:t.type,data:c};if(this.hls.trigger(p.BUFFER_APPENDING,h),e.dropped&&e.independent&&!s){if(r)return;this.flushBufferGap(t)}}flushBufferGap(e){const t=this.media;if(!t)return;if(!Ee.isBuffered(t,t.currentTime)){this.flushMainBuffer(0,e.start);return}const s=t.currentTime,i=Ee.bufferInfo(t,s,0),r=e.duration,n=Math.min(this.config.maxFragLookUpTolerance*2,r*.25),o=Math.max(Math.min(e.start-n,i.end-n),s+n);e.start-o>n&&this.flushMainBuffer(o,e.start)}getFwdBufferInfo(e,t){const s=this.getLoadPosition();return j(s)?this.getFwdBufferInfoAtPos(e,s,t):null}getFwdBufferInfoAtPos(e,t,s){const{config:{maxBufferHole:i}}=this,r=Ee.bufferInfo(e,t,i);if(r.len===0&&r.nextStart!==void 0){const n=this.fragmentTracker.getBufferedFrag(t,s);if(n&&r.nextStart<n.end)return Ee.bufferInfo(e,t,Math.max(r.nextStart,i))}return r}getMaxBufferLength(e){const{config:t}=this;let s;return e?s=Math.max(8*t.maxBufferSize/e,t.maxBufferLength):s=t.maxBufferLength,Math.min(s,t.maxMaxBufferLength)}reduceMaxBufferLength(e,t){const s=this.config,i=Math.max(Math.min(e-t,s.maxBufferLength),t),r=Math.max(e-t*3,s.maxMaxBufferLength/2,i);return r>=i?(s.maxMaxBufferLength=r,this.warn(`Reduce max buffer length to ${r}s`),!0):!1}getAppendedFrag(e,t=Q.MAIN){const s=this.fragmentTracker.getAppendedFrag(e,Q.MAIN);return s&&"fragment"in s?s.fragment:s}getNextFragment(e,t){const s=t.fragments,i=s.length;if(!i)return null;const{config:r}=this,n=s[0].start;let o;if(t.live){const l=r.initialLiveManifestSize;if(i<l)return this.warn(`Not enough fragments to start playback (have: ${i}, need: ${l})`),null;(!t.PTSKnown&&!this.startFragRequested&&this.startPosition===-1||e<n)&&(o=this.getInitialLiveFragment(t,s),this.startPosition=this.nextLoadPosition=o?this.hls.liveSyncPosition||o.start:e)}else e<=n&&(o=s[0]);if(!o){const l=r.lowLatencyMode?t.partEnd:t.fragmentEnd;o=this.getFragmentAtPosition(e,l,t)}return this.mapToInitFragWhenRequired(o)}isLoopLoading(e,t){const s=this.fragmentTracker.getState(e);return(s===Fe.OK||s===Fe.PARTIAL&&!!e.gap)&&this.nextLoadPosition>t}getNextFragmentLoopLoading(e,t,s,i,r){const n=e.gap,o=this.getNextFragment(this.nextLoadPosition,t);if(o===null)return o;if(e=o,n&&e&&!e.gap&&s.nextStart){const l=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,s.nextStart,i);if(l!==null&&s.len+l.len>=r)return this.log(`buffer full after gaps in "${i}" playlist starting at sn: ${e.sn}`),null}return e}mapToInitFragWhenRequired(e){return e!=null&&e.initSegment&&!(e!=null&&e.initSegment.data)&&!this.bitrateTest?e.initSegment:e}getNextPart(e,t,s){let i=-1,r=!1,n=!0;for(let o=0,l=e.length;o<l;o++){const c=e[o];if(n=n&&!c.independent,i>-1&&s<c.start)break;const h=c.loaded;h?i=-1:(r||c.independent||n)&&c.fragment===t&&(i=o),r=h}return i}loadedEndOfParts(e,t){const s=e[e.length-1];return s&&t>s.start&&s.loaded}getInitialLiveFragment(e,t){const s=this.fragPrevious;let i=null;if(s){if(e.hasProgramDateTime&&(this.log(`Live playlist, switching playlist, load frag with same PDT: ${s.programDateTime}`),i=sh(t,s.endProgramDateTime,this.config.maxFragLookUpTolerance)),!i){const r=s.sn+1;if(r>=e.startSN&&r<=e.endSN){const n=t[r-e.startSN];s.cc===n.cc&&(i=n,this.log(`Live playlist, switching playlist, load frag with next SN: ${i.sn}`))}i||(i=nh(t,s.cc),i&&this.log(`Live playlist, switching playlist, load frag with same CC: ${i.sn}`))}}else{const r=this.hls.liveSyncPosition;r!==null&&(i=this.getFragmentAtPosition(r,this.bitrateTest?e.fragmentEnd:e.edge,e))}return i}getFragmentAtPosition(e,t,s){const{config:i}=this;let{fragPrevious:r}=this,{fragments:n,endSN:o}=s;const{fragmentHint:l}=s,{maxFragLookUpTolerance:c}=i,h=s.partList,u=!!(i.lowLatencyMode&&h!=null&&h.length&&l);u&&l&&!this.bitrateTest&&(n=n.concat(l),o=l.sn);let d;if(e<t){const f=e>t-c?0:c;d=ai(r,n,e,f)}else d=n[n.length-1];if(d){const f=d.sn-s.startSN,g=this.fragmentTracker.getState(d);if((g===Fe.OK||g===Fe.PARTIAL&&d.gap)&&(r=d),r&&d.sn===r.sn&&(!u||h[0].fragment.sn>d.sn)&&r&&d.level===r.level){const x=n[f+1];d.sn<o&&this.fragmentTracker.getState(x)!==Fe.OK?d=x:d=null}}return d}synchronizeToLiveEdge(e){const{config:t,media:s}=this;if(!s)return;const i=this.hls.liveSyncPosition,r=s.currentTime,n=e.fragments[0].start,o=e.edge,l=r>=n-t.maxFragLookUpTolerance&&r<=o;if(i!==null&&s.duration>i&&(r<i||!l)){const c=t.liveMaxLatencyDuration!==void 0?t.liveMaxLatencyDuration:t.liveMaxLatencyDurationCount*e.targetduration;(!l&&s.readyState<4||r<o-c)&&(this.loadedmetadata||(this.nextLoadPosition=i),s.readyState&&(this.warn(`Playback: ${r.toFixed(3)} is located too far from the end of live sliding playlist: ${o}, reset currentTime to : ${i.toFixed(3)}`),s.currentTime=i))}}alignPlaylists(e,t,s){const i=e.fragments.length;if(!i)return this.warn("No fragments in live playlist"),0;const r=e.fragments[0].start,n=!t,o=e.alignedSliding&&j(r);if(n||!o&&!r){const{fragPrevious:l}=this;Lh(l,s,e);const c=e.fragments[0].start;return this.log(`Live playlist sliding: ${c.toFixed(2)} start-sn: ${t?t.startSN:"na"}->${e.startSN} prev-sn: ${l?l.sn:"na"} fragments: ${i}`),c}return r}waitForCdnTuneIn(e){return e.live&&e.canBlockReload&&e.partTarget&&e.tuneInGoal>Math.max(e.partHoldBack,e.partTarget*3)}setStartPosition(e,t){let s=this.startPosition;if(s<t&&(s=-1),s===-1||this.lastCurrentTime===-1){const i=this.startTimeOffset!==null,r=i?this.startTimeOffset:e.startTimeOffset;r!==null&&j(r)?(s=t+r,r<0&&(s+=e.totalduration),s=Math.min(Math.max(t,s),t+e.totalduration),this.log(`Start time offset ${r} found in ${i?"multivariant":"media"} playlist, adjust startPosition to ${s}`),this.startPosition=s):e.live?s=this.hls.liveSyncPosition||t:this.startPosition=s=0,this.lastCurrentTime=s}this.nextLoadPosition=s}getLoadPosition(){const{media:e}=this;let t=0;return this.loadedmetadata&&e?t=e.currentTime:this.nextLoadPosition&&(t=this.nextLoadPosition),t}handleFragLoadAborted(e,t){this.transmuxer&&e.sn!=="initSegment"&&e.stats.aborted&&(this.warn(`Fragment ${e.sn}${t?" part "+t.index:""} of level ${e.level} was aborted`),this.resetFragmentLoading(e))}resetFragmentLoading(e){(!this.fragCurrent||!this.fragContextChanged(e)&&this.state!==O.FRAG_LOADING_WAITING_RETRY)&&(this.state=O.IDLE)}onFragmentOrKeyLoadError(e,t){if(t.chunkMeta&&!t.frag){const h=this.getCurrentContext(t.chunkMeta);h&&(t.frag=h.frag)}const s=t.frag;if(!s||s.type!==e||!this.levels)return;if(this.fragContextChanged(s)){var i;this.warn(`Frag load error must match current frag to retry ${s.url} > ${(i=this.fragCurrent)==null?void 0:i.url}`);return}const r=t.details===w.FRAG_GAP;r&&this.fragmentTracker.fragBuffered(s,!0);const n=t.errorAction,{action:o,retryCount:l=0,retryConfig:c}=n||{};if(n&&o===Be.RetryRequest&&c){this.resetStartWhenNotLoaded(this.levelLastLoaded);const h=vr(c,l);this.warn(`Fragment ${s.sn} of ${e} ${s.level} errored with ${t.details}, retrying loading ${l+1}/${c.maxNumRetry} in ${h}ms`),n.resolved=!0,this.retryDate=self.performance.now()+h,this.state=O.FRAG_LOADING_WAITING_RETRY}else if(c&&n)if(this.resetFragmentErrors(e),l<c.maxNumRetry)!r&&o!==Be.RemoveAlternatePermanently&&(n.resolved=!0);else{b.warn(`${t.details} reached or exceeded max retry (${l})`);return}else(n==null?void 0:n.action)===Be.SendAlternateToPenaltyBox?this.state=O.WAITING_LEVEL:this.state=O.ERROR;this.tickImmediate()}reduceLengthAndFlushBuffer(e){if(this.state===O.PARSING||this.state===O.PARSED){const t=e.frag,s=e.parent,i=this.getFwdBufferInfo(this.mediaBuffer,s),r=i&&i.len>.5;r&&this.reduceMaxBufferLength(i.len,(t==null?void 0:t.duration)||10);const n=!r;return n&&this.warn(`Buffer full error while media.currentTime is not buffered, flush ${s} buffer`),t&&(this.fragmentTracker.removeFragment(t),this.nextLoadPosition=t.start),this.resetLoadingState(),n}return!1}resetFragmentErrors(e){e===Q.AUDIO&&(this.fragCurrent=null),this.loadedmetadata||(this.startFragRequested=!1),this.state!==O.STOPPED&&(this.state=O.IDLE)}afterBufferFlushed(e,t,s){if(!e)return;const i=Ee.getBuffered(e);this.fragmentTracker.detectEvictedFragments(t,i,s),this.state===O.ENDED&&this.resetLoadingState()}resetLoadingState(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=O.IDLE}resetStartWhenNotLoaded(e){if(!this.loadedmetadata){this.startFragRequested=!1;const t=e?e.details:null;t!=null&&t.live?(this.startPosition=-1,this.setStartPosition(t,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}}resetWhenMissingContext(e){this.warn(`The loading context changed while buffering fragment ${e.sn} of level ${e.level}. This chunk will not be buffered.`),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState()}removeUnbufferedFrags(e=0){this.fragmentTracker.removeFragmentsInRange(e,1/0,this.playlistType,!1,!0)}updateLevelTiming(e,t,s,i){var r;const n=s.details;if(!n){this.warn("level.details undefined");return}if(!Object.keys(e.elementaryStreams).reduce((l,c)=>{const h=e.elementaryStreams[c];if(h){const u=h.endPTS-h.startPTS;if(u<=0)return this.warn(`Could not parse fragment ${e.sn} ${c} duration reliably (${u})`),l||!1;const d=i?0:Wa(n,e,h.startPTS,h.endPTS,h.startDTS,h.endDTS);return this.hls.trigger(p.LEVEL_PTS_UPDATED,{details:n,level:s,drift:d,type:c,frag:e,start:h.startPTS,end:h.endPTS}),!0}return l},!1)&&((r=this.transmuxer)==null?void 0:r.error)===null){const l=new Error(`Found no media in fragment ${e.sn} of level ${e.level} resetting transmuxer to fallback to playlist timing`);if(s.fragmentError===0&&(s.fragmentError++,e.gap=!0,this.fragmentTracker.removeFragment(e),this.fragmentTracker.fragBuffered(e,!0)),this.warn(l.message),this.hls.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.FRAG_PARSING_ERROR,fatal:!1,error:l,frag:e,reason:`Found no media in msn ${e.sn} of level "${s.url}"`}),!this.hls)return;this.resetTransmuxer()}this.state=O.PARSED,this.hls.trigger(p.FRAG_PARSED,{frag:e,part:t})}resetTransmuxer(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)}recoverWorkerError(e){e.event==="demuxerWorker"&&(this.fragmentTracker.removeAllFragments(),this.resetTransmuxer(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState())}set state(e){const t=this._state;t!==e&&(this._state=e,this.log(`${t}->${e}`))}get state(){return this._state}}class Za{constructor(){this.chunks=[],this.dataLength=0}push(e){this.chunks.push(e),this.dataLength+=e.length}flush(){const{chunks:e,dataLength:t}=this;let s;if(e.length)e.length===1?s=e[0]:s=Ph(e,t);else return new Uint8Array(0);return this.reset(),s}reset(){this.chunks.length=0,this.dataLength=0}}function Ph(a,e){const t=new Uint8Array(e);let s=0;for(let i=0;i<a.length;i++){const r=a[i];t.set(r,s),s+=r.length}return t}function Mh(){return typeof __HLS_WORKER_BUNDLE__=="function"}function Fh(){const a=new self.Blob([`var exports={};var module={exports:exports};function define(f){f()};define.amd=true;(${__HLS_WORKER_BUNDLE__.toString()})(true);`],{type:"text/javascript"}),e=self.URL.createObjectURL(a);return{worker:new self.Worker(e),objectURL:e}}function Oh(a){const e=new self.URL(a,self.location.href).href;return{worker:new self.Worker(e),scriptURL:e}}function lt(a="",e=9e4){return{type:a,id:-1,pid:-1,inputTimeScale:e,sequenceNumber:-1,samples:[],dropped:0}}class Ir{constructor(){this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null,this.lastPTS=null}resetInitSegment(e,t,s,i){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}}resetTimeStamp(e){this.initPTS=e,this.resetContiguity()}resetContiguity(){this.basePTS=null,this.lastPTS=null,this.frameIndex=0}canParse(e,t){return!1}appendFrame(e,t,s){}demux(e,t){this.cachedData&&(e=Ze(this.cachedData,e),this.cachedData=null);let s=ys(e,0),i=s?s.length:0,r;const n=this._audioTrack,o=this._id3Track,l=s?Sr(s):void 0,c=e.length;for((this.basePTS===null||this.frameIndex===0&&j(l))&&(this.basePTS=Nh(l,t,this.initPTS),this.lastPTS=this.basePTS),this.lastPTS===null&&(this.lastPTS=this.basePTS),s&&s.length>0&&o.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:s,type:it.audioId3,duration:Number.POSITIVE_INFINITY});i<c;){if(this.canParse(e,i)){const h=this.appendFrame(n,e,i);h?(this.frameIndex++,this.lastPTS=h.sample.pts,i+=h.length,r=i):i=c}else rc(e,i)?(s=ys(e,i),o.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:s,type:it.audioId3,duration:Number.POSITIVE_INFINITY}),i+=s.length,r=i):i++;if(i===c&&r!==c){const h=Ft(e,r);this.cachedData?this.cachedData=Ze(this.cachedData,h):this.cachedData=h}}return{audioTrack:n,videoTrack:lt(),id3Track:o,textTrack:lt()}}demuxSampleAes(e,t,s){return Promise.reject(new Error(`[${this}] This demuxer does not support Sample-AES decryption`))}flush(e){const t=this.cachedData;return t&&(this.cachedData=null,this.demux(t,0)),{audioTrack:this._audioTrack,videoTrack:lt(),id3Track:this._id3Track,textTrack:lt()}}destroy(){}}const Nh=(a,e,t)=>{if(j(a))return a*90;const s=t?t.baseTime*9e4/t.timescale:0;return e*9e4+s};function Uh(a,e,t,s){let i,r,n,o;const l=navigator.userAgent.toLowerCase(),c=s,h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i=((e[t+2]&192)>>>6)+1;const u=(e[t+2]&60)>>>2;if(u>h.length-1){const d=new Error(`invalid ADTS sampling index:${u}`);a.emit(p.ERROR,p.ERROR,{type:Z.MEDIA_ERROR,details:w.FRAG_PARSING_ERROR,fatal:!0,error:d,reason:d.message});return}return n=(e[t+2]&1)<<2,n|=(e[t+3]&192)>>>6,b.log(`manifest codec:${s}, ADTS type:${i}, samplingIndex:${u}`),/firefox/i.test(l)?u>=6?(i=5,o=new Array(4),r=u-3):(i=2,o=new Array(2),r=u):l.indexOf("android")!==-1?(i=2,o=new Array(2),r=u):(i=5,o=new Array(4),s&&(s.indexOf("mp4a.40.29")!==-1||s.indexOf("mp4a.40.5")!==-1)||!s&&u>=6?r=u-3:((s&&s.indexOf("mp4a.40.2")!==-1&&(u>=6&&n===1||/vivaldi/i.test(l))||!s&&n===1)&&(i=2,o=new Array(2)),r=u)),o[0]=i<<3,o[0]|=(u&14)>>1,o[1]|=(u&1)<<7,o[1]|=n<<3,i===5&&(o[1]|=(r&14)>>1,o[2]=(r&1)<<7,o[2]|=8,o[3]=0),{config:o,samplerate:h[u],channelCount:n,codec:"mp4a.40."+i,manifestCodec:c}}function eo(a,e){return a[e]===255&&(a[e+1]&246)===240}function to(a,e){return a[e+1]&1?7:9}function Dr(a,e){return(a[e+3]&3)<<11|a[e+4]<<3|(a[e+5]&224)>>>5}function Bh(a,e){return e+5<a.length}function li(a,e){return e+1<a.length&&eo(a,e)}function $h(a,e){return Bh(a,e)&&eo(a,e)&&Dr(a,e)<=a.length-e}function Gh(a,e){if(li(a,e)){const t=to(a,e);if(e+t>=a.length)return!1;const s=Dr(a,e);if(s<=t)return!1;const i=e+s;return i===a.length||li(a,i)}return!1}function so(a,e,t,s,i){if(!a.samplerate){const r=Uh(e,t,s,i);if(!r)return;a.config=r.config,a.samplerate=r.samplerate,a.channelCount=r.channelCount,a.codec=r.codec,a.manifestCodec=r.manifestCodec,b.log(`parsed codec:${a.codec}, rate:${r.samplerate}, channels:${r.channelCount}`)}}function io(a){return 1024*9e4/a}function Kh(a,e){const t=to(a,e);if(e+t<=a.length){const s=Dr(a,e)-t;if(s>0)return{headerLength:t,frameLength:s}}}function ro(a,e,t,s,i){const r=io(a.samplerate),n=s+i*r,o=Kh(e,t);let l;if(o){const{frameLength:u,headerLength:d}=o,f=d+u,g=Math.max(0,t+f-e.length);g?(l=new Uint8Array(f-d),l.set(e.subarray(t+d,e.length),0)):l=e.subarray(t+d,t+f);const m={unit:l,pts:n};return g||a.samples.push(m),{sample:m,length:f,missing:g}}const c=e.length-t;return l=new Uint8Array(c),l.set(e.subarray(t,e.length),0),{sample:{unit:l,pts:n},length:c,missing:-1}}let Us=null;const Hh=[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],Vh=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],jh=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],Wh=[0,1,1,4];function no(a,e,t,s,i){if(t+24>e.length)return;const r=ao(e,t);if(r&&t+r.frameLength<=e.length){const n=r.samplesPerFrame*9e4/r.sampleRate,o=s+i*n,l={unit:e.subarray(t,t+r.frameLength),pts:o,dts:o};return a.config=[],a.channelCount=r.channelCount,a.samplerate=r.sampleRate,a.samples.push(l),{sample:l,length:r.frameLength,missing:0}}}function ao(a,e){const t=a[e+1]>>3&3,s=a[e+1]>>1&3,i=a[e+2]>>4&15,r=a[e+2]>>2&3;if(t!==1&&i!==0&&i!==15&&r!==3){const n=a[e+2]>>1&1,o=a[e+3]>>6,l=t===3?3-s:s===3?3:4,c=Hh[l*14+i-1]*1e3,u=Vh[(t===3?0:t===2?1:2)*3+r],d=o===3?1:2,f=jh[t][s],g=Wh[s],m=f*8*g,x=Math.floor(f*c/u+n)*g;if(Us===null){const v=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Us=v?parseInt(v[1]):0}return!!Us&&Us<=87&&s===2&&c>=224e3&&o===0&&(a[e+3]=a[e+3]|128),{sampleRate:u,channelCount:d,frameLength:x,samplesPerFrame:m}}}function Cr(a,e){return a[e]===255&&(a[e+1]&224)===224&&(a[e+1]&6)!==0}function oo(a,e){return e+1<a.length&&Cr(a,e)}function Yh(a,e){return Cr(a,e)&&4<=a.length-e}function lo(a,e){if(e+1<a.length&&Cr(a,e)){const s=ao(a,e);let i=4;s!=null&&s.frameLength&&(i=s.frameLength);const r=e+i;return r===a.length||oo(a,r)}return!1}class qh extends Ir{constructor(e,t){super(),this.observer=void 0,this.config=void 0,this.observer=e,this.config=t}resetInitSegment(e,t,s,i){super.resetInitSegment(e,t,s,i),this._audioTrack={container:"audio/adts",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"aac",samples:[],manifestCodec:t,duration:i,inputTimeScale:9e4,dropped:0}}static probe(e){if(!e)return!1;const t=ys(e,0);let s=(t==null?void 0:t.length)||0;if(lo(e,s))return!1;for(let i=e.length;s<i;s++)if(Gh(e,s))return b.log("ADTS sync word found !"),!0;return!1}canParse(e,t){return $h(e,t)}appendFrame(e,t,s){so(e,this.observer,t,s,e.manifestCodec);const i=ro(e,t,s,this.basePTS,this.frameIndex);if(i&&i.missing===0)return i}}const zh=/\/emsg[-/]ID3/i;class Xh{constructor(e,t){this.remainderData=null,this.timeOffset=0,this.config=void 0,this.videoTrack=void 0,this.audioTrack=void 0,this.id3Track=void 0,this.txtTrack=void 0,this.config=t}resetTimeStamp(){}resetInitSegment(e,t,s,i){const r=this.videoTrack=lt("video",1),n=this.audioTrack=lt("audio",1),o=this.txtTrack=lt("text",1);if(this.id3Track=lt("id3",1),this.timeOffset=0,!(e!=null&&e.byteLength))return;const l=Ua(e);if(l.video){const{id:c,timescale:h,codec:u}=l.video;r.id=c,r.timescale=o.timescale=h,r.codec=u}if(l.audio){const{id:c,timescale:h,codec:u}=l.audio;n.id=c,n.timescale=h,n.codec=u}o.id=Fa.text,r.sampleDuration=0,r.duration=n.duration=i}resetContiguity(){this.remainderData=null}static probe(e){return fc(e)}demux(e,t){this.timeOffset=t;let s=e;const i=this.videoTrack,r=this.txtTrack;if(this.config.progressive){this.remainderData&&(s=Ze(this.remainderData,e));const o=Sc(s);this.remainderData=o.remainder,i.samples=o.valid||new Uint8Array}else i.samples=s;const n=this.extractID3Track(i,t);return r.samples=Cn(t,i),{videoTrack:i,audioTrack:this.audioTrack,id3Track:n,textTrack:this.txtTrack}}flush(){const e=this.timeOffset,t=this.videoTrack,s=this.txtTrack;t.samples=this.remainderData||new Uint8Array,this.remainderData=null;const i=this.extractID3Track(t,this.timeOffset);return s.samples=Cn(e,t),{videoTrack:t,audioTrack:lt(),id3Track:i,textTrack:lt()}}extractID3Track(e,t){const s=this.id3Track;if(e.samples.length){const i=ne(e.samples,["emsg"]);i&&i.forEach(r=>{const n=Lc(r);if(zh.test(n.schemeIdUri)){const o=j(n.presentationTime)?n.presentationTime/n.timeScale:t+n.presentationTimeDelta/n.timeScale;let l=n.eventDuration===4294967295?Number.POSITIVE_INFINITY:n.eventDuration/n.timeScale;l<=.001&&(l=Number.POSITIVE_INFINITY);const c=n.payload;s.samples.push({data:c,len:c.byteLength,dts:o,pts:o,type:it.emsg,duration:l})}})}return s}demuxSampleAes(e,t,s){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))}destroy(){}}const co=(a,e)=>{let t=0,s=5;e+=s;const i=new Uint32Array(1),r=new Uint32Array(1),n=new Uint8Array(1);for(;s>0;){n[0]=a[e];const o=Math.min(s,8),l=8-o;r[0]=4278190080>>>24+l<<l,i[0]=(n[0]&r[0])>>l,t=t?t<<o|i[0]:i[0],e+=1,s-=o}return t};class Qh extends Ir{constructor(e){super(),this.observer=void 0,this.observer=e}resetInitSegment(e,t,s,i){super.resetInitSegment(e,t,s,i),this._audioTrack={container:"audio/ac-3",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"ac3",samples:[],manifestCodec:t,duration:i,inputTimeScale:9e4,dropped:0}}canParse(e,t){return t+64<e.length}appendFrame(e,t,s){const i=ho(e,t,s,this.basePTS,this.frameIndex);if(i!==-1)return{sample:e.samples[e.samples.length-1],length:i,missing:0}}static probe(e){if(!e)return!1;const t=ys(e,0);if(!t)return!1;const s=t.length;return e[s]===11&&e[s+1]===119&&Sr(t)!==void 0&&co(e,s)<16}}function ho(a,e,t,s,i){if(t+8>e.length||e[t]!==11||e[t+1]!==119)return-1;const r=e[t+4]>>6;if(r>=3)return-1;const o=[48e3,44100,32e3][r],l=e[t+4]&63,h=[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][l*3+r]*2;if(t+h>e.length)return-1;const u=e[t+6]>>5;let d=0;u===2?d+=2:(u&1&&u!==1&&(d+=2),u&4&&(d+=2));const f=(e[t+6]<<8|e[t+7])>>12-d&1,m=[2,1,2,3,3,4,4,5][u]+f,x=e[t+5]>>3,T=e[t+5]&7,R=new Uint8Array([r<<6|x<<1|T>>2,(T&3)<<6|u<<3|f<<2|l>>4,l<<4&224]),v=1536/o*9e4,D=s+i*v,L=e.subarray(t,t+h);return a.config=R,a.channelCount=m,a.samplerate=o,a.samples.push({unit:L,pts:D}),h}class Jh{constructor(){this.VideoSample=null}createVideoSample(e,t,s,i){return{key:e,frame:!1,pts:t,dts:s,units:[],debug:i,length:0}}getLastNalUnit(e){var t;let s=this.VideoSample,i;if((!s||s.units.length===0)&&(s=e[e.length-1]),(t=s)!=null&&t.units){const r=s.units;i=r[r.length-1]}return i}pushAccessUnit(e,t){if(e.units.length&&e.frame){if(e.pts===void 0){const s=t.samples,i=s.length;if(i){const r=s[i-1];e.pts=r.pts,e.dts=r.dts}else{t.dropped++;return}}t.samples.push(e)}e.debug.length&&b.log(e.pts+"/"+e.dts+":"+e.debug)}}class ia{constructor(e){this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=e,this.bytesAvailable=e.byteLength,this.word=0,this.bitsAvailable=0}loadWord(){const e=this.data,t=this.bytesAvailable,s=e.byteLength-t,i=new Uint8Array(4),r=Math.min(4,t);if(r===0)throw new Error("no bytes available");i.set(e.subarray(s,s+r)),this.word=new DataView(i.buffer).getUint32(0),this.bitsAvailable=r*8,this.bytesAvailable-=r}skipBits(e){let t;e=Math.min(e,this.bytesAvailable*8+this.bitsAvailable),this.bitsAvailable>e?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,t=e>>3,e-=t<<3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)}readBits(e){let t=Math.min(this.bitsAvailable,e);const s=this.word>>>32-t;if(e>32&&b.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0)this.word<<=t;else if(this.bytesAvailable>0)this.loadWord();else throw new Error("no bits available");return t=e-t,t>0&&this.bitsAvailable?s<<t|this.readBits(t):s}skipLZ(){let e;for(e=0;e<this.bitsAvailable;++e)if(this.word&2147483648>>>e)return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()}skipUEG(){this.skipBits(1+this.skipLZ())}skipEG(){this.skipBits(1+this.skipLZ())}readUEG(){const e=this.skipLZ();return this.readBits(e+1)-1}readEG(){const e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}readBoolean(){return this.readBits(1)===1}readUByte(){return this.readBits(8)}readUShort(){return this.readBits(16)}readUInt(){return this.readBits(32)}skipScalingList(e){let t=8,s=8,i;for(let r=0;r<e;r++)s!==0&&(i=this.readEG(),s=(t+i+256)%256),t=s===0?t:s}readSPS(){let e=0,t=0,s=0,i=0,r,n,o;const l=this.readUByte.bind(this),c=this.readBits.bind(this),h=this.readUEG.bind(this),u=this.readBoolean.bind(this),d=this.skipBits.bind(this),f=this.skipEG.bind(this),g=this.skipUEG.bind(this),m=this.skipScalingList.bind(this);l();const x=l();if(c(5),d(3),l(),g(),x===100||x===110||x===122||x===244||x===44||x===83||x===86||x===118||x===128){const _=h();if(_===3&&d(1),g(),g(),d(1),u())for(n=_!==3?8:12,o=0;o<n;o++)u()&&(o<6?m(16):m(64))}g();const T=h();if(T===0)h();else if(T===1)for(d(1),f(),f(),r=h(),o=0;o<r;o++)f();g(),d(1);const R=h(),v=h(),D=c(1);D===0&&d(1),d(1),u()&&(e=h(),t=h(),s=h(),i=h());let L=[1,1];if(u()&&u())switch(l()){case 1:L=[1,1];break;case 2:L=[12,11];break;case 3:L=[10,11];break;case 4:L=[16,11];break;case 5:L=[40,33];break;case 6:L=[24,11];break;case 7:L=[20,11];break;case 8:L=[32,11];break;case 9:L=[80,33];break;case 10:L=[18,11];break;case 11:L=[15,11];break;case 12:L=[64,33];break;case 13:L=[160,99];break;case 14:L=[4,3];break;case 15:L=[3,2];break;case 16:L=[2,1];break;case 255:{L=[l()<<8|l(),l()<<8|l()];break}}return{width:Math.ceil((R+1)*16-e*2-t*2),height:(2-D)*(v+1)*16-(D?2:4)*(s+i),pixelRatio:L}}readSliceType(){return this.readUByte(),this.readUEG(),this.readUEG()}}class Zh extends Jh{parseAVCPES(e,t,s,i,r){const n=this.parseAVCNALu(e,s.data);let o=this.VideoSample,l,c=!1;s.data=null,o&&n.length&&!e.audFound&&(this.pushAccessUnit(o,e),o=this.VideoSample=this.createVideoSample(!1,s.pts,s.dts,"")),n.forEach(h=>{var u;switch(h.type){case 1:{let m=!1;l=!0;const x=h.data;if(c&&x.length>4){const T=new ia(x).readSliceType();(T===2||T===4||T===7||T===9)&&(m=!0)}if(m){var d;(d=o)!=null&&d.frame&&!o.key&&(this.pushAccessUnit(o,e),o=this.VideoSample=null)}o||(o=this.VideoSample=this.createVideoSample(!0,s.pts,s.dts,"")),o.frame=!0,o.key=m;break}case 5:l=!0,(u=o)!=null&&u.frame&&!o.key&&(this.pushAccessUnit(o,e),o=this.VideoSample=null),o||(o=this.VideoSample=this.createVideoSample(!0,s.pts,s.dts,"")),o.key=!0,o.frame=!0;break;case 6:{l=!0,$a(h.data,1,s.pts,t.samples);break}case 7:{var f,g;l=!0,c=!0;const m=h.data,T=new ia(m).readSPS();if(!e.sps||e.width!==T.width||e.height!==T.height||((f=e.pixelRatio)==null?void 0:f[0])!==T.pixelRatio[0]||((g=e.pixelRatio)==null?void 0:g[1])!==T.pixelRatio[1]){e.width=T.width,e.height=T.height,e.pixelRatio=T.pixelRatio,e.sps=[m],e.duration=r;const R=m.subarray(1,4);let v="avc1.";for(let D=0;D<3;D++){let L=R[D].toString(16);L.length<2&&(L="0"+L),v+=L}e.codec=v}break}case 8:l=!0,e.pps=[h.data];break;case 9:l=!0,e.audFound=!0,o&&this.pushAccessUnit(o,e),o=this.VideoSample=this.createVideoSample(!1,s.pts,s.dts,"");break;case 12:l=!0;break;default:l=!1,o&&(o.debug+="unknown NAL "+h.type+" ");break}o&&l&&o.units.push(h)}),i&&o&&(this.pushAccessUnit(o,e),this.VideoSample=null)}parseAVCNALu(e,t){const s=t.byteLength;let i=e.naluState||0;const r=i,n=[];let o=0,l,c,h,u=-1,d=0;for(i===-1&&(u=0,d=t[0]&31,i=0,o=1);o<s;){if(l=t[o++],!i){i=l?0:1;continue}if(i===1){i=l?0:2;continue}if(!l)i=3;else if(l===1){if(c=o-i-1,u>=0){const f={data:t.subarray(u,c),type:d};n.push(f)}else{const f=this.getLastNalUnit(e.samples);f&&(r&&o<=4-r&&f.state&&(f.data=f.data.subarray(0,f.data.byteLength-r)),c>0&&(f.data=Ze(f.data,t.subarray(0,c)),f.state=0))}o<s?(h=t[o]&31,u=o,d=h,i=0):i=-1}else i=0}if(u>=0&&i>=0){const f={data:t.subarray(u,s),type:d,state:i};n.push(f)}if(n.length===0){const f=this.getLastNalUnit(e.samples);f&&(f.data=Ze(f.data,t))}return e.naluState=i,n}}class eu{constructor(e,t,s){this.keyData=void 0,this.decrypter=void 0,this.keyData=s,this.decrypter=new Rr(t,{removePKCS7Padding:!1})}decryptBuffer(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer)}decryptAacSample(e,t,s){const i=e[t].unit;if(i.length<=16)return;const r=i.subarray(16,i.length-i.length%16),n=r.buffer.slice(r.byteOffset,r.byteOffset+r.length);this.decryptBuffer(n).then(o=>{const l=new Uint8Array(o);i.set(l,16),this.decrypter.isSync()||this.decryptAacSamples(e,t+1,s)})}decryptAacSamples(e,t,s){for(;;t++){if(t>=e.length){s();return}if(!(e[t].unit.length<32)&&(this.decryptAacSample(e,t,s),!this.decrypter.isSync()))return}}getAvcEncryptedData(e){const t=Math.floor((e.length-48)/160)*16+16,s=new Int8Array(t);let i=0;for(let r=32;r<e.length-16;r+=160,i+=16)s.set(e.subarray(r,r+16),i);return s}getAvcDecryptedUnit(e,t){const s=new Uint8Array(t);let i=0;for(let r=32;r<e.length-16;r+=160,i+=16)e.set(s.subarray(i,i+16),r);return e}decryptAvcSample(e,t,s,i,r){const n=Ga(r.data),o=this.getAvcEncryptedData(n);this.decryptBuffer(o.buffer).then(l=>{r.data=this.getAvcDecryptedUnit(n,l),this.decrypter.isSync()||this.decryptAvcSamples(e,t,s+1,i)})}decryptAvcSamples(e,t,s,i){if(e instanceof Uint8Array)throw new Error("Cannot decrypt samples of type Uint8Array");for(;;t++,s=0){if(t>=e.length){i();return}const r=e[t].units;for(;!(s>=r.length);s++){const n=r[s];if(!(n.data.length<=48||n.type!==1&&n.type!==5)&&(this.decryptAvcSample(e,t,s,i,n),!this.decrypter.isSync()))return}}}}const Me=188;class Rt{constructor(e,t,s){this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._videoTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.remainderData=null,this.videoParser=void 0,this.observer=e,this.config=t,this.typeSupported=s,this.videoParser=new Zh}static probe(e){const t=Rt.syncOffset(e);return t>0&&b.warn(`MPEG2-TS detected but first sync word found @ offset ${t}`),t!==-1}static syncOffset(e){const t=e.length;let s=Math.min(Me*5,t-Me)+1,i=0;for(;i<s;){let r=!1,n=-1,o=0;for(let l=i;l<t;l+=Me)if(e[l]===71&&(t-l===Me||e[l+Me]===71)){if(o++,n===-1&&(n=l,n!==0&&(s=Math.min(n+Me*99,e.length-Me)+1)),r||(r=lr(e,l)===0),r&&o>1&&(n===0&&o>2||l+Me>s))return n}else{if(o)return-1;break}i++}return-1}static createTrack(e,t){return{container:e==="video"||e==="audio"?"video/mp2t":void 0,type:e,id:Fa[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:e==="audio"?t:void 0}}resetInitSegment(e,t,s,i){this.pmtParsed=!1,this._pmtId=-1,this._videoTrack=Rt.createTrack("video"),this._audioTrack=Rt.createTrack("audio",i),this._id3Track=Rt.createTrack("id3"),this._txtTrack=Rt.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.remainderData=null,this.audioCodec=t,this.videoCodec=s,this._duration=i}resetTimeStamp(){}resetContiguity(){const{_audioTrack:e,_videoTrack:t,_id3Track:s}=this;e&&(e.pesData=null),t&&(t.pesData=null),s&&(s.pesData=null),this.aacOverFlow=null,this.remainderData=null}demux(e,t,s=!1,i=!1){s||(this.sampleAes=null);let r;const n=this._videoTrack,o=this._audioTrack,l=this._id3Track,c=this._txtTrack;let h=n.pid,u=n.pesData,d=o.pid,f=l.pid,g=o.pesData,m=l.pesData,x=null,T=this.pmtParsed,R=this._pmtId,v=e.length;if(this.remainderData&&(e=Ze(this.remainderData,e),v=e.length,this.remainderData=null),v<Me&&!i)return this.remainderData=e,{audioTrack:o,videoTrack:n,id3Track:l,textTrack:c};const D=Math.max(0,Rt.syncOffset(e));v-=(v-D)%Me,v<e.byteLength&&!i&&(this.remainderData=new Uint8Array(e.buffer,v,e.buffer.byteLength-v));let L=0;for(let k=D;k<v;k+=Me)if(e[k]===71){const B=!!(e[k+1]&64),G=lr(e,k),P=(e[k+3]&48)>>4;let U;if(P>1){if(U=k+5+e[k+4],U===k+Me)continue}else U=k+4;switch(G){case h:B&&(u&&(r=jt(u))&&this.videoParser.parseAVCPES(n,c,r,!1,this._duration),u={data:[],size:0}),u&&(u.data.push(e.subarray(U,k+Me)),u.size+=k+Me-U);break;case d:if(B){if(g&&(r=jt(g)))switch(o.segmentCodec){case"aac":this.parseAACPES(o,r);break;case"mp3":this.parseMPEGPES(o,r);break;case"ac3":this.parseAC3PES(o,r);break}g={data:[],size:0}}g&&(g.data.push(e.subarray(U,k+Me)),g.size+=k+Me-U);break;case f:B&&(m&&(r=jt(m))&&this.parseID3PES(l,r),m={data:[],size:0}),m&&(m.data.push(e.subarray(U,k+Me)),m.size+=k+Me-U);break;case 0:B&&(U+=e[U]+1),R=this._pmtId=tu(e,U);break;case R:{B&&(U+=e[U]+1);const ee=su(e,U,this.typeSupported,s,this.observer);h=ee.videoPid,h>0&&(n.pid=h,n.segmentCodec=ee.segmentVideoCodec),d=ee.audioPid,d>0&&(o.pid=d,o.segmentCodec=ee.segmentAudioCodec),f=ee.id3Pid,f>0&&(l.pid=f),x!==null&&!T&&(b.warn(`MPEG-TS PMT found at ${k} after unknown PID '${x}'. Backtracking to sync byte @${D} to parse all TS packets.`),x=null,k=D-188),T=this.pmtParsed=!0;break}case 17:case 8191:break;default:x=G;break}}else L++;L>0&&ci(this.observer,new Error(`Found ${L} TS packet/s that do not start with 0x47`)),n.pesData=u,o.pesData=g,l.pesData=m;const _={audioTrack:o,videoTrack:n,id3Track:l,textTrack:c};return i&&this.extractRemainingSamples(_),_}flush(){const{remainderData:e}=this;this.remainderData=null;let t;return e?t=this.demux(e,-1,!1,!0):t={videoTrack:this._videoTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(t),this.sampleAes?this.decrypt(t,this.sampleAes):t}extractRemainingSamples(e){const{audioTrack:t,videoTrack:s,id3Track:i,textTrack:r}=e,n=s.pesData,o=t.pesData,l=i.pesData;let c;if(n&&(c=jt(n))?(this.videoParser.parseAVCPES(s,r,c,!0,this._duration),s.pesData=null):s.pesData=n,o&&(c=jt(o))){switch(t.segmentCodec){case"aac":this.parseAACPES(t,c);break;case"mp3":this.parseMPEGPES(t,c);break;case"ac3":this.parseAC3PES(t,c);break}t.pesData=null}else o!=null&&o.size&&b.log("last AAC PES packet truncated,might overlap between fragments"),t.pesData=o;l&&(c=jt(l))?(this.parseID3PES(i,c),i.pesData=null):i.pesData=l}demuxSampleAes(e,t,s){const i=this.demux(e,s,!0,!this.config.progressive),r=this.sampleAes=new eu(this.observer,this.config,t);return this.decrypt(i,r)}decrypt(e,t){return new Promise(s=>{const{audioTrack:i,videoTrack:r}=e;i.samples&&i.segmentCodec==="aac"?t.decryptAacSamples(i.samples,0,()=>{r.samples?t.decryptAvcSamples(r.samples,0,0,()=>{s(e)}):s(e)}):r.samples&&t.decryptAvcSamples(r.samples,0,0,()=>{s(e)})})}destroy(){this._duration=0}parseAACPES(e,t){let s=0;const i=this.aacOverFlow;let r=t.data;if(i){this.aacOverFlow=null;const u=i.missing,d=i.sample.unit.byteLength;if(u===-1)r=Ze(i.sample.unit,r);else{const f=d-u;i.sample.unit.set(r.subarray(0,u),f),e.samples.push(i.sample),s=i.missing}}let n,o;for(n=s,o=r.length;n<o-1&&!li(r,n);n++);if(n!==s){let u;const d=n<o-1;if(d?u=`AAC PES did not start with ADTS header,offset:${n}`:u="No ADTS header found in AAC PES",ci(this.observer,new Error(u),d),!d)return}so(e,this.observer,r,n,this.audioCodec);let l;if(t.pts!==void 0)l=t.pts;else if(i){const u=io(e.samplerate);l=i.sample.pts+u}else{b.warn("[tsdemuxer]: AAC PES unknown PTS");return}let c=0,h;for(;n<o;)if(h=ro(e,r,n,l,c),n+=h.length,h.missing){this.aacOverFlow=h;break}else for(c++;n<o-1&&!li(r,n);n++);}parseMPEGPES(e,t){const s=t.data,i=s.length;let r=0,n=0;const o=t.pts;if(o===void 0){b.warn("[tsdemuxer]: MPEG PES unknown PTS");return}for(;n<i;)if(oo(s,n)){const l=no(e,s,n,o,r);if(l)n+=l.length,r++;else break}else n++}parseAC3PES(e,t){{const s=t.data,i=t.pts;if(i===void 0){b.warn("[tsdemuxer]: AC3 PES unknown PTS");return}const r=s.length;let n=0,o=0,l;for(;o<r&&(l=ho(e,s,o,i,n++))>0;)o+=l}}parseID3PES(e,t){if(t.pts===void 0){b.warn("[tsdemuxer]: ID3 PES unknown PTS");return}const s=we({},t,{type:this._videoTrack?it.emsg:it.audioId3,duration:Number.POSITIVE_INFINITY});e.samples.push(s)}}function lr(a,e){return((a[e+1]&31)<<8)+a[e+2]}function tu(a,e){return(a[e+10]&31)<<8|a[e+11]}function su(a,e,t,s,i){const r={audioPid:-1,videoPid:-1,id3Pid:-1,segmentVideoCodec:"avc",segmentAudioCodec:"aac"},n=(a[e+1]&15)<<8|a[e+2],o=e+3+n-4,l=(a[e+10]&15)<<8|a[e+11];for(e+=12+l;e<o;){const c=lr(a,e),h=(a[e+3]&15)<<8|a[e+4];switch(a[e]){case 207:if(!s){Gi("ADTS AAC");break}case 15:r.audioPid===-1&&(r.audioPid=c);break;case 21:r.id3Pid===-1&&(r.id3Pid=c);break;case 219:if(!s){Gi("H.264");break}case 27:r.videoPid===-1&&(r.videoPid=c,r.segmentVideoCodec="avc");break;case 3:case 4:!t.mpeg&&!t.mp3?b.log("MPEG audio found, not supported in this browser"):r.audioPid===-1&&(r.audioPid=c,r.segmentAudioCodec="mp3");break;case 193:if(!s){Gi("AC-3");break}case 129:t.ac3?r.audioPid===-1&&(r.audioPid=c,r.segmentAudioCodec="ac3"):b.log("AC-3 audio found, not supported in this browser");break;case 6:if(r.audioPid===-1&&h>0){let u=e+5,d=h;for(;d>2;){switch(a[u]){case 106:t.ac3!==!0?b.log("AC-3 audio found, not supported in this browser for now"):(r.audioPid=c,r.segmentAudioCodec="ac3");break}const g=a[u+1]+2;u+=g,d-=g}}break;case 194:case 135:return ci(i,new Error("Unsupported EC-3 in M2TS found")),r;case 36:return ci(i,new Error("Unsupported HEVC in M2TS found")),r}e+=h+5}return r}function ci(a,e,t){b.warn(`parsing error: ${e.message}`),a.emit(p.ERROR,p.ERROR,{type:Z.MEDIA_ERROR,details:w.FRAG_PARSING_ERROR,fatal:!1,levelRetry:t,error:e,reason:e.message})}function Gi(a){b.log(`${a} with AES-128-CBC encryption found in unencrypted stream`)}function jt(a){let e=0,t,s,i,r,n;const o=a.data;if(!a||a.size===0)return null;for(;o[0].length<19&&o.length>1;)o[0]=Ze(o[0],o[1]),o.splice(1,1);if(t=o[0],(t[0]<<16)+(t[1]<<8)+t[2]===1){if(s=(t[4]<<8)+t[5],s&&s>a.size-6)return null;const c=t[7];c&192&&(r=(t[9]&14)*536870912+(t[10]&255)*4194304+(t[11]&254)*16384+(t[12]&255)*128+(t[13]&254)/2,c&64?(n=(t[14]&14)*536870912+(t[15]&255)*4194304+(t[16]&254)*16384+(t[17]&255)*128+(t[18]&254)/2,r-n>60*9e4&&(b.warn(`${Math.round((r-n)/9e4)}s delta between PTS and DTS, align them`),r=n)):n=r),i=t[8];let h=i+9;if(a.size<=h)return null;a.size-=h;const u=new Uint8Array(a.size);for(let d=0,f=o.length;d<f;d++){t=o[d];let g=t.byteLength;if(h)if(h>g){h-=g;continue}else t=t.subarray(h),g-=h,h=0;u.set(t,e),e+=g}return s&&(s-=i+3),{data:u,pts:r,dts:n,len:s}}return null}class iu extends Ir{resetInitSegment(e,t,s,i){super.resetInitSegment(e,t,s,i),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:t,duration:i,inputTimeScale:9e4,dropped:0}}static probe(e){if(!e)return!1;const t=ys(e,0);let s=(t==null?void 0:t.length)||0;if(t&&e[s]===11&&e[s+1]===119&&Sr(t)!==void 0&&co(e,s)<=16)return!1;for(let i=e.length;s<i;s++)if(lo(e,s))return b.log("MPEG Audio sync word found !"),!0;return!1}canParse(e,t){return Yh(e,t)}appendFrame(e,t,s){if(this.basePTS!==null)return no(e,t,s,this.basePTS,this.frameIndex)}}class ra{static getSilentFrame(e,t){switch(e){case"mp4a.40.2":if(t===1)return new Uint8Array([0,200,0,128,35,128]);if(t===2)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(t===3)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(t===4)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(t===5)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(t===6)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224]);break;default:if(t===1)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(t===2)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(t===3)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);break}}}const At=Math.pow(2,32)-1;class I{static init(){I.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],dac3:[],"ac-3":[],mvex:[],mvhd:[],pasp:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]};let e;for(e in I.types)I.types.hasOwnProperty(e)&&(I.types[e]=[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]);const t=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),s=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);I.HDLR_TYPES={video:t,audio:s};const i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),r=new Uint8Array([0,0,0,0,0,0,0,0]);I.STTS=I.STSC=I.STCO=r,I.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),I.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),I.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),I.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);const n=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);I.FTYP=I.box(I.types.ftyp,n,l,n,o),I.DINF=I.box(I.types.dinf,I.box(I.types.dref,i))}static box(e,...t){let s=8,i=t.length;const r=i;for(;i--;)s+=t[i].byteLength;const n=new Uint8Array(s);for(n[0]=s>>24&255,n[1]=s>>16&255,n[2]=s>>8&255,n[3]=s&255,n.set(e,4),i=0,s=8;i<r;i++)n.set(t[i],s),s+=t[i].byteLength;return n}static hdlr(e){return I.box(I.types.hdlr,I.HDLR_TYPES[e])}static mdat(e){return I.box(I.types.mdat,e)}static mdhd(e,t){t*=e;const s=Math.floor(t/(At+1)),i=Math.floor(t%(At+1));return I.box(I.types.mdhd,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,e&255,s>>24,s>>16&255,s>>8&255,s&255,i>>24,i>>16&255,i>>8&255,i&255,85,196,0,0]))}static mdia(e){return I.box(I.types.mdia,I.mdhd(e.timescale,e.duration),I.hdlr(e.type),I.minf(e))}static mfhd(e){return I.box(I.types.mfhd,new Uint8Array([0,0,0,0,e>>24,e>>16&255,e>>8&255,e&255]))}static minf(e){return e.type==="audio"?I.box(I.types.minf,I.box(I.types.smhd,I.SMHD),I.DINF,I.stbl(e)):I.box(I.types.minf,I.box(I.types.vmhd,I.VMHD),I.DINF,I.stbl(e))}static moof(e,t,s){return I.box(I.types.moof,I.mfhd(e),I.traf(s,t))}static moov(e){let t=e.length;const s=[];for(;t--;)s[t]=I.trak(e[t]);return I.box.apply(null,[I.types.moov,I.mvhd(e[0].timescale,e[0].duration)].concat(s).concat(I.mvex(e)))}static mvex(e){let t=e.length;const s=[];for(;t--;)s[t]=I.trex(e[t]);return I.box.apply(null,[I.types.mvex,...s])}static mvhd(e,t){t*=e;const s=Math.floor(t/(At+1)),i=Math.floor(t%(At+1)),r=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,e&255,s>>24,s>>16&255,s>>8&255,s&255,i>>24,i>>16&255,i>>8&255,i&255,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 I.box(I.types.mvhd,r)}static sdtp(e){const t=e.samples||[],s=new Uint8Array(4+t.length);let i,r;for(i=0;i<t.length;i++)r=t[i].flags,s[i+4]=r.dependsOn<<4|r.isDependedOn<<2|r.hasRedundancy;return I.box(I.types.sdtp,s)}static stbl(e){return I.box(I.types.stbl,I.stsd(e),I.box(I.types.stts,I.STTS),I.box(I.types.stsc,I.STSC),I.box(I.types.stsz,I.STSZ),I.box(I.types.stco,I.STCO))}static avc1(e){let t=[],s=[],i,r,n;for(i=0;i<e.sps.length;i++)r=e.sps[i],n=r.byteLength,t.push(n>>>8&255),t.push(n&255),t=t.concat(Array.prototype.slice.call(r));for(i=0;i<e.pps.length;i++)r=e.pps[i],n=r.byteLength,s.push(n>>>8&255),s.push(n&255),s=s.concat(Array.prototype.slice.call(r));const o=I.box(I.types.avcC,new Uint8Array([1,t[3],t[4],t[5],255,224|e.sps.length].concat(t).concat([e.pps.length]).concat(s))),l=e.width,c=e.height,h=e.pixelRatio[0],u=e.pixelRatio[1];return I.box(I.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,l&255,c>>8&255,c&255,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,I.box(I.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),I.box(I.types.pasp,new Uint8Array([h>>24,h>>16&255,h>>8&255,h&255,u>>24,u>>16&255,u>>8&255,u&255])))}static esds(e){const t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))}static audioStsd(e){const t=e.samplerate;return new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,t>>8&255,t&255,0,0])}static mp4a(e){return I.box(I.types.mp4a,I.audioStsd(e),I.box(I.types.esds,I.esds(e)))}static mp3(e){return I.box(I.types[".mp3"],I.audioStsd(e))}static ac3(e){return I.box(I.types["ac-3"],I.audioStsd(e),I.box(I.types.dac3,e.config))}static stsd(e){return e.type==="audio"?e.segmentCodec==="mp3"&&e.codec==="mp3"?I.box(I.types.stsd,I.STSD,I.mp3(e)):e.segmentCodec==="ac3"?I.box(I.types.stsd,I.STSD,I.ac3(e)):I.box(I.types.stsd,I.STSD,I.mp4a(e)):I.box(I.types.stsd,I.STSD,I.avc1(e))}static tkhd(e){const t=e.id,s=e.duration*e.timescale,i=e.width,r=e.height,n=Math.floor(s/(At+1)),o=Math.floor(s%(At+1));return I.box(I.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,t&255,0,0,0,0,n>>24,n>>16&255,n>>8&255,n&255,o>>24,o>>16&255,o>>8&255,o&255,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,i>>8&255,i&255,0,0,r>>8&255,r&255,0,0]))}static traf(e,t){const s=I.sdtp(e),i=e.id,r=Math.floor(t/(At+1)),n=Math.floor(t%(At+1));return I.box(I.types.traf,I.box(I.types.tfhd,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,i&255])),I.box(I.types.tfdt,new Uint8Array([1,0,0,0,r>>24,r>>16&255,r>>8&255,r&255,n>>24,n>>16&255,n>>8&255,n&255])),I.trun(e,s.length+16+20+8+16+8+8),s)}static trak(e){return e.duration=e.duration||4294967295,I.box(I.types.trak,I.tkhd(e),I.mdia(e))}static trex(e){const t=e.id;return I.box(I.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,t&255,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}static trun(e,t){const s=e.samples||[],i=s.length,r=12+16*i,n=new Uint8Array(r);let o,l,c,h,u,d;for(t+=8+r,n.set([e.type==="video"?1:0,0,15,1,i>>>24&255,i>>>16&255,i>>>8&255,i&255,t>>>24&255,t>>>16&255,t>>>8&255,t&255],0),o=0;o<i;o++)l=s[o],c=l.duration,h=l.size,u=l.flags,d=l.cts,n.set([c>>>24&255,c>>>16&255,c>>>8&255,c&255,h>>>24&255,h>>>16&255,h>>>8&255,h&255,u.isLeading<<2|u.dependsOn,u.isDependedOn<<6|u.hasRedundancy<<4|u.paddingValue<<1|u.isNonSync,u.degradPrio&61440,u.degradPrio&15,d>>>24&255,d>>>16&255,d>>>8&255,d&255],12+16*o);return I.box(I.types.trun,n)}static initSegment(e){I.types||I.init();const t=I.moov(e);return Ze(I.FTYP,t)}}I.types=void 0;I.HDLR_TYPES=void 0;I.STTS=void 0;I.STSC=void 0;I.STCO=void 0;I.STSZ=void 0;I.VMHD=void 0;I.SMHD=void 0;I.STSD=void 0;I.FTYP=void 0;I.DINF=void 0;const uo=9e4;function wr(a,e,t=1,s=!1){const i=a*e*t;return s?Math.round(i):i}function ru(a,e,t=1,s=!1){return wr(a,e,1/t,s)}function gs(a,e=!1){return wr(a,1e3,1/uo,e)}function nu(a,e=1){return wr(a,uo,1/e)}const au=10*1e3,na=1024,ou=1152,lu=1536;let Wt=null,Ki=null;class Ys{constructor(e,t,s,i=""){if(this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=null,this._initDTS=null,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.videoTrackConfig=void 0,this.observer=e,this.config=t,this.typeSupported=s,this.ISGenerated=!1,Wt===null){const n=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Wt=n?parseInt(n[1]):0}if(Ki===null){const r=navigator.userAgent.match(/Safari\/(\d+)/i);Ki=r?parseInt(r[1]):0}}destroy(){this.config=this.videoTrackConfig=this._initPTS=this._initDTS=null}resetTimeStamp(e){b.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=e}resetNextTimestamp(){b.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1}resetInitSegment(){b.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1,this.videoTrackConfig=void 0}getVideoStartPts(e){let t=!1;const s=e.reduce((i,r)=>{const n=r.pts-i;return n<-4294967296?(t=!0,Je(i,r.pts)):n>0?i:r.pts},e[0].pts);return t&&b.debug("PTS rollover detected"),s}remux(e,t,s,i,r,n,o,l){let c,h,u,d,f,g,m=r,x=r;const T=e.pid>-1,R=t.pid>-1,v=t.samples.length,D=e.samples.length>0,L=o&&v>0||v>1;if((!T||D)&&(!R||L)||this.ISGenerated||o){if(this.ISGenerated){var k,B,G,P;const se=this.videoTrackConfig;se&&(t.width!==se.width||t.height!==se.height||((k=t.pixelRatio)==null?void 0:k[0])!==((B=se.pixelRatio)==null?void 0:B[0])||((G=t.pixelRatio)==null?void 0:G[1])!==((P=se.pixelRatio)==null?void 0:P[1]))&&this.resetInitSegment()}else u=this.generateIS(e,t,r,n);const U=this.isVideoContiguous;let ee=-1,K;if(L&&(ee=cu(t.samples),!U&&this.config.forceKeyFrameOnDiscontinuity))if(g=!0,ee>0){b.warn(`[mp4-remuxer]: Dropped ${ee} out of ${v} video samples due to a missing keyframe`);const se=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(ee),t.dropped+=ee,x+=(t.samples[0].pts-se)/t.inputTimeScale,K=x}else ee===-1&&(b.warn(`[mp4-remuxer]: No keyframe found out of ${v} video samples`),g=!1);if(this.ISGenerated){if(D&&L){const se=this.getVideoStartPts(t.samples),Y=(Je(e.samples[0].pts,se)-se)/t.inputTimeScale;m+=Math.max(0,Y),x+=Math.max(0,-Y)}if(D){if(e.samplerate||(b.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),u=this.generateIS(e,t,r,n)),h=this.remuxAudio(e,m,this.isAudioContiguous,n,R||L||l===Q.AUDIO?x:void 0),L){const se=h?h.endPTS-h.startPTS:0;t.inputTimeScale||(b.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),u=this.generateIS(e,t,r,n)),c=this.remuxVideo(t,x,U,se)}}else L&&(c=this.remuxVideo(t,x,U,0));c&&(c.firstKeyFrame=ee,c.independent=ee!==-1,c.firstKeyFramePTS=K)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(s.samples.length&&(f=fo(s,r,this._initPTS,this._initDTS)),i.samples.length&&(d=go(i,r,this._initPTS))),{audio:h,video:c,initSegment:u,independent:g,text:d,id3:f}}generateIS(e,t,s,i){const r=e.samples,n=t.samples,o=this.typeSupported,l={},c=this._initPTS;let h=!c||i,u="audio/mp4",d,f,g;if(h&&(d=f=1/0),e.config&&r.length){switch(e.timescale=e.samplerate,e.segmentCodec){case"mp3":o.mpeg?(u="audio/mpeg",e.codec=""):o.mp3&&(e.codec="mp3");break;case"ac3":e.codec="ac-3";break}l.audio={id:"audio",container:u,codec:e.codec,initSegment:e.segmentCodec==="mp3"&&o.mpeg?new Uint8Array(0):I.initSegment([e]),metadata:{channelCount:e.channelCount}},h&&(g=e.inputTimeScale,!c||g!==c.timescale?d=f=r[0].pts-Math.round(g*s):h=!1)}if(t.sps&&t.pps&&n.length){if(t.timescale=t.inputTimeScale,l.video={id:"main",container:"video/mp4",codec:t.codec,initSegment:I.initSegment([t]),metadata:{width:t.width,height:t.height}},h)if(g=t.inputTimeScale,!c||g!==c.timescale){const m=this.getVideoStartPts(n),x=Math.round(g*s);f=Math.min(f,Je(n[0].dts,m)-x),d=Math.min(d,m-x)}else h=!1;this.videoTrackConfig={width:t.width,height:t.height,pixelRatio:t.pixelRatio}}if(Object.keys(l).length)return this.ISGenerated=!0,h?(this._initPTS={baseTime:d,timescale:g},this._initDTS={baseTime:f,timescale:g}):d=g=void 0,{tracks:l,initPTS:d,timescale:g}}remuxVideo(e,t,s,i){const r=e.inputTimeScale,n=e.samples,o=[],l=n.length,c=this._initPTS;let h=this.nextAvcDts,u=8,d=this.videoSampleDuration,f,g,m=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY,T=!1;if(!s||h===null){const V=t*r,H=n[0].pts-Je(n[0].dts,n[0].pts);Wt&&h!==null&&Math.abs(V-H-h)<15e3?s=!0:h=V-H}const R=c.baseTime*r/c.timescale;for(let V=0;V<l;V++){const H=n[V];H.pts=Je(H.pts-R,h),H.dts=Je(H.dts-R,h),H.dts<n[V>0?V-1:V].dts&&(T=!0)}T&&n.sort(function(V,H){const re=V.dts-H.dts,J=V.pts-H.pts;return re||J}),f=n[0].dts,g=n[n.length-1].dts;const v=g-f,D=v?Math.round(v/(l-1)):d||e.inputTimeScale/30;if(s){const V=f-h,H=V>D,re=V<-1;if((H||re)&&(H?b.warn(`AVC: ${gs(V,!0)} ms (${V}dts) hole between fragments detected at ${t.toFixed(3)}`):b.warn(`AVC: ${gs(-V,!0)} ms (${V}dts) overlapping between fragments detected at ${t.toFixed(3)}`),!re||h>=n[0].pts||Wt)){f=h;const J=n[0].pts-V;if(H)n[0].dts=f,n[0].pts=J;else for(let de=0;de<n.length&&!(n[de].dts>J);de++)n[de].dts-=V,n[de].pts-=V;b.log(`Video: Initial PTS/DTS adjusted: ${gs(J,!0)}/${gs(f,!0)}, delta: ${gs(V,!0)} ms`)}}f=Math.max(0,f);let L=0,_=0,k=f;for(let V=0;V<l;V++){const H=n[V],re=H.units,J=re.length;let de=0;for(let ve=0;ve<J;ve++)de+=re[ve].data.length;_+=de,L+=J,H.length=de,H.dts<k?(H.dts=k,k+=D/4|0||1):k=H.dts,m=Math.min(H.pts,m),x=Math.max(H.pts,x)}g=n[l-1].dts;const B=_+4*L+8;let G;try{G=new Uint8Array(B)}catch(V){this.observer.emit(p.ERROR,p.ERROR,{type:Z.MUX_ERROR,details:w.REMUX_ALLOC_ERROR,fatal:!1,error:V,bytes:B,reason:`fail allocating video mdat ${B}`});return}const P=new DataView(G.buffer);P.setUint32(0,B),G.set(I.types.mdat,4);let U=!1,ee=Number.POSITIVE_INFINITY,K=Number.POSITIVE_INFINITY,se=Number.NEGATIVE_INFINITY,ie=Number.NEGATIVE_INFINITY;for(let V=0;V<l;V++){const H=n[V],re=H.units;let J=0;for(let be=0,Pe=re.length;be<Pe;be++){const ye=re[be],bt=ye.data,$e=ye.data.byteLength;P.setUint32(u,$e),u+=4,G.set(bt,u),u+=$e,J+=4+$e}let de;if(V<l-1)d=n[V+1].dts-H.dts,de=n[V+1].pts-H.pts;else{const be=this.config,Pe=V>0?H.dts-n[V-1].dts:D;if(de=V>0?H.pts-n[V-1].pts:D,be.stretchShortVideoTrack&&this.nextAudioPts!==null){const ye=Math.floor(be.maxBufferHole*r),bt=(i?m+i*r:this.nextAudioPts)-H.pts;bt>ye?(d=bt-Pe,d<0?d=Pe:U=!0,b.log(`[mp4-remuxer]: It is approximately ${bt/90} ms to the next segment; using duration ${d/90} ms for the last video frame.`)):d=Pe}else d=Pe}const ve=Math.round(H.pts-H.dts);ee=Math.min(ee,d),se=Math.max(se,d),K=Math.min(K,de),ie=Math.max(ie,de),o.push(new aa(H.key,d,J,ve))}if(o.length){if(Wt){if(Wt<70){const V=o[0].flags;V.dependsOn=2,V.isNonSync=0}}else if(Ki&&ie-K<se-ee&&D/se<.025&&o[0].cts===0){b.warn("Found irregular gaps in sample duration. Using PTS instead of DTS to determine MP4 sample duration.");let V=f;for(let H=0,re=o.length;H<re;H++){const J=V+o[H].duration,de=V+o[H].cts;if(H<re-1){const ve=J+o[H+1].cts;o[H].duration=ve-de}else o[H].duration=H?o[H-1].duration:D;o[H].cts=0,V=J}}}d=U||!d?D:d,this.nextAvcDts=h=g+d,this.videoSampleDuration=d,this.isVideoContiguous=!0;const he={data1:I.moof(e.sequenceNumber++,f,we({},e,{samples:o})),data2:G,startPTS:m/r,endPTS:(x+d)/r,startDTS:f/r,endDTS:h/r,type:"video",hasAudio:!1,hasVideo:!0,nb:o.length,dropped:e.dropped};return e.samples=[],e.dropped=0,he}getSamplesPerFrame(e){switch(e.segmentCodec){case"mp3":return ou;case"ac3":return lu;default:return na}}remuxAudio(e,t,s,i,r){const n=e.inputTimeScale,o=e.samplerate?e.samplerate:n,l=n/o,c=this.getSamplesPerFrame(e),h=c*l,u=this._initPTS,d=e.segmentCodec==="mp3"&&this.typeSupported.mpeg,f=[],g=r!==void 0;let m=e.samples,x=d?0:8,T=this.nextAudioPts||-1;const R=t*n,v=u.baseTime*n/u.timescale;if(this.isAudioContiguous=s=s||m.length&&T>0&&(i&&Math.abs(R-T)<9e3||Math.abs(Je(m[0].pts-v,R)-T)<20*h),m.forEach(function(Y){Y.pts=Je(Y.pts-v,R)}),!s||T<0){if(m=m.filter(Y=>Y.pts>=0),!m.length)return;r===0?T=0:i&&!g?T=Math.max(0,R):T=m[0].pts}if(e.segmentCodec==="aac"){const Y=this.config.maxAudioFramesDrift;for(let le=0,he=T;le<m.length;le++){const V=m[le],H=V.pts,re=H-he,J=Math.abs(1e3*re/n);if(re<=-Y*h&&g)le===0&&(b.warn(`Audio frame @ ${(H/n).toFixed(3)}s overlaps nextAudioPts by ${Math.round(1e3*re/n)} ms.`),this.nextAudioPts=T=he=H);else if(re>=Y*h&&J<au&&g){let de=Math.round(re/h);he=H-de*h,he<0&&(de--,he+=h),le===0&&(this.nextAudioPts=T=he),b.warn(`[mp4-remuxer]: Injecting ${de} audio frame @ ${(he/n).toFixed(3)}s due to ${Math.round(1e3*re/n)} ms gap.`);for(let ve=0;ve<de;ve++){const be=Math.max(he,0);let Pe=ra.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);Pe||(b.log("[mp4-remuxer]: Unable to get silent frame for given audio codec; duplicating last frame instead."),Pe=V.unit.subarray()),m.splice(le,0,{unit:Pe,pts:be}),he+=h,le++}}V.pts=he,he+=h}}let D=null,L=null,_,k=0,B=m.length;for(;B--;)k+=m[B].unit.byteLength;for(let Y=0,le=m.length;Y<le;Y++){const he=m[Y],V=he.unit;let H=he.pts;if(L!==null){const J=f[Y-1];J.duration=Math.round((H-L)/l)}else if(s&&e.segmentCodec==="aac"&&(H=T),D=H,k>0){k+=x;try{_=new Uint8Array(k)}catch(J){this.observer.emit(p.ERROR,p.ERROR,{type:Z.MUX_ERROR,details:w.REMUX_ALLOC_ERROR,fatal:!1,error:J,bytes:k,reason:`fail allocating audio mdat ${k}`});return}d||(new DataView(_.buffer).setUint32(0,k),_.set(I.types.mdat,4))}else return;_.set(V,x);const re=V.byteLength;x+=re,f.push(new aa(!0,c,re,0)),L=H}const G=f.length;if(!G)return;const P=f[f.length-1];this.nextAudioPts=T=L+l*P.duration;const U=d?new Uint8Array(0):I.moof(e.sequenceNumber++,D/l,we({},e,{samples:f}));e.samples=[];const ee=D/n,K=T/n,ie={data1:U,data2:_,startPTS:ee,endPTS:K,startDTS:ee,endDTS:K,type:"audio",hasAudio:!0,hasVideo:!1,nb:G};return this.isAudioContiguous=!0,ie}remuxEmptyAudio(e,t,s,i){const r=e.inputTimeScale,n=e.samplerate?e.samplerate:r,o=r/n,l=this.nextAudioPts,c=this._initDTS,h=c.baseTime*9e4/c.timescale,u=(l!==null?l:i.startDTS*r)+h,d=i.endDTS*r+h,f=o*na,g=Math.ceil((d-u)/f),m=ra.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);if(b.warn("[mp4-remuxer]: remux empty Audio"),!m){b.trace("[mp4-remuxer]: Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec");return}const x=[];for(let T=0;T<g;T++){const R=u+T*f;x.push({unit:m,pts:R,dts:R})}return e.samples=x,this.remuxAudio(e,t,s,!1)}}function Je(a,e){let t;if(e===null)return a;for(e<a?t=-8589934592:t=8589934592;Math.abs(a-e)>4294967296;)a+=t;return a}function cu(a){for(let e=0;e<a.length;e++)if(a[e].key)return e;return-1}function fo(a,e,t,s){const i=a.samples.length;if(!i)return;const r=a.inputTimeScale;for(let o=0;o<i;o++){const l=a.samples[o];l.pts=Je(l.pts-t.baseTime*r/t.timescale,e*r)/r,l.dts=Je(l.dts-s.baseTime*r/s.timescale,e*r)/r}const n=a.samples;return a.samples=[],{samples:n}}function go(a,e,t){const s=a.samples.length;if(!s)return;const i=a.inputTimeScale;for(let n=0;n<s;n++){const o=a.samples[n];o.pts=Je(o.pts-t.baseTime*i/t.timescale,e*i)/i}a.samples.sort((n,o)=>n.pts-o.pts);const r=a.samples;return a.samples=[],{samples:r}}class aa{constructor(e,t,s,i){this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=t,this.size=s,this.cts=i,this.flags={isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:e?2:1,isNonSync:e?0:1}}}class hu{constructor(){this.emitInitSegment=!1,this.audioCodec=void 0,this.videoCodec=void 0,this.initData=void 0,this.initPTS=null,this.initTracks=void 0,this.lastEndTime=null}destroy(){}resetTimeStamp(e){this.initPTS=e,this.lastEndTime=null}resetNextTimestamp(){this.lastEndTime=null}resetInitSegment(e,t,s,i){this.audioCodec=t,this.videoCodec=s,this.generateInitSegment(pc(e,i)),this.emitInitSegment=!0}generateInitSegment(e){let{audioCodec:t,videoCodec:s}=this;if(!(e!=null&&e.byteLength)){this.initTracks=void 0,this.initData=void 0;return}const i=this.initData=Ua(e);i.audio&&(t=oa(i.audio,xe.AUDIO)),i.video&&(s=oa(i.video,xe.VIDEO));const r={};i.audio&&i.video?r.audiovideo={container:"video/mp4",codec:t+","+s,initSegment:e,id:"main"}:i.audio?r.audio={container:"audio/mp4",codec:t,initSegment:e,id:"audio"}:i.video?r.video={container:"video/mp4",codec:s,initSegment:e,id:"main"}:b.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=r}remux(e,t,s,i,r,n){var o,l;let{initPTS:c,lastEndTime:h}=this;const u={audio:void 0,video:void 0,text:i,id3:s,initSegment:void 0};j(h)||(h=this.lastEndTime=r||0);const d=t.samples;if(!(d!=null&&d.length))return u;const f={initPTS:void 0,timescale:1};let g=this.initData;if((o=g)!=null&&o.length||(this.generateInitSegment(d),g=this.initData),!((l=g)!=null&&l.length))return b.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),u;this.emitInitSegment&&(f.tracks=this.initTracks,this.emitInitSegment=!1);const m=yc(d,g),x=xc(g,d),T=x===null?r:x;(uu(c,T,r,m)||f.timescale!==c.timescale&&n)&&(f.initPTS=T-r,c&&c.timescale===1&&b.warn(`Adjusting initPTS by ${f.initPTS-c.baseTime}`),this.initPTS=c={baseTime:f.initPTS,timescale:1});const R=e?T-c.baseTime/c.timescale:h,v=R+m;Ec(g,d,c.baseTime/c.timescale),m>0?this.lastEndTime=v:(b.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());const D=!!g.audio,L=!!g.video;let _="";D&&(_+="audio"),L&&(_+="video");const k={data1:d,startPTS:R,startDTS:R,endPTS:v,endDTS:v,type:_,hasAudio:D,hasVideo:L,nb:1,dropped:0};return u.audio=k.type==="audio"?k:void 0,u.video=k.type!=="audio"?k:void 0,u.initSegment=f,u.id3=fo(s,r,c,c),i.samples.length&&(u.text=go(i,r,c)),u}}function uu(a,e,t,s){if(a===null)return!0;const i=Math.max(s,1),r=e-a.baseTime/a.timescale;return Math.abs(r-t)>i}function oa(a,e){const t=a==null?void 0:a.codec;if(t&&t.length>4)return t;if(e===xe.AUDIO){if(t==="ec-3"||t==="ac-3"||t==="alac")return t;if(t==="fLaC"||t==="Opus")return si(t,!1);const s="mp4a.40.5";return b.info(`Parsed audio codec "${t}" or audio object type not handled. Using "${s}"`),s}return b.warn(`Unhandled video codec "${t}"`),t==="hvc1"||t==="hev1"?"hvc1.1.6.L120.90":t==="av01"?"av01.0.04M.08":"avc1.42e01e"}let Tt;try{Tt=self.performance.now.bind(self.performance)}catch{b.debug("Unable to use Performance API on this environment"),Tt=Jt==null?void 0:Jt.Date.now}const qs=[{demux:Xh,remux:hu},{demux:Rt,remux:Ys},{demux:qh,remux:Ys},{demux:iu,remux:Ys}];qs.splice(2,0,{demux:Qh,remux:Ys});class la{constructor(e,t,s,i,r){this.async=!1,this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.observer=e,this.typeSupported=t,this.config=s,this.vendor=i,this.id=r}configure(e){this.transmuxConfig=e,this.decrypter&&this.decrypter.reset()}push(e,t,s,i){const r=s.transmuxing;r.executeStart=Tt();let n=new Uint8Array(e);const{currentTransmuxState:o,transmuxConfig:l}=this;i&&(this.currentTransmuxState=i);const{contiguous:c,discontinuity:h,trackSwitch:u,accurateTimeOffset:d,timeOffset:f,initSegmentChange:g}=i||o,{audioCodec:m,videoCodec:x,defaultInitPts:T,duration:R,initSegmentData:v}=l,D=du(n,t);if(D&&D.method==="AES-128"){const B=this.getDecrypter();if(B.isSync()){let G=B.softwareDecrypt(n,D.key.buffer,D.iv.buffer);if(s.part>-1&&(G=B.flush()),!G)return r.executeEnd=Tt(),Hi(s);n=new Uint8Array(G)}else return this.decryptionPromise=B.webCryptoDecrypt(n,D.key.buffer,D.iv.buffer).then(G=>{const P=this.push(G,null,s);return this.decryptionPromise=null,P}),this.decryptionPromise}const L=this.needsProbing(h,u);if(L){const B=this.configureTransmuxer(n);if(B)return b.warn(`[transmuxer] ${B.message}`),this.observer.emit(p.ERROR,p.ERROR,{type:Z.MEDIA_ERROR,details:w.FRAG_PARSING_ERROR,fatal:!1,error:B,reason:B.message}),r.executeEnd=Tt(),Hi(s)}(h||u||g||L)&&this.resetInitSegment(v,m,x,R,t),(h||g||L)&&this.resetInitialTimestamp(T),c||this.resetContiguity();const _=this.transmux(n,D,f,d,s),k=this.currentTransmuxState;return k.contiguous=!0,k.discontinuity=!1,k.trackSwitch=!1,r.executeEnd=Tt(),_}flush(e){const t=e.transmuxing;t.executeStart=Tt();const{decrypter:s,currentTransmuxState:i,decryptionPromise:r}=this;if(r)return r.then(()=>this.flush(e));const n=[],{timeOffset:o}=i;if(s){const u=s.flush();u&&n.push(this.push(u,null,e))}const{demuxer:l,remuxer:c}=this;if(!l||!c)return t.executeEnd=Tt(),[Hi(e)];const h=l.flush(o);return zs(h)?h.then(u=>(this.flushRemux(n,u,e),n)):(this.flushRemux(n,h,e),n)}flushRemux(e,t,s){const{audioTrack:i,videoTrack:r,id3Track:n,textTrack:o}=t,{accurateTimeOffset:l,timeOffset:c}=this.currentTransmuxState;b.log(`[transmuxer.ts]: Flushed fragment ${s.sn}${s.part>-1?" p: "+s.part:""} of level ${s.level}`);const h=this.remuxer.remux(i,r,n,o,c,l,!0,this.id);e.push({remuxResult:h,chunkMeta:s}),s.transmuxing.executeEnd=Tt()}resetInitialTimestamp(e){const{demuxer:t,remuxer:s}=this;!t||!s||(t.resetTimeStamp(e),s.resetTimeStamp(e))}resetContiguity(){const{demuxer:e,remuxer:t}=this;!e||!t||(e.resetContiguity(),t.resetNextTimestamp())}resetInitSegment(e,t,s,i,r){const{demuxer:n,remuxer:o}=this;!n||!o||(n.resetInitSegment(e,t,s,i),o.resetInitSegment(e,t,s,r))}destroy(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)}transmux(e,t,s,i,r){let n;return t&&t.method==="SAMPLE-AES"?n=this.transmuxSampleAes(e,t,s,i,r):n=this.transmuxUnencrypted(e,s,i,r),n}transmuxUnencrypted(e,t,s,i){const{audioTrack:r,videoTrack:n,id3Track:o,textTrack:l}=this.demuxer.demux(e,t,!1,!this.config.progressive);return{remuxResult:this.remuxer.remux(r,n,o,l,t,s,!1,this.id),chunkMeta:i}}transmuxSampleAes(e,t,s,i,r){return this.demuxer.demuxSampleAes(e,t,s).then(n=>({remuxResult:this.remuxer.remux(n.audioTrack,n.videoTrack,n.id3Track,n.textTrack,s,i,!1,this.id),chunkMeta:r}))}configureTransmuxer(e){const{config:t,observer:s,typeSupported:i,vendor:r}=this;let n;for(let d=0,f=qs.length;d<f;d++){var o;if((o=qs[d].demux)!=null&&o.probe(e)){n=qs[d];break}}if(!n)return new Error("Failed to find demuxer by probing fragment data");const l=this.demuxer,c=this.remuxer,h=n.remux,u=n.demux;(!c||!(c instanceof h))&&(this.remuxer=new h(s,t,i,r)),(!l||!(l instanceof u))&&(this.demuxer=new u(s,t,i),this.probe=u.probe)}needsProbing(e,t){return!this.demuxer||!this.remuxer||e||t}getDecrypter(){let e=this.decrypter;return e||(e=this.decrypter=new Rr(this.config)),e}}function du(a,e){let t=null;return a.byteLength>0&&(e==null?void 0:e.key)!=null&&e.iv!==null&&e.method!=null&&(t=e),t}const Hi=a=>({remuxResult:{},chunkMeta:a});function zs(a){return"then"in a&&a.then instanceof Function}class fu{constructor(e,t,s,i,r){this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=e,this.videoCodec=t,this.initSegmentData=s,this.duration=i,this.defaultInitPts=r||null}}class gu{constructor(e,t,s,i,r,n){this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=e,this.contiguous=t,this.accurateTimeOffset=s,this.trackSwitch=i,this.timeOffset=r,this.initSegmentChange=n}}var mo={exports:{}};(function(a){var e=Object.prototype.hasOwnProperty,t="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(t=!1));function i(l,c,h){this.fn=l,this.context=c,this.once=h||!1}function r(l,c,h,u,d){if(typeof h!="function")throw new TypeError("The listener must be a function");var f=new i(h,u||l,d),g=t?t+c:c;return l._events[g]?l._events[g].fn?l._events[g]=[l._events[g],f]:l._events[g].push(f):(l._events[g]=f,l._eventsCount++),l}function n(l,c){--l._eventsCount===0?l._events=new s:delete l._events[c]}function o(){this._events=new s,this._eventsCount=0}o.prototype.eventNames=function(){var c=[],h,u;if(this._eventsCount===0)return c;for(u in h=this._events)e.call(h,u)&&c.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(h)):c},o.prototype.listeners=function(c){var h=t?t+c:c,u=this._events[h];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,f=u.length,g=new Array(f);d<f;d++)g[d]=u[d].fn;return g},o.prototype.listenerCount=function(c){var h=t?t+c:c,u=this._events[h];return u?u.fn?1:u.length:0},o.prototype.emit=function(c,h,u,d,f,g){var m=t?t+c:c;if(!this._events[m])return!1;var x=this._events[m],T=arguments.length,R,v;if(x.fn){switch(x.once&&this.removeListener(c,x.fn,void 0,!0),T){case 1:return x.fn.call(x.context),!0;case 2:return x.fn.call(x.context,h),!0;case 3:return x.fn.call(x.context,h,u),!0;case 4:return x.fn.call(x.context,h,u,d),!0;case 5:return x.fn.call(x.context,h,u,d,f),!0;case 6:return x.fn.call(x.context,h,u,d,f,g),!0}for(v=1,R=new Array(T-1);v<T;v++)R[v-1]=arguments[v];x.fn.apply(x.context,R)}else{var D=x.length,L;for(v=0;v<D;v++)switch(x[v].once&&this.removeListener(c,x[v].fn,void 0,!0),T){case 1:x[v].fn.call(x[v].context);break;case 2:x[v].fn.call(x[v].context,h);break;case 3:x[v].fn.call(x[v].context,h,u);break;case 4:x[v].fn.call(x[v].context,h,u,d);break;default:if(!R)for(L=1,R=new Array(T-1);L<T;L++)R[L-1]=arguments[L];x[v].fn.apply(x[v].context,R)}}return!0},o.prototype.on=function(c,h,u){return r(this,c,h,u,!1)},o.prototype.once=function(c,h,u){return r(this,c,h,u,!0)},o.prototype.removeListener=function(c,h,u,d){var f=t?t+c:c;if(!this._events[f])return this;if(!h)return n(this,f),this;var g=this._events[f];if(g.fn)g.fn===h&&(!d||g.once)&&(!u||g.context===u)&&n(this,f);else{for(var m=0,x=[],T=g.length;m<T;m++)(g[m].fn!==h||d&&!g[m].once||u&&g[m].context!==u)&&x.push(g[m]);x.length?this._events[f]=x.length===1?x[0]:x:n(this,f)}return this},o.prototype.removeAllListeners=function(c){var h;return c?(h=t?t+c:c,this._events[h]&&n(this,h)):(this._events=new s,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=t,o.EventEmitter=o,a.exports=o})(mo);var mu=mo.exports,kr=Ul(mu);class po{constructor(e,t,s,i){this.error=null,this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.useWorker=void 0,this.workerContext=null,this.onwmsg=void 0,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0;const r=e.config;this.hls=e,this.id=t,this.useWorker=!!r.enableWorker,this.onTransmuxComplete=s,this.onFlush=i;const n=(c,h)=>{h=h||{},h.frag=this.frag,h.id=this.id,c===p.ERROR&&(this.error=h.error),this.hls.trigger(c,h)};this.observer=new kr,this.observer.on(p.FRAG_DECRYPTED,n),this.observer.on(p.ERROR,n);const o=Ot(r.preferManagedMediaSource)||{isTypeSupported:()=>!1},l={mpeg:o.isTypeSupported("audio/mpeg"),mp3:o.isTypeSupported('audio/mp4; codecs="mp3"'),ac3:o.isTypeSupported('audio/mp4; codecs="ac-3"')};if(this.useWorker&&typeof Worker<"u"&&(r.workerPath||Mh())){try{r.workerPath?(b.log(`loading Web Worker ${r.workerPath} for "${t}"`),this.workerContext=Oh(r.workerPath)):(b.log(`injecting Web Worker for "${t}"`),this.workerContext=Fh()),this.onwmsg=u=>this.onWorkerMessage(u);const{worker:h}=this.workerContext;h.addEventListener("message",this.onwmsg),h.onerror=u=>{const d=new Error(`${u.message} (${u.filename}:${u.lineno})`);r.enableWorker=!1,b.warn(`Error in "${t}" Web Worker, fallback to inline`),this.hls.trigger(p.ERROR,{type:Z.OTHER_ERROR,details:w.INTERNAL_EXCEPTION,fatal:!1,event:"demuxerWorker",error:d})},h.postMessage({cmd:"init",typeSupported:l,vendor:"",id:t,config:JSON.stringify(r)})}catch(h){b.warn(`Error setting up "${t}" Web Worker, fallback to inline`,h),this.resetWorker(),this.error=null,this.transmuxer=new la(this.observer,l,r,"",t)}return}this.transmuxer=new la(this.observer,l,r,"",t)}resetWorker(){if(this.workerContext){const{worker:e,objectURL:t}=this.workerContext;t&&self.URL.revokeObjectURL(t),e.removeEventListener("message",this.onwmsg),e.onerror=null,e.terminate(),this.workerContext=null}}destroy(){if(this.workerContext)this.resetWorker(),this.onwmsg=void 0;else{const t=this.transmuxer;t&&(t.destroy(),this.transmuxer=null)}const e=this.observer;e&&e.removeAllListeners(),this.frag=null,this.observer=null,this.hls=null}push(e,t,s,i,r,n,o,l,c,h){var u,d;c.transmuxing.start=self.performance.now();const{transmuxer:f}=this,g=n?n.start:r.start,m=r.decryptdata,x=this.frag,T=!(x&&r.cc===x.cc),R=!(x&&c.level===x.level),v=x?c.sn-x.sn:-1,D=this.part?c.part-this.part.index:-1,L=v===0&&c.id>1&&c.id===(x==null?void 0:x.stats.chunkCount),_=!R&&(v===1||v===0&&(D===1||L&&D<=0)),k=self.performance.now();(R||v||r.stats.parsing.start===0)&&(r.stats.parsing.start=k),n&&(D||!_)&&(n.stats.parsing.start=k);const B=!(x&&((u=r.initSegment)==null?void 0:u.url)===((d=x.initSegment)==null?void 0:d.url)),G=new gu(T,_,l,R,g,B);if(!_||T||B){b.log(`[transmuxer-interface, ${r.type}]: Starting new transmux session for sn: ${c.sn} p: ${c.part} level: ${c.level} id: ${c.id} 24 discontinuity: ${T} 25 trackSwitch: ${R} 26 contiguous: ${_} 27 accurateTimeOffset: ${l} 28 timeOffset: ${g} 29 initSegmentChange: ${B}`);const P=new fu(s,i,t,o,h);this.configureTransmuxer(P)}if(this.frag=r,this.part=n,this.workerContext)this.workerContext.worker.postMessage({cmd:"demux",data:e,decryptdata:m,chunkMeta:c,state:G},e instanceof ArrayBuffer?[e]:[]);else if(f){const P=f.push(e,m,c,G);zs(P)?(f.async=!0,P.then(U=>{this.handleTransmuxComplete(U)}).catch(U=>{this.transmuxerError(U,c,"transmuxer-interface push error")})):(f.async=!1,this.handleTransmuxComplete(P))}}flush(e){e.transmuxing.start=self.performance.now();const{transmuxer:t}=this;if(this.workerContext)this.workerContext.worker.postMessage({cmd:"flush",chunkMeta:e});else if(t){let s=t.flush(e);zs(s)||t.async?(zs(s)||(s=Promise.resolve(s)),s.then(r=>{this.handleFlushResult(r,e)}).catch(r=>{this.transmuxerError(r,e,"transmuxer-interface flush error")})):this.handleFlushResult(s,e)}}transmuxerError(e,t,s){this.hls&&(this.error=e,this.hls.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.FRAG_PARSING_ERROR,chunkMeta:t,frag:this.frag||void 0,fatal:!1,error:e,err:e,reason:s}))}handleFlushResult(e,t){e.forEach(s=>{this.handleTransmuxComplete(s)}),this.onFlush(t)}onWorkerMessage(e){const t=e.data;if(!(t!=null&&t.event)){b.warn(`worker message received with no ${t?"event name":"data"}`);return}const s=this.hls;if(this.hls)switch(t.event){case"init":{var i;const r=(i=this.workerContext)==null?void 0:i.objectURL;r&&self.URL.revokeObjectURL(r);break}case"transmuxComplete":{this.handleTransmuxComplete(t.data);break}case"flush":{this.onFlush(t.data);break}case"workerLog":b[t.data.logType]&&b[t.data.logType](t.data.message);break;default:{t.data=t.data||{},t.data.frag=this.frag,t.data.id=this.id,s.trigger(t.event,t.data);break}}}configureTransmuxer(e){const{transmuxer:t}=this;this.workerContext?this.workerContext.worker.postMessage({cmd:"configure",config:e}):t&&t.configure(e)}handleTransmuxComplete(e){e.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(e)}}function xo(a,e){if(a.length!==e.length)return!1;for(let t=0;t<a.length;t++)if(!es(a[t].attrs,e[t].attrs))return!1;return!0}function es(a,e,t){const s=a["STABLE-RENDITION-ID"];return s&&!t?s===e["STABLE-RENDITION-ID"]:!(t||["LANGUAGE","NAME","CHARACTERISTICS","AUTOSELECT","DEFAULT","FORCED","ASSOC-LANGUAGE"]).some(i=>a[i]!==e[i])}function cr(a,e){return e.label.toLowerCase()===a.name.toLowerCase()&&(!e.language||e.language.toLowerCase()===(a.lang||"").toLowerCase())}const ca=100;class pu extends br{constructor(e,t,s){super(e,t,s,"[audio-stream-controller]",Q.AUDIO),this.videoBuffer=null,this.videoTrackCC=-1,this.waitingVideoCC=-1,this.bufferedTrack=null,this.switchingTrack=null,this.trackId=-1,this.waitingData=null,this.mainDetails=null,this.flushing=!1,this.bufferFlushed=!1,this.cachedTrackLoadedData=null,this._registerListeners()}onHandlerDestroying(){this._unregisterListeners(),super.onHandlerDestroying(),this.mainDetails=null,this.bufferedTrack=null,this.switchingTrack=null}_registerListeners(){const{hls:e}=this;e.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.LEVEL_LOADED,this.onLevelLoaded,this),e.on(p.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),e.on(p.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.on(p.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.on(p.ERROR,this.onError,this),e.on(p.BUFFER_RESET,this.onBufferReset,this),e.on(p.BUFFER_CREATED,this.onBufferCreated,this),e.on(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(p.BUFFER_FLUSHED,this.onBufferFlushed,this),e.on(p.INIT_PTS_FOUND,this.onInitPtsFound,this),e.on(p.FRAG_BUFFERED,this.onFragBuffered,this)}_unregisterListeners(){const{hls:e}=this;e.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.LEVEL_LOADED,this.onLevelLoaded,this),e.off(p.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),e.off(p.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.off(p.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.off(p.ERROR,this.onError,this),e.off(p.BUFFER_RESET,this.onBufferReset,this),e.off(p.BUFFER_CREATED,this.onBufferCreated,this),e.off(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(p.BUFFER_FLUSHED,this.onBufferFlushed,this),e.off(p.INIT_PTS_FOUND,this.onInitPtsFound,this),e.off(p.FRAG_BUFFERED,this.onFragBuffered,this)}onInitPtsFound(e,{frag:t,id:s,initPTS:i,timescale:r}){if(s==="main"){const n=t.cc;this.initPTS[t.cc]={baseTime:i,timescale:r},this.log(`InitPTS for cc: ${n} found from main: ${i}`),this.videoTrackCC=n,this.state===O.WAITING_INIT_PTS&&this.tick()}}startLoad(e){if(!this.levels){this.startPosition=e,this.state=O.STOPPED;return}const t=this.lastCurrentTime;this.stopLoad(),this.setInterval(ca),t>0&&e===-1?(this.log(`Override startPosition with lastCurrentTime @${t.toFixed(3)}`),e=t,this.state=O.IDLE):(this.loadedmetadata=!1,this.state=O.WAITING_TRACK),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}doTick(){switch(this.state){case O.IDLE:this.doTickIdle();break;case O.WAITING_TRACK:{var e;const{levels:s,trackId:i}=this,r=s==null||(e=s[i])==null?void 0:e.details;if(r){if(this.waitForCdnTuneIn(r))break;this.state=O.WAITING_INIT_PTS}break}case O.FRAG_LOADING_WAITING_RETRY:{var t;const s=performance.now(),i=this.retryDate;if(!i||s>=i||(t=this.media)!=null&&t.seeking){const{levels:r,trackId:n}=this;this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded((r==null?void 0:r[n])||null),this.state=O.IDLE}break}case O.WAITING_INIT_PTS:{const s=this.waitingData;if(s){const{frag:i,part:r,cache:n,complete:o}=s;if(this.initPTS[i.cc]!==void 0){this.waitingData=null,this.waitingVideoCC=-1,this.state=O.FRAG_LOADING;const l=n.flush(),c={frag:i,part:r,payload:l,networkDetails:null};this._handleFragmentLoadProgress(c),o&&super._handleFragmentLoadComplete(c)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log(`Waiting fragment cc (${i.cc}) cancelled because video is at cc ${this.videoTrackCC}`),this.clearWaitingFragment();else{const l=this.getLoadPosition(),c=Ee.bufferInfo(this.mediaBuffer,l,this.config.maxBufferHole);or(c.end,this.config.maxFragLookUpTolerance,i)<0&&(this.log(`Waiting fragment cc (${i.cc}) @ ${i.start} cancelled because another fragment at ${c.end} is needed`),this.clearWaitingFragment())}}else this.state=O.IDLE}}this.onTickEnd()}clearWaitingFragment(){const e=this.waitingData;e&&(this.fragmentTracker.removeFragment(e.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=O.IDLE)}resetLoadingState(){this.clearWaitingFragment(),super.resetLoadingState()}onTickEnd(){const{media:e}=this;e!=null&&e.readyState&&(this.lastCurrentTime=e.currentTime)}doTickIdle(){const{hls:e,levels:t,media:s,trackId:i}=this,r=e.config;if(!s&&(this.startFragRequested||!r.startFragPrefetch)||!(t!=null&&t[i]))return;const n=t[i],o=n.details;if(!o||o.live&&this.levelLastLoaded!==n||this.waitForCdnTuneIn(o)){this.state=O.WAITING_TRACK;return}const l=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&l&&(this.bufferFlushed=!1,this.afterBufferFlushed(l,xe.AUDIO,Q.AUDIO));const c=this.getFwdBufferInfo(l,Q.AUDIO);if(c===null)return;const{bufferedTrack:h,switchingTrack:u}=this;if(!u&&this._streamEnded(c,o)){e.trigger(p.BUFFER_EOS,{type:"audio"}),this.state=O.ENDED;return}const d=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,Q.MAIN),f=c.len,g=this.getMaxBufferLength(d==null?void 0:d.len),m=o.fragments,x=m[0].start;let T=this.flushing?this.getLoadPosition():c.end;if(u&&s){const L=this.getLoadPosition();h&&!es(u.attrs,h.attrs)&&(T=L),o.PTSKnown&&L<x&&(c.end>x||c.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),s.currentTime=x+.05)}if(f>=g&&!u&&T<m[m.length-1].start)return;let R=this.getNextFragment(T,o),v=!1;if(R&&this.isLoopLoading(R,T)&&(v=!!R.gap,R=this.getNextFragmentLoopLoading(R,o,c,Q.MAIN,g)),!R){this.bufferFlushed=!0;return}const D=d&&R.start>d.end+o.targetduration;if(D||!(d!=null&&d.len)&&c.len){const L=this.getAppendedFrag(R.start,Q.MAIN);if(L===null||(v||(v=!!L.gap||!!D&&d.len===0),D&&!v||v&&c.nextStart&&c.nextStart<L.end))return}this.loadFragment(R,n,T)}getMaxBufferLength(e){const t=super.getMaxBufferLength();return e?Math.min(Math.max(t,e),this.config.maxMaxBufferLength):t}onMediaDetaching(){this.videoBuffer=null,this.bufferFlushed=this.flushing=!1,super.onMediaDetaching()}onAudioTracksUpdated(e,{audioTracks:t}){this.resetTransmuxer(),this.levels=t.map(s=>new Zt(s))}onAudioTrackSwitching(e,t){const s=!!t.url;this.trackId=t.id;const{fragCurrent:i}=this;i&&(i.abortRequests(),this.removeUnbufferedFrags(i.start)),this.resetLoadingState(),s?this.setInterval(ca):this.resetTransmuxer(),s?(this.switchingTrack=t,this.state=O.IDLE,this.flushAudioIfNeeded(t)):(this.switchingTrack=null,this.bufferedTrack=t,this.state=O.STOPPED),this.tick()}onManifestLoading(){this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=this.flushing=!1,this.levels=this.mainDetails=this.waitingData=this.bufferedTrack=this.cachedTrackLoadedData=this.switchingTrack=null,this.startFragRequested=!1,this.trackId=this.videoTrackCC=this.waitingVideoCC=-1}onLevelLoaded(e,t){this.mainDetails=t.details,this.cachedTrackLoadedData!==null&&(this.hls.trigger(p.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)}onAudioTrackLoaded(e,t){var s;if(this.mainDetails==null){this.cachedTrackLoadedData=t;return}const{levels:i}=this,{details:r,id:n}=t;if(!i){this.warn(`Audio tracks were reset while loading level ${n}`);return}this.log(`Audio track ${n} loaded [${r.startSN},${r.endSN}]${r.lastPartSn?`[part-${r.lastPartSn}-${r.lastPartIndex}]`:""},duration:${r.totalduration}`);const o=i[n];let l=0;if(r.live||(s=o.details)!=null&&s.live){this.checkLiveUpdate(r);const h=this.mainDetails;if(r.deltaUpdateFailed||!h)return;if(!o.details&&r.hasProgramDateTime&&h.hasProgramDateTime)oi(r,h),l=r.fragments[0].start;else{var c;l=this.alignPlaylists(r,o.details,(c=this.levelLastLoaded)==null?void 0:c.details)}}o.details=r,this.levelLastLoaded=o,!this.startFragRequested&&(this.mainDetails||!r.live)&&this.setStartPosition(this.mainDetails||r,l),this.state===O.WAITING_TRACK&&!this.waitForCdnTuneIn(r)&&(this.state=O.IDLE),this.tick()}_handleFragmentLoadProgress(e){var t;const{frag:s,part:i,payload:r}=e,{config:n,trackId:o,levels:l}=this;if(!l){this.warn(`Audio tracks were reset while fragment load was in progress. Fragment ${s.sn} of level ${s.level} will not be buffered`);return}const c=l[o];if(!c){this.warn("Audio track is undefined on fragment load progress");return}const h=c.details;if(!h){this.warn("Audio track details undefined on fragment load progress"),this.removeUnbufferedFrags(s.start);return}const u=n.defaultAudioCodec||c.audioCodec||"mp4a.40.2";let d=this.transmuxer;d||(d=this.transmuxer=new po(this.hls,Q.AUDIO,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));const f=this.initPTS[s.cc],g=(t=s.initSegment)==null?void 0:t.data;if(f!==void 0){const x=i?i.index:-1,T=x!==-1,R=new Lr(s.level,s.sn,s.stats.chunkCount,r.byteLength,x,T);d.push(r,g,u,"",s,i,h.totalduration,!1,R,f)}else{this.log(`Unknown video PTS for cc ${s.cc}, waiting for video PTS before demuxing audio frag ${s.sn} of [${h.startSN} ,${h.endSN}],track ${o}`);const{cache:m}=this.waitingData=this.waitingData||{frag:s,part:i,cache:new Za,complete:!1};m.push(new Uint8Array(r)),this.waitingVideoCC=this.videoTrackCC,this.state=O.WAITING_INIT_PTS}}_handleFragmentLoadComplete(e){if(this.waitingData){this.waitingData.complete=!0;return}super._handleFragmentLoadComplete(e)}onBufferReset(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1}onBufferCreated(e,t){const s=t.tracks.audio;s&&(this.mediaBuffer=s.buffer||null),t.tracks.video&&(this.videoBuffer=t.tracks.video.buffer||null)}onFragBuffered(e,t){const{frag:s,part:i}=t;if(s.type!==Q.AUDIO){if(!this.loadedmetadata&&s.type===Q.MAIN){const r=this.videoBuffer||this.media;r&&Ee.getBuffered(r).length&&(this.loadedmetadata=!0)}return}if(this.fragContextChanged(s)){this.warn(`Fragment ${s.sn}${i?" p: "+i.index:""} of level ${s.level} finished buffering, but was aborted. state: ${this.state}, audioSwitch: ${this.switchingTrack?this.switchingTrack.name:"false"}`);return}if(s.sn!=="initSegment"){this.fragPrevious=s;const r=this.switchingTrack;r&&(this.bufferedTrack=r,this.switchingTrack=null,this.hls.trigger(p.AUDIO_TRACK_SWITCHED,Oe({},r)))}this.fragBufferedComplete(s,i)}onError(e,t){var s;if(t.fatal){this.state=O.ERROR;return}switch(t.details){case w.FRAG_GAP:case w.FRAG_PARSING_ERROR:case w.FRAG_DECRYPT_ERROR:case w.FRAG_LOAD_ERROR:case w.FRAG_LOAD_TIMEOUT:case w.KEY_LOAD_ERROR:case w.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(Q.AUDIO,t);break;case w.AUDIO_TRACK_LOAD_ERROR:case w.AUDIO_TRACK_LOAD_TIMEOUT:case w.LEVEL_PARSING_ERROR:!t.levelRetry&&this.state===O.WAITING_TRACK&&((s=t.context)==null?void 0:s.type)===ge.AUDIO_TRACK&&(this.state=O.IDLE);break;case w.BUFFER_APPEND_ERROR:case w.BUFFER_FULL_ERROR:if(!t.parent||t.parent!=="audio")return;if(t.details===w.BUFFER_APPEND_ERROR){this.resetLoadingState();return}this.reduceLengthAndFlushBuffer(t)&&(this.bufferedTrack=null,super.flushMainBuffer(0,Number.POSITIVE_INFINITY,"audio"));break;case w.INTERNAL_EXCEPTION:this.recoverWorkerError(t);break}}onBufferFlushing(e,{type:t}){t!==xe.VIDEO&&(this.flushing=!0)}onBufferFlushed(e,{type:t}){if(t!==xe.VIDEO){this.flushing=!1,this.bufferFlushed=!0,this.state===O.ENDED&&(this.state=O.IDLE);const s=this.mediaBuffer||this.media;s&&(this.afterBufferFlushed(s,t,Q.AUDIO),this.tick())}}_handleTransmuxComplete(e){var t;const s="audio",{hls:i}=this,{remuxResult:r,chunkMeta:n}=e,o=this.getCurrentContext(n);if(!o){this.resetWhenMissingContext(n);return}const{frag:l,part:c,level:h}=o,{details:u}=h,{audio:d,text:f,id3:g,initSegment:m}=r;if(this.fragContextChanged(l)||!u){this.fragmentTracker.removeFragment(l);return}if(this.state=O.PARSING,this.switchingTrack&&d&&this.completeAudioSwitch(this.switchingTrack),m!=null&&m.tracks){const x=l.initSegment||l;this._bufferInitSegment(h,m.tracks,x,n),i.trigger(p.FRAG_PARSING_INIT_SEGMENT,{frag:x,id:s,tracks:m.tracks})}if(d){const{startPTS:x,endPTS:T,startDTS:R,endDTS:v}=d;c&&(c.elementaryStreams[xe.AUDIO]={startPTS:x,endPTS:T,startDTS:R,endDTS:v}),l.setElementaryStreamInfo(xe.AUDIO,x,T,R,v),this.bufferFragmentData(d,l,c,n)}if(g!=null&&(t=g.samples)!=null&&t.length){const x=we({id:s,frag:l,details:u},g);i.trigger(p.FRAG_PARSING_METADATA,x)}if(f){const x=we({id:s,frag:l,details:u},f);i.trigger(p.FRAG_PARSING_USERDATA,x)}}_bufferInitSegment(e,t,s,i){if(this.state!==O.PARSING)return;t.video&&delete t.video;const r=t.audio;if(!r)return;r.id="audio";const n=e.audioCodec;this.log(`Init audio buffer, container:${r.container}, codecs[level/parsed]=[${n}/${r.codec}]`),n&&n.split(",").length===1&&(r.levelCodec=n),this.hls.trigger(p.BUFFER_CODECS,t);const o=r.initSegment;if(o!=null&&o.byteLength){const l={type:"audio",frag:s,part:null,chunkMeta:i,parent:s.type,data:o};this.hls.trigger(p.BUFFER_APPENDING,l)}this.tickImmediate()}loadFragment(e,t,s){const i=this.fragmentTracker.getState(e);if(this.fragCurrent=e,this.switchingTrack||i===Fe.NOT_LOADED||i===Fe.PARTIAL){var r;if(e.sn==="initSegment")this._loadInitSegment(e,t);else if((r=t.details)!=null&&r.live&&!this.initPTS[e.cc]){this.log(`Waiting for video PTS in continuity counter ${e.cc} of live stream before loading audio fragment ${e.sn} of level ${this.trackId}`),this.state=O.WAITING_INIT_PTS;const n=this.mainDetails;n&&n.fragments[0].start!==t.details.fragments[0].start&&oi(t.details,n)}else this.startFragRequested=!0,super.loadFragment(e,t,s)}else this.clearTrackerIfNeeded(e)}flushAudioIfNeeded(e){const{media:t,bufferedTrack:s}=this,i=s==null?void 0:s.attrs,r=e.attrs;t&&i&&(i.CHANNELS!==r.CHANNELS||s.name!==e.name||s.lang!==e.lang)&&(this.log("Switching audio track : flushing all audio"),super.flushMainBuffer(0,Number.POSITIVE_INFINITY,"audio"),this.bufferedTrack=null)}completeAudioSwitch(e){const{hls:t}=this;this.flushAudioIfNeeded(e),this.bufferedTrack=e,this.switchingTrack=null,t.trigger(p.AUDIO_TRACK_SWITCHED,Oe({},e))}}class xu extends Ar{constructor(e){super(e,"[audio-track-controller]"),this.tracks=[],this.groupIds=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0,this.registerListeners()}registerListeners(){const{hls:e}=this;e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.MANIFEST_PARSED,this.onManifestParsed,this),e.on(p.LEVEL_LOADING,this.onLevelLoading,this),e.on(p.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(p.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.on(p.ERROR,this.onError,this)}unregisterListeners(){const{hls:e}=this;e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.MANIFEST_PARSED,this.onManifestParsed,this),e.off(p.LEVEL_LOADING,this.onLevelLoading,this),e.off(p.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(p.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.off(p.ERROR,this.onError,this)}destroy(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.currentTrack=null,super.destroy()}onManifestLoading(){this.tracks=[],this.tracksInGroup=[],this.groupIds=null,this.currentTrack=null,this.trackId=-1,this.selectDefaultTrack=!0}onManifestParsed(e,t){this.tracks=t.audioTracks||[]}onAudioTrackLoaded(e,t){const{id:s,groupId:i,details:r}=t,n=this.tracksInGroup[s];if(!n||n.groupId!==i){this.warn(`Audio track with id:${s} and group:${i} not found in active group ${n==null?void 0:n.groupId}`);return}const o=n.details;n.details=t.details,this.log(`Audio track ${s} "${n.name}" lang:${n.lang} group:${i} loaded [${r.startSN}-${r.endSN}]`),s===this.trackId&&this.playlistLoaded(s,t,o)}onLevelLoading(e,t){this.switchLevel(t.level)}onLevelSwitching(e,t){this.switchLevel(t.level)}switchLevel(e){const t=this.hls.levels[e];if(!t)return;const s=t.audioGroups||null,i=this.groupIds;let r=this.currentTrack;if(!s||(i==null?void 0:i.length)!==(s==null?void 0:s.length)||s!=null&&s.some(o=>(i==null?void 0:i.indexOf(o))===-1)){this.groupIds=s,this.trackId=-1,this.currentTrack=null;const o=this.tracks.filter(d=>!s||s.indexOf(d.groupId)!==-1);if(o.length)this.selectDefaultTrack&&!o.some(d=>d.default)&&(this.selectDefaultTrack=!1),o.forEach((d,f)=>{d.id=f});else if(!r&&!this.tracksInGroup.length)return;this.tracksInGroup=o;const l=this.hls.config.audioPreference;if(!r&&l){const d=ht(l,o,Ht);if(d>-1)r=o[d];else{const f=ht(l,this.tracks);r=this.tracks[f]}}let c=this.findTrackId(r);c===-1&&r&&(c=this.findTrackId(null));const h={audioTracks:o};this.log(`Updating audio tracks, ${o.length} track(s) found in group(s): ${s==null?void 0:s.join(",")}`),this.hls.trigger(p.AUDIO_TRACKS_UPDATED,h);const u=this.trackId;if(c!==-1&&u===-1)this.setAudioTrack(c);else if(o.length&&u===-1){var n;const d=new Error(`No audio track selected for current audio group-ID(s): ${(n=this.groupIds)==null?void 0:n.join(",")} track count: ${o.length}`);this.warn(d.message),this.hls.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.AUDIO_TRACK_LOAD_ERROR,fatal:!0,error:d})}}else this.shouldReloadPlaylist(r)&&this.setAudioTrack(this.trackId)}onError(e,t){t.fatal||!t.context||t.context.type===ge.AUDIO_TRACK&&t.context.id===this.trackId&&(!this.groupIds||this.groupIds.indexOf(t.context.groupId)!==-1)&&(this.requestScheduled=-1,this.checkRetry(t))}get allAudioTracks(){return this.tracks}get audioTracks(){return this.tracksInGroup}get audioTrack(){return this.trackId}set audioTrack(e){this.selectDefaultTrack=!1,this.setAudioTrack(e)}setAudioOption(e){const t=this.hls;if(t.config.audioPreference=e,e){const s=this.allAudioTracks;if(this.selectDefaultTrack=!1,s.length){const i=this.currentTrack;if(i&&Xt(e,i,Ht))return i;const r=ht(e,this.tracksInGroup,Ht);if(r>-1){const n=this.tracksInGroup[r];return this.setAudioTrack(r),n}else if(i){let n=t.loadLevel;n===-1&&(n=t.firstAutoLevel);const o=xh(e,t.levels,s,n,Ht);if(o===-1)return null;t.nextLoadLevel=o}if(e.channels||e.audioCodec){const n=ht(e,s);if(n>-1)return s[n]}}}return null}setAudioTrack(e){const t=this.tracksInGroup;if(e<0||e>=t.length){this.warn(`Invalid audio track id: ${e}`);return}this.clearTimer(),this.selectDefaultTrack=!1;const s=this.currentTrack,i=t[e],r=i.details&&!i.details.live;if(e===this.trackId&&i===s&&r||(this.log(`Switching to audio-track ${e} "${i.name}" lang:${i.lang} group:${i.groupId} channels:${i.channels}`),this.trackId=e,this.currentTrack=i,this.hls.trigger(p.AUDIO_TRACK_SWITCHING,Oe({},i)),r))return;const n=this.switchParams(i.url,s==null?void 0:s.details,i.details);this.loadPlaylist(n)}findTrackId(e){const t=this.tracksInGroup;for(let s=0;s<t.length;s++){const i=t[s];if(!(this.selectDefaultTrack&&!i.default)&&(!e||Xt(e,i,Ht)))return s}if(e){const{name:s,lang:i,assocLang:r,characteristics:n,audioCodec:o,channels:l}=e;for(let c=0;c<t.length;c++){const h=t[c];if(Xt({name:s,lang:i,assocLang:r,characteristics:n,audioCodec:o,channels:l},h,Ht))return c}for(let c=0;c<t.length;c++){const h=t[c];if(es(e.attrs,h.attrs,["LANGUAGE","ASSOC-LANGUAGE","CHARACTERISTICS"]))return c}for(let c=0;c<t.length;c++){const h=t[c];if(es(e.attrs,h.attrs,["LANGUAGE"]))return c}}return-1}loadPlaylist(e){const t=this.currentTrack;if(this.shouldLoadPlaylist(t)&&t){super.loadPlaylist();const s=t.id,i=t.groupId;let r=t.url;if(e)try{r=e.addDirectives(r)}catch(n){this.warn(`Could not construct new URL with HLS Delivery Directives: ${n}`)}this.log(`loading audio-track playlist ${s} "${t.name}" lang:${t.lang} group:${i}`),this.clearTimer(),this.hls.trigger(p.AUDIO_TRACK_LOADING,{url:r,id:s,groupId:i,deliveryDirectives:e||null})}}}const ha=500;class yu extends br{constructor(e,t,s){super(e,t,s,"[subtitle-stream-controller]",Q.SUBTITLE),this.currentTrackId=-1,this.tracksBuffered=[],this.mainDetails=null,this._registerListeners()}onHandlerDestroying(){this._unregisterListeners(),super.onHandlerDestroying(),this.mainDetails=null}_registerListeners(){const{hls:e}=this;e.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.LEVEL_LOADED,this.onLevelLoaded,this),e.on(p.ERROR,this.onError,this),e.on(p.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.on(p.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),e.on(p.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.on(p.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),e.on(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(p.FRAG_BUFFERED,this.onFragBuffered,this)}_unregisterListeners(){const{hls:e}=this;e.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.LEVEL_LOADED,this.onLevelLoaded,this),e.off(p.ERROR,this.onError,this),e.off(p.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.off(p.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),e.off(p.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.off(p.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),e.off(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(p.FRAG_BUFFERED,this.onFragBuffered,this)}startLoad(e){this.stopLoad(),this.state=O.IDLE,this.setInterval(ha),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}onManifestLoading(){this.mainDetails=null,this.fragmentTracker.removeAllFragments()}onMediaDetaching(){this.tracksBuffered=[],super.onMediaDetaching()}onLevelLoaded(e,t){this.mainDetails=t.details}onSubtitleFragProcessed(e,t){const{frag:s,success:i}=t;if(this.fragPrevious=s,this.state=O.IDLE,!i)return;const r=this.tracksBuffered[this.currentTrackId];if(!r)return;let n;const o=s.start;for(let c=0;c<r.length;c++)if(o>=r[c].start&&o<=r[c].end){n=r[c];break}const l=s.start+s.duration;n?n.end=l:(n={start:o,end:l},r.push(n)),this.fragmentTracker.fragBuffered(s),this.fragBufferedComplete(s,null)}onBufferFlushing(e,t){const{startOffset:s,endOffset:i}=t;if(s===0&&i!==Number.POSITIVE_INFINITY){const r=i-1;if(r<=0)return;t.endOffsetSubtitles=Math.max(0,r),this.tracksBuffered.forEach(n=>{for(let o=0;o<n.length;){if(n[o].end<=r){n.shift();continue}else if(n[o].start<r)n[o].start=r;else break;o++}}),this.fragmentTracker.removeFragmentsInRange(s,r,Q.SUBTITLE)}}onFragBuffered(e,t){if(!this.loadedmetadata&&t.frag.type===Q.MAIN){var s;(s=this.media)!=null&&s.buffered.length&&(this.loadedmetadata=!0)}}onError(e,t){const s=t.frag;(s==null?void 0:s.type)===Q.SUBTITLE&&(t.details===w.FRAG_GAP&&this.fragmentTracker.fragBuffered(s,!0),this.fragCurrent&&this.fragCurrent.abortRequests(),this.state!==O.STOPPED&&(this.state=O.IDLE))}onSubtitleTracksUpdated(e,{subtitleTracks:t}){if(this.levels&&xo(this.levels,t)){this.levels=t.map(s=>new Zt(s));return}this.tracksBuffered=[],this.levels=t.map(s=>{const i=new Zt(s);return this.tracksBuffered[i.id]=[],i}),this.fragmentTracker.removeFragmentsInRange(0,Number.POSITIVE_INFINITY,Q.SUBTITLE),this.fragPrevious=null,this.mediaBuffer=null}onSubtitleTrackSwitch(e,t){var s;if(this.currentTrackId=t.id,!((s=this.levels)!=null&&s.length)||this.currentTrackId===-1){this.clearInterval();return}const i=this.levels[this.currentTrackId];i!=null&&i.details?this.mediaBuffer=this.mediaBufferTimeRanges:this.mediaBuffer=null,i&&this.setInterval(ha)}onSubtitleTrackLoaded(e,t){var s;const{currentTrackId:i,levels:r}=this,{details:n,id:o}=t;if(!r){this.warn(`Subtitle tracks were reset while loading level ${o}`);return}const l=r[o];if(o>=r.length||!l)return;this.log(`Subtitle track ${o} loaded [${n.startSN},${n.endSN}]${n.lastPartSn?`[part-${n.lastPartSn}-${n.lastPartIndex}]`:""},duration:${n.totalduration}`),this.mediaBuffer=this.mediaBufferTimeRanges;let c=0;if(n.live||(s=l.details)!=null&&s.live){const u=this.mainDetails;if(n.deltaUpdateFailed||!u)return;const d=u.fragments[0];if(!l.details)n.hasProgramDateTime&&u.hasProgramDateTime?(oi(n,u),c=n.fragments[0].start):d&&(c=d.start,ar(n,c));else{var h;c=this.alignPlaylists(n,l.details,(h=this.levelLastLoaded)==null?void 0:h.details),c===0&&d&&(c=d.start,ar(n,c))}}l.details=n,this.levelLastLoaded=l,o===i&&(!this.startFragRequested&&(this.mainDetails||!n.live)&&this.setStartPosition(this.mainDetails||n,c),this.tick(),n.live&&!this.fragCurrent&&this.media&&this.state===O.IDLE&&(ai(null,n.fragments,this.media.currentTime,0)||(this.warn("Subtitle playlist not aligned with playback"),l.details=void 0)))}_handleFragmentLoadComplete(e){const{frag:t,payload:s}=e,i=t.decryptdata,r=this.hls;if(!this.fragContextChanged(t)&&s&&s.byteLength>0&&i!=null&&i.key&&i.iv&&i.method==="AES-128"){const n=performance.now();this.decrypter.decrypt(new Uint8Array(s),i.key.buffer,i.iv.buffer).catch(o=>{throw r.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.FRAG_DECRYPT_ERROR,fatal:!1,error:o,reason:o.message,frag:t}),o}).then(o=>{const l=performance.now();r.trigger(p.FRAG_DECRYPTED,{frag:t,payload:o,stats:{tstart:n,tdecrypt:l}})}).catch(o=>{this.warn(`${o.name}: ${o.message}`),this.state=O.IDLE})}}doTick(){if(!this.media){this.state=O.IDLE;return}if(this.state===O.IDLE){const{currentTrackId:e,levels:t}=this,s=t==null?void 0:t[e];if(!s||!t.length||!s.details)return;const{config:i}=this,r=this.getLoadPosition(),n=Ee.bufferedInfo(this.tracksBuffered[this.currentTrackId]||[],r,i.maxBufferHole),{end:o,len:l}=n,c=this.getFwdBufferInfo(this.media,Q.MAIN),h=s.details,u=this.getMaxBufferLength(c==null?void 0:c.len)+h.levelTargetDuration;if(l>u)return;const d=h.fragments,f=d.length,g=h.edge;let m=null;const x=this.fragPrevious;if(o<g){const T=i.maxFragLookUpTolerance,R=o>g-T?0:T;m=ai(x,d,Math.max(d[0].start,o),R),!m&&x&&x.start<d[0].start&&(m=d[0])}else m=d[f-1];if(!m)return;if(m=this.mapToInitFragWhenRequired(m),m.sn!=="initSegment"){const T=m.sn-h.startSN,R=d[T-1];R&&R.cc===m.cc&&this.fragmentTracker.getState(R)===Fe.NOT_LOADED&&(m=R)}this.fragmentTracker.getState(m)===Fe.NOT_LOADED&&this.loadFragment(m,s,o)}}getMaxBufferLength(e){const t=super.getMaxBufferLength();return e?Math.max(t,e):t}loadFragment(e,t,s){this.fragCurrent=e,e.sn==="initSegment"?this._loadInitSegment(e,t):(this.startFragRequested=!0,super.loadFragment(e,t,s))}get mediaBufferTimeRanges(){return new Tu(this.tracksBuffered[this.currentTrackId]||[])}}class Tu{constructor(e){this.buffered=void 0;const t=(s,i,r)=>{if(i=i>>>0,i>r-1)throw new DOMException(`Failed to execute '${s}' on 'TimeRanges': The index provided (${i}) is greater than the maximum bound (${r})`);return e[i][s]};this.buffered={get length(){return e.length},end(s){return t("end",s,e.length)},start(s){return t("start",s,e.length)}}}}class Eu extends Ar{constructor(e){super(e,"[subtitle-track-controller]"),this.media=null,this.tracks=[],this.groupIds=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0,this.queuedDefaultTrack=-1,this.asyncPollTrackChange=()=>this.pollTrackChange(0),this.useTextTrackPolling=!1,this.subtitlePollingInterval=-1,this._subtitleDisplay=!0,this.onTextTracksChanged=()=>{if(this.useTextTrackPolling||self.clearInterval(this.subtitlePollingInterval),!this.media||!this.hls.config.renderTextTracksNatively)return;let t=null;const s=Vs(this.media.textTracks);for(let r=0;r<s.length;r++)if(s[r].mode==="hidden")t=s[r];else if(s[r].mode==="showing"){t=s[r];break}const i=this.findTrackForTextTrack(t);this.subtitleTrack!==i&&this.setSubtitleTrack(i)},this.registerListeners()}destroy(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.currentTrack=null,this.onTextTracksChanged=this.asyncPollTrackChange=null,super.destroy()}get subtitleDisplay(){return this._subtitleDisplay}set subtitleDisplay(e){this._subtitleDisplay=e,this.trackId>-1&&this.toggleTrackModes()}registerListeners(){const{hls:e}=this;e.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.MANIFEST_PARSED,this.onManifestParsed,this),e.on(p.LEVEL_LOADING,this.onLevelLoading,this),e.on(p.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(p.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.on(p.ERROR,this.onError,this)}unregisterListeners(){const{hls:e}=this;e.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.MANIFEST_PARSED,this.onManifestParsed,this),e.off(p.LEVEL_LOADING,this.onLevelLoading,this),e.off(p.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(p.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.off(p.ERROR,this.onError,this)}onMediaAttached(e,t){this.media=t.media,this.media&&(this.queuedDefaultTrack>-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))}pollTrackChange(e){self.clearInterval(this.subtitlePollingInterval),this.subtitlePollingInterval=self.setInterval(this.onTextTracksChanged,e)}onMediaDetaching(){if(!this.media)return;self.clearInterval(this.subtitlePollingInterval),this.useTextTrackPolling||this.media.textTracks.removeEventListener("change",this.asyncPollTrackChange),this.trackId>-1&&(this.queuedDefaultTrack=this.trackId),Vs(this.media.textTracks).forEach(t=>{zt(t)}),this.subtitleTrack=-1,this.media=null}onManifestLoading(){this.tracks=[],this.groupIds=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0}onManifestParsed(e,t){this.tracks=t.subtitleTracks}onSubtitleTrackLoaded(e,t){const{id:s,groupId:i,details:r}=t,n=this.tracksInGroup[s];if(!n||n.groupId!==i){this.warn(`Subtitle track with id:${s} and group:${i} not found in active group ${n==null?void 0:n.groupId}`);return}const o=n.details;n.details=t.details,this.log(`Subtitle track ${s} "${n.name}" lang:${n.lang} group:${i} loaded [${r.startSN}-${r.endSN}]`),s===this.trackId&&this.playlistLoaded(s,t,o)}onLevelLoading(e,t){this.switchLevel(t.level)}onLevelSwitching(e,t){this.switchLevel(t.level)}switchLevel(e){const t=this.hls.levels[e];if(!t)return;const s=t.subtitleGroups||null,i=this.groupIds;let r=this.currentTrack;if(!s||(i==null?void 0:i.length)!==(s==null?void 0:s.length)||s!=null&&s.some(n=>(i==null?void 0:i.indexOf(n))===-1)){this.groupIds=s,this.trackId=-1,this.currentTrack=null;const n=this.tracks.filter(h=>!s||s.indexOf(h.groupId)!==-1);if(n.length)this.selectDefaultTrack&&!n.some(h=>h.default)&&(this.selectDefaultTrack=!1),n.forEach((h,u)=>{h.id=u});else if(!r&&!this.tracksInGroup.length)return;this.tracksInGroup=n;const o=this.hls.config.subtitlePreference;if(!r&&o){this.selectDefaultTrack=!1;const h=ht(o,n);if(h>-1)r=n[h];else{const u=ht(o,this.tracks);r=this.tracks[u]}}let l=this.findTrackId(r);l===-1&&r&&(l=this.findTrackId(null));const c={subtitleTracks:n};this.log(`Updating subtitle tracks, ${n.length} track(s) found in "${s==null?void 0:s.join(",")}" group-id`),this.hls.trigger(p.SUBTITLE_TRACKS_UPDATED,c),l!==-1&&this.trackId===-1&&this.setSubtitleTrack(l)}else this.shouldReloadPlaylist(r)&&this.setSubtitleTrack(this.trackId)}findTrackId(e){const t=this.tracksInGroup,s=this.selectDefaultTrack;for(let i=0;i<t.length;i++){const r=t[i];if(!(s&&!r.default||!s&&!e)&&(!e||Xt(r,e)))return i}if(e){for(let i=0;i<t.length;i++){const r=t[i];if(es(e.attrs,r.attrs,["LANGUAGE","ASSOC-LANGUAGE","CHARACTERISTICS"]))return i}for(let i=0;i<t.length;i++){const r=t[i];if(es(e.attrs,r.attrs,["LANGUAGE"]))return i}}return-1}findTrackForTextTrack(e){if(e){const t=this.tracksInGroup;for(let s=0;s<t.length;s++){const i=t[s];if(cr(i,e))return s}}return-1}onError(e,t){t.fatal||!t.context||t.context.type===ge.SUBTITLE_TRACK&&t.context.id===this.trackId&&(!this.groupIds||this.groupIds.indexOf(t.context.groupId)!==-1)&&this.checkRetry(t)}get allSubtitleTracks(){return this.tracks}get subtitleTracks(){return this.tracksInGroup}get subtitleTrack(){return this.trackId}set subtitleTrack(e){this.selectDefaultTrack=!1,this.setSubtitleTrack(e)}setSubtitleOption(e){if(this.hls.config.subtitlePreference=e,e){const t=this.allSubtitleTracks;if(this.selectDefaultTrack=!1,t.length){const s=this.currentTrack;if(s&&Xt(e,s))return s;const i=ht(e,this.tracksInGroup);if(i>-1){const r=this.tracksInGroup[i];return this.setSubtitleTrack(i),r}else{if(s)return null;{const r=ht(e,t);if(r>-1)return t[r]}}}}return null}loadPlaylist(e){super.loadPlaylist();const t=this.currentTrack;if(this.shouldLoadPlaylist(t)&&t){const s=t.id,i=t.groupId;let r=t.url;if(e)try{r=e.addDirectives(r)}catch(n){this.warn(`Could not construct new URL with HLS Delivery Directives: ${n}`)}this.log(`Loading subtitle playlist for id ${s}`),this.hls.trigger(p.SUBTITLE_TRACK_LOADING,{url:r,id:s,groupId:i,deliveryDirectives:e||null})}}toggleTrackModes(){const{media:e}=this;if(!e)return;const t=Vs(e.textTracks),s=this.currentTrack;let i;if(s&&(i=t.filter(r=>cr(s,r))[0],i||this.warn(`Unable to find subtitle TextTrack with name "${s.name}" and language "${s.lang}"`)),[].slice.call(t).forEach(r=>{r.mode!=="disabled"&&r!==i&&(r.mode="disabled")}),i){const r=this.subtitleDisplay?"showing":"hidden";i.mode!==r&&(i.mode=r)}}setSubtitleTrack(e){const t=this.tracksInGroup;if(!this.media){this.queuedDefaultTrack=e;return}if(e<-1||e>=t.length||!j(e)){this.warn(`Invalid subtitle track id: ${e}`);return}this.clearTimer(),this.selectDefaultTrack=!1;const s=this.currentTrack,i=t[e]||null;if(this.trackId=e,this.currentTrack=i,this.toggleTrackModes(),!i){this.hls.trigger(p.SUBTITLE_TRACK_SWITCH,{id:e});return}const r=!!i.details&&!i.details.live;if(e===this.trackId&&i===s&&r)return;this.log(`Switching to subtitle-track ${e}`+(i?` "${i.name}" lang:${i.lang} group:${i.groupId}`:""));const{id:n,groupId:o="",name:l,type:c,url:h}=i;this.hls.trigger(p.SUBTITLE_TRACK_SWITCH,{id:n,groupId:o,name:l,type:c,url:h});const u=this.switchParams(i.url,s==null?void 0:s.details,i.details);this.loadPlaylist(u)}}class Su{constructor(e){this.buffers=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.buffers=e}append(e,t,s){const i=this.queues[t];i.push(e),i.length===1&&!s&&this.executeNext(t)}insertAbort(e,t){this.queues[t].unshift(e),this.executeNext(t)}appendBlocker(e){let t;const s=new Promise(r=>{t=r}),i={execute:t,onStart:()=>{},onComplete:()=>{},onError:()=>{}};return this.append(i,e),s}executeNext(e){const t=this.queues[e];if(t.length){const s=t[0];try{s.execute()}catch(i){b.warn(`[buffer-operation-queue]: Exception executing "${e}" SourceBuffer operation: ${i}`),s.onError(i);const r=this.buffers[e];r!=null&&r.updating||this.shiftAndExecuteNext(e)}}}shiftAndExecuteNext(e){this.queues[e].shift(),this.executeNext(e)}current(e){return this.queues[e][0]}}const ua=/(avc[1234]|hvc1|hev1|dvh[1e]|vp09|av01)(?:\.[^.,]+)+/;class vu{constructor(e){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=s=>{this.hls&&this.hls.pauseBuffering()},this._onStartStreaming=s=>{this.hls&&this.hls.resumeBuffering()},this._onMediaSourceOpen=()=>{const{media:s,mediaSource:i}=this;this.log("Media source opened"),s&&(s.removeEventListener("emptied",this._onMediaEmptied),this.updateMediaElementDuration(),this.hls.trigger(p.MEDIA_ATTACHED,{media:s,mediaSource:i})),i&&i.removeEventListener("sourceopen",this._onMediaSourceOpen),this.checkPendingTracks()},this._onMediaSourceClose=()=>{this.log("Media source closed")},this._onMediaSourceEnded=()=>{this.log("Media source ended")},this._onMediaEmptied=()=>{const{mediaSrc:s,_objectUrl:i}=this;s!==i&&b.error(`Media element src was set while attaching MediaSource (${i} > ${s})`)},this.hls=e;const t="[buffer-controller]";this.appendSource=kc(Ot(e.config.preferManagedMediaSource)),this.log=b.log.bind(b,t),this.warn=b.warn.bind(b,t),this.error=b.error.bind(b,t),this._initSourceBuffer(),this.registerListeners()}hasSourceTypes(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0}destroy(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null,this.hls=null}registerListeners(){const{hls:e}=this;e.on(p.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.MANIFEST_PARSED,this.onManifestParsed,this),e.on(p.BUFFER_RESET,this.onBufferReset,this),e.on(p.BUFFER_APPENDING,this.onBufferAppending,this),e.on(p.BUFFER_CODECS,this.onBufferCodecs,this),e.on(p.BUFFER_EOS,this.onBufferEos,this),e.on(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(p.LEVEL_UPDATED,this.onLevelUpdated,this),e.on(p.FRAG_PARSED,this.onFragParsed,this),e.on(p.FRAG_CHANGED,this.onFragChanged,this)}unregisterListeners(){const{hls:e}=this;e.off(p.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.MANIFEST_PARSED,this.onManifestParsed,this),e.off(p.BUFFER_RESET,this.onBufferReset,this),e.off(p.BUFFER_APPENDING,this.onBufferAppending,this),e.off(p.BUFFER_CODECS,this.onBufferCodecs,this),e.off(p.BUFFER_EOS,this.onBufferEos,this),e.off(p.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(p.LEVEL_UPDATED,this.onLevelUpdated,this),e.off(p.FRAG_PARSED,this.onFragParsed,this),e.off(p.FRAG_CHANGED,this.onFragChanged,this)}_initSourceBuffer(){this.sourceBuffer={},this.operationQueue=new Su(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.appendErrors={audio:0,video:0,audiovideo:0},this.lastMpegAudioChunk=null}onManifestLoading(){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=0,this.details=null}onManifestParsed(e,t){let s=2;(t.audio&&!t.video||!t.altAudio)&&(s=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=s,this.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`)}onMediaAttaching(e,t){const s=this.media=t.media,i=Ot(this.appendSource);if(s&&i){var r;const n=this.mediaSource=new i;this.log(`created media source: ${(r=n.constructor)==null?void 0:r.name}`),n.addEventListener("sourceopen",this._onMediaSourceOpen),n.addEventListener("sourceended",this._onMediaSourceEnded),n.addEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(n.addEventListener("startstreaming",this._onStartStreaming),n.addEventListener("endstreaming",this._onEndStreaming));const o=this._objectUrl=self.URL.createObjectURL(n);if(this.appendSource)try{s.removeAttribute("src");const l=self.ManagedMediaSource;s.disableRemotePlayback=s.disableRemotePlayback||l&&n instanceof l,da(s),Au(s,o),s.load()}catch{s.src=o}else s.src=o;s.addEventListener("emptied",this._onMediaEmptied)}}onMediaDetaching(){const{media:e,mediaSource:t,_objectUrl:s}=this;if(t){if(this.log("media source detaching"),t.readyState==="open")try{t.endOfStream()}catch(i){this.warn(`onMediaDetaching: ${i.message} while calling endOfStream`)}this.onBufferReset(),t.removeEventListener("sourceopen",this._onMediaSourceOpen),t.removeEventListener("sourceended",this._onMediaSourceEnded),t.removeEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(t.removeEventListener("startstreaming",this._onStartStreaming),t.removeEventListener("endstreaming",this._onEndStreaming)),e&&(e.removeEventListener("emptied",this._onMediaEmptied),s&&self.URL.revokeObjectURL(s),this.mediaSrc===s?(e.removeAttribute("src"),this.appendSource&&da(e),e.load()):this.warn("media|source.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal,this.pendingTracks={},this.tracks={}}this.hls.trigger(p.MEDIA_DETACHED,void 0)}onBufferReset(){this.getSourceBufferTypes().forEach(e=>{this.resetBuffer(e)}),this._initSourceBuffer()}resetBuffer(e){const t=this.sourceBuffer[e];try{if(t){var s;this.removeBufferListeners(e),this.sourceBuffer[e]=void 0,(s=this.mediaSource)!=null&&s.sourceBuffers.length&&this.mediaSource.removeSourceBuffer(t)}}catch(i){this.warn(`onBufferReset ${e}`,i)}}onBufferCodecs(e,t){const s=this.getSourceBufferTypes().length,i=Object.keys(t);if(i.forEach(n=>{if(s){const l=this.tracks[n];if(l&&typeof l.buffer.changeType=="function"){var o;const{id:c,codec:h,levelCodec:u,container:d,metadata:f}=t[n],g=Pn(l.codec,l.levelCodec),m=g==null?void 0:g.replace(ua,"$1");let x=Pn(h,u);const T=(o=x)==null?void 0:o.replace(ua,"$1");if(x&&m!==T){n.slice(0,5)==="audio"&&(x=si(x,this.appendSource));const R=`${d};codecs=${x}`;this.appendChangeType(n,R),this.log(`switching codec ${g} to ${x}`),this.tracks[n]={buffer:l.buffer,codec:h,container:d,levelCodec:u,metadata:f,id:c}}}}else this.pendingTracks[n]=t[n]}),s)return;const r=Math.max(this.bufferCodecEventsExpected-1,0);this.bufferCodecEventsExpected!==r&&(this.log(`${r} bufferCodec event(s) expected ${i.join(",")}`),this.bufferCodecEventsExpected=r),this.mediaSource&&this.mediaSource.readyState==="open"&&this.checkPendingTracks()}appendChangeType(e,t){const{operationQueue:s}=this,i={execute:()=>{const r=this.sourceBuffer[e];r&&(this.log(`changing ${e} sourceBuffer type to ${t}`),r.changeType(t)),s.shiftAndExecuteNext(e)},onStart:()=>{},onComplete:()=>{},onError:r=>{this.warn(`Failed to change ${e} SourceBuffer type`,r)}};s.append(i,e,!!this.pendingTracks[e])}onBufferAppending(e,t){const{hls:s,operationQueue:i,tracks:r}=this,{data:n,type:o,frag:l,part:c,chunkMeta:h}=t,u=h.buffering[o],d=self.performance.now();u.start=d;const f=l.stats.buffering,g=c?c.stats.buffering:null;f.start===0&&(f.start=d),g&&g.start===0&&(g.start=d);const m=r.audio;let x=!1;o==="audio"&&(m==null?void 0:m.container)==="audio/mpeg"&&(x=!this.lastMpegAudioChunk||h.id===1||this.lastMpegAudioChunk.sn!==h.sn,this.lastMpegAudioChunk=h);const T=l.start,R={execute:()=>{if(u.executeStart=self.performance.now(),x){const v=this.sourceBuffer[o];if(v){const D=T-v.timestampOffset;Math.abs(D)>=.1&&(this.log(`Updating audio SourceBuffer timestampOffset to ${T} (delta: ${D}) sn: ${l.sn})`),v.timestampOffset=T)}}this.appendExecutor(n,o)},onStart:()=>{},onComplete:()=>{const v=self.performance.now();u.executeEnd=u.end=v,f.first===0&&(f.first=v),g&&g.first===0&&(g.first=v);const{sourceBuffer:D}=this,L={};for(const _ in D)L[_]=Ee.getBuffered(D[_]);this.appendErrors[o]=0,o==="audio"||o==="video"?this.appendErrors.audiovideo=0:(this.appendErrors.audio=0,this.appendErrors.video=0),this.hls.trigger(p.BUFFER_APPENDED,{type:o,frag:l,part:c,chunkMeta:h,parent:l.type,timeRanges:L})},onError:v=>{const D={type:Z.MEDIA_ERROR,parent:l.type,details:w.BUFFER_APPEND_ERROR,sourceBufferName:o,frag:l,part:c,chunkMeta:h,error:v,err:v,fatal:!1};if(v.code===DOMException.QUOTA_EXCEEDED_ERR)D.details=w.BUFFER_FULL_ERROR;else{const L=++this.appendErrors[o];D.details=w.BUFFER_APPEND_ERROR,this.warn(`Failed ${L}/${s.config.appendErrorMaxRetry} times to append segment in "${o}" sourceBuffer`),L>=s.config.appendErrorMaxRetry&&(D.fatal=!0)}s.trigger(p.ERROR,D)}};i.append(R,o,!!this.pendingTracks[o])}onBufferFlushing(e,t){const{operationQueue:s}=this,i=r=>({execute:this.removeExecutor.bind(this,r,t.startOffset,t.endOffset),onStart:()=>{},onComplete:()=>{this.hls.trigger(p.BUFFER_FLUSHED,{type:r})},onError:n=>{this.warn(`Failed to remove from ${r} SourceBuffer`,n)}});t.type?s.append(i(t.type),t.type):this.getSourceBufferTypes().forEach(r=>{s.append(i(r),r)})}onFragParsed(e,t){const{frag:s,part:i}=t,r=[],n=i?i.elementaryStreams:s.elementaryStreams;n[xe.AUDIOVIDEO]?r.push("audiovideo"):(n[xe.AUDIO]&&r.push("audio"),n[xe.VIDEO]&&r.push("video"));const o=()=>{const l=self.performance.now();s.stats.buffering.end=l,i&&(i.stats.buffering.end=l);const c=i?i.stats:s.stats;this.hls.trigger(p.FRAG_BUFFERED,{frag:s,part:i,stats:c,id:s.type})};r.length===0&&this.warn(`Fragments must have at least one ElementaryStreamType set. type: ${s.type} level: ${s.level} sn: ${s.sn}`),this.blockBuffers(o,r)}onFragChanged(e,t){this.trimBuffers()}onBufferEos(e,t){this.getSourceBufferTypes().reduce((i,r)=>{const n=this.sourceBuffer[r];return n&&(!t.type||t.type===r)&&(n.ending=!0,n.ended||(n.ended=!0,this.log(`${r} sourceBuffer now EOS`))),i&&!!(!n||n.ended)},!0)&&(this.log("Queueing mediaSource.endOfStream()"),this.blockBuffers(()=>{this.getSourceBufferTypes().forEach(r=>{const n=this.sourceBuffer[r];n&&(n.ending=!1)});const{mediaSource:i}=this;if(!i||i.readyState!=="open"){i&&this.log(`Could not call mediaSource.endOfStream(). mediaSource.readyState: ${i.readyState}`);return}this.log("Calling mediaSource.endOfStream()"),i.endOfStream()}))}onLevelUpdated(e,{details:t}){t.fragments.length&&(this.details=t,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())}trimBuffers(){const{hls:e,details:t,media:s}=this;if(!s||t===null||!this.getSourceBufferTypes().length)return;const r=e.config,n=s.currentTime,o=t.levelTargetDuration,l=t.live&&r.liveBackBufferLength!==null?r.liveBackBufferLength:r.backBufferLength;if(j(l)&&l>0){const c=Math.max(l,o),h=Math.floor(n/o)*o-c;this.flushBackBuffer(n,o,h)}if(j(r.frontBufferFlushThreshold)&&r.frontBufferFlushThreshold>0){const c=Math.max(r.maxBufferLength,r.frontBufferFlushThreshold),h=Math.max(c,o),u=Math.floor(n/o)*o+h;this.flushFrontBuffer(n,o,u)}}flushBackBuffer(e,t,s){const{details:i,sourceBuffer:r}=this;this.getSourceBufferTypes().forEach(o=>{const l=r[o];if(l){const c=Ee.getBuffered(l);if(c.length>0&&s>c.start(0)){if(this.hls.trigger(p.BACK_BUFFER_REACHED,{bufferEnd:s}),i!=null&&i.live)this.hls.trigger(p.LIVE_BACK_BUFFER_REACHED,{bufferEnd:s});else if(l.ended&&c.end(c.length-1)-e<t*2){this.log(`Cannot flush ${o} back buffer while SourceBuffer is in ended state`);return}this.hls.trigger(p.BUFFER_FLUSHING,{startOffset:0,endOffset:s,type:o})}}})}flushFrontBuffer(e,t,s){const{sourceBuffer:i}=this;this.getSourceBufferTypes().forEach(n=>{const o=i[n];if(o){const l=Ee.getBuffered(o),c=l.length;if(c<2)return;const h=l.start(c-1),u=l.end(c-1);if(s>h||e>=h&&e<=u)return;if(o.ended&&e-u<2*t){this.log(`Cannot flush ${n} front buffer while SourceBuffer is in ended state`);return}this.hls.trigger(p.BUFFER_FLUSHING,{startOffset:h,endOffset:1/0,type:n})}})}updateMediaElementDuration(){if(!this.details||!this.media||!this.mediaSource||this.mediaSource.readyState!=="open")return;const{details:e,hls:t,media:s,mediaSource:i}=this,r=e.fragments[0].start+e.totalduration,n=s.duration,o=j(i.duration)?i.duration:0;e.live&&t.config.liveDurationInfinity?(i.duration=1/0,this.updateSeekableRange(e)):(r>o&&r>n||!j(n))&&(this.log(`Updating Media Source duration to ${r.toFixed(3)}`),i.duration=r)}updateSeekableRange(e){const t=this.mediaSource,s=e.fragments;if(s.length&&e.live&&t!=null&&t.setLiveSeekableRange){const r=Math.max(0,s[0].start),n=Math.max(r,r+e.totalduration);this.log(`Media Source duration is set to ${t.duration}. Setting seekable range to ${r}-${n}.`),t.setLiveSeekableRange(r,n)}}checkPendingTracks(){const{bufferCodecEventsExpected:e,operationQueue:t,pendingTracks:s}=this,i=Object.keys(s).length;if(i&&(!e||i===2||"audiovideo"in s)){this.createSourceBuffers(s),this.pendingTracks={};const r=this.getSourceBufferTypes();if(r.length)this.hls.trigger(p.BUFFER_CREATED,{tracks:this.tracks}),r.forEach(n=>{t.executeNext(n)});else{const n=new Error("could not create source buffer for media codec(s)");this.hls.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:n,reason:n.message})}}}createSourceBuffers(e){const{sourceBuffer:t,mediaSource:s}=this;if(!s)throw Error("createSourceBuffers called when mediaSource was null");for(const r in e)if(!t[r]){var i;const n=e[r];if(!n)throw Error(`source buffer exists for track ${r}, however track does not`);let o=((i=n.levelCodec)==null?void 0:i.indexOf(","))===-1?n.levelCodec:n.codec;o&&r.slice(0,5)==="audio"&&(o=si(o,this.appendSource));const l=`${n.container};codecs=${o}`;this.log(`creating sourceBuffer(${l})`);try{const c=t[r]=s.addSourceBuffer(l),h=r;this.addBufferListener(h,"updatestart",this._onSBUpdateStart),this.addBufferListener(h,"updateend",this._onSBUpdateEnd),this.addBufferListener(h,"error",this._onSBUpdateError),this.appendSource&&this.addBufferListener(h,"bufferedchange",(u,d)=>{const f=d.removedRanges;f!=null&&f.length&&this.hls.trigger(p.BUFFER_FLUSHED,{type:r})}),this.tracks[r]={buffer:c,codec:o,container:n.container,levelCodec:n.levelCodec,metadata:n.metadata,id:n.id}}catch(c){this.error(`error while trying to add sourceBuffer: ${c.message}`),this.hls.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:c,sourceBufferName:r,mimeType:l})}}}get mediaSrc(){var e,t;const s=((e=this.media)==null||(t=e.querySelector)==null?void 0:t.call(e,"source"))||this.media;return s==null?void 0:s.src}_onSBUpdateStart(e){const{operationQueue:t}=this;t.current(e).onStart()}_onSBUpdateEnd(e){var t;if(((t=this.mediaSource)==null?void 0:t.readyState)==="closed"){this.resetBuffer(e);return}const{operationQueue:s}=this;s.current(e).onComplete(),s.shiftAndExecuteNext(e)}_onSBUpdateError(e,t){var s;const i=new Error(`${e} SourceBuffer error. MediaSource readyState: ${(s=this.mediaSource)==null?void 0:s.readyState}`);this.error(`${i}`,t),this.hls.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.BUFFER_APPENDING_ERROR,sourceBufferName:e,error:i,fatal:!1});const r=this.operationQueue.current(e);r&&r.onError(i)}removeExecutor(e,t,s){const{media:i,mediaSource:r,operationQueue:n,sourceBuffer:o}=this,l=o[e];if(!i||!r||!l){this.warn(`Attempting to remove from the ${e} SourceBuffer, but it does not exist`),n.shiftAndExecuteNext(e);return}const c=j(i.duration)?i.duration:1/0,h=j(r.duration)?r.duration:1/0,u=Math.max(0,t),d=Math.min(s,c,h);d>u&&(!l.ending||l.ended)?(l.ended=!1,this.log(`Removing [${u},${d}] from the ${e} SourceBuffer`),l.remove(u,d)):n.shiftAndExecuteNext(e)}appendExecutor(e,t){const s=this.sourceBuffer[t];if(!s){if(!this.pendingTracks[t])throw new Error(`Attempting to append to the ${t} SourceBuffer, but it does not exist`);return}s.ended=!1,s.appendBuffer(e)}blockBuffers(e,t=this.getSourceBufferTypes()){if(!t.length){this.log("Blocking operation requested, but no SourceBuffers exist"),Promise.resolve().then(e);return}const{operationQueue:s}=this,i=t.map(r=>s.appendBlocker(r));Promise.all(i).then(()=>{e(),t.forEach(r=>{const n=this.sourceBuffer[r];n!=null&&n.updating||s.shiftAndExecuteNext(r)})})}getSourceBufferTypes(){return Object.keys(this.sourceBuffer)}addBufferListener(e,t,s){const i=this.sourceBuffer[e];if(!i)return;const r=s.bind(this,e);this.listeners[e].push({event:t,listener:r}),i.addEventListener(t,r)}removeBufferListeners(e){const t=this.sourceBuffer[e];t&&this.listeners[e].forEach(s=>{t.removeEventListener(s.event,s.listener)})}}function da(a){const e=a.querySelectorAll("source");[].slice.call(e).forEach(t=>{a.removeChild(t)})}function Au(a,e){const t=self.document.createElement("source");t.type="video/mp4",t.src=e,a.appendChild(t)}const Lu={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},yo=a=>String.fromCharCode(Lu[a]||a),st=15,xt=100,Ru={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},bu={17:2,18:4,21:6,22:8,23:10,19:13,20:15},Iu={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},Du={25:2,26:4,29:6,30:8,31:10,27:13,28:15},Cu=["white","green","blue","cyan","red","yellow","magenta","black","transparent"];class wu{constructor(){this.time=null,this.verboseLevel=0}log(e,t){if(this.verboseLevel>=e){const s=typeof t=="function"?t():t;b.log(`${this.time} [${e}] ${s}`)}}}const _t=function(e){const t=[];for(let s=0;s<e.length;s++)t.push(e[s].toString(16));return t};class To{constructor(){this.foreground="white",this.underline=!1,this.italics=!1,this.background="black",this.flash=!1}reset(){this.foreground="white",this.underline=!1,this.italics=!1,this.background="black",this.flash=!1}setStyles(e){const t=["foreground","underline","italics","background","flash"];for(let s=0;s<t.length;s++){const i=t[s];e.hasOwnProperty(i)&&(this[i]=e[i])}}isDefault(){return this.foreground==="white"&&!this.underline&&!this.italics&&this.background==="black"&&!this.flash}equals(e){return this.foreground===e.foreground&&this.underline===e.underline&&this.italics===e.italics&&this.background===e.background&&this.flash===e.flash}copy(e){this.foreground=e.foreground,this.underline=e.underline,this.italics=e.italics,this.background=e.background,this.flash=e.flash}toString(){return"color="+this.foreground+", underline="+this.underline+", italics="+this.italics+", background="+this.background+", flash="+this.flash}}class ku{constructor(){this.uchar=" ",this.penState=new To}reset(){this.uchar=" ",this.penState.reset()}setChar(e,t){this.uchar=e,this.penState.copy(t)}setPenState(e){this.penState.copy(e)}equals(e){return this.uchar===e.uchar&&this.penState.equals(e.penState)}copy(e){this.uchar=e.uchar,this.penState.copy(e.penState)}isEmpty(){return this.uchar===" "&&this.penState.isDefault()}}class _u{constructor(e){this.chars=[],this.pos=0,this.currPenState=new To,this.cueStartTime=null,this.logger=void 0;for(let t=0;t<xt;t++)this.chars.push(new ku);this.logger=e}equals(e){for(let t=0;t<xt;t++)if(!this.chars[t].equals(e.chars[t]))return!1;return!0}copy(e){for(let t=0;t<xt;t++)this.chars[t].copy(e.chars[t])}isEmpty(){let e=!0;for(let t=0;t<xt;t++)if(!this.chars[t].isEmpty()){e=!1;break}return e}setCursor(e){this.pos!==e&&(this.pos=e),this.pos<0?(this.logger.log(3,"Negative cursor position "+this.pos),this.pos=0):this.pos>xt&&(this.logger.log(3,"Too large cursor position "+this.pos),this.pos=xt)}moveCursor(e){const t=this.pos+e;if(e>1)for(let s=this.pos+1;s<t+1;s++)this.chars[s].setPenState(this.currPenState);this.setCursor(t)}backSpace(){this.moveCursor(-1),this.chars[this.pos].setChar(" ",this.currPenState)}insertChar(e){e>=144&&this.backSpace();const t=yo(e);if(this.pos>=xt){this.logger.log(0,()=>"Cannot insert "+e.toString(16)+" ("+t+") at position "+this.pos+". Skipping it!");return}this.chars[this.pos].setChar(t,this.currPenState),this.moveCursor(1)}clearFromPos(e){let t;for(t=e;t<xt;t++)this.chars[t].reset()}clear(){this.clearFromPos(0),this.pos=0,this.currPenState.reset()}clearToEndOfRow(){this.clearFromPos(this.pos)}getTextString(){const e=[];let t=!0;for(let s=0;s<xt;s++){const i=this.chars[s].uchar;i!==" "&&(t=!1),e.push(i)}return t?"":e.join("")}setPenStyles(e){this.currPenState.setStyles(e),this.chars[this.pos].setPenState(this.currPenState)}}class Vi{constructor(e){this.rows=[],this.currRow=st-1,this.nrRollUpRows=null,this.lastOutputScreen=null,this.logger=void 0;for(let t=0;t<st;t++)this.rows.push(new _u(e));this.logger=e}reset(){for(let e=0;e<st;e++)this.rows[e].clear();this.currRow=st-1}equals(e){let t=!0;for(let s=0;s<st;s++)if(!this.rows[s].equals(e.rows[s])){t=!1;break}return t}copy(e){for(let t=0;t<st;t++)this.rows[t].copy(e.rows[t])}isEmpty(){let e=!0;for(let t=0;t<st;t++)if(!this.rows[t].isEmpty()){e=!1;break}return e}backSpace(){this.rows[this.currRow].backSpace()}clearToEndOfRow(){this.rows[this.currRow].clearToEndOfRow()}insertChar(e){this.rows[this.currRow].insertChar(e)}setPen(e){this.rows[this.currRow].setPenStyles(e)}moveCursor(e){this.rows[this.currRow].moveCursor(e)}setCursor(e){this.logger.log(2,"setCursor: "+e),this.rows[this.currRow].setCursor(e)}setPAC(e){this.logger.log(2,()=>"pacData = "+JSON.stringify(e));let t=e.row-1;if(this.nrRollUpRows&&t<this.nrRollUpRows-1&&(t=this.nrRollUpRows-1),this.nrRollUpRows&&this.currRow!==t){for(let o=0;o<st;o++)this.rows[o].clear();const r=this.currRow+1-this.nrRollUpRows,n=this.lastOutputScreen;if(n){const o=n.rows[r].cueStartTime,l=this.logger.time;if(o!==null&&l!==null&&o<l)for(let c=0;c<this.nrRollUpRows;c++)this.rows[t-this.nrRollUpRows+c+1].copy(n.rows[r+c])}}this.currRow=t;const s=this.rows[this.currRow];if(e.indent!==null){const r=e.indent,n=Math.max(r-1,0);s.setCursor(e.indent),e.color=s.chars[n].penState.foreground}const i={foreground:e.color,underline:e.underline,italics:e.italics,background:"black",flash:!1};this.setPen(i)}setBkgData(e){this.logger.log(2,()=>"bkgData = "+JSON.stringify(e)),this.backSpace(),this.setPen(e),this.insertChar(32)}setRollUpRows(e){this.nrRollUpRows=e}rollUp(){if(this.nrRollUpRows===null){this.logger.log(3,"roll_up but nrRollUpRows not set yet");return}this.logger.log(1,()=>this.getDisplayText());const e=this.currRow+1-this.nrRollUpRows,t=this.rows.splice(e,1)[0];t.clear(),this.rows.splice(this.currRow,0,t),this.logger.log(2,"Rolling up")}getDisplayText(e){e=e||!1;const t=[];let s="",i=-1;for(let r=0;r<st;r++){const n=this.rows[r].getTextString();n&&(i=r+1,e?t.push("Row "+i+": '"+n+"'"):t.push(n.trim()))}return t.length>0&&(e?s="["+t.join(" | ")+"]":s=t.join(` 30`)),s}getTextAndFormat(){return this.rows}}class fa{constructor(e,t,s){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=e,this.outputFilter=t,this.mode=null,this.verbose=0,this.displayedMemory=new Vi(s),this.nonDisplayedMemory=new Vi(s),this.lastOutputScreen=new Vi(s),this.currRollUpRow=this.displayedMemory.rows[st-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.logger=s}reset(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.outputFilter.reset(),this.currRollUpRow=this.displayedMemory.rows[st-1],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null}getHandler(){return this.outputFilter}setHandler(e){this.outputFilter=e}setPAC(e){this.writeScreen.setPAC(e)}setBkgData(e){this.writeScreen.setBkgData(e)}setMode(e){e!==this.mode&&(this.mode=e,this.logger.log(2,()=>"MODE="+e),this.mode==="MODE_POP-ON"?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),this.mode!=="MODE_ROLL-UP"&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=e)}insertChars(e){for(let s=0;s<e.length;s++)this.writeScreen.insertChar(e[s]);const t=this.writeScreen===this.displayedMemory?"DISP":"NON_DISP";this.logger.log(2,()=>t+": "+this.writeScreen.getDisplayText(!0)),(this.mode==="MODE_PAINT-ON"||this.mode==="MODE_ROLL-UP")&&(this.logger.log(1,()=>"DISPLAYED: "+this.displayedMemory.getDisplayText(!0)),this.outputDataUpdate())}ccRCL(){this.logger.log(2,"RCL - Resume Caption Loading"),this.setMode("MODE_POP-ON")}ccBS(){this.logger.log(2,"BS - BackSpace"),this.mode!=="MODE_TEXT"&&(this.writeScreen.backSpace(),this.writeScreen===this.displayedMemory&&this.outputDataUpdate())}ccAOF(){}ccAON(){}ccDER(){this.logger.log(2,"DER- Delete to End of Row"),this.writeScreen.clearToEndOfRow(),this.outputDataUpdate()}ccRU(e){this.logger.log(2,"RU("+e+") - Roll Up"),this.writeScreen=this.displayedMemory,this.setMode("MODE_ROLL-UP"),this.writeScreen.setRollUpRows(e)}ccFON(){this.logger.log(2,"FON - Flash On"),this.writeScreen.setPen({flash:!0})}ccRDC(){this.logger.log(2,"RDC - Resume Direct Captioning"),this.setMode("MODE_PAINT-ON")}ccTR(){this.logger.log(2,"TR"),this.setMode("MODE_TEXT")}ccRTD(){this.logger.log(2,"RTD"),this.setMode("MODE_TEXT")}ccEDM(){this.logger.log(2,"EDM - Erase Displayed Memory"),this.displayedMemory.reset(),this.outputDataUpdate(!0)}ccCR(){this.logger.log(2,"CR - Carriage Return"),this.writeScreen.rollUp(),this.outputDataUpdate(!0)}ccENM(){this.logger.log(2,"ENM - Erase Non-displayed Memory"),this.nonDisplayedMemory.reset()}ccEOC(){if(this.logger.log(2,"EOC - End Of Caption"),this.mode==="MODE_POP-ON"){const e=this.displayedMemory;this.displayedMemory=this.nonDisplayedMemory,this.nonDisplayedMemory=e,this.writeScreen=this.nonDisplayedMemory,this.logger.log(1,()=>"DISP: "+this.displayedMemory.getDisplayText())}this.outputDataUpdate(!0)}ccTO(e){this.logger.log(2,"TO("+e+") - Tab Offset"),this.writeScreen.moveCursor(e)}ccMIDROW(e){const t={flash:!1};if(t.underline=e%2===1,t.italics=e>=46,t.italics)t.foreground="white";else{const s=Math.floor(e/2)-16,i=["white","green","blue","cyan","red","yellow","magenta"];t.foreground=i[s]}this.logger.log(2,"MIDROW: "+JSON.stringify(t)),this.writeScreen.setPen(t)}outputDataUpdate(e=!1){const t=this.logger.time;t!==null&&this.outputFilter&&(this.cueStartTime===null&&!this.displayedMemory.isEmpty()?this.cueStartTime=t:this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue(this.cueStartTime,t,this.lastOutputScreen),e&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:t),this.lastOutputScreen.copy(this.displayedMemory))}cueSplitAtTime(e){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,e,this.displayedMemory),this.cueStartTime=e))}}class ga{constructor(e,t,s){this.channels=void 0,this.currentChannel=0,this.cmdHistory=Mu(),this.logger=void 0;const i=this.logger=new wu;this.channels=[null,new fa(e,t,i),new fa(e+1,s,i)]}getHandler(e){return this.channels[e].getHandler()}setHandler(e,t){this.channels[e].setHandler(t)}addData(e,t){this.logger.time=e;for(let s=0;s<t.length;s+=2){const i=t[s]&127,r=t[s+1]&127;let n=!1,o=null;if(i===0&&r===0)continue;this.logger.log(3,()=>"["+_t([t[s],t[s+1]])+"] -> ("+_t([i,r])+")");const l=this.cmdHistory;if(i>=16&&i<=31){if(Pu(i,r,l)){Bs(null,null,l),this.logger.log(3,()=>"Repeated command ("+_t([i,r])+") is dropped");continue}Bs(i,r,this.cmdHistory),n=this.parseCmd(i,r),n||(n=this.parseMidrow(i,r)),n||(n=this.parsePAC(i,r)),n||(n=this.parseBackgroundAttributes(i,r))}else Bs(null,null,l);if(!n&&(o=this.parseChars(i,r),o)){const h=this.currentChannel;h&&h>0?this.channels[h].insertChars(o):this.logger.log(2,"No channel found yet. TEXT-MODE?")}!n&&!o&&this.logger.log(2,()=>"Couldn't parse cleaned data "+_t([i,r])+" orig: "+_t([t[s],t[s+1]]))}}parseCmd(e,t){const s=(e===20||e===28||e===21||e===29)&&t>=32&&t<=47,i=(e===23||e===31)&&t>=33&&t<=35;if(!(s||i))return!1;const r=e===20||e===21||e===23?1:2,n=this.channels[r];return e===20||e===21||e===28||e===29?t===32?n.ccRCL():t===33?n.ccBS():t===34?n.ccAOF():t===35?n.ccAON():t===36?n.ccDER():t===37?n.ccRU(2):t===38?n.ccRU(3):t===39?n.ccRU(4):t===40?n.ccFON():t===41?n.ccRDC():t===42?n.ccTR():t===43?n.ccRTD():t===44?n.ccEDM():t===45?n.ccCR():t===46?n.ccENM():t===47&&n.ccEOC():n.ccTO(t-32),this.currentChannel=r,!0}parseMidrow(e,t){let s=0;if((e===17||e===25)&&t>=32&&t<=47){if(e===17?s=1:s=2,s!==this.currentChannel)return this.logger.log(0,"Mismatch channel in midrow parsing"),!1;const i=this.channels[s];return i?(i.ccMIDROW(t),this.logger.log(3,()=>"MIDROW ("+_t([e,t])+")"),!0):!1}return!1}parsePAC(e,t){let s;const i=(e>=17&&e<=23||e>=25&&e<=31)&&t>=64&&t<=127,r=(e===16||e===24)&&t>=64&&t<=95;if(!(i||r))return!1;const n=e<=23?1:2;t>=64&&t<=95?s=n===1?Ru[e]:Iu[e]:s=n===1?bu[e]:Du[e];const o=this.channels[n];return o?(o.setPAC(this.interpretPAC(s,t)),this.currentChannel=n,!0):!1}interpretPAC(e,t){let s;const i={color:null,italics:!1,indent:null,underline:!1,row:e};return t>95?s=t-96:s=t-64,i.underline=(s&1)===1,s<=13?i.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(s/2)]:s<=15?(i.italics=!0,i.color="white"):i.indent=Math.floor((s-16)/2)*4,i}parseChars(e,t){let s,i=null,r=null;if(e>=25?(s=2,r=e-8):(s=1,r=e),r>=17&&r<=19){let n;r===17?n=t+80:r===18?n=t+112:n=t+144,this.logger.log(2,()=>"Special char '"+yo(n)+"' in channel "+s),i=[n]}else e>=32&&e<=127&&(i=t===0?[e]:[e,t]);return i&&this.logger.log(3,()=>"Char codes = "+_t(i).join(",")),i}parseBackgroundAttributes(e,t){const s=(e===16||e===24)&&t>=32&&t<=47,i=(e===23||e===31)&&t>=45&&t<=47;if(!(s||i))return!1;let r;const n={};e===16||e===24?(r=Math.floor((t-32)/2),n.background=Cu[r],t%2===1&&(n.background=n.background+"_semi")):t===45?n.background="transparent":(n.foreground="black",t===47&&(n.underline=!0));const o=e<=23?1:2;return this.channels[o].setBkgData(n),!0}reset(){for(let e=0;e<Object.keys(this.channels).length;e++){const t=this.channels[e];t&&t.reset()}Bs(null,null,this.cmdHistory)}cueSplitAtTime(e){for(let t=0;t<this.channels.length;t++){const s=this.channels[t];s&&s.cueSplitAtTime(e)}}}function Bs(a,e,t){t.a=a,t.b=e}function Pu(a,e,t){return t.a===a&&t.b===e}function Mu(){return{a:null,b:null}}class $s{constructor(e,t){this.timelineController=void 0,this.cueRanges=[],this.trackName=void 0,this.startTime=null,this.endTime=null,this.screen=null,this.timelineController=e,this.trackName=t}dispatchCue(){this.startTime!==null&&(this.timelineController.addCues(this.trackName,this.startTime,this.endTime,this.screen,this.cueRanges),this.startTime=null)}newCue(e,t,s){(this.startTime===null||this.startTime>e)&&(this.startTime=e),this.endTime=t,this.screen=s,this.timelineController.createCaptionsTrack(this.trackName)}reset(){this.cueRanges=[],this.startTime=null}}var _r=function(){if(Jt!=null&&Jt.VTTCue)return self.VTTCue;const a=["","lr","rl"],e=["start","middle","end","left","right"];function t(o,l){if(typeof l!="string"||!Array.isArray(o))return!1;const c=l.toLowerCase();return~o.indexOf(c)?c:!1}function s(o){return t(a,o)}function i(o){return t(e,o)}function r(o,...l){let c=1;for(;c<arguments.length;c++){const h=arguments[c];for(const u in h)o[u]=h[u]}return o}function n(o,l,c){const h=this,u={enumerable:!0};h.hasBeenReset=!1;let d="",f=!1,g=o,m=l,x=c,T=null,R="",v=!0,D="auto",L="start",_=50,k="middle",B=50,G="middle";Object.defineProperty(h,"id",r({},u,{get:function(){return d},set:function(P){d=""+P}})),Object.defineProperty(h,"pauseOnExit",r({},u,{get:function(){return f},set:function(P){f=!!P}})),Object.defineProperty(h,"startTime",r({},u,{get:function(){return g},set:function(P){if(typeof P!="number")throw new TypeError("Start time must be set to a number.");g=P,this.hasBeenReset=!0}})),Object.defineProperty(h,"endTime",r({},u,{get:function(){return m},set:function(P){if(typeof P!="number")throw new TypeError("End time must be set to a number.");m=P,this.hasBeenReset=!0}})),Object.defineProperty(h,"text",r({},u,{get:function(){return x},set:function(P){x=""+P,this.hasBeenReset=!0}})),Object.defineProperty(h,"region",r({},u,{get:function(){return T},set:function(P){T=P,this.hasBeenReset=!0}})),Object.defineProperty(h,"vertical",r({},u,{get:function(){return R}
vendor: 6,136 bytes, lines 30-36
30,set:function(P){const U=s(P);if(U===!1)throw new SyntaxError("An invalid or illegal string was specified.");R=U,this.hasBeenReset=!0}})),Object.defineProperty(h,"snapToLines",r({},u,{get:function(){return v},set:function(P){v=!!P,this.hasBeenReset=!0}})),Object.defineProperty(h,"line",r({},u,{get:function(){return D},set:function(P){if(typeof P!="number"&&P!=="auto")throw new SyntaxError("An invalid number or illegal string was specified.");D=P,this.hasBeenReset=!0}})),Object.defineProperty(h,"lineAlign",r({},u,{get:function(){return L},set:function(P){const U=i(P);if(!U)throw new SyntaxError("An invalid or illegal string was specified.");L=U,this.hasBeenReset=!0}})),Object.defineProperty(h,"position",r({},u,{get:function(){return _},set:function(P){if(P<0||P>100)throw new Error("Position must be between 0 and 100.");_=P,this.hasBeenReset=!0}})),Object.defineProperty(h,"positionAlign",r({},u,{get:function(){return k},set:function(P){const U=i(P);if(!U)throw new SyntaxError("An invalid or illegal string was specified.");k=U,this.hasBeenReset=!0}})),Object.defineProperty(h,"size",r({},u,{get:function(){return B},set:function(P){if(P<0||P>100)throw new Error("Size must be between 0 and 100.");B=P,this.hasBeenReset=!0}})),Object.defineProperty(h,"align",r({},u,{get:function(){return G},set:function(P){const U=i(P);if(!U)throw new SyntaxError("An invalid or illegal string was specified.");G=U,this.hasBeenReset=!0}})),h.displayState=void 0}return n.prototype.getCueAsHTML=function(){return self.WebVTT.convertCueToDOMTree(self,this.text)},n}();class Fu{decode(e,t){if(!e)return"";if(typeof e!="string")throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(e))}}function Eo(a){function e(s,i,r,n){return(s|0)*3600+(i|0)*60+(r|0)+parseFloat(n||0)}const t=a.match(/^(?:(\d+):)?(\d{2}):(\d{2})(\.\d+)?/);return t?parseFloat(t[2])>59?e(t[2],t[3],0,t[4]):e(t[1],t[2],t[3],t[4]):null}class Ou{constructor(){this.values=Object.create(null)}set(e,t){!this.get(e)&&t!==""&&(this.values[e]=t)}get(e,t,s){return s?this.has(e)?this.values[e]:t[s]:this.has(e)?this.values[e]:t}has(e){return e in this.values}alt(e,t,s){for(let i=0;i<s.length;++i)if(t===s[i]){this.set(e,t);break}}integer(e,t){/^-?\d+$/.test(t)&&this.set(e,parseInt(t,10))}percent(e,t){if(/^([\d]{1,3})(\.[\d]*)?%$/.test(t)){const s=parseFloat(t);if(s>=0&&s<=100)return this.set(e,s),!0}return!1}}function So(a,e,t,s){const i=s?a.split(s):[a];for(const r in i){if(typeof i[r]!="string")continue;const n=i[r].split(t);if(n.length!==2)continue;const o=n[0],l=n[1];e(o,l)}}const hr=new _r(0,0,""),Gs=hr.align==="middle"?"middle":"center";function Nu(a,e,t){const s=a;function i(){const o=Eo(a);if(o===null)throw new Error("Malformed timestamp: "+s);return a=a.replace(/^[^\sa-zA-Z-]+/,""),o}function r(o,l){const c=new Ou;So(o,function(d,f){let g;switch(d){case"region":for(let m=t.length-1;m>=0;m--)if(t[m].id===f){c.set(d,t[m].region);break}break;case"vertical":c.alt(d,f,["rl","lr"]);break;case"line":g=f.split(","),c.integer(d,g[0]),c.percent(d,g[0])&&c.set("snapToLines",!1),c.alt(d,g[0],["auto"]),g.length===2&&c.alt("lineAlign",g[1],["start",Gs,"end"]);break;case"position":g=f.split(","),c.percent(d,g[0]),g.length===2&&c.alt("positionAlign",g[1],["start",Gs,"end","line-left","line-right","auto"]);break;case"size":c.percent(d,f);break;case"align":c.alt(d,f,["start",Gs,"end","left","right"]);break}},/:/,/\s/),l.region=c.get("region",null),l.vertical=c.get("vertical","");let h=c.get("line","auto");h==="auto"&&hr.line===-1&&(h=-1),l.line=h,l.lineAlign=c.get("lineAlign","start"),l.snapToLines=c.get("snapToLines",!0),l.size=c.get("size",100),l.align=c.get("align",Gs);let u=c.get("position","auto");u==="auto"&&hr.position===50&&(u=l.align==="start"||l.align==="left"?0:l.align==="end"||l.align==="right"?100:50),l.position=u}function n(){a=a.replace(/^\s+/,"")}if(n(),e.startTime=i(),n(),a.slice(0,3)!=="-->")throw new Error("Malformed time stamp (time stamps must be separated by '-->'): "+s);a=a.slice(3),n(),e.endTime=i(),n(),r(a,e)}function vo(a){return a.replace(/<br(?: \/)?>/gi,` 31`)}class Uu{constructor(){this.state="INITIAL",this.buffer="",this.decoder=new Fu,this.regionList=[],this.cue=null,this.oncue=void 0,this.onparsingerror=void 0,this.onflush=void 0}parse(e){const t=this;e&&(t.buffer+=t.decoder.decode(e,{stream:!0}));function s(){let r=t.buffer,n=0;for(r=vo(r);n<r.length&&r[n]!=="\r"&&r[n]!==` 32`;)++n;const o=r.slice(0,n);return r[n]==="\r"&&++n,r[n]===` 33`&&++n,t.buffer=r.slice(n),o}function i(r){So(r,function(n,o){},/:/)}try{let r="";if(t.state==="INITIAL"){if(!/\r\n|\n/.test(t.buffer))return this;r=s();const o=r.match(/^()?WEBVTT([ \t].*)?$/);if(!(o!=null&&o[0]))throw new Error("Malformed WebVTT signature.");t.state="HEADER"}let n=!1;for(;t.buffer;){if(!/\r\n|\n/.test(t.buffer))return this;switch(n?n=!1:r=s(),t.state){case"HEADER":/:/.test(r)?i(r):r||(t.state="ID");continue;case"NOTE":r||(t.state="ID");continue;case"ID":if(/^NOTE($|[ \t])/.test(r)){t.state="NOTE";break}if(!r)continue;if(t.cue=new _r(0,0,""),t.state="CUE",r.indexOf("-->")===-1){t.cue.id=r;continue}case"CUE":if(!t.cue){t.state="BADCUE";continue}try{Nu(r,t.cue,t.regionList)}catch{t.cue=null,t.state="BADCUE";continue}t.state="CUETEXT";continue;case"CUETEXT":{const o=r.indexOf("-->")!==-1;if(!r||o&&(n=!0)){t.oncue&&t.cue&&t.oncue(t.cue),t.cue=null,t.state="ID";continue}if(t.cue===null)continue;t.cue.text&&(t.cue.text+=` 34`),t.cue.text+=r}continue;case"BADCUE":r||(t.state="ID")}}}catch{t.state==="CUETEXT"&&t.cue&&t.oncue&&t.oncue(t.cue),t.cue=null,t.state=t.state==="INITIAL"?"BADWEBVTT":"BADCUE"}return this}flush(){const e=this;try{if((e.cue||e.state==="HEADER")&&(e.buffer+=` 35 36`,e.parse()),e.state==="INITIAL"||e.state==="BADWEBVTT")throw new Error("Malformed WebVTT signature.")}catch(t){e.onparsingerror&&e.onparsingerror(t)}return e.onflush&&e.onflush(),this}}const Bu=/\r\n|\n\r|\n|\r/g,ji=function(e,t,s=0){return e.slice(s,s+t.length)===t},$u=function(e){let t=parseInt(e.slice(-3));const s=parseInt(e.slice(-6,-4)),i=parseInt(e.slice(-9,-7)),r=e.length>9?parseInt(e.substring(0,e.indexOf(":"))):0;
vendor: 31,131 bytes, lines 36-41
36if(!j(t)||!j(s)||!j(i)||!j(r))throw Error(`Malformed X-TIMESTAMP-MAP: Local:${e}`);return t+=1e3*s,t+=60*1e3*i,t+=60*60*1e3*r,t},Wi=function(e){let t=5381,s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return(t>>>0).toString()};function Pr(a,e,t){return Wi(a.toString())+Wi(e.toString())+Wi(t)}const Gu=function(e,t,s){let i=e[t],r=e[i.prevCC];if(!r||!r.new&&i.new){e.ccOffset=e.presentationOffset=i.start,i.new=!1;return}for(;(n=r)!=null&&n.new;){var n;e.ccOffset+=i.start-r.start,i.new=!1,i=r,r=e[i.prevCC]}e.presentationOffset=s};function Ku(a,e,t,s,i,r,n){const o=new Uu,l=dt(new Uint8Array(a)).trim().replace(Bu,` 37`).split(` 38`),c=[],h=e?nu(e.baseTime,e.timescale):0;let u="00:00.000",d=0,f=0,g,m=!0;o.oncue=function(x){const T=t[s];let R=t.ccOffset;const v=(d-h)/9e4;if(T!=null&&T.new&&(f!==void 0?R=t.ccOffset=T.start:Gu(t,s,v)),v){if(!e){g=new Error("Missing initPTS for VTT MPEGTS");return}R=v-t.presentationOffset}const D=x.endTime-x.startTime,L=Je((x.startTime+R-f)*9e4,i*9e4)/9e4;x.startTime=Math.max(L,0),x.endTime=Math.max(L+D,0);const _=x.text.trim();x.text=decodeURIComponent(encodeURIComponent(_)),x.id||(x.id=Pr(x.startTime,x.endTime,_)),x.endTime>0&&c.push(x)},o.onparsingerror=function(x){g=x},o.onflush=function(){if(g){n(g);return}r(c)},l.forEach(x=>{if(m)if(ji(x,"X-TIMESTAMP-MAP=")){m=!1,x.slice(16).split(",").forEach(T=>{ji(T,"LOCAL:")?u=T.slice(6):ji(T,"MPEGTS:")&&(d=parseInt(T.slice(7)))});try{f=$u(u)/1e3}catch(T){g=T}return}else x===""&&(m=!1);o.parse(x+` 39`)}),o.flush()}const Yi="stpp.ttml.im1t",Ao=/^(\d{2,}):(\d{2}):(\d{2}):(\d{2})\.?(\d+)?$/,Lo=/^(\d*(?:\.\d*)?)(h|m|s|ms|f|t)$/,Hu={left:"start",center:"center",right:"end",start:"start",end:"end"};function ma(a,e,t,s){const i=ne(new Uint8Array(a),["mdat"]);if(i.length===0){s(new Error("Could not parse IMSC1 mdat"));return}const r=i.map(o=>dt(o)),n=ru(e.baseTime,1,e.timescale);try{r.forEach(o=>t(Vu(o,n)))}catch(o){s(o)}}function Vu(a,e){const i=new DOMParser().parseFromString(a,"text/xml").getElementsByTagName("tt")[0];if(!i)throw new Error("Invalid ttml");const r={frameRate:30,subFrameRate:1,frameRateMultiplier:0,tickRate:0},n=Object.keys(r).reduce((u,d)=>(u[d]=i.getAttribute(`ttp:${d}`)||r[d],u),{}),o=i.getAttribute("xml:space")!=="preserve",l=pa(qi(i,"styling","style")),c=pa(qi(i,"layout","region")),h=qi(i,"body","[begin]");return[].map.call(h,u=>{const d=Ro(u,o);if(!d||!u.hasAttribute("begin"))return null;const f=Xi(u.getAttribute("begin"),n),g=Xi(u.getAttribute("dur"),n);let m=Xi(u.getAttribute("end"),n);if(f===null)throw xa(u);if(m===null){if(g===null)throw xa(u);m=f+g}const x=new _r(f-e,m-e,d);x.id=Pr(x.startTime,x.endTime,x.text);const T=c[u.getAttribute("region")],R=l[u.getAttribute("style")],v=ju(T,R,l),{textAlign:D}=v;if(D){const L=Hu[D];L&&(x.lineAlign=L),x.align=D}return we(x,v),x}).filter(u=>u!==null)}function qi(a,e,t){const s=a.getElementsByTagName(e)[0];return s?[].slice.call(s.querySelectorAll(t)):[]}function pa(a){return a.reduce((e,t)=>{const s=t.getAttribute("xml:id");return s&&(e[s]=t),e},{})}function Ro(a,e){return[].slice.call(a.childNodes).reduce((t,s,i)=>{var r;return s.nodeName==="br"&&i?t+` 40`:(r=s.childNodes)!=null&&r.length?Ro(s,e):e?t+s.textContent.trim().replace(/\s+/g," "):t+s.textContent},"")}function ju(a,e,t){const s="http://www.w3.org/ns/ttml#styling";let i=null;const r=["displayAlign","textAlign","color","backgroundColor","fontSize","fontFamily"],n=a!=null&&a.hasAttribute("style")?a.getAttribute("style"):null;return n&&t.hasOwnProperty(n)&&(i=t[n]),r.reduce((o,l)=>{const c=zi(e,s,l)||zi(a,s,l)||zi(i,s,l);return c&&(o[l]=c),o},{})}function zi(a,e,t){return a&&a.hasAttributeNS(e,t)?a.getAttributeNS(e,t):null}function xa(a){return new Error(`Could not parse ttml timestamp ${a}`)}function Xi(a,e){if(!a)return null;let t=Eo(a);return t===null&&(Ao.test(a)?t=Wu(a,e):Lo.test(a)&&(t=Yu(a,e))),t}function Wu(a,e){const t=Ao.exec(a),s=(t[4]|0)+(t[5]|0)/e.subFrameRate;return(t[1]|0)*3600+(t[2]|0)*60+(t[3]|0)+s/e.frameRate}function Yu(a,e){const t=Lo.exec(a),s=Number(t[1]);switch(t[2]){case"h":return s*3600;case"m":return s*60;case"ms":return s*1e3;case"f":return s/e.frameRate;case"t":return s/e.tickRate}return s}class qu{constructor(e){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=Ta(),this.captionsProperties=void 0,this.hls=e,this.config=e.config,this.Cues=e.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}},e.on(p.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(p.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.on(p.FRAG_LOADING,this.onFragLoading,this),e.on(p.FRAG_LOADED,this.onFragLoaded,this),e.on(p.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),e.on(p.FRAG_DECRYPTED,this.onFragDecrypted,this),e.on(p.INIT_PTS_FOUND,this.onInitPtsFound,this),e.on(p.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),e.on(p.BUFFER_FLUSHING,this.onBufferFlushing,this)}destroy(){const{hls:e}=this;e.off(p.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(p.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.off(p.FRAG_LOADING,this.onFragLoading,this),e.off(p.FRAG_LOADED,this.onFragLoaded,this),e.off(p.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),e.off(p.FRAG_DECRYPTED,this.onFragDecrypted,this),e.off(p.INIT_PTS_FOUND,this.onInitPtsFound,this),e.off(p.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),e.off(p.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=null,this.cea608Parser1=this.cea608Parser2=void 0}initCea608Parsers(){if(this.config.enableCEA708Captions&&(!this.cea608Parser1||!this.cea608Parser2)){const e=new $s(this,"textTrack1"),t=new $s(this,"textTrack2"),s=new $s(this,"textTrack3"),i=new $s(this,"textTrack4");this.cea608Parser1=new ga(1,e,t),this.cea608Parser2=new ga(3,s,i)}}addCues(e,t,s,i,r){let n=!1;for(let o=r.length;o--;){const l=r[o],c=zu(l[0],l[1],t,s);if(c>=0&&(l[0]=Math.min(l[0],t),l[1]=Math.max(l[1],s),n=!0,c/(s-t)>.5))return}if(n||r.push([t,s]),this.config.renderTextTracksNatively){const o=this.captionsTracks[e];this.Cues.newCue(o,t,s,i)}else{const o=this.Cues.newCue(null,t,s,i);this.hls.trigger(p.CUES_PARSED,{type:"captions",cues:o,track:e})}}onInitPtsFound(e,{frag:t,id:s,initPTS:i,timescale:r}){const{unparsedVttFrags:n}=this;s==="main"&&(this.initPTS[t.cc]={baseTime:i,timescale:r}),n.length&&(this.unparsedVttFrags=[],n.forEach(o=>{this.onFragLoaded(p.FRAG_LOADED,o)}))}getExistingTrack(e,t){const{media:s}=this;if(s)for(let i=0;i<s.textTracks.length;i++){const r=s.textTracks[i];if(ya(r,{name:e,lang:t,attrs:{}}))return r}return null}createCaptionsTrack(e){this.config.renderTextTracksNatively?this.createNativeTrack(e):this.createNonNativeTrack(e)}createNativeTrack(e){if(this.captionsTracks[e])return;const{captionsProperties:t,captionsTracks:s,media:i}=this,{label:r,languageCode:n}=t[e],o=this.getExistingTrack(r,n);if(o)s[e]=o,zt(s[e]),Va(s[e],i);else{const l=this.createTextTrack("captions",r,n);l&&(l[e]=!0,s[e]=l)}}createNonNativeTrack(e){if(this.nonNativeCaptionsTracks[e])return;const t=this.captionsProperties[e];if(!t)return;const s=t.label,i={_id:e,label:s,kind:"captions",default:t.media?!!t.media.default:!1,closedCaptions:t.media};this.nonNativeCaptionsTracks[e]=i,this.hls.trigger(p.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:[i]})}createTextTrack(e,t,s){const i=this.media;if(i)return i.addTextTrack(e,t,s)}onMediaAttaching(e,t){this.media=t.media,this._cleanTracks()}onMediaDetaching(){const{captionsTracks:e}=this;Object.keys(e).forEach(t=>{zt(e[t]),delete e[t]}),this.nonNativeCaptionsTracks={}}onManifestLoading(){this.lastCc=-1,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs=Ta(),this._cleanTracks(),this.tracks=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.textTracks=[],this.unparsedVttFrags=[],this.initPTS=[],this.cea608Parser1&&this.cea608Parser2&&(this.cea608Parser1.reset(),this.cea608Parser2.reset())}_cleanTracks(){const{media:e}=this;if(!e)return;const t=e.textTracks;if(t)for(let s=0;s<t.length;s++)zt(t[s])}onSubtitleTracksUpdated(e,t){const s=t.subtitleTracks||[],i=s.some(r=>r.textCodec===Yi);if(this.config.enableWebVTT||i&&this.config.enableIMSC1){if(xo(this.tracks,s)){this.tracks=s;return}if(this.textTracks=[],this.tracks=s,this.config.renderTextTracksNatively){const n=this.media,o=n?Vs(n.textTracks):null;if(this.tracks.forEach((l,c)=>{let h;if(o){let u=null;for(let d=0;d<o.length;d++)if(o[d]&&ya(o[d],l)){u=o[d],o[d]=null;break}u&&(h=u)}if(h)zt(h);else{const u=bo(l);h=this.createTextTrack(u,l.name,l.lang),h&&(h.mode="disabled")}h&&this.textTracks.push(h)}),o!=null&&o.length){const l=o.filter(c=>c!==null).map(c=>c.label);l.length&&b.warn(`Media element contains unused subtitle tracks: ${l.join(", ")}. Replace media element for each source to clear TextTracks and captions menu.`)}}else if(this.tracks.length){const n=this.tracks.map(o=>({label:o.name,kind:o.type.toLowerCase(),default:o.default,subtitleTrack:o}));this.hls.trigger(p.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:n})}}}onManifestLoaded(e,t){this.config.enableCEA708Captions&&t.captions&&t.captions.forEach(s=>{const i=/(?:CC|SERVICE)([1-4])/.exec(s.instreamId);if(!i)return;const r=`textTrack${i[1]}`,n=this.captionsProperties[r];n&&(n.label=s.name,s.lang&&(n.languageCode=s.lang),n.media=s)})}closedCaptionsForLevel(e){const t=this.hls.levels[e.level];return t==null?void 0:t.attrs["CLOSED-CAPTIONS"]}onFragLoading(e,t){if(this.enabled&&t.frag.type===Q.MAIN){var s,i;const{cea608Parser1:r,cea608Parser2:n,lastSn:o}=this,{cc:l,sn:c}=t.frag,h=(s=(i=t.part)==null?void 0:i.index)!=null?s:-1;r&&n&&(c!==o+1||c===o&&h!==this.lastPartIndex+1||l!==this.lastCc)&&(r.reset(),n.reset()),this.lastCc=l,this.lastSn=c,this.lastPartIndex=h}}onFragLoaded(e,t){const{frag:s,payload:i}=t;if(s.type===Q.SUBTITLE)if(i.byteLength){const r=s.decryptdata,n="stats"in t;if(r==null||!r.encrypted||n){const o=this.tracks[s.level],l=this.vttCCs;l[s.cc]||(l[s.cc]={start:s.start,prevCC:this.prevCC,new:!0},this.prevCC=s.cc),o&&o.textCodec===Yi?this._parseIMSC1(s,i):this._parseVTTs(t)}}else this.hls.trigger(p.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:s,error:new Error("Empty subtitle payload")})}_parseIMSC1(e,t){const s=this.hls;ma(t,this.initPTS[e.cc],i=>{this._appendCues(i,e.level),s.trigger(p.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:e})},i=>{b.log(`Failed to parse IMSC1: ${i}`),s.trigger(p.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:e,error:i})})}_parseVTTs(e){var t;const{frag:s,payload:i}=e,{initPTS:r,unparsedVttFrags:n}=this,o=r.length-1;if(!r[s.cc]&&o===-1){n.push(e);return}const l=this.hls,c=(t=s.initSegment)!=null&&t.data?Ze(s.initSegment.data,new Uint8Array(i)):i;Ku(c,this.initPTS[s.cc],this.vttCCs,s.cc,s.start,h=>{this._appendCues(h,s.level),l.trigger(p.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:s})},h=>{const u=h.message==="Missing initPTS for VTT MPEGTS";u?n.push(e):this._fallbackToIMSC1(s,i),b.log(`Failed to parse VTT cue: ${h}`),!(u&&o>s.cc)&&l.trigger(p.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:s,error:h})})}_fallbackToIMSC1(e,t){const s=this.tracks[e.level];s.textCodec||ma(t,this.initPTS[e.cc],()=>{s.textCodec=Yi,this._parseIMSC1(e,t)},()=>{s.textCodec="wvtt"})}_appendCues(e,t){const s=this.hls;if(this.config.renderTextTracksNatively){const i=this.textTracks[t];if(!i||i.mode==="disabled")return;e.forEach(r=>ja(i,r))}else{const i=this.tracks[t];if(!i)return;const r=i.default?"default":"subtitles"+t;s.trigger(p.CUES_PARSED,{type:"subtitles",cues:e,track:r})}}onFragDecrypted(e,t){const{frag:s}=t;s.type===Q.SUBTITLE&&this.onFragLoaded(p.FRAG_LOADED,t)}onSubtitleTracksCleared(){this.tracks=[],this.captionsTracks={}}onFragParsingUserdata(e,t){this.initCea608Parsers();const{cea608Parser1:s,cea608Parser2:i}=this;if(!this.enabled||!s||!i)return;const{frag:r,samples:n}=t;if(!(r.type===Q.MAIN&&this.closedCaptionsForLevel(r)==="NONE"))for(let o=0;o<n.length;o++){const l=n[o].bytes;if(l){const c=this.extractCea608Data(l);s.addData(n[o].pts,c[0]),i.addData(n[o].pts,c[1])}}}onBufferFlushing(e,{startOffset:t,endOffset:s,endOffsetSubtitles:i,type:r}){const{media:n}=this;if(!(!n||n.currentTime<s)){if(!r||r==="video"){const{captionsTracks:o}=this;Object.keys(o).forEach(l=>ir(o[l],t,s))}if(this.config.renderTextTracksNatively&&t===0&&i!==void 0){const{textTracks:o}=this;Object.keys(o).forEach(l=>ir(o[l],t,i))}}}extractCea608Data(e){const t=[[],[]],s=e[0]&31;let i=2;for(let r=0;r<s;r++){const n=e[i++],o=127&e[i++],l=127&e[i++];if(o===0&&l===0)continue;if((4&n)!==0){const h=3&n;(h===0||h===1)&&(t[h].push(o),t[h].push(l))}}return t}}function bo(a){return a.characteristics&&/transcribes-spoken-dialog/gi.test(a.characteristics)&&/describes-music-and-sound/gi.test(a.characteristics)?"captions":"subtitles"}function ya(a,e){return!!a&&a.kind===bo(e)&&cr(e,a)}function zu(a,e,t,s){return Math.min(e,s)-Math.max(a,t)}function Ta(){return{ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}}}class Mr{constructor(e){this.hls=void 0,this.autoLevelCapping=void 0,this.firstLevel=void 0,this.media=void 0,this.restrictedLevels=void 0,this.timer=void 0,this.clientRect=void 0,this.streamController=void 0,this.hls=e,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.firstLevel=-1,this.media=null,this.restrictedLevels=[],this.timer=void 0,this.clientRect=null,this.registerListeners()}setStreamController(e){this.streamController=e}destroy(){this.hls&&this.unregisterListener(),this.timer&&this.stopCapping(),this.media=null,this.clientRect=null,this.hls=this.streamController=null}registerListeners(){const{hls:e}=this;e.on(p.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.on(p.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(p.MANIFEST_PARSED,this.onManifestParsed,this),e.on(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(p.BUFFER_CODECS,this.onBufferCodecs,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this)}unregisterListener(){const{hls:e}=this;e.off(p.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.off(p.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(p.MANIFEST_PARSED,this.onManifestParsed,this),e.off(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(p.BUFFER_CODECS,this.onBufferCodecs,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this)}onFpsDropLevelCapping(e,t){const s=this.hls.levels[t.droppedLevel];this.isLevelAllowed(s)&&this.restrictedLevels.push({bitrate:s.bitrate,height:s.height,width:s.width})}onMediaAttaching(e,t){this.media=t.media instanceof HTMLVideoElement?t.media:null,this.clientRect=null,this.timer&&this.hls.levels.length&&this.detectPlayerSize()}onManifestParsed(e,t){const s=this.hls;this.restrictedLevels=[],this.firstLevel=t.firstLevel,s.config.capLevelToPlayerSize&&t.video&&this.startCapping()}onLevelsUpdated(e,t){this.timer&&j(this.autoLevelCapping)&&this.detectPlayerSize()}onBufferCodecs(e,t){this.hls.config.capLevelToPlayerSize&&t.video&&this.startCapping()}onMediaDetaching(){this.stopCapping()}detectPlayerSize(){if(this.media){if(this.mediaHeight<=0||this.mediaWidth<=0){this.clientRect=null;return}const e=this.hls.levels;if(e.length){const t=this.hls,s=this.getMaxLevel(e.length-1);s!==this.autoLevelCapping&&b.log(`Setting autoLevelCapping to ${s}: ${e[s].height}p@${e[s].bitrate} for media ${this.mediaWidth}x${this.mediaHeight}`),t.autoLevelCapping=s,t.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=t.autoLevelCapping}}}getMaxLevel(e){const t=this.hls.levels;if(!t.length)return-1;const s=t.filter((i,r)=>this.isLevelAllowed(i)&&r<=e);return this.clientRect=null,Mr.getMaxLevelByMediaSize(s,this.mediaWidth,this.mediaHeight)}startCapping(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())}stopCapping(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)}getDimensions(){if(this.clientRect)return this.clientRect;const e=this.media,t={width:0,height:0};if(e){const s=e.getBoundingClientRect();t.width=s.width,t.height=s.height,!t.width&&!t.height&&(t.width=s.right-s.left||e.width||0,t.height=s.bottom-s.top||e.height||0)}return this.clientRect=t,t}get mediaWidth(){return this.getDimensions().width*this.contentScaleFactor}get mediaHeight(){return this.getDimensions().height*this.contentScaleFactor}get contentScaleFactor(){let e=1;if(!this.hls.config.ignoreDevicePixelRatio)try{e=self.devicePixelRatio}catch{}return e}isLevelAllowed(e){return!this.restrictedLevels.some(s=>e.bitrate===s.bitrate&&e.width===s.width&&e.height===s.height)}static getMaxLevelByMediaSize(e,t,s){if(!(e!=null&&e.length))return-1;const i=(o,l)=>l?o.width!==l.width||o.height!==l.height:!0;let r=e.length-1;const n=Math.max(t,s);for(let o=0;o<e.length;o+=1){const l=e[o];if((l.width>=n||l.height>=n)&&i(l,e[o+1])){r=o;break}}return r}}class Xu{constructor(e){this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=e,this.registerListeners()}setStreamController(e){this.streamController=e}registerListeners(){this.hls.on(p.MEDIA_ATTACHING,this.onMediaAttaching,this)}unregisterListeners(){this.hls.off(p.MEDIA_ATTACHING,this.onMediaAttaching,this)}destroy(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null}onMediaAttaching(e,t){const s=this.hls.config;if(s.capLevelOnFPSDrop){const i=t.media instanceof self.HTMLVideoElement?t.media:null;this.media=i,i&&typeof i.getVideoPlaybackQuality=="function"&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),s.fpsDroppedMonitoringPeriod)}}checkFPS(e,t,s){const i=performance.now();if(t){if(this.lastTime){const r=i-this.lastTime,n=s-this.lastDroppedFrames,o=t-this.lastDecodedFrames,l=1e3*n/r,c=this.hls;if(c.trigger(p.FPS_DROP,{currentDropped:n,currentDecoded:o,totalDroppedFrames:s}),l>0&&n>c.config.fpsDroppedMonitoringThreshold*o){let h=c.currentLevel;b.warn("drop FPS ratio greater than max allowed value for currentLevel: "+h),h>0&&(c.autoLevelCapping===-1||c.autoLevelCapping>=h)&&(h=h-1,c.trigger(p.FPS_DROP_LEVEL_CAPPING,{level:h,droppedLevel:c.currentLevel}),c.autoLevelCapping=h,this.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=s,this.lastDecodedFrames=t}}checkFPSInterval(){const e=this.media;if(e)if(this.isVideoPlaybackQualityAvailable){const t=e.getVideoPlaybackQuality();this.checkFPS(e,t.totalVideoFrames,t.droppedVideoFrames)}else this.checkFPS(e,e.webkitDecodedFrameCount,e.webkitDroppedFrameCount)}}const Ks="[eme]";class Qt{constructor(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=Qt.CDMCleanupPromise?[Qt.CDMCleanupPromise]:[],this.onMediaEncrypted=this._onMediaEncrypted.bind(this),this.onWaitingForKey=this._onWaitingForKey.bind(this),this.debug=b.debug.bind(b,Ks),this.log=b.log.bind(b,Ks),this.warn=b.warn.bind(b,Ks),this.error=b.error.bind(b,Ks),this.hls=e,this.config=e.config,this.registerListeners()}destroy(){this.unregisterListeners(),this.onMediaDetached();const e=this.config;e.requestMediaKeySystemAccessFunc=null,e.licenseXhrSetup=e.licenseResponseCallback=void 0,e.drmSystems=e.drmSystemOptions={},this.hls=this.onMediaEncrypted=this.onWaitingForKey=this.keyIdToKeySessionPromise=null,this.config=null}registerListeners(){this.hls.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(p.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.on(p.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(p.MANIFEST_LOADED,this.onManifestLoaded,this)}unregisterListeners(){this.hls.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(p.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.off(p.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(p.MANIFEST_LOADED,this.onManifestLoaded,this)}getLicenseServerUrl(e){const{drmSystems:t,widevineLicenseUrl:s}=this.config,i=t[e];if(i)return i.licenseUrl;if(e===Se.WIDEVINE&&s)return s;throw new Error(`no license server URL configured for key-system "${e}"`)}getServerCertificateUrl(e){const{drmSystems:t}=this.config,s=t[e];if(s)return s.serverCertificateUrl;this.log(`No Server Certificate in config.drmSystems["${e}"]`)}attemptKeySystemAccess(e){const t=this.hls.levels,s=(n,o,l)=>!!n&&l.indexOf(n)===o,i=t.map(n=>n.audioCodec).filter(s),r=t.map(n=>n.videoCodec).filter(s);return i.length+r.length===0&&r.push("avc1.42e01e"),new Promise((n,o)=>{const l=c=>{const h=c.shift();this.getMediaKeysPromise(h,i,r).then(u=>n({keySystem:h,mediaKeys:u})).catch(u=>{c.length?l(c):u instanceof Qe?o(u):o(new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_NO_ACCESS,error:u,fatal:!0},u.message))})};l(e)})}requestMediaKeySystemAccess(e,t){const{requestMediaKeySystemAccessFunc:s}=this.config;if(typeof s!="function"){let i=`Configured requestMediaKeySystemAccess is not a function ${s}`;return ka===null&&self.location.protocol==="http:"&&(i=`navigator.requestMediaKeySystemAccess is not available over insecure protocol ${location.protocol}`),Promise.reject(new Error(i))}return s(e,t)}getMediaKeysPromise(e,t,s){const i=sc(e,t,s,this.config.drmSystemOptions),r=this.keySystemAccessPromises[e];let n=r==null?void 0:r.keySystemAccess;if(!n){this.log(`Requesting encrypted media "${e}" key-system access with config: ${JSON.stringify(i)}`),n=this.requestMediaKeySystemAccess(e,i);const o=this.keySystemAccessPromises[e]={keySystemAccess:n};return n.catch(l=>{this.log(`Failed to obtain access to key-system "${e}": ${l}`)}),n.then(l=>{this.log(`Access for key-system "${l.keySystem}" obtained`);const c=this.fetchServerCertificate(e);return this.log(`Create media-keys for "${e}"`),o.mediaKeys=l.createMediaKeys().then(h=>(this.log(`Media-keys created for "${e}"`),c.then(u=>u?this.setMediaKeysServerCertificate(h,e,u):h))),o.mediaKeys.catch(h=>{this.error(`Failed to create media-keys for "${e}"}: ${h}`)}),o.mediaKeys})}return n.then(()=>r.mediaKeys)}createMediaKeySessionContext({decryptdata:e,keySystem:t,mediaKeys:s}){this.log(`Creating key-system session "${t}" keyId: ${ot.hexDump(e.keyId||[])}`);const i=s.createSession(),r={decryptdata:e,keySystem:t,mediaKeys:s,mediaKeysSession:i,keyStatus:"status-pending"};return this.mediaKeySessions.push(r),r}renewKeySession(e){const t=e.decryptdata;if(t.pssh){const s=this.createMediaKeySessionContext(e),i=this.getKeyIdString(t),r="cenc";this.keyIdToKeySessionPromise[i]=this.generateRequestWithPreferredKeySession(s,r,t.pssh,"expired")}else this.warn("Could not renew expired session. Missing pssh initData.");this.removeSession(e)}getKeyIdString(e){if(!e)throw new Error("Could not read keyId of undefined decryptdata");if(e.keyId===null)throw new Error("keyId is null");return ot.hexDump(e.keyId)}updateKeySession(e,t){var s;const i=e.mediaKeysSession;return this.log(`Updating key-session "${i.sessionId}" for keyID ${ot.hexDump(((s=e.decryptdata)==null?void 0:s.keyId)||[])} 41 } (data length: ${t&&t.byteLength})`),i.update(t)}selectKeySystemFormat(e){const t=Object.keys(e.levelkeys||{});return this.keyFormatPromise||(this.log(`Selecting key-system from fragment (sn: ${e.sn} ${e.type}: ${e.level}) key formats ${t.join(", ")}`),this.keyFormatPromise=this.getKeyFormatPromise(t)),this.keyFormatPromise}getKeyFormatPromise(e){return new Promise((t,s)=>{const i=_i(this.config),r=e.map(Rn).filter(n=>!!n&&i.indexOf(n)!==-1);return this.getKeySystemSelectionPromise(r).then(({keySystem:n})=>{const o=In(n);o?t(o):s(new Error(`Unable to find format for key-system "${n}"`))}).catch(s)})}loadKey(e){const t=e.keyInfo.decryptdata,s=this.getKeyIdString(t),i=`(keyId: ${s} format: "${t.keyFormat}" method: ${t.method} uri: ${t.uri})`;this.log(`Starting session for key ${i}`);let r=this.keyIdToKeySessionPromise[s];return r||(r=this.keyIdToKeySessionPromise[s]=this.getKeySystemForKeyPromise(t).then(({keySystem:n,mediaKeys:o})=>(this.throwIfDestroyed(),this.log(`Handle encrypted media sn: ${e.frag.sn} ${e.frag.type}: ${e.frag.level} using key ${i}`),this.attemptSetMediaKeys(n,o).then(()=>{this.throwIfDestroyed();const l=this.createMediaKeySessionContext({keySystem:n,mediaKeys:o,decryptdata:t});return this.generateRequestWithPreferredKeySession(l,"cenc",t.pssh,"playlist-key")}))),r.catch(n=>this.handleError(n))),r}throwIfDestroyed(e="Invalid state"){if(!this.hls)throw new Error("invalid state")}handleError(e){this.hls&&(this.error(e.message),e instanceof Qe?this.hls.trigger(p.ERROR,e.data):this.hls.trigger(p.ERROR,{type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_NO_KEYS,error:e,fatal:!0}))}getKeySystemForKeyPromise(e){const t=this.getKeyIdString(e),s=this.keyIdToKeySessionPromise[t];if(!s){const i=Rn(e.keyFormat),r=i?[i]:_i(this.config);return this.attemptKeySystemAccess(r)}return s}getKeySystemSelectionPromise(e){if(e.length||(e=_i(this.config)),e.length===0)throw new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_NO_CONFIGURED_LICENSE,fatal:!0},`Missing key-system license configuration options ${JSON.stringify({drmSystems:this.config.drmSystems})}`);return this.attemptKeySystemAccess(e)}_onMediaEncrypted(e){const{initDataType:t,initData:s}=e,i=`"${e.type}" event: init data type: "${t}"`;if(this.debug(i),s===null)return;let r,n;if(t==="sinf"&&this.config.drmSystems[Se.FAIRPLAY]){const u=_e(new Uint8Array(s));try{const d=Tr(JSON.parse(u).sinf),f=Ba(new Uint8Array(d));if(!f)throw new Error("'schm' box missing or not cbcs/cenc with schi > tenc");r=f.subarray(8,24),n=Se.FAIRPLAY}catch(d){this.warn(`${i} Failed to parse sinf: ${d}`);return}}else{const u=Ic(s),d=u.filter(f=>f.systemId===ps.WIDEVINE)[0];if(!d){u.length===0||u.some(f=>!f.systemId)?this.warn(`${i} contains incomplete or invalid pssh data`):this.log(`ignoring ${i} for ${u.map(f=>bn(f.systemId)).join(",")} pssh data in favor of playlist keys`);return}if(n=bn(d.systemId),d.version===0&&d.data){const f=d.data.length-22;r=d.data.subarray(f,f+16)}}if(!n||!r)return;const o=ot.hexDump(r),{keyIdToKeySessionPromise:l,mediaKeySessions:c}=this;let h=l[o];for(let u=0;u<c.length;u++){const d=c[u],f=d.decryptdata;if(!f.keyId)continue;const g=ot.hexDump(f.keyId);if(o===g||f.uri.replace(/-/g,"").indexOf(o)!==-1){if(h=l[g],f.pssh)break;delete l[g],f.pssh=new Uint8Array(s),f.keyId=r,h=l[o]=h.then(()=>this.generateRequestWithPreferredKeySession(d,t,s,"encrypted-event-key-match"));break}}h||(h=l[o]=this.getKeySystemSelectionPromise([n]).then(({keySystem:u,mediaKeys:d})=>{var f;this.throwIfDestroyed();const g=new Ts("ISO-23001-7",o,(f=In(u))!=null?f:"");return g.pssh=new Uint8Array(s),g.keyId=r,this.attemptSetMediaKeys(u,d).then(()=>{this.throwIfDestroyed();const m=this.createMediaKeySessionContext({decryptdata:g,keySystem:u,mediaKeys:d});return this.generateRequestWithPreferredKeySession(m,t,s,"encrypted-event-no-match")})})),h.catch(u=>this.handleError(u))}_onWaitingForKey(e){this.log(`"${e.type}" event`)}attemptSetMediaKeys(e,t){const s=this.setMediaKeysQueue.slice();this.log(`Setting media-keys for "${e}"`);const i=Promise.all(s).then(()=>{if(!this.media)throw new Error("Attempted to set mediaKeys without media element attached");return this.media.setMediaKeys(t)});return this.setMediaKeysQueue.push(i),i.then(()=>{this.log(`Media-keys set for "${e}"`),s.push(i),this.setMediaKeysQueue=this.setMediaKeysQueue.filter(r=>s.indexOf(r)===-1)})}generateRequestWithPreferredKeySession(e,t,s,i){var r,n;const o=(r=this.config.drmSystems)==null||(n=r[e.keySystem])==null?void 0:n.generateRequest;if(o)try{const g=o.call(this.hls,t,s,e);if(!g)throw new Error("Invalid response from configured generateRequest filter");t=g.initDataType,s=e.decryptdata.pssh=g.initData?new Uint8Array(g.initData):null}catch(g){var l;if(this.warn(g.message),(l=this.hls)!=null&&l.config.debug)throw g}if(s===null)return this.log(`Skipping key-session request for "${i}" (no initData)`),Promise.resolve(e);const c=this.getKeyIdString(e.decryptdata);this.log(`Generating key-session request for "${i}": ${c} (init data type: ${t} length: ${s?s.byteLength:null})`);const h=new kr,u=e._onmessage=g=>{const m=e.mediaKeysSession;if(!m){h.emit("error",new Error("invalid state"));return}const{messageType:x,message:T}=g;this.log(`"${x}" message event for session "${m.sessionId}" message size: ${T.byteLength}`),x==="license-request"||x==="license-renewal"?this.renewLicense(e,T).catch(R=>{this.handleError(R),h.emit("error",R)}):x==="license-release"?e.keySystem===Se.FAIRPLAY&&(this.updateKeySession(e,tr("acknowledged")),this.removeSession(e)):this.warn(`unhandled media key message type "${x}"`)},d=e._onkeystatuseschange=g=>{if(!e.mediaKeysSession){h.emit("error",new Error("invalid state"));return}this.onKeyStatusChange(e);const x=e.keyStatus;h.emit("keyStatus",x),x==="expired"&&(this.warn(`${e.keySystem} expired for key ${c}`),this.renewKeySession(e))};e.mediaKeysSession.addEventListener("message",u),e.mediaKeysSession.addEventListener("keystatuseschange",d);const f=new Promise((g,m)=>{h.on("error",m),h.on("keyStatus",x=>{x.startsWith("usable")?g():x==="output-restricted"?m(new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED,fatal:!1},"HDCP level output restricted")):x==="internal-error"?m(new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_STATUS_INTERNAL_ERROR,fatal:!0},`key status changed to "${x}"`)):x==="expired"?m(new Error("key expired while generating request")):this.warn(`unhandled key status change "${x}"`)})});return e.mediaKeysSession.generateRequest(t,s).then(()=>{var g;this.log(`Request generated for key-session "${(g=e.mediaKeysSession)==null?void 0:g.sessionId}" keyId: ${c}`)}).catch(g=>{throw new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_NO_SESSION,error:g,fatal:!1},`Error generating key-session request: ${g}`)}).then(()=>f).catch(g=>{throw h.removeAllListeners(),this.removeSession(e),g}).then(()=>(h.removeAllListeners(),e))}
vendor: 4,987 bytes, line 41
41onKeyStatusChange(e){e.mediaKeysSession.keyStatuses.forEach((t,s)=>{this.log(`key status change "${t}" for keyStatuses keyId: ${ot.hexDump("buffer"in s?new Uint8Array(s.buffer,s.byteOffset,s.byteLength):new Uint8Array(s))} session keyId: ${ot.hexDump(new Uint8Array(e.decryptdata.keyId||[]))} uri: ${e.decryptdata.uri}`),e.keyStatus=t})}fetchServerCertificate(e){const t=this.config,s=t.loader,i=new s(t),r=this.getServerCertificateUrl(e);return r?(this.log(`Fetching server certificate for "${e}"`),new Promise((n,o)=>{const l={responseType:"arraybuffer",url:r},c=t.certLoadPolicy.default,h={loadPolicy:c,timeout:c.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},u={onSuccess:(d,f,g,m)=>{n(d.data)},onError:(d,f,g,m)=>{o(new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED,fatal:!0,networkDetails:g,response:Oe({url:l.url,data:void 0},d)},`"${e}" certificate request failed (${r}). Status: ${d.code} (${d.text})`))},onTimeout:(d,f,g)=>{o(new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED,fatal:!0,networkDetails:g,response:{url:l.url,data:void 0}},`"${e}" certificate request timed out (${r})`))},onAbort:(d,f,g)=>{o(new Error("aborted"))}};i.load(l,h,u)})):Promise.resolve()}setMediaKeysServerCertificate(e,t,s){return new Promise((i,r)=>{e.setServerCertificate(s).then(n=>{this.log(`setServerCertificate ${n?"success":"not supported by CDM"} (${s==null?void 0:s.byteLength}) on "${t}"`),i(e)}).catch(n=>{r(new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED,error:n,fatal:!0},n.message))})})}renewLicense(e,t){return this.requestLicense(e,new Uint8Array(t)).then(s=>this.updateKeySession(e,new Uint8Array(s)).catch(i=>{throw new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_SESSION_UPDATE_FAILED,error:i,fatal:!0},i.message)}))}unpackPlayReadyKeyMessage(e,t){const s=String.fromCharCode.apply(null,new Uint16Array(t.buffer));if(!s.includes("PlayReadyKeyMessage"))return e.setRequestHeader("Content-Type","text/xml; charset=utf-8"),t;const i=new DOMParser().parseFromString(s,"application/xml"),r=i.querySelectorAll("HttpHeader");if(r.length>0){let h;for(let u=0,d=r.length;u<d;u++){var n,o;h=r[u];const f=(n=h.querySelector("name"))==null?void 0:n.textContent,g=(o=h.querySelector("value"))==null?void 0:o.textContent;f&&g&&e.setRequestHeader(f,g)}}const l=i.querySelector("Challenge"),c=l==null?void 0:l.textContent;if(!c)throw new Error("Cannot find <Challenge> in key message");return tr(atob(c))}setupLicenseXHR(e,t,s,i){const r=this.config.licenseXhrSetup;return r?Promise.resolve().then(()=>{if(!s.decryptdata)throw new Error("Key removed");return r.call(this.hls,e,t,s,i)}).catch(n=>{if(!s.decryptdata)throw n;return e.open("POST",t,!0),r.call(this.hls,e,t,s,i)}).then(n=>(e.readyState||e.open("POST",t,!0),{xhr:e,licenseChallenge:n||i})):(e.open("POST",t,!0),Promise.resolve({xhr:e,licenseChallenge:i}))}requestLicense(e,t){const s=this.config.keyLoadPolicy.default;return new Promise((i,r)=>{const n=this.getLicenseServerUrl(e.keySystem);this.log(`Sending license request to URL: ${n}`);const o=new XMLHttpRequest;o.responseType="arraybuffer",o.onreadystatechange=()=>{if(!this.hls||!e.mediaKeysSession)return r(new Error("invalid state"));if(o.readyState===4)if(o.status===200){this._requestLicenseFailureCount=0;let l=o.response;this.log(`License received ${l instanceof ArrayBuffer?l.byteLength:l}`);const c=this.config.licenseResponseCallback;if(c)try{l=c.call(this.hls,o,n,e)}catch(h){this.error(h)}i(l)}else{const l=s.errorRetry,c=l?l.maxNumRetry:0;if(this._requestLicenseFailureCount++,this._requestLicenseFailureCount>c||o.status>=400&&o.status<500)r(new Qe({type:Z.KEY_SYSTEM_ERROR,details:w.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0,networkDetails:o,response:{url:n,data:void 0,code:o.status,text:o.statusText}},`License Request XHR failed (${n}). Status: ${o.status} (${o.statusText})`));else{const h=c-this._requestLicenseFailureCount+1;this.warn(`Retrying license request, ${h} attempts left`),this.requestLicense(e,t).then(i,r)}}},e.licenseXhr&&e.licenseXhr.readyState!==XMLHttpRequest.DONE&&e.licenseXhr.abort(),e.licenseXhr=o,this.setupLicenseXHR(o,n,e,t).then(({xhr:l,licenseChallenge:c})=>{e.keySystem==Se.PLAYREADY&&(c=this.unpackPlayReadyKeyMessage(l,c)),l.send(c)})})}onMediaAttached(e,t){if(!this.config.emeEnabled)return;const s=t.media;this.media=s,s.addEventListener("encrypted",this.onMediaEncrypted),s.addEventListener("waitingforkey",this.onWaitingForKey)}onMediaDetached(){const e=this.media,t=this.mediaKeySessions;e&&(e.removeEventListener("encrypted",this.onMediaEncrypted),e.removeEventListener("waitingforkey",this.onWaitingForKey),this.media=null),this._requestLicenseFailureCount=0,this.setMediaKeysQueue=[],this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},Ts.clearKeyUriToKeyIdMap();const s=t.length;Qt.CDMCleanupPromise=Promise.all(t.map(i=>this.removeSession(i)).concat(e==null?void 0:e.setMediaKeys(null).cat
vendor: 5,410 bytes, line 41
41ch(i=>{this.log(`Could not clear media keys: ${i}`)}))).then(()=>{s&&(this.log("finished closing key sessions and clearing media keys"),t.length=0)}).catch(i=>{this.log(`Could not close sessions and clear media keys: ${i}`)})}onManifestLoading(){this.keyFormatPromise=null}onManifestLoaded(e,{sessionKeys:t}){if(!(!t||!this.config.emeEnabled)&&!this.keyFormatPromise){const s=t.reduce((i,r)=>(i.indexOf(r.keyFormat)===-1&&i.push(r.keyFormat),i),[]);this.log(`Selecting key-system from session-keys ${s.join(", ")}`),this.keyFormatPromise=this.getKeyFormatPromise(s)}}removeSession(e){const{mediaKeysSession:t,licenseXhr:s}=e;if(t){this.log(`Remove licenses and keys and close session ${t.sessionId}`),e._onmessage&&(t.removeEventListener("message",e._onmessage),e._onmessage=void 0),e._onkeystatuseschange&&(t.removeEventListener("keystatuseschange",e._onkeystatuseschange),e._onkeystatuseschange=void 0),s&&s.readyState!==XMLHttpRequest.DONE&&s.abort(),e.mediaKeysSession=e.decryptdata=e.licenseXhr=void 0;const i=this.mediaKeySessions.indexOf(e);return i>-1&&this.mediaKeySessions.splice(i,1),t.remove().catch(r=>{this.log(`Could not remove session: ${r}`)}).then(()=>t.close()).catch(r=>{this.log(`Could not close session: ${r}`)})}}}Qt.CDMCleanupPromise=void 0;class Qe extends Error{constructor(e,t){super(t),this.data=void 0,e.error||(e.error=new Error(t)),this.data=e,e.err=e.error}}var He;(function(a){a.MANIFEST="m",a.AUDIO="a",a.VIDEO="v",a.MUXED="av",a.INIT="i",a.CAPTION="c",a.TIMED_TEXT="tt",a.KEY="k",a.OTHER="o"})(He||(He={}));var ur;(function(a){a.DASH="d",a.HLS="h",a.SMOOTH="s",a.OTHER="o"})(ur||(ur={}));var Mt;(function(a){a.OBJECT="CMCD-Object",a.REQUEST="CMCD-Request",a.SESSION="CMCD-Session",a.STATUS="CMCD-Status"})(Mt||(Mt={}));const Qu={[Mt.OBJECT]:["br","d","ot","tb"],[Mt.REQUEST]:["bl","dl","mtp","nor","nrr","su"],[Mt.SESSION]:["cid","pr","sf","sid","st","v"],[Mt.STATUS]:["bs","rtp"]};class ts{constructor(e,t){this.value=void 0,this.params=void 0,Array.isArray(e)&&(e=e.map(s=>s instanceof ts?s:new ts(s))),this.value=e,this.params=t}}class Io{constructor(e){this.description=void 0,this.description=e}}const Ju="Dict";function Zu(a){return Array.isArray(a)?JSON.stringify(a):a instanceof Map?"Map{}":a instanceof Set?"Set{}":typeof a=="object"?JSON.stringify(a):String(a)}function ed(a,e,t,s){return new Error(`failed to ${a} "${Zu(e)}" as ${t}`,{cause:s})}const Ea="Bare Item",td="Boolean",sd="Byte Sequence",id="Decimal",rd="Integer";function nd(a){return a<-999999999999999||999999999999999<a}const ad=/[\x00-\x1f\x7f]+/,od="Token",ld="Key";function ft(a,e,t){return ed("serialize",a,e,t)}function cd(a){if(typeof a!="boolean")throw ft(a,td);return a?"?1":"?0"}function hd(a){return btoa(String.fromCharCode(...a))}function ud(a){if(ArrayBuffer.isView(a)===!1)throw ft(a,sd);return`:${hd(a)}:`}function Do(a){if(nd(a))throw ft(a,rd);return a.toString()}function dd(a){return`@${Do(a.getTime()/1e3)}`}function Co(a,e){if(a<0)return-Co(-a,e);const t=Math.pow(10,e);if(Math.abs(a*t%1-.5)<Number.EPSILON){const i=Math.floor(a*t);return(i%2===0?i:i+1)/t}else return Math.round(a*t)/t}function fd(a){const e=Co(a,3);if(Math.floor(Math.abs(e)).toString().length>12)throw ft(a,id);const t=e.toString();return t.includes(".")?t:`${t}.0`}const gd="String";function md(a){if(ad.test(a))throw ft(a,gd);return`"${a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function pd(a){return a.description||a.toString().slice(7,-1)}function Sa(a){const e=pd(a);if(/^([a-zA-Z*])([!#$%&'*+\-.^_`|~\w:/]*)$/.test(e)===!1)throw ft(e,od);return e}function dr(a){switch(typeof a){case"number":if(!j(a))throw ft(a,Ea);return Number.isInteger(a)?Do(a):fd(a);case"string":return md(a);case"symbol":return Sa(a);case"boolean":return cd(a);case"object":if(a instanceof Date)return dd(a);if(a instanceof Uint8Array)return ud(a);if(a instanceof Io)return Sa(a);default:throw ft(a,Ea)}}function fr(a){if(/^[a-z*][a-z0-9\-_.*]*$/.test(a)===!1)throw ft(a,ld);return a}function Fr(a){return a==null?"":Object.entries(a).map(([e,t])=>t===!0?`;${fr(e)}`:`;${fr(e)}=${dr(t)}`).join("")}function wo(a){return a instanceof ts?`${dr(a.value)}${Fr(a.params)}`:dr(a)}function xd(a){return`(${a.value.map(wo).join(" ")})${Fr(a.params)}`}function yd(a,e={whitespace:!0}){if(typeof a!="object")throw ft(a,Ju);const t=a instanceof Map?a.entries():Object.entries(a),s=e!=null&&e.whitespace?" ":"";return Array.from(t).map(([i,r])=>{r instanceof ts||(r=new ts(r));let n=fr(i);return r.value===!0?n+=Fr(r.params):(n+="=",Array.isArray(r.value)?n+=xd(r):n+=wo(r)),n}).join(`,${s}`)}function Td(a,e){return yd(a,e)}const Ed=a=>a==="ot"||a==="sf"||a==="st",Sd=a=>typeof a=="number"?j(a):a!=null&&a!==""&&a!==!1;function vd(a,e){const t=new URL(a),s=new URL(e);if(t.origin!==s.origin)return a;const i=t.pathname.split("/").slice(1),r=s.pathname.split("/").slice(1,-1);for(;i[0]===r[0];)i.shift(),r.shift();for(;r.length;)r.shift(),i.unshift("..");return i.join("/")}function Ad(){try{return crypto.randomUUID()}catch{try{const e=URL.createObjectURL(new Blob),t=e.toString();return URL.revokeObjectURL(e),t.slice(t.lastIndexOf("/")+1)}catch{let t=new Date().getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{const r=(t+Math.random()*16)%16|0;return t=Math.floor(t/16),(i=="x"?r:r&3|8).toString(16)})}}}const Xs=a=>Math.round(a),Ld=(a,e)=>(e!=null&&e.baseUrl&&(a=vd(a,e.baseUrl)),encodeURIComponent(a)),Hs=a=>
41Xs(a/100)*100,Rd={br:Xs,d:Xs,bl:Hs,dl:Hs,mtp:Hs,nor:Ld,rtp:Hs,tb:Xs};function bd(a,e){const t={};if(a==null||typeof a!="object")return t;const s=Object.keys(a).sort(),i=we({},Rd,e==null?void 0:e.formatters),r=e==null?void 0:e.filter;return s.forEach(n=>{if(r!=null&&r(n))return;let o=a[n];const l=i[n];l&&(o=l(o,e)),!(n==="v"&&o===1)&&(n=="pr"&&o===1||Sd(o)&&(Ed(n)&&typeof o=="string"&&(o=new Io(o)),t[n]=o))}),t}function ko(a,e={}){return a?Td(bd(a,e),we({whitespace:!1},e)):""}function Id(a,e={}){if(!a)return{};const t=Object.entries(a),s=Object.entries(Qu).concat(Object.entries((e==null?void 0:e.customHeaderMap)||{})),i=t.reduce((r,n)=>{var o,l;const[c,h]=n,u=((o=s.find(d=>d[1].includes(c)))==null?void 0:o[0])||Mt.REQUEST;return(l=r[u])!=null||(r[u]={}),r[u][c]=h,r},{});return Object.entries(i).reduce((r,[n,o])=>(r[n]=ko(o,e),r),{})}function Dd(a,e,t){return we(a,Id(e,t))}const Cd="CMCD";function wd(a,e={}){if(!a)return"";const t=ko(a,e);return`${Cd}=${encodeURIComponent(t)}`}const va=/CMCD=[^&#]+/;function kd(a,e,t){const s=wd(e,t);if(!s)return a;if(va.test(a))return a.replace(va,s);const i=a.includes("?")?"&":"?";return`${a}${i}${s}`}class _d{constructor(e){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=()=>{this.initialized&&(this.starved=!0),this.buffering=!0},this.onPlaying=()=>{this.initialized||(this.initialized=!0),this.buffering=!1},this.applyPlaylistData=i=>{try{this.apply(i,{ot:He.MANIFEST,su:!this.initialized})}catch(r){b.warn("Could not generate manifest CMCD data.",r)}},this.applyFragmentData=i=>{try{const r=i.frag,n=this.hls.levels[r.level],o=this.getObjectType(r),l={d:r.duration*1e3,ot:o};(o===He.VIDEO||o===He.AUDIO||o==He.MUXED)&&(l.br=n.bitrate/1e3,l.tb=this.getTopBandwidth(o)/1e3,l.bl=this.getBufferLength(o)),this.apply(i,l)}catch(r){b.warn("Could not generate segment CMCD data.",r)}},this.hls=e;const t=this.config=e.config,{cmcd:s}=t;s!=null&&(t.pLoader=this.createPlaylistLoader(),t.fLoader=this.createFragmentLoader(),this.sid=s.sessionId||Ad(),this.cid=s.contentId,this.useHeaders=s.useHeaders===!0,this.includeKeys=s.includeKeys,this.registerListeners())}registerListeners(){const e=this.hls;e.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(p.MEDIA_DETACHED,this.onMediaDetached,this),e.on(p.BUFFER_CREATED,this.onBufferCreated,this)}unregisterListeners(){const e=this.hls;e.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(p.MEDIA_DETACHED,this.onMediaDetached,this),e.off(p.BUFFER_CREATED,this.onBufferCreated,this)}destroy(){this.unregisterListeners(),this.onMediaDetached(),this.hls=this.config=this.audioBuffer=this.videoBuffer=null,this.onWaiting=this.onPlaying=null}onMediaAttached(e,t){this.media=t.media,this.media.addEventListener("waiting",this.onWaiting),this.media.addEventListener("playing",this.onPlaying)}onMediaDetached(){this.media&&(this.media.removeEventListener("waiting",this.onWaiting),this.media.removeEventListener("playing",this.onPlaying),this.media=null)}onBufferCreated(e,t){var s,i;this.audioBuffer=(s=t.tracks.audio)==null?void 0:s.buffer,this.videoBuffer=(i=t.tracks.video)==null?void 0:i.buffer}createData(){var e;return{v:1,sf:ur.HLS,sid:this.sid,cid:this.cid,pr:(e=this.media)==null?void 0:e.playbackRate,mtp:this.hls.bandwidthEstimate/1e3}}apply(e,t={}){we(t,this.createData());const s=t.ot===He.INIT||t.ot===He.VIDEO||t.ot===He.MUXED;this.starved&&s&&(t.bs=!0,t.su=!0,this.starved=!1),t.su==null&&(t.su=this.buffering);const{includeKeys:i}=this;i&&(t=Object.keys(t).reduce((r,n)=>(i.includes(n)&&(r[n]=t[n]),r),{})),this.useHeaders?(e.headers||(e.headers={}),Dd(e.headers,t)):e.url=kd(e.url,t)}getObjectType(e){const{type:t}=e;if(t==="subtitle")return He.TIMED_TEXT;if(e.sn==="initSegment")return He.INIT;if(t==="audio")return He.AUDIO;if(t==="main")return this.hls.audioTracks.length?He.VIDEO:He.MUXED}getTopBandwidth(e){let t=0,s;const i=this.hls;if(e===He.AUDIO)s=i.audioTracks;else{const r=i.maxAutoLevel,n=r>-1?r+1:i.levels.length;s=i.levels.slice(0,n)}for(const r of s)r.bitrate>t&&(t=r.bitrate);return t>0?t:NaN}getBufferLength(e){const t=this.hls.media,s=e===He.AUDIO?this.audioBuffer:this.videoBuffer;return!s||!t?NaN:Ee.bufferInfo(s,t.currentTime,this.config.maxBufferHole).len*1e3}createPlaylistLoader(){const{pLoader:e}=this.config,t=this.applyPlaylistData,s=e||this.config.loader;return class{constructor(r){this.loader=void 0,this.loader=new s(r)}get stats(){return this.loader.stats}get context(){return this.loader.context}destroy(){this.loader.destroy()}abort(){this.loader.abort()}load(r,n,o){t(r),this.loader.load(r,n,o)}}}createFragmentLoader(){const{fLoader:e}=this.config,t=this.applyFragmentData,s=e||this.config.loader;return class{constructor(r){this.loader=void 0,this.loader=new s(r)}get stats(){return this.loader.stats}get context(){return this.loader.context}destroy(){this.loader.destroy()}abort(){this.loader.abort()}load(r,n,o){t(r),this.loader.load(r,n,o)}}}}const Pd=3e5;class Md{constructor(e){this.hls=void 0,this.log=void 0,this.loader=null,this.uri=null,this.pathwayId=".",this.pathwayPriority=null,this.timeToLoad=300,this.reloadTimer=-1,this.updated=0,this.started=!1,this.enabled=!0,this.levels=null,this.audioTracks=null,this.subtitleTracks=null,this.penalizedPathways={},this.hls=e,this.log=b.log.bind(b,"[content-steering]:"),this.registerListeners()}registerListeners(){const e=this.hls;e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(p.MANIFEST_PARSED,this.onManifestParsed,this),e.on(p.ERROR,this.onError,this)}unregisterListeners(){const e=this.hls;e&&(e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(p.MANIFEST_PARSED,this.onManifestParsed,this),e.off(p.ERROR,this.onError,this))}
vendor: 6,356 bytes, line 41
41startLoad(){if(this.started=!0,this.clearTimeout(),this.enabled&&this.uri){if(this.updated){const e=this.timeToLoad*1e3-(performance.now()-this.updated);if(e>0){this.scheduleRefresh(this.uri,e);return}}this.loadSteeringManifest(this.uri)}}stopLoad(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),this.clearTimeout()}clearTimeout(){this.reloadTimer!==-1&&(self.clearTimeout(this.reloadTimer),this.reloadTimer=-1)}destroy(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null}removeLevel(e){const t=this.levels;t&&(this.levels=t.filter(s=>s!==e))}onManifestLoading(){this.stopLoad(),this.enabled=!0,this.timeToLoad=300,this.updated=0,this.uri=null,this.pathwayId=".",this.levels=this.audioTracks=this.subtitleTracks=null}onManifestLoaded(e,t){const{contentSteering:s}=t;s!==null&&(this.pathwayId=s.pathwayId,this.uri=s.uri,this.started&&this.startLoad())}onManifestParsed(e,t){this.audioTracks=t.audioTracks,this.subtitleTracks=t.subtitleTracks}onError(e,t){const{errorAction:s}=t;if((s==null?void 0:s.action)===Be.SendAlternateToPenaltyBox&&s.flags===tt.MoveAllAlternatesMatchingHost){const i=this.levels;let r=this.pathwayPriority,n=this.pathwayId;if(t.context){const{groupId:o,pathwayId:l,type:c}=t.context;o&&i?n=this.getPathwayForGroupId(o,c,n):l&&(n=l)}n in this.penalizedPathways||(this.penalizedPathways[n]=performance.now()),!r&&i&&(r=i.reduce((o,l)=>(o.indexOf(l.pathwayId)===-1&&o.push(l.pathwayId),o),[])),r&&r.length>1&&(this.updatePathwayPriority(r),s.resolved=this.pathwayId!==n),s.resolved||b.warn(`Could not resolve ${t.details} ("${t.error.message}") with content-steering for Pathway: ${n} levels: ${i&&i.length} priorities: ${JSON.stringify(r)} penalized: ${JSON.stringify(this.penalizedPathways)}`)}}filterParsedLevels(e){this.levels=e;let t=this.getLevelsForPathway(this.pathwayId);if(t.length===0){const s=e[0].pathwayId;this.log(`No levels found in Pathway ${this.pathwayId}. Setting initial Pathway to "${s}"`),t=this.getLevelsForPathway(s),this.pathwayId=s}return t.length!==e.length&&this.log(`Found ${t.length}/${e.length} levels in Pathway "${this.pathwayId}"`),t}getLevelsForPathway(e){return this.levels===null?[]:this.levels.filter(t=>e===t.pathwayId)}updatePathwayPriority(e){this.pathwayPriority=e;let t;const s=this.penalizedPathways,i=performance.now();Object.keys(s).forEach(r=>{i-s[r]>Pd&&delete s[r]});for(let r=0;r<e.length;r++){const n=e[r];if(n in s)continue;if(n===this.pathwayId)return;const o=this.hls.nextLoadLevel,l=this.hls.levels[o];if(t=this.getLevelsForPathway(n),t.length>0){this.log(`Setting Pathway to "${n}"`),this.pathwayId=n,za(t),this.hls.trigger(p.LEVELS_UPDATED,{levels:t});const c=this.hls.levels[o];l&&c&&this.levels&&(c.attrs["STABLE-VARIANT-ID"]!==l.attrs["STABLE-VARIANT-ID"]&&c.bitrate!==l.bitrate&&this.log(`Unstable Pathways change from bitrate ${l.bitrate} to ${c.bitrate}`),this.hls.nextLoadLevel=o);break}}}getPathwayForGroupId(e,t,s){const i=this.getLevelsForPathway(s).concat(this.levels||[]);for(let r=0;r<i.length;r++)if(t===ge.AUDIO_TRACK&&i[r].hasAudioGroup(e)||t===ge.SUBTITLE_TRACK&&i[r].hasSubtitleGroup(e))return i[r].pathwayId;return s}clonePathways(e){const t=this.levels;if(!t)return;const s={},i={};e.forEach(r=>{const{ID:n,"BASE-ID":o,"URI-REPLACEMENT":l}=r;if(t.some(h=>h.pathwayId===n))return;const c=this.getLevelsForPathway(o).map(h=>{const u=new Ae(h.attrs);u["PATHWAY-ID"]=n;const d=u.AUDIO&&`${u.AUDIO}_clone_${n}`,f=u.SUBTITLES&&`${u.SUBTITLES}_clone_${n}`;d&&(s[u.AUDIO]=d,u.AUDIO=d),f&&(i[u.SUBTITLES]=f,u.SUBTITLES=f);const g=_o(h.uri,u["STABLE-VARIANT-ID"],"PER-VARIANT-URIS",l),m=new Zt({attrs:u,audioCodec:h.audioCodec,bitrate:h.bitrate,height:h.height,name:h.name,url:g,videoCodec:h.videoCodec,width:h.width});if(h.audioGroups)for(let x=1;x<h.audioGroups.length;x++)m.addGroupId("audio",`${h.audioGroups[x]}_clone_${n}`);if(h.subtitleGroups)for(let x=1;x<h.subtitleGroups.length;x++)m.addGroupId("text",`${h.subtitleGroups[x]}_clone_${n}`);return m});t.push(...c),Aa(this.audioTracks,s,l,n),Aa(this.subtitleTracks,i,l,n)})}loadSteeringManifest(e){const t=this.hls.config,s=t.loader;this.loader&&this.loader.destroy(),this.loader=new s(t);let i;try{i=new self.URL(e)}catch{this.enabled=!1,this.log(`Failed to parse Steering Manifest URI: ${e}`);return}if(i.protocol!=="data:"){const h=(this.hls.bandwidthEstimate||t.abrEwmaDefaultEstimate)|0;i.searchParams.set("_HLS_pathway",this.pathwayId),i.searchParams.set("_HLS_throughput",""+h)}const r={responseType:"json",url:i.href},n=t.steeringManifestLoadPolicy.default,o=n.errorRetry||n.timeoutRetry||{},l={loadPolicy:n,timeout:n.maxLoadTimeMs,maxRetry:o.maxNumRetry||0,retryDelay:o.retryDelayMs||0,maxRetryDelay:o.maxRetryDelayMs||0},c={onSuccess:(h,u,d,f)=>{this.log(`Loaded steering manifest: "${i}"`);const g=h.data;if(g.VERSION!==1){this.log(`Steering VERSION ${g.VERSION} not supported!`);return}this.updated=performance.now(),this.timeToLoad=g.TTL;const{"RELOAD-URI":m,"PATHWAY-CLONES":x,"PATHWAY-PRIORITY":T}=g;if(m)try{this.uri=new self.URL(m,i).href}catch{this.enabled=!1,this.log(`Failed to parse Steering Manifest RELOAD-URI: ${m}`);return}this.scheduleRefresh(this.uri||d.url),x&&this.clonePathways(x);const R={steeringManifest:g,url:i.toString()};this.hls.trigger(p.STEERING_MANIFEST_LOADED,R),T&&this.updatePathwayPriority(T)},onError:(h,u,d,f)=>{if(this.log(`Error loading steering manifest: ${h.code} ${h.text} (${u.url})`),this.stopLoad(),h.code===410){this.enabled=!1,this.log(`Steering manifest ${u.url} no longer available`);return}let g=this.timeToLoad*1e3;if(h.code===429){const m=this.loader;if(typeof(m==null?void 0:m.getResponseHeader)=="function"){const x=m.getResponseHeader("Retry-After");x&&(g=parseFloat(x)*1e3)}this.log(`Steering manifest ${u.url} rate limited`);return}this.scheduleRefresh(this.uri||u.url,g)},onTimeout:(h,u,d)=>{this.log(`Timeout loading steering manifest (${u.url})`),this.scheduleRefresh(this.uri||u.url)}};this.log(`Requesting steering manifest: ${i}`),this.loader.load(r,l,c)}scheduleRefresh(e,t=this.timeToLoad*1e3){this.clearTimeout(),this.reloadTimer=self.setTimeout(()=>{var s;const i=(s=this.hls)==null?void 0:s.media;if(i&&!i.ended){this.loadSteeringManifest(e);return}this.scheduleRefresh(e,this.timeToLoad*1e3)},t)}}function Aa(a,e,t,s){a&&Object.keys(e).forEach(i=>
41{const r=a.filter(n=>n.groupId===i).map(n=>{const o=we({},n);return o.details=void 0,o.attrs=new Ae(o.attrs),o.url=o.attrs.URI=_o(n.url,n.attrs["STABLE-RENDITION-ID"],"PER-RENDITION-URIS",t),o.groupId=o.attrs["GROUP-ID"]=e[i],o.attrs["PATHWAY-ID"]=s,o});a.push(...r)})}function _o(a,e,t,s){const{HOST:i,PARAMS:r,[t]:n}=s;let o;e&&(o=n==null?void 0:n[e],o&&(a=o));const l=new self.URL(a);return i&&!o&&(l.host=i),r&&Object.keys(r).sort().forEach(c=>{c&&l.searchParams.set(c,r[c])}),l.href}const Fd=/^age:\s*[\d.]+\s*$/im;class Po{constructor(e){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=null,this.loader=null,this.stats=void 0,this.xhrSetup=e&&e.xhrSetup||null,this.stats=new hi,this.retryDelay=0}destroy(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null,this.context=null,this.xhrSetup=null}abortInternal(){const e=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),e&&(e.onreadystatechange=null,e.onprogress=null,e.readyState!==4&&(this.stats.aborted=!0,e.abort()))}abort(){var e;this.abortInternal(),(e=this.callbacks)!=null&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)}load(e,t,s){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=e,this.config=t,this.callbacks=s,this.loadInternal()}loadInternal(){const{config:e,context:t}=this;if(!e||!t)return;const s=this.loader=new self.XMLHttpRequest,i=this.stats;i.loading.first=0,i.loaded=0,i.aborted=!1;const r=this.xhrSetup;r?Promise.resolve().then(()=>{if(!(this.loader!==s||this.stats.aborted))return r(s,t.url)}).catch(n=>{if(!(this.loader!==s||this.stats.aborted))return s.open("GET",t.url,!0),r(s,t.url)}).then(()=>{this.loader!==s||this.stats.aborted||this.openAndSendXhr(s,t,e)}).catch(n=>{this.callbacks.onError({code:s.status,text:n.message},t,s,i)}):this.openAndSendXhr(s,t,e)}openAndSendXhr(e,t,s){e.readyState||e.open("GET",t.url,!0);const i=t.headers,{maxTimeToFirstByteMs:r,maxLoadTimeMs:n}=s.loadPolicy;if(i)for(const o in i)e.setRequestHeader(o,i[o]);t.rangeEnd&&e.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),e.onreadystatechange=this.readystatechange.bind(this),e.onprogress=this.loadprogress.bind(this),e.responseType=t.responseType,self.clearTimeout(this.requestTimeout),s.timeout=r&&j(r)?r:n,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),s.timeout),e.send()}readystatechange(){const{context:e,loader:t,stats:s}=this;if(!e||!t)return;const i=t.readyState,r=this.config;if(!s.aborted&&i>=2&&(s.loading.first===0&&(s.loading.first=Math.max(self.performance.now(),s.loading.start),r.timeout!==r.loadPolicy.maxLoadTimeMs&&(self.clearTimeout(this.requestTimeout),r.timeout=r.loadPolicy.maxLoadTimeMs,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),r.loadPolicy.maxLoadTimeMs-(s.loading.first-s.loading.start)))),i===4)){self.clearTimeout(this.requestTimeout),t.onreadystatechange=null,t.onprogress=null;const n=t.status,o=t.responseType!=="text";if(n>=200&&n<300&&(o&&t.response||t.responseText!==null)){s.loading.end=Math.max(self.performance.now(),s.loading.first);const l=o?t.response:t.responseText,c=t.responseType==="arraybuffer"?l.byteLength:l.length;if(s.loaded=s.total=c,s.bwEstimate=s.total*8e3/(s.loading.end-s.loading.first),!this.callbacks)return;const h=this.callbacks.onProgress;if(h&&h(s,e,l,t),!this.callbacks)return;const u={url:t.responseURL,data:l,code:n};this.callbacks.onSuccess(u,s,e,t)}else{const l=r.loadPolicy.errorRetry,c=s.retry,h={url:e.url,data:void 0,code:n};ni(l,c,!1,h)?this.retry(l):(b.error(`${n} while loading ${e.url}`),this.callbacks.onError({code:n,text:t.statusText},e,t,s))}}}loadtimeout(){if(!this.config)return;const e=this.config.loadPolicy.timeoutRetry,t=this.stats.retry;if(ni(e,t,!0))this.retry(e);else{var s;b.warn(`timeout while loading ${(s=this.context)==null?void 0:s.url}`);const i=this.callbacks;i&&(this.abortInternal(),i.onTimeout(this.stats,this.context,this.loader))}}retry(e){const{context:t,stats:s}=this;this.retryDelay=vr(e,s.retry),s.retry++,b.warn(`${status?"HTTP Status "+status:"Timeout"} while loading ${t==null?void 0:t.url}, retrying ${s.retry}/${e.maxNumRetry} in ${this.retryDelay}ms`),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay)}loadprogress(e){const t=this.stats;t.loaded=e.loaded,e.lengthComputable&&(t.total=e.total)}getCacheAge(){let e=null;if(this.loader&&Fd.test(this.loader.getAllResponseHeaders())){const t=this.loader.getResponseHeader("age");e=t?parseFloat(t):null}return e}getResponseHeader(e){return this.loader&&new RegExp(`^${e}:\\s*[\\d.]+\\s*$`,"im").test(this.loader.getAllResponseHeaders())?this.loader.getResponseHeader(e):null}}function Od(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch{}return!1}const Nd=/(\d+)-(\d+)\/(\d+)/;class La{constructor(e){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=e.fetchSetup||Gd,this.controller=new self.AbortController,this.stats=new hi}destroy(){this.loader=this.callbacks=this.context=this.config=this.request=null,this.abortInternal(),this.response=null,this.fetchSetup=this.controller=this.stats=null}abortInternal(){this.controller&&!this.stats.loading.end&&(this.stats.aborted=!0,this.controller.abort())}abort(){var e;this.abortInternal(),(e=this.callbacks)!=null&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.response)}load(e,t,s){const i=this.stats;if(i.loading.start)throw new Error("Loader can only be used once.");i.loading.start=self.performance.now();const r=Ud(e,this.controller.signal),n=s.onProgress,o=e.responseType==="arraybuffer",l=o?"byteLength":"length",{maxTimeToFirstByteMs:c,maxLoadTimeMs:h}=t.loadPolicy;this.context=e,this.config=t,this.callbacks=s,this.request=this.fetchSetup(e,r),self.clearTimeout(this.requestTimeout),t.timeout=c&&j(c)?c:h,this.requestTimeout=self.setTimeout(()=>{this.abortInternal(),s.onTimeout(i,e,this.response)},t.timeout),self.fetch(this.request).then(u=>{this.response=this.loader=u;const d=Math.max(self.performance.now(),i.loading.start);if(self.clearTimeout(this.requestTimeout),t.timeout=h,this.requestTimeout=self.setTimeout(()=>{this.abortInternal(),s.onTimeout(i,e,this.response)},h-(d-i.loading.start)),!u.ok){const{status:f,statusText:g}=u;throw new Kd(g||"fetch, bad network response",f,u)}return i.loading.first=d,i.total=$d(u.headers)||i.total,n&&j(t.highWaterMark)?this.loadProgressively(u,i,e,t.highWaterMark,n):o?u.arrayBuffer():e.responseType==="json"?u.json():u.text()}).then(u=>{const d=this.response;if(!d)throw new Error("loader destroyed");self.clearTimeout(this.requestTimeout),i.loading.end=Math.max(self.performance.now(),i.loading.first);const f=u[l];f&&(i.loaded=i.total=f);const g={url:d.url,data:u,code:d.status};n&&!j(t.highWaterMark)&&n(i,e,u,d),s.onSuccess(g,i,e,d)}).catch(u=>{if(self.clearTimeout(this.requestTimeout),i.aborted)return;const d=u&&u.code||0,f=u?u.message:null;s.onError({code:d,text:f},e,u?u.details:null,i)})}getCacheAge(){let e=null;if(this.response){const t=this.response.headers.get("age");e=t?parseFloat(t):null}return e}getResponseHeader(e){return this.response?this.response.headers.get(e):null}loadProgressively(e,t,s,i=0,r){const n=new Za,o=e.body.getReader(),l=()=>o.read().then(c=>{if(c.done)return n.dataLength&&r(t,s,n.flush(),e),Promise.resolve(new ArrayBuffer(0));const h=c.value,u=h.length;return t.loaded+=u,u<i||n.dataLength?(n.push(h),n.dataLength>=i&&r(t,s,n.flush(),e)):r(t,s,h,e),l()}).catch(()=>Promise.reject());return l()}}function Ud(a,e){const t={method:"GET",mode:"cors",credentials:"same-origin",signal:e,headers:new self.Headers(we({},a.headers))};return a.rangeEnd&&t.headers.set("Range","bytes="+a.rangeStart+"-"+String(a.rangeEnd-1)),t}function Bd(a){const e=Nd.exec(a);if(e)return parseInt(e[2])-parseInt(e[1])+1}function $d(a){const e=a.get("Content-Range");if(e){const s=Bd(e);if(j(s))return s}const t=a.get("Content-Length");if(t)return parseInt(t)}
vendor: 5,348 bytes, line 41
41function Gd(a,e){return new self.Request(a.url,e)}class Kd extends Error{constructor(e,t,s){super(e),this.code=void 0,this.details=void 0,this.code=t,this.details=s}}const Hd=/\s/,Vd={newCue(a,e,t,s){const i=[];let r,n,o,l,c;const h=self.VTTCue||self.TextTrackCue;for(let d=0;d<s.rows.length;d++)if(r=s.rows[d],o=!0,l=0,c="",!r.isEmpty()){var u;for(let m=0;m<r.chars.length;m++)Hd.test(r.chars[m].uchar)&&o?l++:(c+=r.chars[m].uchar,o=!1);r.cueStartTime=e,e===t&&(t+=1e-4),l>=16?l--:l++;const f=vo(c.trim()),g=Pr(e,t,f);a!=null&&(u=a.cues)!=null&&u.getCueById(g)||(n=new h(e,t,f),n.id=g,n.line=d+1,n.align="left",n.position=10+Math.min(80,Math.floor(l*8/32)*10),i.push(n))}return a&&i.length&&(i.sort((d,f)=>d.line==="auto"||f.line==="auto"?0:d.line>8&&f.line>8?f.line-d.line:d.line-f.line),i.forEach(d=>ja(a,d))),i}},jd={maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:null,errorRetry:null},Mo=Oe(Oe({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:60*1e3*1e3,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:Po,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:yh,bufferController:vu,capLevelController:Mr,errorController:ah,fpsController:Xu,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:ka,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0,useMediaCapabilities:!0,certLoadPolicy:{default:jd},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},Wd()),{},{subtitleStreamController:yu,subtitleTrackController:Eu,timelineController:qu,audioStreamController:pu,audioTrackController:xu,emeController:Qt,cmcdController:_d,contentSteeringController:Md});function Wd(){return{cueHandler:Vd,enableWebVTT:!0,enableIMSC1:!0,enableCEA708Captions:!0,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}}function Yd(a,e){if((e.liveSyncDurationCount||e.liveMaxLatencyDurationCount)&&(e.liveSyncDuration||e.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(e.liveMaxLatencyDurationCount!==void 0&&(e.liveSyncDurationCount===void 0||e.liveMaxLatencyDurationCount<=e.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(e.liveMaxLatencyDuration!==void 0&&(e.liveSyncDuration===void 0||e.liveMaxLatencyDuration<=e.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');const t=gr(a),s=["manifest","level","frag"],i=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];
41return s.forEach(r=>{const n=`${r==="level"?"playlist":r}LoadPolicy`,o=e[n]===void 0,l=[];i.forEach(c=>{const h=`${r}Loading${c}`,u=e[h];if(u!==void 0&&o){l.push(h);const d=t[n].default;switch(e[n]={default:d},c){case"TimeOut":d.maxLoadTimeMs=u,d.maxTimeToFirstByteMs=u;break;case"MaxRetry":d.errorRetry.maxNumRetry=u,d.timeoutRetry.maxNumRetry=u;break;case"RetryDelay":d.errorRetry.retryDelayMs=u,d.timeoutRetry.retryDelayMs=u;break;case"MaxRetryTimeout":d.errorRetry.maxRetryDelayMs=u,d.timeoutRetry.maxRetryDelayMs=u;break}}}),l.length&&b.warn(`hls.js config: "${l.join('", "')}" setting(s) are deprecated, use "${n}": ${JSON.stringify(e[n])}`)}),Oe(Oe({},t),e)}function gr(a){return a&&typeof a=="object"?Array.isArray(a)?a.map(gr):Object.keys(a).reduce((e,t)=>(e[t]=gr(a[t]),e),{}):a}function qd(a){const e=a.loader;e!==La&&e!==Po?(b.log("[config]: Custom loader detected, cannot enable progressive streaming"),a.progressive=!1):Od()&&(a.loader=La,a.progressive=!0,a.enableSoftwareAES=!0,b.log("[config]: Progressive streaming enabled, using FetchLoader"))}let Qi;class zd extends Ar{constructor(e,t){super(e,"[level-controller]"),this._levels=[],this._firstLevel=-1,this._maxAutoLevel=-1,this._startLevel=void 0,this.currentLevel=null,this.currentLevelIndex=-1,this.manualLevelIndex=-1,this.steering=void 0,this.onParsedComplete=void 0,this.steering=t,this._registerListeners()}_registerListeners(){const{hls:e}=this;e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(p.LEVEL_LOADED,this.onLevelLoaded,this),e.on(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(p.FRAG_BUFFERED,this.onFragBuffered,this),e.on(p.ERROR,this.onError,this)}_unregisterListeners(){const{hls:e}=this;e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(p.LEVEL_LOADED,this.onLevelLoaded,this),e.off(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(p.FRAG_BUFFERED,this.onFragBuffered,this),e.off(p.ERROR,this.onError,this)}destroy(){this._unregisterListeners(),this.steering=null,this.resetLevels(),super.destroy()}stopLoad(){this._levels.forEach(t=>{t.loadError=0,t.fragmentError=0}),super.stopLoad()}resetLevels(){this._startLevel=void 0,this.manualLevelIndex=-1,this.currentLevelIndex=-1,this.currentLevel=null,this._levels=[],this._maxAutoLevel=-1}onManifestLoading(e,t){this.resetLevels()}onManifestLoaded(e,t){const s=this.hls.config.preferManagedMediaSource,i=[],r={},n={};let o=!1,l=!1,c=!1;t.levels.forEach(h=>{var u,d;const f=h.attrs;let{audioCodec:g,videoCodec:m}=h;((u=g)==null?void 0:u.indexOf("mp4a.40.34"))!==-1&&(Qi||(Qi=/chrome|firefox/i.test(navigator.userAgent)),Qi&&(h.audioCodec=g=void 0)),g&&(h.audioCodec=g=si(g,s)),((d=m)==null?void 0:d.indexOf("avc1"))===0&&(m=h.videoCodec=Fc(m));const{width:x,height:T,unknownCodecs:R}=h;if(o||(o=!!(x&&T)),l||(l=!!m),c||(c=!!g),R!=null&&R.length||g&&!Oi(g,"audio",s)||m&&!Oi(m,"video",s))return;const{CODECS:v,"FRAME-RATE":D,"HDCP-LEVEL":L,"PATHWAY-ID":_,RESOLUTION:k,"VIDEO-RANGE":B}=f,P=`${`${_||"."}-`}${h.bitrate}-${k}-${D}-${v}-${B}-${L}`;if(r[P])if(r[P].uri!==h.url&&!h.attrs["PATHWAY-ID"]){const U=n[P]+=1;h.attrs["PATHWAY-ID"]=new Array(U+1).join(".");const ee=new Zt(h);r[P]=ee,i.push(ee)}else r[P].addGroupId("audio",f.AUDIO),r[P].addGroupId("text",f.SUBTITLES);else{const U=new Zt(h);r[P]=U,n[P]=1,i.push(U)}}),this.filterAndSortMediaOptions(i,t,o,l,c)}filterAndSortMediaOptions(e,t,s,i,r){let n=[],o=[],l=e;if((s||i)&&r&&(l=l.filter(({videoCodec:g,videoRange:m,width:x,height:T})=>(!!g||!!(x&&T))&&qc(m))),l.length===0){Promise.resolve().then(()=>{if(this.hls){t.levels.length&&this.warn(`One or more CODECS in variant not supported: ${JSON.stringify(t.levels[0].attrs)}`);const g=new Error("no level with compatible codecs found in manifest");this.hls.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:t.url,error:g,reason:g.message})}});return}if(t.audioTracks){const{preferManagedMediaSource:g}=this.hls.config;n=t.audioTracks.filter(m=>!m.audioCodec||Oi(m.audioCodec,"audio",g)),Ra(n)}
vendor: 5,143 bytes, line 41
41t.subtitles&&(o=t.subtitles,Ra(o));const c=l.slice(0);l.sort((g,m)=>{if(g.attrs["HDCP-LEVEL"]!==m.attrs["HDCP-LEVEL"])return(g.attrs["HDCP-LEVEL"]||"")>(m.attrs["HDCP-LEVEL"]||"")?1:-1;if(s&&g.height!==m.height)return g.height-m.height;if(g.frameRate!==m.frameRate)return g.frameRate-m.frameRate;if(g.videoRange!==m.videoRange)return ii.indexOf(g.videoRange)-ii.indexOf(m.videoRange);if(g.videoCodec!==m.videoCodec){const x=_n(g.videoCodec),T=_n(m.videoCodec);if(x!==T)return T-x}if(g.uri===m.uri&&g.codecSet!==m.codecSet){const x=ti(g.codecSet),T=ti(m.codecSet);if(x!==T)return T-x}return g.averageBitrate!==m.averageBitrate?g.averageBitrate-m.averageBitrate:0});let h=c[0];if(this.steering&&(l=this.steering.filterParsedLevels(l),l.length!==c.length)){for(let g=0;g<c.length;g++)if(c[g].pathwayId===l[0].pathwayId){h=c[g];break}}this._levels=l;for(let g=0;g<l.length;g++)if(l[g]===h){var u;this._firstLevel=g;const m=h.bitrate,x=this.hls.bandwidthEstimate;if(this.log(`manifest loaded, ${l.length} level(s) found, first bitrate: ${m}`),((u=this.hls.userConfig)==null?void 0:u.abrEwmaDefaultEstimate)===void 0){const T=Math.min(m,this.hls.config.abrEwmaDefaultEstimateMax);T>x&&x===Mo.abrEwmaDefaultEstimate&&(this.hls.bandwidthEstimate=T)}break}const d=r&&!i,f={levels:l,audioTracks:n,subtitleTracks:o,sessionData:t.sessionData,sessionKeys:t.sessionKeys,firstLevel:this._firstLevel,stats:t.stats,audio:r,video:i,altAudio:!d&&n.some(g=>!!g.url)};this.hls.trigger(p.MANIFEST_PARSED,f),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}get levels(){return this._levels.length===0?null:this._levels}get level(){return this.currentLevelIndex}set level(e){const t=this._levels;if(t.length===0)return;if(e<0||e>=t.length){const h=new Error("invalid level idx"),u=e<0;if(this.hls.trigger(p.ERROR,{type:Z.OTHER_ERROR,details:w.LEVEL_SWITCH_ERROR,level:e,fatal:u,error:h,reason:h.message}),u)return;e=Math.min(e,t.length-1)}const s=this.currentLevelIndex,i=this.currentLevel,r=i?i.attrs["PATHWAY-ID"]:void 0,n=t[e],o=n.attrs["PATHWAY-ID"];if(this.currentLevelIndex=e,this.currentLevel=n,s===e&&n.details&&i&&r===o)return;this.log(`Switching to level ${e} (${n.height?n.height+"p ":""}${n.videoRange?n.videoRange+" ":""}${n.codecSet?n.codecSet+" ":""}@${n.bitrate})${o?" with Pathway "+o:""} from level ${s}${r?" with Pathway "+r:""}`);const l={level:e,attrs:n.attrs,details:n.details,bitrate:n.bitrate,averageBitrate:n.averageBitrate,maxBitrate:n.maxBitrate,realBitrate:n.realBitrate,width:n.width,height:n.height,codecSet:n.codecSet,audioCodec:n.audioCodec,videoCodec:n.videoCodec,audioGroups:n.audioGroups,subtitleGroups:n.subtitleGroups,loaded:n.loaded,loadError:n.loadError,fragmentError:n.fragmentError,name:n.name,id:n.id,uri:n.uri,url:n.url,urlId:0,audioGroupIds:n.audioGroupIds,textGroupIds:n.textGroupIds};this.hls.trigger(p.LEVEL_SWITCHING,l);const c=n.details;if(!c||c.live){const h=this.switchParams(n.uri,i==null?void 0:i.details,c);this.loadPlaylist(h)}}get manualLevel(){return this.manualLevelIndex}set manualLevel(e){this.manualLevelIndex=e,this._startLevel===void 0&&(this._startLevel=e),e!==-1&&(this.level=e)}get firstLevel(){return this._firstLevel}set firstLevel(e){this._firstLevel=e}get startLevel(){if(this._startLevel===void 0){const e=this.hls.config.startLevel;return e!==void 0?e:this.hls.firstAutoLevel}return this._startLevel}set startLevel(e){this._startLevel=e}onError(e,t){t.fatal||!t.context||t.context.type===ge.LEVEL&&t.context.level===this.level&&this.checkRetry(t)}onFragBuffered(e,{frag:t}){if(t!==void 0&&t.type===Q.MAIN){const s=t.elementaryStreams;if(!Object.keys(s).some(r=>!!s[r]))return;const i=this._levels[t.level];i!=null&&i.loadError&&(this.log(`Resetting level error count of ${i.loadError} on frag buffered`),i.loadError=0)}}onLevelLoaded(e,t){var s;const{level:i,details:r}=t,n=this._levels[i];if(!n){var o;this.warn(`Invalid level index ${i}`),(o=t.deliveryDirectives)!=null&&o.skip&&(r.deltaUpdateFailed=!0);return}i===this.currentLevelIndex?(n.fragmentError===0&&(n.loadError=0),this.playlistLoaded(i,t,n.details)):(s=t.deliveryDirectives)!=null&&s.skip&&(r.deltaUpdateFailed=!0)}loadPlaylist(e){super.loadPlaylist();const t=this.currentLevelIndex,s=this.currentLevel;if(s&&this.shouldLoadPlaylist(s)){let i=s.uri;if(e)try{i=e.addDirectives(i)}catch(n){this.warn(`Could not construct new URL with HLS Delivery Directives: ${n}`)}const r=s.attrs["PATHWAY-ID"];this.log(`Loading level index ${t}${(e==null?void 0:e.msn)!==void 0?" at sn "+e.msn+" part "+e.part:""} with${r?" Pathway "+r:""} ${i}`),this.clearTimer(),this.hls.trigger(p.LEVEL_LOADING,{url:i,level:t,pathwayId:s.attrs["PATHWAY-ID"],id:0,deliveryDirectives:e||null})}}get nextLoadLevel(){return this.manualLevelIndex!==-1?this.manualLevelIndex:this.hls.nextAutoLevel}set nextLoadLevel(e){this.level=e,this.manualLevelIndex===-1&&(this.hls.nextAutoLevel=e)}removeLevel(e){var t;const s=this._levels.filter((i,r)=>r!==e?!0:(this.steering&&this.steering.removeLevel(i),i===this.currentLevel&&(this.currentLevel=null,this.currentLevelIndex=-1,i.details&&i.details.fragments.forEac
vendor: 4,408 bytes, line 41
41h(n=>n.level=-1)),!1));za(s),this._levels=s,this.currentLevelIndex>-1&&(t=this.currentLevel)!=null&&t.details&&(this.currentLevelIndex=this.currentLevel.details.fragments[0].level),this.hls.trigger(p.LEVELS_UPDATED,{levels:s})}onLevelsUpdated(e,{levels:t}){this._levels=t}checkMaxAutoUpdated(){const{autoLevelCapping:e,maxAutoLevel:t,maxHdcpLevel:s}=this.hls;this._maxAutoLevel!==t&&(this._maxAutoLevel=t,this.hls.trigger(p.MAX_AUTO_LEVEL_UPDATED,{autoLevelCapping:e,levels:this.levels,maxAutoLevel:t,minAutoLevel:this.hls.minAutoLevel,maxHdcpLevel:s}))}}function Ra(a){const e={};a.forEach(t=>{const s=t.groupId||"";t.id=e[s]=e[s]||0,e[s]++})}class Xd{constructor(e){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=e}abort(e){for(const s in this.keyUriToKeyInfo){const i=this.keyUriToKeyInfo[s].loader;if(i){var t;if(e&&e!==((t=i.context)==null?void 0:t.frag.type))return;i.abort()}}}detach(){for(const e in this.keyUriToKeyInfo){const t=this.keyUriToKeyInfo[e];(t.mediaKeySessionContext||t.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[e]}}destroy(){this.detach();for(const e in this.keyUriToKeyInfo){const t=this.keyUriToKeyInfo[e].loader;t&&t.destroy()}this.keyUriToKeyInfo={}}createKeyLoadError(e,t=w.KEY_LOAD_ERROR,s,i,r){return new yt({type:Z.NETWORK_ERROR,details:t,fatal:!1,frag:e,response:r,error:s,networkDetails:i})}loadClear(e,t){if(this.emeController&&this.config.emeEnabled){const{sn:s,cc:i}=e;for(let r=0;r<t.length;r++){const n=t[r];if(i<=n.cc&&(s==="initSegment"||n.sn==="initSegment"||s<n.sn)){this.emeController.selectKeySystemFormat(n).then(o=>{n.setKeyFormat(o)});break}}}}load(e){return!e.decryptdata&&e.encrypted&&this.emeController?this.emeController.selectKeySystemFormat(e).then(t=>this.loadInternal(e,t)):this.loadInternal(e)}loadInternal(e,t){var s,i;t&&e.setKeyFormat(t);const r=e.decryptdata;if(!r){const c=new Error(t?`Expected frag.decryptdata to be defined after setting format ${t}`:"Missing decryption data on fragment in onKeyLoading");return Promise.reject(this.createKeyLoadError(e,w.KEY_LOAD_ERROR,c))}const n=r.uri;if(!n)return Promise.reject(this.createKeyLoadError(e,w.KEY_LOAD_ERROR,new Error(`Invalid key URI: "${n}"`)));let o=this.keyUriToKeyInfo[n];if((s=o)!=null&&s.decryptdata.key)return r.key=o.decryptdata.key,Promise.resolve({frag:e,keyInfo:o});if((i=o)!=null&&i.keyLoadPromise){var l;switch((l=o.mediaKeySessionContext)==null?void 0:l.keyStatus){case void 0:case"status-pending":case"usable":case"usable-in-future":return o.keyLoadPromise.then(c=>(r.key=c.keyInfo.decryptdata.key,{frag:e,keyInfo:o}))}}switch(o=this.keyUriToKeyInfo[n]={decryptdata:r,keyLoadPromise:null,loader:null,mediaKeySessionContext:null},r.method){case"ISO-23001-7":case"SAMPLE-AES":case"SAMPLE-AES-CENC":case"SAMPLE-AES-CTR":return r.keyFormat==="identity"?this.loadKeyHTTP(o,e):this.loadKeyEME(o,e);case"AES-128":return this.loadKeyHTTP(o,e);default:return Promise.reject(this.createKeyLoadError(e,w.KEY_LOAD_ERROR,new Error(`Key supplied with unsupported METHOD: "${r.method}"`)))}}loadKeyEME(e,t){const s={frag:t,keyInfo:e};if(this.emeController&&this.config.emeEnabled){const i=this.emeController.loadKey(s);if(i)return(e.keyLoadPromise=i.then(r=>(e.mediaKeySessionContext=r,s))).catch(r=>{throw e.keyLoadPromise=null,r})}return Promise.resolve(s)}loadKeyHTTP(e,t){const s=this.config,i=s.loader,r=new i(s);return t.keyLoader=e.loader=r,e.keyLoadPromise=new Promise((n,o)=>{const l={keyInfo:e,frag:t,responseType:"arraybuffer",url:e.decryptdata.uri},c=s.keyLoadPolicy.default,h={loadPolicy:c,timeout:c.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},u={onSuccess:(d,f,g,m)=>{const{frag:x,keyInfo:T,url:R}=g;if(!x.decryptdata||T!==this.keyUriToKeyInfo[R])return o(this.createKeyLoadError(x,w.KEY_LOAD_ERROR,new Error("after key load, decryptdata unset or changed"),m));T.decryptdata.key=x.decryptdata.key=new Uint8Array(d.data),x.keyLoader=null,T.loader=null,n({frag:x,keyInfo:T})},onError:(d,f,g,m)=>{this.resetLoader(f),o(this.createKeyLoadError(t,w.KEY_LOAD_ERROR,new Error(`HTTP Error ${d.code} loading key ${d.text}`),g,Oe({url:l.url,data:void 0},d)))},onTimeout:(d,f,g)=>{this.resetLoader(f),o(this.createKeyLoadError(t,w.KEY_LOAD_TIMEOUT,new Error("key loading timed out"),g))},onAbort:(d,f,g)=>{this.resetLoader(f),o(this.createKeyLoadError(t,w.INTERNAL_ABORTED,new Error("key loading aborted"),g))}};r.load(l,h,u)})}
41resetLoader(e){const{frag:t,keyInfo:s,url:i}=e,r=s.loader;t.keyLoader===r&&(t.keyLoader=null,s.loader=null),delete this.keyUriToKeyInfo[i],r&&r.destroy()}}function Fo(){return self.SourceBuffer||self.WebKitSourceBuffer}function Oo(){if(!Ot())return!1;const e=Fo();return!e||e.prototype&&typeof e.prototype.appendBuffer=="function"&&typeof e.prototype.remove=="function"}function Qd(){if(!Oo())return!1;const a=Ot();return typeof(a==null?void 0:a.isTypeSupported)=="function"&&(["avc1.42E01E,mp4a.40.2","av01.0.01M.08","vp09.00.50.08"].some(e=>a.isTypeSupported(Es(e,"video")))||["mp4a.40.2","fLaC"].some(e=>a.isTypeSupported(Es(e,"audio"))))}function Jd(){var a;const e=Fo();return typeof(e==null||(a=e.prototype)==null?void 0:a.changeType)=="function"}const Zd=250,Qs=2,ef=.1,tf=.05;class sf{constructor(e,t,s,i){this.config=void 0,this.media=null,this.fragmentTracker=void 0,this.hls=void 0,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=e,this.media=t,this.fragmentTracker=s,this.hls=i}destroy(){this.media=null,this.hls=this.fragmentTracker=null}poll(e,t){const{config:s,media:i,stalled:r}=this;if(i===null)return;const{currentTime:n,seeking:o}=i,l=this.seeking&&!o,c=!this.seeking&&o;if(this.seeking=o,n!==e){if(this.moved=!0,o||(this.nudgeRetry=0),r!==null){if(this.stallReported){const x=self.performance.now()-r;b.warn(`playback not stuck anymore @${n}, after ${Math.round(x)}ms`),this.stallReported=!1}this.stalled=null}return}if(c||l){this.stalled=null;return}if(i.paused&&!o||i.ended||i.playbackRate===0||!Ee.getBuffered(i).length){this.nudgeRetry=0;return}const h=Ee.bufferInfo(i,n,0),u=h.nextStart||0;if(o){const x=h.len>Qs,T=!u||t&&t.start<=n||u-n>Qs&&!this.fragmentTracker.getPartialFragment(n);if(x||T)return;this.moved=!1}if(!this.moved&&this.stalled!==null){var d;if(!(h.len>0)&&!u)return;const T=Math.max(u,h.start||0)-n,R=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,D=(R==null||(d=R.details)==null?void 0:d.live)?R.details.targetduration*2:Qs,L=this.fragmentTracker.getPartialFragment(n);if(T>0&&(T<=D||L)){i.paused||this._trySkipBufferHole(L);return}}const f=self.performance.now();if(r===null){this.stalled=f;return}const g=f-r;if(!o&&g>=Zd&&(this._reportStall(h),!this.media))return;const m=Ee.bufferInfo(i,n,s.maxBufferHole);this._tryFixBufferStall(m,g)}_tryFixBufferStall(e,t){const{config:s,fragmentTracker:i,media:r}=this;if(r===null)return;const n=r.currentTime,o=i.getPartialFragment(n);o&&(this._trySkipBufferHole(o)||!this.media)||(e.len>s.maxBufferHole||e.nextStart&&e.nextStart-n<s.maxBufferHole)&&t>s.highBufferWatchdogPeriod*1e3&&(b.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}_reportStall(e){const{hls:t,media:s,stallReported:i}=this;if(!i&&s){this.stallReported=!0;const r=new Error(`Playback stalling at @${s.currentTime} due to low buffer (${JSON.stringify(e)})`);b.warn(r.message),t.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.BUFFER_STALLED_ERROR,fatal:!1,error:r,buffer:e.len})}}_trySkipBufferHole(e){const{config:t,hls:s,media:i}=this;if(i===null)return 0;const r=i.currentTime,n=Ee.bufferInfo(i,r,0),o=r<n.start?n.start:n.nextStart;if(o){const l=n.len<=t.maxBufferHole,c=n.len>0&&n.len<1&&i.readyState<3,h=o-r;if(h>0&&(l||c)){if(h>t.maxBufferHole){const{fragmentTracker:d}=this;let f=!1;if(r===0){const g=d.getAppendedFrag(0,Q.MAIN);g&&o<g.end&&(f=!0)}if(!f){const g=e||d.getAppendedFrag(r,Q.MAIN);if(g){let m=!1,x=g.end;for(;x<o;){const T=d.getPartialFragment(x);if(T)x+=T.duration;else{m=!0;break}}if(m)return 0}}}const u=Math.max(o+tf,r+ef);if(b.warn(`skipping hole, adjusting currentTime from ${r} to ${u}`),this.moved=!0,this.stalled=null,i.currentTime=u,e&&!e.gap){const d=new Error(`fragment loaded with buffer holes, seeking from ${r} to ${u}`);s.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.BUFFER_SEEK_OVER_HOLE,fatal:!1,error:d,reason:d.message,frag:e})}return u}}return 0}_tryNudgeBuffer(){const{config:e,hls:t,media:s,nudgeRetry:i}=this;if(s===null)return;const r=s.currentTime;if(this.nudgeRetry++,i<e.nudgeMaxRetry){const n=r+(i+1)*e.nudgeOffset,o=new Error(`Nudging 'currentTime' from ${r} to ${n}`);b.warn(o.message),s.currentTime=n,t.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.BUFFER_NUDGE_ON_STALL,error:o,fatal:!1})}else{const n=new Error(`Playhead still not moving while enough data buffered @${r} after ${e.nudgeMaxRetry} nudges`);b.error(n.message),t.trigger(p.ERROR,{type:Z.MEDIA_ERROR,details:w.BUFFER_STALLED_ERROR,error:n,fatal:!0})}}}const rf=100;class nf extends br{constructor(e,t,s){super(e,t,s,"[stream-controller]",Q.MAIN),this.audioCodecSwap=!1,this.gapController=null,this.level=-1,this._forceStartLoad=!1,this.altAudio=!1,this.audioOnly=!1,this.fragPlaying=null,this.onvplaying=null,this.onvseeked=null,this.fragLastKbps=0,this.couldBacktrack=!1,this.backtrackFragment=null,this.audioCodecSwitch=!1,this.videoBuffer=null,this._registerListeners()}_registerListeners(){const{hls:e}=this;
vendor: 7,713 bytes, line 41
41e.on(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(p.MANIFEST_LOADING,this.onManifestLoading,this),e.on(p.MANIFEST_PARSED,this.onManifestParsed,this),e.on(p.LEVEL_LOADING,this.onLevelLoading,this),e.on(p.LEVEL_LOADED,this.onLevelLoaded,this),e.on(p.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.on(p.ERROR,this.onError,this),e.on(p.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.on(p.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.on(p.BUFFER_CREATED,this.onBufferCreated,this),e.on(p.BUFFER_FLUSHED,this.onBufferFlushed,this),e.on(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(p.FRAG_BUFFERED,this.onFragBuffered,this)}_unregisterListeners(){const{hls:e}=this;e.off(p.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(p.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(p.MANIFEST_LOADING,this.onManifestLoading,this),e.off(p.MANIFEST_PARSED,this.onManifestParsed,this),e.off(p.LEVEL_LOADED,this.onLevelLoaded,this),e.off(p.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.off(p.ERROR,this.onError,this),e.off(p.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.off(p.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.off(p.BUFFER_CREATED,this.onBufferCreated,this),e.off(p.BUFFER_FLUSHED,this.onBufferFlushed,this),e.off(p.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(p.FRAG_BUFFERED,this.onFragBuffered,this)}onHandlerDestroying(){this._unregisterListeners(),super.onHandlerDestroying()}startLoad(e){if(this.levels){const{lastCurrentTime:t,hls:s}=this;if(this.stopLoad(),this.setInterval(rf),this.level=-1,!this.startFragRequested){let i=s.startLevel;i===-1&&(s.config.testBandwidth&&this.levels.length>1?(i=0,this.bitrateTest=!0):i=s.firstAutoLevel),s.nextLoadLevel=i,this.level=s.loadLevel,this.loadedmetadata=!1}t>0&&e===-1&&(this.log(`Override startPosition with lastCurrentTime @${t.toFixed(3)}`),e=t),this.state=O.IDLE,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}else this._forceStartLoad=!0,this.state=O.STOPPED}stopLoad(){this._forceStartLoad=!1,super.stopLoad()}doTick(){switch(this.state){case O.WAITING_LEVEL:{const{levels:t,level:s}=this,i=t==null?void 0:t[s],r=i==null?void 0:i.details;if(r&&(!r.live||this.levelLastLoaded===i)){if(this.waitForCdnTuneIn(r))break;this.state=O.IDLE;break}else if(this.hls.nextLoadLevel!==this.level){this.state=O.IDLE;break}break}case O.FRAG_LOADING_WAITING_RETRY:{var e;const t=self.performance.now(),s=this.retryDate;if(!s||t>=s||(e=this.media)!=null&&e.seeking){const{levels:i,level:r}=this,n=i==null?void 0:i[r];this.resetStartWhenNotLoaded(n||null),this.state=O.IDLE}}break}this.state===O.IDLE&&this.doTickIdle(),this.onTickEnd()}onTickEnd(){super.onTickEnd(),this.checkBuffer(),this.checkFragmentChanged()}doTickIdle(){const{hls:e,levelLastLoaded:t,levels:s,media:i}=this;if(t===null||!i&&(this.startFragRequested||!e.config.startFragPrefetch)||this.altAudio&&this.audioOnly)return;const r=e.nextLoadLevel;if(!(s!=null&&s[r]))return;const n=s[r],o=this.getMainFwdBufferInfo();if(o===null)return;const l=this.getLevelDetails();if(l&&this._streamEnded(o,l)){const m={};this.altAudio&&(m.type="video"),this.hls.trigger(p.BUFFER_EOS,m),this.state=O.ENDED;return}e.loadLevel!==r&&e.manualLevel===-1&&this.log(`Adapting to level ${r} from level ${this.level}`),this.level=e.nextLoadLevel=r;const c=n.details;if(!c||this.state===O.WAITING_LEVEL||c.live&&this.levelLastLoaded!==n){this.level=r,this.state=O.WAITING_LEVEL;return}const h=o.len,u=this.getMaxBufferLength(n.maxBitrate);if(h>=u)return;this.backtrackFragment&&this.backtrackFragment.start>o.end&&(this.backtrackFragment=null);const d=this.backtrackFragment?this.backtrackFragment.start:o.end;let f=this.getNextFragment(d,c);if(this.couldBacktrack&&!this.fragPrevious&&f&&f.sn!=="initSegment"&&this.fragmentTracker.getState(f)!==Fe.OK){var g;const x=((g=this.backtrackFragment)!=null?g:f).sn-c.startSN,T=c.fragments[x-1];T&&f.cc===T.cc&&(f=T,this.fragmentTracker.removeFragment(T))}else this.backtrackFragment&&o.len&&(this.backtrackFragment=null);if(f&&this.isLoopLoading(f,d)){if(!f.gap){const x=this.audioOnly&&!this.altAudio?xe.AUDIO:xe.VIDEO,T=(x===xe.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;T&&this.afterBufferFlushed(T,x,Q.MAIN)}f=this.getNextFragmentLoopLoading(f,c,o,Q.MAIN,u)}f&&(f.initSegment&&!f.initSegment.data&&!this.bitrateTest&&(f=f.initSegment),this.loadFragment(f,n,d))}loadFragment(e,t,s){const i=this.fragmentTracker.getState(e);this.fragCurrent=e,i===Fe.NOT_LOADED||i===Fe.PARTIAL?e.sn==="initSegment"?this._loadInitSegment(e,t):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,t)):(this.startFragRequested=!0,super.loadFragment(e,t,s)):this.clearTrackerIfNeeded(e)}getBufferedFrag(e){return this.fragmentTracker.getBufferedFrag(e,Q.MAIN)}followingBufferedFrag(e){return e?this.getBufferedFrag(e.end+.5):null}immediateLevelSwitch(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)}nextLevelSwitch(){const{levels:e,media:t}=this;if(t!=null&&t.readyState){let s;const i=this.getAppendedFrag(t.currentTime);i&&i.start>1&&this.flushMainBuffer(0,i.start-1);const r=this.getLevelDetails();if(r!=null&&r.live){const o=this.getMainFwdBufferInfo();if(!o||o.len<r.targetduration*2)return}if(!t.paused&&e){const o=this.hls.nextLoadLevel,l=e[o],c=this.fragLastKbps;c&&this.fragCurrent?s=this.fragCurrent.duration*l.maxBitrate/(1e3*c)+1:s=0}else s=0;const n=this.getBufferedFrag(t.currentTime+s);if(n){const o=this.followingBufferedFrag(n);if(o){this.abortCurrentFrag();const l=o.maxStartPTS?o.maxStartPTS:o.start,c=o.duration,h=Math.max(n.end,l+Math.min(Math.max(c-this.config.maxFragLookUpTolerance,c*(this.couldBacktrack?.5:.125)),c*(this.couldBacktrack?.75:.25)));this.flushMainBuffer(h,Number.POSITIVE_INFINITY)}}}}abortCurrentFrag(){const e=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,e&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.state){case O.KEY_LOADING:case O.FRAG_LOADING:case O.FRAG_LOADING_WAITING_RETRY:case O.PARSING:case O.PARSED:this.state=O.IDLE;break}this.nextLoadPosition=this.getLoadPosition()}flushMainBuffer(e,t){super.flushMainBuffer(e,t,this.altAudio?"video":null)}onMediaAttached(e,t){super.onMediaAttached(e,t);const s=t.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),s.addEventListener("playing",this.onvplaying),s.addEventListener("seeked",this.onvseeked),this.gapController=new sf(this.config,s,this.fragmentTracker,this.hls)}onMediaDetaching(){const{media:e}=this;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),super.onMediaDetaching()}onMediaPlaying(){this.tick()}onMediaSeeked(){const e=this.media,t=e?e.currentTime:null;j(t)&&this.log(`Media seeked to ${t.toFixed(3)}`);const s=this.getMainFwdBufferInfo();if(s===null||s.len===0){this.warn(`Main forward buffer length on "seeked" event ${s?s.len:"empty"})`);return}this.tick()}onManifestLoading(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(p.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}onManifestParsed(e,t){let s=!1,i=!1;
vendor: 4,756 bytes, line 41
41t.levels.forEach(r=>{const n=r.audioCodec;n&&(s=s||n.indexOf("mp4a.40.2")!==-1,i=i||n.indexOf("mp4a.40.5")!==-1)}),this.audioCodecSwitch=s&&i&&!Jd(),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=t.levels,this.startFragRequested=!1}onLevelLoading(e,t){const{levels:s}=this;if(!s||this.state!==O.IDLE)return;const i=s[t.level];(!i.details||i.details.live&&this.levelLastLoaded!==i||this.waitForCdnTuneIn(i.details))&&(this.state=O.WAITING_LEVEL)}onLevelLoaded(e,t){var s;const{levels:i}=this,r=t.level,n=t.details,o=n.totalduration;if(!i){this.warn(`Levels were reset while loading level ${r}`);return}this.log(`Level ${r} loaded [${n.startSN},${n.endSN}]${n.lastPartSn?`[part-${n.lastPartSn}-${n.lastPartIndex}]`:""}, cc [${n.startCC}, ${n.endCC}] duration:${o}`);const l=i[r],c=this.fragCurrent;c&&(this.state===O.FRAG_LOADING||this.state===O.FRAG_LOADING_WAITING_RETRY)&&c.level!==t.level&&c.loader&&this.abortCurrentFrag();let h=0;if(n.live||(s=l.details)!=null&&s.live){var u;if(this.checkLiveUpdate(n),n.deltaUpdateFailed)return;h=this.alignPlaylists(n,l.details,(u=this.levelLastLoaded)==null?void 0:u.details)}if(l.details=n,this.levelLastLoaded=l,this.hls.trigger(p.LEVEL_UPDATED,{details:n,level:r}),this.state===O.WAITING_LEVEL){if(this.waitForCdnTuneIn(n))return;this.state=O.IDLE}this.startFragRequested?n.live&&this.synchronizeToLiveEdge(n):this.setStartPosition(n,h),this.tick()}_handleFragmentLoadProgress(e){var t;const{frag:s,part:i,payload:r}=e,{levels:n}=this;if(!n){this.warn(`Levels were reset while fragment load was in progress. Fragment ${s.sn} of level ${s.level} will not be buffered`);return}const o=n[s.level],l=o.details;if(!l){this.warn(`Dropping fragment ${s.sn} of level ${s.level} after level details were reset`),this.fragmentTracker.removeFragment(s);return}const c=o.videoCodec,h=l.PTSKnown||!l.live,u=(t=s.initSegment)==null?void 0:t.data,d=this._getAudioCodec(o),f=this.transmuxer=this.transmuxer||new po(this.hls,Q.MAIN,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),g=i?i.index:-1,m=g!==-1,x=new Lr(s.level,s.sn,s.stats.chunkCount,r.byteLength,g,m),T=this.initPTS[s.cc];f.push(r,u,d,c,s,i,l.totalduration,h,x,T)}onAudioTrackSwitching(e,t){const s=this.altAudio;if(!!!t.url){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;const n=this.fragCurrent;n&&(this.log("Switching to main audio track, cancel main fragment load"),n.abortRequests(),this.fragmentTracker.removeFragment(n)),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();const r=this.hls;s&&(r.trigger(p.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:null}),this.fragmentTracker.removeAllFragments()),r.trigger(p.AUDIO_TRACK_SWITCHED,t)}}onAudioTrackSwitched(e,t){const s=t.id,i=!!this.hls.audioTracks[s].url;if(i){const r=this.videoBuffer;r&&this.mediaBuffer!==r&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=r)}this.altAudio=i,this.tick()}onBufferCreated(e,t){const s=t.tracks;let i,r,n=!1;for(const o in s){const l=s[o];if(l.id==="main"){if(r=o,i=l,o==="video"){const c=s[o];c&&(this.videoBuffer=c.buffer)}}else n=!0}n&&i?(this.log(`Alternate track found, use ${r}.buffered to schedule main fragment loading`),this.mediaBuffer=i.buffer):this.mediaBuffer=this.media}onFragBuffered(e,t){const{frag:s,part:i}=t;if(s&&s.type!==Q.MAIN)return;if(this.fragContextChanged(s)){this.warn(`Fragment ${s.sn}${i?" p: "+i.index:""} of level ${s.level} finished buffering, but was aborted. state: ${this.state}`),this.state===O.PARSED&&(this.state=O.IDLE);return}const r=i?i.stats:s.stats;this.fragLastKbps=Math.round(8*r.total/(r.buffering.end-r.loading.first)),s.sn!=="initSegment"&&(this.fragPrevious=s),this.fragBufferedComplete(s,i)}onError(e,t){var s;if(t.fatal){this.state=O.ERROR;return}switch(t.details){case w.FRAG_GAP:case w.FRAG_PARSING_ERROR:case w.FRAG_DECRYPT_ERROR:case w.FRAG_LOAD_ERROR:case w.FRAG_LOAD_TIMEOUT:case w.KEY_LOAD_ERROR:case w.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(Q.MAIN,t);break;case w.LEVEL_LOAD_ERROR:case w.LEVEL_LOAD_TIMEOUT:case w.LEVEL_PARSING_ERROR:!t.levelRetry&&this.state===O.WAITING_LEVEL&&((s=t.context)==null?void 0:s.type)===ge.LEVEL&&(this.state=O.IDLE);break;case w.BUFFER_APPEND_ERROR:case w.BUFFER_FULL_ERROR:if(!t.parent||t.parent!=="main")return;if(t.details===w.BUFFER_APPEND_ERROR){this.resetLoadingState();return}this.reduceLengthAndFlushBuffer(t)&&this.flushMainBuffer(0,Number.POSITIVE_INFINITY);break;case w.INTERNAL_EXCEPTION:this.recoverWorkerError(t);break}}
41checkBuffer(){const{media:e,gapController:t}=this;if(!(!e||!t||!e.readyState)){if(this.loadedmetadata||!Ee.getBuffered(e).length){const s=this.state!==O.IDLE?this.fragCurrent:null;t.poll(this.lastCurrentTime,s)}this.lastCurrentTime=e.currentTime}}onFragLoadEmergencyAborted(){this.state=O.IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()}onBufferFlushed(e,{type:t}){if(t!==xe.AUDIO||this.audioOnly&&!this.altAudio){const s=(t===xe.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(s,t,Q.MAIN),this.tick()}}onLevelsUpdated(e,t){this.level>-1&&this.fragCurrent&&(this.level=this.fragCurrent.level),this.levels=t.levels}swapAudioCodec(){this.audioCodecSwap=!this.audioCodecSwap}seekToStartPos(){const{media:e}=this;if(!e)return;const t=e.currentTime;let s=this.startPosition;if(s>=0&&t<s){if(e.seeking){this.log(`could not seek to ${s}, already seeking at ${t}`);return}const i=Ee.getBuffered(e),n=(i.length?i.start(0):0)-s;n>0&&(n<this.config.maxBufferHole||n<this.config.maxFragLookUpTolerance)&&(this.log(`adjusting start position by ${n} to match buffer start`),s+=n,this.startPosition=s),this.log(`seek to target start position ${s} from current time ${t}`),e.currentTime=s}}_getAudioCodec(e){let t=this.config.defaultAudioCodec||e.audioCodec;return this.audioCodecSwap&&t&&(this.log("Swapping audio codec"),t.indexOf("mp4a.40.5")!==-1?t="mp4a.40.2":t="mp4a.40.5"),t}_loadBitrateTestFrag(e,t){e.bitrateTest=!0,this._doFragLoad(e,t).then(s=>{const{hls:i}=this;if(!s||this.fragContextChanged(e))return;t.fragmentError=0,this.state=O.IDLE,this.startFragRequested=!1,this.bitrateTest=!1;const r=e.stats;r.parsing.start=r.parsing.end=r.buffering.start=r.buffering.end=self.performance.now(),i.trigger(p.FRAG_LOADED,s),e.bitrateTest=!1})}_handleTransmuxComplete(e){var t;const s="main",{hls:i}=this,{remuxResult:r,chunkMeta:n}=e,o=this.getCurrentContext(n);if(!o){this.resetWhenMissingContext(n);return}const{frag:l,part:c,level:h}=o,{video:u,text:d,id3:f,initSegment:g}=r,{details:m}=h,x=this.altAudio?void 0:r.audio;if(this.fragContextChanged(l)){this.fragmentTracker.removeFragment(l);return}if(this.state=O.PARSING,g){if(g!=null&&g.tracks){const v=l.initSegment||l;this._bufferInitSegment(h,g.tracks,v,n),i.trigger(p.FRAG_PARSING_INIT_SEGMENT,{frag:v,id:s,tracks:g.tracks})}const T=g.initPTS,R=g.timescale;j(T)&&(this.initPTS[l.cc]={baseTime:T,timescale:R},i.trigger(p.INIT_PTS_FOUND,{frag:l,id:s,initPTS:T,timescale:R}))}if(u&&m&&l.sn!=="initSegment"){const T=m.fragments[l.sn-1-m.startSN],R=l.sn===m.startSN,v=!T||l.cc>T.cc;if(r.independent!==!1){const{startPTS:D,endPTS:L,startDTS:_,endDTS:k}=u;if(c)c.elementaryStreams[u.type]={startPTS:D,endPTS:L,startDTS:_,endDTS:k};else if(u.firstKeyFrame&&u.independent&&n.id===1&&!v&&(this.couldBacktrack=!0),u.dropped&&u.independent){const B=this.getMainFwdBufferInfo(),G=(B?B.end:this.getLoadPosition())+this.config.maxBufferHole,P=u.firstKeyFramePTS?u.firstKeyFramePTS:D;if(!R&&G<P-this.config.maxBufferHole&&!v){this.backtrack(l);return}else v&&(l.gap=!0);l.setElementaryStreamInfo(u.type,l.start,L,l.start,k,!0)}else R&&D>Qs&&(l.gap=!0);l.setElementaryStreamInfo(u.type,D,L,_,k),this.backtrackFragment&&(this.backtrackFragment=l),this.bufferFragmentData(u,l,c,n,R||v)}else if(R||v)l.gap=!0;else{this.backtrack(l);return}}if(x){const{startPTS:T,endPTS:R,startDTS:v,endDTS:D}=x;c&&(c.elementaryStreams[xe.AUDIO]={startPTS:T,endPTS:R,startDTS:v,endDTS:D}),l.setElementaryStreamInfo(xe.AUDIO,T,R,v,D),this.bufferFragmentData(x,l,c,n)}if(m&&f!=null&&(t=f.samples)!=null&&t.length){const T={id:s,frag:l,details:m,samples:f.samples};i.trigger(p.FRAG_PARSING_METADATA,T)}if(m&&d){const T={id:s,frag:l,details:m,samples:d.samples};i.trigger(p.FRAG_PARSING_USERDATA,T)}}_bufferInitSegment(e,t,s,i){if(this.state!==O.PARSING)return;this.audioOnly=!!t.audio&&!t.video,this.altAudio&&!this.audioOnly&&delete t.audio;const{audio:r,video:n,audiovideo:o}=t;if(r){let l=e.audioCodec;const c=navigator.userAgent.toLowerCase();if(this.audioCodecSwitch){l&&(l.indexOf("mp4a.40.5")!==-1?l="mp4a.40.2":l="mp4a.40.5");const h=r.metadata;h&&"channelCount"in h&&(h.channelCount||1)!==1&&c.indexOf("firefox")===-1&&(l="mp4a.40.5")}l&&l.indexOf("mp4a.40.5")!==-1&&c.indexOf("android")!==-1&&r.container!=="audio/mpeg"&&(l="mp4a.40.2",this.log(`Android: force audio codec to ${l}`)),e.audioCodec&&e.audioCodec!==l&&this.log(`Swapping manifest audio codec "${e.audioCodec}" for "${l}"`),r.levelCodec=l,r.id="main",this.log(`Init audio buffer, container:${r.container}, codecs[selected/level/parsed]=[${l||""}/${e.audioCodec||""}/${r.codec}]`)}n&&(n.levelCodec=e.videoCodec,n.id="main",this.log(`Init video buffer, container:${n.container}, codecs[level/parsed]=[${e.videoCodec||""}/${n.codec}]`)),o&&this.log(`Init audiovideo buffer, container:${o.container}, codecs[level/parsed]=[${e.codecs}/${o.codec}]`),this.hls.trigger(p.BUFFER_CODECS,t),Object.keys(t).forEach(l=>{const h=t[l].initSegment;h!=null&&h.byteLength&&this.hls.trigger(p.BUFFER_APPENDING,{type:l,data:h,frag:s,part:null,chunkMeta:i,parent:s.type})}),this.tickImmediate()}getMainFwdBufferInfo(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,Q.MAIN)}backtrack(e){this.couldBacktrack=!0,this.backtrackFragment=e,this.resetTransmuxer(),this.flushBufferGap(e),this.fragmentTracker.removeFragment(e),this.fragPrevious=null,this.nextLoadPosition=e.start,this.state=O.IDLE}checkFragmentChanged(){const e=this.media;let t=null;if(e&&e.readyState>1&&e.seeking===!1){const s=e.currentTime;if(Ee.isBuffered(e,s)?t=this.getAppendedFrag(s):Ee.isBuffered(e,s+.1)&&
41(t=this.getAppendedFrag(s+.1)),t){this.backtrackFragment=null;const i=this.fragPlaying,r=t.level;(!i||t.sn!==i.sn||i.level!==r)&&(this.fragPlaying=t,this.hls.trigger(p.FRAG_CHANGED,{frag:t}),(!i||i.level!==r)&&this.hls.trigger(p.LEVEL_SWITCHED,{level:r}))}}}get nextLevel(){const e=this.nextBufferedFrag;return e?e.level:-1}get currentFrag(){const e=this.media;return e?this.fragPlaying||this.getAppendedFrag(e.currentTime):null}get currentProgramDateTime(){const e=this.media;if(e){const t=e.currentTime,s=this.currentFrag;if(s&&j(t)&&j(s.programDateTime)){const i=s.programDateTime+(t-s.start)*1e3;return new Date(i)}}return null}get currentLevel(){const e=this.currentFrag;return e?e.level:-1}get nextBufferedFrag(){const e=this.currentFrag;return e?this.followingBufferedFrag(e):null}get forceStartLoad(){return this._forceStartLoad}}class ut{static get version(){return"1.5.17"}static isMSESupported(){return Oo()}static isSupported(){return Qd()}static getMediaSource(){return Ot()}static get Events(){return p}static get ErrorTypes(){return Z}static get ErrorDetails(){return w}static get DefaultConfig(){return ut.defaultConfig?ut.defaultConfig:Mo}static set DefaultConfig(e){ut.defaultConfig=e}constructor(e={}){this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this.started=!1,this._emitter=new kr,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,Wl(e.debug||!1,"Hls instance");const t=this.config=Yd(ut.DefaultConfig,e);this.userConfig=e,t.progressive&&qd(t);const{abrController:s,bufferController:i,capLevelController:r,errorController:n,fpsController:o}=t,l=new n(this),c=this.abrController=new s(this),h=this.bufferController=new i(this),u=this.capLevelController=new r(this),d=new o(this),f=new $c(this),g=new jc(this),m=t.contentSteeringController,x=m?new m(this):null,T=this.levelController=new zd(this,x),R=new Eh(this),v=new Xd(this.config),D=this.streamController=new nf(this,R,v);u.setStreamController(D),d.setStreamController(D);const L=[f,T,D];x&&L.splice(1,0,x),this.networkControllers=L;const _=[c,h,u,d,g,R];this.audioTrackController=this.createController(t.audioTrackController,L);const k=t.audioStreamController;k&&L.push(new k(this,R,v)),this.subtitleTrackController=this.createController(t.subtitleTrackController,L);const B=t.subtitleStreamController;B&&L.push(new B(this,R,v)),this.createController(t.timelineController,_),v.emeController=this.emeController=this.createController(t.emeController,_),this.cmcdController=this.createController(t.cmcdController,_),this.latencyController=this.createController(Wc,_),this.coreComponents=_,L.push(l);const G=l.onErrorOut;typeof G=="function"&&this.on(p.ERROR,G,l)}createController(e,t){if(e){const s=new e(this);return t&&t.push(s),s}return null}on(e,t,s=this){this._emitter.on(e,t,s)}once(e,t,s=this){this._emitter.once(e,t,s)}removeAllListeners(e){this._emitter.removeAllListeners(e)}off(e,t,s=this,i){this._emitter.off(e,t,s,i)}listeners(e){return this._emitter.listeners(e)}emit(e,t,s){return this._emitter.emit(e,t,s)}trigger(e,t){if(this.config.debug)return this.emit(e,e,t);try{return this.emit(e,e,t)}catch(s){if(b.error("An internal error happened while handling event "+e+'. Error message: "'+s.message+'". Here is a stacktrace:',s),!this.triggeringException){this.triggeringException=!0;const i=e===p.ERROR;this.trigger(p.ERROR,{type:Z.OTHER_ERROR,details:w.INTERNAL_EXCEPTION,fatal:i,event:e,error:s}),this.triggeringException=!1}}return!1}listenerCount(e){return this._emitter.listenerCount(e)}destroy(){b.log("destroy"),this.trigger(p.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach(t=>t.destroy()),this.networkControllers.length=0,this.coreComponents.forEac
41h(t=>t.destroy()),this.coreComponents.length=0;const e=this.config;e.xhrSetup=e.fetchSetup=void 0,this.userConfig=null}attachMedia(e){b.log("attachMedia"),this._media=e,this.trigger(p.MEDIA_ATTACHING,{media:e})}detachMedia(){b.log("detachMedia"),this.trigger(p.MEDIA_DETACHING,void 0),this._media=null}loadSource(e){this.stopLoad();const t=this.media,s=this.url,i=this.url=yr.buildAbsoluteURL(self.location.href,e,{alwaysNormalize:!0});this._autoLevelCapping=-1,this._maxHdcpLevel=null,b.log(`loadSource:${i}`),t&&s&&(s!==i||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(t)),this.trigger(p.MANIFEST_LOADING,{url:e})}startLoad(e=-1){b.log(`startLoad(${e})`),this.started=!0,this.networkControllers.forEach(t=>{t.startLoad(e)})}stopLoad(){b.log("stopLoad"),this.started=!1,this.networkControllers.forEach(e=>{e.stopLoad()})}resumeBuffering(){this.started&&this.networkControllers.forEach(e=>{"fragmentLoader"in e&&e.startLoad(-1)})}pauseBuffering(){this.networkControllers.forEach(e=>{"fragmentLoader"in e&&e.stopLoad()})}swapAudioCodec(){b.log("swapAudioCodec"),this.streamController.swapAudioCodec()}recoverMediaError(){b.log("recoverMediaError");const e=this._media;this.detachMedia(),e&&this.attachMedia(e)}removeLevel(e){this.levelController.removeLevel(e)}get levels(){const e=this.levelController.levels;return e||[]}get currentLevel(){return this.streamController.currentLevel}set currentLevel(e){b.log(`set currentLevel:${e}`),this.levelController.manualLevel=e,this.streamController.immediateLevelSwitch()}get nextLevel(){return this.streamController.nextLevel}set nextLevel(e){b.log(`set nextLevel:${e}`),this.levelController.manualLevel=e,this.streamController.nextLevelSwitch()}get loadLevel(){return this.levelController.level}set loadLevel(e){b.log(`set loadLevel:${e}`),this.levelController.manualLevel=e}get nextLoadLevel(){return this.levelController.nextLoadLevel}set nextLoadLevel(e){this.levelController.nextLoadLevel=e}get firstLevel(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)}set firstLevel(e){b.log(`set firstLevel:${e}`),this.levelController.firstLevel=e}get startLevel(){const e=this.levelController.startLevel;return e===-1&&this.abrController.forcedAutoLevel>-1?this.abrController.forcedAutoLevel:e}set startLevel(e){b.log(`set startLevel:${e}`),e!==-1&&(e=Math.max(e,this.minAutoLevel)),this.levelController.startLevel=e}get capLevelToPlayerSize(){return this.config.capLevelToPlayerSize}set capLevelToPlayerSize(e){const t=!!e;t!==this.config.capLevelToPlayerSize&&(t?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=t)}get autoLevelCapping(){return this._autoLevelCapping}get bandwidthEstimate(){const{bwEstimator:e}=this.abrController;return e?e.getEstimate():NaN}set bandwidthEstimate(e){this.abrController.resetEstimator(e)}get ttfbEstimate(){const{bwEstimator:e}=this.abrController;return e?e.getEstimateTTFB():NaN}set autoLevelCapping(e){this._autoLevelCapping!==e&&(b.log(`set autoLevelCapping:${e}`),this._autoLevelCapping=e,this.levelController.checkMaxAutoUpdated())}get maxHdcpLevel(){return this._maxHdcpLevel}set maxHdcpLevel(e){Yc(e)&&this._maxHdcpLevel!==e&&(this._maxHdcpLevel=e,this.levelController.checkMaxAutoUpdated())}get autoLevelEnabled(){return this.levelController.manualLevel===-1}get manualLevel(){return this.levelController.manualLevel}get minAutoLevel(){const{levels:e,config:{minAutoBitrate:t}}=this;if(!e)return 0;const s=e.length;for(let i=0;i<s;i++)if(e[i].maxBitrate>=t)return i;return 0}get maxAutoLevel(){const{levels:e,autoLevelCapping:t,maxHdcpLevel:s}=this;let i;if(t===-1&&e!=null&&e.length?i=e.length-1:i=t,s)for(let r=i;r--;){const n=e[r].attrs["HDCP-LEVEL"];if(n&&n<=s)return r}return i}get firstAutoLevel(){return this.abrController.firstAutoLevel}get nextAutoLevel(){return this.abrController.nextAutoLevel}set nextAutoLevel(e){this.abrController.nextAutoLevel=e}get playingDate(){return this.streamController.currentProgramDateTime}get mainForwardBufferInfo(){return this.streamController.getMainFwdBufferInfo()}setAudioOption(e){var t;return(t=this.audioTrackController)==null?void 0:t.setAudioOption(e)}setSubtitleOption(e){var t;return(t=this.subtitleTrackController)==null||t.setSubtitleOption(e),null}get allAudioTracks(){const e=this.audioTrackController;return e?e.allAudioTracks:[]}get audioTracks(){const e=this.audioTrackController;return e?e.audioTracks:[]}get audioTrack(){const e=this.audioTrackController;return e?e.audioTrack:-1}set audioTrack(e){const t=this.audioTrackController;t&&(t.audioTrack=e)}get allSubtitleTracks(){const e=this.subtitleTrackController;return e?e.allSubtitleTracks:[]}get subtitleTracks(){const e=this.subtitleTrackController;return e?e.subtitleTracks:[]}get subtitleTrack(){const e=this.subtitleTrackController;return e?e.subtitleTrack:-1}get media(){return this._media}set subtitleTrack(e){const t=this.subtitleTrackController;t&&(t.subtitleTrack=e)}get subtitleDisplay(){const e=this.subtitleTrackController;return e?e.subtitleDisplay:!1}set subtitleDisplay(e){const t=this.subtitleTrackController;t&&(t.subtitleDisplay=e)}get lowLatencyMode(){return this.config.lowLatencyMode}set lowLatencyMode(e){this.config.lowLatencyMode=e}get liveSyncPosition(){return this.latencyController.liveSyncPosition}get latency(){return this.latencyController.latency}get maxLatency(){return this.latencyController.maxLatency}get targetLatency(){return this.latencyController.targetLatency}get drift(){return this.latencyController.drift}get forceStartLoad(){return this.streamController.forceStartLoad}}ut.defaultConfig=void 0;const mr="https://logger.southernfm.com.au";async function No(){var t;const{data:a}=await Yt.auth.getSession(),e=(t=a.session)==null?void 0:t.access_token;if(!e)throw new Error("Not signed in");return e}async function pr(a,e={}){const t=await No(),s=new Headers(e.headers);return s.set("Authorization",`Bearer ${t}`),fetch(`${mr}${a}`,{...e,headers:s})}async function Lt(a,e){const t=await pr(a,e);if(!t.ok){const s=await t.text().catch(()=>"");throw new Error(`${t.status} ${t.statusText}: ${s.slice(0,200)}`)}return t.json()}const Xe={base:mr,status:()=>Lt("/api/status"),peaks:(a,e,t)=>Lt(`/api/peaks?start=${encodeURIComponent(a)}&end=${encodeURIComponent(e)}&width=${t}`),coverage:(a,e)=>Lt(`/api/coverage?start=${encodeURIComponent(a)}&end=${encodeURIComponent(e)}`),gaps:(a,e)=>Lt(`/api/gaps?start=${encodeURIComponent(a)}&end=${encodeURIComponent(e)}`),metadata:(a,e)=>Lt(`/api/metadata?start=${encodeURIComponent(a)}&end=${encodeURIComponent(e)}`),diag:(a,e,t)=>Lt(`/api/diag?start=${encodeURIComponent(a)}&end=${encodeURIComponent(e)}&width=${t}`),playlistUrl:(a,e)=>`${mr}/api/playlist.m3u8?start=${encodeURIComponent(a)}&duration=${e}`,createExport:(a,e,t)=>Lt("/api/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({start:a,end:e,format:t})}),exportStatus:a=>Lt(`/api/export/${a}`),downloadExport:async a=>{const e=await pr(`/api/export/${a}/download`);
41if(!e.ok)throw new Error(`Download failed: ${e.status}`);return e.blob()},authedFetch:pr},Js=14,ms=qt(Zi(new Date,Js-1)),af=qt(new Date),ba=600,Ji=120,of={7:7,30:30,90:90,365:365},lf={redstudio:"Studio 1 (Red)",bluestudio:"Studio 2 (Blue)"},cf=(a,e,t)=>new Date(Math.min(Math.max(a.getTime(),e.getTime()),t.getTime())),Ia=a=>{const e=a;return!!e&&(e.name==="AbortError"||/interrupted|abort/i.test(String(e.message??"")))},Ff=()=>{const{hasTabAccess:a}=kl(),[e,t]=$.useState(()=>new Date(Date.now()-ba*1e3)),[s,i]=$.useState(ba),r=$.useMemo(()=>new Date(e.getTime()+s*1e3),[e,s]),[n,o]=$.useState(null),[l,c]=$.useState(null),[h,u]=$.useState(null),[d,f]=$.useState(null),[g,m]=$.useState(!1),[x,T]=$.useState(!1),[R,v]=$.useState(null),D=$.useRef(null),L=$.useRef(null),_=$.useRef(null),k=$.useRef(0),B=$.useRef(0),G=$.useRef(0),P=$.useRef(null),U=$.useRef(null),ee=$.useRef(null),K=$.useRef(new Map),[se,ie]=$.useState(null),[Y,le]=$.useState(null),[he,V]=$.useState(!1),[H,re]=$.useState(!1),[J,de]=$.useState(null),ve=$.useRef(!1),[be,Pe]=$.useState(1),[ye,bt]=$.useState(null),$e=$.useMemo(()=>Y!=null?new Date(Y):e,[Y,e]),[De,Ss]=$.useState(null),[Ne,vs]=$.useState(null),gt=$.useRef(null),ss=$.useRef(null),[It,Or]=$.useState(!1),[Uo,Nt]=$.useState(""),[et,Bo]=$.useState(null),is=$.useRef(null),Dt=$.useRef(null),[Nr,$o]=$.useState(!1),[Ur,Br]=$.useState(""),[$r,Gr]=$.useState(!1),di=y=>{_.current=y,ie(y)},fi=y=>(ye?ye.getTime():Date.now())-y*500,As=(y,E)=>cf(y,ms,new Date(fi(E))),Le=$.useMemo(()=>{const y=getComputedStyle(document.documentElement),E=C=>`hsl(${y.getPropertyValue(C).trim()})`;return{muted:E("--muted"),background:E("--background"),primary:E("--primary"),mutedFg:E("--muted-foreground"),foreground:E("--foreground"),destructive:E("--destructive"),wave:"hsl(224 76% 33%)",amber:"hsl(38 92% 50%)",green:"hsl(142 71% 45%)",greenText:"hsl(142 71% 40%)",playhead:"hsl(0 84% 55%)"}},[]),Ut=$.useCallback((y,E)=>{var ae;const C=Math.max(0,Math.min(E,(3600-E)/2)),F=new Date(y.getTime()-C*1e3),N=new Date(y.getTime()+(E+C)*1e3),M=Math.max(600,((ae=Dt.current)==null?void 0:ae.clientWidth)??1e3),S=Math.min(8e3,Math.round(M*((E+2*C)/E)));return{bufStart:F,bufEnd:N,startIso:F.toISOString(),endIso:N.toISOString(),width:S}},[]),Kr=(y,E)=>{const C=K.current;C.set(y,{pk:E,ts:Date.now()}),C.size>80&&C.delete(C.keys().next().value)},Hr=5*60*1e3,Vr=8*1e3,jr=2*60*1e3,Go=6*1e3,rt=$.useCallback(async(y,E,C=!1)=>{const{bufStart:F,bufEnd:N,startIso:M,endIso:S,width:ae}=Ut(y,E);B.current=F.getTime(),G.current=N.getTime(),U.current={start:y.getTime(),dur:E};const z=`${M}|${S}|${ae}`,oe=K.current.get(z),fe=(oe==null?void 0:oe.pk)??null,Ie=N.getTime()>Date.now()-Hr,ue=!!oe&&(!Ie||Date.now()-oe.ts<Vr);fe?o(fe):C||m(!0),T(!0),v(null);try{const[te,pe,Te,Ge]=await Promise.allSettled([ue?Promise.resolve(fe):Xe.peaks(M,S,ae),Xe.coverage(M,S),Xe.gaps(M,S),Xe.metadata(M,S)]);if(te.status==="fulfilled"?(o(te.value),ue||Kr(z,te.value)):fe||o(null),pe.status==="fulfilled"?(c(pe.value),ee.current={start:F.getTime(),end:N.getTime()}):(c(null),ee.current=null),u(Te.status==="fulfilled"?Te.value:null),f(Ge.status==="fulfilled"?Ge.value:null),te.status==="rejected"&&pe.status==="rejected")throw te.reason}catch(te){v(te instanceof Error?te.message:"Failed to load waveform")}finally{C||m(!1),T(!1)}},[Ut]),gi=$.useCallback((y,E)=>{for(const C of E){const F=As(new Date(y-C*500),C),{startIso:N,endIso:M,width:S}=Ut(F,C),ae=`${N}|${M}|${S}`;K.current.has(ae)||Xe.peaks(N,M,S).then(z=>Kr(ae,z)).catch(()=>{})}},[Ut]),mt=$.useCallback(async(y,E)=>{const C=D.current;if(!C)return;L.current&&(L.current.destroy(),L.current=null),di(null),P.current=null,re(E);const F=Xe.playlistUrl(y.toISOString(),Ji);let N;try{N=await No()}catch(M){re(!1),v(M instanceof Error?M.message:"Not signed in");return}if(ut.isSupported()){const M=new ut({xhrSetup:S=>S.setRequestHeader("Authorization",`Bearer ${N}`),fragLoadingTimeOut:6e4,maxBufferLength:600,maxMaxBufferLength:1800});L.current=M,M.on(ut.Events.LEVEL_LOADED,(S,ae)=>{const z=ae.details.fragments,fe=(z&&z.length?z[0].programDateTime:null)??y.getTime();di(fe),k.current=ae.details.totalduration||Ji;const Ie=Math.max(0,Math.min((y.getTime()-fe)/1e3,k.current-.25));try{C.currentTime=Ie,le(y.getTime())}catch{}E?C.play().then(()=>re(!1)).catch(ue=>{re(!1),Ia(ue)||v(`Playback failed: ${(ue==null?void 0:ue.message)||ue}`)}):re(!1)}),M.on(ut.Events.ERROR,(S,ae)=>{ae.fatal&&(re(!1),v(`Playback error: ${ae.type}/${ae.details}`))}),M.loadSource(F),M.attachMedia(C)}else C.canPlayType("application/vnd.apple.mpegurl")&&(C.src=F,di(y.getTime()),E?C.play().catch(()=>{}):re(!1))},[]);$.useEffect(()=>{rt(e,s),mt(e,!1);const y=e.getTime()+s*500,E=setTimeout(()=>gi(y,[60,10,3600,21600]),800);return()=>clearTimeout(E)},[]),$.useEffect(()=>{let y=!0;const E=()=>Xe.status().then(F=>{y&&(Bo(F),F.last_segment_onair&&bt(new Date(new Date(F.last_segment_onair).getTime()+1e4)))}).catch(()=>{});E();
41const C=setInterval(E,15e3);return()=>{y=!1,clearInterval(C)}},[]),$.useEffect(()=>{const y=D.current;if(!y)return;const E=()=>{var Ie;const oe=(Ie=L.current)==null?void 0:Ie.playingDate;if(oe){le(oe.getTime());return}const fe=_.current;fe!=null&&le(fe+y.currentTime*1e3)},C=E,F=E,N=()=>V(!0),M=()=>{V(!0),re(!1)},S=()=>re(!0),ae=()=>{V(!1),re(!1)},z=()=>{const oe=_.current;if(oe==null){V(!1);return}const fe=oe+k.current*1e3;fe<Date.now()?mt(new Date(fe),!0):V(!1)};return y.addEventListener("timeupdate",C),y.addEventListener("seeked",F),y.addEventListener("play",N),y.addEventListener("playing",M),y.addEventListener("waiting",S),y.addEventListener("pause",ae),y.addEventListener("ended",z),()=>{y.removeEventListener("timeupdate",C),y.removeEventListener("seeked",F),y.removeEventListener("play",N),y.removeEventListener("playing",M),y.removeEventListener("waiting",S),y.removeEventListener("pause",ae),y.removeEventListener("ended",z)}},[mt]),$.useEffect(()=>{D.current&&(D.current.volume=be)},[be]),$.useEffect(()=>()=>{var y;(y=L.current)==null||y.destroy()},[]);const Wr=$.useCallback(async()=>{const y=_.current;if(y==null)return;const E=y+k.current*1e3;if(!(P.current===E||E>Date.now())){P.current=E;try{const C=await Xe.authedFetch(`/api/playlist.m3u8?start=${encodeURIComponent(new Date(E).toISOString())}&duration=${Ji}`);if(!C.ok)return;const F=await C.text();for(const N of F.split(` 42`)){const M=N.trim();M.startsWith("audio.mp3")&&Xe.authedFetch(`/api/${M}`).catch(()=>{})}}catch{}}},[]);$.useEffect(()=>{const y=D.current;if(!y||!he||_.current==null)return;const E=k.current-y.currentTime;E>0&&E<20&&Wr()},[Y,he,Wr]);const[mi,Ko]=$.useState("30"),[Bt,Ho]=$.useState([]),[hf,Vo]=$.useState([]),[jo,Yr]=$.useState(!0);$.useEffect(()=>{let y=!1;return(async()=>{Yr(!0);const E=Zi(new Date,of[mi]).toISOString(),[C,F]=await Promise.all([Yt.from("signage_alert_events").select("id, screen, active, message, show_name, created_at, applied, note").gte("created_at",E).order("created_at",{ascending:!1}).limit(200),Yt.rpc("get_signage_alert_stats",{_since:E})]);y||(Ho(C.data??[]),Vo(F.data??[]),Yr(!1))})(),()=>{y=!0}},[mi]);const pi=$.useMemo(()=>{const y=e.getTime(),E=r.getTime();return Bt.filter(C=>{const F=new Date(C.created_at).getTime();return F>=y&&F<=E})},[Bt,e,r]),[xi,Wo]=$.useState([]),$t=((et==null?void 0:et.stream_delay_seconds)??0)*1e3,Yo=`${Math.floor(e.getTime()/6e4)}|${s}`;$.useEffect(()=>{let y=!1;return(async()=>{const E=s*1e3+9e5,C=new Date(e.getTime()-E).toISOString(),F=new Date(r.getTime()+E).toISOString(),{data:N}=await Yt.from("song_log").select("id, display, started_at, last_seen_at").gte("started_at",C).lte("started_at",F).order("started_at",{ascending:!0}).limit(500);y||Wo(N??[])})(),()=>{y=!0}},[Yo]);const Ls=$.useMemo(()=>xi.map((E,C)=>{const F=new Date(E.started_at).getTime()-$t;let N=new Date(E.last_seen_at).getTime()-$t+45e3;const M=xi[C+1];return M&&(N=Math.min(N,new Date(M.started_at).getTime()-$t)),{id:E.id,display:E.display,a:F,b:Math.max(F+1e3,N)}}),[xi,$t]),qo=$.useCallback(y=>y==null?null:Ls.find(E=>y>=E.a&&y<=E.b)??null,[Ls]),rs=$.useMemo(()=>{const y=e.getTime(),E=r.getTime();return Ls.filter(C=>C.b>=y&&C.a<=E)},[Ls,e,r]),qr=qo(J??Y),[ns,zr]=$.useState(""),[Ct,Xr]=$.useState("all"),[Rs,Qr]=$.useState(""),[bs,Jr]=$.useState(""),[Zr,en]=$.useState([]),[zo,yi]=$.useState(!1),Xo=$.useMemo(()=>Array.from({length:Js},(y,E)=>qt(Zi(new Date,E))),[]);$.useEffect(()=>{const y=ns.trim();if(!y&&Ct==="all"){en([]),yi(!1);return}let E=!1;yi(!0);const C=setTimeout(async()=>{let F=Yt.from("song_log").select("id, display, title, artist, started_at, last_seen_at").order("started_at",{ascending:!1}).limit(300);if(y){const M=y.replace(/[%,()]/g," ");F=F.or(`display.ilike.%${M}%,title.ilike.%${M}%,artist.ilike.%${M}%`)}if(Ct!=="all"){const M=new Date(`${Ct}T00:00:00`);F=F.gte("started_at",M.toISOString()).lt("started_at",new Date(M.getTime()+864e5).toISOString())}const{data:N}=await F;E||(en(N??[]),yi(!1))},300);return()=>{E=!0,clearTimeout(C)}},[ns,Ct]);const tn=y=>{const E=y.trim().match(/^(\d{1,2}):(\d{2})$/);return E?Math.min(23,+E[1])*60+Math.min(59,+E[2]):null},Is=$.useMemo(()=>{const y=tn(Rs),E=tn(bs);return Zr.map(C=>({row:C,onair:new Date(C.started_at).getTime()-$t})).filter(({onair:C})=>{if(y==null&&E==null)return!0;const F=new Date(C),N=F.getHours()*60+F.getMinutes(),M=y??0,S=E??24*60;return M<=S?N>=M&&N<=S:N>=M||N<=S})},[Zr,Rs,bs,$t]),as=$.useMemo(()=>
42{if(!n||n.length===0)return[];const y=n.length,C=(n.value_max||127)*.05,F=new Date(n.start).getTime(),M=Math.max(1,new Date(n.end).getTime()-F)/y,S=((l==null?void 0:l.intervals)??[]).map(ue=>[new Date(ue.start_onair).getTime(),new Date(ue.end_onair).getTime()]),ae=ue=>S.some(([te,pe])=>ue>=te&&ue<=pe),z=ue=>Math.max(Math.abs(n.min[ue]),Math.abs(n.max[ue])),oe=ue=>z(ue)<=C&&ae(F+(ue+.5)*M),fe=[],Ie=new Set;for(const ue of pi){if(!ue.active)continue;const te=new Date(ue.created_at).getTime(),pe=Math.round((te-F)/M-.5),Te=Math.ceil(12e3/M);let Ge=-1;for(let nt=0;nt<=Te&&Ge<0;nt++)for(const wt of[pe-nt,pe+nt])if(wt>=0&&wt<y&&oe(wt)){Ge=wt;break}if(Ge<0||Ie.has(Ge))continue;let qe=Ge,Et=Ge;for(;qe>0&&oe(qe-1);)qe--;for(;Et<y-1&&oe(Et+1);)Et++;for(let nt=qe;nt<=Et;nt++)Ie.add(nt);(Et-qe+1)*M<2e3||fe.push({a:F+qe*M,b:F+(Et+1)*M})}return fe},[n,l,pi]),Qo=$.useMemo(()=>{if(!n||n.length===0||!l)return[];const y=n.length,E=new Date(n.start).getTime(),F=Math.max(1,new Date(n.end).getTime()-E)/y,N=oe=>l.intervals.some(fe=>oe>=new Date(fe.start_onair).getTime()&&oe<=new Date(fe.end_onair).getTime()),M=oe=>as.some(fe=>oe>=fe.a&&oe<=fe.b),S=Date.now()-jr,ae=[];let z=0;for(;z<y;)if(n.min[z]===0&&n.max[z]===0){let oe=z;for(;oe<y&&n.min[oe]===0&&n.max[oe]===0;)oe++;const fe=E+z*F,Ie=E+oe*F,ue=(fe+Ie)/2;Ie-fe>=Go&&ue>S&&N(ue)&&!M(ue)&&ae.push({a:fe,b:Ie}),z=oe}else z++;return ae},[n,l,as]),sn=$.useRef(()=>{});sn.current=y=>{var pn;const E=is.current,C=Dt.current;if(!E||!C)return;const F=window.devicePixelRatio||1,N=C.clientWidth,M=200;(E.width!==N*F||E.height!==M*F)&&(E.width=N*F,E.height=M*F,E.style.width=`${N}px`,E.style.height=`${M}px`);const S=E.getContext("2d");if(!S)return;const ae=D.current;let z=null;if(ae&&_.current!=null){const W=(pn=L.current)==null?void 0:pn.playingDate;
42z=W?W.getTime():_.current+ae.currentTime*1e3}else Y!=null&&(z=Y);if(ss.current){const{target:W,at:q}=ss.current;(z!=null&&Math.abs(z-W)<600||Date.now()-q>4e3)&&(ss.current=null,de(null))}const oe=M/2,fe=s*1e3,Ie=J??z;let ue=e.getTime();Ie!=null&&(ue=Math.min(Math.max(Ie-fe/2,ms.getTime()),fi(s))),S.setTransform(F,0,0,F,0,0),S.clearRect(0,0,N,M);const te=W=>(W-ue)/fe*N,pe=ye?te(ye.getTime()):1/0,Te=Math.max(0,Math.min(N,pe)),Ge=ue+fe,qe=ee.current,Et=!!l&&!!qe&&ue>=qe.start-1e3&&Ge<=qe.end+1e3,nt=y%1100/1100,wt=(W,q)=>{if(q-W<=1)return;S.save(),S.beginPath(),S.rect(W,0,q-W,M),S.clip(),S.fillStyle=Le.mutedFg,S.globalAlpha=.12,S.fillRect(W,0,q-W,M);const ce=Math.max(50,(q-W)*.5),Ve=W-ce+nt*(q-W+ce*2),ke=S.createLinearGradient(Ve,0,Ve+ce,0);ke.addColorStop(0,"rgba(255,255,255,0)"),ke.addColorStop(.5,"rgba(255,255,255,0.55)"),ke.addColorStop(1,"rgba(255,255,255,0)"),S.fillStyle=ke,S.globalAlpha=1,S.fillRect(Ve,0,ce,M),S.restore()};if(S.fillStyle=Le.muted,S.globalAlpha=.5,S.fillRect(0,0,N,M),S.globalAlpha=1,l){S.fillStyle=Le.background;for(const W of l.intervals){const q=Math.max(0,te(new Date(W.start_onair).getTime())),ce=Math.min(Te,te(new Date(W.end_onair).getTime()));ce>q&&S.fillRect(q,0,ce-q,M)}if(Et){const W=l.intervals.map(ke=>[te(new Date(ke.start_onair).getTime()),te(new Date(ke.end_onair).getTime())]).sort((ke,ze)=>ke[0]-ze[0]),q=[];let ce=0;for(const[ke,ze]of W)if(ke>ce&&q.push([ce,Math.min(ke,Te)]),ce=Math.max(ce,ze),ce>=Te)break;ce<Te&&q.push([ce,Te]);const Ve=te(Date.now()-jr);for(const[ke,ze]of q){const je=Math.max(0,ke),St=Math.min(Te,ze);if(St-je<2)continue;const Re=Math.min(St,Math.max(je,Ve));if(Re>je){S.save(),S.beginPath(),S.rect(je,0,Re-je,M),S.clip(),S.strokeStyle=Le.destructive,S.globalAlpha=.22,S.lineWidth=1.5;for(let Ke=je-M;Ke<Re;Ke+=9)S.beginPath(),S.moveTo(Ke,0),S.lineTo(Ke+M,M),S.stroke();S.restore(),Re-je>74&&(S.fillStyle=Le.destructive,S.globalAlpha=.85,S.font="600 10px system-ui, sans-serif",S.textAlign="center",S.fillText("no recording",(je+Re)/2,oe+3),S.textAlign="start",S.globalAlpha=1)}St>Re&&wt(Re,St)}}}for(const W of as){const q=Math.max(0,te(W.a)),ce=Math.min(N,te(W.b));ce<=q||(S.fillStyle=Le.amber,S.globalAlpha=.16,S.fillRect(q,0,Math.max(1,ce-q),M),S.globalAlpha=1)}for(const W of pi){const q=te(new Date(W.created_at).getTime());q<0||q>N||(S.strokeStyle=W.active?Le.amber:Le.mutedFg,S.globalAlpha=.9,S.beginPath(),S.moveTo(q,0),S.lineTo(q,M),S.stroke(),W.active&&(S.fillStyle=Le.amber,S.beginPath(),S.moveTo(q-4,0),S.lineTo(q+4,0),S.lineTo(q,7),S.fill()),S.globalAlpha=1)}if(n&&n.length>0){const W=n.length,q=n.value_max||127,ce=oe*.92,Ve=new Date(n.start).getTime(),ke=Math.max(1,new Date(n.end).getTime()-Ve),ze=Math.min(N+2,Te),je=Re=>te(Ve+(Re+.5)/W*ke);S.fillStyle=Le.wave,S.globalAlpha=.95,S.beginPath();let St=!1;for(let Re=0;Re<W;Re++){const Ke=je(Re);if(Ke<-2||Ke>ze)continue;const fs=oe-n.max[Re]/q*ce;St?S.lineTo(Ke,fs):(S.moveTo(Ke,fs),St=!0)}if(St){for(let Re=W-1;Re>=0;Re--){const Ke=je(Re);Ke<-2||Ke>ze||S.lineTo(Ke,oe-n.min[Re]/q*ce)}S.closePath(),S.fill()}S.globalAlpha=1;for(const Re of Qo){const Ke=Math.max(0,te(Re.a)),fs=Math.min(ze,te(Re.b));fs-Ke>1&&wt(Ke,fs)}}if(De!=null&&Ne!=null){const W=Math.min(De,Ne),q=Math.max(De,Ne),ce=Math.max(0,te(W)),Ve=Math.min(N,te(q));S.fillStyle=Le.green,S.globalAlpha=.2,S.fillRect(ce,0,Ve-ce,M),S.globalAlpha=1}S.strokeStyle=Le.green,S.fillStyle=Le.green,S.lineWidth=2;for(const W of[De,Ne]){if(W==null)continue;const q=te(W);q<-6||q>N+6||(S.beginPath(),S.moveTo(q,0),S.lineTo(q,M),S.stroke(),S.fillRect(q-3,0,6,12),S.fillRect(q-3,M-12,6,12))}if(S.lineWidth=1,rs.length){S.save(),S.setLineDash([3,3]),S.font="600 10px system-ui, sans-serif",S.textAlign="start";for(let W=0;W<rs.length;W++){const q=rs[W],ce=te(q.a);if(ce<-80||ce>N)continue;S.strokeStyle=Le.primary,S.globalAlpha=.5,S.beginPath(),S.moveTo(ce,0),S.lineTo(ce,M-16),S.stroke();const Ve=rs[W+1]?te(rs[W+1].a):N,ke=Math.min(Ve,N)-ce-8;if(ke>60){S.globalAlpha=.85,S.fillStyle=Le.primary;const ze=`⪠${q.display}`,je=Math.max(4,Math.floor(ke/5.6));S.fillText(ze.length>je?`${ze.slice(0,je-1)}â¦`:ze,Math.max(2,ce+4),11)}S.globalAlpha=1}
42S.restore()}if(h)for(const W of h.items){if(W.kind!=="gap")continue;const q=te(new Date(W.at_onair).getTime());q<0||q>N||(S.strokeStyle=Le.destructive,S.globalAlpha=.85,S.beginPath(),S.moveTo(q,0),S.lineTo(q,M),S.stroke(),S.globalAlpha=1)}if(Te<N){S.fillStyle=Le.mutedFg;for(let q=Math.max(0,Te);q<N;q+=6){const ce=y*.004,Ve=(.3+.28*Math.sin(q*.06+ce)+.18*Math.sin(q*.13-ce*1.7))*(M*.55);S.globalAlpha=.22,S.fillRect(q,oe-Ve/2,3,Math.max(2,Ve))}S.globalAlpha=1;const W=Math.max(0,Math.min(N,pe));S.strokeStyle=Le.green,S.beginPath(),S.moveTo(W,0),S.lineTo(W,M),S.stroke(),N-W>90&&(S.fillStyle=Le.greenText,S.font="600 11px system-ui, sans-serif",S.fillText("â Recording â not yet available",W+8,16))}if(Ie!=null){const W=te(Ie);W>=-6&&W<=N+6&&(S.strokeStyle=Le.playhead,S.lineWidth=2.5,S.beginPath(),S.moveTo(W,0),S.lineTo(W,M),S.stroke(),S.lineWidth=1,S.fillStyle=Le.playhead,S.beginPath(),S.moveTo(W-5,0),S.lineTo(W+5,0),S.lineTo(W,8),S.closePath(),S.fill())}S.fillStyle=Le.mutedFg,S.font="10px ui-monospace, monospace";for(let W=0;W<=4;W++){const q=new Date(ue+W/4*fe),ce=W/4*N;S.fillText(Ue(q,"HH:mm:ss"),Math.min(N-52,Math.max(2,ce-20)),M-4)}},$.useEffect(()=>{let y=0;const E=C=>{sn.current(C),y=requestAnimationFrame(E)};return y=requestAnimationFrame(E),()=>cancelAnimationFrame(y)},[]);const rn=$.useRef({act:()=>{}});$.useEffect(()=>{const y=E=>{const C=E.target;C&&(C.tagName==="INPUT"||C.tagName==="TEXTAREA"||C.isContentEditable)||rn.current.act(E)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[]);const Ds=y=>{const E=D.current;!E||_.current==null||(E.currentTime=Math.max(0,Math.min(k.current-.25,E.currentTime+y)))},Ti=$.useCallback((y,E=!1)=>{const C=D.current;if(!C)return;ye&&y.getTime()>ye.getTime()&&(y=ye);const F=!C.paused||E,N=_.current;N!=null&&y.getTime()>=N&&y.getTime()<=N+k.current*1e3?(C.currentTime=(y.getTime()-N)/1e3,le(y.getTime()),E&&C.paused&&C.play().catch(()=>{})):mt(y,F)},[mt,ye]),nn=$.useCallback(()=>{const y=D.current;if(y)if(y.paused){if(De!=null){Ti(new Date(De),!0);return}if(_.current==null){mt($e,!0);return}re(!0);const E=y.play();E&&typeof E.then=="function"&&E.then(()=>re(!1)).catch(C=>{re(!1),Ia(C)||v(`Playback failed: ${(C==null?void 0:C.message)||C}`)})}else y.pause()},[mt,$e,De,Ti]),Cs=$.useCallback((y,E)=>{const C=As(new Date(y.getTime()-s*500),s);t(C),rt(C,s),mt(y,E),gi(y.getTime(),[60,600,3600])},[s,rt,mt,gi]),os=y=>{const E=$e.getTime(),C=As(new Date(E-y*500),y);i(y),t(C),rt(C,y,!0)},Jo=()=>{Cs(ye??new Date,!1)},an=$.useRef(0);$.useEffect(()=>{if(se==null&&J==null)return;const y=J??$e.getTime(),E=As(new Date(y-s*500),s);if(t(E),gt.current)return;const C=E.getTime(),F=C+s*1e3,N=Math.max(0,(G.current-B.current-s*1e3)/2),M=Math.max(500,N*.4),S=C<B.current+M||F>G.current-M,ae=Date.now();S&&ae-an.current>500&&(an.current=ae,rt(E,s,!0))},[$e,J,se,s,rt]),$.useEffect(()=>{if(he)return;const y=setInterval(()=>{gt.current||!U.current||G.current>Date.now()-Hr&&rt(new Date(U.current.start),U.current.dur,!0)},Vr);return()=>clearInterval(y)},[he,rt]);const[ws,on]=$.useState(()=>Ue(new Date,"HH:mm:ss")),[ls,ln]=$.useState(()=>qt(new Date)),[Zo,Ei]=$.useState(!1),cn=(y,E)=>{var N;const C=E.trim().match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);if(!C){vt({title:"Invalid time",description:"Use HH:MM or HH:MM:SS (24h).",variant:"destructive"});return}const F=new Date(y);F.setHours(Math.min(23,+C[1]),Math.min(59,+C[2]),Math.min(59,+(C[3]??"0")),0),Cs(F,!(((N=D.current)==null?void 0:N.paused)??!0))},el=y=>{var C;const E=new Date(Ai(y));ln(qt(E)),on(Ue(E,"HH:mm:ss")),Cs(E,!(((C=D.current)==null?void 0:C.paused)??!0))},Si=y=>{var E;return y-(((E=is.current)==null?void 0:E.getBoundingClientRect().left)??0)},vi=()=>{var E;let y=J;if(y==null){const C=D.current;if(C&&_.current!=null){const F=(E=L.current)==null?void 0:E.playingDate;y=F?F.getTime():_.current+C.currentTime*1e3}else y=Y}return y==null?e.getTime():Math.min(Math.max(y-s*500,ms.getTime()),fi(s))},hn=y=>{var E;return vi()+y/(((E=Dt.current)==null?void 0:E.clientWidth)??1e3)*s*1e3},un=y=>{var E;
42return(y-vi())/(s*1e3)*(((E=Dt.current)==null?void 0:E.clientWidth)??1e3)},dn=y=>De!=null&&Math.abs(un(De)-y)<=9?"markIn":Ne!=null&&Math.abs(un(Ne)-y)<=9?"markOut":null,Ai=y=>ye&&y>ye.getTime()?ye.getTime():y,Li=y=>{var N,M;const E=Si(y);ss.current=null;const C=dn(E);if(C){gt.current={mode:C,startX:E,startCenterMs:0,moved:!1};return}const F=vi()+s*500;ve.current=!(((N=D.current)==null?void 0:N.paused)??!0),ve.current&&((M=D.current)==null||M.pause()),de(F),gt.current={mode:"scrub",startX:E,startCenterMs:F,moved:!1}},Ri=(y,E=!1)=>{var ae;const C=Si(y),F=gt.current;if(!F){if(E){const z=is.current;z&&(z.style.cursor=dn(C)?"ew-resize":"grab")}return}if(F.mode==="markIn"||F.mode==="markOut"){F.moved=!0;const z=Ai(hn(C));F.mode==="markIn"?Ss(z):vs(z);return}Math.abs(C-F.startX)>3&&(F.moved=!0);const N=((ae=Dt.current)==null?void 0:ae.clientWidth)??1e3,M=-((C-F.startX)/N)*s*1e3,S=(ye==null?void 0:ye.getTime())??Date.now();de(Math.min(Math.max(F.startCenterMs+M,ms.getTime()),S))},fn=y=>{const E=Ai(y);de(E),ss.current={target:E,at:Date.now()},Ti(new Date(E),ve.current),ve.current=!1},bi=y=>{const E=gt.current;gt.current=null,E&&(E.mode==="markIn"||E.mode==="markOut"||fn(E.moved?J??E.startCenterMs:hn(Si(y))))},Ii=()=>{const y=gt.current;gt.current=null,!(!y||y.mode==="markIn"||y.mode==="markOut")&&fn(J??y.startCenterMs)},cs=$.useRef({down:Li,move:Ri,up:bi,cancel:Ii});cs.current={down:Li,move:Ri,up:bi,cancel:Ii},$.useEffect(()=>{const y=is.current;if(!y)return;const E=M=>{M.touches[0]&&cs.current.down(M.touches[0].clientX)},C=M=>{M.touches[0]&&(M.preventDefault(),cs.current.move(M.touches[0].clientX))},F=M=>{var S;cs.current.up(((S=M.changedTouches[0]??M.touches[0])==null?void 0:S.clientX)??0)},N=()=>cs.current.cancel();return y.addEventListener("touchstart",E,{passive:!0}),y.addEventListener("touchmove",C,{passive:!1}),y.addEventListener("touchend",F,{passive:!0}),y.addEventListener("touchcancel",N,{passive:!0}),()=>{y.removeEventListener("touchstart",E),y.removeEventListener("touchmove",C),y.removeEventListener("touchend",F),y.removeEventListener("touchcancel",N)}},[]);const tl=()=>{Ss(null),vs(null)},me=$.useMemo(()=>{if(De==null||Ne==null)return null;const y=Math.min(De,Ne),E=Math.max(De,Ne),C=ee.current,F=C?Math.max(y,C.start):y,N=C?Math.min(E,C.end):E,M=!l||!C||C.start>y+1e3||C.end<E-1e3,S=[];if(l&&N>F){const te=l.intervals.map(Te=>[new Date(Te.start_onair).getTime(),new Date(Te.end_onair).getTime()]).sort((Te,Ge)=>Te[0]-Ge[0]);let pe=F;for(const[Te,Ge]of te)if(!(Ge<=pe)){if(Te>pe){const qe=Math.min(Te,N);qe>pe&&S.push([pe,qe])}if(pe=Math.max(pe,Math.min(Ge,N)),pe>=N)break}pe<N&&S.push([pe,N])}const ae=S.reduce((te,[pe,Te])=>te+(Te-pe),0),z=as.filter(te=>te.b>y&&te.a<E).map(te=>[Math.max(te.a,y),Math.min(te.b,E)]),oe=z.reduce((te,[pe,Te])=>te+(Te-pe),0),fe=((h==null?void 0:h.items)??[]).filter(te=>{const pe=new Date(te.at_onair).getTime();return pe>=y&&pe<=E}),Ie=Bt.filter(te=>{const pe=new Date(te.created_at).getTime();return pe>=y&&pe<=E}),ue=ae>1e3||oe>1e3||fe.length>0||Ie.length>0;return{a:y,b:E,missingMs:ae,missingSpans:S,deadMs:oe,dead:z,gapEvents:fe,alerts:Ie,partial:M,any:ue}},[De,Ne,l,as,h,Bt]),[sl,Di]=$.useState(!1),[hs,il]=$.useState("download"),rl=async(y,E)=>{const C=await Xe.createExport(new Date(y).toISOString(),new Date(E).toISOString(),"mp3");let F=C;for(let N=0;N<120&&F.status!=="done"&&F.status!=="error";N++)await new Promise(M=>setTimeout(M,1e3)),Nt(`Processing⦠(${F.status})`),F=await Xe.exportStatus(C.id);if(F.status!=="done")throw new Error(F.error||"Export did not finish");return Nt("Downloadingâ¦"),Xe.downloadExport(C.id)},nl=async(y,E)=>{const C=`broadcastlogger-${Ue(new Date(E),"yyyyMMdd-HHmmss")}.mp3`,{data:F,error:N}=await Yt.functions.invoke("sign-podcast-upload",{body:{filename:C,contentType:"audio/mpeg"}});if(N||!(F!=null&&F.url))throw new Error((N==null?void 0:N.message)||(F==null?void 0:F.error)||"Failed to get upload URL");const M=new FormData;return Object.entries(F.fields).forEach(([S,ae])=>M.append(S,ae)),M.append("file",new File([y],C,{type:"audio/mpeg"})),await new Promise((S,ae)=>{const z=new XMLHttpRequest;z.open("POST",F.url,!0),z.upload.onprogress=oe=>{oe.lengthComputable&&Nt(`Uploading⦠${Math.round(oe.loaded/oe.total*100)}%`)},z.onload=()=>{z.status>=200&&z.status<300?S():ae(new Error(`Upload failed (${z.status}): ${z.responseText.slice(0,200)}`))},z.onerror=()=>ae(new Error("Network error during upload. Check the bucket CORS configuration.")),z.send(M)}),F.publicUrl},Ci=async(y,E=!1)=>
42{if(De==null||Ne==null){vt({title:"Set both marks",description:"Use Mark In and Mark Out first."});return}const C=Math.min(De,Ne),F=Math.max(De,Ne);if(F-C<200){vt({title:"Clip too short",description:"Select at least ~0.2s."});return}if(!E&&(me!=null&&me.any)){il(y),Di(!0);return}Di(!1),Or(!0),Nt("Requesting clipâ¦");try{const N=await rl(C,F);if(y==="download"){const M=URL.createObjectURL(N),S=document.createElement("a");S.href=M,S.download=`broadcast-${Ue(new Date(C),"yyyyMMdd-HHmmss")}-to-${Ue(new Date(F),"HHmmss")}.mp3`,document.body.appendChild(S),S.click(),S.remove(),setTimeout(()=>URL.revokeObjectURL(M),5e3),vt({title:"Clip downloaded",description:S.download})}else{Nt("Uploading to podcast libraryâ¦");const M=await nl(N,C);wl({track:{title:"",url:M},broadcastDate:Ue(new Date(C),"yyyy-MM-dd"),title:`Broadcast Logger clip - ${Ue(new Date(C),"d MMM yyyy HH:mm")}â${Ue(new Date(F),"HH:mm")}`}),vt({title:"Uploaded",description:"Opening in the Post Editorâ¦"}),window.location.hash=`#tab=${a("posts")?"posts":"myshow"}`}}catch(N){vt({title:"Export failed",description:N instanceof Error?N.message:"Unknown error",variant:"destructive"})}finally{Or(!1),Nt("")}},gn=y=>{var E;Cs(new Date(y),!0),(E=Dt.current)==null||E.scrollIntoView({behavior:"smooth",block:"start"})};$.useEffect(()=>{const y=new URLSearchParams(window.location.hash.replace(/^#/,"")),E=y.get("t");if(!E)return;gn(E),y.delete("t");const C=y.toString();history.replaceState(null,"",`${window.location.pathname}${window.location.search}${C?`#${C}`:""}`)},[]),rn.current.act=y=>{const E=y.key;E===" "||y.code==="Space"?(y.preventDefault(),nn()):E==="ArrowLeft"?(y.preventDefault(),Ds(y.shiftKey?-30:-5)):E==="ArrowRight"?(y.preventDefault(),Ds(y.shiftKey?30:5)):E==="["?Ss($e.getTime()):E==="]"?vs($e.getTime()):E==="+"||E==="="?(y.preventDefault(),os(Math.max(10,Math.round(s/2)))):(E==="-"||E==="_")&&(y.preventDefault(),os(Math.min(21600,Math.round(s*2))))};const us=y=>`${Math.floor(y/60)}:${String(Math.floor(y%60)).padStart(2,"0")}`,ds=De!=null&&Ne!=null,al=ds?Math.abs(Ne-De)/1e3:0,ol=()=>{if(!n||!n.length)return null;const y=n.length,E=new Date(n.start).getTime(),C=new Date(n.end).getTime()-E;let F=0,N=0,M=0,S=0;for(;S<y;)if(n.min[S]===0&&n.max[S]===0){let z=S;for(;z<y&&n.min[z]===0&&n.max[z]===0;)z++;z-S>N&&(N=z-S,M=S),S=z}else F++,S++;const ae=new Date(E+M/y*C);return{length:y,coveragePct:Math.round(F/y*100),biggestBlankSec:+(N/y*(C/1e3)).toFixed(1),blankFrom:N>1?ae.toISOString():null,windowStart:n.start,windowEnd:n.end}},mn=()=>{var N,M;const y=ol(),E=U.current,C=E?Ut(new Date(E.start),E.dur):null,F={client:{now:new Date().toISOString(),zoom_seconds:s,playhead_onair:$e.toISOString(),request:C?{start:C.startIso,end:C.endIso,width:C.width}:null,displayed_waveform:y,coverage_intervals:((N=l==null?void 0:l.intervals)==null?void 0:N.length)??0,gap_events:((M=h==null?void 0:h.items)==null?void 0:M.length)??0},server_diag:Ur?JSON.parse(Ur):'(press "Server check")'};return JSON.stringify(F,null,2)},ll=async()=>{const y=U.current;if(y){Gr(!0);try{const E=Ut(new Date(y.start),y.dur),C=await Xe.diag(E.startIso,E.endIso,E.width);Br(JSON.stringify(C,null,2))}catch(E){Br(JSON.stringify({error:E instanceof Error?E.message:String(E)},null,2))}finally{Gr(!1)}}},cl=async()=>{try{await navigator.clipboard.writeText(mn()),vt({title:"Debug report copied",description:"Paste it here to share."})}catch{vt({title:"Copy failed",description:"Select the text and copy manually.",variant:"destructive"})}};return A.jsxs("div",{className:"space-y-6",children:[A.jsx("audio",{ref:D,className:"hidden"}),A.jsxs("div",{children:[A.jsx("h2",{className:"font-display text-2xl font-bold text-foreground",children:"Broadcast Logger"}),A.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Scrub the last ",Js," days of the off-air stream logger. Click to seek, drag to scroll, Mark In / Mark Out to clip. ",A.jsx("span",{className:"text-destructive font-medium",children:"Red"})," = recording gap;"," ",A.jsx("span",{className:"text-amber-500 font-medium",children:"amber"})," = actual dead air (from the audio), with markers for the detector on/off pulses."]})]}),A.jsx("div",{className:"flex flex-wrap items-center gap-3 text-xs",children:et?A.jsxs(A.Fragment,{children:[A.jsxs("span",{className:ks("inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full font-medium",et.capture_alive?"bg-green-100 text-green-700":"bg-destructive/10 text-destructive"),children:[et.capture_alive?A.jsx(hl,{className:"h-3.5 w-3.5"}):A.jsx(Fl,{className:"h-3.5 w-3.5"}),et.capture_alive?"Recording":"Capture down"]}),A.jsxs("span",{className:"text-muted-foreground",children:["Disk ",et.disk_percent,"%"]}),A.jsxs("span",{className:"text-muted-foreground",children:["Backlog ",et.upload_backlog]}),et.last_segment_onair&&A.jsxs("span",{className:"text-muted-foreground",children:["Latest ",Ue(new Date(et.last_segment_onair),"d MMM HH:mm:ss")]})]}):A.jsx("span",{className:"text-muted-foreground",children:"Connecting to loggerâ¦"})}),A.jsxs("div",{className:"bg-card border border-border rounded-3xl p-5 shadow-sm space-y-4",children:[A.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[A.jsxs("div",{children:[A.jsx("div",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Original Broadcast Time"}),A.jsx("div",{className:"font-mono text-4xl sm:text-5xl font-bold text-primary tabular-nums leading-tight",children:Ue($e,"HH:mm:ss")}),A.jsx("div",{className:"text-sm text-muted-foreground mt-1",children:Ue($e,"EEEE d MMMM yyyy")})]}),A.jsxs(Rl,{open:Zo,onOpenChange:Ei,children:[A.jsx(bl,{asChild:!0,children:A.jsxs(Ce,{variant:"outline",size:"sm",className:"gap-1.5 font-mono font-normal",children:[A.jsx(_l,{className:"h-3.5 w-3.5 text-muted-foreground"}),Ue(ls,"d MMM yyyy")," · ",ws||"--:--:--"]})}),A.jsxs(Il,{className:"w-auto p-3",align:"end",children:[A.jsx(Ll,{mode:"single",selected:ls,onSelect:y=>{y&&ln(qt(y))},disabled:y=>y<ms||y>af,defaultMonth:ls,initialFocus:!0,className:ks("p-0 pointer-events-auto")}),A.jsxs("div",{className:"flex items-center justify-between gap-2 mt-3 pt-3 border-t border-border",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx(ul,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),A.jsx(_s,{value:ws,onChange:y=>on(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(cn(ls,ws),Ei(!1))},placeholder:"HH:MM:SS","aria-label":"Time (24h)",className:"font-mono h-9 w-[108px]"})]}),A.jsx(Ce,{size:"sm",onClick:()=>{cn(ls,ws),Ei(!1)},disabled:g,children:"Jump"})]})]})]})]}),A.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[A.jsxs("div",{className:"flex items-center gap-1.5 text-base font-semibold text-foreground truncate",children:[A.jsx(Pl,{className:"h-4 w-4 text-primary shrink-0"}),qr?qr.display:d&&d.items.length>0?d.items[d.items.length-1].title:"No song detected at this point"]}),A.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A.jsx(Ce,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>rt(e,s),disabled:g,title:"Reload this view",children:A.jsx(Sn,{className:ks("h-4 w-4",g&&"animate-spin")})}),A.jsx("div",{className:"flex items-center gap-1 border border-border rounded-full p-1",children:[["10s",10],["1m",60],["10m",600],["1h",3600],["6h",21600]].map(([y,E])=>A.jsx(Ce,{variant:s===E?"default":"ghost",size:"sm",className:"h-7 px-3 rounded-full",onClick:()=>os(E),children:y},y))}),A.jsxs("div",{className:"flex items-center gap-1",children:[A.jsx(Ce,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>os(Math.min(21600,Math.round(s*2))),title:"Zoom out",children:A.jsx(Nl,{className:"h-4 w-4"})}),A.jsx(Ce,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>os(Math.max(10,Math.round(s/2))),title:"Zoom in",children:A.jsx(Ol,{className:"h-4 w-4"})})]})]})]}),A.jsxs("div",{ref:Dt,className:"relative rounded-xl bg-muted/40 border border-border overflow-hidden select-none",style:{height:200},children:[A.jsx("canvas",{ref:is,onMouseDown:y=>Li(y.clientX),onMouseMove:y=>Ri(y.clientX,!0),onMouseUp:y=>bi(y.clientX),onMouseLeave:Ii,className:"w-full cursor-grab active:cursor-grabbing",style:{height:200}}),(g||x&&!n)&&A.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 backdrop-blur-sm pointer-events-none",children:[A.jsx(kt,{className:"h-6 w-6 animate-spin text-primary"}),A.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading waveformâ¦"})]}),R&&!g&&A.jsx("div",{className:"absolute inset-0 flex items-center justify-center px-4 text-center text-sm text-destructive bg-background/80",children:R})]}),A.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-4",children:[A.jsx(Ce,{size:"lg",onClick:nn,className:"rounded-full h-14 w-14","aria-label":he?"Pause":"Play",children:H?A.jsx(kt,{className:"h-6 w-6 animate-spin"}):he?A.jsx(Ml,{className:"h-6 w-6"}):A.jsx(dl,{className:"h-6 w-6"})}),A.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>Ds(-5),title:"Back 5s",children:"â5s"}),A.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>Ds(5),title:"Forward 5s",children:"+5s"}),A.jsxs(Ce,{variant:"outline",size:"sm",className:"ml-auto",onClick:Jo,title:"Jump to the live edge",children:[A.jsx(Dl,{className:"h-4 w-4 mr-1"}),"Latest"]})]}),A.jsxs("div",{className:"rounded-2xl border border-border bg-muted/20 p-4 space-y-3",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx(vn,{className:"h-4 w-4 text-primary"}),A.jsx("h3",{className:"font-display text-base font-bold",children:"Clip Export"})]}),A.jsx("p",{className:"text-xs text-muted-foreground",children:"Move the playhead, then Mark In / Mark Out to set the clip edges (shaded green once both are set). Exported as MP3 320 kbps, cut losslessly on the server (byte-exact on segment boundaries)."}),A.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>Ss($e.getTime()),children:"Mark In"}),A.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>vs($e.getTime()),children:"Mark Out"}),A.jsx(Ce,{variant:"ghost",size:"sm",onClick:tl,disabled:De==null&&Ne==null,children:"Clear"}),A.jsx("div",{className:"text-xs text-muted-foreground tabular-nums ml-1",children:ds?`${us(al)} selected`:De!=null?"In set â mark out":Ne!=null?"Out set â mark in":"No clip"}),A.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[A.jsxs(Ce,{variant:"outline",onClick:()=>Ci("podcast"),disabled:It||!ds,children:[It&&hs==="podcast"?A.jsx(kt,{className:"h-4 w-4 mr-1.5 animate-spin"}):A.jsx(fl,{className:"h-4 w-4 mr-1.5"}),It&&hs==="podcast"?"Processingâ¦":"Convert to Podcast"]}),A.jsxs(Ce,{onClick:()=>Ci("download"),disabled:It||!ds,children:[It&&hs==="download"?A.jsx(kt,{className:"h-4 w-4 mr-1.5 animate-spin"}):A.jsx(vn,{className:"h-4 w-4 mr-1.5"}),It&&hs==="download"?"Processingâ¦":"Download MP3"]})]})]}),ds&&me&&(me.any||me.partial)&&A.jsxs("div",{className:`rounded-2xl border p-3 text-xs space-y-1 ${me.any?"border-amber-400/60 bg-amber-500/10":"border-border bg-muted/40"}`,children:[A.jsxs("div",{className:"flex items-center gap-1.5 font-semibold",children:[A.jsx(wi,{className:"h-3.5 w-3.5 text-amber-500"}),me.any?"Audio quality warning for this clip":"Partial quality check"]}),A.jsxs("ul",{className:"list-disc pl-5 space-y-0.5 text-muted-foreground",children:[me.missingMs>1e3&&A.jsxs("li",{children:[us(me.missingMs/1e3)," of the selection has ",A.jsx("strong",{children:"no recording"})," (",me.missingSpans.length," gap",me.missingSpans.length===1?"":"s",") â it will be missing or shortened in the export."]}
42),me.gapEvents.length>0&&A.jsxs("li",{children:[me.gapEvents.length," recorder dropout event",me.gapEvents.length===1?"":"s"," logged inside the selection."]}),me.deadMs>1e3&&A.jsxs("li",{children:[us(me.deadMs/1e3)," of near-silent / dead air detected in the waveform."]}),me.alerts.length>0&&A.jsxs("li",{children:[me.alerts.length," silence alert",me.alerts.length===1?"":"s"," were raised during this period."]}),me.partial&&A.jsx("li",{children:"Part of the selection is outside the loaded window, so it couldn't be fully checked."})]})]}),It&&A.jsxs("div",{className:"space-y-1.5",children:[A.jsx("div",{className:"text-xs text-muted-foreground",children:Uo}),A.jsx(Cl,{value:void 0,className:"h-2"})]})]})]}),A.jsx(pl,{open:sl,onOpenChange:Di,children:A.jsxs(xl,{children:[A.jsxs(yl,{children:[A.jsx(Tl,{children:"This clip may not be clean"}),A.jsx(El,{asChild:!0,children:A.jsxs("div",{className:"space-y-2 text-sm",children:[A.jsx("p",{children:"We found possible problems in the selected range:"}),A.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[me&&me.missingMs>1e3&&A.jsxs("li",{children:[us(me.missingMs/1e3)," with no recording (gap in the archive)."]}),me&&me.gapEvents.length>0&&A.jsxs("li",{children:[me.gapEvents.length," recorder dropout event(s) logged."]}),me&&me.deadMs>1e3&&A.jsxs("li",{children:[us(me.deadMs/1e3)," of dead air / near silence."]}),me&&me.alerts.length>0&&A.jsxs("li",{children:[me.alerts.length," silence alert(s) during this time."]})]}),A.jsx("p",{children:"The export will still be produced, but affected sections may be silent or missing."})]})})]}),A.jsxs(Sl,{children:[A.jsx(vl,{children:"Adjust marks"}),A.jsx(Al,{onClick:()=>Ci(hs,!0),children:"Export anyway"})]})]})}),A.jsxs("div",{className:"bg-card border border-border rounded-3xl p-5 shadow-sm space-y-4",children:[A.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-3",children:"Find a song"}),A.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[A.jsx("div",{className:"flex-1 min-w-[220px]",children:A.jsxs("div",{className:"relative",children:[A.jsx(gl,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),A.jsx(_s,{value:ns,onChange:y=>zr(y.target.value),placeholder:"Search title or artistâ¦",className:"pl-9","aria-label":"Search songs by title or artist"})]})}),A.jsxs("div",{children:[A.jsx("div",{className:"text-[11px] text-muted-foreground mb-1",children:"Day"}),A.jsxs(xn,{value:Ct,onValueChange:Xr,children:[A.jsx(yn,{className:"w-[170px]",children:A.jsx(Tn,{})}),A.jsxs(En,{children:[A.jsxs(Gt,{value:"all",children:["All ",Js," days"]}),Xo.map(y=>A.jsx(Gt,{value:Ue(y,"yyyy-MM-dd"),children:Ue(y,"EEE d MMM")},y.toISOString()))]})]})]}),A.jsxs("div",{children:[A.jsx("div",{className:"text-[11px] text-muted-foreground mb-1",children:"Show time (24h)"}),A.jsxs("div",{className:"flex items-center gap-1.5",children:[A.jsx(_s,{value:Rs,onChange:y=>Qr(y.target.value),placeholder:"06:00",className:"font-mono w-[92px]","aria-label":"From time of day"}),A.jsx("span",{className:"text-muted-foreground text-sm",children:"â"}),A.jsx(_s,{value:bs,onChange:y=>Jr(y.target.value),placeholder:"09:00",className:"font-mono w-[92px]","aria-label":"To time of day"})]})]}),(ns||Ct!=="all"||Rs||bs)&&A.jsx(Ce,{variant:"ghost",size:"sm",onClick:()=>{zr(""),Xr("all"),Qr(""),Jr("")},children:"Clear"})]}),A.jsx("div",{className:"mt-4",children:zo?A.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[A.jsx(kt,{className:"h-4 w-4 animate-spin"}),"Searchingâ¦"]}):!ns.trim()&&Ct==="all"?A.jsx("p",{className:"text-xs text-muted-foreground",children:"Type a title or artist, or pick a day, to search the detector log. Click a result to jump the archive there."}):Is.length===0?A.jsx("p",{className:"text-sm text-muted-foreground",children:"No songs match those filters."}):A.jsxs(A.Fragment,{children:[A.jsxs("div",{className:"text-xs text-muted-foreground mb-1.5",children:[Is.length," result",Is.length===1?"":"s"]}),A.jsx("div",{className:"max-h-80 overflow-y-auto rounded-xl border border-border divide-y divide-border",children:Is.map(({row:y,onair:E})=>A.jsxs("button",{type:"button",onClick:()=>el(E),className:"w-full flex items-center gap-3 px-3 py-2 text-left text-sm hover:bg-muted/60 transition-colors",children:[A.jsx("span",{className:"font-mono text-xs text-muted-foreground shrink-0 w-[132px]",children:Ue(new Date(E),"EEE d MMM HH:mm:ss")}),A.jsx("span",{className:"truncate",children:y.display})]},y.id))})]})})]}),A.jsxs("div",{className:"bg-card border border-border rounded-3xl p-5 shadow-sm",children:[A.jsxs("button",{className:"flex items-center gap-2 text-sm font-semibold text-muted-foreground hover:text-foreground",onClick:()=>$o(y=>
42!y),children:[A.jsx(wi,{className:"h-4 w-4"}),"Waveform debug ",Nr?"â¾":"â¸"]}),Nr&&A.jsxs("div",{className:"mt-4 space-y-3",children:[A.jsx("p",{className:"text-xs text-muted-foreground",children:"If a stretch looks blank, capture this: it shows the exact window requested, how much of the displayed waveform has data, the biggest blank, and (on âServer checkâ) what the server actually holds for that window â so we can tell a stale view from a real dropout."}),A.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A.jsxs(Ce,{variant:"outline",size:"sm",onClick:ll,disabled:$r,children:[$r?A.jsx(kt,{className:"h-4 w-4 mr-1.5 animate-spin"}):A.jsx(Sn,{className:"h-4 w-4 mr-1.5"}),"Server check"]}),A.jsx(Ce,{variant:"outline",size:"sm",onClick:cl,children:"Copy report"}),A.jsx(Ce,{variant:"ghost",size:"sm",onClick:()=>{K.current.clear(),U.current&&rt(new Date(U.current.start),U.current.dur)},title:"Clear the client cache and refetch",children:"Force refetch"})]}),A.jsx("pre",{className:"text-[11px] leading-snug bg-muted/40 rounded-xl p-3 overflow-auto max-h-80 whitespace-pre-wrap break-all font-mono",children:mn()})]})]}),A.jsxs("div",{className:"bg-card border border-border rounded-3xl p-5 shadow-sm space-y-5",children:[A.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx(wi,{className:"h-4 w-4 text-primary"}),A.jsx("h3",{className:"font-display text-lg font-bold",children:"Silence Alert Log"})]}),A.jsxs(xn,{value:mi,onValueChange:Ko,children:[A.jsx(yn,{className:"w-[160px]",children:A.jsx(Tn,{})}),A.jsxs(En,{children:[A.jsx(Gt,{value:"7",children:"Last 7 days"}),A.jsx(Gt,{value:"30",children:"Last 30 days"}),A.jsx(Gt,{value:"90",children:"Last 90 days"}),A.jsx(Gt,{value:"365",children:"Last 12 months"})]})]})]}),A.jsx("p",{className:"text-xs text-muted-foreground",children:"Every on/off transition reported by the studio silence detectors. Use âListenâ to jump the player to that moment."}),jo?A.jsx("div",{className:"flex items-center justify-center py-8",children:A.jsx(kt,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):Bt.length===0?A.jsx("div",{className:"rounded-xl border border-dashed border-border p-4 text-sm text-muted-foreground",children:"No events in this period."}):A.jsx("div",{className:"rounded-xl border border-border divide-y divide-border overflow-hidden max-h-80 overflow-y-auto",children:Bt.map(y=>A.jsxs("div",{className:"flex items-start justify-between gap-3 px-4 py-2.5",children:[A.jsxs("div",{className:"min-w-0",children:[A.jsxs("div",{className:"text-sm text-foreground",children:[A.jsx("span",{className:"font-medium",children:lf[y.screen]??y.screen}),y.show_name&&A.jsxs("span",{className:"text-muted-foreground",children:[" · ",y.show_name]})]}),A.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[Ue(new Date(y.created_at),"d MMM yyyy, h:mm:ss a"),y.message&&` · ${y.message}`]}),!y.applied&&A.jsxs("div",{className:"text-[11px] text-amber-600",title:y.note??void 0,children:["Ignored - out-of-order pulse",y.note?`: ${y.note}`:""]})]}),A.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[!y.applied&&A.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full bg-amber-100 text-amber-700",children:"Ignored"}),A.jsx("span",{className:ks("text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full",y.active?"bg-destructive/10 text-destructive":"bg-green-100 text-green-700"),children:y.active?"Silence":"Cleared"}),A.jsx(Ce,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:()=>gn(y.created_at),title:"Jump the player here",children:A.jsx(ml,{className:"h-3.5 w-3.5"})})]})]},y.id))})]})]})};export{of as ALERT_RANGES,lf as SCREEN_LABELS,Ff as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.