@blockcast/mmt-container 2.2.0-main.c3a95413582c → 2.2.0-main.cc080e5a56f2

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/dist/browser-runtime.js +1151 -169
  2. package/dist/browser-runtime.js.map +3 -3
  3. package/dist/delivery-catalog.js +17 -12
  4. package/dist/delivery-catalog.js.map +2 -2
  5. package/dist/delta-fallback-config.js.map +1 -1
  6. package/dist/fec-manager.d.ts +70 -12
  7. package/dist/fec-manager.d.ts.map +1 -1
  8. package/dist/fec-manager.js +403 -58
  9. package/dist/fec-manager.js.map +2 -2
  10. package/dist/fec-worker-setup.js.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +2 -2
  14. package/dist/iso-block-locator.d.ts +48 -13
  15. package/dist/iso-block-locator.d.ts.map +1 -1
  16. package/dist/iso-block-locator.js +97 -25
  17. package/dist/iso-block-locator.js.map +2 -2
  18. package/dist/iso-bmff-timing.d.ts +10 -1
  19. package/dist/iso-bmff-timing.d.ts.map +1 -1
  20. package/dist/iso-bmff-timing.js +36 -2
  21. package/dist/iso-bmff-timing.js.map +2 -2
  22. package/dist/media-router.js.map +1 -1
  23. package/dist/mmtp-container-parser.d.ts +79 -10
  24. package/dist/mmtp-container-parser.d.ts.map +1 -1
  25. package/dist/mmtp-container-parser.js +207 -26
  26. package/dist/mmtp-container-parser.js.map +2 -2
  27. package/dist/mmtp-container-parser.no-modules.js +209 -29
  28. package/dist/mmtp-container-parser.no-modules.js.map +2 -2
  29. package/dist/mmtp-decode-pipeline.js +206 -26
  30. package/dist/mmtp-decode-pipeline.js.map +2 -2
  31. package/dist/mmtp-router.d.ts +34 -8
  32. package/dist/mmtp-router.d.ts.map +1 -1
  33. package/dist/mmtp-router.js +546 -75
  34. package/dist/mmtp-router.js.map +2 -2
  35. package/dist/multicast-manager.d.ts +13 -3
  36. package/dist/multicast-manager.d.ts.map +1 -1
  37. package/dist/multicast-manager.js +971 -142
  38. package/dist/multicast-manager.js.map +2 -2
  39. package/dist/multicast-transport.js +19 -14
  40. package/dist/multicast-transport.js.map +2 -2
  41. package/dist/no-modules.js +206 -26
  42. package/dist/no-modules.js.map +2 -2
  43. package/dist/repair-fetch.d.ts +38 -8
  44. package/dist/repair-fetch.d.ts.map +1 -1
  45. package/dist/repair-fetch.js +286 -27
  46. package/dist/repair-fetch.js.map +3 -3
  47. package/dist/track-session.d.ts.map +1 -1
  48. package/dist/track-session.js +1 -0
  49. package/dist/track-session.js.map +2 -2
  50. package/dist/wasm-mmtp-container-parser.js +206 -26
  51. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  52. package/package.json +5 -5
  53. package/src/fec-manager.ts +433 -32
  54. package/src/index.ts +3 -0
  55. package/src/iso-block-locator.ts +133 -31
  56. package/src/iso-bmff-timing.ts +40 -1
  57. package/src/mmtp-container-parser.ts +306 -29
  58. package/src/mmtp-router.ts +548 -38
  59. package/src/multicast-manager.ts +44 -6
  60. package/src/repair-fetch.ts +366 -50
  61. package/src/track-session.ts +3 -0
@@ -41,6 +41,18 @@
41
41
  * or otherwise never sent cancels nothing (§11.4.5 item 3), and an audio
42
42
  * request never preempts. A P2 that never ran before its block resolved
43
43
  * is reported as `repair-deferred`.
44
+ * - A hole walked over the one-Group transport (no `rangeTransport`) is
45
+ * repair the run gets before its FEC deadline (`walkHole`). On a video
46
+ * track it is keyframe repair (class `unknown`): P0, and no audio or
47
+ * delta FETCH is issued while one of its Group FETCHes is outstanding
48
+ * (fec-multicast-00 rule 3). It reaches no FEC deadline, so it preempts
49
+ * nothing and holds back no audio or delta request: one that comes due
50
+ * cancels the walk's Group FETCH and goes out at once, and the walk asks
51
+ * for that Group again after it (`yieldVideoWalks`). On an audio track
52
+ * it is audio repair: P1 at the audio wire priority, one Group per FETCH,
53
+ * and like any audio request it waits while keyframe repair is
54
+ * outstanding, stopping before its next Group, and is preempted by a
55
+ * keyframe FETCH sent.
44
56
  * - A block reclassified to a higher class while its P2 fetch is in flight
