UNPKG

ft-component-set

Version:

简单组件集

851 lines 982 kB
import { ref as gn, onMounted as Ca, onUnmounted as ol, watch as ui, openBlock as Pa, createElementBlock as ba, createElementVNode as Mr, nextTick as x0, reactive as y0, toRefs as T0, computed as S0, toDisplayString as Ra, unref as Ia, onBeforeUnmount as L0 } from "vue"; var Qr = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function ll(Ke) { return Ke && Ke.__esModule && Object.prototype.hasOwnProperty.call(Ke, "default") ? Ke.default : Ke; } var ul = { exports: {} }; (function(Ke, ze) { typeof window < "u" && function(Ee, Re) { Ke.exports = Re(); }(Qr, () => (() => { var V = { "./src/config.ts": (H, U, I) => { I.r(U), I.d(U, { enableStreamingMode: () => A, hlsDefaultConfig: () => o, mergeConfig: () => _ }); var w = I("./src/controller/abr-controller.ts"), R = I("./src/controller/audio-stream-controller.ts"), C = I("./src/controller/audio-track-controller.ts"), S = I("./src/controller/subtitle-stream-controller.ts"), P = I("./src/controller/subtitle-track-controller.ts"), E = I("./src/controller/buffer-controller.ts"), v = I("./src/controller/timeline-controller.ts"), m = I("./src/controller/cap-level-controller.ts"), u = I("./src/controller/fps-controller.ts"), f = I("./src/controller/eme-controller.ts"), h = I("./src/controller/cmcd-controller.ts"), d = I("./src/utils/xhr-loader.ts"), s = I("./src/utils/fetch-loader.ts"), r = I("./src/utils/cues.ts"), i = I("./src/utils/mediakeys-helper.ts"), n = I("./src/utils/logger.ts"); function c() { return c = Object.assign ? Object.assign.bind() : function(x) { for (var D = 1; D < arguments.length; D++) { var L = arguments[D]; for (var y in L) Object.prototype.hasOwnProperty.call(L, y) && (x[y] = L[y]); } return x; }, c.apply(this, arguments); } function p(x, D) { var L = Object.keys(x); if (Object.getOwnPropertySymbols) { var y = Object.getOwnPropertySymbols(x); D && (y = y.filter(function(O) { return Object.getOwnPropertyDescriptor(x, O).enumerable; })), L.push.apply(L, y); } return L; } function l(x) { for (var D = 1; D < arguments.length; D++) { var L = arguments[D] != null ? arguments[D] : {}; D % 2 ? p(Object(L), !0).forEach(function(y) { a(x, y, L[y]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(x, Object.getOwnPropertyDescriptors(L)) : p(Object(L)).forEach(function(y) { Object.defineProperty(x, y, Object.getOwnPropertyDescriptor(L, y)); }); } return x; } function a(x, D, L) { return D in x ? Object.defineProperty(x, D, { value: L, enumerable: !0, configurable: !0, writable: !0 }) : x[D] = L, x; } var o = l(l({ autoStartLoad: !0, startPosition: -1, defaultAudioCodec: void 0, debug: !1, capLevelOnFPSDrop: !1, capLevelToPlayerSize: !1, ignoreDevicePixelRatio: !1, initialLiveManifestSize: 1, maxBufferLength: 30, backBufferLength: 1 / 0, maxBufferSize: 60 * 1e3 * 1e3, maxBufferHole: 0.1, highBufferWatchdogPeriod: 2, nudgeOffset: 0.1, nudgeMaxRetry: 3, maxFragLookUpTolerance: 0.25, liveSyncDurationCount: 3, liveMaxLatencyDurationCount: 1 / 0, liveSyncDuration: void 0, liveMaxLatencyDuration: void 0, maxLiveSyncPlaybackRate: 1, liveDurationInfinity: !1, liveBackBufferLength: null, maxMaxBufferLength: 600, enableWorker: !0, enableSoftwareAES: !0, manifestLoadingTimeOut: 1e4, manifestLoadingMaxRetry: 1, manifestLoadingRetryDelay: 1e3, manifestLoadingMaxRetryTimeout: 64e3, startLevel: void 0, levelLoadingTimeOut: 1e4, levelLoadingMaxRetry: 4, levelLoadingRetryDelay: 1e3, levelLoadingMaxRetryTimeout: 64e3, fragLoadingTimeOut: 2e4, fragLoadingMaxRetry: 6, fragLoadingRetryDelay: 1e3, fragLoadingMaxRetryTimeout: 64e3, startFragPrefetch: !1, fpsDroppedMonitoringPeriod: 5e3, fpsDroppedMonitoringThreshold: 0.2, appendErrorMaxRetry: 3, loader: d.default, fLoader: void 0, pLoader: void 0, xhrSetup: void 0, licenseXhrSetup: void 0, licenseResponseCallback: void 0, abrController: w.default, bufferController: E.default, capLevelController: m.default, fpsController: u.default, stretchShortVideoTrack: !1, maxAudioFramesDrift: 1, forceKeyFrameOnDiscontinuity: !0, abrEwmaFastLive: 3, abrEwmaSlowLive: 9, abrEwmaFastVoD: 3, abrEwmaSlowVoD: 9, abrEwmaDefaultEstimate: 5e5, abrBandWidthFactor: 0.95, abrBandWidthUpFactor: 0.7, abrMaxWithRealBitrate: !1, maxStarvationDelay: 4, maxLoadingDelay: 4, minAutoBitrate: 0, emeEnabled: !1, widevineLicenseUrl: void 0, drmSystemOptions: {}, requestMediaKeySystemAccessFunc: i.requestMediaKeySystemAccess, testBandwidth: !0, progressive: !1, lowLatencyMode: !0, cmcd: void 0, enableDateRangeMetadataCues: !0, enableEmsgMetadataCues: !0, enableID3MetadataCues: !0 }, g()), {}, { subtitleStreamController: S.SubtitleStreamController, subtitleTrackController: P.default, timelineController: v.TimelineController, audioStreamController: R.default, audioTrackController: C.default, emeController: f.default, cmcdController: h.default }); function g() { return { cueHandler: r.default, 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 _(x, D) { if ((D.liveSyncDurationCount || D.liveMaxLatencyDurationCount) && (D.liveSyncDuration || D.liveMaxLatencyDuration)) throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration"); if (D.liveMaxLatencyDurationCount !== void 0 && (D.liveSyncDurationCount === void 0 || D.liveMaxLatencyDurationCount <= D.liveSyncDurationCount)) throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"'); if (D.liveMaxLatencyDuration !== void 0 && (D.liveSyncDuration === void 0 || D.liveMaxLatencyDuration <= D.liveSyncDuration)) throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"'); return c({}, x, D); } function A(x) { var D = x.loader; if (D !== s.default && D !== d.default) n.logger.log("[config]: Custom loader detected, cannot enable progressive streaming"), x.progressive = !1; else { var L = (0, s.fetchSupported)(); L && (x.loader = s.default, x.progressive = !0, x.enableSoftwareAES = !0, n.logger.log("[config]: Progressive streaming enabled, using FetchLoader")); } } }, "./src/controller/abr-controller.ts": (H, U, I) => { I.r(U), I.d(U, { default: () => f }); var w = I("./src/polyfills/number.ts"), R = I("./src/utils/ewma-bandwidth-estimator.ts"), C = I("./src/events.ts"), S = I("./src/errors.ts"), P = I("./src/types/loader.ts"), E = I("./src/utils/logger.ts"); function v(h, d) { for (var s = 0; s < d.length; s++) { var r = d[s]; r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(h, r.key, r); } } function m(h, d, s) { return d && v(h.prototype, d), s && v(h, s), Object.defineProperty(h, "prototype", { writable: !1 }), h; } var u = /* @__PURE__ */ function() { function h(s) { this.hls = void 0, this.lastLoadedFragLevel = 0, this._nextAutoLevel = -1, this.timer = void 0, this.onCheck = this._abandonRulesCheck.bind(this), this.fragCurrent = null, this.partCurrent = null, this.bitrateTestDelay = 0, this.bwEstimator = void 0, this.hls = s; var r = s.config; this.bwEstimator = new R.default(r.abrEwmaSlowVoD, r.abrEwmaFastVoD, r.abrEwmaDefaultEstimate), this.registerListeners(); } var d = h.prototype; return d.registerListeners = function() { var r = this.hls; r.on(C.Events.FRAG_LOADING, this.onFragLoading, this), r.on(C.Events.FRAG_LOADED, this.onFragLoaded, this), r.on(C.Events.FRAG_BUFFERED, this.onFragBuffered, this), r.on(C.Events.LEVEL_LOADED, this.onLevelLoaded, this), r.on(C.Events.ERROR, this.onError, this); }, d.unregisterListeners = function() { var r = this.hls; r.off(C.Events.FRAG_LOADING, this.onFragLoading, this), r.off(C.Events.FRAG_LOADED, this.onFragLoaded, this), r.off(C.Events.FRAG_BUFFERED, this.onFragBuffered, this), r.off(C.Events.LEVEL_LOADED, this.onLevelLoaded, this), r.off(C.Events.ERROR, this.onError, this); }, d.destroy = function() { this.unregisterListeners(), this.clearTimer(), this.hls = this.onCheck = null, this.fragCurrent = this.partCurrent = null; }, d.onFragLoading = function(r, i) { var n = i.frag; if (n.type === P.PlaylistLevelType.MAIN && !this.timer) { var c; this.fragCurrent = n, this.partCurrent = (c = i.part) != null ? c : null, this.timer = self.setInterval(this.onCheck, 100); } }, d.onLevelLoaded = function(r, i) { var n = this.hls.config; i.details.live ? this.bwEstimator.update(n.abrEwmaSlowLive, n.abrEwmaFastLive) : this.bwEstimator.update(n.abrEwmaSlowVoD, n.abrEwmaFastVoD); }, d._abandonRulesCheck = function() { var r = this.fragCurrent, i = this.partCurrent, n = this.hls, c = n.autoLevelEnabled; n.config; var p = n.media; if (!(!r || !p)) { var l = i ? i.stats : r.stats, a = i ? i.duration : r.duration; if (l.aborted || l.loaded && l.loaded === l.total || r.level === 0) { this.clearTimer(), this._nextAutoLevel = -1; return; } if (!(!c || p.paused || !p.playbackRate || !p.readyState)) { var o = n.mainForwardBufferInfo; if (o !== null) { var g = performance.now() - l.loading.start, _ = Math.abs(p.playbackRate); if (!(g <= 500 * a / _)) { var A = l.loaded && l.loading.first, x = this.bwEstimator.getEstimate(), D = n.levels, L = n.minAutoLevel, y = D[r.level], O = l.total || Math.max(l.loaded, Math.round(a * y.maxBitrate / 8)), b = A ? l.loaded * 1e3 / g : 0, F = b ? (O - l.loaded) / b : O * 8 / x, k = o.len / _; if (!(F <= k)) { var B = Number.POSITIVE_INFINITY, K; for (K = r.level - 1; K > L; K--) { var j = D[K].maxBitrate; if (B = b ? a * j / (8 * 0.8 * b) : a * j / x, B < k) break; } B >= F || (E.logger.warn("Fragment " + r.sn + (i ? " part " + i.index : "") + " of level " + r.level + " is loading too slowly and will cause an underbuffer; aborting and switching to level " + K + ` Current BW estimate: ` + ((0, w.isFiniteNumber)(x) ? (x / 1024).toFixed(3) : "Unknown") + ` Kb/s Estimated load time for current fragment: ` + F.toFixed(3) + ` s Estimated load time for the next fragment: ` + B.toFixed(3) + ` s Time to underbuffer: ` + k.toFixed(3) + " s"), n.nextLoadLevel = K, A && this.bwEstimator.sample(g, l.loaded), this.clearTimer(), r.loader && (this.fragCurrent = this.partCurrent = null, r.loader.abort()), n.trigger(C.Events.FRAG_LOAD_EMERGENCY_ABORTED, { frag: r, part: i, stats: l })); } } } } } }, d.onFragLoaded = function(r, i) { var n = i.frag, c = i.part; if (n.type === P.PlaylistLevelType.MAIN && (0, w.isFiniteNumber)(n.sn)) { var p = c ? c.stats : n.stats, l = c ? c.duration : n.duration; if (this.clearTimer(), this.lastLoadedFragLevel = n.level, this._nextAutoLevel = -1, this.hls.config.abrMaxWithRealBitrate) { var a = this.hls.levels[n.level], o = (a.loaded ? a.loaded.bytes : 0) + p.loaded, g = (a.loaded ? a.loaded.duration : 0) + l; a.loaded = { bytes: o, duration: g }, a.realBitrate = Math.round(8 * o / g); } if (n.bitrateTest) { var _ = { stats: p, frag: n, part: c, id: n.type }; this.onFragBuffered(C.Events.FRAG_BUFFERED, _); } } }, d.onFragBuffered = function(r, i) { var n = i.frag, c = i.part, p = c ? c.stats : n.stats; if (!p.aborted && !(n.type !== P.PlaylistLevelType.MAIN || n.sn === "initSegment")) { var l = p.parsing.end - p.loading.start; this.bwEstimator.sample(l, p.loaded), p.bwEstimate = this.bwEstimator.getEstimate(), n.bitrateTest ? this.bitrateTestDelay = l / 1e3 : this.bitrateTestDelay = 0; } }, d.onError = function(r, i) { switch (i.details) { case S.ErrorDetails.FRAG_LOAD_ERROR: case S.ErrorDetails.FRAG_LOAD_TIMEOUT: this.clearTimer(); break; } }, d.clearTimer = function() { self.clearInterval(this.timer), this.timer = void 0; }, d.getNextABRAutoLevel = function() { var r = this.fragCurrent, i = this.partCurrent, n = this.hls, c = n.maxAutoLevel, p = n.config, l = n.minAutoLevel, a = n.media, o = i ? i.duration : r ? r.duration : 0; a && a.currentTime; var g = a && a.playbackRate !== 0 ? Math.abs(a.playbackRate) : 1, _ = this.bwEstimator ? this.bwEstimator.getEstimate() : p.abrEwmaDefaultEstimate, A = n.mainForwardBufferInfo, x = (A ? A.len : 0) / g, D = this.findBestLevel(_, l, c, x, p.abrBandWidthFactor, p.abrBandWidthUpFactor); if (D >= 0) return D; E.logger.trace((x ? "rebuffering expected" : "buffer is empty") + ", finding optimal quality level"); var L = o ? Math.min(o, p.maxStarvationDelay) : p.maxStarvationDelay, y = p.abrBandWidthFactor, O = p.abrBandWidthUpFactor; if (!x) { var b = this.bitrateTestDelay; if (b) { var F = o ? Math.min(o, p.maxLoadingDelay) : p.maxLoadingDelay; L = F - b, E.logger.trace("bitrate test took " + Math.round(1e3 * b) + "ms, set first fragment max fetchDuration to " + Math.round(1e3 * L) + " ms"), y = O = 1; } } return D = this.findBestLevel(_, l, c, x + L, y, O), Math.max(D, 0); }, d.findBestLevel = function(r, i, n, c, p, l) { for (var a, o = this.fragCurrent, g = this.partCurrent, _ = this.lastLoadedFragLevel, A = this.hls.levels, x = A[_], D = !!(x != null && (a = x.details) !== null && a !== void 0 && a.live), L = x == null ? void 0 : x.codecSet, y = g ? g.duration : o ? o.duration : 0, O = n; O >= i; O--) { var b = A[O]; if (!(!b || L && b.codecSet !== L)) { var F = b.details, k = (g ? F == null ? void 0 : F.partTarget : F == null ? void 0 : F.averagetargetduration) || y, B = void 0; O <= _ ? B = p * r : B = l * r; var K = A[O].maxBitrate, j = K * k / B; if (E.logger.trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: " + O + "/" + Math.round(B) + "/" + K + "/" + k + "/" + c + "/" + j), B > K && (j === 0 || !(0, w.isFiniteNumber)(j) || D && !this.bitrateTestDelay || j < c)) return O; } } return -1; }, m(h, [{ key: "nextAutoLevel", get: function() { var r = this._nextAutoLevel, i = this.bwEstimator; if (r !== -1 && !i.canEstimate()) return r; var n = this.getNextABRAutoLevel(); return r !== -1 && this.hls.levels[n].loadError ? r : (r !== -1 && (n = Math.min(r, n)), n); }, set: function(r) { this._nextAutoLevel = r; } }]), h; }(); const f = u; }, "./src/controller/audio-stream-controller.ts": (H, U, I) => { I.r(U), I.d(U, { default: () => a }); var w = I("./src/polyfills/number.ts"), R = I("./src/controller/base-stream-controller.ts"), C = I("./src/events.ts"), S = I("./src/utils/buffer-helper.ts"), P = I("./src/controller/fragment-tracker.ts"), E = I("./src/types/level.ts"), v = I("./src/types/loader.ts"), m = I("./src/loader/fragment.ts"), u = I("./src/demux/chunk-cache.ts"), f = I("./src/demux/transmuxer-interface.ts"), h = I("./src/types/transmuxer.ts"), d = I("./src/controller/fragment-finders.ts"), s = I("./src/utils/discontinuities.ts"), r = I("./src/errors.ts"); function i() { return i = Object.assign ? Object.assign.bind() : function(o) { for (var g = 1; g < arguments.length; g++) { var _ = arguments[g]; for (var A in _) Object.prototype.hasOwnProperty.call(_, A) && (o[A] = _[A]); } return o; }, i.apply(this, arguments); } function n(o, g) { o.prototype = Object.create(g.prototype), o.prototype.constructor = o, c(o, g); } function c(o, g) { return c = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(A, x) { return A.__proto__ = x, A; }, c(o, g); } var p = 100, l = /* @__PURE__ */ function(o) { n(g, o); function g(A, x) { var D; return D = o.call(this, A, x, "[audio-stream-controller]") || this, D.videoBuffer = null, D.videoTrackCC = -1, D.waitingVideoCC = -1, D.audioSwitch = !1, D.trackId = -1, D.waitingData = null, D.mainDetails = null, D.bufferFlushed = !1, D.cachedTrackLoadedData = null, D._registerListeners(), D; } var _ = g.prototype; return _.onHandlerDestroying = function() { this._unregisterListeners(), this.mainDetails = null; }, _._registerListeners = function() { var x = this.hls; x.on(C.Events.MEDIA_ATTACHED, this.onMediaAttached, this), x.on(C.Events.MEDIA_DETACHING, this.onMediaDetaching, this), x.on(C.Events.MANIFEST_LOADING, this.onManifestLoading, this), x.on(C.Events.LEVEL_LOADED, this.onLevelLoaded, this), x.on(C.Events.AUDIO_TRACKS_UPDATED, this.onAudioTracksUpdated, this), x.on(C.Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this), x.on(C.Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this), x.on(C.Events.ERROR, this.onError, this), x.on(C.Events.BUFFER_RESET, this.onBufferReset, this), x.on(C.Events.BUFFER_CREATED, this.onBufferCreated, this), x.on(C.Events.BUFFER_FLUSHED, this.onBufferFlushed, this), x.on(C.Events.INIT_PTS_FOUND, this.onInitPtsFound, this), x.on(C.Events.FRAG_BUFFERED, this.onFragBuffered, this); }, _._unregisterListeners = function() { var x = this.hls; x.off(C.Events.MEDIA_ATTACHED, this.onMediaAttached, this), x.off(C.Events.MEDIA_DETACHING, this.onMediaDetaching, this), x.off(C.Events.MANIFEST_LOADING, this.onManifestLoading, this), x.off(C.Events.LEVEL_LOADED, this.onLevelLoaded, this), x.off(C.Events.AUDIO_TRACKS_UPDATED, this.onAudioTracksUpdated, this), x.off(C.Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this), x.off(C.Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this), x.off(C.Events.ERROR, this.onError, this), x.off(C.Events.BUFFER_RESET, this.onBufferReset, this), x.off(C.Events.BUFFER_CREATED, this.onBufferCreated, this), x.off(C.Events.BUFFER_FLUSHED, this.onBufferFlushed, this), x.off(C.Events.INIT_PTS_FOUND, this.onInitPtsFound, this), x.off(C.Events.FRAG_BUFFERED, this.onFragBuffered, this); }, _.onInitPtsFound = function(x, D) { var L = D.frag, y = D.id, O = D.initPTS; if (y === "main") { var b = L.cc; this.initPTS[L.cc] = O, this.log("InitPTS for cc: " + b + " found from main: " + O), this.videoTrackCC = b, this.state === R.State.WAITING_INIT_PTS && this.tick(); } }, _.startLoad = function(x) { if (!this.levels) { this.startPosition = x, this.state = R.State.STOPPED; return; } var D = this.lastCurrentTime; this.stopLoad(), this.setInterval(p), this.fragLoadError = 0, D > 0 && x === -1 ? (this.log("Override startPosition with lastCurrentTime @" + D.toFixed(3)), x = D, this.state = R.State.IDLE) : (this.loadedmetadata = !1, this.state = R.State.WAITING_TRACK), this.nextLoadPosition = this.startPosition = this.lastCurrentTime = x, this.tick(); }, _.doTick = function() { switch (this.state) { case R.State.IDLE: this.doTickIdle(); break; case R.State.WAITING_TRACK: { var x, D = this.levels, L = this.trackId, y = D == null || (x = D[L]) === null || x === void 0 ? void 0 : x.details; if (y) { if (this.waitForCdnTuneIn(y)) break; this.state = R.State.WAITING_INIT_PTS; } break; } case R.State.FRAG_LOADING_WAITING_RETRY: { var O, b = performance.now(), F = this.retryDate; (!F || b >= F || (O = this.media) !== null && O !== void 0 && O.seeking) && (this.log("RetryDate reached, switch back to IDLE state"), this.resetStartWhenNotLoaded(this.trackId), this.state = R.State.IDLE); break; } case R.State.WAITING_INIT_PTS: { var k = this.waitingData; if (k) { var B = k.frag, K = k.part, j = k.cache, Y = k.complete; if (this.initPTS[B.cc] !== void 0) { this.waitingData = null, this.waitingVideoCC = -1, this.state = R.State.FRAG_LOADING; var z = j.flush(), Q = { frag: B, part: K, payload: z, networkDetails: null }; this._handleFragmentLoadProgress(Q), Y && o.prototype._handleFragmentLoadComplete.call(this, Q); } else if (this.videoTrackCC !== this.waitingVideoCC) this.log("Waiting fragment cc (" + B.cc + ") cancelled because video is at cc " + this.videoTrackCC), this.clearWaitingFragment(); else { var q = this.getLoadPosition(), ne = S.BufferHelper.bufferInfo(this.mediaBuffer, q, this.config.maxBufferHole), re = (0, d.fragmentWithinToleranceTest)(ne.end, this.config.maxFragLookUpTolerance, B); re < 0 && (this.log("Waiting fragment cc (" + B.cc + ") @ " + B.start + " cancelled because another fragment at " + ne.end + " is needed"), this.clearWaitingFragment()); } } else this.state = R.State.IDLE; } } this.onTickEnd(); }, _.clearWaitingFragment = function() { var x = this.waitingData; x && (this.fragmentTracker.removeFragment(x.frag), this.waitingData = null, this.waitingVideoCC = -1, this.state = R.State.IDLE); }, _.resetLoadingState = function() { this.clearWaitingFragment(), o.prototype.resetLoadingState.call(this); }, _.onTickEnd = function() { var x = this.media; if (!(!x || !x.readyState)) { var D = this.mediaBuffer ? this.mediaBuffer : x, L = D.buffered; !this.loadedmetadata && L.length && (this.loadedmetadata = !0), this.lastCurrentTime = x.currentTime; } }, _.doTickIdle = function() { var x, D, L = this.hls, y = this.levels, O = this.media, b = this.trackId, F = L.config; if (!(!y || !y[b]) && !(!O && (this.startFragRequested || !F.startFragPrefetch))) { var k = y[b], B = k.details; if (!B || B.live && this.levelLastLoaded !== b || this.waitForCdnTuneIn(B)) { this.state = R.State.WAITING_TRACK; return; } var K = this.mediaBuffer ? this.mediaBuffer : this.media; this.bufferFlushed && K && (this.bufferFlushed = !1, this.afterBufferFlushed(K, m.ElementaryStreamTypes.AUDIO, v.PlaylistLevelType.AUDIO)); var j = this.getFwdBufferInfo(K, v.PlaylistLevelType.AUDIO); if (j !== null) { var Y = this.getFwdBufferInfo(this.videoBuffer ? this.videoBuffer : this.media, v.PlaylistLevelType.MAIN), z = j.len, Q = this.getMaxBufferLength(Y == null ? void 0 : Y.len), q = this.audioSwitch; if (!(z >= Q && !q)) { if (!q && this._streamEnded(j, B)) { L.trigger(C.Events.BUFFER_EOS, { type: "audio" }), this.state = R.State.ENDED; return; } var ne = B.fragments, re = ne[0].start, le = j.end; if (q && O) { var he = this.getLoadPosition(); le = he, B.PTSKnown && he < re && (j.end > re || j.nextStart) && (this.log("Alt audio track ahead of main track, seek to start of alt audio track"), O.currentTime = re + 0.05); } if (!(Y && le > Y.end + B.targetduration) && !((!Y || !Y.len) && j.len)) { var ce = this.getNextFragment(le, B); if (!ce) { this.bufferFlushed = !0; return; } ((x = ce.decryptdata) === null || x === void 0 ? void 0 : x.keyFormat) === "identity" && !((D = ce.decryptdata) !== null && D !== void 0 && D.key) ? this.loadKey(ce, B) : this.loadFragment(ce, B, le); } } } } }, _.getMaxBufferLength = function(x) { var D = o.prototype.getMaxBufferLength.call(this); return x ? Math.max(D, x) : D; }, _.onMediaDetaching = function() { this.videoBuffer = null, o.prototype.onMediaDetaching.call(this); }, _.onAudioTracksUpdated = function(x, D) { var L = D.audioTracks; this.resetTransmuxer(), this.levels = L.map(function(y) { return new E.Level(y); }); }, _.onAudioTrackSwitching = function(x, D) { var L = !!D.url; this.trackId = D.id; var y = this.fragCurrent; y != null && y.loader && y.loader.abort(), this.fragCurrent = null, this.clearWaitingFragment(), L ? this.setInterval(p) : this.resetTransmuxer(), L ? (this.audioSwitch = !0, this.state = R.State.IDLE) : this.state = R.State.STOPPED, this.tick(); }, _.onManifestLoading = function() { this.mainDetails = null, this.fragmentTracker.removeAllFragments(), this.startPosition = this.lastCurrentTime = 0, this.bufferFlushed = !1; }, _.onLevelLoaded = function(x, D) { this.mainDetails = D.details, this.cachedTrackLoadedData !== null && (this.hls.trigger(C.Events.AUDIO_TRACK_LOADED, this.cachedTrackLoadedData), this.cachedTrackLoadedData = null); }, _.onAudioTrackLoaded = function(x, D) { var L; if (this.mainDetails == null) { this.cachedTrackLoadedData = D; return; } var y = this.levels, O = D.details, b = D.id; if (!y) { this.warn("Audio tracks were reset while loading level " + b); return; } this.log("Track " + b + " loaded [" + O.startSN + "," + O.endSN + "],duration:" + O.totalduration); var F = y[b], k = 0; if (O.live || (L = F.details) !== null && L !== void 0 && L.live) { var B = this.mainDetails; if (O.fragments[0] || (O.deltaUpdateFailed = !0), O.deltaUpdateFailed || !B) return; !F.details && O.hasProgramDateTime && B.hasProgramDateTime ? ((0, s.alignMediaPlaylistByPDT)(O, B), k = O.fragments[0].start) : k = this.alignPlaylists(O, F.details); } F.details = O, this.levelLastLoaded = b, !this.startFragRequested && (this.mainDetails || !O.live) && this.setStartPosition(F.details, k), this.state === R.State.WAITING_TRACK && !this.waitForCdnTuneIn(O) && (this.state = R.State.IDLE), this.tick(); }, _._handleFragmentLoadProgress = function(x) { var D, L = x.frag, y = x.part, O = x.payload, b = this.config, F = this.trackId, k = this.levels; if (!k) { this.warn("Audio tracks were reset while fragment load was in progress. Fragment " + L.sn + " of level " + L.level + " will not be buffered"); return; } var B = k[F]; console.assert(B, "Audio track is defined on fragment load progress"); var K = B.details; console.assert(K, "Audio track details are defined on fragment load progress"); var j = b.defaultAudioCodec || B.audioCodec || "mp4a.40.2", Y = this.transmuxer; Y || (Y = this.transmuxer = new f.default(this.hls, v.PlaylistLevelType.AUDIO, this._handleTransmuxComplete.bind(this), this._handleTransmuxerFlush.bind(this))); var z = this.initPTS[L.cc], Q = (D = L.initSegment) === null || D === void 0 ? void 0 : D.data; if (z !== void 0) { var q = !1, ne = y ? y.index : -1, re = ne !== -1, le = new h.ChunkMetadata(L.level, L.sn, L.stats.chunkCount, O.byteLength, ne, re); Y.push(O, Q, j, "", L, y, K.totalduration, q, le, z); } else { this.log("Unknown video PTS for cc " + L.cc + ", waiting for video PTS before demuxing audio frag " + L.sn + " of [" + K.startSN + " ," + K.endSN + "],track " + F); var he = this.waitingData = this.waitingData || { frag: L, part: y, cache: new u.default(), complete: !1 }, ce = he.cache; ce.push(new Uint8Array(O)), this.waitingVideoCC = this.videoTrackCC, this.state = R.State.WAITING_INIT_PTS; } }, _._handleFragmentLoadComplete = function(x) { if (this.waitingData) { this.waitingData.complete = !0; return; } o.prototype._handleFragmentLoadComplete.call(this, x); }, _.onBufferReset = function() { this.mediaBuffer = this.videoBuffer = null, this.loadedmetadata = !1; }, _.onBufferCreated = function(x, D) { var L = D.tracks.audio; L && (this.mediaBuffer = L.buffer || null), D.tracks.video && (this.videoBuffer = D.tracks.video.buffer || null); }, _.onFragBuffered = function(x, D) { var L = D.frag, y = D.part; if (L.type === v.PlaylistLevelType.AUDIO) { if (this.fragContextChanged(L)) { this.warn("Fragment " + L.sn + (y ? " p: " + y.index : "") + " of level " + L.level + " finished buffering, but was aborted. state: " + this.state + ", audioSwitch: " + this.audioSwitch); return; } L.sn !== "initSegment" && (this.fragPrevious = L, this.audioSwitch && (this.audioSwitch = !1, this.hls.trigger(C.Events.AUDIO_TRACK_SWITCHED, { id: this.trackId }))), this.fragBufferedComplete(L, y); } }, _.onError = function(x, D) { switch (D.details) { case r.ErrorDetails.FRAG_LOAD_ERROR: case r.ErrorDetails.FRAG_LOAD_TIMEOUT: case r.ErrorDetails.KEY_LOAD_ERROR: case r.ErrorDetails.KEY_LOAD_TIMEOUT: this.onFragmentOrKeyLoadError(v.PlaylistLevelType.AUDIO, D); break; case r.ErrorDetails.AUDIO_TRACK_LOAD_ERROR: case r.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT: this.state !== R.State.ERROR && this.state !== R.State.STOPPED && (this.state = D.fatal ? R.State.ERROR : R.State.IDLE, this.warn(D.details + " while loading frag, switching to " + this.state + " state")); break; case r.ErrorDetails.BUFFER_FULL_ERROR: if (D.parent === "audio" && (this.state === R.State.PARSING || this.state === R.State.PARSED)) { var L = !0, y = this.getFwdBufferInfo(this.mediaBuffer, v.PlaylistLevelType.AUDIO); y && y.len > 0.5 && (L = !this.reduceMaxBufferLength(y.len)), L && (this.warn("Buffer full error also media.currentTime is not buffered, flush audio buffer"), this.fragCurrent = null, o.prototype.flushMainBuffer.call(this, 0, Number.POSITIVE_INFINITY, "audio")), this.resetLoadingState(); } break; } }, _.onBufferFlushed = function(x, D) { var L = D.type; L === m.ElementaryStreamTypes.AUDIO && (this.bufferFlushed = !0); }, _._handleTransmuxComplete = function(x) { var D, L = "audio", y = this.hls, O = x.remuxResult, b = x.chunkMeta, F = this.getCurrentContext(b); if (!F) { this.warn("The loading context changed while buffering fragment " + b.sn + " of level " + b.level + ". This chunk will not be buffered."), this.resetStartWhenNotLoaded(b.level); return; } var k = F.frag, B = F.part, K = F.level.details, j = O.audio, Y = O.text, z = O.id3, Q = O.initSegment; if (!(this.fragContextChanged(k) || !K)) { if (this.state = R.State.PARSING, this.audioSwitch && j && this.completeAudioSwitch(), Q != null && Q.tracks && (this._bufferInitSegment(Q.tracks, k, b), y.trigger(C.Events.FRAG_PARSING_INIT_SEGMENT, { frag: k, id: L, tracks: Q.tracks })), j) { var q = j.startPTS, ne = j.endPTS, re = j.startDTS, le = j.endDTS; B && (B.elementaryStreams[m.ElementaryStreamTypes.AUDIO] = { startPTS: q, endPTS: ne, startDTS: re, endDTS: le }), k.setElementaryStreamInfo(m.ElementaryStreamTypes.AUDIO, q, ne, re, le), this.bufferFragmentData(j, k, B, b); } if (z != null && (D = z.samples) !== null && D !== void 0 && D.length) { var he = i({ id: L, frag: k, details: K }, z); y.trigger(C.Events.FRAG_PARSING_METADATA, he); } if (Y) { var ce = i({ id: L, frag: k, details: K }, Y); y.trigger(C.Events.FRAG_PARSING_USERDATA, ce); } } }, _._bufferInitSegment = function(x, D, L) { if (this.state === R.State.PARSING) { x.video && delete x.video; var y = x.audio; if (!!y) { y.levelCodec = y.codec, y.id = "audio", this.log("Init audio buffer, container:" + y.container + ", codecs[parsed]=[" + y.codec + "]"), this.hls.trigger(C.Events.BUFFER_CODECS, x); var O = y.initSegment; if (O != null && O.byteLength) { var b = { type: "audio", frag: D, part: null, chunkMeta: L, parent: D.type, data: O }; this.hls.trigger(C.Events.BUFFER_APPENDING, b); } this.tick(); } } }, _.loadFragment = function(x, D, L) { var y = this.fragmentTracker.getState(x); this.fragCurrent = x, (this.audioSwitch || y === P.FragmentState.NOT_LOADED || y === P.FragmentState.PARTIAL) && (x.sn === "initSegment" ? this._loadInitSegment(x) : D.live && !(0, w.isFiniteNumber)(this.initPTS[x.cc]) ? (this.log("Waiting for video PTS in continuity counter " + x.cc + " of live stream before loading audio fragment " + x.sn + " of level " + this.trackId), this.state = R.State.WAITING_INIT_PTS) : (this.startFragRequested = !0, o.prototype.loadFragment.call(this, x, D, L))); }, _.completeAudioSwitch = function() { var x = this.hls, D = this.media, L = this.trackId; D && (this.log("Switching audio track : flushing all audio"), o.prototype.flushMainBuffer.call(this, 0, Number.POSITIVE_INFINITY, "audio")), this.audioSwitch = !1, x.trigger(C.Events.AUDIO_TRACK_SWITCHED, { id: L }); }, g; }(R.default); const a = l; }, "./src/controller/audio-track-controller.ts": (H, U, I) => { I.r(U), I.d(U, { default: () => f }); var w = I("./src/events.ts"), R = I("./src/errors.ts"), C = I("./src/controller/base-playlist-controller.ts"), S = I("./src/types/loader.ts"); function P(h, d) { for (var s = 0; s < d.length; s++) { var r = d[s]; r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(h, r.key, r); } } function E(h, d, s) { return d && P(h.prototype, d), s && P(h, s), Object.defineProperty(h, "prototype", { writable: !1 }), h; } function v(h, d) { h.prototype = Object.create(d.prototype), h.prototype.constructor = h, m(h, d); } function m(h, d) { return m = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(r, i) { return r.__proto__ = i, r; }, m(h, d); } var u = /* @__PURE__ */ function(h) { v(d, h); function d(r) { var i; return i = h.call(this, r, "[audio-track-controller]") || this, i.tracks = [], i.groupId = null, i.tracksInGroup = [], i.trackId = -1, i.trackName = "", i.selectDefaultTrack = !0, i.registerListeners(), i; } var s = d.prototype; return s.registerListeners = function() { var i = this.hls; i.on(w.Events.MANIFEST_LOADING, this.onManifestLoading, this), i.on(w.Events.MANIFEST_PARSED, this.onManifestParsed, this), i.on(w.Events.LEVEL_LOADING, this.onLevelLoading, this), i.on(w.Events.LEVEL_SWITCHING, this.onLevelSwitching, this), i.on(w.Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this), i.on(w.Events.ERROR, this.onError, this); }, s.unregisterListeners = function() { var i = this.hls; i.off(w.Events.MANIFEST_LOADING, this.onManifestLoading, this), i.off(w.Events.MANIFEST_PARSED, this.onManifestParsed, this), i.off(w.Events.LEVEL_LOADING, this.onLevelLoading, this), i.off(w.Events.LEVEL_SWITCHING, this.onLevelSwitching, this), i.off(w.Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this), i.off(w.Events.ERROR, this.onError, this); }, s.destroy = function() { this.unregisterListeners(), this.tracks.length = 0, this.tracksInGroup.length = 0, h.prototype.destroy.call(this); }, s.onManifestLoading = function() { this.tracks = [], this.groupId = null, this.tracksInGroup = [], this.trackId = -1, this.trackName = "", this.selectDefaultTrack = !0; }, s.onManifestParsed = function(i, n) { this.tracks = n.audioTracks || []; }, s.onAudioTrackLoaded = function(i, n) { var c = n.id, p = n.details, l = this.tracksInGroup[c]; if (!l) { this.warn("Invalid audio track id " + c); return; } var a = l.details; l.details = n.details, this.log("audioTrack " + c + " loaded [" + p.startSN + "-" + p.endSN + "]"), c === this.trackId && (this.retryCount = 0, this.playlistLoaded(c, n, a)); }, s.onLevelLoading = function(i, n) { this.switchLevel(n.level); }, s.onLevelSwitching = function(i, n) { this.switchLevel(n.level); }, s.switchLevel = function(i) { var n = this.hls.levels[i]; if (!!(n != null && n.audioGroupIds)) { var c = n.audioGroupIds[n.urlId]; if (this.groupId !== c) { this.groupId = c; var p = this.tracks.filter(function(a) { return !c || a.groupId === c; }); this.selectDefaultTrack && !p.some(function(a) { return a.default; }) && (this.selectDefaultTrack = !1), this.tracksInGroup = p; var l = { audioTracks: p }; this.log("Updating audio tracks, " + p.length + ' track(s) found in "' + c + '" group-id'), this.hls.trigger(w.Events.AUDIO_TRACKS_UPDATED, l), this.selectInitialTrack(); } } }, s.onError = function(i, n) { h.prototype.onError.call(this, i, n), !(n.fatal || !n.context) && n.context.type === S.PlaylistContextType.AUDIO_TRACK && n.context.id === this.trackId && n.context.groupId === this.groupId && this.retryLoadingOrFail(n); }, s.setAudioTrack = function(i) { var n = this.tracksInGroup; if (i < 0 || i >= n.length) { this.warn("Invalid id passed to audio-track controller"); return; } this.clearTimer(); var c = n[this.trackId]; this.log("Now switching to audio-track index " + i); var p = n[i], l = p.id, a = p.groupId, o = a === void 0 ? "" : a, g = p.name, _ = p.type, A = p.url; if (this.trackId = i, this.trackName = g, this.selectDefaultTrack = !1, this.hls.trigger(w.Events.AUDIO_TRACK_SWITCHING, { id: l, groupId: o, name: g, type: _, url: A }), !(p.details && !p.details.live)) { var x = this.switchParams(p.url, c == null ? void 0 : c.details); this.loadPlaylist(x); } }, s.selectInitialTrack = function() { var i = this.tracksInGroup; console.assert(i.length, "Initial audio track should be selected when tracks are known"); var n = this.trackName, c = this.findTrackId(n) || this.findTrackId(); c !== -1 ? this.setAudioTrack(c) : (this.warn("No track found for running audio group-ID: " + this.groupId), this.hls.trigger(w.Events.ERROR, { type: R.ErrorTypes.MEDIA_ERROR, details: R.ErrorDetails.AUDIO_TRACK_LOAD_ERROR, fatal: !0 })); }, s.findTrackId = function(i) { for (var n = this.tracksInGroup, c = 0; c < n.length; c++) { var p = n[c]; if ((!this.selectDefaultTrack || p.default) && (!i || i === p.name)) return p.id; } return -1; }, s.loadPlaylist = function(i) { var n = this.tracksInGroup[this.trackId]; if (this.shouldLoadTrack(n)) { var c = n.id, p = n.groupId, l = n.url; if (i) try { l = i.addDirectives(l); } catch (a) { this.warn("Could not construct new URL with HLS Delivery Directives: " + a); } this.log("loading audio-track playlist for id: " + c), this.clearTimer(), this.hls.trigger(w.Events.AUDIO_TRACK_LOADING, { url: l, id: c, groupId: p, deliveryDirectives: i || null }); } }, E(d, [{ key: "audioTracks", get: function() { return this.tracksInGroup; } }, { key: "audioTrack", get: function() { return this.trackId; }, set: function(i) { this.selectDefaultTrack = !1, this.setAudioTrack(i); } }]), d; }(C.default); const f = u; }, "./src/controller/base-playlist-controller.ts": (H, U, I) => { I.r(U), I.d(U, { default: () => E }); var w = I("./src/polyfills/number.ts"), R = I("./src/types/level.ts"), C = I("./src/controller/level-helper.ts"), S = I("./src/utils/logger.ts"), P = I("./src/errors.ts"), E = /* @__PURE__ */ function() { function v(u, f) { this.hls = void 0, this.timer = -1, this.canLoad = !1, this.retryCount = 0, this.log = void 0, this.warn = void 0, this.log = S.logger.log.bind(S.logger, f + ":"), this.warn = S.logger.warn.bind(S.logger, f + ":"), this.hls = u; } var m = v.prototype; return m.destroy = function() { this.clearTimer(), this.hls = this.log = this.warn = null; }, m.onError = function(f, h) { h.fatal && h.type === P.ErrorTypes.NETWORK_ERROR && this.clearTimer(); }, m.clearTimer = function() { clearTimeout(this.timer), this.timer = -1; }, m.startLoad = function() { this.canLoad = !0, this.retryCount = 0, this.loadPlaylist(); }, m.stopLoad = function() { this.canLoad = !1, this.clearTimer(); }, m.switchParams = function(f, h) { var d = h == null ? void 0 : h.renditionReports; if (d) for (var s = 0; s < d.length; s++) { var r = d[s], i = "" + r.URI; if (i === f.slice(-i.length)) { var n = parseInt(r["LAST-MSN"]), c = parseInt(r["LAST-PART"]); if (h && this.hls.config.lowLatencyMode) { var p = Math.min(h.age - h.partTarget, h.targetduration); c !== void 0 && p > h.partTarget && (c += 1); } if ((0, w.isFiniteNumber)(n)) return new R.HlsUrlParameters(n, (0, w.isFiniteNumber)(c) ? c : void 0, R.HlsSkip.No); } } }, m.loadPlaylist = function(f) { }, m.shouldLoadTrack = function(f) { return this.canLoad && f && !!f.url && (!f.details || f.details.live); }, m.playlistLoaded = function(f, h, d) { var s = this, r = h.details, i = h.stats, n = i.loading.end ? Math.max(0, self.performance.now() - i.loading.end) : 0; if (r.advancedDateTime = Date.now() - n, r.live || d != null && d.live) { if (r.reloaded(d), d && this.log("live playlist " + f + " " + (r.advanced ? "REFRESHED " + r.lastPartSn + "-" + r.lastPartIndex : "MISSED")), d && r.fragments.length > 0 && (0, C.mergeDetails)(d, r), !this.canLoad || !r.live) return; var c, p = void 0, l = void 0; if (r.canBlockReload && r.endSN && r.advanced) { var a = this.hls.config.lowLatencyMode, o = r.lastPartSn, g = r.endSN, _ = r.lastPartIndex, A = _ !== -1, x = o === g, D = a ? 0 : _; A ? (p = x ? g + 1 : o, l = x ? D : _ + 1) : p = g + 1; var L = r.age, y = L + r.ageHeader, O = Math.min(y - r.partTarget, r.targetduration * 1.5); if (O > 0) { if (d && O > d.tuneInGoal) this.warn("CDN Tune-in goal increased from: " + d.tuneInGoal + " to: " + O + " with playlist age: " + r.age), O = 0; else { var b = Math.floor(O / r.targetduration); if (p += b, l !== void 0) { var F = Math.round(O % r.targetduration / r.partTarget); l += F; }