avbridge 2.2.1 → 2.3.0

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 (119) hide show
  1. package/CHANGELOG.md +80 -1
  2. package/NOTICE.md +2 -2
  3. package/README.md +2 -3
  4. package/THIRD_PARTY_LICENSES.md +2 -2
  5. package/dist/avi-2JPBSHGA.js +183 -0
  6. package/dist/avi-2JPBSHGA.js.map +1 -0
  7. package/dist/avi-F6WZJK5T.cjs +185 -0
  8. package/dist/avi-F6WZJK5T.cjs.map +1 -0
  9. package/dist/{avi-GCGM7OJI.js → avi-NJXAXUXK.js} +9 -3
  10. package/dist/avi-NJXAXUXK.js.map +1 -0
  11. package/dist/{avi-6SJLWIWW.cjs → avi-W6L3BTWU.cjs} +10 -4
  12. package/dist/avi-W6L3BTWU.cjs.map +1 -0
  13. package/dist/{chunk-ILKDNBSE.js → chunk-2PGRFCWB.js} +59 -10
  14. package/dist/chunk-2PGRFCWB.js.map +1 -0
  15. package/dist/chunk-5YAWWKA3.js +18 -0
  16. package/dist/chunk-5YAWWKA3.js.map +1 -0
  17. package/dist/chunk-6UUT4BEA.cjs +219 -0
  18. package/dist/chunk-6UUT4BEA.cjs.map +1 -0
  19. package/dist/{chunk-UF2N5L63.cjs → chunk-7RGG6ME7.cjs} +489 -76
  20. package/dist/chunk-7RGG6ME7.cjs.map +1 -0
  21. package/dist/{chunk-WD2ZNQA7.js → chunk-DCSOQH2N.js} +7 -4
  22. package/dist/chunk-DCSOQH2N.js.map +1 -0
  23. package/dist/chunk-F3LQJKXK.cjs +20 -0
  24. package/dist/chunk-F3LQJKXK.cjs.map +1 -0
  25. package/dist/chunk-IAYKFGFG.js +200 -0
  26. package/dist/chunk-IAYKFGFG.js.map +1 -0
  27. package/dist/chunk-NNVOHKXJ.cjs +204 -0
  28. package/dist/chunk-NNVOHKXJ.cjs.map +1 -0
  29. package/dist/{chunk-DMWARSEF.js → chunk-NV7ILLWH.js} +483 -74
  30. package/dist/chunk-NV7ILLWH.js.map +1 -0
  31. package/dist/{chunk-HZLQNKFN.cjs → chunk-QQXBPW72.js} +54 -15
  32. package/dist/chunk-QQXBPW72.js.map +1 -0
  33. package/dist/chunk-XKPSTC34.cjs +210 -0
  34. package/dist/chunk-XKPSTC34.cjs.map +1 -0
  35. package/dist/{chunk-L4NPOJ36.cjs → chunk-Z33SBWL5.cjs} +7 -4
  36. package/dist/chunk-Z33SBWL5.cjs.map +1 -0
  37. package/dist/element-browser.js +558 -85
  38. package/dist/element-browser.js.map +1 -1
  39. package/dist/element.cjs +4 -4
  40. package/dist/element.d.cts +1 -1
  41. package/dist/element.d.ts +1 -1
  42. package/dist/element.js +3 -3
  43. package/dist/index.cjs +174 -26
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.cts +48 -4
  46. package/dist/index.d.ts +48 -4
  47. package/dist/index.js +93 -12
  48. package/dist/index.js.map +1 -1
  49. package/dist/libav-http-reader-AZLE7YFS.cjs +16 -0
  50. package/dist/{libav-http-reader-FPYDBMYK.cjs.map → libav-http-reader-AZLE7YFS.cjs.map} +1 -1
  51. package/dist/libav-http-reader-WXG3Z7AI.js +3 -0
  52. package/dist/{libav-http-reader-NQJVY273.js.map → libav-http-reader-WXG3Z7AI.js.map} +1 -1
  53. package/dist/{player-U2NPmFvA.d.cts → player-B6WB74RD.d.cts} +62 -3
  54. package/dist/{player-U2NPmFvA.d.ts → player-B6WB74RD.d.ts} +62 -3
  55. package/dist/player.cjs +5500 -0
  56. package/dist/player.cjs.map +1 -0
  57. package/dist/player.d.cts +649 -0
  58. package/dist/player.d.ts +649 -0
  59. package/dist/player.js +5498 -0
  60. package/dist/player.js.map +1 -0
  61. package/dist/source-73CAH6HW.cjs +28 -0
  62. package/dist/{source-CN43EI7Z.cjs.map → source-73CAH6HW.cjs.map} +1 -1
  63. package/dist/source-F656KYYV.js +3 -0
  64. package/dist/{source-FFZ7TW2B.js.map → source-F656KYYV.js.map} +1 -1
  65. package/dist/source-QJR3OHTW.js +3 -0
  66. package/dist/source-QJR3OHTW.js.map +1 -0
  67. package/dist/source-VB74JQ7Z.cjs +28 -0
  68. package/dist/source-VB74JQ7Z.cjs.map +1 -0
  69. package/dist/variant-routing-434STYAB.js +3 -0
  70. package/dist/{variant-routing-JOBWXYKD.js.map → variant-routing-434STYAB.js.map} +1 -1
  71. package/dist/variant-routing-HONNAA6R.cjs +12 -0
  72. package/dist/{variant-routing-GOHB2RZN.cjs.map → variant-routing-HONNAA6R.cjs.map} +1 -1
  73. package/package.json +9 -1
  74. package/src/classify/rules.ts +27 -5
  75. package/src/convert/remux.ts +8 -0
  76. package/src/convert/transcode.ts +41 -8
  77. package/src/element/avbridge-player.ts +845 -0
  78. package/src/element/player-icons.ts +25 -0
  79. package/src/element/player-styles.ts +472 -0
  80. package/src/errors.ts +47 -0
  81. package/src/index.ts +23 -0
  82. package/src/player-element.ts +18 -0
  83. package/src/player.ts +104 -12
  84. package/src/plugins/builtin.ts +2 -2
  85. package/src/probe/avi.ts +4 -0
  86. package/src/probe/index.ts +40 -10
  87. package/src/strategies/fallback/audio-output.ts +31 -0
  88. package/src/strategies/fallback/decoder.ts +83 -2
  89. package/src/strategies/fallback/index.ts +29 -4
  90. package/src/strategies/fallback/variant-routing.ts +7 -13
  91. package/src/strategies/fallback/video-renderer.ts +124 -32
  92. package/src/strategies/hybrid/decoder.ts +131 -20
  93. package/src/strategies/hybrid/index.ts +31 -5
  94. package/src/strategies/remux/mse.ts +12 -2
  95. package/src/subtitles/index.ts +7 -3
  96. package/src/types.ts +53 -1
  97. package/src/util/libav-http-reader.ts +5 -1
  98. package/src/util/source.ts +28 -8
  99. package/src/util/transport.ts +26 -0
  100. package/vendor/libav/avbridge/libav-6.8.8.0-avbridge.wasm.mjs +1 -1
  101. package/vendor/libav/avbridge/libav-6.8.8.0-avbridge.wasm.wasm +0 -0
  102. package/dist/avi-6SJLWIWW.cjs.map +0 -1
  103. package/dist/avi-GCGM7OJI.js.map +0 -1
  104. package/dist/chunk-DMWARSEF.js.map +0 -1
  105. package/dist/chunk-HZLQNKFN.cjs.map +0 -1
  106. package/dist/chunk-ILKDNBSE.js.map +0 -1
  107. package/dist/chunk-J5MCMN3S.js +0 -27
  108. package/dist/chunk-J5MCMN3S.js.map +0 -1
  109. package/dist/chunk-L4NPOJ36.cjs.map +0 -1
  110. package/dist/chunk-NZU7W256.cjs +0 -29
  111. package/dist/chunk-NZU7W256.cjs.map +0 -1
  112. package/dist/chunk-UF2N5L63.cjs.map +0 -1
  113. package/dist/chunk-WD2ZNQA7.js.map +0 -1
  114. package/dist/libav-http-reader-FPYDBMYK.cjs +0 -16
  115. package/dist/libav-http-reader-NQJVY273.js +0 -3
  116. package/dist/source-CN43EI7Z.cjs +0 -28
  117. package/dist/source-FFZ7TW2B.js +0 -3
  118. package/dist/variant-routing-GOHB2RZN.cjs +0 -12
  119. package/dist/variant-routing-JOBWXYKD.js +0 -3
@@ -1,4 +1,38 @@
1
- 'use strict';
1
+ // src/util/transport.ts
2
+ function mergeFetchInit(base, extra) {
3
+ if (!base && !extra) return void 0;
4
+ return {
5
+ ...base,
6
+ ...extra,
7
+ headers: {
8
+ ...base?.headers ?? {},
9
+ ...extra?.headers ?? {}
10
+ }
11
+ };
12
+ }
13
+ function fetchWith(transport) {
14
+ return transport?.fetchFn ?? globalThis.fetch;
15
+ }
16
+
17
+ // src/errors.ts
18
+ var AvbridgeError = class extends Error {
19
+ constructor(code, message, recovery, options) {
20
+ super(message, options);
21
+ this.code = code;
22
+ this.recovery = recovery;
23
+ }
24
+ code;
25
+ recovery;
26
+ name = "AvbridgeError";
27
+ };
28
+ var ERR_PROBE_FAILED = "ERR_AVBRIDGE_PROBE_FAILED";
29
+ var ERR_PROBE_UNKNOWN_CONTAINER = "ERR_AVBRIDGE_PROBE_UNKNOWN_CONTAINER";
30
+ var ERR_PROBE_FETCH_FAILED = "ERR_AVBRIDGE_PROBE_FETCH_FAILED";
31
+ var ERR_ALL_STRATEGIES_EXHAUSTED = "ERR_AVBRIDGE_ALL_STRATEGIES_EXHAUSTED";
32
+ var ERR_PLAYER_NOT_READY = "ERR_AVBRIDGE_PLAYER_NOT_READY";
33
+ var ERR_LIBAV_NOT_REACHABLE = "ERR_AVBRIDGE_LIBAV_NOT_REACHABLE";
34
+ var ERR_MSE_NOT_SUPPORTED = "ERR_AVBRIDGE_MSE_NOT_SUPPORTED";
35
+ var ERR_MSE_CODEC_NOT_SUPPORTED = "ERR_AVBRIDGE_MSE_CODEC_NOT_SUPPORTED";
2
36
 