45
57
  * is re-issued at once under the new class's wire priority: the running
46
58
  * FETCH is aborted (FETCH_CANCEL) and a new one sent.
@@ -100,21 +112,35 @@
100
112
  * gate behind it) past that deadline.
101
113
  */
102
114
 
103
- import { parseFecBlockProfile, type FecBlockProfile } from '@blockcast/mmt-base'
115
+ import {
116
+ extractRepairFecPayloadId,
117
+ parseFecBlockProfile,
118
+ serial32Add,
119
+ serial32Distance,
120
+ type FecBlockProfile,
121
+ } from '@blockcast/mmt-base'
104
122
  import { extendSsId, repairFetchRange, type RepairFetchRange } from '@blockcast/mmt-fec'
105
123
  import {
106
124
  repairPriorityForClass,
107
125
  type BlockClass,
108
126
  type ClassifierMode,
109
127
  type RepairPriority,
128
+ type TrackKind,
110
129
  } from './block-policy.js'
111
- import type { UndelimitedIsoLoss } from './fec-manager.js'
130
+ import type { ExpiredIsoHole, UndelimitedIsoLoss } from './fec-manager.js'
112
131
  import type { RepairLifecycleObserver } from './multicast-manager.js'
113
132
  import { REPAIR_PRIORITY_MIN } from './repair-layers.js'
114
133
 
115
134
  /** The MoQ Transport priority scale: 0..255, a lower value is delivered first. */
116
135
  const MOQT_PRIORITY_MAX = 255
117
136
 
137
+ /**
138
+ * How long before the span a walked hole leaves asks for its repair (D-28)
139
+ * the walk ends: past the deadline timer's 1 ms slack and one timer tick, so
140
+ * the span's request timer is armed before it is due (walkDeadlineAt).
141
+ */
142
+ const WALK_LEAD_MS = 3
143
+
118
144
  /**
119
145
  * The highest value in the Source Media priority range of
120
146
  * draft-ramadan-moq-fec §10 (64..191): one below the repair range, which
@@ -185,6 +211,8 @@ export interface RepairFetchRequest {
185
211
  /**
186
212
  * Aborts when the scheduler no longer wants the group: preemption by
187
213
  * keyframe work, reprioritisation, block resolution, track reset, dispose.
214
+ * When the scheduler stops a running request, `signal.reason` is its
215
+ * `RepairStopReason`, the one `noteRepairStopped` reports.
188
216
  */
189
217
  readonly signal: AbortSignal
190
218
  /**
@@ -370,10 +398,14 @@ export interface WireRepairFetchOptions {
370
398
  keyframeRepairBudgetMs?: (packetId: number, catalogTrackName?: string) => number
371
399
  /**
372
400
  * Range repair for a lost SS_ID whose block no repair delimited
373
- * (draft-ramadan-moq-fec §7.5), optional. Given, the host keeps such a gap
374
- * as a pending hole and the scheduler FETCHes `repairFetchRange(x, K,
375
- * anchor)` for it under the same admission, priority and abort rules as a
376
- * block request (class `unknown`, P0). Requires `repairEpochReference`.
401
+ * (draft-ramadan-moq-fec §7.5), optional. A host that can keep such a gap as
402
+ * a pending hole gets range repair either way, under the same admission,
403
+ * priority and abort rules as a block request (class `unknown`, P0). Given,
404
+ * the scheduler FETCHes `repairFetchRange(x, K, anchor)` over it, and
405
+ * requires `repairEpochReference`. Absent, it walks the hole over
406
+ * `transport` one Group at a time from the hole's start, whose Group is a
407
+ * block's, each repair stating where the next block starts (BLO-52085),
408
+ * under the class of the hole's track (see the module note).
377
409
  */
378
410
  rangeTransport?: RepairRangeFetchTransport
379
411
  /**
@@ -475,6 +507,12 @@ export interface RepairFetchHost {
475
507
  ): boolean
476
508
  /** The admitted FETCH ended without delivering: back to the multicast wait. */
477
509
  releaseRepairHold(sbn: number, packetId: number, catalogTrackName?: string): void
510
+ /** Run `fn` with `receivedAtMs` as the receipt time of what it feeds (optional). */
511
+ withReceiptTime?(receivedAtMs: number, fn: () => void): void
512
+ /** The configured media kind of a packetId (optional; absent reads as video). */
513
+ trackKindFor?(packetId: number): TrackKind | undefined
514
+ /** The stream's D-28 repair deadline: how long after a block's sources it asks for repair (optional). */
515
+ repairDeadlineMsForPacket?(packetId: number): number | undefined
478
516
  }
