@blockcast/mmt-container 0.4.0-main.d6f2737828fc → 0.4.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 (102) hide show
  1. package/README.md +12 -9
  2. package/dist/browser-runtime.js +14219 -13716
  3. package/dist/browser-runtime.js.map +4 -4
  4. package/dist/carp-catalog.d.ts +1 -12
  5. package/dist/carp-catalog.d.ts.map +1 -1
  6. package/dist/carp-catalog.js +14 -6
  7. package/dist/carp-catalog.js.map +4 -4
  8. package/dist/catalog-fec-params.d.ts +5 -2
  9. package/dist/catalog-fec-params.d.ts.map +1 -1
  10. package/dist/catalog-fec-params.js +101 -42
  11. package/dist/catalog-fec-params.js.map +4 -4
  12. package/dist/catalog-network-source.js +4 -6
  13. package/dist/catalog-network-source.js.map +4 -4
  14. package/dist/cmcd-producer.d.ts.map +1 -1
  15. package/dist/cmcd-producer.js +0 -4
  16. package/dist/cmcd-producer.js.map +2 -2
  17. package/dist/delivery-catalog.d.ts +124 -0
  18. package/dist/delivery-catalog.d.ts.map +1 -0
  19. package/dist/delivery-catalog.js +1867 -0
  20. package/dist/delivery-catalog.js.map +7 -0
  21. package/dist/fec-manager.d.ts +17 -4
  22. package/dist/fec-manager.d.ts.map +1 -1
  23. package/dist/fec-manager.js +41 -20
  24. package/dist/fec-manager.js.map +4 -4
  25. package/dist/fec-state.d.ts +3 -2
  26. package/dist/fec-state.d.ts.map +1 -1
  27. package/dist/fec-state.js +17 -15
  28. package/dist/fec-state.js.map +4 -4
  29. package/dist/fec-worker-setup.d.ts +2 -8
  30. package/dist/fec-worker-setup.d.ts.map +1 -1
  31. package/dist/fec-worker-setup.js +12 -62
  32. package/dist/fec-worker-setup.js.map +4 -4
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +10 -0
  36. package/dist/index.js.map +2 -2
  37. package/dist/iso-block-locator.js +4 -6
  38. package/dist/iso-block-locator.js.map +4 -4
  39. package/dist/mfu-reassembler.js +27 -29
  40. package/dist/mfu-reassembler.js.map +4 -4
  41. package/dist/mmtp-container-parser.d.ts +9 -11
  42. package/dist/mmtp-container-parser.d.ts.map +1 -1
  43. package/dist/mmtp-container-parser.js +107 -98
  44. package/dist/mmtp-container-parser.js.map +4 -4
  45. package/dist/mmtp-container-parser.no-modules.js +133 -108
  46. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  47. package/dist/mmtp-decode-pipeline.js +107 -98
  48. package/dist/mmtp-decode-pipeline.js.map +4 -4
  49. package/dist/mmtp-router.d.ts +34 -14
  50. package/dist/mmtp-router.d.ts.map +1 -1
  51. package/dist/mmtp-router.js +143 -113
  52. package/dist/mmtp-router.js.map +4 -4
  53. package/dist/multicast-input.js +4 -6
  54. package/dist/multicast-input.js.map +4 -4
  55. package/dist/multicast-manager.d.ts +39 -3
  56. package/dist/multicast-manager.d.ts.map +1 -1
  57. package/dist/multicast-manager.js +264 -156
  58. package/dist/multicast-manager.js.map +4 -4
  59. package/dist/multicast-transport.js +14 -14
  60. package/dist/multicast-transport.js.map +4 -4
  61. package/dist/multicast-unwrap.js +32 -34
  62. package/dist/multicast-unwrap.js.map +4 -4
  63. package/dist/no-modules.js +130 -107
  64. package/dist/no-modules.js.map +4 -4
  65. package/dist/repair-fetch.d.ts +86 -2
  66. package/dist/repair-fetch.d.ts.map +1 -1
  67. package/dist/repair-fetch.js +86 -17
  68. package/dist/repair-fetch.js.map +4 -4
  69. package/dist/repair-layers.js +4 -6
  70. package/dist/repair-layers.js.map +4 -4
  71. package/dist/signaling.js +5 -7
  72. package/dist/signaling.js.map +4 -4
  73. package/dist/timestamp-codec.js +27 -29
  74. package/dist/timestamp-codec.js.map +4 -4
  75. package/dist/wasm-mfu-reassembler.js +4 -6
  76. package/dist/wasm-mfu-reassembler.js.map +4 -4
  77. package/dist/wasm-mmtp-container-parser.js +107 -98
  78. package/dist/wasm-mmtp-container-parser.js.map +4 -4
  79. package/package.json +5 -6
  80. package/src/carp-catalog.ts +16 -11
  81. package/src/catalog-fec-params.ts +38 -17
  82. package/src/cmcd-producer.ts +0 -6
  83. package/src/delivery-catalog.ts +498 -0
  84. package/src/fec-manager.ts +44 -17
  85. package/src/fec-state.ts +4 -9
  86. package/src/fec-worker-setup.ts +4 -35
  87. package/src/index.ts +27 -0
  88. package/src/mmtp-container-parser.ts +80 -20
  89. package/src/mmtp-router.ts +71 -29
  90. package/src/multicast-manager.ts +93 -26
  91. package/src/repair-fetch.ts +228 -17
  92. package/test-vectors/catalog/README.md +10 -1
  93. package/test-vectors/catalog/negative/multicast-endpoint-relay-address.json +39 -0
  94. package/test-vectors/catalog/negative/raptorq-unaligned-symbol.json +1 -0
  95. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +38 -0
  96. package/test-vectors/catalog/section-codes.json +33 -0
  97. package/test-vectors/delivery-catalog/README.md +11 -0
  98. package/test-vectors/delivery-catalog/negative/missing-block-profile.json +58 -0
  99. package/test-vectors/delivery-catalog/negative/packet-id-signaling.json +59 -0
  100. package/test-vectors/delivery-catalog/negative/retired-k-padded-block-profile.json +59 -0
  101. package/test-vectors/delivery-catalog/positive/dash.json +56 -0
  102. package/test-vectors/delivery-catalog/positive/mmtp-source-only.json +43 -0