3
37
  // src/util/source.ts
4
38
  var SNIFF_BYTES_NEEDED = 380;
@@ -6,7 +40,7 @@ var URL_SNIFF_RANGE_BYTES = 32 * 1024;
6
40
  function isInMemorySource(source) {
7
41
  return source.kind === "blob";
8
42
  }
9
- async function normalizeSource(source) {
43
+ async function normalizeSource(source, transport) {
10
44
  if (source instanceof File) {
11
45
  return {
12
46
  kind: "blob",
@@ -29,22 +63,31 @@ async function normalizeSource(source) {
29
63
  }
30
64
  if (typeof source === "string" || source instanceof URL) {
31
65
  const url = source instanceof URL ? source.toString() : source;
32
- return await fetchUrlForSniff(url, source);
66
+ return await fetchUrlForSniff(url, source, transport);
33
67
  }
34
68
  throw new TypeError("unsupported source type");
35
69
  }
36
- async function fetchUrlForSniff(url, originalSource) {
70
+ async function fetchUrlForSniff(url, originalSource, transport) {
37
71
  const name = url.split("/").pop()?.split("?")[0] ?? void 0;
72
+ const doFetch = fetchWith(transport);
38
73
  let res;
39
74
  try {
40
- res = await fetch(url, {
75
+ res = await doFetch(url, mergeFetchInit(transport?.requestInit, {
41
76
  headers: { Range: `bytes=0-${URL_SNIFF_RANGE_BYTES - 1}` }
42
- });
77
+ }));
43
78
  } catch (err) {
44
- throw new Error(`failed to fetch source ${url}: ${err.message}`);
79
+ throw new AvbridgeError(
80
+ ERR_PROBE_FETCH_FAILED,
81
+ `Failed to fetch source ${url}: ${err.message}`,
82
+ "Check that the URL is reachable and CORS is configured. If the source requires authentication, pass requestInit with credentials/headers."
83
+ );
45
84
  }
46
85
  if (!res.ok && res.status !== 206) {
47
- throw new Error(`failed to fetch source ${url}: ${res.status} ${res.statusText}`);
86
+ throw new AvbridgeError(
87
+ ERR_PROBE_FETCH_FAILED,
88
+ `Failed to fetch source ${url}: ${res.status} ${res.statusText}`,
89
+ res.status === 403 || res.status === 401 ? "The server rejected the request. Pass requestInit with the required Authorization header or credentials." : "Check that the URL is correct and the server is reachable."
90
+ );
48
91
  }
49
92
  let byteLength;
50
93
  const contentRange = res.headers.get("content-range");
@@ -147,10 +190,6 @@ async function readBlobBytes(blob, limit) {
147
190
  });
148
191
  }
149
192
 
150
- exports.isInMemorySource = isInMemorySource;
151
- exports.normalizeSource = normalizeSource;
152
- exports.sniffContainer = sniffContainer;
153
- exports.sniffContainerFromBytes = sniffContainerFromBytes;
154
- exports.sniffNormalizedSource = sniffNormalizedSource;
155
- //# sourceMappingURL=chunk-HZLQNKFN.cjs.map
156
- //# sourceMappingURL=chunk-HZLQNKFN.cjs.map
193
+ export { AvbridgeError, ERR_ALL_STRATEGIES_EXHAUSTED, ERR_LIBAV_NOT_REACHABLE, ERR_MSE_CODEC_NOT_SUPPORTED, ERR_MSE_NOT_SUPPORTED, ERR_PLAYER_NOT_READY, ERR_PROBE_FAILED, ERR_PROBE_UNKNOWN_CONTAINER, fetchWith, isInMemorySource, normalizeSource, sniffContainer, sniffContainerFromBytes, sniffNormalizedSource };
194
+ //# sourceMappingURL=chunk-QQXBPW72.js.map
195
+ //# sourceMappingURL=chunk-QQXBPW72.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util/transport.ts","../src/errors.ts","../src/util/source.ts"],"names":["sniffBytes"],"mappings":";AAOO,SAAS,cAAA,CACd,MACA,KAAA,EACyB;AACzB,EAAA,IAAI,CAAC,IAAA,IAAQ,CAAC,KAAA,EAAO,OAAO,MAAA;AAC5B,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,GAAG,KAAA;AAAA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C5F,EAAA,IAAI,MAAA,CAAO,SAAS,KAAA,EAAO;AACzB,IAAA,OAAO,uBAAA,CAAwB,OAAO,UAAU,CAAA;AAAA,EAClD;AACA,EAAA,MAAM,GAAA,GAAM,MAAM,aAAA,CAAc,MAAA,CAAO,MAAM,kBAAkB,CAAA;AAC/D,EAAA,OAAO,uBAAA,CAAwB,IAAI,UAAA,CAAW,GAAG,CAAC,CAAA;AACpD;AAMA,eAAsB,eAAe,IAAA,EAAoC;AACvE,EAAA,MAAM,GAAA,GAAM,MAAM,aAAA,CAAc,IAAA,EAAM,kBAAkB,CAAA;AACxD,EAAA,OAAO,uBAAA,CAAwB,IAAI,UAAA,CAAW,GAAG,CAAC,CAAA;AACpD;AAMA,eAAe,aAAA,CAAc,MAAY,KAAA,EAAqC;AAC5E,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA;AACjC,EAAA,IAAI,OAAQ,KAAA,CAA8D,WAAA,KAAgB,UAAA,EAAY;AACpG,IAAA,IAAI;AACF,MAAA,OAAO,MAAO,MAA6D,WAAA,EAAY;AAAA,IACzF,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACA,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACtC,IAAA,MAAM,MAAA,GAAS,IAAI,UAAA,EAAW;AAC9B,IAAA,MAAA,CAAO,MAAA,GAAS,MAAM,OAAA,CAAQ,MAAA,CAAO,MAAqB,CAAA;AAC1D,IAAA,MAAA,CAAO,OAAA,GAAU,MAAM,MAAA,CAAO,MAAA,CAAO,SAAS,IAAI,KAAA,CAAM,mBAAmB,CAAC,CAAA;AAC5E,IAAA,MAAA,CAAO,kBAAkB,KAAK,CAAA;AAAA,EAChC,CAAC,CAAA;AACH","file":"chunk-QQXBPW72.js","sourcesContent":["import type { FetchFn, TransportConfig } from \"../types.js\";\n\n/**\n * Merge two RequestInit objects. Headers are merged (not overwritten) so\n * the caller's auth headers coexist with the player's Range headers.\n * Other fields (credentials, mode, signal, etc.) in `extra` override `base`.\n */\nexport function mergeFetchInit(\n base: RequestInit | undefined,\n extra: RequestInit | undefined,\n): RequestInit | undefined {\n if (!base && !extra) return undefined;\n return {\n ...base,\n ...extra,\n headers: {\n ...(base?.headers as Record<string, string> | undefined ?? {}),\n ...(extra?.headers as Record<string, string> | undefined ?? {}),\n },\n };\n}\n\n/** Return the fetch function from a TransportConfig, falling back to globalThis.fetch. */\nexport function fetchWith(transport?: TransportConfig): FetchFn {\n return transport?.fetchFn ?? globalThis.fetch;\n}\n","/**\n * Structured error with a machine-readable code and human-readable\n * recovery hint. Consumers can switch on `error.code` for programmatic\n * handling and show `error.recovery` in UI.\n *\n * All codes use the `ERR_AVBRIDGE_` prefix to avoid collisions.\n */\nexport class AvbridgeError extends Error {\n override name = \"AvbridgeError\";\n\n constructor(\n /** Machine-readable error code. */\n public readonly code: string,\n message: string,\n /** Human-readable recovery suggestion. */\n public readonly recovery?: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n }\n}\n\n// ── Error codes ────────────────────────────────────────────────────────\n\n// Probe\nexport const ERR_PROBE_FAILED = \"ERR_AVBRIDGE_PROBE_FAILED\";\nexport const ERR_PROBE_UNKNOWN_CONTAINER = \"ERR_AVBRIDGE_PROBE_UNKNOWN_CONTAINER\";\nexport const ERR_PROBE_FETCH_FAILED = \"ERR_AVBRIDGE_PROBE_FETCH_FAILED\";\n\n// Codec / strategy\nexport const ERR_CODEC_NOT_SUPPORTED = \"ERR_AVBRIDGE_CODEC_NOT_SUPPORTED\";\nexport const ERR_STRATEGY_FAILED = \"ERR_AVBRIDGE_STRATEGY_FAILED\";\nexport const ERR_ALL_STRATEGIES_EXHAUSTED = \"ERR_AVBRIDGE_ALL_STRATEGIES_EXHAUSTED\";\n\n// Player lifecycle\nexport const ERR_PLAYER_NOT_READY = \"ERR_AVBRIDGE_PLAYER_NOT_READY\";\n\n// Transport / network\nexport const ERR_RANGE_NOT_SUPPORTED = \"ERR_AVBRIDGE_RANGE_NOT_SUPPORTED\";\nexport const ERR_FETCH_FAILED = \"ERR_AVBRIDGE_FETCH_FAILED\";\n\n// libav\nexport const ERR_LIBAV_NOT_REACHABLE = \"ERR_AVBRIDGE_LIBAV_NOT_REACHABLE\";\n\n// MSE\nexport const ERR_MSE_NOT_SUPPORTED = \"ERR_AVBRIDGE_MSE_NOT_SUPPORTED\";\nexport const ERR_MSE_CODEC_NOT_SUPPORTED = \"ERR_AVBRIDGE_MSE_CODEC_NOT_SUPPORTED\";\n","import type { ContainerKind, MediaInput, TransportConfig } from \"../types.js\";\nimport { mergeFetchInit, fetchWith } from \"./transport.js\";\nimport { AvbridgeError, ERR_PROBE_FETCH_FAILED } from \"../errors.js\";\n\n/**\n * Bytes needed by the sniffer to identify every container we recognize.\n * MPEG-TS needs the most: a sync byte at offset 0 *and* offset 188 (one TS\n * packet apart). Allow a little extra for the M2TS variant (offset 4/192).\n */\nconst SNIFF_BYTES_NEEDED = 380;\n\n/**\n * Bytes to fetch from a URL during the initial sniff. We grab a slightly\n * larger range than `SNIFF_BYTES_NEEDED` so the cache has some headroom for\n * the demuxer's first read after sniffing, in case it wants to look at\n * a few extra bytes (e.g. mp4 ftyp + first moov box).\n */\nconst URL_SNIFF_RANGE_BYTES = 32 * 1024;\n\n/**\n * `NormalizedSource` is a discriminated union: every consumer (probe,\n * strategies) decides what to do based on `kind`. URL sources are NOT\n * fetched eagerly; we only do a Range request for the first ~32 KB so the\n * sniffer has bytes to look at. The strategies are then handed the URL\n * directly so they can stream the rest via Range requests.\n *\n * For File / Blob / ArrayBuffer / Uint8Array sources, the bytes are\n * already in memory, so we wrap them as a `blob` variant.\n */\nexport type NormalizedSource =\n | {\n kind: \"blob\";\n blob: Blob;\n name?: string;\n byteLength: number;\n original: MediaInput;\n }\n | {\n kind: \"url\";\n url: string;\n /** Bytes pulled via Range request for the sniffer. NOT the full file. */\n sniffBytes: Uint8Array;\n name?: string;\n /** Total file size from Content-Length / Content-Range. May be undefined. */\n byteLength: number | undefined;\n original: MediaInput;\n };\n\n/** True if this source carries the entire file's bytes (vs. streaming). */\nexport function isInMemorySource(source: NormalizedSource): source is Extract<NormalizedSource, { kind: \"blob\" }> {\n return source.kind === \"blob\";\n}\n\n\n/**\n * Normalize a `MediaInput` for the probe + strategy layers. **Does not**\n * download URL sources in full — only fetches the first ~32 KB via a\n * Range request, which is enough for the sniffer to identify the\n * container. The strategies are then expected to stream the rest via\n * mediabunny's `UrlSource` (Range requests, prefetch, parallelism, cache).\n *\n * For non-URL inputs, the bytes are already in memory and we just wrap them.\n */\nexport async function normalizeSource(\n source: MediaInput,\n transport?: TransportConfig,\n): Promise<NormalizedSource> {\n if (source instanceof File) {\n return {\n kind: \"blob\",\n blob: source,\n name: source.name,\n byteLength: source.size,\n original: source,\n };\n }\n if (source instanceof Blob) {\n return { kind: \"blob\", blob: source, byteLength: source.size, original: source };\n }\n if (source instanceof ArrayBuffer) {\n const blob = new Blob([source]);\n return { kind: \"blob\", blob, byteLength: blob.size, original: source };\n }\n if (source instanceof Uint8Array) {\n const blob = new Blob([source as BlobPart]);\n return { kind: \"blob\", blob, byteLength: blob.size, original: source };\n }\n if (typeof source === \"string\" || source instanceof URL) {\n const url = source instanceof URL ? source.toString() : source;\n return await fetchUrlForSniff(url, source, transport);\n }\n throw new TypeError(\"unsupported source type\");\n}\n\n/**\n * Fetch the first ~32 KB of a URL via a Range request. Falls back to a\n * full GET if the server doesn't support range requests, but in that case\n * we only read the first 32 KB and abort the rest of the response so we\n * don't accidentally buffer a large file.\n */\nasync function fetchUrlForSniff(\n url: string,\n originalSource: MediaInput,\n transport?: TransportConfig,\n): Promise<NormalizedSource> {\n const name = url.split(\"/\").pop()?.split(\"?\")[0] ?? undefined;\n const doFetch = fetchWith(transport);\n\n // First attempt: Range request for the sniff window.\n let res: Response;\n try {\n res = await doFetch(url, mergeFetchInit(transport?.requestInit, {\n headers: { Range: `bytes=0-${URL_SNIFF_RANGE_BYTES - 1}` },\n })!);\n } catch (err) {\n throw new AvbridgeError(\n ERR_PROBE_FETCH_FAILED,\n `Failed to fetch source ${url}: ${(err as Error).message}`,\n \"Check that the URL is reachable and CORS is configured. If the source requires authentication, pass requestInit with credentials/headers.\",\n );\n }\n if (!res.ok && res.status !== 206) {\n throw new AvbridgeError(\n ERR_PROBE_FETCH_FAILED,\n `Failed to fetch source ${url}: ${res.status} ${res.statusText}`,\n res.status === 403 || res.status === 401\n ? \"The server rejected the request. Pass requestInit with the required Authorization header or credentials.\"\n : \"Check that the URL is correct and the server is reachable.\",\n );\n }\n\n // Determine the total file size from Content-Range (preferred) or Content-Length.\n let byteLength: number | undefined;\n const contentRange = res.headers.get(\"content-range\");\n if (contentRange) {\n // \"bytes 0-32767/12345678\" — parse the part after the slash\n const m = contentRange.match(/\\/(\\d+)$/);\n if (m) byteLength = parseInt(m[1], 10);\n }\n if (byteLength === undefined) {\n const cl = res.headers.get(\"content-length\");\n if (cl) {\n const n = parseInt(cl, 10);\n if (Number.isFinite(n)) {\n // If the server returned 200 (full body), Content-Length is the\n // FILE size. If 206 (partial), it's the chunk size — only use it\n // as a total if no Content-Range was present (server doesn't do\n // ranges) AND the full response is smaller than our sniff window.\n if (res.status === 200) byteLength = n;\n else if (res.status === 206 && !contentRange) byteLength = n;\n }\n }\n }\n\n // Read the sniff bytes. If the server ignored the Range header and is\n // streaming the full file, only read the first window and let the rest\n // be GC'd. We use a reader so we can stop early.\n const reader = res.body?.getReader();\n if (!reader) {\n // No streamed body (some test environments). Fall back to .arrayBuffer()\n // and slice — this might pull more than we wanted, but only for the\n // initial sniff, not the full file.\n const buf = new Uint8Array(await res.arrayBuffer());\n const sniffBytes = buf.slice(0, URL_SNIFF_RANGE_BYTES);\n return { kind: \"url\", url, sniffBytes, name, byteLength, original: originalSource };\n }\n\n const chunks: Uint8Array[] = [];\n let collected = 0;\n while (collected < URL_SNIFF_RANGE_BYTES) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n collected += value.byteLength;\n }\n // Cancel the response so we don't keep downloading.\n await reader.cancel().catch(() => { /* ignore */ });\n\n // Concatenate up to URL_SNIFF_RANGE_BYTES.\n const total = Math.min(collected, URL_SNIFF_RANGE_BYTES);\n const sniffBytes = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n if (offset >= total) break;\n const room = total - offset;\n sniffBytes.set(chunk.subarray(0, Math.min(chunk.byteLength, room)), offset);\n offset += chunk.byteLength;\n }\n\n return { kind: \"url\", url, sniffBytes, name, byteLength, original: originalSource };\n}\n\n/**\n * Identify the container family from a small byte buffer. Used by the\n * probe layer for both file (Blob → first 380 bytes) and URL (Range\n * request → first 32 KB) inputs.\n *\n * Sniffing intentionally does not trust file extensions.\n */\nexport function sniffContainerFromBytes(head: Uint8Array): ContainerKind {\n // MPEG-TS: sync byte 0x47 every 188 bytes. Verify at least two sync\n // bytes in the right places to avoid false positives. Some captures\n // start with a few junk bytes — also try offsets 4 and 192 (M2TS).\n if (head.length >= 376 && head[0] === 0x47 && head[188] === 0x47) {\n return \"mpegts\";\n }\n if (head.length >= 380 && head[4] === 0x47 && head[192] === 0x47) {\n return \"mpegts\"; // M2TS — 4-byte timestamp prefix per packet\n }\n // RIFF....AVI → AVI\n if (\n head[0] === 0x52 && head[1] === 0x49 && head[2] === 0x46 && head[3] === 0x46 &&\n head[8] === 0x41 && head[9] === 0x56 && head[10] === 0x49\n ) return \"avi\";\n // RIFF....WAVE → WAV\n if (\n head[0] === 0x52 && head[1] === 0x49 && head[2] === 0x46 && head[3] === 0x46 &&\n head[8] === 0x57 && head[9] === 0x41 && head[10] === 0x56 && head[11] === 0x45\n ) return \"wav\";\n // EBML start: 1A 45 DF A3 → MKV/WebM. Distinguish later via DocType.\n if (head[0] === 0x1a && head[1] === 0x45 && head[2] === 0xdf && head[3] === 0xa3) {\n return \"mkv\";\n }\n // ftyp at offset 4 → MP4 family\n if (head[4] === 0x66 && head[5] === 0x74 && head[6] === 0x79 && head[7] === 0x70) {\n // brand at bytes 8..11\n const brand = String.fromCharCode(head[8], head[9], head[10], head[11]);\n if (brand.startsWith(\"qt\")) return \"mov\";\n return \"mp4\";\n }\n // ASF / WMV: 30 26 B2 75 8E 66 CF 11\n if (\n head[0] === 0x30 && head[1] === 0x26 && head[2] === 0xb2 && head[3] === 0x75 &&\n head[4] === 0x8e && head[5] === 0x66 && head[6] === 0xcf && head[7] === 0x11\n ) return \"asf\";\n // FLV: 46 4C 56\n if (head[0] === 0x46 && head[1] === 0x4c && head[2] === 0x56) return \"flv\";\n // RealMedia (.rm / .rmvb): \".RMF\" — 2E 52 4D 46\n if (head[0] === 0x2e && head[1] === 0x52 && head[2] === 0x4d && head[3] === 0x46) {\n return \"rm\";\n }\n // OggS: 4F 67 67 53\n if (head[0] === 0x4f && head[1] === 0x67 && head[2] === 0x67 && head[3] === 0x53) return \"ogg\";\n // FLAC: 66 4C 61 43\n if (head[0] === 0x66 && head[1] === 0x4c && head[2] === 0x61 && head[3] === 0x43) return \"flac\";\n // ID3v2: 49 44 33 → MP3 (with id3)\n if (head[0] === 0x49 && head[1] === 0x44 && head[2] === 0x33) return \"mp3\";\n // MPEG audio frame sync: FF Fx\n if (head[0] === 0xff && (head[1] & 0xe0) === 0xe0) {\n // ADTS: FF F1 / FF F9\n if ((head[1] & 0xf6) === 0xf0) return \"adts\";\n return \"mp3\";\n }\n return \"unknown\";\n}\n\n/**\n * Convenience: sniff a `NormalizedSource` regardless of kind. For URL\n * sources, uses the pre-fetched `sniffBytes`. For blob sources, reads the\n * first 380 bytes.\n */\nexport async function sniffNormalizedSource(source: NormalizedSource): Promise<ContainerKind> {\n if (source.kind === \"url\") {\n return sniffContainerFromBytes(source.sniffBytes);\n }\n const buf = await readBlobBytes(source.blob, SNIFF_BYTES_NEEDED);\n return sniffContainerFromBytes(new Uint8Array(buf));\n}\n\n/**\n * Backwards-compatible wrapper for code that still passes a Blob directly.\n * Prefer `sniffNormalizedSource` going forward.\n */\nexport async function sniffContainer(blob: Blob): Promise<ContainerKind> {\n const buf = await readBlobBytes(blob, SNIFF_BYTES_NEEDED);\n return sniffContainerFromBytes(new Uint8Array(buf));\n}\n\n/**\n * Read up to `limit` bytes from a Blob. Tries `Blob.arrayBuffer()` first\n * (modern browsers), then falls back to `FileReader` (works under jsdom).\n */\nasync function readBlobBytes(blob: Blob, limit: number): Promise<ArrayBuffer> {\n const slice = blob.slice(0, limit);\n if (typeof (slice as Blob & { arrayBuffer?: () => Promise<ArrayBuffer> }).arrayBuffer === \"function\") {\n try {\n return await (slice as Blob & { arrayBuffer: () => Promise<ArrayBuffer> }).arrayBuffer();\n } catch {\n /* fall through to FileReader */\n }\n }\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => resolve(reader.result as ArrayBuffer);\n reader.onerror = () => reject(reader.error ?? new Error(\"FileReader failed\"));\n reader.readAsArrayBuffer(slice);\n });\n}\n"]}
@@ -0,0 +1,210 @@
1
+ 'use strict';
2
+
3
+ // src/util/transport.ts
4
+ function mergeFetchInit(base, extra) {
5
+ if (!base && !extra) return void 0;
6
+ return {
7
+ ...base,
8
+ ...extra,
9
+ headers: {
10
+ ...base?.headers ?? {},
11
+ ...extra?.headers ?? {}
12
+ }
13
+ };
14
+ }
15
+ function fetchWith(transport) {
16
+ return transport?.fetchFn ?? globalThis.fetch;
17
+ }
18
+
19
+ // src/errors.ts
20
+ var AvbridgeError = class extends Error {
21
+ constructor(code, message, recovery, options) {
22
+ super(message, options);
23
+ this.code = code;
24
+ this.recovery = recovery;
25
+ }
26
+ code;
27
+ recovery;
28
+ name = "AvbridgeError";
29
+ };
30
+ var ERR_PROBE_FAILED = "ERR_AVBRIDGE_PROBE_FAILED";
31
+ var ERR_PROBE_UNKNOWN_CONTAINER = "ERR_AVBRIDGE_PROBE_UNKNOWN_CONTAINER";
32
+ var ERR_PROBE_FETCH_FAILED = "ERR_AVBRIDGE_PROBE_FETCH_FAILED";
33
+ var ERR_ALL_STRATEGIES_EXHAUSTED = "ERR_AVBRIDGE_ALL_STRATEGIES_EXHAUSTED";
34
+ var ERR_PLAYER_NOT_READY = "ERR_AVBRIDGE_PLAYER_NOT_READY";
35
+ var ERR_LIBAV_NOT_REACHABLE = "ERR_AVBRIDGE_LIBAV_NOT_REACHABLE";
36
+ var ERR_MSE_NOT_SUPPORTED = "ERR_AVBRIDGE_MSE_NOT_SUPPORTED";
37
+ var ERR_MSE_CODEC_NOT_SUPPORTED = "ERR_AVBRIDGE_MSE_CODEC_NOT_SUPPORTED";
38
+
39
+ // src/util/source.ts
40
+ var SNIFF_BYTES_NEEDED = 380;
41
+ var URL_SNIFF_RANGE_BYTES = 32 * 1024;
42
+ function isInMemorySource(source) {
43
+ return source.kind === "blob";
44
+ }
45
+ async function normalizeSource(source, transport) {
46
+ if (source instanceof File) {
47
+ return {
48
+ kind: "blob",
49
+ blob: source,
50
+ name: source.name,
51
+ byteLength: source.size,
52
+ original: source
53
+ };
54
+ }
55
+ if (source instanceof Blob) {
56
+ return { kind: "blob", blob: source, byteLength: source.size, original: source };
57
+ }
58
+ if (source instanceof ArrayBuffer) {
59
+ const blob = new Blob([source]);
60
+ return { kind: "blob", blob, byteLength: blob.size, original: source };
61
+ }
62
+ if (source instanceof Uint8Array) {
63
+ const blob = new Blob([source]);
64
+ return { kind: "blob", blob, byteLength: blob.size, original: source };
65
+ }
66
+ if (typeof source === "string" || source instanceof URL) {
67
+ const url = source instanceof URL ? source.toString() : source;
68
+ return await fetchUrlForSniff(url, source, transport);
69
+ }
70
+ throw new TypeError("unsupported source type");
71
+ }
72
+ async function fetchUrlForSniff(url, originalSource, transport) {
73
+ const name = url.split("/").pop()?.split("?")[0] ?? void 0;
74
+ const doFetch = fetchWith(transport);
75
+ let res;
76
+ try {
77
+ res = await doFetch(url, mergeFetchInit(transport?.requestInit, {
78
+ headers: { Range: `bytes=0-${URL_SNIFF_RANGE_BYTES - 1}` }
79
+ }));
80
+ } catch (err) {
81
+ throw new AvbridgeError(
82
+ ERR_PROBE_FETCH_FAILED,
83
+ `Failed to fetch source ${url}: ${err.message}`,
84
+ "Check that the URL is reachable and CORS is configured. If the source requires authentication, pass requestInit with credentials/headers."
85
+ );
86
+ }
87
+ if (!res.ok && res.status !== 206) {
88
+ throw new AvbridgeError(
89
+ ERR_PROBE_FETCH_FAILED,
90
+ `Failed to fetch source ${url}: ${res.status} ${res.statusText}`,
91
+ res.status === 403 || res.status === 401 ? "The server rejected the request. Pass requestInit with the required Authorization header or credentials." : "Check that the URL is correct and the server is reachable."
92
+ );
93
+ }
94
+ let byteLength;
95
+ const contentRange = res.headers.get("content-range");
96
+ if (contentRange) {
97
+ const m = contentRange.match(/\/(\d+)$/);
98
+ if (m) byteLength = parseInt(m[1], 10);
99
+ }
100
+ if (byteLength === void 0) {
101
+ const cl = res.headers.get("content-length");
102
+ if (cl) {
103
+ const n = parseInt(cl, 10);
104
+ if (Number.isFinite(n)) {
105
+ if (res.status === 200) byteLength = n;
106
+ else if (res.status === 206 && !contentRange) byteLength = n;
107
+ }
108
+ }
109
+ }
110
+ const reader = res.body?.getReader();
111
+ if (!reader) {
112
+ const buf = new Uint8Array(await res.arrayBuffer());
113
+ const sniffBytes2 = buf.slice(0, URL_SNIFF_RANGE_BYTES);
114
+ return { kind: "url", url, sniffBytes: sniffBytes2, name, byteLength, original: originalSource };
115
+ }
116
+ const chunks = [];
117
+ let collected = 0;
118
+ while (collected < URL_SNIFF_RANGE_BYTES) {
119
+ const { done, value } = await reader.read();
120
+ if (done) break;
121
+ chunks.push(value);
122
+ collected += value.byteLength;
123
+ }
124
+ await reader.cancel().catch(() => {
125
+ });
126
+ const total = Math.min(collected, URL_SNIFF_RANGE_BYTES);
127
+ const sniffBytes = new Uint8Array(total);
128
+ let offset = 0;
129
+ for (const chunk of chunks) {
130
+ if (offset >= total) break;
131
+ const room = total - offset;
132
+ sniffBytes.set(chunk.subarray(0, Math.min(chunk.byteLength, room)), offset);
133
+ offset += chunk.byteLength;
134
+ }
135
+ return { kind: "url", url, sniffBytes, name, byteLength, original: originalSource };
136
+ }
137
+ function sniffContainerFromBytes(head) {
138
+ if (head.length >= 376 && head[0] === 71 && head[188] === 71) {
139
+ return "mpegts";
140
+ }
141
+ if (head.length >= 380 && head[4] === 71 && head[192] === 71) {
142
+ return "mpegts";
143
+ }
144
+ if (head[0] === 82 && head[1] === 73 && head[2] === 70 && head[3] === 70 && head[8] === 65 && head[9] === 86 && head[10] === 73) return "avi";
145
+ if (head[0] === 82 && head[1] === 73 && head[2] === 70 && head[3] === 70 && head[8] === 87 && head[9] === 65 && head[10] === 86 && head[11] === 69) return "wav";
146
+ if (head[0] === 26 && head[1] === 69 && head[2] === 223 && head[3] === 163) {
147
+ return "mkv";
148
+ }
149
+ if (head[4] === 102 && head[5] === 116 && head[6] === 121 && head[7] === 112) {
150
+ const brand = String.fromCharCode(head[8], head[9], head[10], head[11]);
151
+ if (brand.startsWith("qt")) return "mov";
152
+ return "mp4";
153
+ }
154
+ if (head[0] === 48 && head[1] === 38 && head[2] === 178 && head[3] === 117 && head[4] === 142 && head[5] === 102 && head[6] === 207 && head[7] === 17) return "asf";
155
+ if (head[0] === 70 && head[1] === 76 && head[2] === 86) return "flv";
156
+ if (head[0] === 46 && head[1] === 82 && head[2] === 77 && head[3] === 70) {
157
+ return "rm";
158
+ }
159
+ if (head[0] === 79 && head[1] === 103 && head[2] === 103 && head[3] === 83) return "ogg";
160
+ if (head[0] === 102 && head[1] === 76 && head[2] === 97 && head[3] === 67) return "flac";
161
+ if (head[0] === 73 && head[1] === 68 && head[2] === 51) return "mp3";
162
+ if (head[0] === 255 && (head[1] & 224) === 224) {
163
+ if ((head[1] & 246) === 240) return "adts";
164
+ return "mp3";
165
+ }
166
+ return "unknown";
167
+ }
168
+ async function sniffNormalizedSource(source) {
169
+ if (source.kind === "url") {
170
+ return sniffContainerFromBytes(source.sniffBytes);
171
+ }
172
+ const buf = await readBlobBytes(source.blob, SNIFF_BYTES_NEEDED);
173
+ return sniffContainerFromBytes(new Uint8Array(buf));
174
+ }
175
+ async function sniffContainer(blob) {
176
+ const buf = await readBlobBytes(blob, SNIFF_BYTES_NEEDED);
177
+ return sniffContainerFromBytes(new Uint8Array(buf));
178
+ }
179
+ async function readBlobBytes(blob, limit) {
180
+ const slice = blob.slice(0, limit);
181
+ if (typeof slice.arrayBuffer === "function") {
182
+ try {
183
+ return await slice.arrayBuffer();
184
+ } catch {
185
+ }
186
+ }
187
+ return new Promise((resolve, reject) => {
188
+ const reader = new FileReader();
189
+ reader.onload = () => resolve(reader.result);
190
+ reader.onerror = () => reject(reader.error ?? new Error("FileReader failed"));
191
+ reader.readAsArrayBuffer(slice);
192
+ });
193
+ }
194
+
195
+ exports.AvbridgeError = AvbridgeError;
196
+ exports.ERR_ALL_STRATEGIES_EXHAUSTED = ERR_ALL_STRATEGIES_EXHAUSTED;
197
+ exports.ERR_LIBAV_NOT_REACHABLE = ERR_LIBAV_NOT_REACHABLE;
198
+ exports.ERR_MSE_CODEC_NOT_SUPPORTED = ERR_MSE_CODEC_NOT_SUPPORTED;
199
+ exports.ERR_MSE_NOT_SUPPORTED = ERR_MSE_NOT_SUPPORTED;
200
+ exports.ERR_PLAYER_NOT_READY = ERR_PLAYER_NOT_READY;
201
+ exports.ERR_PROBE_FAILED = ERR_PROBE_FAILED;
202
+ exports.ERR_PROBE_UNKNOWN_CONTAINER = ERR_PROBE_UNKNOWN_CONTAINER;
203
+ exports.fetchWith = fetchWith;
204
+ exports.isInMemorySource = isInMemorySource;
205
+ exports.normalizeSource = normalizeSource;
206
+ exports.sniffContainer = sniffContainer;
207
+ exports.sniffContainerFromBytes = sniffContainerFromBytes;
208
+ exports.sniffNormalizedSource = sniffNormalizedSource;
209
+ //# sourceMappingURL=chunk-XKPSTC34.cjs.map
210
+ //# sourceMappingURL=chunk-XKPSTC34.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util/transport.ts","../src/errors.ts","../src/util/source.ts"],"names":["sniffBytes"],"mappings":";;;AAOO,S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IAAA,MAAA,CAAO,kBAAkB,KAAK,CAAA;AAAA,EAChC,CAAC,CAAA;AACH","file":"chunk-XKPSTC34.cjs","sourcesContent":["import type { FetchFn, TransportConfig } from \"../types.js\";\n\n/**\n * Merge two RequestInit objects. Headers are merged (not overwritten) so\n * the caller's auth headers coexist with the player's Range headers.\n * Other fields (credentials, mode, signal, etc.) in `extra` override `base`.\n */\nexport function mergeFetchInit(\n base: RequestInit | undefined,\n extra: RequestInit | undefined,\n): RequestInit | undefined {\n if (!base && !extra) return undefined;\n return {\n ...base,\n ...extra,\n headers: {\n ...(base?.headers as Record<string, string> | undefined ?? {}),\n ...(extra?.headers as Record<string, string> | undefined ?? {}),\n },\n };\n}\n\n/** Return the fetch function from a TransportConfig, falling back to globalThis.fetch. */\nexport function fetchWith(transport?: TransportConfig): FetchFn {\n return transport?.fetchFn ?? globalThis.fetch;\n}\n","/**\n * Structured error with a machine-readable code and human-readable\n * recovery hint. Consumers can switch on `error.code` for programmatic\n * handling and show `error.recovery` in UI.\n *\n * All codes use the `ERR_AVBRIDGE_` prefix to avoid collisions.\n */\nexport class AvbridgeError extends Error {\n override name = \"AvbridgeError\";\n\n constructor(\n /** Machine-readable error code. */\n public readonly code: string,\n message: string,\n /** Human-readable recovery suggestion. */\n public readonly recovery?: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n }\n}\n\n// ── Error codes ────────────────────────────────────────────────────────\n\n// Probe\nexport const ERR_PROBE_FAILED = \"ERR_AVBRIDGE_PROBE_FAILED\";\nexport const ERR_PROBE_UNKNOWN_CONTAINER = \"ERR_AVBRIDGE_PROBE_UNKNOWN_CONTAINER\";\nexport const ERR_PROBE_FETCH_FAILED = \"ERR_AVBRIDGE_PROBE_FETCH_FAILED\";\n\n// Codec / strategy\nexport const ERR_CODEC_NOT_SUPPORTED = \"ERR_AVBRIDGE_CODEC_NOT_SUPPORTED\";\nexport const ERR_STRATEGY_FAILED = \"ERR_AVBRIDGE_STRATEGY_FAILED\";\nexport const ERR_ALL_STRATEGIES_EXHAUSTED = \"ERR_AVBRIDGE_ALL_STRATEGIES_EXHAUSTED\";\n\n// Player lifecycle\nexport const ERR_PLAYER_NOT_READY = \"ERR_AVBRIDGE_PLAYER_NOT_READY\";\n\n// Transport / network\nexport const ERR_RANGE_NOT_SUPPORTED = \"ERR_AVBRIDGE_RANGE_NOT_SUPPORTED\";\nexport const ERR_FETCH_FAILED = \"ERR_AVBRIDGE_FETCH_FAILED\";\n\n// libav\nexport const ERR_LIBAV_NOT_REACHABLE = \"ERR_AVBRIDGE_LIBAV_NOT_REACHABLE\";\n\n// MSE\nexport const ERR_MSE_NOT_SUPPORTED = \"ERR_AVBRIDGE_MSE_NOT_SUPPORTED\";\nexport const ERR_MSE_CODEC_NOT_SUPPORTED = \"ERR_AVBRIDGE_MSE_CODEC_NOT_SUPPORTED\";\n","import type { ContainerKind, MediaInput, TransportConfig } from \"../types.js\";\nimport { mergeFetchInit, fetchWith } from \"./transport.js\";\nimport { AvbridgeError, ERR_PROBE_FETCH_FAILED } from \"../errors.js\";\n\n/**\n * Bytes needed by the sniffer to identify every container we recognize.\n * MPEG-TS needs the most: a sync byte at offset 0 *and* offset 188 (one TS\n * packet apart). Allow a little extra for the M2TS variant (offset 4/192).\n */\nconst SNIFF_BYTES_NEEDED = 380;\n\n/**\n * Bytes to fetch from a URL during the initial sniff. We grab a slightly\n * larger range than `SNIFF_BYTES_NEEDED` so the cache has some headroom for\n * the demuxer's first read after sniffing, in case it wants to look at\n * a few extra bytes (e.g. mp4 ftyp + first moov box).\n */\nconst URL_SNIFF_RANGE_BYTES = 32 * 1024;\n\n/**\n * `NormalizedSource` is a discriminated union: every consumer (probe,\n * strategies) decides what to do based on `kind`. URL sources are NOT\n * fetched eagerly; we only do a Range request for the first ~32 KB so the\n * sniffer has bytes to look at. The strategies are then handed the URL\n * directly so they can stream the rest via Range requests.\n *\n * For File / Blob / ArrayBuffer / Uint8Array sources, the bytes are\n * already in memory, so we wrap them as a `blob` variant.\n */\nexport type NormalizedSource =\n | {\n kind: \"blob\";\n blob: Blob;\n name?: string;\n byteLength: number;\n original: MediaInput;\n }\n | {\n kind: \"url\";\n url: string;\n /** Bytes pulled via Range request for the sniffer. NOT the full file. */\n sniffBytes: Uint8Array;\n name?: string;\n /** Total file size from Content-Length / Content-Range. May be undefined. */\n byteLength: number | undefined;\n original: MediaInput;\n };\n\n/** True if this source carries the entire file's bytes (vs. streaming). */\nexport function isInMemorySource(source: NormalizedSource): source is Extract<NormalizedSource, { kind: \"blob\" }> {\n return source.kind === \"blob\";\n}\n\n\n/**\n * Normalize a `MediaInput` for the probe + strategy layers. **Does not**\n * download URL sources in full — only fetches the first ~32 KB via a\n * Range request, which is enough for the sniffer to identify the\n * container. The strategies are then expected to stream the rest via\n * mediabunny's `UrlSource` (Range requests, prefetch, parallelism, cache).\n *\n * For non-URL inputs, the bytes are already in memory and we just wrap them.\n */\nexport async function normalizeSource(\n source: MediaInput,\n transport?: TransportConfig,\n): Promise<NormalizedSource> {\n if (source instanceof File) {\n return {\n kind: \"blob\",\n blob: source,\n name: source.name,\n byteLength: source.size,\n original: source,\n };\n }\n if (source instanceof Blob) {\n return { kind: \"blob\", blob: source, byteLength: source.size, original: source };\n }\n if (source instanceof ArrayBuffer) {\n const blob = new Blob([source]);\n return { kind: \"blob\", blob, byteLength: blob.size, original: source };\n }\n if (source instanceof Uint8Array) {\n const blob = new Blob([source as BlobPart]);\n return { kind: \"blob\", blob, byteLength: blob.size, original: source };\n }\n if (typeof source === \"string\" || source instanceof URL) {\n const url = source instanceof URL ? source.toString() : source;\n return await fetchUrlForSniff(url, source, transport);\n }\n throw new TypeError(\"unsupported source type\");\n}\n\n/**\n * Fetch the first ~32 KB of a URL via a Range request. Falls back to a\n * full GET if the server doesn't support range requests, but in that case\n * we only read the first 32 KB and abort the rest of the response so we\n * don't accidentally buffer a large file.\n */\nasync function fetchUrlForSniff(\n url: string,\n originalSource: MediaInput,\n transport?: TransportConfig,\n): Promise<NormalizedSource> {\n const name = url.split(\"/\").pop()?.split(\"?\")[0] ?? undefined;\n const doFetch = fetchWith(transport);\n\n // First attempt: Range request for the sniff window.\n let res: Response;\n try {\n res = await doFetch(url, mergeFetchInit(transport?.requestInit, {\n headers: { Range: `bytes=0-${URL_SNIFF_RANGE_BYTES - 1}` },\n })!);\n } catch (err) {\n throw new AvbridgeError(\n ERR_PROBE_FETCH_FAILED,\n `Failed to fetch source ${url}: ${(err as Error).message}`,\n \"Check that the URL is reachable and CORS is configured. If the source requires authentication, pass requestInit with credentials/headers.\",\n );\n }\n if (!res.ok && res.status !== 206) {\n throw new AvbridgeError(\n ERR_PROBE_FETCH_FAILED,\n `Failed to fetch source ${url}: ${res.status} ${res.statusText}`,\n res.status === 403 || res.status === 401\n ? \"The server rejected the request. Pass requestInit with the required Authorization header or credentials.\"\n : \"Check that the URL is correct and the server is reachable.\",\n );\n }\n\n // Determine the total file size from Content-Range (preferred) or Content-Length.\n let byteLength: number | undefined;\n const contentRange = res.headers.get(\"content-range\");\n if (contentRange) {\n // \"bytes 0-32767/12345678\" — parse the part after the slash\n const m = contentRange.match(/\\/(\\d+)$/);\n if (m) byteLength = parseInt(m[1], 10);\n }\n if (byteLength === undefined) {\n const cl = res.headers.get(\"content-length\");\n if (cl) {\n const n = parseInt(cl, 10);\n if (Number.isFinite(n)) {\n // If the server returned 200 (full body), Content-Length is the\n // FILE size. If 206 (partial), it's the chunk size — only use it\n // as a total if no Content-Range was present (server doesn't do\n // ranges) AND the full response is smaller than our sniff window.\n if (res.status === 200) byteLength = n;\n else if (res.status === 206 && !contentRange) byteLength = n;\n }\n }\n }\n\n // Read the sniff bytes. If the server ignored the Range header and is\n // streaming the full file, only read the first window and let the rest\n // be GC'd. We use a reader so we can stop early.\n const reader = res.body?.getReader();\n if (!reader) {\n // No streamed body (some test environments). Fall back to .arrayBuffer()\n // and slice — this might pull more than we wanted, but only for the\n // initial sniff, not the full file.\n const buf = new Uint8Array(await res.arrayBuffer());\n const sniffBytes = buf.slice(0, URL_SNIFF_RANGE_BYTES);\n return { kind: \"url\", url, sniffBytes, name, byteLength, original: originalSource };\n }\n\n const chunks: Uint8Array[] = [];\n let collected = 0;\n while (collected < URL_SNIFF_RANGE_BYTES) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n collected += value.byteLength;\n }\n // Cancel the response so we don't keep downloading.\n await reader.cancel().catch(() => { /* ignore */ });\n\n // Concatenate up to URL_SNIFF_RANGE_BYTES.\n const total = Math.min(collected, URL_SNIFF_RANGE_BYTES);\n const sniffBytes = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n if (offset >= total) break;\n const room = total - offset;\n sniffBytes.set(chunk.subarray(0, Math.min(chunk.byteLength, room)), offset);\n offset += chunk.byteLength;\n }\n\n return { kind: \"url\", url, sniffBytes, name, byteLength, original: originalSource };\n}\n\n/**\n * Identify the container family from a small byte buffer. Used by the\n * probe layer for both file (Blob → first 380 bytes) and URL (Range\n * request → first 32 KB) inputs.\n *\n * Sniffing intentionally does not trust file extensions.\n */\nexport function sniffContainerFromBytes(head: Uint8Array): ContainerKind {\n // MPEG-TS: sync byte 0x47 every 188 bytes. Verify at least two sync\n // bytes in the right places to avoid false positives. Some captures\n // start with a few junk bytes — also try offsets 4 and 192 (M2TS).\n if (head.length >= 376 && head[0] === 0x47 && head[188] === 0x47) {\n return \"mpegts\";\n }\n if (head.length >= 380 && head[4] === 0x47 && head[192] === 0x47) {\n return \"mpegts\"; // M2TS — 4-byte timestamp prefix per packet\n }\n // RIFF....AVI → AVI\n if (\n head[0] === 0x52 && head[1] === 0x49 && head[2] === 0x46 && head[3] === 0x46 &&\n head[8] === 0x41 && head[9] === 0x56 && head[10] === 0x49\n ) return \"avi\";\n // RIFF....WAVE → WAV\n if (\n head[0] === 0x52 && head[1] === 0x49 && head[2] === 0x46 && head[3] === 0x46 &&\n head[8] === 0x57 && head[9] === 0x41 && head[10] === 0x56 && head[11] === 0x45\n ) return \"wav\";\n // EBML start: 1A 45 DF A3 → MKV/WebM. Distinguish later via DocType.\n if (head[0] === 0x1a && head[1] === 0x45 && head[2] === 0xdf && head[3] === 0xa3) {\n return \"mkv\";\n }\n // ftyp at offset 4 → MP4 family\n if (head[4] === 0x66 && head[5] === 0x74 && head[6] === 0x79 && head[7] === 0x70) {\n // brand at bytes 8..11\n const brand = String.fromCharCode(head[8], head[9], head[10], head[11]);\n if (brand.startsWith(\"qt\")) return \"mov\";\n return \"mp4\";\n }\n // ASF / WMV: 30 26 B2 75 8E 66 CF 11\n if (\n head[0] === 0x30 && head[1] === 0x26 && head[2] === 0xb2 && head[3] === 0x75 &&\n head[4] === 0x8e && head[5] === 0x66 && head[6] === 0xcf && head[7] === 0x11\n ) return \"asf\";\n // FLV: 46 4C 56\n if (head[0] === 0x46 && head[1] === 0x4c && head[2] === 0x56) return \"flv\";\n // RealMedia (.rm / .rmvb): \".RMF\" — 2E 52 4D 46\n if (head[0] === 0x2e && head[1] === 0x52 && head[2] === 0x4d && head[3] === 0x46) {\n return \"rm\";\n }\n // OggS: 4F 67 67 53\n if (head[0] === 0x4f && head[1] === 0x67 && head[2] === 0x67 && head[3] === 0x53) return \"ogg\";\n // FLAC: 66 4C 61 43\n if (head[0] === 0x66 && head[1] === 0x4c && head[2] === 0x61 && head[3] === 0x43) return \"flac\";\n // ID3v2: 49 44 33 → MP3 (with id3)\n if (head[0] === 0x49 && head[1] === 0x44 && head[2] === 0x33) return \"mp3\";\n // MPEG audio frame sync: FF Fx\n if (head[0] === 0xff && (head[1] & 0xe0) === 0xe0) {\n // ADTS: FF F1 / FF F9\n if ((head[1] & 0xf6) === 0xf0) return \"adts\";\n return \"mp3\";\n }\n return \"unknown\";\n}\n\n/**\n * Convenience: sniff a `NormalizedSource` regardless of kind. For URL\n * sources, uses the pre-fetched `sniffBytes`. For blob sources, reads the\n * first 380 bytes.\n */\nexport async function sniffNormalizedSource(source: NormalizedSource): Promise<ContainerKind> {\n if (source.kind === \"url\") {\n return sniffContainerFromBytes(source.sniffBytes);\n }\n const buf = await readBlobBytes(source.blob, SNIFF_BYTES_NEEDED);\n return sniffContainerFromBytes(new Uint8Array(buf));\n}\n\n/**\n * Backwards-compatible wrapper for code that still passes a Blob directly.\n * Prefer `sniffNormalizedSource` going forward.\n */\nexport async function sniffContainer(blob: Blob): Promise<ContainerKind> {\n const buf = await readBlobBytes(blob, SNIFF_BYTES_NEEDED);\n return sniffContainerFromBytes(new Uint8Array(buf));\n}\n\n/**\n * Read up to `limit` bytes from a Blob. Tries `Blob.arrayBuffer()` first\n * (modern browsers), then falls back to `FileReader` (works under jsdom).\n */\nasync function readBlobBytes(blob: Blob, limit: number): Promise<ArrayBuffer> {\n const slice = blob.slice(0, limit);\n if (typeof (slice as Blob & { arrayBuffer?: () => Promise<ArrayBuffer> }).arrayBuffer === \"function\") {\n try {\n return await (slice as Blob & { arrayBuffer: () => Promise<ArrayBuffer> }).arrayBuffer();\n } catch {\n /* fall through to FileReader */\n }\n }\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => resolve(reader.result as ArrayBuffer);\n reader.onerror = () => reject(reader.error ?? new Error(\"FileReader failed\"));\n reader.readAsArrayBuffer(slice);\n });\n}\n"]}
@@ -3,9 +3,12 @@
3
3
  // src/util/libav-http-reader.ts
4
4
  var MIN_READ = 256 * 1024;
5
5
  var MAX_READ = 1 * 1024 * 1024;
6
- async function prepareLibavInput(libav, filename, source) {
6
+ async function prepareLibavInput(libav, filename, source, transport) {
7
7
  if (source.kind === "url") {
8
- const handle = await attachLibavHttpReader(libav, filename, source.url);
8
+ const handle = await attachLibavHttpReader(libav, filename, source.url, {
9
+ requestInit: transport?.requestInit,
10
+ fetchFn: transport?.fetchFn
11
+ });
9
12
  return {
10
13
  filename,
11
14
  transport: "http-range",
@@ -176,5 +179,5 @@ async function attachLibavHttpReader(libav, filename, url, options = {}) {
176
179
 
177
180
  exports.attachLibavHttpReader = attachLibavHttpReader;
178
181
  exports.prepareLibavInput = prepareLibavInput;
179
- //# sourceMappingURL=chunk-L4NPOJ36.cjs.map
180
- //# sourceMappingURL=chunk-L4NPOJ36.cjs.map
182
+ //# sourceMappingURL=chunk-Z33SBWL5.cjs.map
183
+ //# sourceMappingURL=chunk-Z33SBWL5.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util/libav-http-reader.ts"],"names":[],"mappings":";;;AA0CA,IAAM,WAAW,GAAA,GAAM,IAAA;AACvB,IAAM,QAAA,GAAW,IAAI,IAAA,GAAO,IAAA;AAyD5B,eAAsB,iBAAA,CACpB,KAAA,EACA,QAAA,EACA,MAAA,EACA,SAAA,EAC2B;AAC3B,EAAA,IAAI,MAAA,CAAO,SAAS,KAAA,EAAO;AACzB,IAAA,MAAM,SAAS,MAAM,qBAAA,CAAsB,KAAA,EAAO,QAAA,EAAU,OAAO,GAAA,EAAK;AAAA,MACtE,aAAa,SAAA,EAAW,WAAA;AAAA,MACxB,SAAS,SAAA,EAAW;AAAA,KACrB,CAAA;AACD,IAAA,OAAO;AAAA,MACL,QAAA;AAAA,MACA,SAAA,EAAW,YAAA;AAAA,MACX,MAAM,MAAA,CAAO,IAAA;AAAA,MACb,MAAA,EAAQ,MAAM,MAAA,CAAO,MAAA;AAAO,KAC9B;AAAA,EACF;AACA,EAAA,MAAM,KAAA,CAAM,eAAA,CAAgB,QAAA,EAAU,MAAA,CAAO,IAAI,CAAA;AACjD,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,SAAA,EAAW,MAAA;AAAA,IACX,MAAM,MAAA,CAAO,UAAA;AAAA,IACb,QAAQ,YAAY;AAClB,MAAA,IAAI;AAAE,QAAA,MAAM,KAAA,CAAM,oBAAoB,QAAQ,CAAA;AAAA,MAAG,CAAA,CAAA,MAAQ;AAAA,MAAe;AAAA,IAC1E;AAAA,GACF;AACF;AAUA,eAAsB,sBACpB,KAAA,EACA,QAAA,EACA,GAAA,EACA,OAAA,GAAwC,EAAC,EACT;AAChC,EAAA,MAAM,OAAA,GAAU,QAAQ,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AAA,IAAI,QAAA,EAAU;AACd,MAAA,QAAA,GAAW,IAAA;AAGX,MAAA,KAAA,CAAM,WAAA,GAAc,gBAAA;AAGpB,MAAA,IAAI,QAAA,EAAU;AACZ,QAAA,IAAI;AAAE,UAAA,MAAM,QAAA;AAAA,QAAU,CAAA,CAAA,MAAQ;AAAA,QAAe;AAAA,MAC/C;AAEA,MAAA,MAAA,GAAS,IAAA;AACT,MAAA,IAAI;AAAE,QAAA,MAAM,KAAA,CAAM,oBAAoB,QAAQ,CAAA;AAAA,MAAG,CAAA,CAAA,MAAQ;AAAA,MAAe;AAAA,IAC1E;AAAA,GACF;AACF","file":"chunk-Z33SBWL5.cjs","sourcesContent":["/**\n * libav.js HTTP block reader.\n *\n * Wraps `libav.mkblockreaderdev` + `libav.onblockread` +\n * `libav.ff_block_reader_dev_send` so that libav can demux a remote file\n * via HTTP Range requests instead of needing the entire file in memory.\n *\n * Used by the AVI/ASF/FLV probe path and the libav-backed playback /\n * conversion strategies whenever the source is a URL.\n *\n * Design notes:\n *\n * - **Range support detection** is done by issuing a `Range: bytes=0-0`\n * probe request. We do NOT trust `Accept-Ranges` headers — some servers\n * support ranges but don't advertise them, others advertise but don't.\n * The probe request is the canonical signal: a `206 Partial Content`\n * response means we can stream; anything else fails fast with a clear\n * error. We never silently fall back to a full download.\n *\n * - **Sequential reads.** libav can issue overlapping `onblockread`\n * callbacks. The reader serializes them through a single async queue\n * so a) `ff_block_reader_dev_send` calls are well-ordered and b) we\n * never have two in-flight fetches for unrelated reads. Throughput\n * for v1 is \"good enough\"; correctness > parallelism.\n *\n * - **In-flight dedup.** If libav asks for `(pos=1000, len=4096)` twice\n * in a row before the first request resolves, the second call awaits\n * the first instead of issuing a duplicate fetch. This handles the\n * \"demuxer re-reads the same header\" pattern cheaply.\n *\n * - **Read-ahead clamp.** libav's requested length is doubled, then\n * clamped to `[256 KB, 1 MB]`. Small reads get amortized; pathological\n * large requests don't OOM us.\n *\n * - **Last-block cache.** Only the most-recent fetched block is kept.\n * Re-fetches via Range are cheap; an LRU cache is post-1.0.\n *\n * - **Safe detach.** `detach()` clears `libav.onblockread`, sets a\n * destroyed flag, and ignores any in-flight fetch resolutions so we\n * never write into a torn-down demuxer.\n */\n\nconst MIN_READ = 256 * 1024;\nconst MAX_READ = 1 * 1024 * 1024;\n\ninterface LibavLike {\n mkblockreaderdev(name: string, size: number): Promise<void>;\n unlinkreadaheadfile(name: string): Promise<void>;\n ff_block_reader_dev_send(\n name: string,\n pos: number,\n data: Uint8Array | null,\n opts?: { errorCode?: number; error?: unknown },\n ): Promise<void>;\n onblockread?: (filename: string, pos: number, length: number) => void;\n}\n\nexport interface LibavHttpReaderHandle {\n /** Total file size (bytes) reported by the server. */\n readonly size: number;\n /** Always `\"http-range\"` for now. Reserved for future transports. */\n readonly transport: \"http-range\";\n /** Stop serving reads, clear the libav callback, and ignore late fetches. */\n detach(): Promise<void>;\n}\n\nexport interface AttachLibavHttpReaderOptions {\n /** Optional `RequestInit` extras (mode, credentials, headers, etc.). */\n requestInit?: RequestInit;\n /** Override fetch (for testing). Defaults to globalThis.fetch. */\n fetchFn?: typeof fetch;\n}\n\n/**\n * Result of preparing a libav-readable file from a normalized source.\n * Either an in-memory Blob (created via `mkreadaheadfile`) or a streaming\n * HTTP reader (created via `attachLibavHttpReader`). Callers should\n * `await detach()` when done so resources are cleaned up symmetrically.\n */\nexport interface LibavInputHandle {\n /** The virtual filename libav sees — pass to `ff_init_demuxer_file`. */\n readonly filename: string;\n /** \"blob\" for in-memory, \"http-range\" for streaming URL. */\n readonly transport: \"blob\" | \"http-range\";\n /** Total file size in bytes if known, otherwise undefined. */\n readonly size: number | undefined;\n /** Tear down the virtual file (and any HTTP reader state). */\n detach(): Promise<void>;\n}\n\ninterface LibavLikeWithBlob extends LibavLike {\n mkreadaheadfile(name: string, blob: Blob): Promise<void>;\n}\n\n/**\n * Convenience for the libav-backed strategies. Given a normalized source,\n * either creates an in-memory readahead file (for Blob inputs) or attaches\n * the HTTP block reader (for URL inputs). Returns a handle the caller\n * should detach when done.\n */\nexport async function prepareLibavInput(\n libav: LibavLikeWithBlob,\n filename: string,\n source: import(\"./source.js\").NormalizedSource,\n transport?: import(\"../types.js\").TransportConfig,\n): Promise<LibavInputHandle> {\n if (source.kind === \"url\") {\n const handle = await attachLibavHttpReader(libav, filename, source.url, {\n requestInit: transport?.requestInit,\n fetchFn: transport?.fetchFn,\n });\n return {\n filename,\n transport: \"http-range\",\n size: handle.size,\n detach: () => handle.detach(),\n };\n }\n await libav.mkreadaheadfile(filename, source.blob);\n return {\n filename,\n transport: \"blob\",\n size: source.byteLength,\n detach: async () => {\n try { await libav.unlinkreadaheadfile(filename); } catch { /* ignore */ }\n },\n };\n}\n\n/**\n * Attach an HTTP block reader to a libav.js instance. After this resolves,\n * libav can `ff_init_demuxer_file(filename)` and the demuxer will pull\n * bytes via Range requests instead of needing a Blob.\n *\n * Fails fast (before any libav setup) if the server doesn't support\n * Range requests.\n */\nexport async function attachLibavHttpReader(\n libav: LibavLike,\n filename: string,\n url: string,\n options: AttachLibavHttpReaderOptions = {},\n): Promise<LibavHttpReaderHandle> {\n const fetchFn = options.fetchFn ?? fetch;\n\n // 1. Probe the server with a single-byte Range request.\n let probeRes: Response;\n try {\n probeRes = await fetchFn(url, {\n ...options.requestInit,\n headers: {\n ...(options.requestInit?.headers ?? {}),\n Range: \"bytes=0-0\",\n },\n });\n } catch (err) {\n throw new Error(\n `libav HTTP reader: failed to reach ${url}: ${(err as Error).message}`,\n );\n }\n if (probeRes.status !== 206) {\n // 200 means the server ignored Range and would have sent the whole\n // file. We refuse to silently slurp gigabytes.\n throw new Error(\n `libav HTTP reader: ${url} does not support HTTP Range requests ` +\n `(server returned ${probeRes.status} for a Range probe; need 206 Partial Content). ` +\n `Remote AVI/ASF/FLV playback requires a server that honors byte-range requests.`,\n );\n }\n\n // 2. Parse total file size from Content-Range: \"bytes 0-0/12345678\"\n const contentRange = probeRes.headers.get(\"content-range\") ?? \"\";\n const sizeMatch = contentRange.match(/\\/(\\d+)$/);\n if (!sizeMatch) {\n throw new Error(\n `libav HTTP reader: ${url} returned 206 but no parseable Content-Range header (got: \"${contentRange}\")`,\n );\n }\n const size = parseInt(sizeMatch[1], 10);\n if (!Number.isFinite(size) || size <= 0) {\n throw new Error(\n `libav HTTP reader: ${url} reported invalid file size ${size}`,\n );\n }\n\n // Drain the probe body so the connection can be reused.\n try { await probeRes.arrayBuffer(); } catch { /* ignore */ }\n\n // 3. Create the virtual file libav will read from.\n await libav.mkblockreaderdev(filename, size);\n\n // ── State ───────────────────────────────────────────────────────────────\n\n let detached = false;\n // Most-recently fetched block. Cached so re-reads of the same region\n // (e.g. demuxer re-walks the header) don't issue another HTTP request.\n let cached: { pos: number; bytes: Uint8Array } | null = null;\n // The currently in-flight fetch, if any. Used both for serialization\n // (we await this before starting another) and for in-flight dedup.\n let inflight: Promise<void> | null = null;\n\n function clampReadLength(requested: number): number {\n const doubled = requested * 2;\n if (doubled < MIN_READ) return MIN_READ;\n if (doubled > MAX_READ) return MAX_READ;\n return doubled;\n }\n\n /** True if the cached block fully covers `[pos, pos+length)`. */\n function cacheCovers(pos: number, length: number): boolean {\n if (!cached) return false;\n return pos >= cached.pos && pos + length <= cached.pos + cached.bytes.byteLength;\n }\n\n /** Slice the requested window out of the cached block. */\n function sliceFromCache(pos: number, length: number): Uint8Array {\n if (!cached) throw new Error(\"sliceFromCache called with no cache\");\n const offset = pos - cached.pos;\n return cached.bytes.subarray(offset, offset + length);\n }\n\n /** Fetch one Range and update the cache. */\n async function fetchRange(pos: number, length: number): Promise<Uint8Array> {\n const end = Math.min(pos + length - 1, size - 1);\n const res = await fetchFn(url, {\n ...options.requestInit,\n headers: {\n ...(options.requestInit?.headers ?? {}),\n Range: `bytes=${pos}-${end}`,\n },\n });\n if (res.status !== 206 && res.status !== 200) {\n throw new Error(\n `libav HTTP reader: Range request bytes=${pos}-${end} returned ${res.status}`,\n );\n }\n const buf = new Uint8Array(await res.arrayBuffer());\n cached = { pos, bytes: buf };\n return buf;\n }\n\n /**\n * Handle a single libav read request. Serializes against any in-flight\n * read by chaining off `inflight`. Honors `detached` at every async\n * boundary so a torn-down reader never writes back into libav.\n */\n async function handleRead(name: string, pos: number, length: number): Promise<void> {\n // Wait for any preceding read to finish so we don't interleave.\n if (inflight) {\n try { await inflight; } catch { /* ignore — that read's own caller handled it */ }\n }\n if (detached) return;\n\n // Cache hit — reply directly without a network round-trip.\n if (cacheCovers(pos, length)) {\n const data = sliceFromCache(pos, length);\n try { await libav.ff_block_reader_dev_send(name, pos, data); } catch { /* ignore — libav may have torn down */ }\n return;\n }\n\n // Cache miss — fetch via Range. Read-ahead amortizes small reads.\n const fetchLen = clampReadLength(length);\n const fetched = (async () => {\n try {\n const buf = await fetchRange(pos, fetchLen);\n if (detached) return;\n // Slice exactly what libav asked for and send it back.\n const reply = buf.subarray(0, Math.min(length, buf.byteLength));\n try { await libav.ff_block_reader_dev_send(name, pos, reply); } catch { /* ignore */ }\n } catch (err) {\n if (detached) return;\n // Signal EOF + error code to libav so the demuxer surfaces it.\n try {\n await libav.ff_block_reader_dev_send(name, pos, null, {\n error: err,\n });\n } catch { /* ignore */ }\n }\n })();\n inflight = fetched;\n try { await fetched; } finally { if (inflight === fetched) inflight = null; }\n }\n\n // 4. Wire the callback. The signature accepts `(name, pos, length)` and\n // we hand it to handleRead which does all the work asynchronously.\n // Note: libav.js dispatches this synchronously from a worker message,\n // so we kick off handleRead but don't await — the queue inside handleRead\n // serializes things.\n const previousCallback = libav.onblockread;\n libav.onblockread = (name: string, pos: number, length: number) => {\n if (detached || name !== filename) {\n // Forward to any previous callback (e.g. another reader on the same\n // libav instance). This is rare in practice but cheap to support.\n previousCallback?.(name, pos, length);\n return;\n }\n void handleRead(name, pos, length);\n };\n\n return {\n size,\n transport: \"http-range\",\n async detach() {\n if (detached) return;\n detached = true;\n // Restore the previous callback (if any) so we don't break unrelated\n // readers on the same libav instance.\n libav.onblockread = previousCallback;\n // Wait for the last in-flight read to settle so we don't tear down\n // the virtual file while libav is still expecting a response.\n if (inflight) {\n try { await inflight; } catch { /* ignore */ }\n }\n // Drop the cache and unlink the virtual file.\n cached = null;\n try { await libav.unlinkreadaheadfile(filename); } catch { /* ignore */ }\n },\n };\n}\n"]}