479
517
  onRepairSubscribe(cb: RepairSubscribeCallback): void
480
518
  /**
@@ -493,8 +531,17 @@ export interface RepairFetchHost {
493
531
  ): void
494
532
  addRepairLifecycleObserver(observer: RepairLifecycleObserver): () => void
495
533
  addTrackResetObserver(observer: (packetId: number, catalogTrackName: string) => void): () => void
496
- /** Register for lost SS_IDs in undelimited spans (required with `rangeTransport`). */
497
- onUndelimitedLoss?(cb: (loss: UndelimitedIsoLoss) => void): void
534
+ /**
535
+ * Register for lost SS_IDs in undelimited spans (required with
536
+ * `rangeTransport`). A host that offers it and `closeIsoHoles` keeps such a
537
+ * gap as a pending hole for the scheduler to repair. `onExpired` is told of
538
+ * a pending hole the stream ran past the locator's horizon; returning true,
539
+ * the scheduler closes it (`closeIsoHoles`), otherwise the host discards it.
540
+ */
541
+ onUndelimitedLoss?(
542
+ cb: (loss: UndelimitedIsoLoss) => void,
543
+ onExpired?: (hole: ExpiredIsoHole) => boolean,
544
+ ): void
498
545
  /** A hole's range repair ended, or none is sent: feed what was not stated. */
499
546
  closeIsoHoles?(packetId: number, catalogTrackName: string | undefined, start: number, length: number): void
500
547
  clearRepairForBlock(sbn: number, packetId: number, catalogTrackName?: string): void
@@ -624,9 +671,26 @@ interface RepairEntry {
624
671
  attempts: number
625
672
  running: FetchRun | null
626
673
  /** A range request for a pending hole `[sbn, sbn + holeLength)`. */
627
- readonly range?: RepairFetchRange & { readonly lostSsId: number; readonly holeLength: number }
674
+ readonly range?: {
675
+ readonly lostSsId: number
676
+ readonly holeLength: number
677
+ /** The §7.7 Group range for `rangeTransport`; null walks the hole over `transport`. */
678
+ readonly groups: RepairFetchRange | null
679
+ /** When the hole was reported: what it states keeps the deadline a span opened then would have. */
680
+ readonly reportedAt: number
681
+ }
628
682
  /** A range request's deadline timer (see the module note). */
629
683
  expiry?: ReturnType<typeof setTimeout>
684
+ /**
685
+ * A hole walked over `transport` (walkHole): the Group its next FETCH asks
686
+ * for, and the Group FETCH it has outstanding, if any.
687
+ */
688
+ walk?: {
689
+ next: number
690
+ group: { readonly sbn: number; readonly controller: AbortController } | null
691
+ /** Its Group FETCH was cancelled for best-effort repair: ask for that Group again. */
692
+ yielded: boolean
693
+ }
630
694
  }
631
695
 
632
696
  interface ResolvedDeadline {
@@ -686,8 +750,26 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
686
750
 
687
751
  /** Whatever ends an entry: a block's repair slot, or a hole's pending state. */
688
752
  const clearEntry = (entry: RepairEntry): void => {
689
- if (entry.range) mc.closeIsoHoles!(entry.packetId, entry.catalogTrackName, entry.sbn, entry.range.holeLength)
690
- else clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName)
753
+ const { range } = entry
754
+ if (range) {
755
+ atReport(range, () => mc.closeIsoHoles!(entry.packetId, entry.catalogTrackName, entry.sbn, range.holeLength))
756
+ } else {
757
+ clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName)
758
+ }
759
+ }
760
+
761
+ /**
762
+ * Run what a hole's walk states, or the rest of the hole it leaves as
763
+ * spans, at the time the hole was reported: the blocks start their
764
+ * deadlines from there, as the one repair-less span a host without holes
765
+ * opened then would have, so the walk never holds a frame later than that
766
+ * span did. A §7.7 range FETCH feeds at its own receipt time, as a host
767
+ * with `rangeTransport` always has.
768
+ */
769
+ const atReport = (range: NonNullable<RepairEntry['range']>, work: () => void): void => {
770
+ const fec = mc.fecManager
771
+ if (range.groups !== null || fec.withReceiptTime === undefined) work()
772
+ else fec.withReceiptTime(range.reportedAt, work)
691
773
  }
692
774
 
