UNPKG

pgs.js

Version:

PGS (Presentation Graphic Stream) Subtitle For HTML5 Media Playback

1,349 lines (1,348 loc) 45 kB
var B = Object.defineProperty; var A = (n, t, e) => t in n ? B(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e; var a = (n, t, e) => A(n, typeof t != "symbol" ? t + "" : t, e); class p extends Error { constructor(t, e) { super(t, e), this.name = this.constructor.name; } } class T { constructor(t) { a(this, "actual", null); a(this, "compare"); this.compare = t; } get parent() { return null; } get balanced() { var t; return ((t = this.actual) == null ? void 0 : t.balanced) ?? !0; } get bias() { var t; return ((t = this.actual) == null ? void 0 : t.bias) ?? 0; } toString() { return `${this.actual}`; } refresh() { } rotate() { } has(t) { var e; return ((e = this.actual) == null ? void 0 : e.has(t)) ?? !1; } get(t) { var e; return ((e = this.actual) == null ? void 0 : e.get(t)) ?? void 0; } floor(t) { var e; return ((e = this.actual) == null ? void 0 : e.floor(t)) ?? void 0; } ceil(t) { var e; return ((e = this.actual) == null ? void 0 : e.ceil(t)) ?? void 0; } *range(t, e) { var i; yield* ((i = this.actual) == null ? void 0 : i.range(t, e)) ?? []; } insert(t, e) { this.actual == null ? this.actual = new Y(t, e, this, this.compare) : this.actual.insert(t, e); } delete(t) { var e; (e = this.actual) == null || e.delete(t); } replace(t, e) { t != null && this.actual === t && (t.parent = null, this.actual = e, e != null && (e.parent = this)); } } class Y { constructor(t, e, i, s) { a(this, "key"); a(this, "value"); a(this, "parent"); a(this, "left", null); a(this, "right", null); a(this, "depth", 1); a(this, "compare"); this.key = t, this.value = e, this.parent = i, this.compare = s; } refresh() { var t, e; this.depth = Math.max(((t = this.left) == null ? void 0 : t.depth) ?? 0, ((e = this.right) == null ? void 0 : e.depth) ?? 0) + 1; } get balanced() { var i, s, r, o; const t = Math.min(((i = this.left) == null ? void 0 : i.depth) ?? 0, ((s = this.right) == null ? void 0 : s.depth) ?? 0); return Math.max(((r = this.left) == null ? void 0 : r.depth) ?? 0, ((o = this.right) == null ? void 0 : o.depth) ?? 0) - t <= 1; } get bias() { var t, e; return (((t = this.left) == null ? void 0 : t.depth) ?? 0) - (((e = this.right) == null ? void 0 : e.depth) ?? 0); } toString() { return this.left && console.log(this.left.parent === this ? "OK" : "NG"), this.right && console.log(this.right.parent === this ? "OK" : "NG"), `[${JSON.stringify(this.key)}:${JSON.stringify(this.value)}, [${this.left}, ${this.right}]]`; } leftmost() { return this.left == null ? this : this.left.leftmost(); } rightmost() { return this.right == null ? this : this.right.rightmost(); } rotateL() { var e, i; if (this.right == null) return; const t = this.right; this.replace(t, t.left), t.left = this, (e = this.parent) == null || e.replace(this, t), this.parent = t, this.refresh(), (i = this.parent) == null || i.refresh(); } rotateR() { var e, i; if (this.left == null) return; const t = this.left; this.replace(t, t.right), t.right = this, (e = this.parent) == null || e.replace(this, t), this.parent = t, this.refresh(), (i = this.parent) == null || i.refresh(); } rotateLR() { this.left != null && (this.left.rotateL(), this.rotateR()); } rotateRL() { this.right != null && (this.right.rotateR(), this.rotateL()); } rotate() { var t, e; this.bias === 2 ? (((t = this.left) == null ? void 0 : t.bias) ?? 0) >= 0 ? this.rotateR() : this.rotateLR() : this.bias === -2 && ((((e = this.right) == null ? void 0 : e.bias) ?? 0) <= 0 ? this.rotateL() : this.rotateRL()); } find(t, e = "exact") { let i = this; t: for (; ; ) { const s = this.compare(t, i.key); switch (s) { case 0: return i; case -1: if (i.left != null) { i = i.left; continue t; } else if (e === "ceil") return i; return null; case 1: if (i.right != null) { i = i.right; continue t; } else if (e === "floor") return i; return null; default: const r = s; throw new Error(`Exhaustive check: ${r} reached!`); } } } has(t) { return this.find(t, "exact") != null; } get(t) { var e; return ((e = this.find(t, "exact")) == null ? void 0 : e.value) ?? void 0; } floor(t) { var e; return ((e = this.find(t, "floor")) == null ? void 0 : e.value) ?? void 0; } ceil(t) { var e; return ((e = this.find(t, "ceil")) == null ? void 0 : e.value) ?? void 0; } *range(t, e) { var r, o; const i = this.compare(t, this.key), s = this.compare(e, this.key); i <= 0 && (yield* ((r = this.left) == null ? void 0 : r.range(t, e)) ?? []), i <= 0 && s > 0 && (yield this.value), s > 0 && (yield* ((o = this.right) == null ? void 0 : o.range(t, e)) ?? []); } insert(t, e) { let i = this; t: for (; ; ) { const s = this.compare(t, i.key); switch (s) { case 0: i.value = e; return; case -1: if (i.left != null) { i = i.left; continue t; } i.left = new Y(t, e, i, this.compare), i = i.left; break t; case 1: if (i.right != null) { i = i.right; continue t; } i.right = new Y(t, e, i, this.compare), i = i.right; break t; default: const r = s; throw new Error(`Exhaustive check: ${r} reached!`); } } for (let s = i; s != null; s = s.parent) s.rotate(), s.refresh(); } delete(t) { var r, o, l, d, h, u, S; let e = this.find(t); if (e == null) return; const i = (r = e.left) == null ? void 0 : r.rightmost(), s = (o = e.right) == null ? void 0 : o.leftmost(); i ? ((l = i.parent) == null || l.replace(i, null), (d = e.parent) == null || d.replace(e, i), i.right = e.right, e.right != null && (e.right.parent = i), i !== e.left && (i.left = e.left, e.left != null && (e.left.parent = i))) : s ? ((h = s.parent) == null || h.replace(s, null), (u = e.parent) == null || u.replace(e, s), s.left = e.left, e.left != null && (e.left.parent = s), s !== e.right && (s.right = e.right, e.right != null && (e.right.parent = s))) : (S = e.parent) == null || S.replace(e, null); for (let b = e; b != null; b = b.parent) b.rotate(), b.refresh(); } replace(t, e) { this.left === t && (t.parent === this.left && (t.parent = null), e != null && (e.parent = this), this.left = e), this.right === t && (t.parent === this.right && (t.parent = null), e != null && (e.parent = this), this.right = e); } } class N { constructor(t) { a(this, "root"); a(this, "compare"); this.compare = t, this.root = new T(this.compare); } clear() { this.root = new T(this.compare); } has(t) { return this.root.has(t); } get(t) { return this.root.get(t); } floor(t) { return this.root.floor(t); } ceil(t) { return this.root.ceil(t); } *range(t, e) { yield* this.root.range(t, e); } insert(t, e) { this.root.insert(t, e); } delete(t) { this.root.delete(t); } toString() { return `${this.root}`; } } const E = (...n) => { if (!n) return new ArrayBuffer(0); const t = n.reduce((i, s) => i + s.byteLength, 0), e = new Uint8Array(t); for (let i = 0, s = 0; i < n.length; s += n[i].byteLength, i++) e.set(new Uint8Array(n[i]), s); return e.buffer; }; class m { constructor(t) { a(this, "view"); a(this, "offset"); this.view = new DataView(t), this.offset = 0; } exists(t) { return this.offset + t <= this.view.byteLength; } isEmpty() { return this.offset === this.view.byteLength; } read(t) { if (!this.exists(t)) throw new p("Detected EOF!"); const e = this.view.buffer.slice(this.offset, this.offset + t); return this.offset += t, e; } readU8() { if (!this.exists(1)) throw new p("Detected EOF!"); const t = this.view.getUint8(this.offset); return this.offset += 1, t; } readU16() { if (!this.exists(2)) throw new p("Detected EOF!"); const t = this.view.getUint16(this.offset, !1); return this.offset += 2, t; } readU24() { if (!this.exists(3)) throw new p("Detected EOF!"); const t = this.view.getUint16(this.offset, !1) * 2 ** 8 + this.view.getUint8(this.offset + 2); return this.offset += 3, t; } readU32() { if (!this.exists(4)) throw new p("Detected EOF!"); const t = this.view.getUint32(this.offset, !1); return this.offset += 4, t; } readAll() { const t = this.view.buffer.slice(this.offset, this.view.byteLength); return this.offset = this.view.byteLength, t; } } class k { constructor(t) { a(this, "reader"); a(this, "done", !1); a(this, "buffer", new ArrayBuffer(0)); a(this, "view", new DataView(this.buffer)); a(this, "offset", 0); this.reader = t.getReader(); } async pump(t) { if (this.buffer.byteLength - this.offset >= t) return !0; if (this.done) return !1; const { value: e, done: i } = await this.reader.read(); return i ? (this.done = i, this.buffer.byteLength - this.offset >= t) : (this.buffer = E(this.buffer.slice(this.offset), e instanceof ArrayBuffer ? e : e.buffer), this.view = new DataView(this.buffer), this.offset = 0, this.buffer.byteLength - this.offset >= t ? !0 : this.pump(t)); } async exists(t) { return await this.pump(t); } async read(t) { if (!await this.exists(t)) throw new p("Detected EOF!"); const e = this.buffer.slice(this.offset, this.offset + t); return this.offset += t, e; } async readU8() { if (!await this.exists(1)) throw new p("Detected EOF!"); const t = this.view.getUint8(this.offset); return this.offset += 1, t; } async readU16() { if (!await this.exists(2)) throw new p("Detected EOF!"); const t = this.view.getUint16(this.offset, !1); return this.offset += 2, t; } async readU24() { if (!await this.exists(3)) throw new p("Detected EOF!"); const t = this.view.getUint16(this.offset, !1) * 2 ** 8 + this.view.getUint8(this.offset + 2); return this.offset += 3, t; } async readU32() { if (!await this.exists(4)) throw new p("Detected EOF!"); const t = this.view.getUint32(this.offset, !1); return this.offset += 4, t; } } const Q = (n, t, e) => { const i = n + 0 * (t - 128) + 1.371 * (e - 128), s = n - 0.336 * (t - 128) - 0.698 * (e - 128), r = n + 1.732 * (t - 128) + 0 * (e - 128); return [i, s, r]; }; class w extends Error { constructor(t, e) { super(t, e), this.name = this.constructor.name; } } const c = { PDS: 20, ODS: 21, PCS: 22, WDS: 23, END: 128 }, q = { from(n) { const t = n.readU16(), e = n.readU8(), i = n.readU8() !== 0, s = n.readU16(), r = n.readU16(); if (!i) return { objectId: t, windowId: e, objectCroppedFlag: i, objectHorizontalPosition: s, objectVerticalPosition: r }; const o = n.readU16(), l = n.readU16(), d = n.readU16(), h = n.readU16(); return { objectId: t, windowId: e, objectCroppedFlag: i, objectHorizontalPosition: s, objectVerticalPosition: r, objectCroppingHorizontalPosition: o, objectCroppingVerticalPosition: l, objectCroppingWidth: d, objectCroppingHeight: h }; } }, W = { Normal: 0, AcquisitionPoint: 64, EpochStart: 128 }, z = { from(n) { const t = n.readU16(), e = n.readU16(), i = n.readU8(), s = n.readU16(), r = n.readU8(); if (r !== W.Normal && r !== W.AcquisitionPoint && r !== W.EpochStart) throw new w("Invalid compositionState"); const o = n.readU8() === 128, l = n.readU8(), d = n.readU8(), h = []; for (let u = 0; u < d; u++) h.push(q.from(n)); return { width: t, height: e, frameRate: i, compositionNumber: s, compositionState: r, paletteUpdateFlag: o, paletteId: l, numberOfCompositionObject: d, compositionObjects: h }; } }, $ = { from(n) { const t = n.readU8(), e = n.readU16(), i = n.readU16(), s = n.readU16(), r = n.readU16(); return { windowId: t, windowHorizontalPosition: e, windowVerticalPosition: i, windowWidth: s, windowHeight: r }; } }, I = { from(n) { const t = n.readU8(), e = []; for (let i = 0; i < t; i++) e.push($.from(n)); return { numberOfWindow: t, windows: e }; }, valueOf(n) { const t = /* @__PURE__ */ new Map(); for (const e of (n == null ? void 0 : n.flatMap((i) => i.windows)) ?? []) t.set(e.windowId, e); return t; } }, _ = { from(n) { const t = n.readU8(), e = n.readU8(), i = n.readU8(), s = n.readU8(), r = n.readU8(); return { paletteEntryID: t, luminance: e, colorDifferenceRed: i, colorDifferenceBlue: s, transparency: r }; } }, D = { from(n) { const t = n.readU8(), e = n.readU8(), i = []; for (; !n.isEmpty(); ) i.push(_.from(n)); return { paletteID: t, paletteVersionNumber: e, paletteEntries: i }; } }, G = { LastInSequence: 64, FirstInSequence: 128, FirstAndLastInSequence: 192, IntermediateSequence: 0 }, X = { from(n) { const t = n.readU16(), e = n.readU8(), i = n.readU8(); if (i === G.FirstInSequence || i === G.FirstAndLastInSequence) { const s = n.readU24(), r = n.readU16(), o = n.readU16(), l = n.readAll(); return { objectId: t, objectVersionNumber: e, lastInSequenceFlag: i, objectDataLength: s, width: r, height: o, objectData: l }; } else if (i === G.LastInSequence || i === G.IntermediateSequence) { const s = n.readAll(); return { objectId: t, objectVersionNumber: e, lastInSequenceFlag: i, objectData: s }; } else throw new w("lastInSequenceFlag Invalid"); }, valueOf(n) { const t = /* @__PURE__ */ new Map(); for (const e of n ?? []) t.has(e.objectId) || t.set(e.objectId, []), t.get(e.objectId).push(e); return t; }, isFirstInSequence(n) { return n.lastInSequenceFlag === G.FirstInSequence || n.lastInSequenceFlag === G.FirstAndLastInSequence; } }, x = { from(n, t) { const e = t.find((l) => X.isFirstInSequence(l)); if (e == null) return null; const { width: i, height: s } = e, r = new Uint8ClampedArray(i * s * 4), o = new m(E(...t.map((l) => l.objectData))); { let l = 0; for (; !o.isEmpty(); ) { const d = o.readU8(); let h = null, u = 1; if (d !== 0) h = n.paletteEntries[d]; else { const g = o.readU8(); if (g === 0) continue; const U = (g & 128) !== 0; u = (g & 64) !== 0 ? (g & 63) * 2 ** 8 + o.readU8() : g & 63, h = U ? n.paletteEntries[o.readU8()] : n.paletteEntries[0]; } if (h == null) { l += u; continue; } const [S, b, L] = Q(h.luminance, h.colorDifferenceBlue, h.colorDifferenceRed); for (let g = 0; g < u; g++) r[l * 4 + 0] = S, r[l * 4 + 1] = b, r[l * 4 + 2] = L, r[l * 4 + 3] = h.transparency, l += 1; } } return { objectId: e.objectId, objectVersionNumber: e.objectVersionNumber, objectDataLength: e.objectDataLength, width: i, height: s, rgba: r }; }, valueOf(n, t) { const e = /* @__PURE__ */ new Map(); for (const i of X.valueOf(t).values()) { const s = x.from(n, i); s != null && e.set(s.objectId, s); } return e; } }, V = { from(n) { const t = n.readU8(), e = n.readU16(); switch (t) { case c.PDS: return { type: c.PDS, segment: D.from(new m(n.read(e))) }; case c.ODS: return { type: c.ODS, segment: X.from(new m(n.read(e))) }; case c.PCS: return { type: c.PCS, segment: z.from(new m(n.read(e))) }; case c.WDS: return { type: c.WDS, segment: I.from(new m(n.read(e))) }; case c.END: return { type: c.END }; default: throw new w(`Unrecognized SegmentType: ${t}`); } }, async fromAsync(n) { const t = await n.readU8(), e = await n.readU16(); if (!await n.exists(e)) throw new p("Insufficient SegmentLength!"); switch (t) { case c.PDS: return { type: c.PDS, segment: D.from(new m(await n.read(e))) }; case c.ODS: return { type: c.ODS, segment: X.from(new m(await n.read(e))) }; case c.PCS: return { type: c.PCS, segment: z.from(new m(await n.read(e))) }; case c.WDS: return { type: c.WDS, segment: I.from(new m(await n.read(e))) }; case c.END: return { type: c.END }; default: throw new w(`Unrecognized SegmentType: ${t}`); } } }, O = { SUP: 13, MPEGTS: 5 }, P = { fromSUPFormat(n) { if (n.readU16() !== 20551) throw new w("Magic Number not Found!"); const e = n.readU32(), i = n.readU32(); return { ...V.from(n), pts: e, dts: i, timescale: 9e4 }; }, async fromSUPFormatAsync(n) { if (await n.readU16() !== 20551) throw new w("Magic Number not Found!"); const e = await n.readU32(), i = await n.readU32(); return { ...await V.fromAsync(n), pts: e, dts: i, timescale: 9e4 }; }, fromMpegTSFormat(n, t, e, i = 9e4) { return { ...V.from(n), pts: t, dts: e, timescale: i }; }, async fromMpegTSFormatAsync(n, t, e, i = 9e4) { return { ...await V.fromAsync(n), pts: t, dts: e, timescale: i }; }, *iterateSupFormat(n) { const t = new m(n); for (; !t.isEmpty(); ) yield this.fromSUPFormat(t); }, async *iterateSupFormatAsync(n) { const t = new k(n); for (; await t.exists(O.SUP); ) yield this.fromSUPFormatAsync(t); }, *iterateMpegTSFormat(n, t, e, i = 9e4) { const s = new m(n); for (; !s.isEmpty(); ) yield this.fromMpegTSFormat(s, t, e, i); }, async *iterateMpegTSFormatAsync(n, t, e, i = 9e4) { const s = new k(n); for (; await s.exists(O.MPEGTS); ) yield this.fromMpegTSFormatAsync(s, t, e, i); } }, y = { isAcquisitionPoint(n) { return n.compositionState === W.EpochStart || n.compositionState === W.AcquisitionPoint; }, from(n) { const t = n.filter((o) => o.type === c.PCS); if (t.length === 0) throw new w("PCS not Found!"); if (t.length >= 2) throw new w("Duplicated PCS in DisplaySet!"); const e = t[0], i = n.filter((o) => o.type === c.PDS).find((o) => o.segment.paletteID === e.segment.paletteId), s = n.filter((o) => o.type === c.WDS)[0], r = n.filter((o) => o.type === c.ODS); if (e.segment.compositionState == W.Normal) return { pts: e.pts, timescale: e.timescale, compositionState: e.segment.compositionState, PCS: e.segment, PDS: i == null ? void 0 : i.segment, WDS: s == null ? void 0 : s.segment, ODS: r.map((o) => o.segment) }; if (i == null) throw new w("PDS not Found!"); return { pts: e.pts, timescale: e.timescale, compositionState: e.segment.compositionState, PCS: e.segment, PDS: i.segment, WDS: s.segment, ODS: r.map((o) => o.segment) }; }, merge(n, t) { return { pts: t.pts, timescale: t.timescale, compositionState: n.compositionState, PCS: t.PCS, PDS: t.PDS ?? n.PDS, WDS: t.WDS ?? n.WDS, ODS: t.ODS ?? n.ODS }; }, *aggregate(n) { let t = null; for (const e of n) e.type === c.PCS && (t = []), t != null && (e.type !== c.END ? t.push(e) : (yield this.from(t), t = null)); t != null && (yield this.from(t)); }, async *aggregateAsync(n) { let t = null; for await (const e of n) e.type === c.PCS && (t = []), t != null && (e.type !== c.END ? t.push(e) : (yield this.from(t), t = null)); t != null && (yield this.from(t)); } }, f = { from(n, t = !1) { const e = n.PCS, i = n.PDS; if (e.compositionObjects.length === 0) return { pts: n.pts, timescale: n.timescale, compositionState: n.compositionState, composition: e, palette: i, windows: /* @__PURE__ */ new Map(), objects: /* @__PURE__ */ new Map() }; const s = I.valueOf([n.WDS]), r = t ? x.valueOf(i, n.ODS) : X.valueOf(n.ODS); return { pts: n.pts, timescale: n.timescale, compositionState: n.compositionState, composition: e, palette: i, windows: s, objects: r }; }, *iterate(n, t = !1) { let e = null; for (const i of n) y.isAcquisitionPoint(i) && (e = i), e != null && (yield f.from(y.merge(e, i), t)); }, async *iterateAsync(n, t = !1) { let e = null; for await (const i of n) y.isAcquisitionPoint(i) && (e = i), e != null && (yield f.from(y.merge(e, i), t)); } }, tt = (n, t) => { if (t == null) return null; if (!Array.isArray(t)) return new ImageData(t.rgba, t.width, t.height); const e = x.from(n, t); return e == null ? null : new ImageData(e.rgba, e.width, e.height); }, C = (n, t) => { if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(n, t); if (typeof document < "u") { const e = document.createElement("canvas"); return e.width = n, e.height = t, e; } return null; }, et = (n, t) => { if (typeof document < "u") { const e = document.createElement("canvas"); return e.width = n, e.height = t, e; } return typeof OffscreenCanvas < "u" ? new OffscreenCanvas(n, t) : null; }, F = (n, t) => { const { composition: e, palette: i, objects: s, windows: r } = n; for (const o of e.compositionObjects) { const l = s.get(o.objectId), d = r.get(o.windowId); if (l == null || d == null) continue; const h = tt(i, l); if (h == null) continue; t.save(); const u = new Path2D(); u.rect(d.windowHorizontalPosition, d.windowVerticalPosition, d.windowWidth, d.windowHeight), t.clip(u); const S = o.objectHorizontalPosition, b = o.objectVerticalPosition; if (o.objectCroppedFlag) { const L = o.objectCroppingHorizontalPosition, g = o.objectCroppingVerticalPosition, U = o.objectCroppingWidth, j = o.objectCroppingHeight; t.putImageData(h, S, b, L, g, U, j); } else t.putImageData(h, S, b); t.restore(); } }, Z = { from(n) { return { type: "none", ...n }; }, *iterate(n) { for (const t of n) { const e = Z.from(t); if (e == null) return; yield e; } }, async *iterateAsync(n) { for await (const t of n) { const e = Z.from(t); if (e == null) return; yield e; } } }, v = { from(n) { const { composition: t } = n, { width: e, height: i } = t; if (typeof OffscreenCanvas > "u") return null; const s = new OffscreenCanvas(e, i); if (!s) return null; const r = s.getContext("2d"); return r ? (F(n, r), { type: "bitmap", pts: n.pts, timescale: n.timescale, bitmap: s.transferToImageBitmap() }) : null; }, async fromAsync(n, t = C) { const { composition: e } = n, { width: i, height: s } = e, r = t(i, s); if (!r) return null; const o = r.getContext("2d"); return o ? (F(n, o), { type: "bitmap", pts: n.pts, timescale: n.timescale, bitmap: await createImageBitmap(r) }) : null; }, *iterate(n) { for (const t of n) { const e = v.from(t); if (e == null) return; yield e; } }, async *iterateAsync(n, t = C) { for await (const e of n) { const i = await v.fromAsync(e, t); if (i == null) return; yield i; } } }, nt = { from(n, t = C) { const { composition: e } = n, { width: i, height: s } = e, r = t(i, s); if (!r) return null; const o = r.getContext("2d"); return o ? (F(n, o), { type: "canvas", pts: n.pts, timescale: n.timescale, canvas: r }) : null; } }; let ut = class { constructor(t, e) { a(this, "option"); a(this, "acquisitions"); this.option = { preload: "none", timeshift: 0, ...e }; const i = y.aggregate(P.iterateSupFormat(t)); switch (this.option.preload) { case "decode": this.acquisitions = Array.from(Z.iterate(f.iterate(i, !0))); break; case "render": this.acquisitions = Array.from(v.iterate(f.iterate(i, !0))); break; case "none": default: this.acquisitions = Array.from(Z.iterate(f.iterate(i, !1))); break; } } content(t) { t -= this.option.timeshift; { const s = this.acquisitions[0]; if (!s) return null; const r = s.pts / s.timescale; if (t < r) return null; } let e = 0, i = this.acquisitions.length; for (; e + 1 < i; ) { const s = Math.floor((e + i) / 2), r = this.acquisitions[s]; r.pts / r.timescale <= t ? e = s : i = s; } return this.acquisitions[e] ?? null; } onattach() { } ondetach() { } onseek() { } }; class mt { constructor(t, e) { a(this, "option"); a(this, "acquisitions", []); a(this, "donePromise"); this.option = { preload: "none", timeshift: 0, ...e }, this.donePromise = new Promise((i) => { this.prepare(t, i); }); } async prepare(t, e) { const i = y.aggregateAsync(P.iterateSupFormatAsync(t)); switch (this.option.preload) { case "decode": for await (const s of Z.iterateAsync(f.iterateAsync(i, !0))) this.acquisitions.push(s); break; case "render": for await (const s of v.iterateAsync(f.iterateAsync(i, !0))) this.acquisitions.push(s); break; case "none": default: for await (const s of Z.iterateAsync(f.iterateAsync(i, !1))) this.acquisitions.push(s); break; } e == null || e(!0); } get done() { return this.donePromise; } content(t) { t -= this.option.timeshift; { const s = this.acquisitions[0]; if (!s) return null; const r = s.pts / s.timescale; if (t < r) return null; } let e = 0, i = this.acquisitions.length; for (; e + 1 < i; ) { const s = Math.floor((e + i) / 2), r = this.acquisitions[s]; r.pts / r.timescale <= t ? e = s : i = s; } return this.acquisitions[e] ?? null; } onattach() { } ondetach() { } onseek() { } } const it = /* @__PURE__ */ new Map([ [c.PCS, 0], [c.PDS, 1], [c.ODS, 2], [c.WDS, 3], [c.END, 4] ]), R = (n, t) => Math.sign(n - t), st = (n, t) => R(n.dts, t.dts) !== 0 ? R(n.dts, t.dts) : R(n.order ?? -1, t.order ?? -1); class pt { constructor(t) { a(this, "option"); a(this, "priviousTime", null); a(this, "decode", new N(st)); a(this, "decodeBuffer", []); a(this, "decodingPromise"); a(this, "decodingNotify", Promise.resolve); a(this, "abortController", new AbortController()); a(this, "present", new N(R)); a(this, "isDestroyed", !1); this.option = { preload: "none", timeshift: 0, ...t }, this.decodingPromise = new Promise((e) => { this.decodingNotify = e; }), this.pump(); } notify(t) { var e; t != null ? this.decodeBuffer.push(t) : (this.abortController.abort(), this.abortController = new AbortController()), (e = this.decodingNotify) == null || e.call(this); } async *generator(t) { for (; ; ) { if (await this.decodingPromise, this.decodingPromise = new Promise((i) => { this.decodingNotify = i; }), t.aborted) { this.decodeBuffer = []; return; } const e = [...this.decodeBuffer]; this.decodeBuffer = [], yield* e; } } async pump() { for (; !this.isDestroyed; ) { const t = y.aggregateAsync(this.generator(this.abortController.signal)); switch (this.option.preload) { case "decode": for await (const e of Z.iterateAsync(f.iterateAsync(t, !0))) this.present.insert(e.pts / e.timescale, e); break; case "render": for await (const e of v.iterateAsync(f.iterateAsync(t, !0))) this.present.insert(e.pts / e.timescale, e); break; case "none": default: for await (const e of Z.iterateAsync(f.iterateAsync(t, !1))) this.present.insert(e.pts / e.timescale, e); break; } } } feed(t, e, i, s) { for (const r of P.iterateMpegTSFormat(t, e, i, s)) this.decode.insert({ dts: r.dts / r.timescale, order: it.get(r.type) }, r); } content(t) { if (this.priviousTime != null) for (const e of this.decode.range({ dts: this.priviousTime }, { dts: t })) this.notify(e); return this.priviousTime = t, t -= this.option.timeshift, this.present.floor(t) ?? null; } clear() { this.present.clear(), this.priviousTime = null, this.notify(null); } onattach() { this.clear(); } ondetach() { this.clear(); } onseek() { this.clear(); } destroy() { this.isDestroyed = !0, this.clear(); } } const H = { from(n) { return { preferHTMLCanvasElement: !1, webWorker: !1, ...n }; } }; class M { constructor(t) { a(this, "option"); a(this, "canvas", null); this.option = H.from(t); } attach(t) { this.canvas = t; } snapshot() { return this.canvas; } register(t) { this.canvas != null && this.canvas instanceof HTMLCanvasElement && t.appendChild(this.canvas); } unregister() { this.canvas != null && this.canvas instanceof HTMLCanvasElement && this.canvas.remove(); } detach() { this.canvas = null; } resize(t, e) { this.canvas != null && (this.canvas.width = t, this.canvas.height = e); } getContext2D() { return this.canvas == null ? null : this.canvas.getContext("2d"); } clear() { if (this.canvas == null) return; const t = this.getContext2D(); t && t.clearRect(0, 0, this.canvas.width, this.canvas.height); } destroy() { this.unregister(), this.resize(0, 0), this.detach(); } } class rt extends M { constructor(t) { super(t); } draw(t) { if (this.canvas == null) return; const e = this.getContext2D(); e && ((this.canvas.width !== t.width || this.canvas.height !== t.width) && (this.canvas.width = t.width, this.canvas.height = t.height), this.clear(), e.drawImage(t, 0, 0, this.canvas.width, this.canvas.height)); } render(t) { switch (t.type) { case "none": { const e = nt.from(t, this.option.preferHTMLCanvasElement ? et : C); e && (this.draw(e.canvas), e.canvas.width = e.canvas.height = 0); break; } case "bitmap": this.draw(t.bitmap); break; case "canvas": this.draw(t.canvas); break; default: { const e = t; throw new Error(`Exhaustive check: ${e} reached!`); } } } } const ot = { from(n) { return { type: "render", pgs: n }; } }, J = "dmFyIEw9T2JqZWN0LmRlZmluZVByb3BlcnR5O3ZhciBDPShkLGEsaCk9PmEgaW4gZD9MKGQsYSx7ZW51bWVyYWJsZTohMCxjb25maWd1cmFibGU6ITAsd3JpdGFibGU6ITAsdmFsdWU6aH0pOmRbYV09aDt2YXIgdj0oZCxhLGgpPT5DKGQsdHlwZW9mIGEhPSJzeW1ib2wiP2ErIiI6YSxoKTsoZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7dmFyIGQ9KC4uLnQpPT57aWYoIXQpcmV0dXJuIG5ldyBBcnJheUJ1ZmZlcigwKTtjb25zdCBlPXQucmVkdWNlKChzLHIpPT5zK3IuYnl0ZUxlbmd0aCwwKSxuPW5ldyBVaW50OEFycmF5KGUpO2ZvcihsZXQgcz0wLHI9MDtzPHQubGVuZ3RoO3IrPXRbc10uYnl0ZUxlbmd0aCxzKyspbi5zZXQobmV3IFVpbnQ4QXJyYXkodFtzXSkscik7cmV0dXJuIG4uYnVmZmVyfTtjbGFzcyBhIGV4dGVuZHMgRXJyb3J7Y29uc3RydWN0b3IoZSxuKXtzdXBlcihlLG4pLHRoaXMubmFtZT10aGlzLmNvbnN0cnVjdG9yLm5hbWV9fWNsYXNzIGh7Y29uc3RydWN0b3IoZSl7dih0aGlzLCJ2aWV3Iik7dih0aGlzLCJvZmZzZXQiKTt0aGlzLnZpZXc9bmV3IERhdGFWaWV3KGUpLHRoaXMub2Zmc2V0PTB9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u" && self.Blob && new Blob([at(J)], { type: "text/javascript;charset=utf-8" }); function ct(n) { let t; try { if (t = K && (self.URL || self.webkitURL).createObjectURL(K), !t) throw ""; const e = new Worker(t, { name: n == null ? void 0 : n.name }); return e.addEventListener("error", () => { (self.URL || self.webkitURL).revokeObjectURL(t); }), e; } catch { return new Worker( "data:text/javascript;base64," + J, { name: n == null ? void 0 : n.name } ); } finally { t && (self.URL || self.webkitURL).revokeObjectURL(t); } } class lt extends M { constructor(e) { super(e); a(this, "worker"); a(this, "renderedHandler", this.rendered.bind(this)); this.worker = new ct(), this.worker.addEventListener("message", this.renderedHandler); } render(e) { switch (e.type) { case "none": this.worker.postMessage(ot.from(e)); break; case "bitmap": this.draw(e.bitmap); break; case "canvas": this.draw(e.canvas); break; default: { const i = e; throw new Error(`Exhaustive check: ${i} reached!`); } } } draw(e) { if (this.canvas == null) return; const i = this.getContext2D(); i && ((this.canvas.width !== e.width || this.canvas.height !== e.width) && (this.canvas.width = e.width, this.canvas.height = e.height), this.clear(), i.drawImage(e, 0, 0, this.canvas.width, this.canvas.height)); } rendered(e) { switch (e.data.type) { case "rendered": { const { bitmap: i } = e.data; if (i == null) { this.clear(); return; } this.draw(i), i.close(); break; } default: { const i = e.data.type; throw new Error(`Exhaustive check: ${i} reached!`); } } } destroy() { super.destroy(), this.worker.terminate(); } } const ht = (n) => n.webWorker ? new lt(n) : new rt(n); class bt { constructor(t) { // Option a(this, "option"); // Video a(this, "media", null); a(this, "container", null); // Timeupdate Handler a(this, "onTimeupdateHandler", this.onTimeupdate.bind(this)); a(this, "timer", null); // Seeking Handler a(this, "onSeekingHandler", this.onSeeking.bind(this)); a(this, "onSeekedHandler", this.onSeeked.bind(this)); // Renderer a(this, "renderer", null); a(this, "priviousPts", null); // Feeder a(this, "feeder", null); // Control a(this, "isShowing", !0); this.option = { ...t, renderOption: H.from(t == null ? void 0 : t.renderOption) }; } attachMedia(t, e) { this.media = t, this.container = e ?? t.parentElement, this.setup(); } detachMedia() { this.cleanup(), this.media = this.container = null; } setup() { if (!this.media || !this.container) return; this.media.addEventListener("seeking", this.onSeekingHandler), this.media.addEventListener("seeked", this.onSeekedHandler); const t = document.createElement("canvas"); t.style.position = "absolute", t.style.top = t.style.left = "0", t.style.pointerEvents = "none", t.style.width = "100%", t.style.height = "100%", t.style.objectFit = "contain", this.renderer = ht(this.option.renderOption), this.renderer.attach(t), this.renderer.register(this.container), this.onTimeupdate(); } cleanup() { var t; this.media && (this.media.removeEventListener("seeking", this.onSeekingHandler), this.media.removeEventListener("seeked", this.onSeekedHandler)), (t = this.renderer) == null || t.destroy(); } clear() { var t; (t = this.renderer) == null || t.clear(), this.priviousPts = null; } attachFeeder(t) { this.feeder = t, this.feeder.onattach(), this.clear(); } detachFeeder() { var t; (t = this.feeder) == null || t.ondetach(), this.feeder = null, this.clear(); } onSeeking() { var t; (t = this.feeder) == null || t.onseek(), this.clear(); } onSeeked() { this.clear(); } onTimeupdate() { var i; if (!this.isShowing || (this.timer = requestAnimationFrame(this.onTimeupdateHandler), this.media == null || this.feeder == null)) return; const t = this.media.currentTime, e = this.feeder.content(t) ?? null; e != null && this.priviousPts !== e.pts && ((i = this.renderer) == null || i.render(e), this.priviousPts = e.pts); } show() { this.isShowing = !0, this.timer == null && (this.timer = requestAnimationFrame(this.onTimeupdateHandler)), this.onTimeupdate(); } hide() { this.isShowing = !1, this.timer != null && (cancelAnimationFrame(this.timer), this.timer = null), this.clear(); } showing() { return this.isShowing; } snapshot() { var t; return ((t = this.renderer) == null ? void 0 : t.snapshot()) ?? null; } } const gt = (n, t = !1) => Array.from(f.iterate(y.aggregate(P.iterateSupFormat(n)), t)); export { N as AVLTree, f as AcquisitionPoint, q as CompositionObject, W as CompositionState, x as DecodedObjectDefinitionSegment, y as DisplaySet, p as EOFError, O as HeaderLengthByFormat, X as ObjectDefinitionSegment, mt as PGSAsyncSupFeeder, bt as PGSController, rt as PGSMainThreadRenderer, pt as PGSMpegTSFeeder, ut as PGSSupFeeder, D as PaletteDefinitionSegment, _ as PaletteEntry, z as PresentationCompositionSegment, V as Segment, c as SegmentType, G as SequenceFlag, P as TimestampedSegment, $ as WindowDefinition, I as WindowDefinitionSegment, gt as readSup };