@@ -57,13 +57,36 @@
57
57
  * than sent and cancelled -- and an admitted FETCH holds the block open to
58
58
  * that deadline, so the multicast span elapsing never aborts it.
59
59
  *
60
+ * Keyframe late-repair budget: a block that may hold a RAP may be given a
61
+ * longer deadline than the playout budget (`keyframeRepairBudgetMs`). Losing
62
+ * such a block costs every frame up to the next keyframe, so holding it open
63
+ * for a FETCH that lands within the budget trades a short hold for a GOP-long
64
+ * freeze. At a small playout budget (a low-latency target) the presentation
65
+ * deadline alone leaves less than one round trip by the time the multicast
66
+ * wait gives up on the block, so every keyframe request would be refused
67
+ * (`rtt-exceeds-budget`). Eligible (`keyframeBudgetEligible`): a `keyframe`
68
+ * block (in-band RAP evidence), and an `unknown` block only while its
69
+ * stream's classifier is `classifying`, where `unknown` means the window rule
70
+ * could not exclude a RAP. Under `all-protected` every block reads `unknown`
71
+ * whatever it holds, so there only RAP evidence earns the budget. Never
72
+ * audio (P1) or delta (P2), and never a block its repair group cannot
73
+ * complete (received sources + RSB_length < K'). The hold ends when its
74
+ * FETCH ends without making the block decodable, not at the budget.
75
+ *
76
+ * Every deadline is capped by the release gate's hold ceiling measured the
77
+ * way the gate measures it: from the earliest frame it holds for the stream
78
+ * (a surviving frame of the block itself is routed before a repair symbol
79
+ * states the block, so before its anchor), never later than from the anchor.
80
+ * A FETCH landing after the gate forced that frame out would recover media
81
+ * the gate then drops as stale.
82
+ *
60
83
  * The scheduler arms no timers. A fetch ends when its transport completes or
61
84
  * throws, when it is preempted, when any later scheduling event finds it past
62
85
  * its presentation deadline, when its block resolves (recovered, or failed at
63
86
  * that deadline), on track reset, or on dispose.
64
87
  */
65
88
  import { type FecBlockProfile } from '@blockcast/mmt-base';
66
- import { type BlockClass } from './block-policy.js';
89
+ import { type BlockClass, type ClassifierMode, type RepairPriority } from './block-policy.js';
67
90
  import type { RepairLifecycleObserver } from './multicast-manager.js';
68
91
  /**
69
92
  * The highest value in the Source Media priority range of
@@ -202,6 +225,22 @@ export type RepairFetchPriority = {
202
225
  * least 192, i.e. max(repair, 192); declined when it carries none.
203
226
  */
204
227
  export declare function repairFetchSubscriberPriority(blockClass: BlockClass, target: Pick<RepairTarget, 'sourcePriority' | 'repairPriority'>): RepairFetchPriority;
228
+ /** What `RepairFetchHost.fecManager.blockSymbolCounts` reports for one open block. */
229
+ export interface BlockSymbolCounts {
230
+ readonly sources: number;
231
+ readonly repairs: number;
232
+ readonly authoredLength: number | undefined;
233
+ readonly repairGroupLength: number | undefined;
234
+ }
235
+ /**
236
+ * Whether a block of `blockClass` may get the keyframe late-repair budget:
237
+ * a `keyframe` block always (in-band RAP evidence), an `unknown` block only
238
+ * while its stream's classifier is `classifying` (the window rule could not
239
+ * exclude a RAP). An `all-protected` stream reads `unknown` for every block,
240
+ * delta-only ones included, so there `unknown` is no evidence of a RAP and
241
+ * earns no hold. Audio and delta never do.
242
+ */
243
+ export declare function keyframeBudgetEligible(blockClass: BlockClass, classifierMode: ClassifierMode | undefined): boolean;
205
244
  export interface WireRepairFetchOptions {
206
245
  resolveTarget: ResolveRepairTarget;
207
246
  transport: RepairFetchTransport;
@@ -228,6 +267,20 @@ export interface WireRepairFetchOptions {
228
267
  * (`presentation-delay-unavailable`).
229
268
  */
230
269
  presentationDelayMs: (packetId: number, catalogTrackName?: string) => number;
270
+ /**
271
+ * How long after the first symbol of a block that may hold a RAP a repair
272
+ * FETCH of it may still land, in ms (optional). Such a block
273
+ * (`keyframeBudgetEligible`) gets the larger of this and
274
+ * `presentationDelayMs`, still never later than the release gate's hold
275
+ * ceiling and never earlier than the multicast wait; RTT admission is
276
+ * unchanged. Losing a keyframe block costs the rest of its GOP, so a player
277
+ * may hold the block (and the frames released after it) while its FETCH is
278
+ * in flight rather than freeze to the next keyframe. Absent, throwing, or
279
+ * not finite and positive: every block gets the presentation deadline
280
+ * alone. Never applied to audio, delta, or an `unknown` block of an
281
+ * `all-protected` stream.
282
+ */
283
+ keyframeRepairBudgetMs?: (packetId: number, catalogTrackName?: string) => number;
231
284
  }
232
285
  /** Why the D-28 layer asked for a repair: the block's class at its deadline. */
233
286
  export type RepairSubscribeCallback = (sbn: number, packetId: number, catalogTrackName: string | undefined, blockClass: BlockClass) => void;
@@ -246,6 +299,18 @@ export interface RepairFetchHost {
246
299
  repairFetchTimeoutMsForBlock(sbn: number, packetId: number, catalogTrackName?: string): number | undefined;
247
300
  /** Receiver-local time of the block's first accepted symbol, if any. */
248
301
  blockAnchorAtMs(sbn: number, packetId: number, catalogTrackName?: string): number | undefined;
302
+ /** The stream's classifier mode (optional; absent reads as unknown). */
303
+ classifierModeFor?(packetId: number, catalogTrackName?: string): {
304
+ readonly mode: ClassifierMode;
305
+ };
306
+ /**
307
+ * An open block's received sources and distinct repair symbols, its K'
308
+ * (SSB_length) and RSB_length (optional). The repair group carries
309
+ * RSB_length symbols, so it can complete the block only when
310
+ * sources + RSB_length >= K'; a FETCH that ended leaving fewer than K'
311
+ * distinct symbols cannot be decoding it.
312
+ */
313
+ blockSymbolCounts?(sbn: number, packetId: number, catalogTrackName?: string): BlockSymbolCounts | undefined;
249
314
  /** How long a terminal block stays authoritative: the release-gate hold ceiling. */
250
315
  terminalRetentionMsForPacket(packetId: number): number | undefined;
251
316
  /** Keep the block open to `untilAtMs` for an admitted FETCH. */
@@ -254,6 +319,15 @@ export interface RepairFetchHost {
254
319
  releaseRepairHold(sbn: number, packetId: number, catalogTrackName?: string): void;
255
320
  };
256
321
  onRepairSubscribe(cb: RepairSubscribeCallback): void;
322
+ /**
323
+ * Arrival time of the earliest frame the in-order release gate holds for
324
+ * the stream, or undefined (optional; absent, the block's anchor bounds the
325
+ * ceiling alone). The gate releases that frame `terminalRetentionMsForPacket`
326
+ * after it, whatever its blocks are doing.
327
+ */
328
+ earliestGatedFrameAtMs?(packetId: number, catalogTrackName?: string): number | undefined;
329
+ /** The keyframe budget extended a request's deadline by `extensionMs` (optional). */
330
+ noteKeyframeBudgetGranted?(extensionMs: number, sbn: number, packetId: number, catalogTrackName?: string): void;
257
331
  addRepairLifecycleObserver(observer: RepairLifecycleObserver): () => void;
258
332
  addTrackResetObserver(observer: (packetId: number, catalogTrackName: string) => void): () => void;
259
333
  clearRepairForBlock(sbn: number, packetId: number, catalogTrackName?: string): void;
@@ -261,11 +335,21 @@ export interface RepairFetchHost {
261
335
  noteRepairScheduling(type: 'repair-preempted' | 'repair-deferred', sbn: number, packetId: number, catalogTrackName?: string): void;
262
336
  /** A request whose wire priority the catalog could not supply. */
263
337
  noteRepairPriority(action: 'omitted' | 'declined', reason: RepairPriorityReason, blockClass: BlockClass, sbn: number, packetId: number, catalogTrackName?: string): void;
264
- /** A request the scheduler did not send (see RepairSkipReason). */
338
+ /**
339
+ * A request the scheduler did not send (see RepairSkipReason).
340
+ * `measurement.priority` is the request's repair priority (0 keyframe or
341
+ * unknown, 1 audio, 2 delta).
342
+ */
265
343
  noteRepairSkipped(reason: RepairSkipReason, measurement: {
266
344
  readonly rttMs: number | null;
267
345
  readonly budgetMs: number;
346
+ readonly priority?: RepairPriority;
268
347
  }, sbn: number, packetId: number, catalogTrackName?: string): void;
348
+ /**
349
+ * A FETCH the scheduler admitted and handed to the transport (optional):
350
+ * every attempt, a retry or a reprioritised restart included.
351
+ */
352
+ noteRepairFetchSent?(priority: RepairPriority, sbn: number, packetId: number, catalogTrackName?: string): void;
269
353
  }
270
354
  /**
271
355
  * Wire the D-28 repair-fetch scheduler onto a MulticastManager.
@@ -1 +1 @@
1
- {"version":3,"file":"repair-fetch.d.ts","sourceRoot":"","sources":["../src/repair-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AAEH,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAA0B,KAAK,UAAU,EAAuB,MAAM,mBAAmB,CAAA;AAChG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAMrE;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAA0B,CAAA;AAEhE,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CACvC;AAED;;;;;;;8DAO8D;AAC9D,MAAM,MAAM,mBAAmB,GAAG,CAChC,QAAQ,EAAE,MAAM,EAChB,gBAAgB,CAAC,EAAE,MAAM,KACtB,YAAY,GAAG,IAAI,CAAA;AAExB,8EAA8E;AAC9E,MAAM,WAAW,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iCD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,sBAAsB,GAAG,MAAM,IAAI,CAygB7F"}
@@ -1,13 +1,8 @@
1
- // ../mmt-alta-parse/dist/index.js
1
+ // ../mmt-base/dist/mmtp.js
2
2
  var MPU_HEADER_SIZE = 8;
3
3
  var MPU_LENGTH_FIELD_SIZE = 2;
4
4
  var MPU_HEADER_REMAINDER_SIZE = MPU_HEADER_SIZE - MPU_LENGTH_FIELD_SIZE;
5
5
 
6
- // ../mmt-base/dist/mmtp.js
7
- var MPU_HEADER_SIZE2 = 8;
8
- var MPU_LENGTH_FIELD_SIZE2 = 2;
9
- var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
10
-
11
6
  // ../mmt-base/dist/ntp-short.js
12
7
  var NTP_SHORT_BITS = 32;
13
8
  var NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS;
@@ -29,6 +24,9 @@ function parseFecBlockProfile(value, where) {
29
24
  throw new Error(`${where} must be "iso-ssbg1-v1" (got ${JSON.stringify(value)})`);
30
25
  }
31
26
 
27
+ // ../mmt-base/dist/catalog-fec-source.js
28
+ var ALL_ROLES = Object.freeze(["video", "audio"]);
29
+
32
30
  // src/block-policy.ts
33
31
  import { deriveFecInterleaveDepth } from "@blockcast/mmt-fec";
34
32
  function repairPriorityForClass(blockClass) {
@@ -64,6 +62,10 @@ function repairFetchSubscriberPriority(blockClass, target) {
64
62
  if (!isMoqtPriority(repair)) return { kind: "decline", reason: "repair-priority-invalid" };
65
63
  return { kind: "carry", subscriberPriority: Math.max(repair, REPAIR_PRIORITY_MIN) };
66
64
  }
65
+ function keyframeBudgetEligible(blockClass, classifierMode) {
66
+ if (blockClass === "keyframe") return true;
67
+ return blockClass === "unknown" && classifierMode === "classifying";
68
+ }
67
69
  function wireRepairFetch(mc, opts) {
68
70
  if (!Number.isSafeInteger(opts.attemptLimit) || opts.attemptLimit < 1) {
69
71
  throw new Error(
@@ -101,6 +103,16 @@ function wireRepairFetch(mc, opts) {
101
103
  run.controller.abort();
102
104
  if (reason === "preempted") releaseHold(entry);
103
105
  };
106
+ const readKeyframeBudget = (packetId, catalogTrackName) => {
107
+ const reader = opts.keyframeRepairBudgetMs;
108
+ if (reader === void 0) return null;
109
+ try {
110
+ const budgetMs = reader(packetId, catalogTrackName);
111
+ return Number.isFinite(budgetMs) && budgetMs > 0 ? budgetMs : null;
112
+ } catch {
113
+ return null;
114
+ }
115
+ };
104
116
  const readRtt = () => {
105
117
  try {
106
118
  const rtt = opts.reliableRttMs();
@@ -118,7 +130,7 @@ function wireRepairFetch(mc, opts) {
118
130
  clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
119
131
  mc.noteRepairSkipped(
120
132
  rttMs === null ? "rtt-unmeasured" : "rtt-exceeds-budget",
121
- { rttMs, budgetMs },
133
+ { rttMs, budgetMs, priority: entry.priority },
122
134
  entry.sbn,
123
135
  entry.packetId,
124
136
  entry.catalogTrackName
@@ -157,6 +169,7 @@ function wireRepairFetch(mc, opts) {
157
169
  const start = (entry, counted = true) => {
158
170
  if (!admit(entry, performance.now())) return;
159
171
  if (counted) entry.attempts++;
172
+ mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName);
160
173
  const run = { controller: new AbortController(), stopped: null };
161
174
  entry.running = run;
162
175
  mc.fecManager.holdBlockForRepair(
@@ -194,6 +207,25 @@ function wireRepairFetch(mc, opts) {
194
207
  if (urgentOutstanding()) return;
195
208
  queued.filter((entry) => entry.priority === 2).sort((a, b) => a.deadlineAt - b.deadlineAt || a.order - b.order).forEach((entry) => start(entry));
196
209
  };
210
+ const symbolCounts = (sbn, packetId, catalogTrackName) => {
211
+ try {
212
+ return mc.fecManager.blockSymbolCounts?.(sbn, packetId, catalogTrackName);
213
+ } catch {
214
+ return void 0;
215
+ }
216
+ };
217
+ const decodable = (entry) => {
218
+ const counts = symbolCounts(entry.sbn, entry.packetId, entry.catalogTrackName);
219
+ if (counts === void 0 || counts.authoredLength === void 0) return true;
220
+ return counts.sources + counts.repairs >= counts.authoredLength;
221
+ };
222
+ const groupCanComplete = (sbn, packetId, catalogTrackName) => {
223
+ const counts = symbolCounts(sbn, packetId, catalogTrackName);
224
+ if (counts === void 0 || counts.authoredLength === void 0 || counts.repairGroupLength === void 0) {
225
+ return true;
226
+ }
227
+ return counts.sources + counts.repairGroupLength >= counts.authoredLength;
228
+ };
197
229
  const finish = (entry, run, fed, error) => {
198
230
  if (run.stopped !== null || entry.running !== run || entries.get(entry.key) !== entry) {
199
231
  return;
@@ -201,7 +233,7 @@ function wireRepairFetch(mc, opts) {
201
233
  entry.running = null;
202
234
  if (error === void 0) {
203
235
  retire(entry);
204
- if (fed === 0) {
236
+ if (fed === 0 || !decodable(entry)) {
205
237
  releaseHold(entry);
206
238
  clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
207
239
  }
@@ -275,6 +307,17 @@ function wireRepairFetch(mc, opts) {
275
307
  if (wire === null) return;
276
308
  entry2.priority = promoted;
277
309
  entry2.subscriberPriority = wire.subscriberPriority;
310
+ const promotedDeadline = presentationDeadlineAt(
311
+ entry2.sbn,
312
+ entry2.packetId,
313
+ entry2.catalogTrackName,
314
+ performance.now(),
315
+ event.to
316
+ );
317
+ if (promotedDeadline !== null && promotedDeadline.deadlineAt > entry2.deadlineAt) {
318
+ entry2.deadlineAt = promotedDeadline.deadlineAt;
319
+ noteBudget(entry2, promotedDeadline.extensionMs);
320
+ }
278
321
  if (entry2.running) {
279
322
  stop(entry2, "reprioritized");
280
323
  start(entry2, false);
@@ -293,12 +336,12 @@ function wireRepairFetch(mc, opts) {
293
336
  else if (entry.priority === 2 && entry.attempts === 0) note("repair-deferred", entry);
294
337
  dispatch();
295
338
  });
296
- const presentationDeadlineAt = (sbn, packetId, catalogTrackName, now) => {
339
+ const presentationDeadlineAt = (sbn, packetId, catalogTrackName, now, blockClass) => {
297
340
  const waitMs = mc.fecManager.repairFetchTimeoutMsForBlock(sbn, packetId, catalogTrackName);
298
341
  if (waitMs === void 0) return null;
299
342
  const waitDeadlineAt = now + waitMs;
300
343
  const anchor = mc.fecManager.blockAnchorAtMs(sbn, packetId, catalogTrackName);
301
- if (anchor === void 0) return waitDeadlineAt;
344
+ if (anchor === void 0) return { deadlineAt: waitDeadlineAt, extensionMs: 0 };
302
345
  let delayMs;
303
346
  try {
304
347
  delayMs = opts.presentationDelayMs(packetId, catalogTrackName);
@@ -308,8 +351,31 @@ function wireRepairFetch(mc, opts) {
308
351
  if (!(Number.isFinite(delayMs) && delayMs > 0)) return null;
309
352
  const retentionMs = mc.fecManager.terminalRetentionMsForPacket(packetId);
310
353
  if (retentionMs === void 0) return null;
311
- const ceilingAt = anchor + retentionMs;
312
- return Math.max(waitDeadlineAt, Math.min(anchor + delayMs, ceilingAt));
354
+ const ceilingAt = Math.min(anchor, earliestGatedFrameAt(packetId, catalogTrackName) ?? anchor) + retentionMs;
355
+ const deadlineAt = (delay) => Math.max(waitDeadlineAt, Math.min(anchor + delay, ceilingAt));
356
+ const base = deadlineAt(delayMs);
357
+ const budgetMs = keyframeBudgetEligible(blockClass, classifierMode(packetId, catalogTrackName)) && groupCanComplete(sbn, packetId, catalogTrackName) ? readKeyframeBudget(packetId, catalogTrackName) : null;
358
+ if (budgetMs === null || budgetMs <= delayMs) return { deadlineAt: base, extensionMs: 0 };
359
+ const extended = deadlineAt(budgetMs);
360
+ return { deadlineAt: extended, extensionMs: extended - base };
361
+ };
362
+ const earliestGatedFrameAt = (packetId, catalogTrackName) => {
363
+ try {
364
+ const at = mc.earliestGatedFrameAtMs?.(packetId, catalogTrackName);
365
+ return at !== void 0 && Number.isFinite(at) ? at : void 0;
366
+ } catch {
367
+ return void 0;
368
+ }
369
+ };
370
+ const classifierMode = (packetId, catalogTrackName) => {
371
+ try {
372
+ return mc.fecManager.classifierModeFor?.(packetId, catalogTrackName).mode;
373
+ } catch {
374
+ return void 0;
375
+ }
376
+ };
377
+ const noteBudget = (entry, extensionMs) => {
378
+ if (extensionMs > 0) mc.noteKeyframeBudgetGranted?.(extensionMs, entry.sbn, entry.packetId, entry.catalogTrackName);
313
379
  };
314
380
  mc.onRepairSubscribe((sbn, packetId, catalogTrackName, blockClass) => {
315
381
  if (disposed) {
@@ -347,12 +413,13 @@ function wireRepairFetch(mc, opts) {
347
413
  return;
348
414
  }
349
415
  const now = performance.now();
350
- const deadlineAt = presentationDeadlineAt(sbn, packetId, catalogTrackName, now);
351
- if (deadlineAt === null) {
416
+ const priority = repairPriorityForClass(blockClass);
417
+ const deadline = presentationDeadlineAt(sbn, packetId, catalogTrackName, now, blockClass);
418
+ if (deadline === null) {
352
419
  clearRepair(sbn, packetId, catalogTrackName);
353
420
  mc.noteRepairSkipped(
354
421
  "presentation-delay-unavailable",
355
- { rttMs: readRtt(), budgetMs: 0 },
422
+ { rttMs: readRtt(), budgetMs: 0, priority },
356
423
  sbn,
357
424
  packetId,
358
425
  catalogTrackName
@@ -364,14 +431,15 @@ function wireRepairFetch(mc, opts) {
364
431
  ...identity,
365
432
  repairTrack: target.repairTrack,
366
433
  blockProfile,
367
- priority: repairPriorityForClass(blockClass),
434
+ priority,
368
435
  subscriberPriority: wire.subscriberPriority,
369
- deadlineAt,
436
+ deadlineAt: deadline.deadlineAt,
370
437
  order: enqueueOrder++,
371
438
  attempts: 0,
372
439
  running: null
373
440
  };
374
441
  entries.set(key, entry);
442
+ noteBudget(entry, deadline.extensionMs);
375
443
  if (entry.priority < 2) preemptDeltas();
376
444
  dispatch();
377
445
  });
@@ -389,6 +457,7 @@ function wireRepairFetch(mc, opts) {
389
457
  }
390
458
  export {
391
459
  SOURCE_MEDIA_PRIORITY_MAX,
460
+ keyframeBudgetEligible,
392
461
  repairFetchSubscriberPriority,
393
462
  wireRepairFetch
394
463
  };