@hakit/components
Version:
A series of components to work with @hakit/core
11 lines • 341 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=Number.isFinite||function(n){return typeof n=="number"&&isFinite(n)},yr=Number.isSafeInteger||function(n){return typeof n=="number"&&Math.abs(n)<=Tr},Tr=Number.MAX_SAFE_INTEGER||9007199254740991;let Y=(function(n){return n.NETWORK_ERROR="networkError",n.MEDIA_ERROR="mediaError",n.KEY_SYSTEM_ERROR="keySystemError",n.MUX_ERROR="muxError",n.OTHER_ERROR="otherError",n})({}),D=(function(n){return n.KEY_SYSTEM_NO_KEYS="keySystemNoKeys",n.KEY_SYSTEM_NO_ACCESS="keySystemNoAccess",n.KEY_SYSTEM_NO_SESSION="keySystemNoSession",n.KEY_SYSTEM_NO_CONFIGURED_LICENSE="keySystemNoConfiguredLicense",n.KEY_SYSTEM_LICENSE_REQUEST_FAILED="keySystemLicenseRequestFailed",n.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED="keySystemServerCertificateRequestFailed",n.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED="keySystemServerCertificateUpdateFailed",n.KEY_SYSTEM_SESSION_UPDATE_FAILED="keySystemSessionUpdateFailed",n.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED="keySystemStatusOutputRestricted",n.KEY_SYSTEM_STATUS_INTERNAL_ERROR="keySystemStatusInternalError",n.KEY_SYSTEM_DESTROY_MEDIA_KEYS_ERROR="keySystemDestroyMediaKeysError",n.KEY_SYSTEM_DESTROY_CLOSE_SESSION_ERROR="keySystemDestroyCloseSessionError",n.KEY_SYSTEM_DESTROY_REMOVE_SESSION_ERROR="keySystemDestroyRemoveSessionError",n.MANIFEST_LOAD_ERROR="manifestLoadError",n.MANIFEST_LOAD_TIMEOUT="manifestLoadTimeOut",n.MANIFEST_PARSING_ERROR="manifestParsingError",n.MANIFEST_INCOMPATIBLE_CODECS_ERROR="manifestIncompatibleCodecsError",n.LEVEL_EMPTY_ERROR="levelEmptyError",n.LEVEL_LOAD_ERROR="levelLoadError",n.LEVEL_LOAD_TIMEOUT="levelLoadTimeOut",n.LEVEL_PARSING_ERROR="levelParsingError",n.LEVEL_SWITCH_ERROR="levelSwitchError",n.AUDIO_TRACK_LOAD_ERROR="audioTrackLoadError",n.AUDIO_TRACK_LOAD_TIMEOUT="audioTrackLoadTimeOut",n.SUBTITLE_LOAD_ERROR="subtitleTrackLoadError",n.SUBTITLE_TRACK_LOAD_TIMEOUT="subtitleTrackLoadTimeOut",n.FRAG_LOAD_ERROR="fragLoadError",n.FRAG_LOAD_TIMEOUT="fragLoadTimeOut",n.FRAG_DECRYPT_ERROR="fragDecryptError",n.FRAG_PARSING_ERROR="fragParsingError",n.FRAG_GAP="fragGap",n.REMUX_ALLOC_ERROR="remuxAllocError",n.KEY_LOAD_ERROR="keyLoadError",n.KEY_LOAD_TIMEOUT="keyLoadTimeOut",n.BUFFER_ADD_CODEC_ERROR="bufferAddCodecError",n.BUFFER_INCOMPATIBLE_CODECS_ERROR="bufferIncompatibleCodecsError",n.BUFFER_APPEND_ERROR="bufferAppendError",n.BUFFER_APPENDING_ERROR="bufferAppendingError",n.BUFFER_STALLED_ERROR="bufferStalledError",n.BUFFER_FULL_ERROR="bufferFullError",n.BUFFER_SEEK_OVER_HOLE="bufferSeekOverHole",n.BUFFER_NUDGE_ON_STALL="bufferNudgeOnStall",n.ASSET_LIST_LOAD_ERROR="assetListLoadError",n.ASSET_LIST_LOAD_TIMEOUT="assetListLoadTimeout",n.ASSET_LIST_PARSING_ERROR="assetListParsingError",n.INTERSTITIAL_ASSET_ITEM_ERROR="interstitialAssetItemError",n.INTERNAL_EXCEPTION="internalException",n.INTERNAL_ABORTED="aborted",n.ATTACH_MEDIA_ERROR="attachMediaError",n.UNKNOWN="unknown",n})({}),E=(function(n){return n.MEDIA_ATTACHING="hlsMediaAttaching",n.MEDIA_ATTACHED="hlsMediaAttached",n.MEDIA_DETACHING="hlsMediaDetaching",n.MEDIA_DETACHED="hlsMediaDetached",n.MEDIA_ENDED="hlsMediaEnded",n.STALL_RESOLVED="hlsStallResolved",n.BUFFER_RESET="hlsBufferReset",n.BUFFER_CODECS="hlsBufferCodecs",n.BUFFER_CREATED="hlsBufferCreated",n.BUFFER_APPENDING="hlsBufferAppending",n.BUFFER_APPENDED="hlsBufferAppended",n.BUFFER_EOS="hlsBufferEos",n.BUFFERED_TO_END="hlsBufferedToEnd",n.BUFFER_FLUSHING="hlsBufferFlushing",n.BUFFER_FLUSHED="hlsBufferFlushed",n.MANIFEST_LOADING="hlsManifestLoading",n.MANIFEST_LOADED="hlsManifestLoaded",n.MANIFEST_PARSED="hlsManifestParsed",n.LEVEL_SWITCHING="hlsLevelSwitching",n.LEVEL_SWITCHED="hlsLevelSwitched",n.LEVEL_LOADING="hlsLevelLoading",n.LEVEL_LOADED="hlsLevelLoaded",n.LEVEL_UPDATED="hlsLevelUpdated",n.LEVEL_PTS_UPDATED="hlsLevelPtsUpdated",n.LEVELS_UPDATED="hlsLevelsUpdated",n.AUDIO_TRACKS_UPDATED="hlsAudioTracksUpdated",n.AUDIO_TRACK_SWITCHING="hlsAudioTrackSwitching",n.AUDIO_TRACK_SWITCHED="hlsAudioTrackSwitched",n.AUDIO_TRACK_LOADING="hlsAudioTrackLoading",n.AUDIO_TRACK_LOADED="hlsAudioTrackLoaded",n.AUDIO_TRACK_UPDATED="hlsAudioTrackUpdated",n.SUBTITLE_TRACKS_UPDATED="hlsSubtitleTracksUpdated",n.SUBTITLE_TRACKS_CLEARED="hlsSubtitleTracksCleared",n.SUBTITLE_TRACK_SWITCH="hlsSubtitleTrackSwitch",n.SUBTITLE_TRACK_LOADING="hlsSubtitleTrackLoading",n.SUBTITLE_TRACK_LOADED="hlsSubtitleTrackLoaded",n.SUBTITLE_TRACK_UPDATED="hlsSubtitleTrackUpdated",n.SUBTITLE_FRAG_PROCESSED="hlsSubtitleFragProcessed",n.CUES_PARSED="hlsCuesParsed",n.NON_NATIVE_TEXT_TRACKS_FOUND="hlsNonNativeTextTracksFound",n.INIT_PTS_FOUND="hlsInitPtsFound",n.FRAG_LOADING="hlsFragLoading",n.FRAG_LOAD_EMERGENCY_ABORTED="hlsFragLoadEmergencyAborted",n.FRAG_LOADED="hlsFragLoaded",n.FRAG_DECRYPTED="hlsFragDecrypted",n.FRAG_PARSING_INIT_SEGMENT="hlsFragParsingInitSegment",n.FRAG_PARSING_USERDATA="hlsFragParsingUserdata",n.FRAG_PARSING_METADATA="hlsFragParsingMetadata",n.FRAG_PARSED="hlsFragParsed",n.FRAG_BUFFERED="hlsFragBuffered",n.FRAG_CHANGED="hlsFragChanged",n.FPS_DROP="hlsFpsDrop",n.FPS_DROP_LEVEL_CAPPING="hlsFpsDropLevelCapping",n.MAX_AUTO_LEVEL_UPDATED="hlsMaxAutoLevelUpdated",n.ERROR="hlsError",n.DESTROYING="hlsDestroying",n.KEY_LOADING="hlsKeyLoading",n.KEY_LOADED="hlsKeyLoaded",n.LIVE_BACK_BUFFER_REACHED="hlsLiveBackBufferReached",n.BACK_BUFFER_REACHED="hlsBackBufferReached",n.STEERING_MANIFEST_LOADED="hlsSteeringManifestLoaded",n.ASSET_LIST_LOADING="hlsAssetListLoading",n.ASSET_LIST_LOADED="hlsAssetListLoaded",n.INTERSTITIALS_UPDATED="hlsInterstitialsUpdated",n.INTERSTITIALS_BUFFERED_TO_BOUNDARY="hlsInterstitialsBufferedToBoundary",n.INTERSTITIAL_ASSET_PLAYER_CREATED="hlsInterstitialAssetPlayerCreated",n.INTERSTITIAL_STARTED="hlsInterstitialStarted",n.INTERSTITIAL_ASSET_STARTED="hlsInterstitialAssetStarted",n.INTERSTITIAL_ASSET_ENDED="hlsInterstitialAssetEnded",n.INTERSTITIAL_ASSET_ERROR="hlsInterstitialAssetError",n.INTERSTITIAL_ENDED="hlsInterstitialEnded",n.INTERSTITIALS_PRIMARY_RESUMED="hlsInterstitialsPrimaryResumed",n.PLAYOUT_LIMIT_REACHED="hlsPlayoutLimitReached",n.EVENT_CUE_ENTER="hlsEventCueEnter",n})({});var X={MANIFEST:"manifest",LEVEL:"level",AUDIO_TRACK:"audioTrack",SUBTITLE_TRACK:"subtitleTrack"},W={MAIN:"main",AUDIO:"audio",SUBTITLE:"subtitle"};class Bt{constructor(t,e=0,i=0){this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=t,this.alpha_=t?Math.exp(Math.log(.5)/t):0,this.estimate_=e,this.totalWeight_=i}sample(t,e){const i=Math.pow(this.alpha_,t);this.estimate_=e*(1-i)+i*this.estimate_,this.totalWeight_+=t}getTotalWeight(){return this.totalWeight_}getEstimate(){if(this.alpha_){const t=1-Math.pow(this.alpha_,this.totalWeight_);if(t)return this.estimate_/t}return this.estimate_}}class Sr{constructor(t,e,i,s=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_=i,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new Bt(t),this.fast_=new Bt(e),this.defaultTTFB_=s,this.ttfb_=new Bt(t)}update(t,e){const{slow_:i,fast_:s,ttfb_:r}=this;i.halfLife!==t&&(this.slow_=new Bt(t,i.getEstimate(),i.getTotalWeight())),s.halfLife!==e&&(this.fast_=new Bt(e,s.getEstimate(),s.getTotalWeight())),r.halfLife!==t&&(this.ttfb_=new Bt(t,r.getEstimate(),r.getTotalWeight()))}sample(t,e){t=Math.max(t,this.minDelayMs_);const i=8*e,s=t/1e3,r=i/s;this.fast_.sample(s,r),this.slow_.sample(s,r)}sampleTTFB(t){const e=t/1e3,i=Math.sqrt(2)*Math.exp(-Math.pow(e,2)/2);this.ttfb_.sample(i,Math.max(t,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_}get defaultEstimate(){return this.defaultEstimate_}destroy(){}}function xr(n,t,e){return(t=Ar(t))in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e,n}function at(){return at=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var i in e)({}).hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},at.apply(null,arguments)}function gi(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);t&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(n,s).enumerable})),e.push.apply(e,i)}return e}function ct(n){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?gi(Object(e),!0).forEach(function(i){xr(n,i,e[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):gi(Object(e)).forEach(function(i){Object.defineProperty(n,i,Object.getOwnPropertyDescriptor(e,i))})}return n}function Lr(n,t){if(typeof n!="object"||!n)return n;var e=n[Symbol.toPrimitive];if(e!==void 0){var i=e.call(n,t);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(n)}function Ar(n){var t=Lr(n,"string");return typeof t=="symbol"?t:t+""}class It{constructor(t,e){this.trace=void 0,this.debug=void 0,this.log=void 0,this.warn=void 0,this.info=void 0,this.error=void 0;const i=`[${t}]:`;this.trace=Ct,this.debug=e.debug.bind(null,i),this.log=e.log.bind(null,i),this.warn=e.warn.bind(null,i),this.info=e.info.bind(null,i),this.error=e.error.bind(null,i)}}const Ct=function(){},Rr={trace:Ct,debug:Ct,log:Ct,warn:Ct,info:Ct,error:Ct};function Ge(){return at({},Rr)}function br(n,t){const e=self.console[n];return e?e.bind(self.console,`${t?"["+t+"] ":""}[${n}] >`):Ct}function mi(n,t,e){return t[n]?t[n].bind(t):br(n,e)}const Ve=Ge();function Ir(n,t,e){const i=Ge();if(typeof console=="object"&&n===!0||typeof n=="object"){const s=["debug","log","info","warn","error"];s.forEach(r=>{i[r]=mi(r,n,e)});try{i.log(`Debug logs enabled for "${t}" in hls.js version 1.6.13`)}catch{return Ge()}s.forEach(r=>{Ve[r]=mi(r,n)})}else at(Ve,i);return i}const J=Ve;function ms(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Re,pi;function Dr(){return pi||(pi=1,Re={}),Re}var wt=Dr(),Mt=ms(wt);function bt(n=!0){return typeof self>"u"?void 0:(n||!self.MediaSource)&&self.ManagedMediaSource||self.MediaSource||self.WebKitMediaSource}function Cr(n){return typeof self<"u"&&n===self.ManagedMediaSource}function _r(n,t){const e=Object.keys(n),i=Object.keys(t),s=e.length,r=i.length;return!s||!r||s===r&&!e.some(a=>i.indexOf(a)===-1)}function mt(n,t=!1){if(typeof TextDecoder<"u"){const l=new TextDecoder("utf-8").decode(n);if(t){const d=l.indexOf("\0");return d!==-1?l.substring(0,d):l}return l.replace(/\0/g,"")}const e=n.length;let i,s,r,a="",o=0;for(;o<e;){if(i=n[o++],i===0&&t)return a;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:a+=String.fromCharCode(i);break;case 12:case 13:s=n[o++],a+=String.fromCharCode((i&31)<<6|s&63);break;case 14:s=n[o++],r=n[o++],a+=String.fromCharCode((i&15)<<12|(s&63)<<6|(r&63)<<0);break}}return a}function Xt(n){let t="";for(let e=0;e<n.length;e++){let i=n[e].toString(16);i.length<2&&(i="0"+i),t+=i}return t}function ps(n){return Uint8Array.from(n.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer}var be={exports:{}},Ei;function Pr(){return Ei||(Ei=1,(function(n,t){(function(e){var i=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,s=/^(?=([^\/?#]*))\1([^]*)$/,r=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,o={buildAbsoluteURL:function(u,l,d){if(d=d||{},u=u.trim(),l=l.trim(),!l){if(!d.alwaysNormalize)return u;var h=o.parseURL(u);if(!h)throw new Error("Error trying to parse base URL.");return h.path=o.normalizePath(h.path),o.buildURLFromParts(h)}var c=o.parseURL(l);if(!c)throw new Error("Error trying to parse relative URL.");if(c.scheme)return d.alwaysNormalize?(c.path=o.normalizePath(c.path),o.buildURLFromParts(c)):l;var f=o.parseURL(u);if(!f)throw new Error("Error trying to parse base URL.");if(!f.netLoc&&f.path&&f.path[0]!=="/"){var g=s.exec(f.path);f.netLoc=g[1],f.path=g[2]}f.netLoc&&!f.path&&(f.path="/");var p={scheme:f.scheme,netLoc:c.netLoc,path:null,params:c.params,query:c.query,fragment:c.fragment};if(!c.netLoc&&(p.netLoc=f.netLoc,c.path[0]!=="/"))if(!c.path)p.path=f.path,c.params||(p.params=f.params,c.query||(p.query=f.query));else{var m=f.path,y=m.substring(0,m.lastIndexOf("/")+1)+c.path;p.path=o.normalizePath(y)}return p.path===null&&(p.path=d.alwaysNormalize?o.normalizePath(c.path):c.path),o.buildURLFromParts(p)},parseURL:function(u){var l=i.exec(u);return l?{scheme:l[1]||"",netLoc:l[2]||"",path:l[3]||"",params:l[4]||"",query:l[5]||"",fragment:l[6]||""}:null},normalizePath:function(u){for(u=u.split("").reverse().join("").replace(r,"");u.length!==(u=u.replace(a,"")).length;);return u.split("").reverse().join("")},buildURLFromParts:function(u){return u.scheme+u.netLoc+u.path+u.params+u.query+u.fragment}};n.exports=o})()})(be)),be.exports}var Ze=Pr();class xe{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 et={AUDIO:"audio",VIDEO:"video",AUDIOVIDEO:"audiovideo"};class Je{constructor(t){this._byteRange=null,this._url=null,this._stats=null,this._streams=null,this.base=void 0,this.relurl=void 0,typeof t=="string"&&(t={url:t}),this.base=t,kr(this,"stats")}setByteRange(t,e){const i=t.split("@",2);let s;i.length===1?s=e?.byteRangeEndOffset||0:s=parseInt(i[1]),this._byteRange=[s,parseInt(i[0])+s]}get baseurl(){return this.base.url}get byteRange(){return this._byteRange===null?[]:this._byteRange}get byteRangeStartOffset(){return this.byteRange[0]}get byteRangeEndOffset(){return this.byteRange[1]}get elementaryStreams(){return this._streams===null&&(this._streams={[et.AUDIO]:null,[et.VIDEO]:null,[et.AUDIOVIDEO]:null}),this._streams}set elementaryStreams(t){this._streams=t}get hasStats(){return this._stats!==null}get hasStreams(){return this._streams!==null}get stats(){return this._stats===null&&(this._stats=new xe),this._stats}set stats(t){this._stats=t}get url(){return!this._url&&this.baseurl&&this.relurl&&(this._url=Ze.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""}set url(t){this._url=t}clearElementaryStreamInfo(){const{elementaryStreams:t}=this;t[et.AUDIO]=null,t[et.VIDEO]=null,t[et.AUDIOVIDEO]=null}}function ft(n){return n.sn!=="initSegment"}class he extends Je{constructor(t,e){super(e),this._decryptdata=null,this._programDateTime=null,this._ref=null,this._bitrate=void 0,this.rawProgramDateTime=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.playlistOffset=0,this.deltaPTS=void 0,this.maxStartPTS=void 0,this.minEndPTS=void 0,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=t}get byteLength(){if(this.hasStats){const t=this.stats.total;if(t)return t}if(this.byteRange.length){const t=this.byteRange[0],e=this.byteRange[1];if(B(t)&&B(e))return e-t}return null}get bitrate(){return this.byteLength?this.byteLength*8/this.duration:this._bitrate?this._bitrate:null}set bitrate(t){this._bitrate=t}get decryptdata(){var t;const{levelkeys:e}=this;if(!e||e.NONE)return null;if(e.identity)this._decryptdata||(this._decryptdata=e.identity.getDecryptData(this.sn));else if(!((t=this._decryptdata)!=null&&t.keyId)){const i=Object.keys(e);if(i.length===1){const s=this._decryptdata=e[i[0]]||null;s&&(this._decryptdata=s.getDecryptData(this.sn,e))}}return this._decryptdata}get end(){return this.start+this.duration}get endProgramDateTime(){if(this.programDateTime===null)return null;const t=B(this.duration)?this.duration:0;return this.programDateTime+t*1e3}get encrypted(){var t;if((t=this._decryptdata)!=null&&t.encrypted)return!0;if(this.levelkeys){var e;const i=Object.keys(this.levelkeys),s=i.length;if(s>1||s===1&&(e=this.levelkeys[i[0]])!=null&&e.encrypted)return!0}return!1}get programDateTime(){return this._programDateTime===null&&this.rawProgramDateTime&&(this.programDateTime=Date.parse(this.rawProgramDateTime)),this._programDateTime}set programDateTime(t){if(!B(t)){this._programDateTime=this.rawProgramDateTime=null;return}this._programDateTime=t}get ref(){return ft(this)?(this._ref||(this._ref={base:this.base,start:this.start,duration:this.duration,sn:this.sn,programDateTime:this.programDateTime}),this._ref):null}addStart(t){this.setStart(this.start+t)}setStart(t){this.start=t,this._ref&&(this._ref.start=t)}setDuration(t){this.duration=t,this._ref&&(this._ref.duration=t)}setKeyFormat(t){const e=this.levelkeys;if(e){var i;const s=e[t];s&&!((i=this._decryptdata)!=null&&i.keyId)&&(this._decryptdata=s.getDecryptData(this.sn,e))}}abortRequests(){var t,e;(t=this.loader)==null||t.abort(),(e=this.keyLoader)==null||e.abort()}setElementaryStreamInfo(t,e,i,s,r,a=!1){const{elementaryStreams:o}=this,u=o[t];if(!u){o[t]={startPTS:e,endPTS:i,startDTS:s,endDTS:r,partial:a};return}u.startPTS=Math.min(u.startPTS,e),u.endPTS=Math.max(u.endPTS,i),u.startDTS=Math.min(u.startDTS,s),u.endDTS=Math.max(u.endDTS,r)}}class Es extends Je{constructor(t,e,i,s,r){super(i),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.duration=t.decimalFloatingPoint("DURATION"),this.gap=t.bool("GAP"),this.independent=t.bool("INDEPENDENT"),this.relurl=t.enumeratedString("URI"),this.fragment=e,this.index=s;const a=t.enumeratedString("BYTERANGE");a&&this.setByteRange(a,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:t}=this;return!!(t.audio||t.video||t.audiovideo)}}function vs(n,t){const e=Object.getPrototypeOf(n);if(e){const i=Object.getOwnPropertyDescriptor(e,t);return i||vs(e,t)}}function kr(n,t){const e=vs(n,t);e&&(e.enumerable=!0,Object.defineProperty(n,t,e))}const vi=Math.pow(2,32)-1,Or=[].push,ys={video:1,audio:2,id3:3,text:4};function rt(n){return String.fromCharCode.apply(null,n)}function Ts(n,t){const e=n[t]<<8|n[t+1];return e<0?65536+e:e}function K(n,t){const e=Ss(n,t);return e<0?4294967296+e:e}function yi(n,t){let e=K(n,t);return e*=Math.pow(2,32),e+=K(n,t+4),e}function Ss(n,t){return n[t]<<24|n[t+1]<<16|n[t+2]<<8|n[t+3]}function Fr(n){const t=n.byteLength;for(let e=0;e<t;){const i=K(n,e);if(i>8&&n[e+4]===109&&n[e+5]===111&&n[e+6]===111&&n[e+7]===102)return!0;e=i>1?e+i:t}return!1}function j(n,t){const e=[];if(!t.length)return e;const i=n.byteLength;for(let s=0;s<i;){const r=K(n,s),a=rt(n.subarray(s+4,s+8)),o=r>1?s+r:i;if(a===t[0])if(t.length===1)e.push(n.subarray(s+8,o));else{const u=j(n.subarray(s+8,o),t.slice(1));u.length&&Or.apply(e,u)}s=o}return e}function wr(n){const t=[],e=n[0];let i=8;const s=K(n,i);i+=4;let r=0,a=0;e===0?(r=K(n,i),a=K(n,i+4),i+=8):(r=yi(n,i),a=yi(n,i+8),i+=16),i+=2;let o=n.length+a;const u=Ts(n,i);i+=2;for(let l=0;l<u;l++){let d=i;const h=K(n,d);d+=4;const c=h&2147483647;if((h&2147483648)>>>31===1)return J.warn("SIDX has hierarchical references (not supported)"),null;const g=K(n,d);d+=4,t.push({referenceSize:c,subsegmentDuration:g,info:{duration:g/s,start:o,end:o+c-1}}),o+=c,d+=4,i=d}return{earliestPresentationTime:r,timescale:s,version:e,referencesCount:u,references:t}}function xs(n){const t=[],e=j(n,["moov","trak"]);for(let s=0;s<e.length;s++){const r=e[s],a=j(r,["tkhd"])[0];if(a){let o=a[0];const u=K(a,o===0?12:20),l=j(r,["mdia","mdhd"])[0];if(l){o=l[0];const d=K(l,o===0?12:20),h=j(r,["mdia","hdlr"])[0];if(h){const c=rt(h.subarray(8,12)),f={soun:et.AUDIO,vide:et.VIDEO}[c],g=j(r,["mdia","minf","stbl","stsd"])[0],p=Mr(g);f?(t[u]={timescale:d,type:f,stsd:p},t[f]=ct({timescale:d,id:u},p)):t[u]={timescale:d,type:c,stsd:p}}}}}return j(n,["moov","mvex","trex"]).forEach(s=>{const r=K(s,4),a=t[r];a&&(a.default={duration:K(s,12),flags:K(s,20)})}),t}function Mr(n){const t=n.subarray(8),e=t.subarray(86),i=rt(t.subarray(4,8));let s=i,r;const a=i==="enca"||i==="encv";if(a){const l=j(t,[i])[0].subarray(i==="enca"?28:78);j(l,["sinf"]).forEach(h=>{const c=j(h,["schm"])[0];if(c){const f=rt(c.subarray(4,8));if(f==="cbcs"||f==="cenc"){const g=j(h,["frma"])[0];g&&(s=rt(g))}}})}const o=s;switch(s){case"avc1":case"avc2":case"avc3":case"avc4":{const u=j(e,["avcC"])[0];u&&u.length>3&&(s+="."+se(u[1])+se(u[2])+se(u[3]),r=ie(o==="avc1"?"dva1":"dvav",e));break}case"mp4a":{const u=j(t,[i])[0],l=j(u.subarray(28),["esds"])[0];if(l&&l.length>7){let d=4;if(l[d++]!==3)break;d=Ie(l,d),d+=2;const h=l[d++];if(h&128&&(d+=2),h&64&&(d+=l[d++]),l[d++]!==4)break;d=Ie(l,d);const c=l[d++];if(c===64)s+="."+se(c);else break;if(d+=12,l[d++]!==5)break;d=Ie(l,d);const f=l[d++];let g=(f&248)>>3;g===31&&(g+=1+((f&7)<<3)+((l[d]&224)>>5)),s+="."+g}break}case"hvc1":case"hev1":{const u=j(e,["hvcC"])[0];if(u&&u.length>12){const l=u[1],d=["","A","B","C"][l>>6],h=l&31,c=K(u,2),f=(l&32)>>5?"H":"L",g=u[12],p=u.subarray(6,12);s+="."+d+h,s+="."+Nr(c).toString(16).toUpperCase(),s+="."+f+g;let m="";for(let y=p.length;y--;){const T=p[y];(T||m)&&(m="."+T.toString(16).toUpperCase()+m)}s+=m}r=ie(o=="hev1"?"dvhe":"dvh1",e);break}case"dvh1":case"dvhe":case"dvav":case"dva1":case"dav1":{s=ie(s,e)||s;break}case"vp09":{const u=j(e,["vpcC"])[0];if(u&&u.length>6){const l=u[4],d=u[5],h=u[6]>>4&15;s+="."+yt(l)+"."+yt(d)+"."+yt(h)}break}case"av01":{const u=j(e,["av1C"])[0];if(u&&u.length>2){const l=u[1]>>>5,d=u[1]&31,h=u[2]>>>7?"H":"M",c=(u[2]&64)>>6,f=(u[2]&32)>>5,g=l===2&&c?f?12:10:c?10:8,p=(u[2]&16)>>4,m=(u[2]&8)>>3,y=(u[2]&4)>>2,T=u[2]&3;s+="."+l+"."+yt(d)+h+"."+yt(g)+"."+p+"."+m+y+T+"."+yt(1)+"."+yt(1)+"."+yt(1)+"."+0,r=ie("dav1",e)}break}}return{codec:s,encrypted:a,supplemental:r}}function ie(n,t){const e=j(t,["dvvC"]),i=e.length?e[0]:j(t,["dvcC"])[0];if(i){const s=i[2]>>1&127,r=i[2]<<5&32|i[3]>>3&31;return n+"."+yt(s)+"."+yt(r)}}function Nr(n){let t=0;for(let e=0;e<32;e++)t|=(n>>e&1)<<31-e;return t>>>0}function Ie(n,t){const e=t+5;for(;n[t++]&128&&t<e;);return t}function se(n){return("0"+n.toString(16).toUpperCase()).slice(-2)}function yt(n){return(n<10?"0":"")+n}function Br(n,t){if(!n||!t)return;const e=t.keyId;e&&t.isCommonEncryption&&Ls(n,(i,s)=>{const r=i.subarray(8,24);r.some(a=>a!==0)||(J.log(`[eme] Patching keyId in 'enc${s?"a":"v"}>sinf>>tenc' box: ${Xt(r)} -> ${Xt(e)}`),i.set(e,8))})}function $r(n){const t=[];return Ls(n,e=>t.push(e.subarray(8,24))),t}function Ls(n,t){j(n,["moov","trak"]).forEach(i=>{const s=j(i,["mdia","minf","stbl","stsd"])[0];if(!s)return;const r=s.subarray(8);let a=j(r,["enca"]);const o=a.length>0;o||(a=j(r,["encv"])),a.forEach(u=>{const l=o?u.subarray(28):u.subarray(78);j(l,["sinf"]).forEach(h=>{const c=Ur(h);c&&t(c,o)})})})}function Ur(n){const t=j(n,["schm"])[0];if(t){const e=rt(t.subarray(4,8));if(e==="cbcs"||e==="cenc"){const i=j(n,["schi","tenc"])[0];if(i)return i}}}function Gr(n,t,e){const i={},s=j(n,["moof","traf"]);for(let r=0;r<s.length;r++){const a=s[r],o=j(a,["tfhd"])[0],u=K(o,4),l=t[u];if(!l)continue;i[u]||(i[u]={start:NaN,duration:0,sampleCount:0,timescale:l.timescale,type:l.type});const d=i[u],h=j(a,["tfdt"])[0];if(h){const v=h[0];let S=K(h,4);v===1&&(S===vi?e.warn("[mp4-demuxer]: Ignoring assumed invalid signed 64-bit track fragment decode time"):(S*=vi+1,S+=K(h,8))),B(S)&&(!B(d.start)||S<d.start)&&(d.start=S)}const c=l.default,f=K(o,0)|c?.flags;let g=c?.duration||0;f&8&&(f&2?g=K(o,12):g=K(o,8));const p=j(a,["trun"]);let m=d.start||0,y=0,T=g;for(let v=0;v<p.length;v++){const S=p[v],A=K(S,4),C=d.sampleCount;d.sampleCount+=A;const x=S[3]&1,R=S[3]&4,b=S[2]&1,I=S[2]&2,_=S[2]&4,w=S[2]&8;let $=8,V=A;for(x&&($+=4),R&&A&&(!(S[$+1]&1)&&d.keyFrameIndex===void 0&&(d.keyFrameIndex=C),$+=4,b?(T=K(S,$),$+=4):T=g,I&&($+=4),w&&($+=4),m+=T,y+=T,V--);V--;)b?(T=K(S,$),$+=4):T=g,I&&($+=4),_&&(S[$+1]&1||d.keyFrameIndex===void 0&&(d.keyFrameIndex=d.sampleCount-(V+1),d.keyFrameStart=m),$+=4),w&&($+=4),m+=T,y+=T;!y&&g&&(y+=g*A)}d.duration+=y}if(!Object.keys(i).some(r=>i[r].duration)){let r=1/0,a=0;const o=j(n,["sidx"]);for(let u=0;u<o.length;u++){const l=wr(o[u]);if(l!=null&&l.references){r=Math.min(r,l.earliestPresentationTime/l.timescale);const d=l.references.reduce((h,c)=>h+c.info.duration||0,0);a=Math.max(a,d+l.earliestPresentationTime/l.timescale)}}a&&B(a)&&Object.keys(i).forEach(u=>{i[u].duration||(i[u].duration=a*i[u].timescale-i[u].start)})}return i}function Vr(n){const t={valid:null,remainder:null},e=j(n,["moof"]);if(e.length<2)return t.remainder=n,t;const i=e[e.length-1];return t.valid=n.slice(0,i.byteOffset-8),t.remainder=n.slice(i.byteOffset-8),t}function pt(n,t){const e=new Uint8Array(n.length+t.length);return e.set(n),e.set(t,n.length),e}function Ti(n,t){const e=[],i=t.samples,s=t.timescale,r=t.id;let a=!1;return j(i,["moof"]).map(u=>{const l=u.byteOffset-8;j(u,["traf"]).map(h=>{const c=j(h,["tfdt"]).map(f=>{const g=f[0];let p=K(f,4);return g===1&&(p*=Math.pow(2,32),p+=K(f,8)),p/s})[0];return c!==void 0&&(n=c),j(h,["tfhd"]).map(f=>{const g=K(f,4),p=K(f,0)&16777215,m=(p&1)!==0,y=(p&2)!==0,T=(p&8)!==0;let v=0;const S=(p&16)!==0;let A=0;const C=(p&32)!==0;let x=8;g===r&&(m&&(x+=8),y&&(x+=4),T&&(v=K(f,x),x+=4),S&&(A=K(f,x),x+=4),C&&(x+=4),t.type==="video"&&(a=ti(t.codec)),j(h,["trun"]).map(R=>{const b=R[0],I=K(R,0)&16777215,_=(I&1)!==0;let w=0;const $=(I&4)!==0,V=(I&256)!==0;let N=0;const P=(I&512)!==0;let G=0;const M=(I&1024)!==0,U=(I&2048)!==0;let H=0;const O=K(R,4);let F=8;_&&(w=K(R,F),F+=4),$&&(F+=4);let z=w+l;for(let Z=0;Z<O;Z++){if(V?(N=K(R,F),F+=4):N=v,P?(G=K(R,F),F+=4):G=A,M&&(F+=4),U&&(b===0?H=K(R,F):H=Ss(R,F),F+=4),t.type===et.VIDEO){let Q=0;for(;Q<G;){const it=K(i,z);if(z+=4,Hr(a,i[z])){const Et=i.subarray(z,z+it);As(Et,a?2:1,n+H/s,e)}z+=it,Q+=it+4}}n+=N/s}}))})})}),e}function ti(n){if(!n)return!1;const t=n.substring(0,4);return t==="hvc1"||t==="hev1"||t==="dvh1"||t==="dvhe"}function Hr(n,t){if(n){const e=t>>1&63;return e===39||e===40}else return(t&31)===6}function As(n,t,e,i){const s=Rs(n);let r=0;r+=t;let a=0,o=0,u=0;for(;r<s.length;){a=0;do{if(r>=s.length)break;u=s[r++],a+=u}while(u===255);o=0;do{if(r>=s.length)break;u=s[r++],o+=u}while(u===255);const l=s.length-r;let d=r;if(o<l)r+=o;else if(o>l){J.error(`Malformed SEI payload. ${o} is too small, only ${l} bytes left to parse.`);break}if(a===4){if(s[d++]===181){const c=Ts(s,d);if(d+=2,c===49){const f=K(s,d);if(d+=4,f===1195456820){const g=s[d++];if(g===3){const p=s[d++],m=31&p,y=64&p,T=y?2+m*3:0,v=new Uint8Array(T);if(y){v[0]=p;for(let S=1;S<T;S++)v[S]=s[d++]}i.push({type:g,payloadType:a,pts:e,bytes:v})}}}}}else if(a===5&&o>16){const h=[];for(let g=0;g<16;g++){const p=s[d++].toString(16);h.push(p.length==1?"0"+p:p),(g===3||g===5||g===7||g===9)&&h.push("-")}const c=o-16,f=new Uint8Array(c);for(let g=0;g<c;g++)f[g]=s[d++];i.push({payloadType:a,pts:e,uuid:h.join(""),userData:mt(f),userDataBytes:f})}}}function Rs(n){const t=n.byteLength,e=[];let i=1;for(;i<t-2;)n[i]===0&&n[i+1]===0&&n[i+2]===3?(e.push(i+2),i+=2):i++;if(e.length===0)return n;const s=t-e.length,r=new Uint8Array(s);let a=0;for(i=0;i<s;a++,i++)a===e[0]&&(a++,e.shift()),r[i]=n[a];return r}function Kr(n){const t=n[0];let e="",i="",s=0,r=0,a=0,o=0,u=0,l=0;if(t===0){for(;rt(n.subarray(l,l+1))!=="\0";)e+=rt(n.subarray(l,l+1)),l+=1;for(e+=rt(n.subarray(l,l+1)),l+=1;rt(n.subarray(l,l+1))!=="\0";)i+=rt(n.subarray(l,l+1)),l+=1;i+=rt(n.subarray(l,l+1)),l+=1,s=K(n,12),r=K(n,16),o=K(n,20),u=K(n,24),l=28}else if(t===1){l+=4,s=K(n,l),l+=4;const h=K(n,l);l+=4;const c=K(n,l);for(l+=4,a=2**32*h+c,yr(a)||(a=Number.MAX_SAFE_INTEGER,J.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=K(n,l),l+=4,u=K(n,l),l+=4;rt(n.subarray(l,l+1))!=="\0";)e+=rt(n.subarray(l,l+1)),l+=1;for(e+=rt(n.subarray(l,l+1)),l+=1;rt(n.subarray(l,l+1))!=="\0";)i+=rt(n.subarray(l,l+1)),l+=1;i+=rt(n.subarray(l,l+1)),l+=1}const d=n.subarray(l,n.byteLength);return{schemeIdUri:e,value:i,timeScale:s,presentationTime:a,presentationTimeDelta:r,eventDuration:o,id:u,payload:d}}const bs=()=>/\(Windows.+Firefox\//i.test(navigator.userAgent),Vt={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,dav1:.8,drac:1,dva1:1,dvav:1,dvh1:.7,dvhe:.7,encv:1,hev1:.75,hvc1:.75,mjp2:1,mp4v:1,mvc1:1,mvc2:1,mvc3:1,mvc4:1,resv:1,rv60:1,s263:1,svc1:1,svc2:1,"vc-1":1,vp08:1,vp09:.9},text:{stpp:1,wvtt:1}};function ei(n,t){const e=Vt[t];return!!e&&!!e[n.slice(0,4)]}function Qt(n,t,e=!0){return!n.split(",").some(i=>!ii(i,t,e))}function ii(n,t,e=!0){var i;const s=bt(e);return(i=s?.isTypeSupported(Zt(n,t)))!=null?i:!1}function Zt(n,t){return`${t}/mp4;codecs=${n}`}function Si(n){if(n){const t=n.substring(0,4);return Vt.video[t]}return 2}function ge(n){const t=bs();return n.split(",").reduce((e,i)=>{const r=t&&ti(i)?9:Vt.video[i];return r?(r*2+e)/(e?3:2):(Vt.audio[i]+e)/(e?2:1)},0)}const De={};function Wr(n,t=!0){if(De[n])return De[n];const e={flac:["flac","fLaC","FLAC"],opus:["opus","Opus"],"mp4a.40.34":["mp3"]}[n];for(let s=0;s<e.length;s++){var i;if(ii(e[s],"audio",t))return De[n]=e[s],e[s];if(e[s]==="mp3"&&(i=bt(t))!=null&&i.isTypeSupported("audio/mpeg"))return""}return n}const Yr=/flac|opus|mp4a\.40\.34/i;function me(n,t=!0){return n.replace(Yr,e=>Wr(e.toLowerCase(),t))}function jr(n,t){const e=[];if(n){const i=n.split(",");for(let s=0;s<i.length;s++)ei(i[s],"video")||e.push(i[s])}return t&&e.push(t),e.join(",")}function ce(n,t){if(n&&(n.length>4||["ac-3","ec-3","alac","fLaC","Opus"].indexOf(n)!==-1)&&(xi(n,"audio")||xi(n,"video")))return n;if(t){const e=t.split(",");if(e.length>1){if(n){for(let i=e.length;i--;)if(e[i].substring(0,4)===n.substring(0,4))return e[i]}return e[0]}}return t||n}function xi(n,t){return ei(n,t)&&ii(n,t)}function qr(n){const t=n.split(",");for(let e=0;e<t.length;e++){const i=t[e].split(".");i.length>2&&i[0]==="avc1"&&(t[e]=`avc1.${parseInt(i[1]).toString(16)}${("000"+parseInt(i[2]).toString(16)).slice(-4)}`)}return t.join(",")}function zr(n){if(n.startsWith("av01.")){const t=n.split("."),e=["0","111","01","01","01","0"];for(let i=t.length;i>4&&i<10;i++)t[i]=e[i-4];return t.join(".")}return n}function Li(n){const t=bt(n)||{isTypeSupported:()=>!1};return{mpeg:t.isTypeSupported("audio/mpeg"),mp3:t.isTypeSupported('audio/mp4; codecs="mp3"'),ac3:!1}}function He(n){return n.replace(/^.+codecs=["']?([^"']+).*$/,"$1")}const Ke=["NONE","TYPE-0","TYPE-1",null];function Xr(n){return Ke.indexOf(n)>-1}const pe=["SDR","PQ","HLG"];function Qr(n){return!!n&&pe.indexOf(n)>-1}var Yt={No:"",Yes:"YES",v2:"v2"};function Ai(n){const{canSkipUntil:t,canSkipDateRanges:e,age:i}=n,s=i<t/2;return t&&s?e?Yt.v2:Yt.Yes:Yt.No}class We{constructor(t,e,i){this.msn=void 0,this.part=void 0,this.skip=void 0,this.msn=t,this.part=e,this.skip=i}addDirectives(t){const e=new self.URL(t);return this.msn!==void 0&&e.searchParams.set("_HLS_msn",this.msn.toString()),this.part!==void 0&&e.searchParams.set("_HLS_part",this.part.toString()),this.skip&&e.searchParams.set("_HLS_skip",this.skip),e.href}}class si{constructor(t){if(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.supplemental=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=[t.url],this._attrs=[t.attrs],this.bitrate=t.bitrate,t.details&&(this.details=t.details),this.id=t.id||0,this.name=t.name,this.width=t.width||0,this.height=t.height||0,this.frameRate=t.attrs.optionalFloat("FRAME-RATE",0),this._avgBitrate=t.attrs.decimalInteger("AVERAGE-BANDWIDTH"),this.audioCodec=t.audioCodec,this.videoCodec=t.videoCodec,this.codecSet=[t.videoCodec,t.audioCodec].filter(i=>!!i).map(i=>i.substring(0,4)).join(","),"supplemental"in t){var e;this.supplemental=t.supplemental;const i=(e=t.supplemental)==null?void 0:e.videoCodec;i&&i!==t.videoCodec&&(this.codecSet+=`,${i.substring(0,4)}`)}this.addGroupId("audio",t.attrs.AUDIO),this.addGroupId("text",t.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(t){return Ri(this._audioGroups,t)}hasSubtitleGroup(t){return Ri(this._subtitleGroups,t)}get audioGroups(){return this._audioGroups}get subtitleGroups(){return this._subtitleGroups}addGroupId(t,e){if(e){if(t==="audio"){let i=this._audioGroups;i||(i=this._audioGroups=[]),i.indexOf(e)===-1&&i.push(e)}else if(t==="text"){let i=this._subtitleGroups;i||(i=this._subtitleGroups=[]),i.indexOf(e)===-1&&i.push(e)}}}get urlId(){return 0}set urlId(t){}get audioGroupIds(){return this.audioGroups?[this.audioGroupId]:void 0}get textGroupIds(){return this.subtitleGroups?[this.textGroupId]:void 0}get audioGroupId(){var t;return(t=this.audioGroups)==null?void 0:t[0]}get textGroupId(){var t;return(t=this.subtitleGroups)==null?void 0:t[0]}addFallback(){}}function Ri(n,t){return!t||!n?!1:n.indexOf(t)!==-1}function Zr(){if(typeof matchMedia=="function"){const n=matchMedia("(dynamic-range: high)"),t=matchMedia("bad query");if(n.media!==t.media)return n.matches===!0}return!1}function Jr(n,t){let e=!1,i=[];if(n&&(e=n!=="SDR",i=[n]),t){i=t.allowedVideoRanges||pe.slice(0);const s=i.join("")!=="SDR"&&!t.videoCodec;e=t.preferHDR!==void 0?t.preferHDR:s&&Zr(),e||(i=["SDR"])}return{preferHDR:e,allowedVideoRanges:i}}const tn=n=>{const t=new WeakSet;return(e,i)=>{if(n&&(i=n(e,i)),typeof i=="object"&&i!==null){if(t.has(i))return;t.add(i)}return i}},ot=(n,t)=>JSON.stringify(n,tn(t));function en(n,t,e,i,s){const r=Object.keys(n),a=i?.channels,o=i?.audioCodec,u=s?.videoCodec,l=a&&parseInt(a)===2;let d=!1,h=!1,c=1/0,f=1/0,g=1/0,p=1/0,m=0,y=[];const{preferHDR:T,allowedVideoRanges:v}=Jr(t,s);for(let R=r.length;R--;){const b=n[r[R]];d||(d=b.channels[2]>0),c=Math.min(c,b.minHeight),f=Math.min(f,b.minFramerate),g=Math.min(g,b.minBitrate),v.filter(_=>b.videoRanges[_]>0).length>0&&(h=!0)}c=B(c)?c:0,f=B(f)?f:0;const S=Math.max(1080,c),A=Math.max(30,f);g=B(g)?g:e,e=Math.max(g,e),h||(t=void 0);const C=r.length>1;return{codecSet:r.reduce((R,b)=>{const I=n[b];if(b===R)return R;if(y=h?v.filter(_=>I.videoRanges[_]>0):[],C){if(I.minBitrate>e)return vt(b,`min bitrate of ${I.minBitrate} > current estimate of ${e}`),R;if(!I.hasDefaultAudio)return vt(b,"no renditions with default or auto-select sound found"),R;if(o&&b.indexOf(o.substring(0,4))%5!==0)return vt(b,`audio codec preference "${o}" not found`),R;if(a&&!l){if(!I.channels[a])return vt(b,`no renditions with ${a} channel sound found (channels options: ${Object.keys(I.channels)})`),R}else if((!o||l)&&d&&I.channels[2]===0)return vt(b,"no renditions with stereo sound found"),R;if(I.minHeight>S)return vt(b,`min resolution of ${I.minHeight} > maximum of ${S}`),R;if(I.minFramerate>A)return vt(b,`min framerate of ${I.minFramerate} > maximum of ${A}`),R;if(!y.some(_=>I.videoRanges[_]>0))return vt(b,`no variants with VIDEO-RANGE of ${ot(y)} found`),R;if(u&&b.indexOf(u.substring(0,4))%5!==0)return vt(b,`video codec preference "${u}" not found`),R;if(I.maxScore<m)return vt(b,`max score of ${I.maxScore} < selected max of ${m}`),R}return R&&(ge(b)>=ge(R)||I.fragmentError>n[R].fragmentError)?R:(p=I.minIndex,m=I.maxScore,b)},void 0),videoRanges:y,preferHDR:T,minFramerate:f,minBitrate:g,minIndex:p}}function vt(n,t){J.log(`[abr] start candidates with "${n}" ignored because ${t}`)}function Is(n){return n.reduce((t,e)=>{let i=t.groups[e.groupId];i||(i=t.groups[e.groupId]={tracks:[],channels:{2:0},hasDefault:!1,hasAutoSelect:!1}),i.tracks.push(e);const s=e.channels||"2";return i.channels[s]=(i.channels[s]||0)+1,i.hasDefault=i.hasDefault||e.default,i.hasAutoSelect=i.hasAutoSelect||e.autoselect,i.hasDefault&&(t.hasDefaultAudio=!0),i.hasAutoSelect&&(t.hasAutoSelectAudio=!0),t},{hasDefaultAudio:!1,hasAutoSelectAudio:!1,groups:{}})}function sn(n,t,e,i){return n.slice(e,i+1).reduce((s,r,a)=>{if(!r.codecSet)return s;const o=r.audioGroups;let u=s[r.codecSet];u||(s[r.codecSet]=u={minBitrate:1/0,minHeight:1/0,minFramerate:1/0,minIndex:a,maxScore:0,videoRanges:{SDR:0},channels:{2:0},hasDefaultAudio:!o,fragmentError:0}),u.minBitrate=Math.min(u.minBitrate,r.bitrate);const l=Math.min(r.height,r.width);return u.minHeight=Math.min(u.minHeight,l),u.minFramerate=Math.min(u.minFramerate,r.frameRate),u.minIndex=Math.min(u.minIndex,a),u.maxScore=Math.max(u.maxScore,r.score),u.fragmentError+=r.fragmentError,u.videoRanges[r.videoRange]=(u.videoRanges[r.videoRange]||0)+1,s},{})}function bi(n,t){var e;return!!n&&n!==((e=t.loadLevelObj)==null?void 0:e.uri)}class Ds extends It{constructor(t){super("abr",t.logger),this.hls=void 0,this.lastLevelLoadSec=0,this.lastLoadedFragLevel=-1,this.firstSelection=-1,this._nextAutoLevel=-1,this.nextAutoLevelKey="",this.audioTracksByGroup=null,this.codecTiers=null,this.timer=-1,this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.rebufferNotice=-1,this.supportedCache={},this.bwEstimator=void 0,this._abandonRulesCheck=e=>{var i;const{fragCurrent:s,partCurrent:r,hls:a}=this,{autoLevelEnabled:o,media:u}=a;if(!s||!u)return;const l=performance.now(),d=r?r.stats:s.stats,h=r?r.duration:s.duration,c=l-d.loading.start,f=a.minAutoLevel,g=s.level,p=this._nextAutoLevel;if(d.aborted||d.loaded&&d.loaded===d.total||g<=f){this.clearTimer(),this._nextAutoLevel=-1;return}if(!o)return;const m=p>-1&&p!==g,y=!!e||m;if(!y&&(u.paused||!u.playbackRate||!u.readyState))return;const T=a.mainForwardBufferInfo;if(!y&&T===null)return;const v=this.bwEstimator.getEstimateTTFB(),S=Math.abs(u.playbackRate);if(c<=Math.max(v,1e3*(h/(S*2))))return;const A=T?T.len/S:0,C=d.loading.first?d.loading.first-d.loading.start:-1,x=d.loaded&&C>-1,R=this.getBwEstimate(),b=a.levels,I=b[g],_=Math.max(d.loaded,Math.round(h*(s.bitrate||I.averageBitrate)/8));let w=x?c-C:c;w<1&&x&&(w=Math.min(c,d.loaded*8/R));const $=x?d.loaded*1e3/w:0,V=v/1e3,N=$?(_-d.loaded)/$:_*8/R+V;if(N<=A)return;const P=$?$*8:R,G=((i=e?.details||this.hls.latestLevelDetails)==null?void 0:i.live)===!0,M=this.hls.config.abrBandWidthUpFactor;let U=Number.POSITIVE_INFINITY,H;for(H=g-1;H>f;H--){const Z=b[H].maxBitrate,Q=!b[H].details||G;if(U=this.getTimeToLoadFrag(V,P,h*Z,Q),U<Math.min(A,h+V))break}if(U>=N||U>h*10)return;x?this.bwEstimator.sample(c-Math.min(v,C),d.loaded):this.bwEstimator.sampleTTFB(c);const O=b[H].maxBitrate;this.getBwEstimate()*M>O&&this.resetEstimator(O);const F=this.findBestLevel(O,f,H,0,A,1,1);F>-1&&(H=F),this.warn(`Fragment ${s.sn}${r?" part "+r.index:""} of level ${g} is loading too slowly;
Fragment duration: ${s.duration.toFixed(3)}
Time to underbuffer: ${A.toFixed(3)} s
Estimated load time for current fragment: ${N.toFixed(3)} s
Estimated load time for down switch fragment: ${U.toFixed(3)} s
TTFB estimate: ${C|0} ms
Current BW estimate: ${B(R)?R|0:"Unknown"} bps
New BW estimate: ${this.getBwEstimate()|0} bps
Switching to level ${H} @ ${O|0} bps`),a.nextLoadLevel=a.nextAutoLevel=H,this.clearTimer();const z=()=>{if(this.clearTimer(),this.fragCurrent===s&&this.hls.loadLevel===H&&H>0){const Z=this.getStarvationDelay();if(this.warn(`Aborting inflight request ${H>0?"and switching down":""}
Fragment duration: ${s.duration.toFixed(3)} s
Time to underbuffer: ${Z.toFixed(3)} s`),s.abortRequests(),this.fragCurrent=this.partCurrent=null,H>f){let Q=this.findBestLevel(this.hls.levels[f].bitrate,f,H,0,Z,1,1);Q===-1&&(Q=f),this.hls.nextLoadLevel=this.hls.nextAutoLevel=Q,this.resetEstimator(this.hls.levels[Q].bitrate)}}};m||N>U*2?z():this.timer=self.setInterval(z,U*1e3),a.trigger(E.FRAG_LOAD_EMERGENCY_ABORTED,{frag:s,part:r,stats:d})},this.hls=t,this.bwEstimator=this.initEstimator(),this.registerListeners()}resetEstimator(t){t&&(this.log(`setting initial bwe to ${t}`),this.hls.config.abrEwmaDefaultEstimate=t),this.firstSelection=-1,this.bwEstimator=this.initEstimator()}initEstimator(){const t=this.hls.config;return new Sr(t.abrEwmaSlowVoD,t.abrEwmaFastVoD,t.abrEwmaDefaultEstimate)}registerListeners(){const{hls:t}=this;t.on(E.MANIFEST_LOADING,this.onManifestLoading,this),t.on(E.FRAG_LOADING,this.onFragLoading,this),t.on(E.FRAG_LOADED,this.onFragLoaded,this),t.on(E.FRAG_BUFFERED,this.onFragBuffered,this),t.on(E.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(E.LEVEL_LOADED,this.onLevelLoaded,this),t.on(E.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(E.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),t.on(E.ERROR,this.onError,this)}unregisterListeners(){const{hls:t}=this;t&&(t.off(E.MANIFEST_LOADING,this.onManifestLoading,this),t.off(E.FRAG_LOADING,this.onFragLoading,this),t.off(E.FRAG_LOADED,this.onFragLoaded,this),t.off(E.FRAG_BUFFERED,this.onFragBuffered,this),t.off(E.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(E.LEVEL_LOADED,this.onLevelLoaded,this),t.off(E.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(E.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),t.off(E.ERROR,this.onError,this))}destroy(){this.unregisterListeners(),this.clearTimer(),this.hls=this._abandonRulesCheck=this.supportedCache=null,this.fragCurrent=this.partCurrent=null}onManifestLoading(t,e){this.lastLoadedFragLevel=-1,this.firstSelection=-1,this.lastLevelLoadSec=0,this.supportedCache={},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(t,e){const i=e.frag;if(!this.ignoreFragment(i)){if(!i.bitrateTest){var s;this.fragCurrent=i,this.partCurrent=(s=e.part)!=null?s:null}this.clearTimer(),this.timer=self.setInterval(this._abandonRulesCheck,100)}}onLevelSwitching(t,e){this.clearTimer()}onError(t,e){if(!e.fatal)switch(e.details){case D.BUFFER_ADD_CODEC_ERROR:case D.BUFFER_APPEND_ERROR:this.lastLoadedFragLevel=-1,this.firstSelection=-1;break;case D.FRAG_LOAD_TIMEOUT:{const i=e.frag,{fragCurrent:s,partCurrent:r}=this;if(i&&s&&i.sn===s.sn&&i.level===s.level){const a=performance.now(),o=r?r.stats:i.stats,u=a-o.loading.start,l=o.loading.first?o.loading.first-o.loading.start:-1;if(o.loaded&&l>-1){const h=this.bwEstimator.getEstimateTTFB();this.bwEstimator.sample(u-Math.min(h,l),o.loaded)}else this.bwEstimator.sampleTTFB(u)}break}}}getTimeToLoadFrag(t,e,i,s){const r=t+i/e,a=s?t+this.lastLevelLoadSec:0;return r+a}onLevelLoaded(t,e){const i=this.hls.config,{loading:s}=e.stats,r=s.end-s.first;B(r)&&(this.lastLevelLoadSec=r/1e3),e.details.live?this.bwEstimator.update(i.abrEwmaSlowLive,i.abrEwmaFastLive):this.bwEstimator.update(i.abrEwmaSlowVoD,i.abrEwmaFastVoD),this.timer>-1&&this._abandonRulesCheck(e.levelInfo)}onFragLoaded(t,{frag:e,part:i}){const s=i?i.stats:e.stats;if(e.type===W.MAIN&&this.bwEstimator.sampleTTFB(s.loading.first-s.loading.start),!this.ignoreFragment(e)){if(this.clearTimer(),e.level===this._nextAutoLevel&&(this._nextAutoLevel=-1),this.firstSelection=-1,this.hls.config.abrMaxWithRealBitrate){const r=i?i.duration:e.duration,a=this.hls.levels[e.level],o=(a.loaded?a.loaded.bytes:0)+s.loaded,u=(a.loaded?a.loaded.duration:0)+r;a.loaded={bytes:o,duration:u},a.realBitrate=Math.round(8*o/u)}if(e.bitrateTest){const r={stats:s,frag:e,part:i,id:e.type};this.onFragBuffered(E.FRAG_BUFFERED,r),e.bitrateTest=!1}else this.lastLoadedFragLevel=e.level}}onFragBuffered(t,e){const{frag:i,part:s}=e,r=s!=null&&s.stats.loaded?s.stats:i.stats;if(r.aborted||this.ignoreFragment(i))return;const a=r.parsing.end-r.loading.start-Math.min(r.loading.first-r.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(a,r.loaded),r.bwEstimate=this.getBwEstimate(),i.bitrateTest?this.bitrateTestDelay=a/1e3:this.bitrateTestDelay=0}ignoreFragment(t){return t.type!==W.MAIN||t.sn==="initSegment"}clearTimer(){this.timer>-1&&(self.clearInterval(this.timer),this.timer=-1)}get firstAutoLevel(){const{maxAutoLevel:t,minAutoLevel:e}=this.hls,i=this.getBwEstimate(),s=this.hls.config.maxStarvationDelay,r=this.findBestLevel(i,e,t,0,s,1,1);if(r>-1)return r;const a=this.hls.firstLevel,o=Math.min(Math.max(a,e),t);return this.warn(`Could not find best starting auto level. Defaulting to first in playlist ${a} clamped to ${o}`),o}get forcedAutoLevel(){return this.nextAutoLevelKey?-1:this._nextAutoLevel}get nextAutoLevel(){const t=this.forcedAutoLevel,i=this.bwEstimator.canEstimate(),s=this.lastLoadedFragLevel>-1;if(t!==-1&&(!i||!s||this.nextAutoLevelKey===this.getAutoLevelKey()))return t;const r=i&&s?this.getNextABRAutoLevel():this.firstAutoLevel;if(t!==-1){const a=this.hls.levels;if(a.length>Math.max(t,r)&&a[t].loadError<=a[r].loadError)return t}return this._nextAutoLevel=r,this.nextAutoLevelKey=this.getAutoLevelKey(),r}getAutoLevelKey(){return`${this.getBwEstimate()}_${this.getStarvationDelay().toFixed(2)}`}getNextABRAutoLevel(){const{fragCurrent:t,partCurrent:e,hls:i}=this;if(i.levels.length<=1)return i.loadLevel;const{maxAutoLevel:s,config:r,minAutoLevel:a}=i,o=e?e.duration:t?t.duration:0,u=this.getBwEstimate(),l=this.getStarvationDelay();let d=r.abrBandWidthFactor,h=r.abrBandWidthUpFactor;if(l){const m=this.findBestLevel(u,a,s,l,0,d,h);if(m>=0)return this.rebufferNotice=-1,m}let c=o?Math.min(o,r.maxStarvationDelay):r.maxStarvationDelay;if(!l){const m=this.bitrateTestDelay;m&&(c=(o?Math.min(o,r.maxLoadingDelay):r.maxLoadingDelay)-m,this.info(`bitrate test took ${Math.round(1e3*m)}ms, set first fragment max fetchDuration to ${Math.round(1e3*c)} ms`),d=h=1)}const f=this.findBestLevel(u,a,s,l,c,d,h);if(this.rebufferNotice!==f&&(this.rebufferNotice=f,this.info(`${l?"rebuffering expected":"buffer is empty"}, optimal quality level ${f}`)),f>-1)return f;const g=i.levels[a],p=i.loadLevelObj;return p&&g?.bitrate<p.bitrate?a:i.loadLevel}getStarvationDelay(){const t=this.hls,e=t.media;if(!e)return 1/0;const i=e&&e.playbackRate!==0?Math.abs(e.playbackRate):1,s=t.mainForwardBufferInfo;return(s?s.len:0)/i}getBwEstimate(){return this.bwEstimator.canEstimate()?this.bwEstimator.getEstimate():this.hls.config.abrEwmaDefaultEstimate}findBestLevel(t,e,i,s,r,a,o){var u;const l=s+r,d=this.lastLoadedFragLevel,h=d===-1?this.hls.firstLevel:d,{fragCurrent:c,partCurrent:f}=this,{levels:g,allAudioTracks:p,loadLevel:m,config:y}=this.hls;if(g.length===1)return 0;const T=g[h],v=!!((u=this.hls.latestLevelDetails)!=null&&u.live),S=m===-1||d===-1;let A,C="SDR",x=T?.frameRate||0;const{audioPreference:R,videoPreference:b}=y,I=this.audioTracksByGroup||(this.audioTracksByGroup=Is(p));let _=-1;if(S){if(this.firstSelection!==-1)return this.firstSelection;const P=this.codecTiers||(this.codecTiers=sn(g,I,e,i)),G=en(P,C,t,R,b),{codecSet:M,videoRanges:U,minFramerate:H,minBitrate:O,minIndex:F,preferHDR:z}=G;_=F,A=M,C=z?U[U.length-1]:U[0],x=H,t=Math.max(t,O),this.log(`picked start tier ${ot(G)}`)}else A=T?.codecSet,C=T?.videoRange;const w=f?f.duration:c?c.duration:0,$=this.bwEstimator.getEstimateTTFB()/1e3,V=[];for(let P=i;P>=e;P--){var N;const G=g[P],M=P>h;if(!G)continue;if((A&&G.codecSet!==A||C&&G.videoRange!==C||M&&x>G.frameRate||!M&&x>0&&x<G.frameRate||(N=G.supportedResult)!=null&&(N=N.decodingInfoResults)!=null&&N.some(Q=>Q.smooth===!1))&&(!S||P!==_)){V.push(P);continue}const U=G.details,H=(f?U?.partTarget:U?.averagetargetduration)||w;let O;M?O=o*t:O=a*t;const F=w&&s>=w*2&&r===0?G.averageBitrate:G.maxBitrate,z=this.getTimeToLoadFrag($,O,F*H,U===void 0);if(O>=F&&(P===d||G.loadError===0&&G.fragmentError===0)&&(z<=$||!B(z)||v&&!this.bitrateTestDelay||z<l)){const Q=this.forcedAutoLevel;return P!==m&&(Q===-1||Q!==m)&&(V.length&&this.trace(`Skipped level(s) ${V.join(",")} of ${i} max with CODECS and VIDEO-RANGE:"${g[V[0]].codecs}" ${g[V[0]].videoRange}; not compatible with "${A}" ${C}`),this.info(`switch candidate:${h}->${P} adjustedbw(${Math.round(O)})-bitrate=${Math.round(O-F)} ttfb:${$.toFixed(1)} avgDuration:${H.toFixed(1)} maxFetchDuration:${l.toFixed(1)} fetchDuration:${z.toFixed(1)} firstSelection:${S} codecSet:${G.codecSet} videoRange:${G.videoRange} hls.loadLevel:${m}`)),S&&(this.firstSelection=P),P}}return-1}set nextAutoLevel(t){const e=this.deriveNextAutoLevel(t);this._nextAutoLevel!==e&&(this.nextAutoLevelKey="",this._nextAutoLevel=e)}deriveNextAutoLevel(t){const{maxAutoLevel:e,minAutoLevel:i}=this.hls;return Math.min(Math.max(t,i),e)}}const Cs={search:function(n,t){let e=0,i=n.length-1,s=null,r=null;for(;e<=i;){s=(e+i)/2|0,r=n[s];const a=t(r);if(a>0)e=s+1;else if(a<0)i=s-1;else return r}return null}};function rn(n,t,e){if(t===null||!Array.isArray(n)||!n.length||!B(t))return null;const i=n[0].programDateTime;if(t<(i||0))return null;const s=n[n.length-1].endProgramDateTime;if(t>=(s||0))return null;for(let r=0;r<n.length;++r){const a=n[r];if(an(t,e,a))return a}return null}function ri(n,t,e=0,i=0,s=.005){let r=null;if(n){r=t[1+n.sn-t[0].sn]||null;const o=n.