movi-player 0.3.0 → 0.3.2

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.
Files changed (61) hide show
  1. package/AGENTS.md +2 -0
  2. package/README.md +54 -7
  3. package/dist/core/MoviPlayer.d.ts +77 -1
  4. package/dist/core/MoviPlayer.d.ts.map +1 -1
  5. package/dist/core/MoviPlayer.js +667 -121
  6. package/dist/core/MoviPlayer.js.map +1 -1
  7. package/dist/core/PlayerState.js +1 -1
  8. package/dist/core/PlayerState.js.map +1 -1
  9. package/dist/decode/VideoDecoder.d.ts.map +1 -1
  10. package/dist/decode/VideoDecoder.js +6 -2
  11. package/dist/decode/VideoDecoder.js.map +1 -1
  12. package/dist/demuxer.cjs +315 -129
  13. package/dist/demuxer.js +377 -191
  14. package/dist/element.cjs +58309 -16596
  15. package/dist/element.js +59520 -17807
  16. package/dist/index.cjs +58309 -16596
  17. package/dist/index.js +59520 -17807
  18. package/dist/player.cjs +56818 -15360
  19. package/dist/player.js +57818 -16360
  20. package/dist/render/DASHPlayerWrapper.d.ts +65 -0
  21. package/dist/render/DASHPlayerWrapper.d.ts.map +1 -0
  22. package/dist/render/DASHPlayerWrapper.js +540 -0
  23. package/dist/render/DASHPlayerWrapper.js.map +1 -0
  24. package/dist/render/HLSPlayerWrapper.d.ts.map +1 -1
  25. package/dist/render/HLSPlayerWrapper.js +47 -11
  26. package/dist/render/HLSPlayerWrapper.js.map +1 -1
  27. package/dist/render/MoviElement.d.ts +97 -0
  28. package/dist/render/MoviElement.d.ts.map +1 -1
  29. package/dist/render/MoviElement.js +852 -152
  30. package/dist/render/MoviElement.js.map +1 -1
  31. package/dist/render/ShakaPlayerWrapper.d.ts +111 -0
  32. package/dist/render/ShakaPlayerWrapper.d.ts.map +1 -0
  33. package/dist/render/ShakaPlayerWrapper.js +956 -0
  34. package/dist/render/ShakaPlayerWrapper.js.map +1 -0
  35. package/dist/source/DashFallback.d.ts +32 -0
  36. package/dist/source/DashFallback.d.ts.map +1 -0
  37. package/dist/source/DashFallback.js +142 -0
  38. package/dist/source/DashFallback.js.map +1 -0
  39. package/dist/source/DashManifest.d.ts +34 -0
  40. package/dist/source/DashManifest.d.ts.map +1 -0
  41. package/dist/source/DashManifest.js +194 -0
  42. package/dist/source/DashManifest.js.map +1 -0
  43. package/dist/source/DashSegmentSource.d.ts +32 -0
  44. package/dist/source/DashSegmentSource.d.ts.map +1 -0
  45. package/dist/source/DashSegmentSource.js +86 -0
  46. package/dist/source/DashSegmentSource.js.map +1 -0
  47. package/dist/source/HttpSource.d.ts +64 -0
  48. package/dist/source/HttpSource.d.ts.map +1 -1
  49. package/dist/source/HttpSource.js +444 -57
  50. package/dist/source/HttpSource.js.map +1 -1
  51. package/dist/source/ThumbnailHttpSource.d.ts +13 -0
  52. package/dist/source/ThumbnailHttpSource.d.ts.map +1 -1
  53. package/dist/source/ThumbnailHttpSource.js +70 -8
  54. package/dist/source/ThumbnailHttpSource.js.map +1 -1
  55. package/dist/source/index.d.ts +2 -0
  56. package/dist/source/index.d.ts.map +1 -1
  57. package/dist/source/index.js +1 -0
  58. package/dist/source/index.js.map +1 -1
  59. package/dist/types.d.ts +10 -0
  60. package/dist/types.d.ts.map +1 -1
  61. package/package.json +16 -6
package/dist/demuxer.js CHANGED
@@ -75,14 +75,14 @@ class CodecParser {
75
75
  case 3:
76
76
  e2 = "C";
77
77
  }
78
- let s2 = 0, i2 = F2;
79
- for (let A3 = 0; A3 < 32; A3++) s2 = 2 * s2 + (1 & i2), i2 = Math.floor(i2 / 2);
80
- let u2 = `hvc1.${e2}${n2}.${(s2 >>> 0).toString(16)}.${0 === f2 ? "L" : "H"}${k2}`, a2 = false;
78
+ let i2 = 0, s2 = F2;
79
+ for (let A3 = 0; A3 < 32; A3++) i2 = 2 * i2 + (1 & s2), s2 = Math.floor(s2 / 2);
80
+ let a2 = `hvc1.${e2}${n2}.${(i2 >>> 0).toString(16)}.${0 === f2 ? "L" : "H"}${k2}`, u2 = false;
81
81
  for (let A3 = 5; A3 >= 0; A3--) {
82
82
  const v3 = l2[A3];
83
- (0 !== v3 || a2) && (u2 += "." + v3.toString(16), a2 = true);
83
+ (0 !== v3 || u2) && (a2 += "." + v3.toString(16), u2 = true);
84
84
  }
85
- return r.debug(t, `HEVC codec string: ${u2}`), u2;
85
+ return r.debug(t, `HEVC codec string: ${a2}`), a2;
86
86
  }