693
775
  const releaseHold = (entry: RepairEntry): void => {
@@ -702,7 +784,7 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
702
784
  if (!run) return
703
785
  entry.running = null
704
786
  run.stopped = reason
705
- run.controller.abort()
787
+ run.controller.abort(reason)
706
788
  // A preempted request returns to the queue; until it runs again nothing is
707
789
  // in flight that could land, so the block goes back to its multicast wait.
708
790
  if (reason === 'preempted') releaseHold(entry)
@@ -781,32 +863,78 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
781
863
  const admit = (entry: RepairEntry, now: number): number | null => {
782
864
  const budgetMs = entry.deadlineAt - now
783
865
  const rttMs = readRtt()
784
- const reason: RepairSkipReason | null =
785
- !entry.range && !groupCanComplete(entry.sbn, entry.packetId, entry.catalogTrackName)
786
- ? 'group-cannot-complete'
787
- : rttMs === null
788
- ? 'rtt-unmeasured'
789
- : rttMs < budgetMs
790
- ? null
791
- : 'rtt-exceeds-budget'
866
+ const reason = refusal(entry, now, rttMs)
792
867
  if (reason === null) return rttMs
793
868
  skip(entry, reason, rttMs, budgetMs)
794
869
  return null
795
870
  }
796
871
 
872
+ /** Why admission refuses `entry` at `now` with round trip `rttMs`, or null when it admits it. */
873
+ const refusal = (entry: RepairEntry, now: number, rttMs: number | null): RepairSkipReason | null =>
874
+ !entry.range && !groupCanComplete(entry.sbn, entry.packetId, entry.catalogTrackName)
875
+ ? 'group-cannot-complete'
876
+ : rttMs === null
877
+ ? 'rtt-unmeasured'
878
+ : rttMs < entry.deadlineAt - now
879
+ ? null
880
+ : 'rtt-exceeds-budget'
881
+
797
882
  const retire = (entry: RepairEntry): void => {
798
883
  if (entries.get(entry.key) === entry) entries.delete(entry.key)
799
884
  if (entry.expiry !== undefined) clearTimeout(entry.expiry)
800
885
  }
801
886
 
802
- /** Whether any entry of priority below `priority` is queued or in flight. */
803
- const outstandingBelow = (priority: RepairPriority): boolean => {
887
+ /**
888
+ * Whether `entry` holds back a request of `priority`: no audio or delta
889
+ * repair FETCH is issued while a keyframe repair FETCH is outstanding
890
+ * (fec-multicast-00 rule 3), and no delta one while audio repair is. A
891
+ * walk (walkHole) is repair a run gets before it reaches its FEC deadline:
892
+ * on a video track it is keyframe repair while one of its Group FETCHes is
893
+ * outstanding and between two Groups holds nothing back; on an audio track
894
+ * it holds nothing back (BLO-52085). `videoWalks` false leaves video walks
895
+ * out: they yield to a request that is no walk (`yieldVideoWalks`).
896
+ */
897
+ const holdsBack = (entry: RepairEntry, priority: RepairPriority, videoWalks = true): boolean => {
898
+ if (entry.priority >= priority) return false
899
+ const { walk } = entry
900
+ if (walk === undefined) return true
901
+ if (entry.priority !== 0 || !videoWalks) return false
902
+ return entry.running === null || (walk.group !== null && !walk.group.controller.signal.aborted)
903
+ }
904
+
905
+ /** Whether any entry holds back a request of `priority` (see `holdsBack`). */
906
+ const outstandingBelow = (priority: RepairPriority, videoWalks = true): boolean => {
804
907
  for (const entry of entries.values()) {
805
- if (entry.priority < priority) return true
908
+ if (holdsBack(entry, priority, videoWalks)) return true
806
909
  }
807
910
  return false
808
911
  }
809
912
 
913
+ /**
914
+ * A video walk reaches no FEC deadline, so it holds back no audio or delta
915
+ * request that came due (one of `queued` that is no walk), that nothing
916
+ * else holds back and that admission takes (`admit`): it cancels its outstanding Group FETCH first, so no
917
+ * keyframe repair FETCH is outstanding when that request is issued
918
+ * (fec-multicast-00 rule 3), and asks for that Group again after it
919
+ * (walkHole). Audio and delta repair so goes out when it would with no
920
+ * walk at all (BLO-52085).
921
+ */
922
+ const yieldVideoWalks = (queued: readonly RepairEntry[]): void => {
923
+ const now = performance.now()
924
+ const rttMs = readRtt()
925
+ const due = queued.some((entry) =>
926
+ entry.priority !== 0 && entry.walk === undefined && !outstandingBelow(entry.priority, false) &&
927
+ refusal(entry, now, rttMs) === null)
928
+ if (!due) return
929
+ for (const entry of entries.values()) {
930
+ const walk = entry.walk
931
+ if (entry.priority !== 0 || walk === undefined || walk.group === null) continue
932
+ if (walk.group.controller.signal.aborted) continue
933
+ walk.yielded = true
934
+ walk.group.controller.abort()
935
+ }
936
+ }
937
+
810
938
  /**
811
939
  * A keyframe FETCH is being sent: cancel every in-flight audio and delta
812
940
  * FETCH (§11.4.5 item 3). Called only for a FETCH actually sent.
@@ -849,8 +977,12 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
849
977
  }
850
978
  const rttMs = admit(entry, now)
851
979
  if (rttMs === null) return
852
- // Before the transport sees this request, so the cancels go out first.
853
- if (entry.priority === 0) preemptBestEffort()
980
+ // Before the transport sees this request, so the cancels go out first. A
981
+ // walk reaches no FEC deadline, so it cancels nothing (rule 3).
982
+ if (entry.priority === 0 && entry.walk === undefined) preemptBestEffort()
983
+ // fec-multicast-00 rule 1: one FETCH per block and repair layer. A walk
984
+ // reading this block's Group leaves it to this request.
985
+ if (entry.range === undefined) leaveWalkedGroup(entry)
854
986
  if (counted) entry.attempts++
855
987
  mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
856
988
  rttMs,
@@ -875,6 +1007,20 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
875
1007
  void execute(entry, run)
876
1008
  }
877
1009
 
1010
+ /** End any walk's FETCH of `block`'s Group, cancelling it, before the block's own goes out. */
1011
+ const leaveWalkedGroup = (block: RepairEntry): void => {
1012
+ for (const entry of entries.values()) {
1013
+ const group = entry.walk?.group
1014
+ if (
1015
+ group?.sbn === block.sbn &&
1016
+ entry.packetId === block.packetId &&
1017
+ entry.catalogTrackName === block.catalogTrackName
1018
+ ) {
1019
+ group.controller.abort()
1020
+ }
1021
+ }
1022
+ }
1023
+
878
1024
  const dispatch = (): void => {
879
1025
  if (disposed) return
880
1026
  const now = performance.now()
@@ -905,6 +1051,7 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
905
1051
  for (const entry of queued) {
906
1052
  if (entry.priority === 0) start(entry)
907
1053
  }
1054
+ yieldVideoWalks(queued)
908
1055
  if (outstandingBelow(1)) return
909
1056
  for (const entry of queued) {
910
1057
  if (entry.priority === 1) start(entry)
@@ -954,6 +1101,25 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
954
1101
  }
955
1102
  return counts.sources + counts.repairGroupLength >= counts.authoredLength
956
1103
  }
1104
+ /**
1105
+ * Whether the block a walked Group states can use none of the Group's other
1106
+ * repair symbols: the host holds as many of its symbols as its K' (complete,
1107
+ * or decoding), its group cannot complete it, or it no longer tracks it
1108
+ * (resolved). A relay may hold only part of a Group, or keep its FETCH open,
1109
+ * so the walk does not wait for the rest. False when the host reports no
1110
+ * counts: the walk then takes the whole Group.
1111
+ */
1112
+ const groupServed = (sbn: number, packetId: number, catalogTrackName: string | undefined): boolean => {
1113
+ if (mc.fecManager.blockSymbolCounts === undefined) return false
1114
+ const counts = symbolCounts(sbn, packetId, catalogTrackName)
1115
+ if (counts === undefined || counts.authoredLength === undefined) return true
1116
+ return counts.sources + counts.repairs >= counts.authoredLength || !groupCanComplete(sbn, packetId, catalogTrackName)
1117
+ }
1118
+ /** Where the next block starts after the open block `sbn`, when a repair stated it. */
1119
+ const statedEnd = (sbn: number, packetId: number, catalogTrackName: string | undefined): number | undefined => {
1120
+ const length = symbolCounts(sbn, packetId, catalogTrackName)?.authoredLength
1121
+ return length === undefined ? undefined : serial32Add(sbn, length)
1122
+ }
957
1123
 
958
1124
  const finish = (entry: RepairEntry, run: FetchRun, fed: number, error: unknown): void => {
959
1125
  if (run.stopped !== null || entry.running !== run || entries.get(entry.key) !== entry) {
@@ -1019,23 +1185,30 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1019
1185
  signal: run.controller.signal,
1020
1186
  subscriberPriority: entry.subscriberPriority,
1021
1187
  }
1188
+ const { range } = entry
1189
+ const feed = (packet: Uint8Array): void => {
1190
+ if (entry.catalogTrackName === undefined) {
1191
+ mc.processRepairFromMoQ(packet, entry.packetId)
1192
+ } else {
1193
+ mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName)
1194
+ }
1195
+ }
1022
1196
  try {
1023
- const packets = entry.range
1024
- ? opts.rangeTransport!({
1025
- ...common,
1026
- startGroup: entry.range.startGroup,
1027
- endGroup: entry.range.endGroup,
1028
- lostSsId: entry.range.lostSsId,
1029
- })
1030
- : opts.transport({ ...common, sbn: entry.sbn })
1197
+ const packets = range === undefined
1198
+ ? opts.transport({ ...common, sbn: entry.sbn })
1199
+ : entry.walk !== undefined
1200
+ ? walkHole(entry, entry.walk, range, common)
1201
+ : opts.rangeTransport!({
1202
+ ...common,
1203
+ startGroup: range.groups!.startGroup,
1204
+ endGroup: range.groups!.endGroup,
1205
+ lostSsId: range.lostSsId,
1206
+ })
1031
1207
  for await (const packet of packets) {
1032
1208
  if (run.stopped !== null || entry.running !== run) break
1033
1209
  fed++
1034
- if (entry.catalogTrackName === undefined) {
1035
- mc.processRepairFromMoQ(packet, entry.packetId)
1036
- } else {
1037
- mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName)
1038
- }
1210
+ if (range === undefined) feed(packet)
1211
+ else atReport(range, () => feed(packet))
1039
1212
  }
1040
1213
  finish(entry, run, fed, undefined)
1041
1214
  } catch (error) {
@@ -1043,6 +1216,86 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1043
1216
  }
1044
1217
  }
