@vindral/web-sdk 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/BsfwXDui.js ADDED
@@ -0,0 +1,65 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/typeof.js
2
+ function e(t) {
3
+ "@babel/helpers - typeof";
4
+ return e = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
5
+ return typeof e;
6
+ } : function(e) {
7
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
8
+ }, e(t);
9
+ }
10
+ //#endregion
11
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
12
+ function t(t, n) {
13
+ if (e(t) != "object" || !t) return t;
14
+ var r = t[Symbol.toPrimitive];
15
+ if (r !== void 0) {
16
+ var i = r.call(t, n || "default");
17
+ if (e(i) != "object") return i;
18
+ throw TypeError("@@toPrimitive must return a primitive value.");
19
+ }
20
+ return (n === "string" ? String : Number)(t);
21
+ }
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
24
+ function n(n) {
25
+ var r = t(n, "string");
26
+ return e(r) == "symbol" ? r : r + "";
27
+ }
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
30
+ function r(e, t, r) {
31
+ return (t = n(t)) in e ? Object.defineProperty(e, t, {
32
+ value: r,
33
+ enumerable: !0,
34
+ configurable: !0,
35
+ writable: !0
36
+ }) : e[t] = r, e;
37
+ }
38
+ //#endregion
39
+ //#region \0@oxc-project+runtime@0.115.0/helpers/asyncToGenerator.js
40
+ function i(e, t, n, r, i, a, o) {
41
+ try {
42
+ var s = e[a](o), c = s.value;
43
+ } catch (e) {
44
+ n(e);
45
+ return;
46
+ }
47
+ s.done ? t(c) : Promise.resolve(c).then(r, i);
48
+ }
49
+ function a(e) {
50
+ return function() {
51
+ var t = this, n = arguments;
52
+ return new Promise(function(r, a) {
53
+ var o = e.apply(t, n);
54
+ function s(e) {
55
+ i(o, r, a, s, c, "next", e);
56
+ }
57
+ function c(e) {
58
+ i(o, r, a, s, c, "throw", e);
59
+ }
60
+ s(void 0);
61
+ });
62
+ };
63
+ }
64
+ //#endregion
65
+ export { r as n, a as t };
package/Bt-ONXfO.js ADDED
@@ -0,0 +1,59 @@
1
+ //#region ../../libs/media/src/aac.ts
2
+ var e = [
3
+ 96e3,
4
+ 88200,
5
+ 64e3,
6
+ 48e3,
7
+ 44100,
8
+ 32e3,
9
+ 24e3,
10
+ 22050,
11
+ 16e3,
12
+ 12e3,
13
+ 11025,
14
+ 8e3,
15
+ 7350
16
+ ], t = (t, n) => {
17
+ let r = e.indexOf(n);
18
+ if (r === -1 || t < 1 || t > 8 || t === 7) return;
19
+ let i = /* @__PURE__ */ new ArrayBuffer(2), a = new Uint8Array(i), o = t === 8 ? 7 : t;
20
+ return a[0] = 16 | r >> 1, a[1] = (r & 1) << 7 | o << 3, i;
21
+ }, n = (e) => {
22
+ if (!e) return;
23
+ let t = e.channelMappingTable, n = new Uint8Array(19 + t.byteLength), r = new DataView(n.buffer, n.byteOffset, n.byteLength);
24
+ return n.set([
25
+ 79,
26
+ 112,
27
+ 117,
28
+ 115,
29
+ 72,
30
+ 101,
31
+ 97,
32
+ 100
33
+ ], 0), r.setUint8(8, 1), r.setUint8(9, e.channelCount), r.setUint16(10, e.preSkip, !0), r.setUint32(12, e.inputSampleRate, !0), r.setInt16(16, e.outputGain, !0), r.setUint8(18, e.channelMappingFamily), t.byteLength > 0 && n.set(t, 19), n;
34
+ }, r = (e, t) => {
35
+ if (e < 1 || e > 2) return;
36
+ let n = new Uint8Array(19), r = new DataView(n.buffer, n.byteOffset, n.byteLength);
37
+ return n.set([
38
+ 79,
39
+ 112,
40
+ 117,
41
+ 115,
42
+ 72,
43
+ 101,
44
+ 97,
45
+ 100
46
+ ]), r.setUint8(8, 1), r.setUint8(9, e), r.setUint16(10, 3840, !0), r.setUint32(12, t, !0), r.setInt16(16, 0, !0), r.setUint8(18, 0), n;
47
+ }, i = (e) => {
48
+ switch (e) {
49
+ case "opus": return "opus";
50
+ case "aac": return "mp4a.40.2";
51
+ case "mp3": return "mp3";
52
+ default: {
53
+ let t = e;
54
+ throw Error(`Unsupported audio codec: ${t}`);
55
+ }
56
+ }
57
+ };
58
+ //#endregion
59
+ export { t as i, r as n, n as r, i as t };
package/C01DcfYu.js ADDED
@@ -0,0 +1,118 @@
1
+ import { n as e } from "./BsfwXDui.js";
2
+ import { t } from "./RxoWWyzp.js";
3
+ //#region ../../libs/utils/src/noop.ts
4
+ var n = () => {}, r = "connection_failed", i = "connection_failed_will_not_attempt_again", a = "authentication_error", o = "authentication_expired", s = "channel_not_found", c = "no_incoming_data_error", l = "connection_inactivity", u = "missing_init_segment", d = "no_track_context", f = "invalid_track_context_state", p = "disconnected_by_edge", m = "decoder_error", h = "audio_player_error", g = "unsupported_audio_codec", _ = "media_source_error", v = "webgl_context_lost_error", y = "access_forbidden", b = "channel_switch_failed", x = "drm_error", S = class extends Error {
5
+ constructor(n, r, i = {}) {
6
+ super(n), e(this, "props", void 0), e(this, "extra", {}), e(this, "code", () => this.props.code), e(this, "isFatal", () => this.props.isFatal), e(this, "source", () => this.props.source), e(this, "type", () => {
7
+ var e;
8
+ return (e = this.props.type) == null ? "external" : e;
9
+ }), e(this, "toStringifiable", () => {
10
+ var e;
11
+ let n = this.source(), r = n instanceof Error ? n.stack : this.stack;
12
+ return t(t({}, this.extra), {}, {
13
+ code: this.props.code,
14
+ isFatal: this.props.isFatal,
15
+ type: this.props.type,
16
+ message: this.message,
17
+ sourceMessage: (e = this.source()) == null ? void 0 : e.message,
18
+ stack: r
19
+ });
20
+ }), this.props = r, this.extra = i, Object.setPrototypeOf(this, new.target.prototype);
21
+ }
22
+ }, C = (e, t) => new S("MediaElement Error", {
23
+ isFatal: e,
24
+ code: "media_element_error",
25
+ source: t
26
+ }, { mediaErrorCode: t.code }), w = (e, t) => new S("Decoder Error", {
27
+ isFatal: e,
28
+ code: m,
29
+ source: t,
30
+ type: "internal"
31
+ }), T = (e, t, n) => new S(`No decoder available for audio codec "${e}" in non-MSE playback. ${t}`, {
32
+ isFatal: !0,
33
+ code: g,
34
+ source: n,
35
+ type: "external"
36
+ }, {
37
+ codec: e,
38
+ reason: t
39
+ }), E = (e, t) => new S("Audio Player Error", {
40
+ isFatal: e,
41
+ code: h,
42
+ source: t,
43
+ type: "internal"
44
+ }), D = (e, t) => new S(`No init segment for rendition id ${e} for channel ${t}`, {
45
+ isFatal: !1,
46
+ code: u,
47
+ type: "internal"
48
+ }), O = (e, t, n, r) => new S("MediaSource Error", {
49
+ isFatal: e,
50
+ code: _,
51
+ source: t,
52
+ type: "internal"
53
+ }, {
54
+ type: r,
55
+ consecutiveErrorsCount: n
56
+ }), k = (e, t) => new S(`No track context for ${e}${t ? `, rendition id ${t}` : ""}`, {
57
+ isFatal: !1,
58
+ code: d,
59
+ type: "internal"
60
+ }), A = (e, t) => new S(`Track context is in an invalid state for ${e}${t ? `, rendition id ${t}` : ""}`, {
61
+ isFatal: !1,
62
+ code: f,
63
+ type: "internal"
64
+ }), j = () => new S("Web Audio Context resume timeout", {
65
+ isFatal: !1,
66
+ code: "web_audio_context_resume_timeout"
67
+ }), M = (e) => new S("Disconnected From Edge Server", {
68
+ type: "external",
69
+ source: e,
70
+ isFatal: !1,
71
+ code: p
72
+ }), N = (e) => new S("Authentication Failed", {
73
+ isFatal: !0,
74
+ code: a,
75
+ source: e
76
+ }), P = (e) => new S("Authentication Expired", {
77
+ isFatal: !0,
78
+ code: o,
79
+ source: e
80
+ }), F = (e, t) => new S("Connection closed due to inactivity", {
81
+ isFatal: !1,
82
+ code: l,
83
+ source: t,
84
+ type: e
85
+ }), I = (e, t) => new S("Channel not found", {
86
+ isFatal: !1,
87
+ code: s,
88
+ source: t,
89
+ type: e
90
+ }), L = (e) => new S("No Incoming Data", {
91
+ isFatal: !1,
92
+ code: c,
93
+ source: e
94
+ }), R = (e) => new S("Connection attempt failed", {
95
+ isFatal: !1,
96
+ code: r,
97
+ source: e
98
+ }), z = () => new S("Connection failed - no more reconnect attempts", {
99
+ isFatal: !0,
100
+ code: i
101
+ }), B = (e) => new S("WebGL Context Lost", {
102
+ isFatal: !1,
103
+ code: v,
104
+ source: e,
105
+ type: "internal"
106
+ }), V = (e) => new S(e, {
107
+ isFatal: !0,
108
+ code: y
109
+ }), H = (e) => new S(`Channel switch to '${e}' failed`, {
110
+ isFatal: !1,
111
+ code: b
112
+ }), U = (e, t = !1, n) => new S(e, {
113
+ isFatal: t,
114
+ code: x,
115
+ source: n
116
+ });
117
+ //#endregion
118
+ export { T as A, C, k as D, L as E, n as M, z as O, A as S, D as T, H as _, i as a, U as b, l as c, V as d, j as f, I as g, P as h, s as i, B as j, R as k, c as l, N as m, o as n, r as o, E as p, a as r, p as s, y as t, S as u, w as v, O as w, F as x, M as y };
package/CF-41rJe.js ADDED
@@ -0,0 +1,223 @@
1
+ import { n as e } from "./BsfwXDui.js";
2
+ import { a as t, n, r } from "./B7hT-BKr.js";
3
+ //#region ../../libs/utils/src/formatting.ts
4
+ var i = 1e3, a = i * 1e3, o = a * 1e3, s = (e, t, n) => e % t === 0 ? e / t : (e / t).toFixed(n), c = (e, t = 1) => e >= o ? `${s(e, o, t)} Gbit/s` : e >= a ? `${s(e, a, t)} Mbit/s` : e >= i ? `${s(e, i, t)} Kbit/s` : `${e} bit/s`, l = ({ width: e, height: t }) => `${e}x${t}`, u = {
5
+ PAUSED: "paused",
6
+ MUTED: "muted",
7
+ USER_INTERACTING: "user-interacting",
8
+ IS_CASTING: "is-casting",
9
+ CAST_AVAILABLE: "cast-available",
10
+ CAST_RECEIVER_NAME: "cast-receiver-name",
11
+ BUFFERING: "buffering",
12
+ UI_LOCKED: "ui-locked",
13
+ HIDE_UI_ON_PAUSE: "hide-ui-on-pause",
14
+ FULLSCREEN: "is-fullscreen",
15
+ FULLSCREEN_FALLBACK: "is-fullscreen-fallback",
16
+ RENDITION_LEVELS: "rendition-levels",
17
+ RENDITION_LEVEL: "rendition-level",
18
+ MAX_VIDEO_BITRATE: "max-video-bit-rate",
19
+ MAX_INITIAL_BITRATE: "max-initial-bit-rate",
20
+ ABR_ENABLED: "abr-enabled",
21
+ SIZE_BASED_RESOLUTION_CAP_ENABLED: "size-based-resolution-cap-enabled",
22
+ CHANNELS: "channels",
23
+ CHANNEL_ID: "channel-id",
24
+ CHANNEL_GROUP_ID: "channel-group-id",
25
+ PIP_AVAILABLE: "pip-available",
26
+ IS_PIP: "is-pip",
27
+ AIRPLAY_AVAILABLE: "airplay-available",
28
+ IS_AIRPLAYING: "is-airplaying",
29
+ MEDIA: "media",
30
+ LANGUAGES: "languages",
31
+ LANGUAGE: "language",
32
+ TEXT_TRACKS: "text-tracks",
33
+ TEXT_TRACK: "text-track",
34
+ NEEDS_USER_INPUT_VIDEO: "needs-user-input-video",
35
+ NEEDS_USER_INPUT_AUDIO: "needs-user-input-audio",
36
+ AUTHENTICATION_TOKEN: "authentication-token",
37
+ VOLUME: "volume",
38
+ VOLUME_LEVEL: "volume-level",
39
+ CAST_ENABLED: "cast",
40
+ AIRPLAY_ENABLED: "airplay",
41
+ PIP_ENABLED: "pip",
42
+ FULLSCREEN_ENABLED: "fullscreen",
43
+ VU_METER_ENABLED: "vu-meter",
44
+ TIMESHIFT_ENABLED: "timeshift",
45
+ TIMESHIFT_POSITION: "timeshift-position",
46
+ POSTER_SRC: "poster-src",
47
+ DURATION: "duration",
48
+ DEBUG_PANEL_OPEN: "debug-panel-open",
49
+ TARGET_BUFFER_TIME: "target-buffer-time",
50
+ DRIFT: "drift",
51
+ PLAYBACK_LATENCY: "playback-latency",
52
+ CONNECTION_STATE: "connection-state"
53
+ }, d = Object.values(u), f = {
54
+ PLAY: "play",
55
+ PAUSE: "pause",
56
+ MUTE: "mute",
57
+ UNMUTE: "unmute",
58
+ LOCK_UI: "lock-ui",
59
+ UNLOCK_UI: "unlock-ui",
60
+ ENTER_FULLSCREEN: "enter-fullscreen",
61
+ EXIT_FULLSCREEN: "exit-fullscreen",
62
+ SET_RENDITION: "set-rendition",
63
+ SET_ABR_MODE: "set-abr-mode",
64
+ SET_SIZE_BASED_RESOLUTION_CAP_MODE: "set-size-based-resolution-cap-mode",
65
+ CHANNEL_GRID_OPENED: "channel-grid-opened",
66
+ CHANNEL_GRID_CLOSED: "channel-grid-closed",
67
+ ENTER_PIP: "enter-pip",
68
+ EXIT_PIP: "exit-pip",
69
+ REQUEST_AIRPLAY: "request-airplay",
70
+ SET_LANGUAGE: "set-language",
71
+ SET_TEXT_TRACK: "set-text-track",
72
+ REQUEST_USER_INPUT: "request-user-input",
73
+ SET_VOLUME: "set-volume",
74
+ SEEK: "seek",
75
+ GO_LIVE: "go-live",
76
+ TOGGLE_DEBUG_PANEL: "toggle-debug-panel",
77
+ SET_TARGET_BUFFER_TIME: "set-target-buffer-time"
78
+ };
79
+ //#endregion
80
+ //#region ../../libs/player-next/src/utils/vindralAttributesUtils.ts
81
+ function p(e) {
82
+ return e === "audio" || e === "video" || e === "audio+video" ? e : "audio+video";
83
+ }
84
+ function m(e) {
85
+ return e === "trace" || e === "debug" || e === "info" || e === "warn" || e === "error" || e === "off" ? e : "off";
86
+ }
87
+ function h(e) {
88
+ if (e === null) return;
89
+ let t = e.split(",").map((e) => e.trim()).filter((e) => e === "h264" || e === "h265" || e === "av1");
90
+ if (t.length !== 0) return t;
91
+ }
92
+ function g(e) {
93
+ if (e !== null) try {
94
+ let t = JSON.parse(e);
95
+ if (typeof t == "object" && t) {
96
+ let e = t;
97
+ if (typeof e.width == "number" && typeof e.height == "number") return e;
98
+ }
99
+ } catch (e) {
100
+ return;
101
+ }
102
+ }
103
+ function _(e) {
104
+ if (e !== null) try {
105
+ let t = JSON.parse(e);
106
+ if (typeof t == "object" && t) return t;
107
+ } catch (e) {
108
+ return;
109
+ }
110
+ }
111
+ function v(e) {
112
+ if (e === null) return;
113
+ let t = parseFloat(e);
114
+ return Number.isNaN(t) ? void 0 : t;
115
+ }
116
+ function y(e) {
117
+ return typeof e == "string";
118
+ }
119
+ function b(e, t) {
120
+ if (e === null) return t == null ? void 0 : t;
121
+ let n = e.toLowerCase();
122
+ return n === "false" ? !1 : n === "true" || n === "" || t == null ? !0 : t;
123
+ }
124
+ function x(e, t) {
125
+ return e === null ? t == null ? void 0 : t : e === "" || e.toLowerCase() === "true" ? !0 : e.toLowerCase() === "false" ? !1 : e;
126
+ }
127
+ function S(e) {
128
+ if (e === null) return;
129
+ let t = {}, n = e.split(",");
130
+ for (let e of n) {
131
+ let [n, r] = e.split(":");
132
+ n && r && (t[n.trim()] = r.trim());
133
+ }
134
+ return Object.keys(t).length > 0 ? t : void 0;
135
+ }
136
+ function C(e) {
137
+ if (e === null) return;
138
+ let t = e.split(",").map((e) => e.trim()).filter((e) => e.length > 0);
139
+ return t.length > 0 ? t : void 0;
140
+ }
141
+ //#endregion
142
+ //#region ../../libs/player-next/src/components/VindralButton.ts
143
+ var w = document.createElement("template");
144
+ w.innerHTML = "\n <style>\n :host {\n cursor: pointer;\n color: var(--fg-strong);\n padding: var(--button-padding);\n background: transparent;\n transition: background 0.2s linear;\n -webkit-tap-highlight-color: transparent;\n }\n\n :host(:focus-visible) {\n box-shadow: inset 0 0 0 2px var(--fg-strong);\n outline: 0;\n }\n\n :host(:where(:focus)) {\n box-shadow: none;\n outline: 0;\n }\n\n @media (hover: hover) and (pointer: fine) {\n :host(:hover) {\n background: rgba(255, 255, 255, 0.15);\n }\n }\n\n :host(:active) {\n background: rgba(255, 255, 255, 0.25);\n }\n\n :host(:active) svg {\n scale: 0.9;\n }\n\n :host([disabled]) {\n opacity: 0.5;\n background: transparent;\n }\n\n slot > svg {\n display: block;\n width: var(--button-icon-size);\n height: var(--button-icon-size);\n }\n </style>\n";
145
+ var T = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), k = class extends HTMLElement {
146
+ constructor() {
147
+ super(), t(this, T, null), t(this, E, (e) => {
148
+ this.handleClick(e);
149
+ }), t(this, D, (e) => {
150
+ let { key: t } = e;
151
+ if (!this.keysUsed.includes(t)) {
152
+ this.removeEventListener("keyup", n(D, this));
153
+ return;
154
+ }
155
+ this.handleClick(e);
156
+ }), t(this, O, (e) => {
157
+ let { metaKey: t, altKey: r, key: i } = e;
158
+ if (t || r || !this.keysUsed.includes(i)) {
159
+ this.removeEventListener("keyup", n(D, this));
160
+ return;
161
+ }
162
+ this.addEventListener("keyup", n(D, this), { once: !0 });
163
+ }), this.attachShadow({ mode: "open" }).appendChild(w.content.cloneNode(!0));
164
+ }
165
+ get keysUsed() {
166
+ return ["Enter", " "];
167
+ }
168
+ connectedCallback() {
169
+ var e;
170
+ r(T, this, this.closest("vindral-controller")), (e = n(T, this)) == null || e.connectListener(this), this.hasAttribute("disabled") || this.enable(), this.setAttribute("role", "button");
171
+ }
172
+ enable() {
173
+ this.addEventListener("click", n(E, this)), this.addEventListener("keydown", n(O, this)), this.tabIndex = 0;
174
+ }
175
+ disable() {
176
+ this.removeEventListener("click", n(E, this)), this.removeEventListener("keydown", n(O, this)), this.removeEventListener("keyup", n(D, this)), this.tabIndex = -1;
177
+ }
178
+ disconnectedCallback() {
179
+ var e;
180
+ (e = n(T, this)) == null || e.disconnectListener(this);
181
+ }
182
+ attributeChangedCallback(e, t, n) {
183
+ e === "disabled" && (y(n) ? this.disable() : this.enable());
184
+ }
185
+ };
186
+ e(k, "observedAttributes", ["disabled"]);
187
+ //#endregion
188
+ //#region \0@oxc-project+runtime@0.115.0/helpers/getPrototypeOf.js
189
+ function A(e) {
190
+ return A = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(e) {
191
+ return e.__proto__ || Object.getPrototypeOf(e);
192
+ }, A(e);
193
+ }
194
+ //#endregion
195
+ //#region \0@oxc-project+runtime@0.115.0/helpers/superPropBase.js
196
+ function j(e, t) {
197
+ for (; !{}.hasOwnProperty.call(e, t) && (e = A(e)) !== null;);
198
+ return e;
199
+ }
200
+ //#endregion
201
+ //#region \0@oxc-project+runtime@0.115.0/helpers/get.js
202
+ function M() {
203
+ return M = typeof Reflect < "u" && Reflect.get ? Reflect.get.bind() : function(e, t, n) {
204
+ var r = j(e, t);
205
+ if (r) {
206
+ var i = Object.getOwnPropertyDescriptor(r, t);
207
+ return i.get ? i.get.call(arguments.length < 3 ? e : n) : i.value;
208
+ }
209
+ }, M.apply(null, arguments);
210
+ }
211
+ //#endregion
212
+ //#region \0@oxc-project+runtime@0.115.0/helpers/superPropGet.js
213
+ function N(e, t, n, r) {
214
+ var i = M(A(1 & r ? e.prototype : e), t, n);
215
+ return 2 & r && typeof i == "function" ? function(e) {
216
+ return i.apply(n, e);
217
+ } : i;
218
+ }
219
+ //#endregion
220
+ //#region ../../libs/player-next/src/constants.ts
221
+ var P = 5e3;
222
+ //#endregion
223
+ export { d as _, _ as a, m as c, p as d, v as f, u as g, f as h, y as i, S as l, h as m, N as n, b as o, C as p, k as r, x as s, P as t, g as u, c as v, l as y };
package/Cug44nXk.js ADDED
@@ -0,0 +1,149 @@
1
+ import { n as e, t } from "./BsfwXDui.js";
2
+ import { t as n } from "./DrWNJwZx.js";
3
+ import { t as r } from "./RxoWWyzp.js";
4
+ import { i, n as a, t as o } from "./Bt-ONXfO.js";
5
+ //#region ../../libs/web-sdk/src/decoders/PendingSampleMap.ts
6
+ var s = class {
7
+ constructor() {
8
+ e(this, "map", /* @__PURE__ */ new Map());
9
+ }
10
+ enqueue(e, t) {
11
+ let r = this.map.get(e);
12
+ if (r) r.push(t);
13
+ else {
14
+ let r = new n(Infinity);
15
+ r.push(t), this.map.set(e, r);
16
+ }
17
+ }
18
+ dequeue(e) {
19
+ let t = this.map.get(e);
20
+ if (!t) return;
21
+ let n = t.pop();
22
+ return t.isEmpty() && this.map.delete(e), n;
23
+ }
24
+ dequeueWithFallback(e) {
25
+ let t = this.dequeue(e);
26
+ if (t !== void 0) return t;
27
+ for (let [e, t] of this.map) {
28
+ let n = t.pop();
29
+ if (t.isEmpty() && this.map.delete(e), n !== void 0) return n;
30
+ }
31
+ }
32
+ removeLast(e) {
33
+ let t = this.map.get(e);
34
+ t && (t.popLast(), t.isEmpty() && this.map.delete(e));
35
+ }
36
+ clear() {
37
+ this.map.clear();
38
+ }
39
+ }, c, l = globalThis, u = class {
40
+ constructor(c) {
41
+ var l = this;
42
+ e(this, "decodedSamples", []), e(this, "decoder", null), e(this, "logger", void 0), e(this, "initSegments", /* @__PURE__ */ new Map()), e(this, "previousSample", void 0), e(this, "previousCodec", void 0), e(this, "pendingSamples", new s()), e(this, "errors", new n(10)), e(this, "resetDecoderState", () => {
43
+ this.pendingSamples.clear(), this.previousSample = void 0, this.previousCodec = void 0;
44
+ }), e(this, "ensureDecoder", () => ((!this.decoder || this.decoder.state === "closed") && (this.decoder = this.createDecoder()), this.decoder)), e(this, "createDecoder", () => new AudioDecoder({
45
+ output: (e) => {
46
+ let t = this.pendingSamples.dequeueWithFallback(e.timestamp);
47
+ if (!t) {
48
+ e.close();
49
+ return;
50
+ }
51
+ let { sample: n, decodeStartTime: i } = t;
52
+ try {
53
+ let t = e.numberOfFrames, a = e.numberOfChannels, o = e.sampleRate, s = e.timestamp, c = e.duration, l = new Float32Array(t * a);
54
+ e.copyTo(l, {
55
+ planeIndex: 0,
56
+ format: "f32"
57
+ });
58
+ let u = Math.round(s * n.timescale / 1e6), d = typeof c == "number" && Number.isFinite(c) ? Math.max(0, Math.round(c * n.timescale / 1e6)) : n.duration, f = r(r({}, n), {}, {
59
+ timestamp: u,
60
+ duration: d,
61
+ type: "audio",
62
+ format: "f32",
63
+ data: l,
64
+ sampleRate: o,
65
+ channels: a,
66
+ statistics: {
67
+ decodeTime: Math.max(performance.now() - i, 0),
68
+ transportTimeFromWorker: 0,
69
+ transportTimeToWorker: 0,
70
+ samplesInBatch: 1
71
+ }
72
+ });
73
+ this.decodedSamples.push(f);
74
+ } finally {
75
+ e.close();
76
+ }
77
+ },
78
+ error: (e) => {
79
+ this.logger.error("Decoder error:", e.name, e.message), this.resetDecoderState(), this.errors.push(e);
80
+ }
81
+ })), e(this, "buildCodecString", o), e(this, "getDescription", (e, t) => {
82
+ let n = this.initSegments.get(t.renditionId);
83
+ if (n && n.data.byteLength > 0 && n.codec === e) return n.data;
84
+ if (e === "opus") return a(t.channels, t.sampleRate);
85
+ if (e === "aac") return i(t.channels, t.sampleRate);
86
+ }), e(this, "unload", () => {
87
+ this.decodedSamples = [], this.resetDecoderState(), this.decoder && this.decoder.state !== "closed" && this.decoder.close(), this.decoder = null;
88
+ }), e(this, "initSegment", (e) => {
89
+ this.initSegments.set(e.renditionId, e);
90
+ }), e(this, "enqueue", (e) => {
91
+ var t, n;
92
+ let r = this.ensureDecoder(), i = e.codec, a = ((t = this.previousSample) == null ? void 0 : t.channelId) !== e.channelId, o = ((n = this.previousSample) == null ? void 0 : n.renditionId) !== e.renditionId, s = this.previousCodec !== i;
93
+ if (!this.previousSample || a || o || s) {
94
+ this.previousSample && r.state === "configured" && r.flush().catch((e) => {
95
+ this.logger.warn("Failed to flush before reconfiguration:", e);
96
+ });
97
+ let t = this.buildCodecString(i), n = this.getDescription(i, e), a = {
98
+ codec: t,
99
+ sampleRate: e.sampleRate,
100
+ numberOfChannels: e.channels,
101
+ description: n
102
+ };
103
+ try {
104
+ r.configure(a), this.previousCodec = i;
105
+ } catch (t) {
106
+ this.logger.error(`Failed to configure decoder for ${i} (rendition ${e.renditionId}), dropping sample`, t), this.errors.push(t instanceof Error ? t : /* @__PURE__ */ Error(`Failed to configure decoder for ${i}`)), this.resetDecoderState(), this.ensureDecoder();
107
+ return;
108
+ }
109
+ }
110
+ if (e.timescale <= 0) {
111
+ this.logger.error(`Invalid timescale ${e.timescale} in sample, dropping sample`);
112
+ return;
113
+ }
114
+ this.previousSample = e;
115
+ let c = Math.floor(1e6 * e.timestamp / e.timescale), l = Math.floor(1e6 * e.duration / e.timescale);
116
+ try {
117
+ let t = new EncodedAudioChunk({
118
+ type: "key",
119
+ timestamp: c,
120
+ duration: l > 0 ? l : void 0,
121
+ data: e.data
122
+ });
123
+ this.pendingSamples.enqueue(c, {
124
+ sample: e,
125
+ decodeStartTime: performance.now()
126
+ }), r.decode(t);
127
+ } catch (e) {
128
+ this.logger.error("Failed to decode chunk:", e), this.pendingSamples.removeLast(c), r.state === "closed" && (this.resetDecoderState(), this.ensureDecoder());
129
+ }
130
+ }), e(this, "flush", t(function* () {
131
+ if (l.decoder && l.decoder.state === "configured") try {
132
+ yield l.decoder.flush();
133
+ } catch (e) {
134
+ l.logger.error("Failed to flush decoder:", e), l.resetDecoderState();
135
+ }
136
+ })), e(this, "error", () => this.errors.pop()), e(this, "take", () => this.decodedSamples.shift()), this.logger = c, this.decoder = this.createDecoder();
137
+ }
138
+ };
139
+ c = u, e(u, "isSupported", () => l.AudioDecoder !== void 0), e(u, "create", function() {
140
+ var e = t(function* (e) {
141
+ if (!c.isSupported()) throw Error("WebCodecs AudioDecoder is not supported in this environment");
142
+ return new c(e);
143
+ });
144
+ return function(t) {
145
+ return e.apply(this, arguments);
146
+ };
147
+ }());
148
+ //#endregion
149
+ export { u as WebCodecsAudioDecoderContext };