87
87
  static getAvcCodecString(A2) {
88
88
  if (A2.length < 4) return "avc1.420028";
@@ -283,7 +283,7 @@ class MoviVideoDecoder {
283
283
  }
284
284
  async configure(A2, v2, j2 = 0) {
285
285
  if (this.currentTrack = A2, this.targetFps = j2, this.currentProfile = A2.profile, this.useSoftware = false, this.requiresSoftware = false, this.isAnnexBSource = false, this.openGopErrorCount = 0, this.hardwareRetryCount = 0, this.lastHardwareRetryTime = 0, this.swDecoder && (this.swDecoder.close(), this.swDecoder = null), this.forceSoftware) return r.info(f, "Force software decoding enabled, using WASM decoder"), this.useSoftware = true, this.initSoftwareDecoder();
286
- if (!("VideoDecoder" in window)) return r.error(f, "WebCodecs VideoDecoder not supported"), false;
286
+ if (!("VideoDecoder" in window)) return r.warn(f, "WebCodecs VideoDecoder not supported — falling back to software decoder"), this.useSoftware = true, this.initSoftwareDecoder();
287
287
  let b2 = CodecParser.getCodecString(A2.codec, A2.extradata);
288
288
  if (b2 || (r.debug(f, "CodecParser returned null, falling back to manual mapping"), b2 = this.mapCodecToWebCodecs(A2.codec, A2.width, A2.height, A2.profile, A2.level)), !b2) return r.error(f, `Unsupported codec: ${A2.codec}`), false;
289
289
  const t2 = { codec: b2, codedWidth: A2.width, codedHeight: A2.height, hardwareAcceleration: "prefer-hardware" };
@@ -644,24 +644,24 @@ class MoviVideoDecoder {
644
644
  }
645
645
  if (0 === t2.length) return r.warn(f, "No SPS found in Annex B extradata"), null;
646
646
  const n2 = b2[0] || t2[0], F2 = this.removeEpb(n2), l2 = 32 == (F2[0] >> 1 & 63) ? 6 : 3;
647
- let k2 = v2?.profile ?? 2, e2 = 0, s2 = new Uint8Array([32, 0, 0, 0]), i2 = new Uint8Array(6), u2 = v2?.level ?? 153;
647
+ let k2 = v2?.profile ?? 2, e2 = 0, i2 = new Uint8Array([32, 0, 0, 0]), s2 = new Uint8Array(6), a2 = v2?.level ?? 153;
648
648
  if (F2.length >= l2 + 12) {
649
649
  const A3 = F2[l2];
650
- k2 = 31 & A3, e2 = A3 >> 5 & 1, s2 = F2.slice(l2 + 1, l2 + 5), i2 = F2.slice(l2 + 5, l2 + 11), u2 = F2[l2 + 11], r.debug(f, `hvcC from NAL: profile=${k2}, tier=${e2}, level=${u2}`);
651
- } else null == v2?.profile && null == v2?.level || r.debug(f, `hvcC from track metadata: profile=${k2}, level=${u2}`);
652
- const a2 = [];
653
- b2.length > 0 && a2.push({ type: 32, nalus: b2 }), t2.length > 0 && a2.push({ type: 33, nalus: t2 }), E2.length > 0 && a2.push({ type: 34, nalus: E2 });
650
+ k2 = 31 & A3, e2 = A3 >> 5 & 1, i2 = F2.slice(l2 + 1, l2 + 5), s2 = F2.slice(l2 + 5, l2 + 11), a2 = F2[l2 + 11], r.debug(f, `hvcC from NAL: profile=${k2}, tier=${e2}, level=${a2}`);
651
+ } else null == v2?.profile && null == v2?.level || r.debug(f, `hvcC from track metadata: profile=${k2}, level=${a2}`);
652
+ const u2 = [];
653
+ b2.length > 0 && u2.push({ type: 32, nalus: b2 }), t2.length > 0 && u2.push({ type: 33, nalus: t2 }), E2.length > 0 && u2.push({ type: 34, nalus: E2 });
654
654
  let o2 = 23;
655
- for (const A3 of a2) {
655
+ for (const A3 of u2) {
656
656
  o2 += 3;
657
657
  for (const v3 of A3.nalus) o2 += 2 + v3.length;
658
658
  }
659
659
  const x2 = new Uint8Array(o2), q2 = new DataView(x2.buffer);
660
660
  let B2 = 0;
661
- x2[B2++] = 1, x2[B2++] = e2 << 5 | 31 & k2, x2[B2++] = s2[0], x2[B2++] = s2[1], x2[B2++] = s2[2], x2[B2++] = s2[3];
662
- for (let A3 = 0; A3 < 6; A3++) x2[B2++] = i2[A3];
663
- x2[B2++] = u2, q2.setUint16(B2, 61440), B2 += 2, x2[B2++] = 252, x2[B2++] = 253, x2[B2++] = 250, x2[B2++] = 250, q2.setUint16(B2, 0), B2 += 2, x2[B2++] = 15, x2[B2++] = a2.length;
664
- for (const A3 of a2) {
661
+ x2[B2++] = 1, x2[B2++] = e2 << 5 | 31 & k2, x2[B2++] = i2[0], x2[B2++] = i2[1], x2[B2++] = i2[2], x2[B2++] = i2[3];
662
+ for (let A3 = 0; A3 < 6; A3++) x2[B2++] = s2[A3];
663
+ x2[B2++] = a2, q2.setUint16(B2, 61440), B2 += 2, x2[B2++] = 252, x2[B2++] = 253, x2[B2++] = 250, x2[B2++] = 250, q2.setUint16(B2, 0), B2 += 2, x2[B2++] = 15, x2[B2++] = u2.length;
664
+ for (const A3 of u2) {
665
665
  x2[B2++] = 128 | 63 & A3.type, q2.setUint16(B2, A3.nalus.length), B2 += 2;
666
666
  for (const v3 of A3.nalus) q2.setUint16(B2, v3.length), B2 += 2, x2.set(v3, B2), B2 += v3.length;
667
667
  }
@@ -760,17 +760,17 @@ class ThumbnailRenderer {
760
760
  this.hdrEnabled = f2, this.lastColorPrimaries = t2, this.lastColorTransfer = E2, this.rotation = b2;
761
761
  const F2 = b2 % 180 != 0;
762
762
  this.canvas.width = F2 ? j2 : v2, this.canvas.height = F2 ? v2 : j2;
763
- const l2 = (t2 || "").toLowerCase(), k2 = (E2 || "").toLowerCase(), e2 = k2.includes("pq") || k2.includes("hlg") || k2.includes("smpte2084") || k2.includes("arib-std-b67"), s2 = l2.includes("bt2020") || l2.includes("rec2020");
764
- this.isHDRSource = e2 || s2;
765
- const i2 = this.detectHDRColorSpace(t2, E2);
763
+ const l2 = (t2 || "").toLowerCase(), k2 = (E2 || "").toLowerCase(), e2 = k2.includes("pq") || k2.includes("hlg") || k2.includes("smpte2084") || k2.includes("arib-std-b67"), i2 = l2.includes("bt2020") || l2.includes("rec2020");
764
+ this.isHDRSource = e2 || i2;
765
+ const s2 = this.detectHDRColorSpace(t2, E2);
766
766
  if (this.gl = this.canvas.getContext("webgl2", { alpha: false, antialias: false, depth: false, preserveDrawingBuffer: true }), !this.gl) throw new Error("WebGL2 not supported");
767
767
  try {
768
- "srgb" !== i2 && void 0 !== this.gl.drawingBufferColorSpace && (this.gl.drawingBufferColorSpace = i2, this.gl.unpackColorSpace = i2, r.debug(n, `WebGL color space set to: ${i2}`));
768
+ "srgb" !== s2 && void 0 !== this.gl.drawingBufferColorSpace && (this.gl.drawingBufferColorSpace = s2, this.gl.unpackColorSpace = s2, r.debug(n, `WebGL color space set to: ${s2}`));
769
769
  } catch (A3) {
770
770
  r.warn(n, "Failed to set drawingBufferColorSpace", A3);
771
771
  }
772
- const u2 = this.detectChromium();
773
- this.hasNativeHDRSupport = u2, !this.hasNativeHDRSupport && this.isHDRSource ? (r.debug(n, "Using shader-based HDR tone mapping (non-Chromium)"), this.initWebGLWithHDR()) : (r.debug(n, "Using simple passthrough (Chromium native HDR)"), this.initWebGLSimple()), r.info(n, `Initialized: ${v2}x${j2}, isChromium=${u2}, isHDR=${this.isHDRSource}, colorSpace=${i2}`);
772
+ const a2 = this.detectChromium();
773
+ this.hasNativeHDRSupport = a2, !this.hasNativeHDRSupport && this.isHDRSource ? (r.debug(n, "Using shader-based HDR tone mapping (non-Chromium)"), this.initWebGLWithHDR()) : (r.debug(n, "Using simple passthrough (Chromium native HDR)"), this.initWebGLSimple()), r.info(n, `Initialized: ${v2}x${j2}, isChromium=${a2}, isHDR=${this.isHDRSource}, colorSpace=${s2}`);
774
774
  }
775
775
  initWebGLSimple() {
776
776
  if (!this.gl) return;
@@ -977,11 +977,11 @@ function k(v2) {
977
977
  }
978
978
  }
979
979
  const e = /* @__PURE__ */ new Set();
980
- function s(A2, v2) {
980
+ function i(A2, v2) {
981
981
  const r2 = new DataView(A2.HEAPU8.buffer, v2, F), j2 = A2.HEAPU8.subarray(v2 + 12, v2 + 12 + 32), b2 = new TextDecoder().decode(j2.subarray(0, j2.indexOf(0))), t2 = A2.HEAPU8.subarray(v2 + 100, v2 + 100 + 8), E2 = new TextDecoder().decode(t2.subarray(0, t2.indexOf(0))), f2 = A2.HEAPU8.subarray(v2 + 108, v2 + 108 + 64), n2 = new TextDecoder().decode(f2.subarray(0, f2.indexOf(0)));
982
- return { index: r2.getInt32(0, true), type: r2.getInt32(4, true), codecId: r2.getInt32(8, true), codecName: b2, width: r2.getInt32(44, true), height: r2.getInt32(48, true), frameRate: r2.getFloat64(56, true), channels: r2.getInt32(64, true), sampleRate: r2.getInt32(68, true), duration: r2.getFloat64(72, true), bitRate: Number(r2.getBigInt64(80, true)), extradataSize: r2.getInt32(88, true), profile: r2.getInt32(92, true), level: r2.getInt32(96, true), language: E2 || "", label: n2 || "", rotation: r2.getInt32(172, true), colorPrimaries: i(A2, v2 + 176, 32), colorTransfer: i(A2, v2 + 208, 32), colorMatrix: i(A2, v2 + 240, 32), pixelFormat: i(A2, v2 + 272, 32), colorRange: i(A2, v2 + 304, 32), isAttachedPic: 0 !== r2.getInt32(336, true) };
982
+ return { index: r2.getInt32(0, true), type: r2.getInt32(4, true), codecId: r2.getInt32(8, true), codecName: b2, width: r2.getInt32(44, true), height: r2.getInt32(48, true), frameRate: r2.getFloat64(56, true), channels: r2.getInt32(64, true), sampleRate: r2.getInt32(68, true), duration: r2.getFloat64(72, true), bitRate: Number(r2.getBigInt64(80, true)), extradataSize: r2.getInt32(88, true), profile: r2.getInt32(92, true), level: r2.getInt32(96, true), language: E2 || "", label: n2 || "", rotation: r2.getInt32(172, true), colorPrimaries: s(A2, v2 + 176, 32), colorTransfer: s(A2, v2 + 208, 32), colorMatrix: s(A2, v2 + 240, 32), pixelFormat: s(A2, v2 + 272, 32), colorRange: s(A2, v2 + 304, 32), isAttachedPic: 0 !== r2.getInt32(336, true) };
983
983
  }
984
- function i(A2, v2, r2) {
984
+ function s(A2, v2, r2) {
985
985
  const j2 = A2.HEAPU8.subarray(v2, v2 + r2), b2 = j2.indexOf(0);
986
986
  return new TextDecoder().decode(j2.subarray(0, b2 >= 0 ? b2 : r2));
987
987
  }
@@ -995,7 +995,7 @@ class WasmBindings {
995
995
  lastError = null;
996
996
  constructor(A2) {
997
997
  this.module = A2, this.setupAsyncHandlers(), e.add(this);
998
- const v2 = null !== u ? u : r.getLevel();
998
+ const v2 = null !== a ? a : r.getLevel();
999
999
  this.setLogLevel(k(v2));
1000
1000
  }
1001
1001
  getHumanReadableError(A2) {
@@ -1103,7 +1103,7 @@ class WasmBindings {
1103
1103
  const v2 = this.module._malloc(F);
1104
1104
  this.module.HEAPU8.fill(0, v2, v2 + F);
1105
1105
  try {
1106
- return 0 !== this.module._movi_get_stream_info(this.contextPtr, A2, v2) ? null : s(this.module, v2);
1106
+ return 0 !== this.module._movi_get_stream_info(this.contextPtr, A2, v2) ? null : i(this.module, v2);
1107
1107
  } finally {
1108
1108
  this.module._free(v2);
1109
1109
  }
@@ -1353,7 +1353,7 @@ class WasmBindings {
1353
1353
  this.contextPtr && this.module._movi_set_skip_frame(this.contextPtr, A2, v2);
1354
1354
  }
1355
1355
  }
1356
- let u = A.SILENT;
1356
+ let a = A.SILENT;
1357
1357
  class ThumbnailBindings {
1358
1358
  module;
1359
1359
  contextPtr = 0;
@@ -1437,7 +1437,7 @@ class ThumbnailBindings {
1437
1437
  const A2 = this.module._malloc(F);
1438
1438
  this.module.HEAPU8.fill(0, A2, A2 + F);
1439
1439
  try {
1440
- return 0 !== this.module._movi_thumbnail_get_stream_info(this.contextPtr, A2) ? null : s(this.module, A2);
1440
+ return 0 !== this.module._movi_thumbnail_get_stream_info(this.contextPtr, A2) ? null : i(this.module, A2);
1441
1441
  } finally {
1442
1442
  this.module._free(A2);
1443
1443
  }
@@ -1498,12 +1498,12 @@ async function createMoviModule(A2 = {}) {
1498
1498
  throw new Error(v3.status + " : " + v3.url);
1499
1499
  };
1500
1500
  }
1501
- var n2, F2, l2, k2, e2, HEAP32, s2, i2, u2, HEAPU8, a2 = function() {
1501
+ var n2, F2, l2, k2, e2, HEAP32, i2, s2, a2, HEAPU8, u2 = function() {
1502
1502
  }.bind(), o2 = function() {
1503
1503
  }.bind(), x2 = false, q2 = false;
1504
1504
  function B2() {
1505
1505
  var A3 = I2.buffer;
1506
- i2 = new Int8Array(A3), e2 = new Int16Array(A3), Module.HEAPU8 = HEAPU8 = new Uint8Array(A3), HEAP32 = new Int32Array(A3), u2 = new Uint32Array(A3), Module.HEAPF32 = new Float32Array(A3), s2 = new BigInt64Array(A3), new BigUint64Array(A3);
1506
+ s2 = new Int8Array(A3), e2 = new Int16Array(A3), Module.HEAPU8 = HEAPU8 = new Uint8Array(A3), HEAP32 = new Int32Array(A3), a2 = new Uint32Array(A3), Module.HEAPF32 = new Float32Array(A3), i2 = new BigInt64Array(A3), new BigUint64Array(A3);
1507
1507
  }
1508
1508
  function d2(A3) {
1509
1509
  Module.onAbort?.(A3), o2(A3 = `Aborted(${A3})`), x2 = true, A3 += ". Build with -sASSERTIONS for more info.";
@@ -1516,7 +1516,7 @@ async function createMoviModule(A2 = {}) {
1516
1516
  this.message = `Program terminated with exit(${A3})`, this.status = A3;
1517
1517
  }
1518
1518
  }
1519
- var $2, H2, c2, p2, m2, G2, _2, J2, h2, N2, g2, I2, P2, D2 = (A3) => {
1519
+ var $2, c2, H2, p2, m2, G2, _2, J2, h2, N2, g2, I2, P2, D2 = (A3) => {
1520
1520
  for (; A3.length > 0; ) A3.shift()(Module);
1521
1521
  }, L2 = [], O2 = (A3) => L2.push(A3), y = [], K = (A3) => y.push(A3), C = true, T = (A3) => A3 < -9007199254740992 || A3 > 9007199254740992 ? NaN : Number(A3), M = new TextDecoder(), S = (A3, v3, r3, j3) => {
1522
1522
  var b3 = v3 + r3;
@@ -1635,9 +1635,9 @@ async function createMoviModule(A2 = {}) {
1635
1635
  }
1636
1636
  return z.shift();
1637
1637
  })(), put_char(A3, v3) {
1638
- null === v3 || 10 === v3 ? (a2(V(A3.output)), A3.output = []) : 0 != v3 && A3.output.push(v3);
1638
+ null === v3 || 10 === v3 ? (u2(V(A3.output)), A3.output = []) : 0 != v3 && A3.output.push(v3);
1639
1639
  }, fsync(A3) {
1640
- A3.output?.length > 0 && (a2(V(A3.output)), A3.output = []);
1640
+ A3.output?.length > 0 && (u2(V(A3.output)), A3.output = []);
1641
1641
  }, ioctl_tcgets: (A3) => ({ c_iflag: 25856, c_oflag: 5, c_cflag: 191, c_lflag: 35387, c_cc: [3, 28, 127, 21, 4, 0, 1, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }), ioctl_tcsets: (A3, v3, r3) => 0, ioctl_tiocgwinsz: (A3) => [24, 80] }, default_tty1_ops: { put_char(A3, v3) {
1642
1642
  null === v3 || 10 === v3 ? (o2(V(A3.output)), A3.output = []) : 0 != v3 && A3.output.push(v3);
1643
1643
  }, fsync(A3) {
@@ -1698,7 +1698,7 @@ async function createMoviModule(A2 = {}) {
1698
1698
  var E3 = Math.min(A3.node.usedBytes - b3, j3);
1699
1699
  return v3.set(t3.subarray(b3, b3 + E3), r3), E3;
1700
1700
  }, write(A3, v3, r3, j3, b3, t3) {
1701
- if (v3.buffer === i2.buffer && (t3 = false), !j3) return 0;
1701
+ if (v3.buffer === s2.buffer && (t3 = false), !j3) return 0;
1702
1702
  var E3 = A3.node;
1703
1703
  return E3.mtime = E3.ctime = Date.now(), t3 ? (E3.contents = v3.subarray(r3, r3 + j3), E3.usedBytes = j3) : 0 === E3.usedBytes && 0 === b3 ? (E3.contents = v3.slice(r3, r3 + j3), E3.usedBytes = j3) : (vA.expandFileStorage(E3, b3 + j3), E3.contents.set(v3.subarray(r3, r3 + j3), b3), E3.usedBytes = Math.max(E3.usedBytes, b3 + j3)), j3;
1704
1704
  }, llseek(A3, v3, r3) {
@@ -1708,9 +1708,9 @@ async function createMoviModule(A2 = {}) {
1708
1708
  }, mmap(A3, v3, r3, j3, b3) {
1709
1709
  if (!FS.isFile(A3.node.mode)) throw new FS.ErrnoError(43);
1710
1710
  var t3, E3, f3 = A3.node.contents;
1711
- if (2 & b3 || f3.buffer !== i2.buffer) {
1711
+ if (2 & b3 || f3.buffer !== s2.buffer) {
1712
1712
  if (E3 = true, !(t3 = AA())) throw new FS.ErrnoError(48);
1713
- f3 && ((r3 > 0 || r3 + v3 < f3.length) && (f3 = f3.subarray ? f3.subarray(r3, r3 + v3) : Array.prototype.slice.call(f3, r3, r3 + v3)), i2.set(f3, t3 >>> 0));
1713
+ f3 && ((r3 > 0 || r3 + v3 < f3.length) && (f3 = f3.subarray ? f3.subarray(r3, r3 + v3) : Array.prototype.slice.call(f3, r3, r3 + v3)), s2.set(f3, t3 >>> 0));
1714
1714
  } else E3 = false, t3 = f3.byteOffset;
1715
1715
  return { ptr: t3, allocated: E3 };
1716
1716
  }, msync: (A3, v3, r3, j3, b3) => (vA.stream_ops.write(A3, v3, 0, j3, r3, false), 0) } }, rA = (A3) => ("string" == typeof A3 && (A3 = W(A3)), A3.subarray || (A3 = new Uint8Array(A3)), A3), jA = (A3, v3) => {
@@ -2312,7 +2312,7 @@ async function createMoviModule(A2 = {}) {
2312
2312
  var b6 = new XMLHttpRequest();
2313
2313
  return b6.open("GET", j3, false), r3 !== E4 && b6.setRequestHeader("Range", "bytes=" + A6 + "-" + v6), b6.responseType = "arraybuffer", b6.overrideMimeType && b6.overrideMimeType("text/plain; charset=x-user-defined"), b6.send(null), b6.status >= 200 && b6.status < 300 || 304 === b6.status || d2("Couldn't load " + j3 + ". Status: " + b6.status), void 0 !== b6.response ? new Uint8Array(b6.response || []) : W(b6.responseText || "");
2314
2314
  })(v5, b5)), void 0 === f4.chunks[A5] && d2("doXHR failed!"), f4.chunks[A5];
2315
- }), !t4 && r3 || (E4 = r3 = 1, r3 = this.getter(0).length, E4 = r3, a2("LazyFiles on gzip forces download of the whole file when length is accessed")), this._length = r3, this._chunkSize = E4, this.lengthKnown = true;
2315
+ }), !t4 && r3 || (E4 = r3 = 1, r3 = this.getter(0).length, E4 = r3, u2("LazyFiles on gzip forces download of the whole file when length is accessed")), this._length = r3, this._chunkSize = E4, this.lengthKnown = true;
2316
2316
  }
2317
2317
  get length() {
2318
2318
  return this.lengthKnown || this.cacheLength(), this._length;
@@ -2343,7 +2343,7 @@ async function createMoviModule(A2 = {}) {
2343
2343
  FS.forceLoadFile(f3);
2344
2344
  var t4 = AA();
2345
2345
  if (!t4) throw new FS.ErrnoError(48);
2346
- return F3(A4, i2, t4, v4, r3), { ptr: t4, allocated: true };
2346
+ return F3(A4, s2, t4, v4, r3), { ptr: t4, allocated: true };
2347
2347
  }, f3.stream_ops = n3, f3;
2348
2348
  } }, nA = { currentUmask: 18, calculateAt(A3, v3, r3) {
2349
2349
  if (R.isAbs(v3)) return v3;
@@ -2354,11 +2354,11 @@ async function createMoviModule(A2 = {}) {
2354
2354
  }
2355
2355
  return j3 + "/" + v3;
2356
2356
  }, writeStat(A3, v3) {
2357
- u2[A3 >>> 2 >>> 0] = v3.dev, u2[A3 + 4 >>> 2 >>> 0] = v3.mode, u2[A3 + 8 >>> 2 >>> 0] = v3.nlink, u2[A3 + 12 >>> 2 >>> 0] = v3.uid, u2[A3 + 16 >>> 2 >>> 0] = v3.gid, u2[A3 + 20 >>> 2 >>> 0] = v3.rdev, s2[A3 + 24 >>> 3 >>> 0] = BigInt(v3.size), HEAP32[A3 + 32 >>> 2 >>> 0] = 4096, HEAP32[A3 + 36 >>> 2 >>> 0] = v3.blocks;
2357
+ a2[A3 >>> 2 >>> 0] = v3.dev, a2[A3 + 4 >>> 2 >>> 0] = v3.mode, a2[A3 + 8 >>> 2 >>> 0] = v3.nlink, a2[A3 + 12 >>> 2 >>> 0] = v3.uid, a2[A3 + 16 >>> 2 >>> 0] = v3.gid, a2[A3 + 20 >>> 2 >>> 0] = v3.rdev, i2[A3 + 24 >>> 3 >>> 0] = BigInt(v3.size), HEAP32[A3 + 32 >>> 2 >>> 0] = 4096, HEAP32[A3 + 36 >>> 2 >>> 0] = v3.blocks;
2358
2358
  var r3 = v3.atime.getTime(), j3 = v3.mtime.getTime(), b3 = v3.ctime.getTime();
2359
- return s2[A3 + 40 >>> 3 >>> 0] = BigInt(Math.floor(r3 / 1e3)), u2[A3 + 48 >>> 2 >>> 0] = r3 % 1e3 * 1e3 * 1e3, s2[A3 + 56 >>> 3 >>> 0] = BigInt(Math.floor(j3 / 1e3)), u2[A3 + 64 >>> 2 >>> 0] = j3 % 1e3 * 1e3 * 1e3, s2[A3 + 72 >>> 3 >>> 0] = BigInt(Math.floor(b3 / 1e3)), u2[A3 + 80 >>> 2 >>> 0] = b3 % 1e3 * 1e3 * 1e3, s2[A3 + 88 >>> 3 >>> 0] = BigInt(v3.ino), 0;
2359
+ return i2[A3 + 40 >>> 3 >>> 0] = BigInt(Math.floor(r3 / 1e3)), a2[A3 + 48 >>> 2 >>> 0] = r3 % 1e3 * 1e3 * 1e3, i2[A3 + 56 >>> 3 >>> 0] = BigInt(Math.floor(j3 / 1e3)), a2[A3 + 64 >>> 2 >>> 0] = j3 % 1e3 * 1e3 * 1e3, i2[A3 + 72 >>> 3 >>> 0] = BigInt(Math.floor(b3 / 1e3)), a2[A3 + 80 >>> 2 >>> 0] = b3 % 1e3 * 1e3 * 1e3, i2[A3 + 88 >>> 3 >>> 0] = BigInt(v3.ino), 0;
2360
2360
  }, writeStatFs(A3, v3) {
2361
- u2[A3 + 4 >>> 2 >>> 0] = v3.bsize, u2[A3 + 60 >>> 2 >>> 0] = v3.bsize, s2[A3 + 8 >>> 3 >>> 0] = BigInt(v3.blocks), s2[A3 + 16 >>> 3 >>> 0] = BigInt(v3.bfree), s2[A3 + 24 >>> 3 >>> 0] = BigInt(v3.bavail), s2[A3 + 32 >>> 3 >>> 0] = BigInt(v3.files), s2[A3 + 40 >>> 3 >>> 0] = BigInt(v3.ffree), u2[A3 + 48 >>> 2 >>> 0] = v3.fsid, u2[A3 + 64 >>> 2 >>> 0] = v3.flags, u2[A3 + 56 >>> 2 >>> 0] = v3.namelen;
2361
+ a2[A3 + 4 >>> 2 >>> 0] = v3.bsize, a2[A3 + 60 >>> 2 >>> 0] = v3.bsize, i2[A3 + 8 >>> 3 >>> 0] = BigInt(v3.blocks), i2[A3 + 16 >>> 3 >>> 0] = BigInt(v3.bfree), i2[A3 + 24 >>> 3 >>> 0] = BigInt(v3.bavail), i2[A3 + 32 >>> 3 >>> 0] = BigInt(v3.files), i2[A3 + 40 >>> 3 >>> 0] = BigInt(v3.ffree), a2[A3 + 48 >>> 2 >>> 0] = v3.fsid, a2[A3 + 64 >>> 2 >>> 0] = v3.flags, a2[A3 + 56 >>> 2 >>> 0] = v3.namelen;
2362
2362
  }, doMsync(A3, v3, r3, j3, b3) {
2363
2363
  if (!FS.isFile(v3.node.mode)) throw new FS.ErrnoError(43);
2364
2364
  if (2 & j3) return 0;
@@ -2367,22 +2367,22 @@ async function createMoviModule(A2 = {}) {
2367
2367
  }, getStreamFromFD: (A3) => FS.getStreamChecked(A3), varargs: void 0, getStr: (A3) => w(A3) }, FA = () => {
2368
2368
  var A3 = HEAP32[+nA.varargs >>> 2 >>> 0];
2369
2369
  return nA.varargs += 4, A3;
2370
- }, lA = FA, kA = (A3, v3, r3) => Y(A3, HEAPU8, v3, r3), eA = 0, sA = {}, iA = (A3) => {
2370
+ }, lA = FA, kA = (A3, v3, r3) => Y(A3, HEAPU8, v3, r3), eA = 0, iA = {}, sA = (A3) => {
2371
2371
  if (A3 instanceof ExitStatus || "unwind" == A3) return n2;
2372
2372
  E2(0, A3);
2373
- }, uA = () => C || eA > 0, aA = (A3) => {
2374
- n2 = A3, uA() || (Module.onExit?.(A3), x2 = true), E2(0, new ExitStatus(A3));
2373
+ }, aA = () => C || eA > 0, uA = (A3) => {
2374
+ n2 = A3, aA() || (Module.onExit?.(A3), x2 = true), E2(0, new ExitStatus(A3));
2375
2375
  }, oA = (A3) => {
2376
2376
  if (!x2) try {
2377
2377
  return A3();
2378
2378
  } catch (A4) {
2379
- iA(A4);
2379
+ sA(A4);
2380
2380
  } finally {
2381
2381
  (() => {
2382
- if (!uA()) try {
2383
- n2 = A4 = n2, aA(A4);
2382
+ if (!aA()) try {
2383
+ n2 = A4 = n2, uA(A4);
2384
2384
  } catch (A5) {
2385
- iA(A5);
2385
+ sA(A5);
2386
2386
  }
2387
2387
  var A4;
2388
2388
  })();
@@ -2393,16 +2393,16 @@ async function createMoviModule(A2 = {}) {
2393
2393
  return I2.grow(v3), B2(), 1;
2394
2394
  } catch (A4) {
2395
2395
  }
2396
- }, $A = {}, HA = () => {
2397
- if (!HA.strings) {
2396
+ }, $A = {}, cA = () => {
2397
+ if (!cA.strings) {
2398
2398
  var A3 = { USER: "web_user", LOGNAME: "web_user", PATH: "/", PWD: "/", HOME: "/home/web_user", LANG: (globalThis.navigator?.language ?? "C").replace("-", "_") + ".UTF-8", _: t2 || "./this.program" };
2399
2399
  for (var v3 in $A) void 0 === $A[v3] ? delete A3[v3] : A3[v3] = $A[v3];
2400
2400
  var r3 = [];
2401
2401
  for (var v3 in A3) r3.push(`${v3}=${A3[v3]}`);
2402
- HA.strings = r3;
2402
+ cA.strings = r3;
2403
2403
  }
2404
- return HA.strings;
2405
- }, cA = (A3) => {
2404
+ return cA.strings;
2405
+ }, HA = (A3) => {
2406
2406
  try {
2407
2407
  return A3();
2408
2408
  } catch (A4) {
@@ -2435,14 +2435,14 @@ async function createMoviModule(A2 = {}) {
2435
2435
  }
2436
2436
  return pA.callstackFuncToId.get(A3);
2437
2437
  }, maybeStopUnwind() {
2438
- pA.currData && pA.state === pA.State.Unwinding && 0 === pA.exportCallStack.length && (pA.state = pA.State.Normal, cA(h2), "undefined" != typeof Fibers && Fibers.trampoline());
2438
+ pA.currData && pA.state === pA.State.Unwinding && 0 === pA.exportCallStack.length && (pA.state = pA.State.Normal, HA(h2), "undefined" != typeof Fibers && Fibers.trampoline());
2439
2439
  }, whenDone: () => new Promise((A3, v3) => {
2440
2440
  pA.asyncPromiseHandlers = { resolve: A3, reject: v3 };
2441
2441
  }), allocateData() {
2442
- var A3 = c2(12 + pA.StackSize);
2442
+ var A3 = H2(12 + pA.StackSize);
2443
2443
  return pA.setDataHeader(A3, A3 + 12, pA.StackSize), pA.setDataRewindFunc(A3), A3;
2444
2444
  }, setDataHeader(A3, v3, r3) {
2445
- u2[A3 >>> 2 >>> 0] = v3, u2[A3 + 4 >>> 2 >>> 0] = v3 + r3;
2445
+ a2[A3 >>> 2 >>> 0] = v3, a2[A3 + 4 >>> 2 >>> 0] = v3 + r3;
2446
2446
  }, setDataRewindFunc(A3) {
2447
2447
  var v3 = pA.exportCallStack[0], r3 = pA.getCallStackId(v3);
2448
2448
  HEAP32[A3 + 8 >>> 2 >>> 0] = r3;
@@ -2458,7 +2458,7 @@ async function createMoviModule(A2 = {}) {
2458
2458
  var v3 = false, r3 = false;
2459
2459
  A3((A4 = 0) => {
2460
2460
  if (!x2 && (pA.handleSleepReturnValue = A4, v3 = true, r3)) {
2461
- pA.state = pA.State.Rewinding, cA(() => N2(pA.currData)), "undefined" != typeof MainLoop && MainLoop.func && MainLoop.resume();
2461
+ pA.state = pA.State.Rewinding, HA(() => N2(pA.currData)), "undefined" != typeof MainLoop && MainLoop.func && MainLoop.resume();
2462
2462
  var j3, b3 = false;
2463
2463
  try {
2464
2464
  j3 = pA.doRewind(pA.currData);
@@ -2472,8 +2472,8 @@ async function createMoviModule(A2 = {}) {
2472
2472
  }
2473
2473
  if (b3 && !t3) throw j3;
2474
2474
  }
2475
- }), r3 = true, v3 || (pA.state = pA.State.Unwinding, pA.currData = pA.allocateData(), "undefined" != typeof MainLoop && MainLoop.func && MainLoop.pause(), cA(() => J2(pA.currData)));
2476
- } else pA.state === pA.State.Rewinding ? (pA.state = pA.State.Normal, cA(g2), H2(pA.currData), pA.currData = null, pA.sleepCallbacks.forEach(oA)) : d2(`invalid state: ${pA.state}`);
2475
+ }), r3 = true, v3 || (pA.state = pA.State.Unwinding, pA.currData = pA.allocateData(), "undefined" != typeof MainLoop && MainLoop.func && MainLoop.pause(), HA(() => J2(pA.currData)));
2476
+ } else pA.state === pA.State.Rewinding ? (pA.state = pA.State.Normal, HA(g2), c2(pA.currData), pA.currData = null, pA.sleepCallbacks.forEach(oA)) : d2(`invalid state: ${pA.state}`);
2477
2477
  return pA.handleSleepReturnValue;
2478
2478
  }
2479
2479
  }, handleAsync: (A3) => pA.handleSleep(async (v3) => {
@@ -2487,27 +2487,27 @@ async function createMoviModule(A2 = {}) {
2487
2487
  })(A4)), v4;
2488
2488
  }, array: (A4) => {
2489
2489
  var v4, r4, j4 = GA(A4.length);
2490
- return v4 = A4, r4 = j4, i2.set(v4, r4 >>> 0), j4;
2490
+ return v4 = A4, r4 = j4, s2.set(v4, r4 >>> 0), j4;
2491
2491
  } }, E3 = mA(A3), f3 = [], n3 = 0;
2492
2492
  if (j3) for (var F3 = 0; F3 < j3.length; F3++) {
2493
2493
  var l3 = t3[r3[F3]];
2494
2494
  l3 ? (0 === n3 && (n3 = _A()), f3[F3] = l3(j3[F3])) : f3[F3] = j3[F3];
2495
2495
  }
2496
2496
  var k3 = pA.currData, e3 = E3(...f3);
2497
- function s3(A4) {
2497
+ function i3(A4) {
2498
2498
  return eA -= 1, 0 !== n3 && m2(n3), function(A5) {
2499
2499
  return "string" === v3 ? w(A5) : "pointer" === v3 ? A5 >>> 0 : "boolean" === v3 ? Boolean(A5) : A5;
2500
2500
  }(A4);
2501
2501
  }
2502
- var u3 = b3?.async;
2503
- return eA += 1, pA.currData != k3 ? pA.whenDone().then(s3) : (e3 = s3(e3), u3 ? Promise.resolve(e3) : e3);
2502
+ var a3 = b3?.async;
2503
+ return eA += 1, pA.currData != k3 ? pA.whenDone().then(i3) : (e3 = i3(e3), a3 ? Promise.resolve(e3) : e3);
2504
2504
  }, hA = (A3) => P2.get(A3), NA = [], gA = (A3, v3) => P2.set(A3, v3), IA = (A3) => {
2505
2505
  const v3 = A3.length;
2506
2506
  return [v3 % 128 | 128, v3 >> 7, ...A3];
2507
2507
  }, PA = { i: 127, p: 127, j: 126, f: 125, d: 124, e: 111 }, DA = (A3) => IA(Array.from(A3, (A4) => PA[A4]));
2508
2508
  if (FS.createPreloadedFile = (A3, v3, r3, j3, b3, t3, E3, f3, n3, F3) => {
2509
2509
  fA(A3, v3, r3, j3, b3, f3, n3, F3).then(t3).catch(E3);
2510
- }, FS.preloadFile = fA, FS.staticInit(), Module.noExitRuntime && (C = Module.noExitRuntime), Module.preloadPlugins && (EA = Module.preloadPlugins), Module.print && (a2 = Module.print), Module.printErr && (o2 = Module.printErr), Module.wasmBinary && Module.wasmBinary, Module.arguments && Module.arguments, Module.thisProgram && (t2 = Module.thisProgram), Module.preInit) for ("function" == typeof Module.preInit && (Module.preInit = [Module.preInit]); Module.preInit.length > 0; ) Module.preInit.shift()();
2510
+ }, FS.preloadFile = fA, FS.staticInit(), Module.noExitRuntime && (C = Module.noExitRuntime), Module.preloadPlugins && (EA = Module.preloadPlugins), Module.print && (u2 = Module.print), Module.printErr && (o2 = Module.printErr), Module.wasmBinary && Module.wasmBinary, Module.arguments && Module.arguments, Module.thisProgram && (t2 = Module.thisProgram), Module.preInit) for ("function" == typeof Module.preInit && (Module.preInit = [Module.preInit]); Module.preInit.length > 0; ) Module.preInit.shift()();
2511
2511
  Module.ccall = JA, Module.cwrap = (A3, v3, r3, j3) => {
2512
2512
  var b3 = !r3 || r3.every((A4) => "number" === A4 || "boolean" === A4);
2513
2513
  return "string" !== v3 && b3 && !j3 ? mA(A3) : (...b4) => JA(A3, v3, r3, b4, j3);
@@ -2532,7 +2532,7 @@ async function createMoviModule(A2 = {}) {
2532
2532
  }
2533
2533
  return $2.set(A3, j3), j3;
2534
2534
  }, Module.UTF8ToString = w, Module.lengthBytesUTF8 = Q, Module.stringToNewUTF8 = (A3) => {
2535
- var v3 = Q(A3) + 1, r3 = c2(v3);
2535
+ var v3 = Q(A3) + 1, r3 = H2(v3);
2536
2536
  return r3 && kA(A3, r3, v3), r3;
2537
2537
  }, Module.FS = FS;
2538
2538
  var LA, OA = { b: function(A3, v3, r3, j3) {
@@ -2590,20 +2590,20 @@ async function createMoviModule(A2 = {}) {
2590
2590
  var j3 = nA.getStreamFromFD(A3);
2591
2591
  j3.getdents ||= FS.readdir(j3.path);
2592
2592
  for (var b3 = 280, t3 = 0, E3 = FS.llseek(j3, 0, 1), f3 = Math.floor(E3 / b3), n3 = Math.min(j3.getdents.length, f3 + Math.floor(r3 / b3)), F3 = f3; F3 < n3; F3++) {
2593
- var l3, k3, u3 = j3.getdents[F3];
2594
- if ("." === u3) l3 = j3.node.id, k3 = 4;
2595
- else if (".." === u3) l3 = FS.lookupPath(j3.path, { parent: true }).node.id, k3 = 4;
2593
+ var l3, k3, a3 = j3.getdents[F3];
2594
+ if ("." === a3) l3 = j3.node.id, k3 = 4;
2595
+ else if (".." === a3) l3 = FS.lookupPath(j3.path, { parent: true }).node.id, k3 = 4;
2596
2596
  else {
2597
- var a3;
2597
+ var u3;
2598
2598
  try {
2599
- a3 = FS.lookupNode(j3.node, u3);
2599
+ u3 = FS.lookupNode(j3.node, a3);
2600
2600
  } catch (A4) {
2601
2601
  if (28 === A4?.errno) continue;
2602
2602
  throw A4;
2603
2603
  }
2604
- l3 = a3.id, k3 = FS.isChrdev(a3.mode) ? 2 : FS.isDir(a3.mode) ? 4 : FS.isLink(a3.mode) ? 10 : 8;
2604
+ l3 = u3.id, k3 = FS.isChrdev(u3.mode) ? 2 : FS.isDir(u3.mode) ? 4 : FS.isLink(u3.mode) ? 10 : 8;
2605
2605
  }
2606
- s2[v3 + t3 >>> 3 >>> 0] = BigInt(l3), s2[v3 + t3 + 8 >>> 3 >>> 0] = BigInt((F3 + 1) * b3), e2[v3 + t3 + 16 >>> 1 >>> 0] = 280, i2[v3 + t3 + 18 >>> 0] = k3, kA(u3, v3 + t3 + 19, 256), t3 += b3;
2606
+ i2[v3 + t3 >>> 3 >>> 0] = BigInt(l3), i2[v3 + t3 + 8 >>> 3 >>> 0] = BigInt((F3 + 1) * b3), e2[v3 + t3 + 16 >>> 1 >>> 0] = 280, s2[v3 + t3 + 18 >>> 0] = k3, kA(a3, v3 + t3 + 19, 256), t3 += b3;
2607
2607
  }
2608
2608
  return FS.llseek(j3, F3 * b3, 0), t3;
2609
2609
  } catch (A4) {
@@ -2627,7 +2627,7 @@ async function createMoviModule(A2 = {}) {
2627
2627
  if (j3.tty.ops.ioctl_tcgets) {
2628
2628
  var b3 = j3.tty.ops.ioctl_tcgets(j3), t3 = lA();
2629
2629
  HEAP32[t3 >>> 2 >>> 0] = b3.c_iflag || 0, HEAP32[t3 + 4 >>> 2 >>> 0] = b3.c_oflag || 0, HEAP32[t3 + 8 >>> 2 >>> 0] = b3.c_cflag || 0, HEAP32[t3 + 12 >>> 2 >>> 0] = b3.c_lflag || 0;
2630
- for (var E3 = 0; E3 < 32; E3++) i2[t3 + E3 + 17 >>> 0] = b3.c_cc[E3] || 0;
2630
+ for (var E3 = 0; E3 < 32; E3++) s2[t3 + E3 + 17 >>> 0] = b3.c_cc[E3] || 0;
2631
2631
  return 0;
2632
2632
  }
2633
2633
  return 0;
@@ -2638,7 +2638,7 @@ async function createMoviModule(A2 = {}) {
2638
2638
  if (j3.tty.ops.ioctl_tcsets) {
2639
2639
  t3 = lA();
2640
2640
  var f3 = HEAP32[t3 >>> 2 >>> 0], n3 = HEAP32[t3 + 4 >>> 2 >>> 0], F3 = HEAP32[t3 + 8 >>> 2 >>> 0], l3 = HEAP32[t3 + 12 >>> 2 >>> 0], k3 = [];
2641
- for (E3 = 0; E3 < 32; E3++) k3.push(i2[t3 + E3 + 17 >>> 0]);
2641
+ for (E3 = 0; E3 < 32; E3++) k3.push(s2[t3 + E3 + 17 >>> 0]);
2642
2642
  return j3.tty.ops.ioctl_tcsets(j3.tty, v3, { c_iflag: f3, c_oflag: n3, c_cflag: F3, c_lflag: l3, c_cc: k3 });
2643
2643
  }
2644
2644
  return 0;
@@ -2652,8 +2652,8 @@ async function createMoviModule(A2 = {}) {
2652
2652
  case 21523:
2653
2653
  if (!j3.tty) return -59;
2654
2654
  if (j3.tty.ops.ioctl_tiocgwinsz) {
2655
- var s3 = j3.tty.ops.ioctl_tiocgwinsz(j3.tty);
2656
- t3 = lA(), e2[t3 >>> 1 >>> 0] = s3[0], e2[t3 + 2 >>> 1 >>> 0] = s3[1];
2655
+ var i3 = j3.tty.ops.ioctl_tiocgwinsz(j3.tty);
2656
+ t3 = lA(), e2[t3 >>> 1 >>> 0] = i3[0], e2[t3 + 2 >>> 1 >>> 0] = i3[1];
2657
2657
  }
2658
2658
  return 0;
2659
2659
  default:
@@ -2736,15 +2736,15 @@ async function createMoviModule(A2 = {}) {
2736
2736
  var j3 = Date.UTC(r3.getUTCFullYear(), 0, 1, 0, 0, 0, 0), b3 = (r3.getTime() - j3) / 864e5 | 0;
2737
2737
  HEAP32[v3 + 28 >>> 2 >>> 0] = b3;
2738
2738
  }, k: (A3, v3) => {
2739
- if (sA[A3] && (clearTimeout(sA[A3].id), delete sA[A3]), !v3) return 0;
2739
+ if (iA[A3] && (clearTimeout(iA[A3].id), delete iA[A3]), !v3) return 0;
2740
2740
  var r3 = setTimeout(() => {
2741
- delete sA[A3], oA(() => p2(A3, xA()));
2741
+ delete iA[A3], oA(() => p2(A3, xA()));
2742
2742
  }, v3);
2743
- return sA[A3] = { id: r3, timeout_ms: v3 }, 0;
2743
+ return iA[A3] = { id: r3, timeout_ms: v3 }, 0;
2744
2744
  }, v: function(A3, v3, r3, j3) {
2745
2745
  A3 >>>= 0, v3 >>>= 0, r3 >>>= 0, j3 >>>= 0;
2746
2746
  var b3 = (/* @__PURE__ */ new Date()).getFullYear(), t3 = new Date(b3, 0, 1), E3 = new Date(b3, 6, 1), f3 = t3.getTimezoneOffset(), n3 = E3.getTimezoneOffset(), F3 = Math.max(f3, n3);
2747
- u2[A3 >>> 2 >>> 0] = 60 * F3, HEAP32[v3 >>> 2 >>> 0] = Number(f3 != n3);
2747
+ a2[A3 >>> 2 >>> 0] = 60 * F3, HEAP32[v3 >>> 2 >>> 0] = Number(f3 != n3);
2748
2748
  var l3 = (A4) => {
2749
2749
  var v4 = A4 >= 0 ? "-" : "+", r4 = Math.abs(A4);
2750
2750
  return `UTC${v4}${String(Math.floor(r4 / 60)).padStart(2, "0")}${String(r4 % 60).padStart(2, "0")}`;
@@ -2755,7 +2755,7 @@ async function createMoviModule(A2 = {}) {
2755
2755
  var j3, b3;
2756
2756
  b3 = 0 === A3 ? qA() : xA();
2757
2757
  var t3 = Math.round(1e3 * b3 * 1e3);
2758
- return s2[r3 >>> 3 >>> 0] = BigInt(t3), 0;
2758
+ return i2[r3 >>> 3 >>> 0] = BigInt(t3), 0;
2759
2759
  }, E: qA, e: xA, m: function(A3) {
2760
2760
  A3 >>>= 0;
2761
2761
  var v3 = HEAPU8.length, r3 = 4294901760;
@@ -2770,18 +2770,18 @@ async function createMoviModule(A2 = {}) {
2770
2770
  }, y: function(A3, v3) {
2771
2771
  A3 >>>= 0, v3 >>>= 0;
2772
2772
  var r3 = 0, j3 = 0;
2773
- for (var b3 of HA()) {
2773
+ for (var b3 of cA()) {
2774
2774
  var t3 = v3 + r3;
2775
- u2[A3 + j3 >>> 2 >>> 0] = t3, r3 += kA(b3, t3, 1 / 0) + 1, j3 += 4;
2775
+ a2[A3 + j3 >>> 2 >>> 0] = t3, r3 += kA(b3, t3, 1 / 0) + 1, j3 += 4;
2776
2776
  }
2777
2777
  return 0;
2778
2778
  }, z: function(A3, v3) {
2779
2779
  A3 >>>= 0, v3 >>>= 0;
2780
- var r3 = HA();
2781
- u2[A3 >>> 2 >>> 0] = r3.length;
2780
+ var r3 = cA();
2781
+ a2[A3 >>> 2 >>> 0] = r3.length;
2782
2782
  var j3 = 0;
2783
2783
  for (var b3 of r3) j3 += Q(b3) + 1;
2784
- return u2[v3 >>> 2 >>> 0] = j3, 0;
2784
+ return a2[v3 >>> 2 >>> 0] = j3, 0;
2785
2785
  }, c: function(A3) {
2786
2786
  try {
2787
2787
  var v3 = nA.getStreamFromFD(A3);
@@ -2794,7 +2794,7 @@ async function createMoviModule(A2 = {}) {
2794
2794
  v3 >>>= 0;
2795
2795
  try {
2796
2796
  var r3 = nA.getStreamFromFD(A3), j3 = r3.tty ? 2 : FS.isDir(r3.mode) ? 3 : FS.isLink(r3.mode) ? 7 : 4;
2797
- return i2[v3 >>> 0] = j3, e2[v3 + 2 >>> 1 >>> 0] = 0, s2[v3 + 8 >>> 3 >>> 0] = BigInt(0), s2[v3 + 16 >>> 3 >>> 0] = BigInt(0), 0;
2797
+ return s2[v3 >>> 0] = j3, e2[v3 + 2 >>> 1 >>> 0] = 0, i2[v3 + 8 >>> 3 >>> 0] = BigInt(0), i2[v3 + 16 >>> 3 >>> 0] = BigInt(0), 0;
2798
2798
  } catch (A4) {
2799
2799
  if (void 0 === FS || "ErrnoError" !== A4.name) throw A4;
2800
2800
  return A4.errno;
@@ -2804,15 +2804,15 @@ async function createMoviModule(A2 = {}) {
2804
2804
  try {
2805
2805
  var b3 = ((A4, v4, r4) => {
2806
2806
  for (var j4 = 0, b4 = 0; b4 < r4; b4++) {
2807
- var t3 = u2[v4 >>> 2 >>> 0], E3 = u2[v4 + 4 >>> 2 >>> 0];
2807
+ var t3 = a2[v4 >>> 2 >>> 0], E3 = a2[v4 + 4 >>> 2 >>> 0];
2808
2808
  v4 += 8;
2809
- var f3 = FS.read(A4, i2, t3, E3, void 0);
2809
+ var f3 = FS.read(A4, s2, t3, E3, void 0);
2810
2810
  if (f3 < 0) return -1;
2811
2811
  if (j4 += f3, f3 < E3) break;
2812
2812
  }
2813
2813
  return j4;
2814
2814
  })(nA.getStreamFromFD(A3), v3, r3);
2815
- return u2[j3 >>> 2 >>> 0] = b3, 0;
2815
+ return a2[j3 >>> 2 >>> 0] = b3, 0;
2816
2816
  } catch (A4) {
2817
2817
  if (void 0 === FS || "ErrnoError" !== A4.name) throw A4;
2818
2818
  return A4.errno;
@@ -2822,7 +2822,7 @@ async function createMoviModule(A2 = {}) {
2822
2822
  try {
2823
2823
  if (isNaN(v3)) return 22;
2824
2824
  var b3 = nA.getStreamFromFD(A3);
2825
- return FS.llseek(b3, v3, r3), s2[j3 >>> 3 >>> 0] = BigInt(b3.position), b3.getdents && 0 === v3 && 0 === r3 && (b3.getdents = null), 0;
2825
+ return FS.llseek(b3, v3, r3), i2[j3 >>> 3 >>> 0] = BigInt(b3.position), b3.getdents && 0 === v3 && 0 === r3 && (b3.getdents = null), 0;
2826
2826
  } catch (A4) {
2827
2827
  if (void 0 === FS || "ErrnoError" !== A4.name) throw A4;
2828
2828
  return A4.errno;
@@ -2832,15 +2832,15 @@ async function createMoviModule(A2 = {}) {
2832
2832
  try {
2833
2833
  var b3 = ((A4, v4, r4) => {
2834
2834
  for (var j4 = 0, b4 = 0; b4 < r4; b4++) {
2835
- var t3 = u2[v4 >>> 2 >>> 0], E3 = u2[v4 + 4 >>> 2 >>> 0];
2835
+ var t3 = a2[v4 >>> 2 >>> 0], E3 = a2[v4 + 4 >>> 2 >>> 0];
2836
2836
  v4 += 8;
2837
- var f3 = FS.write(A4, i2, t3, E3, void 0);
2837
+ var f3 = FS.write(A4, s2, t3, E3, void 0);
2838
2838
  if (f3 < 0) return -1;
2839
2839
  if (j4 += f3, f3 < E3) break;
2840
2840
  }
2841
2841
  return j4;
2842
2842
  })(nA.getStreamFromFD(A3), v3, r3);
2843
- return u2[j3 >>> 2 >>> 0] = b3, 0;
2843
+ return a2[j3 >>> 2 >>> 0] = b3, 0;
2844
2844
  } catch (A4) {
2845
2845
  if (void 0 === FS || "ErrnoError" !== A4.name) throw A4;
2846
2846
  return A4.errno;
@@ -2856,13 +2856,13 @@ async function createMoviModule(A2 = {}) {
2856
2856
  });
2857
2857
  }, a: function(A3, v3) {
2858
2858
  globalThis.__movilog?.log("[library_movi] Thumbnail packet ready:", A3, v3), Module._pendingThumbnail && (Module._pendingThumbnail.resolve({ size: A3, pts: v3 }), Module._pendingThumbnail = null);
2859
- }, r: aA, l: function(A3, v3) {
2859
+ }, r: uA, l: function(A3, v3) {
2860
2860
  return A3 >>>= 0, v3 >>>= 0, X(HEAPU8.subarray(A3 >>> 0, A3 + v3 >>> 0));
2861
2861
  } };
2862
2862
  return LA = await async function() {
2863
2863
  function A3(A4, v4) {
2864
2864
  return LA = A4.exports, function(A5) {
2865
- Module._movi_create = A5.J, H2 = Module._free = A5.K, Module._movi_set_file_size = A5.L, Module._movi_destroy = A5.M, Module._movi_open = A5.N, Module._movi_set_log_level = A5.O, Module._movi_enable_audio_downmix = A5.P, Module._movi_get_format_name = A5.Q, Module._movi_get_metadata_title = A5.R, Module._movi_enable_decoder = A5.S, Module._movi_send_packet = A5.T, Module._movi_set_skip_frame = A5.U, Module._movi_receive_frame = A5.V, Module._movi_get_frame_rgba = A5.W, Module._movi_get_frame_rgba_size = A5.X, Module._movi_get_frame_rgba_linesize = A5.Y, Module._movi_decode_subtitle = A5.Z, Module._movi_get_subtitle_text = A5._, Module._movi_get_subtitle_times = A5.$, Module._movi_get_subtitle_image_info = A5.aa, Module._movi_get_subtitle_image_data = A5.ba, Module._movi_free_subtitle = A5.ca, Module._movi_get_frame_pts = A5.da, Module._movi_flush_decoder = A5.ea, Module._movi_clear_prefetched_cues = A5.fa, Module._movi_prefetch_subtitle_cues = A5.ga, c2 = Module._malloc = A5.ha, Module._movi_get_prefetched_cue_count = A5.ia, Module._movi_get_prefetched_cue = A5.ja, Module._movi_get_frame_width = A5.ka, Module._movi_get_frame_height = A5.la, Module._movi_get_frame_format = A5.ma, Module._movi_get_frame_data = A5.na, Module._movi_get_frame_linesize = A5.oa, Module._movi_get_frame_samples = A5.pa, Module._movi_get_frame_channels = A5.qa, Module._movi_get_frame_sample_rate = A5.ra, Module._movi_get_duration = A5.sa, Module._movi_get_start_time = A5.ta, Module._movi_get_stream_count = A5.ua, Module._movi_get_stream_info = A5.va, Module._movi_get_extradata = A5.wa, Module._movi_seek_to = A5.xa, Module._movi_read_frame = A5.ya, Module._movi_get_chapter_count = A5.za, Module._movi_get_chapter_start = A5.Aa, Module._movi_get_chapter_end = A5.Ba, Module._movi_get_chapter_title = A5.Ca, Module._movi_stretch_new = A5.Da, Module._movi_stretch_delete = A5.Ea, Module._movi_stretch_reset = A5.Fa, Module._movi_stretch_set_transpose_semitones = A5.Ga, Module._movi_stretch_input_latency = A5.Ha, Module._movi_stretch_output_latency = A5.Ia, Module._movi_stretch_process = A5.Ja, Module._movi_thumbnail_create = A5.Ka, Module._movi_thumbnail_open = A5.La, Module._movi_thumbnail_read_keyframe = A5.Ma, Module._movi_thumbnail_get_packet_data = A5.Na, Module._movi_thumbnail_get_stream_info = A5.Oa, Module._movi_thumbnail_get_extradata = A5.Pa, Module._movi_thumbnail_decode_frame_yuv = A5.Qa, Module._movi_thumbnail_get_plane_data = A5.Ra, Module._movi_thumbnail_get_plane_linesize = A5.Sa, Module._movi_thumbnail_get_frame_width = A5.Ta, Module._movi_thumbnail_get_frame_height = A5.Ua, Module._movi_thumbnail_decode_frame = A5.Va, Module._movi_thumbnail_clear_buffer = A5.Wa, Module._movi_thumbnail_destroy = A5.Xa, p2 = A5._a, m2 = A5.$a, G2 = A5.ab, _2 = A5.bb, A5.cb, A5.db, A5.eb, A5.fb, A5.gb, A5.hb, A5.ib, A5.jb, A5.kb, A5.lb, A5.mb, A5.nb, A5.ob, A5.pb, A5.qb, A5.rb, A5.sb, A5.tb, A5.ub, A5.vb, A5.wb, A5.xb, A5.yb, A5.zb, A5.Ab, A5.Bb, A5.Cb, A5.Db, A5.Eb, A5.Fb, A5.Gb, A5.Hb, A5.Ib, A5.Jb, A5.Kb, A5.Lb, A5.Mb, A5.Nb, A5.Ob, A5.Pb, A5.Qb, A5.Rb, A5.Sb, A5.Tb, A5.Ub, A5.Vb, A5.Wb, A5.Xb, A5.Yb, A5.Zb, A5._b, A5.$b, A5.ac, J2 = A5.bc, h2 = A5.cc, N2 = A5.dc, g2 = A5.ec, I2 = A5.H, Module._ff_h264_cabac_tables = A5.Ya.value >>> 0, P2 = A5.Za;
2865
+ Module._movi_create = A5.J, c2 = Module._free = A5.K, Module._movi_set_file_size = A5.L, Module._movi_destroy = A5.M, Module._movi_open = A5.N, Module._movi_set_log_level = A5.O, Module._movi_enable_audio_downmix = A5.P, Module._movi_get_format_name = A5.Q, Module._movi_get_metadata_title = A5.R, Module._movi_enable_decoder = A5.S, Module._movi_send_packet = A5.T, Module._movi_set_skip_frame = A5.U, Module._movi_receive_frame = A5.V, Module._movi_get_frame_rgba = A5.W, Module._movi_get_frame_rgba_size = A5.X, Module._movi_get_frame_rgba_linesize = A5.Y, Module._movi_decode_subtitle = A5.Z, Module._movi_get_subtitle_text = A5._, Module._movi_get_subtitle_times = A5.$, Module._movi_get_subtitle_image_info = A5.aa, Module._movi_get_subtitle_image_data = A5.ba, Module._movi_free_subtitle = A5.ca, Module._movi_get_frame_pts = A5.da, Module._movi_flush_decoder = A5.ea, Module._movi_clear_prefetched_cues = A5.fa, Module._movi_prefetch_subtitle_cues = A5.ga, H2 = Module._malloc = A5.ha, Module._movi_get_prefetched_cue_count = A5.ia, Module._movi_get_prefetched_cue = A5.ja, Module._movi_get_frame_width = A5.ka, Module._movi_get_frame_height = A5.la, Module._movi_get_frame_format = A5.ma, Module._movi_get_frame_data = A5.na, Module._movi_get_frame_linesize = A5.oa, Module._movi_get_frame_samples = A5.pa, Module._movi_get_frame_channels = A5.qa, Module._movi_get_frame_sample_rate = A5.ra, Module._movi_get_duration = A5.sa, Module._movi_get_start_time = A5.ta, Module._movi_get_stream_count = A5.ua, Module._movi_get_stream_info = A5.va, Module._movi_get_extradata = A5.wa, Module._movi_seek_to = A5.xa, Module._movi_read_frame = A5.ya, Module._movi_get_chapter_count = A5.za, Module._movi_get_chapter_start = A5.Aa, Module._movi_get_chapter_end = A5.Ba, Module._movi_get_chapter_title = A5.Ca, Module._movi_stretch_new = A5.Da, Module._movi_stretch_delete = A5.Ea, Module._movi_stretch_reset = A5.Fa, Module._movi_stretch_set_transpose_semitones = A5.Ga, Module._movi_stretch_input_latency = A5.Ha, Module._movi_stretch_output_latency = A5.Ia, Module._movi_stretch_process = A5.Ja, Module._movi_thumbnail_create = A5.Ka, Module._movi_thumbnail_open = A5.La, Module._movi_thumbnail_read_keyframe = A5.Ma, Module._movi_thumbnail_get_packet_data = A5.Na, Module._movi_thumbnail_get_stream_info = A5.Oa, Module._movi_thumbnail_get_extradata = A5.Pa, Module._movi_thumbnail_decode_frame_yuv = A5.Qa, Module._movi_thumbnail_get_plane_data = A5.Ra, Module._movi_thumbnail_get_plane_linesize = A5.Sa, Module._movi_thumbnail_get_frame_width = A5.Ta, Module._movi_thumbnail_get_frame_height = A5.Ua, Module._movi_thumbnail_decode_frame = A5.Va, Module._movi_thumbnail_clear_buffer = A5.Wa, Module._movi_thumbnail_destroy = A5.Xa, p2 = A5._a, m2 = A5.$a, G2 = A5.ab, _2 = A5.bb, A5.cb, A5.db, A5.eb, A5.fb, A5.gb, A5.hb, A5.ib, A5.jb, A5.kb, A5.lb, A5.mb, A5.nb, A5.ob, A5.pb, A5.qb, A5.rb, A5.sb, A5.tb, A5.ub, A5.vb, A5.wb, A5.xb, A5.yb, A5.zb, A5.Ab, A5.Bb, A5.Cb, A5.Db, A5.Eb, A5.Fb, A5.Gb, A5.Hb, A5.Ib, A5.Jb, A5.Kb, A5.Lb, A5.Mb, A5.Nb, A5.Ob, A5.Pb, A5.Qb, A5.Rb, A5.Sb, A5.Tb, A5.Ub, A5.Vb, A5.Wb, A5.Xb, A5.Yb, A5.Zb, A5._b, A5.$b, A5.ac, J2 = A5.bc, h2 = A5.cc, N2 = A5.dc, g2 = A5.ec, I2 = A5.H, Module._ff_h264_cabac_tables = A5.Ya.value >>> 0, P2 = A5.Za;
2866
2866
  }(LA = function(A5) {
2867
2867
  var v5, r3 = (A6) => (v6) => A6(v6) >>> 0;
2868
2868
  return (A5 = Object.assign({}, A5)).ha = r3(A5.ha), A5.ab = r3(A5.ab), A5.bb = (v5 = A5.bb, () => v5() >>> 0), A5;
@@ -49091,11 +49091,11 @@ RR\vR\bR\x07R;\fR\rRR RSQR@#RRRRRRRRRR\x1BRRR(.RJ!LRR R!R"R
49091
49091
  F2 = A3, l2 = v3;
49092
49092
  });
49093
49093
  }
49094
- const a = "FFmpegLoader";
49094
+ const u = "FFmpegLoader";
49095
49095
  let o = null, x = null;
49096
49096
  async function q(A2 = {}) {
49097
49097
  return x || o || (o = (async () => {
49098
- r.info(a, "Loading WASM module...");
49098
+ r.info(u, "Loading WASM module...");
49099
49099
  const wasmBinary = A2.wasmBinary || null;
49100
49100
  try {
49101
49101
  const A3 = createMoviModule, v2 = { print: (A4) => {
@@ -49105,14 +49105,14 @@ async function q(A2 = {}) {
49105
49105
  } };
49106
49106
  wasmBinary && (v2.wasmBinary = wasmBinary);
49107
49107
  const j2 = await A3(v2);
49108
- return r.info(a, "WASM module loaded successfully"), j2.FS ? r.debug(a, "FS is present on module") : r.error(a, "FS is MISSING from module!"), x = j2, j2;
49108
+ return r.info(u, "WASM module loaded successfully"), j2.FS ? r.debug(u, "FS is present on module") : r.error(u, "FS is MISSING from module!"), x = j2, j2;
49109
49109
  } catch (A3) {
49110
- throw r.error(a, "Failed to load WASM module", A3), o = null, A3;
49110
+ throw r.error(u, "Failed to load WASM module", A3), o = null, A3;
49111
49111
  }
49112
49112
  })(), o);
49113
49113
  }
49114
49114
  async function B(A2 = {}) {
49115
- r.info(a, "Loading NEW WASM module instance (isolated)...");
49115
+ r.info(u, "Loading NEW WASM module instance (isolated)...");
49116
49116
  const wasmBinary = A2.wasmBinary || null;
49117
49117
  try {
49118
49118
  const A3 = createMoviModule, v2 = { print: (A4) => {
@@ -49122,9 +49122,9 @@ async function B(A2 = {}) {
49122
49122
  } };
49123
49123
  wasmBinary && (v2.wasmBinary = wasmBinary);
49124
49124
  const j2 = await A3(v2);
49125
- return r.info(a, "NEW WASM module instance loaded"), j2;
49125
+ return r.info(u, "NEW WASM module instance loaded"), j2;
49126
49126
  } catch (A3) {
49127
- throw r.error(a, "Failed to load new WASM module", A3), A3;
49127
+ throw r.error(u, "Failed to load new WASM module", A3), A3;
49128
49128
  }
49129
49129
  }
49130
49130
  function d() {
@@ -49134,7 +49134,7 @@ function d() {
49134
49134
  function $() {
49135
49135
  return null !== x;
49136
49136
  }
49137
- const H = "HttpSource", c = 2097152, p = 262144e3, m = 131072;
49137
+ const c = "HttpSource", H = 2097152, p = 262144e3, m = 131072;
49138
49138
  class HttpSource {
49139
49139
  url;
49140
49140
  headers;
@@ -49156,10 +49156,15 @@ class HttpSource {
49156
49156
  streamError = null;
49157
49157
  maxBufferedEnd = 0;
49158
49158
  fullyBuffered = false;
49159
+ rangeUnsupported = false;
49160
+ linearMode = false;
49161
+ onLinearMode = null;
49162
+ readMax = 0;
49163
+ recentReads = [];
49159
49164
  consecutiveForceRestarts = 0;
49160
49165
  lastForceRestartTime = 0;
49161
49166
  MAX_FORCE_RESTARTS = 3;
49162
- bufferSize = c;
49167
+ bufferSize = H;
49163
49168
  totalBytesDownloaded = 0;
49164
49169
  streamStartTime = 0;
49165
49170
  lastSpeedBytes = 0;
@@ -49170,7 +49175,7 @@ class HttpSource {
49170
49175
  this.url = A2, this.headers = v2, this.maxBufferSizeMB = r2 ?? 250, this.initBuffer();
49171
49176
  }
49172
49177
  initBuffer() {
49173
- this.bufferSize = c, this.resizeBuffer(this.bufferSize);
49178
+ this.bufferSize = H, this.resizeBuffer(this.bufferSize);
49174
49179
  }
49175
49180
  setMaxBufferSize(A2) {
49176
49181
  if (A2 > 0 && (this.maxBufferSizeMB = A2, this.size > 0)) {
@@ -49178,14 +49183,23 @@ class HttpSource {
49178
49183
  this.resizeBuffer(r2);
49179
49184
  }
49180
49185
  }
49186
+ setOnLinearMode(A2) {
49187
+ this.onLinearMode = A2, this.linearMode && A2();
49188
+ }
49189
+ isLinearMode() {
49190
+ return this.linearMode;
49191
+ }
49192
+ isRangeUnsupported() {
49193
+ return this.rangeUnsupported;
49194
+ }
49181
49195
  resizeBuffer(A2) {
49182
- const v2 = 1024 * this.maxBufferSizeMB * 1024, j2 = Math.max(c, Math.min(v2, A2));
49196
+ const v2 = 1024 * this.maxBufferSizeMB * 1024, j2 = Math.max(H, Math.min(v2, A2));
49183
49197
  if (this.bufferSize !== j2 || !this.sharedBuffer && !this.fallbackBuffer) {
49184
49198
  this.bufferSize = j2;
49185
49199
  try {
49186
- "undefined" != typeof SharedArrayBuffer && crossOriginIsolated ? (this.sharedBuffer = new SharedArrayBuffer(24 + this.bufferSize), this.headerView = new Int32Array(this.sharedBuffer, 0, 6), this.dataView = new Uint8Array(this.sharedBuffer, 24, this.bufferSize), this.useSharedBuffer = true, r.info(H, `Using SharedArrayBuffer for zero-copy streaming (${(this.bufferSize / 1024 / 1024).toFixed(2)} MB)`)) : (this.fallbackBuffer = new Uint8Array(this.bufferSize), r.info(H, `Using standard ArrayBuffer (${(this.bufferSize / 1024 / 1024).toFixed(2)} MB)`));
49200
+ "undefined" != typeof SharedArrayBuffer && crossOriginIsolated ? (this.sharedBuffer = new SharedArrayBuffer(24 + this.bufferSize), this.headerView = new Int32Array(this.sharedBuffer, 0, 6), this.dataView = new Uint8Array(this.sharedBuffer, 24, this.bufferSize), this.useSharedBuffer = true, r.info(c, `Using SharedArrayBuffer for zero-copy streaming (${(this.bufferSize / 1024 / 1024).toFixed(2)} MB)`)) : (this.fallbackBuffer = new Uint8Array(this.bufferSize), r.info(c, `Using standard ArrayBuffer (${(this.bufferSize / 1024 / 1024).toFixed(2)} MB)`));
49187
49201
  } catch {
49188
- this.fallbackBuffer = new Uint8Array(this.bufferSize), r.warn(H, `SharedArrayBuffer init failed, using fallback (${(this.bufferSize / 1024 / 1024).toFixed(2)} MB)`);
49202
+ this.fallbackBuffer = new Uint8Array(this.bufferSize), r.warn(c, `SharedArrayBuffer init failed, using fallback (${(this.bufferSize / 1024 / 1024).toFixed(2)} MB)`);
49189
49203
  }
49190
49204
  }
49191
49205
  }
@@ -49220,34 +49234,85 @@ class HttpSource {
49220
49234
  this.useSharedBuffer && this.headerView && Atomics.store(this.headerView, 3, 0);
49221
49235
  }
49222
49236
  async resolveSize() {
49223
- const A2 = await fetch(this.url, { method: "HEAD", headers: await this.buildRequestHeaders() });
49224
- if (!A2.ok) {
49225
- if (403 === A2.status) throw new Error("Access denied. Check video permissions.");
49226
- if (401 === A2.status) throw new Error("Authentication required.");
49227
- if (404 === A2.status) throw new Error("Video not found.");
49228
- throw new Error(`HTTP ${A2.status}`);
49237
+ let A2 = new Error("Content-Length missing");
49238
+ for (let v2 = 0; v2 < 4; v2++) {
49239
+ try {
49240
+ const v3 = await fetch(this.url, { method: "HEAD", headers: await this.buildRequestHeaders() });
49241
+ if (v3.ok) {
49242
+ this.setFilenameFromDisposition(v3.headers.get("Content-Disposition"));
49243
+ const r2 = v3.headers.get("Content-Length");
49244
+ if (r2) return parseInt(r2, 10);
49245
+ const j2 = await this.resolveSizeViaRange();
49246
+ if (null !== j2) return j2;
49247
+ const b2 = await this.resolveSizeViaPlainGet();
49248
+ if (null !== b2) return b2;
49249
+ A2 = new Error("Content-Length missing");
49250
+ } else {
49251
+ if (403 === v3.status) throw new Error("Access denied. Check video permissions.");
49252
+ if (401 === v3.status) throw new Error("Authentication required.");
49253
+ if (404 === v3.status) throw new Error("Video not found.");
49254
+ A2 = new Error(`HTTP ${v3.status}`);
49255
+ }
49256
+ } catch (v3) {
49257
+ if (/Access denied|Authentication required|Video not found/.test(v3?.message || "")) throw v3;
49258
+ A2 = v3 instanceof Error ? v3 : new Error(String(v3));
49259
+ }
49260
+ v2 < 3 && await new Promise((A3) => setTimeout(A3, 400 * (v2 + 1)));
49261
+ }
49262
+ throw A2;
49263
+ }
49264
+ async resolveSizeViaRange() {
49265
+ let A2;
49266
+ try {
49267
+ A2 = await fetch(this.url, { method: "GET", headers: await this.buildRequestHeaders({ offset: 0, length: 1 }) });
49268
+ } catch {
49269
+ return null;
49270
+ }
49271
+ if (A2.body?.cancel().catch(() => {
49272
+ }), !A2.ok && 206 !== A2.status) return null;
49273
+ const v2 = A2.headers.get("Content-Range");
49274
+ if (v2) {
49275
+ const A3 = /\/\s*(\d+)\s*$/.exec(v2);
49276
+ if (A3) return parseInt(A3[1], 10);
49277
+ }
49278
+ const r2 = A2.headers.get("Content-Length");
49279
+ return 200 === A2.status && r2 ? parseInt(r2, 10) : null;
49280
+ }
49281
+ async resolveSizeViaPlainGet() {
49282
+ let A2;
49283
+ try {
49284
+ A2 = await fetch(this.url, { method: "GET", headers: await this.buildRequestHeaders() });
49285
+ } catch {
49286
+ return null;
49229
49287
  }
49288
+ if (A2.body?.cancel().catch(() => {
49289
+ }), !A2.ok) return null;
49230
49290
  const v2 = A2.headers.get("Content-Length");
49231
- if (!v2) throw new Error("Content-Length missing");
49232
- const j2 = A2.headers.get("Content-Disposition");
49233
- if (j2) {
49234
- let A3 = j2.match(/filename\*\s*=\s*(?:UTF-8''|utf-8'')([^;]+)/i);
49235
- if (A3) try {
49236
- this._contentDispositionFilename = decodeURIComponent(A3[1].trim());
49291
+ if (200 === A2.status && v2) return parseInt(v2, 10);
49292
+ const r2 = A2.headers.get("Content-Range");
49293
+ if (r2) {
49294
+ const A3 = /\/\s*(\d+)\s*$/.exec(r2);
49295
+ if (A3) return parseInt(A3[1], 10);
49296
+ }
49297
+ return null;
49298
+ }
49299
+ setFilenameFromDisposition(A2) {
49300
+ if (!A2) return;
49301
+ let v2 = A2.match(/filename\*\s*=\s*(?:UTF-8''|utf-8'')([^;]+)/i);
49302
+ if (v2) try {
49303
+ this._contentDispositionFilename = decodeURIComponent(v2[1].trim());
49304
+ } catch {
49305
+ this._contentDispositionFilename = v2[1].trim();
49306
+ }
49307
+ if (!this._contentDispositionFilename && (v2 = A2.match(/filename\s*=\s*"([^"]+)"/i), v2 || (v2 = A2.match(/filename\s*=\s*([^;]+)/i)), v2)) {
49308
+ const A3 = v2[1].trim();
49309
+ try {
49310
+ this._contentDispositionFilename = decodeURIComponent(A3);
49237
49311
  } catch {
49238
- this._contentDispositionFilename = A3[1].trim();
49239
- }
49240
- if (!this._contentDispositionFilename && (A3 = j2.match(/filename\s*=\s*"([^"]+)"/i), A3 || (A3 = j2.match(/filename\s*=\s*([^;]+)/i)), A3)) {
49241
- const v3 = A3[1].trim();
49242
- try {
49243
- this._contentDispositionFilename = decodeURIComponent(v3);
49244
- } catch {
49245
- this._contentDispositionFilename = v3;
49246
- }
49312
+ this._contentDispositionFilename = A3;
49247
49313
  }
49248
- this._contentDispositionFilename && r.debug(H, `Content-Disposition filename: ${this._contentDispositionFilename}`);
49249
49314
  }
49250
- return parseInt(v2, 10);
49315
+ this._contentDispositionFilename && r.debug(c, `Content-Disposition filename: ${this._contentDispositionFilename}`);
49251
49316
  }
49252
49317
  async buildRequestHeaders(A2) {
49253
49318
  return A2 ? { ...this.headers, Range: `bytes=${A2.offset}-${A2.offset + A2.length - 1}` } : { ...this.headers };
@@ -49255,9 +49320,9 @@ class HttpSource {
49255
49320
  async getSize() {
49256
49321
  if (this.size >= 0) return this.size;
49257
49322
  try {
49258
- this.size = await this.resolveSize(), r.debug(H, `File size: ${this.size} bytes`);
49323
+ this.size = await this.resolveSize(), r.debug(c, `File size: ${this.size} bytes`);
49259
49324
  const A2 = 1024 * this.maxBufferSizeMB * 1024, v2 = this.size <= A2, j2 = v2 ? this.size : Math.floor(0.08 * this.size);
49260
- return this.resizeBuffer(j2), r.info(H, `Buffer: ${(this.bufferSize / 1024 / 1024).toFixed(1)}MB ${v2 ? "(full file cache)" : "(8% sliding window)"} for ${(this.size / 1024 / 1024).toFixed(1)}MB file`), this.size;
49325
+ return this.resizeBuffer(j2), r.info(c, `Buffer: ${(this.bufferSize / 1024 / 1024).toFixed(1)}MB ${v2 ? "(full file cache)" : "(8% sliding window)"} for ${(this.size / 1024 / 1024).toFixed(1)}MB file`), this.size;
49261
49326
  } catch (A2) {
49262
49327
  const v2 = A2.message || "";
49263
49328
  if ("TypeError" === A2.name && v2.includes("Failed to fetch") && !v2.includes("HTTP")) throw new Error("Failed to fetch video resource. Check your connection or CORS settings.");
@@ -49311,11 +49376,11 @@ class HttpSource {
49311
49376
  return f2.set(t2.subarray(E2, E2 + v2)), this.useSharedBuffer && this.headerView && r2 !== Atomics.load(this.headerView, 5) ? null : f2;
49312
49377
  }
49313
49378
  async startStream(A2) {
49314
- if (this.fullyBuffered) r.debug(H, `startStream(${A2}): skipped — file fully cached`);
49379
+ if (this.fullyBuffered) r.debug(c, `startStream(${A2}): skipped — file fully cached`);
49315
49380
  else {
49316
- if (await this.stopStream(), r.info(H, `Starting stream from ${A2}`), this.streamError = null, this.size > 0 && A2 >= this.size) return r.debug(H, "Requested stream at or past EOF. Ignoring."), this.atomicSetBufferStart(A2), this.atomicSetWritePos(0), void this.atomicSetStreaming(false);
49381
+ if (await this.stopStream(), r.info(c, `Starting stream from ${A2}`), this.streamError = null, this.size > 0 && A2 >= this.size) return r.debug(c, "Requested stream at or past EOF. Ignoring."), this.atomicSetBufferStart(A2), this.atomicSetWritePos(0), void this.atomicSetStreaming(false);
49317
49382
  this.atomicSetBufferStart(A2), this.atomicSetWritePos(0), this.atomicSetStreaming(true), this.atomicIncrementVersion(), this.fullyBuffered = false, this.maxBufferedEnd = A2, this.abortController = new AbortController(), this.readStreamBackground(A2).catch((A3) => {
49318
- r.error(H, "Background stream failed fatally", A3), this.atomicSetStreaming(false);
49383
+ r.error(c, "Background stream failed fatally", A3), this.atomicSetStreaming(false);
49319
49384
  });
49320
49385
  }
49321
49386
  }
@@ -49325,28 +49390,33 @@ class HttpSource {
49325
49390
  const f2 = this.getBuffer();
49326
49391
  let n2;
49327
49392
  if (n2 = j2 ? this.atomicGetBufferStart() + this.atomicGetWritePos() : A2, this.size > 0 && n2 >= this.size) {
49328
- r.debug(H, "Stream reached end of requested range (EOF)"), this.atomicSetStreaming(false);
49393
+ r.debug(c, "Stream reached end of requested range (EOF)"), this.atomicSetStreaming(false);
49329
49394
  break;
49330
49395
  }
49331
49396
  const F2 = this.size > 0 && this.bufferSize >= this.size ? this.size : Math.floor(Math.min(p, 0.9 * this.bufferSize)), l2 = this.size > 0 ? Math.min(n2 + F2 - 1, this.size - 1) : n2 + F2 - 1;
49332
- r.debug(H, `Fetching range: ${n2}-${l2} (max ${(F2 / 1024 / 1024).toFixed(1)}MB)`);
49397
+ r.debug(c, `Fetching range: ${n2}-${l2} (max ${(F2 / 1024 / 1024).toFixed(1)}MB)`);
49333
49398
  const k2 = await fetch(this.url, { headers: await this.buildRequestHeaders({ offset: n2, length: l2 - n2 + 1 }), cache: "no-store", signal: this.abortController.signal });
49334
49399
  if (200 === k2.status) {
49400
+ if (b2++, b2 <= 3) {
49401
+ try {
49402
+ k2.body?.cancel();
49403
+ } catch {
49404
+ }
49405
+ r.warn(c, `Server returned 200 instead of 206 (attempt ${b2}/3). CDN may be caching — retrying in 1500ms...`), await new Promise((A3) => setTimeout(A3, 1500));
49406
+ continue;
49407
+ }
49408
+ if (0 === A2) return r.warn(c, "No Range support after 3 retries — falling back to sequential playback."), void await this.consumeNonRangeStream(k2);
49335
49409
  try {
49336
49410
  k2.body?.cancel();
49337
49411
  } catch {
49338
49412
  }
49339
- if (b2++, b2 <= 3) {
49340
- r.warn(H, `Server returned 200 instead of 206 (attempt ${b2}/3). CDN may be caching — retrying in 1500ms...`), await new Promise((A4) => setTimeout(A4, 1500));
49341
- continue;
49342
- }
49343
- const A3 = new Error("Server does not support range requests.");
49344
- throw r.error(H, "Server returned 200 after 3 retries. Range requests not supported."), this.abortController?.abort(), this.atomicSetStreaming(false), this.streamError = A3, A3;
49413
+ const v3 = new Error("Server does not support range requests.");
49414
+ throw r.error(c, `Server returned 200 for offset ${A2}; range requests not supported.`), this.abortController?.abort(), this.atomicSetStreaming(false), this.streamError = v3, v3;
49345
49415
  }
49346
49416
  if (b2 = 0, !k2.ok && 206 !== k2.status) {
49347
49417
  if (k2.status >= 400 && k2.status < 500) {
49348
49418
  if (416 === k2.status) {
49349
- r.warn(H, "Range not satisfiable, assuming EOF"), this.atomicSetStreaming(false);
49419
+ r.warn(c, "Range not satisfiable, assuming EOF"), this.atomicSetStreaming(false);
49350
49420
  break;
49351
49421
  }
49352
49422
  throw new Error(`HTTP ${k2.status} (Fatal)`);
@@ -49354,9 +49424,9 @@ class HttpSource {
49354
49424
  throw new Error(`HTTP ${k2.status}`);
49355
49425
  }
49356
49426
  this.reader = k2.body.getReader(), v2 = 0, t2 = 0, j2 || (this.atomicSetBufferStart(A2), this.atomicSetWritePos(0), j2 = true);
49357
- let e2 = 0, s2 = 0;
49358
- const i2 = Date.now();
49359
- for (0 === this.streamStartTime && (this.streamStartTime = i2, this.lastSpeedTime = i2); this.atomicIsStreaming(); ) {
49427
+ let e2 = 0, i2 = 0;
49428
+ const s2 = Date.now();
49429
+ for (0 === this.streamStartTime && (this.streamStartTime = s2, this.lastSpeedTime = s2); this.atomicIsStreaming(); ) {
49360
49430
  const { done: A3, value: v3 } = await this.reader.read();
49361
49431
  if (A3) {
49362
49432
  this.atomicSetStreaming(false);
@@ -49369,13 +49439,13 @@ class HttpSource {
49369
49439
  const v4 = this.totalBytesDownloaded - this.lastSpeedBytes;
49370
49440
  this.currentSpeed = v4 / j3, this.lastSpeedBytes = this.totalBytesDownloaded, this.lastSpeedTime = A4;
49371
49441
  }
49372
- if (e2 - s2 > 1048576) {
49373
- const A5 = (Date.now() - i2) / 1e3, v4 = A5 > 0 ? e2 / 1024 / 1024 / A5 : 0;
49374
- r.debug(H, `Stream progress: ${(e2 / 1024 / 1024).toFixed(2)} MB read @ ${v4.toFixed(2)} MB/s`), s2 = e2;
49442
+ if (e2 - i2 > 1048576) {
49443
+ const A5 = (Date.now() - s2) / 1e3, v4 = A5 > 0 ? e2 / 1024 / 1024 / A5 : 0;
49444
+ r.debug(c, `Stream progress: ${(e2 / 1024 / 1024).toFixed(2)} MB read @ ${v4.toFixed(2)} MB/s`), i2 = e2;
49375
49445
  }
49376
49446
  let b3 = this.atomicGetWritePos();
49377
49447
  if (!(b3 + v3.length <= f2.length)) {
49378
- r.debug(H, "Buffer full, stopping stream"), this.atomicSetStreaming(false);
49448
+ r.debug(c, "Buffer full, stopping stream"), this.atomicSetStreaming(false);
49379
49449
  break;
49380
49450
  }
49381
49451
  {
@@ -49388,7 +49458,7 @@ class HttpSource {
49388
49458
  await new Promise((A6) => setTimeout(A6, 1));
49389
49459
  }
49390
49460
  if (!A5) {
49391
- r.error(H, "Failed to acquire lock for writing"), this.atomicSetStreaming(false);
49461
+ r.error(c, "Failed to acquire lock for writing"), this.atomicSetStreaming(false);
49392
49462
  break;
49393
49463
  }
49394
49464
  {
@@ -49403,16 +49473,16 @@ class HttpSource {
49403
49473
  if (b4 > 0.25 * this.bufferSize && this.size > 0 && j4 < this.size) {
49404
49474
  const j5 = Math.floor(b4);
49405
49475
  if (j5 > 0 && A6 > j5) {
49406
- f2.copyWithin(0, j5, A6), this.atomicSetBufferStart(v4 + j5), this.atomicSetWritePos(A6 - j5), E2 = v4 + j5, this.unlock(), r.debug(H, `Buffer compacted: reclaimed ${(j5 / 1024 / 1024).toFixed(1)}MB`);
49476
+ f2.copyWithin(0, j5, A6), this.atomicSetBufferStart(v4 + j5), this.atomicSetWritePos(A6 - j5), E2 = v4 + j5, this.unlock(), r.debug(c, `Buffer compacted: reclaimed ${(j5 / 1024 / 1024).toFixed(1)}MB`);
49407
49477
  break;
49408
49478
  }
49409
49479
  }
49410
- this.unlock(), r.debug(H, `Downloaded ${(n3 / 1024 / 1024).toFixed(1)}MB (${l3 ? "limit reached" : "buffer full"}), stopping stream`), this.atomicSetStreaming(false);
49480
+ this.unlock(), r.debug(c, `Downloaded ${(n3 / 1024 / 1024).toFixed(1)}MB (${l3 ? "limit reached" : "buffer full"}), stopping stream`), this.atomicSetStreaming(false);
49411
49481
  break;
49412
49482
  }
49413
49483
  if (this.unlock(), this.size > 0 && j4 >= this.size) {
49414
49484
  const A7 = this.atomicGetBufferStart();
49415
- 0 === A7 && this.bufferSize >= this.size && (this.fullyBuffered = true, r.info(H, `Entire file cached in memory (${(this.size / 1024 / 1024).toFixed(1)}MB)`)), r.debug(H, `Reached EOF (bufferStart=${A7}, bufferEnd=${j4}), stopping stream`), this.atomicSetStreaming(false);
49485
+ 0 === A7 && this.bufferSize >= this.size && (this.fullyBuffered = true, r.info(c, `Entire file cached in memory (${(this.size / 1024 / 1024).toFixed(1)}MB)`)), r.debug(c, `Reached EOF (bufferStart=${A7}, bufferEnd=${j4}), stopping stream`), this.atomicSetStreaming(false);
49416
49486
  break;
49417
49487
  }
49418
49488
  }
@@ -49431,32 +49501,32 @@ class HttpSource {
49431
49501
  else {
49432
49502
  if (t2++, t2 >= 3) {
49433
49503
  const A4 = new Error("Failed to fetch video resource. Check your connection or CORS settings.");
49434
- throw r.error(H, `CORS error accessing ${this.url} (${t2} consecutive failures while online)`), this.atomicSetStreaming(false), this.streamError = A4, A4;
49504
+ throw r.error(c, `CORS error accessing ${this.url} (${t2} consecutive failures while online)`), this.atomicSetStreaming(false), this.streamError = A4, A4;
49435
49505
  }
49436
- r.warn(H, `Fetch failed while online (${t2}/3), may be transient network issue`);
49506
+ r.warn(c, `Fetch failed while online (${t2}/3), may be transient network issue`);
49437
49507
  }
49438
- if (A3.message && A3.message.includes("does not support range requests")) throw r.error(H, "Range requests not supported, cannot stream this URL"), this.atomicSetStreaming(false), A3;
49508
+ if (A3.message && A3.message.includes("does not support range requests")) throw r.error(c, "Range requests not supported, cannot stream this URL"), this.atomicSetStreaming(false), A3;
49439
49509
  const f2 = A3?.message || "";
49440
49510
  if (f2.includes("(Fatal)")) {
49441
- r.error(H, `Fatal HTTP error, not retrying: ${f2}`), this.atomicSetStreaming(false), this.streamError = A3 instanceof Error ? A3 : new Error(f2);
49511
+ r.error(c, `Fatal HTTP error, not retrying: ${f2}`), this.atomicSetStreaming(false), this.streamError = A3 instanceof Error ? A3 : new Error(f2);
49442
49512
  break;
49443
49513
  }
49444
- r.warn(H, "Stream error, retrying...", A3);
49514
+ r.warn(c, "Stream error, retrying...", A3);
49445
49515
  try {
49446
49516
  this.reader && await this.reader.cancel();
49447
49517
  } catch {
49448
49518
  }
49449
49519
  if (this.reader = null, "undefined" != typeof self && self.navigator && !self.navigator.onLine) {
49450
- r.warn(H, "Network offline, waiting for connection...");
49520
+ r.warn(c, "Network offline, waiting for connection...");
49451
49521
  const A4 = this.abortController?.signal;
49452
49522
  if (await new Promise((v3) => {
49453
49523
  let j4 = false;
49454
49524
  const b4 = () => {
49455
49525
  j4 || (j4 = true, clearTimeout(t3), "undefined" != typeof self && self.removeEventListener("online", E4), A4?.removeEventListener("abort", f3), v3());
49456
49526
  }, t3 = setTimeout(() => {
49457
- r.warn(H, "Offline wait timeout, retrying anyway..."), b4();
49527
+ r.warn(c, "Offline wait timeout, retrying anyway..."), b4();
49458
49528
  }, 3e4), E4 = () => {
49459
- r.info(H, "Network online, resuming..."), b4();
49529
+ r.info(c, "Network online, resuming..."), b4();
49460
49530
  }, f3 = () => b4();
49461
49531
  "undefined" != typeof self && self.addEventListener("online", E4), A4?.addEventListener("abort", f3);
49462
49532
  }), !this.atomicIsStreaming()) break;
@@ -49464,7 +49534,7 @@ class HttpSource {
49464
49534
  continue;
49465
49535
  }
49466
49536
  if (v2++, v2 > 10) {
49467
- r.error(H, "Max retries (10) reached, giving up."), this.atomicSetStreaming(false), this.streamError = A3 instanceof Error ? A3 : new Error("string" == typeof A3 ? A3 : "Stream failed after maximum retries");
49537
+ r.error(c, "Max retries (10) reached, giving up."), this.atomicSetStreaming(false), this.streamError = A3 instanceof Error ? A3 : new Error("string" == typeof A3 ? A3 : "Stream failed after maximum retries");
49468
49538
  break;
49469
49539
  }
49470
49540
  const n2 = Math.min(1e3 * Math.pow(1.5, v2), 1e4), F2 = this.abortController?.signal;
@@ -49473,7 +49543,7 @@ class HttpSource {
49473
49543
  const b4 = () => {
49474
49544
  j4 || (j4 = true, clearTimeout(E4), "undefined" != typeof self && self.removeEventListener("online", f3), F2?.removeEventListener("abort", l2), A4());
49475
49545
  }, E4 = setTimeout(b4, n2), f3 = () => {
49476
- r.info(H, "Online event during backoff — retrying immediately"), v2 = 0, t2 = 0, b4();
49546
+ r.info(c, "Online event during backoff — retrying immediately"), v2 = 0, t2 = 0, b4();
49477
49547
  }, l2 = () => b4();
49478
49548
  "undefined" != typeof self && self.addEventListener && self.addEventListener("online", f3), F2?.addEventListener("abort", l2);
49479
49549
  });
@@ -49486,6 +49556,87 @@ class HttpSource {
49486
49556
  this.reader = null;
49487
49557
  }
49488
49558
  }
49559
+ async consumeNonRangeStream(A2) {
49560
+ if (this.rangeUnsupported = true, this.size > 0) {
49561
+ const A3 = this.useSharedBuffer && this.headerView ? Atomics.load(this.headerView, 5) : 0;
49562
+ this.resizeBuffer(this.size), this.useSharedBuffer && this.headerView && Atomics.store(this.headerView, 5, A3);
49563
+ }
49564
+ const v2 = this.getBuffer(), j2 = this.size > 0 && this.bufferSize >= this.size;
49565
+ if (j2) r.info(c, `Caching entire ${(this.size / 1048576).toFixed(1)}MB file in memory (no Range support).`);
49566
+ else {
49567
+ this.linearMode = true, r.warn(c, `Linear (non-seekable) playback: ${this.size > 0 ? (this.size / 1048576).toFixed(0) + "MB" : "unknown size"} exceeds the ${this.maxBufferSizeMB}MB cache cap or size is unknown.`);
49568
+ try {
49569
+ this.onLinearMode?.();
49570
+ } catch {
49571
+ }
49572
+ }
49573
+ if (this.atomicSetBufferStart(0), this.atomicSetWritePos(0), this.maxBufferedEnd = 0, this.fullyBuffered = false, this.atomicSetStreaming(true), !A2.body) return this.streamError = new Error("Empty response body"), void this.atomicSetStreaming(false);
49574
+ const b2 = A2.body.getReader();
49575
+ this.reader = b2;
49576
+ try {
49577
+ for (; this.atomicIsStreaming(); ) {
49578
+ const { done: A3, value: r2 } = await b2.read();
49579
+ if (A3) break;
49580
+ r2 && 0 !== r2.length && (this.totalBytesDownloaded += r2.length, await this.writeSequential(r2, v2, j2));
49581
+ }
49582
+ } catch (A3) {
49583
+ "AbortError" !== A3?.name && (this.streamError = A3 instanceof Error ? A3 : new Error(String(A3)), r.error(c, "Non-range stream failed", A3));
49584
+ } finally {
49585
+ try {
49586
+ await b2.cancel();
49587
+ } catch {
49588
+ }
49589
+ this.reader = null;
49590
+ }
49591
+ const t2 = this.atomicGetBufferStart() + this.atomicGetWritePos();
49592
+ this.size <= 0 && (this.size = t2), j2 && 0 === this.atomicGetBufferStart() && this.size > 0 && t2 >= this.size && (this.fullyBuffered = true, r.info(c, `Entire file cached (${(this.size / 1048576).toFixed(1)}MB) — full random access.`)), this.atomicSetStreaming(false);
49593
+ }
49594
+ async writeSequential(A2, v2, r2) {
49595
+ let j2 = 0;
49596
+ for (; j2 < A2.length; ) {
49597
+ if (!this.atomicIsStreaming()) return;
49598
+ let b2 = this.atomicGetWritePos();
49599
+ if (b2 >= v2.length) {
49600
+ if (r2) return;
49601
+ if (!await this.slideWindow(v2)) {
49602
+ await new Promise((A3) => setTimeout(A3, 5));
49603
+ continue;
49604
+ }
49605
+ b2 = this.atomicGetWritePos();
49606
+ }
49607
+ const t2 = v2.length - b2, E2 = Math.min(t2, A2.length - j2);
49608
+ let f2 = false;
49609
+ for (let A3 = 0; A3 < 50; A3++) {
49610
+ if (this.tryLock()) {
49611
+ f2 = true;
49612
+ break;
49613
+ }
49614
+ await new Promise((A4) => setTimeout(A4, 1));
49615
+ }
49616
+ if (!f2) {
49617
+ await new Promise((A3) => setTimeout(A3, 5));
49618
+ continue;
49619
+ }
49620
+ v2.set(A2.subarray(j2, j2 + E2), b2);
49621
+ const n2 = b2 + E2;
49622
+ this.atomicSetWritePos(n2);
49623
+ const F2 = this.atomicGetBufferStart() + n2;
49624
+ F2 > this.maxBufferedEnd && (this.maxBufferedEnd = F2), this.unlock(), j2 += E2;
49625
+ }
49626
+ }
49627
+ async slideWindow(A2) {
49628
+ const v2 = this.atomicGetBufferStart(), r2 = this.atomicGetWritePos(), j2 = Math.floor(this.bufferSize / 2), b2 = this.recentReads.length ? Math.min(...this.recentReads) : this.readMax, t2 = Math.max(0, Math.min(b2, this.readMax - j2)), E2 = Math.min(t2 - v2, r2);
49629
+ if (E2 <= 0) return false;
49630
+ let f2 = false;
49631
+ for (let A3 = 0; A3 < 50; A3++) {
49632
+ if (this.tryLock()) {
49633
+ f2 = true;
49634
+ break;
49635
+ }
49636
+ await new Promise((A4) => setTimeout(A4, 1));
49637
+ }
49638
+ return !!f2 && (A2.copyWithin(0, E2, r2), this.atomicSetBufferStart(v2 + E2), this.atomicSetWritePos(r2 - E2), this.unlock(), true);
49639
+ }
49489
49640
  async stopStream() {
49490
49641
  if (this.atomicSetStreaming(false), this.abortController && (this.abortController.abort(), this.abortController = null), this.reader) {
49491
49642
  try {
@@ -49506,9 +49657,9 @@ class HttpSource {
49506
49657
  const v3 = Date.now();
49507
49658
  this.bufferEnd > n2 && (n2 = this.bufferEnd, F2 = v3, v3 - b2 > 0.8 * j2 && (t2 = v3 + 15e3));
49508
49659
  const l3 = v3 - F2;
49509
- if (l3 > 15e3) return r.error(H, `Stream stalled: no progress for ${(l3 / 1e3).toFixed(1)}s at ${A2}, needed ${E2}, currently ${this.bufferEnd}`), false;
49510
- if (v3 > t2) return r.error(H, `Timeout waiting for data at ${A2}, needed ${E2}, currently ${this.bufferEnd}`), false;
49511
- if (this.useSharedBuffer && this.headerView && Atomics.load(this.headerView, 5) !== f2) return r.warn(H, `Stream superseded while waiting for ${A2}`), false;
49660
+ if (l3 > 15e3) return r.error(c, `Stream stalled: no progress for ${(l3 / 1e3).toFixed(1)}s at ${A2}, needed ${E2}, currently ${this.bufferEnd}`), false;
49661
+ if (v3 > t2) return r.error(c, `Timeout waiting for data at ${A2}, needed ${E2}, currently ${this.bufferEnd}`), false;
49662
+ if (this.useSharedBuffer && this.headerView && Atomics.load(this.headerView, 5) !== f2) return r.warn(c, `Stream superseded while waiting for ${A2}`), false;
49512
49663
  this.useSharedBuffer && this.headerView ? await new Promise((A3) => setTimeout(A3, 2)) : await new Promise((A3) => setTimeout(A3, 10));
49513
49664
  }
49514
49665
  const l2 = this.bufferEnd >= E2;
@@ -49516,39 +49667,47 @@ class HttpSource {
49516
49667
  if (!l2 && !this.atomicIsStreaming()) {
49517
49668
  if (this.size > 0 && this.bufferEnd >= this.size) return true;
49518
49669
  if (this.bufferEnd >= E2) return true;
49519
- r.warn(H, `Stream ended before reaching needed offset ${E2} (current end: ${this.bufferEnd})`);
49670
+ r.warn(c, `Stream ended before reaching needed offset ${E2} (current end: ${this.bufferEnd})`);
49520
49671
  }
49521
49672
  return l2;
49522
49673
  }
49523
49674
  async read(A2, v2) {
49524
49675
  const j2 = this.peekMetadata(A2, v2);
49525
- if (j2) return this.position = A2 + v2, r.debug(H, "Read: served from metadata LRU"), j2.buffer;
49676
+ if (j2) return this.position = A2 + v2, r.debug(c, "Read: served from metadata LRU"), j2.buffer;
49526
49677
  const b2 = await this._readInternal(A2, v2);
49527
49678
  return b2.byteLength > 0 && b2.byteLength <= m && this.cacheMetadataRead(A2, new Uint8Array(b2)), b2;
49528
49679
  }
49529
49680
  async _readInternal(A2, v2) {
49530
- if (r.debug(H, `Read: offset=${A2}, length=${v2}, bufferStart=${this.atomicGetBufferStart()}, bufferEnd=${this.bufferEnd}, streaming=${this.atomicIsStreaming()}`), this.size > 0 && A2 >= this.size) return r.debug(H, "Read: returning empty (EOF)"), new ArrayBuffer(0);
49531
- if (this.fullyBuffered && A2 >= this.atomicGetBufferStart() && A2 < this.bufferEnd) return this.consecutiveForceRestarts = 0, r.debug(H, "Read: served from full-file cache"), this.readFromBuffer(A2, v2);
49681
+ if (r.debug(c, `Read: offset=${A2}, length=${v2}, bufferStart=${this.atomicGetBufferStart()}, bufferEnd=${this.bufferEnd}, streaming=${this.atomicIsStreaming()}`), this.size > 0 && A2 >= this.size) return r.debug(c, "Read: returning empty (EOF)"), new ArrayBuffer(0);
49682
+ if (this.fullyBuffered && A2 >= this.atomicGetBufferStart() && A2 < this.bufferEnd) return this.consecutiveForceRestarts = 0, r.debug(c, "Read: served from full-file cache"), this.readFromBuffer(A2, v2);
49532
49683
  if (this.headBuffer && A2 + v2 <= this.headBuffer.length) {
49533
49684
  const j3 = new Uint8Array(v2);
49534
- return j3.set(this.headBuffer.subarray(A2, A2 + v2)), this.position = A2 + v2, r.debug(H, "Read: served from head cache"), j3.buffer;
49685
+ return j3.set(this.headBuffer.subarray(A2, A2 + v2)), this.position = A2 + v2, r.debug(c, "Read: served from head cache"), j3.buffer;
49686
+ }
49687
+ if (this.isInBuffer(A2, v2)) return this.consecutiveForceRestarts = 0, r.debug(c, "Read: serving from buffer"), this.readFromBuffer(A2, v2);
49688
+ if (this.rangeUnsupported) {
49689
+ if (A2 < this.atomicGetBufferStart()) throw new Error("Server does not support range requests.");
49690
+ if (this.linearMode && A2 + v2 > this.atomicGetBufferStart() + this.bufferSize) throw new Error("Server does not support range requests.");
49691
+ if (this.atomicIsStreaming() && await this.waitForData(A2, v2)) return this.readFromBuffer(A2, v2);
49692
+ if (this.isInBuffer(A2, v2)) return this.readFromBuffer(A2, v2);
49693
+ if (this.streamError) throw this.streamError;
49694
+ throw new Error("Server does not support range requests.");
49535
49695
  }
49536
- if (this.isInBuffer(A2, v2)) return this.consecutiveForceRestarts = 0, r.debug(H, "Read: serving from buffer"), this.readFromBuffer(A2, v2);
49537
49696
  const j2 = this.atomicGetBufferStart(), b2 = A2 - this.bufferEnd, t2 = 2097152, E2 = this.atomicIsStreaming() && A2 >= j2 && A2 < j2 + this.bufferSize && b2 <= t2;
49538
- if (r.debug(H, `Read: isCoveredByStream=${E2}, gap=${(b2 / 1024).toFixed(0)}KB`), E2) {
49539
- r.debug(H, "Read: waiting for data from active stream...");
49697
+ if (r.debug(c, `Read: isCoveredByStream=${E2}, gap=${(b2 / 1024).toFixed(0)}KB`), E2) {
49698
+ r.debug(c, "Read: waiting for data from active stream...");
49540
49699
  const j3 = await this.waitForData(A2, v2);
49541
- if (r.debug(H, `Read: waitForData returned ${j3}`), j3) return this.consecutiveForceRestarts = 0, this.readFromBuffer(A2, v2);
49700
+ if (r.debug(c, `Read: waitForData returned ${j3}`), j3) return this.consecutiveForceRestarts = 0, this.readFromBuffer(A2, v2);
49542
49701
  if (this.atomicIsStreaming()) {
49543
49702
  if (this.isInBuffer(A2, v2)) return this.readFromBuffer(A2, v2);
49544
49703
  const j4 = Date.now();
49545
- if (j4 - this.lastForceRestartTime > 5e3 && (this.consecutiveForceRestarts = 0), this.consecutiveForceRestarts >= this.MAX_FORCE_RESTARTS) throw r.error(H, `Too many consecutive force restarts (${this.consecutiveForceRestarts}), giving up.`), new Error(`Stream failed after ${this.consecutiveForceRestarts} restart attempts`);
49704
+ if (j4 - this.lastForceRestartTime > 5e3 && (this.consecutiveForceRestarts = 0), this.consecutiveForceRestarts >= this.MAX_FORCE_RESTARTS) throw r.error(c, `Too many consecutive force restarts (${this.consecutiveForceRestarts}), giving up.`), new Error(`Stream failed after ${this.consecutiveForceRestarts} restart attempts`);
49546
49705
  const b3 = Math.min(100 * Math.pow(2, this.consecutiveForceRestarts), 500);
49547
- r.warn(H, `Read timeout for ${A2} but stream is active. Force restarting after ${b3}ms (attempt ${this.consecutiveForceRestarts + 1}/${this.MAX_FORCE_RESTARTS}).`), await new Promise((A3) => setTimeout(A3, b3)), this.consecutiveForceRestarts++, this.lastForceRestartTime = j4;
49706
+ r.warn(c, `Read timeout for ${A2} but stream is active. Force restarting after ${b3}ms (attempt ${this.consecutiveForceRestarts + 1}/${this.MAX_FORCE_RESTARTS}).`), await new Promise((A3) => setTimeout(A3, b3)), this.consecutiveForceRestarts++, this.lastForceRestartTime = j4;
49548
49707
  }
49549
49708
  }
49550
49709
  if (this.size > 0 && this.bufferSize >= this.size && this.atomicIsStreaming() && b2 > t2) {
49551
- r.info(H, `Read: one-off range fetch for offset=${A2}, length=${v2} (gap=${(b2 / 1024).toFixed(0)}KB, main stream continues)`);
49710
+ r.info(c, `Read: one-off range fetch for offset=${A2}, length=${v2} (gap=${(b2 / 1024).toFixed(0)}KB, main stream continues)`);
49552
49711
  try {
49553
49712
  const r2 = Math.min(A2 + v2 - 1, this.size - 1) - A2 + 1, j3 = await fetch(this.url, { headers: await this.buildRequestHeaders({ offset: A2, length: r2 }) });
49554
49713
  if (j3.ok || 206 === j3.status) {
@@ -49558,17 +49717,17 @@ class HttpSource {
49558
49717
  return E3.set(r3), this.position = A2 + r3.length, this.consecutiveForceRestarts = 0, E3.buffer;
49559
49718
  }
49560
49719
  } catch (A3) {
49561
- r.warn(H, "One-off range fetch failed, falling back to stream restart", A3);
49720
+ r.warn(c, "One-off range fetch failed, falling back to stream restart", A3);
49562
49721
  }
49563
49722
  }
49564
- r.debug(H, `Read: starting new stream from ${A2}`), await this.startStream(A2), r.debug(H, "Read: waiting for data...");
49723
+ r.debug(c, `Read: starting new stream from ${A2}`), await this.startStream(A2), r.debug(c, "Read: waiting for data...");
49565
49724
  const f2 = await this.waitForData(A2, v2);
49566
- if (r.debug(H, `Read: waitForData returned ${f2}`), !f2) throw new Error(`Timeout at ${A2}`);
49725
+ if (r.debug(c, `Read: waitForData returned ${f2}`), !f2) throw new Error(`Timeout at ${A2}`);
49567
49726
  return this.consecutiveForceRestarts = 0, this.readFromBuffer(A2, v2);
49568
49727
  }
49569
49728
  readFromBuffer(A2, v2) {
49570
49729
  const r2 = this.getBuffer(), j2 = A2 - this.atomicGetBufferStart(), b2 = Math.min(v2, this.bufferEnd - A2), t2 = new Uint8Array(b2);
49571
- return t2.set(r2.subarray(j2, j2 + b2)), this.position = A2 + b2, t2.buffer;
49730
+ return t2.set(r2.subarray(j2, j2 + b2)), this.position = A2 + b2, this.position > this.readMax && (this.readMax = this.position), this.recentReads.push(A2), this.recentReads.length > 64 && this.recentReads.shift(), t2.buffer;
49572
49731
  }
49573
49732
  seek(A2) {
49574
49733
  return this.position = A2, this.position;
@@ -49580,7 +49739,7 @@ class HttpSource {
49580
49739
  return this.sharedBuffer;
49581
49740
  }
49582
49741
  close() {
49583
- this.stopStream(), r.debug(H, "Source closed");
49742
+ this.stopStream(), r.debug(c, "Source closed");
49584
49743
  }
49585
49744
  getKey() {
49586
49745
  return this.url;
@@ -49842,6 +50001,7 @@ class ThumbnailHttpSource {
49842
50001
  size = -1;
49843
50002
  position = 0;
49844
50003
  abortController = null;
50004
+ rangeUnsupported = false;
49845
50005
  buffer = null;
49846
50006
  bufferStart = 0;
49847
50007
  bufferEnd = 0;
@@ -49852,13 +50012,38 @@ class ThumbnailHttpSource {
49852
50012
  setBorrowSource(A2) {
49853
50013
  this.borrowSource = A2;
49854
50014
  }
50015
+ seedSize(A2) {
50016
+ A2 > 0 && (this.size = A2);
50017
+ }
49855
50018
  async getSize() {
49856
50019
  if (this.size >= 0) return this.size;
49857
50020
  const A2 = await fetch(this.url, { method: "HEAD", headers: this.headers });
49858
50021
  if (!A2.ok) throw new Error(`HTTP ${A2.status}`);
49859
50022
  const v2 = A2.headers.get("Content-Length");
49860
- if (!v2) throw new Error("Content-Length missing");
49861
- return this.size = parseInt(v2, 10), r.debug(g, `File size: ${this.size} bytes`), this.size;
50023
+ if (v2) this.size = parseInt(v2, 10);
50024
+ else {
50025
+ const A3 = await this.resolveSizeViaRange();
50026
+ if (null === A3) throw new Error("Content-Length missing");
50027
+ this.size = A3;
50028
+ }
50029
+ return r.debug(g, `File size: ${this.size} bytes`), this.size;
50030
+ }
50031
+ async resolveSizeViaRange() {
50032
+ let A2;
50033
+ try {
50034
+ A2 = await fetch(this.url, { method: "GET", headers: { ...this.headers, Range: "bytes=0-0" } });
50035
+ } catch {
50036
+ return null;
50037
+ }
50038
+ if (A2.body?.cancel().catch(() => {
50039
+ }), !A2.ok && 206 !== A2.status) return null;
50040
+ const v2 = A2.headers.get("Content-Range");
50041
+ if (v2) {
50042
+ const A3 = /\/\s*(\d+)\s*$/.exec(v2);
50043
+ if (A3) return parseInt(A3[1], 10);
50044
+ }
50045
+ const r2 = A2.headers.get("Content-Length");
50046
+ return 200 === A2.status && r2 ? parseInt(r2, 10) : null;
49862
50047
  }
49863
50048
  isInBuffer(A2, v2) {
49864
50049
  return null !== this.buffer && A2 >= this.bufferStart && A2 + v2 <= this.bufferEnd;
@@ -49875,6 +50060,7 @@ class ThumbnailHttpSource {
49875
50060
  const b3 = this.borrowSource.peekRange(A2, v2);
49876
50061
  if (b3) return this.position = A2 + v2, r.debug(g, `Read borrowed from main window: offset=${A2}, length=${v2}`), b3.buffer;
49877
50062
  }
50063
+ if (this.rangeUnsupported) return new ArrayBuffer(0);
49878
50064
  const j2 = A2, b2 = Math.min(Math.max(2097152, v2), 5242880), t2 = this.size > 0 ? Math.min(j2 + b2 - 1, this.size - 1) : j2 + b2 - 1;
49879
50065
  r.debug(g, `Fetching: range=${j2}-${t2} (${((t2 - j2 + 1) / 1024).toFixed(1)} KB)`);
49880
50066
  for (let b3 = 0; b3 <= 5; b3++) {
@@ -49887,7 +50073,7 @@ class ThumbnailHttpSource {
49887
50073
  const E2 = new AbortController(), f2 = setTimeout(() => E2.abort(), 1e4);
49888
50074
  try {
49889
50075
  const b4 = await fetch(this.url, { headers: { ...this.headers, Range: `bytes=${j2}-${t2}` }, cache: "no-store", signal: E2.signal });
49890
- if (clearTimeout(f2), 200 === b4.status) throw r.error(g, "Server returned 200 instead of 206. Range requests not supported."), E2.abort(), new Error("Server does not support range requests.");
50076
+ if (clearTimeout(f2), 200 === b4.status) return r.info(g, "Server returned 200 (no Range support) thumbnails switch to borrow-only."), E2.abort(), this.rangeUnsupported = true, new ArrayBuffer(0);
49891
50077
  if (!b4.ok && 206 !== b4.status) {
49892
50078
  if (416 === b4.status) return r.warn(g, `HTTP 416 (Range Not Satisfiable) at ${j2}-${t2}. Treating as EOF.`), new ArrayBuffer(0);
49893
50079
  throw b4.status >= 500 || 429 === b4.status ? new Error(`HTTP ${b4.status}`) : new Error(`HTTP ${b4.status} (Fatal)`);