1045
1218
 
1219
+ /**
1220
+ * The §7.7 range FETCH of a hole over a transport that FETCHes one Group.
1221
+ * A hole starts where a stated block ends, so ext(hole start) is a block's
1222
+ * Group; the repair of each Group states its block, and that block's end is
1223
+ * the next block's Group. Walks to the block holding the hole's highest
1224
+ * lost SS_ID (everything after it arrived) and stops early when a Group
1225
+ * names no block and none is stated there. A Group is done when it ends,
1226
+ * when it held its RSB_length repair symbols, or once the block it states
1227
+ * can use none of the rest (`groupServed`): a relay may keep the FETCH open
1228
+ * past its last object (BLO-52085 D2 80601), or hold only part of the
1229
+ * Group. Each Group is its own FETCH with its own signal, aborted once the
1230
+ * walk leaves it, so the transport cancels it on the wire, and never one
1231
+ * the block's own FETCH reads (fec-multicast-00 rule 1: `leaveWalkedGroup`
1232
+ * takes it over). Between two Groups the walk honours rule 3 (see
1233
+ * `holdsBack`): an audio walk that finds keyframe repair outstanding goes
1234
+ * back to the queue and resumes at `walk.next`; a video walk first
1235
+ * dispatches what came due, and asks again for a Group whose FETCH it
1236
+ * cancelled for audio or delta repair (`yieldVideoWalks`). Every packet is
1237
+ * fed before the walk reads the host's counts: the consumer feeds what it
1238
+ * yields before asking for more.
1239
+ */
1240
+ async function* walkHole(
1241
+ entry: RepairEntry,
1242
+ walk: NonNullable<RepairEntry['walk']>,
1243
+ hole: NonNullable<RepairEntry['range']>,
1244
+ common: Omit<RepairFetchRequest, 'sbn'>,
1245
+ ): AsyncGenerator<Uint8Array> {
1246
+ const lostAt = serial32Distance(entry.sbn, hole.lostSsId)
1247
+ for (let first = true; !common.signal.aborted; first = false) {
1248
+ if (!first && entry.priority !== 0 && outstandingBelow(1)) {
1249
+ stop(entry, 'preempted')
1250
+ note('repair-preempted', entry)
1251
+ return
1252
+ }
1253
+ if (!first && entry.priority === 0) {
1254
+ dispatch()
1255
+ if (common.signal.aborted) return
1256
+ }
1257
+ const sbn = walk.next
1258
+ let next: number | undefined
1259
+ if (entries.get(requestKey(sbn, entry.packetId, entry.catalogTrackName))?.running == null) {
1260
+ const rsIds = new Set<number>()
1261
+ const group = new AbortController()
1262
+ const cancel = (): void => group.abort(common.signal.reason)
1263
+ common.signal.addEventListener('abort', cancel, { once: true })
1264
+ walk.group = { sbn, controller: group }
1265
+ try {
1266
+ for await (const packet of opts.transport({ ...common, sbn, signal: group.signal })) {
1267
+ yield packet
1268
+ const id = extractRepairFecPayloadId(packet)
1269
+ if (id === null || id.ssStart !== sbn || id.ssbLength === 0) continue
1270
+ next ??= serial32Add(sbn, id.ssbLength)
1271
+ rsIds.add(id.rsId)
1272
+ // Aborted before the loop lets go of the transport, whose own
1273
+ // cleanup may stop listening for the abort.
1274
+ if (rsIds.size >= id.rsbLength || groupServed(sbn, entry.packetId, entry.catalogTrackName)) {
1275
+ group.abort()
1276
+ break
1277
+ }
1278
+ }
1279
+ } catch (error) {
1280
+ // The Group was taken over or yielded: the walk goes on.
1281
+ if (!group.signal.aborted || common.signal.aborted) throw error
1282
+ } finally {
1283
+ common.signal.removeEventListener('abort', cancel)
1284
+ walk.group = null
1285
+ }
1286
+ if (walk.yielded) {
1287
+ walk.yielded = false
1288
+ continue
1289
+ }
1290
+ }
1291
+ next ??= statedEnd(sbn, entry.packetId, entry.catalogTrackName)
1292
+ if (next === undefined) return
1293
+ // Past the highest lost SS_ID, which lies in the hole: done.
1294
+ if (serial32Distance(entry.sbn, next) > lostAt) return
1295
+ walk.next = next
1296
+ }
1297
+ }
1298
+
1046
1299
  const removeResetObserver = mc.addTrackResetObserver((packetId, catalogTrackName) => {
1047
1300
  for (const entry of [...entries.values()]) {
1048
1301
  if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue
@@ -1300,17 +1553,75 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1300
1553
  }
1301
1554
  }
1302
1555
 
1303
- if (opts.rangeTransport !== undefined) {
1304
- mc.onUndelimitedLoss!((loss) => {
1556
+ const trackKind = (packetId: number): TrackKind | undefined => {
1557
+ try {
1558
+ return mc.fecManager.trackKindFor?.(packetId)
1559
+ } catch {
1560
+ return undefined
1561
+ }
1562
+ }
1563
+
1564
+ /**
1565
+ * Where a walk of a hole reported `now` ends: WALK_LEAD_MS before the span
1566
+ * it leaves asks for its repair (D-28 from the report, as the span a host
1567
+ * without holes opened then did), so that span's request is armed before
1568
+ * it is due and goes out at the same time; never later than `deadlineAt`.
1569
+ */
1570
+ const walkDeadlineAt = (packetId: number, now: number, deadlineAt: number): number => {
1571
+ let repairDeadlineMs: number | undefined
1572
+ try {
1573
+ repairDeadlineMs = mc.fecManager.repairDeadlineMsForPacket?.(packetId)
1574
+ } catch {
1575
+ repairDeadlineMs = undefined
1576
+ }
1577
+ if (repairDeadlineMs === undefined || !Number.isFinite(repairDeadlineMs)) return deadlineAt
1578
+ return Math.min(deadlineAt, now + repairDeadlineMs - WALK_LEAD_MS)
1579
+ }
1580
+
1581
+ /**
1582
+ * The stream ran past the locator's horizon behind a hole: no repair can
1583
+ * state its blocks any more. A walking hole's walk ends and the hole closes
1584
+ * as at its deadline, so the span it leaves fails, and is reported, as the
1585
+ * span opened at its report would have (BLO-52085); the host discards any
1586
+ * other. Called from inside the stream's packet handling, so the walk ends
1587
+ * once that returns, as for a RAP (below).
1588
+ */
1589
+ const onHoleExpired = (hole: ExpiredIsoHole): boolean => {
1590
+ if (disposed) return false
1591
+ const entry = [...entries.values()].find((candidate) =>
1592
+ candidate.walk !== undefined &&
1593
+ candidate.packetId === hole.packetId &&
1594
+ candidate.catalogTrackName === hole.catalogTrackName &&
1595
+ serial32Distance(candidate.sbn, hole.holeStart) < candidate.range!.holeLength)
1596
+ if (entry === undefined) return false
1597
+ queueMicrotask(() => {
1598
+ if (entries.get(entry.key) !== entry) return
1599
+ retire(entry)
1600
+ stop(entry, 'expired')
1601
+ clearEntry(entry)
1602
+ dispatch()
1603
+ })
1604
+ return true
1605
+ }
1606
+
1607
+ // A host that can keep a hole gets range repair: the §7.7 range over
1608
+ // `rangeTransport`, or else a walk of the hole's Groups over `transport`.
1609
+ if (mc.onUndelimitedLoss !== undefined && mc.closeIsoHoles !== undefined) {
1610
+ mc.onUndelimitedLoss((loss) => {
1305
1611
  const { packetId, catalogTrackName, holeStart, holeLength } = loss
1306
1612
  const close = (): void => mc.closeIsoHoles!(packetId, catalogTrackName, holeStart, holeLength)
1307
1613
  if (disposed) return close()
1308
1614
  const blockProfile = blockProfileOf(packetId)
1309
1615
  const target = opts.resolveTarget(packetId, catalogTrackName)
1310
1616
  if (!target) return close()
1311
- const priority = repairPriorityForClass('unknown')
1312
- const range = rangeFor(loss, target.repairTrack)
1313
- if (range === null) {
1617
+ // The run's class (fec-multicast-00 Block Classification, Audio
1618
+ // Blocks): walked, a hole on an audio track is audio repair, one Group
1619
+ // per FETCH; any other is of unknown class, so keyframe repair.
1620
+ const walked = opts.rangeTransport === undefined
1621
+ const holeClass: BlockClass = walked && trackKind(packetId) === 'audio' ? 'audio' : 'unknown'
1622
+ const priority = repairPriorityForClass(holeClass)
1623
+ const groups = walked ? null : rangeFor(loss, target.repairTrack)
1624
+ if (!walked && groups === null) {
1314
1625
  close()
1315
1626
  mc.noteRepairSkipped('range-no-anchor', { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName)
1316
1627
  return
@@ -1321,12 +1632,15 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1321
1632
  packetId,
1322
1633
  ...(catalogTrackName === undefined ? {} : { catalogTrackName }),
1323
1634
  }
1324
- // `unknown` is P0, whose request is never declined (omitted at worst).
1325
- const wire = wirePriority(identity, 'unknown')!
1635
+ // `unknown` is P0, whose request is never declined (omitted at worst);
1636
+ // an audio FETCH the catalog gives no priority for is not sent.
1637
+ const wire = wirePriority(identity, holeClass)
1638
+ if (wire === null) return close()
1326
1639
  // The hole is no tracked block: no anchor, so this is the multicast
1327
1640
  // wait (`bound: 'wait'`), by intent. A hole holds the release gate, so it
1328
1641
  // must not wait out a presentation delay on top.
1329
- const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, performance.now(), 'unknown')
1642
+ const now = performance.now()
1643
+ const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, now, holeClass)
1330
1644
  if (deadline === null) {
1331
1645
  close()
1332
1646
  mc.noteRepairSkipped(
@@ -1338,6 +1652,7 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1338
1652
  )
1339
1653
  return
1340
1654
  }
1655
+ const deadlineAt = walked ? walkDeadlineAt(packetId, now, deadline.deadlineAt) : deadline.deadlineAt
1341
1656
  const entry: RepairEntry = {
1342
1657
  key: JSON.stringify(['range', packetId, catalogTrackName ?? null, holeStart]),
1343
1658
  ...identity,
@@ -1345,15 +1660,16 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1345
1660
  blockProfile,
1346
1661
  priority,
1347
1662
  subscriberPriority: wire.subscriberPriority,
1348
- deadlineAt: deadline.deadlineAt,
1349
- playoutDeadlineAt: deadline.deadlineAt - deadline.extensionMs,
1663
+ deadlineAt,
1664
+ playoutDeadlineAt: deadlineAt - deadline.extensionMs,
1350
1665
  anchorAt: deadline.anchorAt,
1351
1666
  delayMs: deadline.delayMs,
1352
1667
  bound: deadline.bound,
1353
1668
  order: enqueueOrder++,
1354
1669
  attempts: 0,
1355
1670
  running: null,
1356
- range: { ...range, lostSsId: loss.lostSsId, holeLength },
1671
+ range: { lostSsId: loss.lostSsId, holeLength, groups, reportedAt: now },
1672
+ ...(walked ? { walk: { next: holeStart, group: null, yielded: false } } : {}),
1357
1673
  }
1358
1674
  const previous = entries.get(entry.key)
1359
1675
  if (previous) {
@@ -1363,7 +1679,7 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1363
1679
  entries.set(entry.key, entry)
1364
1680
  entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1)
1365
1681
  dispatch()
1366
- })
1682
+ }, onHoleExpired)
1367
1683
  }
1368
1684
 
1369
1685
  // A RAP arrived complete: a keyframe FETCH below it is moot (§11.4.2). The
@@ -535,6 +535,9 @@ export class TrackSession {
535
535
  // via unsubscribe(), which has already disarmed). A bare assignment there
536
536
  // drops the host's decoder without a fec-teardown -- a leaked Worker.
537
537
  this.#disarmFec()
538
+ // A retired manager must release any decoder suppression it acquired.
539
+ // Unlike unsubscribe(), dispose() is called directly by SessionManager.
540
+ this.#unsuppress()
538
541
  }
539
542
 
540
543
  // -----------------------------------------------------------------------